nihal0107 commented on a change in pull request #3819: URL: https://github.com/apache/carbondata/pull/3819#discussion_r450848843 ########## File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonWriterBuilder.java ########## @@ -594,6 +613,332 @@ public CarbonWriterBuilder withJsonInput(Schema carbonSchema) { return this; } + /** + * to build a {@link CarbonWriter}, which accepts loading CSV files. + * + * @param filePath absolute path under which files should be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withCsvPath(String filePath) { + if (filePath.length() == 0) { + throw new IllegalArgumentException("filePath can not be empty"); + } + this.filePath = filePath; + this.isDirectory = new File(filePath).isDirectory(); + this.withCsvInput(); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts CSV files directory and + * list of file which has to be loaded. + * + * @param filePath directory where the CSV file exists. + * @param fileList list of files which has to be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withCsvPath(String filePath, List<String> fileList) { + this.fileList = fileList; + this.withCsvPath(filePath); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts loading Parquet files. + * + * @param filePath absolute path under which files should be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withParquetPath(String filePath) throws IOException { + if (filePath.length() == 0) { + throw new IllegalArgumentException("filePath can not be empty"); + } + this.filePath = filePath; + this.isDirectory = new File(filePath).isDirectory(); + this.writerType = WRITER_TYPE.PARQUET; + this.buildParquetReader(); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts parquet files directory and + * list of file which has to be loaded. + * + * @param filePath directory where the parquet file exists. + * @param fileList list of files which has to be loaded. + * @return CarbonWriterBuilder + * @throws IOException + */ + public CarbonWriterBuilder withParquetPath(String filePath, List<String> fileList) + throws IOException { + this.fileList = fileList; + this.withParquetPath(filePath); + return this; + } + + private void buildParquetReader() throws IOException { + AvroReadSupport<GenericRecord> avroReadSupport = new AvroReadSupport<>(); + ParquetReader<GenericRecord> parquetReader; + if (this.isDirectory) { + if (this.fileList == null || this.fileList.size() == 0) { + File[] dataFiles = new File(this.filePath).listFiles(); + if (dataFiles == null || dataFiles.length == 0) { + throw new RuntimeException("No Parquet file found at given location. Please provide" + + "the correct folder location."); + } + parquetReader = ParquetReader.builder(avroReadSupport, + new Path(String.valueOf(dataFiles[0]))).build(); + } else { + parquetReader = ParquetReader.builder(avroReadSupport, Review comment: checked the schema at the time of the carbon writer builder. If not all the files are having the same schema then throwing the exception. ########## File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonWriterBuilder.java ########## @@ -594,6 +613,332 @@ public CarbonWriterBuilder withJsonInput(Schema carbonSchema) { return this; } + /** + * to build a {@link CarbonWriter}, which accepts loading CSV files. + * + * @param filePath absolute path under which files should be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withCsvPath(String filePath) { + if (filePath.length() == 0) { + throw new IllegalArgumentException("filePath can not be empty"); + } + this.filePath = filePath; + this.isDirectory = new File(filePath).isDirectory(); + this.withCsvInput(); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts CSV files directory and + * list of file which has to be loaded. + * + * @param filePath directory where the CSV file exists. + * @param fileList list of files which has to be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withCsvPath(String filePath, List<String> fileList) { + this.fileList = fileList; + this.withCsvPath(filePath); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts loading Parquet files. + * + * @param filePath absolute path under which files should be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withParquetPath(String filePath) throws IOException { + if (filePath.length() == 0) { + throw new IllegalArgumentException("filePath can not be empty"); + } + this.filePath = filePath; + this.isDirectory = new File(filePath).isDirectory(); + this.writerType = WRITER_TYPE.PARQUET; + this.buildParquetReader(); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts parquet files directory and + * list of file which has to be loaded. + * + * @param filePath directory where the parquet file exists. + * @param fileList list of files which has to be loaded. + * @return CarbonWriterBuilder + * @throws IOException + */ + public CarbonWriterBuilder withParquetPath(String filePath, List<String> fileList) + throws IOException { + this.fileList = fileList; + this.withParquetPath(filePath); + return this; + } + + private void buildParquetReader() throws IOException { + AvroReadSupport<GenericRecord> avroReadSupport = new AvroReadSupport<>(); + ParquetReader<GenericRecord> parquetReader; + if (this.isDirectory) { + if (this.fileList == null || this.fileList.size() == 0) { + File[] dataFiles = new File(this.filePath).listFiles(); + if (dataFiles == null || dataFiles.length == 0) { + throw new RuntimeException("No Parquet file found at given location. Please provide" + + "the correct folder location."); + } + parquetReader = ParquetReader.builder(avroReadSupport, + new Path(String.valueOf(dataFiles[0]))).build(); + } else { + parquetReader = ParquetReader.builder(avroReadSupport, + new Path(this.filePath + "/" + this.fileList.get(0))).build(); Review comment: handled. ########## File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/CarbonWriterBuilder.java ########## @@ -594,6 +613,332 @@ public CarbonWriterBuilder withJsonInput(Schema carbonSchema) { return this; } + /** + * to build a {@link CarbonWriter}, which accepts loading CSV files. + * + * @param filePath absolute path under which files should be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withCsvPath(String filePath) { + if (filePath.length() == 0) { + throw new IllegalArgumentException("filePath can not be empty"); + } + this.filePath = filePath; + this.isDirectory = new File(filePath).isDirectory(); + this.withCsvInput(); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts CSV files directory and + * list of file which has to be loaded. + * + * @param filePath directory where the CSV file exists. + * @param fileList list of files which has to be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withCsvPath(String filePath, List<String> fileList) { + this.fileList = fileList; + this.withCsvPath(filePath); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts loading Parquet files. + * + * @param filePath absolute path under which files should be loaded. + * @return CarbonWriterBuilder + */ + public CarbonWriterBuilder withParquetPath(String filePath) throws IOException { + if (filePath.length() == 0) { + throw new IllegalArgumentException("filePath can not be empty"); + } + this.filePath = filePath; + this.isDirectory = new File(filePath).isDirectory(); + this.writerType = WRITER_TYPE.PARQUET; + this.buildParquetReader(); + return this; + } + + /** + * to build a {@link CarbonWriter}, which accepts parquet files directory and + * list of file which has to be loaded. + * + * @param filePath directory where the parquet file exists. + * @param fileList list of files which has to be loaded. + * @return CarbonWriterBuilder + * @throws IOException + */ + public CarbonWriterBuilder withParquetPath(String filePath, List<String> fileList) + throws IOException { + this.fileList = fileList; + this.withParquetPath(filePath); + return this; + } + + private void buildParquetReader() throws IOException { + AvroReadSupport<GenericRecord> avroReadSupport = new AvroReadSupport<>(); + ParquetReader<GenericRecord> parquetReader; + if (this.isDirectory) { + if (this.fileList == null || this.fileList.size() == 0) { + File[] dataFiles = new File(this.filePath).listFiles(); + if (dataFiles == null || dataFiles.length == 0) { + throw new RuntimeException("No Parquet file found at given location. Please provide" + + "the correct folder location."); + } + parquetReader = ParquetReader.builder(avroReadSupport, + new Path(String.valueOf(dataFiles[0]))).build(); + } else { + parquetReader = ParquetReader.builder(avroReadSupport, + new Path(this.filePath + "/" + this.fileList.get(0))).build(); + } + } else { + parquetReader = ParquetReader.builder(avroReadSupport, + new Path(this.filePath)).build(); Review comment: done. ---------------------------------------------------------------- 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] |
Free forum by Nabble | Edit this page |