Posted by
GitBox on
Dec 15, 2020; 5:49am
URL: http://apache-carbondata-dev-mailing-list-archive.168.s1.nabble.com/GitHub-carbondata-Karan980-opened-a-new-pull-request-4046-CARBONDATA-4071-Fix-wrong-values-of-date-o-tp104510p104730.html
Karan980 commented on a change in pull request #4046:
URL:
https://github.com/apache/carbondata/pull/4046#discussion_r543064547##########
File path: sdk/sdk/src/test/java/org/apache/carbondata/sdk/file/CarbonReaderTest.java
##########
@@ -1741,6 +1742,246 @@ public boolean accept(File dir, String name) {
}
}
+ @Test
+ public void testReadDateAndTimestampColumnInArray() {
+ String path = "./testWriteFiles";
+ try {
+ FileUtils.deleteDirectory(new File(path));
+ Field[] fields = new Field[11];
+ fields[0] = new Field("stringField", DataTypes.STRING);
+ fields[1] = new Field("shortField", DataTypes.SHORT);
+ fields[2] = new Field("dateField", DataTypes.DATE);
+ fields[3] = new Field("timeField", DataTypes.TIMESTAMP);
+ fields[4] = new Field("varcharField", DataTypes.VARCHAR);
+ fields[5] = new Field("arrayFieldDate", DataTypes.createArrayType(DataTypes.DATE));
+ fields[6] = new Field("arrayFieldTimestamp", DataTypes.createArrayType(DataTypes.TIMESTAMP));
+ Map<String, String> map = new HashMap<>();
+ map.put("complex_delimiter_level_1", "#");
+ CarbonWriter writer = CarbonWriter.builder()
+ .outputPath(path)
+ .withLoadOptions(map)
+ .withCsvInput(new Schema(fields))
+ .writtenBy("CarbonReaderTest")
+ .build();
+
+ for (int i = 0; i < 10; i++) {
+ String[] row2 = new String[]{
+ "robot" + (i % 10),
+ String.valueOf(i % 10000),
+ "2019-03-02",
+ "2019-02-12 03:03:34",
+ "varchar",
+ "2019-03-02#2019-03-03#2019-03-04#2019-03-05",
+ "2019-02-12 03:03:34#2019-02-12 03:03:38#2019-02-12 03:03:41#2019-02-12 03:12:34"
+ };
+ writer.write(row2);
+ }
+ writer.close();
+ File[] dataFiles = new File(path).listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ if (name == null) {
+ return false;
+ }
+ return name.endsWith("carbondata");
+ }
+ });
+ if (dataFiles == null || dataFiles.length < 1) {
+ throw new RuntimeException("Carbon data file not exists.");
+ }
+ Schema schema = CarbonSchemaReader
+ .readSchema(dataFiles[0].getAbsolutePath())
+ .asOriginOrder();
+ // Transform the schema
+ String[] strings = new String[schema.getFields().length];
+ for (int i = 0; i < schema.getFields().length; i++) {
+ strings[i] = (schema.getFields())[i].getFieldName();
+ }
+ // Read data
+ CarbonReader reader = CarbonReader
+ .builder(path)
+ .projection(strings)
+ .build();
+
+ int i = 0;
+ while (reader.hasNext()) {
+ Object[] row = (Object[]) reader.readNextRow();
+ assert (row[0].equals("robot" + i));
+ assert (row[2].equals("2019-03-02"));
+ assert (row[3].equals("2019-02-12 03:03:34"));
+ Object[] arrDate = (Object[]) row[5];
+ assert (arrDate[0].equals("2019-03-02"));
+ assert (arrDate[1].equals("2019-03-03"));
+ assert (arrDate[2].equals("2019-03-04"));
+ assert (arrDate[3].equals("2019-03-05"));
+ Object[] arrTimestamp = (Object[]) row[6];
+ assert (arrTimestamp[0].equals("2019-02-12 03:03:34"));
+ assert (arrTimestamp[1].equals("2019-02-12 03:03:38"));
+ assert (arrTimestamp[2].equals("2019-02-12 03:03:41"));
+ assert (arrTimestamp[3].equals("2019-02-12 03:12:34"));
+ i++;
+ }
+ Assert.assertEquals(i, 10);
+ reader.close();
+ FileUtils.deleteDirectory(new File(path));
+ } catch (Throwable e) {
+ e.printStackTrace();
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Test public void testReadDateAndTimestampColumnInStruct()
+ throws IOException, InvalidLoadOptionException, InterruptedException {
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]