You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by pa...@apache.org on 2015/04/13 20:09:04 UTC

[4/4] drill git commit: DRILL-2668: Fix: CAST(1.1 AS FLOAT) was yielding DOUBLE.

DRILL-2668: Fix: CAST(1.1 AS FLOAT) was yielding DOUBLE.

- Added test method (and others for parallel cases) to TestFunctionsQuery.
- Fixed use of DOUBLE methods/classes for FLOAT:
  - Changed a FLOAT -> DOUBLE mapping in ValueExpressions.
  - Added parallel FLOAT methods/classes in EvaluationVisitor.


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

Branch: refs/heads/master
Commit: 49042bca078aacb24a8d0dddb451363be8e764da
Parents: fe11e86
Author: dbarclay <db...@maprtech.com>
Authored: Thu Apr 2 13:43:36 2015 -0700
Committer: Parth Chandra <pc...@maprtech.com>
Committed: Mon Apr 13 09:36:55 2015 -0700

----------------------------------------------------------------------
 .../common/expression/ValueExpressions.java     |  2 +-
 .../drill/exec/expr/EvaluationVisitor.java      | 25 +++++++
 .../org/apache/drill/TestFunctionsQuery.java    | 76 ++++++++++++++++++++
 3 files changed, 102 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/49042bca/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
index e095e7e..4b7314e 100644
--- a/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
+++ b/common/src/main/java/org/apache/drill/common/expression/ValueExpressions.java
@@ -44,7 +44,7 @@ public class ValueExpressions {
     return new DoubleExpression(d, ExpressionPosition.UNKNOWN);
   }
   public static LogicalExpression getFloat4(float f){
-    return new DoubleExpression(f, ExpressionPosition.UNKNOWN);
+    return new FloatExpression(f, ExpressionPosition.UNKNOWN);
   }
 
   public static LogicalExpression getBit(boolean b){

http://git-wip-us.apache.org/repos/asf/drill/blob/49042bca/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
index 386ab79..b6e3858 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/EvaluationVisitor.java
@@ -40,6 +40,7 @@ import org.apache.drill.common.expression.ValueExpressions.Decimal28Expression;
 import org.apache.drill.common.expression.ValueExpressions.Decimal38Expression;
 import org.apache.drill.common.expression.ValueExpressions.Decimal9Expression;
 import org.apache.drill.common.expression.ValueExpressions.DoubleExpression;
+import org.apache.drill.common.expression.ValueExpressions.FloatExpression;
 import org.apache.drill.common.expression.ValueExpressions.IntExpression;
 import org.apache.drill.common.expression.ValueExpressions.IntervalDayExpression;
 import org.apache.drill.common.expression.ValueExpressions.IntervalYearExpression;
@@ -248,6 +249,14 @@ public class EvaluationVisitor {
     }
 
     @Override
+    public HoldingContainer visitFloatConstant(FloatExpression e, ClassGenerator<?> generator)
+        throws RuntimeException {
+      HoldingContainer out = generator.declare(e.getMajorType());
+      generator.getEvalBlock().assign(out.getValue(), JExpr.lit(e.getFloat()));
+      return out;
+    }
+
+    @Override
     public HoldingContainer visitDoubleConstant(DoubleExpression e, ClassGenerator<?> generator)
         throws RuntimeException {
       HoldingContainer out = generator.declare(e.getMajorType());
@@ -944,6 +953,22 @@ public class EvaluationVisitor {
     }
 
     @Override
+    public HoldingContainer visitFloatConstant(FloatExpression e, ClassGenerator<?> generator)
+        throws RuntimeException {
+      if (constantBoundaries.contains(e)) {
+        generator.getMappingSet().enterConstant();
+        HoldingContainer c = super.visitFloatConstant(e, generator);
+        // generator.getMappingSet().exitConstant();
+        // return c;
+        return renderConstantExpression(generator, c);
+      } else if (generator.getMappingSet().isWithinConstant()) {
+        return super.visitFloatConstant(e, generator).setConstant(true);
+      } else {
+        return super.visitFloatConstant(e, generator);
+      }
+    }
+
+    @Override
     public HoldingContainer visitDoubleConstant(DoubleExpression e, ClassGenerator<?> generator)
         throws RuntimeException {
       if (constantBoundaries.contains(e)) {

http://git-wip-us.apache.org/repos/asf/drill/blob/49042bca/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java b/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java
index 476370d..9a483a1 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestFunctionsQuery.java
@@ -294,6 +294,82 @@ public class TestFunctionsQuery extends BaseTestQuery {
         .go();
   }
 
+
+  // From DRILL-2668:  "CAST ( 1.1 AS FLOAT )" yielded TYPE DOUBLE:
+
+  /**
+   * Test for DRILL-2668, that "CAST ( 1.5 AS FLOAT )" really yields type FLOAT
+   * (rather than type DOUBLE).
+   */
+  @Test
+  public void testLiteralCastToFLOATYieldsFLOAT() throws Exception {
+    testBuilder()
+    .sqlQuery( "SELECT CAST( 1.5 AS FLOAT ) AS ShouldBeFLOAT "
+               + "FROM cp.`employee.json` LIMIT 1" )
+    .unOrdered()
+    .baselineColumns("ShouldBeFLOAT")
+    .baselineValues(new Float(1.5f))
+    .go();
+  }
+
+  @Test
+  public void testLiteralCastToDOUBLEYieldsDOUBLE() throws Exception {
+    testBuilder()
+    .sqlQuery( "SELECT CAST( 1.25 AS DOUBLE PRECISION ) AS ShouldBeDOUBLE "
+               + "FROM cp.`employee.json` LIMIT 1" )
+    .unOrdered()
+    .baselineColumns("ShouldBeDOUBLE")
+    .baselineValues(new Double(1.25))
+    .go();
+  }
+
+  @Test
+  public void testLiteralCastToBIGINTYieldsBIGINT() throws Exception {
+    testBuilder()
+    .sqlQuery( "SELECT CAST( 64 AS BIGINT ) AS ShouldBeBIGINT "
+               + "FROM cp.`employee.json` LIMIT 1" )
+    .unOrdered()
+    .baselineColumns("ShouldBeBIGINT")
+    .baselineValues(new Long(64))
+    .go();
+  }
+
+  @Test
+  public void testLiteralCastToINTEGERYieldsINTEGER() throws Exception {
+    testBuilder()
+    .sqlQuery( "SELECT CAST( 32 AS INTEGER ) AS ShouldBeINTEGER "
+               + "FROM cp.`employee.json` LIMIT 1" )
+    .unOrdered()
+    .baselineColumns("ShouldBeINTEGER")
+    .baselineValues(new Integer(32))
+    .go();
+  }
+
+  @Ignore( "until SMALLINT is supported (DRILL-2470)" )
+  @Test
+  public void testLiteralCastToSMALLINTYieldsSMALLINT() throws Exception {
+    testBuilder()
+    .sqlQuery( "SELECT CAST( 16 AS SMALLINT ) AS ShouldBeSMALLINT "
+               + "FROM cp.`employee.json` LIMIT 1" )
+    .unOrdered()
+    .baselineColumns("ShouldBeSMALLINT")
+    .baselineValues(new Short((short) 16))
+    .go();
+  }
+
+  @Ignore( "until TINYINT is supported (~DRILL-2470)" )
+  @Test
+  public void testLiteralCastToTINYINTYieldsTINYINT() throws Exception {
+    testBuilder()
+    .sqlQuery( "SELECT CAST( 8 AS TINYINT ) AS ShouldBeTINYINT "
+               + "FROM cp.`employee.json` LIMIT 1" )
+    .unOrdered()
+    .baselineColumns("ShouldBeTINYINT")
+    .baselineValues(new Byte((byte) 8))
+    .go();
+  }
+
+
   @Test
   public void testDecimalMultiplicationOverflowHandling() throws Exception {
     String query = "select cast('1' as decimal(9, 5)) * cast ('999999999999999999999999999.999999999' as decimal(38, 9)) as DEC38_1, " +