This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 9386af4266ebd0b1b1133e3e8d593d897cf015b1 Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Fri Aug 23 10:57:51 2024 +0800 [opt](Nereids) support alter statement syntax in Nereids (#39709) --- .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 141 +++++++++++++++++++-- .../doris/analysis/AlterCatalogCommentStmt.java | 2 +- .../doris/analysis/AlterCatalogNameStmt.java | 2 +- .../doris/analysis/AlterCatalogPropertyStmt.java | 2 +- .../doris/analysis/AlterColocateGroupStmt.java | 2 +- .../doris/analysis/AlterColumnStatsStmt.java | 2 +- .../doris/analysis/AlterDatabasePropertyStmt.java | 2 +- .../doris/analysis/AlterDatabaseQuotaStmt.java | 2 +- .../apache/doris/analysis/AlterDatabaseRename.java | 2 +- .../org/apache/doris/analysis/AlterPolicyStmt.java | 2 +- .../apache/doris/analysis/AlterRepositoryStmt.java | 2 +- .../apache/doris/analysis/AlterResourceStmt.java | 2 +- .../doris/analysis/AlterRoutineLoadStmt.java | 2 +- .../doris/analysis/AlterSqlBlockRuleStmt.java | 2 +- .../org/apache/doris/analysis/AlterSystemStmt.java | 2 +- .../apache/doris/analysis/AlterTableStatsStmt.java | 2 +- .../org/apache/doris/analysis/AlterTableStmt.java | 2 +- .../org/apache/doris/analysis/AlterUserStmt.java | 2 +- .../doris/analysis/AlterWorkloadGroupStmt.java | 2 +- .../analysis/AlterWorkloadSchedPolicyStmt.java | 2 +- .../doris/nereids/parser/LogicalPlanBuilder.java | 18 +-- .../trees/plans/commands/CreatePolicyCommand.java | 5 +- .../java/org/apache/doris/qe/StmtExecutor.java | 8 +- .../suites/prepared_stmt_p0/prepared_stmt.groovy | 56 ++++---- .../schema_change_p0/test_new_schema_change.groovy | 9 +- 25 files changed, 202 insertions(+), 73 deletions(-) diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 0135bcb58af..ab316cf2794 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -63,6 +63,7 @@ unsupportedStatement | unsupportedCreateStatement | unsupportedDropStatement | unsupportedStatsStatement + | unsupportedAlterStatement ; materailizedViewStatement @@ -166,6 +167,125 @@ supportedDropStatement : DROP CATALOG RECYCLE BIN WHERE idType=STRING_LITERAL EQ id=INTEGER_VALUE #dropCatalogRecycleBin ; +unsupportedAlterStatement + : ALTER TABLE tableName=multipartIdentifier + alterTableClause (COMMA alterTableClause)* #alterTable + | ALTER TABLE tableName=multipartIdentifier ADD ROLLUP + addRollupClause (COMMA addRollupClause)* #alterTableAddRollup + | ALTER TABLE tableName=multipartIdentifier DROP ROLLUP + dropRollupClause (COMMA dropRollupClause)* #alterTableDropRollup + | ALTER SYSTEM alterSystemClause #alterSystem + | ALTER DATABASE name=identifier SET (DATA |REPLICA | TRANSACTION) + QUOTA INTEGER_VALUE identifier? #alterDatabaseSetQuota + | ALTER DATABASE name=identifier RENAME newName=identifier #alterDatabaseRename + | ALTER DATABASE name=identifier SET PROPERTIES + LEFT_PAREN propertyItemList RIGHT_PAREN #alterDatabaseProperties + | ALTER CATALOG name=identifier RENAME newName=identifier #alterCatalogRename + | ALTER CATALOG name=identifier SET PROPERTIES + LEFT_PAREN propertyItemList RIGHT_PAREN #alterCatalogProperties + | ALTER CATALOG name=identifier MODIFY COMMENT comment=STRING_LITERAL #alterCatalogComment + | ALTER RESOURCE name=identifierOrText properties=propertyClause? #alterResource + | ALTER COLOCATE GROUP name=multipartIdentifier + SET LEFT_PAREN propertyItemList RIGHT_PAREN #alterColocateGroup + | ALTER WORKLOAD GROUP name=identifierOrText properties=propertyClause? #alterWorkloadGroup + | ALTER WORKLOAD POLICY name=identifierOrText properties=propertyClause? #alterWorkloadPolicy + | ALTER ROUTINE LOAD FOR name=multipartIdentifier properties=propertyClause? + (FROM type=identifier LEFT_PAREN propertyItemList RIGHT_PAREN)? #alterRoutineLoad + | ALTER SQL_BLOCK_RULE name=identifier properties=propertyClause? #alterSqlBlockRule + | ALTER TABLE name=multipartIdentifier + SET LEFT_PAREN propertyItemList RIGHT_PAREN #alterTableProperties + | ALTER STORAGE POLICY name=identifierOrText properties=propertyClause #alterStoragePlicy + | ALTER USER (IF EXISTS)? grantUserIdentify + passwordOption (COMMENT STRING_LITERAL)? #alterUser + | ALTER REPOSITORY name=identifier properties=propertyClause? #alterRepository + ; + +alterSystemClause + : ADD BACKEND hostPorts+=STRING_LITERAL (COMMA hostPorts+=STRING_LITERAL)* + properties=propertyClause? #addBackendClause + | (DROP | DROPP) BACKEND hostPorts+=STRING_LITERAL + (COMMA hostPorts+=STRING_LITERAL)* #dropBackendClause + | DECOMMISSION BACKEND hostPorts+=STRING_LITERAL + (COMMA hostPorts+=STRING_LITERAL)* #decommissionBackendClause + | ADD OBSERVER hostPort=STRING_LITERAL #addObserverClause + | DROP OBSERVER hostPort=STRING_LITERAL #dropObserverClause + | ADD FOLLOWER hostPort=STRING_LITERAL #addFollowerClause + | DROP FOLLOWER hostPort=STRING_LITERAL #dropFollowerClause + | ADD BROKER name=identifierOrText hostPorts+=STRING_LITERAL + (COMMA hostPorts+=STRING_LITERAL)* #addBrokerClause + | DROP BROKER name=identifierOrText hostPorts+=STRING_LITERAL + (COMMA hostPorts+=STRING_LITERAL)* #dropBrokerClause + | DROP ALL BROKER name=identifierOrText #dropAllBrokerClause + | SET LOAD ERRORS HUB properties=propertyClause? #alterLoadErrorUrlClause + | MODIFY BACKEND hostPorts+=STRING_LITERAL + (COMMA hostPorts+=STRING_LITERAL)* + SET LEFT_PAREN propertyItemList RIGHT_PAREN #modifyBackendClause + | MODIFY (FRONTEND | BACKEND) hostPort=STRING_LITERAL + HOSTNAME hostName=STRING_LITERAL #modifyFrontendOrBackendHostNameClause + ; + +dropRollupClause + : rollupName=identifier properties=propertyClause? + ; + +addRollupClause + : rollupName=identifier columns=identifierList + (DUPLICATE KEY dupKeys=identifierList)? fromRollup? + properties=propertyClause? + ; + +alterTableClause + : ADD COLUMN columnDef columnPosition? toRollup? properties=propertyClause? #addColumnClause + | ADD COLUMN LEFT_PAREN columnDef (COMMA columnDef) RIGHT_PAREN + toRollup? properties=propertyClause? #addColumnsClause + | DROP COLUMN name=identifier fromRollup? properties=propertyClause? #dropColumnClause + | MODIFY COLUMN columnDef columnPosition? fromRollup? + properties=propertyClause? #modifyColumnClause + | ORDER BY identifierList fromRollup? properties=propertyClause? #reorderColumnsClause + | ADD TEMPORARY? (lessThanPartitionDef | fixedPartitionDef | inPartitionDef) + (LEFT_PAREN partitionProperties=propertyItemList RIGHT_PAREN)? + (DISTRIBUTED BY (HASH hashKeys=identifierList | RANDOM) + (BUCKETS (INTEGER_VALUE | autoBucket=AUTO))?)? + properties=propertyClause? #addPartitionClause + | DROP TEMPORARY? PARTITION (IF EXISTS)? partitionName=identifier FORCE? + (FROM INDEX indexName=identifier)? #dropPartitionClause + | MODIFY TEMPORARY? PARTITION (IF EXISTS)? + (partitionName=identifier | partitionNames=identifierList + | LEFT_PAREN ASTERISK RIGHT_PAREN) + SET LEFT_PAREN partitionProperties=propertyItemList RIGHT_PAREN #modifyPartitionClause + | REPLACE partitions=partitionSpec? WITH tempPartitions=partitionSpec? + FORCE? properties=propertyClause? #replacePartitionClause + | REPLACE WITH TABLE name=identifier properties=propertyClause? #replaceTableClause + | RENAME newName=identifier #renameClause + | RENAME ROLLUP name=identifier newName=identifier #renameRollupClause + | RENAME PARTITION name=identifier newName=identifier #renamePartitionClause + | RENAME COLUMN name=identifier newName=identifier #renameColumnClause + | ADD indexDef #addIndexClause + | DROP INDEX (IF EXISTS)? name=identifier #dropIndexClause + | ENABLE FEATURE name=STRING_LITERAL (WITH properties=propertyClause)? #enableFeatureClause + | MODIFY DISTRIBUTION (DISTRIBUTED BY (HASH hashKeys=identifierList | RANDOM) + (BUCKETS (INTEGER_VALUE | autoBucket=AUTO))?)? #modifyDistributionClause + | MODIFY COMMENT comment=STRING_LITERAL #modifyTableCommentClause + | MODIFY COLUMN name=identifier COMMENT comment=STRING_LITERAL #modifyColumnCommentClause + | MODIFY ENGINE TO name=identifier properties=propertyClause? #modifyEngineClause + | ADD TEMPORARY? PARTITIONS + FROM from=partitionValueList TO to=partitionValueList + INTERVAL INTEGER_VALUE unit=identifier? properties=propertyClause? #alterMultiPartitionClause + ; + +columnPosition + : FIRST + | AFTER position=identifier + ; + +toRollup + : (TO | IN) rollup=identifier + ; + +fromRollup + : FROM rollup=identifier + ; + unsupportedDropStatement : DROP (DATABASE | SCHEMA) (IF EXISTS)? name=multipartIdentifier FORCE? #dropDatabase | DROP CATALOG (IF EXISTS)? name=identifier #dropCatalog @@ -192,7 +312,12 @@ unsupportedDropStatement ; unsupportedStatsStatement - : DROP STATS tableName=multipartIdentifier + : ALTER TABLE name=multipartIdentifier SET STATS + LEFT_PAREN propertyItemList RIGHT_PAREN partitionSpec? #alterTableStats + | ALTER TABLE name=multipartIdentifier (INDEX indexName=identifier)? + MODIFY COLUMN columnName=identifier + SET STATS LEFT_PAREN propertyItemList RIGHT_PAREN partitionSpec? #alterColumnStats + | DROP STATS tableName=multipartIdentifier columns=identifierList? partitionSpec? #dropStats | DROP CACHED STATS tableName=multipartIdentifier #dropCachedStats | DROP EXPIRED STATS #dropExpiredStats @@ -823,7 +948,7 @@ indexDefs ; indexDef - : INDEX indexName=identifier cols=identifierList (USING indexType=(BITMAP | INVERTED | NGRAM_BF))? (PROPERTIES LEFT_PAREN properties=propertyItemList RIGHT_PAREN)? (COMMENT comment=STRING_LITERAL)? + : INDEX (IF NOT EXISTS)? indexName=identifier cols=identifierList (USING indexType=(BITMAP | INVERTED | NGRAM_BF))? (PROPERTIES LEFT_PAREN properties=propertyItemList RIGHT_PAREN)? (COMMENT comment=STRING_LITERAL)? ; partitionsDef @@ -835,23 +960,23 @@ partitionDef ; lessThanPartitionDef - : PARTITION (IF NOT EXISTS)? partitionName=identifier VALUES LESS THAN (MAXVALUE | constantSeq) + : PARTITION (IF NOT EXISTS)? partitionName=identifier VALUES LESS THAN (MAXVALUE | partitionValueList) ; fixedPartitionDef - : PARTITION (IF NOT EXISTS)? partitionName=identifier VALUES LEFT_BRACKET lower=constantSeq COMMA upper=constantSeq RIGHT_PAREN + : PARTITION (IF NOT EXISTS)? partitionName=identifier VALUES LEFT_BRACKET lower=partitionValueList COMMA upper=partitionValueList RIGHT_PAREN ; stepPartitionDef - : FROM from=constantSeq TO to=constantSeq INTERVAL unitsAmount=INTEGER_VALUE unit=datetimeUnit? + : FROM from=partitionValueList TO to=partitionValueList INTERVAL unitsAmount=INTEGER_VALUE unit=datetimeUnit? ; inPartitionDef - : PARTITION (IF NOT EXISTS)? partitionName=identifier (VALUES IN ((LEFT_PAREN constantSeqs+=constantSeq - (COMMA constantSeqs+=constantSeq)* RIGHT_PAREN) | constants=constantSeq))? + : PARTITION (IF NOT EXISTS)? partitionName=identifier (VALUES IN ((LEFT_PAREN partitionValueLists+=partitionValueList + (COMMA partitionValueLists+=partitionValueList)* RIGHT_PAREN) | constants=partitionValueList))? ; -constantSeq +partitionValueList : LEFT_PAREN values+=partitionValueDef (COMMA values+=partitionValueDef)* RIGHT_PAREN ; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogCommentStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogCommentStmt.java index 8249b01b2bf..279ba1a9ba7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogCommentStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogCommentStmt.java @@ -22,7 +22,7 @@ import org.apache.doris.common.UserException; import com.google.common.base.Strings; -public class AlterCatalogCommentStmt extends AlterCatalogStmt { +public class AlterCatalogCommentStmt extends AlterCatalogStmt implements NotFallbackInParser { private final String comment; public AlterCatalogCommentStmt(String catalogName, String comment) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java index abfdae6b5a8..c00987deacc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogNameStmt.java @@ -27,7 +27,7 @@ import com.google.common.base.Strings; /** * Statement for alter the catalog name. */ -public class AlterCatalogNameStmt extends AlterCatalogStmt { +public class AlterCatalogNameStmt extends AlterCatalogStmt implements NotFallbackInParser { private final String newCatalogName; public AlterCatalogNameStmt(String catalogName, String newCatalogName) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java index 1f204015ad7..8ea73033cd5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterCatalogPropertyStmt.java @@ -26,7 +26,7 @@ import java.util.Map; /** * Statement for alter the catalog property. */ -public class AlterCatalogPropertyStmt extends AlterCatalogStmt { +public class AlterCatalogPropertyStmt extends AlterCatalogStmt implements NotFallbackInParser { private final Map<String, String> newProperties; public AlterCatalogPropertyStmt(String catalogName, Map<String, String> newProperties) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColocateGroupStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColocateGroupStmt.java index 98b1ec76f98..86e677d53e3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColocateGroupStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColocateGroupStmt.java @@ -31,7 +31,7 @@ import com.google.common.base.Strings; import java.util.Map; -public class AlterColocateGroupStmt extends DdlStmt { +public class AlterColocateGroupStmt extends DdlStmt implements NotFallbackInParser { private final ColocateGroupName colocateGroupName; private final Map<String, String> properties; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java index e5cc4bff614..199e8f8d3c0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java @@ -59,7 +59,7 @@ import java.util.Optional; * Note: partition stats injection is mainly convenient for test cost estimation, * and can be removed after the related functions are completed. */ -public class AlterColumnStatsStmt extends DdlStmt { +public class AlterColumnStatsStmt extends DdlStmt implements NotFallbackInParser { private static final ImmutableSet<StatsType> CONFIGURABLE_PROPERTIES_SET = new ImmutableSet.Builder<StatsType>() .add(StatsType.ROW_COUNT) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabasePropertyStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabasePropertyStmt.java index af01882dc3c..281c60d8cba 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabasePropertyStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabasePropertyStmt.java @@ -32,7 +32,7 @@ import com.google.common.base.Strings; import java.util.HashMap; import java.util.Map; -public class AlterDatabasePropertyStmt extends DdlStmt { +public class AlterDatabasePropertyStmt extends DdlStmt implements NotFallbackInParser { private String dbName; private Map<String, String> properties; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseQuotaStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseQuotaStmt.java index e832e193ab3..fd41e3800f2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseQuotaStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseQuotaStmt.java @@ -29,7 +29,7 @@ import org.apache.doris.qe.ConnectContext; import com.google.common.base.Strings; import com.google.gson.annotations.SerializedName; -public class AlterDatabaseQuotaStmt extends DdlStmt { +public class AlterDatabaseQuotaStmt extends DdlStmt implements NotFallbackInParser { @SerializedName("db") private String dbName; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseRename.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseRename.java index 1e4d78840d4..fd82d99ec4f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseRename.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterDatabaseRename.java @@ -30,7 +30,7 @@ import org.apache.doris.qe.ConnectContext; import com.google.common.base.Strings; -public class AlterDatabaseRename extends DdlStmt { +public class AlterDatabaseRename extends DdlStmt implements NotFallbackInParser { private String dbName; private String newDbName; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java index 622feed12ed..1dd54f6f1b1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterPolicyStmt.java @@ -39,7 +39,7 @@ import java.util.Optional; * Alter policy **/ @Data -public class AlterPolicyStmt extends DdlStmt { +public class AlterPolicyStmt extends DdlStmt implements NotFallbackInParser { private final String policyName; private final Map<String, String> properties; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRepositoryStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRepositoryStmt.java index 31c33b6b8e1..1627603a122 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRepositoryStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRepositoryStmt.java @@ -32,7 +32,7 @@ import com.google.common.collect.Maps; import java.util.HashMap; import java.util.Map; -public class AlterRepositoryStmt extends DdlStmt { +public class AlterRepositoryStmt extends DdlStmt implements NotFallbackInParser { private String name; private Map<String, String> properties; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterResourceStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterResourceStmt.java index bd05f478412..3b6f325e9b8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterResourceStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterResourceStmt.java @@ -29,7 +29,7 @@ import org.apache.doris.qe.ConnectContext; import java.util.Map; -public class AlterResourceStmt extends DdlStmt { +public class AlterResourceStmt extends DdlStmt implements NotFallbackInParser { private static final String TYPE = "type"; private final String resourceName; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRoutineLoadStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRoutineLoadStmt.java index d2a0844dfb4..f383e02aee1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRoutineLoadStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterRoutineLoadStmt.java @@ -48,7 +48,7 @@ import java.util.Optional; * ... * ) */ -public class AlterRoutineLoadStmt extends DdlStmt { +public class AlterRoutineLoadStmt extends DdlStmt implements NotFallbackInParser { private static final String NAME_TYPE = "ROUTINE LOAD NAME"; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSqlBlockRuleStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSqlBlockRuleStmt.java index a3cb97dd6bd..12262043f7f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSqlBlockRuleStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSqlBlockRuleStmt.java @@ -32,7 +32,7 @@ import org.apache.commons.lang3.StringUtils; import java.util.Map; -public class AlterSqlBlockRuleStmt extends DdlStmt { +public class AlterSqlBlockRuleStmt extends DdlStmt implements NotFallbackInParser { public static final Long LONG_NOT_SET = SqlBlockUtil.LONG_MINUS_ONE; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSystemStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSystemStmt.java index 47cb4fc4306..7d52c06da50 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSystemStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterSystemStmt.java @@ -28,7 +28,7 @@ import com.google.common.base.Preconditions; import lombok.Getter; @Getter -public class AlterSystemStmt extends DdlStmt { +public class AlterSystemStmt extends DdlStmt implements NotFallbackInParser { private final AlterClause alterClause; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java index 8a9e55f4ebf..31d6d4c377d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java @@ -45,7 +45,7 @@ import java.util.Optional; * e.g. * ALTER TABLE stats_test.example_tbl SET STATS ('row_count'='6001215'); */ -public class AlterTableStatsStmt extends DdlStmt { +public class AlterTableStatsStmt extends DdlStmt implements NotFallbackInParser { private static final ImmutableSet<StatsType> CONFIGURABLE_PROPERTIES_SET = new ImmutableSet.Builder<StatsType>() diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java index f5d42435532..a9e9c78d418 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStmt.java @@ -38,7 +38,7 @@ import java.util.List; import java.util.Map; // Alter table statement. -public class AlterTableStmt extends DdlStmt { +public class AlterTableStmt extends DdlStmt implements NotFallbackInParser { private TableName tbl; private List<AlterClause> ops; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterUserStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterUserStmt.java index f87884c6c4b..2815f2a30b1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterUserStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterUserStmt.java @@ -38,7 +38,7 @@ import java.util.Set; // ACCOUNT_LOCK[ACCOUNT_UNLOCK] // FAILED_LOGIN_ATTEMPTS // PASSWORD_LOCK_TIME -public class AlterUserStmt extends DdlStmt { +public class AlterUserStmt extends DdlStmt implements NotFallbackInParser { private boolean ifExist; private UserDesc userDesc; private String role; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadGroupStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadGroupStmt.java index 3a5a3c0b63f..8cba792dd39 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadGroupStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadGroupStmt.java @@ -28,7 +28,7 @@ import org.apache.doris.qe.ConnectContext; import java.util.Map; -public class AlterWorkloadGroupStmt extends DdlStmt { +public class AlterWorkloadGroupStmt extends DdlStmt implements NotFallbackInParser { private final String workloadGroupName; private final Map<String, String> properties; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadSchedPolicyStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadSchedPolicyStmt.java index 17ffdd26d6b..8d167d2fe73 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadSchedPolicyStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterWorkloadSchedPolicyStmt.java @@ -28,7 +28,7 @@ import org.apache.doris.qe.ConnectContext; import java.util.Map; -public class AlterWorkloadSchedPolicyStmt extends DdlStmt { +public class AlterWorkloadSchedPolicyStmt extends DdlStmt implements NotFallbackInParser { private final String policyName; private final Map<String, String> properties; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index bb3090d8a9b..07a97fe1e1d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -76,7 +76,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; @@ -139,6 +138,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; @@ -2815,7 +2815,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, @@ -2826,15 +2826,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); } @@ -2843,17 +2843,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()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreatePolicyCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreatePolicyCommand.java index ee4a4bfea45..7672c6a3f22 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreatePolicyCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreatePolicyCommand.java @@ -19,7 +19,7 @@ package org.apache.doris.nereids.trees.plans.commands; import org.apache.doris.analysis.StmtType; import org.apache.doris.analysis.UserIdentity; -import org.apache.doris.nereids.exceptions.AnalysisException; +import org.apache.doris.nereids.exceptions.MustFallbackException; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.plans.PlanType; import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; @@ -80,8 +80,7 @@ public class CreatePolicyCommand extends Command implements ForwardWithSync { @Override public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { - ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce(); - throw new AnalysisException("Not support create policy command in Nereids now"); + throw new MustFallbackException("Not support create policy command in Nereids now"); } @Override 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 86e5603d94c..f2d17170173 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 @@ -149,12 +149,14 @@ import org.apache.doris.nereids.minidump.MinidumpUtils; import org.apache.doris.nereids.parser.NereidsParser; import org.apache.doris.nereids.rules.exploration.mv.InitMaterializationContextHook; import org.apache.doris.nereids.trees.plans.commands.Command; +import org.apache.doris.nereids.trees.plans.commands.CreatePolicyCommand; import org.apache.doris.nereids.trees.plans.commands.CreateTableCommand; 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; import org.apache.doris.nereids.trees.plans.commands.insert.BatchInsertIntoTableCommand; import org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTableCommand; @@ -700,6 +702,9 @@ public class StmtExecutor { if (isForwardToMaster()) { throw new UserException("Forward master command is not supported for prepare statement"); } + if (logicalPlan instanceof UnsupportedCommand || logicalPlan instanceof CreatePolicyCommand) { + throw new MustFallbackException("cannot prepare command " + logicalPlan.getClass().getSimpleName()); + } logicalPlan = new PrepareCommand(String.valueOf(context.getStmtId()), logicalPlan, statementContext.getPlaceholders(), originStmt); @@ -950,7 +955,8 @@ public class StmtExecutor { parseByLegacy(); if (context.isTxnModel() && !(parsedStmt instanceof InsertStmt) && !(parsedStmt instanceof TransactionStmt)) { - throw new TException("This is in a transaction, only insert, commit, rollback is acceptable."); + throw new TException("This is in a transaction, only insert, update, delete, " + + "commit, rollback is acceptable."); } // support select hint e.g. select /*+ SET_VAR(query_timeout=1) */ sleep(3); analyzeVariablesInStmt(); diff --git a/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy b/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy index 7e3732fd69a..b403b3a2f51 100644 --- a/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy +++ b/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy @@ -61,14 +61,14 @@ suite("test_prepared_stmt", "nonConcurrent") { sql "set enable_fallback_to_original_planner = false" def stmt_read = prepareStatement "select * from ${tableName} where k1 = ? order by k1" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setInt(1, 1231) qe_select0 stmt_read stmt_read.setInt(1, 1232) qe_select0 stmt_read qe_select0 stmt_read def stmt_read1 = prepareStatement "select hex(k3), ? \n from ${tableName} where k1 = ? order by 1" - assertEquals(stmt_read1.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read1.setString(1, "xxxx---") stmt_read1.setInt(2, 1231) qe_select1 stmt_read1 @@ -78,7 +78,7 @@ suite("test_prepared_stmt", "nonConcurrent") { qe_select1 stmt_read1 stmt_read1.close() def stmt_read2 = prepareStatement "select * from ${tableName} as t1 join ${tableName} as t2 on t1.`k1` = t2.`k1` where t1.`k1` >= ? and t1.`k2` >= ? and size(t1.`k9`) > ? order by 1, 2, 3" - assertEquals(stmt_read2.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read2.setInt(1, 1237) stmt_read2.setBigDecimal(2, new BigDecimal("120939.11130")) stmt_read2.setInt(3, 0) @@ -107,7 +107,7 @@ suite("test_prepared_stmt", "nonConcurrent") { sql "sync" stmt_read = prepareStatement "SELECT *, ? FROM (select *, ? from mytable1 where citycode = ?) AS `SpotfireCustomQuery1` WHERE 1 = 1" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setInt(1, 12345) stmt_read.setInt(2, 1234) stmt_read.setInt(3, 1) @@ -115,32 +115,32 @@ suite("test_prepared_stmt", "nonConcurrent") { stmt_read.close() stmt_read = prepareStatement "SELECT 10" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) qe_select4 stmt_read stmt_read = prepareStatement "SELECT 1" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) qe_select5 stmt_read stmt_read = prepareStatement "SELECT 'a' FROM mytable1" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) qe_select5 stmt_read stmt_read.close() stmt_read = prepareStatement "SELECT 1-2 + ?" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setInt(1, 3); qe_select5 stmt_read stmt_read.setInt(1, -1); qe_select5 stmt_read stmt_read.close() - stmt_read = prepareStatement "SELECT 1 + ? AS c1, 'MySQL' AS c2, ? AS c3" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + stmt_read = prepareStatement "SELECT 1 + ? AS c1, 'MySQL' AS c2, ? AS c3" + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setInt(1, 5) stmt_read.setString(2, "Connector/J") qe_select5 stmt_read - stmt_read = prepareStatement "SELECT ?, ?, ?, ?, ?" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + stmt_read = prepareStatement "SELECT ?, ?, ?, ?, ?" + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) boolean value = false; stmt_read.setBoolean(1, value); stmt_read.setObject(2, value); @@ -154,7 +154,7 @@ suite("test_prepared_stmt", "nonConcurrent") { // sql "set experimental_enable_nereids_planner = false" stmt_read = prepareStatement "SELECT *, ? FROM (select *, ? from mytable1 where pv is null) AS `SpotfireCustomQuery1` WHERE 1 = 1" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setString(1, "xxxlalala") stmt_read.setDouble(2, 1234.1111) qe_select6 stmt_read @@ -173,13 +173,13 @@ suite("test_prepared_stmt", "nonConcurrent") { qe_select7_1 stmt_read stmt_read = prepareStatement "SELECT COUNT() from mytable1 WHERE citycode = ? GROUP BY siteid" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setString(1, "1") qe_select8 stmt_read stmt_read.close() stmt_read = prepareStatement "SELECT COUNT() from mytable1 WHERE citycode = ? GROUP BY ?" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setString(1, "1") stmt_read.setString(2, "1") qe_select9 stmt_read @@ -210,33 +210,33 @@ suite("test_prepared_stmt", "nonConcurrent") { // limit stmt_read = prepareStatement "SELECT 1 LIMIT ?" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ClientPreparedStatement); + assertEquals(com.mysql.cj.jdbc.ClientPreparedStatement, stmt_read.class) stmt_read.setInt(1, 1) qe_select14 stmt_read - stmt_read = prepareStatement "SELECT 1 LIMIT 1" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + stmt_read = prepareStatement "SELECT 1 LIMIT 1" + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) qe_select15 stmt_read // insert with label - stmt_read = prepareStatement "insert into mytable1 with xxx_label 12222 values(?, ?, ?, ?)" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ClientPreparedStatement); + stmt_read = prepareStatement "insert into mytable1 with xxx_label 12222 values(?, ?, ?, ?)" + assertEquals(com.mysql.cj.jdbc.ClientPreparedStatement, stmt_read.class) // alter stmt - stmt_read = prepareStatement "alter table mytable1 rename mytable2" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ClientPreparedStatement); + stmt_read = prepareStatement "alter table mytable1 rename mytable2" + assertEquals(com.mysql.cj.jdbc.ClientPreparedStatement, stmt_read.class) // update stmt - stmt_read = prepareStatement "update tbl_prepared_stmt set k5 = ?" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + stmt_read = prepareStatement "update tbl_prepared_stmt set k5 = ?" + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) stmt_read.setString(1, "2021-01-01") def result = stmt_read.execute() logger.info("result: ${result}") - stmt_read = prepareStatement "update tbl_prepared_stmt set k4 = 'Will we ignore LIMIT ?,?'" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ServerPreparedStatement); + stmt_read = prepareStatement "update tbl_prepared_stmt set k4 = 'Will we ignore LIMIT ?,?'" + assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, stmt_read.class) result = stmt_read.execute() logger.info("result: ${result}") qt_sql "select * from tbl_prepared_stmt where k4 = 'Will we ignore LIMIT ?,?' order by k1" // show create table - stmt_read = prepareStatement "SHOW CREATE TABLE mytable1" - assertEquals(stmt_read.class, com.mysql.cj.jdbc.ClientPreparedStatement); + stmt_read = prepareStatement "SHOW CREATE TABLE mytable1" + assertEquals(com.mysql.cj.jdbc.ClientPreparedStatement, stmt_read.class) // not stable // qe_select16 stmt_read stmt_read.close() diff --git a/regression-test/suites/schema_change_p0/test_new_schema_change.groovy b/regression-test/suites/schema_change_p0/test_new_schema_change.groovy index 7b9f6cdd508..c5c68013f70 100644 --- a/regression-test/suites/schema_change_p0/test_new_schema_change.groovy +++ b/regression-test/suites/schema_change_p0/test_new_schema_change.groovy @@ -37,13 +37,12 @@ suite("test_new_schema_change") { DISTRIBUTED BY HASH(siteid) BUCKETS 5 PROPERTIES("replication_num" = "1", "light_schema_change" = "true"); """ - try{ sql "begin" sql """ insert into ${tbName} values('2021-11-01',1,1,'用户A',1),('2021-11-01',1,1,'用户B',1),('2021-11-01',1,1,'用户A',3),('2021-11-02',1,1,'用户A',1),('2021-11-02',1,1,'用户B',1),('2021-11-02',101,112332121,'用户B',112312),('2021-11-02',103,112332211,'用户B',112312); """ - sql """ alter table ${tbName} add column vv int after pv""" + test { + sql """ alter table ${tbName} add column vv int after pv""" + exception "This is in a transaction, only insert, update, delete, commit, rollback is acceptable." + } sql "commit" sql """ DROP TABLE ${tbName} """ - }catch (Exception e){ - assertTrue(e.getMessage().contains("This is in a transaction, only insert, commit, rollback is acceptable.")) - } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org