From 8308becb6c1cc6fb7e334a4650ab9855fa6b32f8 Mon Sep 17 00:00:00 2001 From: morrySnow Date: Thu, 12 Sep 2024 16:45:21 +0800 Subject: [PATCH] [chore](variable) remove enable_nereids_planner flag --- .../org/apache/doris/analysis/SlotRef.java | 1 - .../doris/cloud/CacheHotspotManagerUtils.java | 1 - .../apache/doris/load/ExportTaskExecutor.java | 14 +- .../jobs/scheduler/SimpleJobScheduler.java | 4 +- .../analysis/EliminateLogicalSelectHint.java | 7 - .../functions/scalar/ArrayApply.java | 2 +- .../plans/commands/AlterMTMVCommand.java | 2 +- .../plans/commands/CancelMTMVTaskCommand.java | 2 +- .../plans/commands/CreateMTMVCommand.java | 2 +- .../trees/plans/commands/DropMTMVCommand.java | 2 +- .../plans/commands/NotAllowFallback.java | 25 - .../plans/commands/PauseMTMVCommand.java | 2 +- .../plans/commands/RefreshMTMVCommand.java | 2 +- .../plans/commands/ResumeMTMVCommand.java | 2 +- .../plans/commands/ShowCreateMTMVCommand.java | 2 +- .../worker/job/UnassignedJobBuilder.java | 8 - .../apache/doris/planner/PlanFragment.java | 6 +- .../plsql/executor/PlsqlQueryExecutor.java | 3 +- .../org/apache/doris/qe/ConnectProcessor.java | 100 +- .../java/org/apache/doris/qe/Coordinator.java | 7 - .../doris/qe/MysqlConnectProcessor.java | 8 +- .../org/apache/doris/qe/SessionVariable.java | 37 +- .../org/apache/doris/qe/StmtExecutor.java | 184 +- .../FlightSqlConnectProcessor.java | 2 +- .../doris/statistics/util/StatisticsUtil.java | 2 - .../doris/analysis/InsertArrayStmtTest.java | 25 +- .../analysis/RangePartitionPruneTest.java | 96 +- .../apache/doris/analysis/SelectStmtTest.java | 1087 -------- .../doris/analysis/SetVariableTest.java | 2 +- .../TableNameComparedLowercaseTest.java | 17 - .../doris/catalog/CreateFunctionTest.java | 154 +- .../doris/external/hms/HmsCatalogTest.java | 1 - .../doris/nereids/metrics/EventTest.java | 1 - .../nereids/preprocess/SelectHintTest.java | 85 - .../rules/analysis/CheckRowPolicyTest.java | 2 - .../doris/planner/ColocatePlanTest.java | 309 --- .../doris/planner/DistributedPlannerTest.java | 171 -- .../org/apache/doris/planner/PlannerTest.java | 734 ------ .../planner/ProjectPlannerFunctionTest.java | 111 - .../planner/QueryCacheNormalizerTest.java | 3 - .../apache/doris/planner/QueryPlanTest.java | 2300 ----------------- .../apache/doris/planner/RepeatNodeTest.java | 80 - .../doris/planner/TableFunctionPlanTest.java | 554 ---- .../org/apache/doris/policy/PolicyTest.java | 96 - .../apache/doris/qe/SessionVariablesTest.java | 37 +- .../org/apache/doris/qe/StmtExecutorTest.java | 2 +- .../ExtractCommonFactorsRuleFunctionTest.java | 338 --- .../doris/rewrite/InferFiltersRuleTest.java | 404 --- .../RewriteBinaryPredicatesRuleTest.java | 129 - .../rewrite/RewriteInPredicateRuleTest.java | 144 -- .../apache/doris/utframe/AnotherDemoTest.java | 2 +- .../org/apache/doris/utframe/DemoTest.java | 2 +- .../correctness_p0/test_colocate_join.out | 22 - .../test_array_zip_array_enumerate_uniq.out | 12 - .../get_assignment_compatible_type.out | 2 +- ...t_create_table_generated_column_legacy.out | 93 - .../data/ddl_p0/test_create_view.out | 29 - ...ert_group_commit_into_max_filter_ratio.out | 6 - .../test_array_functions_by_literal.out | 20 +- .../cast_function/test_cast_map_function.out | 4 +- .../test_show_create_table_and_views.out | 46 - ...reate_view_star_except_and_cast_to_sql.out | 4 +- .../correctness_p0/test_colocate_join.groovy | 311 --- .../test_push_conjuncts_inlineview.groovy | 189 -- .../datetimev2/test_timezone.groovy | 19 - ...test_array_zip_array_enumerate_uniq.groovy | 72 +- ...reate_table_generated_column_legacy.groovy | 249 -- .../suites/ddl_p0/test_create_view.groovy | 237 -- .../suites/demo_p0/explain_action.groovy | 6 +- ..._group_commit_into_max_filter_ratio.groovy | 94 +- .../insert_group_commit_with_exception.groovy | 351 ++- .../txn_insert_with_specify_columns.groovy | 54 - .../test_jsonb_load_and_function.groovy | 9 - .../grouping_sets/valid_grouping.groovy | 54 - .../test_date_function_prune.groovy | 12 +- .../suites/query_p0/dual/dual.groovy | 8 - .../test_array_functions_by_literal.groovy | 27 +- .../test_cast_map_function.groovy | 1 - .../test_show_create_table_and_views.groovy | 150 -- .../test_create_table.groovy | 21 - ...te_view_star_except_and_cast_to_sql.groovy | 1 - 81 files changed, 444 insertions(+), 8972 deletions(-) delete mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NotAllowFallback.java delete mode 100755 fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/planner/ColocatePlanTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/planner/DistributedPlannerTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/planner/RepeatNodeTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRuleTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteInPredicateRuleTest.java delete mode 100644 regression-test/data/correctness_p0/test_colocate_join.out delete mode 100644 regression-test/data/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.out delete mode 100644 regression-test/data/ddl_p0/test_create_view.out delete mode 100644 regression-test/data/show_p0/test_show_create_table_and_views.out delete mode 100644 regression-test/suites/correctness_p0/test_colocate_join.groovy delete mode 100644 regression-test/suites/correctness_p0/test_push_conjuncts_inlineview.groovy delete mode 100644 regression-test/suites/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.groovy delete mode 100644 regression-test/suites/ddl_p0/test_create_view.groovy delete mode 100644 regression-test/suites/nereids_rules_p0/grouping_sets/valid_grouping.groovy delete mode 100644 regression-test/suites/show_p0/test_show_create_table_and_views.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java index 8db81c9ac10f34a..7078c90f1ed5be8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java @@ -262,7 +262,6 @@ public String toSqlImpl() { && ConnectContext.get().getState().isNereids() && !ConnectContext.get().getState().isQuery() && ConnectContext.get().getSessionVariable() != null - && ConnectContext.get().getSessionVariable().isEnableNereidsPlanner() && desc != null) { return label + "[#" + desc.getId().asInt() + "]"; } else { diff --git a/fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManagerUtils.java b/fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManagerUtils.java index 8e46547ae6c121e..d73003e0daf9ea7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManagerUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManagerUtils.java @@ -231,7 +231,6 @@ public static AutoCloseConnectContext buildConnectContext() { sessionVariable.setEnableInsertStrict(true); sessionVariable.setInsertMaxFilterRatio(1); // sessionVariable.parallelExecInstanceNum = StatisticConstants.STATISTIC_PARALLEL_EXEC_INSTANCE_NUM; - sessionVariable.setEnableNereidsPlanner(false); sessionVariable.enableProfile = false; connectContext.setEnv(Env.getCurrentEnv()); connectContext.setDatabase(FeConstants.INTERNAL_DB_NAME); diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/ExportTaskExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/load/ExportTaskExecutor.java index 569693570668468..d18d69bd90bbe3a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/load/ExportTaskExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/load/ExportTaskExecutor.java @@ -18,7 +18,6 @@ package org.apache.doris.load; import org.apache.doris.analysis.OutFileClause; -import org.apache.doris.analysis.SelectStmt; import org.apache.doris.analysis.StatementBase; import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; @@ -95,15 +94,10 @@ public void execute() throws JobException { table.readLock(); try { List tabletIds; - if (exportJob.getSessionVariables().isEnableNereidsPlanner()) { - LogicalPlanAdapter logicalPlanAdapter = (LogicalPlanAdapter) selectStmtLists.get(idx); - Optional unboundRelation = findUnboundRelation( - logicalPlanAdapter.getLogicalPlan()); - tabletIds = unboundRelation.get().getTabletIds(); - } else { - SelectStmt selectStmt = (SelectStmt) selectStmtLists.get(idx); - tabletIds = selectStmt.getTableRefs().get(0).getSampleTabletIds(); - } + LogicalPlanAdapter logicalPlanAdapter = (LogicalPlanAdapter) selectStmtLists.get(idx); + Optional unboundRelation = findUnboundRelation( + logicalPlanAdapter.getLogicalPlan()); + tabletIds = unboundRelation.get().getTabletIds(); for (Long tabletId : tabletIds) { TabletMeta tabletMeta = Env.getCurrentEnv().getTabletInvertedIndex().getTabletMeta( diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/scheduler/SimpleJobScheduler.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/scheduler/SimpleJobScheduler.java index 32a82127e6dbe25..e31c92e3fe004cb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/scheduler/SimpleJobScheduler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/scheduler/SimpleJobScheduler.java @@ -18,7 +18,7 @@ package org.apache.doris.nereids.jobs.scheduler; import org.apache.doris.nereids.CascadesContext; -import org.apache.doris.nereids.exceptions.DoNotFallbackException; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.jobs.Job; import org.apache.doris.qe.SessionVariable; @@ -37,7 +37,7 @@ public void executeJobPool(ScheduleContext scheduleContext) { if (sessionVariable.enableNereidsTimeout && context.getStatementContext().getStopwatch().elapsed(TimeUnit.MILLISECONDS) > sessionVariable.nereidsTimeoutSecond * 1000L) { - throw new DoNotFallbackException( + throw new AnalysisException( "Nereids cost too much time ( > " + sessionVariable.nereidsTimeoutSecond + "s )"); } Job job = pool.pop(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java index b0f55365f332fd9..1275c33a565909f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/EliminateLogicalSelectHint.java @@ -23,7 +23,6 @@ import org.apache.doris.nereids.CascadesContext; import org.apache.doris.nereids.StatementContext; import org.apache.doris.nereids.exceptions.AnalysisException; -import org.apache.doris.nereids.exceptions.MustFallbackException; import org.apache.doris.nereids.hint.Hint; import org.apache.doris.nereids.hint.LeadingHint; import org.apache.doris.nereids.hint.OrderedHint; @@ -108,12 +107,6 @@ private void setVar(SelectHintSetVar selectHint, StatementContext context) { } } } - // if sv set enable_nereids_planner=true and hint set enable_nereids_planner=false, we should set - // enable_fallback_to_original_planner=true and revert it after executing. - // throw exception to fall back to original planner - if (!sessionVariable.isEnableNereidsPlanner()) { - throw new MustFallbackException("The nereids is disabled in this sql, fallback to original planner"); - } } private void extractLeading(SelectHintLeading selectHint, CascadesContext context, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java index 07e4c16d7766535..86138b82cac170b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java @@ -73,7 +73,7 @@ public void checkLegalityBeforeTypeCoercion() { DataType argType = ((ArrayType) child(0).getDataType()).getItemType(); if (!(argType.isIntegralType() || argType.isFloatLikeType() || argType.isDecimalLikeType() || argType.isDateLikeType() || argType.isBooleanType())) { - throw new AnalysisException("array_apply does not support type: " + toSql()); + throw new AnalysisException("array_apply does not support type " + argType + ", expression is " + toSql()); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterMTMVCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterMTMVCommand.java index 56f1ffec182444a..24cb47846da9adc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterMTMVCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AlterMTMVCommand.java @@ -32,7 +32,7 @@ /** * alter multi table materialized view */ -public class AlterMTMVCommand extends Command implements ForwardWithSync, NotAllowFallback { +public class AlterMTMVCommand extends Command implements ForwardWithSync { public static final Logger LOG = LogManager.getLogger(AlterMTMVCommand.class); private final AlterMTMVInfo alterMTMVInfo; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CancelMTMVTaskCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CancelMTMVTaskCommand.java index c8b2a19067df892..ba1078c33d95394 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CancelMTMVTaskCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CancelMTMVTaskCommand.java @@ -30,7 +30,7 @@ /** * cancel mtmv task */ -public class CancelMTMVTaskCommand extends Command implements ForwardWithSync, NotAllowFallback { +public class CancelMTMVTaskCommand extends Command implements ForwardWithSync { private final CancelMTMVTaskInfo cancelMTMVTaskInfo; public CancelMTMVTaskCommand(CancelMTMVTaskInfo cancelMTMVTaskInfo) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java index 0bc3c335fd12f43..0eac139d5f9ae55 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java @@ -33,7 +33,7 @@ /** * create multi table materialized view */ -public class CreateMTMVCommand extends Command implements ForwardWithSync, NotAllowFallback { +public class CreateMTMVCommand extends Command implements ForwardWithSync { public static final Logger LOG = LogManager.getLogger(CreateMTMVCommand.class); private final CreateMTMVInfo createMTMVInfo; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropMTMVCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropMTMVCommand.java index 909b87ef9aa3f84..f5b986a37188238 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropMTMVCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropMTMVCommand.java @@ -30,7 +30,7 @@ /** * refresh mtmv */ -public class DropMTMVCommand extends Command implements ForwardWithSync, NotAllowFallback { +public class DropMTMVCommand extends Command implements ForwardWithSync { private final DropMTMVInfo dropMTMVInfo; public DropMTMVCommand(DropMTMVInfo dropMTMVInfo) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NotAllowFallback.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NotAllowFallback.java deleted file mode 100644 index 72d8c82e5996a9d..000000000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NotAllowFallback.java +++ /dev/null @@ -1,25 +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.doris.nereids.trees.plans.commands; - -/** - * The class that implements this interface does not allow fallback to OriginalPlanner, - * for example, some new features are not implemented by the old parser - */ -public interface NotAllowFallback { -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PauseMTMVCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PauseMTMVCommand.java index fadb3bc0c3270aa..7e130a9ab47cd71 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PauseMTMVCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PauseMTMVCommand.java @@ -30,7 +30,7 @@ /** * pause mtmv */ -public class PauseMTMVCommand extends Command implements ForwardWithSync, NotAllowFallback { +public class PauseMTMVCommand extends Command implements ForwardWithSync { private final PauseMTMVInfo pauseMTMVInfo; public PauseMTMVCommand(PauseMTMVInfo pauseMTMVInfo) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java index 2ed3e446d7bec0a..c8ea6f19bbdb312 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java @@ -30,7 +30,7 @@ /** * refresh mtmv */ -public class RefreshMTMVCommand extends Command implements ForwardWithSync, NotAllowFallback { +public class RefreshMTMVCommand extends Command implements ForwardWithSync { private final RefreshMTMVInfo refreshMTMVInfo; public RefreshMTMVCommand(RefreshMTMVInfo refreshMTMVInfo) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ResumeMTMVCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ResumeMTMVCommand.java index 5fc933886c2f8e2..7c53636f5555ac7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ResumeMTMVCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ResumeMTMVCommand.java @@ -30,7 +30,7 @@ /** * resume mtmv */ -public class ResumeMTMVCommand extends Command implements ForwardWithSync, NotAllowFallback { +public class ResumeMTMVCommand extends Command implements ForwardWithSync { private final ResumeMTMVInfo resumeMTMVInfo; public ResumeMTMVCommand(ResumeMTMVInfo resumeMTMVInfo) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateMTMVCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateMTMVCommand.java index 7da1df6af6f30ad..19ecac345b36a5a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateMTMVCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowCreateMTMVCommand.java @@ -29,7 +29,7 @@ /** * resume mtmv */ -public class ShowCreateMTMVCommand extends Command implements NoForward, NotAllowFallback { +public class ShowCreateMTMVCommand extends Command implements NoForward { private final ShowCreateMTMVInfo showCreateMTMVInfo; public ShowCreateMTMVCommand(ShowCreateMTMVInfo showCreateMTMVInfo) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/distribute/worker/job/UnassignedJobBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/distribute/worker/job/UnassignedJobBuilder.java index f7357f1851994b8..396ba51e01b4ee0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/distribute/worker/job/UnassignedJobBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/distribute/worker/job/UnassignedJobBuilder.java @@ -30,8 +30,6 @@ import org.apache.doris.planner.PlanNodeId; import org.apache.doris.planner.ScanNode; import org.apache.doris.planner.SchemaScanNode; -import org.apache.doris.qe.ConnectContext; -import org.apache.doris.qe.SessionVariable; import org.apache.doris.thrift.TExplainLevel; import com.google.common.collect.ArrayListMultimap; @@ -255,12 +253,6 @@ private static boolean shouldAssignByBucket(PlanFragment fragment) { } private static boolean enableBucketShuffleJoin() { - if (ConnectContext.get() != null) { - SessionVariable sessionVariable = ConnectContext.get().getSessionVariable(); - if (!sessionVariable.isEnableBucketShuffleJoin() && !sessionVariable.isEnableNereidsPlanner()) { - return false; - } - } return true; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java index bb41761cfd550e5..ae1d34308a38edc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanFragment.java @@ -484,11 +484,7 @@ public boolean isTransferQueryStatisticsWithEveryBatch() { } public int getFragmentSequenceNum() { - if (ConnectContext.get().getSessionVariable().isEnableNereidsPlanner()) { - return fragmentSequenceNum; - } else { - return fragmentId.asInt(); - } + return fragmentSequenceNum; } public void setFragmentSequenceNum(int seq) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/plsql/executor/PlsqlQueryExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/plsql/executor/PlsqlQueryExecutor.java index f9c7ca767fc13ae..37a8cf310a1d959 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/plsql/executor/PlsqlQueryExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/plsql/executor/PlsqlQueryExecutor.java @@ -20,7 +20,6 @@ import org.apache.doris.catalog.MysqlColType; import org.apache.doris.catalog.PrimitiveType; import org.apache.doris.catalog.Type; -import org.apache.doris.mysql.MysqlCommand; import org.apache.doris.plsql.exception.QueryException; import org.apache.doris.qe.AutoCloseConnectContext; import org.apache.doris.qe.ConnectContext; @@ -47,7 +46,7 @@ public QueryResult executeQuery(String sql, ParserRuleContext ctx) { autoCloseCtx.call(); context.setRunProcedure(true); ConnectProcessor processor = new MysqlConnectProcessor(context); - processor.executeQuery(MysqlCommand.COM_QUERY, sql); + processor.executeQuery(sql); StmtExecutor executor = context.getExecutor(); if (executor.getParsedStmt().getResultExprs() != null) { return new QueryResult(new DorisRowResult(executor.getCoord(), executor.getColumns(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java index 8289b27f0690c1b..6308dfd23588f14 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java @@ -48,7 +48,6 @@ import org.apache.doris.datasource.CatalogIf; import org.apache.doris.metric.MetricRepo; import org.apache.doris.mysql.MysqlChannel; -import org.apache.doris.mysql.MysqlCommand; import org.apache.doris.mysql.MysqlPacket; import org.apache.doris.mysql.MysqlSerializer; import org.apache.doris.mysql.MysqlServerStatusFlag; @@ -56,7 +55,6 @@ import org.apache.doris.nereids.SqlCacheContext.CacheKeyType; import org.apache.doris.nereids.StatementContext; import org.apache.doris.nereids.exceptions.NotSupportedException; -import org.apache.doris.nereids.exceptions.ParseException; import org.apache.doris.nereids.glue.LogicalPlanAdapter; import org.apache.doris.nereids.minidump.MinidumpUtils; import org.apache.doris.nereids.parser.Dialect; @@ -218,7 +216,7 @@ protected void auditAfterExec(String origStmt, StatementBase parsedStmt, } // only throw an exception when there is a problem interacting with the requesting client - protected void handleQuery(MysqlCommand mysqlCommand, String originStmt) throws ConnectionException { + protected void handleQuery(String originStmt) throws ConnectionException { if (Config.isCloudMode()) { if (!ctx.getCurrentUserIdentity().isRootUser() && ((CloudSystemInfoService) Env.getCurrentSystemInfo()).getInstanceStatus() @@ -233,7 +231,7 @@ protected void handleQuery(MysqlCommand mysqlCommand, String originStmt) throws } } try { - executeQuery(mysqlCommand, originStmt); + executeQuery(originStmt); } catch (ConnectionException exception) { throw exception; } catch (Exception ignored) { @@ -241,7 +239,7 @@ protected void handleQuery(MysqlCommand mysqlCommand, String originStmt) throws } } - public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Exception { + public void executeQuery(String originStmt) throws Exception { if (MetricRepo.isInit) { MetricRepo.COUNTER_REQUEST_ALL.increase(1L); MetricRepo.increaseClusterRequestAll(ctx.getCloudCluster(false)); @@ -252,89 +250,37 @@ public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Ex ctx.setSqlHash(sqlHash); SessionVariable sessionVariable = ctx.getSessionVariable(); - boolean wantToParseSqlFromSqlCache = sessionVariable.isEnableNereidsPlanner() - && CacheAnalyzer.canUseSqlCache(sessionVariable); + boolean wantToParseSqlFromSqlCache = CacheAnalyzer.canUseSqlCache(sessionVariable); List stmts = null; - Exception nereidsParseException = null; - Exception nereidsSyntaxException = null; long parseSqlStartTime = System.currentTimeMillis(); List cachedStmts = null; CacheKeyType cacheKeyType = null; - if (sessionVariable.isEnableNereidsPlanner()) { - if (wantToParseSqlFromSqlCache) { - cachedStmts = parseFromSqlCache(originStmt); - Optional sqlCacheContext = ConnectContext.get() - .getStatementContext().getSqlCacheContext(); - if (sqlCacheContext.isPresent()) { - cacheKeyType = sqlCacheContext.get().getCacheKeyType(); - } - if (cachedStmts != null) { - stmts = cachedStmts; - } - } - - if (cachedStmts == null) { - try { - stmts = new NereidsParser().parseSQL(convertedStmt, sessionVariable); - } catch (NotSupportedException e) { - // Parse sql failed, audit it and return - handleQueryException(e, convertedStmt, null, null); - return; - } catch (ParseException e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Nereids parse sql failed. Reason: {}. Statement: \"{}\".", - e.getMessage(), convertedStmt); - } - // ATTN: Do not set nereidsParseException in this case. - // Because ParseException means the sql is not supported by Nereids. - // It should be parsed by old parser, so not setting nereidsParseException to avoid - // suppressing the exception thrown by old parser. - nereidsParseException = e; - } catch (Exception e) { - // TODO: We should catch all exception here until we support all query syntax. - if (LOG.isDebugEnabled()) { - LOG.debug("Nereids parse sql failed with other exception. Reason: {}. Statement: \"{}\".", - e.getMessage(), convertedStmt); - } - nereidsSyntaxException = e; - } + if (wantToParseSqlFromSqlCache) { + cachedStmts = parseFromSqlCache(originStmt); + Optional sqlCacheContext = ConnectContext.get() + .getStatementContext().getSqlCacheContext(); + if (sqlCacheContext.isPresent()) { + cacheKeyType = sqlCacheContext.get().getCacheKeyType(); } - - if (stmts == null) { - String errMsg; - Throwable exception = null; - if (nereidsParseException != null) { - errMsg = nereidsParseException.getMessage(); - exception = nereidsParseException; - } else if (nereidsSyntaxException != null) { - errMsg = nereidsSyntaxException.getMessage(); - exception = nereidsSyntaxException; - } else { - errMsg = "Nereids parse statements failed. " + originStmt; - } - if (exception == null) { - exception = new AnalysisException(errMsg); - } else { - exception = new AnalysisException(errMsg, exception); - } - handleQueryException(exception, originStmt, null, null); - return; + if (cachedStmts != null) { + stmts = cachedStmts; } } - // stmts == null when Nereids cannot planner this query or Nereids is disabled. if (stmts == null) { - if (mysqlCommand == MysqlCommand.COM_STMT_PREPARE) { - // avoid fall back to legacy planner - ctx.getState().setError(ErrorCode.ERR_UNSUPPORTED_PS, "Not supported such prepared statement"); - ctx.getState().setErrType(QueryState.ErrType.OTHER_ERR); - return; - } try { - stmts = parse(convertedStmt); - } catch (Throwable throwable) { + stmts = new NereidsParser().parseSQL(convertedStmt, sessionVariable); + } catch (NotSupportedException e) { // Parse sql failed, audit it and return - handleQueryException(throwable, convertedStmt, null, null); + handleQueryException(e, convertedStmt, null, null); + return; + } catch (Exception e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Nereids parse sql failed. Reason: {}. Statement: \"{}\".", + e.getMessage(), convertedStmt, e); + } + Throwable exception = new AnalysisException(e.getMessage(), e); + handleQueryException(exception, originStmt, null, null); return; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java b/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java index 5e3a59d9a54d96c..e0ec272cf4cb963 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java @@ -2591,13 +2591,6 @@ public BucketShuffleJoinController(Map> fragmentIdT // check whether the node fragment is bucket shuffle join fragment protected boolean isBucketShuffleJoin(int fragmentId, PlanNode node) { - if (ConnectContext.get() != null) { - if (!ConnectContext.get().getSessionVariable().isEnableBucketShuffleJoin() - && !ConnectContext.get().getSessionVariable().isEnableNereidsPlanner()) { - return false; - } - } - // check the node is be the part of the fragment if (fragmentId != node.getFragmentId().asInt()) { return false; diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java index 0f3de945f8508bf..db0eb8480790de7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/MysqlConnectProcessor.java @@ -182,7 +182,7 @@ private void handleExecute() { } // Process COM_QUERY statement, - private void handleQuery(MysqlCommand mysqlCommand) throws ConnectionException { + private void handleQuery() throws ConnectionException { // convert statement to Java string byte[] bytes = packetBuf.array(); int ending = packetBuf.limit() - 1; @@ -191,7 +191,7 @@ private void handleQuery(MysqlCommand mysqlCommand) throws ConnectionException { } String originStmt = new String(bytes, 1, ending, StandardCharsets.UTF_8); - handleQuery(mysqlCommand, originStmt); + handleQuery(originStmt); } private void dispatch() throws IOException { @@ -200,7 +200,7 @@ private void dispatch() throws IOException { if (command == null) { ErrorReport.report(ErrorCode.ERR_UNKNOWN_COM_ERROR); ctx.getState().setError(ErrorCode.ERR_UNKNOWN_COM_ERROR, "Unknown command(" + code + ")"); - LOG.warn("Unknown command(" + code + ")"); + LOG.warn("Unknown command({})", code); return; } if (LOG.isDebugEnabled()) { @@ -219,7 +219,7 @@ private void dispatch() throws IOException { break; case COM_QUERY: case COM_STMT_PREPARE: - handleQuery(command); + handleQuery(); break; case COM_STMT_EXECUTE: handleExecute(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index 1af6239bf4c19c0..549e02b83f92448 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java @@ -1305,8 +1305,7 @@ public void setEnableLeftZigZag(boolean enableLeftZigZag) { * the new optimizer is fully developed. I hope that day * would be coming soon. */ - @VariableMgr.VarAttr(name = ENABLE_NEREIDS_PLANNER, needForward = true, - fuzzy = true, varType = VariableAnnotation.EXPERIMENTAL_ONLINE) + @VariableMgr.VarAttr(name = ENABLE_NEREIDS_PLANNER, needForward = true, varType = VariableAnnotation.REMOVED) private boolean enableNereidsPlanner = true; @VariableMgr.VarAttr(name = DISABLE_NEREIDS_RULES, needForward = true) @@ -2244,8 +2243,6 @@ public void initFuzzyModeVariables() { */ // pull_request_id default value is 0. When it is 0, use default (global) session variable. if (Config.pull_request_id > 0) { - this.enableNereidsPlanner = true; - switch (Config.pull_request_id % 4) { case 0: this.runtimeFilterType |= TRuntimeFilterType.BITMAP.getValue(); @@ -3318,19 +3315,6 @@ public boolean isEnablePushDownStringMinMax() { return enablePushDownStringMinMax; } - /** - * Nereids only support vectorized engine. - * - * @return true if both nereids and vectorized engine are enabled - */ - public boolean isEnableNereidsPlanner() { - return enableNereidsPlanner; - } - - public void setEnableNereidsPlanner(boolean enableNereidsPlanner) { - this.enableNereidsPlanner = enableNereidsPlanner; - } - /** canUseNereidsDistributePlanner */ public static boolean canUseNereidsDistributePlanner() { // TODO: support cloud mode @@ -3426,7 +3410,7 @@ public void setNereidsCboPenaltyFactor(double penaltyFactor) { } public boolean isEnableNereidsTrace() { - return isEnableNereidsPlanner() && enableNereidsTrace; + return enableNereidsTrace; } public void setEnableExprTrace(boolean enableExprTrace) { @@ -3662,7 +3646,7 @@ public TQueryOptions toThrift() { } tResult.setCodegenLevel(codegenLevel); tResult.setBeExecVersion(Config.be_exec_version); - tResult.setEnableLocalShuffle(enableLocalShuffle && enableNereidsPlanner); + tResult.setEnableLocalShuffle(enableLocalShuffle); tResult.setParallelInstance(getParallelExecInstanceNum()); tResult.setReturnObjectDataAsBinary(returnObjectDataAsBinary); tResult.setTrimTailingSpacesForExternalTableQuery(trimTailingSpacesForExternalTableQuery); @@ -4071,18 +4055,7 @@ public void disableConstantFoldingByBEOnce() throws DdlException { new SetVar(SessionVariable.ENABLE_FOLD_CONSTANT_BY_BE, new StringLiteral("false"))); } - public void disableNereidsPlannerOnce() throws DdlException { - if (!enableNereidsPlanner) { - return; - } - setIsSingleSetVar(true); - VariableMgr.setVar(this, new SetVar(SessionVariable.ENABLE_NEREIDS_PLANNER, new StringLiteral("false"))); - } - public void disableNereidsJoinReorderOnce() throws DdlException { - if (!enableNereidsPlanner) { - return; - } setIsSingleSetVar(true); VariableMgr.setVar(this, new SetVar(SessionVariable.DISABLE_JOIN_REORDER, new StringLiteral("true"))); } @@ -4314,7 +4287,7 @@ public int getCreateTablePartitionMaxNum() { } public boolean isIgnoreStorageDataDistribution() { - return ignoreStorageDataDistribution && enableLocalShuffle && enableNereidsPlanner; + return ignoreStorageDataDistribution && enableLocalShuffle; } public void setIgnoreStorageDataDistribution(boolean ignoreStorageDataDistribution) { @@ -4352,7 +4325,7 @@ public boolean isEnableCountPushDownForExternalTable() { } public boolean isForceToLocalShuffle() { - return enableLocalShuffle && enableNereidsPlanner && forceToLocalShuffle; + return enableLocalShuffle && forceToLocalShuffle; } public void setForceToLocalShuffle(boolean forceToLocalShuffle) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index c22478710173fd0..402bb2b9661b577 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -141,7 +141,6 @@ import org.apache.doris.nereids.NereidsPlanner; import org.apache.doris.nereids.PlanProcess; import org.apache.doris.nereids.StatementContext; -import org.apache.doris.nereids.exceptions.DoNotFallbackException; import org.apache.doris.nereids.exceptions.MustFallbackException; import org.apache.doris.nereids.exceptions.ParseException; import org.apache.doris.nereids.glue.LogicalPlanAdapter; @@ -154,7 +153,6 @@ import org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand; import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand; import org.apache.doris.nereids.trees.plans.commands.Forward; -import org.apache.doris.nereids.trees.plans.commands.NotAllowFallback; import org.apache.doris.nereids.trees.plans.commands.PrepareCommand; import org.apache.doris.nereids.trees.plans.commands.UnsupportedCommand; import org.apache.doris.nereids.trees.plans.commands.UpdateCommand; @@ -582,17 +580,6 @@ public void queryRetry(TUniqueId queryId) throws Exception { } } - public boolean notAllowFallback(NereidsException e) { - if (e.getException() instanceof DoNotFallbackException) { - return true; - } - if (parsedStmt instanceof LogicalPlanAdapter) { - LogicalPlan logicalPlan = ((LogicalPlanAdapter) parsedStmt).getLogicalPlan(); - return logicalPlan instanceof NotAllowFallback; - } - return false; - } - public void execute(TUniqueId queryId) throws Exception { SessionVariable sessionVariable = context.getSessionVariable(); if (context.getConnectType() == ConnectType.ARROW_FLIGHT_SQL) { @@ -600,43 +587,37 @@ public void execute(TUniqueId queryId) throws Exception { } try { - if (parsedStmt instanceof LogicalPlanAdapter - || (parsedStmt == null && sessionVariable.isEnableNereidsPlanner())) { - try { - executeByNereids(queryId); - } catch (NereidsException | ParseException e) { - if (context.getMinidump() != null && context.getMinidump().toString(4) != null) { - MinidumpUtils.saveMinidumpString(context.getMinidump(), DebugUtil.printId(context.queryId())); - } - // try to fall back to legacy planner - if (LOG.isDebugEnabled()) { - LOG.debug("nereids cannot process statement\n{}\n because of {}", - originStmt.originStmt, e.getMessage(), e); - } - if (e instanceof NereidsException && notAllowFallback((NereidsException) e)) { - LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e); - throw new AnalysisException(e.getMessage()); - } - if (e instanceof NereidsException - && !(((NereidsException) e).getException() instanceof MustFallbackException)) { - LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e); - context.getState().setError(e.getMessage()); - return; - } - if (LOG.isDebugEnabled()) { - LOG.debug("fall back to legacy planner on statement:\n{}", originStmt.originStmt); - } - parsedStmt = null; - planner = null; - // Attention: currently exception from nereids does not mean an Exception to user terminal - // unless user does not allow fallback to lagency planner. But state of query - // has already been set to Error in this case, it will have some side effect on profile result - // and audit log. So we need to reset state to OK if query cancel be processd by lagency. - context.getState().reset(); - context.getState().setNereids(false); - executeByLegacy(queryId); + try { + executeByNereids(queryId); + } catch (NereidsException | ParseException e) { + if (context.getMinidump() != null && context.getMinidump().toString(4) != null) { + MinidumpUtils.saveMinidumpString(context.getMinidump(), DebugUtil.printId(context.queryId())); } - } else { + // try to fall back to legacy planner + if (LOG.isDebugEnabled()) { + LOG.debug("nereids cannot process statement\n{}\n because of {}", + originStmt.originStmt, e.getMessage(), e); + } + // only must fall back + unsupported command could use legacy planner + if ((e instanceof NereidsException + && !(((NereidsException) e).getException() instanceof MustFallbackException)) + || !((parsedStmt instanceof LogicalPlanAdapter + && ((LogicalPlanAdapter) parsedStmt).getLogicalPlan() instanceof Command))) { + LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e); + context.getState().setError(e.getMessage()); + return; + } + if (LOG.isDebugEnabled()) { + LOG.debug("fall back to legacy planner on statement:\n{}", originStmt.originStmt); + } + parsedStmt = null; + planner = null; + // Attention: currently exception from nereids does not mean an Exception to user terminal + // unless user does not allow fallback to lagency planner. But state of query + // has already been set to Error in this case, it will have some side effect on profile result + // and audit log. So we need to reset state to OK if query cancel be processd by lagency. + context.getState().reset(); + context.getState().setNereids(false); executeByLegacy(queryId); } } finally { @@ -753,7 +734,7 @@ private void executeByNereids(TUniqueId queryId) throws Exception { syncJournalIfNeeded(); try { ((Command) logicalPlan).run(context, this); - } catch (MustFallbackException | DoNotFallbackException e) { + } catch (MustFallbackException e) { if (LOG.isDebugEnabled()) { LOG.debug("Command({}) process failed.", originStmt.originStmt, e); } @@ -823,7 +804,7 @@ private void executeByNereids(TUniqueId queryId) throws Exception { try { planner.plan(parsedStmt, context.getSessionVariable().toThrift()); checkBlockRules(); - } catch (MustFallbackException | DoNotFallbackException e) { + } catch (MustFallbackException e) { LOG.warn("Nereids plan query failed:\n{}", originStmt.originStmt, e); throw new NereidsException("Command(" + originStmt.originStmt + ") process failed.", e); } catch (Exception e) { @@ -845,11 +826,16 @@ private void parseByNereids() { } catch (Exception e) { throw new ParseException("Nereids parse failed. " + e.getMessage()); } - if (statements.size() <= originStmt.idx) { - throw new ParseException("Nereids parse failed. Parser get " + statements.size() + " statements," - + " but we need at least " + originStmt.idx + " statements."); + if (statements.isEmpty()) { + // for test only + parsedStmt = new LogicalPlanAdapter(new UnsupportedCommand(), new StatementContext()); + } else { + if (statements.size() <= originStmt.idx) { + throw new ParseException("Nereids parse failed. Parser get " + statements.size() + " statements," + + " but we need at least " + originStmt.idx + " statements."); + } + parsedStmt = statements.get(originStmt.idx); } - parsedStmt = statements.get(originStmt.idx); } public void finalizeQuery() { @@ -3313,7 +3299,7 @@ public StatementBase setParsedStmt(StatementBase parsedStmt) { public List executeInternalQuery() { if (LOG.isDebugEnabled()) { - LOG.debug("INTERNAL QUERY: " + originStmt.toString()); + LOG.debug("INTERNAL QUERY: {}", originStmt.toString()); } UUID uuid = UUID.randomUUID(); TUniqueId queryId = new TUniqueId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()); @@ -3321,29 +3307,14 @@ public List executeInternalQuery() { try { List resultRows = new ArrayList<>(); try { - if (ConnectContext.get() != null - && ConnectContext.get().getSessionVariable().isEnableNereidsPlanner()) { - try { - parseByNereids(); - Preconditions.checkState(parsedStmt instanceof LogicalPlanAdapter, - "Nereids only process LogicalPlanAdapter," - + " but parsedStmt is " + parsedStmt.getClass().getName()); - context.getState().setNereids(true); - context.getState().setIsQuery(true); - planner = new NereidsPlanner(statementContext); - planner.plan(parsedStmt, context.getSessionVariable().toThrift()); - } catch (Exception e) { - LOG.warn("Fall back to legacy planner, because: {}", e.getMessage(), e); - parsedStmt = null; - planner = null; - context.getState().setNereids(false); - analyzer = new Analyzer(context.getEnv(), context); - analyze(context.getSessionVariable().toThrift()); - } - } else { - analyzer = new Analyzer(context.getEnv(), context); - analyze(context.getSessionVariable().toThrift()); - } + parseByNereids(); + Preconditions.checkState(parsedStmt instanceof LogicalPlanAdapter, + "Nereids only process LogicalPlanAdapter," + + " but parsedStmt is " + parsedStmt.getClass().getName()); + context.getState().setNereids(true); + context.getState().setIsQuery(true); + planner = new NereidsPlanner(statementContext); + planner.plan(parsedStmt, context.getSessionVariable().toThrift()); } catch (Exception e) { LOG.warn("Failed to run internal SQL: {}", originStmt, e); throw new RuntimeException("Failed to execute internal SQL. " + Util.getRootCauseMessage(e), e); @@ -3526,44 +3497,25 @@ public HttpStreamParams generateHttpStreamPlan(TUniqueId queryId) throws Excepti SessionVariable sessionVariable = context.getSessionVariable(); HttpStreamParams httpStreamParams = null; try { - if (sessionVariable.isEnableNereidsPlanner()) { - try { - // disable shuffle for http stream (only 1 sink) - sessionVariable.disableStrictConsistencyDmlOnce(); - httpStreamParams = generateHttpStreamNereidsPlan(queryId); - } catch (NereidsException | ParseException e) { - if (context.getMinidump() != null && context.getMinidump().toString(4) != null) { - MinidumpUtils.saveMinidumpString(context.getMinidump(), DebugUtil.printId(context.queryId())); - } - // try to fall back to legacy planner - if (LOG.isDebugEnabled()) { - LOG.debug("nereids cannot process statement\n{}\n because of {}", - originStmt.originStmt, e.getMessage(), e); - } - if (e instanceof NereidsException && notAllowFallback((NereidsException) e)) { - LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e); - throw ((NereidsException) e).getException(); - } - if (e instanceof NereidsException - && !(((NereidsException) e).getException() instanceof MustFallbackException)) { - LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e); - throw ((NereidsException) e).getException(); - } - if (LOG.isDebugEnabled()) { - LOG.debug("fall back to legacy planner on statement:\n{}", originStmt.originStmt); - } - // Attention: currently exception from nereids does not mean an Exception to user terminal - // unless user does not allow fallback to lagency planner. But state of query - // has already been set to Error in this case, it will have some side effect on profile result - // and audit log. So we need to reset state to OK if query cancel be processd by lagency. - context.getState().reset(); - context.getState().setNereids(false); - httpStreamParams = generateHttpStreamLegacyPlan(queryId); - } catch (Exception e) { - throw new RuntimeException(e); + try { + // disable shuffle for http stream (only 1 sink) + sessionVariable.disableStrictConsistencyDmlOnce(); + httpStreamParams = generateHttpStreamNereidsPlan(queryId); + } catch (NereidsException | ParseException e) { + if (context.getMinidump() != null && context.getMinidump().toString(4) != null) { + MinidumpUtils.saveMinidumpString(context.getMinidump(), DebugUtil.printId(context.queryId())); + } + // try to fall back to legacy planner + if (LOG.isDebugEnabled()) { + LOG.debug("nereids cannot process statement\n{}\n because of {}", + originStmt.originStmt, e.getMessage(), e); } - } else { - httpStreamParams = generateHttpStreamLegacyPlan(queryId); + if (e instanceof NereidsException) { + LOG.warn("Analyze failed. {}", context.getQueryIdentifier(), e); + throw ((NereidsException) e).getException(); + } + } catch (Exception e) { + throw new RuntimeException(e); } } finally { // revert Session Value diff --git a/fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/FlightSqlConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/FlightSqlConnectProcessor.java index f83c67d2daf17c4..fe0648a0680ca12 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/FlightSqlConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/service/arrowflight/FlightSqlConnectProcessor.java @@ -87,7 +87,7 @@ public void handleQuery(String query) throws ConnectionException { prepare(command); ctx.setRunningQuery(query); - handleQuery(command, query); + super.handleQuery(query); } // TODO diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java index 0dca003069e3bbe..1647feb0ff0f42f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java @@ -162,7 +162,6 @@ public static QueryState execUpdate(String sql) throws Exception { StmtExecutor stmtExecutor = null; AutoCloseConnectContext r = StatisticsUtil.buildConnectContext(); try { - r.connectContext.getSessionVariable().disableNereidsPlannerOnce(); stmtExecutor = new StmtExecutor(r.connectContext, sql); r.connectContext.setExecutor(stmtExecutor); stmtExecutor.execute(); @@ -215,7 +214,6 @@ public static AutoCloseConnectContext buildConnectContext(boolean limitScan, boo sessionVariable.enableProfile = Config.enable_profile_when_analyze; sessionVariable.parallelExecInstanceNum = Config.statistics_sql_parallel_exec_instance_num; sessionVariable.parallelPipelineTaskNum = Config.statistics_sql_parallel_exec_instance_num; - sessionVariable.setEnableNereidsPlanner(true); sessionVariable.enableScanRunSerial = limitScan; sessionVariable.setQueryTimeoutS(StatisticsUtil.getAnalyzeTimeout()); sessionVariable.insertTimeoutS = StatisticsUtil.getAnalyzeTimeout(); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/InsertArrayStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/InsertArrayStmtTest.java index 0d8759aa08e237b..0d6e09c5051d89b 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/InsertArrayStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/InsertArrayStmtTest.java @@ -23,7 +23,11 @@ import org.apache.doris.common.AnalysisException; import org.apache.doris.common.ExceptionChecker; import org.apache.doris.common.util.SqlParserUtils; +import org.apache.doris.nereids.StatementContext; +import org.apache.doris.nereids.glue.LogicalPlanAdapter; +import org.apache.doris.nereids.trees.plans.commands.UnsupportedCommand; import org.apache.doris.qe.ConnectContext; +import org.apache.doris.qe.OriginStatement; import org.apache.doris.qe.QueryState; import org.apache.doris.qe.QueryState.MysqlStateType; import org.apache.doris.qe.StmtExecutor; @@ -131,19 +135,18 @@ public void testTransactionalInsert() throws Exception { + "\"disable_auto_compaction\" = \"false\"\n" + ");")); - SqlParser parser = new SqlParser(new SqlScanner( - new StringReader("begin"), connectContext.getSessionVariable().getSqlMode() - )); - TransactionBeginStmt beginStmt = (TransactionBeginStmt) SqlParserUtils.getFirstStmt(parser); - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, beginStmt); + OriginStatement originStatement = new OriginStatement("begin", 0); + StatementBase begin = new LogicalPlanAdapter(new UnsupportedCommand(), + new StatementContext(connectContext, originStatement)); + begin.setOrigStmt(originStatement); + StmtExecutor stmtExecutor = new StmtExecutor(connectContext, begin); stmtExecutor.execute(); - parser = new SqlParser(new SqlScanner( - new StringReader("insert into test.txn_insert_tbl values(2, 3.3, \"xyz\", [1], [1, 0]);"), - connectContext.getSessionVariable().getSqlMode() - )); - InsertStmt insertStmt = (InsertStmt) SqlParserUtils.getFirstStmt(parser); - stmtExecutor = new StmtExecutor(connectContext, insertStmt); + originStatement = new OriginStatement("insert into test.txn_insert_tbl values(2, 3.3, \"xyz\", [1], [1, 0]);", 0); + StatementBase insert = new LogicalPlanAdapter(new UnsupportedCommand(), + new StatementContext(connectContext, originStatement)); + insert.setOrigStmt(originStatement); + stmtExecutor = new StmtExecutor(connectContext, insert); stmtExecutor.execute(); QueryState state = connectContext.getState(); Assert.assertEquals(state.getErrorMessage(), MysqlStateType.OK, state.getStateType()); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java index 7bce2526df00c36..d30658ff6d48b26 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/RangePartitionPruneTest.java @@ -124,87 +124,87 @@ protected void runBeforeAll() throws Exception { private void initTestCases() { // 1. Single partition column // no filters - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1", "partitions=8/8"); + addCase("select * from test.t1", "partitions=8/8"); // equal to - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt=20211122", "partitions=1/8"); + addCase("select * from test.t1 where dt=20211122", "partitions=1/8"); // less than - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt<20211122", "partitions=2/8"); + addCase("select * from test.t1 where dt<20211122", "partitions=2/8"); // less than or equal - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt<=20211122", "partitions=3/8"); + addCase("select * from test.t1 where dt<=20211122", "partitions=3/8"); // greater than - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt>20211122", "partitions=6/8"); + addCase("select * from test.t1 where dt>20211122", "partitions=5/8"); // greater than or equal - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt>=20211122", "partitions=6/8"); + addCase("select * from test.t1 where dt>=20211122", "partitions=6/8"); // in - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt in (20211124, 20211126, 20211122)", "partitions=3/8"); + addCase("select * from test.t1 where dt in (20211124, 20211126, 20211122)", "partitions=3/8"); // is null - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt is null", "partitions=1/8"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.`single_not_null` where dt is null", "partitions=0/7"); + addCase("select * from test.t1 where dt is null", "partitions=1/8"); + addCase("select * from test.`single_not_null` where dt is null", "VEMPTYSET"); // not equal to - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt!=20211122", "partitions=8/8"); + addCase("select * from test.t1 where dt!=20211122", "partitions=7/8"); // 2. Multiple partition columns // no filters - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2", "partitions=9/9"); + addCase("select * from test.t2", "partitions=9/9"); // equal to - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1=7", "partitions=2/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k2=7", "partitions=9/9"); + addCase("select * from test.t2 where k1=7", "partitions=2/9"); + addCase("select * from test.t2 where k2=7", "partitions=7/9"); // less than - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1<7", "partitions=2/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k2<7", "partitions=9/9"); + addCase("select * from test.t2 where k1<7", "partitions=2/9"); + addCase("select * from test.t2 where k2<7", "partitions=9/9"); // less than or equal - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1<=7", "partitions=3/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k2>7", "partitions=9/9"); + addCase("select * from test.t2 where k1<=7", "partitions=3/9"); + addCase("select * from test.t2 where k2>7", "partitions=8/9"); // greater than or equal - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1>=7", "partitions=8/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k2>=7", "partitions=9/9"); + addCase("select * from test.t2 where k1>=7", "partitions=8/9"); + addCase("select * from test.t2 where k2>=7", "partitions=8/9"); // in - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 in (7,9,16)", "partitions=3/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k2 in (7,9,16)", "partitions=9/9"); + addCase("select * from test.t2 where k1 in (7,9,16)", "partitions=3/9"); + addCase("select * from test.t2 where k2 in (7,9,16)", "partitions=8/9"); // is null - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 is null", "partitions=1/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k2 is null", "partitions=9/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.multi_not_null where k1 is null", "partitions=0/2"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.multi_not_null where k2 is null", "partitions=2/2"); + addCase("select * from test.t2 where k1 is null", "partitions=1/9"); + addCase("select * from test.t2 where k2 is null", "partitions=7/9"); + addCase("select * from test.multi_not_null where k1 is null", "VEMPTYSET"); + addCase("select * from test.multi_not_null where k2 is null", "EMPTYSET"); // not equal to - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1!=23", "partitions=9/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k2!=23", "partitions=9/9"); + addCase("select * from test.t2 where k1!=23", "partitions=7/9"); + addCase("select * from test.t2 where k2!=23", "partitions=9/9"); // 3. Conjunctive predicates // equal to and other predicates - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1=23 and k2=5", "partitions=1/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1=23 and k2>5", "partitions=1/9"); + addCase("select * from test.t2 where k1=23 and k2=5", "partitions=1/9"); + addCase("select * from test.t2 where k1=23 and k2>5", "partitions=1/9"); // in and other equal predicates - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 in (3, 10, 13) and k2>10", "partitions=2/9"); + addCase("select * from test.t2 where k1 in (3, 10, 13) and k2>10", "partitions=2/9"); // is null and other predicates - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 > 10 and k1 is null", "partitions=0/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 is null and k1 > 10", "partitions=0/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.multi_not_null where k1 > 10 and k1 is null", "partitions=0/2"); + addCase("select * from test.t2 where k1 > 10 and k1 is null", "VEMPTYSET"); + addCase("select * from test.t2 where k1 is null and k1 > 10", "VEMPTYSET"); + addCase("select * from test.multi_not_null where k1 > 10 and k1 is null", "VEMPTYSET"); // others predicates combination - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 > 10 and k2 < 4", "partitions=6/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 >10 and k1 < 10 and (k1=11 or k1=12)", "partitions=0/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 > 20 and k1 < 7 and k1 = 10", "partitions=0/9"); + addCase("select * from test.t2 where k1 > 10 and k2 < 4", "partitions=5/9"); + addCase("select * from test.t2 where k1 >10 and k1 < 10 and (k1=11 or k1=12)", "VEMPTYSET"); + addCase("select * from test.t2 where k1 > 20 and k1 < 7 and k1 = 10", "VEMPTYSET"); // 4. Disjunctive predicates - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1=10 or k1=23", "partitions=3/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where (k1=10 or k1=23) and (k2=4 or k2=5)", "partitions=1/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where (k1=10 or k1=23) and (k2=4 or k2=11)", "partitions=2/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where (k1=10 or k1=23) and (k2=3 or k2=4 or k2=11)", "partitions=3/9"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where dt=20211123 or dt=20211124", "partitions=2/8"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where ((dt=20211123 and k1=1) or (dt=20211125 and k1=3))", "partitions=2/8"); + addCase("select * from test.t2 where k1=10 or k1=23", "partitions=3/9"); + addCase("select * from test.t2 where (k1=10 or k1=23) and (k2=4 or k2=5)", "partitions=1/9"); + addCase("select * from test.t2 where (k1=10 or k1=23) and (k2=4 or k2=11)", "partitions=2/9"); + addCase("select * from test.t2 where (k1=10 or k1=23) and (k2=3 or k2=4 or k2=11)", "partitions=3/9"); + addCase("select * from test.t1 where dt=20211123 or dt=20211124", "partitions=2/8"); + addCase("select * from test.t1 where ((dt=20211123 and k1=1) or (dt=20211125 and k1=3))", "partitions=2/8"); // TODO: predicates are "PREDICATES: ((`dt` = 20211123 AND `k1` = 1) OR (`dt` = 20211125 AND `k1` = 3)), `k2` > ", // maybe something goes wrong with ExtractCommonFactorsRule. - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where ((dt=20211123 and k1=1) or (dt=20211125 and k1=3)) and k2>0", + addCase("select * from test.t1 where ((dt=20211123 and k1=1) or (dt=20211125 and k1=3)) and k2>0", "partitions=2/8"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t2 where k1 > 10 or k2 < 1", "partitions=9/9"); + addCase("select * from test.t2 where k1 > 10 or k2 < 1", "partitions=9/9"); // add some cases for CompoundPredicate - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where (dt >= 20211121 and dt <= 20211122) or (dt >= 20211123 and dt <= 20211125)", + addCase("select * from test.t1 where (dt >= 20211121 and dt <= 20211122) or (dt >= 20211123 and dt <= 20211125)", "partitions=5/8"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where (dt between 20211121 and 20211122) or (dt between 20211123 and 20211125)", + addCase("select * from test.t1 where (dt between 20211121 and 20211122) or (dt between 20211123 and 20211125)", "partitions=5/8"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.t1 where (dt between 20211121 and 20211122) or dt is null or (dt between 20211123 and 20211125)", + addCase("select * from test.t1 where (dt between 20211121 and 20211122) or dt is null or (dt between 20211123 and 20211125)", "partitions=6/8"); - addCase("select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test_to_date_trunc where event_day= \"2023-08-07 11:00:00\" ", + addCase("select * from test.test_to_date_trunc where event_day= \"2023-08-07 11:00:00\" ", "partitions=1/2"); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java deleted file mode 100755 index b4299f0f62f60cf..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java +++ /dev/null @@ -1,1087 +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.doris.analysis; - -import org.apache.doris.catalog.Database; -import org.apache.doris.catalog.Env; -import org.apache.doris.catalog.MaterializedIndex; -import org.apache.doris.catalog.MaterializedIndex.IndexExtState; -import org.apache.doris.catalog.OlapTable; -import org.apache.doris.catalog.Partition; -import org.apache.doris.catalog.Tablet; -import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.Config; -import org.apache.doris.common.FeConstants; -import org.apache.doris.common.util.Util; -import org.apache.doris.planner.OlapScanNode; -import org.apache.doris.planner.OriginalPlanner; -import org.apache.doris.qe.ConnectContext; -import org.apache.doris.qe.VariableMgr; -import org.apache.doris.utframe.DorisAssert; -import org.apache.doris.utframe.UtFrameUtils; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import mockit.Mock; -import mockit.MockUp; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.jupiter.api.Disabled; -import org.junit.rules.ExpectedException; - -import java.util.List; -import java.util.Set; -import java.util.UUID; - -public class SelectStmtTest { - private static final String runningDir = "fe/mocked/DemoTest/" + UUID.randomUUID() + "/"; - private static DorisAssert dorisAssert; - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @AfterClass - public static void tearDown() throws Exception { - UtFrameUtils.cleanDorisFeDir(runningDir); - } - - @BeforeClass - public static void setUp() throws Exception { - Config.enable_http_server_v2 = false; - UtFrameUtils.createDorisCluster(runningDir); - String createTblStmtStr = "create table db1.tbl1(k1 varchar(32)," - + " k2 varchar(32), k3 varchar(32), k4 int, k5 largeint) " - + "AGGREGATE KEY(k1, k2,k3,k4,k5) distributed by hash(k1) buckets 3" - + " properties('replication_num' = '1');"; - String createBaseAllStmtStr = "create table db1.baseall(k1 int, k2 varchar(32)) distributed by hash(k1) " - + "buckets 3 properties('replication_num' = '1');"; - String createPratitionTableStr = "CREATE TABLE db1.partition_table (\n" - + "datekey int(11) NULL COMMENT \"datekey\",\n" - + "poi_id bigint(20) NULL COMMENT \"poi_id\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(datekey, poi_id)\n" - + "COMMENT \"OLAP\"\n" - + "PARTITION BY RANGE(datekey)\n" - + "(PARTITION p20200727 VALUES [(\"20200726\"), (\"20200727\")),\n" - + "PARTITION p20200728 VALUES [(\"20200727\"), (\"20200728\")))\n" - + "DISTRIBUTED BY HASH(poi_id) BUCKETS 2\n" - + "PROPERTIES (\n" - + "\"storage_type\" = \"COLUMN\",\n" - + "\"replication_num\" = \"1\"\n" - + ");"; - String createDatePartitionTableStr = "CREATE TABLE db1.date_partition_table (\n" - + " `dt` date NOT NULL COMMENT \"\",\n" - + " `poi_id` bigint(20) NULL COMMENT \"poi_id\",\n" - + " `uv1` bitmap BITMAP_UNION NOT NULL COMMENT \"\",\n" - + " `uv2` bitmap BITMAP_UNION NOT NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "PARTITION BY RANGE(`dt`)\n" - + "( PARTITION `p201701` VALUES LESS THAN (\"2020-09-08\"),\n" - + " PARTITION `p201702` VALUES LESS THAN (\"2020-09-09\"),\n" - + " PARTITION `p201703` VALUES LESS THAN (\"2020-09-10\"))\n" - + "DISTRIBUTED BY HASH(`poi_id`) BUCKETS 20\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"DEFAULT\"\n" - + ");"; - String tbl1 = "CREATE TABLE db1.table1 (\n" - + " `siteid` int(11) NULL DEFAULT \"10\" COMMENT \"\",\n" - + " `citycode` smallint(6) NULL COMMENT \"\",\n" - + " `username` varchar(32) NULL DEFAULT \"\" COMMENT \"\",\n" - + " `pv` bigint(20) NULL DEFAULT \"0\" COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "UNIQUE KEY(`siteid`, `citycode`, `username`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`siteid`) BUCKETS 10\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ")"; - String tbl2 = "CREATE TABLE db1.table2 (\n" - + " `siteid` int(11) NULL DEFAULT \"10\" COMMENT \"\",\n" - + " `citycode` smallint(6) NULL COMMENT \"\",\n" - + " `username` varchar(32) NOT NULL DEFAULT \"\" COMMENT \"\",\n" - + " `pv` bigint(20) NULL DEFAULT \"0\" COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "UNIQUE KEY(`siteid`, `citycode`, `username`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`siteid`) BUCKETS 10\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ")"; - String tbl3 = "CREATE TABLE db1.table3 (\n" - + " `siteid` int(11) NULL DEFAULT \"10\" COMMENT \"\",\n" - + " `citycode` smallint(6) NULL COMMENT \"\",\n" - + " `username` varchar(32) NULL DEFAULT \"\" COMMENT \"\",\n" - + " `pv` bigint(20) NULL DEFAULT \"0\" COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`siteid`, `citycode`, `username`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY RANDOM BUCKETS 10\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ")"; - dorisAssert = new DorisAssert(); - dorisAssert.withDatabase("db1").useDatabase("db1"); - dorisAssert.withTable(createTblStmtStr) - .withTable(createBaseAllStmtStr) - .withTable(createPratitionTableStr) - .withTable(createDatePartitionTableStr) - .withTable(tbl1) - .withTable(tbl2) - .withTable(tbl3); - } - - @Test - public void testGroupingSets() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - String selectStmtStr = "select k1,k2,MAX(k4) from db1.tbl1 GROUP BY GROUPING sets ((k1,k2),(k1),(k2),());"; - UtFrameUtils.parseAndAnalyzeStmt(selectStmtStr, ctx); - String selectStmtStr2 = "select k1,k4,MAX(k4) from db1.tbl1 GROUP BY GROUPING sets ((k1,k4),(k1),(k4),());"; - expectedEx.expect(AnalysisException.class); - expectedEx.expectMessage("column: `k4` cannot both in select list and aggregate functions when using GROUPING" - + " SETS/CUBE/ROLLUP, please use union instead."); - UtFrameUtils.parseAndAnalyzeStmt(selectStmtStr2, ctx); - String selectStmtStr3 = "select k1,k4,MAX(k4+k4) from db1.tbl1 GROUP BY GROUPING sets ((k1,k4),(k1),(k4),());"; - UtFrameUtils.parseAndAnalyzeStmt(selectStmtStr3, ctx); - String selectStmtStr4 = "select k1,k4+k4,MAX(k4+k4) from db1.tbl1 GROUP BY GROUPING sets ((k1,k4),(k1),(k4),()" - + ");"; - UtFrameUtils.parseAndAnalyzeStmt(selectStmtStr4, ctx); - } - - @Disabled - public void testSubqueryInCase() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - String sql1 = "SELECT CASE\n" - + " WHEN (\n" - + " SELECT COUNT(*) / 2\n" - + " FROM db1.tbl1\n" - + " ) > k4 THEN (\n" - + " SELECT AVG(k4)\n" - + " FROM db1.tbl1\n" - + " )\n" - + " ELSE (\n" - + " SELECT SUM(k4)\n" - + " FROM db1.tbl1\n" - + " )\n" - + " END AS kk4\n" - + "FROM db1.tbl1;"; - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql1, ctx); - stmt.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt.toSql().contains("`$a$1`.`$c$1` > `k4` THEN `$a$2`.`$c$2` ELSE `$a$3`.`$c$3`")); - - String sql2 = "select case when k1 in (select k1 from db1.tbl1) then \"true\" else k1 end a from db1.tbl1"; - try { - SelectStmt stmt2 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql2, ctx); - stmt2.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.fail("syntax not supported."); - } catch (AnalysisException e) { - // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.fail("must be AnalysisException."); - } - try { - String sql3 = "select case k1 when exists (select 1) then \"empty\" else \"p_test\" end a from db1.tbl1"; - SelectStmt stmt3 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql3, ctx); - stmt3.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.fail("syntax not supported."); - } catch (AnalysisException e) { - // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.fail("must be AnalysisException."); - } - String sql4 = "select case when k1 < (select max(k1) from db1.tbl1) and " - + "k1 > (select min(k1) from db1.tbl1) then \"empty\" else \"p_test\" end a from db1.tbl1"; - SelectStmt stmt4 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql4, ctx); - stmt4.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt4.toSql().contains("`k1` < `$a$1`.`$c$1` AND `k1` > `$a$2`.`$c$2`")); - - String sql5 = "select case when k1 < (select max(k1) from db1.tbl1) is null " - + "then \"empty\" else \"p_test\" end a from db1.tbl1"; - SelectStmt stmt5 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql5, ctx); - stmt5.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt5.toSql().contains(" `k1` < `$a$1`.`$c$1` IS NULL ")); - } - - @Test - public void testDeduplicateOrs() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - String sql = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2,\n" - + " db1.tbl1 t3,\n" - + " db1.tbl1 t4,\n" - + " db1.tbl1 t5,\n" - + " db1.tbl1 t6\n" - + "where\n" - + " t2.k1 = t1.k1\n" - + " and t1.k2 = t6.k2\n" - + " and t6.k4 = 2001\n" - + " and(\n" - + " (\n" - + " t1.k2 = t4.k2\n" - + " and t3.k3 = t1.k3\n" - + " and t3.k1 = 'D'\n" - + " and t4.k3 = '2 yr Degree'\n" - + " and t1.k4 between 100.00\n" - + " and 150.00\n" - + " and t4.k4 = 3\n" - + " )\n" - + " or (\n" - + " t1.k2 = t4.k2\n" - + " and t3.k3 = t1.k3\n" - + " and t3.k1 = 'S'\n" - + " and t4.k3 = 'Secondary'\n" - + " and t1.k4 between 50.00\n" - + " and 100.00\n" - + " and t4.k4 = 1\n" - + " )\n" - + " or (\n" - + " t1.k2 = t4.k2\n" - + " and t3.k3 = t1.k3\n" - + " and t3.k1 = 'W'\n" - + " and t4.k3 = 'Advanced Degree'\n" - + " and t1.k4 between 150.00\n" - + " and 200.00\n" - + " and t4.k4 = 1\n" - + " )\n" - + " )\n" - + " and(\n" - + " (\n" - + " t1.k1 = t5.k1\n" - + " and t5.k2 = 'United States'\n" - + " and t5.k3 in ('CO', 'IL', 'MN')\n" - + " and t1.k4 between 100\n" - + " and 200\n" - + " )\n" - + " or (\n" - + " t1.k1 = t5.k1\n" - + " and t5.k2 = 'United States'\n" - + " and t5.k3 in ('OH', 'MT', 'NM')\n" - + " and t1.k4 between 150\n" - + " and 300\n" - + " )\n" - + " or (\n" - + " t1.k1 = t5.k1\n" - + " and t5.k2 = 'United States'\n" - + " and t5.k3 in ('TX', 'MO', 'MI')\n" - + " and t1.k4 between 50 and 250\n" - + " )\n" - + " );"; - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - stmt.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - String commonExpr1 = "`t1`.`k2` = `t4`.`k2`"; - String commonExpr2 = "`t3`.`k3` = `t1`.`k3`"; - String commonExpr3 = "`t1`.`k1` = `t5`.`k1`"; - String commonExpr4 = "t5`.`k2` = 'United States'"; - String betweenExpanded1 = "(CAST(CAST(`t1`.`k4` AS decimalv3(12,2)) AS int) >= 100)) AND (CAST(CAST(`t1`.`k4` AS decimalv3(12,2)) AS int) <= 150))"; - String betweenExpanded2 = "(CAST(CAST(`t1`.`k4` AS decimalv3(12,2)) AS int) >= 50)) AND (CAST(CAST(`t1`.`k4` AS decimalv3(12,2)) AS int) <= 100))"; - String betweenExpanded3 = "(`t1`.`k4` >= 50)) AND (`t1`.`k4` <= 250)"; - - String rewrittenSql = stmt.toSql(); - Assert.assertTrue(rewrittenSql.contains(commonExpr1)); - Assert.assertEquals(rewrittenSql.indexOf(commonExpr1), rewrittenSql.lastIndexOf(commonExpr1)); - Assert.assertTrue(rewrittenSql.contains(commonExpr2)); - Assert.assertEquals(rewrittenSql.indexOf(commonExpr2), rewrittenSql.lastIndexOf(commonExpr2)); - Assert.assertTrue(rewrittenSql.contains(commonExpr3)); - Assert.assertEquals(rewrittenSql.indexOf(commonExpr3), rewrittenSql.lastIndexOf(commonExpr3)); - Assert.assertTrue(rewrittenSql.contains(commonExpr4)); - Assert.assertEquals(rewrittenSql.indexOf(commonExpr4), rewrittenSql.lastIndexOf(commonExpr4)); - Assert.assertTrue(rewrittenSql.contains(betweenExpanded1)); - Assert.assertTrue(rewrittenSql.contains(betweenExpanded2)); - Assert.assertTrue(rewrittenSql.contains(betweenExpanded3)); - - String sql2 = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2\n" - + "where\n" - + "(\n" - + " t1.k1 = t2.k3\n" - + " and t2.k2 = 'United States'\n" - + " and t2.k3 in ('CO', 'IL', 'MN')\n" - + " and t1.k4 between 100\n" - + " and 200\n" - + ")\n" - + "or (\n" - + " t1.k1 = t2.k1\n" - + " and t2.k2 = 'United States1'\n" - + " and t2.k3 in ('OH', 'MT', 'NM')\n" - + " and t1.k4 between 150\n" - + " and 300\n" - + ")\n" - + "or (\n" - + " t1.k1 = t2.k1\n" - + " and t2.k2 = 'United States'\n" - + " and t2.k3 in ('TX', 'MO', 'MI')\n" - + " and t1.k4 between 50 and 250\n" - + ")"; - SelectStmt stmt2 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql2, ctx); - stmt2.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - String fragment3 = - "(((((`t1`.`k4` >= 50) AND (`t1`.`k4` <= 300)) AND `t2`.`k2` IN ('United States', 'United States1')) " - + "AND `t2`.`k3` IN ('CO', 'IL', 'MN', 'OH', 'MT', 'NM', 'TX', 'MO', 'MI')) " - + "AND (((((((`t1`.`k1` = `t2`.`k3`) AND (`t2`.`k2` = 'United States')) " - + "AND `t2`.`k3` IN ('CO', 'IL', 'MN')) AND (`t1`.`k4` >= 100)) AND (`t1`.`k4` <= 200)) " - + "OR " - + "(((((`t1`.`k1` = `t2`.`k1`) AND (`t2`.`k2` = 'United States1')) " - + "AND `t2`.`k3` IN ('OH', 'MT', 'NM')) AND (`t1`.`k4` >= 150)) AND (`t1`.`k4` <= 300))) " - + "OR " - + "(((((`t1`.`k1` = `t2`.`k1`) AND (`t2`.`k2` = 'United States')) " - + "AND `t2`.`k3` IN ('TX', 'MO', 'MI')) " - + "AND (`t1`.`k4` >= 50)) AND (`t1`.`k4` <= 250))))"; - Assert.assertTrue(stmt2.toSql().contains(fragment3)); - - String sql3 = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2\n" - + "where\n" - + " t1.k1 = t2.k3 or t1.k1 = t2.k3 or t1.k1 = t2.k3"; - SelectStmt stmt3 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql3, ctx); - stmt3.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertFalse( - stmt3.toSql().contains("(`t1`.`k1` = `t2`.`k3`) OR (`t1`.`k1` = `t2`.`k3`) OR" + " (`t1`.`k1` = `t2`.`k3`)")); - - String sql4 = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2\n" - + "where\n" - + " t1.k1 = t2.k2 or t1.k1 = t2.k3 or t1.k1 = t2.k3"; - SelectStmt stmt4 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql4, ctx); - stmt4.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt4.toSql().contains("(`t1`.`k1` = `t2`.`k2`) OR (`t1`.`k1` = `t2`.`k3`)")); - - String sql5 = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2\n" - + "where\n" - + " t2.k1 is not null or t1.k1 is not null or t1.k1 is not null"; - SelectStmt stmt5 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql5, ctx); - stmt5.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt5.toSql().contains("`t2`.`k1` IS NOT NULL OR `t1`.`k1` IS NOT NULL")); - Assert.assertEquals(2, stmt5.toSql().split(" OR ").length); - - String sql6 = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2\n" - + "where\n" - + " t2.k1 is not null or t1.k1 is not null and t1.k1 is not null"; - SelectStmt stmt6 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql6, ctx); - stmt6.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt6.toSql().contains("`t2`.`k1` IS NOT NULL OR `t1`.`k1` IS NOT NULL")); - Assert.assertEquals(2, stmt6.toSql().split(" OR ").length); - - String sql7 = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2\n" - + "where\n" - + " t2.k1 is not null or t1.k1 is not null and t1.k2 is not null"; - SelectStmt stmt7 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql7, ctx); - stmt7.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt7.toSql() - .contains("`t2`.`k1` IS NOT NULL OR (`t1`.`k1` IS NOT NULL AND `t1`.`k2` IS NOT NULL)")); - - String sql8 = "select\n" - + " avg(t1.k4)\n" - + "from\n" - + " db1.tbl1 t1,\n" - + " db1.tbl1 t2\n" - + "where\n" - + " t2.k1 is not null and t1.k1 is not null and t1.k1 is not null"; - SelectStmt stmt8 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql8, ctx); - stmt8.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt8.toSql() - .contains("(`t2`.`k1` IS NOT NULL AND `t1`.`k1` IS NOT NULL) AND `t1`.`k1` IS NOT NULL")); - - String sql9 = "select * from db1.tbl1 where (k1='shutdown' and k4<1) or (k1='switchOff' and k4>=1)"; - SelectStmt stmt9 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql9, ctx); - stmt9.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue( - stmt9.toSql().contains("((`k1` = 'shutdown') AND (`k4` < 1)) OR ((`k1` = 'switchOff') AND (`k4` >= 1))")); - } - - @Test - public void testForbiddenCorrelatedSubqueryInHavingClause() throws Exception { - String sql = "SELECT k1 FROM baseall GROUP BY k1 HAVING EXISTS(SELECT k4 FROM tbl1 GROUP BY k4 HAVING SUM" - + "(baseall.k1) = k4);"; - try { - dorisAssert.query(sql).explainQuery(); - Assert.fail("The correlated subquery in having clause should be forbidden."); - } catch (AnalysisException e) { - System.out.println(e.getMessage()); - } - } - - @Test - public void testGroupByConstantExpression() throws Exception { - String sql = "SELECT k1 - 4*60*60 FROM baseall GROUP BY k1 - 4*60*60"; - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testMultrGroupByInCorrelationSubquery() throws Exception { - String sql = "SELECT * from baseall where k1 > (select min(k1) from tbl1 where baseall.k1 = tbl1.k4 and baseall.k2 = tbl1.k2)"; - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testOuterJoinNullUnionView() throws Exception { - String sql = "WITH test_view(k) AS(SELECT NULL AS k UNION ALL SELECT NULL AS k )\n" - + "SELECT v1.k FROM test_view AS v1 LEFT OUTER JOIN test_view AS v2 ON v1.k=v2.k"; - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testDataGripSupport() throws Exception { - String sql = "select schema();"; - dorisAssert.query(sql).explainQuery(); - sql = "select\n" - - + "collation_name,\n" - - + "character_set_name,\n" - - + "is_default collate utf8mb4_0900_bin = 'Yes' as is_default\n" - + "from information_schema.collations"; - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testRandFunction() throws Exception { - String sql = "select rand(db1.tbl1.k1) from db1.tbl1;"; - try { - dorisAssert.query(sql).explainQuery(); - Assert.fail("The param of rand function must be literal"); - } catch (AnalysisException e) { - System.out.println(e.getMessage()); - } - sql = "select rand(1234) from db1.tbl1;"; - dorisAssert.query(sql).explainQuery(); - sql = "select rand() from db1.tbl1;"; - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testImplicitConvertSupport() throws Exception { - String sql1 = "select /*+ SET_VAR(enable_nereids_planner=false) */ count(*) from db1.partition_table where datekey='20200730'"; - Assert.assertTrue(dorisAssert - .query(sql1) - .explainQuery() - .contains("`datekey` = 20200730")); - String sql2 = "select /*+ SET_VAR(enable_nereids_planner=false) */ count(*) from db1.partition_table where '20200730'=datekey"; - Assert.assertTrue(dorisAssert - .query(sql2) - .explainQuery() - .contains("`datekey` = 20200730")); - String sql3 = "select /*+ SET_VAR(enable_nereids_planner=false) */ count() from db1.date_partition_table where dt=20200908"; - Assert.assertTrue(dorisAssert - .query(sql3) - .explainQuery() - .contains(Config.enable_date_conversion ? "`dt` = '2020-09-08'" : "`dt` = '2020-09-08 00:00:00'")); - String sql4 = "select /*+ SET_VAR(enable_nereids_planner=false) */ count() from db1.date_partition_table where dt='2020-09-08'"; - Assert.assertTrue(dorisAssert - .query(sql4) - .explainQuery() - .contains(Config.enable_date_conversion ? "`dt` = '2020-09-08'" : "`dt` = '2020-09-08 00:00:00'")); - } - - @Test - public void testDeleteSign() throws Exception { - String sql1 = "SELECT /*+ SET_VAR(enable_nereids_planner=true, ENABLE_FALLBACK_TO_ORIGINAL_PLANNER=false, DISABLE_NEREIDS_RULES=PRUNE_EMPTY_PARTITION) */ * FROM db1.table1 LEFT ANTI JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; - String explain = dorisAssert.query(sql1).explainQuery(); - Assert.assertTrue(explain - .contains("__DORIS_DELETE_SIGN__ = 0")); - Assert.assertFalse(explain.contains("other predicates:")); - String sql2 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM db1.table1 JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; - explain = dorisAssert.query(sql2).explainQuery(); - Assert.assertTrue(explain - .contains("`db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0")); - Assert.assertTrue(explain - .contains("`db1`.`table2`.`__DORIS_DELETE_SIGN__` = 0")); - Assert.assertFalse(explain.contains("other predicates:")); - String sql3 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM db1.table1"; - Assert.assertTrue(dorisAssert.query(sql3).explainQuery() - .contains("`db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0")); - String sql4 = " SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM db1.table1 table2"; - Assert.assertTrue(dorisAssert.query(sql4).explainQuery() - .contains("`table2`.`__DORIS_DELETE_SIGN__` = 0")); - new MockUp() { - @Mock - public boolean showHiddenColumns() { - return true; - } - }; - String sql5 = "SELECT * FROM db1.table1 LEFT ANTI JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; - Assert.assertFalse(dorisAssert.query(sql5).explainQuery().contains("`table1`.`__DORIS_DELETE_SIGN__` = 0")); - String sql6 = "SELECT * FROM db1.table1 JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; - Assert.assertFalse(dorisAssert.query(sql6).explainQuery().contains("`table1`.`__DORIS_DELETE_SIGN__` = 0")); - String sql7 = "SELECT * FROM db1.table1"; - Assert.assertFalse(dorisAssert.query(sql7).explainQuery().contains("`table1`.`__DORIS_DELETE_SIGN__` = 0")); - String sql8 = " SELECT * FROM db1.table1 table2"; - Assert.assertFalse(dorisAssert.query(sql8).explainQuery().contains("`table2`.`__DORIS_DELETE_SIGN__` = 0")); - } - - @Test - public void testSelectHints() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - - // hint with integer literal parameter - String sql = "select /*+ common_hint(1) */ 1"; - UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - - // hint with float literal parameter - sql = "select /*+ common_hint(1.1) */ 1"; - UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - - // hint with string literal parameter - sql = "select /*+ common_hint(\"string\") */ 1"; - UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - - // hint with key value parameter - sql = "select /*+ common_hint(k = \"v\") */ 1"; - UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - - // hint with multi-parameters - sql = "select /*+ common_hint(1, 1.1, \"string\") */ 1"; - UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - - // multi-hints - sql = "select /*+ common_hint(1) another_hint(2) */ 1"; - UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - } - - @Test - public void testSelectHintSetVar() throws Exception { - String sql = "SELECT sleep(3);"; - OriginalPlanner planner = (OriginalPlanner) dorisAssert.query(sql).internalExecuteOneAndGetPlan(); - Assert.assertEquals(VariableMgr.getDefaultSessionVariable().getQueryTimeoutS(), - planner.getPlannerContext().getQueryOptions().query_timeout); - - sql = "SELECT /*+ SET_VAR(query_timeout = 1) */ sleep(3);"; - planner = (OriginalPlanner) dorisAssert.query(sql).internalExecuteOneAndGetPlan(); - Assert.assertEquals(1, planner.getPlannerContext().getQueryOptions().query_timeout); - - sql = "select * from db1.partition_table where datekey=20200726"; - planner = (OriginalPlanner) dorisAssert.query(sql).internalExecuteOneAndGetPlan(); - Assert.assertEquals(VariableMgr.getDefaultSessionVariable().getMaxExecMemByte(), - planner.getPlannerContext().getQueryOptions().mem_limit); - - sql = "select /*+ SET_VAR(exec_mem_limit = 8589934592) */ poi_id, count(*) from db1.partition_table " - + "where datekey=20200726 group by 1"; - planner = (OriginalPlanner) dorisAssert.query(sql).internalExecuteOneAndGetPlan(); - Assert.assertEquals(8589934592L, planner.getPlannerContext().getQueryOptions().mem_limit); - - int queryTimeOut = dorisAssert.getSessionVariable().getQueryTimeoutS(); - long execMemLimit = dorisAssert.getSessionVariable().getMaxExecMemByte(); - sql = "select /*+ SET_VAR(exec_mem_limit = 8589934592, query_timeout = 1) */ 1 + 2;"; - planner = (OriginalPlanner) dorisAssert.query(sql).internalExecuteOneAndGetPlan(); - // session variable have been changed - Assert.assertEquals(1, planner.getPlannerContext().getQueryOptions().query_timeout); - Assert.assertEquals(8589934592L, planner.getPlannerContext().getQueryOptions().mem_limit); - // session variable change have been reverted - Assert.assertEquals(queryTimeOut, dorisAssert.getSessionVariable().getQueryTimeoutS()); - Assert.assertEquals(execMemLimit, dorisAssert.getSessionVariable().getMaxExecMemByte()); - } - - @Test - public void testWithWithoutDatabase() throws Exception { - String sql = "with tmp as (select count(*) from db1.table1) select * from tmp;"; - dorisAssert.withoutUseDatabase(); - dorisAssert.query(sql).explainQuery(); - - sql = "with tmp as (select * from db1.table1) " - + "select a.siteid, b.citycode, a.siteid from (select siteid, citycode from tmp) a " - + "left join (select siteid, citycode from tmp) b on a.siteid = b.siteid;"; - dorisAssert.withoutUseDatabase(); - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testWithInNestedQueryStmt() throws Exception { - String sql = "select 1 from (with w as (select 1 from db1.table1) select 1 from w) as tt"; - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testGetTableRefs() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - String sql = "SELECT * FROM db1.table1 JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; - dorisAssert.query(sql).explainQuery(); - QueryStmt stmt = (QueryStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - List tblRefs = Lists.newArrayList(); - Set parentViewNameSet = Sets.newHashSet(); - stmt.getTableRefs(new Analyzer(ctx.getEnv(), ctx), tblRefs, parentViewNameSet); - - Assert.assertEquals(2, tblRefs.size()); - Assert.assertEquals("table1", tblRefs.get(0).getName().getTbl()); - Assert.assertEquals("table2", tblRefs.get(1).getName().getTbl()); - } - - @Test - public void testOutfile() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - Config.enable_outfile_to_local = true; - String sql - = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\" FORMAT AS PARQUET PROPERTIES (\"schema\"=\"required,byte_array,col0\");"; - dorisAssert.query(sql).explainQuery(); - // if shema not set, gen schema - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\" FORMAT AS PARQUET;"; - try { - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - Assert.assertEquals(1, stmt.getOutFileClause().getParquetSchemas().size()); - Assert.assertEquals("k1", stmt.getOutFileClause().getParquetSchemas().get(0).schema_column_name); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - - // schema can not be empty - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\" FORMAT AS PARQUET PROPERTIES (\"schema\"=\"\");"; - try { - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("Parquet schema property should not be empty")); - } - - // schema must contains 3 fields - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\" FORMAT AS PARQUET PROPERTIES (\"schema\"=\"int32,siteid;\");"; - try { - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("must only contains repetition type/column type/column name")); - } - - // unknown repetition type - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\" FORMAT AS PARQUET PROPERTIES (\"schema\"=\"repeat, int32,siteid;\");"; - try { - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("unknown repetition type")); - } - - // only support required type - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\" FORMAT AS PARQUET PROPERTIES (\"schema\"=\"repeated,int32,siteid;\");"; - try { - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("currently only support required type")); - } - - // unknown data type - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\" FORMAT AS PARQUET PROPERTIES (\"schema\"=\"required,int128,siteid;\");"; - try { - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("data type is not supported")); - } - - // contains parquet properties - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"file:///root/doris/\"" - + " FORMAT AS PARQUET" - + " PROPERTIES (\"schema\"=\"required,byte_array,siteid;\"," - + " 'parquet.compression'='snappy');"; - dorisAssert.query(sql).explainQuery(); - // support parquet for broker - sql = "SELECT k1 FROM db1.tbl1 INTO OUTFILE \"hdfs://test/test_sql_prc_2019_02_19/\" FORMAT AS PARQUET " - + "PROPERTIES ( \"broker.name\" = \"hdfs_broker\", " - + "\"broker.hadoop.security.authentication\" = \"kerberos\", " - + "\"broker.kerberos_principal\" = \"test\", " - + "\"broker.kerberos_keytab_content\" = \"test\" , " - + "\"schema\"=\"required,byte_array,siteid;\");"; - dorisAssert.query(sql).explainQuery(); - - // do not support large int type - try { - sql = "SELECT k5 FROM db1.tbl1 INTO OUTFILE \"hdfs://test/test_sql_prc_2019_02_19/\" FORMAT AS PARQUET " - + "PROPERTIES ( \"broker.name\" = \"hdfs_broker\", " - + "\"broker.hadoop.security.authentication\" = \"kerberos\", " - + "\"broker.kerberos_principal\" = \"test\", " - + "\"broker.kerberos_keytab_content\" = \"test\" ," - + " \"schema\"=\"required,int32,siteid;\");"; - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - e.printStackTrace(); - Assert.assertTrue(e.getMessage().contains("should use byte_array")); - } - - // do not support large int type, contains function - try { - sql = "SELECT sum(k5) FROM db1.tbl1 group by k5 INTO OUTFILE \"hdfs://test/test_sql_prc_2019_02_19/\" " - + "FORMAT AS PARQUET PROPERTIES ( \"broker.name\" = \"hdfs_broker\", " - + "\"broker.hadoop.security.authentication\" = \"kerberos\", " - + "\"broker.kerberos_principal\" = \"test\", " - + "\"broker.kerberos_keytab_content\" = \"test\" , " - + "\"schema\"=\"required,int32,siteid;\");"; - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("should use byte_array")); - } - - // support cast - try { - sql = "SELECT cast(sum(k5) as bigint) FROM db1.tbl1 group by k5" - + " INTO OUTFILE \"hdfs://test/test_sql_prc_2019_02_19/\" " - + "FORMAT AS PARQUET PROPERTIES ( \"broker.name\" = \"hdfs_broker\", " - + "\"broker.hadoop.security.authentication\" = \"kerberos\", " - + "\"broker.kerberos_principal\" = \"test\", " - + "\"broker.kerberos_keytab_content\" = \"test\" , " - + "\"schema\"=\"required,int64,siteid;\");"; - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); // CHECKSTYLE IGNORE THIS LINE - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - } - - @Test - public void testSystemViewCaseInsensitive() throws Exception { - String sql1 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ ROUTINE_SCHEMA, ROUTINE_NAME FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " - + "'ech_dw' ORDER BY ROUTINES.ROUTINE_SCHEMA\n"; - // The system view names in information_schema are case-insensitive, - dorisAssert.query(sql1).explainQuery(); - - String sql2 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ ROUTINE_SCHEMA, ROUTINE_NAME FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " - + "'ech_dw' ORDER BY routines.ROUTINE_SCHEMA\n"; - try { - // Should not refer to one of system views using different cases within the same statement. - // sql2 is wrong because 'ROUTINES' and 'routines' are used. - dorisAssert.query(sql2).explainQuery(); - Assert.fail("Refer to one of system views using different cases within the same statement is wrong."); - } catch (AnalysisException e) { - System.out.println(e.getMessage()); - } - } - - @Test - public void testWithUnionToSql() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - String sql1 = - "select \n" - + " t.k1 \n" - + "from (\n" - + " with \n" - + " v1 as (select t1.k1 from db1.tbl1 t1),\n" - + " v2 as (select t2.k1 from db1.tbl1 t2)\n" - + " select v1.k1 as k1 from v1\n" - + " union\n" - + " select v2.k1 as k1 from v2\n" - + ") t"; - SelectStmt stmt1 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql1, ctx); - stmt1.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertEquals("SELECT `t`.`k1` AS `k1` FROM (WITH v1 AS (SELECT `t1`.`k1` " - + "FROM `db1`.`tbl1` t1),v2 AS (SELECT `t2`.`k1` FROM `db1`.`tbl1` t2) " - + "SELECT `v1`.`k1` AS `k1` FROM `v1` UNION SELECT `v2`.`k1` AS `k1` FROM `v2`) t", stmt1.toSql()); - - String sql2 = - "with\n" - + " v1 as (select t1.k1 from db1.tbl1 t1),\n" - + " v2 as (select t2.k1 from db1.tbl1 t2)\n" - + "select\n" - + " t.k1\n" - + "from (\n" - + " select v1.k1 as k1 from v1\n" - + " union\n" - + " select v2.k1 as k1 from v2\n" - + ") t"; - SelectStmt stmt2 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql2, ctx); - stmt2.rewriteExprs(new Analyzer(ctx.getEnv(), ctx).getExprRewriter()); - Assert.assertTrue(stmt2.toSql().contains("WITH v1 AS (SELECT `t1`.`k1` FROM `db1`.`tbl1` t1)," - + "v2 AS (SELECT `t2`.`k1` FROM `db1`.`tbl1` t2)")); - } - - @Test - public void testSelectOuterJoinSql() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - String sql1 = "select l.citycode, group_concat(distinct r.username) from db1.table1 l " - + "left join db1.table2 r on l.citycode=r.citycode group by l.citycode"; - SelectStmt stmt1 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql1, ctx); - Assert.assertFalse(stmt1.getAnalyzer().getSlotDesc(new SlotId(2)).getIsNullable()); - Assert.assertFalse(stmt1.getAnalyzer().getSlotDescriptor("r.username").getIsNullable()); - FunctionCallExpr expr = (FunctionCallExpr) stmt1.getSelectList().getItems().get(1).getExpr(); - Assert.assertTrue(expr.getFnParams().isDistinct()); - } - - @Test - public void testHashBucketSelectTablet() throws Exception { - String sql1 = "SELECT * FROM db1.table1 TABLET(10031,10032,10033)"; - OriginalPlanner planner = (OriginalPlanner) dorisAssert.query(sql1).internalExecuteOneAndGetPlan(); - Set sampleTabletIds = ((OlapScanNode) planner.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertTrue(sampleTabletIds.contains(10031L)); - Assert.assertTrue(sampleTabletIds.contains(10032L)); - Assert.assertTrue(sampleTabletIds.contains(10033L)); - } - - @Test - public void testRandomBucketSelectTablet() throws Exception { - String sql1 = "SELECT * FROM db1.table3 TABLET(10031,10032,10033)"; - OriginalPlanner planner = (OriginalPlanner) dorisAssert.query(sql1).internalExecuteOneAndGetPlan(); - Set sampleTabletIds = ((OlapScanNode) planner.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertTrue(sampleTabletIds.contains(10031L)); - Assert.assertTrue(sampleTabletIds.contains(10032L)); - Assert.assertTrue(sampleTabletIds.contains(10033L)); - } - - @Test - public void testSelectSampleHashBucketTable() throws Exception { - FeConstants.runningUnitTest = true; - Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("db1"); - OlapTable tbl = (OlapTable) db.getTableOrMetaException("table1"); - long tabletId = 10031L; - for (Partition partition : tbl.getPartitions()) { - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(10000); - for (Tablet tablet : mIndex.getTablets()) { - tablet.setTabletId(tabletId); - tabletId += 1; - } - } - } - - // 1. TABLESAMPLE ROWS - String sql1 = "SELECT * FROM db1.table1 TABLESAMPLE(10 ROWS)"; - OriginalPlanner planner1 = (OriginalPlanner) dorisAssert.query(sql1).internalExecuteOneAndGetPlan(); - Set sampleTabletIds1 = ((OlapScanNode) planner1.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds1.size()); - - String sql2 = "SELECT * FROM db1.table1 TABLESAMPLE(1000 ROWS)"; - OriginalPlanner planner2 = (OriginalPlanner) dorisAssert.query(sql2).internalExecuteOneAndGetPlan(); - Set sampleTabletIds2 = ((OlapScanNode) planner2.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds2.size()); - - String sql3 = "SELECT * FROM db1.table1 TABLESAMPLE(1001 ROWS)"; - OriginalPlanner planner3 = (OriginalPlanner) dorisAssert.query(sql3).internalExecuteOneAndGetPlan(); - Set sampleTabletIds3 = ((OlapScanNode) planner3.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(2, sampleTabletIds3.size()); - - String sql4 = "SELECT * FROM db1.table1 TABLESAMPLE(9500 ROWS)"; - OriginalPlanner planner4 = (OriginalPlanner) dorisAssert.query(sql4).internalExecuteOneAndGetPlan(); - Set sampleTabletIds4 = ((OlapScanNode) planner4.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(10, sampleTabletIds4.size()); - - String sql5 = "SELECT * FROM db1.table1 TABLESAMPLE(11000 ROWS)"; - OriginalPlanner planner5 = (OriginalPlanner) dorisAssert.query(sql5).internalExecuteOneAndGetPlan(); - Set sampleTabletIds5 = ((OlapScanNode) planner5.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(0, sampleTabletIds5.size()); // no sample, all tablet - - String sql6 = "SELECT * FROM db1.table1 TABLET(10033) TABLESAMPLE(900 ROWS)"; - OriginalPlanner planner6 = (OriginalPlanner) dorisAssert.query(sql6).internalExecuteOneAndGetPlan(); - Set sampleTabletIds6 = ((OlapScanNode) planner6.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertTrue(sampleTabletIds6.size() >= 1 && sampleTabletIds6.size() <= 2); - Assert.assertTrue(sampleTabletIds6.contains(10033L)); - - // 2. TABLESAMPLE PERCENT - String sql7 = "SELECT * FROM db1.table1 TABLESAMPLE(10 PERCENT)"; - OriginalPlanner planner7 = (OriginalPlanner) dorisAssert.query(sql7).internalExecuteOneAndGetPlan(); - Set sampleTabletIds7 = ((OlapScanNode) planner7.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds7.size()); - - String sql8 = "SELECT * FROM db1.table1 TABLESAMPLE(15 PERCENT)"; - OriginalPlanner planner8 = (OriginalPlanner) dorisAssert.query(sql8).internalExecuteOneAndGetPlan(); - Set sampleTabletIds8 = ((OlapScanNode) planner8.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(2, sampleTabletIds8.size()); - - String sql9 = "SELECT * FROM db1.table1 TABLESAMPLE(100 PERCENT)"; - OriginalPlanner planner9 = (OriginalPlanner) dorisAssert.query(sql9).internalExecuteOneAndGetPlan(); - Set sampleTabletIds9 = ((OlapScanNode) planner9.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(0, sampleTabletIds9.size()); - - String sql10 = "SELECT * FROM db1.table1 TABLESAMPLE(110 PERCENT)"; - OriginalPlanner planner10 = (OriginalPlanner) dorisAssert.query(sql10).internalExecuteOneAndGetPlan(); - Set sampleTabletIds10 = ((OlapScanNode) planner10.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(0, sampleTabletIds10.size()); - - String sql11 = "SELECT * FROM db1.table1 TABLET(10033) TABLESAMPLE(5 PERCENT)"; - OriginalPlanner planner11 = (OriginalPlanner) dorisAssert.query(sql11).internalExecuteOneAndGetPlan(); - Set sampleTabletIds11 = ((OlapScanNode) planner11.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertTrue(sampleTabletIds11.size() >= 1 && sampleTabletIds11.size() <= 2); - Assert.assertTrue(sampleTabletIds11.contains(10033L)); - - // 3. TABLESAMPLE REPEATABLE - String sql12 = "SELECT * FROM db1.table1 TABLESAMPLE(900 ROWS)"; - OriginalPlanner planner12 = (OriginalPlanner) dorisAssert.query(sql12).internalExecuteOneAndGetPlan(); - Set sampleTabletIds12 = ((OlapScanNode) planner12.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds12.size()); - - String sql13 = "SELECT * FROM db1.table1 TABLESAMPLE(900 ROWS) REPEATABLE 2"; - OriginalPlanner planner13 = (OriginalPlanner) dorisAssert.query(sql13).internalExecuteOneAndGetPlan(); - Set sampleTabletIds13 = ((OlapScanNode) planner13.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds13.size()); - Assert.assertTrue(sampleTabletIds13.contains(10033L)); - - String sql14 = "SELECT * FROM db1.table1 TABLESAMPLE(900 ROWS) REPEATABLE 10"; - OriginalPlanner planner14 = (OriginalPlanner) dorisAssert.query(sql14).internalExecuteOneAndGetPlan(); - Set sampleTabletIds14 = ((OlapScanNode) planner14.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds14.size()); - Assert.assertTrue(sampleTabletIds14.contains(10031L)); - - String sql15 = "SELECT * FROM db1.table1 TABLESAMPLE(900 ROWS) REPEATABLE 0"; - OriginalPlanner planner15 = (OriginalPlanner) dorisAssert.query(sql15).internalExecuteOneAndGetPlan(); - Set sampleTabletIds15 = ((OlapScanNode) planner15.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds15.size()); - Assert.assertTrue(sampleTabletIds15.contains(10031L)); - - // 4. select returns 900 rows of results - String sql16 = "SELECT * FROM (SELECT * FROM db1.table1 TABLESAMPLE(900 ROWS) REPEATABLE 9999999 limit 900) t"; - OriginalPlanner planner16 = (OriginalPlanner) dorisAssert.query(sql16).internalExecuteOneAndGetPlan(); - Set sampleTabletIds16 = ((OlapScanNode) planner16.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds16.size()); - - String sql17 = "SELECT * FROM db1.table1 TABLESAMPLE(15 PERCENT) where siteid != 0"; - OriginalPlanner planner17 = (OriginalPlanner) dorisAssert.query(sql17).internalExecuteOneAndGetPlan(); - Set sampleTabletIds17 = ((OlapScanNode) planner17.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(2, sampleTabletIds17.size()); - FeConstants.runningUnitTest = false; - } - - @Test - public void testSelectSampleRandomBucketTable() throws Exception { - FeConstants.runningUnitTest = true; - Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("db1"); - OlapTable tbl = (OlapTable) db.getTableOrMetaException("table3"); - long tabletId = 10031L; - for (Partition partition : tbl.getPartitions()) { - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(10000); - for (Tablet tablet : mIndex.getTablets()) { - tablet.setTabletId(tabletId); - tabletId += 1; - } - } - } - - // 1. TABLESAMPLE ROWS - String sql1 = "SELECT * FROM db1.table3 TABLESAMPLE(10 ROWS)"; - OriginalPlanner planner1 = (OriginalPlanner) dorisAssert.query(sql1).internalExecuteOneAndGetPlan(); - Set sampleTabletIds1 = ((OlapScanNode) planner1.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds1.size()); - - String sql2 = "SELECT * FROM db1.table3 TABLESAMPLE(1000 ROWS)"; - OriginalPlanner planner2 = (OriginalPlanner) dorisAssert.query(sql2).internalExecuteOneAndGetPlan(); - Set sampleTabletIds2 = ((OlapScanNode) planner2.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds2.size()); - - String sql3 = "SELECT * FROM db1.table3 TABLESAMPLE(1001 ROWS)"; - OriginalPlanner planner3 = (OriginalPlanner) dorisAssert.query(sql3).internalExecuteOneAndGetPlan(); - Set sampleTabletIds3 = ((OlapScanNode) planner3.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(2, sampleTabletIds3.size()); - - String sql4 = "SELECT * FROM db1.table3 TABLESAMPLE(9500 ROWS)"; - OriginalPlanner planner4 = (OriginalPlanner) dorisAssert.query(sql4).internalExecuteOneAndGetPlan(); - Set sampleTabletIds4 = ((OlapScanNode) planner4.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(10, sampleTabletIds4.size()); - - String sql5 = "SELECT * FROM db1.table3 TABLESAMPLE(11000 ROWS)"; - OriginalPlanner planner5 = (OriginalPlanner) dorisAssert.query(sql5).internalExecuteOneAndGetPlan(); - Set sampleTabletIds5 = ((OlapScanNode) planner5.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(0, sampleTabletIds5.size()); // no sample, all tablet - - String sql6 = "SELECT * FROM db1.table3 TABLET(10033) TABLESAMPLE(900 ROWS)"; - OriginalPlanner planner6 = (OriginalPlanner) dorisAssert.query(sql6).internalExecuteOneAndGetPlan(); - Set sampleTabletIds6 = ((OlapScanNode) planner6.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertTrue(sampleTabletIds6.size() >= 1 && sampleTabletIds6.size() <= 2); - Assert.assertTrue(sampleTabletIds6.contains(10033L)); - - // 2. TABLESAMPLE PERCENT - String sql7 = "SELECT * FROM db1.table3 TABLESAMPLE(10 PERCENT)"; - OriginalPlanner planner7 = (OriginalPlanner) dorisAssert.query(sql7).internalExecuteOneAndGetPlan(); - Set sampleTabletIds7 = ((OlapScanNode) planner7.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds7.size()); - - String sql8 = "SELECT * FROM db1.table3 TABLESAMPLE(15 PERCENT)"; - OriginalPlanner planner8 = (OriginalPlanner) dorisAssert.query(sql8).internalExecuteOneAndGetPlan(); - Set sampleTabletIds8 = ((OlapScanNode) planner8.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(2, sampleTabletIds8.size()); - - String sql9 = "SELECT * FROM db1.table3 TABLESAMPLE(100 PERCENT)"; - OriginalPlanner planner9 = (OriginalPlanner) dorisAssert.query(sql9).internalExecuteOneAndGetPlan(); - Set sampleTabletIds9 = ((OlapScanNode) planner9.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(0, sampleTabletIds9.size()); - - String sql10 = "SELECT * FROM db1.table3 TABLESAMPLE(110 PERCENT)"; - OriginalPlanner planner10 = (OriginalPlanner) dorisAssert.query(sql10).internalExecuteOneAndGetPlan(); - Set sampleTabletIds10 = ((OlapScanNode) planner10.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(0, sampleTabletIds10.size()); - - String sql11 = "SELECT * FROM db1.table3 TABLET(10033) TABLESAMPLE(5 PERCENT)"; - OriginalPlanner planner11 = (OriginalPlanner) dorisAssert.query(sql11).internalExecuteOneAndGetPlan(); - Set sampleTabletIds11 = ((OlapScanNode) planner11.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertTrue(sampleTabletIds11.size() >= 1 && sampleTabletIds11.size() <= 2); - Assert.assertTrue(sampleTabletIds11.contains(10033L)); - - // 3. TABLESAMPLE REPEATABLE - String sql12 = "SELECT * FROM db1.table3 TABLESAMPLE(900 ROWS)"; - OriginalPlanner planner12 = (OriginalPlanner) dorisAssert.query(sql12).internalExecuteOneAndGetPlan(); - Set sampleTabletIds12 = ((OlapScanNode) planner12.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds12.size()); - - String sql13 = "SELECT * FROM db1.table3 TABLESAMPLE(900 ROWS) REPEATABLE 2"; - OriginalPlanner planner13 = (OriginalPlanner) dorisAssert.query(sql13).internalExecuteOneAndGetPlan(); - Set sampleTabletIds13 = ((OlapScanNode) planner13.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds13.size()); - Assert.assertTrue(sampleTabletIds13.contains(10033L)); - - String sql14 = "SELECT * FROM db1.table3 TABLESAMPLE(900 ROWS) REPEATABLE 10"; - OriginalPlanner planner14 = (OriginalPlanner) dorisAssert.query(sql14).internalExecuteOneAndGetPlan(); - Set sampleTabletIds14 = ((OlapScanNode) planner14.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds14.size()); - Assert.assertTrue(sampleTabletIds14.contains(10031L)); - - String sql15 = "SELECT * FROM db1.table3 TABLESAMPLE(900 ROWS) REPEATABLE 0"; - OriginalPlanner planner15 = (OriginalPlanner) dorisAssert.query(sql15).internalExecuteOneAndGetPlan(); - Set sampleTabletIds15 = ((OlapScanNode) planner15.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds15.size()); - Assert.assertTrue(sampleTabletIds15.contains(10031L)); - - // 4. select returns 900 rows of results - String sql16 = "SELECT * FROM (SELECT * FROM db1.table3 TABLESAMPLE(900 ROWS) REPEATABLE 9999999 limit 900) t"; - OriginalPlanner planner16 = (OriginalPlanner) dorisAssert.query(sql16).internalExecuteOneAndGetPlan(); - Set sampleTabletIds16 = ((OlapScanNode) planner16.getScanNodes().get(0)).getSampleTabletIds(); - Assert.assertEquals(1, sampleTabletIds16.size()); - FeConstants.runningUnitTest = false; - } - - - @Test - public void testSelectExcept() throws Exception { - ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - String sql = "SELECT * EXCEPT (siteid) FROM db1.table1"; - SelectStmt stmt = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx); - Assert.assertFalse(stmt.getColLabels().contains("siteid")); - Assert.assertEquals(stmt.resultExprs.size(), 3); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/SetVariableTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/SetVariableTest.java index 703ba49c8263526..1148f64de3fd10f 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/SetVariableTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/SetVariableTest.java @@ -58,7 +58,7 @@ public void testSqlMode() throws Exception { stmtExecutor.execute(); Expr expr = stmtExecutor.getParsedStmt().getResultExprs().get(0); Assert.assertTrue(expr instanceof SlotRef); - Assert.assertSame(expr.getType(), Type.VARCHAR); + Assert.assertSame(Type.STRING, expr.getType()); } @Test diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/TableNameComparedLowercaseTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/TableNameComparedLowercaseTest.java index 2c8625ae0e228d0..e1bf796104bbc90 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/TableNameComparedLowercaseTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/TableNameComparedLowercaseTest.java @@ -18,7 +18,6 @@ package org.apache.doris.analysis; import org.apache.doris.catalog.Env; -import org.apache.doris.common.AnalysisException; import org.apache.doris.common.Config; import org.apache.doris.qe.GlobalVariable; import org.apache.doris.utframe.DorisAssert; @@ -88,22 +87,6 @@ public void testTableNameLowerCasTe() { Assert.assertTrue(tableNames.contains("TABLE2")); } - @Test - public void testQueryTableNameCaseInsensitive() throws Exception { - String sql1 = "select /*+ SET_VAR(enable_nereids_planner=false) */ Table1.siteid, Table2.k2 from Table1 join Table2 on Table1.siteid = Table2.k1" - + " where Table2.k5 > 1000 order by Table1.siteid"; - dorisAssert.query(sql1).explainQuery(); - - String sql2 = "select /*+ SET_VAR(enable_nereids_planner=false) */ Table1.siteid, Table2.k2 from table1 join table2 on TAble1.siteid = TAble2.k1" - + " where TABle2.k5 > 1000 order by TABLe1.siteid"; - try { - dorisAssert.query(sql2).explainQuery(); - Assert.fail("Different references to the same table name are used: 'table1', 'TAble1'"); - } catch (AnalysisException e) { - System.out.println(e.getMessage()); - } - } - @Test public void testCreateSameTableFailed() { String table2 = "create table db1.TABle2(k1 int, k2 varchar(32), k3 varchar(32)) " diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java index 17a4b5fe04a7309..7368e6fb5924279 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java @@ -23,7 +23,6 @@ import org.apache.doris.analysis.Expr; import org.apache.doris.analysis.FunctionCallExpr; import org.apache.doris.analysis.StringLiteral; -import org.apache.doris.common.Config; import org.apache.doris.common.FeConstants; import org.apache.doris.common.jmockit.Deencapsulation; import org.apache.doris.planner.PlanFragment; @@ -61,7 +60,6 @@ public static void setup() throws Exception { FeConstants.runningUnitTest = true; // create connect context connectContext = UtFrameUtils.createDefaultCtx(); - connectContext.getSessionVariable().setEnableNereidsPlanner(false); } @AfterClass @@ -73,8 +71,6 @@ public static void teardown() { @Test public void test() throws Exception { ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - ctx.getSessionVariable().setEnableNereidsPlanner(false); - ctx.getSessionVariable().setEnableFoldConstantByBe(false); // create database db1 createDatabase(ctx, "create database db1;"); @@ -114,102 +110,13 @@ public void test() throws Exception { queryStr = "select db1.id_masking(k1) from db1.tbl1"; Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "concat(left(CAST(`k1` AS VARCHAR(65533)), 3), '****', right(CAST(`k1` AS VARCHAR(65533)), 4))")); - - // create alias function with cast - // cast any type to decimal with specific precision and scale - createFuncStr = "create alias function db1.decimal(all, int, int) with parameter(col, precision, scale)" - + " as cast(col as decimal(precision, scale));"; - createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx); - Env.getCurrentEnv().createFunction(createFunctionStmt); - - functions = db.getFunctions(); - Assert.assertEquals(2, functions.size()); - - queryStr = "select db1.decimal(333, 4, 1);"; - ctx.getState().reset(); - stmtExecutor = new StmtExecutor(ctx, queryStr); - stmtExecutor.execute(); - Assert.assertNotEquals(QueryState.MysqlStateType.ERR, ctx.getState().getStateType()); - planner = stmtExecutor.planner(); - Assert.assertEquals(1, planner.getFragments().size()); - fragment = planner.getFragments().get(0); - Assert.assertTrue(fragment.getPlanRoot() instanceof UnionNode); - unionNode = (UnionNode) fragment.getPlanRoot(); - constExprLists = Deencapsulation.getField(unionNode, "constExprLists"); - System.out.println(constExprLists.get(0).get(0)); - Assert.assertTrue(constExprLists.get(0).get(0) instanceof StringLiteral); - - queryStr = "select db1.decimal(k3, 4, 1) from db1.tbl1;"; - if (Config.enable_decimal_conversion) { - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k3` AS decimalv3(4,1))")); - } else { - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k3` AS decimal(4,1))")); - } - - // cast any type to varchar with fixed length - createFuncStr = "create alias function db1.varchar(all, int) with parameter(text, length) as " - + "cast(text as varchar(length));"; - createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx); - Env.getCurrentEnv().createFunction(createFunctionStmt); - - functions = db.getFunctions(); - Assert.assertEquals(3, functions.size()); - - queryStr = "select db1.varchar(333, 4);"; - ctx.getState().reset(); - stmtExecutor = new StmtExecutor(ctx, queryStr); - stmtExecutor.execute(); - Assert.assertNotEquals(QueryState.MysqlStateType.ERR, ctx.getState().getStateType()); - planner = stmtExecutor.planner(); - Assert.assertEquals(1, planner.getFragments().size()); - fragment = planner.getFragments().get(0); - Assert.assertTrue(fragment.getPlanRoot() instanceof UnionNode); - unionNode = (UnionNode) fragment.getPlanRoot(); - constExprLists = Deencapsulation.getField(unionNode, "constExprLists"); - Assert.assertEquals(1, constExprLists.size()); - Assert.assertEquals(1, constExprLists.get(0).size()); - Assert.assertTrue(constExprLists.get(0).get(0) instanceof StringLiteral); - - queryStr = "select db1.varchar(k1, 4) from db1.tbl1;"; - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k1` AS varchar(65533))")); - - // cast any type to char with fixed length - createFuncStr = "create alias function db1.to_char(all, int) with parameter(text, length) as " - + "cast(text as char(length));"; - createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx); - Env.getCurrentEnv().createFunction(createFunctionStmt); - - functions = db.getFunctions(); - Assert.assertEquals(4, functions.size()); - - queryStr = "select db1.to_char(333, 4);"; - ctx.getState().reset(); - stmtExecutor = new StmtExecutor(ctx, queryStr); - stmtExecutor.execute(); - Assert.assertNotEquals(QueryState.MysqlStateType.ERR, ctx.getState().getStateType()); - planner = stmtExecutor.planner(); - Assert.assertEquals(1, planner.getFragments().size()); - fragment = planner.getFragments().get(0); - Assert.assertTrue(fragment.getPlanRoot() instanceof UnionNode); - unionNode = (UnionNode) fragment.getPlanRoot(); - constExprLists = Deencapsulation.getField(unionNode, "constExprLists"); - Assert.assertEquals(1, constExprLists.size()); - Assert.assertEquals(1, constExprLists.get(0).size()); - Assert.assertTrue(constExprLists.get(0).get(0) instanceof StringLiteral); - - queryStr = "select db1.to_char(k1, 4) from db1.tbl1;"; - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k1` AS character")); + "concat(left(CAST(CAST(k1 as BIGINT) AS VARCHAR(65533)), 3), '****'," + + " right(CAST(CAST(k1 AS BIGINT) AS VARCHAR(65533)), 4))")); } @Test public void testCreateGlobalFunction() throws Exception { ConnectContext ctx = UtFrameUtils.createDefaultCtx(); - ctx.getSessionVariable().setEnableNereidsPlanner(false); ctx.getSessionVariable().setEnableFoldConstantByBe(false); // 1. create database db2 @@ -240,61 +147,8 @@ public void testCreateGlobalFunction() throws Exception { queryStr = "select id_masking(k1) from db2.tbl1"; Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "concat(left(CAST(`k1` AS varchar(65533)), 3), '****', right(CAST(`k1` AS varchar(65533)), 4))")); - - // 4. create alias function with cast - // cast any type to decimal with specific precision and scale - createFuncStr = "create global alias function decimal(all, int, int) with parameter(col, precision, scale)" - + " as cast(col as decimal(precision, scale));"; - createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx); - Env.getCurrentEnv().createFunction(createFunctionStmt); - - functions = Env.getCurrentEnv().getGlobalFunctionMgr().getFunctions(); - Assert.assertEquals(2, functions.size()); - - queryStr = "select decimal(333, 4, 1);"; - testFunctionQuery(ctx, queryStr, true); - - queryStr = "select decimal(k3, 4, 1) from db2.tbl1;"; - if (Config.enable_decimal_conversion) { - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k3` AS decimalv3(4,1))")); - } else { - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k3` AS decimal(4,1))")); - } - - // 5. cast any type to varchar with fixed length - createFuncStr = "create global alias function db2.varchar(all, int) with parameter(text, length) as " - + "cast(text as varchar(length));"; - createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx); - Env.getCurrentEnv().createFunction(createFunctionStmt); - - functions = Env.getCurrentEnv().getGlobalFunctionMgr().getFunctions(); - Assert.assertEquals(3, functions.size()); - - queryStr = "select varchar(333, 4);"; - testFunctionQuery(ctx, queryStr, true); - - queryStr = "select varchar(k1, 4) from db2.tbl1;"; - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k1` AS varchar(65533))")); - - // 6. cast any type to char with fixed length - createFuncStr = "create global alias function db2.to_char(all, int) with parameter(text, length) as " - + "cast(text as char(length));"; - createFunctionStmt = (CreateFunctionStmt) UtFrameUtils.parseAndAnalyzeStmt(createFuncStr, ctx); - Env.getCurrentEnv().createFunction(createFunctionStmt); - - functions = Env.getCurrentEnv().getGlobalFunctionMgr().getFunctions(); - Assert.assertEquals(4, functions.size()); - - queryStr = "select to_char(333, 4);"; - testFunctionQuery(ctx, queryStr, true); - - queryStr = "select to_char(k1, 4) from db2.tbl1;"; - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k1` AS character(255))")); + "concat(left(CAST(CAST(k1 as BIGINT) AS VARCHAR(65533)), 3), '****'," + + " right(CAST(CAST(k1 AS BIGINT) AS VARCHAR(65533)), 4))")); } private void testFunctionQuery(ConnectContext ctx, String queryStr, Boolean isStringLiteral) throws Exception { diff --git a/fe/fe-core/src/test/java/org/apache/doris/external/hms/HmsCatalogTest.java b/fe/fe-core/src/test/java/org/apache/doris/external/hms/HmsCatalogTest.java index e6281fd8f2fa202..fb6ac9859341d87 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/external/hms/HmsCatalogTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/external/hms/HmsCatalogTest.java @@ -338,7 +338,6 @@ private void createDbAndTableForHmsCatalog(HMSExternalCatalog hmsCatalog) { public void testQueryView() { SessionVariable sv = connectContext.getSessionVariable(); Assertions.assertNotNull(sv); - sv.setEnableNereidsPlanner(true); createDbAndTableForHmsCatalog((HMSExternalCatalog) env.getCatalogMgr().getCatalog(HMS_CATALOG)); queryViews(false); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/metrics/EventTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/metrics/EventTest.java index 631022d1759d035..b3566ed00d2e24c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/metrics/EventTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/metrics/EventTest.java @@ -48,7 +48,6 @@ public void write(int b) { @Override public void runBeforeAll() { connectContext.getSessionVariable().setEnableNereidsTrace(true); - connectContext.getSessionVariable().setEnableNereidsPlanner(true); channel = new EventChannel() .addConsumers( new PrintConsumer(CounterEvent.class, printStream), diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java deleted file mode 100644 index 03b7e8dc366644c..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/preprocess/SelectHintTest.java +++ /dev/null @@ -1,85 +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.doris.nereids.preprocess; - -import org.apache.doris.catalog.Env; -import org.apache.doris.nereids.NereidsPlanner; -import org.apache.doris.nereids.StatementContext; -import org.apache.doris.nereids.exceptions.MustFallbackException; -import org.apache.doris.nereids.parser.NereidsParser; -import org.apache.doris.nereids.properties.PhysicalProperties; -import org.apache.doris.qe.ConnectContext; -import org.apache.doris.qe.OriginStatement; -import org.apache.doris.qe.SessionVariable; -import org.apache.doris.qe.StmtExecutor; -import org.apache.doris.thrift.TUniqueId; - -import mockit.Expectations; -import mockit.Mock; -import mockit.MockUp; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -public class SelectHintTest { - - @BeforeAll - public static void init() { - ConnectContext ctx = new ConnectContext(); - new MockUp() { - @Mock - public ConnectContext get() { - return ctx; - } - }; - new MockUp() { - @Mock - public boolean isMaster() { - return true; - } - }; - } - - @Test - public void testFallbackToOriginalPlanner() throws Exception { - String sql = " SELECT /*+ SET_VAR(enable_nereids_planner=\"false\") */ 1"; - - ConnectContext ctx = new ConnectContext(); - ctx.setEnv(Env.getCurrentEnv()); - StatementContext statementContext = new StatementContext(ctx, new OriginStatement(sql, 0)); - SessionVariable sv = ctx.getSessionVariable(); - Assertions.assertNotNull(sv); - sv.setEnableNereidsPlanner(true); - Assertions.assertThrows(MustFallbackException.class, () -> new NereidsPlanner(statementContext) - .planWithLock(new NereidsParser().parseSingle(sql), PhysicalProperties.ANY)); - - // manually recover sv - sv.setEnableNereidsPlanner(true); - StmtExecutor stmtExecutor = new StmtExecutor(ctx, sql); - - new Expectations(stmtExecutor) { - { - stmtExecutor.executeByLegacy((TUniqueId) any); - } - }; - - stmtExecutor.execute(); - - Assertions.assertTrue(sv.isEnableNereidsPlanner()); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java index b807bbbbc7a4bd5..4c24c789b123739 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java @@ -196,7 +196,6 @@ public void checkOnePolicy() throws Exception { LogicalRelation relation = new LogicalOlapScan(StatementScopeIdGenerator.newRelationId(), olapTable, Arrays.asList(fullDbName)); LogicalCheckPolicy checkPolicy = new LogicalCheckPolicy<>(relation); - connectContext.getSessionVariable().setEnableNereidsPlanner(true); createPolicy("CREATE ROW POLICY " + policyName + " ON " @@ -226,7 +225,6 @@ public void checkOnePolicyRandomDist() throws Exception { ImmutableList.of(tableNameRanddomDist)), connectContext, new BindRelation()); LogicalCheckPolicy checkPolicy = new LogicalCheckPolicy(plan); - connectContext.getSessionVariable().setEnableNereidsPlanner(true); createPolicy("CREATE ROW POLICY " + policyName + " ON " diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/ColocatePlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/ColocatePlanTest.java deleted file mode 100644 index 68279489bfc1e5f..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/ColocatePlanTest.java +++ /dev/null @@ -1,309 +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.doris.planner; - -import org.apache.doris.catalog.ColocateGroupSchema; -import org.apache.doris.catalog.ColocateTableIndex; -import org.apache.doris.catalog.ColocateTableIndex.GroupId; -import org.apache.doris.catalog.Database; -import org.apache.doris.catalog.Env; -import org.apache.doris.catalog.OlapTable; -import org.apache.doris.common.FeConstants; -import org.apache.doris.common.jmockit.Deencapsulation; -import org.apache.doris.qe.Coordinator; -import org.apache.doris.qe.QueryStatisticsItem; -import org.apache.doris.qe.StmtExecutor; -import org.apache.doris.utframe.TestWithFeService; - -import org.apache.commons.lang3.StringUtils; -import org.junit.Assert; -import org.junit.jupiter.api.Test; - -import java.util.List; - -public class ColocatePlanTest extends TestWithFeService { - public static final String COLOCATE_ENABLE = "COLOCATE"; - private static final String GLOBAL_GROUP = "__global__group1"; - private static final String GLOBAL_GROUP2 = "__global__group2"; - - @Override - protected void runBeforeAll() throws Exception { - FeConstants.runningUnitTest = true; - createDatabase("db1"); - createTable("create table db1.test_colocate(k1 int, k2 int, k3 int, k4 int) " - + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2'," - + "'colocate_with' = 'group1');"); - createTable("create table db1.test(k1 int, k2 int, k3 int, k4 int)" - + "partition by range(k1) (partition p1 values less than (\"1\"), partition p2 values less than (\"2\"))" - + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2')"); - createTable("create table db1.test_multi_partition(k1 int, k2 int)" - + "partition by range(k1) (partition p1 values less than(\"1\"), partition p2 values less than (\"2\"))" - + "distributed by hash(k2) buckets 10 properties ('replication_num' = '2', 'colocate_with' = 'group2')"); - - // global colocate tables - createDatabase("db2"); - createTable("create table db1.test_global_colocate1(k1 varchar(10), k2 int, k3 int, k4 int) " - + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2'," - + "'colocate_with' = '" + GLOBAL_GROUP + "');"); - createTable("create table db2.test_global_colocate2(k1 varchar(20), k2 int, k3 int) " - + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2'," - + "'colocate_with' = '" + GLOBAL_GROUP + "');"); - createTable("create table db2.test_global_colocate3(k1 varchar(20), k2 int, k3 date) " - + "partition by range(k3) (partition p1 values less than(\"2020-01-01\"), partition p2 values less than (\"2020-02-01\")) " - + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2'," - + "'colocate_with' = '" + GLOBAL_GROUP + "');"); - } - - @Override - protected int backendNum() { - return 2; - } - - // without - // 1. agg: group by column < distributed columns - // 2. join: src data has been redistributed - @Test - public void sqlDistributedSmallerThanData1() throws Exception { - String plan1 = getSQLPlanOrErrorMsg( - "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from (select k1 from db1.test_colocate group by k1) a , db1.test_colocate b " - + "where a.k1=b.k1"); - Assert.assertEquals(2, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertTrue(plan1.contains(DistributedPlanColocateRule.REDISTRIBUTED_SRC_DATA)); - } - - // without : join column < distributed columns; - @Test - public void sqlDistributedSmallerThanData2() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from (select k1 from db1.test_colocate group by k1, k2) a , db1.test_colocate b " - + "where a.k1=b.k1"; - String plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertTrue(plan1.contains(DistributedPlanColocateRule.INCONSISTENT_DISTRIBUTION_OF_TABLE_AND_QUERY)); - } - - // with: - // 1. agg columns = distributed columns - // 2. hash columns = agg output columns = distributed columns - @Test - public void sqlAggAndJoinSameAsTableMeta() throws Exception { - String sql = - "explain select * from (select k1, k2 from db1.test_colocate group by k1, k2) a , db1.test_colocate b " - + "where a.k1=b.k1 and a.k2=b.k2"; - String plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertEquals(1, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertTrue(plan1.contains(COLOCATE_ENABLE)); - } - - // with: - // 1. agg columns > distributed columns - // 2. hash columns = agg output columns > distributed columns - @Test - public void sqlAggAndJoinMoreThanTableMeta() throws Exception { - String sql = "explain select * from (select k1, k2, k3 from db1.test_colocate group by k1, k2, k3) a , " - + "db1.test_colocate b where a.k1=b.k1 and a.k2=b.k2 and a.k3=b.k3"; - String plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertEquals(1, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertTrue(plan1.contains(COLOCATE_ENABLE)); - } - - // with: - // 1. agg columns > distributed columns - // 2. hash columns = distributed columns - @Test - public void sqlAggMoreThanTableMeta() throws Exception { - String sql = "explain select * from (select k1, k2, k3 from db1.test_colocate group by k1, k2, k3) a , " - + "db1.test_colocate b where a.k1=b.k1 and a.k2=b.k2"; - String plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertEquals(1, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertTrue(plan1.contains(COLOCATE_ENABLE)); - } - - // without: - // 1. agg columns = distributed columns - // 2. table is not in colocate group - // 3. more then 1 instances - // Fixed #6028 - @Test - public void sqlAggWithNonColocateTable() throws Exception { - String sql = "explain select k1, k2 from db1.test group by k1, k2"; - String plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertEquals(2, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertFalse(plan1.contains(COLOCATE_ENABLE)); - } - - // check colocate add scan range - // Fix #6726 - // 1. colocate agg node - // 2. scan node with two tablet one instance - @Test - public void sqlAggWithColocateTable() throws Exception { - connectContext.getSessionVariable().setParallelResultSink(false); - String sql = "select k1, k2, count(*) from db1.test_multi_partition where k2 = 1 group by k1, k2"; - StmtExecutor executor = getSqlStmtExecutor(sql); - Planner planner = executor.planner(); - Coordinator coordinator = Deencapsulation.getField(executor, "coord"); - List scanNodeList = planner.getScanNodes(); - Assert.assertEquals(scanNodeList.size(), 1); - Assert.assertTrue(scanNodeList.get(0) instanceof OlapScanNode); - OlapScanNode olapScanNode = (OlapScanNode) scanNodeList.get(0); - Assert.assertEquals(olapScanNode.getSelectedPartitionIds().size(), 2); - long selectedTablet = Deencapsulation.getField(olapScanNode, "selectedSplitNum"); - Assert.assertEquals(selectedTablet, 2); - - List instanceInfo = coordinator.getFragmentInstanceInfos(); - Assert.assertEquals(instanceInfo.size(), 2); - } - - @Test - public void checkColocatePlanFragment() throws Exception { - connectContext.getSessionVariable().setEnableSharedScan(false); - String sql - = "select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.test_colocate a, db1.test_colocate b where a.k1=b.k1 and a.k2=b.k2 group by a.k1;"; - StmtExecutor executor = getSqlStmtExecutor(sql); - Planner planner = executor.planner(); - Coordinator coordinator = Deencapsulation.getField(executor, "coord"); - boolean isColocateFragment0 = Deencapsulation.invoke(coordinator, "isColocateFragment", - planner.getFragments().get(1), planner.getFragments().get(1).getPlanRoot()); - Assert.assertFalse(isColocateFragment0); - boolean isColocateFragment1 = Deencapsulation.invoke(coordinator, "isColocateFragment", - planner.getFragments().get(2), planner.getFragments().get(2).getPlanRoot()); - Assert.assertTrue(isColocateFragment1); - } - - // Fix #8778 - @Test - public void rollupAndMoreThanOneInstanceWithoutColocate() throws Exception { - connectContext.getSessionVariable().setParallelResultSink(false); - String createColocateTblStmtStr = "create table db1.test_colocate_one_backend(k1 int, k2 int, k3 int, k4 int) " - + "distributed by hash(k1, k2, k3) buckets 10 properties('replication_num' = '1');"; - createTable(createColocateTblStmtStr); - String sql = "select a.k1, a.k2, sum(a.k3) " - + "from db1.test_colocate_one_backend a join[shuffle] db1.test_colocate_one_backend b on a.k1=b.k1 " - + "group by rollup(a.k1, a.k2);"; - Deencapsulation.setField(connectContext.getSessionVariable(), "parallelExecInstanceNum", 2); - String plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertEquals(2, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertEquals(5, StringUtils.countMatches(plan1, "PLAN FRAGMENT")); - } - - @Test - public void testGlobalColocateGroup() throws Exception { - Database db1 = Env.getCurrentEnv().getInternalCatalog().getDbNullable("db1"); - Database db2 = Env.getCurrentEnv().getInternalCatalog().getDbNullable("db2"); - OlapTable tbl1 = (OlapTable) db1.getTableNullable("test_global_colocate1"); - OlapTable tbl2 = (OlapTable) db2.getTableNullable("test_global_colocate2"); - OlapTable tbl3 = (OlapTable) db2.getTableNullable("test_global_colocate3"); - - String sql = "explain select * from (select k1, k2 from " - + "db1.test_global_colocate1 group by k1, k2) a , db2.test_global_colocate2 b " - + "where a.k1=b.k1 and a.k2=b.k2"; - String plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertEquals(1, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertTrue(plan1.contains(COLOCATE_ENABLE)); - ColocateTableIndex colocateTableIndex = Env.getCurrentColocateIndex(); - ColocateGroupSchema groupSchema = colocateTableIndex.getGroupSchema( - GroupId.getFullGroupName(1000, GLOBAL_GROUP)); - Assert.assertNotNull(groupSchema); - GroupId groupId = groupSchema.getGroupId(); - List tableIds = colocateTableIndex.getAllTableIds(groupId); - Assert.assertEquals(3, tableIds.size()); - Assert.assertTrue(tableIds.contains(tbl1.getId())); - Assert.assertTrue(tableIds.contains(tbl2.getId())); - Assert.assertTrue(tableIds.contains(tbl3.getId())); - Assert.assertEquals(3, groupId.getTblId2DbIdSize()); - Assert.assertEquals(db1.getId(), groupId.getDbIdByTblId(tbl1.getId())); - Assert.assertEquals(db2.getId(), groupId.getDbIdByTblId(tbl2.getId())); - Assert.assertEquals(db2.getId(), groupId.getDbIdByTblId(tbl3.getId())); - - sql = "explain select * from (select k1, k2 from " - + "db1.test_global_colocate1 group by k1, k2) a , db2.test_global_colocate3 b " - + "where a.k1=b.k1 and a.k2=b.k2"; - plan1 = getSQLPlanOrErrorMsg(sql); - Assert.assertEquals(1, StringUtils.countMatches(plan1, "AGGREGATE")); - Assert.assertTrue(plan1.contains(COLOCATE_ENABLE)); - - String addPartitionStmt - = "alter table db2.test_global_colocate3 add partition p3 values less than (\"2020-03-01\");"; - alterTableSync(addPartitionStmt); - - try { - createTable("create table db1.test_global_colocate4(k1 int, k2 int, k3 int, k4 int) " - + "distributed by hash(k1, k2) buckets 10 properties('replication_num' = '2'," - + "'colocate_with' = '" + GLOBAL_GROUP + "');"); - Assert.fail(); - } catch (Exception e) { - e.printStackTrace(); - Assert.assertTrue( - e.getMessage().contains("Colocate tables distribution columns must have the same data type")); - List tmpTableIds = colocateTableIndex.getAllTableIds(groupId); - Assert.assertEquals(3, tmpTableIds.size()); - Assert.assertTrue(tmpTableIds.contains(tbl1.getId())); - Assert.assertTrue(tmpTableIds.contains(tbl2.getId())); - Assert.assertTrue(tmpTableIds.contains(tbl3.getId())); - Assert.assertEquals(3, groupId.getTblId2DbIdSize()); - Assert.assertEquals(db1.getId(), groupId.getDbIdByTblId(tbl1.getId())); - Assert.assertEquals(db2.getId(), groupId.getDbIdByTblId(tbl2.getId())); - Assert.assertEquals(db2.getId(), groupId.getDbIdByTblId(tbl3.getId())); - } - - // modify table's colocate group - String modifyStmt = "alter table db2.test_global_colocate3 set ('colocate_with' = '');"; - alterTableSync(modifyStmt); - tableIds = colocateTableIndex.getAllTableIds(groupId); - Assert.assertEquals(2, tableIds.size()); - Assert.assertTrue(tableIds.contains(tbl1.getId())); - Assert.assertTrue(tableIds.contains(tbl2.getId())); - Assert.assertEquals(2, groupId.getTblId2DbIdSize()); - Assert.assertEquals(db1.getId(), groupId.getDbIdByTblId(tbl1.getId())); - Assert.assertEquals(db2.getId(), groupId.getDbIdByTblId(tbl2.getId())); - - // change table's colocate group - modifyStmt = "alter table db2.test_global_colocate2 set ('colocate_with' = '" + GLOBAL_GROUP2 + "');"; - alterTableSync(modifyStmt); - tableIds = colocateTableIndex.getAllTableIds(groupId); - Assert.assertEquals(1, tableIds.size()); - Assert.assertTrue(tableIds.contains(tbl1.getId())); - Assert.assertEquals(1, groupId.getTblId2DbIdSize()); - Assert.assertEquals(db1.getId(), groupId.getDbIdByTblId(tbl1.getId())); - - GroupId groupId2 = colocateTableIndex.getGroupSchema( - GroupId.getFullGroupName(1000, GLOBAL_GROUP2)).getGroupId(); - tableIds = colocateTableIndex.getAllTableIds(groupId2); - Assert.assertEquals(1, tableIds.size()); - Assert.assertTrue(tableIds.contains(tbl2.getId())); - Assert.assertEquals(1, groupId2.getTblId2DbIdSize()); - Assert.assertEquals(db2.getId(), groupId2.getDbIdByTblId(tbl2.getId())); - - // checkpoint - // Get currentCatalog first - Env currentEnv = Env.getCurrentEnv(); - // Save real ckptThreadId - long ckptThreadId = currentEnv.getCheckpointer().getId(); - try { - // set checkpointThreadId to current thread id, so that when do checkpoint manually here, - // the Catalog.isCheckpointThread() will return true. - Deencapsulation.setField(Env.class, "checkpointThreadId", Thread.currentThread().getId()); - currentEnv.getCheckpointer().doCheckpoint(); - } catch (Throwable e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } finally { - // Restore the ckptThreadId - Deencapsulation.setField(Env.class, "checkpointThreadId", ckptThreadId); - } - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/DistributedPlannerTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/DistributedPlannerTest.java deleted file mode 100644 index 6f3a66ab3bab925..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/DistributedPlannerTest.java +++ /dev/null @@ -1,171 +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.doris.planner; - -import org.apache.doris.analysis.CreateDbStmt; -import org.apache.doris.analysis.CreateTableStmt; -import org.apache.doris.analysis.ExplainOptions; -import org.apache.doris.analysis.TupleId; -import org.apache.doris.catalog.Env; -import org.apache.doris.common.jmockit.Deencapsulation; -import org.apache.doris.qe.ConnectContext; -import org.apache.doris.qe.StmtExecutor; -import org.apache.doris.utframe.UtFrameUtils; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import mockit.Expectations; -import mockit.Injectable; -import mockit.Mocked; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -public class DistributedPlannerTest { - private static String runningDir = "fe/mocked/DemoTest/" + UUID.randomUUID().toString() + "/"; - private static ConnectContext ctx; - - @BeforeClass - public static void setUp() throws Exception { - UtFrameUtils.createDorisCluster(runningDir); - ctx = UtFrameUtils.createDefaultCtx(); - ctx.getSessionVariable().setEnableNereidsPlanner(false); - String createDbStmtStr = "create database db1;"; - CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, ctx); - Env.getCurrentEnv().createDb(createDbStmt); - // create table tbl1 - String createTblStmtStr = "create table db1.tbl1(k1 int, k2 varchar(32), v bigint sum) " - + "AGGREGATE KEY(k1,k2) distributed by hash(k1) buckets 1 properties('replication_num' = '1');"; - CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx); - Env.getCurrentEnv().createTable(createTableStmt); - // create table tbl2 - createTblStmtStr = "create table db1.tbl2(k3 int, k4 varchar(32)) " - + "DUPLICATE KEY(k3) distributed by hash(k3) buckets 1 properties('replication_num' = '1');"; - createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx); - Env.getCurrentEnv().createTable(createTableStmt); - } - - @After - public void tearDown() throws Exception { - FileUtils.deleteDirectory(new File(runningDir)); - } - - @Test - public void testAssertFragmentWithDistributedInput(@Injectable AssertNumRowsNode assertNumRowsNode, - @Injectable PlanFragment inputFragment, - @Injectable PlanNodeId planNodeId, - @Injectable PlanFragmentId planFragmentId, - @Injectable PlanNode inputPlanRoot, - @Injectable TupleId tupleId, - @Mocked PlannerContext plannerContext) { - DistributedPlanner distributedPlanner = new DistributedPlanner(plannerContext); - - List tupleIdList = Lists.newArrayList(tupleId); - Set tupleIdSet = Sets.newHashSet(tupleId); - Deencapsulation.setField(inputPlanRoot, "tupleIds", tupleIdList); - Deencapsulation.setField(inputPlanRoot, "tblRefIds", tupleIdList); - Deencapsulation.setField(inputPlanRoot, "nullableTupleIds", Sets.newHashSet(tupleId)); - Deencapsulation.setField(inputPlanRoot, "conjuncts", Lists.newArrayList()); - new Expectations() { - { - inputPlanRoot.getOutputTupleDesc(); - result = null; - inputFragment.isPartitioned(); - result = true; - plannerContext.getNextNodeId(); - result = planNodeId; - plannerContext.getNextFragmentId(); - result = planFragmentId; - inputFragment.getPlanRoot(); - result = inputPlanRoot; - inputPlanRoot.getTupleIds(); - result = tupleIdList; - inputPlanRoot.getTblRefIds(); - result = tupleIdList; - inputPlanRoot.getNullableTupleIds(); - result = tupleIdSet; - assertNumRowsNode.getChildren(); - result = inputPlanRoot; - } - }; - - PlanFragment assertFragment = Deencapsulation.invoke(distributedPlanner, "createAssertFragment", - assertNumRowsNode, inputFragment); - Assert.assertFalse(assertFragment.isPartitioned()); - Assert.assertSame(assertNumRowsNode, assertFragment.getPlanRoot()); - } - - @Test - public void testAssertFragmentWithUnpartitionInput(@Injectable AssertNumRowsNode assertNumRowsNode, - @Injectable PlanFragment inputFragment, - @Mocked PlannerContext plannerContext) { - DistributedPlanner distributedPlanner = new DistributedPlanner(plannerContext); - - PlanFragment assertFragment = Deencapsulation.invoke(distributedPlanner, "createAssertFragment", - assertNumRowsNode, inputFragment); - Assert.assertSame(assertFragment, inputFragment); - Assert.assertTrue(assertFragment.getPlanRoot() instanceof AssertNumRowsNode); - } - - @Test - public void testExplicitlyBroadcastJoin() throws Exception { - String sql = "explain select * from db1.tbl1 join [BROADCAST] db1.tbl2 on tbl1.k1 = tbl2.k3"; - StmtExecutor stmtExecutor = new StmtExecutor(ctx, sql); - stmtExecutor.execute(); - Planner planner = stmtExecutor.planner(); - String plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assert.assertEquals(1, StringUtils.countMatches(plan, "INNER JOIN(BROADCAST)")); - - sql = "explain select * from db1.tbl1 join [SHUFFLE] db1.tbl2 on tbl1.k1 = tbl2.k3"; - stmtExecutor = new StmtExecutor(ctx, sql); - stmtExecutor.execute(); - planner = stmtExecutor.planner(); - plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assert.assertEquals(1, StringUtils.countMatches(plan, "INNER JOIN(PARTITIONED)")); - } - - @Test - public void testBroadcastJoinCostThreshold() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1 join db1.tbl2 on tbl1.k1 = tbl2.k3"; - StmtExecutor stmtExecutor = new StmtExecutor(ctx, sql); - stmtExecutor.execute(); - Planner planner = stmtExecutor.planner(); - String plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assert.assertEquals(1, StringUtils.countMatches(plan, "INNER JOIN(BROADCAST)")); - - double originThreshold = ctx.getSessionVariable().autoBroadcastJoinThreshold; - try { - ctx.getSessionVariable().autoBroadcastJoinThreshold = -1.0; - stmtExecutor = new StmtExecutor(ctx, sql); - stmtExecutor.execute(); - planner = stmtExecutor.planner(); - plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assert.assertEquals(1, StringUtils.countMatches(plan, "INNER JOIN(PARTITIONED)")); - } finally { - ctx.getSessionVariable().autoBroadcastJoinThreshold = originThreshold; - } - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java deleted file mode 100644 index 573a19bd9dbd96d..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java +++ /dev/null @@ -1,734 +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.doris.planner; - -import org.apache.doris.analysis.ExplainOptions; -import org.apache.doris.analysis.Expr; -import org.apache.doris.analysis.UserIdentity; -import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.FeConstants; -import org.apache.doris.qe.QueryState; -import org.apache.doris.qe.QueryState.MysqlStateType; -import org.apache.doris.qe.StmtExecutor; -import org.apache.doris.utframe.TestWithFeService; - -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; - -public class PlannerTest extends TestWithFeService { - - @Override - protected void runBeforeAll() throws Exception { - - connectContext.getSessionVariable().setEnableNereidsPlanner(false); - - // Create database `db1`. - createDatabase("db1"); - - // Create tables. - String tbl1 = "create table db1.tbl1(" + "k1 varchar(32), " + "k2 varchar(32), " + "k3 varchar(32), " - + "k4 int) " + "AGGREGATE KEY(k1, k2,k3,k4) " + "distributed by hash(k1) buckets 3 " - + "properties('replication_num' = '1');"; - - String tbl2 = "create table db1.tbl2(" + "k1 int, " + "k2 int sum) " + "AGGREGATE KEY(k1) " - + "partition by range(k1) () " + "distributed by hash(k1) buckets 3 " - + "properties('replication_num' = '1');"; - - String tbl3 = "create table db1.tbl3 (" + "k1 date, " + "k2 varchar(128) NULL, " + "k3 varchar(5000) NULL) " - + "DUPLICATE KEY(k1, k2, k3) " + "distributed by hash(k1) buckets 1 " - + "properties ('replication_num' = '1');"; - - String tbl4 = "create table db1.tbl4(" + "k1 int," + " k2 int," + " v1 int)" + " distributed by hash(k1)" - + " properties('replication_num' = '1');"; - - String tbl5 = "create table db1.tbl5(" + "k1 int," + "k2 int) " + "DISTRIBUTED BY HASH(k2) " - + "BUCKETS 3 PROPERTIES ('replication_num' = '1');"; - - String tbl6 = "create table db1.tbl6(" + "k1 int," + "k2 int, " + "v1 int)" + "UNIQUE KEY (k1, k2)" - + "DISTRIBUTED BY HASH(k2) " + "BUCKETS 3 PROPERTIES ('replication_num' = '1');"; - - createTables(tbl1, tbl2, tbl3, tbl4, tbl5, tbl6); - } - - @Test - public void testSetOperation() throws Exception { - // union - String sql1 = "explain select * from\n" - + " (select k1, k2 from db1.tbl1\n" - + " union all\n" - + " select k1, k2 from db1.tbl1) a\n" - + " inner join\n" - + " db1.tbl1 b\n" - + " on (a.k1 = b.k1)\n" - + "where b.k1 = 'a'"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(1, StringUtils.countMatches(plan1, "UNION")); - String sql2 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1 where k1='a' and k4=1\n" - + "union distinct\n" - + " (select * from db1.tbl1 where k1='b' and k4=2\n" - + " union all\n" - + " select * from db1.tbl1 where k1='b' and k4=2)\n" - + "union distinct\n" - + " (select * from db1.tbl1 where k1='b' and k4=2\n" - + " union all\n" - + " (select * from db1.tbl1 where k1='b' and k4=3)\n" - + " order by 3 limit 3)\n" - + "union all\n" - + " (select * from db1.tbl1 where k1='b' and k4=3\n" - + " union all\n" - + " select * from db1.tbl1 where k1='b' and k4=4)\n" - + "union all\n" - + " (select * from db1.tbl1 where k1='b' and k4=3\n" - + " union all\n" - + " (select * from db1.tbl1 where k1='b' and k4=5)\n" - + " order by 3 limit 3)"; - StmtExecutor stmtExecutor2 = new StmtExecutor(connectContext, sql2); - stmtExecutor2.execute(); - Planner planner2 = stmtExecutor2.planner(); - String plan2 = planner2.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(4, StringUtils.countMatches(plan2, "UNION")); - - // intersect - String sql3 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from\n" - + " (select k1, k2 from db1.tbl1\n" - + " intersect\n" - + " select k1, k2 from db1.tbl1) a\n" - + " inner join\n" - + " db1.tbl1 b\n" - + " on (a.k1 = b.k1)\n" - + "where b.k1 = 'a'"; - StmtExecutor stmtExecutor3 = new StmtExecutor(connectContext, sql3); - stmtExecutor3.execute(); - Planner planner3 = stmtExecutor3.planner(); - String plan3 = planner3.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(1, StringUtils.countMatches(plan3, "INTERSECT")); - String sql4 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1 where k1='a' and k4=1\n" - + "intersect distinct\n" - + " (select * from db1.tbl1 where k1='b' and k4=2\n" - + " intersect\n" - + " select * from db1.tbl1 where k1='b' and k4=2)\n" - + "intersect distinct\n" - + " (select * from db1.tbl1 where k1='b' and k4=2\n" - + " intersect\n" - + " (select * from db1.tbl1 where k1='b' and k4=3)\n" - + " order by 3 limit 3)\n" - + "intersect\n" - + " (select * from db1.tbl1 where k1='b' and k4=3\n" - + " intersect\n" - + " select * from db1.tbl1 where k1='b' and k4=4)\n" - + "intersect\n" - + " (select * from db1.tbl1 where k1='b' and k4=3\n" - + " intersect\n" - + " (select * from db1.tbl1 where k1='b' and k4=5)\n" - + " order by 3 limit 3)"; - - StmtExecutor stmtExecutor4 = new StmtExecutor(connectContext, sql4); - stmtExecutor4.execute(); - Planner planner4 = stmtExecutor4.planner(); - String plan4 = planner4.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(3, StringUtils.countMatches(plan4, "INTERSECT")); - - // except - String sql5 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from\n" - + " (select k1, k2 from db1.tbl1\n" - + " except\n" - + " select k1, k2 from db1.tbl1) a\n" - + " inner join\n" - + " db1.tbl1 b\n" - + " on (a.k1 = b.k1)\n" - + "where b.k1 = 'a'"; - StmtExecutor stmtExecutor5 = new StmtExecutor(connectContext, sql5); - stmtExecutor5.execute(); - Planner planner5 = stmtExecutor5.planner(); - String plan5 = planner5.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(1, StringUtils.countMatches(plan5, "EXCEPT")); - - String sql6 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1 where k1='a' and k4=1\n" - + "except\n" - + "select * from db1.tbl1 where k1='a' and k4=1\n" - + "except\n" - + "select * from db1.tbl1 where k1='a' and k4=2\n" - + "except distinct\n" - + "(select * from db1.tbl1 where k1='a' and k4=2)\n" - + "order by 3 limit 3"; - StmtExecutor stmtExecutor6 = new StmtExecutor(connectContext, sql6); - stmtExecutor6.execute(); - Planner planner6 = stmtExecutor6.planner(); - String plan6 = planner6.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(1, StringUtils.countMatches(plan6, "EXCEPT")); - - String sql7 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1 where k1='a' and k4=1\n" - + "except distinct\n" - + "select * from db1.tbl1 where k1='a' and k4=1\n" - + "except\n" - + "select * from db1.tbl1 where k1='a' and k4=2\n" - + "except\n" - + "(select * from db1.tbl1 where k1='a' and k4=2)\n" - + "order by 3 limit 3"; - StmtExecutor stmtExecutor7 = new StmtExecutor(connectContext, sql7); - stmtExecutor7.execute(); - Planner planner7 = stmtExecutor7.planner(); - String plan7 = planner7.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(1, StringUtils.countMatches(plan7, "EXCEPT")); - - // mixed - String sql8 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1 where k1='a' and k4=1\n" - + "union\n" - + "select * from db1.tbl1 where k1='a' and k4=1\n" - + "except\n" - + "select * from db1.tbl1 where k1='a' and k4=2\n" - + "intersect\n" - + "(select * from db1.tbl1 where k1='a' and k4=2)\n" - + "order by 3 limit 3"; - StmtExecutor stmtExecutor8 = new StmtExecutor(connectContext, sql8); - stmtExecutor8.execute(); - Planner planner8 = stmtExecutor8.planner(); - String plan8 = planner8.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(1, StringUtils.countMatches(plan8, "UNION")); - Assertions.assertEquals(1, StringUtils.countMatches(plan8, "INTERSECT")); - Assertions.assertEquals(1, StringUtils.countMatches(plan8, "EXCEPT")); - - String sql9 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1 where k1='a' and k4=1\n" - + "intersect distinct\n" - + " (select * from db1.tbl1 where k1='b' and k4=2\n" - + " union all\n" - + " select * from db1.tbl1 where k1='b' and k4=2)\n" - + "intersect distinct\n" - + " (select * from db1.tbl1 where k1='b' and k4=2\n" - + " except\n" - + " (select * from db1.tbl1 where k1='b' and k4=3)\n" - + " order by 3 limit 3)\n" - + "union all\n" - + " (select * from db1.tbl1 where k1='b' and k4=3\n" - + " intersect\n" - + " select * from db1.tbl1 where k1='b' and k4=4)\n" - + "except\n" - + " (select * from db1.tbl1 where k1='b' and k4=3\n" - + " intersect\n" - + " (select * from db1.tbl1 where k1='b' and k4=5)\n" - + " order by 3 limit 3)"; - - StmtExecutor stmtExecutor9 = new StmtExecutor(connectContext, sql9); - stmtExecutor9.execute(); - Planner planner9 = stmtExecutor9.planner(); - String plan9 = planner9.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertEquals(2, StringUtils.countMatches(plan9, "UNION")); - Assertions.assertEquals(3, StringUtils.countMatches(plan9, "INTERSECT")); - Assertions.assertEquals(2, StringUtils.countMatches(plan9, "EXCEPT")); - - String sql10 = "select /*+ SET_VAR(enable_nereids_planner=false) */ 499 union select 670 except select 499"; - StmtExecutor stmtExecutor10 = new StmtExecutor(connectContext, sql10); - stmtExecutor10.execute(); - Planner planner10 = stmtExecutor10.planner(); - List fragments10 = planner10.getFragments(); - Assertions.assertTrue(fragments10.get(0).getPlanRoot().getFragment() - .getPlanRoot().getChild(0) instanceof AggregationNode); - Assertions.assertTrue(fragments10.get(0).getPlanRoot() - .getFragment().getPlanRoot().getChild(1) instanceof UnionNode); - - String sql11 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.x FROM\n" - + "(SELECT '01' x) a \n" - + "INNER JOIN\n" - + "(SELECT '01' x UNION all SELECT '02') b"; - StmtExecutor stmtExecutor11 = new StmtExecutor(connectContext, sql11); - stmtExecutor11.execute(); - Planner planner11 = stmtExecutor11.planner(); - SetOperationNode setNode11 = (SetOperationNode) (planner11.getFragments().get(1).getPlanRoot()); - Assertions.assertEquals(2, setNode11.getMaterializedConstExprLists().size()); - - String sql12 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.x \n" - + "FROM (SELECT '01' x) a \n" - + "INNER JOIN \n" - + "(SELECT k1 from db1.tbl1 \n" - + "UNION all \n" - + "SELECT k1 from db1.tbl1) b;"; - StmtExecutor stmtExecutor12 = new StmtExecutor(connectContext, sql12); - stmtExecutor12.execute(); - Planner planner12 = stmtExecutor12.planner(); - SetOperationNode setNode12 = (SetOperationNode) (planner12.getFragments().get(1).getPlanRoot()); - Assertions.assertEquals(2, setNode12.getMaterializedResultExprLists().size()); - } - - @Test - public void testPushDown() throws Exception { - String sql1 = - "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ \n" - + " IF(k2 IS NULL, 'ALL', k2) AS k2,\n" - + " IF(k3 IS NULL, 'ALL', k3) AS k3,\n" - + " k4\n" - + "FROM\n" - + "(\n" - + " SELECT\n" - + " k1,\n" - + " k2,\n" - + " k3,\n" - + " SUM(k4) AS k4\n" - + " FROM db1.tbl1\n" - + " WHERE k1 = 0\n" - + " AND k4 = 1\n" - + " AND k3 = 'foo'\n" - + " GROUP BY \n" - + " GROUPING SETS (\n" - + " (k1),\n" - + " (k1, k2),\n" - + " (k1, k3),\n" - + " (k1, k2, k3)\n" - + " )\n" - + ") t\n" - + "WHERE IF(k2 IS NULL, 'ALL', k2) = 'ALL'"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - List fragments1 = planner1.getFragments(); - Assertions.assertEquals("if", - fragments1.get(0).getPlanRoot().conjuncts.get(0).getChild(0).getFn().functionName()); - Assertions.assertEquals(3, fragments1.get(0).getPlanRoot().getChild(0).getChild(0).conjuncts.size()); - - String sql2 = - "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ \n" - + " IF(k2 IS NULL, 'ALL', k2) AS k2,\n" - + " IF(k3 IS NULL, 'ALL', k3) AS k3,\n" - + " k4\n" - + "FROM\n" - + "(\n" - + " SELECT\n" - + " k1,\n" - + " k2,\n" - + " k3,\n" - + " SUM(k4) AS k4\n" - + " FROM db1.tbl1\n" - + " WHERE k1 = 0\n" - + " AND k4 = 1\n" - + " AND k3 = 'foo'\n" - + " GROUP BY k1, k2, k3\n" - + ") t\n" - + "WHERE IF(k2 IS NULL, 'ALL', k2) = 'ALL'"; - StmtExecutor stmtExecutor2 = new StmtExecutor(connectContext, sql2); - stmtExecutor2.execute(); - Planner planner2 = stmtExecutor2.planner(); - List fragments2 = planner2.getFragments(); - Assertions.assertEquals(4, fragments2.get(0).getPlanRoot().getChild(0).conjuncts.size()); - - } - - @Test - public void testWithStmtSlotIsAllowNull() throws Exception { - // union - String sql1 = "with a as (select NULL as user_id ), " - + "b as ( select '543' as user_id) " - + "select /*+ SET_VAR(enable_nereids_planner=false) */ user_id from a union all select user_id from b"; - - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(true, false, false)); - Assertions.assertEquals(2, StringUtils.countMatches(plan1, "nullable=true")); - } - - @Test - public void testAccessingVisibleColumnWithoutPartition() throws Exception { - String sql = "select count(k1) from db1.tbl2"; - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql); - stmtExecutor.execute(); - Assertions.assertNotNull(stmtExecutor.planner()); - } - - @Test - public void testAnalyticSortNodeLeftJoin() throws Exception { - String sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.k1, a.k3, SUM(COUNT(t.k2)) OVER (PARTITION BY a.k3 ORDER BY a.k1) AS c\n" - + "FROM ( SELECT k1, k3 FROM db1.tbl3) a\n" - + "LEFT JOIN (SELECT 1 AS line, k1, k2, k3 FROM db1.tbl3) t\n" - + "ON t.k1 = a.k1 AND t.k3 = a.k3\n" - + "GROUP BY a.k1, a.k3"; - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql); - stmtExecutor.execute(); - Assertions.assertNotNull(stmtExecutor.planner()); - Planner planner = stmtExecutor.planner(); - List fragments = planner.getFragments(); - Assertions.assertTrue(fragments.size() > 0); - PlanNode node = fragments.get(0).getPlanRoot().getChild(0); - Assertions.assertTrue(node.getChildren().size() > 0); - Assertions.assertTrue(node instanceof SortNode); - SortNode sortNode = (SortNode) node; - List tupleExprs = sortNode.resolvedTupleExprs; - List sortTupleExprs = sortNode.getSortInfo().getSortTupleSlotExprs(); - for (Expr expr : tupleExprs) { - expr.isBoundByTupleIds(sortNode.getChild(0).tupleIds); - } - for (Expr expr : sortTupleExprs) { - expr.isBoundByTupleIds(sortNode.getChild(0).tupleIds); - } - } - - - @Test - public void testBigintSlotRefCompareDecimalLiteral() { - java.util.function.BiConsumer compare = (sql1, sql2) -> { - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - try { - stmtExecutor1.execute(); - } catch (Exception e) { - e.printStackTrace(); - } - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - - StmtExecutor stmtExecutor2 = new StmtExecutor(connectContext, sql2); - try { - stmtExecutor2.execute(); - } catch (Exception e) { - e.printStackTrace(); - } - Planner planner2 = stmtExecutor2.planner(); - String plan2 = planner2.getExplainString(new ExplainOptions(false, false, false)); - - Assertions.assertEquals(plan1, plan2); - }; - - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl2 where k1 = 2.0", "select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl2 where k1 = 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl2 where k1 = 2.1", "select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl2 where 2 = 2.1"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 != 2.0", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 != 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 != 2.1", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where TRUE"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 <= 2.0", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 <= 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 <= 2.1", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 <= 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 >= 2.0", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 >= 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 >= 2.1", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 > 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 < 2.0", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 < 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 < 2.1", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 <= 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 > 2.0", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 > 2"); - compare.accept("select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 > 2.1", "select /*+ SET_VAR(enable_nereids_planner=false) */* from db1.tbl2 where k1 > 2"); - } - - @Test - public void testStringType() { - String createTbl1 = "create table db1.tbl1(k1 string, k2 varchar(32), k3 varchar(32), k4 int) " - + "AGGREGATE KEY(k1, k2,k3,k4) distributed by hash(k1) buckets 3 properties('replication_num' = '1')"; - AnalysisException exception = Assertions.assertThrows( - AnalysisException.class, () -> parseAndAnalyzeStmt(createTbl1)); - Assertions.assertTrue(exception.getMessage().contains("String Type should not be used in key column[k1].")); - } - - @Test - public void testPushDownPredicateOnGroupingSetAggregate() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1, k2, count(distinct v1) from db1.tbl4" - + " group by grouping sets((k1), (k1, k2)) having k1 = 1 and k2 = 1"; - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql); - stmtExecutor.execute(); - Planner planner = stmtExecutor.planner(); - String plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan.contains("`k1` = 1")); - } - - @Test - public void testPushDownPredicateOnRollupAggregate() throws Exception { - String sql = "explain select k1, k2, count(distinct v1) from db1.tbl4" - + " group by rollup(k1, k2) having k1 = 1 and k2 = 1"; - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql); - stmtExecutor.execute(); - Planner planner = stmtExecutor.planner(); - String plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan.contains("PREDICATES:")); - } - - @Test - public void testPushDownPredicateOnNormalAggregate() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1, k2, count(distinct v1) from db1.tbl4" - + " group by k1, k2 having k1 = 1 and k2 = 1"; - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql); - stmtExecutor.execute(); - Planner planner = stmtExecutor.planner(); - String plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan.contains("(`k1` = 1) AND (`k2` = 1)")); - } - - @Test - public void testPushDownPredicateOnWindowFunction() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ v1, k1," - + " sum(v1) over (partition by k1 order by v1 rows between 1 preceding and 1 following)" - + " as 'moving total' from db1.tbl4 where k1 = 1"; - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql); - stmtExecutor.execute(); - Planner planner = stmtExecutor.planner(); - String plan = planner.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan.contains("`k1` = 1")); - } - - @Test - public void testRewriteNestedUnionStmt() throws Exception { - String qSQL = "SELECT k1 FROM db1.tbl5 WHERE k1 IN " - + "( SELECT k1 FROM ( SELECT k1 FROM db1.tbl5 ORDER BY k2 DESC, k1 DESC LIMIT 300 INTERSECT " - + "(SELECT k1 FROM db1.tbl5 ORDER BY k2 DESC, k1 DESC LIMIT 9 EXCEPT SELECT k1 " - + "FROM db1.tbl5 ORDER BY k2 DESC, k1 DESC LIMIT 2) ) t )"; - - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, qSQL); - stmtExecutor.execute(); - } - - @Test - public void testUpdateUnique() throws Exception { - String qSQL = "update db1.tbl6 set v1=5 where k1=5"; - UserIdentity user1 = new UserIdentity("cmy", "%"); - user1.setIsAnalyzed(); - // check user priv - connectContext.setCurrentUserIdentity(user1); - StmtExecutor stmtExecutor = new StmtExecutor(connectContext, qSQL); - stmtExecutor.execute(); - QueryState state = connectContext.getState(); - Assertions.assertEquals(MysqlStateType.ERR, state.getStateType()); - Assertions.assertTrue(state.getErrorMessage() - .contains("you need (at least one of) the (LOAD) privilege(s) for this operation")); - // set to admin user - connectContext.setCurrentUserIdentity(UserIdentity.ADMIN); - } - - @Test - public void testPushSortToOlapScan() throws Exception { - // Push sort fail without limit - String sql1 = "explain select k1 from db1.tbl3 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("SORT INFO:\n `k1`\n `k2`")); - Assertions.assertFalse(plan1.contains("SORT LIMIT:")); - - // Push sort fail limit > topnOptLimitThreshold - sql1 = "explain select k1 from db1.tbl3 order by k1, k2 limit " - + (connectContext.getSessionVariable().topnOptLimitThreshold + 1); - stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - planner1 = stmtExecutor1.planner(); - plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("SORT INFO:\n `k1`\n `k2`")); - Assertions.assertFalse(plan1.contains("SORT LIMIT:")); - - // Push sort success limit = topnOptLimitThreshold - sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl3 order by k1, k2 limit " - + (connectContext.getSessionVariable().topnOptLimitThreshold); - stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - planner1 = stmtExecutor1.planner(); - plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("SORT INFO:\n `k1`\n `k2`")); - Assertions.assertTrue(plan1.contains("SORT LIMIT:")); - - // Push sort success limit < topnOptLimitThreshold - if (connectContext.getSessionVariable().topnOptLimitThreshold > 1) { - sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl3 order by k1, k2 limit " - + (connectContext.getSessionVariable().topnOptLimitThreshold - 1); - stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - planner1 = stmtExecutor1.planner(); - plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("SORT INFO:\n `k1`\n `k2`")); - Assertions.assertTrue(plan1.contains("SORT LIMIT:")); - } - - // Push sort failed - String sql2 = "explain select k1, k2, k3 from db1.tbl3 order by k1, k3, k2"; - StmtExecutor stmtExecutor2 = new StmtExecutor(connectContext, sql2); - stmtExecutor2.execute(); - Planner planner2 = stmtExecutor2.planner(); - String plan2 = planner2.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan2.contains("SORT INFO:")); - Assertions.assertFalse(plan2.contains("SORT LIMIT:")); - } - - @Test - public void testEliminatingSortNode() throws Exception { - // fail case 1 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 = 1 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("order by:")); - } - - // fail case 2 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 = 1 and k3 = 2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("order by:")); - } - - // fail case 3 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 = 1 and k2 != 2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("order by:")); - } - - // fail case 4 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 = 1 or k2 = 2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("order by:")); - } - - // fail case 5 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 = 1 and k2 = 2 or k3 = 3 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("order by:")); - } - - // fail case 6 - // TODO, support: in (select 1) - { - String sql1 = "explain select k1 from db1.tbl1 where k1 in (select 1) and k2 = 2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("order by:")); - } - - // fail case 7 - { - String sql1 = "explain select k1 from db1.tbl1 where k1 not in (1) and k2 = 2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("order by:")); - } - - // success case 1 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 = 1 and k2 = 2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("order by:")); - } - - // success case 2 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k3 = 3 and k2 = 2 and k1 = 1 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("order by:")); - } - - // success case 3 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 in (1) and k2 in (2) and k2 !=2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("order by:")); - } - - // success case 4 - { - String sql1 = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where k1 in (concat('1','2')) and k2 = 2 order by k1, k2"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("order by:")); - } - - // success case 5 - { - String sql1 = "explain select tbl1.k1 from db1.tbl1 join db1.tbl2 on tbl1.k1 = tbl2.k1" - + " where tbl1.k1 = 1 and tbl2.k1 = 2 and tbl1.k2 = 3 order by tbl1.k1, tbl2.k1"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("order by:")); - } - } - - @Test - public void testInsertPlan() throws Exception { - FeConstants.runningUnitTest = true; - // 1. should not contains exchange node in old planner - boolean v = connectContext.getSessionVariable().isEnableNereidsPlanner(); - try { - connectContext.getSessionVariable().setEnableNereidsPlanner(false); - String sql1 = "explain insert into db1.tbl1 select * from db1.tbl1"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("VEXCHANGE")); - } finally { - connectContext.getSessionVariable().setEnableNereidsPlanner(v); - } - - // 2. should not contains exchange node in new planner - v = connectContext.getSessionVariable().isEnableNereidsPlanner(); - boolean v2 = connectContext.getSessionVariable().isEnableStrictConsistencyDml(); - try { - connectContext.getSessionVariable().setEnableNereidsPlanner(true); - connectContext.getSessionVariable().setEnableStrictConsistencyDml(false); - String sql1 = "explain insert into db1.tbl1 select * from db1.tbl1"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertFalse(plan1.contains("VEXCHANGE")); - } finally { - connectContext.getSessionVariable().setEnableNereidsPlanner(v); - connectContext.getSessionVariable().setEnableStrictConsistencyDml(v2); - } - - // 3. should contain exchange node in new planner if enable strict consistency dml - v = connectContext.getSessionVariable().isEnableNereidsPlanner(); - v2 = connectContext.getSessionVariable().isEnableStrictConsistencyDml(); - try { - connectContext.getSessionVariable().setEnableNereidsPlanner(true); - connectContext.getSessionVariable().setEnableStrictConsistencyDml(true); - String sql1 = "explain insert into db1.tbl1 select * from db1.tbl1"; - StmtExecutor stmtExecutor1 = new StmtExecutor(connectContext, sql1); - stmtExecutor1.execute(); - Planner planner1 = stmtExecutor1.planner(); - String plan1 = planner1.getExplainString(new ExplainOptions(false, false, false)); - Assertions.assertTrue(plan1.contains("VEXCHANGE")); - } finally { - connectContext.getSessionVariable().setEnableNereidsPlanner(v); - connectContext.getSessionVariable().setEnableStrictConsistencyDml(v2); - } - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java deleted file mode 100644 index 53198a63b15dfc9..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/ProjectPlannerFunctionTest.java +++ /dev/null @@ -1,111 +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.doris.planner; - -import org.apache.doris.analysis.CreateDbStmt; -import org.apache.doris.analysis.CreateTableStmt; -import org.apache.doris.catalog.Env; -import org.apache.doris.common.jmockit.Deencapsulation; -import org.apache.doris.qe.ConnectContext; -import org.apache.doris.utframe.UtFrameUtils; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.UUID; - -public class ProjectPlannerFunctionTest { - - private static String runningDir = "fe/mocked/ProjectPlannerFunctionTest/" + UUID.randomUUID().toString() + "/"; - - private static ConnectContext connectContext; - - @BeforeClass - public static void beforeClass() throws Exception { - UtFrameUtils.createDorisCluster(runningDir); - - // create connect context - connectContext = UtFrameUtils.createDefaultCtx(); - - // enable hash project - Deencapsulation.setField(connectContext.getSessionVariable(), "enableProjection", true); - - // create database - String createDbStmtStr = "create database test;"; - CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, connectContext); - Env.getCurrentEnv().createDb(createDbStmt); - String createTableStmtStr = "create table test.t1 (k1 int, k2 int) distributed by hash (k1) " - + "properties(\"replication_num\" = \"1\")"; - CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTableStmtStr, connectContext); - Env.getCurrentEnv().createTable(createTableStmt); - } - - @AfterClass - public static void tearDown() { - File file = new File(runningDir); - file.delete(); - } - - // keep a.k2 after a join b - @Test - public void projectByAgg() throws Exception { - String queryStr = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ a.k2 from test.t1 a , test.t1 b where a.k1=b.k1 group by a.k2;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr); - Assert.assertTrue(explainString.contains("output slot ids: 0")); - } - - // keep a.k2 after a join b - @Test - public void projectBySort() throws Exception { - String queryStr = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ a.k2 from test.t1 a , test.t1 b where a.k1=b.k1 order by a.k2;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr); - Assert.assertTrue(explainString.contains("output slot ids: 0")); - } - - // keep a.k2 after a join c - // keep a.k1, a.k2 after a join b - @Test - public void projectByJoin() throws Exception { - String queryStr = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ a.k2 from test.t1 a inner join test.t1 b on a.k1=b.k1 " - + "inner join test.t1 c on a.k1=c.k1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr); - Assert.assertTrue(explainString.contains("output slot ids: 8")); - Assert.assertTrue(explainString.contains("output slot ids: 4 5")); - } - - // keep a.k2 after a join b - @Test - public void projectByResultExprs() throws Exception { - String queryStr = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ a.k2 from test.t1 a , test.t1 b where a.k1=b.k1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr); - Assert.assertTrue(explainString.contains("output slot ids: 0")); - } - - // keep b.k1 after a join b - // keep a.k2, b.k1, b.k2 after hash table - @Test - public void projectHashTable() throws Exception { - String queryStr = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ b.k1 from test.t1 a right join test.t1 b on a.k1=b.k1 and b.k2>1 where a.k2>1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr); - Assert.assertTrue(explainString.contains("output slot ids: 1")); - Assert.assertTrue(explainString.contains("hash output slot ids: 1 2 3")); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryCacheNormalizerTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryCacheNormalizerTest.java index 829d1b0d1e507c6..cecd752644018d1 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryCacheNormalizerTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryCacheNormalizerTest.java @@ -44,8 +44,6 @@ public class QueryCacheNormalizerTest extends TestWithFeService { @Override protected void runBeforeAll() throws Exception { - connectContext.getSessionVariable().setEnableNereidsPlanner(true); - // Create database `db1`. createDatabase("db1"); @@ -114,7 +112,6 @@ protected void runBeforeAll() throws Exception { createTables(nonPart, part1, part2, multiLeveParts); - connectContext.getSessionVariable().setEnableNereidsPlanner(true); connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION"); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java deleted file mode 100644 index 36194494ee1da23..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java +++ /dev/null @@ -1,2300 +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.doris.planner; - -import org.apache.doris.analysis.Analyzer; -import org.apache.doris.analysis.CreateDbStmt; -import org.apache.doris.analysis.DropDbStmt; -import org.apache.doris.analysis.ExplainTest; -import org.apache.doris.analysis.Expr; -import org.apache.doris.analysis.InformationFunction; -import org.apache.doris.analysis.SelectStmt; -import org.apache.doris.analysis.ShowCreateDbStmt; -import org.apache.doris.analysis.StatementBase; -import org.apache.doris.catalog.Database; -import org.apache.doris.catalog.Env; -import org.apache.doris.catalog.MaterializedIndex; -import org.apache.doris.catalog.MaterializedIndex.IndexExtState; -import org.apache.doris.catalog.OlapTable; -import org.apache.doris.catalog.Partition; -import org.apache.doris.catalog.Replica; -import org.apache.doris.catalog.ScalarType; -import org.apache.doris.catalog.Tablet; -import org.apache.doris.catalog.Type; -import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.Config; -import org.apache.doris.common.FeConstants; -import org.apache.doris.common.jmockit.Deencapsulation; -import org.apache.doris.qe.ConnectContext; -import org.apache.doris.qe.QueryState.MysqlStateType; -import org.apache.doris.rewrite.RewriteDateLiteralRuleTest; -import org.apache.doris.thrift.TRuntimeFilterType; -import org.apache.doris.utframe.TestWithFeService; -import org.apache.doris.utframe.UtFrameUtils; - -import com.google.common.collect.Lists; -import org.apache.commons.lang3.StringUtils; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.util.List; - -public class QueryPlanTest extends TestWithFeService { - - @Override - protected void runBeforeAll() throws Exception { - FeConstants.runningUnitTest = true; - // disable bucket shuffle join - Deencapsulation.setField(connectContext.getSessionVariable(), "enableBucketShuffleJoin", false); - connectContext.getSessionVariable().setEnableRuntimeFilterPrune(false); - // create database - createDatabase("test"); - connectContext.getSessionVariable().setEnableNereidsPlanner(false); - connectContext.getSessionVariable().setEnableFoldConstantByBe(false); - Config.enable_odbc_mysql_broker_table = true; - - createTable("create table test.test1\n" - + "(\n" - + " query_id varchar(48) comment \"Unique query id\",\n" - + " time_col datetime not null comment \"Query start time\",\n" - + " client_ip varchar(32) comment \"Client IP\",\n" - + " user varchar(64) comment \"User name\",\n" - + " db varchar(96) comment \"Database of this query\",\n" - + " state varchar(8) comment \"Query result state. EOF, ERR, OK\",\n" - + " query_time bigint comment \"Query execution time in millisecond\",\n" - + " scan_bytes bigint comment \"Total scan bytes of this query\",\n" - + " scan_rows bigint comment \"Total scan rows of this query\",\n" - + " return_rows bigint comment \"Returned rows of this query\",\n" - + " stmt_id int comment \"An incremental id of statement\",\n" - + " is_query tinyint comment \"Is this statemt a query. 1 or 0\",\n" - + " frontend_ip varchar(32) comment \"Frontend ip of executing this statement\",\n" - + " stmt varchar(2048) comment \"The original statement, trimed if longer than 2048 bytes\"\n" - + ")\n" - + "partition by range(time_col) ()\n" - + "distributed by hash(query_id) buckets 1\n" - + "properties(\n" - + " \"dynamic_partition.time_unit\" = \"DAY\",\n" - + " \"dynamic_partition.start\" = \"-30\",\n" - + " \"dynamic_partition.end\" = \"3\",\n" - + " \"dynamic_partition.prefix\" = \"p\",\n" - + " \"dynamic_partition.buckets\" = \"1\",\n" - + " \"dynamic_partition.enable\" = \"true\",\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.bitmap_table (\n" - + " `id` int(11) NULL COMMENT \"\",\n" - + " `id2` bitmap bitmap_union \n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`id`)\n" - + "DISTRIBUTED BY HASH(`id`) BUCKETS 1\n" - + "PROPERTIES (\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.join1 (\n" - + " `dt` int(11) COMMENT \"\",\n" - + " `id` int(11) COMMENT \"\",\n" - + " `value` varchar(8) COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`dt`, `id`)\n" - + "PARTITION BY RANGE(`dt`)\n" - + "(PARTITION p1 VALUES LESS THAN (\"10\"))\n" - + "DISTRIBUTED BY HASH(`id`) BUCKETS 10\n" - + "PROPERTIES (\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.join2 (\n" - + " `dt` int(11) COMMENT \"\",\n" - + " `id` int(11) COMMENT \"\",\n" - + " `value` varchar(8) COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`dt`, `id`)\n" - + "PARTITION BY RANGE(`dt`)\n" - + "(PARTITION p1 VALUES LESS THAN (\"10\"))\n" - + "DISTRIBUTED BY HASH(`id`) BUCKETS 10\n" - + "PROPERTIES (\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.bitmap_table_2 (\n" - + " `id` int(11) NULL COMMENT \"\",\n" - + " `id2` bitmap bitmap_union ,\n" - + " `id3` bitmap bitmap_union \n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`id`)\n" - + "DISTRIBUTED BY HASH(`id`) BUCKETS 1\n" - + "PROPERTIES (\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.hll_table (\n" - + " `id` int(11) NULL COMMENT \"\",\n" - + " `id2` hll hll_union \n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`id`)\n" - + "DISTRIBUTED BY HASH(`id`) BUCKETS 1\n" - + "PROPERTIES (\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.`bigtable` (\n" - + " `k1` tinyint(4) NULL COMMENT \"\",\n" - + " `k2` smallint(6) NULL COMMENT \"\",\n" - + " `k3` int(11) NULL COMMENT \"\",\n" - + " `k4` bigint(20) NULL COMMENT \"\",\n" - + " `k5` decimal(9, 3) NULL COMMENT \"\",\n" - + " `k6` char(5) NULL COMMENT \"\",\n" - + " `k10` date NULL COMMENT \"\",\n" - + " `k11` datetime NULL COMMENT \"\",\n" - + " `k7` varchar(20) NULL COMMENT \"\",\n" - + " `k8` double MAX NULL COMMENT \"\",\n" - + " `k9` float SUM NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`k1`, `k2`, `k3`, `k4`, `k5`, `k6`, `k10`, `k11`, `k7`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 5\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.`baseall` (\n" - + " `k1` tinyint(4) NULL COMMENT \"\",\n" - + " `k2` smallint(6) NULL COMMENT \"\",\n" - + " `k3` int(11) NULL COMMENT \"\",\n" - + " `k4` bigint(20) NULL COMMENT \"\",\n" - + " `k5` decimal(9, 3) NULL COMMENT \"\",\n" - + " `k6` char(5) NULL COMMENT \"\",\n" - + " `k10` date NULL COMMENT \"\",\n" - + " `k11` datetime NULL COMMENT \"\",\n" - + " `k7` varchar(20) NULL COMMENT \"\",\n" - + " `k8` double MAX NULL COMMENT \"\",\n" - + " `k9` float SUM NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`k1`, `k2`, `k3`, `k4`, `k5`, `k6`, `k10`, `k11`, `k7`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 5\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.`dynamic_partition` (\n" - + " `k1` date NULL COMMENT \"\",\n" - + " `k2` smallint(6) NULL COMMENT \"\",\n" - + " `k3` int(11) NULL COMMENT \"\",\n" - + " `k4` bigint(20) NULL COMMENT \"\",\n" - + " `k5` decimal(9, 3) NULL COMMENT \"\",\n" - + " `k6` char(5) NULL COMMENT \"\",\n" - + " `k10` date NULL COMMENT \"\",\n" - + " `k11` datetime NULL COMMENT \"\",\n" - + " `k7` varchar(20) NULL COMMENT \"\",\n" - + " `k8` double MAX NULL COMMENT \"\",\n" - + " `k9` float SUM NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`k1`, `k2`, `k3`, `k4`, `k5`, `k6`, `k10`, `k11`, `k7`)\n" - + "COMMENT \"OLAP\"\n" - + "PARTITION BY RANGE (k1)\n" - + "(\n" - + "PARTITION p1 VALUES LESS THAN (\"2014-01-01\"),\n" - + "PARTITION p2 VALUES LESS THAN (\"2014-06-01\"),\n" - + "PARTITION p3 VALUES LESS THAN (\"2014-12-01\")\n" - + ")\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 5\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"dynamic_partition.enable\" = \"true\",\n" - + "\"dynamic_partition.start\" = \"-3\",\n" - + "\"dynamic_partition.end\" = \"3\",\n" - + "\"dynamic_partition.time_unit\" = \"day\",\n" - + "\"dynamic_partition.prefix\" = \"p\",\n" - + "\"dynamic_partition.buckets\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.`app_profile` (\n" - + " `event_date` date NOT NULL COMMENT \"\",\n" - + " `app_name` varchar(64) NOT NULL COMMENT \"\",\n" - + " `package_name` varchar(64) NOT NULL COMMENT \"\",\n" - + " `age` varchar(32) NOT NULL COMMENT \"\",\n" - + " `gender` varchar(32) NOT NULL COMMENT \"\",\n" - + " `level` varchar(64) NOT NULL COMMENT \"\",\n" - + " `city` varchar(64) NOT NULL COMMENT \"\",\n" - + " `model` varchar(64) NOT NULL COMMENT \"\",\n" - + " `brand` varchar(64) NOT NULL COMMENT \"\",\n" - + " `hours` varchar(16) NOT NULL COMMENT \"\",\n" - + " `use_num` int(11) SUM NOT NULL COMMENT \"\",\n" - + " `use_time` double SUM NOT NULL COMMENT \"\",\n" - + " `start_times` bigint(20) SUM NOT NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`event_date`, `app_name`, `package_name`, `age`, `gender`, `level`, " - + "`city`, `model`, `brand`, `hours`) COMMENT \"OLAP\"\n" - + "PARTITION BY RANGE(`event_date`)\n" - + "(PARTITION p_20200301 VALUES [('2020-02-27'), ('2020-03-02')),\n" - + "PARTITION p_20200306 VALUES [('2020-03-02'), ('2020-03-07')))\n" - + "DISTRIBUTED BY HASH(`event_date`, `app_name`, `package_name`, `age`, `gender`, `level`, " - + "`city`, `model`, `brand`, `hours`) BUCKETS 1\n" - + "PROPERTIES (\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.`pushdown_test` (\n" - + " `k1` tinyint(4) NULL COMMENT \"\",\n" - + " `k2` smallint(6) NULL COMMENT \"\",\n" - + " `k3` int(11) NULL COMMENT \"\",\n" - + " `k4` bigint(20) NULL COMMENT \"\",\n" - + " `k5` decimal(9, 3) NULL COMMENT \"\",\n" - + " `k6` char(5) NULL COMMENT \"\",\n" - + " `k10` date NULL COMMENT \"\",\n" - + " `k11` datetime NULL COMMENT \"\",\n" - + " `k7` varchar(20) NULL COMMENT \"\",\n" - + " `k8` double MAX NULL COMMENT \"\",\n" - + " `k9` float SUM NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`k1`, `k2`, `k3`, `k4`, `k5`, `k6`, `k10`, `k11`, `k7`)\n" - + "COMMENT \"OLAP\"\n" - + "PARTITION BY RANGE(`k1`)\n" - + "(PARTITION p1 VALUES [(\"-128\"), (\"-64\")),\n" - + "PARTITION p2 VALUES [(\"-64\"), (\"0\")),\n" - + "PARTITION p3 VALUES [(\"0\"), (\"64\")))\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 5\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"DEFAULT\"\n" - + ");"); - - createTable("create table test.jointest\n" - + "(k1 int, k2 int) distributed by hash(k1) buckets 1\n" - + "properties(\"replication_num\" = \"1\");"); - - createTable("create table test.bucket_shuffle1\n" - + "(k1 int, k2 int, k3 int) distributed by hash(k1, k2) buckets 5\n" - + "properties(\"replication_num\" = \"1\"" - + ");"); - - createTable("CREATE TABLE test.`bucket_shuffle2` (\n" - + " `k1` int NULL COMMENT \"\",\n" - + " `k2` int(6) NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "COMMENT \"OLAP\"\n" - + "PARTITION BY RANGE(`k1`)\n" - + "(PARTITION p1 VALUES [(\"-128\"), (\"-64\")),\n" - + "PARTITION p2 VALUES [(\"-64\"), (\"0\")),\n" - + "PARTITION p3 VALUES [(\"0\"), (\"64\")))\n" - + "DISTRIBUTED BY HASH(k1, k2) BUCKETS 5\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"DEFAULT\"\n" - + ");"); - - createTable("create table test.colocate1\n" - + "(k1 int, k2 int, k3 int) distributed by hash(k1, k2) buckets 1\n" - + "properties(\"replication_num\" = \"1\"," - + "\"colocate_with\" = \"group1\");"); - - createTable("create table test.colocate2\n" - + "(k1 int, k2 int, k3 int) distributed by hash(k1, k2) buckets 1\n" - + "properties(\"replication_num\" = \"1\"," - + "\"colocate_with\" = \"group1\");"); - - createTable("create external table test.mysql_table\n" - + "(k1 int, k2 int)\n" - + "ENGINE=MYSQL\n" - + "PROPERTIES (\n" - + "\"host\" = \"127.0.0.1\",\n" - + "\"port\" = \"3306\",\n" - + "\"user\" = \"root\",\n" - + "\"password\" = \"123\",\n" - + "\"database\" = \"db1\",\n" - + "\"table\" = \"tbl1\"\n" - + ");"); - - createTable("CREATE TABLE test.`table_partitioned` (\n" - + " `dt` int(11) NOT NULL COMMENT \"\",\n" - + " `dis_key` varchar(20) NOT NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`dt`, `dis_key`)\n" - + "PARTITION BY RANGE(`dt`)\n" - + "(PARTITION p20200101 VALUES [(\"-1\"), (\"20200101\")),\n" - + "PARTITION p20200201 VALUES [(\"20200101\"), (\"20200201\")))\n" - + "DISTRIBUTED BY HASH(`dt`, `dis_key`) BUCKETS 2\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"\n" - + ");"); - - createTable("CREATE TABLE test.`table_unpartitioned` (\n" - + " `dt` int(11) NOT NULL COMMENT \"\",\n" - + " `dis_key` varchar(20) NOT NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`dt`, `dis_key`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`dt`, `dis_key`) BUCKETS 2\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"\n" - + ");"); - - createTable("create external table test.odbc_oracle\n" - + "(k1 float, k2 int)\n" - + "ENGINE=ODBC\n" - + "PROPERTIES (\n" - + "\"host\" = \"127.0.0.1\",\n" - + "\"port\" = \"3306\",\n" - + "\"user\" = \"root\",\n" - + "\"password\" = \"123\",\n" - + "\"database\" = \"db1\",\n" - + "\"table\" = \"tbl1\",\n" - + "\"driver\" = \"Oracle Driver\",\n" - + "\"odbc_type\" = \"oracle\"\n" - + ");"); - - createTable("create external table test.odbc_mysql\n" - + "(k1 int, k2 int)\n" - + "ENGINE=ODBC\n" - + "PROPERTIES (\n" - + "\"host\" = \"127.0.0.1\",\n" - + "\"port\" = \"3306\",\n" - + "\"user\" = \"root\",\n" - + "\"password\" = \"123\",\n" - + "\"database\" = \"db1\",\n" - + "\"table\" = \"tbl1\",\n" - + "\"driver\" = \"Oracle Driver\",\n" - + "\"odbc_type\" = \"mysql\"\n" - + ");"); - - createTable("create table test.tbl_int_date (" - + "`date` datetime NULL," - + "`day` date NULL," - + "`site_id` int(11) NULL )" - + " ENGINE=OLAP " - + "DUPLICATE KEY(`date`, `day`, `site_id`)" - + "DISTRIBUTED BY HASH(`site_id`) BUCKETS 10 " - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ");"); - - createView("create view test.tbl_null_column_view AS SELECT *,NULL as add_column FROM test.test1;"); - - createView("create view test.function_view AS SELECT query_id, client_ip, concat(user, db) as" - + " concat FROM test.test1;"); - - createTable("create table test.tbl_using_a\n" - + "(\n" - + " k1 int,\n" - + " k2 int,\n" - + " v1 int sum\n" - + ")\n" - + "DISTRIBUTED BY HASH(k1) BUCKETS 3 " - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"" - + ");"); - - createTable("create table test.tbl_using_b\n" - + "(\n" - + " k1 int,\n" - + " k2 int,\n" - + " k3 int \n" - + ")\n" - + "DISTRIBUTED BY HASH(k1) BUCKETS 3 " - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"" - + ");"); - } - - @Test - public void testFunctionViewGroupingSet() throws Exception { - String queryStr = "select /*+ SET_VAR(enable_nereids_planner=false) */ query_id, client_ip, concat from test.function_view group by rollup(" - + "query_id, client_ip, concat);"; - assertSQLPlanOrErrorMsgContains(queryStr, "repeat: repeat 3 lines [[], [8], [8, 9], [8, 9, 10]]"); - } - - @Test - public void testBitmapInsertInto() throws Exception { - String sql = "INSERT INTO test.bitmap_table (id, id2) VALUES (1001, to_bitmap(1000)), (1001, to_bitmap(2000));"; - String explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("OLAP TABLE SINK")); - - sql = "insert into test.bitmap_table select id, bitmap_union(id2) from test.bitmap_table_2 group by id;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("OLAP TABLE SINK")); - Assert.assertTrue(explainString.contains("bitmap_union")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "AGGREGATE")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 0, "OlapScanNode")); - - sql = "insert into test.bitmap_table select /*+ SET_VAR(enable_nereids_planner=false) */ id, id2 from test.bitmap_table_2;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("OLAP TABLE SINK")); - Assert.assertTrue(explainString.contains("OUTPUT EXPRS:\n `id`\n `id2`")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 0, "OlapScanNode")); - - assertSQLPlanOrErrorMsgContains("insert into test.bitmap_table select id, id from test.bitmap_table_2;", - "bitmap column require the function return type is BITMAP"); - } - - @Test - public void testBitmapQuery() throws Exception { - assertSQLPlanOrErrorMsgContains( - "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.bitmap_table;", - "OUTPUT EXPRS:\n `test`.`bitmap_table`.`id`\n `test`.`bitmap_table`.`id2`" - ); - - assertSQLPlanOrErrorMsgContains( - "select count(id2) from test.bitmap_table;", - "No matching function with signature" - ); - - assertSQLPlanOrErrorMsgContains( - "select group_concat(id2) from test.bitmap_table;", - "group_concat requires first parameter to be of type STRING: group_concat(`id2`)" - ); - - assertSQLPlanOrErrorMsgContains( - "select sum(id2) from test.bitmap_table;", - "sum requires a numeric parameter: sum(`id2`)" - ); - - assertSQLPlanOrErrorMsgContains( - "select avg(id2) from test.bitmap_table;", - "avg requires a numeric parameter: avg(`id2`)" - ); - - assertSQLPlanOrErrorMsgContains( - "select max(id2) from test.bitmap_table;", - Type.OnlyMetricTypeErrorMsg - ); - - assertSQLPlanOrErrorMsgContains( - "select min(id2) from test.bitmap_table;", - Type.OnlyMetricTypeErrorMsg - ); - - assertSQLPlanOrErrorMsgContains( - "select count(*) from test.bitmap_table group by id2;", - Type.OnlyMetricTypeErrorMsg - ); - - assertSQLPlanOrErrorMsgContains( - "select count(*) from test.bitmap_table where id2 = 1;", - "Unsupported bitmap type in expression: (`id2` = 1)" - ); - - } - - @Test - public void testHLLTypeQuery() throws Exception { - assertSQLPlanOrErrorMsgContains( - "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.hll_table;", - "OUTPUT EXPRS:\n `test`.`hll_table`.`id`\n `test`.`hll_table`.`id2`" - ); - - assertSQLPlanOrErrorMsgContains( - "select count(id2) from test.hll_table;", - "No matching function with signature" - ); - - assertSQLPlanOrErrorMsgContains( - "select group_concat(id2) from test.hll_table;", - "group_concat requires first parameter to be of type STRING: group_concat(`id2`)" - ); - - assertSQLPlanOrErrorMsgContains( - "select sum(id2) from test.hll_table;", - "sum requires a numeric parameter: sum(`id2`)" - ); - - assertSQLPlanOrErrorMsgContains( - "select avg(id2) from test.hll_table;", - "avg requires a numeric parameter: avg(`id2`)" - ); - - assertSQLPlanOrErrorMsgContains( - "select max(id2) from test.hll_table;", - Type.OnlyMetricTypeErrorMsg - ); - - assertSQLPlanOrErrorMsgContains( - "select min(id2) from test.hll_table;", - Type.OnlyMetricTypeErrorMsg - ); - - assertSQLPlanOrErrorMsgContains( - "select min(id2) from test.hll_table;", - Type.OnlyMetricTypeErrorMsg - ); - - assertSQLPlanOrErrorMsgContains( - "select count(*) from test.hll_table group by id2;", - Type.OnlyMetricTypeErrorMsg - ); - - assertSQLPlanOrErrorMsgContains( - "select count(*) from test.hll_table where id2 = 1", - "Hll type dose not support operand: (`id2` = 1)" - ); - } - - @Test - public void testTypeCast() throws Exception { - // cmy: this test may sometimes failed in our daily test env, so I add a case here. - String sql = "select * from test.baseall a where k1 in (select k1 from test.bigtable b where k2 > 0 and k1 = 1);"; - getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertEquals(MysqlStateType.EOF, connectContext.getState().getStateType()); - - sql = "SHOW VARIABLES LIKE 'lower_case_%'; SHOW VARIABLES LIKE 'sql_mode'"; - List stmts = parseAndAnalyzeStmts(sql); - Assert.assertEquals(2, stmts.size()); - - // disable cast hll/bitmap to string - assertSQLPlanOrErrorMsgContains( - "select cast(id2 as varchar) from test.hll_table;", - "Invalid type cast of `id2` from hll to varchar(65533)" - ); - assertSQLPlanOrErrorMsgContains( - "select cast(id2 as varchar) from test.bitmap_table;", - "Invalid type cast of `id2` from bitmap to varchar(65533)" - ); - // disable implicit cast hll/bitmap to string - assertSQLPlanOrErrorMsgContains( - "select length(id2) from test.hll_table;", - "No matching function with signature: length(hll)" - ); - assertSQLPlanOrErrorMsgContains( - "select length(id2) from test.bitmap_table;", - "No matching function with signature: length(bitmap)" - ); - } - - @Test - public void testMultiStmts() throws Exception { - String sql = "SHOW VARIABLES LIKE 'lower_case_%'; SHOW VARIABLES LIKE 'sql_mode'"; - List stmts = parseAndAnalyzeStmts(sql); - Assert.assertEquals(2, stmts.size()); - - sql = "SHOW VARIABLES LIKE 'lower_case_%';;;"; - stmts = parseAndAnalyzeStmts(sql); - Assert.assertEquals(1, stmts.size()); - - sql = "SHOW VARIABLES LIKE 'lower_case_%';;;SHOW VARIABLES LIKE 'lower_case_%';"; - stmts = parseAndAnalyzeStmts(sql); - Assert.assertEquals(4, stmts.size()); - - sql = "SHOW VARIABLES LIKE 'lower_case_%'"; - stmts = parseAndAnalyzeStmts(sql); - Assert.assertEquals(1, stmts.size()); - } - - @Test - public void testCountDistinctRewrite() throws Exception { - String sql = "select count(distinct id) from test.bitmap_table"; - String explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("output: count")); - - sql = "select count(distinct id2) from test.bitmap_table"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - sql = "select sum(id) / count(distinct id2) from test.bitmap_table"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - sql = "select count(distinct id2) from test.hll_table"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("hll_union_agg")); - - sql = "select sum(id) / count(distinct id2) from test.hll_table"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("hll_union_agg")); - - sql = "select count(distinct id2) from test.bitmap_table group by id order by count(distinct id2)"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - sql = "select count(distinct id2) from test.bitmap_table having count(distinct id2) > 0"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - sql = "select count(distinct id2) from test.bitmap_table order by count(distinct id2)"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - sql = "select count(distinct if(id = 1, id2, null)) from test.bitmap_table"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - sql = "select count(distinct ifnull(id2, id3)) from test.bitmap_table_2"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - sql = "select count(distinct coalesce(id2, id3)) from test.bitmap_table_2"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("bitmap_union_count")); - - ConnectContext.get().getSessionVariable().setRewriteCountDistinct(false); - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ count(distinct id2) from test.bitmap_table"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("No matching function with signature")); - } - - @Test - public void testCreateDbQueryPlanWithSchemaSyntax() throws Exception { - String createSchemaSql = "create schema if not exists test"; - String createDbSql = "create database if not exists test"; - CreateDbStmt createSchemaStmt = (CreateDbStmt) parseAndAnalyzeStmt(createSchemaSql); - CreateDbStmt createDbStmt = (CreateDbStmt) parseAndAnalyzeStmt(createDbSql); - Assert.assertEquals(createDbStmt.toSql(), createSchemaStmt.toSql()); - } - - @Test - public void testDropDbQueryPlanWithSchemaSyntax() throws Exception { - String dropSchemaSql = "drop schema if exists test"; - String dropDbSql = "drop database if exists test"; - DropDbStmt dropSchemaStmt = (DropDbStmt) parseAndAnalyzeStmt(dropSchemaSql); - DropDbStmt dropDbStmt = (DropDbStmt) parseAndAnalyzeStmt(dropDbSql); - Assert.assertEquals(dropDbStmt.toSql(), dropSchemaStmt.toSql()); - } - - @Test - public void testShowCreateDbQueryPlanWithSchemaSyntax() throws Exception { - String showCreateSchemaSql = "show create schema test"; - String showCreateDbSql = "show create database test"; - ShowCreateDbStmt showCreateSchemaStmt = (ShowCreateDbStmt) parseAndAnalyzeStmt(showCreateSchemaSql); - ShowCreateDbStmt showCreateDbStmt = (ShowCreateDbStmt) parseAndAnalyzeStmt(showCreateDbSql); - Assert.assertEquals(showCreateDbStmt.toSql(), showCreateSchemaStmt.toSql()); - } - - @Test - public void testDateTypeCastSyntax() throws Exception { - String castSql = "select * from test.baseall where k11 < cast('2020-03-26' as date)"; - SelectStmt selectStmt = (SelectStmt) parseAndAnalyzeStmt(castSql); - Expr rightExpr = selectStmt.getWhereClause().getChildren().get(1); - Assert.assertEquals(rightExpr.getType(), ScalarType.getDefaultDateType(Type.DATETIME)); - - String castSql2 = "select /*+ SET_VAR(enable_nereids_planner=false) */ str_to_date('11/09/2011', '%m/%d/%Y');"; - String explainString = getSQLPlanOrErrorMsg("explain " + castSql2); - Assert.assertTrue(explainString.contains("2011-11-09")); - Assert.assertFalse(explainString.contains("2011-11-09 00:00:00")); - } - - @Test - public void testJoinPredicateTransitivity() throws Exception { - connectContext.setDatabase("test"); - - ConnectContext.get().getSessionVariable().setEnableInferPredicate(true); - /* TODO: commit on_clause and where_clause Cross-identification - // test left join : left table where binary predicate - String sql = "select join1.id\n" - + "from join1\n" - + "left join join2 on join1.id = join2.id\n" - + "where join1.id > 1;"; - String explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1")); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1")); - - // test left join: left table where in predicate - sql = "select join1.id\n" - + "from join1\n" - + "left join join2 on join1.id = join2.id\n" - + "where join1.id in (2);"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` IN (2)")); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` IN (2)")); - - // test left join: left table where between predicate - sql = "select join1.id\n" - + "from join1\n" - + "left join join2 on join1.id = join2.id\n" - + "where join1.id BETWEEN 1 AND 2;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` >= 1, `join1`.`id` <= 2")); - Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` >= 1, `join2`.`id` <= 2")); - - */ - // test left join: left table join predicate, left table couldn't push down - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "left join join2 on join1.id = join2.id\n" - + "and join1.id > 1;"; - String explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains(" > 1")); - Assert.assertFalse(explainString.contains("`join1`.`id` > 1")); - - /* - // test left join: right table where predicate. - // If we eliminate outer join, we could push predicate down to join1 and join2. - // Currently, we push predicate to join1 and keep join predicate for join2 - sql = "select *\n from join1\n" - + "left join join2 on join1.id = join2.id\n" - + "where join2.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1")); - Assert.assertFalse(explainString.contains("other join predicates: `join2`.`id` > 1")); - */ - - // test left join: right table join predicate, only push down right table - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "left join join2 on join1.id = join2.id\n" - + "and join2.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("`join2`.`id` > 1")); - Assert.assertFalse(explainString.contains("`join1`.`id` > 1")); - - /* - // test inner join: left table where predicate, both push down left table and right table - sql = "select *\n from join1\n" - + "join join2 on join1.id = join2.id\n" - + "where join1.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1")); - Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1")); - */ - - // test inner join: left table join predicate, both push down left table and right table - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "join join2 on join1.id = join2.id\n" - + "and join1.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("`join1`.`id` > 1")); - Assert.assertTrue(explainString.contains("`join2`.`id` > 1")); - - /* - // test inner join: right table where predicate, both push down left table and right table - sql = "select *\n from join1\n" - + "join join2 on join1.id = join2.id\n" - + "where join2.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1")); - Assert.assertTrue(explainString.contains("PREDICATES: `join2`.`id` > 1")); - */ - - // test inner join: right table join predicate, both push down left table and right table - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - - + "join join2 on join1.id = join2.id\n" + "and 1 < join2.id;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("`join1`.`id` > 1")); - Assert.assertTrue(explainString.contains("`join2`.`id` > 1")); - - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "join join2 on join1.id = join2.value\n" - + "and join2.value in ('abc');"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertFalse(explainString.contains("'abc' is not a number")); - Assert.assertFalse(explainString.contains("`join1`.`value` IN ('abc')")); - - // test anti join, right table join predicate, only push to right table - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "left anti join join2 on join1.id = join2.id\n" - + "and join2.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("`join2`.`id` > 1")); - Assert.assertFalse(explainString.contains("`join1`.`id` > 1")); - - // test semi join, right table join predicate, only push to right table - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "left semi join join2 on join1.id = join2.id\n" - + "and join2.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("`join2`.`id` > 1")); - Assert.assertTrue(explainString.contains("`join1`.`id` > 1")); - - // test anti join, left table join predicate, left table couldn't push down - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "left anti join join2 on join1.id = join2.id\n" - + "and join1.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains(" > 1")); - Assert.assertFalse(explainString.contains("`join1`.`id` > 1")); - - // test semi join, left table join predicate, only push to left table - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ *\n from join1\n" - + "left semi join join2 on join1.id = join2.id\n" - + "and join1.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("`join1`.`id` > 1")); - - /* - // test anti join, left table where predicate, only push to left table - sql = "select join1.id\n" - + "from join1\n" - + "left anti join join2 on join1.id = join2.id\n" - + "where join1.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1")); - Assert.assertFalse(explainString.contains("PREDICATES: `join2`.`id` > 1")); - - // test semi join, left table where predicate, only push to left table - sql = "select join1.id\n" - + "from join1\n" - + "left semi join join2 on join1.id = join2.id\n" - + "where join1.id > 1;"; - explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `join1`.`id` > 1")); - Assert.assertFalse(explainString.contains("PREDICATES: `join2`.`id` > 1")); - */ - } - - @Disabled - public void testConvertCaseWhenToConstant() throws Exception { - // basic test - String caseWhenSql = "select " - + "case when date_format(now(),'%H%i') < 123 then 1 else 0 end as col " - + "from test.test1 " - + "where time_col = case when date_format(now(),'%H%i') < 123 then date_format(date_sub(" - + "now(),2),'%Y%m%d') else date_format(date_sub(now(),1),'%Y%m%d') end"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + caseWhenSql), - "CASE WHEN")); - - // test 1: case when then - // 1.1 multi when in on `case when` and can be converted to constants - String sql11 = "select case when false then 2 when true then 3 else 0 end as col11;"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql11), - "constant exprs: \n 3")); - - // 1.2 multi `when expr` in on `case when` ,`when expr` can not be converted to constants - String sql121 = "select case when false then 2 when substr(k7,2,1) then 3 else 0 end as col121 from" - + " test.baseall"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql121), - "OUTPUT EXPRS:\n CASE WHEN substr(`k7`, 2, 1) THEN 3 ELSE 0 END")); - - // 1.2.2 when expr which can not be converted to constants in the first - String sql122 = "select case when substr(k7,2,1) then 2 when false then 3 else 0 end as col122" - + " from test.baseall"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql122), - "OUTPUT EXPRS:\n CASE WHEN substr(`k7`, 2, 1) THEN 2 WHEN FALSE THEN 3 ELSE 0 END")); - - // 1.2.3 test return `then expr` in the middle - String sql124 = "select case when false then 1 when true then 2 when false then 3 else 'other' end as col124"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql124), - "constant exprs: \n '2'")); - - // 1.3 test return null - String sql3 = "select case when false then 2 end as col3"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql3), - "constant exprs: \n NULL")); - - // 1.3.1 test return else expr - String sql131 = "select case when false then 2 when false then 3 else 4 end as col131"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql131), - "constant exprs: \n 4")); - - // 1.4 nest `case when` and can be converted to constants - String sql14 = "select case when (case when true then true else false end) then 2 when false then 3 else 0 end as col"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql14), - "constant exprs: \n 2")); - - // 1.5 nest `case when` and can not be converted to constants - String sql15 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case when case when substr(k7,2,1) then true else false end then 2 when false then 3" - + " else 0 end as col from test.baseall"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql15), - "OUTPUT EXPRS:\n CASE WHEN CASE WHEN substr(`k7`, 2, 1) THEN TRUE ELSE FALSE END THEN 2" - + " WHEN FALSE THEN 3 ELSE 0 END")); - - // 1.6 test when expr is null - String sql16 = "select case when null then 1 else 2 end as col16;"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql16), - "constant exprs: \n 2")); - - // test 2: case xxx when then - // 2.1 test equal - String sql2 = "select case 1 when 1 then 'a' when 2 then 'b' else 'other' end as col2;"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql2), - "constant exprs: \n 'a'")); - - // 2.1.2 test not equal - String sql212 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case 'a' when 1 then 'a' when 'a' then 'b' else 'other' end as col212;"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql212), - "constant exprs: \n 'b'")); - - // 2.2 test return null - String sql22 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case 'a' when 1 then 'a' when 'b' then 'b' end as col22;"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql22), - "constant exprs: \n NULL")); - - // 2.2.2 test return else - String sql222 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case 1 when 2 then 'a' when 3 then 'b' else 'other' end as col222;"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql222), - "constant exprs: \n 'other'")); - - // 2.3 test can not convert to constant,middle when expr is not constant - String sql23 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case 'a' when 'b' then 'a' when substr(k7,2,1) then 2 when false then 3" - + " else 0 end as col23 from test.baseall"; - String a = getSQLPlanOrErrorMsg("explain " + sql23); - Assert.assertTrue(StringUtils.containsIgnoreCase(a, - "OUTPUT EXPRS:\n CASE 'a' WHEN substr(`k7`, 2, 1) THEN '2' WHEN '0' THEN '3' ELSE '0' END")); - - // 2.3.1 first when expr is not constant - String sql231 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case 'a' when substr(k7,2,1) then 2 when 1 then 'a' when false then 3 else 0 end" - + " as col231 from test.baseall"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql231), - "OUTPUT EXPRS:\n CASE 'a' WHEN substr(`k7`, 2, 1) THEN '2' WHEN '1' THEN 'a' WHEN '0'" - + " THEN '3' ELSE '0' END")); - - // 2.3.2 case expr is not constant - String sql232 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case k1 when substr(k7,2,1) then 2 when 1 then 'a' when false then 3 else 0 end" - + " as col232 from test.baseall"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql232), - "OUTPUT EXPRS:\n CASE `k1` WHEN substr(`k7`, 2, 1) THEN '2' WHEN '1' THEN 'a' " - + "WHEN '0' THEN '3' ELSE '0' END")); - - // 3.1 test float,float in case expr - String sql31 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case cast(100 as float) when 1 then 'a' when 2 then 'b' else 'other' end as col31;"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql31), - "constant exprs: \n CASE 100 WHEN 1 THEN 'a' WHEN 2 THEN 'b' ELSE 'other' END")); - - // 4.1 test null in case expr return else - String sql41 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case null when 1 then 'a' when 2 then 'b' else 'other' end as col41"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql41), - "constant exprs: \n 'other'")); - - // 4.1.2 test null in case expr return null - String sql412 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case null when 1 then 'a' when 2 then 'b' end as col41"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql412), - "constant exprs: \n NULL")); - - // 4.2.1 test null in when expr - String sql421 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case 'a' when null then 'a' else 'other' end as col421"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql421), - "constant exprs: \n 'other'")); - - // 5.1 test same type in then expr and else expr - String sql51 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case when 132 then k7 else 'all' end as col51 from test.baseall group by col51"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql51), - "CASE WHEN 132 THEN `k7` ELSE 'all' END")); - - // 5.2 test same type in then expr and else expr - String sql52 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case when 2 < 1 then 'all' else k7 end as col52 from test.baseall group by col52"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql52), - "`k7`")); - - // 5.3 test different type in then expr and else expr, and return CastExpr - String sql53 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case when 2 < 1 then 'all' else k1 end as col53 from test.baseall group by col53"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql53), - "`k1`")); - - // 5.4 test return CastExpr with other SlotRef in selectListItem - String sql54 = "select /*+ SET_VAR(enable_nereids_planner=false) */ k2, case when 2 < 1 then 'all' else k1 end as col54, k7 from test.baseall" - + " group by k2, col54, k7"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql54), - "OUTPUT EXPRS:\n `k2`\n `k1`\n `k7`")); - - // 5.5 test return CastExpr> with other SlotRef in selectListItem - String sql55 = "select /*+ SET_VAR(enable_nereids_planner=false) */ case when 2 < 1 then 'all' else cast(k1 as int) end as col55, k7 from" - + " test.baseall group by col55, k7"; - Assert.assertTrue(StringUtils.containsIgnoreCase(getSQLPlanOrErrorMsg("explain " + sql55), - "OUTPUT EXPRS:\n CAST(`k1` AS INT)\n `k7`")); - } - - @Test - public void testJoinPredicateTransitivityWithSubqueryInWhereClause() throws Exception { - connectContext.setDatabase("test"); - String sql = "SELECT *\n" - + "FROM test.pushdown_test\n" - + "WHERE 0 < (\n" - + " SELECT MAX(k9)\n" + " FROM test.pushdown_test);"; - String explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PLAN FRAGMENT")); - Assert.assertTrue(explainString.contains("NESTED LOOP JOIN")); - Assert.assertTrue(!explainString.contains("PREDICATES") || explainString.contains("PREDICATES: TRUE")); - } - - @Test - public void testDistinctPushDown() throws Exception { - connectContext.setDatabase("test"); - String sql = "select distinct k1 from (select distinct k1 from test.pushdown_test) t where k1 > 1"; - String explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assert.assertTrue(explainString.contains("PLAN FRAGMENT")); - } - - @Test - public void testConstInPartitionPrune() throws Exception { - FeConstants.runningUnitTest = true; - String queryStr = "explain select * from (select 'aa' as kk1, sum(id) from test.join1 where dt = 9" - + " group by kk1)tt where kk1 in ('aa');"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - FeConstants.runningUnitTest = false; - Assert.assertTrue(explainString.contains("partitions=1/1")); - } - - @Test - public void testOrCompoundPredicateFold() throws Exception { - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from baseall where (k1 > 1) or (k1 > 1 and k2 < 1)"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("`k1` > 1")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from baseall where (k1 > 1 and k2 < 1) or (k1 > 1)"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("`k1` > 1")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from baseall where (k1 > 1) or (k1 > 1)"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("`k1` > 1")); - } - - @Test - public void testColocateJoin() throws Exception { - FeConstants.runningUnitTest = true; - - String queryStr = "explain select * from test.colocate1 t1, test.colocate2 t2 where t1.k1 = t2.k1 and" - + " t1.k2 = t2.k2 and t1.k3 = t2.k3"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains(ColocatePlanTest.COLOCATE_ENABLE)); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.colocate1 t1 join [shuffle] test.colocate2 t2 on t1.k1 = t2.k1 and t1.k2 = t2.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains(ColocatePlanTest.COLOCATE_ENABLE)); - - // t1.k1 = t2.k2 not same order with distribute column - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.colocate1 t1, test.colocate2 t2 where t1.k1 = t2.k2 and t1.k2 = t2.k1 and t1.k3 = t2.k3"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains(ColocatePlanTest.COLOCATE_ENABLE)); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.colocate1 t1, test.colocate2 t2 where t1.k2 = t2.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains(ColocatePlanTest.COLOCATE_ENABLE)); - } - - @Test - public void testSelfColocateJoin() throws Exception { - FeConstants.runningUnitTest = true; - - // single partition - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.jointest t1, test.jointest t2 where t1.k1 = t2.k1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains(ColocatePlanTest.COLOCATE_ENABLE)); - - // multi partition, should not be colocate - queryStr = "explain select * from test.dynamic_partition t1, test.dynamic_partition t2 where t1.k1 = t2.k1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains(ColocatePlanTest.COLOCATE_ENABLE)); - } - - @Test - public void testBucketShuffleJoin() throws Exception { - FeConstants.runningUnitTest = true; - // enable bucket shuffle join - Deencapsulation.setField(connectContext.getSessionVariable(), "enableBucketShuffleJoin", true); - - // set data size and row count for the olap table - Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("test"); - OlapTable tbl = (OlapTable) db.getTableOrMetaException("bucket_shuffle1"); - for (Partition partition : tbl.getPartitions()) { - partition.updateVisibleVersion(2); - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(10000); - for (Tablet tablet : mIndex.getTablets()) { - for (Replica replica : tablet.getReplicas()) { - replica.updateVersion(2); - } - } - } - } - - db = Env.getCurrentInternalCatalog().getDbOrMetaException("test"); - tbl = (OlapTable) db.getTableOrMetaException("bucket_shuffle2"); - for (Partition partition : tbl.getPartitions()) { - partition.updateVisibleVersion(2); - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(10000); - for (Tablet tablet : mIndex.getTablets()) { - for (Replica replica : tablet.getReplicas()) { - replica.updateVersion(2); - } - } - } - } - - // single partition - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.jointest t1, test.bucket_shuffle1 t2 where t1.k1 = t2.k1" - + " and t1.k1 = t2.k2"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("BUCKET_SHFFULE")); - Assert.assertTrue(explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t1`.`k1`, `t1`.`k1`")); - - // not bucket shuffle join do not support different type - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.jointest t1, test.bucket_shuffle1 t2 where cast (t1.k1 as tinyint)" - + " = t2.k1 and t1.k1 = t2.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(!explainString.contains("BUCKET_SHFFULE")); - - // left table distribution column not match - queryStr = "explain select * from test.jointest t1, test.bucket_shuffle1 t2 where t1.k1 = t2.k1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(!explainString.contains("BUCKET_SHFFULE")); - - // multi partition, should not be bucket shuffle join - queryStr = "explain select * from test.jointest t1, test.bucket_shuffle2 t2 where t1.k1 = t2.k1" - + " and t1.k1 = t2.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(!explainString.contains("BUCKET_SHFFULE")); - - // left table is colocate table, should be bucket shuffle - queryStr = "explain select * from test.colocate1 t1, test.bucket_shuffle2 t2 where t1.k1 = t2.k1" - + " and t1.k1 = t2.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(!explainString.contains("BUCKET_SHFFULE")); - - // support recurse of bucket shuffle join - // TODO: support the UT in the future - queryStr = "explain select * from test.jointest t1 join test.bucket_shuffle1 t2" - + " on t1.k1 = t2.k1 and t1.k1 = t2.k2 join test.colocate1 t3" - + " on t2.k1 = t3.k1 and t2.k2 = t3.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - // Assert.assertTrue(explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t1`.`k1`, `t1`.`k1`")); - // Assert.assertTrue(explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t3`.`k1`, `t3`.`k2`")); - - // support recurse of bucket shuffle because t4 join t2 and join column name is same as t2 distribute column name - queryStr = "explain select * from test.jointest t1 join test.bucket_shuffle1 t2 on t1.k1 = t2.k1 and" - + " t1.k1 = t2.k2 join test.colocate1 t3 on t2.k1 = t3.k1 join test.jointest t4 on t4.k1 = t2.k1 and" - + " t4.k1 = t2.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - //Assert.assertTrue(explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t1`.`k1`, `t1`.`k1`")); - //Assert.assertTrue(explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t4`.`k1`, `t4`.`k1`")); - - // some column name in join expr t3 join t4 and t1 distribute column name, so should not be bucket shuffle join - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.jointest t1 join test.bucket_shuffle1 t2 on t1.k1 = t2.k1 and t1.k1 =" - + " t2.k2 join test.colocate1 t3 on t2.k1 = t3.k1 join test.jointest t4 on t4.k1 = t3.k1 and" - + " t4.k2 = t3.k2"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t1`.`k1`, `t1`.`k1`")); - Assert.assertTrue(!explainString.contains("BUCKET_SHFFULE_HASH_PARTITIONED: `t4`.`k1`, `t4`.`k1`")); - - // here only a bucket shuffle + broadcast jost join - queryStr = "explain SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM test.bucket_shuffle1 T LEFT JOIN test.bucket_shuffle1 T1 ON T1.k2 = T.k1 and T.k2 = T1.k3 LEFT JOIN" - + " test.bucket_shuffle2 T2 ON T2.k2 = T1.k1 and T2.k1 = T1.k2;"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("BUCKET_SHFFULE")); - Assert.assertTrue(explainString.contains("BROADCAST")); - // disable bucket shuffle join again - Deencapsulation.setField(connectContext.getSessionVariable(), "enableBucketShuffleJoin", false); - } - - @Test - public void testJoinWithMysqlTable() throws Exception { - connectContext.setDatabase("test"); - - // set data size and row count for the olap table - Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("test"); - OlapTable tbl = (OlapTable) db.getTableOrMetaException("jointest"); - for (Partition partition : tbl.getPartitions()) { - partition.updateVisibleVersion(2); - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(10000); - for (Tablet tablet : mIndex.getTablets()) { - for (Replica replica : tablet.getReplicas()) { - replica.updateVersion(2); - } - } - } - } - - // disable bucket shuffle join - Deencapsulation.setField(connectContext.getSessionVariable(), "enableBucketShuffleJoin", false); - - String queryStr = "explain select * from mysql_table t2, jointest t1 where t1.k1 = t2.k1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("INNER JOIN(BROADCAST)")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "SCAN MYSQL")); - - queryStr = "explain select * from jointest t1, mysql_table t2 where t1.k1 = t2.k1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("INNER JOIN(BROADCAST)")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "SCAN MYSQL")); - - queryStr = "explain select * from jointest t1, mysql_table t2, mysql_table t3 where t1.k1 = t3.k1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("INNER JOIN(PARTITIONED)")); - - // should clear the jointest table to make sure do not affect other test - for (Partition partition : tbl.getPartitions()) { - partition.updateVisibleVersion(2); - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(0); - for (Tablet tablet : mIndex.getTablets()) { - for (Replica replica : tablet.getReplicas()) { - replica.updateVersion(2); - } - } - } - } - } - - @Test - public void testJoinWithOdbcTable() throws Exception { - connectContext.setDatabase("test"); - - // set data size and row count for the olap table - Database db = Env.getCurrentInternalCatalog().getDbOrMetaException("test"); - OlapTable tbl = (OlapTable) db.getTableOrMetaException("jointest"); - for (Partition partition : tbl.getPartitions()) { - partition.updateVisibleVersion(2); - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(10000); - for (Tablet tablet : mIndex.getTablets()) { - for (Replica replica : tablet.getReplicas()) { - replica.updateVersion(2); - } - } - } - } - - // disable bucket shuffle join - Deencapsulation.setField(connectContext.getSessionVariable(), "enableBucketShuffleJoin", false); - String queryStr = "explain select * from odbc_mysql t2, jointest t1 where t1.k1 = t2.k1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("INNER JOIN(BROADCAST)")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "SCAN ODBC")); - - queryStr = "explain select * from jointest t1, odbc_mysql t2 where t1.k1 = t2.k1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("INNER JOIN(BROADCAST)")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "SCAN ODBC")); - - queryStr = "explain select * from jointest t1, odbc_mysql t2, odbc_mysql t3 where t1.k1 = t3.k1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("INNER JOIN(PARTITIONED)")); - - // should clear the jointest table to make sure do not affect other test - for (Partition partition : tbl.getPartitions()) { - partition.updateVisibleVersion(2); - for (MaterializedIndex mIndex : partition.getMaterializedIndices(IndexExtState.VISIBLE)) { - mIndex.setRowCount(0); - for (Tablet tablet : mIndex.getTablets()) { - for (Replica replica : tablet.getReplicas()) { - replica.updateVersion(2); - } - } - } - } - } - - @Disabled - public void testPushDownOfOdbcTable() throws Exception { - connectContext.setDatabase("test"); - - // MySQL ODBC table can push down all filter - String queryStr = "explain select * from odbc_mysql where k1 > 10 and abs(k1) > 10"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("`k1` > 10")); - Assert.assertTrue(explainString.contains("abs(`k1`) > 10")); - - // now we do not support odbc scan node push down function call, except MySQL ODBC table - // this table is Oracle ODBC table, so abs(k1) should not be pushed down - queryStr = "explain select * from odbc_oracle where k1 > 10 and abs(k1) > 10"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("\"K1\" > 10")); - Assert.assertTrue(!explainString.contains("abs(k1) > 10")); - } - - @Test - public void testLimitOfExternalTable() throws Exception { - connectContext.setDatabase("test"); - - // ODBC table (MySQL) - String queryStr = "explain select * from odbc_mysql where k1 > 10 and abs(k1) > 10 limit 10"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("LIMIT 10")); - - // ODBC table (Oracle) not push down limit - queryStr = "explain select * from odbc_oracle where k1 > 10 and abs(k1) > 10 limit 10"; - explainString = getSQLPlanOrErrorMsg(queryStr); - // abs is function, so Doris do not push down function except MySQL Database - // so should not push down limit operation - Assert.assertTrue(!explainString.contains("ROWNUM <= 10")); - - // ODBC table (Oracle) push down limit - queryStr = "explain select * from odbc_oracle where k1 > 10 limit 10"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("ROWNUM <= 10")); - - // MySQL table - queryStr = "explain select * from mysql_table where k1 > 10 and abs(k1) > 10 limit 10"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("LIMIT 10")); - } - - @Test - public void testOdbcSink() throws Exception { - connectContext.setDatabase("test"); - - // insert into odbc_oracle table - String queryStr = "explain insert into odbc_oracle select * from odbc_mysql"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("TABLENAME IN DORIS: odbc_oracle")); - Assert.assertTrue(explainString.contains("TABLE TYPE: ORACLE")); - Assert.assertTrue(explainString.contains("TABLENAME OF EXTERNAL TABLE: \"TBL1\"")); - - // enable transaction of ODBC Sink - Deencapsulation.setField(connectContext.getSessionVariable(), "enableOdbcTransaction", true); - queryStr = "explain insert into odbc_oracle select * from odbc_mysql"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("EnableTransaction: true")); - } - - @Test - public void testPreferBroadcastJoin() throws Exception { - connectContext.setDatabase("test"); - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from (select k2 from jointest)t2, jointest t1 where t1.k1 = t2.k2"; - // disable bucket shuffle join - Deencapsulation.setField(connectContext.getSessionVariable(), "enableBucketShuffleJoin", false); - - // default set PreferBroadcastJoin true - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("INNER JOIN(BROADCAST)")); - - connectContext.getSessionVariable().setPreferJoinMethod("shuffle"); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("INNER JOIN(PARTITIONED)")); - - connectContext.getSessionVariable().setPreferJoinMethod("broadcast"); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("INNER JOIN(BROADCAST)")); - } - - @Test - public void testRuntimeFilterMode() throws Exception { - connectContext.setDatabase("test"); - - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from jointest t2, jointest t1 where t1.k1 = t2.k1"; - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "LOCAL"); - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("runtime filter")); - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "REMOTE"); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("runtime filter")); - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "OFF"); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("runtime filter")); - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "GLOBAL"); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("runtime filter")); - - queryStr = "explain select * from jointest t2, jointest t1 where t1.k1 <=> t2.k1"; - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "LOCAL"); - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 15); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("runtime filter")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from jointest as a where k1 = (select count(1) from jointest as b" - + " where a.k1 = b.k1);"; - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "GLOBAL"); - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 15); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("runtime filter")); - } - - @Test - public void testRuntimeFilterType() throws Exception { - connectContext.setDatabase("test"); - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from jointest t2, jointest t1 where t1.k1 = t2.k1"; - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "GLOBAL"); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 0); - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("runtime filter")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 1); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 2); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 3); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] <- `t1`.`k1`")); - - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 4); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[min_max] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 5); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 6); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[bloom] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 7); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[min_max] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 8); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in_or_bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 9); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[in_or_bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 10); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[bloom] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[in_or_bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 11); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[in_or_bloom] -> `t2`.`k1`")); - - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 12); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[min_max] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[in_or_bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 13); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[in_or_bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 14); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[bloom] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[min_max] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[in_or_bloom] -> `t2`.`k1`")); - - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", 15); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[min_max] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF003[in_or_bloom] <- `t1`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF001[bloom] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF002[min_max] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF003[in_or_bloom] -> `t2`.`k1`")); - - // support merge in filter, and forbidden implicit conversion to bloom filter - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from jointest t2 join [shuffle] jointest t1 where t1.k1 = t2.k1"; - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "GLOBAL"); - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", TRuntimeFilterType.IN.getValue()); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in] <- `t1`.`k1`")); - Assert.assertFalse(explainString.contains("RF000[bloom] -> `t2`.`k1`")); - Assert.assertFalse(explainString.contains("RF000[bloom] <- `t1`.`k1`")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from jointest t2 join [shuffle] jointest t1 where t1.k1 = t2.k1"; - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterMode", "GLOBAL"); - Deencapsulation.setField(connectContext.getSessionVariable(), "runtimeFilterType", TRuntimeFilterType.IN_OR_BLOOM.getValue()); - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("RF000[in_or_bloom] -> `t2`.`k1`")); - Assert.assertTrue(explainString.contains("RF000[in_or_bloom] <- `t1`.`k1`")); - } - - @Test - public void testEmptyNode() throws Exception { - connectContext.setDatabase("test"); - String emptyNode = "EMPTYSET"; - - List sqls = Lists.newArrayList(); - sqls.add("explain select * from baseall limit 0"); - sqls.add("explain select count(*) from baseall limit 0;"); - sqls.add("explain select k3, dense_rank() OVER () AS rank FROM baseall limit 0;"); - sqls.add("explain select rank from (select k3, dense_rank() OVER () AS rank FROM baseall) a limit 0;"); - sqls.add("explain select * from baseall join bigtable as b limit 0"); - - sqls.add("explain select * from baseall where 1 = 2"); - sqls.add("explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from baseall where null = null"); - sqls.add("explain select count(*) from baseall where 1 = 2;"); - sqls.add("explain select /*+ SET_VAR(enable_nereids_planner=false) */ k3, dense_rank() OVER () AS rank FROM baseall where 1 =2;"); - sqls.add("explain select rank from (select k3, dense_rank() OVER () AS rank FROM baseall) a where 1 =2;"); - sqls.add("explain select * from baseall join bigtable as b where 1 = 2"); - - for (String sql : sqls) { - String explainString = getSQLPlanOrErrorMsg(sql); - Assert.assertTrue(explainString.contains(emptyNode)); - } - } - - @Test - public void testInformationFunctions() throws Exception { - connectContext.setDatabase("test"); - Analyzer analyzer = new Analyzer(connectContext.getEnv(), connectContext); - InformationFunction infoFunc = new InformationFunction("database"); - infoFunc.analyze(analyzer); - Assert.assertEquals("test", infoFunc.getStrValue()); - - infoFunc = new InformationFunction("user"); - infoFunc.analyze(analyzer); - Assert.assertEquals("'root'@'127.0.0.1'", infoFunc.getStrValue()); - - infoFunc = new InformationFunction("current_user"); - infoFunc.analyze(analyzer); - Assert.assertEquals("'root'@'%'", infoFunc.getStrValue()); - } - - @Test - public void testAggregateSatisfyOlapTableDistribution() throws Exception { - FeConstants.runningUnitTest = true; - connectContext.setDatabase("test"); - String sql = "SELECT dt, dis_key, COUNT(1) FROM table_unpartitioned group by dt, dis_key"; - String explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("AGGREGATE (update finalize)")); - } - - - @Test - public void testLeadAndLagFunction() throws Exception { - connectContext.setDatabase("test"); - - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ time_col, lead(query_time, 1, NULL) over () as time2 from test.test1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("lead(`query_time`, 1, NULL)")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ time_col, lead(query_time, 1, 2) over () as time2 from test.test1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("lead(`query_time`, 1, 2)")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ time_col, lead(time_col, 1, '2020-01-01 00:00:00') over () as time2 from test.test1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("lead(`time_col`, 1, '2020-01-01 00:00:00')")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ time_col, lag(query_time, 1, 2) over () as time2 from test.test1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("lag(`query_time`, 1, 2)")); - } - - @Disabled - public void testIntDateTime() throws Exception { - connectContext.setDatabase("test"); - //valid date - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day in ('2020-10-30')"; - String explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains(Config.enable_date_conversion ? "PREDICATES: `day` IN ('2020-10-30')" - : "PREDICATES: `day` IN ('2020-10-30 00:00:00')")); - //valid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day in ('2020-10-30','2020-10-29')"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains(Config.enable_date_conversion - ? "PREDICATES: `day` IN ('2020-10-30', '2020-10-29')" - : "PREDICATES: `day` IN ('2020-10-30 00:00:00', '2020-10-29 00:00:00')")); - - //valid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date in ('2020-10-30 12:12:30')"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` IN ('2020-10-30 12:12:30')")); - //valid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date in ('2020-10-30')"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` IN ('2020-10-30 00:00:00')")); - - //int date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day in (20201030)"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `day` IN ('2020-10-30 00:00:00')")); - //int datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date in (20201030)"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` IN ('2020-10-30 00:00:00')")); - } - - @Test - public void testOutJoinSmapReplace() throws Exception { - connectContext.setDatabase("test"); - //valid date - String sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.aid, b.bid FROM (SELECT 3 AS aid) a right outer JOIN (SELECT 4 AS bid) b ON (a.aid=b.bid)"; - assertSQLPlanOrErrorMsgContains(sql, "OUTPUT EXPRS:\n" + " 3\n" + " 4"); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.aid, b.bid FROM (SELECT 3 AS aid) a left outer JOIN (SELECT 4 AS bid) b ON (a.aid=b.bid)"; - assertSQLPlanOrErrorMsgContains(sql, "OUTPUT EXPRS:\n" + " 3\n" + " 4"); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.aid, b.bid FROM (SELECT 3 AS aid) a full outer JOIN (SELECT 4 AS bid) b ON (a.aid=b.bid)"; - assertSQLPlanOrErrorMsgContains(sql, "OUTPUT EXPRS:\n" + " 3\n" + " 4"); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.aid, b.bid FROM (SELECT 3 AS aid) a JOIN (SELECT 4 AS bid) b ON (a.aid=b.bid)"; - assertSQLPlanOrErrorMsgContains(sql, "OUTPUT EXPRS:\n" + " 3\n" + " 4"); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.k1, b.k2 FROM (SELECT k1 from baseall) a LEFT OUTER JOIN (select k1, 999 as k2 from baseall) b ON (a.k1=b.k1)"; - assertSQLPlanOrErrorMsgContains(sql, " `k1`\n" + " 999"); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.k1, b.k2 FROM (SELECT 1 as k1 from baseall) a RIGHT OUTER JOIN (select k1, 999 as k2 from baseall) b ON (a.k1=b.k1)"; - assertSQLPlanOrErrorMsgContains(sql, " 1\n" + " 999"); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.k1, b.k2 FROM (SELECT 1 as k1 from baseall) a FULL JOIN (select k1, 999 as k2 from baseall) b ON (a.k1=b.k1)"; - assertSQLPlanOrErrorMsgContains(sql, " 1\n" + " 999"); - } - - @Test - public void testFromUnixTimeRewrite() throws Exception { - connectContext.setDatabase("test"); - //default format - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where from_unixtime(query_time) > '2021-03-02 10:01:28'"; - String explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("(`query_time` <= 253402271999) AND (`query_time` > 1614650488)")); - } - - @Disabled - public void testCheckInvalidDate() throws Exception { - FeConstants.runningUnitTest = true; - connectContext.setDatabase("test"); - //valid date - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = '2020-10-30'"; - String explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains(Config.enable_date_conversion ? "PREDICATES: `day` = '2020-10-30'" - : "PREDICATES: `day` = '2020-10-30 00:00:00'")); - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = from_unixtime(1196440219)"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `day` = '2007-12-01 00:30:19'")); - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = str_to_date('2014-12-21 12:34:56', '%Y-%m-%d %H:%i:%s');"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `day` = '2014-12-21 12:34:56'")); - //valid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = 20201030"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains(Config.enable_date_conversion ? "PREDICATES: `day` = '2020-10-30'" - : "PREDICATES: `day` = '2020-10-30 00:00:00'")); - //valid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = '20201030'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains(Config.enable_date_conversion ? "PREDICATES: `day` = '2020-10-30'" - : "PREDICATES: `day` = '2020-10-30 00:00:00'")); - //valid date contains micro second - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = '2020-10-30 10:00:01.111111'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains(Config.enable_date_conversion - ? "VEMPTYSET" - : "PREDICATES: `day` = '2020-10-30 10:00:01'")); - //invalid date - - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = '2020-10-32'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: '2020-10-32' in expression: `day` = '2020-10-32'")); - - //invalid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = '20201032'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: '20201032' in expression: `day` = '20201032'")); - //invalid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = 20201032"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: 20201032 in expression: `day` = 20201032")); - //invalid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = 'hello'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: 'hello' in expression: `day` = 'hello'")); - //invalid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = 2020-10-30"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: 1980 in expression: `day` = 1980")); - //invalid date - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where day = 10-30"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: -20 in expression: `day` = -20")); - //valid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '2020-10-30 12:12:30'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 12:12:30'")); - //valid datetime, support parsing to minute - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '2020-10-30 12:12'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 12:12:00'")); - //valid datetime, support parsing to hour - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '2020-10-30 12'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 12:00:00'")); - //valid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = 20201030"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 00:00:00'")); - //valid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '20201030'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 00:00:00'")); - //valid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '2020-10-30'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 00:00:00'")); - //valid datetime contains micro second - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '2020-10-30 10:00:01.111111'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains(Config.enable_date_conversion - ? "VEMPTYSET" : "PREDICATES: `date` = '2020-10-30 10:00:01'")); - //invalid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '2020-10-32'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: '2020-10-32' in expression: `date` = '2020-10-32'")); - //invalid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = 'hello'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: 'hello' in expression: `date` = 'hello'")); - //invalid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = 2020-10-30"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: 1980 in expression: `date` = 1980")); - //invalid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = 10-30"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: -20 in expression: `date` = -20")); - //invalid datetime - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '2020-10-12 12:23:76'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("Incorrect datetime value: '2020-10-12 12:23:76' in expression: `date` = '2020-10-12 12:23:76'")); - - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '1604031150'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2016-04-03 11:50:00'")); - - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ day from tbl_int_date where date = '1604031150000'"; - explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2016-04-03 11:50:00'")); - - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ count(*) from test.baseall where k11 > to_date(now())"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("PREDICATES: `k11` > to_date")); - - queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ count(*) from test.baseall where k11 > '2021-6-1'"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertTrue(explainString.contains("PREDICATES: `k11` > '2021-06-01 00:00:00'")); - } - - @Test - public void testCompoundPredicateWriteRule() throws Exception { - connectContext.setDatabase("test"); - - // false or e ==> e - String sql1 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where 2=-2 OR query_time=0;"; - String explainString1 = getSQLPlanOrErrorMsg("EXPLAIN " + sql1); - Assert.assertTrue(explainString1.contains("`query_time` = 0")); - - //true or e ==> true - String sql2 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5=-5 OR query_time=0;"; - String explainString2 = getSQLPlanOrErrorMsg("EXPLAIN " + sql2); - Assert.assertTrue(!explainString2.contains("OR")); - - //e or true ==> true - String sql3 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where query_time=0 OR -5=-5;"; - String explainString3 = getSQLPlanOrErrorMsg("EXPLAIN " + sql3); - Assert.assertTrue(!explainString3.contains("OR")); - - //e or false ==> e - String sql4 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5!=-5 OR query_time=0;"; - String explainString4 = getSQLPlanOrErrorMsg("EXPLAIN " + sql4); - Assert.assertTrue(explainString4.contains("`query_time` = 0")); - - - // true and e ==> e - String sql5 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5=-5 AND query_time=0;"; - String explainString5 = getSQLPlanOrErrorMsg("EXPLAIN " + sql5); - Assert.assertTrue(explainString5.contains("`query_time` = 0")); - - // e and true ==> e - String sql6 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where query_time=0 AND -5=-5;"; - String explainString6 = getSQLPlanOrErrorMsg("EXPLAIN " + sql6); - Assert.assertTrue(explainString6.contains("`query_time` = 0")); - - // false and e ==> false - String sql7 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where -5!=-5 AND query_time=0;"; - String explainString7 = getSQLPlanOrErrorMsg("EXPLAIN " + sql7); - Assert.assertTrue(!explainString7.contains("FALSE")); - - // e and false ==> false - String sql8 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where query_time=0 AND -5!=-5;"; - String explainString8 = getSQLPlanOrErrorMsg("EXPLAIN " + sql8); - Assert.assertTrue(!explainString8.contains("FALSE")); - - // (false or expr1) and (false or expr2) ==> expr1 and expr2 - String sql9 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where (-2=2 or query_time=2) and (-2=2 or stmt_id=2);"; - String explainString9 = getSQLPlanOrErrorMsg("EXPLAIN " + sql9); - Assert.assertTrue(explainString9.contains("(`query_time` = 2) AND (`stmt_id` = 2)")); - - // false or (expr and true) ==> expr - String sql10 = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.test1 where (2=-2) OR (query_time=0 AND 1=1);"; - String explainString10 = getSQLPlanOrErrorMsg("EXPLAIN " + sql10); - Assert.assertTrue(explainString10.contains("`query_time` = 0")); - } - - @Test - public void testOutfile() throws Exception { - connectContext.setDatabase("test"); - Config.enable_outfile_to_local = true; - createTable("CREATE TABLE test.`outfile1` (\n" - + " `date` date NOT NULL,\n" - + " `road_code` int(11) NOT NULL DEFAULT \"-1\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`date`, `road_code`)\n" - + "COMMENT \"OLAP\"\n" - + "PARTITION BY RANGE(`date`)\n" - + "(PARTITION v2x_ads_lamp_source_percent_statistic_20210929 VALUES [('2021-09-29'), ('2021-09-30')))\n" - + "DISTRIBUTED BY HASH(`road_code`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"\n" - + ");"); - - // test after query rewrite, outfile still work - String sql = "select * from test.outfile1 where `date` between '2021-10-07' and '2021-10-11'" - + "INTO OUTFILE \"file:///tmp/1_\" FORMAT AS CSV PROPERTIES (" - + " \"column_separator\" = \",\"," - + " \"line_delimiter\" = \"\\n\"," - + " \"max_file_size\" = \"500MB\" );"; - String explainStr = getSQLPlanOrErrorMsg("EXPLAIN " + sql); - if (Config.enable_date_conversion) { - Assert.assertTrue(explainStr.contains("(`date` >= '2021-10-07') AND" - + " (`date` <= '2021-10-11')")); - } else { - Assert.assertTrue(explainStr.contains("(`date` >= '2021-10-07 00:00:00') AND" - + " (`date` <= '2021-10-11 00:00:00')")); - } - } - - // Fix: issue-#7929 - @Test - public void testEmptyNodeWithOuterJoinAndAnalyticFunction() throws Exception { - // create database - String createDbStmtStr = "create database issue7929;"; - CreateDbStmt createDbStmt = (CreateDbStmt) parseAndAnalyzeStmt(createDbStmtStr); - Env.getCurrentEnv().createDb(createDbStmt); - createTable(" CREATE TABLE issue7929.`t1` (\n" - + " `k1` int(11) NULL COMMENT \"\",\n" - + " `k2` int(11) NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`k1`, `k2`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ")"); - createTable("CREATE TABLE issue7929.`t2` (\n" - + " `j1` int(11) NULL COMMENT \"\",\n" - + " `j2` int(11) NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`j1`, `j2`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`j1`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ")"); - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from issue7929.t1 left join (select max(j1) over() as x from issue7929.t2) a" - + " on t1.k1 = a.x where 1 = 0;"; - String explainStr = getSQLPlanOrErrorMsg(sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainStr, 5, "EMPTYSET")); - Assert.assertTrue(explainStr.contains("tuple ids: 5")); - } - - @Ignore - // Open it after fixing issue #7971 - public void testGroupingSetOutOfBoundError() throws Exception { - String createDbStmtStr = "create database issue1111;"; - CreateDbStmt createDbStmt = (CreateDbStmt) parseAndAnalyzeStmt(createDbStmtStr); - Env.getCurrentEnv().createDb(createDbStmt); - createTable("CREATE TABLE issue1111.`test1` (\n" - + " `k1` tinyint(4) NULL COMMENT \"\",\n" - + " `k2` smallint(6) NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\"\n" - + ");"); - String sql = "SELECT k1 ,GROUPING(k2) FROM issue1111.test1 GROUP BY CUBE (k1) ORDER BY k1"; - String explainStr = getSQLPlanOrErrorMsg(sql, true); - System.out.println(explainStr); - } - - // --begin-- implicit cast in explain verbose - @Disabled - public void testExplainInsertInto() throws Exception { - ExplainTest explainTest = new ExplainTest(); - explainTest.before(connectContext); - explainTest.testExplainInsertInto(); - explainTest.testExplainVerboseInsertInto(); - explainTest.testExplainSelect(); - explainTest.testExplainVerboseSelect(); - explainTest.testExplainConcatSelect(); - explainTest.testExplainVerboseConcatSelect(); - explainTest.after(); - } - // --end-- - - // --begin-- rewrite date literal rule - @Disabled - public void testRewriteDateLiteralRule() throws Exception { - RewriteDateLiteralRuleTest rewriteDateLiteralRuleTest = new RewriteDateLiteralRuleTest(); - rewriteDateLiteralRuleTest.before(connectContext); - rewriteDateLiteralRuleTest.testWithDoubleFormatDate(); - rewriteDateLiteralRuleTest.testWithIntFormatDate(); - rewriteDateLiteralRuleTest.testWithInvalidFormatDate(); - rewriteDateLiteralRuleTest.testWithStringFormatDate(); - rewriteDateLiteralRuleTest.testWithDoubleFormatDateV2(); - rewriteDateLiteralRuleTest.testWithIntFormatDateV2(); - rewriteDateLiteralRuleTest.testWithInvalidFormatDateV2(); - rewriteDateLiteralRuleTest.testWithStringFormatDateV2(); - rewriteDateLiteralRuleTest.after(); - } - // --end-- - - @Test - public void testGroupingSets() throws Exception { - String createDbStmtStr = "create database issue7971;"; - CreateDbStmt createDbStmt = (CreateDbStmt) parseAndAnalyzeStmt(createDbStmtStr); - Env.getCurrentEnv().createDb(createDbStmt); - createTable("CREATE TABLE issue7971.`t` (\n" - + " `k1` tinyint(4) NULL COMMENT \"\",\n" - + " `k2` smallint(6) NULL COMMENT \"\",\n" - + " `k3` smallint(6) NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`k1`, `k2`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ")"); - createTable("CREATE TABLE issue7971.`t1` (\n" - + " `k1` tinyint(4) NULL COMMENT \"\",\n" - + " `k21` smallint(6) NULL COMMENT \"\",\n" - + " `k31` smallint(6) NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`k1`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ")"); - String sql = "SELECT k1, k2, GROUPING(k1), GROUPING(k2), SUM(k3) FROM issue7971.t GROUP BY GROUPING SETS ( (k1, k2), (k2), (k1), ( ) );"; - String explainStr = getSQLPlanOrErrorMsg(sql); - Assert.assertTrue(explainStr.contains("REPEAT_NODE")); - sql = "SELECT k1 ,GROUPING(k2) FROM issue7971.t GROUP BY CUBE (k1) ORDER BY k1;"; - explainStr = getSQLPlanOrErrorMsg(sql); - Assert.assertTrue(explainStr.contains("errCode = 2")); - sql = "select grouping_id(t1.k1), t1.k1, max(k2) from issue7971.t left join issue7971.t1 on t.k3 = t1.k1 group by grouping sets ((k1), ());"; - explainStr = getSQLPlanOrErrorMsg(sql); - Assert.assertTrue(explainStr.contains("REPEAT_NODE")); - } - - @Test - public void testQueryWithUsingClause() throws Exception { - connectContext.setDatabase("test"); - String iSql1 = "explain insert into test.tbl_using_a values(1,3,7),(2,2,8),(3,1,9)"; - String iSql2 = "explain insert into test.tbl_using_b values(1,3,1),(3,1,1),(4,1,1),(5,2,1)"; - getSQLPlanOrErrorMsg(iSql1); - getSQLPlanOrErrorMsg(iSql2); - String qSQL = "explain select t1.* from test.tbl_using_a t1 join test.tbl_using_b t2 using(k1,k2) where t1.k1 " - + "between 1 and 3 and t2.k3 between 1+0 and 3+0"; - try { - getSQLPlanOrErrorMsg(qSQL); - } catch (AnalysisException e) { - Assert.fail(); - } - } - - @Test - public void testResultExprs() throws Exception { - connectContext.setDatabase("test"); - createTable("CREATE TABLE test.result_exprs (\n" - + " `aid` int(11) NULL,\n" - + " `bid` int(11) NULL\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`aid`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`aid`) BUCKETS 7\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_medium\" = \"HDD\",\n" - + "\"storage_format\" = \"V2\"\n" - + ");\n"); - String queryStr = "EXPLAIN VERBOSE INSERT INTO result_exprs\n" + "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ a.aid,\n" + " b.bid\n" + "FROM\n" - + " (SELECT 3 AS aid)a\n" + "RIGHT JOIN\n" + " (SELECT 4 AS bid)b ON (a.aid=b.bid)\n"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assert.assertFalse(explainString.contains("OUTPUT EXPRS:\n 3\n 4")); - System.out.println(explainString); - Assert.assertTrue(explainString.contains( - "OUTPUT EXPRS:\n" + " CAST( 3 AS int)\n" + " CAST( 4 AS int)")); - } - - @Test - public void testInsertIntoSelect() throws Exception { - connectContext.setDatabase("test"); - createTable("CREATE TABLE test.`decimal_tb` (\n" - + " `k1` decimal(1, 0) NULL COMMENT \"\",\n" - + " `v1` decimal(1, 0) SUM NULL COMMENT \"\",\n" - + " `v2` decimal(1, 0) MAX NULL COMMENT \"\",\n" - + " `v3` decimal(1, 0) MIN NULL COMMENT \"\",\n" - + " `v4` decimal(1, 0) REPLACE NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`k1`)\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\"\n" - + ")"); - String sql = "explain insert into test.decimal_tb select 1, 1, 1, 1, 1;"; - String explainString = getSQLPlanOrErrorMsg(sql); - Assert.assertTrue(explainString.contains("1 | 1 | 1 | 1 | 1")); - } - - @Test - public void testOutJoinWithOnFalse() throws Exception { - connectContext.setDatabase("test"); - createTable("create table out_join_1\n" - + "(\n" - + " k1 int,\n" - + " v int\n" - + ")\n" - + "DISTRIBUTED BY HASH(k1) BUCKETS 10\n" - + "PROPERTIES(\"replication_num\" = \"1\");"); - - createTable("create table out_join_2\n" - + "(\n" - + " k1 int,\n" - + " v int\n" - + ")\n" - + "DISTRIBUTED BY HASH(k1) BUCKETS 10\n" - + "PROPERTIES(\"replication_num\" = \"1\");"); - - String sql = "explain select * from out_join_1 left join out_join_2 on out_join_1.k1 = out_join_2.k1 and 1=2;"; - String explainString = getSQLPlanOrErrorMsg(sql); - Assert.assertFalse(explainString.contains("non-equal LEFT OUTER JOIN is not supported")); - - sql = "explain select * from out_join_1 right join out_join_2 on out_join_1.k1 = out_join_2.k1 and 1=2;"; - explainString = getSQLPlanOrErrorMsg(sql); - Assert.assertFalse(explainString.contains("non-equal RIGHT OUTER JOIN is not supported")); - - sql = "explain select * from out_join_1 full join out_join_2 on out_join_1.k1 = out_join_2.k1 and 1=2;"; - explainString = getSQLPlanOrErrorMsg(sql); - Assert.assertFalse(explainString.contains("non-equal FULL OUTER JOIN is not supported")); - - } - - @Test - public void testDefaultJoinReorder() throws Exception { - connectContext.setDatabase("test"); - createTable("CREATE TABLE t1 (col1 varchar, col2 varchar, col3 int)\n" + "DISTRIBUTED BY HASH(col3)\n" - + "BUCKETS 3\n" + "PROPERTIES(\n" + " \"replication_num\"=\"1\"\n" + ");"); - createTable("CREATE TABLE t2 (col1 varchar, col2 varchar, col3 int)\n" + "DISTRIBUTED BY HASH(col3)\n" - + "BUCKETS 3\n" + "PROPERTIES(\n" + " \"replication_num\"=\"1\"\n" + ");"); - createTable("CREATE TABLE t3 (col1 varchar, col2 varchar, col3 int)\n" + "DISTRIBUTED BY HASH(col3)\n" - + "BUCKETS 3\n" + "PROPERTIES(\n" + " \"replication_num\"=\"1\"\n" + ");"); - String sql = "explain select x.col2 from t1,t2,t3 x,t3 y " - + "where x.col1=t2.col1 and y.col1=t2.col2 and t1.col1=y.col1"; - String explainString = getSQLPlanOrErrorMsg(sql); - Assert.assertFalse(explainString.contains("CROSS JOIN")); - - } - - @Test - public void testDefaultJoinReorderWithView() throws Exception { - connectContext.setDatabase("test"); - createTable("CREATE TABLE t_1 (col1 varchar, col2 varchar, col3 int)\n" + "DISTRIBUTED BY HASH(col3)\n" - + "BUCKETS 3\n" + "PROPERTIES(\n" + " \"replication_num\"=\"1\"\n" + ");"); - createTable("CREATE TABLE t_2 (col1 varchar, col2 varchar, col3 int)\n" + "DISTRIBUTED BY HASH(col3)\n" - + "BUCKETS 3\n" + "PROPERTIES(\n" + " \"replication_num\"=\"1\"\n" + ");"); - createView("CREATE VIEW v_1 as select col1 from t_1;"); - createView("CREATE VIEW v_2 as select x.col2 from (select t_2.col2, 1 + 1 from t_2) x;"); - - String sql = "explain select t_1.col2, v_1.col1 from t_1 inner join t_2 on t_1.col1 = t_2.col1 inner join v_1 " - + "on v_1.col1 = t_2.col2 inner join v_2 on v_2.col2 = t_2.col1"; - String explainString = getSQLPlanOrErrorMsg(sql); - System.out.println(explainString); - // errCode = 2, detailMessage = Unknown column 'col2' in 't_2' - Assert.assertFalse(explainString.contains("errCode")); - } - - @Test - public void testKeyOrderError() throws Exception { - Assertions.assertTrue(getSQLPlanOrErrorMsg("CREATE TABLE `test`.`test_key_order` (\n" - + " `k1` tinyint(4) NULL COMMENT \"\",\n" - + " `k2` smallint(6) NULL COMMENT \"\",\n" - + " `k3` int(11) NULL COMMENT \"\",\n" - + " `v1` double MAX NULL COMMENT \"\",\n" - + " `v2` float SUM NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`k1`, `k3`, `k2`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`k1`) BUCKETS 5\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\"\n" - + ");").contains("Key columns should be a ordered prefix of the schema. " - + "KeyColumns[1] (starts from zero) is k3, " - + "but corresponding column is k2 in the previous columns declaration.")); - } - - @Test - public void testPreaggregationOfOrthogonalBitmapUDAF() throws Exception { - connectContext.setDatabase("test"); - createTable("CREATE TABLE test.bitmap_tb (\n" - + " `id` int(11) NULL COMMENT \"\",\n" - + " `id2` int(11) NULL COMMENT \"\",\n" - + " `id3` bitmap bitmap_union \n" - + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`id`,`id2`)\n" - + "DISTRIBUTED BY HASH(`id`) BUCKETS 1\n" - + "PROPERTIES (\n" - + " \"replication_num\" = \"1\"\n" - + ");"); - - String queryBaseTableStr = "explain select id,id2,orthogonal_bitmap_union_count(id3) from test.bitmap_tb t1 group by id,id2"; - String explainString1 = getSQLPlanOrErrorMsg(queryBaseTableStr); - Assert.assertTrue(explainString1.contains("PREAGGREGATION: ON")); - - String queryTableStr = "explain select id,orthogonal_bitmap_union_count(id3) from test.bitmap_tb t1 group by id"; - String explainString2 = getSQLPlanOrErrorMsg(queryTableStr); - Assert.assertTrue(explainString2.contains("PREAGGREGATION: ON")); - } - - @Test - public void testPreaggregationOfHllUnion() throws Exception { - connectContext.setDatabase("test"); - createTable("create table test.test_hll(\n" - + " dt date,\n" - + " id int,\n" - + " name char(10),\n" - + " province char(10),\n" - + " os char(10),\n" - + " pv hll hll_union\n" - + ")\n" - + "Aggregate KEY (dt,id,name,province,os)\n" - + "distributed by hash(id) buckets 10\n" - + "PROPERTIES(\n" - + " \"replication_num\" = \"1\",\n" - + " \"in_memory\"=\"false\"\n" - + ");"); - - String queryBaseTableStr = "explain select dt, hll_union(pv) from test.test_hll group by dt"; - String explainString = getSQLPlanOrErrorMsg(queryBaseTableStr); - Assert.assertTrue(explainString.contains("PREAGGREGATION: ON")); - } - - /* - NOTE: - explainString.contains("PREDICATES: xxx\n") - add '\n' at the end of line to ensure there are no other predicates - */ - @Test - public void testRewriteOrToIn() throws Exception { - connectContext.setDatabase("test"); - connectContext.getSessionVariable().setEnableRewriteElementAtToSlot(false); - String sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where query_time = 1 or query_time = 2 or query_time in (3, 4)"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2, 3, 4)\n")); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2) and query_time in (3, 4)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: (`query_time` IN (1, 2) AND `query_time` IN (3, 4))\n")); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2 or scan_bytes = 2) and scan_bytes in (2, 3)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: ((`query_time` IN (1, 2) OR (`scan_bytes` = 2)) AND `scan_bytes` IN (2, 3))\n")); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2) and (scan_bytes = 2 or scan_bytes = 3)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: (`query_time` IN (1, 2) AND `scan_bytes` IN (2, 3))\n")); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where query_time = 1 or query_time = 2 or query_time = 3 or query_time = 1"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2, 3)\n")); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where query_time = 1 or query_time = 2 or query_time in (3, 2)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2, 3)\n")); - - connectContext.getSessionVariable().setRewriteOrToInPredicateThreshold(100); - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where query_time = 1 or query_time = 2 or query_time in (3, 4)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: (((`query_time` = 1) OR (`query_time` = 2)) OR `query_time` IN (3, 4))\n")); - connectContext.getSessionVariable().setRewriteOrToInPredicateThreshold(2); - - sql = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2) and query_time in (3, 4)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: (`query_time` IN (1, 2) AND `query_time` IN (3, 4))\n")); - - //test we can handle `!=` and `not in` - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2 or query_time!= 3 or query_time not in (5, 6))"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: (`query_time` IN (1, 2) OR ((`query_time` != 3) OR `query_time` NOT IN (5, 6)))\n")); - - //test we can handle merge 2 or more columns - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2 or scan_rows = 3 or scan_rows = 4)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: (`query_time` IN (1, 2) OR `scan_rows` IN (3, 4))")); - - //merge in-pred or in-pred - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (query_time = 1 or query_time = 2 or query_time = 3 or query_time = 4)"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains("PREDICATES: `query_time` IN (1, 2, 3, 4)\n")); - - //rewrite recursively - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 " - + "where query_id=client_ip " - + " and (stmt_id=1 or stmt_id=2 or stmt_id=3 " - + " or (user='abc' and (state = 'a' or state='b' or state in ('c', 'd'))))" - + " or (db not in ('x', 'y')) "; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains( - "PREDICATES: (((`query_id` = `client_ip`) AND (`stmt_id` IN (1, 2, 3) OR ((`user` = 'abc') " - + "AND `state` IN ('a', 'b', 'c', 'd')))) OR (`db` NOT IN ('x', 'y')))\n")); - - //ExtractCommonFactorsRule may generate more expr, test the rewriteOrToIn applied on generated exprs - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from test1 where (stmt_id=1 and state='a') or (stmt_id=2 and state='b')"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql); - Assert.assertTrue(explainString.contains( - "PREDICATES: ((`state` IN ('a', 'b') AND `stmt_id` IN (1, 2)) AND (((`stmt_id` = 1) AND " - + "(`state` = 'a')) OR ((`stmt_id` = 2) AND (`state` = 'b'))))\n" - )); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/RepeatNodeTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/RepeatNodeTest.java deleted file mode 100644 index 9a9b1a3b8c5fec4..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/RepeatNodeTest.java +++ /dev/null @@ -1,80 +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.doris.planner; - -import org.apache.doris.utframe.TestWithFeService; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class RepeatNodeTest extends TestWithFeService { - - @Override - protected void runBeforeAll() throws Exception { - createDatabase("testdb"); - useDatabase("testdb"); - createTable(" CREATE TABLE `testdb`.`mycost` (\n" + " `id` tinyint(4) NULL,\n" + " `name` varchar(20) NULL,\n" - + " `date` date NULL,\n" + " `cost` bigint(20) SUM NULL\n" + ") ENGINE=OLAP\n" - + "AGGREGATE KEY(`id`, `name`, `date`)\n" + "COMMENT 'OLAP'\n" + "PARTITION BY RANGE(`date`)\n" - + "(PARTITION p2020 VALUES [('0000-01-01'), ('2021-01-01')),\n" - + "PARTITION p2021 VALUES [('2021-01-01'), ('2022-01-01')),\n" - + "PARTITION p2022 VALUES [('2022-01-01'), ('2023-01-01')))\n" + "DISTRIBUTED BY HASH(`id`) BUCKETS 8\n" - + "PROPERTIES (\n" + "\"replication_allocation\" = \"tag.location.default: 1\",\n" - + "\"in_memory\" = \"false\",\n" + "\"storage_format\" = \"V2\"\n" + ");"); - - createTable( - " CREATE TABLE `testdb`.`mypeople` (\n" + " `id` bigint(20) NULL,\n" + " `name` varchar(20) NULL,\n" - + " `sex` varchar(10) NULL,\n" + " `age` int(11) NULL,\n" + " `phone` char(15) NULL,\n" - + " `address` varchar(50) NULL\n" + ") ENGINE=OLAP\n" + "DUPLICATE KEY(`id`, `name`)\n" - + "COMMENT 'OLAP'\n" + "DISTRIBUTED BY HASH(`id`) BUCKETS 8\n" + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\",\n" + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" + ");"); - } - - @Test - public void testNormal() throws Exception { - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ id, name, sum(cost), grouping_id(id, name) from mycost group by cube(id, name);"; - String explainString = getSQLPlanOrErrorMsg("explain " + sql); - Assertions.assertTrue(explainString.contains("exprs: `id`, `name`, `cost`")); - Assertions.assertTrue(explainString.contains( - "output slots: ``id``, ``name``, ``cost``, ``GROUPING_ID``, ``GROUPING_PREFIX_`id`_`name```")); - } - - @Test - public void testExpr() throws Exception { - String sql1 = "select /*+ SET_VAR(enable_nereids_planner=false) */ if(c.id > 0, 1, 0) as id_, p.name, sum(c.cost) from mycost c " - + "join mypeople p on c.id = p.id group by grouping sets((id_, name),());"; - String explainString1 = getSQLPlanOrErrorMsg("explain " + sql1); - System.out.println(explainString1); - Assertions.assertTrue(explainString1.contains( - "output slots: `if((`c`.`id` > 0), 1, 0)`, ``p`.`name``, ``c`.`cost``, ``GROUPING_ID``")); - - String sql2 = "select /*+ SET_VAR(enable_nereids_planner=false) */ (id + 1) id_, name, sum(cost) from mycost group by grouping sets((id_, name),());"; - String explainString2 = getSQLPlanOrErrorMsg("explain " + sql2); - System.out.println(explainString2); - Assertions.assertTrue(explainString2.contains("exprs: ((`id` + 1)), `name`, `cost`")); - Assertions.assertTrue( - explainString2.contains(" output slots: `((`id` + 1))`, ``name``, ``cost``, ``GROUPING_ID``")); - - String sql3 = "select /*+ SET_VAR(enable_nereids_planner=false) */ 1 as id_, name, sum(cost) from mycost group by grouping sets((id_, name),());"; - String explainString3 = getSQLPlanOrErrorMsg("explain " + sql3); - System.out.println(explainString3); - Assertions.assertTrue(explainString3.contains("exprs: 1, `name`, `cost`")); - Assertions.assertTrue(explainString3.contains("output slots: `1`, ``name``, ``cost``, ``GROUPING_ID``")); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java deleted file mode 100644 index 98f368427953412..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java +++ /dev/null @@ -1,554 +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.doris.planner; - -import org.apache.doris.analysis.CreateDbStmt; -import org.apache.doris.analysis.CreateTableStmt; -import org.apache.doris.analysis.CreateViewStmt; -import org.apache.doris.catalog.Env; -import org.apache.doris.qe.ConnectContext; -import org.apache.doris.utframe.UtFrameUtils; - -import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.util.UUID; - -public class TableFunctionPlanTest { - private static final String runningDir = "fe/mocked/TableFunctionPlanTest/" + UUID.randomUUID() + "/"; - private static ConnectContext ctx; - - @After - public void tearDown() throws Exception { - FileUtils.deleteDirectory(new File(runningDir)); - } - - @BeforeClass - public static void setUp() throws Exception { - UtFrameUtils.createDorisCluster(runningDir); - ctx = UtFrameUtils.createDefaultCtx(); - String createDbStmtStr = "create database db1;"; - CreateDbStmt createDbStmt = (CreateDbStmt) UtFrameUtils.parseAndAnalyzeStmt(createDbStmtStr, ctx); - Env.getCurrentEnv().createDb(createDbStmt); - // 3. create table tbl1 - String createTblStmtStr = "create table db1.tbl1(k1 int, k2 varchar(1), k3 varchar(1)) " - + "DUPLICATE KEY(k1) distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - CreateTableStmt createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx); - Env.getCurrentEnv().createTable(createTableStmt); - - createTblStmtStr = "create table db1.tbl2(k1 int, k2 varchar(1), v1 bitmap bitmap_union) " - + "distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx); - Env.getCurrentEnv().createTable(createTableStmt); - - createTblStmtStr = "create table db1.table_for_view (k1 int, k2 int, k3 varchar(100)) distributed by hash(k1)" - + "properties('replication_num' = '1');"; - createTableStmt = (CreateTableStmt) UtFrameUtils.parseAndAnalyzeStmt(createTblStmtStr, ctx); - Env.getCurrentEnv().createTable(createTableStmt); - } - - // test planner - /* Case1 normal table function - select k1, e1 from table lateral view explode_split(k2, ",") tmp as e1; - */ - @Test - public void normalTableFunction() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl1 lateral view explode_split(k2, \",\") tmp as e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("tuple ids: 0 1")); - Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e1, colUniqueId=-1, type=varchar")); - } - - /* Case2 without output explode column - select k1 from table lateral view explode_split(k2, ",") tmp as e1; - */ - @Test - public void withoutOutputExplodeColumn() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 lateral view explode_split(k2, \",\") tmp as e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString.contains("OUTPUT EXPRS:\n `k1`")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("tuple ids: 0 1")); - Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e1, colUniqueId=-1, type=varchar")); - } - - /* Case3 group by explode column - select k1, e1, count(*) from table lateral view explode_split(k2, ",") tmp as e1 group by k1 e1; - */ - @Test - public void groupByExplodeColumn() throws Exception { - String sql = - "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1, count(*) from db1.tbl1 lateral view explode_split(k2, \",\") tmp as e1 " - + "group by k1, e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - // group by node with k1, e1 - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 2, "AGGREGATE (update finalize)")); - Assert.assertTrue(explainString.contains("group by: `k1`, `e1`")); - // table function node - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("tuple ids: 0 1")); - Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e1, colUniqueId=-1, type=varchar")); - // group by tuple - Assert.assertTrue(explainString.contains("TupleDescriptor{id=2, tbl=null")); - } - - /* Case4 where explode column - select k1, e1 from table lateral view explode_split(k2, ",") tmp as e1 where e1 = "1"; - */ - @Test - public void whereExplodeColumn() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl1 lateral view explode_split(k2, \",\") tmp as e1 " - + "where e1='1'; "; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("`e1` = '1'")); - Assert.assertTrue(explainString.contains("tuple ids: 0 1")); - Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e1, colUniqueId=-1, type=varchar")); - } - - /* Case5 where normal column - select k1, e1 from table lateral view explode_split(k2, ",") tmp as e1 where k1 = 1; - */ - @Test - public void whereNormalColumn() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl1 lateral view explode_split(k2, \",\") tmp as e1 " - + "where k1=1; "; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("tuple ids: 0 1")); - Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e1, colUniqueId=-1, type=varchar")); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 0, "OlapScanNode")); - Assert.assertTrue(explainString.contains("`k1` = 1")); - } - - /* Case6 multi lateral view - select k1, e1, e2 from table lateral view explode_split(k2, ",") tmp1 as e1 - lateral view explode_split(k2, ",") tmp2 as e2; - */ - @Test - public void testMultiLateralView() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1, e2 from db1.tbl1 lateral view explode_split(k2, \",\") tmp1 as e1" - + " lateral view explode_split(k2, \",\") tmp2 as e2;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue(explainString.contains( - "table function: explode_split(`db1`.`tbl1`.`k2`, ',') explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 1 2")); - // lateral view 2 tuple - Assert.assertTrue(explainString.contains("TupleDescriptor{id=1, tbl=tmp2")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=e2, colUniqueId=-1, type=varchar")); - // lateral view 1 tuple - Assert.assertTrue(explainString.contains("TupleDescriptor{id=2, tbl=tmp1")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=2, col=e1, colUniqueId=-1, type=varchar")); - } - - // test explode_split function - // k1 int ,k2 string - /* Case1 error param - select k1, e1 from table lateral view explode_split(k2) tmp as e1; - select k1, e1 from table lateral view explode_split(k1) tmp as e1; - select k1, e1 from table lateral view explode_split(k2, k2) tmp as e1; - */ - @Test - public void errorParam() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl1 lateral view explode_split(k2) tmp as e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql); - Assert.assertTrue(explainString.contains("No matching function with signature: explode_split(varchar(1))")); - - sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl1 lateral view explode_split(k1) tmp as e1;"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql); - Assert.assertTrue(explainString.contains("No matching function with signature: explode_split(int)")); - } - - /* Case2 table function in where stmt - select k1 from table where explode_split(k2, ",") = "1"; - */ - @Test - public void tableFunctionInWhere() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where explode_split(k2, \",\");"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql); - Assert.assertTrue(explainString, - explainString.contains("No matching function with signature: explode_split(varchar(1), varchar(65533)).")); - } - - // test projection - /* Case1 the source column is not be projected - select k1, e1 from table lateral view explode_split(k2, ",") t1 as e1 - project column: k1, e1 - prune column: k2 - */ - @Test - public void nonProjectSourceColumn() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl1 lateral view explode_split(k2, \",\") tmp1 as e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 1")); - Assert.assertTrue(explainString.contains("output slot id: 1 2")); - } - - /* - Case2 the lateral view column is projected when it is in the agg function. - select k1, sum(cast(e1 as int)) from table lateral view explode_split(k2, ",") t1 as e1 group by k1; - project column: k1, e1 - prune column: k2 - */ - @Test - public void projectLateralViewColumn() throws Exception { - String sql = - "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, sum(cast(e1 as int)) from db1.tbl1 lateral view explode_split(k2, \",\") tmp1 as e1" - + " group by k1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 1")); - Assert.assertTrue(explainString.contains("output slot id: 1 2")); - } - - /* - Case3 the source column is not be projected when it is in the where clause - select k1, e1 from table lateral view explode_split(k2, ",") t1 as e1 where k2=1; - project column: k1, e1 - prune column: k2 - */ - @Test - public void nonProjectSourceColumnWhenInWhereClause() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl1 lateral view explode_split(k2, \",\") tmp1 as e1" - + " where k2=1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(`db1`.`tbl1`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 1")); - Assert.assertTrue(explainString.contains("output slot id: 1 2")); - } - - /* - Case4 the source column is projected when predicate could not be pushed down - select a.k1, t1.e1 from table a lateral view explode_split(k2, ",") t1 as e1 - right join table b on a.k1=b.k1 where k2=1; - project column: k1, k2, e1 - */ - @Test - public void projectSourceColumnWhenPredicateCannotPushedDown() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1, tmp1.e1 from db1.tbl1 a lateral view explode_split(k2, \",\") tmp1 as e1" - + " right join db1.tbl1 b on a.k1=b.k1 where a.k2=1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue(explainString.contains("table function: explode_split(`a`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 1")); - Assert.assertTrue(explainString.contains("output slot id: 0 1 2")); - } - - /* - Case5 There is only one source column in select items - select a.k1 from table a lateral view explode_split(k2, ",") t1 as e1 - left join table b on a.k1=b.k1 where k2=1 - project column: k1 - prune column: k2, e1 - */ - @Test - public void nonProjectLateralColumnAndSourceColumn() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.tbl1 a lateral view explode_split(k2, \",\") tmp1 as e1" - + " left join db1.tbl1 b on a.k1=b.k1 where a.k2=1"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue(explainString.contains("table function: explode_split(`a`.`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 1")); - Assert.assertTrue(explainString.contains("output slot id: 2")); - } - - // scalar function in explode_split - /* - Case1 invalid column in scalar function - select a.k1 from table a lateral view explode_split(t2.k2, ",") t1 as e1 - invalid column: t2.k2 - Case2 - select a.k1 from table a lateral view explode_split(k100, ",") t1 as e1 - invalid column: t1.k100 - Case3 - select a.k1 from db1.table a lateral view explode_split(db2.table.k2, ",") t1 as e1 - invalid column: db2.table.k2 - */ - @Test - public void invalidColumnInExplodeSplit() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.tbl1 a lateral view explode_split(tbl2.k1, \",\") tmp1 as e1"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString, explainString.contains("The column `tbl2`.`k1` in lateral view must come from the origin table `a`")); - sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.tbl1 a lateral view explode_split(k100, \",\") tmp1 as e1"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString, explainString.contains("Unknown column 'k100'")); - sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.tbl1 a lateral view explode_split(db2.tbl1.k2, \",\") tmp1 as e1"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString, explainString.contains("The column `db2`.`tbl1`.`k2` in lateral view must come from the origin table")); - } - - /* - Case1 invalid agg function - select a.k1 from db1.tbl1 a lateral view explode_split(sum(a.k1), ",") tmp1 as e1 - Case2 subquery - select a.k1 from db1.tbl1 a lateral view explode_split(a in ) - */ - @Test - public void invalidFunctionInLateralView() throws Exception { - String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.tbl1 a lateral view explode_split(sum(k1), \",\") tmp1 as e1"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString.contains("Agg function are not allowed in lateral view.")); - sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.tbl1 a lateral view explode_split(k1=(select k1 from db1.tbl1), \",\") tmp1 as e1"; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString.contains("Subquery is not allowed in lateral view")); - } - - /* - Case1 valid scalar function - select a.k1 from db1.tbl1 a lateral view explode_split(concat('a', ',', 'b'), ",") tmp1 as e1 - */ - @Test - public void scalarFunctionInLateralView() throws Exception { - String sql = - "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ a.k1 from db1.tbl1 a lateral view explode_split(concat(k2, ',' , k3), \",\") tmp1 as e1 "; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue( - explainString.contains("table function: explode_split(concat(`a`.`k2`, ',', `a`.`k3`), ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 1")); - Assert.assertTrue(explainString.contains("output slot id: 3")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=0, col=k2, colUniqueId=1, type=varchar(1)")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=1, col=k3, colUniqueId=2, type=varchar(1)")); - } - - // lateral view of subquery - /* - Case1 reduce tuple of subquery - select e1 from (select k1 as c1 from tbl1) tmp1 lateral view explode_split(c1, ",") tmp2 as e1 - */ - @Test - public void lateralViewColumnOfReduceTuple() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ e1 from (select k2 as c1 from db1.tbl1) a lateral view explode_split(c1, \",\") tmp1 as e1 "; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 1, "TABLE FUNCTION NODE")); - Assert.assertTrue(explainString.contains("table function: explode_split(`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 2")); - Assert.assertTrue(explainString.contains("output slot id: 2")); - Assert.assertTrue(explainString.contains("tuple ids: 0 2")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=2, col=e1, colUniqueId=-1, type=varchar")); - } - - /* - Case2 agg column of inlineview - select e1 from (select k1 as c1 from tbl1 group by k1) tmp1 lateral view explode_split(c1, ",") tmp2 as e1 - */ - @Test - public void aggInlineView() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ e1 from (select k2 as c1 from db1.tbl1 group by c1) a lateral view explode_split(c1, \",\") tmp1 as e1 "; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 2, "TABLE FUNCTION NODE")); - Assert.assertTrue(explainString.contains("table function: explode_split(`k2`, ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 3")); - Assert.assertTrue(explainString.contains("output slot id: 3")); - Assert.assertTrue(explainString.contains("tuple ids: 1 3")); - Assert.assertTrue(explainString.contains("SlotDescriptor{id=3, col=e1, colUniqueId=-1, type=varchar")); - } - - /* - Case3 materialize inline view column - select c1, e1 from (select k1 as c1, min(k2) as c2 from tbl1 group by k1) tmp1 lateral view explode_split(c2, ",") tmp2 as e1 - */ - @Test - public void aggColumnInlineViewInTB() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ c1, e1 from (select k1 as c1, min(k2) as c2 from db1.tbl1 group by c1) a " - + "lateral view explode_split(c2, \",\") tmp1 as e1"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 2, "TABLE FUNCTION NODE")); - Assert.assertTrue(explainString.contains("table function: explode_split(min(`k2`), ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 3")); - Assert.assertTrue(explainString.contains("output slot id: 2 6")); - Assert.assertTrue(explainString.contains("tuple ids: 1 3")); - String formatString = explainString.replaceAll(" ", ""); - Assert.assertTrue(formatString.contains( - "SlotDescriptor{id=0,col=k1,colUniqueId=0,type=int" - )); - Assert.assertTrue(formatString.contains( - "SlotDescriptor{id=1,col=k2,colUniqueId=1,type=varchar(1)" - )); - Assert.assertTrue(formatString.contains( - "SlotDescriptor{id=2,col=k1,colUniqueId=0,type=int" - )); - Assert.assertTrue(formatString.contains( - "SlotDescriptor{id=3,col=null,colUniqueId=null,type=varchar" - )); - Assert.assertTrue(formatString.contains( - "SlotDescriptor{id=6,col=e1,colUniqueId=-1,type=varchar" - )); - } - - @Test - public void testExplodeBitmap() throws Exception { - String sql = "desc select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl2 lateral view explode_bitmap(v1) tmp1 as e1 "; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - System.out.println(explainString); - Assert.assertTrue(explainString.contains("table function: explode_bitmap(`db1`.`tbl2`.`v1`)")); - Assert.assertTrue(explainString.contains("output slot id: 1 2")); - } - - @Test - public void testExplodeJsonArray() throws Exception { - String sql = "desc select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl2 lateral view explode_json_array_int('[1,2,3]') tmp1 as e1 "; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - System.out.println(explainString); - Assert.assertTrue(explainString.contains("table function: explode_json_array_int('[1,2,3]')")); - Assert.assertTrue(explainString.contains("output slot id: 0 1")); - - sql = "desc select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl2 lateral view explode_json_array_string('[\"a\",\"b\",\"c\"]') tmp1 as e1 "; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - System.out.println(explainString); - Assert.assertTrue(explainString.contains("table function: explode_json_array_string('[\"a\",\"b\",\"c\"]')")); - Assert.assertTrue(explainString.contains("output slot id: 0 1")); - - sql = "desc select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl2 lateral view explode_json_array_double('[1.1, 2.2, 3.3]') tmp1 as e1 "; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - System.out.println(explainString); - Assert.assertTrue(explainString.contains("table function: explode_json_array_double('[1.1, 2.2, 3.3]')")); - Assert.assertTrue(explainString.contains("output slot id: 0 1")); - - sql = "desc select /*+ SET_VAR(enable_nereids_planner=false) */ k1, e1 from db1.tbl2 lateral view explode_json_array_json('[{\"id\":1,\"name\":\"John\"},{\"id\":2,\"name\":\"Mary\"},{\"id\":3,\"name\":\"Bob\"}]') tmp1 as e1 "; - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - System.out.println(explainString); - Assert.assertTrue(explainString.contains("table function: explode_json_array_json('[{\"id\":1,\"name\":\"John\"},{\"id\":2,\"name\":\"Mary\"},{\"id\":3,\"name\":\"Bob\"}]')")); - Assert.assertTrue(explainString.contains("output slot id: 0 1")); - } - - /* - Case4 agg and order column in the same stmt with lateral view - select min(c1) from (select k1 as c1, min(k2) as c2 from tbl1 group by k1) tmp1 - lateral view explode_split(c2, ",") tmp2 as e1 order by min(c1) - */ - @Test - public void aggColumnForbidden() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ min(c1) from (select k1 as c1, min(k2) as c2 from db1.tbl1 group by c1) a " - + "lateral view explode_split(c2, \",\") tmp1 as e1 order by min(c1)"; - String errorMsg = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(errorMsg.toLowerCase().contains("lateral view as a inline view")); - } - - /* - Case5 agg and order column in the outer level - select min(c1) from (select c1 from (select k1 as c1, min(k2) as c2 from tbl1 group by k1) tmp1 - lateral view explode_split(c2, ",") tmp2 as e1 ) tmp3 - */ - @Test - public void aggColumnInOuterQuery() throws Exception { - String sql = "desc verbose select /*+ SET_VAR(enable_nereids_planner=false) */ min(c1) from (select c1 from" - + " (select k1 as c1, min(k2) as c2 from db1.tbl1 group by c1) a " - + "lateral view explode_split(c2, \",\") tmp1 as e1) tmp2"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(UtFrameUtils.checkPlanResultContainsNode(explainString, 2, "TABLE FUNCTION NODE")); - Assert.assertTrue(explainString.contains("table function: explode_split(min(`k2`), ',')")); - Assert.assertTrue(explainString.contains("lateral view tuple id: 3")); - Assert.assertTrue(explainString.contains("output slot id: 2")); - Assert.assertTrue(explainString.contains("tuple ids: 1 3")); - } - - @Test - public void testLateralViewWithView() throws Exception { - // test 1 - String createViewStr = "create view db1.v1 (k1,e1) as select /*+ SET_VAR(enable_nereids_planner=false) */ k1,e1" - + " from db1.table_for_view lateral view explode_split(k3,',') tmp as e1;"; - CreateViewStmt createViewStmt = (CreateViewStmt) UtFrameUtils.parseAndAnalyzeStmt(createViewStr, ctx); - Env.getCurrentEnv().createView(createViewStmt); - - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.v1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString.contains("output slot id: 1 2")); - // query again to see if it has error - explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString.contains("output slot id: 1 2")); - } - - @Test - public void testLateralViewWithWhere() throws Exception { - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ k1,e1 from db1.table_for_view lateral view explode_split(k3,',') tmp as e1" - + " where k1 in (select k2 from db1.table_for_view);"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString.contains("join op: LEFT SEMI JOIN(BROADCAST)")); - Assert.assertTrue(explainString.contains("`k1` = `k2`")); - Assert.assertTrue(!explainString.contains("`k2` = `k2`")); - } - - @Test - public void testLateralViewWithCTE() throws Exception { - String sql = "with tmp as (select k1,e1 from db1.table_for_view lateral view explode_split(k3,',') tmp2 as e1)" - + " select /*+ SET_VAR(enable_nereids_planner=false) */ * from tmp;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertTrue(explainString.contains("table function:" - + " explode_split(`db1`.`table_for_view`.`k3`, ',') ")); - } - - @Test - public void testLateralViewWithCTEBug() throws Exception { - String sql = "with tmp as (select * from db1.table_for_view where k2=1)" - + " select /*+ SET_VAR(enable_nereids_planner=false) */ k1,e1 from tmp lateral view explode_split(k3,',') tmp2 as e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertFalse(explainString.contains("Unknown column 'e1' in 'table list'")); - } - - @Test - public void testLateralViewUnknownColumnBug() throws Exception { - // test2 - String createViewStr = "create view db1.v2 (k1,k3) as select k1,k3 from db1.table_for_view;"; - CreateViewStmt createViewStmt = (CreateViewStmt) UtFrameUtils.parseAndAnalyzeStmt(createViewStr, ctx); - Env.getCurrentEnv().createView(createViewStmt); - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ k1,e1 from db1.v2 lateral view explode_split(k3,',') tmp as e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertFalse(explainString.contains("Unknown column 'e1' in 'table list'")); - } - - - // The 'k1' column in 'd' view should be materialized - // Fix #8850 - @Test - public void testLateralViewWithInlineViewBug() throws Exception { - String sql = "with d as (select k1+k1 as k1 from db1.table_for_view ) " - + "select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from d lateral view explode_split(k1,',') tmp as e1;"; - String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql, true); - Assert.assertFalse(explainString.contains("Unexpected exception: org.apache.doris.analysis.FunctionCallExpr" - + " cannot be cast to org.apache.doris.analysis.SlotRef")); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java b/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java index aa04c14bbe9c6ba..f803dc10563193c 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java @@ -105,22 +105,6 @@ public void testNoPolicy() throws Exception { @Test public void testNormalSql() throws Exception { - // test user - createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); - String queryStr = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("`k1` = 1")); - dropPolicy("DROP ROW POLICY test_row_policy ON test.table1"); - // test role - createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO ROLE role1 USING (k1 = 2)"); - queryStr = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("`k1` = 2")); - dropPolicy("DROP ROW POLICY test_row_policy ON test.table1 for role role1"); - } - - @Test - public void testNormalSqlNereidsPlanners() throws Exception { // test user createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); String queryStr = "EXPLAIN select * from test.table1"; @@ -137,16 +121,6 @@ public void testNormalSqlNereidsPlanners() throws Exception { @Test public void testUniqueTable() throws Exception { - // test user - createPolicy("CREATE ROW POLICY test_unique_policy ON test.table3 AS PERMISSIVE TO test_policy USING (k1 = 1)"); - String queryStr = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table3"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("`k1` = 1")); - dropPolicy("DROP ROW POLICY test_unique_policy ON test.table3"); - } - - @Test - public void testUniqueTableNereidsPlanners() throws Exception { // test user createPolicy("CREATE ROW POLICY test_unique_policy ON test.table3 AS PERMISSIVE TO test_policy USING (k1 = 1)"); String queryStr = "EXPLAIN select * from test.table3"; @@ -157,20 +131,6 @@ public void testUniqueTableNereidsPlanners() throws Exception { @Test public void testAliasSql() throws Exception { - createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); - String queryStr = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1 a"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("`a`.`k1` = 1")); - queryStr = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1 b"; - explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("`b`.`k1` = 1")); - dropPolicy("DROP ROW POLICY test_row_policy ON test.table1"); - } - - @Test - public void testAliasSqlNereidsPlanner() throws Exception { - boolean beforeConfig = connectContext.getSessionVariable().isEnableNereidsPlanner(); - connectContext.getSessionVariable().setEnableNereidsPlanner(true); createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); String queryStr = "EXPLAIN select * from test.table1 a"; String explainString = getSQLPlanOrErrorMsg(queryStr); @@ -179,21 +139,10 @@ public void testAliasSqlNereidsPlanner() throws Exception { explainString = getSQLPlanOrErrorMsg(queryStr); Assertions.assertTrue(explainString.contains("k1[#0] = 1")); dropPolicy("DROP ROW POLICY test_row_policy ON test.table1"); - connectContext.getSessionVariable().setEnableNereidsPlanner(beforeConfig); } @Test public void testUnionSql() throws Exception { - createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); - String queryStr - = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1 union all select * from test.table1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("`k1` = 1")); - dropPolicy("DROP ROW POLICY test_row_policy ON test.table1"); - } - - @Test - public void testUnionSqlNereidsPlanner() throws Exception { createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); String queryStr = "EXPLAIN select * from test.table1 union all select * from test.table1"; String explainString = getSQLPlanOrErrorMsg(queryStr); @@ -203,16 +152,6 @@ public void testUnionSqlNereidsPlanner() throws Exception { @Test public void testInsertSelectSql() throws Exception { - createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); - String queryStr - = "EXPLAIN insert into test.table1 select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("`k1` = 1")); - dropPolicy("DROP ROW POLICY test_row_policy ON test.table1"); - } - - @Test - public void testInsertSelectSqlNereidsPlanner() throws Exception { createPolicy("CREATE ROW POLICY test_row_policy ON test.table1 AS PERMISSIVE TO test_policy USING (k1 = 1)"); String queryStr = "EXPLAIN insert into test.table1 select * from test.table1"; String explainString = getSQLPlanOrErrorMsg(queryStr); @@ -264,21 +203,6 @@ public void testDropPolicy() throws Exception { @Test public void testMergeFilter() throws Exception { - createPolicy("CREATE ROW POLICY test_row_policy1 ON test.table1 AS RESTRICTIVE TO test_policy USING (k1 = 1)"); - createPolicy("CREATE ROW POLICY test_row_policy2 ON test.table1 AS RESTRICTIVE TO ROLE role1 USING (k2 = 1)"); - createPolicy("CREATE ROW POLICY test_row_policy3 ON test.table1 AS PERMISSIVE TO ROLE role1 USING (k2 = 2)"); - createPolicy("CREATE ROW POLICY test_row_policy4 ON test.table1 AS PERMISSIVE TO test_policy USING (k2 = 1)"); - String queryStr = "EXPLAIN select /*+ SET_VAR(enable_nereids_planner=false) */ * from test.table1"; - String explainString = getSQLPlanOrErrorMsg(queryStr); - Assertions.assertTrue(explainString.contains("(((`k1` = 1) AND (`k2` = 1)) AND ((`k2` = 2) OR (`k2` = 1)))")); - dropPolicy("DROP ROW POLICY test_row_policy1 ON test.table1"); - dropPolicy("DROP ROW POLICY test_row_policy2 ON test.table1"); - dropPolicy("DROP ROW POLICY test_row_policy3 ON test.table1"); - dropPolicy("DROP ROW POLICY test_row_policy4 ON test.table1"); - } - - @Test - public void testMergeFilterNereidsPlanner() throws Exception { createPolicy("CREATE ROW POLICY test_row_policy1 ON test.table1 AS RESTRICTIVE TO test_policy USING (k1 = 1)"); createPolicy("CREATE ROW POLICY test_row_policy3 ON test.table1 AS PERMISSIVE TO ROLE role1 USING (k2 = 2)"); createPolicy("CREATE ROW POLICY test_row_policy4 ON test.table1 AS PERMISSIVE TO test_policy USING (k2 = 1)"); @@ -295,26 +219,6 @@ public void testMergeFilterNereidsPlanner() throws Exception { @Test public void testComplexSql() throws Exception { - createPolicy("CREATE ROW POLICY test_row_policy1 ON test.table1 AS RESTRICTIVE TO test_policy USING (k1 = 1)"); - createPolicy("CREATE ROW POLICY test_row_policy2 ON test.table1 AS RESTRICTIVE TO test_policy USING (k2 = 1)"); - String joinSql - = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table1 join table2 on table1.k1=table2.k1"; - Assertions.assertTrue(getSQLPlanOrErrorMsg(joinSql).contains("(`k1` = 1) AND (`k2` = 1)")); - String unionSql - = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table1 union select * from table2"; - Assertions.assertTrue(getSQLPlanOrErrorMsg(unionSql).contains("(`k1` = 1) AND (`k2` = 1)")); - String subQuerySql - = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table2 where k1 in (select k1 from table1)"; - Assertions.assertTrue(getSQLPlanOrErrorMsg(subQuerySql).contains("(`k1` = 1) AND (`k2` = 1)")); - String aliasSql - = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table1 t1 join table2 t2 on t1.k1=t2.k1"; - Assertions.assertTrue(getSQLPlanOrErrorMsg(aliasSql).contains("(`t1`.`k1` = 1) AND (`t1`.`k2` = 1)")); - dropPolicy("DROP ROW POLICY test_row_policy1 ON test.table1"); - dropPolicy("DROP ROW POLICY test_row_policy2 ON test.table1"); - } - - @Test - public void testComplexSqlNereidsPlanner() throws Exception { createPolicy("CREATE ROW POLICY test_row_policy1 ON test.table1 AS RESTRICTIVE TO test_policy USING (k1 = 1)"); createPolicy("CREATE ROW POLICY test_row_policy2 ON test.table1 AS RESTRICTIVE TO test_policy USING (k2 = 1)"); String joinSql = "select * from table1 join table2 on table1.k1=table2.k1"; diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java index 05408d3b67405ef..88fd4c932033219 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java @@ -26,11 +26,9 @@ import org.apache.doris.common.PatternMatcher; import org.apache.doris.common.PatternMatcherWrapper; import org.apache.doris.common.VariableAnnotation; -import org.apache.doris.common.util.ProfileManager; import org.apache.doris.thrift.TQueryOptions; import org.apache.doris.utframe.TestWithFeService; -import org.junit.Assert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -42,7 +40,6 @@ public class SessionVariablesTest extends TestWithFeService { private SessionVariable sessionVariable; private int numOfForwardVars; - private ProfileManager profileManager = ProfileManager.getInstance(); @Override protected void runBeforeAll() throws Exception { @@ -68,33 +65,33 @@ public void testExperimentalSessionVariables() throws Exception { connectContext.setThreadLocalInfo(); // 1. set without experimental SessionVariable sessionVar = connectContext.getSessionVariable(); - boolean enableNereids = sessionVar.isEnableNereidsPlanner(); - String sql = "set enable_nereids_planner=" + (enableNereids ? "false" : "true"); + boolean enableShareScan = sessionVar.getEnableSharedScan(); + String sql = "set enable_shared_scan=" + (enableShareScan ? "false" : "true"); SetStmt setStmt = (SetStmt) parseAndAnalyzeStmt(sql, connectContext); SetExecutor setExecutor = new SetExecutor(connectContext, setStmt); setExecutor.execute(); - Assert.assertNotEquals(sessionVar.isEnableNereidsPlanner(), enableNereids); + Assertions.assertNotEquals(sessionVar.getEnableSharedScan(), enableShareScan); // 2. set with experimental - enableNereids = sessionVar.isEnableNereidsPlanner(); - sql = "set experimental_enable_nereids_planner=" + (enableNereids ? "false" : "true"); + enableShareScan = sessionVar.getEnableSharedScan(); + sql = "set experimental_enable_shared_scan=" + (enableShareScan ? "false" : "true"); setStmt = (SetStmt) parseAndAnalyzeStmt(sql, connectContext); setExecutor = new SetExecutor(connectContext, setStmt); setExecutor.execute(); - Assert.assertNotEquals(sessionVar.isEnableNereidsPlanner(), enableNereids); + Assertions.assertNotEquals(sessionVar.getEnableSharedScan(), enableShareScan); // 3. set global without experimental - enableNereids = sessionVar.isEnableNereidsPlanner(); - sql = "set global enable_nereids_planner=" + (enableNereids ? "false" : "true"); + enableShareScan = sessionVar.getEnableSharedScan(); + sql = "set global enable_shared_scan=" + (enableShareScan ? "false" : "true"); setStmt = (SetStmt) parseAndAnalyzeStmt(sql, connectContext); setExecutor = new SetExecutor(connectContext, setStmt); setExecutor.execute(); - Assert.assertNotEquals(sessionVar.isEnableNereidsPlanner(), enableNereids); + Assertions.assertNotEquals(sessionVar.getEnableSharedScan(), enableShareScan); // 4. set global with experimental - enableNereids = sessionVar.isEnableNereidsPlanner(); - sql = "set global experimental_enable_nereids_planner=" + (enableNereids ? "false" : "true"); + enableShareScan = sessionVar.getEnableSharedScan(); + sql = "set global experimental_enable_shared_scan=" + (enableShareScan ? "false" : "true"); setStmt = (SetStmt) parseAndAnalyzeStmt(sql, connectContext); setExecutor = new SetExecutor(connectContext, setStmt); setExecutor.execute(); - Assert.assertNotEquals(sessionVar.isEnableNereidsPlanner(), enableNereids); + Assertions.assertNotEquals(sessionVar.getEnableSharedScan(), enableShareScan); // 5. set experimental for EXPERIMENTAL_ONLINE var boolean bucketShuffle = sessionVar.isEnableBucketShuffleJoin(); @@ -102,7 +99,7 @@ public void testExperimentalSessionVariables() throws Exception { setStmt = (SetStmt) parseAndAnalyzeStmt(sql, connectContext); setExecutor = new SetExecutor(connectContext, setStmt); setExecutor.execute(); - Assert.assertNotEquals(sessionVar.isEnableBucketShuffleJoin(), bucketShuffle); + Assertions.assertNotEquals(sessionVar.isEnableBucketShuffleJoin(), bucketShuffle); // 6. set non experimental for EXPERIMENTAL_ONLINE var bucketShuffle = sessionVar.isEnableBucketShuffleJoin(); @@ -110,14 +107,14 @@ public void testExperimentalSessionVariables() throws Exception { setStmt = (SetStmt) parseAndAnalyzeStmt(sql, connectContext); setExecutor = new SetExecutor(connectContext, setStmt); setExecutor.execute(); - Assert.assertNotEquals(sessionVar.isEnableBucketShuffleJoin(), bucketShuffle); + Assertions.assertNotEquals(sessionVar.isEnableBucketShuffleJoin(), bucketShuffle); // 4. set experimental for none experimental var sql = "set experimental_group_concat_max_len=5"; setStmt = (SetStmt) parseAndAnalyzeStmt(sql, connectContext); SetExecutor setExecutor2 = new SetExecutor(connectContext, setStmt); ExceptionChecker.expectThrowsWithMsg(DdlException.class, "Unknown system variable", - () -> setExecutor2.execute()); + setExecutor2::execute); // 5. show variables String showSql = "show variables like '%experimental%'"; @@ -129,7 +126,7 @@ public void testExperimentalSessionVariables() throws Exception { } int num = sessionVar.getVariableNumByVariableAnnotation(VariableAnnotation.EXPERIMENTAL); List> result = VariableMgr.dump(showStmt.getType(), sessionVar, matcher); - Assert.assertEquals(num, result.size()); + Assertions.assertEquals(num, result.size()); } @Test @@ -140,7 +137,7 @@ public void testForwardSessionVariables() { vars.put(SessionVariable.ENABLE_PROFILE, "true"); sessionVariable.setForwardedSessionVariables(vars); - Assertions.assertEquals(true, sessionVariable.enableProfile); + Assertions.assertTrue(sessionVariable.enableProfile); } @Test diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/StmtExecutorTest.java b/fe/fe-core/src/test/java/org/apache/doris/qe/StmtExecutorTest.java index 852e4ba2de7eda5..3a692ebed26076e 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/qe/StmtExecutorTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/qe/StmtExecutorTest.java @@ -543,7 +543,7 @@ public void testSet(@Mocked SetStmt setStmt, @Mocked SqlParser parser, public void testStmtWithUserInfo(@Mocked StatementBase stmt, @Mocked ConnectContext context) throws Exception { StmtExecutor stmtExecutor = new StmtExecutor(ctx, stmt); Deencapsulation.setField(stmtExecutor, "parsedStmt", null); - Deencapsulation.setField(stmtExecutor, "originStmt", new OriginStatement("show databases;", 1)); + Deencapsulation.setField(stmtExecutor, "originStmt", new OriginStatement("show databases;", 0)); stmtExecutor.execute(); StatementBase newstmt = Deencapsulation.getField(stmtExecutor, "parsedStmt"); Assert.assertNotNull(newstmt.getUserInfo()); diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java deleted file mode 100644 index 915dce122d8dce6..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java +++ /dev/null @@ -1,338 +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.doris.rewrite; - -import org.apache.doris.common.FeConstants; -import org.apache.doris.utframe.DorisAssert; -import org.apache.doris.utframe.UtFrameUtils; - -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.UUID; - -public class ExtractCommonFactorsRuleFunctionTest { - private static final Logger LOG = LogManager.getLogger(ExtractCommonFactorsRuleFunctionTest.class); - private static String baseDir = "fe"; - private static String runningDir = baseDir + "/mocked/ExtractCommonFactorsRuleFunctionTest/" - + UUID.randomUUID().toString() + "/"; - private static DorisAssert dorisAssert; - private static final String DB_NAME = "db1"; - private static final String TABLE_NAME_1 = "tb1"; - private static final String TABLE_NAME_2 = "tb2"; - private static final String TABLE_NAME_3 = "tb3"; - private static final String TABLE_NAME_4 = "nation"; - - @BeforeClass - public static void beforeClass() throws Exception { - FeConstants.default_scheduler_interval_millisecond = 10; - FeConstants.runningUnitTest = true; - UtFrameUtils.createDorisCluster(runningDir); - dorisAssert = new DorisAssert(); - dorisAssert.withDatabase(DB_NAME).useDatabase(DB_NAME); - String createTableSQL = "create table " + DB_NAME + "." + TABLE_NAME_1 - + " (k1 int, k2 int) " - + "distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - dorisAssert.withTable(createTableSQL); - createTableSQL = "create table " + DB_NAME + "." + TABLE_NAME_2 - + " (k1 int, k2 int) " - + "distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - dorisAssert.withTable(createTableSQL); - createTableSQL = "create table " + DB_NAME + "." + TABLE_NAME_3 - + " (k1 tinyint, k2 smallint, k3 int, k4 bigint, k5 largeint, k6 date, k7 datetime, k8 float, k9 double) " - + "distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - dorisAssert.withTable(createTableSQL); - createTableSQL = "CREATE TABLE " + DB_NAME + "." + TABLE_NAME_4 + "(\n" - + " `n_nationkey` int(11) NOT NULL,\n" - + " `n_name` varchar(25) NOT NULL,\n" - + " `n_regionkey` int(11) NOT NULL,\n" - + " `n_comment` varchar(152) NULL\n" - + ")\n" - + "DUPLICATE KEY(`n_nationkey`)\n" - + "DISTRIBUTED BY HASH(`n_nationkey`) BUCKETS 1\n" - + "PROPERTIES (\n" - + "\"replication_allocation\" = \"tag.location.default: 1\"\n" - + ");"; - dorisAssert.withTable(createTableSQL); - } - - @AfterClass - public static void afterClass() throws Exception { - UtFrameUtils.cleanDorisFeDir(baseDir); - } - - @Test - public void testWithoutRewritten() throws Exception { - String query = "select * from tb1, tb2 where (tb1.k1 =1) or (tb2.k2=1)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testCommonFactors() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1=tb2.k1 and tb1.k2 =1) or (tb1.k1=tb2.k1 and tb2.k2=1)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("HASH JOIN")); - Assert.assertEquals(1, StringUtils.countMatches(planString, "`tb1`.`k1` = `tb2`.`k1`")); - } - - @Test - public void testWideCommonFactorsWithOrPredicate() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 where tb1.k1 > 1000 or tb1.k1 < 200 or tb1.k1 = 300"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("((`tb1`.`k1` = 300) OR ((`tb1`.`k1` > 1000) OR (`tb1`.`k1` < 200)))")); - } - - @Test - public void testWideCommonFactorsWithEqualPredicate() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1=1 and tb2.k1=1) or (tb1.k1 =2 and tb2.k1=2)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` IN (1, 2)")); - Assert.assertTrue(planString.contains("`tb2`.`k1` IN (1, 2)")); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWithoutWideCommonFactorsWhenInfinityRangePredicate() throws Exception { - String query = "select * from tb1, tb2 where (tb1.k1>1 and tb2.k1=1) or (tb1.k1 <2 and tb2.k2=2)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("(`tb1`.`k1` > 1 OR `tb1`.`k1` < 2)")); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWideCommonFactorsWithMergeRangePredicate() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1 between 1 and 3 and tb2.k1=1) or (tb1.k1 <2 and tb2.k2=2)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` <= 3")); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWideCommonFactorsWithIntersectRangePredicate() throws Exception { - String query = "select * from tb1, tb2 where (tb1.k1 >1 and tb1.k1 <3 and tb1.k1 <5 and tb2.k1=1) " - + "or (tb1.k1 <2 and tb2.k2=2)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWideCommonFactorsWithDuplicateRangePredicate() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1 >1 and tb1.k1 >1 and tb1.k1 <5 and tb2.k1=1) " - + "or (tb1.k1 <2 and tb2.k2=2)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` < 5")); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWideCommonFactorsWithInPredicate() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1 in (1) and tb2.k1 in(1)) " - + "or (tb1.k1 in(2) and tb2.k1 in(2))"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` IN (1, 2)")); - Assert.assertTrue(planString.contains("`tb2`.`k1` IN (1, 2)")); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWideCommonFactorsWithDuplicateInPredicate() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1 in (1,2) and tb2.k1 in(1,2)) " - + "or (tb1.k1 in(3) and tb2.k1 in(2))"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` IN (1, 2, 3)")); - Assert.assertTrue(planString.contains("`tb2`.`k1` IN (1, 2)")); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWideCommonFactorsWithRangeAndIn() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1 between 1 and 3 and tb2.k1 in(1,2)) " - + "or (tb1.k1 between 2 and 4 and tb2.k1 in(3))"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` >= 1")); - Assert.assertTrue(planString.contains("`tb1`.`k1` <= 4")); - Assert.assertTrue(planString.contains("`tb2`.`k1` IN (1, 2, 3)")); - Assert.assertTrue(planString.contains("NESTED LOOP JOIN")); - } - - @Test - public void testWideCommonFactorsAndCommonFactors() throws Exception { - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where (tb1.k1 between 1 and 3 and tb1.k1=tb2.k1) " - + "or (tb1.k1=tb2.k1 and tb1.k1 between 2 and 4)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` >= 1")); - Assert.assertTrue(planString.contains("`tb1`.`k1` <= 4")); - Assert.assertTrue(planString.contains("`tb1`.`k1` = `tb2`.`k1`")); - Assert.assertTrue(planString.contains("HASH JOIN")); - } - - // TPC-H Q19 - @Test - public void testComplexQuery() throws Exception { - String createTableSQL = "CREATE TABLE `lineitem` (\n" - + " `l_orderkey` int(11) NOT NULL COMMENT \"\",\n" - + " `l_partkey` int(11) NOT NULL COMMENT \"\",\n" - + " `l_suppkey` int(11) NOT NULL COMMENT \"\",\n" - + " `l_linenumber` int(11) NOT NULL COMMENT \"\",\n" - + " `l_quantity` decimal(15, 2) NOT NULL COMMENT \"\",\n" - + " `l_extendedprice` decimal(15, 2) NOT NULL COMMENT \"\",\n" - + " `l_discount` decimal(15, 2) NOT NULL COMMENT \"\",\n" - + " `l_tax` decimal(15, 2) NOT NULL COMMENT \"\",\n" - + " `l_returnflag` char(1) NOT NULL COMMENT \"\",\n" - + " `l_linestatus` char(1) NOT NULL COMMENT \"\",\n" - + " `l_shipdate` date NOT NULL COMMENT \"\",\n" - + " `l_commitdate` date NOT NULL COMMENT \"\",\n" - + " `l_receiptdate` date NOT NULL COMMENT \"\",\n" - + " `l_shipinstruct` char(25) NOT NULL COMMENT \"\",\n" - + " `l_shipmode` char(10) NOT NULL COMMENT \"\",\n" - + " `l_comment` varchar(44) NOT NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`l_orderkey`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 2\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ");"; - dorisAssert.withTable(createTableSQL); - createTableSQL = "CREATE TABLE `part` (\n" - + " `p_partkey` int(11) NOT NULL COMMENT \"\",\n" - + " `p_name` varchar(55) NOT NULL COMMENT \"\",\n" - + " `p_mfgr` char(25) NOT NULL COMMENT \"\",\n" - + " `p_brand` char(10) NOT NULL COMMENT \"\",\n" - + " `p_type` varchar(25) NOT NULL COMMENT \"\",\n" - + " `p_size` int(11) NOT NULL COMMENT \"\",\n" - + " `p_container` char(10) NOT NULL COMMENT \"\",\n" - + " `p_retailprice` decimal(15, 2) NOT NULL COMMENT \"\",\n" - + " `p_comment` varchar(23) NOT NULL COMMENT \"\"\n" - + ") ENGINE=OLAP\n" - + "DUPLICATE KEY(`p_partkey`)\n" - + "COMMENT \"OLAP\"\n" - + "DISTRIBUTED BY HASH(`p_partkey`) BUCKETS 2\n" - + "PROPERTIES (\n" - + "\"replication_num\" = \"1\",\n" - + "\"in_memory\" = \"false\",\n" - + "\"storage_format\" = \"V2\"\n" - + ");"; - dorisAssert.withTable(createTableSQL); - String query = "select /*+ SET_VAR(enable_nereids_planner=false,enable_fold_constant_by_be=false) */ sum(l_extendedprice* (1 - l_discount)) as revenue " - + "from lineitem, part " - + "where ( p_partkey = l_partkey and p_brand = 'Brand#11' " - + "and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') " - + "and l_quantity >= 9 and l_quantity <= 9 + 10 " - + "and p_size between 1 and 5 and l_shipmode in ('AIR', 'AIR REG') " - + "and l_shipinstruct = 'DELIVER IN PERSON' ) " - + "or ( p_partkey = l_partkey and p_brand = 'Brand#21' " - + "and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') " - + "and l_quantity >= 20 and l_quantity <= 20 + 10 " - + "and p_size between 1 and 10 and l_shipmode in ('AIR', 'AIR REG') " - + "and l_shipinstruct = 'DELIVER IN PERSON' ) " - + "or ( p_partkey = l_partkey and p_brand = 'Brand#32' " - + "and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') " - + "and l_quantity >= 26 and l_quantity <= 26 + 10 " - + "and p_size between 1 and 15 and l_shipmode in ('AIR', 'AIR REG') " - + "and l_shipinstruct = 'DELIVER IN PERSON' )"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("HASH JOIN")); - Assert.assertTrue(planString.contains("`l_partkey` = `p_partkey`")); - Assert.assertTrue(planString.contains("`l_shipmode` IN ('AIR', 'AIR REG')")); - Assert.assertTrue(planString.contains("`l_shipinstruct` = 'DELIVER IN PERSON'")); - Assert.assertTrue(planString.contains("(((`l_quantity` >= 9.00) AND (`l_quantity` <= 19.00)) " - + "OR ((`l_quantity` >= 20.00) AND (`l_quantity` <= 36.00)))")); - Assert.assertTrue(planString.contains("`p_size` >= 1")); - Assert.assertTrue(planString.contains("`p_brand` IN ('Brand#11', 'Brand#21', 'Brand#32')")); - Assert.assertTrue(planString.contains("`p_size` <= 15")); - Assert.assertTrue(planString.contains("`p_container` IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG', 'MED BAG', " - + "'MED BOX', 'MED PKG', 'MED PACK', 'LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')")); - } - - @Test - public void testRewriteLikePredicate() throws Exception { - // tinyint - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb3 where k1 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - dorisAssert.query(sql).explainContains("CAST(`k1` AS varchar(65533)) LIKE '%4%'"); - - // smallint - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb3 where k2 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - dorisAssert.query(sql).explainContains("CAST(`k2` AS varchar(65533)) LIKE '%4%'"); - - // int - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb3 where k3 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - dorisAssert.query(sql).explainContains("CAST(`k3` AS varchar(65533)) LIKE '%4%'"); - - // bigint - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb3 where k4 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - dorisAssert.query(sql).explainContains("CAST(`k4` AS varchar(65533)) LIKE '%4%'"); - - // largeint - sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb3 where k5 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - dorisAssert.query(sql).explainContains("CAST(`k5` AS varchar(65533)) LIKE '%4%'"); - } - - @Test - public void testRewriteLikePredicateDate() throws Exception { - // date - String sql = "select * from tb3 where k6 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - } - - @Test - public void testRewriteLikePredicateDateTime() throws Exception { - // datetime - String sql = "select * from tb3 where k7 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - dorisAssert.query(sql).explainQuery(); - } - - @Test - public void testRewriteLikePredicateFloat() throws Exception { - // date - String sql = "select * from tb3 where k8 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - } - - @Test - public void testRewriteLikePredicateDouble() throws Exception { - // date - String sql = "select * from tb3 where k9 like '%4%';"; - LOG.info("EXPLAIN:{}", dorisAssert.query(sql).explainQuery()); - } - - @Test - public void testExtractCommonFactorsWithOnClause() throws Exception { - String sql = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from\n" - + "db1.nation n1 join db1.nation n2\n" - + "on (n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')\n" - + "or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')"; - String explainStr = dorisAssert.query(sql).explainQuery(); - Assert.assertTrue(explainStr.contains("PREDICATES: `n1`.`n_name` IN ('FRANCE', 'GERMANY')")); - Assert.assertTrue(explainStr.contains("PREDICATES: `n2`.`n_name` IN ('FRANCE', 'GERMANY')")); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java deleted file mode 100644 index fdac5c3dcc3e6cb..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java +++ /dev/null @@ -1,404 +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.doris.rewrite; - -import org.apache.doris.common.FeConstants; -import org.apache.doris.qe.SessionVariable; -import org.apache.doris.utframe.DorisAssert; -import org.apache.doris.utframe.UtFrameUtils; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.UUID; - -public class InferFiltersRuleTest { - private static final String baseDir = "fe"; - private static final String runningDir = baseDir + "/mocked/InferFiltersRuleTest/" - + UUID.randomUUID() + "/"; - private static DorisAssert dorisAssert; - private static final String DB_NAME = "db1"; - private static final String TABLE_NAME_1 = "tb1"; - private static final String TABLE_NAME_2 = "tb2"; - private static final String TABLE_NAME_3 = "tb3"; - - @BeforeClass - public static void beforeClass() throws Exception { - FeConstants.default_scheduler_interval_millisecond = 10; - FeConstants.runningUnitTest = true; - UtFrameUtils.createDorisCluster(runningDir); - dorisAssert = new DorisAssert(); - dorisAssert.withDatabase(DB_NAME).useDatabase(DB_NAME); - String createTableSQL = "create table " + DB_NAME + "." + TABLE_NAME_1 - + " (k1 int, k2 int) " - + "distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - dorisAssert.withTable(createTableSQL); - createTableSQL = "create table " + DB_NAME + "." + TABLE_NAME_2 - + " (k1 int, k2 int) " - + "distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - dorisAssert.withTable(createTableSQL); - createTableSQL = "create table " + DB_NAME + "." + TABLE_NAME_3 - + " (k1 tinyint, k2 smallint, k3 int, k4 bigint," - + " k5 largeint, k6 date, k7 datetime, k8 float, k9 double) " - + "distributed by hash(k1) buckets 3 properties('replication_num' = '1');"; - dorisAssert.withTable(createTableSQL); - } - - @AfterClass - public static void afterClass() throws Exception { - UtFrameUtils.cleanDorisFeDir(baseDir); - } - - @Test - //set enableInferPredicate = false; - public void testWithoutRewritten() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(false); - Assert.assertFalse(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1, tb2 where tb1.k1 = 1 and tb1.k1 = tb2.k1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb2`.`k1` = 1")); - } - - @Test - public void testRewritten() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2 where tb1.k1 = 1 and tb1.k1 = tb2.k1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - } - - @Test - public void testUnequalSlotPredicate() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1, tb2 where tb1.k1 = 1 and tb1.k1 > tb2.k1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb2`.`k1` = 1")); - } - - @Test - public void testOn3TablesBothInnerJoinRewritten() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 inner join tb3" - + " where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb3.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testOn2TablesLeftSemiJoinEqLiteralAt2nd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 left semi join tb2 on tb1.k1 = tb2.k1 and tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testOn2TablesLeftSemiJoinEqLiteralAt1st() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 left semi join tb2 on tb1.k1 = tb2.k1 and tb1.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - } - - @Test - public void testOn2TablesLeftAntiJoinEqLiteralAt2nd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 left anti join tb2 on tb1.k1 = tb2.k1 and tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testOn2TablesLeftJoinNotInferable() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 left join tb2 on tb1.k1 = tb2.k1 and tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb1`.`k1` = 1")); - } - - /* - the following 3 test case is valid. But we cannot tell them from other incorrect inferences. - In origin design we made a mistake: we assume inference is symmetrical. - For example, t1.x=t2.x and t1.x=1 => t2.x=1 - this is not always true. - if this is left join, t1 is left, t2.x=1 is not valid. - However, in inferFilterRule, we do not know whether t1.x is from left or right table. - And hence, we have to skip inference for outer/anti join for quick fix. - - @Test - public void testOn3Tables1stInner2ndRightJoinEqLiteralAt2nd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 inner join tb2 on tb1.k1 = tb2.k1" - + " right outer join tb3 on tb2.k1 = tb3.k1 and tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - Assert.assertFalse(planString.contains("`tb3`.`k1` = 1")); - } - - @Test - public void testOn3Tables1stInner2ndRightJoinEqLiteralAt3rd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 inner join tb2 on tb1.k1 = tb2.k1" - + " right outer join tb3 on tb2.k1 = tb3.k1 and tb3.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - @Test - public void testOn2TablesLeftAntiJoinEqLiteralAt1st() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 left anti join tb2 on tb1.k1 = tb2.k1 and tb1.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - } - */ - @Test - public void testOnIsNotNullPredicate() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 on tb1.k1 = tb2.k1 right outer join tb3 on tb2.k1 = tb3.k1" - + " where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - Assert.assertTrue(planString, planString.contains("CAST(`tb3`.`k1` AS int)")); - } - - @Test - public void testOnBetweenPredicate() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 on tb1.k1 = tb2.k1 and tb1.k1 between 1 and 2"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` >= 1")); - Assert.assertTrue(planString.contains("`tb2`.`k1` <= 2")); - } - - @Test - public void testOnInPredicate() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 on tb1.k1 = tb2.k1 and tb1.k1 in (2)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` IN (2)")); - } - - @Test - public void testWhere3TablesInnerJoinRewritten() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1, tb2, tb3 where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb3.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testWhere3TablesBothInnerJoinRewritten() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 inner join tb3" - + " where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb3.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testWhere3Tables1stInner2ndLeftJoinEqLiteralAt3rd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 left outer join tb3 on tb3.k1 = tb2.k1" - + " where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb3.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testWhere3Tables1stInner2ndLeftJoinEqLiteralAt2nd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 left outer join tb3 on tb3.k1 = tb2.k1" - + " where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - Assert.assertFalse(planString.contains("`tb3`.`k1` = 1")); - } - - @Test - public void testWhere3Tables1stInner2ndRightJoinEqLiteralAt2nd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 on tb1.k1 = tb2.k1 right outer join tb3 on tb2.k1 = tb3.k1" - + " where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString, planString.contains("`tb1`.`k1` = 1")); - Assert.assertTrue(planString, planString.contains("CAST(`tb3`.`k1` AS int) = 1")); - } - - @Test - public void testWhere3Tables1stInner2ndRightJoinEqLiteralAt3rd() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 inner join tb2 on tb1.k1 = tb2.k1 right outer join tb3 on tb2.k1 = tb3.k1" - + " where tb1.k1 = tb2.k1 and tb2.k1 = tb3.k1 and tb3.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb2`.`k1` = 1")); - Assert.assertFalse(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testWhereIsNotNullPredicate() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - sessionVariable.setEnableRewriteElementAtToSlot(false); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false,enable_fold_constant_by_be=false) */ * from tb1 inner join tb2 inner join tb3" - + " where tb1.k1 = tb3.k1 and tb2.k1 = tb3.k1 and tb1.k1 is not null"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb3`.`k1` IS NOT NULL")); - Assert.assertTrue(planString.contains("`tb2`.`k1` IS NOT NULL")); - } - - @Test - public void testWhereInPredicate() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 where tb1.k1 = tb2.k1 and tb1.k1 in (2)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` IN (2)")); - } - - @Test - public void testWhereBetweenPredicate() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 where tb1.k1 = tb2.k1 and tb1.k1 between 1 and 2"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` >= 1")); - Assert.assertTrue(planString.contains("`tb2`.`k1` <= 2")); - } - - @Test - public void testOnAndWhere2TablesLeftJoin2ndIsLiteral() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 left join tb2 on tb1.k1 = tb2.k1 where tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testOnAndWhere2TablesInnerJoin2ndIsLiteral() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 on tb1.k1 = tb2.k1 where tb2.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb1`.`k1` = 1")); - } - - @Test - public void testOnAndWhere2TableLeftJoin1stIsLiteral() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 left join tb2 on tb1.k1 = tb2.k1 where tb1.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - } - - @Test - public void testOnAndWhere2TablesInnerJoin1stIsLiteral() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from tb1 inner join tb2 on tb1.k1 = tb2.k1 where tb1.k1 = 1"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertTrue(planString.contains("`tb2`.`k1` = 1")); - } - - @Test - public void testSameAliasWithSlotEqualToLiteralInDifferentUnionChildren() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 inner join tb2 on tb1.k1 = tb2.k1" - + " union select * from tb1 inner join tb2 on tb1.k2 = tb2.k2 where tb1.k1 = 3"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb2`.`k1` = 3")); - } - - @Test - public void testSameAliasWithSlotInPredicateInDifferentUnionChildren() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 inner join tb2 on tb1.k1 = tb2.k1" - + " union select * from tb1 inner join tb2 on tb1.k2 = tb2.k2 where tb1.k1 in (3, 4, 5)"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb2`.`k1` IN (3, 4, 5)")); - } - - @Test - public void testSameAliasWithSlotIsNullInDifferentUnionChildren() throws Exception { - SessionVariable sessionVariable = dorisAssert.getSessionVariable(); - sessionVariable.setEnableInferPredicate(true); - Assert.assertTrue(sessionVariable.isEnableInferPredicate()); - String query = "select * from tb1 inner join tb2 on tb1.k1 = tb2.k1" - + " union select * from tb1 inner join tb2 on tb1.k2 = tb2.k2 where tb1.k1 is not null"; - String planString = dorisAssert.query(query).explainQuery(); - Assert.assertFalse(planString.contains("`tb2`.`k1` IS NOT NULL")); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRuleTest.java deleted file mode 100644 index a169843f602ad0e..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteBinaryPredicatesRuleTest.java +++ /dev/null @@ -1,129 +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.doris.rewrite; - -import org.apache.doris.analysis.BinaryPredicate; -import org.apache.doris.analysis.BinaryPredicate.Operator; -import org.apache.doris.analysis.BoolLiteral; -import org.apache.doris.analysis.Expr; -import org.apache.doris.analysis.LiteralExpr; -import org.apache.doris.analysis.SelectStmt; -import org.apache.doris.catalog.PrimitiveType; -import org.apache.doris.qe.StmtExecutor; -import org.apache.doris.utframe.TestWithFeService; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class RewriteBinaryPredicatesRuleTest extends TestWithFeService { - @Override - protected void runBeforeAll() throws Exception { - connectContext = createDefaultCtx(); - createDatabase("db"); - useDatabase("db"); - String createTable = "create table table1(id smallint, cost bigint sum) " - + "aggregate key(`id`) distributed by hash (`id`) buckets 4 " - + "properties (\"replication_num\"=\"1\");"; - createTable(createTable); - } - - @Test - public void testNormal() throws Exception { - testRewrite(Operator.EQ, "2.0", Operator.EQ, 2L, true); - testBoolean(Operator.EQ, "2.5", false); - - testBase(Operator.NE, "2.0", Operator.NE, 2L); - testBoolean(Operator.NE, "2.5", true); - - testBase(Operator.LE, "2.0", Operator.LE, 2L); - testBase(Operator.LE, "-2.5", Operator.LT, -2L); - testBase(Operator.LE, "2.5", Operator.LE, 2L); - - testBase(Operator.GE, "2.0", Operator.GE, 2L); - testBase(Operator.GE, "-2.5", Operator.GE, -2L); - testBase(Operator.GE, "2.5", Operator.GT, 2L); - - testBase(Operator.LT, "2.0", Operator.LT, 2L); - testBase(Operator.LT, "-2.5", Operator.LT, -2L); - testBase(Operator.LT, "2.5", Operator.LE, 2L); - - testBase(Operator.GT, "2.0", Operator.GT, 2L); - testBase(Operator.GT, "-2.5", Operator.GE, -2L); - testBase(Operator.GT, "2.5", Operator.GT, 2L); - } - - @Test - public void testOutOfRange() throws Exception { - // 32767 -32768 - testBoolean(Operator.EQ, "-32769.0", false); - testBase(Operator.EQ, "32767.0", Operator.EQ, 32767L); - - testBoolean(Operator.NE, "32768.0", true); - - testBoolean(Operator.LE, "32768.2", true); - testBoolean(Operator.LE, "-32769.1", false); - testBase(Operator.LE, "32767.0", Operator.LE, 32767L); - - testBoolean(Operator.GE, "32768.1", false); - testBoolean(Operator.GE, "-32769.1", true); - testBase(Operator.GE, "32767.0", Operator.GE, 32767L); - - testBoolean(Operator.LT, "32768.1", true); - testBoolean(Operator.LT, "-32769.1", false); - testBase(Operator.LT, "32767.1", Operator.LE, 32767L); - - testBoolean(Operator.GT, "32768.1", false); - testBoolean(Operator.GT, "-32769.1", true); - testBase(Operator.GT, "32767.0", Operator.GT, 32767L); - } - - private void testRewrite(Operator operator, String queryLiteral, Operator expectedOperator, long expectedChild1, - boolean expectedResultAfterRewritten) - throws Exception { - Expr expr1 = getExpr(operator, queryLiteral); - if (expr1 instanceof BoolLiteral) { - Assertions.assertEquals(((BoolLiteral) expr1).getValue(), expectedResultAfterRewritten); - } else { - testBase(operator, queryLiteral, expectedOperator, expectedChild1); - } - } - - private void testBase(Operator operator, String queryLiteral, Operator expectedOperator, long expectedChild1) - throws Exception { - Expr expr1 = getExpr(operator, queryLiteral); - Assertions.assertTrue(expr1 instanceof BinaryPredicate); - Assertions.assertEquals(expectedOperator, ((BinaryPredicate) expr1).getOp()); - Assertions.assertEquals(PrimitiveType.SMALLINT, expr1.getChild(0).getType().getPrimitiveType()); - Assertions.assertEquals(PrimitiveType.SMALLINT, expr1.getChild(1).getType().getPrimitiveType()); - Assertions.assertEquals(expectedChild1, ((LiteralExpr) expr1.getChild(1)).getLongValue()); - } - - private void testBoolean(Operator operator, String queryLiteral, boolean result) throws Exception { - Expr expr1 = getExpr(operator, queryLiteral); - Assertions.assertTrue(expr1 instanceof BoolLiteral); - Assertions.assertEquals(result, ((BoolLiteral) expr1).getValue()); - } - - private Expr getExpr(Operator operator, String queryLiteral) throws Exception { - String queryFormat = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table1 where id %s %s;"; - String query = String.format(queryFormat, operator.toString(), queryLiteral); - StmtExecutor executor1 = getSqlStmtExecutor(query); - Assertions.assertNotNull(executor1); - return ((SelectStmt) executor1.getParsedStmt()).getWhereClause(); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteInPredicateRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteInPredicateRuleTest.java deleted file mode 100644 index ba13e6602a4c073..000000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteInPredicateRuleTest.java +++ /dev/null @@ -1,144 +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.doris.rewrite; - -import org.apache.doris.analysis.BoolLiteral; -import org.apache.doris.analysis.Expr; -import org.apache.doris.analysis.InPredicate; -import org.apache.doris.analysis.IntLiteral; -import org.apache.doris.analysis.LargeIntLiteral; -import org.apache.doris.analysis.LiteralExpr; -import org.apache.doris.analysis.SelectStmt; -import org.apache.doris.catalog.PrimitiveType; -import org.apache.doris.qe.StmtExecutor; -import org.apache.doris.utframe.TestWithFeService; - -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; - -public class RewriteInPredicateRuleTest extends TestWithFeService { - private static final String DB_NAME = "testdb"; - private static final String TABLE_SMALL = "table_small"; - private static final String TABLE_LARGE = "table_large"; - - @Override - protected void runBeforeAll() throws Exception { - connectContext = createDefaultCtx(); - createDatabase(DB_NAME); - useDatabase(DB_NAME); - String createTableFormat = "create table %s(id %s, `date` datetime, cost bigint sum) " - + "aggregate key(`id`, `date`) distributed by hash (`id`) buckets 4 " - + "properties (\"replication_num\"=\"1\");"; - createTable(String.format(createTableFormat, TABLE_SMALL, PrimitiveType.SMALLINT)); - createTable(String.format(createTableFormat, TABLE_LARGE, PrimitiveType.LARGEINT)); - } - - @Test - public void testIntLiteralAndLargeIntLiteral() throws Exception { - // id in (TINY_INT_MIN, SMALL_INT_MIN, INT_MIN, BIG_INT_MAX, LARGE_INT_MAX) - // => id in (TINY_INT_MIN, SMALL_INT_MIN) - testBase(3, PrimitiveType.SMALLINT, IntLiteral.TINY_INT_MIN, TABLE_SMALL, - String.valueOf(IntLiteral.TINY_INT_MIN), String.valueOf(IntLiteral.SMALL_INT_MAX), - String.valueOf(IntLiteral.INT_MIN), String.valueOf(IntLiteral.BIG_INT_MAX), - LargeIntLiteral.LARGE_INT_MAX.toString()); - - // id in (TINY_INT_MIN, SMALL_INT_MIN, INT_MIN, BIG_INT_MAX, LARGE_INT_MAX) - // => id in (TINY_INT_MIN, SMALL_INT_MIN, INT_MIN, BIG_INT_MAX, LARGE_INT_MAX) - testBase(6, PrimitiveType.LARGEINT, IntLiteral.TINY_INT_MIN, TABLE_LARGE, - String.valueOf(IntLiteral.TINY_INT_MIN), String.valueOf(IntLiteral.SMALL_INT_MAX), - String.valueOf(IntLiteral.INT_MIN), String.valueOf(IntLiteral.BIG_INT_MAX), - LargeIntLiteral.LARGE_INT_MAX.toString()); - } - - @Test - public void testDecimalLiteral() throws Exception { - // type of id is smallint: id in (2.0, 3.5) => id in (2) - testBase(2, PrimitiveType.SMALLINT, 2, TABLE_SMALL, "2.0", "3.5"); - - testBase(2, PrimitiveType.SMALLINT, 3, TABLE_SMALL, "2.1", "3.0", "3.5"); - - // type of id is largeint: id in (2.0, 3.5) => id in (2) - testBase(2, PrimitiveType.LARGEINT, 2, TABLE_LARGE, "2.0", "3.5"); - } - - @Test - public void testStringLiteral() throws Exception { - // type of id is smallint: id in ("2.0", "3.5") => id in (2) - testBase(2, PrimitiveType.SMALLINT, 2, TABLE_SMALL, "\"2.0\"", "\"3.5\""); - - // type of id is largeint: id in ("2.0", "3.5") => id in (2) - testBase(2, PrimitiveType.LARGEINT, 2, TABLE_LARGE, "\"2.0\"", "\"3.5\""); - } - - @Test - public void testBooleanLiteral() throws Exception { - // type of id is smallint: id in (true, false) => id in (1, 0) - testBase(3, PrimitiveType.SMALLINT, 0, TABLE_SMALL, "false", "true"); - - // type of id is largeint: id in (true, false) => id in (1, 0) - testBase(3, PrimitiveType.LARGEINT, 1, TABLE_LARGE, "true", "false"); - } - - @Test - public void testMixedLiteralExpr() throws Exception { - // type of id is smallint: id in (1, 2.0, 3.3) -> id in (1, 2) - testBase(3, PrimitiveType.SMALLINT, 1, TABLE_SMALL, "1", "2.0", "3.3"); - // type of id is smallint: id in (1, 1.0, 1.1) => id in (1, 1) - testBase(3, PrimitiveType.SMALLINT, 1, TABLE_SMALL, "1", "1.0", "1.1"); - // type of id is smallint: id in ("1.0", 2.0, 3.3, "5.2") => id in (1, 2) - testBase(3, PrimitiveType.SMALLINT, 1, TABLE_SMALL, "\"1.0\"", "2.0", "3.3", "\"5.2\""); - // type of id is smallint: id in (false, 2.0, 3.3, "5.2", true) => id in (0, 2, 1) - testBase(4, PrimitiveType.SMALLINT, 0, TABLE_SMALL, "false", "2.0", "3.3", "\"5.2\"", "true"); - - // largeint - testBase(3, PrimitiveType.LARGEINT, 1, TABLE_LARGE, "1", "2.0", "3.3"); - testBase(3, PrimitiveType.LARGEINT, 1, TABLE_LARGE, "1", "1.0", "1.1"); - testBase(3, PrimitiveType.LARGEINT, 1, TABLE_LARGE, "\"1.0\"", "2.0", "3.3", "\"5.2\""); - testBase(4, PrimitiveType.LARGEINT, 0, TABLE_LARGE, "false", "2.0", "3.3", "\"5.2\"", "true"); - } - - @Test - public void testEmpty() throws Exception { - // type of id is smallint: id in (5.5, "6.2") => false - String query = "select /*+ SET_VAR(enable_nereids_planner=false) */ * from table_small where id in (5.5, \"6.2\");"; - StmtExecutor executor1 = getSqlStmtExecutor(query); - Expr expr1 = ((SelectStmt) executor1.getParsedStmt()).getWhereClause(); - Assertions.assertTrue(expr1 instanceof BoolLiteral); - Assertions.assertFalse(((BoolLiteral) expr1).getValue()); - } - - private void testBase(int childrenNum, PrimitiveType type, long expectedOfChild1, String... literals) - throws Exception { - List list = Lists.newArrayList(); - Lists.newArrayList(literals).forEach(e -> list.add("%s")); - list.remove(list.size() - 1); - String queryFormat = "select /*+ SET_VAR(enable_nereids_planner=false,enable_fold_constant_by_be=false) */ * from %s where id in (" + Joiner.on(", ").join(list) + ");"; - String query = String.format(queryFormat, literals); - StmtExecutor executor1 = getSqlStmtExecutor(query); - Expr expr1 = ((SelectStmt) executor1.getParsedStmt()).getWhereClause(); - Assertions.assertTrue(expr1 instanceof InPredicate); - Assertions.assertEquals(childrenNum, expr1.getChildren().size()); - Assertions.assertEquals(type, expr1.getChild(0).getType().getPrimitiveType()); - Assertions.assertEquals(type, expr1.getChild(1).getType().getPrimitiveType()); - Assertions.assertEquals(expectedOfChild1, ((LiteralExpr) expr1.getChild(1)).getLongValue()); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/utframe/AnotherDemoTest.java b/fe/fe-core/src/test/java/org/apache/doris/utframe/AnotherDemoTest.java index 4f18a60fa817be8..2da5a3cabd871eb 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/utframe/AnotherDemoTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/utframe/AnotherDemoTest.java @@ -120,7 +120,7 @@ public void testCreateDbAndTable() throws Exception { } // 5. query // TODO: we can not process real query for now. So it has to be a explain query - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1"; + String queryStr = "explain select /*+ SET_VAR(disable_nereids_rules=PRUNE_EMPTY_PARTITION) */ * from db1.tbl1"; StmtExecutor stmtExecutor = new StmtExecutor(ctx, queryStr); stmtExecutor.execute(); Planner planner = stmtExecutor.planner(); diff --git a/fe/fe-core/src/test/java/org/apache/doris/utframe/DemoTest.java b/fe/fe-core/src/test/java/org/apache/doris/utframe/DemoTest.java index fec4081a41d2885..289f6c9902d8f84 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/utframe/DemoTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/utframe/DemoTest.java @@ -108,7 +108,7 @@ public void testCreateDbAndTable() throws Exception { // 7. query // TODO: we can not process real query for now. So it has to be a explain query - String queryStr = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ * from db1.tbl1"; + String queryStr = "explain select /*+ SET_VAR(disable_nereids_rules=PRUNE_EMPTY_PARTITION) */ * from db1.tbl1"; StmtExecutor stmtExecutor = new StmtExecutor(connectContext, queryStr); stmtExecutor.execute(); Planner planner = stmtExecutor.planner(); diff --git a/regression-test/data/correctness_p0/test_colocate_join.out b/regression-test/data/correctness_p0/test_colocate_join.out deleted file mode 100644 index aa5795a72f84d7a..000000000000000 --- a/regression-test/data/correctness_p0/test_colocate_join.out +++ /dev/null @@ -1,22 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !global1 -- -1 jack 2022-01-01 1 jack 2022-01-01 10 -2 jack1 2022-01-02 2 jack1 2022-01-02 11 -3 jack2 2022-01-03 3 jack2 2022-01-03 12 -4 jack3 2022-02-01 4 jack3 2022-02-01 13 -5 jack4 2022-02-01 5 jack4 2022-02-01 14 - --- !global2 -- -1 jack 2022-01-01 1 jack 2022-01-01 10 -2 jack1 2022-01-02 2 jack1 2022-01-02 11 -3 jack2 2022-01-03 3 jack2 2022-01-03 12 -4 jack3 2022-02-01 4 jack3 2022-02-01 13 -5 jack4 2022-02-01 5 jack4 2022-02-01 14 - --- !global3 -- -1 jack 2022-01-01 1 jack 2022-01-01 10 -2 jack1 2022-01-02 2 jack1 2022-01-02 11 -3 jack2 2022-01-03 3 jack2 2022-01-03 12 -4 jack3 2022-02-01 4 jack3 2022-02-01 13 -5 jack4 2022-02-01 5 jack4 2022-02-01 14 - diff --git a/regression-test/data/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.out b/regression-test/data/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.out index e29e7082664cb90..069148cd3f49dd5 100644 --- a/regression-test/data/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.out +++ b/regression-test/data/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.out @@ -2,18 +2,6 @@ -- !sql -- array_enumerate_uniq --- !old_sql -- -[1, 1, 2] - --- !old_sql -- -[1, 1, 1] - --- !old_sql -- -[1] - --- !sql -- -array_enumerate_uniq - -- !nereid_sql -- [1, 1, 2] diff --git a/regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out b/regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out index 030a9b1286c2141..09b6e11c95f98e9 100644 --- a/regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out +++ b/regression-test/data/datatype_p0/scalar_types/get_assignment_compatible_type.out @@ -1,6 +1,6 @@ -- This file is automatically generated. You should know what you did if you want to edit this -- !test_sql -- -test_decimal_boolean_view CREATE VIEW `test_decimal_boolean_view` AS SELECT `id` AS `id`, `c1` AS `c1`, `c2` AS `c2` FROM `regression_test_datatype_p0_scalar_types`.`test_decimal_boolean` WHERE ((0.0 = CAST(`c1` AS decimalv3(2,1))) AND (CAST(`c2` AS decimalv3(6,1)) = 1.0)); utf8mb4 utf8mb4_0900_bin +test_decimal_boolean_view CREATE VIEW `test_decimal_boolean_view` AS select `internal`.`regression_test_datatype_p0_scalar_types`.`test_decimal_boolean`.`id`,`internal`.`regression_test_datatype_p0_scalar_types`.`test_decimal_boolean`.`c1`,`internal`.`regression_test_datatype_p0_scalar_types`.`test_decimal_boolean`.`c2` from `internal`.`regression_test_datatype_p0_scalar_types`.`test_decimal_boolean` where 0.0=`internal`.`regression_test_datatype_p0_scalar_types`.`test_decimal_boolean`.`c1` and `internal`.`regression_test_datatype_p0_scalar_types`.`test_decimal_boolean`.`c2` = 1.0; utf8mb4 utf8mb4_0900_bin -- !test_union -- 0.0 diff --git a/regression-test/data/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.out b/regression-test/data/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.out deleted file mode 100644 index afe56855ba3e99d..000000000000000 --- a/regression-test/data/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.out +++ /dev/null @@ -1,93 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !common_default -- -0 - --- !common_without_generated_always -- -0 - --- !gencol_in_middle -- -0 - --- !gencol_refer_gencol -- -0 - --- !gencol_array_function_create -- -0 - --- !gencol_array_function_element_at_create -- -0 - --- !common_default_insert -- -1 - --- !common_default_insert_with_specific_column -- -1 - --- !common_default_test_insert_default -- -1 - --- !commont_default_select -- -1 2 3.0 -3 5 8.0 -6 7 13.0 - --- !common_without_generated_always_insert -- -1 - --- !common_without_generated_always_insert_with_specific_column -- -1 - --- !commont_without_generated_always_select -- -1 2 3.0 -6 7 13.0 - --- !gencol_in_middle_insert -- -1 - --- !gencol_in_middle_insert_with_specific_column -- -1 - --- !gencol_in_middle_insert_with_specific_column_2 -- -1 - --- !gencol_in_middle_select -- -1 6.0 5 -1 7.0 6 -4 9.0 5 - --- !gencol_refer_gencol_insert -- -1 - --- !gencol_refer_gencol_insert2 -- -1 - --- !gencol_refer_gencol_insert3 -- -1 - --- !gencol_refer_gencol_insert4 -- -1 - --- !gencol_refer_gencol_select -- -1 6.0 5 7 -2 11.0 9 12 -3 6.0 3 7 -5 11.0 6 12 - --- !gencol_array_function_insert -- -1 - --- !gencol_array_function_select -- -1 [1, 2] [3, 2] [3, 2, 1] - --- !gencol_array_function_element_at_insert -- -1 - --- !gencol_array_function_element_at_select -- -1 [1, 2] [3, 2] 1 - --- !gencol_refer_gencol -- -0 - --- !test_drop_column -- -3 - diff --git a/regression-test/data/ddl_p0/test_create_view.out b/regression-test/data/ddl_p0/test_create_view.out deleted file mode 100644 index 1edf464474fd28b..000000000000000 --- a/regression-test/data/ddl_p0/test_create_view.out +++ /dev/null @@ -1,29 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !test_view_1 -- -1 [1, 2, 3] -2 [10, -2, 8] -3 [-1, 20, 0] - --- !test_view_2 -- -1 [1, 2, 3] [1, 1, 1] -2 [10, -2, 8] [1, 0, 1] -3 [-1, 20, 0] [0, 1, 0] - --- !test_view_3 -- -1 [1, 2, 3] [1, 2, 3] [1, 2, 3] -2 [10, -2, 8] [10, 8] [10, 8] -3 [-1, 20, 0] [20] [20] - --- !test_view_4 -- -1 [1, 2, 3] [1, 2, 3] [1, 2, 3] -2 [10, -2, 8] [10, 8] [10, 8] -3 [-1, 20, 0] [20] [20] - --- !test_view_5 -- -1 [1, 2, 3] [1, 1, 1] -2 [10, -2, 8] [1, 0, 1] -3 [-1, 20, 0] [0, 1, 0] - --- !test_view_6 -- -v1 CREATE VIEW `v1` AS SELECT `error_code` AS `error_code`, 1 AS `__literal_1`, 'string' AS `__literal_2`, now() AS `__now_3`, dayofyear(`op_time`) AS `__dayofyear_4`, CAST(`source` AS bigint) AS `__cast_expr_5`, min(`timestamp`) OVER (ORDER BY `op_time` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND 1 FOLLOWING) AS `__min_6`, (1 > 2) AS `__binary_predicate_7`, (2 + 3) AS `__arithmetic_expr_8`, 1 IN (1, 2, 3, 4) AS `__in_predicate_9`, `remark` LIKE '%like' AS `__like_predicate_10`, CASE WHEN (`remark` = 's') THEN 1 ELSE 2 END AS `__case_expr_11`, (TRUE | FALSE) AS `__arithmetic_expr_12` FROM `regression_test_ddl_p0`.`view_column_name_test`; - diff --git a/regression-test/data/insert_p0/insert_group_commit_into_max_filter_ratio.out b/regression-test/data/insert_p0/insert_group_commit_into_max_filter_ratio.out index 241c03af460f116..bcb14bea5257133 100644 --- a/regression-test/data/insert_p0/insert_group_commit_into_max_filter_ratio.out +++ b/regression-test/data/insert_p0/insert_group_commit_into_max_filter_ratio.out @@ -1,10 +1,4 @@ -- This file is automatically generated. You should know what you did if you want to edit this --- !sql -- -1 a 10 -2 \N -1 -3 a 10 -9 a \N - -- !sql -- 1 a 10 2 \N -1 diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out index bddcebea7003a43..221d38b267a9d2d 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out @@ -744,10 +744,10 @@ _ ["2022-01-03 00:00:00", "2021-01-01 00:00:00"] -- !sql -- -[25.990] +[25.990000000] -- !sql -- -[24.990, 25.990] +[24.990000000, 25.990000000] -- !sql -- [1, 2, 3, 2, 3, 4, 8, 1, 2, 9] @@ -774,28 +774,28 @@ _ ["2023-03-05 12:23:24.999", "2023-03-05 15:23:23.997"] -- !sql -- -[{"col":"a", "col":"d"}, {"col":"b", "col":"e"}, {"col":"c", "col":"f"}] +[{"1":"a", "2":"d"}, {"1":"b", "2":"e"}, {"1":"c", "2":"f"}] -- !sql -- -[{"col":"a", "col":"d", "col":"g"}, {"col":"b", "col":"e", "col":"h"}, {"col":"c", "col":"f", "col":"i"}] +[{"1":"a", "2":"d", "3":"g"}, {"1":"b", "2":"e", "3":"h"}, {"1":"c", "2":"f", "3":"i"}] -- !sql -- -[{"col":1, "col":"d"}, {"col":2, "col":"o"}, {"col":3, "col":"r"}, {"col":4, "col":"i"}, {"col":5, "col":"s"}] +[{"1":1, "2":"d"}, {"1":2, "2":"o"}, {"1":3, "2":"r"}, {"1":4, "2":"i"}, {"1":5, "2":"s"}] -- !sql -- -[{"col":1.1, "col":1}, {"col":2.2, "col":2}, {"col":3.3, "col":3}] +[{"1":1.1, "2":1}, {"1":2.2, "2":2}, {"1":3.3, "2":3}] -- !sql -- -[{"col":1, "col":null}, {"col":null, "col":"b"}, {"col":3, "col":null}] +[{"1":1, "2":null}, {"1":null, "2":"b"}, {"1":3, "2":null}] -- !sql -- -[{"col":3.050, "col":3.140}, {"col":2.220, "col":6.660}] +[{"1":3.050, "2":3.140}, {"1":2.220, "2":6.660}] -- !sql -- -[{"col":"2000-03-05", "col":"2000-02-02"}, {"col":"2023-03-10", "col":"2023-03-10"}] +[{"1":"2000-03-05", "2":"2000-02-02"}, {"1":"2023-03-10", "2":"2023-03-10"}] -- !sql -- -[{"col":"2023-03-05 12:23:24.999"}, {"col":"2023-03-05 15:23:23.997"}] +[{"1":"2023-03-05 12:23:24.999"}, {"1":"2023-03-05 15:23:23.997"}] -- !sql -- \N diff --git a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_map_function.out b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_map_function.out index dead718723c4bbe..2b4e1abd302ce4f 100644 --- a/regression-test/data/query_p0/sql_functions/cast_function/test_cast_map_function.out +++ b/regression-test/data/query_p0/sql_functions/cast_function/test_cast_map_function.out @@ -39,8 +39,8 @@ {null:"12", 123:"7777"} -- !sql9 -- -{null:1, null:2, 1234567:77} -{null:12, 123:7777} +{null:1.000000000, null:2.000000000, 1234567:77.000000000} +{null:12.000000000, 123:7777.000000000} -- !sql10 -- {null:null, null:null, 1234567:null} diff --git a/regression-test/data/show_p0/test_show_create_table_and_views.out b/regression-test/data/show_p0/test_show_create_table_and_views.out deleted file mode 100644 index c5885f8b004e9db..000000000000000 --- a/regression-test/data/show_p0/test_show_create_table_and_views.out +++ /dev/null @@ -1,46 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !show -- -show_create_table_and_views_table CREATE TABLE `show_create_table_and_views_table` (\n `user_id` largeint NOT NULL,\n `good_id` largeint NOT NULL,\n `cost` bigint SUM NULL DEFAULT "0",\n INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY RANGE(`good_id`)\n(PARTITION p1 VALUES [("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES [("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 VALUES [("300"), ("400")),\nPARTITION p5 VALUES [("400"), ("500")),\nPARTITION p6 VALUES [("500"), ("600")),\nPARTITION p7 VALUES [("600"), (MAXVALUE)))\nDISTRIBUTED BY HASH(`user_id`) BUCKETS 2\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"min_load_replica_num" = "-1",\n"is_being_synced" = "false",\n"storage_medium" = "hdd",\n"storage_format" = "V2",\n"inverted_index_storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false",\n"binlog.enable" = "false",\n"binlog.ttl_seconds" = "86400",\n"binlog.max_bytes" = "9223372036854775807",\n"binlog.max_history_nums" = "9223372036854775807",\n"enable_single_replica_compaction" = "false",\n"group_commit_interval_ms" = "10000",\n"group_commit_data_bytes" = "134217728"\n); - --- !select -- -1 1 30 -1 2 5 -1 3 10 -1 300 2 -2 1 100 -2 2 10 -2 3 44 -2 200 1111 -3 1 10 -3 2 1 -23 900 1 -100 100 1 -200 20 1 -300 20 1 - --- !select -- -1 5 -2 10 -3 1 - --- !show -- -show_create_table_and_views_view CREATE VIEW `show_create_table_and_views_view` AS SELECT `user_id` AS `user_id`, `cost` AS `cost` FROM `show_create_table_and_views_db`.`show_create_table_and_views_table` WHERE (`good_id` = 2); utf8mb4 utf8mb4_0900_bin - --- !select -- -1 47 -2 1265 -3 11 -23 1 -100 1 -200 1 -300 1 - --- !show -- -show_create_table_and_views_table CREATE TABLE `show_create_table_and_views_table` (\n `user_id` largeint NOT NULL,\n `good_id` largeint NOT NULL,\n `cost` bigint SUM NULL DEFAULT "0",\n INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY RANGE(`good_id`)\n(PARTITION p1 VALUES [("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES [("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 VALUES [("300"), ("400")),\nPARTITION p5 VALUES [("400"), ("500")),\nPARTITION p6 VALUES [("500"), ("600")),\nPARTITION p7 VALUES [("600"), (MAXVALUE)))\nDISTRIBUTED BY HASH(`user_id`) BUCKETS 2\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"min_load_replica_num" = "-1",\n"is_being_synced" = "false",\n"storage_medium" = "hdd",\n"storage_format" = "V2",\n"inverted_index_storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false",\n"binlog.enable" = "false",\n"binlog.ttl_seconds" = "86400",\n"binlog.max_bytes" = "9223372036854775807",\n"binlog.max_history_nums" = "9223372036854775807",\n"enable_single_replica_compaction" = "false",\n"group_commit_interval_ms" = "10000",\n"group_commit_data_bytes" = "134217728"\n); - --- !show -- -show_create_table_and_views_like CREATE TABLE `show_create_table_and_views_like` (\n `user_id` largeint NOT NULL,\n `good_id` largeint NOT NULL,\n `cost` bigint SUM NULL DEFAULT "0",\n INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY RANGE(`good_id`)\n(PARTITION p1 VALUES [("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES [("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 VALUES [("300"), ("400")),\nPARTITION p5 VALUES [("400"), ("500")),\nPARTITION p6 VALUES [("500"), ("600")),\nPARTITION p7 VALUES [("600"), (MAXVALUE)))\nDISTRIBUTED BY HASH(`user_id`) BUCKETS 2\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"min_load_replica_num" = "-1",\n"is_being_synced" = "false",\n"storage_medium" = "hdd",\n"storage_format" = "V2",\n"inverted_index_storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false",\n"binlog.enable" = "false",\n"binlog.ttl_seconds" = "86400",\n"binlog.max_bytes" = "9223372036854775807",\n"binlog.max_history_nums" = "9223372036854775807",\n"enable_single_replica_compaction" = "false",\n"group_commit_interval_ms" = "10000",\n"group_commit_data_bytes" = "134217728"\n); - --- !show -- -show_create_table_and_views_like_with_rollup CREATE TABLE `show_create_table_and_views_like_with_rollup` (\n `user_id` largeint NOT NULL,\n `good_id` largeint NOT NULL,\n `cost` bigint SUM NULL DEFAULT "0",\n INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment',\n INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test index\\" comment'\n) ENGINE=OLAP\nAGGREGATE KEY(`user_id`, `good_id`)\nPARTITION BY RANGE(`good_id`)\n(PARTITION p1 VALUES [("-170141183460469231731687303715884105728"), ("100")),\nPARTITION p2 VALUES [("100"), ("200")),\nPARTITION p3 VALUES [("200"), ("300")),\nPARTITION p4 VALUES [("300"), ("400")),\nPARTITION p5 VALUES [("400"), ("500")),\nPARTITION p6 VALUES [("500"), ("600")),\nPARTITION p7 VALUES [("600"), (MAXVALUE)))\nDISTRIBUTED BY HASH(`user_id`) BUCKETS 2\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"min_load_replica_num" = "-1",\n"is_being_synced" = "false",\n"storage_medium" = "hdd",\n"storage_format" = "V2",\n"inverted_index_storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false",\n"binlog.enable" = "false",\n"binlog.ttl_seconds" = "86400",\n"binlog.max_bytes" = "9223372036854775807",\n"binlog.max_history_nums" = "9223372036854775807",\n"enable_single_replica_compaction" = "false",\n"group_commit_interval_ms" = "10000",\n"group_commit_data_bytes" = "134217728"\n); - diff --git a/regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out b/regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out index ede8faef76f8d78..3b8ebb65805049d 100644 --- a/regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out +++ b/regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out @@ -7,8 +7,8 @@ 6 6 -- !test_select_star_except_sql -- -v_mal_old_create_view CREATE VIEW `v_mal_old_create_view` AS SELECT `regression_test_view_p0`.`mal_old_create_view`.`pk` AS `pk`, `regression_test_view_p0`.`mal_old_create_view`.`b` AS `b` FROM `regression_test_view_p0`.`mal_old_create_view`; utf8mb4 utf8mb4_0900_bin +v_mal_old_create_view CREATE VIEW `v_mal_old_create_view` AS select `internal`.`regression_test_view_p0`.`mal_old_create_view`.`pk`, `internal`.`regression_test_view_p0`.`mal_old_create_view`.`b` from `internal`.`regression_test_view_p0`.`mal_old_create_view`; utf8mb4 utf8mb4_0900_bin -- !test_sql -- -v_mal_old_create_view2 CREATE VIEW `v_mal_old_create_view2` AS SELECT CAST(CAST(`a` AS text) AS time(0)) AS `__cast_expr_0` FROM `regression_test_view_p0`.`mal_old_create_view`; utf8mb4 utf8mb4_0900_bin +v_mal_old_create_view2 CREATE VIEW `v_mal_old_create_view2` AS select cast(cast(`internal`.`regression_test_view_p0`.`mal_old_create_view`.`a` as string) as time) from `internal`.`regression_test_view_p0`.`mal_old_create_view`; utf8mb4 utf8mb4_0900_bin diff --git a/regression-test/suites/correctness_p0/test_colocate_join.groovy b/regression-test/suites/correctness_p0/test_colocate_join.groovy deleted file mode 100644 index 44e401235b063f8..000000000000000 --- a/regression-test/suites/correctness_p0/test_colocate_join.groovy +++ /dev/null @@ -1,311 +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. - -suite("test_colocate_join") { - - // this case check explain, so we disable nereids - sql """set enable_nereids_planner=false""" - - def db1 = "test_colocate_join_db1" - def db2 = "test_colocate_join_db2" - sql """ drop database if exists ${db1}""" - sql """ drop database if exists ${db2}""" - sql """ create database if not exists ${db1}""" - sql """ create database if not exists ${db2}""" - sql """ use ${db1}""" - - sql """ DROP TABLE IF EXISTS `test_colo1` """ - sql """ DROP TABLE IF EXISTS `test_colo2` """ - sql """ DROP TABLE IF EXISTS `test_colo3` """ - sql """ DROP TABLE IF EXISTS `test_colo4` """ - sql """ DROP TABLE IF EXISTS `test_colo5` """ - sql """ DROP TABLE IF EXISTS `test_global_tbl1` """ - sql """ DROP TABLE IF EXISTS `test_global_tbl2` """ - sql """ DROP TABLE IF EXISTS ${db2}.`test_global_tbl3` """ - - sql """ - CREATE TABLE `test_colo1` ( - `id` varchar(64) NULL, - `name` varchar(64) NULL, - `age` int NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`,`name`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`,`name`) BUCKETS 4 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "colocate_with" = "group", - "in_memory" = "false", - "storage_format" = "V2", - "disable_auto_compaction" = "false" - ); - """ - - sql """ - CREATE TABLE `test_colo2` ( - `id` varchar(64) NULL, - `name` varchar(64) NULL, - `age` int NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`,`name`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`,`name`) BUCKETS 4 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "colocate_with" = "group", - "in_memory" = "false", - "storage_format" = "V2", - "disable_auto_compaction" = "false" - ); - """ - - sql """ - CREATE TABLE `test_colo3` ( - `id` varchar(64) NULL, - `name` varchar(64) NULL, - `age` int NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`,`name`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`,`name`) BUCKETS 4 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "colocate_with" = "group", - "in_memory" = "false", - "storage_format" = "V2", - "disable_auto_compaction" = "false" - ); - """ - - sql """ - CREATE TABLE `test_colo4` ( - `id` varchar(64) NULL, - `name` varchar(64) NULL, - `age` int NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`,`name`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`,`name`) BUCKETS 4 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "colocate_with" = "group", - "in_memory" = "false", - "storage_format" = "V2", - "disable_auto_compaction" = "false" - ); - """ - - sql """ - CREATE TABLE `test_colo5` ( - `id` varchar(64) NULL, - `name` varchar(64) NULL, - `age` int NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`,`name`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`,`name`) BUCKETS 4 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "colocate_with" = "group", - "in_memory" = "false", - "storage_format" = "V2", - "disable_auto_compaction" = "false" - ); - """ - - sql """ - create table test_global_tbl1 ( - id int, - name varchar(100), - dt date - ) - distributed by hash(id, name) buckets 4 - properties("colocate_with" = "__global__group1", - "replication_num" = "1"); - """ - - sql """ - create table test_global_tbl2 ( - id int, - name varchar(20), - dt date, - age bigint - ) - distributed by hash(id, name) buckets 4 - properties("colocate_with" = "__global__group1", - "replication_num" = "1"); - """ - - sql """ - create table ${db2}.test_global_tbl3 ( - id int, - name varchar(50), - dt date, - age bigint - ) - partition by range(dt) ( - partition p1 values less than("2022-02-01"), - partition p2 values less than("2022-03-01"), - partition p3 values less than("2022-04-01") - ) - distributed by hash(id, name) buckets 4 - properties("colocate_with" = "__global__group1", - "replication_num" = "1"); - """ - - sql """insert into test_colo1 values('1','a',12);""" - sql """insert into test_colo2 values('1','a',12);""" - sql """insert into test_colo3 values('1','a',12);""" - sql """insert into test_colo4 values('1','a',12);""" - sql """insert into test_colo5 values('1','a',12);""" - - explain { - sql("select * from test_colo1 a inner join test_colo2 b on a.id = b.id and a.name = b.name inner join test_colo3 c on a.id=c.id and a.name= c.name inner join test_colo4 d on a.id=d.id and a.name= d.name inner join test_colo5 e on a.id=e.id and a.name= e.name;") - contains "8:VHASH JOIN\n | join op: INNER JOIN(COLOCATE[])[]" - contains "6:VHASH JOIN\n | join op: INNER JOIN(COLOCATE[])[]" - contains "4:VHASH JOIN\n | join op: INNER JOIN(COLOCATE[])[]" - contains "2:VHASH JOIN\n | join op: INNER JOIN(COLOCATE[])[]" - } - - /* test join same table but hit different rollup, should disable colocate join */ - sql """ DROP TABLE IF EXISTS `test_query_colocate`;""" - - sql """ - CREATE TABLE `test_query_colocate` ( - `datekey` int(11) NULL, - `rollup_1_condition` int null, - `rollup_2_condition` int null, - `sum_col1` bigint(20) SUM NULL, - `sum_col2` bigint(20) SUM NULL - ) ENGINE=OLAP - AGGREGATE KEY(`datekey`,`rollup_1_condition`,`rollup_2_condition`) - COMMENT "" - PARTITION BY RANGE(`datekey`) - (PARTITION p20220102 VALUES [("20220101"), ("20220102")), - PARTITION p20220103 VALUES [("20220102"), ("20220103"))) - DISTRIBUTED BY HASH(`datekey`) BUCKETS 1 - rollup ( - rollup_1(datekey, sum_col1), - rollup_2(datekey, sum_col2) - ) - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "in_memory" = "false", - "storage_format" = "V2" - ) - """ - - sql """insert into test_query_colocate values - (20220101, 102, 200, 200, 100), - (20220101, 101, 200, 200, 100), - (20220101, 102, 202, 200, 100), - (20220101, 101, 202, 200, 100);""" - - explain { - sql("select /*+SET_VAR(parallel_fragment_exec_instance_num=1,parallel_pipeline_task_num=1)*/ " + - " sum_col1,sum_col2 " + - "from " + - "(select datekey,sum(sum_col1) as sum_col1 from test_query_colocate where datekey=20220101 group by datekey) t1 " + - "left join " + - "(select datekey,sum(sum_col2) as sum_col2 from test_query_colocate where datekey=20220101 group by datekey) t2 " + - "on t1.datekey = t2.datekey") - contains "Tables are not in the same group" - } - - sql """ DROP TABLE IF EXISTS `test_query_colocate` """ - - /* test no rollup is selected */ - sql """ DROP TABLE IF EXISTS `tbl1`;""" - sql """ DROP TABLE IF EXISTS `tbl2`;""" - - sql """ - create table tbl1(k1 int, k2 varchar(32), v bigint sum) AGGREGATE KEY(k1,k2) distributed by hash(k1) buckets 1 properties('replication_num' = '1'); - """ - - sql """ - create table tbl2(k3 int, k4 varchar(32)) DUPLICATE KEY(k3) distributed by hash(k3) buckets 1 properties('replication_num' = '1'); - """ - - explain { - sql("select * from tbl1 join tbl2 on tbl1.k1 = tbl2.k3") - contains "INNER JOIN" - } - - sql """ DROP TABLE IF EXISTS `tbl1`;""" - sql """ DROP TABLE IF EXISTS `tbl2`;""" - - sql """insert into ${db1}.test_global_tbl1 values - (1,"jack", "2022-01-01"), - (2,"jack1", "2022-01-02"), - (3,"jack2", "2022-01-03"), - (4,"jack3", "2022-02-01"), - (5,"jack4", "2022-02-01"), - (6, null, "2022-03-01"); - """ - - sql """insert into ${db1}.test_global_tbl2 values - (1,"jack", "2022-01-01", 10), - (2,"jack1", "2022-01-02", 11), - (3,"jack2", "2022-01-03", 12), - (4,"jack3", "2022-02-01", 13), - (5,"jack4", "2022-02-01", 14), - (6,null, "2022-03-01", 15); - """ - - sql """insert into ${db2}.test_global_tbl3 values - (1,"jack", "2022-01-01", 10), - (2,"jack1", "2022-01-02", 11), - (3,"jack2", "2022-01-03", 12), - (4,"jack3", "2022-02-01", 13), - (5,"jack4", "2022-02-01", 14), - (6,null, "2022-03-01", 15); - """ - - order_qt_global1 """select * from ${db1}.test_global_tbl1 a join ${db1}.test_global_tbl2 b on a.id = b.id and a.name = b.name """ - order_qt_global2 """select * from ${db1}.test_global_tbl1 a join ${db2}.test_global_tbl3 b on a.id = b.id and a.name = b.name """ - - explain { - sql ("select * from ${db1}.test_global_tbl1 a join ${db1}.test_global_tbl2 b on a.id = b.id and a.name = b.name") - contains "COLOCATE" - } - explain { - sql ("select * from ${db1}.test_global_tbl1 a join ${db2}.test_global_tbl3 b on a.id = b.id and a.name = b.name") - contains "COLOCATE" - } - /* add partition */ - sql """alter table ${db2}.test_global_tbl3 add partition p4 values less than("2022-05-01")""" - sql """insert into ${db2}.test_global_tbl3 values (7, "jack7", "2022-04-01", 16)""" - order_qt_global3 """select * from ${db1}.test_global_tbl1 a join ${db2}.test_global_tbl3 b on a.id = b.id and a.name = b.name """ - explain { - sql ("select * from ${db1}.test_global_tbl1 a join ${db2}.test_global_tbl3 b on a.id = b.id and a.name = b.name") - contains "COLOCATE" - } - - /* modify group: unset */ - sql """alter table ${db2}.test_global_tbl3 set ("colocate_with" = "");""" - explain { - sql ("select * from ${db1}.test_global_tbl1 a join ${db2}.test_global_tbl3 b on a.id = b.id and a.name = b.name") - contains "Tables are not in the same group" - } - - /* modify group: from global to database level */ - sql """alter table ${db1}.test_global_tbl2 set ("colocate_with" = "db_level_group");""" - explain { - sql ("select * from ${db1}.test_global_tbl1 a join ${db1}.test_global_tbl2 b on a.id = b.id and a.name = b.name") - contains "Tables are not in the same group" - } -} diff --git a/regression-test/suites/correctness_p0/test_push_conjuncts_inlineview.groovy b/regression-test/suites/correctness_p0/test_push_conjuncts_inlineview.groovy deleted file mode 100644 index 29663c702dff87d..000000000000000 --- a/regression-test/suites/correctness_p0/test_push_conjuncts_inlineview.groovy +++ /dev/null @@ -1,189 +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. - -suite("test_push_conjuncts_inlineview") { - sql """ set enable_nereids_planner=false""" - sql """ DROP TABLE IF EXISTS `push_conjunct_table` """ - sql """ - CREATE TABLE `push_conjunct_table` ( - `a_key` varchar(255) NULL , - `d_key` varchar(255) NULL , - `c_key` varchar(32) NULL , - `b_key` date NOT NULL - ) ENGINE=OLAP - UNIQUE KEY(`a_key`, `d_key`, `c_key`) - DISTRIBUTED BY HASH(`a_key`, `d_key`, `c_key`) BUCKETS 4 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "in_memory" = "false", - "storage_format" = "V2", - "disable_auto_compaction" = "false" - ); - """ - explain { - sql("""select - 1 - from - ( - select - rank() over( - partition by a_key - , c_key - , d_key - order by - b_key desc - ) as px - from - push_conjunct_table a - - union all - select 2 as px - from - push_conjunct_table a - )a - where - a.px = 1;""") - contains "5:VSELECT" - } - -explain { - sql("""SELECT * - FROM - (SELECT `a_key` AS `a_key` - FROM - (SELECT `b`.`a_key` AS `a_key` - FROM - (SELECT `a`.`a_key` AS `a_key` - FROM `push_conjunct_table` a) b - GROUP BY 1 ) t2 ) t1 - WHERE a_key = '123';""") - notContains "having" - contains "= '123'" - } - -explain { - sql("""SELECT * - FROM - (SELECT `a`.`a_key` AS `a_key`, - now() as d - FROM `push_conjunct_table` a) t1 - join - (SELECT `a`.`a_key` AS `a_key`, - b_key - FROM `push_conjunct_table` a) t2 - on t1. d = t2.b_key;""") - notContains "VNESTED LOOP JOIN" - } - -sql """ - WITH ttt AS - (SELECT c1, - c2, - c3, - c4, - c5, - c6, - c7 - FROM - (SELECT '10000003' c1, '0816ffk' c2, '1' c3, 1416.0800 c4, '0816ffk' c5, '2023-07-03 15:36:36' c6, 1 c7 ) a - WHERE c7 = 1 ) - SELECT dd.c1, - dd.d1 - FROM - (SELECT src.c1, - - CASE - WHEN IFNULL(src.c3,'') = '' - OR src.c3 = '3' THEN - '-1' - WHEN src.c4 = 0 THEN - '0' - WHEN src.c4 <= 200 THEN - '1' - WHEN src.c4 > 200 - AND src.c4 <= 500 THEN - '2' - WHEN src.c4 > 500 - AND src.c4 <= 1000 THEN - '3' - ELSE '4' - END AS d1 - FROM ttt src - WHERE src.c1 = '10000003' - GROUP BY src.c1, d1 ) dd - WHERE dd.d1 IN ('-1'); -""" - -explain { - sql("""SELECT max(b_key) - FROM - (SELECT a_key, - max(b_key) AS b_key - FROM - (SELECT a_key, - max(b_key) AS b_key - FROM push_conjunct_table - GROUP BY a_key - UNION all - SELECT a_key, - max(b_key) AS b_key - FROM push_conjunct_table - GROUP BY a_key) t2 - GROUP BY t2.a_key ) t - WHERE t.a_key = "abcd" - GROUP BY t.a_key;""") - notContains "having" - contains "= 'abcd'" - } - - sql """ DROP TABLE IF EXISTS `push_conjunct_table` """ - - sql """ DROP TABLE IF EXISTS `dwd_mf_wms_plate_table` """ - sql """ CREATE TABLE `dwd_mf_wms_plate_table` ( - `id` int(11) NOT NULL COMMENT '主键', - `length` float NOT NULL COMMENT '', - `created_time` datetime NULL COMMENT '创建时间' - ) ENGINE=OLAP - UNIQUE KEY(`id`) - COMMENT '' - DISTRIBUTED BY HASH(`id`) BUCKETS 1 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1" - );""" - explain { - sql("""select created_time from( - select - ROW_NUMBER() over(order by id ) as row_num, - id, - length, - created_time - from( - select - id, - `length` , - created_time - from - dwd_mf_wms_plate_table - ) t - group by id,length,created_time - ) res - where res.created_time<'2022-02-18 09:30:13';""") - contains "VSELECT" - } - sql """ DROP TABLE IF EXISTS `dwd_mf_wms_plate_table` """ -} - diff --git a/regression-test/suites/datatype_p0/datetimev2/test_timezone.groovy b/regression-test/suites/datatype_p0/datetimev2/test_timezone.groovy index 5c16b37802c5b39..746a78de4417b3a 100644 --- a/regression-test/suites/datatype_p0/datetimev2/test_timezone.groovy +++ b/regression-test/suites/datatype_p0/datetimev2/test_timezone.groovy @@ -31,27 +31,8 @@ suite("test_timezone") { sql """ set time_zone = '+02:00' """ - sql """ set enable_nereids_planner = false """ - if (isGroupCommitMode()) { - sql """ set enable_nereids_planner = true """ - } - sql """insert into test_timezone values('2022-01-01 01:02:55', '2022-01-01 01:02:55.123')""" - sql """insert into test_timezone values('2022-02-01 01:02:55Z', '2022-02-01 01:02:55.123Z')""" - sql """insert into test_timezone values('2022-03-01 01:02:55+08:00', '2022-03-01 01:02:55.123UTC')""" - sql """insert into test_timezone values('2022-04-01T01:02:55-06:00', '2022-04-01T01:02:55.123+06:00')""" - sql """insert into test_timezone values('2022-05-01 01:02:55+02:30', '2022-05-01 01:02:55.123-02:30')""" - sql """insert into test_timezone values('2022-06-01T01:02:55+04:30', '2022-06-01 01:02:55.123-07:30')""" - sql """insert into test_timezone values('20220701010255+07:00', '20220701010255-05:00')""" - if (isGroupCommitMode()) { - sql """insert into test_timezone values('2022-07-31 21:00', '2022-08-01')""" - } else { - sql """insert into test_timezone values('20220801+05:00', '20220801America/Argentina/Buenos_Aires')""" - } - qt_legacy "select * from test_timezone order by k1" - sql """ truncate table test_timezone """ - sql """ set enable_nereids_planner = true """ sql """insert into test_timezone values('2022-01-01 01:02:55', '2022-01-01 01:02:55.123')""" sql """insert into test_timezone values('2022-02-01 01:02:55Z', '2022-02-01 01:02:55.123Z')""" sql """insert into test_timezone values('2022-05-01 01:02:55+02:30', '2022-05-01 01:02:55.123-02:30')""" diff --git a/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy b/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy index 7ec3942c331f25c..82ed0c8a73c9566 100644 --- a/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy +++ b/regression-test/suites/datatype_p0/nested_types/query/array_functions/test_array_zip_array_enumerate_uniq.groovy @@ -16,30 +16,24 @@ // under the License. suite("test_array_zip_array_enumerate_uniq", "p0") { - sql "set enable_nereids_planner=false;" // ========== array-zip ========== // wrong case - try { - sql """ - SELECT array_zip(); - """ - } catch (Exception ex) { - assertTrue(ex.getMessage().contains("errCode = 2, detailMessage =")) + test { + sql """ SELECT array_zip() """ + exception "errCode = 2, detailMessage =" } - try { - sql """ - SELECT array_zip(['a', 'b', 'c'], ['d', 'e', 'f', 'd']); - """ - } catch (Exception ex) { - assertTrue(ex.getMessage().contains("function array_zip's 2-th argument should have same offsets with first argument")) + test { + sql """ SELECT array_zip(['a', 'b', 'c'], ['d', 'e', 'f', 'd']) """ + exception """function array_zip's 2-th argument should have same offsets with first argument""" } + // nereid not support array_enumerate_uniq // ============= array_enumerate_uniq ========= qt_sql "SELECT 'array_enumerate_uniq';" - order_qt_old_sql """ SELECT array_enumerate_uniq(array_enumerate_uniq(array(cast(10 as LargeInt), cast(100 as LargeInt), cast(2 as LargeInt))), array(cast(123 as LargeInt), cast(1023 as LargeInt), cast(123 as LargeInt))); """ + order_qt_nereid_sql """ SELECT array_enumerate_uniq(array_enumerate_uniq(array(cast(10 as LargeInt), cast(100 as LargeInt), cast(2 as LargeInt))), array(cast(123 as LargeInt), cast(1023 as LargeInt), cast(123 as LargeInt))); """ - order_qt_old_sql """SELECT array_enumerate_uniq( + order_qt_nereid_sql """SELECT array_enumerate_uniq( [111111, 222222, 333333], [444444, 555555, 666666], [111111, 222222, 333333], @@ -48,8 +42,8 @@ suite("test_array_zip_array_enumerate_uniq", "p0") { [444444, 555555, 666666], [111111, 222222, 333333], [444444, 555555, 666666]);""" - order_qt_old_sql """SELECT array_enumerate_uniq(array(STDDEV_SAMP(910947.571364)), array(NULL)) from numbers;""" - //order_qt_sql """ SELECT max(array_join(arr)) FROM (SELECT array_enumerate_uniq(group_array(DIV(number, 54321)) AS nums, group_array(cast(DIV(number, 98765) as string))) AS arr FROM (SELECT number FROM numbers LIMIT 1000000) GROUP BY bitmap_hash(number) % 100000);""" + order_qt_nereid_sql """SELECT array_enumerate_uniq(array(STDDEV_SAMP(910947.571364)), array(NULL)) from numbers;""" +// //order_qt_sql """ SELECT max(array_join(arr)) FROM (SELECT array_enumerate_uniq(group_array(DIV(number, 54321)) AS nums, group_array(cast(DIV(number, 98765) as string))) AS arr FROM (SELECT number FROM numbers LIMIT 1000000) GROUP BY bitmap_hash(number) % 100000);""" sql """ DROP TABLE IF EXISTS ARRAY_BIGINT_DATA;""" sql """ CREATE TABLE IF NOT EXISTS `ARRAY_BIGINT_DATA` ( @@ -64,50 +58,6 @@ suite("test_array_zip_array_enumerate_uniq", "p0") { sql """ INSERT INTO ARRAY_BIGINT_DATA VALUES (0, [-1, 0, 1, 2, -9223372036854775808, 9223372036854775807, 1]);""" sql """ INSERT INTO ARRAY_BIGINT_DATA VALUES (1, []);""" - test { - sql """ select array_enumerate_uniq((select data from ARRAY_BIGINT_DATA where id = 0), (select data from ARRAY_BIGINT_DATA where id = 1), (select data from ARRAY_BIGINT_DATA where id = 1));""" - exception ("A subquery should not return Array/Map/Struct type") - } - - - // nereids - sql "set enable_nereids_planner=true;" - sql "set enable_fallback_to_original_planner=false;" -// ========== array-zip ========== -// wrong case - try { - sql """ - SELECT array_zip(); - """ - } catch (Exception ex) { - assertTrue(ex.getMessage().size() > 0) - } - - try { - sql """ - SELECT array_zip(['a', 'b', 'c'], ['d', 'e', 'f', 'd']); - """ - } catch (Exception ex) { - assertTrue(ex.getMessage().contains("function array_zip's 2-th argument should have same offsets with first argument")) - } - - // nereid not support array_enumerate_uniq - // ============= array_enumerate_uniq ========= - qt_sql "SELECT 'array_enumerate_uniq';" - order_qt_nereid_sql """ SELECT array_enumerate_uniq(array_enumerate_uniq(array(cast(10 as LargeInt), cast(100 as LargeInt), cast(2 as LargeInt))), array(cast(123 as LargeInt), cast(1023 as LargeInt), cast(123 as LargeInt))); """ - - order_qt_nereid_sql """SELECT array_enumerate_uniq( - [111111, 222222, 333333], - [444444, 555555, 666666], - [111111, 222222, 333333], - [444444, 555555, 666666], - [111111, 222222, 333333], - [444444, 555555, 666666], - [111111, 222222, 333333], - [444444, 555555, 666666]);""" - order_qt_nereid_sql """SELECT array_enumerate_uniq(array(STDDEV_SAMP(910947.571364)), array(NULL)) from numbers;""" -// //order_qt_sql """ SELECT max(array_join(arr)) FROM (SELECT array_enumerate_uniq(group_array(DIV(number, 54321)) AS nums, group_array(cast(DIV(number, 98765) as string))) AS arr FROM (SELECT number FROM numbers LIMIT 1000000) GROUP BY bitmap_hash(number) % 100000);""" - test { sql """ select array_enumerate_uniq((select data from ARRAY_BIGINT_DATA where id = 0), (select data from ARRAY_BIGINT_DATA where id = 1), (select data from ARRAY_BIGINT_DATA where id = 1));""" exception ("lengths of all arrays of function array_enumerate_uniq must be equal") diff --git a/regression-test/suites/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.groovy b/regression-test/suites/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.groovy deleted file mode 100644 index bd6d39005857414..000000000000000 --- a/regression-test/suites/ddl_p0/test_create_table_generated_column/test_create_table_generated_column_legacy.groovy +++ /dev/null @@ -1,249 +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. - -suite("test_create_table_generated_column_legacy") { - // test legacy planner create - sql "SET enable_nereids_planner=false;" - sql "drop table if exists test_gen_col_common_legacy" - qt_common_default """create table test_gen_col_common_legacy(a int,b int,c double generated always as (abs(a+b)) not null) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - ;""" - sql "drop table if exists test_gen_col_without_generated_always_legacy" - qt_common_without_generated_always """create table test_gen_col_without_generated_always_legacy(a int,b int,c double as (abs(a+b)) not null) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - ;""" - sql "drop table if exists test_gen_col_in_middle_legacy" - qt_gencol_in_middle """create table test_gen_col_in_middle_legacy(a int,c double generated always as (abs(a+b)) not null,b int) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1");""" - sql "drop table if exists gencol_refer_gencol_legacy" - qt_gencol_refer_gencol """ - create table gencol_refer_gencol_legacy(a int,c double generated always as (abs(a+b)) not null,b int, d int generated always as(c+1)) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - sql "drop table if exists test_gen_col_array_func_legacy" - qt_gencol_array_function_create """ - create table test_gen_col_array_func_legacy(pk int,a array,b array, c array generated always as (array_union(a,b)) not null) - DISTRIBUTED BY HASH(pk) - PROPERTIES("replication_num" = "1"); - ; - """ - sql "drop table if exists test_gen_col_element_at_func_legacy" - qt_gencol_array_function_element_at_create """ - create table test_gen_col_element_at_func_legacy(pk int,a array,b array, c int generated always as (element_at(a, 1)) not null) - DISTRIBUTED BY HASH(pk) - PROPERTIES("replication_num" = "1"); - ; - """ - test { - sql """ - create table gencol_type_check(a int,b int, c array generated always as (abs(a+b,3)) not null) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "In generated column 'c', no matching function with signature" - } - - // gencol_has_sum - test { - sql """ - create table gencol_has_sum(a int,b int, c int generated always as (sum(a)) not null) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "Expression of generated column 'c' contains a disallowed function" - } - - // gencol_has_column_not_define - test { - sql """ - create table gencol_has_sum(a int,b int, c int generated always as (abs(d)) not null) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "Unknown column 'd' in 'generated column function'" - } - - // gencol_refer_gencol_after - test { - sql """ - create table gencol_refer_gencol_legacy(a int,c double generated always as (abs(a+d)) not null,b int, d int generated always as(c+1)) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "Generated column can refer only to generated columns defined prior to it." - } - - sql "set @myvar=2" - // gencol_has_var - test { - sql """ - create table test_gen_col_not_null100(a varchar(10),c double generated always as (abs(a+b+@myvar)) not null,b int) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "Generated column expression cannot contain variable." - } - - test { - sql """ - create table test_gen_col_auto_increment(a bigint not null auto_increment, b int, c int as (a*b)) - distributed by hash(a) properties("replication_num" = "1"); - """ - exception "Generated column 'c' cannot refer to auto-increment column." - } - - test{ - sql """ - create table test_gen_col_subquery(a int,b int, c int generated always as (a+(select 1)) not null) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "Generated column does not support subquery." - } - - test { - sql """ - create table test_gen_col_array_func_lambda(pk int,a array,b array, c array generated always as (array_count(x->(x%2=0),b)) not null) - DISTRIBUTED BY HASH(pk) - PROPERTIES("replication_num" = "1"); - """ - exception "Generated column does not support lambda." - } - - test { - sql """ - create table test_gen_col_array_func_legacy(pk int,a array,b array, c double generated always as (a+b) not null) - DISTRIBUTED BY HASH(pk) - PROPERTIES("replication_num" = "1"); - """ - exception "In generated column 'c', can not cast from origin type" - } - - test { - sql """ - create table test_window_func(a int default 10, b int default 100, c boolean as(rank() over())) DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1");""" - exception "Expression of generated column 'c' contains a disallowed expression:'rank() OVER ()'" - } - test { - sql """ - create table test_grouping(a int default 10, b int default 100, c boolean as(grouping(a))) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1");""" - exception "Expression of generated column 'c' contains a disallowed function:'grouping'" - } - - sql "SET enable_nereids_planner=true;" - sql "SET enable_fallback_to_original_planner=false;" - qt_common_default_insert "INSERT INTO test_gen_col_common_legacy values(6,7,default);" - qt_common_default_insert_with_specific_column "INSERT INTO test_gen_col_common_legacy(a,b) values(1,2);" - qt_common_default_test_insert_default "INSERT INTO test_gen_col_common_legacy values(3,5,default);" - qt_commont_default_select "select * from test_gen_col_common_legacy order by 1,2,3;" - - // qt_common_default_test_insert_null - test { - sql "INSERT INTO test_gen_col_common_legacy(a,b) values(1,null);" - def exception_str = isGroupCommitMode() ? "too many filtered rows" : "Insert has filtered data in strict mode" - exception exception_str - } - - // qt_common_default_test_insert_gencol - test { - sql "INSERT INTO test_gen_col_common_legacy values(1,2,3);" - exception "The value specified for generated column 'c' in table 'test_gen_col_common_legacy' is not allowed." - } - - - qt_common_without_generated_always_insert "INSERT INTO test_gen_col_without_generated_always_legacy values(6,7,default);" - qt_common_without_generated_always_insert_with_specific_column "INSERT INTO test_gen_col_without_generated_always_legacy(a,b) values(1,2);" - qt_commont_without_generated_always_select "select * from test_gen_col_without_generated_always_legacy order by 1,2,3;" - - - qt_gencol_in_middle_insert "insert into test_gen_col_in_middle_legacy values(1,default,5);" - qt_gencol_in_middle_insert_with_specific_column "insert into test_gen_col_in_middle_legacy(a,b) values(4,5);" - qt_gencol_in_middle_insert_with_specific_column_2 "insert into test_gen_col_in_middle_legacy(a,b,c) values(1,6,default);" - qt_gencol_in_middle_select "select * from test_gen_col_in_middle_legacy order by 1,2,3;" - - - qt_gencol_refer_gencol_insert "insert into gencol_refer_gencol_legacy values(1,default,5,default);" - qt_gencol_refer_gencol_insert2 "insert into gencol_refer_gencol_legacy(a,b) values(5,6);" - qt_gencol_refer_gencol_insert3 "insert into gencol_refer_gencol_legacy(a,b,c) values(2,9,default);" - qt_gencol_refer_gencol_insert4 "insert into gencol_refer_gencol_legacy(a,b,c,d) values(3,3,default,default);" - qt_gencol_refer_gencol_select "select * from gencol_refer_gencol_legacy order by 1,2,3,4;" - - - qt_gencol_array_function_insert "insert into test_gen_col_array_func_legacy values(1,[1,2],[3,2],default);" - qt_gencol_array_function_select "select * from test_gen_col_array_func_legacy" - - - qt_gencol_array_function_element_at_insert "insert into test_gen_col_element_at_func_legacy values(1,[1,2],[3,2],default);" - qt_gencol_array_function_element_at_select "select * from test_gen_col_element_at_func_legacy" - - test { - sql """ - create table test_gen_col_aggregate(a int,b int,c int sum generated always as (abs(a+1)) not null) - aggregate key(a,b) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "The generated columns can be key columns, or value columns of replace and replace_if_not_null aggregation type." - } - - // test drop dependency - sql "drop table if exists gencol_refer_gencol_legacy" - qt_gencol_refer_gencol """ - create table gencol_refer_gencol_legacy(a int,c double generated always as (abs(a+b)) not null,b int, d int generated always as(c+1)) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - sql "insert into gencol_refer_gencol_legacy(a,b) values(3,4)" - test { - sql "alter table gencol_refer_gencol_legacy drop column a" - exception "Column 'a' has a generated column dependency on :[c]" - } - test { - sql "alter table gencol_refer_gencol_legacy drop column c" - exception "Column 'c' has a generated column dependency on :[d]" - } - sql "alter table gencol_refer_gencol_legacy drop column d" - sql "alter table gencol_refer_gencol_legacy drop column c" - sql "alter table gencol_refer_gencol_legacy drop column b" - qt_test_drop_column "select * from gencol_refer_gencol_legacy" - test { - sql """ - create table test_gen_col_default(a int,b int,c int generated always as (abs(a+1)) not null default 10) - aggregate key(a,b,c) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "Generated columns cannot have default value." - } - test { - sql """ - create table test_gen_col_increment(a int,b int,c int generated always as (abs(a+1)) not null auto_increment) - aggregate key(a,b,c) - DISTRIBUTED BY HASH(a) - PROPERTIES("replication_num" = "1"); - """ - exception "Generated columns cannot be auto_increment." - } - -} \ No newline at end of file diff --git a/regression-test/suites/ddl_p0/test_create_view.groovy b/regression-test/suites/ddl_p0/test_create_view.groovy deleted file mode 100644 index 0cc42f8fcc16167..000000000000000 --- a/regression-test/suites/ddl_p0/test_create_view.groovy +++ /dev/null @@ -1,237 +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. - -suite("test_create_view") { - sql "SET enable_nereids_planner=false" - sql """DROP TABLE IF EXISTS count_distinct""" - sql """ - CREATE TABLE IF NOT EXISTS count_distinct - ( - RQ DATE NOT NULL COMMENT "日期", - v1 VARCHAR(100) NOT NULL COMMENT "字段1", - v2 VARCHAR(100) NOT NULL COMMENT "字段2", - v3 VARCHAR(100) REPLACE_IF_NOT_NULL COMMENT "字段3" - ) - AGGREGATE KEY(RQ,v1,v2) - PARTITION BY RANGE(RQ) - ( - PARTITION p20220908 VALUES LESS THAN ('2022-09-09') - ) - DISTRIBUTED BY HASH(v1,v2) BUCKETS 3 - PROPERTIES( - "replication_num" = "1", - "dynamic_partition.enable" = "true", - "dynamic_partition.time_unit" = "DAY", - "dynamic_partition.start" = "-3", - "dynamic_partition.end" = "3", - "dynamic_partition.prefix" = "p", - "dynamic_partition.buckets" = "3" - ); - """ - sql "drop view if exists test_count_distinct" - sql """ - CREATE VIEW IF NOT EXISTS test_count_distinct - ( - RQ comment "日期", - v1 comment "v1", - v2 comment "v2", - v3 comment "v3" - ) - AS - select aa.RQ as RQ, aa.v1 as v1,aa.v2 as v2 , bb.v3 as v3 from - ( - select RQ, count(distinct v1) as v1 , count(distinct v2 ) as v2 - from count_distinct - group by RQ - ) aa - LEFT JOIN - ( - select RQ, max(v3) as v3 - from count_distinct - group by RQ - ) bb - on aa.RQ = bb.RQ; - """ - - sql """select * from test_count_distinct""" - sql """DROP VIEW IF EXISTS test_count_distinct""" - sql """DROP TABLE IF EXISTS count_distinct""" - - sql """DROP TABLE IF EXISTS t1""" - sql """ - CREATE TABLE `t1` ( - k1 int, - k2 date, - v1 int - ) ENGINE=OLAP - UNIQUE KEY(`k1`,`k2`) - COMMENT '测试' - PARTITION BY RANGE(k2) ( - PARTITION p1 VALUES [('2023-07-01'), ('2023-07-10')), - PARTITION p2 VALUES [('2023-07-11'), ('2023-07-20')) - ) - DISTRIBUTED BY HASH(`k1`) BUCKETS 3 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1" - );""" - sql """DROP TABLE IF EXISTS t2""" - sql """ - CREATE TABLE `t2` ( - k1 int, - k2 date, - v1 int - ) ENGINE=OLAP - UNIQUE KEY(`k1`,`k2`) - COMMENT '测试' - PARTITION BY RANGE(k2) ( - PARTITION p1 VALUES [('2023-07-01'), ('2023-07-05')), - PARTITION p2 VALUES [('2023-07-05'), ('2023-07-15')) - ) - DISTRIBUTED BY HASH(`k1`) BUCKETS 3 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1" - ); """ - sql """ - CREATE VIEW IF NOT EXISTS my_view AS - SELECT t1.* FROM t1 PARTITION(p1) JOIN t2 PARTITION(p2) ON t1.k1 = t2.k1; """ - sql """SELECT * FROM my_view""" - sql """DROP VIEW IF EXISTS my_view""" - sql """DROP TABLE IF EXISTS t1""" - sql """DROP TABLE IF EXISTS t2""" - - - sql """DROP TABLE IF EXISTS view_baseall""" - sql """DROP VIEW IF EXISTS test_view7""" - sql """DROP VIEW IF EXISTS test_view8""" - sql """ - CREATE TABLE `view_baseall` ( - `k1` int(11) NULL, - `k3` array NULL - ) ENGINE=OLAP - DUPLICATE KEY(`k1`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`k1`) BUCKETS 5 - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1", - "is_being_synced" = "false", - "storage_format" = "V2", - "light_schema_change" = "true", - "disable_auto_compaction" = "false", - "enable_single_replica_compaction" = "false" - ); - """ - sql """insert into view_baseall values(1,[1,2,3]);""" - sql """insert into view_baseall values(2,[10,-2,8]);""" - sql """insert into view_baseall values(3,[-1,20,0]);""" - - qt_test_view_1 """ select * from view_baseall order by k1; """ - qt_test_view_2 """ select *, array_map(x->x>0,k3) from view_baseall order by k1; """ - qt_test_view_3 """ select *, array_filter(x->x>0,k3),array_filter(`k3`, array_map(x -> x > 0, `k3`)) from view_baseall order by k1; """ - - - sql """ - create view IF NOT EXISTS test_view7 (k1,k2,k3,k4) as - select *, array_filter(x->x>0,k3),array_filter(`k3`, array_map(x -> x > 0, `k3`)) from view_baseall order by k1; - """ - qt_test_view_4 """ select * from test_view7 order by k1; """ - - sql """ - create view IF NOT EXISTS test_view8 (k1,k2,k3) as - select *, array_map(x->x>0,k3) from view_baseall order by k1; - """ - qt_test_view_5 """ select * from test_view8 order by k1; """ - - sql """DROP TABLE IF EXISTS view_column_name_test""" - sql """ - CREATE TABLE IF NOT EXISTS view_column_name_test - ( - `timestamp` DATE NOT NULL COMMENT "['0000-01-01', '9999-12-31']", - `type` TINYINT NOT NULL COMMENT "[-128, 127]", - `error_code` INT COMMENT "[-2147483648, 2147483647]", - `error_msg` VARCHAR(300) COMMENT "[1-65533]", - `op_id` BIGINT COMMENT "[-9223372036854775808, 9223372036854775807]", - `op_time` DATETIME COMMENT "['0000-01-01 00:00:00', '9999-12-31 23:59:59']", - `target` float COMMENT "4 字节", - `source` double COMMENT "8 字节", - `lost_cost` decimal(12,2) COMMENT "", - `remark` string COMMENT "1m size", - `op_userid` LARGEINT COMMENT "[-2^127 + 1 ~ 2^127 - 1]", - `plate` SMALLINT COMMENT "[-32768, 32767]", - `iscompleted` boolean COMMENT "true 或者 false" - ) - DISTRIBUTED BY HASH(`type`) BUCKETS 1 - PROPERTIES ('replication_num' = '1'); - """ - - sql """ - DROP VIEW IF EXISTS v1 - """ - sql """ - CREATE VIEW v1 AS - SELECT - error_code, - 1, - 'string', - now(), - dayofyear(op_time), - cast (source AS BIGINT), - min(`timestamp`) OVER ( - ORDER BY - op_time DESC ROWS BETWEEN UNBOUNDED PRECEDING - AND 1 FOLLOWING - ), - 1 > 2, - 2 + 3, - 1 IN (1, 2, 3, 4), - remark LIKE '%like', - CASE WHEN remark = 's' THEN 1 ELSE 2 END, - TRUE | FALSE - FROM - view_column_name_test - """ - qt_test_view_6 """ SHOW VIEW FROM view_column_name_test;""" - - sql """ drop view if exists xxx;""" - sql """CREATE VIEW - `xxx` COMMENT 'VIEW' AS - WITH - CHENGBENJIA AS ( - SELECT - RN - FROM - ( - SELECT - row_number() OVER ( - PARTITION BY `A`.`timestamp`, - `A`.`type` - ORDER BY - CAST( - concat( - CAST(`A`.`error_msg` AS VARCHAR(*)), - CAST(`A`.`remark` AS VARCHAR(*)) - ) AS INT - ) DESC NULLS LAST - ) AS `RN` - FROM - view_column_name_test A - ) A - ) - SELECT - * from CHENGBENJIA;""" - sql """select * from xxx;""" - sql """ drop view if exists xxx;""" -} diff --git a/regression-test/suites/demo_p0/explain_action.groovy b/regression-test/suites/demo_p0/explain_action.groovy index 511b9509360a3f3..ba6cb6ad726e1d7 100644 --- a/regression-test/suites/demo_p0/explain_action.groovy +++ b/regression-test/suites/demo_p0/explain_action.groovy @@ -23,9 +23,9 @@ suite("explain_action") { explain { sql("select 100") - // contains("OUTPUT EXPRS:\n 100\n") && contains("PARTITION: UNPARTITIONED\n") - contains "OUTPUT EXPRS:\n 100\n" - contains "PARTITION: UNPARTITIONED\n" + // contains("100") && contains("UNION") + contains "100" + contains "UNION" } explain { diff --git a/regression-test/suites/insert_p0/insert_group_commit_into_max_filter_ratio.groovy b/regression-test/suites/insert_p0/insert_group_commit_into_max_filter_ratio.groovy index 64ae30f8f8a63f5..53faa68816e4224 100644 --- a/regression-test/suites/insert_p0/insert_group_commit_into_max_filter_ratio.groovy +++ b/regression-test/suites/insert_p0/insert_group_commit_into_max_filter_ratio.groovy @@ -168,69 +168,49 @@ suite("insert_group_commit_into_max_filter_ratio") { // if enable strict mode // 100 rows(success, fail), 10000 rows(success, fail), 15000 rows(success, fail) // async mode, sync mode, off mode - for (item in ["legacy", "nereids"]) { - sql """ truncate table ${tableName} """ - connect(user = context.config.jdbcUser, password = context.config.jdbcPassword, url = context.config.jdbcUrl) { - if (item == "nereids") { - sql """ set enable_nereids_planner=true; """ - sql """ set enable_fallback_to_original_planner=false; """ - } else { - sql """ set enable_nereids_planner = false; """ - } + sql """ truncate table ${tableName} """ + connect(user = context.config.jdbcUser, password = context.config.jdbcPassword, url = context.config.jdbcUrl) { - sql """ set group_commit = sync_mode; """ - group_commit_insert """ insert into ${dbTableName} values (1, 'a', 10); """, 1 - sql """ set group_commit = async_mode; """ - group_commit_insert """ insert into ${dbTableName}(id) values(2); """, 1 - sql """ set group_commit = off_mode; """ - off_mode_group_commit_insert """ insert into ${dbTableName} values (3, 'a', 10); """, 1 + sql """ set group_commit = sync_mode; """ + group_commit_insert """ insert into ${dbTableName} values (1, 'a', 10); """, 1 + sql """ set group_commit = async_mode; """ + group_commit_insert """ insert into ${dbTableName}(id) values(2); """, 1 + sql """ set group_commit = off_mode; """ + off_mode_group_commit_insert """ insert into ${dbTableName} values (3, 'a', 10); """, 1 - sql """ set group_commit = async_mode; """ - if (item == "nereids") { - group_commit_insert """ insert into ${dbTableName} values (4, 'abc', 10); """, 0 - } else { - fail_group_commit_insert """ insert into ${dbTableName} values (4, 'abc', 10); """, 0 - } - sql """ set enable_insert_strict = false; """ - group_commit_insert """ insert into ${dbTableName} values (5, 'abc', 10); """, 0 - - // The row 6 and 7 is different between legacy and nereids - try { - sql """ set group_commit = off_mode; """ - sql """ set enable_insert_strict = true; """ - sql """ insert into ${dbTableName} values (6, 'a', 'a'); """ - } catch (Exception e) { - logger.info("exception: " + e) - assertTrue(e.toString().contains("Invalid number format")) - } + sql """ set group_commit = async_mode; """ + group_commit_insert """ insert into ${dbTableName} values (4, 'abc', 10); """, 0 + sql """ set enable_insert_strict = false; """ + group_commit_insert """ insert into ${dbTableName} values (5, 'abc', 10); """, 0 - try { - sql """ set group_commit = off_mode; """ - sql """ set enable_insert_strict = false; """ - sql """ insert into ${dbTableName} values (7, 'a', 'a'); """ - } catch (Exception e) { - logger.info("exception: " + e) - assertTrue(e.toString().contains("Invalid number format")) - } - - // TODO should throw exception? - sql """ set group_commit = async_mode; """ + // The row 6 and 7 is different between legacy and nereids + try { + sql """ set group_commit = off_mode; """ sql """ set enable_insert_strict = true; """ - if (item == "nereids") { - // will write [8, a, null] - // group_commit_insert """ insert into ${dbTableName} values (8, 'a', 'a'); """, 1 - } else { - fail_group_commit_insert """ insert into ${dbTableName} values (8, 'a', 'a'); """, 0 - } - sql """ set group_commit = async_mode; """ - sql """ set enable_insert_strict = false; """ - group_commit_insert """ insert into ${dbTableName} values (9, 'a', 'a'); """, 1 + sql """ insert into ${dbTableName} values (6, 'a', 'a'); """ + } catch (Exception e) { + logger.info("exception: " + e) + assertTrue(e.toString().contains("Invalid number format")) } - if (item == "nereids") { - get_row_count_with_retry(6) - } else { - get_row_count_with_retry(4) + + try { + sql """ set group_commit = off_mode; """ + sql """ set enable_insert_strict = false; """ + sql """ insert into ${dbTableName} values (7, 'a', 'a'); """ + } catch (Exception e) { + logger.info("exception: " + e) + assertTrue(e.toString().contains("Invalid number format")) } + + // TODO should throw exception? + sql """ set group_commit = async_mode; """ + sql """ set enable_insert_strict = true; """ + // will write [8, a, null] + // group_commit_insert """ insert into ${dbTableName} values (8, 'a', 'a'); """, 1 + sql """ set group_commit = async_mode; """ + sql """ set enable_insert_strict = false; """ + group_commit_insert """ insert into ${dbTableName} values (9, 'a', 'a'); """, 1 + get_row_count_with_retry(6) order_qt_sql """ select * from ${dbTableName} """ } sql """ truncate table ${tableName} """ diff --git a/regression-test/suites/insert_p0/insert_group_commit_with_exception.groovy b/regression-test/suites/insert_p0/insert_group_commit_with_exception.groovy index f59c9bb8b00c699..e207e71f2cc964e 100644 --- a/regression-test/suites/insert_p0/insert_group_commit_with_exception.groovy +++ b/regression-test/suites/insert_p0/insert_group_commit_with_exception.groovy @@ -43,12 +43,11 @@ suite("insert_group_commit_with_exception") { return true } - for (item in ["legacy", "nereids"]) { - try { - // create table - sql """ drop table if exists ${table}; """ + try { + // create table + sql """ drop table if exists ${table}; """ - sql """ + sql """ CREATE TABLE `${table}` ( `id` int(11) NOT NULL, `name` varchar(1100) NULL, @@ -62,234 +61,214 @@ suite("insert_group_commit_with_exception") { ); """ - sql """ set group_commit = async_mode; """ - if (item == "nereids") { - sql """ set enable_nereids_planner=true; """ - sql """ set enable_fallback_to_original_planner=false; """ - sql "set enable_server_side_prepared_statement = true" - } else { - sql """ set enable_nereids_planner = false; """ - sql "set enable_server_side_prepared_statement = false" - } + sql """ set group_commit = async_mode; """ + sql "set enable_server_side_prepared_statement = true" + // insert into without column + try { + def result = sql """ insert into ${table} values(1, 'a', 10, 100) """ + assertTrue(false) + } catch (Exception e) { + assertTrue(e.getMessage().contains("Column count doesn't match value count")) + } - // insert into without column - try { - def result = sql """ insert into ${table} values(1, 'a', 10, 100) """ + try { + def result = sql """ insert into ${table} values(2, 'b') """ + assertTrue(false) + } catch (Exception e) { + assertTrue(e.getMessage().contains("Column count doesn't match value count")) + } + + result = sql """ insert into ${table} values(3, 'c', 30) """ + logger.info("insert result: " + result) + + // insert into with column + result = sql """ insert into ${table}(id, name) values(4, 'd') """ + logger.info("insert result: " + result) + + getRowCount(2) + + try { + result = sql """ insert into ${table}(id, name) values(5, 'd', 50) """ + assertTrue(false) + } catch (Exception e) { + assertTrue(e.getMessage().contains("Column count doesn't match value count")) + } + + try { + result = sql """ insert into ${table}(id, name) values(6) """ + assertTrue(false) + } catch (Exception e) { + assertTrue(e.getMessage().contains("Column count doesn't match value count")) + } + + try { + result = sql """ insert into ${table}(id, names) values(7, 'd') """ + assertTrue(false) + } catch (Exception e) { + assertTrue(e.getMessage().contains("Unknown column 'names'")) + } + + + // prepare insert + def db = context.config.defaultDb + "_insert_p0" + String url = getServerPrepareJdbcUrl(context.config.jdbcUrl, db) + + try (Connection connection = DriverManager.getConnection(url, context.config.jdbcUser, context.config.jdbcPassword)) { + Statement statement = connection.createStatement(); + statement.execute("use ${db}"); + statement.execute("set group_commit = eventual_consistency;"); + statement.execute("set enable_server_side_prepared_statement = true") + // without column + try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?, ?)")) { + ps.setObject(1, 8); + ps.setObject(2, "f"); + ps.setObject(3, 70); + ps.setObject(4, "a"); + ps.addBatch(); + int[] result = ps.executeBatch(); assertTrue(false) } catch (Exception e) { assertTrue(e.getMessage().contains("Column count doesn't match value count")) } - try { - def result = sql """ insert into ${table} values(2, 'b') """ + try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?)")) { + ps.setObject(1, 9); + ps.setObject(2, "f"); + ps.addBatch(); + int[] result = ps.executeBatch(); assertTrue(false) } catch (Exception e) { assertTrue(e.getMessage().contains("Column count doesn't match value count")) } - result = sql """ insert into ${table} values(3, 'c', 30) """ - logger.info("insert result: " + result) - - // insert into with column - result = sql """ insert into ${table}(id, name) values(4, 'd') """ - logger.info("insert result: " + result) + try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?)")) { + ps.setObject(1, 10); + ps.setObject(2, "f"); + ps.setObject(3, 90); + ps.addBatch(); + int[] result = ps.executeBatch(); + logger.info("prepare insert result: " + result) + } - getRowCount(2) + // with columns + try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name) values(?, ?)")) { + ps.setObject(1, 11); + ps.setObject(2, "f"); + ps.addBatch(); + int[] result = ps.executeBatch(); + logger.info("prepare insert result: " + result) + } - try { - result = sql """ insert into ${table}(id, name) values(5, 'd', 50) """ + try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name) values(?, ?, ?)")) { + ps.setObject(1, 12); + ps.setObject(2, "f"); + ps.setObject(3, "f"); + ps.addBatch(); + int[] result = ps.executeBatch(); assertTrue(false) } catch (Exception e) { assertTrue(e.getMessage().contains("Column count doesn't match value count")) } - try { - result = sql """ insert into ${table}(id, name) values(6) """ + try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name) values(?)")) { + ps.setObject(1, 13); + ps.addBatch(); + int[] result = ps.executeBatch(); assertTrue(false) } catch (Exception e) { assertTrue(e.getMessage().contains("Column count doesn't match value count")) } - try { - result = sql """ insert into ${table}(id, names) values(7, 'd') """ + try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, names) values(?, ?)")) { + ps.setObject(1, 12); + ps.setObject(2, "f"); + ps.addBatch(); + int[] result = ps.executeBatch(); assertTrue(false) } catch (Exception e) { assertTrue(e.getMessage().contains("Unknown column 'names'")) } + getRowCount(4) - // prepare insert - def db = context.config.defaultDb + "_insert_p0" - String url = getServerPrepareJdbcUrl(context.config.jdbcUrl, db) - - try (Connection connection = DriverManager.getConnection(url, context.config.jdbcUser, context.config.jdbcPassword)) { - Statement statement = connection.createStatement(); - statement.execute("use ${db}"); - statement.execute("set group_commit = eventual_consistency;"); - if (item == "nereids") { - statement.execute("set enable_nereids_planner=true;"); - statement.execute("set enable_fallback_to_original_planner=false;"); - sql "set enable_server_side_prepared_statement = true" - } else { - statement.execute("set enable_nereids_planner = false;") - sql "set enable_server_side_prepared_statement = false" - } - // without column - try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?, ?)")) { - ps.setObject(1, 8); - ps.setObject(2, "f"); - ps.setObject(3, 70); - ps.setObject(4, "a"); - ps.addBatch(); - int[] result = ps.executeBatch(); - assertTrue(false) - } catch (Exception e) { - assertTrue(e.getMessage().contains("Column count doesn't match value count")) - } - - try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?)")) { - ps.setObject(1, 9); - ps.setObject(2, "f"); - ps.addBatch(); - int[] result = ps.executeBatch(); - assertTrue(false) - } catch (Exception e) { - assertTrue(e.getMessage().contains("Column count doesn't match value count")) - } - - try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?)")) { - ps.setObject(1, 10); + // prepare insert with multi rows + try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?)")) { + for (int i = 0; i < 5; i++) { + ps.setObject(1, 13 + i); ps.setObject(2, "f"); ps.setObject(3, 90); ps.addBatch(); int[] result = ps.executeBatch(); logger.info("prepare insert result: " + result) } + } + getRowCount(9) - // with columns - try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name) values(?, ?)")) { - ps.setObject(1, 11); - ps.setObject(2, "f"); - ps.addBatch(); - int[] result = ps.executeBatch(); - logger.info("prepare insert result: " + result) - } - - try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name) values(?, ?, ?)")) { - ps.setObject(1, 12); - ps.setObject(2, "f"); - ps.setObject(3, "f"); - ps.addBatch(); - int[] result = ps.executeBatch(); - assertTrue(false) - } catch (Exception e) { - assertTrue(e.getMessage().contains("Column count doesn't match value count")) - } - - try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name) values(?)")) { - ps.setObject(1, 13); - ps.addBatch(); - int[] result = ps.executeBatch(); - assertTrue(false) - } catch (Exception e) { - assertTrue(e.getMessage().contains("Column count doesn't match value count")) - } - - try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, names) values(?, ?)")) { - ps.setObject(1, 12); + // prepare insert with multi rows + try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?),(?, ?, ?)")) { + for (int i = 0; i < 2; i++) { + ps.setObject(1, 18 + i); ps.setObject(2, "f"); + ps.setObject(3, 90); + ps.setObject(4, 18 + i + 1); + ps.setObject(5, "f"); + ps.setObject(6, 90); ps.addBatch(); int[] result = ps.executeBatch(); - assertTrue(false) - } catch (Exception e) { - assertTrue(e.getMessage().contains("Unknown column 'names'")) - } - - getRowCount(4) - - // prepare insert with multi rows - try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?)")) { - for (int i = 0; i < 5; i++) { - ps.setObject(1, 13 + i); - ps.setObject(2, "f"); - ps.setObject(3, 90); - ps.addBatch(); - int[] result = ps.executeBatch(); - logger.info("prepare insert result: " + result) - } - } - getRowCount(9) - - // prepare insert with multi rows - try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?),(?, ?, ?)")) { - for (int i = 0; i < 2; i++) { - ps.setObject(1, 18 + i); - ps.setObject(2, "f"); - ps.setObject(3, 90); - ps.setObject(4, 18 + i + 1); - ps.setObject(5, "f"); - ps.setObject(6, 90); - ps.addBatch(); - int[] result = ps.executeBatch(); - logger.info("prepare insert result: " + result) - } - } - getRowCount(13) - - // prepare insert without column names, and do schema change - try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?)")) { - ps.setObject(1, 22) - ps.setObject(2, "f") - ps.setObject(3, 90) - ps.addBatch() - int[] result = ps.executeBatch() logger.info("prepare insert result: " + result) - - sql """ alter table ${table} ADD column age int after name; """ - assertTrue(getAlterTableState(), "add column should success") - - try { - ps.setObject(1, 23) - ps.setObject(2, "f") - ps.setObject(3, 90) - ps.addBatch() - result = ps.executeBatch() - assertTrue(false) - } catch (Exception e) { - logger.info("exception : " + e) - if (item == "legacy") { - assertTrue(e.getMessage().contains("Column count doesn't match value count")) - } - if (item == "nereids") { - assertTrue(e.getMessage().contains("insert into cols should be corresponding to the query output")) - } - } } - getRowCount(14) - - // prepare insert with column names, and do schema change - try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name, score) values(?, ?, ?)")) { - ps.setObject(1, 24) - ps.setObject(2, "f") - ps.setObject(3, 90) - ps.addBatch() - int[] result = ps.executeBatch() - logger.info("prepare insert result: " + result) - - sql """ alter table ${table} DROP column age; """ - assertTrue(getAlterTableState(), "drop column should success") - - ps.setObject(1, 25) + } + getRowCount(13) + + // prepare insert without column names, and do schema change + try (PreparedStatement ps = connection.prepareStatement("insert into ${table} values(?, ?, ?)")) { + ps.setObject(1, 22) + ps.setObject(2, "f") + ps.setObject(3, 90) + ps.addBatch() + int[] result = ps.executeBatch() + logger.info("prepare insert result: " + result) + + sql """ alter table ${table} ADD column age int after name; """ + assertTrue(getAlterTableState(), "add column should success") + + try { + ps.setObject(1, 23) ps.setObject(2, "f") ps.setObject(3, 90) ps.addBatch() result = ps.executeBatch() - logger.info("prepare insert result: " + result) + assertTrue(false) + } catch (Exception e) { + logger.info("exception : " + e) + assertTrue(e.getMessage().contains("insert into cols should be corresponding to the query output")) } - getRowCount(16) } - } finally { - // try_sql("DROP TABLE ${table}") + getRowCount(14) + + // prepare insert with column names, and do schema change + try (PreparedStatement ps = connection.prepareStatement("insert into ${table}(id, name, score) values(?, ?, ?)")) { + ps.setObject(1, 24) + ps.setObject(2, "f") + ps.setObject(3, 90) + ps.addBatch() + int[] result = ps.executeBatch() + logger.info("prepare insert result: " + result) + + sql """ alter table ${table} DROP column age; """ + assertTrue(getAlterTableState(), "drop column should success") + + ps.setObject(1, 25) + ps.setObject(2, "f") + ps.setObject(3, 90) + ps.addBatch() + result = ps.executeBatch() + logger.info("prepare insert result: " + result) + } + getRowCount(16) } + } finally { + // try_sql("DROP TABLE ${table}") } + } diff --git a/regression-test/suites/insert_p0/transaction/txn_insert_with_specify_columns.groovy b/regression-test/suites/insert_p0/transaction/txn_insert_with_specify_columns.groovy index 495b84aed788b8d..e7c09d267399bd7 100644 --- a/regression-test/suites/insert_p0/transaction/txn_insert_with_specify_columns.groovy +++ b/regression-test/suites/insert_p0/transaction/txn_insert_with_specify_columns.groovy @@ -65,58 +65,4 @@ suite("txn_insert_with_specify_columns", "p0") { sql """insert into ${table} (c3, c2, c1) values(35, 25, 15);""" sql """commit""" qt_select_unique """select c1,c2,c3 from ${table} order by c1,c2,c3""" - - try { - sql """set enable_nereids_planner=false""" - sql """ DROP TABLE IF EXISTS ${table}""" - sql """ - CREATE TABLE ${table}( - c1 INT NULL, - c2 INT NULL, - c3 INT NULL default 1 - ) ENGINE=OLAP - UNIQUE KEY(c1) - DISTRIBUTED BY HASH(c1) BUCKETS 3 - PROPERTIES ( - "replication_num" = "1" - ); - """ - sql """begin""" - sql """insert into ${table} (c1, c3, c2) values(10, 30, 20);""" - logger.info(failed) - assertFalse(true); - } catch (Exception e) { - logger.info(e.getMessage()) - assertTrue(e.getMessage().contains("The legacy planner does not support specifying column names")) - } finally { - sql "commit" - sql """ DROP TABLE IF EXISTS ${table}""" - } - - try { - sql """set enable_nereids_planner=false""" - sql """ DROP TABLE IF EXISTS ${table}""" - sql """ - CREATE TABLE ${table}( - c1 INT NULL, - c2 INT NULL, - c3 INT NULL default 1 - ) ENGINE=OLAP - DUPLICATE KEY(c1) - DISTRIBUTED BY HASH(c1) BUCKETS 3 - PROPERTIES ( - "replication_num" = "1" - ); - """ - sql """begin""" - sql """insert into ${table} (c1, c3, c2) values(10, 30, 20);""" - logger.info(failed) - assertFalse(true); - } catch (Exception e) { - logger.info(e.getMessage()) - assertTrue(e.getMessage().contains("The legacy planner does not support specifying column names")) - } finally { - sql "commit" - sql """ DROP TABLE IF EXISTS ${table}""" - } } diff --git a/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy b/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy index 46f61f63fd750f0..cb1b8f4262a1c8b 100644 --- a/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy +++ b/regression-test/suites/jsonb_p0/test_jsonb_load_and_function.groovy @@ -532,15 +532,6 @@ suite("test_jsonb_load_and_function", "p0") { qt_select_json_contains """SELECT id, j, json_contains(j, cast('{"k2":300}' as json)) FROM ${testTable} ORDER BY id""" qt_select_json_contains """SELECT id, j, json_contains(j, cast('{"k1":"v41","k2":400}' as json), '\$.a1') FROM ${testTable} ORDER BY id""" qt_select_json_contains """SELECT id, j, json_contains(j, cast('[123,456]' as json)) FROM ${testTable} ORDER BY id""" - // old planner do not support explode_json_object - test { - sql """ select /*+SET_VAR(experimental_enable_nereids_planner=false)*/ id, j, k,v from ${testTable} lateral view explode_json_object_outer(j) tmp as k,v order by id; """ - exception "errCode = 2" - } - test { - sql """ select /*+SET_VAR(experimental_enable_nereids_planner=false)*/ id, j, k,v from ${testTable} lateral view explode_json_object_outer(j) tmp as k,v order by id; """ - exception "errCode = 2" - } // json_parse qt_sql_json_parse """SELECT/*+SET_VAR(enable_fold_constant_by_be=false)*/ json_parse('{"":"v1"}')""" diff --git a/regression-test/suites/nereids_rules_p0/grouping_sets/valid_grouping.groovy b/regression-test/suites/nereids_rules_p0/grouping_sets/valid_grouping.groovy deleted file mode 100644 index 624fc7e9f159ccb..000000000000000 --- a/regression-test/suites/nereids_rules_p0/grouping_sets/valid_grouping.groovy +++ /dev/null @@ -1,54 +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. - -suite("valid_grouping"){ - - // this suite test legacy planner - sql "set enable_nereids_planner=false" - - sql "drop table if exists valid_grouping" - sql """ - CREATE TABLE `valid_grouping` ( - `a` INT NULL, - `b` VARCHAR(10) NULL, - `c` INT NULL, - `d` INT NULL - ) ENGINE=OLAP - DUPLICATE KEY(`a`, `b`) - DISTRIBUTED BY RANDOM BUCKETS AUTO - PROPERTIES ( - "replication_allocation" = "tag.location.default: 1" - ); - """ - sql "insert into valid_grouping values(1,'d2',3,5);" - test { - sql """select - b, 'day' as DT_TYPE - from valid_grouping - group by grouping sets ( (grouping_id(b)),(b));""" - exception("GROUP BY expression must not contain grouping scalar functions: grouping_id(`b`)") - } - - test { - sql """select - b, 'day' as DT_TYPE - from valid_grouping - group by grouping sets ( (grouping(b)),(b));""" - exception("GROUP BY expression must not contain grouping scalar functions: grouping(`b`)") - } - -} \ No newline at end of file diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy index c6f122e3c8735b8..b0e13260aa24935 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/test_date_function_prune.groovy @@ -18,10 +18,8 @@ suite("test_date_function_prune") { String db = context.config.getDbNameByFile(context.file) sql "use ${db}" - sql "SET enable_nereids_planner=true" - sql "set runtime_filter_mode=OFF"; + sql "set runtime_filter_mode=OFF" sql "SET ignore_shape_nodes='PhysicalDistribute,PhysicalProject'" - sql "SET enable_fallback_to_original_planner=false" sql "set partition_pruning_expand_threshold=10;" sql "drop table if exists dp" sql """ @@ -105,19 +103,11 @@ suite("test_date_function_prune") { DISTRIBUTED BY HASH(event_day) BUCKETS 4 PROPERTIES("replication_num" = "1"); """ - explain { - sql """ select /*+ SET_VAR(enable_nereids_planner=false) */ * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ - contains("partitions=0/2") - } explain { sql """ select * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ contains("VEMPTYSET") } sql """ insert into test_to_date_trunc values ("20230807000000"); """ - explain { - sql """ select /*+ SET_VAR(enable_nereids_planner=false) */ * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ - contains("partitions=1/2 (p20230807)") - } explain { sql """ select * from test_to_date_trunc where date_trunc(event_day, "day")= "2023-08-07 11:00:00" """ contains("partitions=1/2 (p20230807)") diff --git a/regression-test/suites/query_p0/dual/dual.groovy b/regression-test/suites/query_p0/dual/dual.groovy index eb001305b47e61f..964ca49f3ab2c1a 100644 --- a/regression-test/suites/query_p0/dual/dual.groovy +++ b/regression-test/suites/query_p0/dual/dual.groovy @@ -73,14 +73,6 @@ suite('dual') { exception "Table [dual] does not exist in database [regression_test_query_p0_dual]" } - // Disable and enable Nereids planner to check behavior differences - sql "set enable_nereids_planner = false" - test { - sql "select 1 from `dual`" - exception "Unknown table 'dual'" - } - sql "set enable_nereids_planner = true" - // Tests for unknown column errors test { sql "select a from dual" diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy index afc88acd65128c6..b48afb358c92fc4 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy @@ -405,41 +405,28 @@ suite("test_array_functions_by_literal") { qt_sql "select array_cum_sum(array(cast (11.9999 as decimalv3(6,4)),cast (22.0001 as decimalv3(6,4))))" // abnormal test - try { + test { sql "select array_intersect([1, 2, 3, 1, 2, 3], '1[3, 2, 5]')" - } catch (Exception ex) { - assert("${ex}".contains("errCode = 2, detailMessage = No matching function with signature: array_intersect")) + exception "Can not find the compatibility function signature: array_intersect" } // array_min/max with nested array for args test { sql "select array_min(array(1,2,3),array(4,5,6));" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } + exception "" } test { sql "select array_max(array(1,2,3),array(4,5,6));" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } + exception "" } test { sql "select array_min(array(split_by_string('a,b,c',',')));" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } + exception "" } test { sql "select array_max(array(split_by_string('a,b,c',',')));" - check{result, exception, startTime, endTime -> - assertTrue(exception != null) - logger.info(exception.message) - } + exception "" } // array_map with string is can be succeed @@ -448,6 +435,6 @@ suite("test_array_functions_by_literal") { // array_apply with string should be failed test { sql """select array_apply(split_by_string("amory,is,better,committing", ","), '!=', '');""" - exception("No matching function") + exception("array_apply does not support type") } } diff --git a/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_map_function.groovy b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_map_function.groovy index d412e0d8f3741d0..14fa8ee4b142a10 100644 --- a/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_map_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/cast_function/test_cast_map_function.groovy @@ -16,7 +16,6 @@ // under the License. suite("test_cast_map_function", "query") { - sql """set enable_nereids_planner = false """ def tableName = "tbl_test_cast_map_function" // array functions only supported in vectorized engine diff --git a/regression-test/suites/show_p0/test_show_create_table_and_views.groovy b/regression-test/suites/show_p0/test_show_create_table_and_views.groovy deleted file mode 100644 index 8b087adc4ab9227..000000000000000 --- a/regression-test/suites/show_p0/test_show_create_table_and_views.groovy +++ /dev/null @@ -1,150 +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. - -import org.apache.doris.regression.util.JdbcUtils - -suite("test_show_create_table_and_views", "show") { - sql "SET enable_nereids_planner=false;" - - def shouldNotShowHiddenColumnsAndCreateWithHiddenColumns = { - connect { - multi_sql """ - SET enable_nereids_planner=false; - drop table if exists test_show_create_table_no_hidden_column; - create table test_show_create_table_no_hidden_column(id int, name varchar(50)) unique key(id) distributed by hash(id) properties('replication_num'='1'); - set show_hidden_columns=true; - """ - - def result = JdbcUtils.executeToMapArray(context.getConnection(), "show create table test_show_create_table_no_hidden_column") - assertTrue(!result[0].get("Create Table").toString().contains("__DORIS_DELETE_SIGN__")) - - test { - sql "create table table_with_hidden_sign(id int, __DORIS_DELETE_SIGN__ int) distributed by hash(id) properties('replication_num'='1')" - exception "Disable to create table column with name start with __DORIS_: " - } - } - }() - - def ret = sql "SHOW FRONTEND CONFIG like '%enable_feature_binlog%';" - logger.info("${ret}") - if (ret.size() != 0 && ret[0].size() > 1 && ret[0][1] == 'false') { - logger.info("enable_feature_binlog=false in frontend config, no need to run this case.") - return - } - - String suiteName = "show_create_table_and_views" - String dbName = "${suiteName}_db" - String tableName = "${suiteName}_table" - String viewName = "${suiteName}_view" - String rollupName = "${suiteName}_rollup" - String likeName = "${suiteName}_like" - - sql "CREATE DATABASE IF NOT EXISTS ${dbName}" - sql "DROP TABLE IF EXISTS ${dbName}.${tableName}" - sql """ - CREATE TABLE ${dbName}.${tableName} ( - `user_id` LARGEINT NOT NULL, - `good_id` LARGEINT NOT NULL, - `cost` BIGINT SUM DEFAULT "0", - INDEX index_user_id (`user_id`) USING INVERTED COMMENT 'test index comment', - INDEX index_good_id (`good_id`) USING INVERTED COMMENT 'test index" comment' - ) - AGGREGATE KEY(`user_id`, `good_id`) - PARTITION BY RANGE(`good_id`) - ( - PARTITION p1 VALUES LESS THAN ("100"), - PARTITION p2 VALUES LESS THAN ("200"), - PARTITION p3 VALUES LESS THAN ("300"), - PARTITION p4 VALUES LESS THAN ("400"), - PARTITION p5 VALUES LESS THAN ("500"), - PARTITION p6 VALUES LESS THAN ("600"), - PARTITION p7 VALUES LESS THAN MAXVALUE - ) - DISTRIBUTED BY HASH(`user_id`) BUCKETS 2 - PROPERTIES ( - "replication_num" = "1" - ) - """ - - sql """INSERT INTO ${dbName}.${tableName} VALUES - (1, 1, 10), - (1, 1, 20), - (1, 2, 5), - (1, 3, 10), - (2, 1, 0), - (2, 1, 100), - (3, 1, 10), - (2, 2, 10), - (2, 3, 44), - (3, 2, 1), - (100, 100, 1), - (200, 20, 1), - (300, 20, 1), - (1, 300, 2), - (2, 200, 1111), - (23, 900, 1)""" - - qt_show "SHOW CREATE TABLE ${dbName}.${tableName}" - qt_select "SELECT * FROM ${dbName}.${tableName} ORDER BY user_id, good_id" - - sql "drop view if exists ${dbName}.${viewName};" - // create view and show - sql """ - CREATE VIEW IF NOT EXISTS ${dbName}.${viewName} (user_id, cost) - AS - SELECT user_id, cost FROM ${dbName}.${tableName} - WHERE good_id = 2 - """ - qt_select "SELECT * FROM ${dbName}.${viewName} ORDER BY user_id" - qt_show "SHOW CREATE VIEW ${dbName}.${viewName}" - - // create rollup - sql """ALTER TABLE ${dbName}.${tableName} - ADD ROLLUP ${rollupName} (user_id, cost) - """ - - def isAlterTableFinish = { -> - def records = sql """SHOW ALTER TABLE ROLLUP FROM ${dbName}""" - for (def row in records) { - if (row[5] == "${rollupName}" && row[8] == "FINISHED") { - return true - } - } - false - } - while (!isAlterTableFinish()) { - Thread.sleep(100) - } - - qt_select "SELECT user_id, SUM(cost) FROM ${dbName}.${tableName} GROUP BY user_id ORDER BY user_id" - qt_show "SHOW CREATE TABLE ${dbName}.${tableName}" - - // create like - sql "CREATE TABLE ${dbName}.${likeName} LIKE ${dbName}.${tableName}" - qt_show "SHOW CREATE TABLE ${dbName}.${likeName}" - - // create like with rollup - sql "CREATE TABLE ${dbName}.${likeName}_with_rollup LIKE ${dbName}.${tableName} WITH ROLLUP" - qt_show "SHOW CREATE TABLE ${dbName}.${likeName}_with_rollup" - - sql "DROP TABLE IF EXISTS ${dbName}.${likeName}_with_rollup FORCE" - sql "DROP TABLE ${dbName}.${likeName} FORCE" - sql "DROP VIEW ${dbName}.${viewName}" - sql "DROP TABLE ${dbName}.${tableName} FORCE" - sql "DROP DATABASE ${dbName} FORCE" -} - diff --git a/regression-test/suites/unique_with_mow_c_p0/test_create_table.groovy b/regression-test/suites/unique_with_mow_c_p0/test_create_table.groovy index 8cd7cb6d19874b1..94cff68c8cfc11b 100644 --- a/regression-test/suites/unique_with_mow_c_p0/test_create_table.groovy +++ b/regression-test/suites/unique_with_mow_c_p0/test_create_table.groovy @@ -184,27 +184,6 @@ suite("test_create_table") { ); """ - // test legacy planner - sql """set enable_nereids_planner=false;""" - // duplicate table with cluster keys - test { - sql """ - CREATE TABLE `$tableName` ( - `c_custkey` int(11) NOT NULL COMMENT "", - `c_name` varchar(26) NOT NULL COMMENT "", - `c_address` varchar(41) NOT NULL COMMENT "", - `c_city` varchar(11) NOT NULL COMMENT "" - ) - DUPLICATE KEY (`c_custkey`) - CLUSTER BY (`c_name`, `c_address`) - DISTRIBUTED BY HASH(`c_custkey`) BUCKETS 1 - PROPERTIES ( - "replication_num" = "1" - ); - """ - exception "Syntax error" - } - // test nereids planner sql """set enable_nereids_planner=true;""" sql """set enable_nereids_dml=true;""" diff --git a/regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy b/regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy index 7b047136e336179..ce490063bcf1286 100644 --- a/regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy +++ b/regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy @@ -16,7 +16,6 @@ // under the License. suite("create_view_star_except_and_cast_to_sql") { - sql "SET enable_nereids_planner=false;" sql """ DROP TABLE IF EXISTS mal_old_create_view """