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 2016/05/04 02:31:01 UTC
[2/2] calcite git commit: Fix up [CALCITE-1219],
moving tests to new class SqlOperatorBindingTest
Fix up [CALCITE-1219], moving tests to new class SqlOperatorBindingTest
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/44a6ba67
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/44a6ba67
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/44a6ba67
Branch: refs/heads/master
Commit: 44a6ba67b92c193468f0de9dc3417c218624e69f
Parents: 1b4209e
Author: Julian Hyde <jh...@apache.org>
Authored: Tue May 3 11:56:16 2016 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Tue May 3 11:56:16 2016 -0700
----------------------------------------------------------------------
.../org/apache/calcite/test/CalciteSuite.java | 1 +
.../calcite/test/SqlOperatorBindingTest.java | 126 +++++++++++++++++++
.../java/org/apache/calcite/util/UtilTest.java | 78 ------------
3 files changed, 127 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/44a6ba67/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteSuite.java b/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
index d9c9e4a..e864910 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteSuite.java
@@ -86,6 +86,7 @@ import org.junit.runners.Suite;
TraitPropagationTest.class,
RelWriterTest.class,
RexProgramTest.class,
+ SqlOperatorBindingTest.class,
RexTransformerTest.class,
BinarySearchTest.class,
EnumerablesTest.class,
http://git-wip-us.apache.org/repos/asf/calcite/blob/44a6ba67/core/src/test/java/org/apache/calcite/test/SqlOperatorBindingTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlOperatorBindingTest.java b/core/src/test/java/org/apache/calcite/test/SqlOperatorBindingTest.java
new file mode 100644
index 0000000..3762c45
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/test/SqlOperatorBindingTest.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.test;
+
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexProgramBuilder;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlUtil;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.type.SqlTypeUtil;
+
+import com.google.common.collect.Lists;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+
+/**
+ * Unit tests for {@link RexProgram} and
+ * {@link RexProgramBuilder}.
+ */
+public class SqlOperatorBindingTest {
+ private RexBuilder rexBuilder;
+ private RelDataType integerDataType;
+ private SqlDataTypeSpec integerType;
+
+ //~ Methods ----------------------------------------------------------------
+
+ /**
+ * Creates a SqlOperatorBindingTest.
+ */
+ public SqlOperatorBindingTest() {
+ super();
+ }
+
+ @Before
+ public void setUp() {
+ JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+ integerDataType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+ integerType = SqlTypeUtil.convertTypeToSpec(integerDataType);
+ rexBuilder = new RexBuilder(typeFactory);
+ }
+
+ /** Tests {@link org.apache.calcite.sql.SqlUtil#isLiteral(SqlNode, boolean)},
+ * which was added to enhance Calcite's public API
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-1219">[CALCITE-1219]
+ * Add a method to SqlOperatorBinding to determine whether operand is a
+ * literal</a>.
+ */
+ @Test public void testSqlNodeLiteral() {
+ final SqlNode literal = SqlLiteral.createExactNumeric(
+ "0",
+ SqlParserPos.ZERO);
+ final SqlNode castLiteral = SqlStdOperatorTable.CAST.createCall(
+ SqlParserPos.ZERO,
+ literal,
+ integerType);
+ final SqlNode castCastLiteral = SqlStdOperatorTable.CAST.createCall(
+ SqlParserPos.ZERO,
+ castLiteral,
+ integerType);
+
+ // SqlLiteral is considered as a Literal
+ assertSame(true, SqlUtil.isLiteral(literal, true));
+ // CAST(SqlLiteral as type) is considered as a Literal
+ assertSame(true, SqlUtil.isLiteral(castLiteral, true));
+ // CAST(CAST(SqlLiteral as type) as type) is NOT considered as a Literal
+ assertSame(false, SqlUtil.isLiteral(castCastLiteral, true));
+ }
+
+ /** Tests {@link org.apache.calcite.rex.RexUtil#isLiteral(RexNode, boolean)},
+ * which was added to enhance Calcite's public API
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-1219">[CALCITE-1219]
+ * Add a method to SqlOperatorBinding to determine whether operand is a
+ * literal</a>.
+ */
+ @Test public void testRexNodeLiteral() {
+ final RexNode literal = rexBuilder.makeZeroLiteral(
+ integerDataType);
+
+ final RexNode castLiteral = rexBuilder.makeCall(
+ integerDataType,
+ SqlStdOperatorTable.CAST,
+ Lists.newArrayList(literal));
+
+ final RexNode castCastLiteral = rexBuilder.makeCall(
+ integerDataType,
+ SqlStdOperatorTable.CAST,
+ Lists.newArrayList(castLiteral));
+
+ // RexLiteral is considered as a Literal
+ assertSame(true, RexUtil.isLiteral(literal, true));
+ // CAST(RexLiteral as type) is considered as a Literal
+ assertSame(true, RexUtil.isLiteral(castLiteral, true));
+ // CAST(CAST(RexLiteral as type) as type) is NOT considered as a Literal
+ assertSame(false, RexUtil.isLiteral(castCastLiteral, true));
+ }
+}
+
+// End SqlOperatorBindingTest.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/44a6ba67/core/src/test/java/org/apache/calcite/util/UtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/util/UtilTest.java b/core/src/test/java/org/apache/calcite/util/UtilTest.java
index c3a7670..548b538 100644
--- a/core/src/test/java/org/apache/calcite/util/UtilTest.java
+++ b/core/src/test/java/org/apache/calcite/util/UtilTest.java
@@ -22,26 +22,11 @@ import org.apache.calcite.examples.RelBuilderExample;
import org.apache.calcite.linq4j.Ord;
import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.linq4j.function.Parameter;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rel.type.RelDataTypeFactory;
-import org.apache.calcite.rel.type.RelDataTypeSystem;
-import org.apache.calcite.rex.RexBuilder;
-import org.apache.calcite.rex.RexNode;
-import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.runtime.ConsList;
import org.apache.calcite.runtime.FlatLists;
import org.apache.calcite.runtime.Resources;
import org.apache.calcite.runtime.Utilities;
-import org.apache.calcite.sql.SqlDataTypeSpec;
import org.apache.calcite.sql.SqlDialect;
-import org.apache.calcite.sql.SqlLiteral;
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.SqlUtil;
-import org.apache.calcite.sql.fun.SqlStdOperatorTable;
-import org.apache.calcite.sql.parser.SqlParserPos;
-import org.apache.calcite.sql.type.SqlTypeFactoryImpl;
-import org.apache.calcite.sql.type.SqlTypeName;
-import org.apache.calcite.sql.type.SqlTypeUtil;
import org.apache.calcite.sql.util.SqlBuilder;
import org.apache.calcite.sql.util.SqlString;
import org.apache.calcite.test.DiffTestCase;
@@ -96,7 +81,6 @@ import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -1768,68 +1752,6 @@ public class UtilTest {
}
assertThat(local2.get(), is("x"));
}
-
- /** Tests {@link org.apache.calcite.sql.SqlUtil#isLiteral(SqlNode, boolean)}.
- *
- * <p>The method {@link org.apache.calcite.sql.SqlUtil#isLiteral(SqlNode, boolean)}
- * was added to enhance Calcite's public API
- * <a href="https://issues.apache.org/jira/browse/CALCITE-1219">[CALCITE-1219]</a>
- */
- @Test public void testSqlNodeLiteral() {
- final RelDataTypeFactory relDataTypeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
- final SqlDataTypeSpec integerType = SqlTypeUtil.convertTypeToSpec(
- relDataTypeFactory.createSqlType(SqlTypeName.INTEGER));
- final SqlNode literal = SqlLiteral.createExactNumeric(
- "0",
- SqlParserPos.ZERO);
- final SqlNode castLiteral = SqlStdOperatorTable.CAST.createCall(
- SqlParserPos.ZERO,
- literal,
- integerType);
- final SqlNode castCastLiteral = SqlStdOperatorTable.CAST.createCall(
- SqlParserPos.ZERO,
- castLiteral,
- integerType);
-
- // SqlLiteral is considered as a Literal
- assertSame(true, SqlUtil.isLiteral(literal, true));
- // CAST(SqlLiteral as type) is considered as a Literal
- assertSame(true, SqlUtil.isLiteral(castLiteral, true));
- // CAST(CAST(SqlLiteral as type) as type) is NOT considered as a Literal
- assertSame(false, SqlUtil.isLiteral(castCastLiteral, true));
- }
-
- /** Tests {@link org.apache.calcite.rex.RexUtil#isLiteral(RexNode, boolean)}.
- *
- * <p>The method {@link org.apache.calcite.rex.RexUtil#isLiteral(RexNode, boolean)}
- * was added to enhance Calcite's public API
- * <a href="https://issues.apache.org/jira/browse/CALCITE-1219">[CALCITE-1219]</a>
- */
- @Test public void testRexNodeLiteral() {
- final RelDataTypeFactory relDataTypeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
- final RelDataType integerDataType = relDataTypeFactory.createSqlType(SqlTypeName.INTEGER);
-
- final RexBuilder rexBuilder = new RexBuilder(relDataTypeFactory);
- final RexNode literal = rexBuilder.makeZeroLiteral(
- relDataTypeFactory.createSqlType(SqlTypeName.INTEGER));
-
- final RexNode castLiteral = rexBuilder.makeCall(
- integerDataType,
- SqlStdOperatorTable.CAST,
- Lists.newArrayList(literal));
-
- final RexNode castCastLiteral = rexBuilder.makeCall(
- integerDataType,
- SqlStdOperatorTable.CAST,
- Lists.newArrayList(castLiteral));
-
- // RexLiteral is considered as a Literal
- assertSame(true, RexUtil.isLiteral(literal, true));
- // CAST(RexLiteral as type) is considered as a Literal
- assertSame(true, RexUtil.isLiteral(castLiteral, true));
- // CAST(CAST(RexLiteral as type) as type) is NOT considered as a Literal
- assertSame(false, RexUtil.isLiteral(castCastLiteral, true));
- }
}
// End UtilTest.java