[GitHub] [carbondata] xubo245 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] xubo245 commented on a change in pull request #3819: [CARBONDATA-3855]support carbon SDK to load data from different files

GitBox

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



##########
File path: sdk/sdk/src/test/java/org/apache/carbondata/sdk/file/JSONCarbonWriterTest.java
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.sdk.file;
+
+import org.apache.carbondata.common.exceptions.sql.InvalidLoadOptionException;
+import org.apache.carbondata.core.metadata.datatype.DataTypes;
+import org.apache.carbondata.core.metadata.datatype.Field;
+import org.apache.carbondata.core.metadata.datatype.StructField;
+import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Test suite for {@link JsonCarbonWriter}
+ */
+public class JSONCarbonWriterTest {
+
+  private Schema buildSchema() {
+    Field[] fields = new Field[9];
+    fields[0] = new Field("stringField", "STRING");
+    fields[1] = new Field("intField", "INT");
+    fields[2] = new Field("shortField", "SHORT");
+    fields[3] = new Field("longField", "LONG");
+    fields[4] = new Field("doubleField", "DOUBLE");
+    fields[5] = new Field("boolField", "BOOLEAN");
+    fields[6] = new Field("dateField", "DATE");
+    fields[7] = new Field("timeField", "TIMESTAMP");
+    fields[8] = new Field("decimalField", "DECIMAL");
+    return new Schema(fields);
+  }
+
+  @Test
+  public void testJsonFileLoadSingleRow() throws IOException,
+      InvalidLoadOptionException, InterruptedException {
+    String filePath = "./src/test/resources/file/json_files/allPrimitiveType.json";
+    String path = "./testLoadJsonFIle";
+    FileUtils.deleteDirectory(new File(path));
+    Schema schema = buildSchema();
+    CarbonWriterBuilder carbonWriterBuilder = new CarbonWriterBuilder();
+    CarbonWriter carbonWriter = carbonWriterBuilder.withJsonPath(filePath).outputPath(path)
+        .withJsonInput(schema).writtenBy("JSONCarbonWriterTest").build();
+    carbonWriter.write();
+    carbonWriter.close();
+    File[] dataFiles = new File(path).listFiles();
+    assert (Objects.requireNonNull(dataFiles).length == 2);
+
+    CarbonReader reader = CarbonReader.builder("./testLoadJsonFIle", "_temp")
+        .projection(new String[]{"stringField", "boolField", "decimalField", "longField"}).build();
+    int id = 0;
+    while (reader.hasNext()) {
+      Object[] row = (Object[]) reader.readNextRow();
+      Assert.assertEquals(row[0], "nihal\"ojha\"");
+      Assert.assertEquals(row[1], false);
+      Assert.assertEquals(row[2], (new BigDecimal("55.35")).setScale(2, BigDecimal.ROUND_FLOOR));
+      Assert.assertEquals(row[3], (long) 1234567);
+      id++;
+    }
+    assert (id == 1);
+    FileUtils.deleteDirectory(new File(path));

Review comment:
       pleae close reader when finihed.
   
   
   please  check all




----------------------------------------------------------------
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]