calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject calcite git commit: [CALCITE-1310] Infer type of arguments to BETWEEN operator (Yiming Liu)
Date Fri, 08 Jul 2016 21:01:32 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 2193c6e6e -> 63c51d0c6


[CALCITE-1310] Infer type of arguments to BETWEEN operator (Yiming Liu)

Close apache/calcite#252


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

Branch: refs/heads/master
Commit: 63c51d0c6459a4de5cab01188a7f3b7dd1a259fb
Parents: 2193c6e
Author: Yiming Liu <liuyiming.vip@gmail.com>
Authored: Fri Jul 8 14:36:28 2016 +0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Fri Jul 8 12:36:19 2016 -0700

----------------------------------------------------------------------
 .../apache/calcite/sql/fun/SqlBetweenOperator.java  | 13 ++++---------
 .../test/java/org/apache/calcite/test/JdbcTest.java | 16 ++++++++++++++++
 .../org/apache/calcite/test/SqlValidatorTest.java   | 12 ++++++++++++
 3 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/63c51d0c/core/src/main/java/org/apache/calcite/sql/fun/SqlBetweenOperator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlBetweenOperator.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlBetweenOperator.java
index c4358d1..86660a2 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlBetweenOperator.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlBetweenOperator.java
@@ -31,6 +31,7 @@ import org.apache.calcite.sql.SqlWriter;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.parser.SqlParserUtil;
 import org.apache.calcite.sql.type.ComparableOperandTypeChecker;
+import org.apache.calcite.sql.type.InferTypes;
 import org.apache.calcite.sql.type.ReturnTypes;
 import org.apache.calcite.sql.type.SqlOperandTypeChecker;
 import org.apache.calcite.sql.type.SqlTypeUtil;
@@ -107,15 +108,9 @@ public class SqlBetweenOperator extends SqlInfixOperator {
 
   //~ Constructors -----------------------------------------------------------
 
-  public SqlBetweenOperator(
-      Flag flag,
-      boolean negated) {
-    super(
-        negated ? NOT_BETWEEN_NAMES : BETWEEN_NAMES,
-        SqlKind.BETWEEN,
-        30,
-        null,
-        null, OTC_CUSTOM);
+  public SqlBetweenOperator(Flag flag, boolean negated) {
+    super(negated ? NOT_BETWEEN_NAMES : BETWEEN_NAMES, SqlKind.BETWEEN, 30,
+        null, InferTypes.FIRST_KNOWN, OTC_CUSTOM);
     this.flag = flag;
     this.negated = negated;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/63c51d0c/core/src/test/java/org/apache/calcite/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
index 2c0b513..7721163 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -4942,7 +4942,23 @@ public class JdbcTest {
                       "deptno=10; name=Theodore\n",
                       CalciteAssert.toString(resultSet));
 
+                  // Now BETWEEN, with 3 arguments, 2 of which are parameters
+                  final String sql2 = "select \"deptno\", \"name\" "
+                      + "from \"hr\".\"emps\"\n"
+                      + "where \"deptno\" between symmetric ? and ?\n"
+                      + "order by 2";
+                  final PreparedStatement preparedStatement2 =
+                      connection.prepareStatement(sql2);
+                  preparedStatement2.setInt(1, 15);
+                  preparedStatement2.setInt(2, 5);
+                  resultSet = preparedStatement2.executeQuery();
+                  assertThat(CalciteAssert.toString(resultSet),
+                      is("deptno=10; name=Bill\n"
+                          + "deptno=10; name=Sebastian\n"
+                          + "deptno=10; name=Theodore\n"));
+
                   resultSet.close();
+                  preparedStatement2.close();
                   preparedStatement.close();
                   return null;
                 } catch (SQLException e) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/63c51d0c/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 02e29c1..57f71d1 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -6573,6 +6573,18 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
     sql("select 1 from emp having sum(sal) < ?").ok();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1310">[CALCITE-1310]
+   * Infer type of arguments to BETWEEN operator</a>. */
+  @Test public void testBindBetween() {
+    sql("select * from emp where ename between ? and ?").ok();
+    sql("select * from emp where deptno between ? and ?").ok();
+    sql("select * from emp where ? between deptno and ?").ok();
+    sql("select * from emp where ? between ? and deptno").ok();
+    sql("select * from emp where ^?^ between ? and ?")
+        .fails("Illegal use of dynamic parameter");
+  }
+
   @Test public void testUnnest() {
     checkColumnType("select*from unnest(multiset[1])", "INTEGER NOT NULL");
     checkColumnType("select*from unnest(multiset[1, 2])", "INTEGER NOT NULL");


Mime
View raw message