drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [drill] arina-ielchiieva commented on a change in pull request #1726: DRILL-7143: Support default value for empty columns
Date Sun, 07 Apr 2019 13:03:20 GMT
arina-ielchiieva commented on a change in pull request #1726: DRILL-7143: Support default value
for empty columns
URL: https://github.com/apache/drill/pull/1726#discussion_r272833495
 
 

 ##########
 File path: exec/java-exec/src/test/java/org/apache/drill/exec/store/easy/text/compliant/TestCsvWithSchema.java
 ##########
 @@ -1069,4 +1070,203 @@ public void testMissingColsReqDefault() throws Exception {
       resetSchema();
     }
   }
+
+  public static final String missingColContents[] = {
+    "id,amount,start_date",
+    "1,20,2019-01-01",
+    "2",
+    "3,30"
+  };
+
+  /**
+   * Demonstrate that CSV works for a schema with nullable types when columns
+   * are missing (there is no comma to introduce an empty field in the data.)
+   */
+  @Test
+  public void testMissingColsNullable() throws Exception {
+    String tableName = "missingColsNullable";
+    String tablePath = buildTable(tableName, missingColContents);
+
+    try {
+      enableV3(true);
+      enableSchema(true);
+      String sql = "create or replace schema (" +
+          "id int not null, amount int, start_date date" +
+          ") for table %s";
+      run(sql, tablePath);
+      sql = "SELECT * FROM " + tablePath + "ORDER BY id";
+      RowSet actual = client.queryBuilder().sql(sql).rowSet();
+
+      TupleMetadata expectedSchema = new SchemaBuilder()
+          .add("id", MinorType.INT)
+          .addNullable("amount", MinorType.INT)
+          .addNullable("start_date", MinorType.DATE)
+          .buildSchema();
+      RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+          .addRow(1, 20, new LocalDate(2019, 1, 1))
+          .addRow(2, null, null)
+          .addRow(3, 30, null)
+          .build();
+      RowSetUtilities.verify(expected, actual);
+    } finally {
+      resetV3();
+      resetSchema();
+    }
+  }
+
+  public static final String blankColContents[] = {
+    "id,amount,start_date",
+    "1,20,2019-01-01",
+    "2,,",
+    "3,30,"
+  };
+
+  /**
+   * Demonstrate that CSV uses a comma to introduce a column,
+   * even if that column has no data. In this case, CSV assumes the
+   * value of the column is a blank string.
+   * <p>
+   * Such a schema cannot be converted to a number or date column,
+   * even nullable, because a blank string is neither a valid number nor
+   * a valid date.
+   */
+
+  @Test
+  public void testBlankCols() throws Exception {
+    String tableName = "blankCols";
+    String tablePath = buildTable(tableName, blankColContents);
+
+    try {
+      enableV3(true);
+      enableSchema(true);
+      String sql = "SELECT * FROM " + tablePath + "ORDER BY id";
+      RowSet actual = client.queryBuilder().sql(sql).rowSet();
+
+      TupleMetadata expectedSchema = new SchemaBuilder()
+          .add("id", MinorType.VARCHAR)
+          .add("amount", MinorType.VARCHAR)
+          .add("start_date", MinorType.VARCHAR)
+          .buildSchema();
+      RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
+          .addRow("1", "20", "2019-01-01")
+          .addRow("2", "", "")
+          .addRow("3", "30", "")
+          .build();
+      RowSetUtilities.verify(expected, actual);
+    } finally {
+      resetV3();
+      resetSchema();
+    }
+  }
+
+  /**
+   * Use the same data set as above tests, but use a schema to do type
+   * conversion. Blank columns become 0 for numeric non-nullable, nulls for
+   * nullable non-numeric.
+   *
+   * @throws Exception
 
 Review comment:
   Please remove @throws or add description to avoid warnings in the IDE.

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

Mime
View raw message