You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by GitBox <gi...@apache.org> on 2020/02/25 06:40:00 UTC

[GitHub] [carbondata] akashrn5 commented on a change in pull request #3627: [CARBONDATA-3710] Make stage files queryable

akashrn5 commented on a change in pull request #3627: [CARBONDATA-3710] Make stage files queryable
URL: https://github.com/apache/carbondata/pull/3627#discussion_r383680405
 
 

 ##########
 File path: core/src/main/java/org/apache/carbondata/core/statusmanager/StageInputCollector.java
 ##########
 @@ -0,0 +1,143 @@
+/*
+ * 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.carbondata.core.statusmanager;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.stream.Collectors;
+
+import org.apache.carbondata.common.logging.LogServiceFactory;
+import org.apache.carbondata.core.datastore.filesystem.CarbonFile;
+import org.apache.carbondata.core.datastore.impl.FileFactory;
+import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
+
+import static org.apache.carbondata.core.util.path.CarbonTablePath.SUCCESS_FILE_SUBFIX;
+
+import com.google.gson.Gson;
+import org.apache.commons.io.IOUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.InputSplit;
+import org.apache.log4j.Logger;
+
+/**
+ * Utilities to create input split from stage files
+ */
+public class StageInputCollector {
+
+  private static Logger LOGGER =
+      LogServiceFactory.getLogService(StageInputCollector.class.getCanonicalName());
+
+  /**
+   * Collect all stage files and create splits from them.
+   * These splits can be included in the queried.
+   */
+  public static List<InputSplit> createInputSplits(CarbonTable table, Configuration hadoopConf)
+      throws ExecutionException, InterruptedException {
+    List<CarbonFile> stageInputFiles = new LinkedList<>();
+    List<CarbonFile> successFiles = new LinkedList<>();
+    collectStageFiles(table, hadoopConf, stageInputFiles, successFiles);
+    if (stageInputFiles.size() > 0) {
+      int numThreads = Math.min(Math.max(stageInputFiles.size(), 1), 10);
+      ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
+      return createInputSplits(executorService, stageInputFiles);
+    } else {
+      return new ArrayList<>(0);
+    }
+  }
+
+  /**
+   * Collect all stage files and matched success files.
+   * A stage file without success file will not be collected
+   */
+  public static void collectStageFiles(CarbonTable table, Configuration hadoopConf,
+      List<CarbonFile> stageInputList, List<CarbonFile> successFileList) {
+    Objects.requireNonNull(table);
+    Objects.requireNonNull(hadoopConf);
+    Objects.requireNonNull(stageInputList);
+    Objects.requireNonNull(successFileList);
+    CarbonFile dir = FileFactory.getCarbonFile(table.getStagePath(), hadoopConf);
+    if (dir.exists()) {
+      // list the stage folder and collect all stage files who has corresponding success file,
+      // which means the file is committed
+      CarbonFile[] allFiles = dir.listFiles();
 
 Review comment:
   i think, better to avoid listfiles to avoid any future problems. it will create many file objects once, we can use nio APIs. like below
   `Files.newDirectoryStream(Paths.get(table.getStagePath()), "*.success").forEach(path -> {
           map.put(key, value);
         }
         );`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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