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/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 d42e2e828aed7ed..6ede4d568878fca 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 @@ -1302,8 +1302,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) @@ -2241,8 +2240,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(); @@ -3315,19 +3312,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 @@ -3423,7 +3407,7 @@ public void setNereidsCboPenaltyFactor(double penaltyFactor) { } public boolean isEnableNereidsTrace() { - return isEnableNereidsPlanner() && enableNereidsTrace; + return enableNereidsTrace; } public void setEnableExprTrace(boolean enableExprTrace) { @@ -3659,7 +3643,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); @@ -4068,18 +4052,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"))); } @@ -4311,7 +4284,7 @@ public int getCreateTablePartitionMaxNum() { } public boolean isIgnoreStorageDataDistribution() { - return ignoreStorageDataDistribution && enableLocalShuffle && enableNereidsPlanner; + return ignoreStorageDataDistribution && enableLocalShuffle; } public void setIgnoreStorageDataDistribution(boolean ignoreStorageDataDistribution) { @@ -4349,7 +4322,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..8272f141b1bd2b4 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) { @@ -3313,7 +3294,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 +3302,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 +3492,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 fd8d6fc2bf59772..1053adef19f9bed 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/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/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/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/policy/PolicyTest.java b/fe/fe-core/src/test/java/org/apache/doris/policy/PolicyTest.java index aa04c14bbe9c6ba..2db3154dd4f0bf5 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 @@ -169,8 +169,6 @@ public void testAliasSql() throws Exception { @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,7 +177,6 @@ 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 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