Use real properties, not their names, in tests
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/aae56a58 Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/aae56a58 Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/aae56a58 Branch: refs/heads/master Commit: aae56a58af2a11cf63d26d8b1f8dfcf256aaa48f Parents: 44f7338 Author: Julian Hyde <[email protected]> Authored: Mon Feb 5 22:17:45 2018 -0800 Committer: Julian Hyde <[email protected]> Committed: Fri Jun 29 01:23:21 2018 -0700 ---------------------------------------------------------------------- .../calcite/sql/test/SqlOperatorBaseTest.java | 3 +- .../apache/calcite/sql/test/SqlTesterImpl.java | 14 ++++++--- .../org/apache/calcite/test/CalciteAssert.java | 31 +++++++++++++++----- .../java/org/apache/calcite/test/JdbcTest.java | 25 ++++++++-------- .../org/apache/calcite/test/QuidemTest.java | 3 +- .../apache/calcite/test/TableFunctionTest.java | 12 ++++++++ .../enumerable/EnumerableCorrelateTest.java | 6 ++-- .../org/apache/calcite/test/DruidAdapterIT.java | 26 ++++++++-------- .../calcite/adapter/os/OsAdapterTest.java | 5 ++-- 9 files changed, 82 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java index f2109f4..0af5a95 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java +++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java @@ -17,6 +17,7 @@ package org.apache.calcite.sql.test; import org.apache.calcite.avatica.util.DateTimeUtils; +import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.linq4j.Linq4j; import org.apache.calcite.plan.Strong; import org.apache.calcite.rel.type.RelDataType; @@ -312,7 +313,7 @@ public abstract class SqlOperatorBaseTest { CalciteAssert.EMPTY_CONNECTION_FACTORY .with(new CalciteAssert .AddSchemaSpecPostProcessor(CalciteAssert.SchemaSpec.HR)) - .with("fun", "oracle")); + .with(CalciteConnectionProperty.FUN, "oracle")); } protected SqlTester oracleTester(SqlConformance conformance) { http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java b/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java index c96c4e8..c4eba51 100644 --- a/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java +++ b/core/src/test/java/org/apache/calcite/sql/test/SqlTesterImpl.java @@ -18,6 +18,7 @@ package org.apache.calcite.sql.test; import org.apache.calcite.avatica.util.Casing; import org.apache.calcite.avatica.util.Quoting; +import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.config.Lex; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; @@ -293,10 +294,15 @@ public class SqlTesterImpl implements SqlTester, AutoCloseable { if (conformance == null) { conformance = SqlConformanceEnum.DEFAULT; } - return with("conformance", conformance) - .withConnectionFactory( - CalciteAssert.EMPTY_CONNECTION_FACTORY - .with("conformance", conformance)); + final SqlTesterImpl tester = with("conformance", conformance); + if (conformance instanceof SqlConformanceEnum) { + return tester + .withConnectionFactory( + CalciteAssert.EMPTY_CONNECTION_FACTORY + .with(CalciteConnectionProperty.CONFORMANCE, conformance)); + } else { + return tester; + } } public SqlTester withOperatorTable(SqlOperatorTable operatorTable) { http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/core/src/test/java/org/apache/calcite/test/CalciteAssert.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java index 7078f8d..0749de5 100644 --- a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java +++ b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java @@ -20,6 +20,7 @@ import org.apache.calcite.DataContext; import org.apache.calcite.adapter.clone.CloneSchema; import org.apache.calcite.adapter.java.ReflectiveSchema; import org.apache.calcite.adapter.jdbc.JdbcSchema; +import org.apache.calcite.avatica.ConnectionProperty; import org.apache.calcite.avatica.util.DateTimeUtils; import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.config.Lex; @@ -881,10 +882,6 @@ public class CalciteAssert { } public AssertThat with(Config config) { - if (config == Config.SPARK) { - return with("spark", "true"); - } - switch (config) { case EMPTY: return EMPTY; @@ -895,7 +892,7 @@ public class CalciteAssert { return with(SchemaSpec.HR, SchemaSpec.REFLECTIVE_FOODMART); case GEO: return with(SchemaSpec.GEO) - .with(CalciteConnectionProperty.CONFORMANCE.camelName(), + .with(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT); case LINGUAL: return with(SchemaSpec.LINGUAL); @@ -909,6 +906,8 @@ public class CalciteAssert { return with(SchemaSpec.JDBC_SCOTT); case SCOTT: return with(SchemaSpec.SCOTT); + case SPARK: + return with(CalciteConnectionProperty.SPARK, true); default: throw Util.unexpected(config); } @@ -940,9 +939,16 @@ public class CalciteAssert { return new AssertThat(connectionFactory.with(property, value)); } + public AssertThat with(ConnectionProperty property, Object value) { + if (!property.type().valid(value, property.valueClass())) { + throw new IllegalArgumentException(); + } + return new AssertThat(connectionFactory.with(property, value)); + } + /** Sets Lex property **/ public AssertThat with(Lex lex) { - return with(CalciteConnectionProperty.LEX.name(), lex.toString()); + return with(CalciteConnectionProperty.LEX, lex); } /** Sets the default schema to a given schema. */ @@ -956,7 +962,7 @@ public class CalciteAssert { } public final AssertThat withModel(String model) { - return with("model", "inline:" + model); + return with(CalciteConnectionProperty.MODEL, "inline:" + model); } public final AssertThat withMaterializations(String model, @@ -1114,6 +1120,10 @@ public class CalciteAssert { throw new UnsupportedOperationException(); } + public ConnectionFactory with(ConnectionProperty property, Object value) { + throw new UnsupportedOperationException(); + } + public ConnectionFactory with(ConnectionPostProcessor postProcessor) { throw new UnsupportedOperationException(); } @@ -1233,6 +1243,13 @@ public class CalciteAssert { postProcessors); } + public ConnectionFactory with(ConnectionProperty property, Object value) { + if (!property.type().valid(value, property.valueClass())) { + throw new IllegalArgumentException(); + } + return with(property.camelName(), value.toString()); + } + public ConnectionFactory with( ConnectionPostProcessor postProcessor) { ImmutableList.Builder<ConnectionPostProcessor> builder = http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/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 fcdc0a6..b68f2a8 100644 --- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java +++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java @@ -28,7 +28,10 @@ import org.apache.calcite.avatica.AvaticaStatement; import org.apache.calcite.avatica.Handler; import org.apache.calcite.avatica.HandlerImpl; import org.apache.calcite.avatica.Meta; +import org.apache.calcite.avatica.util.Casing; +import org.apache.calcite.avatica.util.Quoting; import org.apache.calcite.config.CalciteConnectionConfig; +import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.config.Lex; import org.apache.calcite.config.NullCollation; import org.apache.calcite.jdbc.CalciteConnection; @@ -3032,7 +3035,7 @@ public class JdbcTest { }; final CalciteAssert.AssertThat with = CalciteAssert.that() .with(CalciteAssert.Config.FOODMART_CLONE) - .with("defaultNullCollation", nullCollation.name()); + .with(CalciteConnectionProperty.DEFAULT_NULL_COLLATION, nullCollation); final String sql = "select \"store_id\", \"grocery_sqft\" from \"store\"\n" + "where \"store_id\" < 3 order by 2 " + (desc ? " DESC" : ""); @@ -4578,7 +4581,7 @@ public class JdbcTest { + " select 1 from \"hr\".\"depts\"\n" + " where \"emps\".\"deptno\"=\"depts\".\"deptno\")"; CalciteAssert.hr() - .with("forceDecorrelate", false) + .with(CalciteConnectionProperty.FORCE_DECORRELATE, false) .query(sql) .explainContains(plan) .returnsUnordered( @@ -5648,7 +5651,7 @@ public class JdbcTest { * is executed. */ @Test public void testCurrentTimestamp() throws Exception { CalciteAssert.that() - .with("timezone", "GMT+1:00") + .with(CalciteConnectionProperty.TIME_ZONE, "GMT+1:00") .doWithConnection( new Function<CalciteConnection, Void>() { public Void apply(CalciteConnection connection) { @@ -5688,9 +5691,7 @@ public class JdbcTest { /** Test for timestamps and time zones, based on pgsql TimezoneTest. */ @Test public void testGetTimestamp() throws Exception { CalciteAssert.that() - .with("timezone", "GMT+1:00") - // Workaround, until [CALCITE-1667] is fixed in Avatica - .with("TIME_ZONE", "GMT+1:00") + .with(CalciteConnectionProperty.TIME_ZONE, "GMT+1:00") .doWithConnection( new Function<CalciteConnection, Void>() { public Void apply(CalciteConnection connection) { @@ -6110,10 +6111,10 @@ public class JdbcTest { @Test public void testLexOracleAsJava() throws Exception { CalciteAssert.that() .with(Lex.ORACLE) - .with("quoting", "BACK_TICK") - .with("unquotedCasing", "UNCHANGED") - .with("quotedCasing", "UNCHANGED") - .with("caseSensitive", "TRUE") + .with(CalciteConnectionProperty.QUOTING, Quoting.BACK_TICK) + .with(CalciteConnectionProperty.UNQUOTED_CASING, Casing.UNCHANGED) + .with(CalciteConnectionProperty.QUOTED_CASING, Casing.UNCHANGED) + .with(CalciteConnectionProperty.CASE_SENSITIVE, true) .doWithConnection( new Function<CalciteConnection, Void>() { public Void apply(CalciteConnection connection) { @@ -6211,7 +6212,7 @@ public class JdbcTest { @Test public void testFunOracle() { CalciteAssert.that(CalciteAssert.Config.REGULAR) - .with("fun", "oracle") + .with(CalciteConnectionProperty.FUN, "oracle") .query("select nvl(\"commission\", -99) as c from \"hr\".\"emps\"") .returnsUnordered("C=-99", "C=1000", @@ -6232,7 +6233,7 @@ public class JdbcTest { + " ST_PointFromText('POINT(-71.0642.28)') as c\n" + "from \"hr\".\"emps\""; CalciteAssert.that(CalciteAssert.Config.REGULAR) - .with("fun", "spatial") + .with(CalciteConnectionProperty.FUN, "spatial") .query(sql) .returnsUnordered("C={\"x\":-71.0642,\"y\":0.28}"); http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/core/src/test/java/org/apache/calcite/test/QuidemTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/QuidemTest.java b/core/src/test/java/org/apache/calcite/test/QuidemTest.java index 05c7a29..20e47b3 100644 --- a/core/src/test/java/org/apache/calcite/test/QuidemTest.java +++ b/core/src/test/java/org/apache/calcite/test/QuidemTest.java @@ -18,6 +18,7 @@ package org.apache.calcite.test; import org.apache.calcite.adapter.java.ReflectiveSchema; import org.apache.calcite.avatica.AvaticaUtils; +import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.jdbc.CalciteConnection; import org.apache.calcite.prepare.Prepare; import org.apache.calcite.rel.type.RelDataType; @@ -271,7 +272,7 @@ public abstract class QuidemTest { .connect(); case "blank": return CalciteAssert.that() - .with("parserFactory", + .with(CalciteConnectionProperty.PARSER_FACTORY, "org.apache.calcite.sql.parser.parserextensiontesting" + ".ExtensionSqlParserImpl#FACTORY") .with(CalciteAssert.SchemaSpec.BLANK) http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java b/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java index fefd7d2..336fb54 100644 --- a/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java +++ b/core/src/test/java/org/apache/calcite/test/TableFunctionTest.java @@ -16,12 +16,14 @@ */ package org.apache.calcite.test; +import org.apache.calcite.config.CalciteConnectionProperty; import org.apache.calcite.jdbc.CalciteConnection; import org.apache.calcite.schema.ScannableTable; import org.apache.calcite.schema.SchemaPlus; import org.apache.calcite.schema.TableFunction; import org.apache.calcite.schema.impl.AbstractSchema; import org.apache.calcite.schema.impl.TableFunctionImpl; +import org.apache.calcite.sql.validate.SqlConformanceEnum; import org.apache.calcite.util.Smalls; import com.google.common.base.Function; @@ -409,6 +411,16 @@ public class TableFunctionTest { + "from table(\"s\".\"fibonacci2\"(20))"; with().query(q).returnsUnordered("C=7"); } + + @Test public void testCrossApply() { + final String q = "select *\n" + + "from (values 2, 5) as t (c)\n" + + "cross apply table(\"s\".\"fibonacci2\"(c))"; + with() + .with(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT) + .query(q) + .returnsUnordered("C=7"); + } } // End TableFunctionTest.java http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java index 8efec08..08d5ead 100644 --- a/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java +++ b/core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCorrelateTest.java @@ -17,6 +17,8 @@ package org.apache.calcite.test.enumerable; import org.apache.calcite.adapter.java.ReflectiveSchema; +import org.apache.calcite.config.CalciteConnectionProperty; +import org.apache.calcite.config.Lex; import org.apache.calcite.test.CalciteAssert; import org.apache.calcite.test.JdbcTest; @@ -64,8 +66,8 @@ public class EnumerableCorrelateTest { private CalciteAssert.AssertThat tester(boolean forceDecorrelate, Object schema) { return CalciteAssert.that() - .with("lex", "JAVA") - .with("forceDecorrelate", Boolean.toString(forceDecorrelate)) + .with(CalciteConnectionProperty.LEX, Lex.JAVA) + .with(CalciteConnectionProperty.FORCE_DECORRELATE, forceDecorrelate) .withSchema("s", new ReflectiveSchema(schema)); } } http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java ---------------------------------------------------------------------- diff --git a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java index 36940b8..817142f 100644 --- a/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java +++ b/druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java @@ -144,10 +144,10 @@ public class DruidAdapterIT { private CalciteAssert.AssertQuery approxQuery(URL url, String sql) { return CalciteAssert.that() .enable(enabled()) - .with(ImmutableMap.of("model", url.getPath())) - .with(CalciteConnectionProperty.APPROXIMATE_DISTINCT_COUNT.camelName(), true) - .with(CalciteConnectionProperty.APPROXIMATE_TOP_N.camelName(), true) - .with(CalciteConnectionProperty.APPROXIMATE_DECIMAL.camelName(), true) + .with(CalciteConnectionProperty.MODEL, url.getPath()) + .with(CalciteConnectionProperty.APPROXIMATE_DISTINCT_COUNT, true) + .with(CalciteConnectionProperty.APPROXIMATE_TOP_N, true) + .with(CalciteConnectionProperty.APPROXIMATE_DECIMAL, true) .query(sql); } @@ -155,7 +155,7 @@ public class DruidAdapterIT { private CalciteAssert.AssertQuery sql(String sql, URL url) { return CalciteAssert.that() .enable(enabled()) - .with(ImmutableMap.of("model", url.getPath())) + .with(CalciteConnectionProperty.MODEL, url.getPath()) .query(sql); } @@ -677,8 +677,8 @@ public class DruidAdapterIT { + "aggs=[[SUM($1)]], sort0=[1], dir0=[DESC], fetch=[3])"; CalciteAssert.that() .enable(enabled()) - .with(ImmutableMap.of("model", FOODMART.getPath())) - .with(CalciteConnectionProperty.APPROXIMATE_TOP_N.name(), approx) + .with(CalciteConnectionProperty.MODEL, FOODMART.getPath()) + .with(CalciteConnectionProperty.APPROXIMATE_TOP_N, approx) .query(sql) .runs() .returnsOrdered("brand_name=Hermanos; S=8469", @@ -2992,8 +2992,8 @@ public class DruidAdapterIT { String expectedDruidQuery) { CalciteAssert.that() .enable(enabled()) - .with(ImmutableMap.of("model", FOODMART.getPath())) - .with(CalciteConnectionProperty.APPROXIMATE_DISTINCT_COUNT.camelName(), approx) + .with(CalciteConnectionProperty.MODEL, FOODMART.getPath()) + .with(CalciteConnectionProperty.APPROXIMATE_DISTINCT_COUNT, approx) .query(sql) .runs() .explainContains(expectedExplain) @@ -3293,8 +3293,8 @@ public class DruidAdapterIT { CalciteAssert.that() .enable(enabled()) - .with(ImmutableMap.of("model", WIKI_AUTO2.getPath())) - .with(CalciteConnectionProperty.TIME_ZONE.camelName(), "Asia/Kolkata") + .with(CalciteConnectionProperty.MODEL, WIKI_AUTO2.getPath()) + .with(CalciteConnectionProperty.TIME_ZONE, "Asia/Kolkata") .query(sql) .runs() .queryContains(druidChecker(druidQueryPart1, druidQueryPart2)) @@ -3341,8 +3341,8 @@ public class DruidAdapterIT { CalciteAssert.that() .enable(enabled()) - .with(ImmutableMap.of("model", WIKI_AUTO2.getPath())) - .with(CalciteConnectionProperty.TIME_ZONE.camelName(), "Asia/Kolkata") + .with(CalciteConnectionProperty.MODEL, WIKI_AUTO2.getPath()) + .with(CalciteConnectionProperty.TIME_ZONE, "Asia/Kolkata") .query(sql) .runs() .queryContains(druidChecker(druidQueryPart1, druidQueryPart2)) http://git-wip-us.apache.org/repos/asf/calcite/blob/aae56a58/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java ---------------------------------------------------------------------- diff --git a/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java b/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java index 1216520..50e80b7 100644 --- a/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java +++ b/plus/src/test/java/org/apache/calcite/adapter/os/OsAdapterTest.java @@ -378,9 +378,8 @@ public class OsAdapterTest { static CalciteAssert.AssertQuery sql(String sql) { return CalciteAssert.that() .withModel(SqlShell.MODEL) - .with(CalciteConnectionProperty.LEX.camelName(), Lex.JAVA) - .with(CalciteConnectionProperty.CONFORMANCE.camelName(), - SqlConformanceEnum.LENIENT) + .with(CalciteConnectionProperty.LEX, Lex.JAVA) + .with(CalciteConnectionProperty.CONFORMANCE, SqlConformanceEnum.LENIENT) .query(sql); } }
