You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2018/05/11 17:16:46 UTC

calcite git commit: [CALCITE-2306] AssertionError in RexLiteral.getValue3 with null literal of type DECIMAL (Godfrey He)

Repository: calcite
Updated Branches:
  refs/heads/master 2a4f6c2c7 -> e1326ace2


[CALCITE-2306] AssertionError in RexLiteral.getValue3 with null literal of type DECIMAL (Godfrey He)

Close apache/calcite#690


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

Branch: refs/heads/master
Commit: e1326ace25d508f7217a8cbc5a7a2db2abf92048
Parents: 2a4f6c2
Author: xiaoling.hxl <xi...@alibaba-inc.com>
Authored: Thu May 10 10:05:44 2018 +0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Fri May 11 00:27:12 2018 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/calcite/rex/RexLiteral.java  |  3 +++
 .../java/org/apache/calcite/rex/RexBuilderTest.java   | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/e1326ace/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
index b5900bb..9143616 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
@@ -752,6 +752,9 @@ public class RexLiteral extends RexNode {
    * translator wants it.
    */
   public Object getValue3() {
+    if (value == null) {
+      return null;
+    }
     switch (typeName) {
     case DECIMAL:
       assert value instanceof BigDecimal;

http://git-wip-us.apache.org/repos/asf/calcite/blob/e1326ace/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java b/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
index 2edddf8..f959a76 100644
--- a/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
+++ b/core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
@@ -34,6 +34,7 @@ import java.util.TimeZone;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
@@ -362,6 +363,19 @@ public class RexBuilderTest {
     assertThat(literal.getValueAs(DateString.class), notNullValue());
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-2306">[CALCITE-2306]
+   * AssertionError in {@link RexLiteral#getValue3} with null literal of type
+   * DECIMAL</a>. */
+  @Test public void testDecimalLiteral() {
+    final RelDataTypeFactory typeFactory =
+        new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RelDataType type = typeFactory.createSqlType(SqlTypeName.DECIMAL);
+    final RexBuilder builder = new RexBuilder(typeFactory);
+    final RexLiteral literal = builder.makeExactLiteral(null, type);
+    assertThat(literal.getValue3(), nullValue());
+  }
+
   /** Tests {@link DateString} year range. */
   @Test public void testDateStringYearError() {
     try {