From d909bc5cd3ebaa272f72da734387eca34604dea6 Mon Sep 17 00:00:00 2001 From: guojn1 Date: Thu, 2 Jan 2025 09:59:45 +0800 Subject: [PATCH] [fix][dingo-calcite] Display the view normally --- dingo-calcite/src/main/codegen/config.fmpp | 13 ++ .../src/main/codegen/includes/AlterTable.ftl | 219 ++++-------------- .../src/main/codegen/includes/parserImpls.ftl | 113 ++++++++- .../io/dingodb/calcite/DingoDdlExecutor.java | 63 ++++- .../executor/ShowCreateTableExecutor.java | 57 ++++- .../calcite/grammar/ddl/ColumnOption.java | 49 ++++ .../calcite/grammar/ddl/Constraint.java | 27 +++ .../grammar/ddl/DingoSqlCreateView.java | 4 +- .../calcite/grammar/ddl/DingoSqlDdlNodes.java | 11 + ...eTable.java => SqlSyntaxVerification.java} | 106 ++++----- .../exec/operator/InfoSchemaScanOperator.java | 3 +- .../server/executor/ddl/DdlRollBack.java | 9 +- .../main/java/io/dingodb/meta/DdlService.java | 18 +- .../dingodb/store/proxy/ddl/DdlService.java | 51 ++-- .../dingodb/store/proxy/meta/MetaService.java | 2 +- 15 files changed, 434 insertions(+), 311 deletions(-) create mode 100644 dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/ColumnOption.java create mode 100644 dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/Constraint.java rename dingo-calcite/src/test/java/io/dingodb/calcite/{TestCreateTable.java => SqlSyntaxVerification.java} (85%) diff --git a/dingo-calcite/src/main/codegen/config.fmpp b/dingo-calcite/src/main/codegen/config.fmpp index 6cedf9bf14..3f52345a8a 100644 --- a/dingo-calcite/src/main/codegen/config.fmpp +++ b/dingo-calcite/src/main/codegen/config.fmpp @@ -28,6 +28,8 @@ data: { imports: [ "io.dingodb.common.partition.PartitionDetailDefinition" "io.dingodb.common.partition.PartitionDefinition" + "io.dingodb.calcite.grammar.ddl.ColumnOption" + "io.dingodb.calcite.grammar.ddl.Constraint" "io.dingodb.calcite.grammar.ddl.DingoSqlDdlNodes" "io.dingodb.calcite.grammar.ddl.SqlBeginTx" "io.dingodb.calcite.grammar.ddl.SqlBlock" @@ -163,6 +165,7 @@ data: { # not a reserved keyword, add it to the 'nonReservedKeywords' section. keywords: [ "ALGORITHM" + "AUTO_RANDOM" "INPLACE" "IF" "COPY" @@ -176,6 +179,8 @@ data: { "ACCOUNT" "AUTO_INCREMENT" "COLUMNS" + "CLUSTERED" + "NONCLUSTERED" "DATABASES" "DISTRIBUTION" "ENCLOSED" @@ -187,6 +192,7 @@ data: { "EXECUTORS" "ENFORCED" "EXPIRE" + "ENCRYPTION" "ESCAPED" "FIELDS" "FLUSH" @@ -212,9 +218,11 @@ data: { "REQUIRE" "SCAN" "SSL" + "SERIAL" "STARTING" "SHARED" "STATUS" + "STORAGE" "TABLES" "STARTTS" "TERMINATED" @@ -256,6 +264,7 @@ data: { "RENAME" "TEXT_SEARCH" "HYBRID_SEARCH" + "DISK" "DISK_ANN_BUILD" "DISK_ANN_LOAD" "DISK_ANN_STATUS" @@ -274,6 +283,9 @@ data: { "RTREE" "UNDEFINED" "TEMPTABLE" + "FIXED" + "MEMORY" + "COLUMN_FORMAT" ] # List of non-reserved keywords to add; @@ -328,6 +340,7 @@ data: { "SqlAlterUser" "SqlAlterTenant" "SqlAlterSchema" + "SqlAlterIgnoreTable" ] statementParserMethods: [ diff --git a/dingo-calcite/src/main/codegen/includes/AlterTable.ftl b/dingo-calcite/src/main/codegen/includes/AlterTable.ftl index 9e05666938..0365b8a2fe 100644 --- a/dingo-calcite/src/main/codegen/includes/AlterTable.ftl +++ b/dingo-calcite/src/main/codegen/includes/AlterTable.ftl @@ -173,50 +173,25 @@ SqlAlterTable addPartition(Span s, String scope, SqlIdentifier id): { SqlAlterTable addColumn(Span s, String scope, SqlIdentifier id): { final SqlIdentifier columnId; final SqlDataTypeSpec type; - final boolean nullable; - SqlNode e = null; - SqlNode constraint = null; - ColumnStrategy strategy = null; - boolean primary = false; - String comment = ""; - boolean autoInc = false; - String collate = "utf8_bin"; + SqlIdentifier afterCol = null; + ColumnOption columnOpt = null; } { columnId = SimpleIdentifier() type = DataType() - nullable = NullableOptDefaultTrue() - ( - [ ] - e = Expression(ExprContext.ACCEPT_SUB_QUERY) - ( - { strategy = ColumnStrategy.VIRTUAL; } - | - { strategy = ColumnStrategy.STORED; } - | - { strategy = ColumnStrategy.VIRTUAL; } - ) - | - e = Expression(ExprContext.ACCEPT_SUB_QUERY) - { strategy = ColumnStrategy.DEFAULT; } - | - { primary=true; } - | - comment = dingoIdentifier() - | - { collate = this.getNextToken().image;} - | - { autoInc = true;} - | - - )* + columnOpt = parseColumnOption() + [ + ( + afterCol = SimpleIdentifier() + | + + ) + ] { - if (e == null) { - strategy = nullable ? ColumnStrategy.NULLABLE - : ColumnStrategy.NOT_NULLABLE; - } + boolean nullable = true; + if (columnOpt != null) { nullable = columnOpt.nullable; } return new SqlAlterAddColumn(s.end(this), id, DingoSqlDdlNodes.createColumn( - s.end(this), columnId, type.withNullable(nullable), e, strategy, autoInc, comment, primary, collate + s.end(this), columnId, type.withNullable(nullable), columnOpt )); } } @@ -255,8 +230,9 @@ SqlAlterTable addIndex(Span s, String scope, SqlIdentifier id): { Properties prop = new Properties(); String indexAlg = null; String indexLockOpt = null; + boolean ifNotExists = false; } { - { s.add(this); } + (|) ifNotExists = IfNotExistsOpt() { s.add(this); } { index = getNextToken().image; } ( { indexType = "vector"; } columnList = indexColumns() @@ -354,7 +330,7 @@ SqlAlterTable addIndexByMode(Span s, String scope, SqlIdentifier id, String mode String indexAlg = null; String indexLockOpt = null; } { - { s.add(this); } + [(|)] { s.add(this); } { index = getNextToken().image; } columnList = indexColumns() ( @@ -563,83 +539,25 @@ SqlAlterTable dropPartition(Span s, String scope, SqlIdentifier id): { SqlAlterTable modifyColumn(Span s, String scope, SqlIdentifier id, SqlAlterTable alterTable): { DingoSqlColumn columnDec; final SqlDataTypeSpec type; - boolean nullable = true; - SqlNode checkExpr = null; - SqlNode e = null; - final SqlNode constraint; - SqlIdentifier name = null; - final SqlNodeList columnList; - SqlNodeList withColumnList = null; - ColumnStrategy strategy = null; - final String index; - Boolean autoIncrement = false; - Properties properties = null; - PartitionDefinition partitionDefinition = null; - int replica = 0; - String engine = null; - String collate = "utf8_bin"; - String indexType = "scalar"; - Boolean primaryKey = false; - String comment = ""; - SqlNodeList refColumnList = null; - SqlIdentifier refTable = null; - String updateRefOpt = null; - String deleteRefOpt = null; + ColumnOption columnOpt = null; SqlIdentifier afterCol = null; + SqlIdentifier name = null; } { name = SimpleIdentifier() ( type = DataType() - ( - {autoIncrement = true; } - | - { nullable = true; } - | - { nullable = false; } - | - [ ] - e = Expression(ExprContext.ACCEPT_SUB_QUERY) - ( - { strategy = ColumnStrategy.VIRTUAL; } - | - { strategy = ColumnStrategy.STORED; } - | - { strategy = ColumnStrategy.VIRTUAL; } - ) - | - e = Expression(ExprContext.ACCEPT_SUB_QUERY) { strategy = ColumnStrategy.DEFAULT;} - | - { primaryKey = true; } - | - - checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) - [] [] - | - (|) { comment = token.image; } - | - - | - { collate = this.getNextToken().image; } - | - { s.add(this); } [name = SimpleIdentifier()] - checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) - [] [] - | - refTable = CompoundIdentifier() refColumnList = ParenthesizedSimpleIdentifierList() - ( ( - updateRefOpt = referenceOpt() + columnOpt = parseColumnOption() + [ + ( + afterCol = SimpleIdentifier() | - deleteRefOpt = referenceOpt() + ) - )* - )* - [ afterCol = SimpleIdentifier() ] + ] { - if (e == null) { - strategy = nullable ? ColumnStrategy.NULLABLE - : ColumnStrategy.NOT_NULLABLE; - } - columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), name, type.withNullable(nullable), e, strategy, autoIncrement, comment, primaryKey, collate); + boolean nullable = true; + if (columnOpt != null) { nullable = columnOpt.nullable; } + columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), name, type.withNullable(nullable), columnOpt); } ) { @@ -657,13 +575,20 @@ SqlAlterTable modifyColumn(Span s, String scope, SqlIdentifier id, SqlAlterTable SqlAlterTable alterColumn(Span s, String scope, SqlIdentifier id): { SqlIdentifier name = null; SqlNode e = null; + boolean visible = true; } { { s.add(this); } name = SimpleIdentifier() ( - e = Expression(ExprContext.ACCEPT_SUB_QUERY) + ( + e = Expression(ExprContext.ACCEPT_SUB_QUERY) + | + { visible = true;} + | + { visible = false; } + ) { return new SqlAlterColumn( s.end(this), id, name, 1, e @@ -679,80 +604,16 @@ SqlAlterTable changeColumn(Span s, String scope, SqlIdentifier id): { SqlIdentifier newName = null; DingoSqlColumn columnDec = null; final SqlDataTypeSpec type; - boolean nullable = true; - SqlNode checkExpr = null; - SqlNode e = null; - final SqlNode constraint; - final SqlNodeList columnList; - SqlNodeList withColumnList = null; - ColumnStrategy strategy = null; - final String index; - Boolean autoIncrement = false; - Properties properties = null; - PartitionDefinition partitionDefinition = null; - int replica = 0; - String engine = null; - String indexType = "scalar"; - Boolean primaryKey = false; - String comment = ""; - SqlNodeList refColumnList = null; - SqlIdentifier refTable = null; - String updateRefOpt = null; - String deleteRefOpt = null; - String collate = "utf8_bin"; + ColumnOption columnOpt = null; } { name = SimpleIdentifier() newName = SimpleIdentifier() ( type = DataType() - ( - {autoIncrement = true; } - | - { nullable = true; } - | - { nullable = false; } - | - [ ] - e = Expression(ExprContext.ACCEPT_SUB_QUERY) - ( - { strategy = ColumnStrategy.VIRTUAL; } - | - { strategy = ColumnStrategy.STORED; } - | - { strategy = ColumnStrategy.VIRTUAL; } - ) - | - e = Expression(ExprContext.ACCEPT_SUB_QUERY) { strategy = ColumnStrategy.DEFAULT;} - | - { primaryKey = true; } - | - - checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) - [] [] - | - (|) { comment = token.image; } - | - - | - { collate = this.getNextToken().image;} - | - { s.add(this); } [name = SimpleIdentifier()] - checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) - [] [] - | - refTable = CompoundIdentifier() refColumnList = ParenthesizedSimpleIdentifierList() - ( ( - updateRefOpt = referenceOpt() - | - deleteRefOpt = referenceOpt() - ) - )* - )* + columnOpt = parseColumnOption() { - if (e == null) { - strategy = nullable ? ColumnStrategy.NULLABLE - : ColumnStrategy.NOT_NULLABLE; - } - columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), name, type.withNullable(nullable), e, strategy, autoIncrement, comment, primaryKey, collate); + boolean nullable = true; + if (columnOpt != null) { nullable = columnOpt.nullable;} + columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), name, type.withNullable(nullable), columnOpt); } )? { diff --git a/dingo-calcite/src/main/codegen/includes/parserImpls.ftl b/dingo-calcite/src/main/codegen/includes/parserImpls.ftl index 44ce7e3f64..56a7603036 100644 --- a/dingo-calcite/src/main/codegen/includes/parserImpls.ftl +++ b/dingo-calcite/src/main/codegen/includes/parserImpls.ftl @@ -51,8 +51,15 @@ SqlCreate SqlCreateSchema(Span s, boolean replace) : } { ( | ) ifNotExists = IfNotExistsOpt() id = CompoundIdentifier() - [ { charset = getNextToken().image; }] - [ { collate = getNextToken().image; } ] + ( + + | + { charset = getNextToken().image; } + | + { collate = getNextToken().image; } + | + + )* { return new io.dingodb.calcite.grammar.ddl.SqlCreateSchema(s.end(this), replace, ifNotExists, id, charset, collate); } @@ -187,7 +194,7 @@ void TableElement(List list) : | checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) - [] [] + [] [(|)] | (|) { comment = token.image; } | @@ -197,7 +204,7 @@ void TableElement(List list) : | { s.add(this); } [name = SimpleIdentifier()] checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) - [] [] + [] [(|)] )* { if (e == null) { @@ -300,6 +307,98 @@ void TableElement(List list) : ) } +ColumnOption parseColumnOption(): { + ColumnOption colOpt = new ColumnOption(); + SqlNode e = null; + ColumnStrategy strategy = null; + SqlNode checkExpr = null; + boolean constraintNot = false; + String constraintOpt = null; + SqlIdentifier name = null; + SqlNodeList refColumnList = null; + SqlIdentifier refTable = null; + String updateRefOpt = null; + String deleteRefOpt = null; +} { + ( + { colOpt.autoIncrement = true; } + | + { colOpt.nullable=true; } + | + { colOpt.nullable=false; } + | + [ ] + e = Expression(ExprContext.ACCEPT_SUB_QUERY) + ( + { strategy = ColumnStrategy.VIRTUAL; } + | + { strategy = ColumnStrategy.STORED; } + | + { strategy = ColumnStrategy.VIRTUAL; } + ) + | + e = Expression(ExprContext.ACCEPT_SUB_QUERY) { strategy = ColumnStrategy.DEFAULT;} + | + { colOpt.primaryKey=true; } [ {colOpt.clustered=true;}| {colOpt.clustered=false;}] [| {colOpt.global=false;}] + | + + checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) + [ {constraintNot = true;}] [( {constraintOpt="enforced";}| {constraintOpt="null";})] + | + { String comment = strIdent(); colOpt.comment=comment; } + | + { String collate = strIdent(); colOpt.collate=collate; } + | + ( {colOpt.columnFormat="fixed";}| {colOpt.columnFormat="dynamic";}| {colOpt.columnFormat="default";}) + | + + | + ( {colOpt.storage="disk";}|{colOpt.storage="memory";}) + | + [ {int autoRandomLen = UnsignedIntLiteral(); colOpt.autoRandom=autoRandomLen;} ] + | + { colOpt.uniqueKey=true;} [] [( {colOpt.global=true;}| {colOpt.global=false;})] + | + {colOpt.serialDefaultVal=true;} + | + {colOpt.visible=true;} + | + {colOpt.visible=false;} + | + refTable = CompoundIdentifier() refColumnList = ParenthesizedSimpleIdentifierList() + [(||)] + ( ( + updateRefOpt = referenceOpt() + | + deleteRefOpt = referenceOpt() + ) + )* + | + [name = SimpleIdentifier()] + checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) + [ {constraintNot=true;}] [( {constraintOpt="enforced";}|{constraintOpt="null";})] + )* + { + if (e == null) { + strategy = colOpt.nullable ? ColumnStrategy.NULLABLE + : ColumnStrategy.NOT_NULLABLE; + } + Constraint constraint = new Constraint(); + constraint.name = name; + constraint.expression = checkExpr; + constraint.constraintNot = constraintNot; + constraint.constraintOpt = constraintOpt; + colOpt.constraint = constraint; + colOpt.expression = e; + colOpt.strategy = strategy; + colOpt.refTable = refTable; + colOpt.refColumnList = refColumnList; + colOpt.updateRefOpt = updateRefOpt; + colOpt.deleteRefOpt = deleteRefOpt; + return colOpt; + } +} + SqlNodeList AttributeDefList() : { final Span s; @@ -621,9 +720,9 @@ SqlCreate SqlCreateView(Span s, boolean replace) : final SqlNode query; String user = null; String host = null; - String alg = null; - String security = null; - String checkOpt = null; + String alg = "UNDEFINED"; + String security = "DEFINER"; + String checkOpt = "CASCADED"; } { [ (||)] diff --git a/dingo-calcite/src/main/java/io/dingodb/calcite/DingoDdlExecutor.java b/dingo-calcite/src/main/java/io/dingodb/calcite/DingoDdlExecutor.java index 325cb9dc2e..167ec6dfc1 100644 --- a/dingo-calcite/src/main/java/io/dingodb/calcite/DingoDdlExecutor.java +++ b/dingo-calcite/src/main/java/io/dingodb/calcite/DingoDdlExecutor.java @@ -836,10 +836,19 @@ public void execute(DingoSqlCreateView sqlCreateView, CalcitePrepare.Context con .updateTime(0) .build(); Properties properties = new Properties(); + String grantorUser = (String) context.getDataContext().get("user"); + String grantorHost = (String) context.getDataContext().get("host"); + if (sqlCreateView.definer == null) { + sqlCreateView.definer = grantorUser; + } + if (sqlCreateView.host == null) { + sqlCreateView.host = grantorHost; + } properties.setProperty("user", sqlCreateView.definer); properties.setProperty("host", sqlCreateView.host); properties.setProperty("check_option", sqlCreateView.checkOpt); properties.setProperty("security_type", sqlCreateView.security); + properties.setProperty("algorithm", sqlCreateView.alg); tableDefinition.setProperties(properties); DdlService ddlService = DdlService.root(); ddlService.createViewWithInfo(schemaName, tableDefinition, connId, null); @@ -1019,7 +1028,7 @@ public void execute(@NonNull SqlAlterTableAddPart sqlAlterTableAddPart, CalciteP } DdlService.root().alterTableAddPart( - schema.getSchemaId(), schema.getSchemaName(), table.getTableId().seq, tableName, detail + schema.getSchemaId(), schema.getSchemaName(), table, detail ); timeCtx.stop(); @@ -1083,7 +1092,7 @@ public void execute(@NonNull SqlAlterIndexVisible sqlAlterIndexVisible, CalciteP = getSchemaAndTableName(sqlAlterIndexVisible.table, context); final String tableName = Parameters.nonNull(schemaTableName.right, "table name"); final SubSnapshotSchema schema = Parameters.nonNull(schemaTableName.left, "table schema"); - DingoTable table = schema.getTable(tableName); + Table table = schema.getTableInfo(tableName); if (table == null) { throw DINGO_RESOURCE.tableNotExists(tableName).ex(); } @@ -1093,7 +1102,7 @@ public void execute(@NonNull SqlAlterIndexVisible sqlAlterIndexVisible, CalciteP throw DingoErrUtil.newStdErr(ErrKeyDoesNotExist, sqlAlterIndexVisible.getIndex(), tableName); } DdlService.root().alterIndexVisible( - schema.getSchemaId(), schema.getSchemaName(), table.getTableId().seq, tableName, + schema.getSchemaId(), schema.getSchemaName(), table, sqlAlterIndexVisible.index, sqlAlterIndexVisible.invisible ); RootCalciteSchema rootCalciteSchema = (RootCalciteSchema) context.getMutableRootSchema(); @@ -1204,6 +1213,10 @@ public void execute(SqlAlterDropColumn sqlAlterDropColumn, CalcitePrepare.Contex = getSchemaAndTableName(sqlAlterDropColumn.table, context); final String tableName = Parameters.nonNull(schemaTableName.right, "table name"); final SubSnapshotSchema schema = Parameters.nonNull(schemaTableName.left, "table schema"); + SchemaInfo schemaInfo = schema.getSchemaInfo(schema.getSchemaName()); + if (schemaInfo == null) { + throw DINGO_RESOURCE.unknownSchema(schema.getSchemaName()).ex(); + } Table table = schema.getTableInfo(tableName); if (table == null) { throw DINGO_RESOURCE.tableNotExists(tableName).ex(); @@ -1251,10 +1264,8 @@ public void execute(SqlAlterDropColumn sqlAlterDropColumn, CalcitePrepare.Contex } DdlService.root().dropColumn( - table.getTableId().domain, - schema.getSchemaName(), - table.tableId.seq, - tableName, + schemaInfo, + table, sqlAlterDropColumn.columnNm, markedDelete, "", @@ -1686,7 +1697,7 @@ public void execute(SqlAlterRenameTable sqlAlterRenameTable, CalcitePrepare.Cont throw DINGO_RESOURCE.tableNotExists(tableName).ex(); } DdlService.root().renameTable( - schema.getSchemaId(), schema.getSchemaName(), table.tableId.seq, tableName, + schema.getSchemaId(), schema.getSchemaName(), table, getTableName(sqlAlterRenameTable.toIdList.get(0))); RootCalciteSchema rootCalciteSchema = (RootCalciteSchema) context.getMutableRootSchema(); RootSnapshotSchema rootSnapshotSchema = (RootSnapshotSchema) rootCalciteSchema.schema; @@ -1717,7 +1728,7 @@ public void execute(SqlAlterRenameIndex sqlAlterRenameIndex, CalcitePrepare.Cont } DdlService.root().renameIndex( - schema.getSchemaId(), schema.getSchemaName(), table.tableId.seq, tableName, + schema.getSchemaId(), schema.getSchemaName(), table, originIndexName, sqlAlterRenameIndex.toIndexName); RootCalciteSchema rootCalciteSchema = (RootCalciteSchema) context.getMutableRootSchema(); RootSnapshotSchema rootSnapshotSchema = (RootSnapshotSchema) rootCalciteSchema.schema; @@ -1741,7 +1752,7 @@ public void execute(SqlAlterTableComment sqlAlterTableComment, CalcitePrepare.Co throw DINGO_RESOURCE.tableNotExists(tableName).ex(); } DdlService.root().alterModifyComment( - schema.getSchemaId(), schema.getSchemaName(), table.tableId.seq, tableName, + schema.getSchemaId(), schema.getSchemaName(), table, sqlAlterTableComment.comment); RootCalciteSchema rootCalciteSchema = (RootCalciteSchema) context.getMutableRootSchema(); RootSnapshotSchema rootSnapshotSchema = (RootSnapshotSchema) rootCalciteSchema.schema; @@ -1760,6 +1771,10 @@ public void execute(SqlAlterDropPart sqlAlterDropPart, CalcitePrepare.Context co = getSchemaAndTableName(sqlAlterDropPart.table, context); final String tableName = Parameters.nonNull(schemaTableName.right, "table name"); final SubSnapshotSchema schema = Parameters.nonNull(schemaTableName.left, "table schema"); + SchemaInfo schemaInfo = schema.getSchemaInfo(schema.getSchemaName()); + if (schemaInfo == null) { + throw DINGO_RESOURCE.unknownSchema(schema.getSchemaName()).ex(); + } Table table = schema.getTableInfo(tableName); if (table == null) { throw DINGO_RESOURCE.tableNotExists(tableName).ex(); @@ -1774,9 +1789,18 @@ public void execute(SqlAlterDropPart sqlAlterDropPart, CalcitePrepare.Context co throw DingoErrUtil.newStdErr(ErrDropPartitionNonExistent); } DdlService.root().alterTableDropPart( - schema.getSchemaId(), schema.getSchemaName(), - table.tableId.seq, tableName, part); + schemaInfo, + table, part); + RootCalciteSchema rootCalciteSchema = (RootCalciteSchema) context.getMutableRootSchema(); + RootSnapshotSchema rootSnapshotSchema = (RootSnapshotSchema) rootCalciteSchema.schema; + SchemaDiff diff = SchemaDiff.builder() + .schemaId(schema.getSchemaId()) + .tableId(table.getTableId().seq) + .type(ActionType.ActionDropTablePartition) + .build(); + diff.setTableName(tableName); + rootSnapshotSchema.applyDiff(diff); } public void execute(SqlAlterTruncatePart sqlAlterTruncatePart, CalcitePrepare.Context context) { @@ -1785,6 +1809,10 @@ public void execute(SqlAlterTruncatePart sqlAlterTruncatePart, CalcitePrepare.Co = getSchemaAndTableName(sqlAlterTruncatePart.table, context); final String tableName = Parameters.nonNull(schemaTableName.right, "table name"); final SubSnapshotSchema schema = Parameters.nonNull(schemaTableName.left, "table schema"); + SchemaInfo schemaInfo = schema.getSchemaInfo(schema.getSchemaName()); + if (schemaInfo == null) { + throw DINGO_RESOURCE.unknownSchema(schema.getSchemaName()).ex(); + } Table table = schema.getTableInfo(tableName); if (table == null) { throw DINGO_RESOURCE.tableNotExists(tableName).ex(); @@ -1799,6 +1827,17 @@ public void execute(SqlAlterTruncatePart sqlAlterTruncatePart, CalcitePrepare.Co if (noneMatch) { throw DingoErrUtil.newStdErr(ErrDropPartitionNonExistent); } + DdlService.root().alterTableTruncatePart(schemaInfo, table, part); + + RootCalciteSchema rootCalciteSchema = (RootCalciteSchema) context.getMutableRootSchema(); + RootSnapshotSchema rootSnapshotSchema = (RootSnapshotSchema) rootCalciteSchema.schema; + SchemaDiff diff = SchemaDiff.builder() + .schemaId(schema.getSchemaId()) + .tableId(table.getTableId().seq) + .type(ActionType.ActionTruncateTablePartition) + .build(); + diff.setTableName(tableName); + rootSnapshotSchema.applyDiff(diff); } public void execute(SqlAlterExchangePart sqlAlterExchangePart, CalcitePrepare.Context context) { diff --git a/dingo-calcite/src/main/java/io/dingodb/calcite/executor/ShowCreateTableExecutor.java b/dingo-calcite/src/main/java/io/dingodb/calcite/executor/ShowCreateTableExecutor.java index 6e60db68bc..c112fa2465 100644 --- a/dingo-calcite/src/main/java/io/dingodb/calcite/executor/ShowCreateTableExecutor.java +++ b/dingo-calcite/src/main/java/io/dingodb/calcite/executor/ShowCreateTableExecutor.java @@ -45,22 +45,37 @@ public class ShowCreateTableExecutor extends QueryExecutor { private String schemaName; private String tableName; + private boolean isView; + public ShowCreateTableExecutor(SqlNode sqlNode, String defaultSchemaName) { SqlShowCreateTable showCreateTable = (SqlShowCreateTable) sqlNode; SqlIdentifier tableIdentifier = showCreateTable.tableIdentifier; if (tableIdentifier.names.size() == 1) { - this.schemaName = defaultSchemaName; + this.schemaName = defaultSchemaName.toUpperCase(); tableName = tableIdentifier.names.get(0); } else if (tableIdentifier.names.size() == 2) { this.schemaName = tableIdentifier.names.get(0).toUpperCase(); tableName = tableIdentifier.names.get(1); } + InfoSchema is = DdlService.root().getIsLatest(); + assert schemaName != null; + Table table = is.getTable(schemaName, tableName); + if (table == null) { + String errorKey = schemaName + "." + tableName; + throw DingoResource.DINGO_RESOURCE.tableNotExists(errorKey).ex(); + } + isView = table.getTableType().equalsIgnoreCase("view"); } @Override public Iterator getIterator() { List createTableList = new ArrayList<>(); - String createTable = getCreateTable(); + String createTable; + if (!isView) { + createTable = getCreateTable(); + } else { + createTable = getCreateView(); + } if (StringUtils.isNotBlank(createTable)) { Object[] tuples = new Object[]{tableName, createTable}; createTableList.add(tuples); @@ -72,18 +87,39 @@ public Iterator getIterator() { @Override public List columns() { List columns = new ArrayList<>(); - columns.add("Table"); - columns.add("Create Table"); + if (!isView) { + columns.add("Table"); + columns.add("Create Table"); + } else { + columns.add("View"); + columns.add("Create View"); + } return columns; } + private String getCreateView() { + InfoSchema is = DdlService.root().getIsLatest(); + Table table = is.getTable(schemaName, tableName); + StringBuilder createTableSqlStr = new StringBuilder(); + createTableSqlStr.append("CREATE "); + String alg = table.getProperties().getProperty("algorithm"); + createTableSqlStr.append("ALGORITHM=").append(alg); + String user = table.getProperties().getProperty("user"); + String host = table.getProperties().getProperty("host"); + createTableSqlStr.append(" DEFINER=").append(user).append("@").append(host); + String securityType = table.getProperties().getProperty("security_type"); + createTableSqlStr.append(" SQL SECURITY ").append(securityType); + createTableSqlStr.append(" VIEW "); + createTableSqlStr.append("`").append(tableName).append('`'); + createTableSqlStr.append(" AS "); + createTableSqlStr.append(table.createSql); + return createTableSqlStr.toString(); + } + private String getCreateTable() { InfoSchema is = DdlService.root().getIsLatest(); - Table table = is.getTable(schemaName.toUpperCase(), tableName); - if (table == null) { - String errorKey = schemaName + "." + tableName; - throw DingoResource.DINGO_RESOURCE.tableNotExists(errorKey).ex(); - } + Table table = is.getTable(schemaName, tableName); + StringBuilder createTableSqlStr = new StringBuilder(); createTableSqlStr.append("CREATE ").append("TABLE ").append("`").append(tableName.toUpperCase()).append("`"); createTableSqlStr.append("("); @@ -214,6 +250,9 @@ private String getCreateTable() { createTableSqlStr.append(")"); createTableSqlStr.append(" engine=").append(table.getEngine()).append(" "); createTableSqlStr.append(" replica=").append(table.getReplica()); + if (table.getComment() != null) { + createTableSqlStr.append(" comment=").append(table.getComment()); + } appendPart(table, createTableSqlStr); return createTableSqlStr.toString(); } diff --git a/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/ColumnOption.java b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/ColumnOption.java new file mode 100644 index 0000000000..f32edaca80 --- /dev/null +++ b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/ColumnOption.java @@ -0,0 +1,49 @@ +/* + * Copyright 2021 DataCanvas + * + * Licensed 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 io.dingodb.calcite.grammar.ddl; + +import org.apache.calcite.schema.ColumnStrategy; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; + +public class ColumnOption { + public boolean nullable; + public boolean autoIncrement; + public boolean primaryKey; + public boolean clustered = true; + public boolean global = true; + + public boolean uniqueKey; + public SqlNode expression; + public boolean serialDefaultVal; + public String comment; + public Constraint constraint; + public SqlNodeList refColumnList; + public SqlIdentifier refTable; + public String updateRefOpt; + public String deleteRefOpt; + public String collate = "utf8_bin"; + public String columnFormat; + public String storage; + public int autoRandom; + public boolean visible; + public ColumnStrategy strategy; + + public ColumnOption() { + } +} diff --git a/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/Constraint.java b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/Constraint.java new file mode 100644 index 0000000000..ed994704e7 --- /dev/null +++ b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/Constraint.java @@ -0,0 +1,27 @@ +/* + * Copyright 2021 DataCanvas + * + * Licensed 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 io.dingodb.calcite.grammar.ddl; + +import org.apache.calcite.sql.SqlNode; + +public class Constraint { + public SqlNode name; + public SqlNode expression; + public boolean constraintNot; + public String constraintOpt; + +} diff --git a/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlCreateView.java b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlCreateView.java index 05964df6a8..b52384777c 100644 --- a/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlCreateView.java +++ b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlCreateView.java @@ -60,8 +60,8 @@ public DingoSqlCreateView( this.name = (SqlIdentifier) Objects.requireNonNull(name, "name"); this.columnList = columnList; this.query = (SqlNode)Objects.requireNonNull(query, "query"); - this.security = security; - this.alg = alg; + this.security = security == null ? "" : security; + this.alg = alg == null ? "" : security; this.definer = definer; this.host = host; this.checkOpt = checkOpt; diff --git a/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlDdlNodes.java b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlDdlNodes.java index 4a33a0b1c3..57c9524c9d 100644 --- a/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlDdlNodes.java +++ b/dingo-calcite/src/main/java/io/dingodb/calcite/grammar/ddl/DingoSqlDdlNodes.java @@ -85,4 +85,15 @@ public static DingoSqlColumn createColumn( return new DingoSqlColumn(pos, name, dataType, expression, strategy, autoIncrement, comment, primary, collate); } + public static DingoSqlColumn createColumn( + SqlParserPos pos, + SqlIdentifier name, + SqlDataTypeSpec dataType, + ColumnOption columnOption + ) { + return new DingoSqlColumn(pos, name, dataType, columnOption.expression, + columnOption.strategy, columnOption.autoIncrement, columnOption.comment, columnOption.primaryKey, + columnOption.collate); + } + } diff --git a/dingo-calcite/src/test/java/io/dingodb/calcite/TestCreateTable.java b/dingo-calcite/src/test/java/io/dingodb/calcite/SqlSyntaxVerification.java similarity index 85% rename from dingo-calcite/src/test/java/io/dingodb/calcite/TestCreateTable.java rename to dingo-calcite/src/test/java/io/dingodb/calcite/SqlSyntaxVerification.java index cdc845de22..f06a761a6a 100644 --- a/dingo-calcite/src/test/java/io/dingodb/calcite/TestCreateTable.java +++ b/dingo-calcite/src/test/java/io/dingodb/calcite/SqlSyntaxVerification.java @@ -20,14 +20,17 @@ import io.dingodb.calcite.grammar.ddl.SqlAlterAddConstraint; import io.dingodb.calcite.grammar.ddl.SqlAlterAddForeign; import io.dingodb.calcite.grammar.ddl.SqlAlterAddIndex; -import io.dingodb.calcite.grammar.ddl.SqlAlterChangeColumn; import io.dingodb.calcite.grammar.ddl.SqlAlterColumn; import io.dingodb.calcite.grammar.ddl.SqlAlterConstraint; import io.dingodb.calcite.grammar.ddl.SqlAlterDropConstraint; import io.dingodb.calcite.grammar.ddl.SqlAlterDropForeign; import io.dingodb.calcite.grammar.ddl.SqlAlterModifyColumn; import io.dingodb.calcite.grammar.ddl.SqlCreateIndex; +import io.dingodb.calcite.grammar.ddl.SqlCreateTenant; +import io.dingodb.calcite.grammar.ddl.SqlCreateUser; +import io.dingodb.calcite.grammar.ddl.SqlDropUser; import io.dingodb.calcite.grammar.ddl.SqlGrant; +import io.dingodb.calcite.grammar.ddl.SqlRevoke; import io.dingodb.calcite.grammar.ddl.SqlSetPassword; import org.apache.calcite.sql.SqlIdentifier; import org.apache.calcite.sql.SqlKind; @@ -40,37 +43,9 @@ import org.apache.calcite.sql.parser.dingo.DingoSqlParserImpl; import org.junit.jupiter.api.Test; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - import static io.dingodb.calcite.DingoParser.PARSER_CONFIG; -public class TestCreateTable { - - public static void parseCreateTable(SqlCreateTable create) { - List keyList = null; - for (SqlNode sqlNode : create.columnList) { - if (sqlNode instanceof SqlKeyConstraint) { - SqlKeyConstraint constraint = (SqlKeyConstraint) sqlNode; - if (constraint.getOperator().getKind() == SqlKind.PRIMARY_KEY) { - // The 0th element is the name of the constraint - keyList = ((SqlNodeList) constraint.getOperandList().get(1)).getList().stream() - .map(t -> ((SqlIdentifier) Objects.requireNonNull(t)).getSimple()) - .collect(Collectors.toList()); - break; - } - } - } - - for (String key : keyList) { - System.out.println("---> primary key:" + key); - } - } - - public static void main(String[] args) { - System.out.println("---"); - } +public class SqlSyntaxVerification { @Test public void createUser() { @@ -79,9 +54,8 @@ public void createUser() { SqlParser parser = SqlParser.create(sql, config); try { SqlNode sqlNode = parser.parseStmt(); - System.out.println("---> sqlNode:" + sqlNode); + assert sqlNode instanceof SqlCreateUser; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -93,27 +67,12 @@ public void createTenant() { SqlParser parser = SqlParser.create(sql, config); try { SqlNode sqlNode = parser.parseStmt(); - System.out.println("---> sqlNode: " + sqlNode); + assert sqlNode instanceof SqlCreateTenant; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(); } } - @Test - public void createUserWithLocation() { - String sql = "CREATE USER 'gj'@localhost IDENTIFIED BY 'abc'"; - SqlParser.Config config = SqlParser.config().withParserFactory(DingoSqlParserImpl::new); - SqlParser parser = SqlParser.create(sql, config); - try { - SqlNode sqlNode = parser.parseStmt(); - System.out.println("---> sqlNode:" + sqlNode); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - @Test public void dropUser() { String sql = "drop USER gj@localhost"; @@ -121,9 +80,8 @@ public void dropUser() { SqlParser parser = SqlParser.create(sql, config); try { SqlNode sqlNode = parser.parseStmt(); - System.out.println("---> sqlNode:" + sqlNode); + assert sqlNode instanceof SqlDropUser; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -135,9 +93,8 @@ public void grant() { SqlParser parser = SqlParser.create(sql, config); try { SqlNode sqlNode = parser.parseStmt(); - System.out.println("---> sqlNode:" + sqlNode); + assert sqlNode instanceof SqlGrant; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -149,11 +106,8 @@ public void grant2() { SqlParser parser = SqlParser.create(sql, config); try { SqlNode sqlNode = parser.parseStmt(); - SqlGrant sqlGrant = (SqlGrant) sqlNode; - System.out.println(sqlGrant.privileges.size()); - System.out.println("---> sqlNode:" + sqlNode); + assert sqlNode instanceof SqlGrant; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -165,9 +119,8 @@ public void revoke() { SqlParser parser = SqlParser.create(sql, config); try { SqlNode sqlNode = parser.parseStmt(); - System.out.println("---> sqlNode:" + sqlNode); + assert sqlNode instanceof SqlRevoke; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -183,7 +136,6 @@ public void addConstraint() { SqlNode sqlNode = parser.parseStmt(); assert sqlNode instanceof SqlAlterAddConstraint; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -212,7 +164,6 @@ public void addUniqueIndex() { SqlNode sqlNode = parser.parseStmt(); assert sqlNode instanceof SqlAlterAddIndex; } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -352,7 +303,7 @@ public void sqlAlterColumnSetDefault() { @Test public void sqlAlterChangeColumn() { - String sql = "ALTER TABLE `config_info` MODIFY COLUMN `src_ip` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT 'source ip'"; + String sql = "ALTER TABLE `config_info` MODIFY COLUMN `src_ip` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT 'source ip' first"; SqlParser parser = SqlParser.create(sql, PARSER_CONFIG); try { SqlNode sqlNode = parser.parseStmt(); @@ -380,8 +331,8 @@ public void sqlCreateIndex() { } @Test - public void sqlAlterAddIndex() { - String sql = "alter table t1 add fulltext index ix(age) btree comment 'commitsss' algorithm=inplace lock=none"; + public void sqlAlterAddFulltextKey() { + String sql = "alter table t1 add fulltext key ix(age) btree comment 'commitsss' algorithm=inplace lock=none"; SqlParser parser = SqlParser.create(sql, PARSER_CONFIG); try { SqlNode sqlNode = parser.parseStmt(); @@ -403,4 +354,33 @@ public void sqlCreateView() { } } + @Test + public void sqlCreateFullTextIndex() { + String sql = "alter table t1 add fulltext key ix1 (age)"; + SqlParser parser = SqlParser.create(sql, PARSER_CONFIG); + try { + SqlNode sqlNode = parser.parseStmt(); + assert sqlNode instanceof SqlAlterAddIndex; + SqlAlterAddIndex sqlAlterAddIndex = (SqlAlterAddIndex) sqlNode; + assert sqlAlterAddIndex.getIndexDeclaration().mode.equalsIgnoreCase("fulltext"); + assert !sqlAlterAddIndex.getIndexDeclaration().unique; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Test + public void sqlAlterAddIndex() { + String sql = "alter table t1 add index if not exists ix1 (age)"; + SqlParser parser = SqlParser.create(sql, PARSER_CONFIG); + try { + SqlNode sqlNode = parser.parseStmt(); + assert sqlNode instanceof SqlAlterAddIndex; + SqlAlterAddIndex sqlAlterAddIndex = (SqlAlterAddIndex) sqlNode; + assert !sqlAlterAddIndex.getIndexDeclaration().unique; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } diff --git a/dingo-exec/src/main/java/io/dingodb/exec/operator/InfoSchemaScanOperator.java b/dingo-exec/src/main/java/io/dingodb/exec/operator/InfoSchemaScanOperator.java index 64a2f35b54..4641f97db2 100644 --- a/dingo-exec/src/main/java/io/dingodb/exec/operator/InfoSchemaScanOperator.java +++ b/dingo-exec/src/main/java/io/dingodb/exec/operator/InfoSchemaScanOperator.java @@ -400,7 +400,8 @@ public static Iterator getView() { return tables.stream() .filter(td -> td.getTableType().equalsIgnoreCase("VIEW")) .map(td -> { - String checkOpt = td.getProperties().getProperty("check_option", ""); + String checkOpt = td.getProperties() + .getProperty("check_option", "").toUpperCase(); String isUpdaTable = "NO"; String user = td.getProperties().getProperty("user", ""); String host = td.getProperties().getProperty("host", ""); diff --git a/dingo-executor/src/main/java/io/dingodb/server/executor/ddl/DdlRollBack.java b/dingo-executor/src/main/java/io/dingodb/server/executor/ddl/DdlRollBack.java index 921589f18f..989b867c80 100644 --- a/dingo-executor/src/main/java/io/dingodb/server/executor/ddl/DdlRollBack.java +++ b/dingo-executor/src/main/java/io/dingodb/server/executor/ddl/DdlRollBack.java @@ -21,6 +21,7 @@ import io.dingodb.common.ddl.JobState; import io.dingodb.common.log.LogUtils; import io.dingodb.common.meta.SchemaInfo; +import io.dingodb.common.mysql.DingoErrUtil; import io.dingodb.common.table.TableDefinition; import io.dingodb.common.util.Pair; import io.dingodb.meta.InfoSchemaService; @@ -31,7 +32,7 @@ import io.dingodb.store.proxy.mapper.Mapper; import lombok.extern.slf4j.Slf4j; -import java.util.Base64; +import static io.dingodb.common.mysql.error.ErrorCode.ErrCancelledDDLJob; @Slf4j public final class DdlRollBack { @@ -62,7 +63,8 @@ public static Pair convertJob2RollbackJob(DdlJob job) { break; default: job.setState(JobState.jobStateCancelled); - error = "ErrCancelledDDLJob"; + job.setDingoErr(DingoErrUtil.newInternalErr(ErrCancelledDDLJob)); + error = job.getDingoErr().errorMsg; } if (error != null) { if (job.getError() == null) { @@ -94,7 +96,8 @@ public static String rollingbackDropTableOrView(DdlJob ddlJob) { } if (res.getKey().getTableDefinition().getSchemaState() == SchemaState.SCHEMA_PUBLIC) { ddlJob.setState(JobState.jobStateCancelled); - return "ErrCancelledDDLJob"; + ddlJob.setDingoErr(DingoErrUtil.newInternalErr(ErrCancelledDDLJob)); + return ddlJob.getDingoErr().errorMsg; } ddlJob.setState(JobState.jobStateRunning); return null; diff --git a/dingo-meta-api/src/main/java/io/dingodb/meta/DdlService.java b/dingo-meta-api/src/main/java/io/dingodb/meta/DdlService.java index a8d73c337d..bbf43a0ca2 100644 --- a/dingo-meta-api/src/main/java/io/dingodb/meta/DdlService.java +++ b/dingo-meta-api/src/main/java/io/dingodb/meta/DdlService.java @@ -55,8 +55,8 @@ default void addColumn(SchemaInfo schemaInfo, Table table, ColumnDefinition colu } default void dropColumn( - long schemaId, String schemaName, - Long tableId, String tableName, String column, + SchemaInfo schemaInfo, + Table table, String column, String markDel, String relatedIndex, String connId ) { @@ -75,16 +75,16 @@ default void changeColumn( } - default void renameTable(long schemaId, String schemaName, long tableId, String tableName, String toName) { + default void renameTable(long schemaId, String schemaName, Table table, String toName) { } - default void renameIndex(long schemaId, String schemaName, long tableId, String tableName, + default void renameIndex(long schemaId, String schemaName, Table table, String originIndexName, String toIndexName) { } - default void alterModifyComment(long schemaId, String schemaName, long tableId, String tableName, String comment) { + default void alterModifyComment(long schemaId, String schemaName, Table table, String comment) { } @@ -127,22 +127,22 @@ default void resetAutoInc() { } default void alterIndexVisible( - long schemaId, String schemaName, long tableId, String tableName, String index, boolean invisible + long schemaId, String schemaName, Table table, String index, boolean invisible ) { } default void alterTableAddPart( - long schemaId, String schemaName, long tableId, String tableName, PartitionDetailDefinition part + long schemaId, String schemaName, Table table, PartitionDetailDefinition part ) { } - default void alterTableDropPart(long schemaId, String schemaName, long tableId, String tableName, String part) { + default void alterTableDropPart(SchemaInfo schemaInfo, Table table, String part) { } - default void alterTableTruncatePart(long schemaId, String schemaName, long tableId, String tableName, String part) { + default void alterTableTruncatePart(SchemaInfo schemaInfo, Table table, String part) { } } diff --git a/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/ddl/DdlService.java b/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/ddl/DdlService.java index 69fde8daba..0f4b60be70 100644 --- a/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/ddl/DdlService.java +++ b/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/ddl/DdlService.java @@ -49,12 +49,12 @@ public io.dingodb.meta.DdlService root() { } } - public void renameTable(long schemaId, String schemaName, long tableId, String tableName, String toName) { + public void renameTable(long schemaId, String schemaName, Table table, String toName) { DdlJob job = DdlJob.builder() .schemaId(schemaId) .schemaName(schemaName) - .tableId(tableId) - .tableName(tableName) + .tableId(table.tableId.seq) + .tableName(table.getName()) .actionType(ActionType.ActionRenameTable) .build(); List args = new ArrayList<>(); @@ -63,13 +63,13 @@ public void renameTable(long schemaId, String schemaName, long tableId, String t DdlHandler.doDdlJob(job); } - public void renameIndex(long schemaId, String schemaName, long tableId, String tableName, + public void renameIndex(long schemaId, String schemaName, Table table, String originIndexName, String toIndexName) { DdlJob job = DdlJob.builder() .schemaId(schemaId) .schemaName(schemaName) - .tableId(tableId) - .tableName(tableName) + .tableId(table.tableId.seq) + .tableName(table.getName()) .actionType(ActionType.ActionRenameIndex) .build(); List args = new ArrayList<>(); @@ -79,12 +79,12 @@ public void renameIndex(long schemaId, String schemaName, long tableId, String t DdlHandler.doDdlJob(job); } - public void alterModifyComment(long schemaId, String schemaName, long tableId, String tableName, String comment) { + public void alterModifyComment(long schemaId, String schemaName, Table table, String comment) { DdlJob job = DdlJob.builder() .schemaId(schemaId) .schemaName(schemaName) - .tableId(tableId) - .tableName(tableName) + .tableId(table.tableId.seq) + .tableName(table.getName()) .actionType(ActionType.ActionModifyTableComment) .build(); List args = new ArrayList<>(); @@ -189,13 +189,13 @@ public void resetAutoInc() { } public void alterIndexVisible( - long schemaId, String schemaName, long tableId, String tableName, String index, boolean invisible + long schemaId, String schemaName, Table table, String index, boolean invisible ) { DdlJob job = DdlJob.builder() .schemaId(schemaId) - .tableId(tableId) + .tableId(table.tableId.seq) .schemaName(schemaName) - .tableName(tableName) + .tableName(table.getName()) .actionType(ActionType.ActionAlterIndexVisibility) .build(); List args = new ArrayList<>(); @@ -206,13 +206,13 @@ public void alterIndexVisible( } public void alterTableAddPart( - long schemaId, String schemaName, long tableId, String tableName, PartitionDetailDefinition part + long schemaId, String schemaName, Table table, PartitionDetailDefinition part ) { DdlJob job = DdlJob.builder() .schemaId(schemaId) - .tableId(tableId) + .tableId(table.tableId.seq) .schemaName(schemaName) - .tableName(tableName) + .tableName(table.getName()) .actionType(ActionType.ActionAddTablePartition) .build(); List args = new ArrayList<>(); @@ -221,12 +221,12 @@ public void alterTableAddPart( DdlHandler.doDdlJob(job); } - public void alterTableDropPart(long schemaId, String schemaName, long tableId, String tableName, String part) { + public void alterTableDropPart(SchemaInfo schemaInfo, Table table, String part) { DdlJob job = DdlJob.builder() - .schemaId(schemaId) - .tableId(tableId) - .schemaName(schemaName) - .tableName(tableName) + .schemaId(schemaInfo.getSchemaId()) + .tableId(table.tableId.seq) + .schemaName(schemaInfo.getName()) + .tableName(table.getName()) .schemaState(SchemaState.SCHEMA_PUBLIC) .actionType(ActionType.ActionDropTablePartition) .build(); @@ -236,13 +236,14 @@ public void alterTableDropPart(long schemaId, String schemaName, long tableId, S DdlHandler.doDdlJob(job); } - public void alterTableTruncatePart(long schemaId, String schemaName, long tableId, String tableName, String part) { + public void alterTableTruncatePart(SchemaInfo schemaInfo, Table table, String part) { DdlJob job = DdlJob.builder() - .schemaId(schemaId) - .tableId(tableId) - .schemaName(schemaName) - .tableName(tableName) + .schemaId(schemaInfo.getSchemaId()) + .tableId(table.getTableId().seq) + .schemaName(schemaInfo.getName()) + .tableName(table.getName()) .actionType(ActionType.ActionTruncateTablePartition) + .schemaState(SchemaState.SCHEMA_PUBLIC) .build(); List args = new ArrayList<>(); args.add(part); diff --git a/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/meta/MetaService.java b/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/meta/MetaService.java index 23d7af178c..9f6267a954 100644 --- a/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/meta/MetaService.java +++ b/dingo-store-proxy/src/main/java/io/dingodb/store/proxy/meta/MetaService.java @@ -1163,10 +1163,10 @@ public boolean dropTable(long tenantId, long schemaId, String tableName, long jo boolean autoInc = table.getColumns().stream().anyMatch(Column::isAutoIncrement); long ts = TsoService.getDefault().tso(); - dropRegionByTable(table.getTableId(), jobId, ts, autoInc); List indexes = null; if (!"view".equalsIgnoreCase(table.getTableType())) { + dropRegionByTable(table.getTableId(), jobId, ts, autoInc); indexes = table.getIndexes(); if (indexes != null) { for (IndexTable index : indexes) {