[GitHub] [carbondata] VenuReddy2103 commented on a change in pull request #3819: [CARBONDATA-3855]support carbon SDK to load data from different files

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [carbondata] VenuReddy2103 commented on a change in pull request #3819: [CARBONDATA-3855]support carbon SDK to load data from different files

GitBox

VenuReddy2103 commented on a change in pull request #3819:
URL: https://github.com/apache/carbondata/pull/3819#discussion_r472408878



##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/utils/SDKUtil.java
##########
@@ -79,4 +98,75 @@ public static ArrayList listFiles(String sourceImageFolder,
     return (Object[]) input[i];
   }
 
+  public static List<CarbonFile> extractFilesFromFolder(String path,
+      String suf, Configuration hadoopConf) {
+    List dataFiles = listFiles(path, suf, hadoopConf);
+    List<CarbonFile> carbonFiles = new ArrayList<>();
+    for (Object dataFile: dataFiles) {
+      carbonFiles.add(FileFactory.getCarbonFile(dataFile.toString(), hadoopConf));
+    }
+    if (CollectionUtils.isEmpty(dataFiles)) {
+      throw new RuntimeException("No file found at given location. Please provide" +
+          "the correct folder location.");
+    }
+    return carbonFiles;
+  }
+
+  public static DataFileStream<GenericData.Record> buildAvroReader(CarbonFile carbonFile,
+       Configuration configuration) throws IOException {
+    try {
+      GenericDatumReader<GenericData.Record> genericDatumReader =
+          new GenericDatumReader<>();
+      DataFileStream<GenericData.Record> avroReader =
+          new DataFileStream<>(FileFactory.getDataInputStream(carbonFile.getPath(),
+          -1, configuration), genericDatumReader);
+      return avroReader;
+    } catch (FileNotFoundException ex) {
+      throw new FileNotFoundException("File " + carbonFile.getPath()
+          + " not found to build carbon writer.");
+    } catch (IOException ex) {
+      if (ex.getMessage().contains("Not a data file")) {
+        throw new RuntimeException("File " + carbonFile.getPath() + " is not in avro format.");
+      } else {
+        throw ex;
+      }
+    }
+  }
+
+  public static Reader buildOrcReader(String path, Configuration conf) throws IOException {
+    try {
+      Reader orcReader = OrcFile.createReader(new Path(path),
+          OrcFile.readerOptions(conf));
+      return orcReader;
+    } catch (FileFormatException ex) {
+      throw new RuntimeException("File " + path + " is not in ORC format");
+    } catch (FileNotFoundException ex) {
+      throw new FileNotFoundException("File " + path + " not found to build carbon writer.");
+    }
+  }
+
+  public static ParquetReader<GenericRecord> buildPqrquetReader(String path, Configuration conf)

Review comment:
       Please correct spelling mistake for parquet in method name.




----------------------------------------------------------------
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:
[hidden email]