DRILL-720: Add secondary cast rules to be able to implicitly cast to VARBINARY 
(from VARCHAR, INT, BIGINT, FLOAT4, FLOAT8)


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

Branch: refs/heads/master
Commit: 564f9690c9f41b456751b4c3fcda4e547195b375
Parents: fc54e8e
Author: Mehant Baid <[email protected]>
Authored: Tue Jun 10 16:04:12 2014 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Wed Jun 11 09:03:24 2014 -0700

----------------------------------------------------------------------
 .../drill/exec/resolver/ResolverTypePrecedence.java     | 12 +++++++++++-
 .../org/apache/drill/exec/resolver/TypeCastRules.java   |  1 +
 .../java/org/apache/drill/jdbc/test/TestJdbcQuery.java  | 10 +++++++++-
 3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/564f9690/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java
index 9d83941..68a1643 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/ResolverTypePrecedence.java
@@ -125,8 +125,18 @@ public class ResolverTypePrecedence {
     rule.add(MinorType.INTERVAL);
     rule.add(MinorType.INTERVALYEAR);
     rule.add(MinorType.INTERVALDAY);
-
     secondaryImplicitCastRules.put(MinorType.VARCHAR, rule);
+
+    rule = new HashSet<>();
+
+    // Be able to implicitly cast to VARBINARY
+    rule.add(MinorType.INT);
+    rule.add(MinorType.BIGINT);
+    rule.add(MinorType.FLOAT4);
+    rule.add(MinorType.FLOAT8);
+    rule.add(MinorType.VARCHAR);
+    secondaryImplicitCastRules.put(MinorType.VARBINARY, rule);
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/564f9690/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
index 3c20555..5c5ff80 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/resolver/TypeCastRules.java
@@ -761,6 +761,7 @@ public class TypeCastRules {
     rule.add(MinorType.FLOAT4);
     rule.add(MinorType.FLOAT8);
     rule.add(MinorType.BIT);
+    rule.add(MinorType.VARCHAR);
     rule.add(MinorType.VARBINARY);
     rule.add(MinorType.FIXEDBINARY);
     rules.put(MinorType.VARBINARY, rule);

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/564f9690/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
----------------------------------------------------------------------
diff --git 
a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java 
b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
index 501927c..0412f00 100644
--- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
+++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java
@@ -414,5 +414,13 @@ public class TestJdbcQuery extends JdbcTest{
         );
   }
 
-
+  @Test
+  public void testLengthUTF8VarCharInput() throws Exception {
+    JdbcAssert.withNoDefaultSchema()
+        .sql("select length('Sheri', 'UTF8') as L_UTF8 " +
+            "from cp.`employee.json` where employee_id = 1")
+        .returns(
+            "L_UTF8=5\n"
+        );
+  }
 }

Reply via email to