accumulo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] milleruntime commented on a change in pull request #890: Organize new Bulk Import code
Date Thu, 10 Jan 2019 22:20:25 GMT
milleruntime commented on a change in pull request #890: Organize new Bulk Import code
URL: https://github.com/apache/accumulo/pull/890#discussion_r246942446
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/clientImpl/bulk/LoadMappingIterator.java
 ##########
 @@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.clientImpl.bulk;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.accumulo.core.clientImpl.bulk.BulkSerialize.createGson;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UncheckedIOException;
+import java.util.AbstractMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.accumulo.core.clientImpl.Table;
+import org.apache.accumulo.core.dataImpl.KeyExtent;
+
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonReader;
+
+/**
+ * Iterator for reading the Bulk Load Mapping JSON.
+ */
+public class LoadMappingIterator
+    implements Iterator<Map.Entry<KeyExtent,Bulk.Files>>, AutoCloseable {
+  private Table.ID tableId;
+  private JsonReader reader;
+  private Gson gson = createGson();
+  private Map<String,String> renameMap;
+
+  LoadMappingIterator(Table.ID tableId, InputStream loadMapFile) throws IOException {
+    this.tableId = tableId;
+    this.reader = new JsonReader(new BufferedReader(new InputStreamReader(loadMapFile, UTF_8)));
+    this.reader.beginArray();
+  }
+
+  public void setRenameMap(Map<String,String> renameMap) {
+    this.renameMap = renameMap;
+  }
+
+  @Override
+  public void close() throws IOException {
+    reader.close();
+  }
+
+  @Override
+  public boolean hasNext() {
+    try {
+      return reader.hasNext();
+    } catch (IOException e) {
+      throw new UncheckedIOException(e);
+    }
+  }
+
+  @Override
+  public Map.Entry<KeyExtent,Bulk.Files> next() {
+    if (!hasNext())
+      return null;
 
 Review comment:
   >  Would prefer caller check hasNext and we throw an exception here. However, I'm not
sure what would be better.
   
   This is basically what we are currently doing as the JSON will throw an exception if you
try to get more from the gson object.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message