[opt](Nereids) support all syntax to avoid fallback in multi-statement query (#41811)

This commit is contained in:
morrySnow
2024-10-17 12:42:01 +08:00
committed by GitHub
parent 5736dc537c
commit 3ff67350d0
4 changed files with 858 additions and 151 deletions

View File

@ -64,6 +64,7 @@ LEFT_PAREN: '(';
RIGHT_PAREN: ')';
COMMA: ',';
DOT: '.';
DOTDOTDOT: '...';
LEFT_BRACKET: '[';
RIGHT_BRACKET: ']';
LEFT_BRACE: '{';
@ -77,6 +78,7 @@ RIGHT_BRACE: '}';
//--DORIS-KEYWORD-LIST-START
ACCOUNT_LOCK: 'ACCOUNT_LOCK';
ACCOUNT_UNLOCK: 'ACCOUNT_UNLOCK';
ACTIONS: 'ACTIONS';
ADD: 'ADD';
ADDDATE:'ADDDATE';
ADMIN: 'ADMIN';
@ -151,6 +153,7 @@ COMMITTED: 'COMMITTED';
COMPACT: 'COMPACT';
COMPLETE: 'COMPLETE';
COMPRESS_TYPE: 'COMPRESS_TYPE';
CONDITIONS: 'CONDITIONS';
CONFIG: 'CONFIG';
CONNECTION: 'CONNECTION';
CONNECTION_ID: 'CONNECTION_ID';
@ -158,7 +161,7 @@ CONSISTENT: 'CONSISTENT';
CONSTRAINT: 'CONSTRAINT';
CONSTRAINTS: 'CONSTRAINTS';
CONVERT: 'CONVERT';
CONVERT_LSC: 'CONVERT_LSC';
CONVERT_LSC: 'CONVERT_LIGHT_SCHEMA_CHANGE_PROCESS';
COPY: 'COPY';
COUNT: 'COUNT';
CREATE: 'CREATE';
@ -202,6 +205,7 @@ DEMAND: 'DEMAND';
DESC: 'DESC';
DESCRIBE: 'DESCRIBE';
DIAGNOSE: 'DIAGNOSE';
DIAGNOSIS: 'DIAGNOSIS';
DISK: 'DISK';
DISTINCT: 'DISTINCT';
DISTINCTPC: 'DISTINCTPC';
@ -469,6 +473,7 @@ SERIALIZABLE: 'SERIALIZABLE';
SESSION: 'SESSION';
SET: 'SET';
SETS: 'SETS';
SET_SESSION_VARIABLE: 'SET_SESSION_VARIABLE';
SHAPE: 'SHAPE';
SHOW: 'SHOW';
SIGNED: 'SIGNED';
@ -530,6 +535,7 @@ UNINSTALL: 'UNINSTALL';
UNION: 'UNION';
UNIQUE: 'UNIQUE';
UNLOCK: 'UNLOCK';
UNSET: 'UNSET';
UNSIGNED: 'UNSIGNED';
UP: 'UP';
UPDATE: 'UPDATE';
@ -539,11 +545,13 @@ USING: 'USING';
VALUE: 'VALUE';
VALUES: 'VALUES';
VARCHAR: 'VARCHAR';
VARIABLE: 'VARIABLE';
VARIABLES: 'VARIABLES';
VARIANT: 'VARIANT';
VERBOSE: 'VERBOSE';
VERSION: 'VERSION';
VIEW: 'VIEW';
VIEWS: 'VIEWS';
WARM: 'WARM';
WARNINGS: 'WARNINGS';
WEEK: 'WEEK';

View File

@ -73,7 +73,6 @@ import org.apache.doris.nereids.DorisParser.ComplexColTypeContext;
import org.apache.doris.nereids.DorisParser.ComplexColTypeListContext;
import org.apache.doris.nereids.DorisParser.ComplexDataTypeContext;
import org.apache.doris.nereids.DorisParser.ConstantContext;
import org.apache.doris.nereids.DorisParser.ConstantSeqContext;
import org.apache.doris.nereids.DorisParser.CreateMTMVContext;
import org.apache.doris.nereids.DorisParser.CreateProcedureContext;
import org.apache.doris.nereids.DorisParser.CreateRowPolicyContext;
@ -81,6 +80,7 @@ import org.apache.doris.nereids.DorisParser.CreateTableContext;
import org.apache.doris.nereids.DorisParser.CreateTableLikeContext;
import org.apache.doris.nereids.DorisParser.CreateViewContext;
import org.apache.doris.nereids.DorisParser.CteContext;
import org.apache.doris.nereids.DorisParser.DataTypeContext;
import org.apache.doris.nereids.DorisParser.DataTypeWithNullableContext;
import org.apache.doris.nereids.DorisParser.DateCeilContext;
import org.apache.doris.nereids.DorisParser.DateFloorContext;
@ -135,6 +135,7 @@ import org.apache.doris.nereids.DorisParser.OutFileClauseContext;
import org.apache.doris.nereids.DorisParser.ParenthesizedExpressionContext;
import org.apache.doris.nereids.DorisParser.PartitionSpecContext;
import org.apache.doris.nereids.DorisParser.PartitionValueDefContext;
import org.apache.doris.nereids.DorisParser.PartitionValueListContext;
import org.apache.doris.nereids.DorisParser.PartitionsDefContext;
import org.apache.doris.nereids.DorisParser.PauseMTMVContext;
import org.apache.doris.nereids.DorisParser.PlanTypeContext;
@ -788,7 +789,11 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
}
@Override
public DropMTMVCommand visitDropMTMV(DropMTMVContext ctx) {
public Command visitDropMTMV(DropMTMVContext ctx) {
if (ctx.tableName != null) {
// TODO support drop sync mv
return new UnsupportedCommand();
}
List<String> nameParts = visitMultipartIdentifier(ctx.mvName);
return new DropMTMVCommand(new DropMTMVInfo(new TableNameInfo(nameParts), ctx.EXISTS() != null));
}
@ -1091,7 +1096,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
: LoadTask.MergeType.valueOf(ddc.mergeType().getText());
Optional<String> fileFormat = ddc.format == null ? Optional.empty()
: Optional.of(visitIdentifierOrStringLiteral(ddc.format));
: Optional.of(visitIdentifierOrText(ddc.format));
Optional<String> separator = ddc.separator == null ? Optional.empty() : Optional.of(ddc.separator.getText()
.substring(1, ddc.separator.getText().length() - 1));
Optional<String> comma = ddc.comma == null ? Optional.empty() : Optional.of(ddc.comma.getText()
@ -1115,7 +1120,10 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
: Optional.of(ddc.sequenceColumn.identifier().getText()), dataProperties));
}
String labelName = ctx.lableName.getText();
Map<String, String> properties = visitPropertyItemList(ctx.properties);
Map<String, String> properties = Collections.emptyMap();
if (ctx.propertyClause() != null) {
properties = visitPropertyItemList(ctx.propertyClause().propertyItemList());
}
String commentSpec = ctx.commentSpec() == null ? "''" : ctx.commentSpec().STRING_LITERAL().getText();
String comment =
LogicalPlanBuilderAssistant.escapeBackSlash(commentSpec.substring(1, commentSpec.length() - 1));
@ -1191,15 +1199,6 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
@Override
public String visitIdentifierOrText(IdentifierOrTextContext ctx) {
if (ctx.STRING_LITERAL() != null) {
return ctx.STRING_LITERAL().getText().substring(1, ctx.STRING_LITERAL().getText().length() - 1);
} else {
return ctx.errorCapturingIdentifier().getText();
}
}
@Override
public String visitIdentifierOrStringLiteral(DorisParser.IdentifierOrStringLiteralContext ctx) {
if (ctx.STRING_LITERAL() != null) {
return ctx.STRING_LITERAL().getText().substring(1, ctx.STRING_LITERAL().getText().length() - 1);
} else {
@ -2040,11 +2039,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
@Override
public Expression visitCast(DorisParser.CastContext ctx) {
return ParserUtils.withOrigin(ctx, () -> {
DataType dataType = ((DataType) typedVisit(ctx.dataType())).conversion();
Expression cast = new Cast(getExpression(ctx.expression()), dataType, true);
return processCast(cast, dataType);
});
return ParserUtils.withOrigin(ctx, () -> processCast(getExpression(ctx.expression()), ctx.dataType()));
}
@Override
@ -2085,14 +2080,13 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
@Override
public Expression visitConvertType(DorisParser.ConvertTypeContext ctx) {
return ParserUtils.withOrigin(ctx, () -> {
DataType dataType = ((DataType) typedVisit(ctx.type)).conversion();
Expression cast = new Cast(getExpression(ctx.argument), dataType, true);
return processCast(cast, dataType);
});
return ParserUtils.withOrigin(ctx, () -> processCast(getExpression(ctx.expression()), ctx.dataType()));
}
private Expression processCast(Expression cast, DataType dataType) {
private Expression processCast(Expression expression, DataTypeContext dataTypeCtx) {
DataType dataType = typedVisit(dataTypeCtx);
dataType = dataType.conversion();
Expression cast = new Cast(expression, dataType, true);
if (dataType.isStringLikeType() && ((CharacterType) dataType).getLen() >= 0) {
if (dataType.isVarcharType() && ((VarcharType) dataType).isWildcardVarchar()) {
return cast;
@ -2783,7 +2777,7 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
public PartitionDefinition visitLessThanPartitionDef(LessThanPartitionDefContext ctx) {
String partitionName = ctx.partitionName.getText();
if (ctx.MAXVALUE() == null) {
List<Expression> lessThanValues = visitConstantSeq(ctx.constantSeq());
List<Expression> lessThanValues = visitPartitionValueList(ctx.partitionValueList());
return new LessThanPartition(ctx.EXISTS() != null, partitionName, lessThanValues);
} else {
return new LessThanPartition(ctx.EXISTS() != null, partitionName,
@ -2794,15 +2788,15 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
@Override
public PartitionDefinition visitFixedPartitionDef(FixedPartitionDefContext ctx) {
String partitionName = ctx.partitionName.getText();
List<Expression> lowerBounds = visitConstantSeq(ctx.lower);
List<Expression> upperBounds = visitConstantSeq(ctx.upper);
List<Expression> lowerBounds = visitPartitionValueList(ctx.lower);
List<Expression> upperBounds = visitPartitionValueList(ctx.upper);
return new FixedRangePartition(ctx.EXISTS() != null, partitionName, lowerBounds, upperBounds);
}
@Override
public PartitionDefinition visitStepPartitionDef(StepPartitionDefContext ctx) {
List<Expression> fromExpression = visitConstantSeq(ctx.from);
List<Expression> toExpression = visitConstantSeq(ctx.to);
List<Expression> fromExpression = visitPartitionValueList(ctx.from);
List<Expression> toExpression = visitPartitionValueList(ctx.to);
return new StepPartition(false, null, fromExpression, toExpression,
Long.parseLong(ctx.unitsAmount.getText()), ctx.unit != null ? ctx.unit.getText() : null);
}
@ -2811,17 +2805,17 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
public PartitionDefinition visitInPartitionDef(InPartitionDefContext ctx) {
List<List<Expression>> values;
if (ctx.constants == null) {
values = ctx.constantSeqs.stream().map(this::visitConstantSeq)
values = ctx.partitionValueLists.stream().map(this::visitPartitionValueList)
.collect(Collectors.toList());
} else {
values = visitConstantSeq(ctx.constants).stream().map(ImmutableList::of)
values = visitPartitionValueList(ctx.constants).stream().map(ImmutableList::of)
.collect(Collectors.toList());
}
return new InPartition(ctx.EXISTS() != null, ctx.partitionName.getText(), values);
}
@Override
public List<Expression> visitConstantSeq(ConstantSeqContext ctx) {
public List<Expression> visitPartitionValueList(PartitionValueListContext ctx) {
return ctx.values.stream()
.map(this::visitPartitionValueDef)
.collect(Collectors.toList());

View File

@ -149,6 +149,7 @@ import org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand;
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.insert.BatchInsertIntoTableCommand;
import org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTableCommand;
import org.apache.doris.nereids.trees.plans.commands.insert.InsertOverwriteTableCommand;
@ -670,7 +671,8 @@ public class StmtExecutor {
// when we in transaction mode, we only support insert into command and transaction command
if (context.isTxnModel()) {
if (!(logicalPlan instanceof BatchInsertIntoTableCommand
|| logicalPlan instanceof InsertIntoTableCommand)) {
|| logicalPlan instanceof InsertIntoTableCommand
|| logicalPlan instanceof UnsupportedCommand)) {
String errMsg = "This is in a transaction, only insert, commit, rollback is acceptable.";
throw new NereidsException(errMsg, new AnalysisException(errMsg));
}