drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ve...@apache.org
Subject [3/3] drill git commit: DRILL-2342: Store the nullability property of column in view persistence store.
Date Fri, 20 Mar 2015 18:31:52 GMT
DRILL-2342: Store the nullability property of column in view persistence store.


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/d7dc0b95
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/d7dc0b95
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/d7dc0b95

Branch: refs/heads/master
Commit: d7dc0b95b8086b63523ec2e6a1cc9236d1a5bc44
Parents: 9c9ee8c
Author: vkorukanti <venki.korukanti@gmail.com>
Authored: Tue Mar 17 17:38:55 2015 -0700
Committer: vkorukanti <venki.korukanti@gmail.com>
Committed: Thu Mar 19 22:16:46 2015 -0700

----------------------------------------------------------------------
 .../org/apache/drill/exec/dotdrill/View.java    | 26 +++++++++++---
 .../org/apache/drill/TestMergeFilterPlan.java   |  4 +--
 .../apache/drill/exec/sql/TestViewSupport.java  | 36 ++++++++++++++++++++
 .../apache/drill/jdbc/test/TestMetadataDDL.java |  2 +-
 .../org/apache/drill/jdbc/test/TestViews.java   |  4 +--
 5 files changed, 63 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/d7dc0b95/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java b/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
index 8b6e1e3..a7b496b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/dotdrill/View.java
@@ -52,13 +52,23 @@ public class View {
     public final SqlTypeName type;
     public final Integer precision;
     public final Integer scale;
+    public final Boolean isNullable;
 
     @JsonCreator
-    public FieldType(@JsonProperty("name") String name, @JsonProperty("type") SqlTypeName
type, @JsonProperty("precision") Integer precision, @JsonProperty("scale") Integer scale){
+    public FieldType(
+        @JsonProperty("name") String name,
+        @JsonProperty("type") SqlTypeName type,
+        @JsonProperty("precision") Integer precision,
+        @JsonProperty("scale") Integer scale,
+        @JsonProperty("isNullable") Boolean isNullable){
       this.name = name;
       this.type = type;
       this.precision = precision;
       this.scale = scale;
+
+      // Property "isNullable" is not part of the initial view definition and added in DRILL-2342.
If the
+      // default value is null, consider it as "true". It is safe to default to "nullable"
than "required" type.
+      this.isNullable = (isNullable == null) ? true : isNullable;
     }
 
     public FieldType(String name, RelDataType dataType){
@@ -82,6 +92,7 @@ public class View {
 
       this.precision = p;
       this.scale = s;
+      this.isNullable = dataType.isNullable();
     }
   }
 
@@ -120,12 +131,19 @@ public class View {
 
     for(FieldType field : fields){
       names.add(field.name);
+      RelDataType type;
       if(field.precision == null && field.scale == null){
-        types.add(factory.createSqlType(field.type));
+        type = factory.createSqlType(field.type);
       }else if(field.precision != null && field.scale == null){
-        types.add(factory.createSqlType(field.type, field.precision));
+        type = factory.createSqlType(field.type, field.precision);
       }else{
-        types.add(factory.createSqlType(field.type, field.precision, field.scale));
+        type = factory.createSqlType(field.type, field.precision, field.scale);
+      }
+
+      if (field.isNullable) {
+        types.add(factory.createTypeWithNullability(type, true));
+      } else {
+        types.add(type);
       }
     }
     return factory.createStructType(types, names);

http://git-wip-us.apache.org/repos/asf/drill/blob/d7dc0b95/exec/java-exec/src/test/java/org/apache/drill/TestMergeFilterPlan.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestMergeFilterPlan.java b/exec/java-exec/src/test/java/org/apache/drill/TestMergeFilterPlan.java
index 65559b1..0b20b7a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestMergeFilterPlan.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestMergeFilterPlan.java
@@ -55,8 +55,8 @@ public class TestMergeFilterPlan extends PlanTestBase {
         "group by dat.store_id\n" +
         "order by dat.store_id";
 
-    String expectedPattern1 = "Filter(condition=[AND(OR(=($0, 1), =($0, 2), =($0, 3)), =(CAST($4):ANY
NOT NULL, 'GRADUATE DEGREE'))])";
-    String expectedPattern2 = "Filter(condition=[AND(OR(=($0, 1), =($0, 2), =($0, 3)), LIKE(CAST($1):ANY
NOT NULL, '%VP%'))])";
+    String expectedPattern1 = "Filter(condition=[AND(OR(=($0, 1), =($0, 2), =($0, 3)), =($4,
'GRADUATE DEGREE'))])";
+    String expectedPattern2 = "Filter(condition=[AND(OR(=($0, 1), =($0, 2), =($0, 3)), LIKE($1,
'%VP%'))])";
     String excludedPattern = "Filter(condition=[OR(=($0, 1), =($0, 2), =($0, 3))])";
 
     test("use dfs.tmp");

http://git-wip-us.apache.org/repos/asf/drill/blob/d7dc0b95/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
index bfd3f18..3b55b99 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java
@@ -40,5 +40,41 @@ public class TestViewSupport extends BaseTestQuery{
     test(selectOutside);
   }
 
+  /**
+   * DRILL-2342 This test is for case where output columns are nullable. Existing tests already
cover the case
+   * where columns are required.
+   */
+  @Test
+  public void testNullabilityPropertyInViewPersistence() throws Exception {
+    final String viewName = "testNullabilityPropertyInViewPersistence";
+    try {
+
+      test("USE dfs_test.tmp");
+      test(String.format("CREATE OR REPLACE VIEW %s AS SELECT " +
+          "CAST(customer_id AS BIGINT) as cust_id, " +
+          "CAST(fname AS VARCHAR(25)) as fname, " +
+          "CAST(country AS VARCHAR(20)) as country " +
+          "FROM cp.`customer.json` " +
+          "ORDER BY customer_id " +
+          "LIMIT 1;", viewName));
 
+      testBuilder()
+          .sqlQuery(String.format("DESCRIBE %s", viewName))
+          .unOrdered()
+          .baselineColumns("COLUMN_NAME", "DATA_TYPE", "IS_NULLABLE")
+          .baselineValues("cust_id", "BIGINT", "YES")
+          .baselineValues("fname", "VARCHAR", "YES")
+          .baselineValues("country", "VARCHAR", "YES")
+          .go();
+
+      testBuilder()
+          .sqlQuery(String.format("SELECT * FROM %s", viewName))
+          .ordered()
+          .baselineColumns("cust_id", "fname", "country")
+          .baselineValues(1L, "Sheri", "Mexico")
+          .go();
+    } finally {
+      test("drop view " + viewName + ";");
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/drill/blob/d7dc0b95/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
index 41a595d..3534f35 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestMetadataDDL.java
@@ -228,7 +228,7 @@ public class TestMetadataDDL extends JdbcTestQueryBase {
           resultSet = statement.executeQuery("DESCRIBE `TABLES`");
           Set<String> result = JdbcAssert.toStringSet(resultSet);
           resultSet.close();
-          ImmutableSet<String> expected = ImmutableSet.of("COLUMN_NAME=key; DATA_TYPE=INTEGER;
IS_NULLABLE=NO");
+          ImmutableSet<String> expected = ImmutableSet.of("COLUMN_NAME=key; DATA_TYPE=INTEGER;
IS_NULLABLE=YES");
           assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result,
expected), expected.equals(result));
 
           // Test describe of `TABLES` with a schema qualifier which is not in default schema

http://git-wip-us.apache.org/repos/asf/drill/blob/d7dc0b95/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
----------------------------------------------------------------------
diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
index 8042a6d..3fe8e2f 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestViews.java
@@ -350,8 +350,8 @@ public class TestViews extends JdbcTestQueryBase {
           result = JdbcAssert.toString(resultSet).trim();
           resultSet.close();
           expected =
-              "COLUMN_NAME=key; DATA_TYPE=INTEGER; IS_NULLABLE=NO\n" +
-              "COLUMN_NAME=value; DATA_TYPE=VARCHAR; IS_NULLABLE=NO";
+              "COLUMN_NAME=key; DATA_TYPE=INTEGER; IS_NULLABLE=YES\n" +
+              "COLUMN_NAME=value; DATA_TYPE=VARCHAR; IS_NULLABLE=YES";
           assertTrue(String.format("Generated string:\n%s\ndoes not match:\n%s", result,
expected),
               expected.equals(result));
 


Mime
View raw message