From ac6c677adb0fdfc24f495199c457d25b55abdcd1 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 9 Apr 2024 08:29:48 +0000 Subject: [PATCH 01/24] Quidem test runner * adds a test scoped jdbc driver for `druidtest:///` backed `DruidAvaticaTestDriver` * `DecoupledTestConfig` can switch test validation to be backed by a quidem execution * this enables plan/etc validation for those cases as well * `DruidQuidemTestBase` can be used to create module level set of quidem tests * added quidem commands: `!nativePlan`, `!logicalPlan`, `!druidPlan`, `!convertedPlan` --- .gitignore | 1 + benchmarks/pom.xml | 25 ++ .../META-INF/services/java.sql.Driver | 2 + pom.xml | 4 +- quidem | 43 ++ sql/pom.xml | 16 + .../apache/druid/sql/avatica/DruidMeta.java | 2 +- .../sql/calcite/planner/CalcitePlanner.java | 2 + .../sql/calcite/planner/QueryHandler.java | 4 + .../druid/quidem/DruidAvaticaDriverTest.java | 56 +++ .../druid/quidem/DruidAvaticaTestDriver.java | 383 ++++++++++++++++++ .../apache/druid/quidem/DruidQTestInfo.java | 39 ++ .../quidem/DruidQuidemCommandHandler.java | 204 ++++++++++ .../quidem/DruidQuidemConnectionFactory.java | 52 +++ .../druid/quidem/DruidQuidemTestBase.java | 207 ++++++++++ .../druid/quidem/MapToInterfaceHandler.java | 75 ++++ .../apache/druid/quidem/ProjectPathUtils.java | 49 +++ .../apache/druid/quidem/SqlQuidemTest.java | 36 ++ .../druid/sql/calcite/CalciteQueryTest.java | 20 +- .../druid/sql/calcite/DecoupledExtension.java | 144 +++++++ .../DecoupledPlanningCalciteQueryTest.java | 43 +- ...ecoupledPlanningCalciteUnionQueryTest.java | 43 +- .../sql/calcite/DecoupledTestConfig.java | 6 + .../apache/druid/sql/calcite/QTestCase.java | 118 ++++++ .../druid/sql/calcite/QueryTestBuilder.java | 6 + .../druid/sql/calcite/QueryTestRunner.java | 24 ++ .../sql/calcite/SqlTestFrameworkConfig.java | 104 ++++- .../calcite/SqlTestFrameworkConfigTest.java | 34 ++ .../sql/calcite/util/CalciteTestBase.java | 4 +- .../druid/sql/calcite/util/QueryLogHook.java | 7 + .../sql/calcite/util/SqlTestFramework.java | 1 + .../a.iq | 60 +++ .../asd.iq | 34 ++ .../numMerge.iq | 82 ++++ ...DistinctWithGroupingAndOtherAggregators.iq | 70 ++++ .../testGroupByLimitPushdownExtraction.iq | 83 ++++ .../testGroupBySortPushDown.iq | 75 ++++ ...TimeFloorAndDimOnGroupByTimeFloorAndDim.iq | 145 +++++++ ...estGroupByWithLiteralInSubqueryGrouping.iq | 109 +++++ ...ithGroupingAndOtherAggregatorsUsingJoin.iq | 80 ++++ ...eatedIdenticalVirtualExpressionGrouping.iq | 69 ++++ .../testSubqueryTypeMismatchWithLiterals.iq | 111 +++++ .../testWindowingWithScanAndSort.iq | 201 +++++++++ 43 files changed, 2771 insertions(+), 102 deletions(-) create mode 100644 benchmarks/src/test/resources/META-INF/services/java.sql.Driver create mode 100755 quidem create mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidAvaticaDriverTest.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidQuidemConnectionFactory.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/MapToInterfaceHandler.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/ProjectPathUtils.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java create mode 100644 sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java create mode 100644 sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java create mode 100644 sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfigTest.java create mode 100644 sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/a.iq create mode 100644 sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq create mode 100644 sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/numMerge.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq diff --git a/.gitignore b/.gitignore index 7d7cf0d5bd24..569be8d0173c 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ website/i18n/* nbproject nbactions.xml nb-configuration.xml +*.iq.out diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index 56bd3700a587..f51e94ebc1c5 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -180,6 +180,31 @@ junit test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + org.apache.druid.extensions druid-protobuf-extensions diff --git a/benchmarks/src/test/resources/META-INF/services/java.sql.Driver b/benchmarks/src/test/resources/META-INF/services/java.sql.Driver new file mode 100644 index 000000000000..b4e0887f920c --- /dev/null +++ b/benchmarks/src/test/resources/META-INF/services/java.sql.Driver @@ -0,0 +1,2 @@ +org.apache.druid.quidem.DruidAvaticaTestDriver +org.apache.calcite.avatica.remote.Driver diff --git a/pom.xml b/pom.xml index 6cf5534b9989..0eb87547a5c7 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,7 @@ 3 + false ${skipUTs} - false + ${surefire.trimStackTrace} true @@ -2167,6 +2168,7 @@ **/.settings/**/* **/.classpath **/.project + **/*.iq diff --git a/quidem b/quidem new file mode 100755 index 000000000000..6b18187ecf6f --- /dev/null +++ b/quidem @@ -0,0 +1,43 @@ +#!/bin/bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#-------------------------------------------------------------------- + +# Utility script for running the new integration tests, since the Maven +# commands are unwieldy. Allows straightforward usage of ITs on the desktop +# and in various build scripts. Handles configuration of various kinds. + + +set -e + +OPTS+=" -Pskip-static-checks" +OPTS+=" -Dsurefire.rerunFailingTestsCount=0" +OPTS+=" -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugin.surefire.SurefirePlugin=INFO" +[[ $@ =~ "-q" ]] && OPTS+=" -Dsurefire.trimStackTrace=true" + +OPTS+=" -pl sql -Dtest=SqlQuidemTest" +OPTS+=" org.apache.maven.plugins:maven-surefire-plugin:test" + +if [ "$1" == "-h" ];then +cat << EOF +Run SqlQuidemTest tests. + -Dquidem.overwrite enables overwrite mode + -Dquidem.filter=*join* runs only tests matching path expression +EOF +exit 1 +fi + +exec mvn "$@" $OPTS diff --git a/sql/pom.xml b/sql/pom.xml index e4d920dfba03..3a6f58e26d2d 100644 --- a/sql/pom.xml +++ b/sql/pom.xml @@ -192,6 +192,22 @@ junit test + + net.hydromatic + quidem + 0.11 + test + + + org.apache.httpcomponents + httpclient + test + + + org.apache.httpcomponents + httpcore + test + org.junit.jupiter junit-jupiter-api diff --git a/sql/src/main/java/org/apache/druid/sql/avatica/DruidMeta.java b/sql/src/main/java/org/apache/druid/sql/avatica/DruidMeta.java index 0dde72e4830c..4fb611177215 100644 --- a/sql/src/main/java/org/apache/druid/sql/avatica/DruidMeta.java +++ b/sql/src/main/java/org/apache/druid/sql/avatica/DruidMeta.java @@ -752,7 +752,7 @@ public MetaResultSet getTableTypes(final ConnectionHandle ch) } @VisibleForTesting - void closeAllConnections() + public void closeAllConnections() { for (String connectionId : ImmutableSet.copyOf(connections.keySet())) { closeConnection(new ConnectionHandle(connectionId)); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java index f2d0408b491d..933baaac9ba8 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalcitePlanner.java @@ -43,6 +43,7 @@ import org.apache.calcite.rel.type.RelDataTypeSystem; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexExecutor; +import org.apache.calcite.runtime.Hook; import org.apache.calcite.schema.SchemaPlus; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.SqlOperatorTable; @@ -234,6 +235,7 @@ public SqlNode parse(final Reader reader) throws SqlParseException @Override public SqlNode validate(SqlNode sqlNode) throws ValidationException { + Hook.PARSE_TREE.run(new Object[] {null, sqlNode}); ensure(CalcitePlanner.State.STATE_3_PARSED); this.validator = createSqlValidator(createCatalogReader()); try { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java index dfbded5281be..eca1bc79946d 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java @@ -47,6 +47,7 @@ import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.rex.RexNode; +import org.apache.calcite.runtime.Hook; import org.apache.calcite.schema.ScannableTable; import org.apache.calcite.sql.SqlExplain; import org.apache.calcite.sql.SqlNode; @@ -154,6 +155,7 @@ public void prepare() isPrepared = true; SqlNode validatedQueryNode = validatedQueryNode(); rootQueryRel = handlerContext.planner().rel(validatedQueryNode); + Hook.CONVERTED.run(rootQueryRel.rel); handlerContext.hook().captureQueryRel(rootQueryRel); final RelDataTypeFactory typeFactory = rootQueryRel.rel.getCluster().getTypeFactory(); final SqlValidator validator = handlerContext.planner().getValidator(); @@ -546,6 +548,7 @@ protected PlannerResult planWithDruidConvention() throws ValidationException RelNode parameterized = possiblyLimitedRoot.rel.accept( new RelParameterizerShuttle(plannerContext) ); + Hook.TRIMMED.run(parameterized); QueryValidations.validateLogicalQueryForDruid(handlerContext.plannerContext(), parameterized); CalcitePlanner planner = handlerContext.planner(); @@ -561,6 +564,7 @@ protected PlannerResult planWithDruidConvention() throws ValidationException .plus(DruidLogicalConvention.instance()), newRoot ); + Hook.JAVA_PLAN.run(newRoot); DruidQueryGenerator generator = new DruidQueryGenerator(plannerContext, (DruidLogicalNode) newRoot, rexBuilder); DruidQuery baseQuery = generator.buildQuery(); diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaDriverTest.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaDriverTest.java new file mode 100644 index 000000000000..efdf782d147f --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaDriverTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DruidAvaticaDriverTest +{ + // create a new driver instance; this will load the class and register it + DruidAvaticaTestDriver driver = new DruidAvaticaTestDriver(); + + @Test + public void testSelect() throws SQLException + { + try (Connection con = DriverManager.getConnection("druidtest:///"); + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery("select 42");) { + assertTrue(rs.next()); + assertEquals(42, rs.getInt(1)); + assertFalse(rs.next()); + } + } + + @Test + public void testURIParse() throws SQLException + { + DruidAvaticaTestDriver.buildConfigfromURIParams("druidtest:///"); + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java new file mode 100644 index 000000000000..2323b2408f3c --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java @@ -0,0 +1,383 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Binder; +import com.google.inject.Injector; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; +import org.apache.calcite.avatica.server.AbstractAvaticaHandler; +import org.apache.druid.guice.DruidInjectorBuilder; +import org.apache.druid.guice.LazySingleton; +import org.apache.druid.initialization.DruidModule; +import org.apache.druid.java.util.common.FileUtils; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.io.Closer; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.query.DefaultQueryConfig; +import org.apache.druid.query.QueryRunnerFactoryConglomerate; +import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider; +import org.apache.druid.segment.join.JoinableFactoryWrapper; +import org.apache.druid.server.DruidNode; +import org.apache.druid.server.QueryLifecycleFactory; +import org.apache.druid.server.QueryScheduler; +import org.apache.druid.server.QuerySchedulerProvider; +import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; +import org.apache.druid.server.log.RequestLogger; +import org.apache.druid.server.log.TestRequestLogger; +import org.apache.druid.server.metrics.NoopServiceEmitter; +import org.apache.druid.server.security.AuthenticatorMapper; +import org.apache.druid.server.security.AuthorizerMapper; +import org.apache.druid.server.security.Escalator; +import org.apache.druid.sql.avatica.AvaticaMonitor; +import org.apache.druid.sql.avatica.DruidAvaticaJsonHandler; +import org.apache.druid.sql.avatica.DruidMeta; +import org.apache.druid.sql.calcite.SqlTestFrameworkConfig; +import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.ConfigurationInstance; +import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigInstance; +import org.apache.druid.sql.calcite.SqlTestFrameworkConfig.SqlTestFrameworkConfigStore; +import org.apache.druid.sql.calcite.planner.CalciteRulesManager; +import org.apache.druid.sql.calcite.planner.CatalogResolver; +import org.apache.druid.sql.calcite.planner.PlannerConfig; +import org.apache.druid.sql.calcite.run.SqlEngine; +import org.apache.druid.sql.calcite.schema.DruidSchemaCatalog; +import org.apache.druid.sql.calcite.schema.DruidSchemaName; +import org.apache.druid.sql.calcite.util.CalciteTests; +import org.apache.druid.sql.calcite.util.SqlTestFramework; +import org.apache.druid.sql.calcite.util.SqlTestFramework.Builder; +import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier; +import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier; +import org.apache.druid.sql.guice.SqlModule; +import org.apache.http.NameValuePair; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.client.utils.URLEncodedUtils; +import org.eclipse.jetty.server.Server; + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.logging.Logger; + +public class DruidAvaticaTestDriver implements Driver +{ + static { + new DruidAvaticaTestDriver().register(); + } + + public static final String URI_PREFIX = "druidtest://"; + public static final String DEFAULT_URI = URI_PREFIX + "/"; + + private static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore(); + + public DruidAvaticaTestDriver() + { + } + + @Override + public Connection connect(String url, Properties info) throws SQLException + { + if (!acceptsURL(url)) { + return null; + } + SqlTestFrameworkConfigInstance config = buildConfigfromURIParams(url); + + ConfigurationInstance ci = CONFIG_STORE.getConfigurationInstance( + config, + new AvaticaBasedTestConnectionSupplier( + new StandardComponentSupplier(createTempFolder(getClass().getSimpleName())) + ) + ); + + + try { + AvaticaJettyServer server = ci.framework.injector().getInstance(AvaticaJettyServer.class); + return server.getConnection(info); + } + catch (Exception e) { + throw new SQLException("Can't create testconnection", e); + } + } + + static class AvaticaBasedConnectionModule implements DruidModule + { + @Provides + @LazySingleton + public DruidSchemaCatalog getLookupNodeService(QueryRunnerFactoryConglomerate conglomerate, + SpecificSegmentsQuerySegmentWalker walker, PlannerConfig plannerConfig) + { + return CalciteTests.createMockRootSchema( + conglomerate, + walker, + plannerConfig, + CalciteTests.TEST_AUTHORIZER_MAPPER + ); + } + + @Provides + @LazySingleton + public AvaticaJettyServer getAvaticaServer(DruidMeta druidMeta, Closer closer) throws Exception + { + AvaticaJettyServer avaticaJettyServer = new AvaticaJettyServer(druidMeta); + closer.register(avaticaJettyServer); + return avaticaJettyServer; + } + + @Override + public void configure(Binder binder) + { + } + + } + + static class AvaticaJettyServer implements Closeable + { + final DruidMeta druidMeta; + final Server server; + final String url; + + AvaticaJettyServer(final DruidMeta druidMeta) throws Exception + { + this.druidMeta = druidMeta; + server = new Server(0); + server.setHandler(getAvaticaHandler(druidMeta)); + server.start(); + url = StringUtils.format( + "jdbc:avatica:remote:url=%s", + new URIBuilder(server.getURI()).setPath(DruidAvaticaJsonHandler.AVATICA_PATH).build() + ); + } + + public Connection getConnection(Properties info) throws SQLException + { + return DriverManager.getConnection(url, info); + } + + @Override + public void close() + { + druidMeta.closeAllConnections(); + try { + server.stop(); + } + catch (Exception e) { + throw new RuntimeException("Can't stop server", e); + } + } + + protected AbstractAvaticaHandler getAvaticaHandler(final DruidMeta druidMeta) + { + return new DruidAvaticaJsonHandler( + druidMeta, + new DruidNode("dummy", "dummy", false, 1, null, true, false), + new AvaticaMonitor() + ); + } + } + + static class AvaticaBasedTestConnectionSupplier implements QueryComponentSupplier + { + + private QueryComponentSupplier delegate; + + public AvaticaBasedTestConnectionSupplier(QueryComponentSupplier delegate) + { + this.delegate = delegate; + } + + @Override + public void gatherProperties(Properties properties) + { + delegate.gatherProperties(properties); + } + + @Override + public void configureGuice(DruidInjectorBuilder builder) + { + delegate.configureGuice(builder); + TestRequestLogger testRequestLogger = new TestRequestLogger(); + builder.addModule(new AvaticaBasedConnectionModule()); + builder.addModule( + binder -> { + binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test"); + binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0); + binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1); + binder.bind(AuthenticatorMapper.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_MAPPER); + binder.bind(AuthorizerMapper.class).toInstance(CalciteTests.TEST_AUTHORIZER_MAPPER); + binder.bind(Escalator.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_ESCALATOR); + binder.bind(RequestLogger.class).toInstance(testRequestLogger); + binder.bind(String.class) + .annotatedWith(DruidSchemaName.class) + .toInstance(CalciteTests.DRUID_SCHEMA_NAME); + binder.bind(ServiceEmitter.class).to(NoopServiceEmitter.class); + binder.bind(QuerySchedulerProvider.class).in(LazySingleton.class); + binder.bind(QueryScheduler.class) + .toProvider(QuerySchedulerProvider.class) + .in(LazySingleton.class); + binder.install(new SqlModule.SqlStatementFactoryModule()); + binder.bind(new TypeLiteral>() + { + }).toInstance(Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))); + binder.bind(CalciteRulesManager.class).toInstance(new CalciteRulesManager(ImmutableSet.of())); + // binder.bind(JoinableFactoryWrapper.class).toInstance(CalciteTests.createJoinableFactoryWrapper()); + binder.bind(CatalogResolver.class).toInstance(CatalogResolver.NULL_RESOLVER); + } + ); + } + + @Override + public QueryRunnerFactoryConglomerate createCongolmerate(Builder builder, Closer closer) + { + return delegate.createCongolmerate(builder, closer); + } + + @Override + public SpecificSegmentsQuerySegmentWalker createQuerySegmentWalker(QueryRunnerFactoryConglomerate conglomerate, + JoinableFactoryWrapper joinableFactory, Injector injector) + { + return delegate.createQuerySegmentWalker(conglomerate, joinableFactory, injector); + } + + @Override + public SqlEngine createEngine(QueryLifecycleFactory qlf, ObjectMapper objectMapper, Injector injector) + { + return delegate.createEngine(qlf, objectMapper, injector); + } + + @Override + public void configureJsonMapper(ObjectMapper mapper) + { + delegate.configureJsonMapper(mapper); + } + + @Override + public JoinableFactoryWrapper createJoinableFactoryWrapper(LookupExtractorFactoryContainerProvider lookupProvider) + { + return delegate.createJoinableFactoryWrapper(lookupProvider); + } + + @Override + public void finalizeTestFramework(SqlTestFramework sqlTestFramework) + { + delegate.finalizeTestFramework(sqlTestFramework); + } + } + + protected File createTempFolder(String prefix) + { + File tempDir = FileUtils.createTempDir(prefix); + Runtime.getRuntime().addShutdownHook(new Thread() + { + @Override + public void run() + { + try { + FileUtils.deleteDirectory(tempDir); + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + }); + return tempDir; + } + + public static SqlTestFrameworkConfigInstance buildConfigfromURIParams(String url) throws SQLException + { + Map queryParams; + queryParams = new HashMap<>(); + try { + List params = URLEncodedUtils.parse(new URI(url), StandardCharsets.UTF_8); + for (NameValuePair pair : params) { + queryParams.put(pair.getName(), pair.getValue()); + } + // possible caveat: duplicate entries overwrite earlier ones + } + catch (URISyntaxException e) { + throw new SQLException("Can't decode URI", e); + } + + SqlTestFrameworkConfig config = MapToInterfaceHandler.newInstanceFor(SqlTestFrameworkConfig.class, queryParams); + return new SqlTestFrameworkConfigInstance(config); + } + + private void register() + { + try { + DriverManager.registerDriver(this); + } + catch (SQLException e) { + System.out.println("Error occurred while registering JDBC driver " + this.getClass().getName() + ": " + e); + } + } + + @Override + public boolean acceptsURL(String url) + { + return url.startsWith(URI_PREFIX); + } + + @Override + public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) + { + throw new RuntimeException("Unimplemented method!"); + } + + @Override + public int getMajorVersion() + { + return 0; + } + + @Override + public int getMinorVersion() + { + return 0; + } + + @Override + public boolean jdbcCompliant() + { + return false; + } + + @Override + public Logger getParentLogger() + { + return Logger.getLogger(""); + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java b/sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java new file mode 100644 index 000000000000..49f9d98668aa --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import java.io.File; + +public class DruidQTestInfo +{ + public final File caseDir; + public final String testName; + + public DruidQTestInfo(File caseDir, String testName) + { + this.caseDir = caseDir; + this.testName = testName; + } + + public File getIQFile() + { + return new File(caseDir, testName + ".iq"); + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java new file mode 100644 index 000000000000..10409bce4ea6 --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import net.hydromatic.quidem.AbstractCommand; +import net.hydromatic.quidem.Command; +import net.hydromatic.quidem.CommandHandler; +import net.hydromatic.quidem.Quidem.SqlCommand; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.runtime.Hook; +import org.apache.calcite.sql.SqlExplainFormat; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.calcite.util.Util; +import org.apache.druid.jackson.DefaultObjectMapper; +import org.apache.druid.query.Query; +import org.apache.druid.segment.TestHelper; +import org.apache.druid.sql.calcite.BaseCalciteQueryTest; +import org.apache.druid.sql.calcite.util.QueryLogHook; + +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +public class DruidQuidemCommandHandler implements CommandHandler +{ + + @Override + public Command parseCommand(List lines, List content, String line) + { + if (line.startsWith("convertedPlan")) { + return new ConvertedPlanCommand(lines, content); + } + if (line.startsWith("logicalPlan")) { + return new LogicalPlanCommand(lines, content); + } + if (line.startsWith("druidPlan")) { + return new PhysicalPlanCommand(lines, content); + } + if (line.startsWith("nativePlan")) { + return new NativePlanCommand(lines, content); + } + return null; + } + + abstract static class AbstractPlanCommand extends AbstractCommand + { + private final List content; + private final List lines; + + AbstractPlanCommand(List lines, List content) + { + this.lines = ImmutableList.copyOf(lines); + this.content = content; + } + + @Override + public final String describe(Context x) + { + return commandName() + " [sql: " + x.previousSqlCommand().sql + "]"; + } + + @Override + public final void execute(Context x, boolean execute) + { + if (execute) { + try { + executeExplain(x); + } + catch (Exception e) { + throw new Error(e); + } + } else { + x.echo(content); + } + x.echo(lines); + } + + protected final void executeQuery(Context x) + { + final SqlCommand sqlCommand = x.previousSqlCommand(); + try ( + final Statement statement = x.connection().createStatement(); + final ResultSet resultSet = statement.executeQuery(sqlCommand.sql)) { + // throw away all results + while (resultSet.next()) { + Util.discard(false); + } + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected abstract void executeExplain(Context x) throws Exception; + } + + /** Command that prints the plan for the current query. */ + static class NativePlanCommand extends AbstractPlanCommand + { + NativePlanCommand(List lines, List content) + { + super(lines, content); + } + + @Override + protected void executeExplain(Context x) throws Exception + { + QueryLogHook qlh = new QueryLogHook(new DefaultObjectMapper()); + qlh.logQueriesForGlobal( + () -> { + executeQuery(x); + } + ); + + List> queries = qlh.getRecordedQueries(); + + ObjectMapper objectMapper = TestHelper.JSON_MAPPER; + queries = queries + .stream() + .map(q -> BaseCalciteQueryTest.recursivelyClearContext(q, objectMapper)) + .collect(Collectors.toList()); + + for (Query query : queries) { + String str = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(query); + x.echo(ImmutableList.of(str)); + } + } + } + + /** + * Handles plan commands captured via {@link Hook}. + */ + abstract static class AbstractRelPlanCommand extends AbstractPlanCommand + { + Hook hook; + + AbstractRelPlanCommand(List lines, List content, Hook hook) + { + super(lines, content); + this.hook = hook; + } + + @Override + protected final void executeExplain(Context x) + { + List logged = new ArrayList<>(); + try (final Hook.Closeable unhook = hook.add((Consumer) logged::add)) { + executeQuery(x); + } + + for (RelNode node : logged) { + String str = RelOptUtil.dumpPlan("", node, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES); + x.echo(ImmutableList.of(str)); + } + } + } + + static class LogicalPlanCommand extends AbstractRelPlanCommand + { + LogicalPlanCommand(List lines, List content) + { + super(lines, content, Hook.TRIMMED); + } + } + + static class PhysicalPlanCommand extends AbstractRelPlanCommand + { + PhysicalPlanCommand(List lines, List content) + { + super(lines, content, Hook.JAVA_PLAN); + } + } + + static class ConvertedPlanCommand extends AbstractRelPlanCommand + { + ConvertedPlanCommand(List lines, List content) + { + super(lines, content, Hook.CONVERTED); + } + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemConnectionFactory.java b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemConnectionFactory.java new file mode 100644 index 000000000000..b9a7963f4d80 --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemConnectionFactory.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import net.hydromatic.quidem.Quidem.ConnectionFactory; +import net.hydromatic.quidem.Quidem.PropertyHandler; +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.Properties; + +public class DruidQuidemConnectionFactory implements ConnectionFactory, PropertyHandler +{ + private Properties props = new Properties(); + + public DruidQuidemConnectionFactory() + { + // ensure driver loaded + new DruidAvaticaTestDriver(); + } + + @Override + public Connection connect(String name, boolean reference) throws Exception + { + if (name.startsWith("druidtest://")) { + return DriverManager.getConnection(name, props); + } + throw new RuntimeException("unknown connection '" + name + "'"); + } + + @Override + public void onSet(String key, Object value) + { + props.setProperty(key, value.toString()); + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java new file mode 100644 index 000000000000..ca58ab10fe2d --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java @@ -0,0 +1,207 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import com.google.common.io.Files; +import net.hydromatic.quidem.CommandHandler; +import net.hydromatic.quidem.Quidem; +import net.hydromatic.quidem.Quidem.Config; +import net.hydromatic.quidem.Quidem.ConfigBuilder; +import org.apache.calcite.test.DiffTestCase; +import org.apache.calcite.util.Closer; +import org.apache.calcite.util.Util; +import org.apache.commons.io.filefilter.TrueFileFilter; +import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.apache.druid.java.util.common.FileUtils; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.RE; +import org.apache.druid.java.util.common.StringUtils; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.fail; + +/** + * Execute Quidem tests in Druid. + * + * How these tests work: + *
    + *
  1. Test cases are in .iq files - contract of these files is that they + * produce themselves if it was executed without errors
  2. + *
  3. Executor (this class) picks up these files and runs them as part of unit + * testruns
  4. + *
  5. System under test is connected via an adapter which looks like a JDBC + * driver
  6. + *
+ * + * Example usage: + *
    + *
  1. Write new .iq test as a under the appropriate directory; with command for + * expectations but without specifying them.
  2. + *
  3. Run the test - it will produce a ".iq.out" file next to the ".iq" + * one.
  4. + *
  5. Copy over the .iq.out to .iq to accept the changes
  6. + *
+ * + * To shorten the above 2 steps + * + */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public abstract class DruidQuidemTestBase +{ + + public static final String IQ_SUFFIX = ".iq"; + /** + * System property name for "overwrite mode"; note: empty value is treated as + * true + */ + private static final String OVERWRITE_PROPERTY = "quidem.overwrite"; + + private static final String PROPERTY_FILTER = "quidem.filter"; + + private FileFilter filter = TrueFileFilter.INSTANCE; + + private DruidQuidemRunner druidQuidemRunner; + + public DruidQuidemTestBase() + { + String filterStr = System.getProperty(PROPERTY_FILTER, null); + if (filterStr != null) { + if (!filterStr.endsWith("*") && !filterStr.endsWith(IQ_SUFFIX)) { + filterStr = filterStr + IQ_SUFFIX; + } + filter = new WildcardFileFilter(filterStr); + } + druidQuidemRunner = new DruidQuidemRunner(); + } + + /** Creates a command handler. */ + protected CommandHandler createCommandHandler() + { + return Quidem.EMPTY_COMMAND_HANDLER; + } + + @ParameterizedTest + @MethodSource("getFileNames") + public void test(String testFileName) throws Exception + { + File inFile = new File(getTestRoot(), testFileName); + + final File outFile = new File(inFile.getParentFile(), inFile.getName() + ".out"); + druidQuidemRunner.run(inFile, outFile); + } + + public static class DruidQuidemRunner + { + public DruidQuidemRunner() + { + } + + public void run(File inFile) throws Exception + { + File outFile = new File(inFile.getParent(), inFile.getName() + ".out"); + run(inFile, outFile); + } + + public void run(File inFile, final File outFile) throws Exception + { + FileUtils.mkdirp(outFile.getParentFile()); + try (Reader reader = Util.reader(inFile); + Writer writer = Util.printWriter(outFile); + Closer closer = new Closer()) { + + DruidQuidemConnectionFactory connectionFactory = new DruidQuidemConnectionFactory(); + ConfigBuilder configBuilder = Quidem.configBuilder() + .withConnectionFactory(connectionFactory) + // this is not nice - but it makes it possible to do queryContext + // changes + .withPropertyHandler(connectionFactory) + .withCommandHandler(new DruidQuidemCommandHandler()); + + Config config = configBuilder + .withReader(reader) + .withWriter(writer).build(); + + new Quidem(config).execute(); + } + catch (Exception e) { + throw new RE(e, "Encountered exception while running [%s]", inFile); + } + + final String diff = DiffTestCase.diff(inFile, outFile); + + if (!diff.isEmpty()) { + if (isOverwrite()) { + Files.copy(outFile, inFile); + } else { + fail("Files differ: " + outFile + " " + inFile + "\n" + diff); + } + } + } + + public static boolean isOverwrite() + { + String property = System.getProperty(OVERWRITE_PROPERTY, "false"); + return property.length() == 0 || Boolean.valueOf(property); + } + } + + protected final List getFileNames() throws IOException + { + List ret = new ArrayList(); + + File testRoot = getTestRoot(); + if (!testRoot.exists()) { + throw new FileNotFoundException(StringUtils.format("testRoot [%s] doesn't exists!", testRoot)); + } + for (File f : testRoot.listFiles(this::isTestIncluded)) { + ret.add(f.getName()); + } + if (ret.isEmpty()) { + throw new IAE( + "There are no test cases in directory [%s] or there are no matches to filter [%s]", + testRoot, + filter + ); + } + Collections.sort(ret); + return ret; + } + + private boolean isTestIncluded(File f) + { + return !f.isDirectory() + && f.getName().endsWith(IQ_SUFFIX) + && filter.accept(f); + } + + protected abstract File getTestRoot(); +} diff --git a/sql/src/test/java/org/apache/druid/quidem/MapToInterfaceHandler.java b/sql/src/test/java/org/apache/druid/quidem/MapToInterfaceHandler.java new file mode 100644 index 000000000000..5637db7c42b6 --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/MapToInterfaceHandler.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.Map; + +/** + * Utility class to provide interface implementation based on a map of string + * values. + * + * intended usage: MapToInterfaceHandler.newInstanceFor(TargetInterface.class, + * map); + */ +class MapToInterfaceHandler implements InvocationHandler +{ + private Map backingMap; + + @SuppressWarnings("unchecked") + public static T newInstanceFor(Class clazz, Map queryParams) + { + return (T) Proxy.newProxyInstance( + clazz.getClassLoader(), + new Class[] {clazz}, + new MapToInterfaceHandler(queryParams) + ); + } + + private MapToInterfaceHandler(Map backingMap) + { + this.backingMap = backingMap; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) + { + Class returnType = method.getReturnType(); + String obj = backingMap.get(method.getName()); + if (obj == null) { + return method.getDefaultValue(); + } else { + if (returnType.isInstance(obj)) { + return obj; + } + return uglyCastCrap(obj, returnType); + } + } + + private Object uglyCastCrap(String obj, Class returnType) + { + if (returnType == int.class) { + return Integer.parseInt(obj); + } + throw new RuntimeException("don't know how to handle conversion to " + returnType); + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/ProjectPathUtils.java b/sql/src/test/java/org/apache/druid/quidem/ProjectPathUtils.java new file mode 100644 index 000000000000..5751b6f465cb --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/ProjectPathUtils.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import java.io.File; + +public class ProjectPathUtils +{ + public static final File PROJECT_ROOT = findProjectRoot(); + + public static File getPathFromProjectRoot(String path) + { + return new File(PROJECT_ROOT, path); + } + + protected static File findProjectRoot() + { + File f = new File(".").getAbsoluteFile(); + while (f != null) { + if (isProjectRoot(f)) { + return f; + } + f = f.getParentFile(); + } + throw new IllegalStateException("Can't find project root!"); + } + + private static boolean isProjectRoot(File candidate) + { + return new File(candidate, "web-console").exists(); + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java b/sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java new file mode 100644 index 000000000000..9e6a965891ce --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import java.io.File; + +public class SqlQuidemTest extends DruidQuidemTestBase +{ + public SqlQuidemTest() + { + super(); + } + + @Override + protected File getTestRoot() + { + return ProjectPathUtils.getPathFromProjectRoot("sql/src/test/quidem/" + getClass().getName()); + } +} diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 478648088c32..44d5dcbf3e67 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -6928,7 +6928,7 @@ public void testApproxCountDistinctBuiltin() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testExactCountDistinctWithGroupingAndOtherAggregators() { @@ -6983,7 +6983,7 @@ public void testExactCountDistinctWithGroupingAndOtherAggregators() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin() { @@ -8182,7 +8182,7 @@ public void testRegexpLikeFilter() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testGroupBySortPushDown() { @@ -8278,7 +8278,7 @@ public void testGroupByLimitPushDownWithHavingOnLong() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByLimitPushdownExtraction() { @@ -8725,7 +8725,7 @@ public void testGroupByFloor() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @SqlTestFrameworkConfig(numMergeBuffers = 3) @Test public void testQueryWithSelectProjectAndIdentityProjectDoesNotRename() @@ -10570,7 +10570,7 @@ public void testGroupByTimeAndOtherDimension() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim() { @@ -12705,7 +12705,7 @@ public void testNvlColumns() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByWithLiteralInSubqueryGrouping() { @@ -12894,7 +12894,7 @@ public void testQueryContextOuterLimit() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testRepeatedIdenticalVirtualExpressionGrouping() { @@ -14470,7 +14470,7 @@ public void testGreatestFunctionForStringWithIsNull() ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) @Test public void testSubqueryTypeMismatchWithLiterals() { @@ -15192,7 +15192,7 @@ public void testScanAndSortCanGetSchemaFromScanQuery() .run(); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @Test public void testWindowingWithScanAndSort() { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java new file mode 100644 index 000000000000..f85e7dc34e7b --- /dev/null +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.sql.calcite; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import com.google.common.io.Files; +import org.apache.druid.query.QueryContexts; +import org.apache.druid.quidem.DruidQTestInfo; +import org.apache.druid.quidem.DruidQuidemTestBase; +import org.apache.druid.quidem.ProjectPathUtils; +import org.apache.druid.server.security.AuthConfig; +import org.apache.druid.sql.calcite.BaseCalciteQueryTest.CalciteTestConfig; +import org.apache.druid.sql.calcite.planner.PlannerConfig; +import org.apache.druid.sql.calcite.util.SqlTestFramework; +import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DecoupledExtension implements BeforeEachCallback +{ + private BaseCalciteQueryTest baseTest; + + public DecoupledExtension(BaseCalciteQueryTest baseTest) + { + this.baseTest = baseTest; + } + + private File qCaseDir; + + @Override + public void beforeEach(ExtensionContext context) throws Exception + { + Class testClass = context.getTestClass().get(); + qCaseDir = ProjectPathUtils.getPathFromProjectRoot("sql/src/test/quidem/" + testClass.getName()); + validateTestClass(context); + } + + private void validateTestClass(ExtensionContext context) throws Exception + { + Class testClass = context.getTestClass().get(); + String methodName = "validateTestClass"; + Method testMethod = Preconditions.checkNotNull( + testClass.getMethod(methodName), "Please add validateTestClass() test method to the testClass!" + ); + if (methodName.equals(testMethod.getName())) { + checkAnnotationConsistency(testClass); + } + } + + private void checkAnnotationConsistency(Class testClass) + { + Map testNameToFileMap = new HashMap<>(); + if (qCaseDir.exists()) { + for (File iqFile : qCaseDir.listFiles(f -> f.getName().endsWith(DruidQuidemTestBase.IQ_SUFFIX))) { + testNameToFileMap.put(Files.getNameWithoutExtension(iqFile.getName()), iqFile); + } + } + for (Method method : testClass.getMethods()) { + DecoupledTestConfig dtc = method.getAnnotation(DecoupledTestConfig.class); + if (dtc == null || !dtc.quidem()) { + continue; + } + testNameToFileMap.remove(method.getName()); + } + assertEquals(Collections.emptyMap(), testNameToFileMap, "Please remove dangling quidem files!"); + } + + private static final ImmutableMap CONTEXT_OVERRIDES = ImmutableMap.builder() + .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) + .put(PlannerConfig.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, PlannerConfig.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED) + .put(QueryContexts.ENABLE_DEBUG, true) + .build(); + + public QueryTestBuilder testBuilder() + { + DecoupledTestConfig decTestConfig = BaseCalciteQueryTest.queryFrameworkRule + .getAnnotation(DecoupledTestConfig.class); + + assumeTrue(BaseCalciteQueryTest.queryFrameworkRule.getConfig().numMergeBuffers == 0); + + PlannerComponentSupplier componentSupplier = baseTest; + + boolean runQuidem = (decTestConfig != null && decTestConfig.quidem()); + + CalciteTestConfig testConfig = baseTest.new CalciteTestConfig(CONTEXT_OVERRIDES) + { + + @Override + public SqlTestFramework.PlannerFixture plannerFixture(PlannerConfig plannerConfig, AuthConfig authConfig) + { + plannerConfig = plannerConfig.withOverrides(CONTEXT_OVERRIDES); + + return baseTest.queryFramework().plannerFixture(componentSupplier, plannerConfig, authConfig); + } + + @Override + public DruidQTestInfo getQTestInfo() + { + if (runQuidem) { + return new DruidQTestInfo(qCaseDir, BaseCalciteQueryTest.queryFrameworkRule.testName()); + } else { + return null; + } + } + }; + + QueryTestBuilder builder = new QueryTestBuilder(testConfig) + .cannotVectorize(baseTest.cannotVectorize) + .skipVectorize(baseTest.skipVectorize); + + if (decTestConfig != null && decTestConfig.nativeQueryIgnore().isPresent()) { + builder.verifyNativeQueries(x -> false); + } + + return builder; + } +} diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java index 1a0ae448319f..befa7e48c879 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java @@ -19,49 +19,26 @@ package org.apache.druid.sql.calcite; -import com.google.common.collect.ImmutableMap; -import org.apache.druid.query.QueryContexts; -import org.apache.druid.server.security.AuthConfig; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; -import org.apache.druid.sql.calcite.planner.PlannerConfig; -import org.apache.druid.sql.calcite.util.SqlTestFramework; -import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; @ExtendWith(NotYetSupportedProcessor.class) public class DecoupledPlanningCalciteQueryTest extends CalciteQueryTest { - private static final ImmutableMap CONTEXT_OVERRIDES = - ImmutableMap.builder() - .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) - .put(PlannerConfig.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, PlannerConfig.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED) - .put(QueryContexts.ENABLE_DEBUG, true) - .build(); + @RegisterExtension + DecoupledExtension decoupledExtension = new DecoupledExtension(this); @Override protected QueryTestBuilder testBuilder() { - PlannerComponentSupplier componentSupplier = this; - CalciteTestConfig testConfig = new CalciteTestConfig(CONTEXT_OVERRIDES) - { - @Override - public SqlTestFramework.PlannerFixture plannerFixture(PlannerConfig plannerConfig, AuthConfig authConfig) - { - plannerConfig = plannerConfig.withOverrides(CONTEXT_OVERRIDES); - return queryFramework().plannerFixture(componentSupplier, plannerConfig, authConfig); - } - }; - - QueryTestBuilder builder = new QueryTestBuilder(testConfig) - .cannotVectorize(cannotVectorize) - .skipVectorize(skipVectorize); - - DecoupledTestConfig decTestConfig = queryFrameworkRule.getAnnotation(DecoupledTestConfig.class); - - if (decTestConfig != null && decTestConfig.nativeQueryIgnore().isPresent()) { - builder.verifyNativeQueries(x -> false); - } + return decoupledExtension.testBuilder(); + } - return builder; + @Test + public void validateTestClass() + { + // technical testcase needed by the extension temporarily } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java index 7ddfc59c9bcd..ebdf3f25b029 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java @@ -19,49 +19,26 @@ package org.apache.druid.sql.calcite; -import com.google.common.collect.ImmutableMap; -import org.apache.druid.query.QueryContexts; -import org.apache.druid.server.security.AuthConfig; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; -import org.apache.druid.sql.calcite.planner.PlannerConfig; -import org.apache.druid.sql.calcite.util.SqlTestFramework; -import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; @ExtendWith(NotYetSupportedProcessor.class) public class DecoupledPlanningCalciteUnionQueryTest extends CalciteUnionQueryTest { - private static final ImmutableMap CONTEXT_OVERRIDES = - ImmutableMap.builder() - .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) - .put(PlannerConfig.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, PlannerConfig.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED) - .put(QueryContexts.ENABLE_DEBUG, true) - .build(); + @RegisterExtension + DecoupledExtension decoupledExtension = new DecoupledExtension(this); @Override protected QueryTestBuilder testBuilder() { - PlannerComponentSupplier componentSupplier = this; - CalciteTestConfig testConfig = new CalciteTestConfig(CONTEXT_OVERRIDES) - { - @Override - public SqlTestFramework.PlannerFixture plannerFixture(PlannerConfig plannerConfig, AuthConfig authConfig) - { - plannerConfig = plannerConfig.withOverrides(CONTEXT_OVERRIDES); - return queryFramework().plannerFixture(componentSupplier, plannerConfig, authConfig); - } - }; - - QueryTestBuilder builder = new QueryTestBuilder(testConfig) - .cannotVectorize(cannotVectorize) - .skipVectorize(skipVectorize); - - DecoupledTestConfig decTestConfig = queryFrameworkRule.getAnnotation(DecoupledTestConfig.class); - - if (decTestConfig != null && decTestConfig.nativeQueryIgnore().isPresent()) { - builder.verifyNativeQueries(x -> false); - } + return decoupledExtension.testBuilder(); + } - return builder; + @Test + public void validateTestClass() + { + // technical testcase needed by the extension temporarily } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java index 511db82b76b7..2ac031f4e08b 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java @@ -44,6 +44,12 @@ */ NativeQueryIgnore nativeQueryIgnore() default NativeQueryIgnore.NONE; + /** + * Use alternate quidem test for testcase + */ + boolean quidem() default false; + + enum NativeQueryIgnore { NONE, diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java b/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java new file mode 100644 index 000000000000..765c3f9b7303 --- /dev/null +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.sql.calcite; + +import com.google.common.hash.HashCode; +import com.google.common.hash.Hashing; +import com.google.common.io.Files; +import org.apache.druid.java.util.common.FileUtils; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.quidem.DruidQTestInfo; +import org.apache.druid.quidem.DruidQuidemTestBase; +import org.apache.druid.quidem.DruidQuidemTestBase.DruidQuidemRunner; +import org.apache.druid.sql.calcite.QueryTestRunner.QueryRunStep; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +public class QTestCase +{ + private StringBuffer sb; + private DruidQTestInfo testInfo; + + public QTestCase(DruidQTestInfo testInfo) + { + this.testInfo = testInfo; + sb = new StringBuffer(); + } + + public void println(String str) + { + sb.append(str); + sb.append("\n"); + } + + public QueryRunStep toRunner() + { + return new QueryRunStep(null) + { + + @Override + public void run() + { + try { + if (DruidQuidemRunner.isOverwrite()) { + writeCaseTo(testInfo.getIQFile()); + } else { + isValidTestCaseFile(testInfo.getIQFile()); + } + + DruidQuidemRunner runner = new DruidQuidemTestBase.DruidQuidemRunner(); + runner.run(testInfo.getIQFile()); + } + catch (Exception e) { + throw new RuntimeException("Error running quidem test", e); + } + } + }; + } + + protected void isValidTestCaseFile(File iqFile) + { + if (!iqFile.exists()) { + throw new IllegalStateException("testcase doesn't exists; run with (-Dquidem.overwrite) : " + iqFile); + } + try { + String header = makeHeader(); + String testCaseFirstLine = Files.asCharSource(iqFile, StandardCharsets.UTF_8).readFirstLine(); + if (!header.equals(testCaseFirstLine)) { + throw new IllegalStateException( + "backing quidem testcase doesn't match test - run with (-Dquidem.overwrite) : " + iqFile + ); + } + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String makeHeader() + { + HashCode hash = Hashing.crc32().hashBytes(sb.toString().getBytes(StandardCharsets.UTF_8)); + return StringUtils.format("# %s case-crc:%s", testInfo.testName, hash); + + } + + public void writeCaseTo(File file) throws IOException + { + FileUtils.mkdirp(file.getParentFile()); + try (FileOutputStream fos = new FileOutputStream(file)) { + fos.write(makeHeader().getBytes(StandardCharsets.UTF_8)); + fos.write('\n'); + fos.write(sb.toString().getBytes(StandardCharsets.UTF_8)); + } + catch (IOException e) { + throw new RuntimeException("Error writing testcase to: " + file, e); + } + } + +} diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java index ff7e9b5a6bac..d06ac1d1c121 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java @@ -23,6 +23,7 @@ import com.google.common.base.Preconditions; import org.apache.druid.query.Query; import org.apache.druid.query.QueryContexts; +import org.apache.druid.quidem.DruidQTestInfo; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.server.security.AuthenticationResult; @@ -75,6 +76,11 @@ public interface QueryTestConfig boolean isRunningMSQ(); Map baseQueryContext(); + + default DruidQTestInfo getQTestInfo() + { + return null; + } } protected final QueryTestConfig config; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java index 58fa5635e8f5..5899440128d8 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java @@ -33,6 +33,7 @@ import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.Query; import org.apache.druid.query.QueryContexts; +import org.apache.druid.quidem.DruidQTestInfo; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.server.security.ResourceAction; import org.apache.druid.sql.DirectStatement; @@ -55,6 +56,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -634,6 +636,28 @@ public void verify() public QueryTestRunner(QueryTestBuilder builder) { QueryTestConfig config = builder.config; + DruidQTestInfo iqTestInfo = config.getQTestInfo(); + if (iqTestInfo != null) { + QTestCase qt = new QTestCase(iqTestInfo); + Map queryContext = builder.getQueryContext(); + for (Entry entry : queryContext.entrySet()) { + qt.println(StringUtils.format("!set %s %s", entry.getKey(), entry.getValue())); + } + qt.println("!set outputformat mysql"); + qt.println("!use druidtest:///"); + + qt.println(builder.sql + ";"); + if (builder.expectedResults != null) { + qt.println("!ok"); + } + qt.println("!logicalPlan"); + qt.println("!druidPlan"); + if (builder.expectedQueries != null) { + qt.println("!nativePlan"); + } + runSteps.add(qt.toRunner()); + return; + } if (builder.expectedResultsVerifier == null && builder.expectedResults != null) { builder.expectedResultsVerifier = config.defaultResultsVerifier( builder.expectedResults, diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java index df50dd62bec7..e33e6c1af8fe 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; + import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -34,6 +35,7 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * Annotation to specify desired framework settings. @@ -51,25 +53,83 @@ ResultCacheMode resultCache() default ResultCacheMode.DISABLED; + /** + * Non-annotation version of {@link SqlTestFrameworkConfig}. + * + * Makes it less convoluted to work with configurations created at runtime. + */ + class SqlTestFrameworkConfigInstance + { + public final int numMergeBuffers; + public final int minTopNThreshold; + public final ResultCacheMode resultCache; + + public SqlTestFrameworkConfigInstance(SqlTestFrameworkConfig annotation) + { + numMergeBuffers = annotation.numMergeBuffers(); + minTopNThreshold = annotation.minTopNThreshold(); + resultCache = annotation.resultCache(); + } + + @Override + public int hashCode() + { + return Objects.hash(minTopNThreshold, numMergeBuffers, resultCache); + } + + @Override + public boolean equals(Object obj) + { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + SqlTestFrameworkConfigInstance other = (SqlTestFrameworkConfigInstance) obj; + return minTopNThreshold == other.minTopNThreshold + && numMergeBuffers == other.numMergeBuffers + && resultCache == other.resultCache; + } + + } + + class SqlTestFrameworkConfigStore + { + Map configMap = new HashMap<>(); + + public ConfigurationInstance getConfigurationInstance( + SqlTestFrameworkConfigInstance config, + QueryComponentSupplier testHost) + { + ConfigurationInstance ret = configMap.get(config); + if (!configMap.containsKey(config)) { + ret = new ConfigurationInstance(config, testHost); + configMap.put(config, ret); + } + return ret; + } + public void close() + { + for (ConfigurationInstance f : configMap.values()) { + f.close(); + } + configMap.clear(); + } + } /** * @see {@link SqlTestFrameworkConfig} */ class Rule implements AfterAllCallback, BeforeEachCallback { - Map configMap = new HashMap<>(); - private SqlTestFrameworkConfig config; + SqlTestFrameworkConfigStore configStore = new SqlTestFrameworkConfigStore(); + private SqlTestFrameworkConfigInstance config; private QueryComponentSupplier testHost; private Method method; @Override public void afterAll(ExtensionContext context) { - for (ConfigurationInstance f : configMap.values()) { - f.close(); - } - configMap.clear(); + configStore.close(); } @Override @@ -95,32 +155,32 @@ public SqlTestFrameworkConfig defaultConfig() } } - public void setConfig(SqlTestFrameworkConfig annotation) + private void setConfig(SqlTestFrameworkConfig annotation) { - config = annotation; - if (config == null) { - config = defaultConfig(); + if (annotation == null) { + annotation = defaultConfig(); } + config = new SqlTestFrameworkConfigInstance(annotation); } - public SqlTestFramework get() + public SqlTestFrameworkConfigInstance getConfig() { - return getConfigurationInstance().framework; + return config; } - public T getAnnotation(Class annotationType) + public SqlTestFramework get() { - return method.getAnnotation(annotationType); + return configStore.getConfigurationInstance(config, testHost).framework; } - private ConfigurationInstance getConfigurationInstance() + public T getAnnotation(Class annotationType) { - return configMap.computeIfAbsent(config, this::buildConfiguration); + return method.getAnnotation(annotationType); } - ConfigurationInstance buildConfiguration(SqlTestFrameworkConfig config) + public String testName() { - return new ConfigurationInstance(config, testHost); + return method.getName(); } } @@ -128,13 +188,13 @@ class ConfigurationInstance { public SqlTestFramework framework; - ConfigurationInstance(SqlTestFrameworkConfig config, QueryComponentSupplier testHost) + ConfigurationInstance(SqlTestFrameworkConfigInstance config, QueryComponentSupplier testHost) { SqlTestFramework.Builder builder = new SqlTestFramework.Builder(testHost) .catalogResolver(testHost.createCatalogResolver()) - .minTopNThreshold(config.minTopNThreshold()) - .mergeBufferCount(config.numMergeBuffers()) - .withOverrideModule(config.resultCache().makeModule()); + .minTopNThreshold(config.minTopNThreshold) + .mergeBufferCount(config.numMergeBuffers) + .withOverrideModule(config.resultCache.makeModule()); framework = builder.build(); } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfigTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfigTest.java new file mode 100644 index 000000000000..26b8d17e03aa --- /dev/null +++ b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfigTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.sql.calcite; + +import nl.jqno.equalsverifier.EqualsVerifier; +import org.junit.jupiter.api.Test; + +public class SqlTestFrameworkConfigTest +{ + @Test + public void testEquals() + { + EqualsVerifier.forClass(SqlTestFrameworkConfig.SqlTestFrameworkConfigInstance.class) + .usingGetClass() + .verify(); + } +} diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java index 9ec71acc2d92..4604318456fa 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java @@ -70,10 +70,10 @@ public static void setupCalciteProperties() public void setCaseTempDir(TestInfo testInfo) { String methodName = testInfo.getTestMethod().get().getName(); - casetempPath = FileUtils.createTempDirInLocation(rootTempPath, methodName).toPath(); + Path path = FileUtils.createTempDirInLocation(rootTempPath, methodName).toPath(); + casetempPath = path; } - public File newTempFolder() { return newTempFolder(null); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java index 3e00d1701818..428579ae5976 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java @@ -67,4 +67,11 @@ public void logQueriesFor(Runnable r) r.run(); } } + + public void logQueriesForGlobal(Runnable r) + { + try (final Hook.Closeable unhook = Hook.QUERY_PLAN.add(this::accept)) { + r.run(); + } + } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java index 1506a5c2001a..462aa7dd9ca7 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java @@ -570,6 +570,7 @@ private SqlTestFramework(Builder builder) // test pulls in a module, then pull in that module, even though we are // not the Druid node to which the module is scoped. .ignoreLoadScopes() + .addModule(binder -> binder.bind(Closer.class).toInstance(resourceCloser)) .addModule(new LookylooModule()) .addModule(new SegmentWranglerModule()) .addModule(new SqlAggregationModule()) diff --git a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/a.iq b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/a.iq new file mode 100644 index 000000000000..e1487433f2e0 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/a.iq @@ -0,0 +1,60 @@ +!use druidtest:/// +!set outputformat mysql + +select 1+5; ++--------+ +| EXPR$0 | ++--------+ +| 6 | ++--------+ +(1 row) + +!ok + +select cityName, countryName from wikipedia where cityName='New York' limit 1; ++----------+---------------+ +| cityName | countryName | ++----------+---------------+ +| New York | United States | ++----------+---------------+ +(1 row) + +!ok +{ + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "wikipedia" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "limit" : 1, + "filter" : { + "type" : "equals", + "column" : "cityName", + "matchValueType" : "STRING", + "matchValue" : "New York" + }, + "columns" : [ "cityName", "countryName" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan +LogicalSort(fetch=[1]) + LogicalProject(cityName=[$2], countryName=[$5]) + LogicalFilter(condition=[=($2, 'New York')]) + LogicalTableScan(table=[[druid, wikipedia]]) + +!logicalPlan +LogicalSort(fetch=[1]) + LogicalProject(cityName=[$2], countryName=[$5]) + LogicalFilter(condition=[=($2, 'New York')]) + LogicalTableScan(table=[[druid, wikipedia]]) + +!convertedPlan diff --git a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq new file mode 100644 index 000000000000..f75543609e04 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq @@ -0,0 +1,34 @@ +!use druidtest:/// +!set outputformat mysql + + +select 1+5; ++--------+ +| EXPR$0 | ++--------+ +| 6 | ++--------+ +(1 row) + +!ok + +select cityName, countryName from wikipedia where cityName='New York' limit 1; ++----------+---------------+ +| cityName | countryName | ++----------+---------------+ +| New York | United States | ++----------+---------------+ +(1 row) + +!ok + + +select cityName, countryName from wikipedia where cityName is null limit 1; ++----------+-------------+ +| cityName | countryName | ++----------+-------------+ +| | | ++----------+-------------+ +(1 row) + +!ok diff --git a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/numMerge.iq b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/numMerge.iq new file mode 100644 index 000000000000..2c42ea49c782 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/numMerge.iq @@ -0,0 +1,82 @@ +!use druidtest://?numMergeBuffers=3 +!set outputformat mysql + +SELECT +dim1, dim2, SUM(m1), COUNT(*) +FROM (SELECT * FROM foo UNION ALL SELECT * FROM foo UNION ALL SELECT * FROM foo) +WHERE dim2 = 'a' OR dim2 = 'def' +GROUP BY 1, 2; ++------+------+--------+--------+ +| dim1 | dim2 | EXPR$2 | EXPR$3 | ++------+------+--------+--------+ +| | a | 3.0 | 3 | +| 1 | a | 12.0 | 3 | ++------+------+--------+--------+ +(2 rows) + +!ok +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "union", + "dataSources" : [ { + "type" : "table", + "name" : "foo" + }, { + "type" : "table", + "name" : "foo" + }, { + "type" : "table", + "name" : "foo" + } ] + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "filter" : { + "type" : "inType", + "column" : "dim2", + "matchValueType" : "STRING", + "sortedValues" : [ "a", "def" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim1", + "outputName" : "d0", + "outputType" : "STRING" + }, { + "type" : "default", + "dimension" : "dim2", + "outputName" : "d1", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "doubleSum", + "name" : "a0", + "fieldName" : "m1" + }, { + "type" : "count", + "name" : "a1" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan +LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)], EXPR$3=[COUNT()]) + LogicalProject(dim1=[$1], dim2=[$2], m1=[$5]) + LogicalFilter(condition=[OR(=($2, 'a'), =($2, 'def'))]) + LogicalUnion(all=[true]) + LogicalUnion(all=[true]) + LogicalProject(__time=[$0], dim1=[$1], dim2=[$2], dim3=[$3], cnt=[$4], m1=[$5], m2=[$6], unique_dim1=[$7]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(__time=[$0], dim1=[$1], dim2=[$2], dim3=[$3], cnt=[$4], m1=[$5], m2=[$6], unique_dim1=[$7]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(__time=[$0], dim1=[$1], dim2=[$2], dim3=[$3], cnt=[$4], m1=[$5], m2=[$6], unique_dim1=[$7]) + LogicalTableScan(table=[[druid, foo]]) + +!convertedPlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq new file mode 100644 index 000000000000..5dd3bc1c2603 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq @@ -0,0 +1,70 @@ +# testExactCountDistinctWithGroupingAndOtherAggregators case-crc:046d1e3e +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT dim2, SUM(cnt), COUNT(distinct dim1) FROM druid.foo GROUP BY dim2; ++------+--------+--------+ +| dim2 | EXPR$1 | EXPR$2 | ++------+--------+--------+ +| | 1 | 1 | +| a | 2 | 2 | +| abc | 1 | 1 | +| | 2 | 2 | ++------+--------+--------+ +(4 rows) + +!ok +LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT(DISTINCT $2)]) + LogicalProject(dim2=[$2], cnt=[$4], dim1=[$1]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{2}], EXPR$1=[SUM($4)], EXPR$2=[COUNT(DISTINCT $1)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim2", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "longSum", + "name" : "a0", + "fieldName" : "cnt" + }, { + "type" : "cardinality", + "name" : "a1", + "fields" : [ { + "type" : "default", + "dimension" : "dim1", + "outputName" : "dim1", + "outputType" : "STRING" + } ], + "byRow" : false, + "round" : true + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq new file mode 100644 index 000000000000..60734ddbeed8 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq @@ -0,0 +1,83 @@ +# testGroupByLimitPushdownExtraction case-crc:da2618b7 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT dim4, substring(dim5, 1, 1), count(*) FROM druid.numfoo WHERE dim4 = 'a' GROUP BY 1,2 LIMIT 2; ++------+--------+--------+ +| dim4 | EXPR$1 | EXPR$2 | ++------+--------+--------+ +| a | a | 2 | +| a | b | 1 | ++------+--------+--------+ +(2 rows) + +!ok +LogicalSort(fetch=[2]) + LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()]) + LogicalProject(dim4=[$4], EXPR$1=[SUBSTRING($5, 1, 1)]) + LogicalFilter(condition=[=($4, 'a')]) + LogicalTableScan(table=[[druid, numfoo]]) + +!logicalPlan +DruidProject(dim4=[CAST('a':VARCHAR):VARCHAR], EXPR$1=[$0], EXPR$2=[$1], druid=[logical]) + DruidSort(fetch=[2], druid=[logical]) + DruidAggregate(group=[{0}], EXPR$2=[COUNT()], druid=[logical]) + DruidProject(EXPR$1=[SUBSTRING($5, 1, 1)], druid=[logical]) + DruidFilter(condition=[=($4, 'a')]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "topN", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "dimension" : { + "type" : "extraction", + "dimension" : "dim5", + "outputName" : "_d0", + "outputType" : "STRING", + "extractionFn" : { + "type" : "substring", + "index" : 0, + "length" : 1 + } + }, + "metric" : { + "type" : "dimension", + "ordering" : { + "type" : "lexicographic" + } + }, + "threshold" : 2, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "filter" : { + "type" : "equals", + "column" : "dim4", + "matchValueType" : "STRING", + "matchValue" : "a" + }, + "granularity" : { + "type" : "all" + }, + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ], + "postAggregations" : [ { + "type" : "expression", + "name" : "s0", + "expression" : "'a'", + "outputType" : "STRING" + } ] +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq new file mode 100644 index 000000000000..17e7be5b364b --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq @@ -0,0 +1,75 @@ +# testGroupBySortPushDown case-crc:54515e94 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT dim2, dim1, SUM(cnt) FROM druid.foo GROUP BY dim2, dim1 ORDER BY dim1 LIMIT 4; ++------+------+--------+ +| dim2 | dim1 | EXPR$2 | ++------+------+--------+ +| a | | 1 | +| a | 1 | 1 | +| | 10.1 | 1 | +| | 2 | 1 | ++------+------+--------+ +(4 rows) + +!ok +LogicalSort(sort0=[$1], dir0=[ASC], fetch=[4]) + LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)]) + LogicalProject(dim2=[$2], dim1=[$1], cnt=[$4]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(dim2=[$1], dim1=[$0], EXPR$2=[$2], druid=[logical]) + DruidSort(sort0=[$0], dir0=[ASC], fetch=[4], druid=[logical]) + DruidAggregate(group=[{1, 2}], EXPR$2=[SUM($4)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim1", + "outputName" : "d0", + "outputType" : "STRING" + }, { + "type" : "default", + "dimension" : "dim2", + "outputName" : "d1", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "longSum", + "name" : "a0", + "fieldName" : "cnt" + } ], + "limitSpec" : { + "type" : "default", + "columns" : [ { + "dimension" : "d0", + "direction" : "ascending", + "dimensionOrder" : { + "type" : "lexicographic" + } + } ], + "limit" : 4 + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq new file mode 100644 index 000000000000..10c05b8b5d8c --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq @@ -0,0 +1,145 @@ +# testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim case-crc:f87d60a4 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT dim2, time_floor(gran, 'P1M') gran, sum(s) +FROM (SELECT time_floor(__time, 'P1D') AS gran, dim2, sum(m1) as s FROM druid.foo GROUP BY 1, 2 HAVING sum(m1) > 1) AS x +GROUP BY 1, 2 +ORDER BY dim2, gran desc; ++------+---------------------+--------+ +| dim2 | gran | EXPR$2 | ++------+---------------------+--------+ +| | 2001-01-01 00:00:00 | 6.0 | +| | 2000-01-01 00:00:00 | 2.0 | +| | 2000-01-01 00:00:00 | 3.0 | +| a | 2001-01-01 00:00:00 | 4.0 | +| abc | 2001-01-01 00:00:00 | 5.0 | ++------+---------------------+--------+ +(5 rows) + +!ok +LogicalSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[DESC]) + LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)]) + LogicalProject(dim2=[$1], gran=[TIME_FLOOR($0, 'P1M')], s=[$2]) + LogicalFilter(condition=[>($2, 1)]) + LogicalAggregate(group=[{0, 1}], s=[SUM($2)]) + LogicalProject(gran=[TIME_FLOOR($0, 'P1D')], dim2=[$2], m1=[$5]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[DESC], druid=[logical]) + DruidAggregate(group=[{0, 1}], EXPR$2=[SUM($2)], druid=[logical]) + DruidProject(dim2=[$1], gran=[TIME_FLOOR($0, 'P1M')], s=[$2], druid=[logical]) + DruidFilter(condition=[>($2, 1)]) + DruidAggregate(group=[{0, 1}], s=[SUM($2)], druid=[logical]) + DruidProject(gran=[TIME_FLOOR($0, 'P1D')], dim2=[$2], m1=[$5], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "timestamp_floor(\"__time\",'P1D',null,'UTC')", + "outputType" : "LONG" + } ], + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "d0", + "outputType" : "LONG" + }, { + "type" : "default", + "dimension" : "dim2", + "outputName" : "d1", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "doubleSum", + "name" : "a0", + "fieldName" : "m1" + } ], + "having" : { + "type" : "filter", + "filter" : { + "type" : "range", + "column" : "a0", + "matchValueType" : "LONG", + "lower" : 1, + "lowerOpen" : true + }, + "finalize" : true + }, + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "timestamp_floor(\"d0\",'P1M',null,'UTC')", + "outputType" : "LONG" + } ], + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "d1", + "outputName" : "_d0", + "outputType" : "STRING" + }, { + "type" : "default", + "dimension" : "v0", + "outputName" : "_d1", + "outputType" : "LONG" + } ], + "aggregations" : [ { + "type" : "doubleSum", + "name" : "_a0", + "fieldName" : "a0" + } ], + "limitSpec" : { + "type" : "default", + "columns" : [ { + "dimension" : "_d0", + "direction" : "ascending", + "dimensionOrder" : { + "type" : "lexicographic" + } + }, { + "dimension" : "_d1", + "direction" : "descending", + "dimensionOrder" : { + "type" : "numeric" + } + } ] + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq new file mode 100644 index 000000000000..fd6a883d75e6 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq @@ -0,0 +1,109 @@ +# testGroupByWithLiteralInSubqueryGrouping case-crc:933d8c09 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT + t1, t2 + FROM + ( SELECT + 'dummy' as t1, + CASE + WHEN + dim4 = 'b' + THEN dim4 + ELSE NULL + END AS t2 + FROM + numfoo + GROUP BY + dim4 + ) + GROUP BY + t1,t2 +; ++-------+----+ +| t1 | t2 | ++-------+----+ +| dummy | b | +| dummy | | ++-------+----+ +(2 rows) + +!ok +LogicalAggregate(group=[{0, 1}]) + LogicalProject(t1=['dummy'], t2=[CASE(=($0, 'b'), $0, null:VARCHAR)]) + LogicalAggregate(group=[{0}]) + LogicalProject(dim4=[$4]) + LogicalTableScan(table=[[druid, numfoo]]) + +!logicalPlan +DruidProject(t1=['dummy'], t2=[$0], druid=[logical]) + DruidAggregate(group=[{0}], druid=[logical]) + DruidProject(t2=[CASE(=($0, 'b'), $0, null:VARCHAR)], druid=[logical]) + DruidAggregate(group=[{4}], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim4", + "outputName" : "_d0", + "outputType" : "STRING" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "case_searched((\"_d0\" == 'b'),\"_d0\",null)", + "outputType" : "STRING" + } ], + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "postAggregations" : [ { + "type" : "expression", + "name" : "p0", + "expression" : "'dummy'", + "outputType" : "STRING" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq new file mode 100644 index 000000000000..b3f8b6caf1cc --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq @@ -0,0 +1,80 @@ +# testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin case-crc:a794c731 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT dim2, COUNT(*), COUNT(distinct dim1), COUNT(distinct cnt) FROM druid.foo GROUP BY dim2; ++------+--------+--------+--------+ +| dim2 | EXPR$1 | EXPR$2 | EXPR$3 | ++------+--------+--------+--------+ +| | 1 | 1 | 1 | +| a | 2 | 2 | 1 | +| abc | 1 | 1 | 1 | +| | 2 | 2 | 1 | ++------+--------+--------+--------+ +(4 rows) + +!ok +LogicalAggregate(group=[{0}], EXPR$1=[COUNT()], EXPR$2=[COUNT(DISTINCT $1)], EXPR$3=[COUNT(DISTINCT $2)]) + LogicalProject(dim2=[$2], dim1=[$1], cnt=[$4]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{2}], EXPR$1=[COUNT()], EXPR$2=[COUNT(DISTINCT $1)], EXPR$3=[COUNT(DISTINCT $4)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim2", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "count", + "name" : "a0" + }, { + "type" : "cardinality", + "name" : "a1", + "fields" : [ { + "type" : "default", + "dimension" : "dim1", + "outputName" : "dim1", + "outputType" : "STRING" + } ], + "byRow" : false, + "round" : true + }, { + "type" : "cardinality", + "name" : "a2", + "fields" : [ { + "type" : "default", + "dimension" : "cnt", + "outputName" : "cnt", + "outputType" : "LONG" + } ], + "byRow" : false, + "round" : true + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq new file mode 100644 index 000000000000..df807bbab138 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq @@ -0,0 +1,69 @@ +# testRepeatedIdenticalVirtualExpressionGrouping case-crc:e79279c4 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT + CASE dim1 WHEN NULL THEN FALSE ELSE TRUE END AS col_a, + CASE dim2 WHEN NULL THEN FALSE ELSE TRUE END AS col_b +FROM foo +GROUP BY 1, 2; ++-------+-------+ +| col_a | col_b | ++-------+-------+ +| true | true | ++-------+-------+ +(1 row) + +!ok +LogicalAggregate(group=[{0, 1}]) + LogicalProject(col_a=[true], col_b=[true]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(col_a=[$0], col_b=[true], druid=[logical]) + DruidAggregate(group=[{0}], druid=[logical]) + DruidProject(col_a=[true], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "1", + "outputType" : "LONG" + } ], + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "d0", + "outputType" : "LONG" + } ], + "postAggregations" : [ { + "type" : "expression", + "name" : "p0", + "expression" : "1", + "outputType" : "LONG" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq new file mode 100644 index 000000000000..df9d409828d7 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq @@ -0,0 +1,111 @@ +# testSubqueryTypeMismatchWithLiterals case-crc:ff3645c9 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT + dim1, + SUM(CASE WHEN sum_l1 = 0 THEN 1 ELSE 0 END) AS outer_l1 +from ( + select + dim1, + SUM(l1) as sum_l1 + from numfoo + group by dim1 +) +group by 1; ++------+----------+ +| dim1 | outer_l1 | ++------+----------+ +| | 0 | +| 1 | 0 | +| 10.1 | 0 | +| 2 | 1 | +| abc | 0 | +| def | 0 | ++------+----------+ +(6 rows) + +!ok +LogicalAggregate(group=[{0}], outer_l1=[SUM($1)]) + LogicalProject(dim1=[$0], $f1=[CASE(=($1, 0), 1, 0)]) + LogicalAggregate(group=[{0}], sum_l1=[SUM($1)]) + LogicalProject(dim1=[$1], l1=[$11]) + LogicalTableScan(table=[[druid, numfoo]]) + +!logicalPlan +DruidAggregate(group=[{0}], outer_l1=[COUNT() FILTER $1], druid=[logical]) + DruidProject(dim1=[$0], $f2=[IS TRUE(=($1, 0))], druid=[logical]) + DruidAggregate(group=[{1}], sum_l1=[SUM($11)], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim1", + "outputName" : "_d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "longSum", + "name" : "a0", + "fieldName" : "l1" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "_d0", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "filtered", + "aggregator" : { + "type" : "count", + "name" : "_a0" + }, + "filter" : { + "type" : "equals", + "column" : "a0", + "matchValueType" : "LONG", + "matchValue" : 0 + }, + "name" : "_a0" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq new file mode 100644 index 000000000000..04db9cbaf2ec --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq @@ -0,0 +1,201 @@ +# testWindowingWithScanAndSort case-crc:1d06dc93 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set enableWindowing true +!set maxScatterGatherBytes 9223372036854775807 +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set outputformat mysql +!use druidtest:/// +with t AS ( +SELECT + RANK() OVER (PARTITION BY m2 ORDER BY m2 ASC) + AS ranking, + COUNT(m1) as trend_score +FROM foo +GROUP BY m2,m1 LIMIT 10 +) +select ranking, trend_score from t ORDER BY trend_score; ++---------+-------------+ +| ranking | trend_score | ++---------+-------------+ +| 1 | 1 | +| 1 | 1 | +| 1 | 1 | +| 1 | 1 | +| 1 | 1 | +| 1 | 1 | ++---------+-------------+ +(6 rows) + +!ok +LogicalSort(sort0=[$1], dir0=[ASC]) + LogicalProject(ranking=[$0], trend_score=[$1]) + LogicalSort(fetch=[10]) + LogicalProject(ranking=[RANK() OVER (PARTITION BY $0 ORDER BY $0)], trend_score=[$2]) + LogicalAggregate(group=[{0, 1}], trend_score=[COUNT($1)]) + LogicalProject(m2=[$6], m1=[$5]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(ranking=[$2], trend_score=[$1], druid=[logical]) + DruidSort(sort0=[$1], dir0=[ASC], druid=[logical]) + DruidSort(fetch=[10], druid=[logical]) + DruidWindow(window#0=[window(partition {0} order by [0] aggs [RANK()])]) + DruidProject(m2=[$1], trend_score=[$2], druid=[logical]) + DruidAggregate(group=[{5, 6}], trend_score=[COUNT($5)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "windowOperator", + "dataSource" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "query", + "query" : { + "queryType" : "windowOperator", + "dataSource" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "m1", + "outputName" : "d0", + "outputType" : "FLOAT" + }, { + "type" : "default", + "dimension" : "m2", + "outputName" : "d1", + "outputType" : "DOUBLE" + } ], + "aggregations" : [ { + "type" : "filtered", + "aggregator" : { + "type" : "count", + "name" : "a0" + }, + "filter" : { + "type" : "not", + "field" : { + "type" : "null", + "column" : "m1" + } + }, + "name" : "a0" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "intervals" : { + "type" : "LegacySegmentSpec", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "outputSignature" : [ { + "name" : "d1", + "type" : "DOUBLE" + }, { + "name" : "a0", + "type" : "LONG" + }, { + "name" : "w0", + "type" : "LONG" + } ], + "operatorDefinition" : [ { + "type" : "naiveSort", + "columns" : [ { + "column" : "d1", + "direction" : "ASC" + } ] + }, { + "type" : "naivePartition", + "partitionColumns" : [ "d1" ] + }, { + "type" : "window", + "processor" : { + "type" : "rank", + "group" : [ "d1" ], + "outputColumn" : "w0", + "asPercent" : false + } + } ], + "leafOperators" : [ ], + "granularity" : { + "type" : "all" + } + } + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "limit" : 10, + "columns" : [ "a0", "d1", "w0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "DOUBLE", "LONG" ], + "granularity" : { + "type" : "all" + } + } + }, + "intervals" : { + "type" : "LegacySegmentSpec", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "outputSignature" : [ { + "name" : "w0", + "type" : "LONG" + }, { + "name" : "a0", + "type" : "LONG" + } ], + "operatorDefinition" : [ { + "type" : "naiveSort", + "columns" : [ { + "column" : "a0", + "direction" : "ASC" + } ] + }, { + "type" : "scan", + "timeRange" : null, + "filter" : null, + "offsetLimit" : null, + "projectedColumns" : [ "w0", "a0" ], + "virtualColumns" : null, + "ordering" : null + } ], + "leafOperators" : [ { + "type" : "scan", + "timeRange" : null, + "filter" : null, + "offsetLimit" : { + "offset" : 0, + "limit" : 9223372036854775807 + }, + "projectedColumns" : [ "a0", "w0" ], + "virtualColumns" : null, + "ordering" : null + } ], + "granularity" : { + "type" : "all" + } +} +!nativePlan From 6f547e10742d3af7dae52aabcbc22eec486cc994 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Mon, 15 Apr 2024 11:46:20 +0000 Subject: [PATCH 02/24] updates --- .../calcite/planner/CalciteRulesManager.java | 17 +++ .../sql/calcite/planner/QueryHandler.java | 1 - .../druid/quidem/DruidAvaticaTestDriver.java | 24 +++- .../druid/quidem/DruidConnectionExtras.java | 43 ++++++ .../quidem/DruidQuidemCommandHandler.java | 8 +- .../apache/druid/quidem/DynamicComposite.java | 61 ++++++++ .../druid/quidem/DynamicCompositeTest.java | 48 +++++++ .../druid/sql/calcite/CalciteQueryTest.java | 83 +++++++++++ .../asd.iq | 34 ----- .../decoupled.iq | 96 +++++++++++++ .../join.iq | 131 ++++++++++++++++++ .../{a.iq => simple.iq} | 4 +- 12 files changed, 503 insertions(+), 47 deletions(-) create mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java create mode 100644 sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java delete mode 100644 sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq create mode 100644 sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/decoupled.iq create mode 100644 sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/join.iq rename sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/{a.iq => simple.iq} (92%) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java index e7b909b5327c..85a768e1fa8b 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java @@ -39,6 +39,7 @@ import org.apache.calcite.rel.rules.DateRangeRules; import org.apache.calcite.rel.rules.JoinPushThroughJoinRule; import org.apache.calcite.rel.rules.PruneEmptyRules; +import org.apache.calcite.runtime.Hook; import org.apache.calcite.sql.SqlExplainFormat; import org.apache.calcite.sql.SqlExplainLevel; import org.apache.calcite.sql2rel.RelDecorrelator; @@ -239,17 +240,20 @@ public List programs(final PlannerContext plannerContext) return ImmutableList.of( Programs.sequence( druidPreProgram, + SaveLogicalPlanProgram.INSTANCE, Programs.ofRules(druidConventionRuleSet(plannerContext)), new LoggingProgram("After Druid volcano planner program", isDebug) ), Programs.sequence( bindablePreProgram, + SaveLogicalPlanProgram.INSTANCE, Programs.ofRules(bindableConventionRuleSet(plannerContext)), new LoggingProgram("After bindable volcano planner program", isDebug) ), Programs.sequence( druidPreProgram, buildDecoupledLogicalOptimizationProgram(plannerContext), + SaveLogicalPlanProgram.INSTANCE, new LoggingProgram("After DecoupledLogicalOptimizationProgram program", isDebug), Programs.ofRules(logicalConventionRuleSet(plannerContext)), new LoggingProgram("After logical volcano planner program", isDebug) @@ -368,6 +372,19 @@ private Program buildReductionProgram(final PlannerContext plannerContext, final return Programs.of(builder.build(), true, DefaultRelMetadataProvider.INSTANCE); } + private static class SaveLogicalPlanProgram implements Program { + + public static SaveLogicalPlanProgram INSTANCE = new SaveLogicalPlanProgram(); + + @Override + public RelNode run(RelOptPlanner planner, RelNode rel, RelTraitSet requiredOutputTraits, + List materializations, List lattices) + { + Hook.TRIMMED.run(rel); + return rel; + } + } + private static class LoggingProgram implements Program { private final String stage; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java index eca1bc79946d..8a7bf4a6f742 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java @@ -548,7 +548,6 @@ protected PlannerResult planWithDruidConvention() throws ValidationException RelNode parameterized = possiblyLimitedRoot.rel.accept( new RelParameterizerShuttle(plannerContext) ); - Hook.TRIMMED.run(parameterized); QueryValidations.validateLogicalQueryForDruid(handlerContext.plannerContext(), parameterized); CalcitePlanner planner = handlerContext.planner(); diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java index 2323b2408f3c..48b4bed58587 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java @@ -75,7 +75,6 @@ import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URLEncodedUtils; import org.eclipse.jetty.server.Server; - import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -123,7 +122,6 @@ public Connection connect(String url, Properties info) throws SQLException ) ); - try { AvaticaJettyServer server = ci.framework.injector().getInstance(AvaticaJettyServer.class); return server.getConnection(info); @@ -150,9 +148,16 @@ public DruidSchemaCatalog getLookupNodeService(QueryRunnerFactoryConglomerate co @Provides @LazySingleton - public AvaticaJettyServer getAvaticaServer(DruidMeta druidMeta, Closer closer) throws Exception + public DruidConnectionExtras getConnectionExtras(ObjectMapper objectMapper) { + return new DruidConnectionExtras.DruidConnectionExtrasImpl(objectMapper); + } + + + @Provides + @LazySingleton + public AvaticaJettyServer getAvaticaServer(DruidMeta druidMeta, Closer closer, DruidConnectionExtras druidConnectionExtras) throws Exception { - AvaticaJettyServer avaticaJettyServer = new AvaticaJettyServer(druidMeta); + AvaticaJettyServer avaticaJettyServer = new AvaticaJettyServer(druidMeta, druidConnectionExtras); closer.register(avaticaJettyServer); return avaticaJettyServer; } @@ -169,8 +174,9 @@ static class AvaticaJettyServer implements Closeable final DruidMeta druidMeta; final Server server; final String url; + final DruidConnectionExtras connectionExtras; - AvaticaJettyServer(final DruidMeta druidMeta) throws Exception + AvaticaJettyServer(final DruidMeta druidMeta, DruidConnectionExtras druidConnectionExtras) throws Exception { this.druidMeta = druidMeta; server = new Server(0); @@ -180,11 +186,17 @@ static class AvaticaJettyServer implements Closeable "jdbc:avatica:remote:url=%s", new URIBuilder(server.getURI()).setPath(DruidAvaticaJsonHandler.AVATICA_PATH).build() ); + connectionExtras = druidConnectionExtras; } public Connection getConnection(Properties info) throws SQLException { - return DriverManager.getConnection(url, info); + Connection realConnection = DriverManager.getConnection(url, info); + Connection proxyConnection = DynamicComposite.make( + realConnection, Connection.class, + connectionExtras, DruidConnectionExtras.class + ); + return proxyConnection; } @Override diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java b/sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java new file mode 100644 index 000000000000..2b75f82122c1 --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public interface DruidConnectionExtras +{ + ObjectMapper getObjectMapper(); + + public class DruidConnectionExtrasImpl implements DruidConnectionExtras + { + private final ObjectMapper objectMapper; + + public DruidConnectionExtrasImpl(ObjectMapper objectMapper) + { + this.objectMapper = objectMapper; + } + + @Override + public ObjectMapper getObjectMapper() + { + return objectMapper; + } + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java index 10409bce4ea6..168692f09126 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java @@ -31,9 +31,7 @@ import org.apache.calcite.sql.SqlExplainFormat; import org.apache.calcite.sql.SqlExplainLevel; import org.apache.calcite.util.Util; -import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.query.Query; -import org.apache.druid.segment.TestHelper; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; import org.apache.druid.sql.calcite.util.QueryLogHook; @@ -128,16 +126,18 @@ static class NativePlanCommand extends AbstractPlanCommand @Override protected void executeExplain(Context x) throws Exception { - QueryLogHook qlh = new QueryLogHook(new DefaultObjectMapper()); + DruidConnectionExtras connectionExtras = (DruidConnectionExtras) x.connection(); + ObjectMapper objectMapper = connectionExtras.getObjectMapper(); + QueryLogHook qlh = new QueryLogHook(objectMapper); qlh.logQueriesForGlobal( () -> { executeQuery(x); } ); +// BaseCalciteQueryTest conn = x.connection().unwrap(BaseCalciteQueryTest.class); List> queries = qlh.getRecordedQueries(); - ObjectMapper objectMapper = TestHelper.JSON_MAPPER; queries = queries .stream() .map(q -> BaseCalciteQueryTest.recursivelyClearContext(q, objectMapper)) diff --git a/sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java b/sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java new file mode 100644 index 000000000000..ec4605e6fc6c --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +public class DynamicComposite implements InvocationHandler +{ + + @SuppressWarnings("unchecked") + public static T make(T base, Class baseClass, E ext, Class extClass) + { + return (T) Proxy.newProxyInstance( + base.getClass().getClassLoader(), + new Class[] {baseClass, extClass}, + new DynamicComposite(base, baseClass, ext, extClass) + ); + } + + private final T base; + private final Class baseClass; + private final E ext; + private final Class extClass; + + DynamicComposite(T base, Class baseClass, E ext, Class extClass) + { + this.base = base; + this.baseClass = baseClass; + this.ext = ext; + this.extClass = extClass; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable + { + if (method.getDeclaringClass() == extClass) { + return method.invoke(ext, args); + } else { + return method.invoke(base, args); + } + } +} diff --git a/sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java b/sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java new file mode 100644 index 000000000000..2a018a95a0b6 --- /dev/null +++ b/sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.quidem; + +import org.junit.jupiter.api.Test; + +import java.util.HashSet; +import java.util.Set; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +public class DynamicCompositeTest +{ + @Test + public void testCompose() + { + HashSet set = new HashSet(); + Function sq = x -> x * x; + Set composite = DynamicComposite.make(set, Set.class, sq, Function.class); + composite.add(1); + assertEquals(1, set.size()); + assertEquals(1, composite.size()); + + assertInstanceOf(Function.class, composite); + Function sq2 = (Function) composite; + assertEquals(9, sq.apply(3)); + + } +} diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 44d5dcbf3e67..24122531f0d7 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -12281,6 +12281,89 @@ public void testRequireTimeConditionPositive2() ); } + + @Test + public void testRequireTimeConditionPositive13() + { + // Cannot vectorize next test due to extraction dimension spec. + cannotVectorize(); + + // semi-join requires time condition on both left and right query + testQuery( + PLANNER_CONFIG_DEFAULT , + "with v as (\n" + + " select cityName, count(1) as cnt from wikipedia\n" + + " where cityName = 'New York'\n" + + " group by 1\n" + + " order by 1 asc\n" + + "),\n" + + "e as (\n" + + " select cityName, count(1) as cnt from wikipedia\n" + + " group by 1\n" + + " order by 1 asc\n" + + ")\n" + + "select v.*,e.* from v inner join e on (e.cityName = v.cityName)\n" + , + CalciteTests.REGULAR_USER_AUTH_RESULT, + ImmutableList.of( + Druids.newTimeseriesQueryBuilder() + .dataSource( + join( + new TableDataSource(CalciteTests.DATASOURCE1), + new QueryDataSource( + GroupByQuery.builder() + .setDataSource(CalciteTests.DATASOURCE1) + .setInterval( + querySegmentSpec( + Intervals.utc( + DateTimes.of("2000-01-01").getMillis(), + JodaUtils.MAX_INSTANT + ) + ) + ) + .setDimFilter(not(equality("dim1", "", ColumnType.STRING))) + .setGranularity(Granularities.ALL) + .setDimensions( + new ExtractionDimensionSpec( + "dim1", + "d0", + ColumnType.STRING, + new SubstringDimExtractionFn(0, 1) + ) + ) + .setContext(QUERY_CONTEXT_DEFAULT) + .build() + ), + "j0.", + equalsCondition( + makeExpression("substring(\"dim2\", 0, 1)"), + DruidExpression.ofColumn(ColumnType.STRING, "j0.d0") + ), + JoinType.INNER + ) + ) + .intervals( + querySegmentSpec( + Intervals.utc( + DateTimes.of("2000-01-01").getMillis(), + JodaUtils.MAX_INSTANT + ) + ) + ) + .granularity(Granularities.ALL) + .aggregators(aggregators(new CountAggregatorFactory("a0"))) + .context(QUERY_CONTEXT_DEFAULT) + .build() + ), + ImmutableList.of( + new Object[]{3L} + ) + ); + } + + + + // __time >= x remains in the join condition @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) @Test diff --git a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq deleted file mode 100644 index f75543609e04..000000000000 --- a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/asd.iq +++ /dev/null @@ -1,34 +0,0 @@ -!use druidtest:/// -!set outputformat mysql - - -select 1+5; -+--------+ -| EXPR$0 | -+--------+ -| 6 | -+--------+ -(1 row) - -!ok - -select cityName, countryName from wikipedia where cityName='New York' limit 1; -+----------+---------------+ -| cityName | countryName | -+----------+---------------+ -| New York | United States | -+----------+---------------+ -(1 row) - -!ok - - -select cityName, countryName from wikipedia where cityName is null limit 1; -+----------+-------------+ -| cityName | countryName | -+----------+-------------+ -| | | -+----------+-------------+ -(1 row) - -!ok diff --git a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/decoupled.iq b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/decoupled.iq new file mode 100644 index 000000000000..be52c7c4c65b --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/decoupled.iq @@ -0,0 +1,96 @@ +!set plannerStrategy DECOUPLED +!use druidtest://?numMergeBuffers=3 +!set outputformat mysql + +select cityName, count(case when delta > 0 then channel end) as cnt, count(1) as aall +from wikipedia +where cityName in ('New York', 'Aarhus') +group by 1 +order by 1; ++----------+-----+------+ +| cityName | cnt | aall | ++----------+-----+------+ +| Aarhus | 0 | 1 | +| New York | 7 | 13 | ++----------+-----+------+ +(2 rows) + +!ok +LogicalSort(sort0=[$0], dir0=[ASC]) + LogicalAggregate(group=[{0}], cnt=[COUNT($1)], aall=[COUNT()]) + LogicalProject(cityName=[$2], $f1=[CASE(>($17, 0), $1, null:VARCHAR)]) + LogicalFilter(condition=[OR(=($2, 'New York'), =($2, 'Aarhus'))]) + LogicalTableScan(table=[[druid, wikipedia]]) + +!convertedPlan +LogicalSort(sort0=[$0], dir0=[ASC]) + LogicalAggregate(group=[{0}], cnt=[COUNT($1) FILTER $2], aall=[COUNT()]) + LogicalProject(cityName=[$2], channel=[$1], $f3=[IS TRUE(>($17, 0))]) + LogicalFilter(condition=[SEARCH($2, Sarg['Aarhus':VARCHAR(8), 'New York':VARCHAR(8)]:VARCHAR(8))]) + LogicalTableScan(table=[[druid, wikipedia]]) + +!logicalPlan +DruidAggregate(group=[{0}], cnt=[COUNT($1) FILTER $2], aall=[COUNT()], druid=[logical]) + DruidProject(cityName=[$2], channel=[$1], $f3=[IS TRUE(>($17, 0))], druid=[logical]) + DruidFilter(condition=[SEARCH($2, Sarg['Aarhus':VARCHAR(8), 'New York':VARCHAR(8)]:VARCHAR(8))]) + DruidTableScan(table=[[druid, wikipedia]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "wikipedia" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "filter" : { + "type" : "inType", + "column" : "cityName", + "matchValueType" : "STRING", + "sortedValues" : [ "Aarhus", "New York" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "cityName", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "filtered", + "aggregator" : { + "type" : "count", + "name" : "a0" + }, + "filter" : { + "type" : "and", + "fields" : [ { + "type" : "not", + "field" : { + "type" : "null", + "column" : "channel" + } + }, { + "type" : "range", + "column" : "delta", + "matchValueType" : "LONG", + "lower" : 0, + "lowerOpen" : true + } ] + }, + "name" : "a0" + }, { + "type" : "count", + "name" : "a1" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan + diff --git a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/join.iq b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/join.iq new file mode 100644 index 000000000000..e1ae27eef0d2 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/join.iq @@ -0,0 +1,131 @@ +!use druidtest://?numMergeBuffers=3 +!set outputformat mysql + +with v as ( + select cityName, count(1) as cnt from wikipedia + where cityName = 'New York' + group by 1 + order by 1 asc +), +e as ( + select cityName, count(1) as cnt from wikipedia + group by 1 + order by 1 asc +) +select v.*,e.* from v inner join e on (e.cityName = v.cityName); ++----------+-----+-----------+------+ +| cityName | cnt | cityName0 | cnt0 | ++----------+-----+-----------+------+ +| New York | 13 | New York | 13 | ++----------+-----+-----------+------+ +(1 row) + +!ok +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "wikipedia" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "filter" : { + "type" : "equals", + "column" : "cityName", + "matchValueType" : "STRING", + "matchValue" : "New York" + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "cityName", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "wikipedia" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "cityName", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"d0\" == \"j0.d0\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "a0", "d0", "j0.a0", "j0.d0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING", "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan +LogicalProject(cityName=[$0], cnt=[$1], cityName0=[$2], cnt0=[$3]) + LogicalJoin(condition=[=($2, $0)], joinType=[inner]) + LogicalAggregate(group=[{0}], cnt=[COUNT()]) + LogicalProject(cityName=[$2]) + LogicalFilter(condition=[=($2, 'New York')]) + LogicalTableScan(table=[[druid, wikipedia]]) + LogicalAggregate(group=[{0}], cnt=[COUNT()]) + LogicalProject(cityName=[$2]) + LogicalTableScan(table=[[druid, wikipedia]]) + +!convertedPlan +LogicalJoin(condition=[=($2, $0)], joinType=[inner]) + LogicalAggregate(group=[{0}], cnt=[COUNT()]) + LogicalFilter(condition=[=($0, 'New York')]) + LogicalProject(cityName=[$2]) + LogicalTableScan(table=[[druid, wikipedia]]) + LogicalAggregate(group=[{0}], cnt=[COUNT()]) + LogicalProject(cityName=[$2]) + LogicalTableScan(table=[[druid, wikipedia]]) + +!logicalPlan diff --git a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/a.iq b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/simple.iq similarity index 92% rename from sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/a.iq rename to sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/simple.iq index e1487433f2e0..92ce8c261726 100644 --- a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/a.iq +++ b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/simple.iq @@ -47,8 +47,8 @@ select cityName, countryName from wikipedia where cityName='New York' limit 1; } !nativePlan LogicalSort(fetch=[1]) - LogicalProject(cityName=[$2], countryName=[$5]) - LogicalFilter(condition=[=($2, 'New York')]) + LogicalFilter(condition=[=($0, 'New York')]) + LogicalProject(cityName=[$2], countryName=[$5]) LogicalTableScan(table=[[druid, wikipedia]]) !logicalPlan From 9db1aee50531c3e118a3ca0a99286b8d47efda79 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 07:41:41 +0000 Subject: [PATCH 03/24] update --- quidem | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/quidem b/quidem index 6b18187ecf6f..a68e08b3cfc1 100755 --- a/quidem +++ b/quidem @@ -31,13 +31,16 @@ OPTS+=" -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugin.surefire.SurefirePl OPTS+=" -pl sql -Dtest=SqlQuidemTest" OPTS+=" org.apache.maven.plugins:maven-surefire-plugin:test" -if [ "$1" == "-h" ];then -cat << EOF +case "$1" in + -h|--help) + cat << EOF Run SqlQuidemTest tests. + -q quiet (recommened) -Dquidem.overwrite enables overwrite mode -Dquidem.filter=*join* runs only tests matching path expression EOF exit 1 -fi + ;; +esac exec mvn "$@" $OPTS From 3bc928e875674f507fd3db6216041d7f8eaa5d85 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 07:48:45 +0000 Subject: [PATCH 04/24] missed update --- .../druid/sql/calcite/CalciteQueryTest.java | 83 ------------------- ...DistinctWithGroupingAndOtherAggregators.iq | 5 +- .../testGroupByLimitPushdownExtraction.iq | 11 +-- .../testGroupBySortPushDown.iq | 6 +- ...estGroupByWithLiteralInSubqueryGrouping.iq | 8 +- ...ithGroupingAndOtherAggregatorsUsingJoin.iq | 5 +- ...eatedIdenticalVirtualExpressionGrouping.iq | 7 +- .../testSubqueryTypeMismatchWithLiterals.iq | 9 +- .../testWindowingWithScanAndSort.iq | 10 +-- 9 files changed, 30 insertions(+), 114 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 24122531f0d7..44d5dcbf3e67 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -12281,89 +12281,6 @@ public void testRequireTimeConditionPositive2() ); } - - @Test - public void testRequireTimeConditionPositive13() - { - // Cannot vectorize next test due to extraction dimension spec. - cannotVectorize(); - - // semi-join requires time condition on both left and right query - testQuery( - PLANNER_CONFIG_DEFAULT , - "with v as (\n" - + " select cityName, count(1) as cnt from wikipedia\n" - + " where cityName = 'New York'\n" - + " group by 1\n" - + " order by 1 asc\n" - + "),\n" - + "e as (\n" - + " select cityName, count(1) as cnt from wikipedia\n" - + " group by 1\n" - + " order by 1 asc\n" - + ")\n" - + "select v.*,e.* from v inner join e on (e.cityName = v.cityName)\n" - , - CalciteTests.REGULAR_USER_AUTH_RESULT, - ImmutableList.of( - Druids.newTimeseriesQueryBuilder() - .dataSource( - join( - new TableDataSource(CalciteTests.DATASOURCE1), - new QueryDataSource( - GroupByQuery.builder() - .setDataSource(CalciteTests.DATASOURCE1) - .setInterval( - querySegmentSpec( - Intervals.utc( - DateTimes.of("2000-01-01").getMillis(), - JodaUtils.MAX_INSTANT - ) - ) - ) - .setDimFilter(not(equality("dim1", "", ColumnType.STRING))) - .setGranularity(Granularities.ALL) - .setDimensions( - new ExtractionDimensionSpec( - "dim1", - "d0", - ColumnType.STRING, - new SubstringDimExtractionFn(0, 1) - ) - ) - .setContext(QUERY_CONTEXT_DEFAULT) - .build() - ), - "j0.", - equalsCondition( - makeExpression("substring(\"dim2\", 0, 1)"), - DruidExpression.ofColumn(ColumnType.STRING, "j0.d0") - ), - JoinType.INNER - ) - ) - .intervals( - querySegmentSpec( - Intervals.utc( - DateTimes.of("2000-01-01").getMillis(), - JodaUtils.MAX_INSTANT - ) - ) - ) - .granularity(Granularities.ALL) - .aggregators(aggregators(new CountAggregatorFactory("a0"))) - .context(QUERY_CONTEXT_DEFAULT) - .build() - ), - ImmutableList.of( - new Object[]{3L} - ) - ); - } - - - - // __time >= x remains in the join condition @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) @Test diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq index 5dd3bc1c2603..c6fc5658ddbb 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq @@ -19,9 +19,8 @@ SELECT dim2, SUM(cnt), COUNT(distinct dim1) FROM druid.foo GROUP BY dim2; (4 rows) !ok -LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)], EXPR$2=[COUNT(DISTINCT $2)]) - LogicalProject(dim2=[$2], cnt=[$4], dim1=[$1]) - LogicalTableScan(table=[[druid, foo]]) +LogicalAggregate(group=[{2}], EXPR$1=[SUM($4)], EXPR$2=[COUNT(DISTINCT $1)]) + LogicalTableScan(table=[[druid, foo]]) !logicalPlan DruidAggregate(group=[{2}], EXPR$1=[SUM($4)], EXPR$2=[COUNT(DISTINCT $1)], druid=[logical]) diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq index 60734ddbeed8..8562edf7fc28 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq @@ -17,11 +17,12 @@ SELECT dim4, substring(dim5, 1, 1), count(*) FROM druid.numfoo WHERE dim4 = 'a' (2 rows) !ok -LogicalSort(fetch=[2]) - LogicalAggregate(group=[{0, 1}], EXPR$2=[COUNT()]) - LogicalProject(dim4=[$4], EXPR$1=[SUBSTRING($5, 1, 1)]) - LogicalFilter(condition=[=($4, 'a')]) - LogicalTableScan(table=[[druid, numfoo]]) +LogicalProject(dim4=[CAST('a':VARCHAR):VARCHAR], EXPR$1=[$0], EXPR$2=[$1]) + LogicalSort(fetch=[2]) + LogicalAggregate(group=[{0}], EXPR$2=[COUNT()]) + LogicalProject(EXPR$1=[SUBSTRING($5, 1, 1)]) + LogicalFilter(condition=[=($4, 'a')]) + LogicalTableScan(table=[[druid, numfoo]]) !logicalPlan DruidProject(dim4=[CAST('a':VARCHAR):VARCHAR], EXPR$1=[$0], EXPR$2=[$1], druid=[logical]) diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq index 17e7be5b364b..6ec000ab2d8d 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq @@ -19,9 +19,9 @@ SELECT dim2, dim1, SUM(cnt) FROM druid.foo GROUP BY dim2, dim1 ORDER BY dim1 LIM (4 rows) !ok -LogicalSort(sort0=[$1], dir0=[ASC], fetch=[4]) - LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)]) - LogicalProject(dim2=[$2], dim1=[$1], cnt=[$4]) +LogicalProject(dim2=[$1], dim1=[$0], EXPR$2=[$2]) + LogicalSort(sort0=[$0], dir0=[ASC], fetch=[4]) + LogicalAggregate(group=[{1, 2}], EXPR$2=[SUM($4)]) LogicalTableScan(table=[[druid, foo]]) !logicalPlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq index fd6a883d75e6..cc80c384e2cd 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq @@ -35,10 +35,10 @@ SELECT (2 rows) !ok -LogicalAggregate(group=[{0, 1}]) - LogicalProject(t1=['dummy'], t2=[CASE(=($0, 'b'), $0, null:VARCHAR)]) - LogicalAggregate(group=[{0}]) - LogicalProject(dim4=[$4]) +LogicalProject(t1=['dummy'], t2=[$0]) + LogicalAggregate(group=[{0}]) + LogicalProject(t2=[CASE(=($0, 'b'), $0, null:VARCHAR)]) + LogicalAggregate(group=[{4}]) LogicalTableScan(table=[[druid, numfoo]]) !logicalPlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq index b3f8b6caf1cc..d3446d3ddc51 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq @@ -19,9 +19,8 @@ SELECT dim2, COUNT(*), COUNT(distinct dim1), COUNT(distinct cnt) FROM druid.foo (4 rows) !ok -LogicalAggregate(group=[{0}], EXPR$1=[COUNT()], EXPR$2=[COUNT(DISTINCT $1)], EXPR$3=[COUNT(DISTINCT $2)]) - LogicalProject(dim2=[$2], dim1=[$1], cnt=[$4]) - LogicalTableScan(table=[[druid, foo]]) +LogicalAggregate(group=[{2}], EXPR$1=[COUNT()], EXPR$2=[COUNT(DISTINCT $1)], EXPR$3=[COUNT(DISTINCT $4)]) + LogicalTableScan(table=[[druid, foo]]) !logicalPlan DruidAggregate(group=[{2}], EXPR$1=[COUNT()], EXPR$2=[COUNT(DISTINCT $1)], EXPR$3=[COUNT(DISTINCT $4)], druid=[logical]) diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq index df807bbab138..9727a7427c37 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq @@ -20,9 +20,10 @@ GROUP BY 1, 2; (1 row) !ok -LogicalAggregate(group=[{0, 1}]) - LogicalProject(col_a=[true], col_b=[true]) - LogicalTableScan(table=[[druid, foo]]) +LogicalProject(col_a=[$0], col_b=[true]) + LogicalAggregate(group=[{0}]) + LogicalProject(col_a=[true]) + LogicalTableScan(table=[[druid, foo]]) !logicalPlan DruidProject(col_a=[$0], col_b=[true], druid=[logical]) diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq index df9d409828d7..d8fc18f942c1 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq @@ -31,11 +31,10 @@ group by 1; (6 rows) !ok -LogicalAggregate(group=[{0}], outer_l1=[SUM($1)]) - LogicalProject(dim1=[$0], $f1=[CASE(=($1, 0), 1, 0)]) - LogicalAggregate(group=[{0}], sum_l1=[SUM($1)]) - LogicalProject(dim1=[$1], l1=[$11]) - LogicalTableScan(table=[[druid, numfoo]]) +LogicalAggregate(group=[{0}], outer_l1=[COUNT() FILTER $1]) + LogicalProject(dim1=[$0], $f2=[IS TRUE(=($1, 0))]) + LogicalAggregate(group=[{1}], sum_l1=[SUM($11)]) + LogicalTableScan(table=[[druid, numfoo]]) !logicalPlan DruidAggregate(group=[{0}], outer_l1=[COUNT() FILTER $1], druid=[logical]) diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq index 04db9cbaf2ec..34efc5ba2f0c 100644 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq @@ -30,12 +30,12 @@ select ranking, trend_score from t ORDER BY trend_score; (6 rows) !ok -LogicalSort(sort0=[$1], dir0=[ASC]) - LogicalProject(ranking=[$0], trend_score=[$1]) +LogicalProject(ranking=[$2], trend_score=[$1]) + LogicalSort(sort0=[$1], dir0=[ASC]) LogicalSort(fetch=[10]) - LogicalProject(ranking=[RANK() OVER (PARTITION BY $0 ORDER BY $0)], trend_score=[$2]) - LogicalAggregate(group=[{0, 1}], trend_score=[COUNT($1)]) - LogicalProject(m2=[$6], m1=[$5]) + LogicalWindow(window#0=[window(partition {0} order by [0] aggs [RANK()])]) + LogicalProject(m2=[$1], trend_score=[$2]) + LogicalAggregate(group=[{5, 6}], trend_score=[COUNT($5)]) LogicalTableScan(table=[[druid, foo]]) !logicalPlan From b637d53017578dab71ce6fdb6383d1cdf1dca616 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 08:06:31 +0000 Subject: [PATCH 05/24] disable quidem tests in sqlcompatible=false --- .../java/org/apache/druid/quidem/SqlQuidemTest.java | 10 ++++++++++ .../java/org/apache/druid/sql/calcite/QTestCase.java | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java b/sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java index 9e6a965891ce..d1922472d7f3 100644 --- a/sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java +++ b/sql/src/test/java/org/apache/druid/quidem/SqlQuidemTest.java @@ -19,10 +19,20 @@ package org.apache.druid.quidem; +import org.apache.druid.common.config.NullHandling; +import org.junit.jupiter.api.condition.EnabledIf; + import java.io.File; +@EnabledIf(value = "enabled", disabledReason = "These tests are only run in SqlCompatible mode!") public class SqlQuidemTest extends DruidQuidemTestBase { + public static boolean enabled() + { + NullHandling.initializeForTests(); + return NullHandling.sqlCompatible(); + } + public SqlQuidemTest() { super(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java b/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java index 765c3f9b7303..7bb4fcd61333 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java @@ -22,6 +22,7 @@ import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; import com.google.common.io.Files; +import org.apache.druid.common.config.NullHandling; import org.apache.druid.java.util.common.FileUtils; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.quidem.DruidQTestInfo; @@ -34,6 +35,8 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + public class QTestCase { private StringBuffer sb; @@ -59,6 +62,7 @@ public QueryRunStep toRunner() @Override public void run() { + assumeTrue(NullHandling.sqlCompatible(), "Quidem tests are only run in sql-compatible mode!"); try { if (DruidQuidemRunner.isOverwrite()) { writeCaseTo(testInfo.getIQFile()); From f840e9ffccc97867664bbab97e1d53edeb0d5cdf Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 08:57:42 +0000 Subject: [PATCH 06/24] make join opts named --- .../sql/calcite/BaseCalciteQueryTest.java | 27 ++++++++++--------- .../druid/sql/calcite/CalciteQueryTest.java | 20 +++++++------- .../sql/calcite/DecoupledTestConfig.java | 5 ++++ 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java index 854ac2215985..58ff9e4ff1e3 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java @@ -124,6 +124,7 @@ import org.junit.Assert; import org.junit.internal.matchers.ThrowableMessageMatcher; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.extension.RegisterExtension; import javax.annotation.Nullable; @@ -1394,51 +1395,51 @@ public static Object[] provideQueryContexts() { return new Object[] { // default behavior - QUERY_CONTEXT_DEFAULT, + Named.of("default", QUERY_CONTEXT_DEFAULT), // all rewrites enabled - new ImmutableMap.Builder() + Named.of("all_enabled", new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), + .build()), // filter-on-value-column rewrites disabled, everything else enabled - new ImmutableMap.Builder() + Named.of("filter-on-value-column_disabled", new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), + .build()), // filter rewrites fully disabled, join-to-filter enabled - new ImmutableMap.Builder() + Named.of("join-to-filter", new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), + .build()), // filter rewrites disabled, but value column filters still set to true // (it should be ignored and this should // behave the same as the previous context) - new ImmutableMap.Builder() + Named.of("filter-rewrites-disabled", new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), + .build()), // filter rewrites fully enabled, join-to-filter disabled - new ImmutableMap.Builder() + Named.of("filter-rewrites", new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) - .build(), + .build()), // all rewrites disabled - new ImmutableMap.Builder() + Named.of("all_disabled", new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) - .build(), + .build()), }; } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 44d5dcbf3e67..61bb560a63e9 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -6928,7 +6928,7 @@ public void testApproxCountDistinctBuiltin() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testExactCountDistinctWithGroupingAndOtherAggregators() { @@ -6983,7 +6983,7 @@ public void testExactCountDistinctWithGroupingAndOtherAggregators() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin() { @@ -8182,7 +8182,7 @@ public void testRegexpLikeFilter() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testGroupBySortPushDown() { @@ -8278,7 +8278,7 @@ public void testGroupByLimitPushDownWithHavingOnLong() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByLimitPushdownExtraction() { @@ -8725,7 +8725,7 @@ public void testGroupByFloor() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @SqlTestFrameworkConfig(numMergeBuffers = 3) @Test public void testQueryWithSelectProjectAndIdentityProjectDoesNotRename() @@ -10570,7 +10570,7 @@ public void testGroupByTimeAndOtherDimension() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim() { @@ -12705,7 +12705,7 @@ public void testNvlColumns() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByWithLiteralInSubqueryGrouping() { @@ -12894,7 +12894,7 @@ public void testQueryContextOuterLimit() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testRepeatedIdenticalVirtualExpressionGrouping() { @@ -14470,7 +14470,7 @@ public void testGreatestFunctionForStringWithIsNull() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) @Test public void testSubqueryTypeMismatchWithLiterals() { @@ -15192,7 +15192,7 @@ public void testScanAndSortCanGetSchemaFromScanQuery() .run(); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(quidem2 = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @Test public void testWindowingWithScanAndSort() { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java index 2ac031f4e08b..d0f3e6da177f 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java @@ -49,6 +49,11 @@ */ boolean quidem() default false; + /** + * Use alternate quidem test for testcase + */ + NativeQueryIgnore quidem2() default NativeQueryIgnore.NONE; + enum NativeQueryIgnore { From b0a9991152c0f54e3e163e14d8c2c33d3f4b2d08 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 09:06:22 +0000 Subject: [PATCH 07/24] some stuff --- .../druid/sql/calcite/CalciteQueryTest.java | 20 ++++----- ...DecoupledPlanningCalciteJoinQueryTest.java | 41 ++++--------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 61bb560a63e9..44d5dcbf3e67 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -6928,7 +6928,7 @@ public void testApproxCountDistinctBuiltin() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testExactCountDistinctWithGroupingAndOtherAggregators() { @@ -6983,7 +6983,7 @@ public void testExactCountDistinctWithGroupingAndOtherAggregators() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin() { @@ -8182,7 +8182,7 @@ public void testRegexpLikeFilter() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testGroupBySortPushDown() { @@ -8278,7 +8278,7 @@ public void testGroupByLimitPushDownWithHavingOnLong() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByLimitPushdownExtraction() { @@ -8725,7 +8725,7 @@ public void testGroupByFloor() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @SqlTestFrameworkConfig(numMergeBuffers = 3) @Test public void testQueryWithSelectProjectAndIdentityProjectDoesNotRename() @@ -10570,7 +10570,7 @@ public void testGroupByTimeAndOtherDimension() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim() { @@ -12705,7 +12705,7 @@ public void testNvlColumns() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByWithLiteralInSubqueryGrouping() { @@ -12894,7 +12894,7 @@ public void testQueryContextOuterLimit() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testRepeatedIdenticalVirtualExpressionGrouping() { @@ -14470,7 +14470,7 @@ public void testGreatestFunctionForStringWithIsNull() ); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) @Test public void testSubqueryTypeMismatchWithLiterals() { @@ -15192,7 +15192,7 @@ public void testScanAndSortCanGetSchemaFromScanQuery() .run(); } - @DecoupledTestConfig(quidem2 = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @Test public void testWindowingWithScanAndSort() { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java index 7c73b1125063..c8c7fce72fad 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java @@ -19,14 +19,9 @@ package org.apache.druid.sql.calcite; -import com.google.common.collect.ImmutableMap; -import org.apache.druid.query.QueryContexts; -import org.apache.druid.server.security.AuthConfig; import org.apache.druid.sql.calcite.DisableUnless.DisableUnlessRule; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; -import org.apache.druid.sql.calcite.planner.PlannerConfig; -import org.apache.druid.sql.calcite.util.SqlTestFramework; -import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; @@ -41,37 +36,19 @@ public class DecoupledPlanningCalciteJoinQueryTest extends CalciteJoinQueryTest @RegisterExtension public DisableUnlessRule sqlCompatOnly = DisableUnless.SQL_COMPATIBLE; - private static final ImmutableMap CONTEXT_OVERRIDES = ImmutableMap.builder() - .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) - .put(PlannerConfig.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, PlannerConfig.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED) - .put(QueryContexts.ENABLE_DEBUG, true) - .build(); + @RegisterExtension + DecoupledExtension decoupledExtension = new DecoupledExtension(this); @Override protected QueryTestBuilder testBuilder() { - PlannerComponentSupplier componentSupplier = this; - CalciteTestConfig testConfig = new CalciteTestConfig(CONTEXT_OVERRIDES) - { - @Override - public SqlTestFramework.PlannerFixture plannerFixture(PlannerConfig plannerConfig, AuthConfig authConfig) - { - plannerConfig = plannerConfig.withOverrides(CONTEXT_OVERRIDES); - return queryFramework().plannerFixture(componentSupplier, plannerConfig, authConfig); - } - }; - - QueryTestBuilder builder = new QueryTestBuilder(testConfig) - .cannotVectorize(cannotVectorize) - .skipVectorize(skipVectorize); - - DecoupledTestConfig decTestConfig = queryFrameworkRule.getAnnotation(DecoupledTestConfig.class); - - if (decTestConfig != null && decTestConfig.nativeQueryIgnore().isPresent()) { - builder.verifyNativeQueries(x -> false); - } + return decoupledExtension.testBuilder(); + } - return builder; + @Test + public void validateTestClass() + { + // technical testcase needed by the extension temporarily } @MethodSource("provideQueryContexts") From 8b46032692edc54a6868d9cb3bd4e850af4152d9 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:03:35 +0000 Subject: [PATCH 08/24] add iq for join stuff --- .../sql/calcite/CalciteJoinQueryTest.java | 50 ++--- .../sql/calcite/DecoupledTestConfig.java | 6 - .../testCommaJoinLeftFunction.iq | 89 ++++++++ .../testExactTopNOnInnerJoinWithLimit.iq | 115 ++++++++++ ...upByOverInnerJoinOnTwoInlineDataSources.iq | 164 ++++++++++++++ .../testInnerJoinCastLeft.iq | 89 ++++++++ .../testInnerJoinLeftFunction.iq | 92 ++++++++ ...rcesWithOuterWhere_withLeftDirectAccess.iq | 134 ++++++++++++ ...oInlineDataSources_withLeftDirectAccess.iq | 134 ++++++++++++ .../testInnerJoinQueryOfLookup.iq | 112 ++++++++++ .../testInnerJoinQueryOfLookupRemovable.iq | 95 +++++++++ ...testInnerJoinSubqueryWithSelectorFilter.iq | 94 ++++++++ ...JoinTwoLookupsToTableUsingNumericColumn.iq | 110 ++++++++++ ...oupByInsteadOfTimeseriesWithFloorOnTime.iq | 155 ++++++++++++++ ...loorOnTimeWithNoAggregateMultipleValues.iq | 155 ++++++++++++++ .../testJoinOnTimeseriesWithFloorOnTime.iq | 138 ++++++++++++ .../testJoinWithInputRefCondition.iq | 185 ++++++++++++++++ ...rcesWithOuterWhere_withLeftDirectAccess.iq | 134 ++++++++++++ ...rcesWithTimeFilter_withLeftDirectAccess.iq | 140 ++++++++++++ ...oInlineDataSources_withLeftDirectAccess.iq | 134 ++++++++++++ .../testLeftJoinSubqueryWithSelectorFilter.iq | 99 +++++++++ ...ntiJoinSimultaneouslyUsingExplicitJoins.iq | 139 ++++++++++++ ...OnStringWithNonSortedOrUniqueDictionary.iq | 86 ++++++++ ...thNonSortedOrUniqueDictionaryOrderByDim.iq | 88 ++++++++ .../testUsingSubqueryWithExtractionFns.iq | 139 ++++++++++++ ...stVirtualColumnOnMVFilterJoinExpression.iq | 125 +++++++++++ ...tualColumnOnMVFilterMultiJoinExpression.iq | 201 ++++++++++++++++++ 27 files changed, 3171 insertions(+), 31 deletions(-) create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq create mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java index bf631da78e51..c75e46f69773 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java @@ -183,7 +183,7 @@ public void testInnerJoinWithLimitAndAlias() // to compute the query with limit 1. @SqlTestFrameworkConfig(minTopNThreshold = 1) @Test - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) public void testExactTopNOnInnerJoinWithLimit() { Map context = new HashMap<>(QUERY_CONTEXT_DEFAULT); @@ -491,7 +491,7 @@ public void testJoinWithLimitBeforeJoining() } @Test - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinOnTimeseriesWithFloorOnTime() { // Cannot vectorize JOIN operator. @@ -546,7 +546,7 @@ public void testJoinOnTimeseriesWithFloorOnTime() } @Test - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime() { // Cannot vectorize JOIN operator. @@ -613,7 +613,7 @@ public void testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime() } @Test - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues() { // Cannot vectorize JOIN operator. @@ -1528,7 +1528,7 @@ public void testManyManyInnerJoinOnManyManyLookup(Map queryConte ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.FINALIZING_FIELD_ACCESS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.FINALIZING_FIELD_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinQueryOfLookup(Map queryContext) @@ -1608,7 +1608,7 @@ public void testTimeColumnAggregationsOnLookups(Map queryContext } } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinQueryOfLookupRemovable(Map queryContext) @@ -1647,7 +1647,7 @@ public void testInnerJoinQueryOfLookupRemovable(Map queryContext ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinTwoLookupsToTableUsingNumericColumn(Map queryContext) @@ -1975,7 +1975,7 @@ public void testWhereInSelectNullFromLookup() } @Test - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testCommaJoinLeftFunction() { testQuery( @@ -2150,7 +2150,7 @@ public void testJoinTableLookupTableMismatchedTypesWithoutComma(Map queryContext) @@ -2279,7 +2279,7 @@ public void testInnerJoinMismatchedTypes(Map queryContext) ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinLeftFunction(Map queryContext) @@ -2732,7 +2732,7 @@ public void testNotInAggregationSubquery(Map queryContext) ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testUsingSubqueryWithExtractionFns(Map queryContext) @@ -2936,7 +2936,7 @@ public void testLeftJoinOnTwoInlineDataSourcesWithTimeFilter(Map ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess(Map queryContext) @@ -3048,7 +3048,7 @@ public void testLeftJoinOnTwoInlineDataSourcesWithOuterWhere(Map ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess(Map queryContext) @@ -3150,7 +3150,7 @@ public void testLeftJoinOnTwoInlineDataSources(Map queryContext) ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess(Map queryContext) @@ -3252,7 +3252,7 @@ public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere(Map queryContext) @@ -3354,7 +3354,7 @@ public void testInnerJoinOnTwoInlineDataSources(Map queryContext ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources(Map queryContext) @@ -3440,7 +3440,7 @@ public void testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources(Map queryContext) @@ -3670,7 +3670,7 @@ public void testLeftJoinSubqueryWithNullKeyFilter(Map queryConte ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinSubqueryWithSelectorFilter(Map queryContext) @@ -3876,7 +3876,7 @@ public void testJoinWithExplicitIsNotDistinctFromCondition(Map q ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinSubqueryWithSelectorFilter(Map queryContext) @@ -4152,7 +4152,7 @@ public void testSemiAndAntiJoinSimultaneouslyUsingWhereInSubquery(Map queryContext) @@ -5153,7 +5153,7 @@ public void testCountOnSemiJoinSingleColumn(Map queryContext) ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testTopNOnStringWithNonSortedOrUniqueDictionary(Map queryContext) @@ -5194,7 +5194,7 @@ public void testTopNOnStringWithNonSortedOrUniqueDictionary(Map ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim(Map queryContext) @@ -5235,7 +5235,7 @@ public void testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim(Map queryContext) @@ -5292,7 +5292,7 @@ public void testVirtualColumnOnMVFilterJoinExpression(Map queryC ); } - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testVirtualColumnOnMVFilterMultiJoinExpression(Map queryContext) @@ -6028,7 +6028,7 @@ public void testJoinsWithThreeConditions() } @Test - @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinWithInputRefCondition() { cannotVectorize(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java index d0f3e6da177f..cbc9ebd2cc48 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java @@ -49,12 +49,6 @@ */ boolean quidem() default false; - /** - * Use alternate quidem test for testcase - */ - NativeQueryIgnore quidem2() default NativeQueryIgnore.NONE; - - enum NativeQueryIgnore { NONE, diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq new file mode 100644 index 000000000000..6af247ffc7e7 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq @@ -0,0 +1,89 @@ +# testCommaJoinLeftFunction case-crc:40471241 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT foo.dim1, foo.dim2, l.k, l.v +FROM foo, lookup.lookyloo l +WHERE SUBSTRING(foo.dim2, 1, 1) = l.k +; ++------+------+---+----+ +| dim1 | dim2 | k | v | ++------+------+---+----+ +| | a | a | xa | +| 1 | a | a | xa | +| def | abc | a | xa | ++------+------+---+----+ +(3 rows) + +!ok +LogicalProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4]) + LogicalJoin(condition=[=($2, $3)], joinType=[inner]) + LogicalProject(dim1=[$1], dim2=[$2], $f2=[SUBSTRING($2, 1, 1)]) + LogicalTableScan(table=[[druid, foo]]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4], druid=[logical]) + DruidJoin(condition=[=($2, $3)], joinType=[inner]) + DruidProject(dim1=[$1], dim2=[$2], $f2=[SUBSTRING($2, 1, 1)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "substring(\"dim2\", 0, 1)", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "dim1", "dim2", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.k\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "dim1", "dim2", "j0.k", "j0.v" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING", "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq new file mode 100644 index 000000000000..304cbda993b6 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq @@ -0,0 +1,115 @@ +# testExactTopNOnInnerJoinWithLimit case-crc:bbbef51a +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set useApproximateTopN false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set outputformat mysql +!use druidtest:/// +select f1."dim4", sum("m1") from numfoo f1 inner join ( + select "dim4" from numfoo where dim4 <> 'a' group by 1 +) f2 on f1."dim4" = f2."dim4" group by 1 limit 1; ++------+--------+ +| dim4 | EXPR$1 | ++------+--------+ +| b | 15.0 | ++------+--------+ +(1 row) + +!ok +LogicalSort(fetch=[1]) + LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)]) + LogicalJoin(condition=[=($0, $2)], joinType=[inner]) + LogicalProject(dim4=[$4], m1=[$14]) + LogicalTableScan(table=[[druid, numfoo]]) + LogicalAggregate(group=[{4}]) + LogicalFilter(condition=[<>($4, 'a')]) + LogicalTableScan(table=[[druid, numfoo]]) + +!logicalPlan +DruidSort(fetch=[1], druid=[logical]) + DruidAggregate(group=[{0}], EXPR$1=[SUM($1)], druid=[logical]) + DruidJoin(condition=[=($0, $2)], joinType=[inner]) + DruidProject(dim4=[$4], m1=[$14], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + DruidAggregate(group=[{4}], druid=[logical]) + DruidFilter(condition=[<>($4, 'a')]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "topN", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "numfoo" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "filter" : { + "type" : "not", + "field" : { + "type" : "equals", + "column" : "dim4", + "matchValueType" : "STRING", + "matchValue" : "a" + } + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim4", + "outputName" : "_d0", + "outputType" : "STRING" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"dim4\" == \"j0._d0\")", + "joinType" : "INNER" + }, + "dimension" : { + "type" : "default", + "dimension" : "dim4", + "outputName" : "d0", + "outputType" : "STRING" + }, + "metric" : { + "type" : "dimension", + "ordering" : { + "type" : "lexicographic" + } + }, + "threshold" : 1, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "aggregations" : [ { + "type" : "doubleSum", + "name" : "a0", + "fieldName" : "m1" + } ] +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq new file mode 100644 index 000000000000..a0393243cac1 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq @@ -0,0 +1,164 @@ +# testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources case-crc:a595df5b +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +with abc as +( + SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' +) +SELECT dim1 from (SELECT dim1,__time FROM (SELECT t1.dim1, t1."__time" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1) GROUP BY 1,2) GROUP BY dim1 +; ++------+ +| dim1 | ++------+ +| 10.1 | ++------+ +(1 row) + +!ok +LogicalAggregate(group=[{0}]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR]) + LogicalAggregate(group=[{1}]) + LogicalJoin(condition=[=($0, $2)], joinType=[inner]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(dim1=[$1]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{0}], druid=[logical]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], druid=[logical]) + DruidAggregate(group=[{1}], druid=[logical]) + DruidJoin(condition=[=($0, $2)], joinType=[inner]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(dim1=[$1], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "__time", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "dim1" ], + "legacy" : false, + "columnTypes" : [ "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.dim1\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "__time", + "outputName" : "d0", + "outputType" : "LONG" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "_d0", + "outputType" : "STRING" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq new file mode 100644 index 000000000000..664e031edaac --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq @@ -0,0 +1,89 @@ +# testInnerJoinCastLeft case-crc:96c532bb +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT foo.m1, l.k, l.v +FROM foo +INNER JOIN lookup.lookyloo l ON CAST(foo.m1 AS VARCHAR) = l.k +; ++----+---+---+ +| m1 | k | v | ++----+---+---+ ++----+---+---+ +(0 rows) + +!ok +LogicalProject(m1=[$0], k=[$2], v=[$3]) + LogicalJoin(condition=[=($1, $2)], joinType=[inner]) + LogicalProject(m1=[$5], m10=[CAST($5):VARCHAR]) + LogicalTableScan(table=[[druid, foo]]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidProject(m1=[$0], k=[$2], v=[$3], druid=[logical]) + DruidJoin(condition=[=($1, $2)], joinType=[inner]) + DruidProject(m1=[$5], m10=[CAST($5):VARCHAR], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "CAST(\"m1\", 'STRING')", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "m1", "v0" ], + "legacy" : false, + "columnTypes" : [ "FLOAT", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.k\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "j0.k", "j0.v", "m1" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING", "FLOAT" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq new file mode 100644 index 000000000000..c87313c3bbb1 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq @@ -0,0 +1,92 @@ +# testInnerJoinLeftFunction case-crc:8d4f8e31 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT foo.dim1, foo.dim2, l.k, l.v +FROM foo +INNER JOIN lookup.lookyloo l ON SUBSTRING(foo.dim2, 1, 1) = l.k +; ++------+------+---+----+ +| dim1 | dim2 | k | v | ++------+------+---+----+ +| | a | a | xa | +| 1 | a | a | xa | +| def | abc | a | xa | ++------+------+---+----+ +(3 rows) + +!ok +LogicalProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4]) + LogicalJoin(condition=[=($2, $3)], joinType=[inner]) + LogicalProject(dim1=[$1], dim2=[$2], $f8=[SUBSTRING($2, 1, 1)]) + LogicalTableScan(table=[[druid, foo]]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4], druid=[logical]) + DruidJoin(condition=[=($2, $3)], joinType=[inner]) + DruidProject(dim1=[$1], dim2=[$2], $f8=[SUBSTRING($2, 1, 1)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "substring(\"dim2\", 0, 1)", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "dim1", "dim2", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.k\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "dim1", "dim2", "j0.k", "j0.v" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING", "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq new file mode 100644 index 000000000000..edc3f547c91f --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq @@ -0,0 +1,134 @@ +# testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess case-crc:c9234000 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set enableJoinLeftTableScanDirect true +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +with abc as +( + SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' +) +SELECT t1.dim1, t1."__time" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1' +; ++------+---------------------+ +| dim1 | __time | ++------+---------------------+ +| 10.1 | 2000-01-02 00:00:00 | ++------+---------------------+ +(1 row) + +!ok +LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) + LogicalJoin(condition=[=($0, $2)], joinType=[inner]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(dim1=[$1]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) + DruidJoin(condition=[=($0, $2)], joinType=[inner]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(dim1=[$1], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "__time", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "dim1" ], + "legacy" : false, + "columnTypes" : [ "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.dim1\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "_v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "_v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq new file mode 100644 index 000000000000..d421397b0158 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq @@ -0,0 +1,134 @@ +# testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess case-crc:9b3900d5 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set enableJoinLeftTableScanDirect true +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +with abc as +( + SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' +) +SELECT t1.dim1, t1."__time" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1 +; ++------+---------------------+ +| dim1 | __time | ++------+---------------------+ +| 10.1 | 2000-01-02 00:00:00 | ++------+---------------------+ +(1 row) + +!ok +LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) + LogicalJoin(condition=[=($0, $2)], joinType=[inner]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(dim1=[$1]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) + DruidJoin(condition=[=($0, $2)], joinType=[inner]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(dim1=[$1], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "__time", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "dim1" ], + "legacy" : false, + "columnTypes" : [ "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.dim1\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "_v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "_v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq new file mode 100644 index 000000000000..ea94aae48a93 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq @@ -0,0 +1,112 @@ +# testInnerJoinQueryOfLookup case-crc:06d01cd2 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT dim1, dim2, t1.v, t1.v +FROM foo +INNER JOIN + (SELECT SUBSTRING(k, 1, 1) k, ANY_VALUE(v, 10) v FROM lookup.lookyloo GROUP BY 1) t1 + ON foo.dim2 = t1.k; ++------+------+------+------+ +| dim1 | dim2 | v | v | ++------+------+------+------+ +| | a | xabc | xabc | +| 1 | a | xabc | xabc | ++------+------+------+------+ +(2 rows) + +!ok +LogicalProject(dim1=[$0], dim2=[$1], v=[$3], v0=[$3]) + LogicalJoin(condition=[=($1, $2)], joinType=[inner]) + LogicalProject(dim1=[$1], dim2=[$2]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{0}], v=[ANY_VALUE($1, $2)]) + LogicalProject(k=[SUBSTRING($0, 1, 1)], v=[$1], $f2=[10]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidProject(dim1=[$0], dim2=[$1], v=[$3], v0=[$3], druid=[logical]) + DruidJoin(condition=[=($1, $2)], joinType=[inner]) + DruidProject(dim1=[$1], dim2=[$2], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{0}], v=[ANY_VALUE($1, $2)], druid=[logical]) + DruidProject(k=[SUBSTRING($0, 1, 1)], v=[$1], $f2=[10], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "foo" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "extraction", + "dimension" : "k", + "outputName" : "d0", + "outputType" : "STRING", + "extractionFn" : { + "type" : "substring", + "index" : 0, + "length" : 1 + } + } ], + "aggregations" : [ { + "type" : "stringAny", + "name" : "a0:a", + "fieldName" : "v", + "maxStringBytes" : 10, + "aggregateMultipleValues" : true + } ], + "postAggregations" : [ { + "type" : "finalizingFieldAccess", + "name" : "a0", + "fieldName" : "a0:a" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"dim2\" == \"j0.d0\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "dim1", "dim2", "j0.a0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq new file mode 100644 index 000000000000..7d4926868c04 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq @@ -0,0 +1,95 @@ +# testInnerJoinQueryOfLookupRemovable case-crc:f94036af +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT dim1, dim2, t1.sk +FROM foo +INNER JOIN + (SELECT k, SUBSTRING(v, 1, 3) sk FROM lookup.lookyloo) t1 + ON foo.dim2 = t1.k; ++------+------+-----+ +| dim1 | dim2 | sk | ++------+------+-----+ +| | a | xa | +| 1 | a | xa | +| def | abc | xab | ++------+------+-----+ +(3 rows) + +!ok +LogicalProject(dim1=[$0], dim2=[$1], sk=[$3]) + LogicalJoin(condition=[=($1, $2)], joinType=[inner]) + LogicalProject(dim1=[$1], dim2=[$2]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(k=[$0], sk=[SUBSTRING($1, 1, 3)]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidProject(dim1=[$0], dim2=[$1], sk=[$3], druid=[logical]) + DruidJoin(condition=[=($1, $2)], joinType=[inner]) + DruidProject(dim1=[$1], dim2=[$2], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(k=[$0], sk=[SUBSTRING($1, 1, 3)], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "foo" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "substring(\"v\", 0, 3)", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "k", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"dim2\" == \"j0.k\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "dim1", "dim2", "j0.v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq new file mode 100644 index 000000000000..9c1d6306ddf2 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq @@ -0,0 +1,94 @@ +# testInnerJoinSubqueryWithSelectorFilter case-crc:ecd38651 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT dim1, l1.k FROM foo INNER JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 ON foo.dim1 = l1.k and l1.k = 'abc'; ++------+-----+ +| dim1 | k | ++------+-----+ +| abc | abc | ++------+-----+ +(1 row) + +!ok +LogicalJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) + LogicalProject(dim1=[$1]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{0}]) + LogicalProject(k=[||($0, '')]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) + DruidProject(dim1=[$1], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{0}], druid=[logical]) + DruidProject(k=[||($0, '')], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "foo" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "concat(\"k\",'')", + "outputType" : "STRING" + } ], + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "((\"dim1\" == \"j0.d0\") && (\"j0.d0\" == 'abc'))", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "dim1", "j0.d0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq new file mode 100644 index 000000000000..1824f446759d --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq @@ -0,0 +1,110 @@ +# testInnerJoinTwoLookupsToTableUsingNumericColumn case-crc:ac4fadf1 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT COUNT(*) +FROM foo +INNER JOIN lookup.lookyloo l1 ON l1.k = foo.m1 +INNER JOIN lookup.lookyloo l2 ON l2.k = l1.k; ++--------+ +| EXPR$0 | ++--------+ +| 1 | ++--------+ +(1 row) + +!ok +LogicalAggregate(group=[{}], EXPR$0=[COUNT()]) + LogicalJoin(condition=[=($1, $0)], joinType=[inner]) + LogicalProject(k=[$1]) + LogicalJoin(condition=[=($2, $0)], joinType=[inner]) + LogicalProject(m1=[$5]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(k=[$0], k0=[CAST($0):FLOAT]) + LogicalTableScan(table=[[lookup, lookyloo]]) + LogicalProject(k=[$0]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidAggregate(group=[{}], EXPR$0=[COUNT()], druid=[logical]) + DruidJoin(condition=[=($1, $0)], joinType=[inner]) + DruidProject(k=[$1], druid=[logical]) + DruidJoin(condition=[=($2, $0)], joinType=[inner]) + DruidProject(m1=[$5], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(k=[$0], k0=[CAST($0):FLOAT], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + DruidProject(k=[$0], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "timeseries", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "foo" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "CAST(\"k\", 'DOUBLE')", + "outputType" : "FLOAT" + } ], + "resultFormat" : "compactedList", + "columns" : [ "k", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "FLOAT" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"j0.v0\" == \"m1\")", + "joinType" : "INNER" + }, + "right" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "rightPrefix" : "_j0.", + "condition" : "(\"_j0.k\" == \"j0.k\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ] +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq new file mode 100644 index 000000000000..903843303001 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq @@ -0,0 +1,155 @@ +# testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime case-crc:b7a9de50 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT CAST(__time AS BIGINT), m1, ANY_VALUE(dim3, 100) FROM foo WHERE (CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1, m1) IN + ( + SELECT CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1 AS t1, MIN(m1) AS t2 FROM foo WHERE dim3 = 'b' + AND __time BETWEEN '1994-04-29 00:00:00' AND '2020-01-11 00:00:00' GROUP BY 1 + ) +GROUP BY 1, 2 +; ++--------------+-----+--------+ +| EXPR$0 | m1 | EXPR$2 | ++--------------+-----+--------+ +| 946684800000 | 1.0 | [a, b] | +| 946771200000 | 2.0 | [b, c] | ++--------------+-----+--------+ +(2 rows) + +!ok +LogicalAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3)]) + LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100]) + LogicalJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) + LogicalProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{0}], t2=[MIN($1)]) + LogicalProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5]) + LogicalFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3)], druid=[logical]) + DruidProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], druid=[logical]) + DruidJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) + DruidProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{0}], t2=[MIN($1)], druid=[logical]) + DruidProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5], druid=[logical]) + DruidFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", + "outputType" : "LONG" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "dim3", "m1", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING", "FLOAT", "LONG" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "1994-04-29T00:00:00.000Z/2020-01-11T00:00:00.001Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", + "outputType" : "LONG" + } ], + "filter" : { + "type" : "equals", + "column" : "dim3", + "matchValueType" : "STRING", + "matchValue" : "b" + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "d0", + "outputType" : "LONG" + } ], + "aggregations" : [ { + "type" : "floatMin", + "name" : "a0", + "fieldName" : "m1" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "((\"v0\" == \"j0.d0\") && (\"m1\" == \"j0.a0\"))", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "__time", + "outputName" : "d0", + "outputType" : "LONG" + }, { + "type" : "default", + "dimension" : "m1", + "outputName" : "d1", + "outputType" : "FLOAT" + } ], + "aggregations" : [ { + "type" : "stringAny", + "name" : "a0", + "fieldName" : "dim3", + "maxStringBytes" : 100, + "aggregateMultipleValues" : true + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq new file mode 100644 index 000000000000..ee95a76a3c90 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq @@ -0,0 +1,155 @@ +# testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues case-crc:cdb8c84b +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT CAST(__time AS BIGINT), m1, ANY_VALUE(dim3, 100, false) FROM foo WHERE (CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1, m1) IN + ( + SELECT CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1 AS t1, MIN(m1) AS t2 FROM foo WHERE dim3 = 'b' + AND __time BETWEEN '1994-04-29 00:00:00' AND '2020-01-11 00:00:00' GROUP BY 1 + ) +GROUP BY 1, 2 +; ++--------------+-----+--------+ +| EXPR$0 | m1 | EXPR$2 | ++--------------+-----+--------+ +| 946684800000 | 1.0 | a | +| 946771200000 | 2.0 | b | ++--------------+-----+--------+ +(2 rows) + +!ok +LogicalAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)]) + LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[false]) + LogicalJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) + LogicalProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{0}], t2=[MIN($1)]) + LogicalProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5]) + LogicalFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)], druid=[logical]) + DruidProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[false], druid=[logical]) + DruidJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) + DruidProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{0}], t2=[MIN($1)], druid=[logical]) + DruidProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5], druid=[logical]) + DruidFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", + "outputType" : "LONG" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "dim3", "m1", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING", "FLOAT", "LONG" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "1994-04-29T00:00:00.000Z/2020-01-11T00:00:00.001Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", + "outputType" : "LONG" + } ], + "filter" : { + "type" : "equals", + "column" : "dim3", + "matchValueType" : "STRING", + "matchValue" : "b" + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "d0", + "outputType" : "LONG" + } ], + "aggregations" : [ { + "type" : "floatMin", + "name" : "a0", + "fieldName" : "m1" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "((\"v0\" == \"j0.d0\") && (\"m1\" == \"j0.a0\"))", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "__time", + "outputName" : "d0", + "outputType" : "LONG" + }, { + "type" : "default", + "dimension" : "m1", + "outputName" : "d1", + "outputType" : "FLOAT" + } ], + "aggregations" : [ { + "type" : "stringAny", + "name" : "a0", + "fieldName" : "dim3", + "maxStringBytes" : 100, + "aggregateMultipleValues" : false + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq new file mode 100644 index 000000000000..48b2ffd2b841 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq @@ -0,0 +1,138 @@ +# testJoinOnTimeseriesWithFloorOnTime case-crc:283a6693 +!set sqlQueryId dummy +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set defaultTimeout 300000 +!set maxScatterGatherBytes 9223372036854775807 +!set plannerStrategy DECOUPLED +!set debug true +!set outputformat mysql +!use druidtest:/// +SELECT CAST(__time AS BIGINT), m1, ANY_VALUE(dim3, 100, true) FROM foo WHERE (TIME_FLOOR(__time, 'PT1H'), m1) IN + ( + SELECT TIME_FLOOR(__time, 'PT1H') AS t1, MIN(m1) AS t2 FROM foo WHERE dim3 = 'b' + AND __time BETWEEN '1994-04-29 00:00:00' AND '2020-01-11 00:00:00' GROUP BY 1 + ) +GROUP BY 1, 2 +; ++--------------+-----+--------+ +| EXPR$0 | m1 | EXPR$2 | ++--------------+-----+--------+ +| 946684800000 | 1.0 | [a, b] | +| 946771200000 | 2.0 | [b, c] | ++--------------+-----+--------+ +(2 rows) + +!ok +LogicalAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)]) + LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[true]) + LogicalJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) + LogicalProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[TIME_FLOOR($0, 'PT1H')]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{0}], t2=[MIN($1)]) + LogicalProject(t1=[TIME_FLOOR($0, 'PT1H')], m1=[$5]) + LogicalFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)], druid=[logical]) + DruidProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[true], druid=[logical]) + DruidJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) + DruidProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[TIME_FLOOR($0, 'PT1H')], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{0}], t2=[MIN($1)], druid=[logical]) + DruidProject(t1=[TIME_FLOOR($0, 'PT1H')], m1=[$5], druid=[logical]) + DruidFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "timestamp_floor(\"__time\",'PT1H',null,'UTC')", + "outputType" : "LONG" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "dim3", "m1", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING", "FLOAT", "LONG" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "timeseries", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "1994-04-29T00:00:00.000Z/2020-01-11T00:00:00.001Z" ] + }, + "filter" : { + "type" : "equals", + "column" : "dim3", + "matchValueType" : "STRING", + "matchValue" : "b" + }, + "granularity" : "HOUR", + "aggregations" : [ { + "type" : "floatMin", + "name" : "a0", + "fieldName" : "m1" + } ] + } + }, + "rightPrefix" : "j0.", + "condition" : "((\"v0\" == \"j0.d0\") && (\"m1\" == \"j0.a0\"))", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "__time", + "outputName" : "d0", + "outputType" : "LONG" + }, { + "type" : "default", + "dimension" : "m1", + "outputName" : "d1", + "outputType" : "FLOAT" + } ], + "aggregations" : [ { + "type" : "stringAny", + "name" : "a0", + "fieldName" : "dim3", + "maxStringBytes" : 100, + "aggregateMultipleValues" : true + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq new file mode 100644 index 000000000000..0f11e3a6c220 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq @@ -0,0 +1,185 @@ +# testJoinWithInputRefCondition case-crc:912f3b33 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set outputformat mysql +!use druidtest:/// +SELECT COUNT(*) FILTER (WHERE FLOOR(100) NOT IN (SELECT m1 FROM foo)) FROM foo; ++--------+ +| EXPR$0 | ++--------+ +| 6 | ++--------+ +(1 row) + +!ok +LogicalAggregate(group=[{}], EXPR$0=[COUNT() FILTER $0]) + LogicalProject($f0=[OR(=($1, 0), AND(IS NULL($4), >=($2, $1)))]) + LogicalJoin(condition=[=(CAST(FLOOR(100)):FLOAT NOT NULL, $3)], joinType=[left]) + LogicalJoin(condition=[true], joinType=[inner]) + LogicalProject(DUMMY=[0]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($5)]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{5}], i=[LITERAL_AGG(true)]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{}], EXPR$0=[COUNT() FILTER $0], druid=[logical]) + DruidProject($f0=[OR(=($1, 0), AND(IS NULL($4), >=($2, $1)))], druid=[logical]) + DruidJoin(condition=[=(CAST(FLOOR(100)):FLOAT NOT NULL, $3)], joinType=[left]) + DruidJoin(condition=[true], joinType=[inner]) + DruidProject(DUMMY=[0], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{}], c=[COUNT()], ck=[COUNT($5)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{5}], i=[LITERAL_AGG(true)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "timeseries", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "0", + "outputType" : "LONG" + } ], + "resultFormat" : "compactedList", + "columns" : [ "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "timeseries", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "aggregations" : [ { + "type" : "count", + "name" : "a0" + }, { + "type" : "filtered", + "aggregator" : { + "type" : "count", + "name" : "a1" + }, + "filter" : { + "type" : "not", + "field" : { + "type" : "null", + "column" : "m1" + } + }, + "name" : "a1" + } ] + } + }, + "rightPrefix" : "j0.", + "condition" : "1", + "joinType" : "INNER" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "m1", + "outputName" : "d0", + "outputType" : "FLOAT" + } ], + "postAggregations" : [ { + "type" : "expression", + "name" : "a0", + "expression" : "1", + "outputType" : "LONG" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "_j0.", + "condition" : "(CAST(floor(100), 'DOUBLE') == \"_j0.d0\")", + "joinType" : "LEFT" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "aggregations" : [ { + "type" : "filtered", + "aggregator" : { + "type" : "count", + "name" : "a0" + }, + "filter" : { + "type" : "or", + "fields" : [ { + "type" : "equals", + "column" : "j0.a0", + "matchValueType" : "LONG", + "matchValue" : 0 + }, { + "type" : "and", + "fields" : [ { + "type" : "null", + "column" : "_j0.a0" + }, { + "type" : "expression", + "expression" : "(\"j0.a1\" >= \"j0.a0\")" + } ] + } ] + }, + "name" : "a0" + } ] +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq new file mode 100644 index 000000000000..d3b71e0d8f49 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq @@ -0,0 +1,134 @@ +# testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess case-crc:eb6c3cbe +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set enableJoinLeftTableScanDirect true +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +with abc as +( + SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' +) +SELECT t1.dim1, t1."__time" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1' +; ++------+---------------------+ +| dim1 | __time | ++------+---------------------+ +| 10.1 | 2000-01-02 00:00:00 | ++------+---------------------+ +(1 row) + +!ok +LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) + LogicalJoin(condition=[=($0, $2)], joinType=[left]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(dim1=[$1]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) + DruidJoin(condition=[=($0, $2)], joinType=[left]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(dim1=[$1], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "__time", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "dim1" ], + "legacy" : false, + "columnTypes" : [ "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.dim1\")", + "joinType" : "LEFT" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "_v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "_v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq new file mode 100644 index 000000000000..0391d00a2a42 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq @@ -0,0 +1,140 @@ +# testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess case-crc:1833b879 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set enableJoinLeftTableScanDirect true +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +with abc as +( + SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' AND "__time" >= '1999' +) +SELECT t1.dim1, t1."__time" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1' +; ++------+---------------------+ +| dim1 | __time | ++------+---------------------+ +| 10.1 | 2000-01-02 00:00:00 | ++------+---------------------+ +(1 row) + +!ok +LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) + LogicalJoin(condition=[=($0, $2)], joinType=[left]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) + LogicalFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR]) + LogicalFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) + DruidJoin(condition=[=($0, $2)], joinType=[left]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) + DruidFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], druid=[logical]) + DruidFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "1999-01-01T00:00:00.000Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "__time", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "1999-01-01T00:00:00.000Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.v0\")", + "joinType" : "LEFT" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "_v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "_v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq new file mode 100644 index 000000000000..fea4326b5fe1 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq @@ -0,0 +1,134 @@ +# testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess case-crc:35bb78bb +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set enableJoinLeftTableScanDirect true +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +with abc as +( + SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' +) +SELECT t1.dim1, t1."__time" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 +; ++------+---------------------+ +| dim1 | __time | ++------+---------------------+ +| 10.1 | 2000-01-02 00:00:00 | ++------+---------------------+ +(1 row) + +!ok +LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) + LogicalJoin(condition=[=($0, $2)], joinType=[left]) + LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + LogicalProject(dim1=[$1]) + LogicalFilter(condition=[=($1, '10.1')]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) + DruidJoin(condition=[=($0, $2)], joinType=[left]) + DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidProject(dim1=[$1], druid=[logical]) + DruidFilter(condition=[=($1, '10.1')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "__time", "v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "filter" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "10.1" + }, + "columns" : [ "dim1" ], + "legacy" : false, + "columnTypes" : [ "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.dim1\")", + "joinType" : "LEFT" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "_v0", + "expression" : "'10.1'", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "__time", "_v0" ], + "legacy" : false, + "columnTypes" : [ "LONG", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq new file mode 100644 index 000000000000..7e94bb3c8bf4 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq @@ -0,0 +1,99 @@ +# testLeftJoinSubqueryWithSelectorFilter case-crc:503594a7 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set computeInnerJoinCostAsFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT dim1, l1.k +FROM foo +LEFT JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 ON foo.dim1 = l1.k +WHERE l1.k = 'abc' +; ++------+-----+ +| dim1 | k | ++------+-----+ +| abc | abc | ++------+-----+ +(1 row) + +!ok +LogicalJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) + LogicalProject(dim1=[$1]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{0}]) + LogicalProject(k=[||($0, '')]) + LogicalTableScan(table=[[lookup, lookyloo]]) + +!logicalPlan +DruidJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) + DruidProject(dim1=[$1], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{0}], druid=[logical]) + DruidProject(k=[||($0, '')], druid=[logical]) + DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "foo" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "lookup", + "lookup" : "lookyloo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "concat(\"k\",'')", + "outputType" : "STRING" + } ], + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "v0", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "((\"dim1\" == \"j0.d0\") && (\"j0.d0\" == 'abc'))", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "dim1", "j0.d0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq new file mode 100644 index 000000000000..9d9259eab10c --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq @@ -0,0 +1,139 @@ +# testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins case-crc:692fc7cc +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set enableTimeBoundaryPlanning true +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT dim1, COUNT(*) FROM +foo +INNER JOIN (SELECT MAX(__time) t FROM foo) t0 on t0.t = foo.__time +LEFT JOIN (SELECT MIN(__time) t FROM foo) t1 on t1.t = foo.__time +WHERE dim1 IN ('abc', 'def') AND t1.t is null +GROUP BY 1; ++------+--------+ +| dim1 | EXPR$1 | ++------+--------+ +| abc | 1 | ++------+--------+ +(1 row) + +!ok +LogicalAggregate(group=[{1}], EXPR$1=[COUNT()]) + LogicalFilter(condition=[AND(SEARCH($1, Sarg['abc', 'def']:CHAR(3)), IS NULL($3))]) + LogicalJoin(condition=[=($3, $0)], joinType=[left]) + LogicalJoin(condition=[=($2, $0)], joinType=[inner]) + LogicalProject(__time=[$0], dim1=[$1]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{}], t=[MAX($0)]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{}], t=[MIN($0)]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{1}], EXPR$1=[COUNT()], druid=[logical]) + DruidFilter(condition=[AND(SEARCH($1, Sarg['abc', 'def']:CHAR(3)), IS NULL($3))]) + DruidJoin(condition=[=($3, $0)], joinType=[left]) + DruidJoin(condition=[=($2, $0)], joinType=[inner]) + DruidProject(__time=[$0], dim1=[$1], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{}], t=[MAX($0)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{}], t=[MIN($0)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "foo" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "timeBoundary", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "bound" : "maxTime", + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"j0.a0\" == \"__time\")", + "joinType" : "INNER" + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "timeBoundary", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "bound" : "minTime", + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "_j0.", + "condition" : "(\"_j0.a0\" == \"__time\")", + "joinType" : "LEFT" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "filter" : { + "type" : "and", + "fields" : [ { + "type" : "inType", + "column" : "dim1", + "matchValueType" : "STRING", + "sortedValues" : [ "abc", "def" ] + }, { + "type" : "null", + "column" : "_j0.a0" + } ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim1", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq new file mode 100644 index 000000000000..8174204174d3 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq @@ -0,0 +1,86 @@ +# testTopNOnStringWithNonSortedOrUniqueDictionary case-crc:7aa7e615 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT druid.broadcast.dim4, COUNT(*) +FROM druid.numfoo +INNER JOIN druid.broadcast ON numfoo.dim4 = broadcast.dim4 +GROUP BY 1 ORDER BY 2 LIMIT 4; ++------+--------+ +| dim4 | EXPR$1 | ++------+--------+ +| a | 9 | +| b | 9 | ++------+--------+ +(2 rows) + +!ok +LogicalSort(sort0=[$1], dir0=[ASC], fetch=[4]) + LogicalAggregate(group=[{1}], EXPR$1=[COUNT()]) + LogicalJoin(condition=[=($0, $1)], joinType=[inner]) + LogicalProject(dim4=[$4]) + LogicalTableScan(table=[[druid, numfoo]]) + LogicalProject(dim4=[$4]) + LogicalTableScan(table=[[druid, broadcast]]) + +!logicalPlan +DruidSort(sort0=[$1], dir0=[ASC], fetch=[4], druid=[logical]) + DruidAggregate(group=[{1}], EXPR$1=[COUNT()], druid=[logical]) + DruidJoin(condition=[=($0, $1)], joinType=[inner]) + DruidProject(dim4=[$4], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + DruidProject(dim4=[$4], druid=[logical]) + DruidTableScan(table=[[druid, broadcast]], druid=[logical]) + +!druidPlan +{ + "queryType" : "topN", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "numfoo" + }, + "right" : { + "type" : "globalTable", + "name" : "broadcast" + }, + "rightPrefix" : "j0.", + "condition" : "(\"dim4\" == \"j0.dim4\")", + "joinType" : "INNER" + }, + "dimension" : { + "type" : "default", + "dimension" : "j0.dim4", + "outputName" : "d0", + "outputType" : "STRING" + }, + "metric" : { + "type" : "inverted", + "metric" : { + "type" : "numeric", + "metric" : "a0" + } + }, + "threshold" : 4, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ] +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq new file mode 100644 index 000000000000..eabe251fc356 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq @@ -0,0 +1,88 @@ +# testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim case-crc:0d2340d3 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT druid.broadcast.dim4, COUNT(*) +FROM druid.numfoo +INNER JOIN druid.broadcast ON numfoo.dim4 = broadcast.dim4 +GROUP BY 1 ORDER BY 1 DESC LIMIT 4; ++------+--------+ +| dim4 | EXPR$1 | ++------+--------+ +| b | 9 | +| a | 9 | ++------+--------+ +(2 rows) + +!ok +LogicalSort(sort0=[$0], dir0=[DESC], fetch=[4]) + LogicalAggregate(group=[{1}], EXPR$1=[COUNT()]) + LogicalJoin(condition=[=($0, $1)], joinType=[inner]) + LogicalProject(dim4=[$4]) + LogicalTableScan(table=[[druid, numfoo]]) + LogicalProject(dim4=[$4]) + LogicalTableScan(table=[[druid, broadcast]]) + +!logicalPlan +DruidSort(sort0=[$0], dir0=[DESC], fetch=[4], druid=[logical]) + DruidAggregate(group=[{1}], EXPR$1=[COUNT()], druid=[logical]) + DruidJoin(condition=[=($0, $1)], joinType=[inner]) + DruidProject(dim4=[$4], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + DruidProject(dim4=[$4], druid=[logical]) + DruidTableScan(table=[[druid, broadcast]], druid=[logical]) + +!druidPlan +{ + "queryType" : "topN", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "table", + "name" : "numfoo" + }, + "right" : { + "type" : "globalTable", + "name" : "broadcast" + }, + "rightPrefix" : "j0.", + "condition" : "(\"dim4\" == \"j0.dim4\")", + "joinType" : "INNER" + }, + "dimension" : { + "type" : "default", + "dimension" : "j0.dim4", + "outputName" : "d0", + "outputType" : "STRING" + }, + "metric" : { + "type" : "inverted", + "metric" : { + "type" : "dimension", + "ordering" : { + "type" : "lexicographic" + } + } + }, + "threshold" : 4, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ] +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq new file mode 100644 index 000000000000..fc0d44bb2f56 --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq @@ -0,0 +1,139 @@ +# testUsingSubqueryWithExtractionFns case-crc:f4decaef +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT dim2, COUNT(*) FROM druid.foo WHERE substring(dim2, 1, 1) IN (SELECT substring(dim1, 1, 1) FROM druid.foo WHERE dim1 <> '')group by dim2; ++------+--------+ +| dim2 | EXPR$1 | ++------+--------+ +| a | 2 | +| abc | 1 | ++------+--------+ +(2 rows) + +!ok +LogicalAggregate(group=[{0}], EXPR$1=[COUNT()]) + LogicalJoin(condition=[=($1, $2)], joinType=[inner]) + LogicalProject(dim2=[$2], $f1=[SUBSTRING($2, 1, 1)]) + LogicalTableScan(table=[[druid, foo]]) + LogicalAggregate(group=[{0}]) + LogicalProject(EXPR$0=[SUBSTRING($1, 1, 1)]) + LogicalFilter(condition=[<>($1, '')]) + LogicalTableScan(table=[[druid, foo]]) + +!logicalPlan +DruidAggregate(group=[{0}], EXPR$1=[COUNT()], druid=[logical]) + DruidJoin(condition=[=($1, $2)], joinType=[inner]) + DruidProject(dim2=[$2], $f1=[SUBSTRING($2, 1, 1)], druid=[logical]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + DruidAggregate(group=[{0}], druid=[logical]) + DruidProject(EXPR$0=[SUBSTRING($1, 1, 1)], druid=[logical]) + DruidFilter(condition=[<>($1, '')]) + DruidTableScan(table=[[druid, foo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "groupBy", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "expression", + "name" : "v0", + "expression" : "substring(\"dim2\", 0, 1)", + "outputType" : "STRING" + } ], + "resultFormat" : "compactedList", + "columns" : [ "dim2", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "groupBy", + "dataSource" : { + "type" : "table", + "name" : "foo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "filter" : { + "type" : "not", + "field" : { + "type" : "equals", + "column" : "dim1", + "matchValueType" : "STRING", + "matchValue" : "" + } + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "extraction", + "dimension" : "dim1", + "outputName" : "d0", + "outputType" : "STRING", + "extractionFn" : { + "type" : "substring", + "index" : 0, + "length" : 1 + } + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.d0\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "granularity" : { + "type" : "all" + }, + "dimensions" : [ { + "type" : "default", + "dimension" : "dim2", + "outputName" : "d0", + "outputType" : "STRING" + } ], + "aggregations" : [ { + "type" : "count", + "name" : "a0" + } ], + "limitSpec" : { + "type" : "NoopLimitSpec" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq new file mode 100644 index 000000000000..c9758e24448b --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq @@ -0,0 +1,125 @@ +# testVirtualColumnOnMVFilterJoinExpression case-crc:3277a762 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT foo1.dim3, foo2.dim3 FROM druid.numfoo as foo1 INNER JOIN druid.numfoo as foo2 ON MV_FILTER_ONLY(foo1.dim3, ARRAY['a']) = MV_FILTER_ONLY(foo2.dim3, ARRAY['a']) +; ++-----------+-----------+ +| dim3 | dim3 | ++-----------+-----------+ +| ["a","b"] | ["a","b"] | ++-----------+-----------+ +(1 row) + +!ok +LogicalProject(dim3=[$0], dim30=[$2]) + LogicalJoin(condition=[=($1, $3)], joinType=[inner]) + LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) + LogicalTableScan(table=[[druid, numfoo]]) + LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) + LogicalTableScan(table=[[druid, numfoo]]) + +!logicalPlan +DruidProject(dim3=[$0], dim30=[$2], druid=[logical]) + DruidJoin(condition=[=($1, $3)], joinType=[inner]) + DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "mv-filtered", + "name" : "v0", + "delegate" : { + "type" : "default", + "dimension" : "dim3", + "outputName" : "dim3", + "outputType" : "STRING" + }, + "values" : [ "a" ], + "isAllowList" : true + } ], + "resultFormat" : "compactedList", + "columns" : [ "dim3", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "mv-filtered", + "name" : "v0", + "delegate" : { + "type" : "default", + "dimension" : "dim3", + "outputName" : "dim3", + "outputType" : "STRING" + }, + "values" : [ "a" ], + "isAllowList" : true + } ], + "resultFormat" : "compactedList", + "columns" : [ "dim3", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.v0\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "dim3", "j0.dim3" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq new file mode 100644 index 000000000000..e5733597521a --- /dev/null +++ b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq @@ -0,0 +1,201 @@ +# testVirtualColumnOnMVFilterMultiJoinExpression case-crc:177cadd2 +!set sqlQueryId dummy +!set defaultTimeout 300000 +!set debug true +!set maxScatterGatherBytes 9223372036854775807 +!set enableJoinFilterRewriteValueColumnFilters false +!set enableRewriteJoinToFilter false +!set sqlCurrentTimestamp 2000-01-01T00:00:00Z +!set plannerStrategy DECOUPLED +!set enableJoinFilterRewrite false +!set outputformat mysql +!use druidtest:/// +SELECT foo1.dim3, foo2.dim3 FROM druid.numfoo as foo1 INNER JOIN (SELECT foo3.dim3 FROM druid.numfoo as foo3 INNER JOIN druid.numfoo as foo4 ON MV_FILTER_ONLY(foo3.dim3, ARRAY['a']) = MV_FILTER_ONLY(foo4.dim3, ARRAY['a'])) as foo2 ON MV_FILTER_ONLY(foo1.dim3, ARRAY['a']) = MV_FILTER_ONLY(foo2.dim3, ARRAY['a']) +; ++-----------+-----------+ +| dim3 | dim3 | ++-----------+-----------+ +| ["a","b"] | ["a","b"] | ++-----------+-----------+ +(1 row) + +!ok +LogicalProject(dim3=[$0], dim30=[$2]) + LogicalJoin(condition=[=($1, $3)], joinType=[inner]) + LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) + LogicalTableScan(table=[[druid, numfoo]]) + LogicalProject(dim3=[$0], $f1=[MV_FILTER_ONLY($0, ARRAY('a'))]) + LogicalJoin(condition=[=($1, $2)], joinType=[inner]) + LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) + LogicalTableScan(table=[[druid, numfoo]]) + LogicalProject($f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) + LogicalTableScan(table=[[druid, numfoo]]) + +!logicalPlan +DruidProject(dim3=[$0], dim30=[$2], druid=[logical]) + DruidJoin(condition=[=($1, $3)], joinType=[inner]) + DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + DruidProject(dim3=[$0], $f1=[MV_FILTER_ONLY($0, ARRAY('a'))], druid=[logical]) + DruidJoin(condition=[=($1, $2)], joinType=[inner]) + DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + DruidProject($f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) + DruidTableScan(table=[[druid, numfoo]], druid=[logical]) + +!druidPlan +{ + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "mv-filtered", + "name" : "v0", + "delegate" : { + "type" : "default", + "dimension" : "dim3", + "outputName" : "dim3", + "outputType" : "STRING" + }, + "values" : [ "a" ], + "isAllowList" : true + } ], + "resultFormat" : "compactedList", + "columns" : [ "dim3", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "join", + "left" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "mv-filtered", + "name" : "v0", + "delegate" : { + "type" : "default", + "dimension" : "dim3", + "outputName" : "dim3", + "outputType" : "STRING" + }, + "values" : [ "a" ], + "isAllowList" : true + } ], + "resultFormat" : "compactedList", + "columns" : [ "dim3", "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "right" : { + "type" : "query", + "query" : { + "queryType" : "scan", + "dataSource" : { + "type" : "table", + "name" : "numfoo" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "mv-filtered", + "name" : "v0", + "delegate" : { + "type" : "default", + "dimension" : "dim3", + "outputName" : "dim3", + "outputType" : "STRING" + }, + "values" : [ "a" ], + "isAllowList" : true + } ], + "resultFormat" : "compactedList", + "columns" : [ "v0" ], + "legacy" : false, + "columnTypes" : [ "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "j0.", + "condition" : "(\"v0\" == \"j0.v0\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "virtualColumns" : [ { + "type" : "mv-filtered", + "name" : "_v0", + "delegate" : { + "type" : "default", + "dimension" : "dim3", + "outputName" : "dim3", + "outputType" : "STRING" + }, + "values" : [ "a" ], + "isAllowList" : true + } ], + "resultFormat" : "compactedList", + "columns" : [ "_v0", "dim3" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } + } + }, + "rightPrefix" : "_j0.", + "condition" : "(\"v0\" == \"_j0._v0\")", + "joinType" : "INNER" + }, + "intervals" : { + "type" : "intervals", + "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] + }, + "resultFormat" : "compactedList", + "columns" : [ "_j0.dim3", "dim3" ], + "legacy" : false, + "columnTypes" : [ "STRING", "STRING" ], + "granularity" : { + "type" : "all" + } +} +!nativePlan From 38471a621db998d0ad466549d8bac72bf9195076 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:11:45 +0000 Subject: [PATCH 09/24] undo not needed change --- .../org/apache/druid/sql/calcite/util/CalciteTestBase.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java index 4604318456fa..9a69c62dc734 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java @@ -70,8 +70,7 @@ public static void setupCalciteProperties() public void setCaseTempDir(TestInfo testInfo) { String methodName = testInfo.getTestMethod().get().getName(); - Path path = FileUtils.createTempDirInLocation(rootTempPath, methodName).toPath(); - casetempPath = path; + casetempPath = FileUtils.createTempDirInLocation(rootTempPath, methodName).toPath(); } public File newTempFolder() From d5bf196c12b6fa0dcafda27f543a01a2be22deca Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:10:09 +0000 Subject: [PATCH 10/24] remove&undo quidem run in decoupledextension for now --- .../sql/calcite/BaseCalciteQueryTest.java | 27 ++- .../sql/calcite/CalciteJoinQueryTest.java | 50 ++--- .../druid/sql/calcite/CalciteQueryTest.java | 20 +- .../druid/sql/calcite/DecoupledExtension.java | 54 ----- ...DecoupledPlanningCalciteJoinQueryTest.java | 7 - .../DecoupledPlanningCalciteQueryTest.java | 7 - ...ecoupledPlanningCalciteUnionQueryTest.java | 7 - .../apache/druid/sql/calcite/QTestCase.java | 122 ----------- .../druid/sql/calcite/QueryTestBuilder.java | 6 - .../druid/sql/calcite/QueryTestRunner.java | 24 --- .../testCommaJoinLeftFunction.iq | 89 -------- .../testExactTopNOnInnerJoinWithLimit.iq | 115 ---------- ...upByOverInnerJoinOnTwoInlineDataSources.iq | 164 -------------- .../testInnerJoinCastLeft.iq | 89 -------- .../testInnerJoinLeftFunction.iq | 92 -------- ...rcesWithOuterWhere_withLeftDirectAccess.iq | 134 ------------ ...oInlineDataSources_withLeftDirectAccess.iq | 134 ------------ .../testInnerJoinQueryOfLookup.iq | 112 ---------- .../testInnerJoinQueryOfLookupRemovable.iq | 95 --------- ...testInnerJoinSubqueryWithSelectorFilter.iq | 94 -------- ...JoinTwoLookupsToTableUsingNumericColumn.iq | 110 ---------- ...oupByInsteadOfTimeseriesWithFloorOnTime.iq | 155 -------------- ...loorOnTimeWithNoAggregateMultipleValues.iq | 155 -------------- .../testJoinOnTimeseriesWithFloorOnTime.iq | 138 ------------ .../testJoinWithInputRefCondition.iq | 185 ---------------- ...rcesWithOuterWhere_withLeftDirectAccess.iq | 134 ------------ ...rcesWithTimeFilter_withLeftDirectAccess.iq | 140 ------------ ...oInlineDataSources_withLeftDirectAccess.iq | 134 ------------ .../testLeftJoinSubqueryWithSelectorFilter.iq | 99 --------- ...ntiJoinSimultaneouslyUsingExplicitJoins.iq | 139 ------------ ...OnStringWithNonSortedOrUniqueDictionary.iq | 86 -------- ...thNonSortedOrUniqueDictionaryOrderByDim.iq | 88 -------- .../testUsingSubqueryWithExtractionFns.iq | 139 ------------ ...stVirtualColumnOnMVFilterJoinExpression.iq | 125 ----------- ...tualColumnOnMVFilterMultiJoinExpression.iq | 201 ------------------ ...DistinctWithGroupingAndOtherAggregators.iq | 69 ------ .../testGroupByLimitPushdownExtraction.iq | 84 -------- .../testGroupBySortPushDown.iq | 75 ------- ...TimeFloorAndDimOnGroupByTimeFloorAndDim.iq | 145 ------------- ...estGroupByWithLiteralInSubqueryGrouping.iq | 109 ---------- ...ithGroupingAndOtherAggregatorsUsingJoin.iq | 79 ------- ...eatedIdenticalVirtualExpressionGrouping.iq | 70 ------ .../testSubqueryTypeMismatchWithLiterals.iq | 110 ---------- .../testWindowingWithScanAndSort.iq | 201 ------------------ 44 files changed, 48 insertions(+), 4364 deletions(-) delete mode 100644 sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq delete mode 100644 sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java index 58ff9e4ff1e3..854ac2215985 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java @@ -124,7 +124,6 @@ import org.junit.Assert; import org.junit.internal.matchers.ThrowableMessageMatcher; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Named; import org.junit.jupiter.api.extension.RegisterExtension; import javax.annotation.Nullable; @@ -1395,51 +1394,51 @@ public static Object[] provideQueryContexts() { return new Object[] { // default behavior - Named.of("default", QUERY_CONTEXT_DEFAULT), + QUERY_CONTEXT_DEFAULT, // all rewrites enabled - Named.of("all_enabled", new ImmutableMap.Builder() + new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build()), + .build(), // filter-on-value-column rewrites disabled, everything else enabled - Named.of("filter-on-value-column_disabled", new ImmutableMap.Builder() + new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build()), + .build(), // filter rewrites fully disabled, join-to-filter enabled - Named.of("join-to-filter", new ImmutableMap.Builder() + new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build()), + .build(), // filter rewrites disabled, but value column filters still set to true // (it should be ignored and this should // behave the same as the previous context) - Named.of("filter-rewrites-disabled", new ImmutableMap.Builder() + new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build()), + .build(), // filter rewrites fully enabled, join-to-filter disabled - Named.of("filter-rewrites", new ImmutableMap.Builder() + new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) - .build()), + .build(), // all rewrites disabled - Named.of("all_disabled", new ImmutableMap.Builder() + new ImmutableMap.Builder() .putAll(QUERY_CONTEXT_DEFAULT) .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) - .build()), + .build(), }; } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java index c75e46f69773..bf631da78e51 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java @@ -183,7 +183,7 @@ public void testInnerJoinWithLimitAndAlias() // to compute the query with limit 1. @SqlTestFrameworkConfig(minTopNThreshold = 1) @Test - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) public void testExactTopNOnInnerJoinWithLimit() { Map context = new HashMap<>(QUERY_CONTEXT_DEFAULT); @@ -491,7 +491,7 @@ public void testJoinWithLimitBeforeJoining() } @Test - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinOnTimeseriesWithFloorOnTime() { // Cannot vectorize JOIN operator. @@ -546,7 +546,7 @@ public void testJoinOnTimeseriesWithFloorOnTime() } @Test - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime() { // Cannot vectorize JOIN operator. @@ -613,7 +613,7 @@ public void testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime() } @Test - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues() { // Cannot vectorize JOIN operator. @@ -1528,7 +1528,7 @@ public void testManyManyInnerJoinOnManyManyLookup(Map queryConte ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.FINALIZING_FIELD_ACCESS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.FINALIZING_FIELD_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinQueryOfLookup(Map queryContext) @@ -1608,7 +1608,7 @@ public void testTimeColumnAggregationsOnLookups(Map queryContext } } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinQueryOfLookupRemovable(Map queryContext) @@ -1647,7 +1647,7 @@ public void testInnerJoinQueryOfLookupRemovable(Map queryContext ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinTwoLookupsToTableUsingNumericColumn(Map queryContext) @@ -1975,7 +1975,7 @@ public void testWhereInSelectNullFromLookup() } @Test - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testCommaJoinLeftFunction() { testQuery( @@ -2150,7 +2150,7 @@ public void testJoinTableLookupTableMismatchedTypesWithoutComma(Map queryContext) @@ -2279,7 +2279,7 @@ public void testInnerJoinMismatchedTypes(Map queryContext) ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinLeftFunction(Map queryContext) @@ -2732,7 +2732,7 @@ public void testNotInAggregationSubquery(Map queryContext) ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testUsingSubqueryWithExtractionFns(Map queryContext) @@ -2936,7 +2936,7 @@ public void testLeftJoinOnTwoInlineDataSourcesWithTimeFilter(Map ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess(Map queryContext) @@ -3048,7 +3048,7 @@ public void testLeftJoinOnTwoInlineDataSourcesWithOuterWhere(Map ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess(Map queryContext) @@ -3150,7 +3150,7 @@ public void testLeftJoinOnTwoInlineDataSources(Map queryContext) ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess(Map queryContext) @@ -3252,7 +3252,7 @@ public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere(Map queryContext) @@ -3354,7 +3354,7 @@ public void testInnerJoinOnTwoInlineDataSources(Map queryContext ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources(Map queryContext) @@ -3440,7 +3440,7 @@ public void testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources(Map queryContext) @@ -3670,7 +3670,7 @@ public void testLeftJoinSubqueryWithNullKeyFilter(Map queryConte ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testLeftJoinSubqueryWithSelectorFilter(Map queryContext) @@ -3876,7 +3876,7 @@ public void testJoinWithExplicitIsNotDistinctFromCondition(Map q ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testInnerJoinSubqueryWithSelectorFilter(Map queryContext) @@ -4152,7 +4152,7 @@ public void testSemiAndAntiJoinSimultaneouslyUsingWhereInSubquery(Map queryContext) @@ -5153,7 +5153,7 @@ public void testCountOnSemiJoinSingleColumn(Map queryContext) ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testTopNOnStringWithNonSortedOrUniqueDictionary(Map queryContext) @@ -5194,7 +5194,7 @@ public void testTopNOnStringWithNonSortedOrUniqueDictionary(Map ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim(Map queryContext) @@ -5235,7 +5235,7 @@ public void testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim(Map queryContext) @@ -5292,7 +5292,7 @@ public void testVirtualColumnOnMVFilterJoinExpression(Map queryC ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") public void testVirtualColumnOnMVFilterMultiJoinExpression(Map queryContext) @@ -6028,7 +6028,7 @@ public void testJoinsWithThreeConditions() } @Test - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) public void testJoinWithInputRefCondition() { cannotVectorize(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 44d5dcbf3e67..478648088c32 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -6928,7 +6928,7 @@ public void testApproxCountDistinctBuiltin() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testExactCountDistinctWithGroupingAndOtherAggregators() { @@ -6983,7 +6983,7 @@ public void testExactCountDistinctWithGroupingAndOtherAggregators() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin() { @@ -8182,7 +8182,7 @@ public void testRegexpLikeFilter() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGG_COL_EXCHANGE) @Test public void testGroupBySortPushDown() { @@ -8278,7 +8278,7 @@ public void testGroupByLimitPushDownWithHavingOnLong() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByLimitPushdownExtraction() { @@ -8725,7 +8725,7 @@ public void testGroupByFloor() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @SqlTestFrameworkConfig(numMergeBuffers = 3) @Test public void testQueryWithSelectProjectAndIdentityProjectDoesNotRename() @@ -10570,7 +10570,7 @@ public void testGroupByTimeAndOtherDimension() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim() { @@ -12705,7 +12705,7 @@ public void testNvlColumns() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testGroupByWithLiteralInSubqueryGrouping() { @@ -12894,7 +12894,7 @@ public void testQueryContextOuterLimit() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.IMPROVED_PLAN) @Test public void testRepeatedIdenticalVirtualExpressionGrouping() { @@ -14470,7 +14470,7 @@ public void testGreatestFunctionForStringWithIsNull() ); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.AGGREGATE_REMOVE_NOT_FIRED) @Test public void testSubqueryTypeMismatchWithLiterals() { @@ -15192,7 +15192,7 @@ public void testScanAndSortCanGetSchemaFromScanQuery() .run(); } - @DecoupledTestConfig(quidem = true, nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) @Test public void testWindowingWithScanAndSort() { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java index f85e7dc34e7b..508ff54aec2d 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java @@ -19,12 +19,8 @@ package org.apache.druid.sql.calcite; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; -import com.google.common.io.Files; import org.apache.druid.query.QueryContexts; -import org.apache.druid.quidem.DruidQTestInfo; -import org.apache.druid.quidem.DruidQuidemTestBase; import org.apache.druid.quidem.ProjectPathUtils; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.sql.calcite.BaseCalciteQueryTest.CalciteTestConfig; @@ -35,13 +31,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import java.io.File; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - import static org.junit.Assume.assumeTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; public class DecoupledExtension implements BeforeEachCallback { @@ -59,37 +49,6 @@ public void beforeEach(ExtensionContext context) throws Exception { Class testClass = context.getTestClass().get(); qCaseDir = ProjectPathUtils.getPathFromProjectRoot("sql/src/test/quidem/" + testClass.getName()); - validateTestClass(context); - } - - private void validateTestClass(ExtensionContext context) throws Exception - { - Class testClass = context.getTestClass().get(); - String methodName = "validateTestClass"; - Method testMethod = Preconditions.checkNotNull( - testClass.getMethod(methodName), "Please add validateTestClass() test method to the testClass!" - ); - if (methodName.equals(testMethod.getName())) { - checkAnnotationConsistency(testClass); - } - } - - private void checkAnnotationConsistency(Class testClass) - { - Map testNameToFileMap = new HashMap<>(); - if (qCaseDir.exists()) { - for (File iqFile : qCaseDir.listFiles(f -> f.getName().endsWith(DruidQuidemTestBase.IQ_SUFFIX))) { - testNameToFileMap.put(Files.getNameWithoutExtension(iqFile.getName()), iqFile); - } - } - for (Method method : testClass.getMethods()) { - DecoupledTestConfig dtc = method.getAnnotation(DecoupledTestConfig.class); - if (dtc == null || !dtc.quidem()) { - continue; - } - testNameToFileMap.remove(method.getName()); - } - assertEquals(Collections.emptyMap(), testNameToFileMap, "Please remove dangling quidem files!"); } private static final ImmutableMap CONTEXT_OVERRIDES = ImmutableMap.builder() @@ -107,11 +66,8 @@ public QueryTestBuilder testBuilder() PlannerComponentSupplier componentSupplier = baseTest; - boolean runQuidem = (decTestConfig != null && decTestConfig.quidem()); - CalciteTestConfig testConfig = baseTest.new CalciteTestConfig(CONTEXT_OVERRIDES) { - @Override public SqlTestFramework.PlannerFixture plannerFixture(PlannerConfig plannerConfig, AuthConfig authConfig) { @@ -119,16 +75,6 @@ public SqlTestFramework.PlannerFixture plannerFixture(PlannerConfig plannerConfi return baseTest.queryFramework().plannerFixture(componentSupplier, plannerConfig, authConfig); } - - @Override - public DruidQTestInfo getQTestInfo() - { - if (runQuidem) { - return new DruidQTestInfo(qCaseDir, BaseCalciteQueryTest.queryFrameworkRule.testName()); - } else { - return null; - } - } }; QueryTestBuilder builder = new QueryTestBuilder(testConfig) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java index c8c7fce72fad..dba11b35ffeb 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java @@ -21,7 +21,6 @@ import org.apache.druid.sql.calcite.DisableUnless.DisableUnlessRule; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; @@ -45,12 +44,6 @@ protected QueryTestBuilder testBuilder() return decoupledExtension.testBuilder(); } - @Test - public void validateTestClass() - { - // technical testcase needed by the extension temporarily - } - @MethodSource("provideQueryContexts") @ParameterizedTest(name = "{0}") @DecoupledTestConfig diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java index befa7e48c879..7d12ff56f4b4 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java @@ -20,7 +20,6 @@ package org.apache.druid.sql.calcite; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; @@ -35,10 +34,4 @@ protected QueryTestBuilder testBuilder() { return decoupledExtension.testBuilder(); } - - @Test - public void validateTestClass() - { - // technical testcase needed by the extension temporarily - } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java index ebdf3f25b029..8a541a2ed975 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java @@ -20,7 +20,6 @@ package org.apache.druid.sql.calcite; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; @@ -35,10 +34,4 @@ protected QueryTestBuilder testBuilder() { return decoupledExtension.testBuilder(); } - - @Test - public void validateTestClass() - { - // technical testcase needed by the extension temporarily - } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java b/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java deleted file mode 100644 index 7bb4fcd61333..000000000000 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QTestCase.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.druid.sql.calcite; - -import com.google.common.hash.HashCode; -import com.google.common.hash.Hashing; -import com.google.common.io.Files; -import org.apache.druid.common.config.NullHandling; -import org.apache.druid.java.util.common.FileUtils; -import org.apache.druid.java.util.common.StringUtils; -import org.apache.druid.quidem.DruidQTestInfo; -import org.apache.druid.quidem.DruidQuidemTestBase; -import org.apache.druid.quidem.DruidQuidemTestBase.DruidQuidemRunner; -import org.apache.druid.sql.calcite.QueryTestRunner.QueryRunStep; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -public class QTestCase -{ - private StringBuffer sb; - private DruidQTestInfo testInfo; - - public QTestCase(DruidQTestInfo testInfo) - { - this.testInfo = testInfo; - sb = new StringBuffer(); - } - - public void println(String str) - { - sb.append(str); - sb.append("\n"); - } - - public QueryRunStep toRunner() - { - return new QueryRunStep(null) - { - - @Override - public void run() - { - assumeTrue(NullHandling.sqlCompatible(), "Quidem tests are only run in sql-compatible mode!"); - try { - if (DruidQuidemRunner.isOverwrite()) { - writeCaseTo(testInfo.getIQFile()); - } else { - isValidTestCaseFile(testInfo.getIQFile()); - } - - DruidQuidemRunner runner = new DruidQuidemTestBase.DruidQuidemRunner(); - runner.run(testInfo.getIQFile()); - } - catch (Exception e) { - throw new RuntimeException("Error running quidem test", e); - } - } - }; - } - - protected void isValidTestCaseFile(File iqFile) - { - if (!iqFile.exists()) { - throw new IllegalStateException("testcase doesn't exists; run with (-Dquidem.overwrite) : " + iqFile); - } - try { - String header = makeHeader(); - String testCaseFirstLine = Files.asCharSource(iqFile, StandardCharsets.UTF_8).readFirstLine(); - if (!header.equals(testCaseFirstLine)) { - throw new IllegalStateException( - "backing quidem testcase doesn't match test - run with (-Dquidem.overwrite) : " + iqFile - ); - } - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - private String makeHeader() - { - HashCode hash = Hashing.crc32().hashBytes(sb.toString().getBytes(StandardCharsets.UTF_8)); - return StringUtils.format("# %s case-crc:%s", testInfo.testName, hash); - - } - - public void writeCaseTo(File file) throws IOException - { - FileUtils.mkdirp(file.getParentFile()); - try (FileOutputStream fos = new FileOutputStream(file)) { - fos.write(makeHeader().getBytes(StandardCharsets.UTF_8)); - fos.write('\n'); - fos.write(sb.toString().getBytes(StandardCharsets.UTF_8)); - } - catch (IOException e) { - throw new RuntimeException("Error writing testcase to: " + file, e); - } - } - -} diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java index d06ac1d1c121..ff7e9b5a6bac 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java @@ -23,7 +23,6 @@ import com.google.common.base.Preconditions; import org.apache.druid.query.Query; import org.apache.druid.query.QueryContexts; -import org.apache.druid.quidem.DruidQTestInfo; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.server.security.AuthenticationResult; @@ -76,11 +75,6 @@ public interface QueryTestConfig boolean isRunningMSQ(); Map baseQueryContext(); - - default DruidQTestInfo getQTestInfo() - { - return null; - } } protected final QueryTestConfig config; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java index 5899440128d8..58fa5635e8f5 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java @@ -33,7 +33,6 @@ import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.Query; import org.apache.druid.query.QueryContexts; -import org.apache.druid.quidem.DruidQTestInfo; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.server.security.ResourceAction; import org.apache.druid.sql.DirectStatement; @@ -56,7 +55,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -636,28 +634,6 @@ public void verify() public QueryTestRunner(QueryTestBuilder builder) { QueryTestConfig config = builder.config; - DruidQTestInfo iqTestInfo = config.getQTestInfo(); - if (iqTestInfo != null) { - QTestCase qt = new QTestCase(iqTestInfo); - Map queryContext = builder.getQueryContext(); - for (Entry entry : queryContext.entrySet()) { - qt.println(StringUtils.format("!set %s %s", entry.getKey(), entry.getValue())); - } - qt.println("!set outputformat mysql"); - qt.println("!use druidtest:///"); - - qt.println(builder.sql + ";"); - if (builder.expectedResults != null) { - qt.println("!ok"); - } - qt.println("!logicalPlan"); - qt.println("!druidPlan"); - if (builder.expectedQueries != null) { - qt.println("!nativePlan"); - } - runSteps.add(qt.toRunner()); - return; - } if (builder.expectedResultsVerifier == null && builder.expectedResults != null) { builder.expectedResultsVerifier = config.defaultResultsVerifier( builder.expectedResults, diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq deleted file mode 100644 index 6af247ffc7e7..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testCommaJoinLeftFunction.iq +++ /dev/null @@ -1,89 +0,0 @@ -# testCommaJoinLeftFunction case-crc:40471241 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT foo.dim1, foo.dim2, l.k, l.v -FROM foo, lookup.lookyloo l -WHERE SUBSTRING(foo.dim2, 1, 1) = l.k -; -+------+------+---+----+ -| dim1 | dim2 | k | v | -+------+------+---+----+ -| | a | a | xa | -| 1 | a | a | xa | -| def | abc | a | xa | -+------+------+---+----+ -(3 rows) - -!ok -LogicalProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4]) - LogicalJoin(condition=[=($2, $3)], joinType=[inner]) - LogicalProject(dim1=[$1], dim2=[$2], $f2=[SUBSTRING($2, 1, 1)]) - LogicalTableScan(table=[[druid, foo]]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4], druid=[logical]) - DruidJoin(condition=[=($2, $3)], joinType=[inner]) - DruidProject(dim1=[$1], dim2=[$2], $f2=[SUBSTRING($2, 1, 1)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "substring(\"dim2\", 0, 1)", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "dim1", "dim2", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.k\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "dim1", "dim2", "j0.k", "j0.v" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING", "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq deleted file mode 100644 index 304cbda993b6..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testExactTopNOnInnerJoinWithLimit.iq +++ /dev/null @@ -1,115 +0,0 @@ -# testExactTopNOnInnerJoinWithLimit case-crc:bbbef51a -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set useApproximateTopN false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set outputformat mysql -!use druidtest:/// -select f1."dim4", sum("m1") from numfoo f1 inner join ( - select "dim4" from numfoo where dim4 <> 'a' group by 1 -) f2 on f1."dim4" = f2."dim4" group by 1 limit 1; -+------+--------+ -| dim4 | EXPR$1 | -+------+--------+ -| b | 15.0 | -+------+--------+ -(1 row) - -!ok -LogicalSort(fetch=[1]) - LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)]) - LogicalJoin(condition=[=($0, $2)], joinType=[inner]) - LogicalProject(dim4=[$4], m1=[$14]) - LogicalTableScan(table=[[druid, numfoo]]) - LogicalAggregate(group=[{4}]) - LogicalFilter(condition=[<>($4, 'a')]) - LogicalTableScan(table=[[druid, numfoo]]) - -!logicalPlan -DruidSort(fetch=[1], druid=[logical]) - DruidAggregate(group=[{0}], EXPR$1=[SUM($1)], druid=[logical]) - DruidJoin(condition=[=($0, $2)], joinType=[inner]) - DruidProject(dim4=[$4], m1=[$14], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - DruidAggregate(group=[{4}], druid=[logical]) - DruidFilter(condition=[<>($4, 'a')]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "topN", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "numfoo" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "filter" : { - "type" : "not", - "field" : { - "type" : "equals", - "column" : "dim4", - "matchValueType" : "STRING", - "matchValue" : "a" - } - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim4", - "outputName" : "_d0", - "outputType" : "STRING" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"dim4\" == \"j0._d0\")", - "joinType" : "INNER" - }, - "dimension" : { - "type" : "default", - "dimension" : "dim4", - "outputName" : "d0", - "outputType" : "STRING" - }, - "metric" : { - "type" : "dimension", - "ordering" : { - "type" : "lexicographic" - } - }, - "threshold" : 1, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "aggregations" : [ { - "type" : "doubleSum", - "name" : "a0", - "fieldName" : "m1" - } ] -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq deleted file mode 100644 index a0393243cac1..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources.iq +++ /dev/null @@ -1,164 +0,0 @@ -# testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources case-crc:a595df5b -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -with abc as -( - SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' -) -SELECT dim1 from (SELECT dim1,__time FROM (SELECT t1.dim1, t1."__time" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1) GROUP BY 1,2) GROUP BY dim1 -; -+------+ -| dim1 | -+------+ -| 10.1 | -+------+ -(1 row) - -!ok -LogicalAggregate(group=[{0}]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR]) - LogicalAggregate(group=[{1}]) - LogicalJoin(condition=[=($0, $2)], joinType=[inner]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(dim1=[$1]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{0}], druid=[logical]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], druid=[logical]) - DruidAggregate(group=[{1}], druid=[logical]) - DruidJoin(condition=[=($0, $2)], joinType=[inner]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(dim1=[$1], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "__time", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "dim1" ], - "legacy" : false, - "columnTypes" : [ "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.dim1\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "__time", - "outputName" : "d0", - "outputType" : "LONG" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "_d0", - "outputType" : "STRING" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq deleted file mode 100644 index 664e031edaac..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinCastLeft.iq +++ /dev/null @@ -1,89 +0,0 @@ -# testInnerJoinCastLeft case-crc:96c532bb -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT foo.m1, l.k, l.v -FROM foo -INNER JOIN lookup.lookyloo l ON CAST(foo.m1 AS VARCHAR) = l.k -; -+----+---+---+ -| m1 | k | v | -+----+---+---+ -+----+---+---+ -(0 rows) - -!ok -LogicalProject(m1=[$0], k=[$2], v=[$3]) - LogicalJoin(condition=[=($1, $2)], joinType=[inner]) - LogicalProject(m1=[$5], m10=[CAST($5):VARCHAR]) - LogicalTableScan(table=[[druid, foo]]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidProject(m1=[$0], k=[$2], v=[$3], druid=[logical]) - DruidJoin(condition=[=($1, $2)], joinType=[inner]) - DruidProject(m1=[$5], m10=[CAST($5):VARCHAR], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "CAST(\"m1\", 'STRING')", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "m1", "v0" ], - "legacy" : false, - "columnTypes" : [ "FLOAT", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.k\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "j0.k", "j0.v", "m1" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING", "FLOAT" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq deleted file mode 100644 index c87313c3bbb1..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinLeftFunction.iq +++ /dev/null @@ -1,92 +0,0 @@ -# testInnerJoinLeftFunction case-crc:8d4f8e31 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT foo.dim1, foo.dim2, l.k, l.v -FROM foo -INNER JOIN lookup.lookyloo l ON SUBSTRING(foo.dim2, 1, 1) = l.k -; -+------+------+---+----+ -| dim1 | dim2 | k | v | -+------+------+---+----+ -| | a | a | xa | -| 1 | a | a | xa | -| def | abc | a | xa | -+------+------+---+----+ -(3 rows) - -!ok -LogicalProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4]) - LogicalJoin(condition=[=($2, $3)], joinType=[inner]) - LogicalProject(dim1=[$1], dim2=[$2], $f8=[SUBSTRING($2, 1, 1)]) - LogicalTableScan(table=[[druid, foo]]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidProject(dim1=[$0], dim2=[$1], k=[$3], v=[$4], druid=[logical]) - DruidJoin(condition=[=($2, $3)], joinType=[inner]) - DruidProject(dim1=[$1], dim2=[$2], $f8=[SUBSTRING($2, 1, 1)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "substring(\"dim2\", 0, 1)", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "dim1", "dim2", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.k\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "dim1", "dim2", "j0.k", "j0.v" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING", "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq deleted file mode 100644 index edc3f547c91f..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq +++ /dev/null @@ -1,134 +0,0 @@ -# testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess case-crc:c9234000 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set enableJoinLeftTableScanDirect true -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -with abc as -( - SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' -) -SELECT t1.dim1, t1."__time" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1' -; -+------+---------------------+ -| dim1 | __time | -+------+---------------------+ -| 10.1 | 2000-01-02 00:00:00 | -+------+---------------------+ -(1 row) - -!ok -LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) - LogicalJoin(condition=[=($0, $2)], joinType=[inner]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(dim1=[$1]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) - DruidJoin(condition=[=($0, $2)], joinType=[inner]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(dim1=[$1], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "__time", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "dim1" ], - "legacy" : false, - "columnTypes" : [ "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.dim1\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "_v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "_v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq deleted file mode 100644 index d421397b0158..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.iq +++ /dev/null @@ -1,134 +0,0 @@ -# testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess case-crc:9b3900d5 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set enableJoinLeftTableScanDirect true -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -with abc as -( - SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' -) -SELECT t1.dim1, t1."__time" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1 -; -+------+---------------------+ -| dim1 | __time | -+------+---------------------+ -| 10.1 | 2000-01-02 00:00:00 | -+------+---------------------+ -(1 row) - -!ok -LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) - LogicalJoin(condition=[=($0, $2)], joinType=[inner]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(dim1=[$1]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) - DruidJoin(condition=[=($0, $2)], joinType=[inner]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(dim1=[$1], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "__time", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "dim1" ], - "legacy" : false, - "columnTypes" : [ "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.dim1\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "_v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "_v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq deleted file mode 100644 index ea94aae48a93..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookup.iq +++ /dev/null @@ -1,112 +0,0 @@ -# testInnerJoinQueryOfLookup case-crc:06d01cd2 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT dim1, dim2, t1.v, t1.v -FROM foo -INNER JOIN - (SELECT SUBSTRING(k, 1, 1) k, ANY_VALUE(v, 10) v FROM lookup.lookyloo GROUP BY 1) t1 - ON foo.dim2 = t1.k; -+------+------+------+------+ -| dim1 | dim2 | v | v | -+------+------+------+------+ -| | a | xabc | xabc | -| 1 | a | xabc | xabc | -+------+------+------+------+ -(2 rows) - -!ok -LogicalProject(dim1=[$0], dim2=[$1], v=[$3], v0=[$3]) - LogicalJoin(condition=[=($1, $2)], joinType=[inner]) - LogicalProject(dim1=[$1], dim2=[$2]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{0}], v=[ANY_VALUE($1, $2)]) - LogicalProject(k=[SUBSTRING($0, 1, 1)], v=[$1], $f2=[10]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidProject(dim1=[$0], dim2=[$1], v=[$3], v0=[$3], druid=[logical]) - DruidJoin(condition=[=($1, $2)], joinType=[inner]) - DruidProject(dim1=[$1], dim2=[$2], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{0}], v=[ANY_VALUE($1, $2)], druid=[logical]) - DruidProject(k=[SUBSTRING($0, 1, 1)], v=[$1], $f2=[10], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "foo" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "extraction", - "dimension" : "k", - "outputName" : "d0", - "outputType" : "STRING", - "extractionFn" : { - "type" : "substring", - "index" : 0, - "length" : 1 - } - } ], - "aggregations" : [ { - "type" : "stringAny", - "name" : "a0:a", - "fieldName" : "v", - "maxStringBytes" : 10, - "aggregateMultipleValues" : true - } ], - "postAggregations" : [ { - "type" : "finalizingFieldAccess", - "name" : "a0", - "fieldName" : "a0:a" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"dim2\" == \"j0.d0\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "dim1", "dim2", "j0.a0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq deleted file mode 100644 index 7d4926868c04..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinQueryOfLookupRemovable.iq +++ /dev/null @@ -1,95 +0,0 @@ -# testInnerJoinQueryOfLookupRemovable case-crc:f94036af -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT dim1, dim2, t1.sk -FROM foo -INNER JOIN - (SELECT k, SUBSTRING(v, 1, 3) sk FROM lookup.lookyloo) t1 - ON foo.dim2 = t1.k; -+------+------+-----+ -| dim1 | dim2 | sk | -+------+------+-----+ -| | a | xa | -| 1 | a | xa | -| def | abc | xab | -+------+------+-----+ -(3 rows) - -!ok -LogicalProject(dim1=[$0], dim2=[$1], sk=[$3]) - LogicalJoin(condition=[=($1, $2)], joinType=[inner]) - LogicalProject(dim1=[$1], dim2=[$2]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(k=[$0], sk=[SUBSTRING($1, 1, 3)]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidProject(dim1=[$0], dim2=[$1], sk=[$3], druid=[logical]) - DruidJoin(condition=[=($1, $2)], joinType=[inner]) - DruidProject(dim1=[$1], dim2=[$2], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(k=[$0], sk=[SUBSTRING($1, 1, 3)], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "foo" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "substring(\"v\", 0, 3)", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "k", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"dim2\" == \"j0.k\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "dim1", "dim2", "j0.v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq deleted file mode 100644 index 9c1d6306ddf2..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinSubqueryWithSelectorFilter.iq +++ /dev/null @@ -1,94 +0,0 @@ -# testInnerJoinSubqueryWithSelectorFilter case-crc:ecd38651 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT dim1, l1.k FROM foo INNER JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 ON foo.dim1 = l1.k and l1.k = 'abc'; -+------+-----+ -| dim1 | k | -+------+-----+ -| abc | abc | -+------+-----+ -(1 row) - -!ok -LogicalJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) - LogicalProject(dim1=[$1]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{0}]) - LogicalProject(k=[||($0, '')]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) - DruidProject(dim1=[$1], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{0}], druid=[logical]) - DruidProject(k=[||($0, '')], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "foo" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "concat(\"k\",'')", - "outputType" : "STRING" - } ], - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "((\"dim1\" == \"j0.d0\") && (\"j0.d0\" == 'abc'))", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "dim1", "j0.d0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq deleted file mode 100644 index 1824f446759d..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testInnerJoinTwoLookupsToTableUsingNumericColumn.iq +++ /dev/null @@ -1,110 +0,0 @@ -# testInnerJoinTwoLookupsToTableUsingNumericColumn case-crc:ac4fadf1 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT COUNT(*) -FROM foo -INNER JOIN lookup.lookyloo l1 ON l1.k = foo.m1 -INNER JOIN lookup.lookyloo l2 ON l2.k = l1.k; -+--------+ -| EXPR$0 | -+--------+ -| 1 | -+--------+ -(1 row) - -!ok -LogicalAggregate(group=[{}], EXPR$0=[COUNT()]) - LogicalJoin(condition=[=($1, $0)], joinType=[inner]) - LogicalProject(k=[$1]) - LogicalJoin(condition=[=($2, $0)], joinType=[inner]) - LogicalProject(m1=[$5]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(k=[$0], k0=[CAST($0):FLOAT]) - LogicalTableScan(table=[[lookup, lookyloo]]) - LogicalProject(k=[$0]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidAggregate(group=[{}], EXPR$0=[COUNT()], druid=[logical]) - DruidJoin(condition=[=($1, $0)], joinType=[inner]) - DruidProject(k=[$1], druid=[logical]) - DruidJoin(condition=[=($2, $0)], joinType=[inner]) - DruidProject(m1=[$5], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(k=[$0], k0=[CAST($0):FLOAT], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - DruidProject(k=[$0], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "timeseries", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "foo" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "CAST(\"k\", 'DOUBLE')", - "outputType" : "FLOAT" - } ], - "resultFormat" : "compactedList", - "columns" : [ "k", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "FLOAT" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"j0.v0\" == \"m1\")", - "joinType" : "INNER" - }, - "right" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "rightPrefix" : "_j0.", - "condition" : "(\"_j0.k\" == \"j0.k\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "aggregations" : [ { - "type" : "count", - "name" : "a0" - } ] -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq deleted file mode 100644 index 903843303001..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime.iq +++ /dev/null @@ -1,155 +0,0 @@ -# testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTime case-crc:b7a9de50 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT CAST(__time AS BIGINT), m1, ANY_VALUE(dim3, 100) FROM foo WHERE (CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1, m1) IN - ( - SELECT CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1 AS t1, MIN(m1) AS t2 FROM foo WHERE dim3 = 'b' - AND __time BETWEEN '1994-04-29 00:00:00' AND '2020-01-11 00:00:00' GROUP BY 1 - ) -GROUP BY 1, 2 -; -+--------------+-----+--------+ -| EXPR$0 | m1 | EXPR$2 | -+--------------+-----+--------+ -| 946684800000 | 1.0 | [a, b] | -| 946771200000 | 2.0 | [b, c] | -+--------------+-----+--------+ -(2 rows) - -!ok -LogicalAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3)]) - LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100]) - LogicalJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) - LogicalProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{0}], t2=[MIN($1)]) - LogicalProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5]) - LogicalFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3)], druid=[logical]) - DruidProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], druid=[logical]) - DruidJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) - DruidProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{0}], t2=[MIN($1)], druid=[logical]) - DruidProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5], druid=[logical]) - DruidFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", - "outputType" : "LONG" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "dim3", "m1", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING", "FLOAT", "LONG" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "1994-04-29T00:00:00.000Z/2020-01-11T00:00:00.001Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", - "outputType" : "LONG" - } ], - "filter" : { - "type" : "equals", - "column" : "dim3", - "matchValueType" : "STRING", - "matchValue" : "b" - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "d0", - "outputType" : "LONG" - } ], - "aggregations" : [ { - "type" : "floatMin", - "name" : "a0", - "fieldName" : "m1" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "((\"v0\" == \"j0.d0\") && (\"m1\" == \"j0.a0\"))", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "__time", - "outputName" : "d0", - "outputType" : "LONG" - }, { - "type" : "default", - "dimension" : "m1", - "outputName" : "d1", - "outputType" : "FLOAT" - } ], - "aggregations" : [ { - "type" : "stringAny", - "name" : "a0", - "fieldName" : "dim3", - "maxStringBytes" : 100, - "aggregateMultipleValues" : true - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq deleted file mode 100644 index ee95a76a3c90..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues.iq +++ /dev/null @@ -1,155 +0,0 @@ -# testJoinOnGroupByInsteadOfTimeseriesWithFloorOnTimeWithNoAggregateMultipleValues case-crc:cdb8c84b -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT CAST(__time AS BIGINT), m1, ANY_VALUE(dim3, 100, false) FROM foo WHERE (CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1, m1) IN - ( - SELECT CAST(TIME_FLOOR(__time, 'PT1H') AS BIGINT) + 1 AS t1, MIN(m1) AS t2 FROM foo WHERE dim3 = 'b' - AND __time BETWEEN '1994-04-29 00:00:00' AND '2020-01-11 00:00:00' GROUP BY 1 - ) -GROUP BY 1, 2 -; -+--------------+-----+--------+ -| EXPR$0 | m1 | EXPR$2 | -+--------------+-----+--------+ -| 946684800000 | 1.0 | a | -| 946771200000 | 2.0 | b | -+--------------+-----+--------+ -(2 rows) - -!ok -LogicalAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)]) - LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[false]) - LogicalJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) - LogicalProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{0}], t2=[MIN($1)]) - LogicalProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5]) - LogicalFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)], druid=[logical]) - DruidProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[false], druid=[logical]) - DruidJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) - DruidProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{0}], t2=[MIN($1)], druid=[logical]) - DruidProject(t1=[+(CAST(TIME_FLOOR($0, 'PT1H')):BIGINT NOT NULL, 1)], m1=[$5], druid=[logical]) - DruidFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", - "outputType" : "LONG" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "dim3", "m1", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING", "FLOAT", "LONG" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "1994-04-29T00:00:00.000Z/2020-01-11T00:00:00.001Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "(timestamp_floor(\"__time\",'PT1H',null,'UTC') + 1)", - "outputType" : "LONG" - } ], - "filter" : { - "type" : "equals", - "column" : "dim3", - "matchValueType" : "STRING", - "matchValue" : "b" - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "d0", - "outputType" : "LONG" - } ], - "aggregations" : [ { - "type" : "floatMin", - "name" : "a0", - "fieldName" : "m1" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "((\"v0\" == \"j0.d0\") && (\"m1\" == \"j0.a0\"))", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "__time", - "outputName" : "d0", - "outputType" : "LONG" - }, { - "type" : "default", - "dimension" : "m1", - "outputName" : "d1", - "outputType" : "FLOAT" - } ], - "aggregations" : [ { - "type" : "stringAny", - "name" : "a0", - "fieldName" : "dim3", - "maxStringBytes" : 100, - "aggregateMultipleValues" : false - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq deleted file mode 100644 index 48b2ffd2b841..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinOnTimeseriesWithFloorOnTime.iq +++ /dev/null @@ -1,138 +0,0 @@ -# testJoinOnTimeseriesWithFloorOnTime case-crc:283a6693 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT CAST(__time AS BIGINT), m1, ANY_VALUE(dim3, 100, true) FROM foo WHERE (TIME_FLOOR(__time, 'PT1H'), m1) IN - ( - SELECT TIME_FLOOR(__time, 'PT1H') AS t1, MIN(m1) AS t2 FROM foo WHERE dim3 = 'b' - AND __time BETWEEN '1994-04-29 00:00:00' AND '2020-01-11 00:00:00' GROUP BY 1 - ) -GROUP BY 1, 2 -; -+--------------+-----+--------+ -| EXPR$0 | m1 | EXPR$2 | -+--------------+-----+--------+ -| 946684800000 | 1.0 | [a, b] | -| 946771200000 | 2.0 | [b, c] | -+--------------+-----+--------+ -(2 rows) - -!ok -LogicalAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)]) - LogicalProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[true]) - LogicalJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) - LogicalProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[TIME_FLOOR($0, 'PT1H')]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{0}], t2=[MIN($1)]) - LogicalProject(t1=[TIME_FLOOR($0, 'PT1H')], m1=[$5]) - LogicalFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{0, 1}], EXPR$2=[ANY_VALUE($2, $3, $4)], druid=[logical]) - DruidProject(EXPR$0=[CAST($0):BIGINT NOT NULL], m1=[$2], dim3=[$1], $f3=[100], $f4=[true], druid=[logical]) - DruidJoin(condition=[AND(=($3, $4), =($2, $5))], joinType=[inner]) - DruidProject(__time=[$0], dim3=[$3], m1=[$5], $f3=[TIME_FLOOR($0, 'PT1H')], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{0}], t2=[MIN($1)], druid=[logical]) - DruidProject(t1=[TIME_FLOOR($0, 'PT1H')], m1=[$5], druid=[logical]) - DruidFilter(condition=[AND(=($3, 'b'), SEARCH($0, Sarg[[1994-04-29 00:00:00:TIMESTAMP(3)..2020-01-11 00:00:00:TIMESTAMP(3)]]:TIMESTAMP(3)))]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "timestamp_floor(\"__time\",'PT1H',null,'UTC')", - "outputType" : "LONG" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "dim3", "m1", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING", "FLOAT", "LONG" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "timeseries", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "1994-04-29T00:00:00.000Z/2020-01-11T00:00:00.001Z" ] - }, - "filter" : { - "type" : "equals", - "column" : "dim3", - "matchValueType" : "STRING", - "matchValue" : "b" - }, - "granularity" : "HOUR", - "aggregations" : [ { - "type" : "floatMin", - "name" : "a0", - "fieldName" : "m1" - } ] - } - }, - "rightPrefix" : "j0.", - "condition" : "((\"v0\" == \"j0.d0\") && (\"m1\" == \"j0.a0\"))", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "__time", - "outputName" : "d0", - "outputType" : "LONG" - }, { - "type" : "default", - "dimension" : "m1", - "outputName" : "d1", - "outputType" : "FLOAT" - } ], - "aggregations" : [ { - "type" : "stringAny", - "name" : "a0", - "fieldName" : "dim3", - "maxStringBytes" : 100, - "aggregateMultipleValues" : true - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq deleted file mode 100644 index 0f11e3a6c220..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testJoinWithInputRefCondition.iq +++ /dev/null @@ -1,185 +0,0 @@ -# testJoinWithInputRefCondition case-crc:912f3b33 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set outputformat mysql -!use druidtest:/// -SELECT COUNT(*) FILTER (WHERE FLOOR(100) NOT IN (SELECT m1 FROM foo)) FROM foo; -+--------+ -| EXPR$0 | -+--------+ -| 6 | -+--------+ -(1 row) - -!ok -LogicalAggregate(group=[{}], EXPR$0=[COUNT() FILTER $0]) - LogicalProject($f0=[OR(=($1, 0), AND(IS NULL($4), >=($2, $1)))]) - LogicalJoin(condition=[=(CAST(FLOOR(100)):FLOAT NOT NULL, $3)], joinType=[left]) - LogicalJoin(condition=[true], joinType=[inner]) - LogicalProject(DUMMY=[0]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{}], c=[COUNT()], ck=[COUNT($5)]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{5}], i=[LITERAL_AGG(true)]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{}], EXPR$0=[COUNT() FILTER $0], druid=[logical]) - DruidProject($f0=[OR(=($1, 0), AND(IS NULL($4), >=($2, $1)))], druid=[logical]) - DruidJoin(condition=[=(CAST(FLOOR(100)):FLOAT NOT NULL, $3)], joinType=[left]) - DruidJoin(condition=[true], joinType=[inner]) - DruidProject(DUMMY=[0], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{}], c=[COUNT()], ck=[COUNT($5)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{5}], i=[LITERAL_AGG(true)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "timeseries", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "0", - "outputType" : "LONG" - } ], - "resultFormat" : "compactedList", - "columns" : [ "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "timeseries", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "aggregations" : [ { - "type" : "count", - "name" : "a0" - }, { - "type" : "filtered", - "aggregator" : { - "type" : "count", - "name" : "a1" - }, - "filter" : { - "type" : "not", - "field" : { - "type" : "null", - "column" : "m1" - } - }, - "name" : "a1" - } ] - } - }, - "rightPrefix" : "j0.", - "condition" : "1", - "joinType" : "INNER" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "m1", - "outputName" : "d0", - "outputType" : "FLOAT" - } ], - "postAggregations" : [ { - "type" : "expression", - "name" : "a0", - "expression" : "1", - "outputType" : "LONG" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "_j0.", - "condition" : "(CAST(floor(100), 'DOUBLE') == \"_j0.d0\")", - "joinType" : "LEFT" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "aggregations" : [ { - "type" : "filtered", - "aggregator" : { - "type" : "count", - "name" : "a0" - }, - "filter" : { - "type" : "or", - "fields" : [ { - "type" : "equals", - "column" : "j0.a0", - "matchValueType" : "LONG", - "matchValue" : 0 - }, { - "type" : "and", - "fields" : [ { - "type" : "null", - "column" : "_j0.a0" - }, { - "type" : "expression", - "expression" : "(\"j0.a1\" >= \"j0.a0\")" - } ] - } ] - }, - "name" : "a0" - } ] -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq deleted file mode 100644 index d3b71e0d8f49..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.iq +++ /dev/null @@ -1,134 +0,0 @@ -# testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess case-crc:eb6c3cbe -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set enableJoinLeftTableScanDirect true -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -with abc as -( - SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' -) -SELECT t1.dim1, t1."__time" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1' -; -+------+---------------------+ -| dim1 | __time | -+------+---------------------+ -| 10.1 | 2000-01-02 00:00:00 | -+------+---------------------+ -(1 row) - -!ok -LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) - LogicalJoin(condition=[=($0, $2)], joinType=[left]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(dim1=[$1]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) - DruidJoin(condition=[=($0, $2)], joinType=[left]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(dim1=[$1], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "__time", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "dim1" ], - "legacy" : false, - "columnTypes" : [ "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.dim1\")", - "joinType" : "LEFT" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "_v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "_v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq deleted file mode 100644 index 0391d00a2a42..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.iq +++ /dev/null @@ -1,140 +0,0 @@ -# testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess case-crc:1833b879 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set enableJoinLeftTableScanDirect true -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -with abc as -( - SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' AND "__time" >= '1999' -) -SELECT t1.dim1, t1."__time" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1' -; -+------+---------------------+ -| dim1 | __time | -+------+---------------------+ -| 10.1 | 2000-01-02 00:00:00 | -+------+---------------------+ -(1 row) - -!ok -LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) - LogicalJoin(condition=[=($0, $2)], joinType=[left]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) - LogicalFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR]) - LogicalFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) - DruidJoin(condition=[=($0, $2)], joinType=[left]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) - DruidFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], druid=[logical]) - DruidFilter(condition=[AND(=($1, '10.1'), >=($0, 1999-01-01 00:00:00))]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "1999-01-01T00:00:00.000Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "__time", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "1999-01-01T00:00:00.000Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.v0\")", - "joinType" : "LEFT" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "_v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "_v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq deleted file mode 100644 index fea4326b5fe1..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess.iq +++ /dev/null @@ -1,134 +0,0 @@ -# testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess case-crc:35bb78bb -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set enableJoinLeftTableScanDirect true -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -with abc as -( - SELECT dim1, "__time", m1 from foo WHERE "dim1" = '10.1' -) -SELECT t1.dim1, t1."__time" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 -; -+------+---------------------+ -| dim1 | __time | -+------+---------------------+ -| 10.1 | 2000-01-02 00:00:00 | -+------+---------------------+ -(1 row) - -!ok -LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1]) - LogicalJoin(condition=[=($0, $2)], joinType=[left]) - LogicalProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - LogicalProject(dim1=[$1]) - LogicalFilter(condition=[=($1, '10.1')]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$1], druid=[logical]) - DruidJoin(condition=[=($0, $2)], joinType=[left]) - DruidProject(dim1=[CAST('10.1':VARCHAR):VARCHAR], __time=[$0], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidProject(dim1=[$1], druid=[logical]) - DruidFilter(condition=[=($1, '10.1')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "__time", "v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "filter" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "10.1" - }, - "columns" : [ "dim1" ], - "legacy" : false, - "columnTypes" : [ "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.dim1\")", - "joinType" : "LEFT" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "_v0", - "expression" : "'10.1'", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "__time", "_v0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq deleted file mode 100644 index 7e94bb3c8bf4..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testLeftJoinSubqueryWithSelectorFilter.iq +++ /dev/null @@ -1,99 +0,0 @@ -# testLeftJoinSubqueryWithSelectorFilter case-crc:503594a7 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set computeInnerJoinCostAsFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT dim1, l1.k -FROM foo -LEFT JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 ON foo.dim1 = l1.k -WHERE l1.k = 'abc' -; -+------+-----+ -| dim1 | k | -+------+-----+ -| abc | abc | -+------+-----+ -(1 row) - -!ok -LogicalJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) - LogicalProject(dim1=[$1]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{0}]) - LogicalProject(k=[||($0, '')]) - LogicalTableScan(table=[[lookup, lookyloo]]) - -!logicalPlan -DruidJoin(condition=[AND(=($0, $1), =($1, 'abc'))], joinType=[inner]) - DruidProject(dim1=[$1], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{0}], druid=[logical]) - DruidProject(k=[||($0, '')], druid=[logical]) - DruidTableScan(table=[[lookup, lookyloo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "foo" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "lookup", - "lookup" : "lookyloo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "concat(\"k\",'')", - "outputType" : "STRING" - } ], - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "((\"dim1\" == \"j0.d0\") && (\"j0.d0\" == 'abc'))", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "dim1", "j0.d0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq deleted file mode 100644 index 9d9259eab10c..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.iq +++ /dev/null @@ -1,139 +0,0 @@ -# testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins case-crc:692fc7cc -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set enableTimeBoundaryPlanning true -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT dim1, COUNT(*) FROM -foo -INNER JOIN (SELECT MAX(__time) t FROM foo) t0 on t0.t = foo.__time -LEFT JOIN (SELECT MIN(__time) t FROM foo) t1 on t1.t = foo.__time -WHERE dim1 IN ('abc', 'def') AND t1.t is null -GROUP BY 1; -+------+--------+ -| dim1 | EXPR$1 | -+------+--------+ -| abc | 1 | -+------+--------+ -(1 row) - -!ok -LogicalAggregate(group=[{1}], EXPR$1=[COUNT()]) - LogicalFilter(condition=[AND(SEARCH($1, Sarg['abc', 'def']:CHAR(3)), IS NULL($3))]) - LogicalJoin(condition=[=($3, $0)], joinType=[left]) - LogicalJoin(condition=[=($2, $0)], joinType=[inner]) - LogicalProject(__time=[$0], dim1=[$1]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{}], t=[MAX($0)]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{}], t=[MIN($0)]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{1}], EXPR$1=[COUNT()], druid=[logical]) - DruidFilter(condition=[AND(SEARCH($1, Sarg['abc', 'def']:CHAR(3)), IS NULL($3))]) - DruidJoin(condition=[=($3, $0)], joinType=[left]) - DruidJoin(condition=[=($2, $0)], joinType=[inner]) - DruidProject(__time=[$0], dim1=[$1], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{}], t=[MAX($0)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{}], t=[MIN($0)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "foo" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "timeBoundary", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "bound" : "maxTime", - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"j0.a0\" == \"__time\")", - "joinType" : "INNER" - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "timeBoundary", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "bound" : "minTime", - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "_j0.", - "condition" : "(\"_j0.a0\" == \"__time\")", - "joinType" : "LEFT" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "filter" : { - "type" : "and", - "fields" : [ { - "type" : "inType", - "column" : "dim1", - "matchValueType" : "STRING", - "sortedValues" : [ "abc", "def" ] - }, { - "type" : "null", - "column" : "_j0.a0" - } ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim1", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "count", - "name" : "a0" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq deleted file mode 100644 index 8174204174d3..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionary.iq +++ /dev/null @@ -1,86 +0,0 @@ -# testTopNOnStringWithNonSortedOrUniqueDictionary case-crc:7aa7e615 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT druid.broadcast.dim4, COUNT(*) -FROM druid.numfoo -INNER JOIN druid.broadcast ON numfoo.dim4 = broadcast.dim4 -GROUP BY 1 ORDER BY 2 LIMIT 4; -+------+--------+ -| dim4 | EXPR$1 | -+------+--------+ -| a | 9 | -| b | 9 | -+------+--------+ -(2 rows) - -!ok -LogicalSort(sort0=[$1], dir0=[ASC], fetch=[4]) - LogicalAggregate(group=[{1}], EXPR$1=[COUNT()]) - LogicalJoin(condition=[=($0, $1)], joinType=[inner]) - LogicalProject(dim4=[$4]) - LogicalTableScan(table=[[druid, numfoo]]) - LogicalProject(dim4=[$4]) - LogicalTableScan(table=[[druid, broadcast]]) - -!logicalPlan -DruidSort(sort0=[$1], dir0=[ASC], fetch=[4], druid=[logical]) - DruidAggregate(group=[{1}], EXPR$1=[COUNT()], druid=[logical]) - DruidJoin(condition=[=($0, $1)], joinType=[inner]) - DruidProject(dim4=[$4], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - DruidProject(dim4=[$4], druid=[logical]) - DruidTableScan(table=[[druid, broadcast]], druid=[logical]) - -!druidPlan -{ - "queryType" : "topN", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "numfoo" - }, - "right" : { - "type" : "globalTable", - "name" : "broadcast" - }, - "rightPrefix" : "j0.", - "condition" : "(\"dim4\" == \"j0.dim4\")", - "joinType" : "INNER" - }, - "dimension" : { - "type" : "default", - "dimension" : "j0.dim4", - "outputName" : "d0", - "outputType" : "STRING" - }, - "metric" : { - "type" : "inverted", - "metric" : { - "type" : "numeric", - "metric" : "a0" - } - }, - "threshold" : 4, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "aggregations" : [ { - "type" : "count", - "name" : "a0" - } ] -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq deleted file mode 100644 index eabe251fc356..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim.iq +++ /dev/null @@ -1,88 +0,0 @@ -# testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim case-crc:0d2340d3 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT druid.broadcast.dim4, COUNT(*) -FROM druid.numfoo -INNER JOIN druid.broadcast ON numfoo.dim4 = broadcast.dim4 -GROUP BY 1 ORDER BY 1 DESC LIMIT 4; -+------+--------+ -| dim4 | EXPR$1 | -+------+--------+ -| b | 9 | -| a | 9 | -+------+--------+ -(2 rows) - -!ok -LogicalSort(sort0=[$0], dir0=[DESC], fetch=[4]) - LogicalAggregate(group=[{1}], EXPR$1=[COUNT()]) - LogicalJoin(condition=[=($0, $1)], joinType=[inner]) - LogicalProject(dim4=[$4]) - LogicalTableScan(table=[[druid, numfoo]]) - LogicalProject(dim4=[$4]) - LogicalTableScan(table=[[druid, broadcast]]) - -!logicalPlan -DruidSort(sort0=[$0], dir0=[DESC], fetch=[4], druid=[logical]) - DruidAggregate(group=[{1}], EXPR$1=[COUNT()], druid=[logical]) - DruidJoin(condition=[=($0, $1)], joinType=[inner]) - DruidProject(dim4=[$4], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - DruidProject(dim4=[$4], druid=[logical]) - DruidTableScan(table=[[druid, broadcast]], druid=[logical]) - -!druidPlan -{ - "queryType" : "topN", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "table", - "name" : "numfoo" - }, - "right" : { - "type" : "globalTable", - "name" : "broadcast" - }, - "rightPrefix" : "j0.", - "condition" : "(\"dim4\" == \"j0.dim4\")", - "joinType" : "INNER" - }, - "dimension" : { - "type" : "default", - "dimension" : "j0.dim4", - "outputName" : "d0", - "outputType" : "STRING" - }, - "metric" : { - "type" : "inverted", - "metric" : { - "type" : "dimension", - "ordering" : { - "type" : "lexicographic" - } - } - }, - "threshold" : 4, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "aggregations" : [ { - "type" : "count", - "name" : "a0" - } ] -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq deleted file mode 100644 index fc0d44bb2f56..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testUsingSubqueryWithExtractionFns.iq +++ /dev/null @@ -1,139 +0,0 @@ -# testUsingSubqueryWithExtractionFns case-crc:f4decaef -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT dim2, COUNT(*) FROM druid.foo WHERE substring(dim2, 1, 1) IN (SELECT substring(dim1, 1, 1) FROM druid.foo WHERE dim1 <> '')group by dim2; -+------+--------+ -| dim2 | EXPR$1 | -+------+--------+ -| a | 2 | -| abc | 1 | -+------+--------+ -(2 rows) - -!ok -LogicalAggregate(group=[{0}], EXPR$1=[COUNT()]) - LogicalJoin(condition=[=($1, $2)], joinType=[inner]) - LogicalProject(dim2=[$2], $f1=[SUBSTRING($2, 1, 1)]) - LogicalTableScan(table=[[druid, foo]]) - LogicalAggregate(group=[{0}]) - LogicalProject(EXPR$0=[SUBSTRING($1, 1, 1)]) - LogicalFilter(condition=[<>($1, '')]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{0}], EXPR$1=[COUNT()], druid=[logical]) - DruidJoin(condition=[=($1, $2)], joinType=[inner]) - DruidProject(dim2=[$2], $f1=[SUBSTRING($2, 1, 1)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - DruidAggregate(group=[{0}], druid=[logical]) - DruidProject(EXPR$0=[SUBSTRING($1, 1, 1)], druid=[logical]) - DruidFilter(condition=[<>($1, '')]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "substring(\"dim2\", 0, 1)", - "outputType" : "STRING" - } ], - "resultFormat" : "compactedList", - "columns" : [ "dim2", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "filter" : { - "type" : "not", - "field" : { - "type" : "equals", - "column" : "dim1", - "matchValueType" : "STRING", - "matchValue" : "" - } - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "extraction", - "dimension" : "dim1", - "outputName" : "d0", - "outputType" : "STRING", - "extractionFn" : { - "type" : "substring", - "index" : 0, - "length" : 1 - } - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.d0\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim2", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "count", - "name" : "a0" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq deleted file mode 100644 index c9758e24448b..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterJoinExpression.iq +++ /dev/null @@ -1,125 +0,0 @@ -# testVirtualColumnOnMVFilterJoinExpression case-crc:3277a762 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT foo1.dim3, foo2.dim3 FROM druid.numfoo as foo1 INNER JOIN druid.numfoo as foo2 ON MV_FILTER_ONLY(foo1.dim3, ARRAY['a']) = MV_FILTER_ONLY(foo2.dim3, ARRAY['a']) -; -+-----------+-----------+ -| dim3 | dim3 | -+-----------+-----------+ -| ["a","b"] | ["a","b"] | -+-----------+-----------+ -(1 row) - -!ok -LogicalProject(dim3=[$0], dim30=[$2]) - LogicalJoin(condition=[=($1, $3)], joinType=[inner]) - LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) - LogicalTableScan(table=[[druid, numfoo]]) - LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) - LogicalTableScan(table=[[druid, numfoo]]) - -!logicalPlan -DruidProject(dim3=[$0], dim30=[$2], druid=[logical]) - DruidJoin(condition=[=($1, $3)], joinType=[inner]) - DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "mv-filtered", - "name" : "v0", - "delegate" : { - "type" : "default", - "dimension" : "dim3", - "outputName" : "dim3", - "outputType" : "STRING" - }, - "values" : [ "a" ], - "isAllowList" : true - } ], - "resultFormat" : "compactedList", - "columns" : [ "dim3", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "mv-filtered", - "name" : "v0", - "delegate" : { - "type" : "default", - "dimension" : "dim3", - "outputName" : "dim3", - "outputType" : "STRING" - }, - "values" : [ "a" ], - "isAllowList" : true - } ], - "resultFormat" : "compactedList", - "columns" : [ "dim3", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.v0\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "dim3", "j0.dim3" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq deleted file mode 100644 index e5733597521a..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteJoinQueryTest/testVirtualColumnOnMVFilterMultiJoinExpression.iq +++ /dev/null @@ -1,201 +0,0 @@ -# testVirtualColumnOnMVFilterMultiJoinExpression case-crc:177cadd2 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set maxScatterGatherBytes 9223372036854775807 -!set enableJoinFilterRewriteValueColumnFilters false -!set enableRewriteJoinToFilter false -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set enableJoinFilterRewrite false -!set outputformat mysql -!use druidtest:/// -SELECT foo1.dim3, foo2.dim3 FROM druid.numfoo as foo1 INNER JOIN (SELECT foo3.dim3 FROM druid.numfoo as foo3 INNER JOIN druid.numfoo as foo4 ON MV_FILTER_ONLY(foo3.dim3, ARRAY['a']) = MV_FILTER_ONLY(foo4.dim3, ARRAY['a'])) as foo2 ON MV_FILTER_ONLY(foo1.dim3, ARRAY['a']) = MV_FILTER_ONLY(foo2.dim3, ARRAY['a']) -; -+-----------+-----------+ -| dim3 | dim3 | -+-----------+-----------+ -| ["a","b"] | ["a","b"] | -+-----------+-----------+ -(1 row) - -!ok -LogicalProject(dim3=[$0], dim30=[$2]) - LogicalJoin(condition=[=($1, $3)], joinType=[inner]) - LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) - LogicalTableScan(table=[[druid, numfoo]]) - LogicalProject(dim3=[$0], $f1=[MV_FILTER_ONLY($0, ARRAY('a'))]) - LogicalJoin(condition=[=($1, $2)], joinType=[inner]) - LogicalProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) - LogicalTableScan(table=[[druid, numfoo]]) - LogicalProject($f17=[MV_FILTER_ONLY($3, ARRAY('a'))]) - LogicalTableScan(table=[[druid, numfoo]]) - -!logicalPlan -DruidProject(dim3=[$0], dim30=[$2], druid=[logical]) - DruidJoin(condition=[=($1, $3)], joinType=[inner]) - DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - DruidProject(dim3=[$0], $f1=[MV_FILTER_ONLY($0, ARRAY('a'))], druid=[logical]) - DruidJoin(condition=[=($1, $2)], joinType=[inner]) - DruidProject(dim3=[$3], $f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - DruidProject($f17=[MV_FILTER_ONLY($3, ARRAY('a'))], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "mv-filtered", - "name" : "v0", - "delegate" : { - "type" : "default", - "dimension" : "dim3", - "outputName" : "dim3", - "outputType" : "STRING" - }, - "values" : [ "a" ], - "isAllowList" : true - } ], - "resultFormat" : "compactedList", - "columns" : [ "dim3", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "join", - "left" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "mv-filtered", - "name" : "v0", - "delegate" : { - "type" : "default", - "dimension" : "dim3", - "outputName" : "dim3", - "outputType" : "STRING" - }, - "values" : [ "a" ], - "isAllowList" : true - } ], - "resultFormat" : "compactedList", - "columns" : [ "dim3", "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "right" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "mv-filtered", - "name" : "v0", - "delegate" : { - "type" : "default", - "dimension" : "dim3", - "outputName" : "dim3", - "outputType" : "STRING" - }, - "values" : [ "a" ], - "isAllowList" : true - } ], - "resultFormat" : "compactedList", - "columns" : [ "v0" ], - "legacy" : false, - "columnTypes" : [ "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "j0.", - "condition" : "(\"v0\" == \"j0.v0\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "mv-filtered", - "name" : "_v0", - "delegate" : { - "type" : "default", - "dimension" : "dim3", - "outputName" : "dim3", - "outputType" : "STRING" - }, - "values" : [ "a" ], - "isAllowList" : true - } ], - "resultFormat" : "compactedList", - "columns" : [ "_v0", "dim3" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } - } - }, - "rightPrefix" : "_j0.", - "condition" : "(\"v0\" == \"_j0._v0\")", - "joinType" : "INNER" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "columns" : [ "_j0.dim3", "dim3" ], - "legacy" : false, - "columnTypes" : [ "STRING", "STRING" ], - "granularity" : { - "type" : "all" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq deleted file mode 100644 index c6fc5658ddbb..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testExactCountDistinctWithGroupingAndOtherAggregators.iq +++ /dev/null @@ -1,69 +0,0 @@ -# testExactCountDistinctWithGroupingAndOtherAggregators case-crc:046d1e3e -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT dim2, SUM(cnt), COUNT(distinct dim1) FROM druid.foo GROUP BY dim2; -+------+--------+--------+ -| dim2 | EXPR$1 | EXPR$2 | -+------+--------+--------+ -| | 1 | 1 | -| a | 2 | 2 | -| abc | 1 | 1 | -| | 2 | 2 | -+------+--------+--------+ -(4 rows) - -!ok -LogicalAggregate(group=[{2}], EXPR$1=[SUM($4)], EXPR$2=[COUNT(DISTINCT $1)]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{2}], EXPR$1=[SUM($4)], EXPR$2=[COUNT(DISTINCT $1)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim2", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "longSum", - "name" : "a0", - "fieldName" : "cnt" - }, { - "type" : "cardinality", - "name" : "a1", - "fields" : [ { - "type" : "default", - "dimension" : "dim1", - "outputName" : "dim1", - "outputType" : "STRING" - } ], - "byRow" : false, - "round" : true - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq deleted file mode 100644 index 8562edf7fc28..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByLimitPushdownExtraction.iq +++ /dev/null @@ -1,84 +0,0 @@ -# testGroupByLimitPushdownExtraction case-crc:da2618b7 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT dim4, substring(dim5, 1, 1), count(*) FROM druid.numfoo WHERE dim4 = 'a' GROUP BY 1,2 LIMIT 2; -+------+--------+--------+ -| dim4 | EXPR$1 | EXPR$2 | -+------+--------+--------+ -| a | a | 2 | -| a | b | 1 | -+------+--------+--------+ -(2 rows) - -!ok -LogicalProject(dim4=[CAST('a':VARCHAR):VARCHAR], EXPR$1=[$0], EXPR$2=[$1]) - LogicalSort(fetch=[2]) - LogicalAggregate(group=[{0}], EXPR$2=[COUNT()]) - LogicalProject(EXPR$1=[SUBSTRING($5, 1, 1)]) - LogicalFilter(condition=[=($4, 'a')]) - LogicalTableScan(table=[[druid, numfoo]]) - -!logicalPlan -DruidProject(dim4=[CAST('a':VARCHAR):VARCHAR], EXPR$1=[$0], EXPR$2=[$1], druid=[logical]) - DruidSort(fetch=[2], druid=[logical]) - DruidAggregate(group=[{0}], EXPR$2=[COUNT()], druid=[logical]) - DruidProject(EXPR$1=[SUBSTRING($5, 1, 1)], druid=[logical]) - DruidFilter(condition=[=($4, 'a')]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "topN", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "dimension" : { - "type" : "extraction", - "dimension" : "dim5", - "outputName" : "_d0", - "outputType" : "STRING", - "extractionFn" : { - "type" : "substring", - "index" : 0, - "length" : 1 - } - }, - "metric" : { - "type" : "dimension", - "ordering" : { - "type" : "lexicographic" - } - }, - "threshold" : 2, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "filter" : { - "type" : "equals", - "column" : "dim4", - "matchValueType" : "STRING", - "matchValue" : "a" - }, - "granularity" : { - "type" : "all" - }, - "aggregations" : [ { - "type" : "count", - "name" : "a0" - } ], - "postAggregations" : [ { - "type" : "expression", - "name" : "s0", - "expression" : "'a'", - "outputType" : "STRING" - } ] -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq deleted file mode 100644 index 6ec000ab2d8d..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupBySortPushDown.iq +++ /dev/null @@ -1,75 +0,0 @@ -# testGroupBySortPushDown case-crc:54515e94 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT dim2, dim1, SUM(cnt) FROM druid.foo GROUP BY dim2, dim1 ORDER BY dim1 LIMIT 4; -+------+------+--------+ -| dim2 | dim1 | EXPR$2 | -+------+------+--------+ -| a | | 1 | -| a | 1 | 1 | -| | 10.1 | 1 | -| | 2 | 1 | -+------+------+--------+ -(4 rows) - -!ok -LogicalProject(dim2=[$1], dim1=[$0], EXPR$2=[$2]) - LogicalSort(sort0=[$0], dir0=[ASC], fetch=[4]) - LogicalAggregate(group=[{1, 2}], EXPR$2=[SUM($4)]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(dim2=[$1], dim1=[$0], EXPR$2=[$2], druid=[logical]) - DruidSort(sort0=[$0], dir0=[ASC], fetch=[4], druid=[logical]) - DruidAggregate(group=[{1, 2}], EXPR$2=[SUM($4)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim1", - "outputName" : "d0", - "outputType" : "STRING" - }, { - "type" : "default", - "dimension" : "dim2", - "outputName" : "d1", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "longSum", - "name" : "a0", - "fieldName" : "cnt" - } ], - "limitSpec" : { - "type" : "default", - "columns" : [ { - "dimension" : "d0", - "direction" : "ascending", - "dimensionOrder" : { - "type" : "lexicographic" - } - } ], - "limit" : 4 - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq deleted file mode 100644 index 10c05b8b5d8c..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim.iq +++ /dev/null @@ -1,145 +0,0 @@ -# testGroupByTimeFloorAndDimOnGroupByTimeFloorAndDim case-crc:f87d60a4 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT dim2, time_floor(gran, 'P1M') gran, sum(s) -FROM (SELECT time_floor(__time, 'P1D') AS gran, dim2, sum(m1) as s FROM druid.foo GROUP BY 1, 2 HAVING sum(m1) > 1) AS x -GROUP BY 1, 2 -ORDER BY dim2, gran desc; -+------+---------------------+--------+ -| dim2 | gran | EXPR$2 | -+------+---------------------+--------+ -| | 2001-01-01 00:00:00 | 6.0 | -| | 2000-01-01 00:00:00 | 2.0 | -| | 2000-01-01 00:00:00 | 3.0 | -| a | 2001-01-01 00:00:00 | 4.0 | -| abc | 2001-01-01 00:00:00 | 5.0 | -+------+---------------------+--------+ -(5 rows) - -!ok -LogicalSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[DESC]) - LogicalAggregate(group=[{0, 1}], EXPR$2=[SUM($2)]) - LogicalProject(dim2=[$1], gran=[TIME_FLOOR($0, 'P1M')], s=[$2]) - LogicalFilter(condition=[>($2, 1)]) - LogicalAggregate(group=[{0, 1}], s=[SUM($2)]) - LogicalProject(gran=[TIME_FLOOR($0, 'P1D')], dim2=[$2], m1=[$5]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[DESC], druid=[logical]) - DruidAggregate(group=[{0, 1}], EXPR$2=[SUM($2)], druid=[logical]) - DruidProject(dim2=[$1], gran=[TIME_FLOOR($0, 'P1M')], s=[$2], druid=[logical]) - DruidFilter(condition=[>($2, 1)]) - DruidAggregate(group=[{0, 1}], s=[SUM($2)], druid=[logical]) - DruidProject(gran=[TIME_FLOOR($0, 'P1D')], dim2=[$2], m1=[$5], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "timestamp_floor(\"__time\",'P1D',null,'UTC')", - "outputType" : "LONG" - } ], - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "d0", - "outputType" : "LONG" - }, { - "type" : "default", - "dimension" : "dim2", - "outputName" : "d1", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "doubleSum", - "name" : "a0", - "fieldName" : "m1" - } ], - "having" : { - "type" : "filter", - "filter" : { - "type" : "range", - "column" : "a0", - "matchValueType" : "LONG", - "lower" : 1, - "lowerOpen" : true - }, - "finalize" : true - }, - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "timestamp_floor(\"d0\",'P1M',null,'UTC')", - "outputType" : "LONG" - } ], - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "d1", - "outputName" : "_d0", - "outputType" : "STRING" - }, { - "type" : "default", - "dimension" : "v0", - "outputName" : "_d1", - "outputType" : "LONG" - } ], - "aggregations" : [ { - "type" : "doubleSum", - "name" : "_a0", - "fieldName" : "a0" - } ], - "limitSpec" : { - "type" : "default", - "columns" : [ { - "dimension" : "_d0", - "direction" : "ascending", - "dimensionOrder" : { - "type" : "lexicographic" - } - }, { - "dimension" : "_d1", - "direction" : "descending", - "dimensionOrder" : { - "type" : "numeric" - } - } ] - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq deleted file mode 100644 index cc80c384e2cd..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testGroupByWithLiteralInSubqueryGrouping.iq +++ /dev/null @@ -1,109 +0,0 @@ -# testGroupByWithLiteralInSubqueryGrouping case-crc:933d8c09 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT - t1, t2 - FROM - ( SELECT - 'dummy' as t1, - CASE - WHEN - dim4 = 'b' - THEN dim4 - ELSE NULL - END AS t2 - FROM - numfoo - GROUP BY - dim4 - ) - GROUP BY - t1,t2 -; -+-------+----+ -| t1 | t2 | -+-------+----+ -| dummy | b | -| dummy | | -+-------+----+ -(2 rows) - -!ok -LogicalProject(t1=['dummy'], t2=[$0]) - LogicalAggregate(group=[{0}]) - LogicalProject(t2=[CASE(=($0, 'b'), $0, null:VARCHAR)]) - LogicalAggregate(group=[{4}]) - LogicalTableScan(table=[[druid, numfoo]]) - -!logicalPlan -DruidProject(t1=['dummy'], t2=[$0], druid=[logical]) - DruidAggregate(group=[{0}], druid=[logical]) - DruidProject(t2=[CASE(=($0, 'b'), $0, null:VARCHAR)], druid=[logical]) - DruidAggregate(group=[{4}], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim4", - "outputName" : "_d0", - "outputType" : "STRING" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "case_searched((\"_d0\" == 'b'),\"_d0\",null)", - "outputType" : "STRING" - } ], - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "postAggregations" : [ { - "type" : "expression", - "name" : "p0", - "expression" : "'dummy'", - "outputType" : "STRING" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq deleted file mode 100644 index d3446d3ddc51..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin.iq +++ /dev/null @@ -1,79 +0,0 @@ -# testMultipleExactCountDistinctWithGroupingAndOtherAggregatorsUsingJoin case-crc:a794c731 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT dim2, COUNT(*), COUNT(distinct dim1), COUNT(distinct cnt) FROM druid.foo GROUP BY dim2; -+------+--------+--------+--------+ -| dim2 | EXPR$1 | EXPR$2 | EXPR$3 | -+------+--------+--------+--------+ -| | 1 | 1 | 1 | -| a | 2 | 2 | 1 | -| abc | 1 | 1 | 1 | -| | 2 | 2 | 1 | -+------+--------+--------+--------+ -(4 rows) - -!ok -LogicalAggregate(group=[{2}], EXPR$1=[COUNT()], EXPR$2=[COUNT(DISTINCT $1)], EXPR$3=[COUNT(DISTINCT $4)]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidAggregate(group=[{2}], EXPR$1=[COUNT()], EXPR$2=[COUNT(DISTINCT $1)], EXPR$3=[COUNT(DISTINCT $4)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim2", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "count", - "name" : "a0" - }, { - "type" : "cardinality", - "name" : "a1", - "fields" : [ { - "type" : "default", - "dimension" : "dim1", - "outputName" : "dim1", - "outputType" : "STRING" - } ], - "byRow" : false, - "round" : true - }, { - "type" : "cardinality", - "name" : "a2", - "fields" : [ { - "type" : "default", - "dimension" : "cnt", - "outputName" : "cnt", - "outputType" : "LONG" - } ], - "byRow" : false, - "round" : true - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq deleted file mode 100644 index 9727a7427c37..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testRepeatedIdenticalVirtualExpressionGrouping.iq +++ /dev/null @@ -1,70 +0,0 @@ -# testRepeatedIdenticalVirtualExpressionGrouping case-crc:e79279c4 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT - CASE dim1 WHEN NULL THEN FALSE ELSE TRUE END AS col_a, - CASE dim2 WHEN NULL THEN FALSE ELSE TRUE END AS col_b -FROM foo -GROUP BY 1, 2; -+-------+-------+ -| col_a | col_b | -+-------+-------+ -| true | true | -+-------+-------+ -(1 row) - -!ok -LogicalProject(col_a=[$0], col_b=[true]) - LogicalAggregate(group=[{0}]) - LogicalProject(col_a=[true]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(col_a=[$0], col_b=[true], druid=[logical]) - DruidAggregate(group=[{0}], druid=[logical]) - DruidProject(col_a=[true], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "virtualColumns" : [ { - "type" : "expression", - "name" : "v0", - "expression" : "1", - "outputType" : "LONG" - } ], - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "v0", - "outputName" : "d0", - "outputType" : "LONG" - } ], - "postAggregations" : [ { - "type" : "expression", - "name" : "p0", - "expression" : "1", - "outputType" : "LONG" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq deleted file mode 100644 index d8fc18f942c1..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testSubqueryTypeMismatchWithLiterals.iq +++ /dev/null @@ -1,110 +0,0 @@ -# testSubqueryTypeMismatchWithLiterals case-crc:ff3645c9 -!set sqlQueryId dummy -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set defaultTimeout 300000 -!set maxScatterGatherBytes 9223372036854775807 -!set plannerStrategy DECOUPLED -!set debug true -!set outputformat mysql -!use druidtest:/// -SELECT - dim1, - SUM(CASE WHEN sum_l1 = 0 THEN 1 ELSE 0 END) AS outer_l1 -from ( - select - dim1, - SUM(l1) as sum_l1 - from numfoo - group by dim1 -) -group by 1; -+------+----------+ -| dim1 | outer_l1 | -+------+----------+ -| | 0 | -| 1 | 0 | -| 10.1 | 0 | -| 2 | 1 | -| abc | 0 | -| def | 0 | -+------+----------+ -(6 rows) - -!ok -LogicalAggregate(group=[{0}], outer_l1=[COUNT() FILTER $1]) - LogicalProject(dim1=[$0], $f2=[IS TRUE(=($1, 0))]) - LogicalAggregate(group=[{1}], sum_l1=[SUM($11)]) - LogicalTableScan(table=[[druid, numfoo]]) - -!logicalPlan -DruidAggregate(group=[{0}], outer_l1=[COUNT() FILTER $1], druid=[logical]) - DruidProject(dim1=[$0], $f2=[IS TRUE(=($1, 0))], druid=[logical]) - DruidAggregate(group=[{1}], sum_l1=[SUM($11)], druid=[logical]) - DruidTableScan(table=[[druid, numfoo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "groupBy", - "dataSource" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "numfoo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "dim1", - "outputName" : "_d0", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "longSum", - "name" : "a0", - "fieldName" : "l1" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "_d0", - "outputName" : "d0", - "outputType" : "STRING" - } ], - "aggregations" : [ { - "type" : "filtered", - "aggregator" : { - "type" : "count", - "name" : "_a0" - }, - "filter" : { - "type" : "equals", - "column" : "a0", - "matchValueType" : "LONG", - "matchValue" : 0 - }, - "name" : "_a0" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } -} -!nativePlan diff --git a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq b/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq deleted file mode 100644 index 34efc5ba2f0c..000000000000 --- a/sql/src/test/quidem/org.apache.druid.sql.calcite.DecoupledPlanningCalciteQueryTest/testWindowingWithScanAndSort.iq +++ /dev/null @@ -1,201 +0,0 @@ -# testWindowingWithScanAndSort case-crc:1d06dc93 -!set sqlQueryId dummy -!set defaultTimeout 300000 -!set debug true -!set enableWindowing true -!set maxScatterGatherBytes 9223372036854775807 -!set sqlCurrentTimestamp 2000-01-01T00:00:00Z -!set plannerStrategy DECOUPLED -!set outputformat mysql -!use druidtest:/// -with t AS ( -SELECT - RANK() OVER (PARTITION BY m2 ORDER BY m2 ASC) - AS ranking, - COUNT(m1) as trend_score -FROM foo -GROUP BY m2,m1 LIMIT 10 -) -select ranking, trend_score from t ORDER BY trend_score; -+---------+-------------+ -| ranking | trend_score | -+---------+-------------+ -| 1 | 1 | -| 1 | 1 | -| 1 | 1 | -| 1 | 1 | -| 1 | 1 | -| 1 | 1 | -+---------+-------------+ -(6 rows) - -!ok -LogicalProject(ranking=[$2], trend_score=[$1]) - LogicalSort(sort0=[$1], dir0=[ASC]) - LogicalSort(fetch=[10]) - LogicalWindow(window#0=[window(partition {0} order by [0] aggs [RANK()])]) - LogicalProject(m2=[$1], trend_score=[$2]) - LogicalAggregate(group=[{5, 6}], trend_score=[COUNT($5)]) - LogicalTableScan(table=[[druid, foo]]) - -!logicalPlan -DruidProject(ranking=[$2], trend_score=[$1], druid=[logical]) - DruidSort(sort0=[$1], dir0=[ASC], druid=[logical]) - DruidSort(fetch=[10], druid=[logical]) - DruidWindow(window#0=[window(partition {0} order by [0] aggs [RANK()])]) - DruidProject(m2=[$1], trend_score=[$2], druid=[logical]) - DruidAggregate(group=[{5, 6}], trend_score=[COUNT($5)], druid=[logical]) - DruidTableScan(table=[[druid, foo]], druid=[logical]) - -!druidPlan -{ - "queryType" : "windowOperator", - "dataSource" : { - "type" : "query", - "query" : { - "queryType" : "scan", - "dataSource" : { - "type" : "query", - "query" : { - "queryType" : "windowOperator", - "dataSource" : { - "type" : "query", - "query" : { - "queryType" : "groupBy", - "dataSource" : { - "type" : "table", - "name" : "foo" - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "granularity" : { - "type" : "all" - }, - "dimensions" : [ { - "type" : "default", - "dimension" : "m1", - "outputName" : "d0", - "outputType" : "FLOAT" - }, { - "type" : "default", - "dimension" : "m2", - "outputName" : "d1", - "outputType" : "DOUBLE" - } ], - "aggregations" : [ { - "type" : "filtered", - "aggregator" : { - "type" : "count", - "name" : "a0" - }, - "filter" : { - "type" : "not", - "field" : { - "type" : "null", - "column" : "m1" - } - }, - "name" : "a0" - } ], - "limitSpec" : { - "type" : "NoopLimitSpec" - } - } - }, - "intervals" : { - "type" : "LegacySegmentSpec", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "outputSignature" : [ { - "name" : "d1", - "type" : "DOUBLE" - }, { - "name" : "a0", - "type" : "LONG" - }, { - "name" : "w0", - "type" : "LONG" - } ], - "operatorDefinition" : [ { - "type" : "naiveSort", - "columns" : [ { - "column" : "d1", - "direction" : "ASC" - } ] - }, { - "type" : "naivePartition", - "partitionColumns" : [ "d1" ] - }, { - "type" : "window", - "processor" : { - "type" : "rank", - "group" : [ "d1" ], - "outputColumn" : "w0", - "asPercent" : false - } - } ], - "leafOperators" : [ ], - "granularity" : { - "type" : "all" - } - } - }, - "intervals" : { - "type" : "intervals", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "resultFormat" : "compactedList", - "limit" : 10, - "columns" : [ "a0", "d1", "w0" ], - "legacy" : false, - "columnTypes" : [ "LONG", "DOUBLE", "LONG" ], - "granularity" : { - "type" : "all" - } - } - }, - "intervals" : { - "type" : "LegacySegmentSpec", - "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] - }, - "outputSignature" : [ { - "name" : "w0", - "type" : "LONG" - }, { - "name" : "a0", - "type" : "LONG" - } ], - "operatorDefinition" : [ { - "type" : "naiveSort", - "columns" : [ { - "column" : "a0", - "direction" : "ASC" - } ] - }, { - "type" : "scan", - "timeRange" : null, - "filter" : null, - "offsetLimit" : null, - "projectedColumns" : [ "w0", "a0" ], - "virtualColumns" : null, - "ordering" : null - } ], - "leafOperators" : [ { - "type" : "scan", - "timeRange" : null, - "filter" : null, - "offsetLimit" : { - "offset" : 0, - "limit" : 9223372036854775807 - }, - "projectedColumns" : [ "a0", "w0" ], - "virtualColumns" : null, - "ordering" : null - } ], - "granularity" : { - "type" : "all" - } -} -!nativePlan From 136e79d862b7c6e634b25d1f0d404d7c5ad8e50e Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:18:17 +0000 Subject: [PATCH 11/24] checkstyle --- .../sql/calcite/planner/CalciteRulesManager.java | 4 ++-- .../apache/druid/quidem/DruidAvaticaTestDriver.java | 12 +++++++----- .../druid/quidem/DruidQuidemCommandHandler.java | 1 - .../apache/druid/sql/calcite/DecoupledExtension.java | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java index 85a768e1fa8b..7faaa69581bc 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java @@ -372,8 +372,8 @@ private Program buildReductionProgram(final PlannerContext plannerContext, final return Programs.of(builder.build(), true, DefaultRelMetadataProvider.INSTANCE); } - private static class SaveLogicalPlanProgram implements Program { - + private static class SaveLogicalPlanProgram implements Program + { public static SaveLogicalPlanProgram INSTANCE = new SaveLogicalPlanProgram(); @Override diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java index 48b4bed58587..cc29f4d13be7 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java @@ -148,11 +148,11 @@ public DruidSchemaCatalog getLookupNodeService(QueryRunnerFactoryConglomerate co @Provides @LazySingleton - public DruidConnectionExtras getConnectionExtras(ObjectMapper objectMapper) { + public DruidConnectionExtras getConnectionExtras(ObjectMapper objectMapper) + { return new DruidConnectionExtras.DruidConnectionExtrasImpl(objectMapper); } - @Provides @LazySingleton public AvaticaJettyServer getAvaticaServer(DruidMeta druidMeta, Closer closer, DruidConnectionExtras druidConnectionExtras) throws Exception @@ -186,15 +186,17 @@ static class AvaticaJettyServer implements Closeable "jdbc:avatica:remote:url=%s", new URIBuilder(server.getURI()).setPath(DruidAvaticaJsonHandler.AVATICA_PATH).build() ); - connectionExtras = druidConnectionExtras; + connectionExtras = druidConnectionExtras; } public Connection getConnection(Properties info) throws SQLException { Connection realConnection = DriverManager.getConnection(url, info); Connection proxyConnection = DynamicComposite.make( - realConnection, Connection.class, - connectionExtras, DruidConnectionExtras.class + realConnection, + Connection.class, + connectionExtras, + DruidConnectionExtras.class ); return proxyConnection; } diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java index 168692f09126..f6577e3903fe 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemCommandHandler.java @@ -134,7 +134,6 @@ protected void executeExplain(Context x) throws Exception executeQuery(x); } ); -// BaseCalciteQueryTest conn = x.connection().unwrap(BaseCalciteQueryTest.class); List> queries = qlh.getRecordedQueries(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java index 508ff54aec2d..9023eaebb3c1 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import java.io.File; + import static org.junit.Assume.assumeTrue; public class DecoupledExtension implements BeforeEachCallback From ddc26e97d7364aa47ead4f08811cf91b58c1d66c Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:29:33 +0000 Subject: [PATCH 12/24] followup --- .../org/apache/druid/sql/calcite/DecoupledTestConfig.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java index cbc9ebd2cc48..511db82b76b7 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledTestConfig.java @@ -44,11 +44,6 @@ */ NativeQueryIgnore nativeQueryIgnore() default NativeQueryIgnore.NONE; - /** - * Use alternate quidem test for testcase - */ - boolean quidem() default false; - enum NativeQueryIgnore { NONE, From ec54b5b08b687a939db37ccfa3d0ece2f693c442 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:29:39 +0000 Subject: [PATCH 13/24] cleanup --- .../apache/druid/quidem/DruidAvaticaTestDriver.java | 1 - .../java/org/apache/druid/quidem/DynamicComposite.java | 10 +++++----- .../org/apache/druid/quidem/DynamicCompositeTest.java | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java index cc29f4d13be7..72fe4d4b155f 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java @@ -267,7 +267,6 @@ public void configureGuice(DruidInjectorBuilder builder) { }).toInstance(Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))); binder.bind(CalciteRulesManager.class).toInstance(new CalciteRulesManager(ImmutableSet.of())); - // binder.bind(JoinableFactoryWrapper.class).toInstance(CalciteTests.createJoinableFactoryWrapper()); binder.bind(CatalogResolver.class).toInstance(CatalogResolver.NULL_RESOLVER); } ); diff --git a/sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java b/sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java index ec4605e6fc6c..290e972761ee 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java +++ b/sql/src/test/java/org/apache/druid/quidem/DynamicComposite.java @@ -23,28 +23,28 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; +/** + * Dynamically creates a composite from two classes. + */ public class DynamicComposite implements InvocationHandler { - @SuppressWarnings("unchecked") public static T make(T base, Class baseClass, E ext, Class extClass) { return (T) Proxy.newProxyInstance( base.getClass().getClassLoader(), new Class[] {baseClass, extClass}, - new DynamicComposite(base, baseClass, ext, extClass) + new DynamicComposite(base, ext, extClass) ); } private final T base; - private final Class baseClass; private final E ext; private final Class extClass; - DynamicComposite(T base, Class baseClass, E ext, Class extClass) + private DynamicComposite(T base, E ext, Class extClass) { this.base = base; - this.baseClass = baseClass; this.ext = ext; this.extClass = extClass; } diff --git a/sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java b/sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java index 2a018a95a0b6..b8fb71f6acae 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java +++ b/sql/src/test/java/org/apache/druid/quidem/DynamicCompositeTest.java @@ -42,7 +42,6 @@ public void testCompose() assertInstanceOf(Function.class, composite); Function sq2 = (Function) composite; - assertEquals(9, sq.apply(3)); - + assertEquals(9, sq2.apply(3)); } } From 659ced932704e9fbf7bf89d3babef48256847413 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:51:24 +0000 Subject: [PATCH 14/24] remove urnelated --- .../druid/quidem/DruidConnectionExtras.java | 2 +- .../druid/sql/calcite/DecoupledExtension.java | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java b/sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java index 2b75f82122c1..75bdd4280fab 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidConnectionExtras.java @@ -25,7 +25,7 @@ public interface DruidConnectionExtras { ObjectMapper getObjectMapper(); - public class DruidConnectionExtrasImpl implements DruidConnectionExtras + class DruidConnectionExtrasImpl implements DruidConnectionExtras { private final ObjectMapper objectMapper; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java index 9023eaebb3c1..f740649aaebc 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java @@ -21,20 +21,15 @@ import com.google.common.collect.ImmutableMap; import org.apache.druid.query.QueryContexts; -import org.apache.druid.quidem.ProjectPathUtils; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.sql.calcite.BaseCalciteQueryTest.CalciteTestConfig; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.io.File; - +import org.junit.jupiter.api.extension.Extension; import static org.junit.Assume.assumeTrue; -public class DecoupledExtension implements BeforeEachCallback +public class DecoupledExtension implements Extension { private BaseCalciteQueryTest baseTest; @@ -43,15 +38,6 @@ public DecoupledExtension(BaseCalciteQueryTest baseTest) this.baseTest = baseTest; } - private File qCaseDir; - - @Override - public void beforeEach(ExtensionContext context) throws Exception - { - Class testClass = context.getTestClass().get(); - qCaseDir = ProjectPathUtils.getPathFromProjectRoot("sql/src/test/quidem/" + testClass.getName()); - } - private static final ImmutableMap CONTEXT_OVERRIDES = ImmutableMap.builder() .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) .put(PlannerConfig.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, PlannerConfig.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED) @@ -64,7 +50,6 @@ public QueryTestBuilder testBuilder() .getAnnotation(DecoupledTestConfig.class); assumeTrue(BaseCalciteQueryTest.queryFrameworkRule.getConfig().numMergeBuffers == 0); - PlannerComponentSupplier componentSupplier = baseTest; CalciteTestConfig testConfig = baseTest.new CalciteTestConfig(CONTEXT_OVERRIDES) From f55f3e4ab665758bf3347f160dd28d0cb0e9b768 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 16 Apr 2024 10:52:01 +0000 Subject: [PATCH 15/24] remove incorrect assume --- .../java/org/apache/druid/sql/calcite/DecoupledExtension.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java index f740649aaebc..7a4ef5ad925a 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java @@ -27,7 +27,6 @@ import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; import org.junit.jupiter.api.extension.Extension; -import static org.junit.Assume.assumeTrue; public class DecoupledExtension implements Extension { @@ -49,7 +48,6 @@ public QueryTestBuilder testBuilder() DecoupledTestConfig decTestConfig = BaseCalciteQueryTest.queryFrameworkRule .getAnnotation(DecoupledTestConfig.class); - assumeTrue(BaseCalciteQueryTest.queryFrameworkRule.getConfig().numMergeBuffers == 0); PlannerComponentSupplier componentSupplier = baseTest; CalciteTestConfig testConfig = baseTest.new CalciteTestConfig(CONTEXT_OVERRIDES) From a13051e071d4e198a11ef94140c111f86253bef3 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Thu, 18 Apr 2024 12:56:35 +0000 Subject: [PATCH 16/24] followup remove class --- .../apache/druid/quidem/DruidQTestInfo.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java b/sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java deleted file mode 100644 index 49f9d98668aa..000000000000 --- a/sql/src/test/java/org/apache/druid/quidem/DruidQTestInfo.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.druid.quidem; - -import java.io.File; - -public class DruidQTestInfo -{ - public final File caseDir; - public final String testName; - - public DruidQTestInfo(File caseDir, String testName) - { - this.caseDir = caseDir; - this.testName = testName; - } - - public File getIQFile() - { - return new File(caseDir, testName + ".iq"); - } -} From 494f1054ec9a44c551b69d6ff1bac1ee0f4bbf10 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 23 Apr 2024 13:03:31 +0000 Subject: [PATCH 17/24] add afterall-close (cherry picked from commit 1fc55a9ff6e071ccad43d6d725d1f21871a48b54) --- .../java/org/apache/druid/quidem/DruidQuidemTestBase.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java index ca58ab10fe2d..f7cbc2134d03 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java @@ -33,6 +33,7 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.RE; import org.apache.druid.java.util.common.StringUtils; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -204,4 +205,10 @@ private boolean isTestIncluded(File f) } protected abstract File getTestRoot(); + + @AfterAll + public static void afterAll() + { + DruidAvaticaTestDriver.CONFIG_STORE.close(); + } } From 73111ab9ea75de49aee6b3ddfe66c0590549c98a Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 23 Apr 2024 13:03:40 +0000 Subject: [PATCH 18/24] Revert "Revert "close AvaticaJettyServer"" This reverts commit 0ab23642ab51fc4df4218e4a185099db821d8bc7. (cherry picked from commit 7d1992da1009635dca9509294466f5899a4b773a) --- .../druid/quidem/DruidAvaticaTestDriver.java | 24 +++++++++++++++---- .../sql/calcite/SqlTestFrameworkConfig.java | 3 ++- .../sql/calcite/util/SqlTestFramework.java | 9 ++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java index 72fe4d4b155f..33df8694cb9a 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java @@ -131,8 +131,10 @@ public Connection connect(String url, Properties info) throws SQLException } } - static class AvaticaBasedConnectionModule implements DruidModule + static class AvaticaBasedConnectionModule implements DruidModule, Closeable { + Closer closer = Closer.create(); + @Provides @LazySingleton public DruidSchemaCatalog getLookupNodeService(QueryRunnerFactoryConglomerate conglomerate, @@ -155,7 +157,7 @@ public DruidConnectionExtras getConnectionExtras(ObjectMapper objectMapper) @Provides @LazySingleton - public AvaticaJettyServer getAvaticaServer(DruidMeta druidMeta, Closer closer, DruidConnectionExtras druidConnectionExtras) throws Exception + public AvaticaJettyServer getAvaticaServer(DruidMeta druidMeta, DruidConnectionExtras druidConnectionExtras) throws Exception { AvaticaJettyServer avaticaJettyServer = new AvaticaJettyServer(druidMeta, druidConnectionExtras); closer.register(avaticaJettyServer); @@ -167,6 +169,12 @@ public void configure(Binder binder) { } + @Override + public void close() throws IOException + { + closer.close(); + } + } static class AvaticaJettyServer implements Closeable @@ -225,12 +233,13 @@ protected AbstractAvaticaHandler getAvaticaHandler(final DruidMeta druidMeta) static class AvaticaBasedTestConnectionSupplier implements QueryComponentSupplier { - private QueryComponentSupplier delegate; + private AvaticaBasedConnectionModule connectionModule; public AvaticaBasedTestConnectionSupplier(QueryComponentSupplier delegate) { this.delegate = delegate; + this.connectionModule = new AvaticaBasedConnectionModule(); } @Override @@ -244,7 +253,7 @@ public void configureGuice(DruidInjectorBuilder builder) { delegate.configureGuice(builder); TestRequestLogger testRequestLogger = new TestRequestLogger(); - builder.addModule(new AvaticaBasedConnectionModule()); + builder.addModule(connectionModule); builder.addModule( binder -> { binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test"); @@ -308,6 +317,13 @@ public void finalizeTestFramework(SqlTestFramework sqlTestFramework) { delegate.finalizeTestFramework(sqlTestFramework); } + + @Override + public void close() throws IOException + { + connectionModule.close(); + delegate.close(); + } } protected File createTempFolder(String prefix) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java index e33e6c1af8fe..3cfc920bad3f 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; +import java.io.Closeable; import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -91,7 +92,7 @@ public boolean equals(Object obj) } - class SqlTestFrameworkConfigStore + class SqlTestFrameworkConfigStore implements Closeable { Map configMap = new HashMap<>(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java index 462aa7dd9ca7..3b1385cde74f 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java @@ -67,6 +67,7 @@ import org.apache.druid.sql.calcite.view.ViewManager; import org.apache.druid.timeline.DataSegment; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -126,7 +127,7 @@ public class SqlTestFramework * exist in {@code BaseCalciteQueryTest}. Any changes here will impact that * base class, and possibly many test cases that extend that class. */ - public interface QueryComponentSupplier + public interface QueryComponentSupplier extends Closeable { /** * Gather properties to be used within tests. Particularly useful when choosing @@ -285,6 +286,11 @@ public JoinableFactoryWrapper createJoinableFactoryWrapper(LookupExtractorFactor public void finalizeTestFramework(SqlTestFramework sqlTestFramework) { } + + @Override + public void close() + { + } } public static class StandardPlannerComponentSupplier implements PlannerComponentSupplier @@ -655,6 +661,7 @@ public void close() { try { resourceCloser.close(); + componentSupplier.close(); } catch (IOException e) { throw new RE(e); From 49693ee68e763f3fde03bc6ca77ebcb4313966e6 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 23 Apr 2024 13:23:26 +0000 Subject: [PATCH 19/24] close (cherry picked from commit 5ba6e9b61a347dbdfa1ec6fb7036f1a597dbae4b) --- .../java/org/apache/druid/quidem/DruidAvaticaTestDriver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java index 33df8694cb9a..913ff0e42e82 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java @@ -101,7 +101,7 @@ public class DruidAvaticaTestDriver implements Driver public static final String URI_PREFIX = "druidtest://"; public static final String DEFAULT_URI = URI_PREFIX + "/"; - private static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore(); + static final SqlTestFrameworkConfigStore CONFIG_STORE = new SqlTestFrameworkConfigStore(); public DruidAvaticaTestDriver() { From cfaa99b5763eaf02501e9ffb85445936581133bf Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 23 Apr 2024 13:28:43 +0000 Subject: [PATCH 20/24] add close to BaseCalciteQueryTest --- .../org/apache/druid/sql/calcite/BaseCalciteQueryTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java index 854ac2215985..f87aa71ad0cb 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java @@ -1644,4 +1644,9 @@ public File getResourceAsTemporaryFile(final String resource) } return file; } + + @Override + public void close() throws IOException + { + } } From 7b3ac58e338057d5dde62649655fe418902d5b0c Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 23 Apr 2024 13:30:49 +0000 Subject: [PATCH 21/24] use default impl instead of empty methods --- .../apache/druid/sql/calcite/BaseCalciteQueryTest.java | 5 ----- .../apache/druid/sql/calcite/util/SqlTestFramework.java | 9 ++++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java index f87aa71ad0cb..854ac2215985 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java @@ -1644,9 +1644,4 @@ public File getResourceAsTemporaryFile(final String resource) } return file; } - - @Override - public void close() throws IOException - { - } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java index 3b1385cde74f..96783d8bbae4 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java @@ -175,6 +175,10 @@ default CatalogResolver createCatalogResolver() JoinableFactoryWrapper createJoinableFactoryWrapper(LookupExtractorFactoryContainerProvider lookupProvider); void finalizeTestFramework(SqlTestFramework sqlTestFramework); + + default void close() throws IOException + { + } } public interface PlannerComponentSupplier @@ -286,11 +290,6 @@ public JoinableFactoryWrapper createJoinableFactoryWrapper(LookupExtractorFactor public void finalizeTestFramework(SqlTestFramework sqlTestFramework) { } - - @Override - public void close() - { - } } public static class StandardPlannerComponentSupplier implements PlannerComponentSupplier From d61b9a0ecaedd835c348bb2b31d3d130b5e1e89b Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 23 Apr 2024 14:31:47 +0000 Subject: [PATCH 22/24] add missing override --- .../org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java | 1 + .../java/org/apache/druid/sql/calcite/util/SqlTestFramework.java | 1 + 2 files changed, 2 insertions(+) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java index 3cfc920bad3f..0178d6eaabc3 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java @@ -108,6 +108,7 @@ public ConfigurationInstance getConfigurationInstance( return ret; } + @Override public void close() { for (ConfigurationInstance f : configMap.values()) { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java index 96783d8bbae4..4bc9cc297bd0 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java @@ -176,6 +176,7 @@ default CatalogResolver createCatalogResolver() void finalizeTestFramework(SqlTestFramework sqlTestFramework); + @Override default void close() throws IOException { } From bf524c73c1ac791572bb7a85380bf26e2debae2c Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Mon, 29 Apr 2024 14:09:09 +0000 Subject: [PATCH 23/24] add runnable --- .../druid/sql/calcite/schema/BrokerSegmentMetadataCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/BrokerSegmentMetadataCache.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/BrokerSegmentMetadataCache.java index c09873c59420..0573d8d49ee1 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/BrokerSegmentMetadataCache.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/BrokerSegmentMetadataCache.java @@ -159,7 +159,7 @@ public ServerView.CallbackAction segmentSchemasAnnounced(SegmentSchemas segmentS public void start() throws InterruptedException { log.info("Initializing cache."); - cacheExec.submit(this::cacheExecLoop); + cacheExec.submit((Runnable) this::cacheExecLoop); if (config.isAwaitInitializationOnStart()) { awaitInitialization(); } From b09aa1acdca905c504262c998adf2d559d69997f Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Mon, 29 Apr 2024 15:17:57 +0000 Subject: [PATCH 24/24] fix merge issues --- .../apache/druid/quidem/DruidAvaticaTestDriver.java | 11 +++++++++-- .../apache/druid/sql/calcite/DecoupledExtension.java | 5 +---- .../druid/sql/calcite/SqlTestFrameworkConfig.java | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java index 913ff0e42e82..5e1a474ffdd9 100644 --- a/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java +++ b/sql/src/test/java/org/apache/druid/quidem/DruidAvaticaTestDriver.java @@ -68,6 +68,7 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.Builder; +import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier; import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier; import org.apache.druid.sql.guice.SqlModule; @@ -117,8 +118,8 @@ public Connection connect(String url, Properties info) throws SQLException ConfigurationInstance ci = CONFIG_STORE.getConfigurationInstance( config, - new AvaticaBasedTestConnectionSupplier( - new StandardComponentSupplier(createTempFolder(getClass().getSimpleName())) + tempDirProducer -> new AvaticaBasedTestConnectionSupplier( + new StandardComponentSupplier(tempDirProducer) ) ); @@ -324,6 +325,12 @@ public void close() throws IOException connectionModule.close(); delegate.close(); } + + @Override + public PlannerComponentSupplier getPlannerComponentSupplier() + { + return delegate.getPlannerComponentSupplier(); + } } protected File createTempFolder(String prefix) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java index 7a4ef5ad925a..ec1e64df95c3 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledExtension.java @@ -25,7 +25,6 @@ import org.apache.druid.sql.calcite.BaseCalciteQueryTest.CalciteTestConfig; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.SqlTestFramework; -import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; import org.junit.jupiter.api.extension.Extension; public class DecoupledExtension implements Extension @@ -48,8 +47,6 @@ public QueryTestBuilder testBuilder() DecoupledTestConfig decTestConfig = BaseCalciteQueryTest.queryFrameworkRule .getAnnotation(DecoupledTestConfig.class); - PlannerComponentSupplier componentSupplier = baseTest; - CalciteTestConfig testConfig = baseTest.new CalciteTestConfig(CONTEXT_OVERRIDES) { @Override @@ -57,7 +54,7 @@ public SqlTestFramework.PlannerFixture plannerFixture(PlannerConfig plannerConfi { plannerConfig = plannerConfig.withOverrides(CONTEXT_OVERRIDES); - return baseTest.queryFramework().plannerFixture(componentSupplier, plannerConfig, authConfig); + return baseTest.queryFramework().plannerFixture(plannerConfig, authConfig); } }; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java index c0f81985a714..fecd7e7deb24 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java @@ -102,11 +102,11 @@ class SqlTestFrameworkConfigStore implements Closeable public ConfigurationInstance getConfigurationInstance( SqlTestFrameworkConfigInstance config, - QueryComponentSupplier testHost) + Function testHostSupplier) { ConfigurationInstance ret = configMap.get(config); if (!configMap.containsKey(config)) { - ret = new ConfigurationInstance(config, testHost); + ret = new ConfigurationInstance(config, testHostSupplier.apply(new TempDirProducer("druid-test"))); configMap.put(config, ret); } return ret; @@ -202,7 +202,7 @@ public SqlTestFrameworkConfigInstance getConfig() public SqlTestFramework get() { - return configStore.getConfigurationInstance(config, testHost).framework; + return configStore.getConfigurationInstance(config, testHostSupplier).framework; } public T getAnnotation(Class annotationType)