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 2014/11/14 22:32:22 UTC
[14/58] [abbrv] [partial] incubator-calcite git commit: [CALCITE-306]
Standardize code style for "import package.*; "
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/LatticeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/LatticeTest.java b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
index e9c1ac4..e70b80b 100644
--- a/core/src/test/java/org/apache/calcite/test/LatticeTest.java
+++ b/core/src/test/java/org/apache/calcite/test/LatticeTest.java
@@ -14,15 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.optiq.materialize.MaterializationService;
-import net.hydromatic.optiq.runtime.Hook;
-
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.RelOptUtil;
-import org.eigenbase.util.TestUtil;
-import org.eigenbase.util.Util;
+import org.apache.calcite.materialize.MaterializationService;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.util.TestUtil;
+import org.apache.calcite.util.Util;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
@@ -49,7 +48,7 @@ import static org.junit.Assert.assertThat;
* Unit test for lattices.
*/
public class LatticeTest {
- private OptiqAssert.AssertThat modelWithLattice(String name, String sql,
+ private CalciteAssert.AssertThat modelWithLattice(String name, String sql,
String... extras) {
final StringBuilder buf = new StringBuilder("{ name: '")
.append(name)
@@ -62,10 +61,10 @@ public class LatticeTest {
return modelWithLattices(buf.toString());
}
- private OptiqAssert.AssertThat modelWithLattices(String... lattices) {
+ private CalciteAssert.AssertThat modelWithLattices(String... lattices) {
final Class<JdbcTest.EmpDeptTableFactory> clazz =
JdbcTest.EmpDeptTableFactory.class;
- return OptiqAssert.that().withModel(""
+ return CalciteAssert.that().withModel(""
+ "{\n"
+ " version: '1.0',\n"
+ " schemas: [\n"
@@ -118,14 +117,14 @@ public class LatticeTest {
@Test public void testLatticeSqlWithGroupByFails() {
modelWithLattice("star",
"select 1 from \"foodmart\".\"sales_fact_1997\" as s group by \"product_id\"")
- .connectThrows("Invalid node type AggregateRel in lattice query");
+ .connectThrows("Invalid node type LogicalAggregate in lattice query");
}
/** Tests a lattice whose SQL is invalid because it contains a ORDER BY. */
@Test public void testLatticeSqlWithOrderByFails() {
modelWithLattice("star",
"select 1 from \"foodmart\".\"sales_fact_1997\" as s order by \"product_id\"")
- .connectThrows("Invalid node type SortRel in lattice query");
+ .connectThrows("Invalid node type Sort in lattice query");
}
/** Tests a lattice whose SQL is invalid because it contains a UNION ALL. */
@@ -134,7 +133,7 @@ public class LatticeTest {
"select 1 from \"foodmart\".\"sales_fact_1997\" as s\n"
+ "union all\n"
+ "select 1 from \"foodmart\".\"sales_fact_1997\" as s")
- .connectThrows("Invalid node type UnionRel in lattice query");
+ .connectThrows("Invalid node type LogicalUnion in lattice query");
}
/** Tests a lattice with valid join SQL. */
@@ -170,10 +169,10 @@ public class LatticeTest {
foodmartModel()
.query("select count(*) from \"adhoc\".\"star\"")
.convertMatches(
- OptiqAssert.checkRel(
- "AggregateRel(group=[{}], EXPR$0=[COUNT()])\n"
- + " ProjectRel(DUMMY=[0])\n"
- + " StarTableScan(table=[[adhoc, star]])\n",
+ CalciteAssert.checkRel(
+ "LogicalAggregate(group=[{}], EXPR$0=[COUNT()])\n"
+ + " LogicalProject(DUMMY=[0])\n"
+ + " StarTableScan(table=[[adhoc, star]])\n",
counter));
} catch (RuntimeException e) {
assertThat(Util.getStackTrace(e), containsString("CannotPlanException"));
@@ -185,16 +184,15 @@ public class LatticeTest {
@Test public void testLatticeRecognizeJoin() {
final AtomicInteger counter = new AtomicInteger();
foodmartModel()
- .query(
- "select s.\"unit_sales\", p.\"brand_name\"\n"
+ .query("select s.\"unit_sales\", p.\"brand_name\"\n"
+ "from \"foodmart\".\"sales_fact_1997\" as s\n"
+ "join \"foodmart\".\"product\" as p using (\"product_id\")\n")
.enableMaterializations(true)
.substitutionMatches(
- OptiqAssert.checkRel(
- "ProjectRel(unit_sales=[$7], brand_name=[$10])\n"
- + " ProjectRel($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], $f5=[$5], $f6=[$6], $f7=[$7], $f8=[$8], $f9=[$9], $f10=[$10], $f11=[$11], $f12=[$12], $f13=[$13], $f14=[$14], $f15=[$15], $f16=[$16], $f17=[$17], $f18=[$18], $f19=[$19], $f20=[$20], $f21=[$21], $f22=[$22])\n"
- + " TableAccessRel(table=[[adhoc, star]])\n",
+ CalciteAssert.checkRel(
+ "LogicalProject(unit_sales=[$7], brand_name=[$10])\n"
+ + " LogicalProject($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], $f5=[$5], $f6=[$6], $f7=[$7], $f8=[$8], $f9=[$9], $f10=[$10], $f11=[$11], $f12=[$12], $f13=[$13], $f14=[$14], $f15=[$15], $f16=[$16], $f17=[$17], $f18=[$18], $f19=[$19], $f20=[$20], $f21=[$21], $f22=[$22])\n"
+ + " LogicalTableScan(table=[[adhoc, star]])\n",
counter));
assertThat(counter.intValue(), equalTo(1));
}
@@ -202,9 +200,8 @@ public class LatticeTest {
/** Tests an aggregate on a 2-way join query can use an aggregate table. */
@Test public void testLatticeRecognizeGroupJoin() {
final AtomicInteger counter = new AtomicInteger();
- OptiqAssert.AssertQuery that = foodmartModel()
- .query(
- "select distinct p.\"brand_name\", s.\"customer_id\"\n"
+ CalciteAssert.AssertQuery that = foodmartModel()
+ .query("select distinct p.\"brand_name\", s.\"customer_id\"\n"
+ "from \"foodmart\".\"sales_fact_1997\" as s\n"
+ "join \"foodmart\".\"product\" as p using (\"product_id\")\n")
.enableMaterializations(true)
@@ -216,19 +213,19 @@ public class LatticeTest {
assertThat(s,
anyOf(
containsString(
- "ProjectRel($f0=[$1], $f1=[$0])\n"
- + " AggregateRel(group=[{2, 10}])\n"
- + " TableAccessRel(table=[[adhoc, star]])\n"),
+ "LogicalProject($f0=[$1], $f1=[$0])\n"
+ + " LogicalAggregate(group=[{2, 10}])\n"
+ + " LogicalTableScan(table=[[adhoc, star]])\n"),
containsString(
- "AggregateRel(group=[{2, 10}])\n"
- + " TableAccessRel(table=[[adhoc, star]])\n")));
+ "LogicalAggregate(group=[{2, 10}])\n"
+ + " LogicalTableScan(table=[[adhoc, star]])\n")));
return null;
}
});
assertThat(counter.intValue(), equalTo(2));
- that.explainContains(
- "EnumerableCalcRel(expr#0..1=[{inputs}], $f0=[$t1], $f1=[$t0])\n"
- + " EnumerableTableAccessRel(table=[[adhoc, m{2, 10}]])")
+ that.explainContains(""
+ + "EnumerableCalc(expr#0..1=[{inputs}], $f0=[$t1], $f1=[$t0])\n"
+ + " EnumerableTableScan(table=[[adhoc, m{2, 10}]])")
.returnsCount(69203);
// Run the same query again and see whether it uses the same
@@ -244,7 +241,7 @@ public class LatticeTest {
.returnsCount(69203);
// Ideally the counter would stay at 2. It increments to 3 because
- // OptiqAssert.AssertQuery creates a new schema for every request,
+ // CalciteAssert.AssertQuery creates a new schema for every request,
// and therefore cannot re-use lattices or materializations from the
// previous request.
assertThat(counter.intValue(), equalTo(3));
@@ -264,8 +261,7 @@ public class LatticeTest {
+ "from \"foodmart\".\"sales_fact_1997\" as s\n"
+ "join \"foodmart\".\"time_by_day\" as t using (\"time_id\")\n")
.enableMaterializations(true)
- .explainContains(
- "EnumerableTableAccessRel(table=[[adhoc, m{27, 31}")
+ .explainContains("EnumerableTableScan(table=[[adhoc, m{27, 31}")
.returnsCount(4);
}
@@ -278,9 +274,9 @@ public class LatticeTest {
+ "join \"foodmart\".\"time_by_day\" as t using (\"time_id\")\n"
+ "group by t.\"the_year\", t.\"quarter\"")
.enableMaterializations(true)
- .explainContains(
- "EnumerableCalcRel(expr#0..4=[{inputs}], proj#0..2=[{exprs}])\n"
- + " EnumerableTableAccessRel(table=[[adhoc, m{27, 31}")
+ .explainContains(""
+ + "EnumerableCalc(expr#0..4=[{inputs}], proj#0..2=[{exprs}])\n"
+ + " EnumerableTableScan(table=[[adhoc, m{27, 31}")
.returnsUnordered("the_year=1997; quarter=Q1; C=21588",
"the_year=1997; quarter=Q2; C=20368",
"the_year=1997; quarter=Q3; C=21453",
@@ -301,10 +297,10 @@ public class LatticeTest {
+ "join \"foodmart\".\"time_by_day\" as t using (\"time_id\")\n"
+ "group by t.\"the_year\"")
.enableMaterializations(true)
- .explainContains(
- "EnumerableCalcRel(expr#0..3=[{inputs}], expr#4=[10], expr#5=[*($t3, $t4)], proj#0..2=[{exprs}], US=[$t5])\n"
- + " EnumerableAggregateRel(group=[{0}], C=[$SUM0($2)], Q=[MIN($1)], agg#2=[$SUM0($4)])\n"
- + " EnumerableTableAccessRel(table=[[adhoc, m{27, 31}")
+ .explainContains(""
+ + "EnumerableCalc(expr#0..3=[{inputs}], expr#4=[10], expr#5=[*($t3, $t4)], proj#0..2=[{exprs}], US=[$t5])\n"
+ + " EnumerableAggregate(group=[{0}], C=[$SUM0($2)], Q=[MIN($1)], agg#2=[$SUM0($4)])\n"
+ + " EnumerableTableScan(table=[[adhoc, m{27, 31}")
.returnsUnordered("the_year=1997; C=86837; Q=Q1; US=2667730.0000")
.sameResultWithMaterializationsDisabled();
}
@@ -337,13 +333,12 @@ public class LatticeTest {
+ " dimensions: [ 'the_year', ['t', 'quarter'] ],\n"
+ " measures: [ ]\n"
+ " } ]\n")
- .query(
- "select distinct t.\"the_year\", t.\"quarter\"\n"
+ .query("select distinct t.\"the_year\", t.\"quarter\"\n"
+ "from \"foodmart\".\"sales_fact_1997\" as s\n"
+ "join \"foodmart\".\"time_by_day\" as t using (\"time_id\")\n")
.enableMaterializations(true)
- .explainContains("EnumerableAggregateRel(group=[{2, 3}])\n"
- + " EnumerableTableAccessRel(table=[[adhoc, m{16, 17, 27, 31}]])")
+ .explainContains("EnumerableAggregate(group=[{2, 3}])\n"
+ + " EnumerableTableScan(table=[[adhoc, m{16, 17, 27, 31}]])")
.returnsUnordered("the_year=1997; quarter=Q1",
"the_year=1997; quarter=Q2",
"the_year=1997; quarter=Q3",
@@ -386,12 +381,12 @@ public class LatticeTest {
return null;
}
};
- final OptiqAssert.AssertThat that = foodmartModel().pooled();
+ final CalciteAssert.AssertThat that = foodmartModel().pooled();
that.query("select sum(\"unit_sales\") as s, count(*) as c\n"
+ "from \"foodmart\".\"sales_fact_1997\"")
.withHook(Hook.CREATE_MATERIALIZATION, handler)
.enableMaterializations(true)
- .explainContains("EnumerableTableAccessRel(table=[[adhoc, m{}]])")
+ .explainContains("EnumerableTableScan(table=[[adhoc, m{}]])")
.returnsUnordered("S=266773.0000; C=86837");
assertThat(mats.toString(), mats.size(), equalTo(2));
@@ -426,10 +421,10 @@ public class LatticeTest {
+ "join \"foodmart\".\"time_by_day\" using (\"time_id\")\n"
+ "group by \"the_year\"")
.enableMaterializations(true)
- .explainContains("EnumerableCalcRel(expr#0..1=[{inputs}], C=[$t1])\n"
- + " EnumerableAggregateRel(group=[{0}], C=[COUNT($1)])\n"
- + " EnumerableCalcRel(expr#0..4=[{inputs}], proj#0..1=[{exprs}])\n"
- + " EnumerableTableAccessRel(table=[[adhoc, m{27, 31}]])")
+ .explainContains("EnumerableCalc(expr#0..1=[{inputs}], C=[$t1])\n"
+ + " EnumerableAggregate(group=[{0}], C=[COUNT($1)])\n"
+ + " EnumerableCalc(expr#0..4=[{inputs}], proj#0..1=[{exprs}])\n"
+ + " EnumerableTableScan(table=[[adhoc, m{27, 31}]])")
.returnsUnordered("C=4");
}
@@ -440,10 +435,10 @@ public class LatticeTest {
+ "join \"foodmart\".\"time_by_day\" using (\"time_id\")\n"
+ "group by \"the_year\"")
.enableMaterializations(true)
- .explainContains("EnumerableCalcRel(expr#0..1=[{inputs}], C=[$t1])\n"
- + " EnumerableAggregateRel(group=[{0}], C=[COUNT($0)])\n"
- + " EnumerableAggregateRel(group=[{0}])\n"
- + " EnumerableTableAccessRel(table=[[adhoc, m{27, 31}]])")
+ .explainContains("EnumerableCalc(expr#0..1=[{inputs}], C=[$t1])\n"
+ + " EnumerableAggregate(group=[{0}], C=[COUNT($0)])\n"
+ + " EnumerableAggregate(group=[{0}])\n"
+ + " EnumerableTableScan(table=[[adhoc, m{27, 31}]])")
.returnsUnordered("C=1");
}
@@ -512,18 +507,17 @@ public class LatticeTest {
// TODO
}
- private OptiqAssert.AssertThat foodmartModel(String... extras) {
+ private CalciteAssert.AssertThat foodmartModel(String... extras) {
return modelWithLattice("star",
"select 1 from \"foodmart\".\"sales_fact_1997\" as \"s\"\n"
- + "join \"foodmart\".\"product\" as \"p\" using (\"product_id\")\n"
- + "join \"foodmart\".\"time_by_day\" as \"t\" using (\"time_id\")\n"
- + "join \"foodmart\".\"product_class\" as \"pc\" on \"p\".\"product_class_id\" = \"pc\".\"product_class_id\"",
+ + "join \"foodmart\".\"product\" as \"p\" using (\"product_id\")\n"
+ + "join \"foodmart\".\"time_by_day\" as \"t\" using (\"time_id\")\n"
+ + "join \"foodmart\".\"product_class\" as \"pc\" on \"p\".\"product_class_id\" = \"pc\".\"product_class_id\"",
extras);
}
- private OptiqAssert.AssertThat foodmartModelWithOneTile() {
- return foodmartModel(
- " auto: false,\n"
+ private CalciteAssert.AssertThat foodmartModelWithOneTile() {
+ return foodmartModel(" auto: false,\n"
+ " defaultMeasures: [ {\n"
+ " agg: 'count'\n"
+ " } ],\n"
@@ -547,7 +541,7 @@ public class LatticeTest {
"jdbc:calcite:model=core/src/test/resources/mysql-foodmart-lattice-model.json");
final ResultSet resultSet = connection.createStatement()
.executeQuery("select * from \"adhoc\".\"m{27, 31}\"");
- System.out.println(OptiqAssert.toString(resultSet));
+ System.out.println(CalciteAssert.toString(resultSet));
connection.close();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/LinqFrontJdbcBackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/LinqFrontJdbcBackTest.java b/core/src/test/java/org/apache/calcite/test/LinqFrontJdbcBackTest.java
index a7218e2..5349579 100644
--- a/core/src/test/java/org/apache/calcite/test/LinqFrontJdbcBackTest.java
+++ b/core/src/test/java/org/apache/calcite/test/LinqFrontJdbcBackTest.java
@@ -14,17 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.linq4j.expressions.Expressions;
-import net.hydromatic.linq4j.expressions.ParameterExpression;
-import net.hydromatic.linq4j.function.Predicate1;
-
-import net.hydromatic.optiq.SchemaPlus;
-import net.hydromatic.optiq.Schemas;
-import net.hydromatic.optiq.jdbc.OptiqConnection;
-
-import org.eigenbase.util.Util;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.linq4j.function.Predicate1;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.util.Util;
import org.junit.Test;
@@ -36,8 +34,8 @@ import java.sql.SQLException;
public class LinqFrontJdbcBackTest {
@Test public void testTableWhere() throws SQLException,
ClassNotFoundException {
- final OptiqConnection connection =
- OptiqAssert.getConnection(OptiqAssert.SchemaSpec.JDBC_FOODMART);
+ final CalciteConnection connection =
+ CalciteAssert.getConnection(CalciteAssert.SchemaSpec.JDBC_FOODMART);
final SchemaPlus schema =
connection.getRootSchema().getSubSchema("foodmart");
ParameterExpression c =
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
index 3b6827b..7fa1848 100644
--- a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
+++ b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
@@ -14,17 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
-
-import net.hydromatic.optiq.jdbc.JavaTypeFactoryImpl;
-import net.hydromatic.optiq.materialize.MaterializationService;
-import net.hydromatic.optiq.prepare.Prepare;
-
-import org.eigenbase.relopt.SubstitutionVisitor;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.reltype.RelDataTypeSystem;
-import org.eigenbase.rex.*;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
+package org.apache.calcite.test;
+
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.materialize.MaterializationService;
+import org.apache.calcite.plan.SubstitutionVisitor;
+import org.apache.calcite.prepare.Prepare;
+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.RexInputRef;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import com.google.common.base.Function;
@@ -34,8 +36,11 @@ import org.junit.Test;
import java.math.BigDecimal;
import java.sql.ResultSet;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
/**
* Unit test for the materialized view rewrite mechanism. Each test has a
@@ -44,16 +49,16 @@ import static org.junit.Assert.*;
*/
public class MaterializationTest {
private static final Function<ResultSet, Void> CONTAINS_M0 =
- OptiqAssert.checkResultContains(
- "EnumerableTableAccessRel(table=[[hr, m0]])");
+ CalciteAssert.checkResultContains(
+ "EnumerableTableScan(table=[[hr, m0]])");
final JavaTypeFactoryImpl typeFactory =
new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
final RexBuilder rexBuilder = new RexBuilder(typeFactory);
@Test public void testFilter() {
- OptiqAssert.that()
- .with(OptiqAssert.Config.REGULAR)
+ CalciteAssert.that()
+ .with(CalciteAssert.Config.REGULAR)
.withMaterializations(
JdbcTest.HR_MODEL,
"m0",
@@ -61,8 +66,7 @@ public class MaterializationTest {
.query(
"select \"empid\" + 1 from \"emps\" where \"deptno\" = 10")
.enableMaterializations(true)
- .explainContains(
- "EnumerableTableAccessRel(table=[[hr, m0]])")
+ .explainContains("EnumerableTableScan(table=[[hr, m0]])")
.sameResultWithMaterializationsDisabled();
}
@@ -70,8 +74,8 @@ public class MaterializationTest {
try {
Prepare.THREAD_TRIM.set(true);
MaterializationService.setThreadLocal();
- OptiqAssert.that()
- .with(OptiqAssert.Config.REGULAR)
+ CalciteAssert.that()
+ .with(CalciteAssert.Config.REGULAR)
.withMaterializations(
JdbcTest.HR_MODEL,
"m0",
@@ -79,8 +83,7 @@ public class MaterializationTest {
.query(
"select \"empid\" + 1 as x from \"emps\" where \"deptno\" = 10")
.enableMaterializations(true)
- .explainContains(
- "EnumerableTableAccessRel(table=[[hr, m0]])")
+ .explainContains("EnumerableTableScan(table=[[hr, m0]])")
.sameResultWithMaterializationsDisabled();
} finally {
Prepare.THREAD_TRIM.set(false);
@@ -100,8 +103,8 @@ public class MaterializationTest {
try {
Prepare.THREAD_TRIM.set(true);
MaterializationService.setThreadLocal();
- OptiqAssert.that()
- .with(OptiqAssert.Config.REGULAR)
+ CalciteAssert.that()
+ .with(CalciteAssert.Config.REGULAR)
.withMaterializations(model, "m0", materialize)
.query(query)
.enableMaterializations(true)
@@ -119,13 +122,12 @@ public class MaterializationTest {
try {
Prepare.THREAD_TRIM.set(true);
MaterializationService.setThreadLocal();
- OptiqAssert.that()
- .with(OptiqAssert.Config.REGULAR)
+ CalciteAssert.that()
+ .with(CalciteAssert.Config.REGULAR)
.withMaterializations(model, "m0", materialize)
.query(query)
.enableMaterializations(true)
- .explainContains(
- "EnumerableTableAccessRel(table=[[hr, emps]])");
+ .explainContains("EnumerableTableScan(table=[[hr, emps]])");
} finally {
Prepare.THREAD_TRIM.set(false);
}
@@ -179,9 +181,9 @@ public class MaterializationTest {
"select \"name\", \"empid\" + 1 as e\n"
+ "from \"emps\" where \"deptno\" - 10 = 2",
JdbcTest.HR_MODEL,
- OptiqAssert.checkResultContains(
- "EnumerableCalcRel(expr#0..2=[{inputs}], expr#3=[2], expr#4=[=($t0, $t3)], name=[$t2], E=[$t1], $condition=[$t4])\n"
- + " EnumerableTableAccessRel(table=[[hr, m0]]"));
+ CalciteAssert.checkResultContains(
+ "EnumerableCalc(expr#0..2=[{inputs}], expr#3=[2], expr#4=[=($t0, $t3)], name=[$t2], E=[$t1], $condition=[$t4])\n"
+ + " EnumerableTableScan(table=[[hr, m0]]"));
}
/** Cannot materialize because "name" is not projected in the MV. */
@@ -224,9 +226,9 @@ public class MaterializationTest {
"select \"deptno\", \"empid\", \"name\" from \"emps\" where \"deptno\" = 10 or \"deptno\" = 20 or \"empid\" < 160",
"select \"empid\" + 1 as x, \"name\" from \"emps\" where \"deptno\" = 10",
JdbcTest.HR_MODEL,
- OptiqAssert.checkResultContains(
+ CalciteAssert.checkResultContains(
"EnumerableCalcRel(expr#0..2=[{inputs}], expr#3=[1], expr#4=[+($t1, $t3)], X=[$t4], name=[$t2], condition=?)\n"
- + " EnumerableTableAccessRel(table=[[hr, m0]])"));
+ + " EnumerableTableScan(table=[[hr, m0]])"));
}
/** Aggregation query at same level of aggregation as aggregation
@@ -238,17 +240,17 @@ public class MaterializationTest {
}
/** Aggregation query at coarser level of aggregation than aggregation
- * materialization. Requires an additional AggregateRel to roll up. Note that
+ * materialization. Requires an additional aggregate to roll up. Note that
* COUNT is rolled up using SUM. */
@Test public void testAggregateRollUp() {
checkMaterialize(
"select \"empid\", \"deptno\", count(*) as c, sum(\"empid\") as s from \"emps\" group by \"empid\", \"deptno\"",
"select count(*) + 1 as c, \"deptno\" from \"emps\" group by \"deptno\"",
JdbcTest.HR_MODEL,
- OptiqAssert.checkResultContains(
- "EnumerableCalcRel(expr#0..1=[{inputs}], expr#2=[1], expr#3=[+($t1, $t2)], C=[$t3], deptno=[$t0])\n"
- + " EnumerableAggregateRel(group=[{1}], agg#0=[$SUM0($2)])\n"
- + " EnumerableTableAccessRel(table=[[hr, m0]])"));
+ CalciteAssert.checkResultContains(
+ "EnumerableCalc(expr#0..1=[{inputs}], expr#2=[1], expr#3=[+($t1, $t2)], C=[$t3], deptno=[$t0])\n"
+ + " EnumerableAggregate(group=[{1}], agg#0=[$SUM0($2)])\n"
+ + " EnumerableTableScan(table=[[hr, m0]])"));
}
/** Aggregation materialization with a project. */
@@ -260,7 +262,7 @@ public class MaterializationTest {
"select \"deptno\", count(*) as c, \"empid\" + 2, sum(\"empid\") as s from \"emps\" group by \"empid\", \"deptno\"",
"select count(*) + 1 as c, \"deptno\" from \"emps\" group by \"deptno\"",
JdbcTest.HR_MODEL,
- OptiqAssert.checkResultContains(
+ CalciteAssert.checkResultContains(
"xxx"));
}
@@ -288,8 +290,8 @@ public class MaterializationTest {
@Test public void testMaterializationReferencesTableInOtherSchema() {}
/** Unit test for logic functions
- * {@link org.eigenbase.relopt.SubstitutionVisitor#mayBeSatisfiable} and
- * {@link org.eigenbase.relopt.SubstitutionVisitor#simplify}. */
+ * {@link org.apache.calcite.plan.SubstitutionVisitor#mayBeSatisfiable} and
+ * {@link org.apache.calcite.plan.SubstitutionVisitor#simplify}. */
@Test public void testSatisfiable() {
// TRUE may be satisfiable
checkSatisfiable(rexBuilder.makeLiteral(true), "true");
@@ -555,8 +557,8 @@ public class MaterializationTest {
*/
@Ignore
@Test public void testFilterGroupQueryOnStar() {
- checkMaterialize(
- "select p.\"product_name\", t.\"the_year\", sum(f.\"unit_sales\") as \"sum_unit_sales\", count(*) as \"c\"\n"
+ checkMaterialize("select p.\"product_name\", t.\"the_year\",\n"
+ + " sum(f.\"unit_sales\") as \"sum_unit_sales\", count(*) as \"c\"\n"
+ "from \"foodmart\".\"sales_fact_1997\" as f\n"
+ "join (\n"
+ " select \"time_id\", \"the_year\", \"the_month\"\n"
@@ -572,14 +574,14 @@ public class MaterializationTest {
+ " pc.\"product_category\",\n"
+ " p.\"product_name\"",
"select t.\"the_month\", count(*) as x\n"
- + "from (\n"
- + " select \"time_id\", \"the_year\", \"the_month\"\n"
- + " from \"foodmart\".\"time_by_day\") as t,\n"
- + " \"foodmart\".\"sales_fact_1997\" as f\n"
- + "where t.\"the_year\" = 1997\n"
- + "and t.\"time_id\" = f.\"time_id\"\n"
- + "group by t.\"the_year\",\n"
- + " t.\"the_month\"\n",
+ + "from (\n"
+ + " select \"time_id\", \"the_year\", \"the_month\"\n"
+ + " from \"foodmart\".\"time_by_day\") as t,\n"
+ + " \"foodmart\".\"sales_fact_1997\" as f\n"
+ + "where t.\"the_year\" = 1997\n"
+ + "and t.\"time_id\" = f.\"time_id\"\n"
+ + "group by t.\"the_year\",\n"
+ + " t.\"the_month\"\n",
JdbcTest.FOODMART_MODEL,
CONTAINS_M0);
}
@@ -588,8 +590,7 @@ public class MaterializationTest {
* materialization that is just a join. */
@Ignore
@Test public void testQueryOnStar() {
- String q =
- "select *\n"
+ String q = "select *\n"
+ "from \"foodmart\".\"sales_fact_1997\" as f\n"
+ "join \"foodmart\".\"time_by_day\" as t on f.\"time_id\" = t.\"time_id\"\n"
+ "join \"foodmart\".\"product\" as p on f.\"product_id\" = p.\"product_id\"\n"
@@ -604,8 +605,7 @@ public class MaterializationTest {
* nothing unpleasant happens. */
@Ignore
@Test public void testJoinOnUnionMaterialization() {
- String q =
- "select *\n"
+ String q = "select *\n"
+ "from (select * from \"emps\" union all select * from \"emps\")\n"
+ "join \"depts\" using (\"deptno\")";
checkNoMaterialize(q, q, JdbcTest.HR_MODEL);
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java b/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
index a51694f..7abe734 100644
--- a/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
+++ b/core/src/test/java/org/apache/calcite/test/MockCatalogReader.java
@@ -14,28 +14,48 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.RelOptPlanner;
-import org.eigenbase.relopt.RelOptSchema;
-import org.eigenbase.reltype.*;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.parser.*;
-import org.eigenbase.sql.type.*;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.util.Pair;
-import org.eigenbase.util.Util;
-
-import net.hydromatic.linq4j.expressions.Expression;
-
-import net.hydromatic.optiq.prepare.Prepare;
+package org.apache.calcite.test;
+
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptSchema;
+import org.apache.calcite.prepare.Prepare;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelCollationImpl;
+import org.apache.calcite.rel.RelFieldCollation;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalTableScan;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeComparability;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
+import org.apache.calcite.sql.SqlAccessType;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.ObjectSqlType;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.validate.SqlMoniker;
+import org.apache.calcite.sql.validate.SqlMonikerImpl;
+import org.apache.calcite.sql.validate.SqlMonikerType;
+import org.apache.calcite.sql.validate.SqlMonotonicity;
+import org.apache.calcite.sql.validate.SqlValidatorCatalogReader;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
/**
* Mock implementation of {@link SqlValidatorCatalogReader} which returns tables
* "EMP", "DEPT", "BONUS", "SALGRADE" (same as Oracle's SCOTT schema).
@@ -318,6 +338,7 @@ public class MockCatalogReader implements Prepare.CatalogReader {
//~ Inner Classes ----------------------------------------------------------
+ /** Mock schema. */
public static class MockSchema {
private final List<String> tableNames = new ArrayList<String>();
private String name;
@@ -337,7 +358,7 @@ public class MockCatalogReader implements Prepare.CatalogReader {
/**
* Mock implementation of
- * {@link net.hydromatic.optiq.prepare.Prepare.PreparingTable}.
+ * {@link org.apache.calcite.prepare.Prepare.PreparingTable}.
*/
public static class MockTable implements Prepare.PreparingTable {
private final MockCatalogReader catalogReader;
@@ -373,7 +394,7 @@ public class MockCatalogReader implements Prepare.CatalogReader {
}
public RelNode toRel(ToRelContext context) {
- return new TableAccessRel(context.getCluster(), this);
+ return new LogicalTableScan(context.getCluster(), this);
}
public List<RelCollation> getCollationList() {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/MockRelOptCost.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MockRelOptCost.java b/core/src/test/java/org/apache/calcite/test/MockRelOptCost.java
index 5a4d4ca..4dbd98f 100644
--- a/core/src/test/java/org/apache/calcite/test/MockRelOptCost.java
+++ b/core/src/test/java/org/apache/calcite/test/MockRelOptCost.java
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
+package org.apache.calcite.test;
-import org.eigenbase.relopt.*;
+import org.apache.calcite.plan.RelOptCost;
/**
* MockRelOptCost is a mock implementation of the {@link RelOptCost} interface.
@@ -25,15 +25,13 @@ import org.eigenbase.relopt.*;
public class MockRelOptCost implements RelOptCost {
//~ Methods ----------------------------------------------------------------
- @Override
- public boolean equals(Object obj) {
+ @Override public boolean equals(Object obj) {
return this == obj
|| obj instanceof MockRelOptCost
&& equals((MockRelOptCost) obj);
}
- @Override
- public int hashCode() {
+ @Override public int hashCode() {
return 1;
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java b/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java
index 102309b..ce61d21 100644
--- a/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java
+++ b/core/src/test/java/org/apache/calcite/test/MockRelOptPlanner.java
@@ -14,16 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.rex.RexExecutorImpl;
-import org.eigenbase.util.Pair;
-
-import net.hydromatic.optiq.Schemas;
+package org.apache.calcite.test;
+
+import org.apache.calcite.plan.AbstractRelOptPlanner;
+import org.apache.calcite.plan.RelOptCostImpl;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rex.RexExecutorImpl;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.util.Pair;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
/**
* MockRelOptPlanner is a mock implementation of the {@link RelOptPlanner}
@@ -185,8 +193,7 @@ public class MockRelOptPlanner extends AbstractRelOptPlanner {
return true;
}
- @Override
- public long getRelMetadataTimestamp(RelNode rel) {
+ @Override public long getRelMetadataTimestamp(RelNode rel) {
return metadataTimestamp;
}
@@ -197,6 +204,7 @@ public class MockRelOptPlanner extends AbstractRelOptPlanner {
//~ Inner Classes ----------------------------------------------------------
+ /** Mock call to a planner rule. */
private class MockRuleCall extends RelOptRuleCall {
/**
* Creates a MockRuleCall.
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java
index 5a077d2..02e7526 100644
--- a/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java
+++ b/core/src/test/java/org/apache/calcite/test/MockSqlOperatorTable.java
@@ -14,12 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
+package org.apache.calcite.test;
-import org.eigenbase.reltype.*;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.type.*;
-import org.eigenbase.sql.util.*;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.SqlFunction;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
+import org.apache.calcite.sql.util.ListSqlOperatorTable;
import com.google.common.collect.ImmutableList;
@@ -55,10 +63,10 @@ public class MockSqlOperatorTable extends ChainedSqlOperatorTable {
opTab.addOperator(new DedupFunction());
}
+ /** "RAMP" user-defined function. */
public static class RampFunction extends SqlFunction {
public RampFunction() {
- super(
- "RAMP",
+ super("RAMP",
SqlKind.OTHER_FUNCTION,
null,
null,
@@ -75,10 +83,10 @@ public class MockSqlOperatorTable extends ChainedSqlOperatorTable {
}
}
+ /** "DEDUP" user-defined function. */
public static class DedupFunction extends SqlFunction {
public DedupFunction() {
- super(
- "DEDUP",
+ super("DEDUP",
SqlKind.OTHER_FUNCTION,
null,
null,
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/ModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/ModelTest.java b/core/src/test/java/org/apache/calcite/test/ModelTest.java
index d1ca838..13d12fc 100644
--- a/core/src/test/java/org/apache/calcite/test/ModelTest.java
+++ b/core/src/test/java/org/apache/calcite/test/ModelTest.java
@@ -14,9 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.optiq.model.*;
+import org.apache.calcite.model.JsonColumn;
+import org.apache.calcite.model.JsonCustomSchema;
+import org.apache.calcite.model.JsonJdbcSchema;
+import org.apache.calcite.model.JsonLattice;
+import org.apache.calcite.model.JsonMapSchema;
+import org.apache.calcite.model.JsonRoot;
+import org.apache.calcite.model.JsonTable;
+import org.apache.calcite.model.JsonView;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -24,10 +31,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.io.IOException;
-import java.util.*;
+import java.util.List;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Unit test for data models.
@@ -113,18 +124,17 @@ public class ModelTest {
/** Reads a custom schema. */
@Test public void testCustomSchema() throws IOException {
final ObjectMapper mapper = mapper();
- JsonRoot root = mapper.readValue(
- "{\n"
- + " version: '1.0',\n"
- + " schemas: [\n"
- + " {\n"
- + " type: 'custom',\n"
- + " name: 'My Custom Schema',\n"
- + " factory: 'com.acme.MySchemaFactory',\n"
- + " operand: {a: 'foo', b: [1, 3.5] }\n"
- + " }\n"
- + " ]\n"
- + "}",
+ JsonRoot root = mapper.readValue("{\n"
+ + " version: '1.0',\n"
+ + " schemas: [\n"
+ + " {\n"
+ + " type: 'custom',\n"
+ + " name: 'My Custom Schema',\n"
+ + " factory: 'com.acme.MySchemaFactory',\n"
+ + " operand: {a: 'foo', b: [1, 3.5] }\n"
+ + " }\n"
+ + " ]\n"
+ + "}",
JsonRoot.class);
assertEquals("1.0", root.version);
assertEquals(1, root.schemas.size());
@@ -144,9 +154,8 @@ public class ModelTest {
* materialization. */
@Test public void testModelImmutableSchemaCannotContainMaterialization()
throws Exception {
- final OptiqAssert.AssertThat that =
- OptiqAssert.that().withModel(
- "{\n"
+ final CalciteAssert.AssertThat that =
+ CalciteAssert.that().withModel("{\n"
+ " version: '1.0',\n"
+ " defaultSchema: 'adhoc',\n"
+ " schemas: [\n"
@@ -172,61 +181,59 @@ public class ModelTest {
+ " }\n"
+ " ]\n"
+ "}");
- that.connectThrows(
- "Cannot define materialization; parent schema 'adhoc' is not a "
- + "SemiMutableSchema");
+ that.connectThrows("Cannot define materialization; parent schema 'adhoc' "
+ + "is not a SemiMutableSchema");
}
/** Tests a model containing a lattice and some views. */
@Test public void testReadLattice() throws IOException {
final ObjectMapper mapper = mapper();
- JsonRoot root = mapper.readValue(
- "{\n"
- + " version: '1.0',\n"
- + " schemas: [\n"
- + " {\n"
- + " name: 'FoodMart',\n"
- + " tables: [\n"
- + " {\n"
- + " name: 'time_by_day',\n"
- + " columns: [\n"
- + " {\n"
- + " name: 'time_id'\n"
- + " }\n"
- + " ]\n"
- + " },\n"
- + " {\n"
- + " name: 'sales_fact_1997',\n"
- + " columns: [\n"
- + " {\n"
- + " name: 'time_id'\n"
- + " }\n"
- + " ]\n"
- + " },\n"
- + " {\n"
- + " name: 'V',\n"
- + " type: 'view',\n"
- + " sql: 'values (1)'\n"
- + " },\n"
- + " {\n"
- + " name: 'V2',\n"
- + " type: 'view',\n"
- + " sql: [ 'values (1)', '(2)' ]\n"
- + " }\n"
- + " ],\n"
- + " lattices: [\n"
- + " {\n"
- + " name: 'SalesStar',\n"
- + " sql: 'select * from sales_fact_1997'\n"
- + " },\n"
- + " {\n"
- + " name: 'SalesStar2',\n"
- + " sql: [ 'select *', 'from sales_fact_1997' ]\n"
- + " }\n"
- + " ]\n"
- + " }\n"
- + " ]\n"
- + "}",
+ JsonRoot root = mapper.readValue("{\n"
+ + " version: '1.0',\n"
+ + " schemas: [\n"
+ + " {\n"
+ + " name: 'FoodMart',\n"
+ + " tables: [\n"
+ + " {\n"
+ + " name: 'time_by_day',\n"
+ + " columns: [\n"
+ + " {\n"
+ + " name: 'time_id'\n"
+ + " }\n"
+ + " ]\n"
+ + " },\n"
+ + " {\n"
+ + " name: 'sales_fact_1997',\n"
+ + " columns: [\n"
+ + " {\n"
+ + " name: 'time_id'\n"
+ + " }\n"
+ + " ]\n"
+ + " },\n"
+ + " {\n"
+ + " name: 'V',\n"
+ + " type: 'view',\n"
+ + " sql: 'values (1)'\n"
+ + " },\n"
+ + " {\n"
+ + " name: 'V2',\n"
+ + " type: 'view',\n"
+ + " sql: [ 'values (1)', '(2)' ]\n"
+ + " }\n"
+ + " ],\n"
+ + " lattices: [\n"
+ + " {\n"
+ + " name: 'SalesStar',\n"
+ + " sql: 'select * from sales_fact_1997'\n"
+ + " },\n"
+ + " {\n"
+ + " name: 'SalesStar2',\n"
+ + " sql: [ 'select *', 'from sales_fact_1997' ]\n"
+ + " }\n"
+ + " ]\n"
+ + " }\n"
+ + " ]\n"
+ + "}",
JsonRoot.class);
assertEquals("1.0", root.version);
assertEquals(1, root.schemas.size());
@@ -253,22 +260,21 @@ public class ModelTest {
/** Tests a model with bad multi-line SQL. */
@Test public void testReadBadMultiLineSql() throws IOException {
final ObjectMapper mapper = mapper();
- JsonRoot root = mapper.readValue(
- "{\n"
- + " version: '1.0',\n"
- + " schemas: [\n"
- + " {\n"
- + " name: 'FoodMart',\n"
- + " tables: [\n"
- + " {\n"
- + " name: 'V',\n"
- + " type: 'view',\n"
- + " sql: [ 'values (1)', 2 ]\n"
- + " }\n"
- + " ]\n"
- + " }\n"
- + " ]\n"
- + "}",
+ JsonRoot root = mapper.readValue("{\n"
+ + " version: '1.0',\n"
+ + " schemas: [\n"
+ + " {\n"
+ + " name: 'FoodMart',\n"
+ + " tables: [\n"
+ + " {\n"
+ + " name: 'V',\n"
+ + " type: 'view',\n"
+ + " sql: [ 'values (1)', 2 ]\n"
+ + " }\n"
+ + " ]\n"
+ + " }\n"
+ + " ]\n"
+ + "}",
JsonRoot.class);
assertEquals(1, root.schemas.size());
final JsonMapSchema schema = (JsonMapSchema) root.schemas.get(0);
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java b/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java
index c46ce79..426b531 100644
--- a/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java
+++ b/core/src/test/java/org/apache/calcite/test/MultiJdbcSchemaJoinTest.java
@@ -14,25 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
+package org.apache.calcite.test;
-import net.hydromatic.optiq.SchemaPlus;
-import net.hydromatic.optiq.impl.java.ReflectiveSchema;
-import net.hydromatic.optiq.impl.jdbc.JdbcSchema;
-import net.hydromatic.optiq.jdbc.OptiqConnection;
-import net.hydromatic.optiq.prepare.OptiqPrepareImpl;
+import org.apache.calcite.adapter.java.ReflectiveSchema;
+import org.apache.calcite.adapter.jdbc.JdbcSchema;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.prepare.CalcitePrepareImpl;
+import org.apache.calcite.schema.SchemaPlus;
import com.google.common.collect.Sets;
import org.junit.Test;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import javax.sql.DataSource;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
/** Test case for joining tables from two different JDBC databases. */
public class MultiJdbcSchemaJoinTest {
@@ -42,25 +47,24 @@ public class MultiJdbcSchemaJoinTest {
final String db1 = TempDb.INSTANCE.getUrl();
Connection c1 = DriverManager.getConnection(db1, "", "");
Statement stmt1 = c1.createStatement();
- stmt1.execute(
- "create table table1(id varchar(10) not null primary key, "
- + "field1 varchar(10))");
+ stmt1.execute("create table table1(id varchar(10) not null primary key, "
+ + "field1 varchar(10))");
stmt1.execute("insert into table1 values('a', 'aaaa')");
c1.close();
final String db2 = TempDb.INSTANCE.getUrl();
Connection c2 = DriverManager.getConnection(db2, "", "");
Statement stmt2 = c2.createStatement();
- stmt2.execute(
- "create table table2(id varchar(10) not null primary key, "
- + "field1 varchar(10))");
+ stmt2.execute("create table table2(id varchar(10) not null primary key, "
+ + "field1 varchar(10))");
stmt2.execute("insert into table2 values('a', 'aaaa')");
c2.close();
// Connect via calcite to these databases
Connection connection = DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection = connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
final DataSource ds1 =
JdbcSchema.dataSource(db1, "org.hsqldb.jdbcDriver", "", "");
rootSchema.add("DB1",
@@ -71,10 +75,9 @@ public class MultiJdbcSchemaJoinTest {
JdbcSchema.create(rootSchema, "DB2", ds2, null, null));
Statement stmt3 = connection.createStatement();
- ResultSet rs = stmt3.executeQuery(
- "select table1.id, table1.field1 "
- + "from db1.table1 join db2.table2 on table1.id = table2.id");
- assertThat(OptiqAssert.toString(rs), equalTo("ID=a; FIELD1=aaaa\n"));
+ ResultSet rs = stmt3.executeQuery("select table1.id, table1.field1 "
+ + "from db1.table1 join db2.table2 on table1.id = table2.id");
+ assertThat(CalciteAssert.toString(rs), equalTo("ID=a; FIELD1=aaaa\n"));
}
/** Makes sure that {@link #test} is re-entrant.
@@ -90,22 +93,22 @@ public class MultiJdbcSchemaJoinTest {
Statement stmt1 = c1.createStatement();
// This is a table we can join with the emps from the hr schema
stmt1.execute("create table table1(id integer not null primary key, "
- + "field1 varchar(10))");
+ + "field1 varchar(10))");
stmt1.execute("insert into table1 values(100, 'foo')");
stmt1.execute("insert into table1 values(200, 'bar')");
c1.close();
// Make a Calcite schema with both a jdbc schema and a non-jdbc schema
- Connection optiqConn = DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- optiqConn.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ Connection connection = DriverManager.getConnection("jdbc:calcite:");
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
rootSchema.add("DB",
JdbcSchema.create(rootSchema, "DB",
JdbcSchema.dataSource(db, "org.hsqldb.jdbcDriver", "", ""),
null, null));
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
- return optiqConn;
+ return connection;
}
@Test public void testJdbcWithEnumerableJoin() throws SQLException {
@@ -141,13 +144,13 @@ public class MultiJdbcSchemaJoinTest {
assertThat(runQuery(setup(), query), equalTo(expected));
}
- private Set<Integer> runQuery(Connection optiqConn, String query)
+ private Set<Integer> runQuery(Connection calciteConnection, String query)
throws SQLException {
// Print out the plan
- Statement stmt = optiqConn.createStatement();
+ Statement stmt = calciteConnection.createStatement();
try {
ResultSet rs;
- if (OptiqPrepareImpl.DEBUG) {
+ if (CalcitePrepareImpl.DEBUG) {
rs = stmt.executeQuery("explain plan for " + query);
rs.next();
System.out.println(rs.getString(1));
@@ -170,14 +173,14 @@ public class MultiJdbcSchemaJoinTest {
final String db = TempDb.INSTANCE.getUrl();
Connection c1 = DriverManager.getConnection(db, "", "");
Statement stmt1 = c1.createStatement();
- stmt1.execute(
- "create table table1(id varchar(10) not null primary key, "
- + "field1 varchar(10))");
+ stmt1.execute("create table table1(id varchar(10) not null primary key, "
+ + "field1 varchar(10))");
// Connect via calcite to these databases
Connection connection = DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection = connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
final DataSource ds =
JdbcSchema.dataSource(db, "org.hsqldb.jdbcDriver", "", "");
final SchemaPlus s =
@@ -196,9 +199,8 @@ public class MultiJdbcSchemaJoinTest {
equalTo("Table 'DB.TABLE2' not found"));
}
- stmt1.execute(
- "create table table2(id varchar(10) not null primary key, "
- + "field1 varchar(10))");
+ stmt1.execute("create table table2(id varchar(10) not null primary key, "
+ + "field1 varchar(10))");
stmt1.execute("insert into table2 values('a', 'aaaa')");
// fails, table not visible due to caching
@@ -213,7 +215,7 @@ public class MultiJdbcSchemaJoinTest {
// disable caching and table becomes visible
s.setCacheEnabled(false);
rs = stmt3.executeQuery("select * from db.table2");
- assertThat(OptiqAssert.toString(rs), equalTo("ID=a; FIELD1=aaaa\n"));
+ assertThat(CalciteAssert.toString(rs), equalTo("ID=a; FIELD1=aaaa\n"));
c1.close();
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
index bd9a91f..0ff6ebc 100644
--- a/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
+++ b/core/src/test/java/org/apache/calcite/test/ReflectiveSchemaTest.java
@@ -14,32 +14,48 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.test;
-
-import net.hydromatic.linq4j.*;
-import net.hydromatic.linq4j.expressions.*;
-import net.hydromatic.linq4j.expressions.Types;
-import net.hydromatic.linq4j.function.*;
-
-import net.hydromatic.optiq.SchemaPlus;
-import net.hydromatic.optiq.impl.*;
-import net.hydromatic.optiq.impl.java.*;
-import net.hydromatic.optiq.jdbc.OptiqConnection;
-
-import org.eigenbase.util14.DateTimeUtil;
+package org.apache.calcite.test;
+
+import org.apache.calcite.adapter.java.ReflectiveSchema;
+import org.apache.calcite.jdbc.CalciteConnection;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.linq4j.function.Predicate1;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.linq4j.tree.Primitive;
+import org.apache.calcite.linq4j.tree.Types;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.impl.AbstractSchema;
+import org.apache.calcite.schema.impl.TableMacroImpl;
+import org.apache.calcite.schema.impl.ViewTable;
+import org.apache.calcite.util.DateTimeUtil;
import org.junit.Ignore;
import org.junit.Test;
-import java.lang.reflect.*;
-import java.sql.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Statement;
-import java.util.*;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collections;
import java.util.Date;
+import java.util.List;
-import static net.hydromatic.optiq.test.JdbcTest.Employee;
+import static org.apache.calcite.test.JdbcTest.Employee;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link ReflectiveSchema}.
@@ -50,12 +66,13 @@ public class ReflectiveSchemaTest {
Linq4j.class, "asEnumerable", Object[].class);
/**
- * Test that uses a JDBC connection as a linq4j {@link net.hydromatic.linq4j.QueryProvider}.
+ * Test that uses a JDBC connection as a linq4j
+ * {@link org.apache.calcite.linq4j.QueryProvider}.
*
* @throws Exception on error
*/
@Test public void testQueryProvider() throws Exception {
- Connection connection = OptiqAssert.getConnection("hr", "foodmart");
+ Connection connection = CalciteAssert.getConnection("hr", "foodmart");
QueryProvider queryProvider = connection.unwrap(QueryProvider.class);
ParameterExpression e = Expressions.parameter(Employee.class, "e");
@@ -104,7 +121,7 @@ public class ReflectiveSchemaTest {
}
@Test public void testQueryProviderSingleColumn() throws Exception {
- Connection connection = OptiqAssert.getConnection("hr", "foodmart");
+ Connection connection = CalciteAssert.getConnection("hr", "foodmart");
QueryProvider queryProvider = connection.unwrap(QueryProvider.class);
ParameterExpression e = Expressions.parameter(Employee.class, "e");
@@ -129,16 +146,15 @@ public class ReflectiveSchemaTest {
/**
* Tests a relation that is accessed via method syntax.
- * The function returns a {@link net.hydromatic.linq4j.Queryable}.
+ * The function returns a {@link org.apache.calcite.linq4j.Queryable}.
*/
@Ignore
@Test public void testOperator() throws SQLException, ClassNotFoundException {
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
schema.add("GenerateStrings",
TableMacroImpl.create(JdbcTest.GENERATE_STRINGS_METHOD));
@@ -158,12 +174,11 @@ public class ReflectiveSchemaTest {
* Tests a view.
*/
@Test public void testView() throws SQLException, ClassNotFoundException {
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
schema.add("emps_view",
ViewTable.viewMacro(schema,
@@ -177,19 +192,18 @@ public class ReflectiveSchemaTest {
assertEquals(
"empid=100; deptno=10; name=Bill; salary=10000.0; commission=1000\n"
+ "empid=110; deptno=10; name=Theodore; salary=11500.0; commission=250\n",
- OptiqAssert.toString(resultSet));
+ CalciteAssert.toString(resultSet));
}
/**
* Tests a view with a path.
*/
@Test public void testViewPath() throws SQLException, ClassNotFoundException {
- Class.forName("net.hydromatic.optiq.jdbc.Driver");
Connection connection =
DriverManager.getConnection("jdbc:calcite:");
- OptiqConnection optiqConnection =
- connection.unwrap(OptiqConnection.class);
- SchemaPlus rootSchema = optiqConnection.getRootSchema();
+ CalciteConnection calciteConnection =
+ connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
// create a view s.emps based on hr.emps. uses explicit schema path "hr".
schema.add("emps",
@@ -232,18 +246,18 @@ public class ReflectiveSchemaTest {
/** Tests column based on java.sql.Date field. */
@Test public void testDateColumn() throws Exception {
- OptiqAssert.that()
+ CalciteAssert.that()
.with("s", new DateColumnSchema())
.query("select * from \"s\".\"emps\"")
- .returns(
- "hireDate=1970-01-01; empid=10; deptno=20; name=fred; salary=0.0; commission=null\n"
+ .returns(""
+ + "hireDate=1970-01-01; empid=10; deptno=20; name=fred; salary=0.0; commission=null\n"
+ "hireDate=1970-04-11; empid=10; deptno=20; name=bill; salary=0.0; commission=null\n");
}
/** Tests querying an object that has no public fields. */
@Test public void testNoPublicFields() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that().with("s", new CatchallSchema());
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().with("s", new CatchallSchema());
with.query("select 1 from \"s\".\"allPrivates\"")
.returns("EXPR$0=1\n");
with.query("select \"x\" from \"s\".\"allPrivates\"")
@@ -254,15 +268,14 @@ public class ReflectiveSchemaTest {
*
* @see CatchallSchema#everyTypes */
@Test public void testColumnTypes() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that().with("s", new CatchallSchema());
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().with("s", new CatchallSchema());
with.query("select \"primitiveBoolean\" from \"s\".\"everyTypes\"")
- .returns(
- "primitiveBoolean=false\n"
+ .returns("primitiveBoolean=false\n"
+ "primitiveBoolean=true\n");
with.query("select * from \"s\".\"everyTypes\"")
- .returns(
- "primitiveBoolean=false; primitiveByte=0; primitiveChar=\u0000; primitiveShort=0; primitiveInt=0; primitiveLong=0; primitiveFloat=0.0; primitiveDouble=0.0; wrapperBoolean=false; wrapperByte=0; wrapperCharacter=\u0000; wrapperShort=0; wrapperInteger=0; wrapperLong=0; wrapperFloat=0.0; wrapperDouble=0.0; sqlDate=1970-01-01; sqlTime=00:00:00; sqlTimestamp=1970-01-01 00:00:00; utilDate=1970-01-01 00:00:00; string=1\n"
+ .returns(""
+ + "primitiveBoolean=false; primitiveByte=0; primitiveChar=\u0000; primitiveShort=0; primitiveInt=0; primitiveLong=0; primitiveFloat=0.0; primitiveDouble=0.0; wrapperBoolean=false; wrapperByte=0; wrapperCharacter=\u0000; wrapperShort=0; wrapperInteger=0; wrapperLong=0; wrapperFloat=0.0; wrapperDouble=0.0; sqlDate=1970-01-01; sqlTime=00:00:00; sqlTimestamp=1970-01-01 00:00:00; utilDate=1970-01-01 00:00:00; string=1\n"
+ "primitiveBoolean=true; primitiveByte=127; primitiveChar=\uffff; primitiveShort=32767; primitiveInt=2147483647; primitiveLong=9223372036854775807; primitiveFloat=3.4028235E38; primitiveDouble=1.7976931348623157E308; wrapperBoolean=null; wrapperByte=null; wrapperCharacter=null; wrapperShort=null; wrapperInteger=null; wrapperLong=null; wrapperFloat=null; wrapperDouble=null; sqlDate=null; sqlTime=null; sqlTimestamp=null; utilDate=null; string=null\n");
}
@@ -270,8 +283,8 @@ public class ReflectiveSchemaTest {
*
* @see CatchallSchema#everyTypes */
@Test public void testAggregateFunctions() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that()
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that()
.with("s", new CatchallSchema());
checkAgg(with, "min");
checkAgg(with, "max");
@@ -279,33 +292,28 @@ public class ReflectiveSchemaTest {
checkAgg(with, "count");
}
- private void checkAgg(OptiqAssert.AssertThat with, String fn) {
+ private void checkAgg(CalciteAssert.AssertThat with, String fn) {
for (Field field
: fn.equals("avg") ? EveryType.numericFields() : EveryType.fields()) {
- with.query(
- "select " + fn + "(\"" + field.getName() + "\") as c\n"
+ with.query("select " + fn + "(\"" + field.getName() + "\") as c\n"
+ "from \"s\".\"everyTypes\"")
- .returns(OptiqAssert.<ResultSet, Void>constantNull());
+ .returns(CalciteAssert.<ResultSet, Void>constantNull());
}
}
@Test public void testJavaBoolean() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that().with("s", new CatchallSchema());
- with.query(
- "select count(*) as c from \"s\".\"everyTypes\"\n"
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().with("s", new CatchallSchema());
+ with.query("select count(*) as c from \"s\".\"everyTypes\"\n"
+ "where \"primitiveBoolean\"")
.returns("C=1\n");
- with.query(
- "select count(*) as c from \"s\".\"everyTypes\"\n"
+ with.query("select count(*) as c from \"s\".\"everyTypes\"\n"
+ "where \"wrapperBoolean\"")
.returns("C=0\n");
- with.query(
- "select count(*) as c from \"s\".\"everyTypes\"\n"
+ with.query("select count(*) as c from \"s\".\"everyTypes\"\n"
+ "where \"wrapperBoolean\" is not true")
.returns("C=2\n");
- with.query(
- "select count(*) as c from \"s\".\"everyTypes\"\n"
+ with.query("select count(*) as c from \"s\".\"everyTypes\"\n"
+ "where \"primitiveInt\" > 0")
.returns("C=1\n");
}
@@ -314,19 +322,17 @@ public class ReflectiveSchemaTest {
* <a href="https://issues.apache.org/jira/browse/CALCITE-119">CALCITE-119</a>,
* "Comparing a Java type long with a SQL type INTEGER gives wrong answer". */
@Test public void testCompareJavaAndSqlTypes() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that().with("s", new CatchallSchema());
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().with("s", new CatchallSchema());
// With CALCITE-119, returned 0 rows. The problem was that when comparing
// a Java type (long) and a SQL type (INTEGER), the SQL type was deemed
// "less restrictive". So, the long value got truncated to an int value.
- with.query(
- "select \"primitiveLong\" as c from \"s\".\"everyTypes\"\n"
+ with.query("select \"primitiveLong\" as c from \"s\".\"everyTypes\"\n"
+ "where \"primitiveLong\" > 0")
.returns("C=9223372036854775807\n");
// count(nullif(b, false)) counts how many times b is true
- with.query(
- "select count(\"primitiveBoolean\") as p,\n"
+ with.query("select count(\"primitiveBoolean\") as p,\n"
+ " count(\"wrapperBoolean\") as w,\n"
+ " count(nullif(\"primitiveShort\" >= 0, false)) as sp,\n"
+ " count(nullif(\"wrapperShort\" >= 0, false)) as sw,\n"
@@ -339,10 +345,9 @@ public class ReflectiveSchemaTest {
}
@Test public void testDivideWraperPrimitive() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that().with("s", new CatchallSchema());
- with.query(
- "select \"wrapperLong\" / \"primitiveLong\" as c\n"
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().with("s", new CatchallSchema());
+ with.query("select \"wrapperLong\" / \"primitiveLong\" as c\n"
+ " from \"s\".\"everyTypes\" where \"primitiveLong\" <> 0")
.planContains(
"final Long inp13_ = current.wrapperLong;")
@@ -352,35 +357,33 @@ public class ReflectiveSchemaTest {
}
@Test public void testDivideWraperWrapper() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that().with("s", new CatchallSchema());
- with.query(
- "select \"wrapperLong\" / \"wrapperLong\" as c\n"
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().with("s", new CatchallSchema());
+ with.query("select \"wrapperLong\" / \"wrapperLong\" as c\n"
+ " from \"s\".\"everyTypes\" where \"primitiveLong\" <> 0")
.planContains(
- "final Long inp13_ = ((net.hydromatic.optiq.test.ReflectiveSchemaTest.EveryType) inputEnumerator.current()).wrapperLong;")
+ "final Long inp13_ = ((org.apache.calcite.test.ReflectiveSchemaTest.EveryType) inputEnumerator.current()).wrapperLong;")
.planContains(
"return inp13_ == null ? (Long) null : Long.valueOf(inp13_.longValue() / inp13_.longValue());")
.returns("C=null\n");
}
@Test public void testDivideWraperWrapperMultipleTimes() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that().with("s", new CatchallSchema());
- with.query(
- "select \"wrapperLong\" / \"wrapperLong\"\n"
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that().with("s", new CatchallSchema());
+ with.query("select \"wrapperLong\" / \"wrapperLong\"\n"
+ "+ \"wrapperLong\" / \"wrapperLong\" as c\n"
+ " from \"s\".\"everyTypes\" where \"primitiveLong\" <> 0")
.planContains(
- "final Long inp13_ = ((net.hydromatic.optiq.test.ReflectiveSchemaTest.EveryType) inputEnumerator.current()).wrapperLong;")
+ "final Long inp13_ = ((org.apache.calcite.test.ReflectiveSchemaTest.EveryType) inputEnumerator.current()).wrapperLong;")
.planContains(
"return inp13_ == null ? (Long) null : Long.valueOf(inp13_.longValue() / inp13_.longValue() + inp13_.longValue() / inp13_.longValue());")
.returns("C=null\n");
}
@Test public void testOp() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that()
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that()
.with("s", new CatchallSchema());
checkOp(with, "+");
checkOp(with, "-");
@@ -388,28 +391,25 @@ public class ReflectiveSchemaTest {
checkOp(with, "/");
}
- private void checkOp(OptiqAssert.AssertThat with, String fn) {
+ private void checkOp(CalciteAssert.AssertThat with, String fn) {
for (Field field : EveryType.numericFields()) {
for (Field field2 : EveryType.numericFields()) {
final String name = "\"" + field.getName() + "\"";
final String name2 = "\"" + field2.getName() + "\"";
- with.query(
- "select " + name + "\n"
+ with.query("select " + name + "\n"
+ " " + fn + " " + name2 + " as c\n"
+ "from \"s\".\"everyTypes\"\n"
+ "where " + name + " <> 0")
- .returns(OptiqAssert.<ResultSet, Void>constantNull());
+ .returns(CalciteAssert.<ResultSet, Void>constantNull());
}
}
}
@Test public void testCastFromString() {
- OptiqAssert.that()
+ CalciteAssert.that()
.with("s", new CatchallSchema())
- .query(
- "select cast(\"string\" as int) as c from \"s\".\"everyTypes\"")
- .returns(
- "C=1\n"
+ .query("select cast(\"string\" as int) as c from \"s\".\"everyTypes\"")
+ .returns("C=1\n"
+ "C=null\n");
}
@@ -429,7 +429,7 @@ public class ReflectiveSchemaTest {
*
* @see CatchallSchema#badTypes */
@Test public void testTableFieldHasBadType() throws Exception {
- OptiqAssert.that()
+ CalciteAssert.that()
.with("s", new CatchallSchema())
.query("select * from \"s\".\"badTypes\"")
.returns("integer=0; bitSet={}\n");
@@ -441,8 +441,8 @@ public class ReflectiveSchemaTest {
* @see CatchallSchema#enumerable
* @see CatchallSchema#list */
@Test public void testSchemaFieldHasBadType() throws Exception {
- final OptiqAssert.AssertThat with =
- OptiqAssert.that()
+ final CalciteAssert.AssertThat with =
+ CalciteAssert.that()
.with("s", new CatchallSchema());
// BitSet is not a valid relation type. It's as if "bitSet" field does
// not exist.
@@ -450,15 +450,13 @@ public class ReflectiveSchemaTest {
.throws_("Table 's.bitSet' not found");
// Enumerable field returns 3 records with 0 fields
with.query("select * from \"s\".\"enumerable\"")
- .returns(
- "\n"
+ .returns("\n"
+ "\n"
+ "\n"
+ "\n");
// List is implicitly converted to Enumerable
with.query("select * from \"s\".\"list\"")
- .returns(
- "\n"
+ .returns("\n"
+ "\n"
+ "\n"
+ "\n");
@@ -467,12 +465,11 @@ public class ReflectiveSchemaTest {
/** Test case for a bug where a Java string 'Abc' compared to a char 'Ab'
* would be truncated to the char precision and falsely match. */
@Test public void testPrefix() throws Exception {
- OptiqAssert.that()
+ CalciteAssert.that()
.with("s", new CatchallSchema())
.query(
"select * from \"s\".\"prefixEmps\" where \"name\" in ('Ab', 'Abd')")
- .returns(
- "empid=2; deptno=10; name=Ab; salary=0.0; commission=null\n"
+ .returns("empid=2; deptno=10; name=Ab; salary=0.0; commission=null\n"
+ "empid=4; deptno=10; name=Abd; salary=0.0; commission=null\n");
}
@@ -481,27 +478,24 @@ public class ReflectiveSchemaTest {
* should be expanded. */
@Ignore
@Test public void testTableMacroIsView() throws Exception {
- OptiqAssert.that()
+ CalciteAssert.that()
.with("s", new JdbcTest.HrSchema())
- .query(
- "select * from table(\"s\".\"view\"('abc'))")
- .returns(
- "empid=2; deptno=10; name=Ab; salary=0.0; commission=null\n"
+ .query("select * from table(\"s\".\"view\"('abc'))")
+ .returns("empid=2; deptno=10; name=Ab; salary=0.0; commission=null\n"
+ "empid=4; deptno=10; name=Abd; salary=0.0; commission=null\n");
}
/** Finds a table-macro using reflection. */
@Ignore
@Test public void testTableMacro() throws Exception {
- OptiqAssert.that()
+ CalciteAssert.that()
.with("s", new JdbcTest.HrSchema())
- .query(
- "select * from table(\"s\".\"foo\"(3))")
- .returns(
- "empid=2; deptno=10; name=Ab; salary=0.0; commission=null\n"
+ .query("select * from table(\"s\".\"foo\"(3))")
+ .returns("empid=2; deptno=10; name=Ab; salary=0.0; commission=null\n"
+ "empid=4; deptno=10; name=Abd; salary=0.0; commission=null\n");
}
+ /** Extension to {@link Employee} with a {@code hireDate} column. */
public static class EmployeeWithHireDate extends Employee {
public final java.sql.Date hireDate;
@@ -513,6 +507,7 @@ public class ReflectiveSchemaTest {
}
}
+ /** Record that has a field of every interesting type. */
public static class EveryType {
public final boolean primitiveBoolean;
public final byte primitiveByte;
@@ -645,6 +640,7 @@ public class ReflectiveSchemaTest {
};
}
+ /** Schema that contains a table with a date column. */
public static class DateColumnSchema {
public final EmployeeWithHireDate[] emps = {
new EmployeeWithHireDate(
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index 32e6dda..41caea0 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -14,14 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.eigenbase.test;
-
-import java.lang.reflect.Method;
-import java.util.*;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.metadata.*;
-import org.eigenbase.relopt.*;
+package org.apache.calcite.test;
+
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.metadata.CachingRelMetadataProvider;
+import org.apache.calcite.rel.metadata.ChainedRelMetadataProvider;
+import org.apache.calcite.rel.metadata.DefaultRelMetadataProvider;
+import org.apache.calcite.rel.metadata.Metadata;
+import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelColumnOrigin;
+import org.apache.calcite.rel.metadata.RelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -31,15 +39,24 @@ import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
/**
- * Unit test for {@link DefaultRelMetadataProvider}. See {@link
- * SqlToRelTestBase} class comments for details on the schema used. Note that no
- * optimizer rules are fired on the translation of the SQL into relational
- * algebra (e.g. join conditions in the WHERE clause will look like filters), so
- * it's necessary to phrase the SQL carefully.
+ * Unit test for {@link DefaultRelMetadataProvider}. See
+ * {@link SqlToRelTestBase} class comments for details on the schema used. Note
+ * that no optimizer rules are fired on the translation of the SQL into
+ * relational algebra (e.g. join conditions in the WHERE clause will look like
+ * filters), so it's necessary to phrase the SQL carefully.
*/
public class RelMetadataTest extends SqlToRelTestBase {
//~ Static fields/initializers ---------------------------------------------
@@ -113,17 +130,17 @@ public class RelMetadataTest extends SqlToRelTestBase {
@Ignore
@Test public void testPercentageOriginalRowsTwoFilters() {
- checkPercentageOriginalRows(
- "select * from (select * from dept where name='X')"
- + " where deptno = 20",
+ checkPercentageOriginalRows("select * from (\n"
+ + " select * from dept where name='X')\n"
+ + "where deptno = 20",
DEFAULT_EQUAL_SELECTIVITY_SQUARED);
}
@Ignore
@Test public void testPercentageOriginalRowsRedundantFilter() {
- checkPercentageOriginalRows(
- "select * from (select * from dept where deptno=20)"
- + " where deptno = 20",
+ checkPercentageOriginalRows("select * from (\n"
+ + " select * from dept where deptno=20)\n"
+ + "where deptno = 20",
DEFAULT_EQUAL_SELECTIVITY);
}
@@ -135,10 +152,10 @@ public class RelMetadataTest extends SqlToRelTestBase {
@Ignore
@Test public void testPercentageOriginalRowsJoinTwoFilters() {
- checkPercentageOriginalRows(
- "select * from (select * from emp where deptno=10) e"
- + " inner join (select * from dept where deptno=10) d"
- + " on e.deptno=d.deptno",
+ checkPercentageOriginalRows("select * from (\n"
+ + " select * from emp where deptno=10) e\n"
+ + "inner join (select * from dept where deptno=10) d\n"
+ + "on e.deptno=d.deptno",
DEFAULT_EQUAL_SELECTIVITY_SQUARED);
}
@@ -152,7 +169,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
@Test public void testPercentageOriginalRowsUnionLittleFilter() {
checkPercentageOriginalRows(
"select name from dept where deptno=20"
- + " union all select ename from emp",
+ + " union all select ename from emp",
((DEPT_SIZE * DEFAULT_EQUAL_SELECTIVITY) + EMP_SIZE)
/ (DEPT_SIZE + EMP_SIZE));
}
@@ -161,7 +178,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
@Test public void testPercentageOriginalRowsUnionBigFilter() {
checkPercentageOriginalRows(
"select name from dept"
- + " union all select ename from emp where deptno=20",
+ + " union all select ename from emp where deptno=20",
((EMP_SIZE * DEFAULT_EQUAL_SELECTIVITY) + DEPT_SIZE)
/ (DEPT_SIZE + EMP_SIZE));
}
@@ -306,7 +323,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
@Test public void testColumnOriginsJoinOuter() {
checkSingleColumnOrigin(
"select name as dname from emp left outer join dept"
- + " on emp.deptno = dept.deptno",
+ + " on emp.deptno = dept.deptno",
"DEPT",
"NAME",
true);
@@ -315,7 +332,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
@Test public void testColumnOriginsJoinFullOuter() {
checkSingleColumnOrigin(
"select name as dname from emp full outer join dept"
- + " on emp.deptno = dept.deptno",
+ + " on emp.deptno = dept.deptno",
"DEPT",
"NAME",
true);
@@ -482,24 +499,22 @@ public class RelMetadataTest extends SqlToRelTestBase {
@Test public void testSelectivitySort() {
RelNode rel =
- convertSql(
- "select * from emp where deptno = 10"
+ convertSql("select * from emp where deptno = 10"
+ "order by ename");
checkRelSelectivity(rel, DEFAULT_EQUAL_SELECTIVITY);
}
@Test public void testSelectivityUnion() {
RelNode rel =
- convertSql(
- "select * from (select * from emp union all select * from emp) "
- + "where deptno = 10");
+ convertSql("select * from (\n"
+ + " select * from emp union all select * from emp) "
+ + "where deptno = 10");
checkRelSelectivity(rel, DEFAULT_EQUAL_SELECTIVITY);
}
@Test public void testSelectivityAgg() {
RelNode rel =
- convertSql(
- "select deptno, count(*) from emp where deptno > 10 "
+ convertSql("select deptno, count(*) from emp where deptno > 10 "
+ "group by deptno having count(*) = 0");
checkRelSelectivity(
rel,
@@ -510,8 +525,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
* argument. */
@Test public void testSelectivityAggCached() {
RelNode rel =
- convertSql(
- "select deptno, count(*) from emp where deptno > 10 "
+ convertSql("select deptno, count(*) from emp where deptno > 10 "
+ "group by deptno having count(*) = 0");
rel.getCluster().setMetadataProvider(
new CachingRelMetadataProvider(
@@ -537,25 +551,24 @@ public class RelMetadataTest extends SqlToRelTestBase {
ColTypeImpl.THREAD_LIST.set(buf);
RelNode rel =
- convertSql(
- "select deptno, count(*) from emp where deptno > 10 "
- + "group by deptno having count(*) = 0");
+ convertSql("select deptno, count(*) from emp where deptno > 10 "
+ + "group by deptno having count(*) = 0");
rel.getCluster().setMetadataProvider(
ChainedRelMetadataProvider.of(
ImmutableList.of(
ColTypeImpl.SOURCE, rel.getCluster().getMetadataProvider())));
// Top node is a filter. Its metadata uses getColType(RelNode, int).
- assertThat(rel, instanceOf(FilterRel.class));
+ assertThat(rel, instanceOf(LogicalFilter.class));
assertThat(rel.metadata(ColType.class).getColType(0),
equalTo("DEPTNO-rel"));
assertThat(rel.metadata(ColType.class).getColType(1),
equalTo("EXPR$1-rel"));
// Next node is an aggregate. Its metadata uses
- // getColType(AggregateRel, int).
+ // getColType(LogicalAggregate, int).
final RelNode input = rel.getInput(0);
- assertThat(input, instanceOf(AggregateRel.class));
+ assertThat(input, instanceOf(LogicalAggregate.class));
assertThat(input.metadata(ColType.class).getColType(0),
equalTo("DEPTNO-agg"));
@@ -605,7 +618,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
String getColType(int column);
}
- /** A provider for {@link org.eigenbase.test.RelMetadataTest.ColType} via
+ /** A provider for {@link org.apache.calcite.test.RelMetadataTest.ColType} via
* reflection. */
public static class ColTypeImpl {
static final ThreadLocal<List<String>> THREAD_LIST =
@@ -624,9 +637,10 @@ public class RelMetadataTest extends SqlToRelTestBase {
METHOD, new ColTypeImpl());
/** Implementation of {@link ColType#getColType(int)} for
- * {@link AggregateRel}, called via reflection. */
+ * {@link org.apache.calcite.rel.logical.LogicalAggregate}, called via
+ * reflection. */
@SuppressWarnings("UnusedDeclaration")
- public String getColType(AggregateRelBase rel, int column) {
+ public String getColType(Aggregate rel, int column) {
final String name =
rel.getRowType().getFieldList().get(column).getName() + "-agg";
THREAD_LIST.get().add(name);