diff --git a/dingo-calcite/src/main/codegen/config.fmpp b/dingo-calcite/src/main/codegen/config.fmpp index 49075929a2..6cedf9bf14 100644 --- a/dingo-calcite/src/main/codegen/config.fmpp +++ b/dingo-calcite/src/main/codegen/config.fmpp @@ -67,6 +67,7 @@ data: { "io.dingodb.calcite.grammar.ddl.SqlAnalyze" "io.dingodb.calcite.grammar.ddl.SqlCreateTenant" "io.dingodb.calcite.grammar.ddl.SqlCreateSchema" + "io.dingodb.calcite.grammar.ddl.DingoSqlCreateView" "io.dingodb.calcite.grammar.ddl.SqlCreateUser" "io.dingodb.calcite.grammar.ddl.SqlCreateIndex" "io.dingodb.calcite.grammar.ddl.SqlCreateVectorIndex" @@ -161,7 +162,10 @@ data: { # List of new keywords. Example: "DATABASES", "TABLES". If the keyword is # not a reserved keyword, add it to the 'nonReservedKeywords' section. keywords: [ + "ALGORITHM" + "INPLACE" "IF" + "COPY" "MATERIALIZED" "STORED" "VIRTUAL" @@ -178,6 +182,7 @@ data: { "ENGINE" "ENGINES" "EXCHANGE" + "EXCLUSIVE" "EXECUTOR" "EXECUTORS" "ENFORCED" @@ -208,6 +213,7 @@ data: { "SCAN" "SSL" "STARTING" + "SHARED" "STATUS" "TABLES" "STARTTS" @@ -228,6 +234,7 @@ data: { "SAMPLES" "SAMPLERATE" "PESSIMISTIC" + "PARSER" "OPTIMISTIC" "BLOCKS" "HASH" @@ -260,6 +267,13 @@ data: { "CACHE" "MODIFY" "CHANGE" + "SPATIAL" + "FULLTEXT" + "KEY_BLOCK_SIZE" + "BTREE" + "RTREE" + "UNDEFINED" + "TEMPTABLE" ] # List of non-reserved keywords to add; diff --git a/dingo-calcite/src/main/codegen/includes/AlterTable.ftl b/dingo-calcite/src/main/codegen/includes/AlterTable.ftl index 500429b12c..9e05666938 100644 --- a/dingo-calcite/src/main/codegen/includes/AlterTable.ftl +++ b/dingo-calcite/src/main/codegen/includes/AlterTable.ftl @@ -64,6 +64,16 @@ SqlAlterSchema SqlAlterSchema(Span s, String scope): { } } +SqlAlterTable SqlAlterIgnoreTable(Span s, String scope): { + SqlAlterTable alterTable = null; +} { + + alterTable = SqlAlterTable(s, scope) + { + return alterTable; + } +} + SqlAlterTable SqlAlterTable(Span s, String scope): { SqlIdentifier id; SqlAlterTable alterTable = null; @@ -81,6 +91,10 @@ SqlAlterTable SqlAlterTable(Span s, String scope): { alterTable = addColumn(s, scope, id) | alterTable = addConstraint(s, scope, id) + | + alterTable = addIndexByMode(s, scope, id, "fulltext") + | + alterTable = addIndexByMode(s, scope, id, "spetail") ) | @@ -166,6 +180,7 @@ SqlAlterTable addColumn(Span s, String scope, SqlIdentifier id): { boolean primary = false; String comment = ""; boolean autoInc = false; + String collate = "utf8_bin"; } { columnId = SimpleIdentifier() @@ -188,6 +203,8 @@ SqlAlterTable addColumn(Span s, String scope, SqlIdentifier id): { { primary=true; } | comment = dingoIdentifier() + | + { collate = this.getNextToken().image;} | { autoInc = true;} | @@ -199,7 +216,7 @@ SqlAlterTable addColumn(Span s, String scope, SqlIdentifier id): { : ColumnStrategy.NOT_NULLABLE; } return new SqlAlterAddColumn(s.end(this), id, DingoSqlDdlNodes.createColumn( - s.end(this), columnId, type.withNullable(nullable), e, strategy, autoInc, comment, primary + s.end(this), columnId, type.withNullable(nullable), e, strategy, autoInc, comment, primary, collate )); } } @@ -233,17 +250,20 @@ SqlAlterTable addIndex(Span s, String scope, SqlIdentifier id): { int replica = 0; String indexType = "scalar"; SqlNodeList withColumnList = null; - final SqlNodeList columnList; + List columnList; String engine = null; + Properties prop = new Properties(); + String indexAlg = null; + String indexLockOpt = null; } { { s.add(this); } { index = getNextToken().image; } ( - { indexType = "vector"; } columnList = ParenthesizedSimpleIdentifierList() + { indexType = "vector"; } columnList = indexColumns() | - { indexType = "text"; } columnList = ParenthesizedSimpleIdentifierList() + { indexType = "text"; } columnList = indexColumns() | - [] columnList = ParenthesizedSimpleIdentifierList() + [] columnList = indexColumns() ) ( withColumnList = ParenthesizedSimpleIdentifierList() @@ -261,11 +281,14 @@ SqlAlterTable addIndex(Span s, String scope, SqlIdentifier id): { | properties = readProperties() )* + prop = indexOption() + [ indexAlg = indexAlg()] + [ indexLockOpt = indexLockOpt()] { return new SqlAlterAddIndex( s.end(this), id, new SqlIndexDeclaration( - s.end(this), index, columnList, withColumnList, properties,partitionDefinition, replica, indexType, engine, false + s.end(this), index, columnList, withColumnList, properties,partitionDefinition, replica, indexType, engine, "", prop, indexAlg, indexLockOpt ) ); } @@ -279,12 +302,15 @@ SqlAlterTable addUniqueIndex(Span s, String scope, SqlIdentifier id): { int replica = 0; String indexType = "scalar"; SqlNodeList withColumnList = null; - final SqlNodeList columnList; + List columnList; String engine = null; + Properties prop = null; + String indexAlg = null; + String indexLockOpt = null; } { [][] { s.add(this); } { index = getNextToken().image; } - [] columnList = ParenthesizedSimpleIdentifierList() + [] columnList = indexColumns() ( withColumnList = ParenthesizedSimpleIdentifierList() | @@ -301,16 +327,66 @@ SqlAlterTable addUniqueIndex(Span s, String scope, SqlIdentifier id): { | properties = readProperties() )* + prop = indexOption() + [ indexAlg = indexAlg()] + [ indexLockOpt = indexLockOpt()] { return new SqlAlterAddIndex( s.end(this), id, new SqlIndexDeclaration( - s.end(this), index, columnList, withColumnList, properties,partitionDefinition, replica, indexType, engine, true + s.end(this), index, columnList, withColumnList, properties,partitionDefinition, replica, indexType, engine, "unique", prop, indexAlg, indexLockOpt ) ); } } +SqlAlterTable addIndexByMode(Span s, String scope, SqlIdentifier id, String mode): { + final String index; + Boolean autoIncrement = false; + Properties properties = null; + PartitionDefinition partitionDefinition = null; + int replica = 0; + String indexType = "scalar"; + SqlNodeList withColumnList = null; + List columnList; + String engine = null; + Properties prop = null; + String indexAlg = null; + String indexLockOpt = null; +} { + { s.add(this); } + { index = getNextToken().image; } + columnList = indexColumns() + ( + withColumnList = ParenthesizedSimpleIdentifierList() + | + engine = dingoIdentifier() { if (engine.equalsIgnoreCase("innodb")) { engine = "TXN_LSM";} } + | + + { + partitionDefinition = new PartitionDefinition(); + partitionDefinition.setFuncName(getNextToken().image); + partitionDefinition.setDetails(readPartitionDetails()); + } + | + {replica = Integer.parseInt(getNextToken().image);} + | + properties = readProperties() + )* + prop = indexOption() + [ indexAlg = indexAlg()] + [ indexLockOpt = indexLockOpt()] + { + return new SqlAlterAddIndex( + s.end(this), id, + new SqlIndexDeclaration( + s.end(this), index, columnList, withColumnList, properties,partitionDefinition, replica, indexType, engine, mode, prop, indexAlg, indexLockOpt + ) + ); + } +} + + SqlAlterTable alterIndex(Span s, String scope, SqlIdentifier id): { final String index; Properties properties = new Properties(); @@ -501,6 +577,7 @@ SqlAlterTable modifyColumn(Span s, String scope, SqlIdentifier id, SqlAlterTable PartitionDefinition partitionDefinition = null; int replica = 0; String engine = null; + String collate = "utf8_bin"; String indexType = "scalar"; Boolean primaryKey = false; String comment = ""; @@ -508,6 +585,7 @@ SqlAlterTable modifyColumn(Span s, String scope, SqlIdentifier id, SqlAlterTable SqlIdentifier refTable = null; String updateRefOpt = null; String deleteRefOpt = null; + SqlIdentifier afterCol = null; } { name = SimpleIdentifier() ( @@ -540,6 +618,8 @@ SqlAlterTable modifyColumn(Span s, String scope, SqlIdentifier id, SqlAlterTable (|) { comment = token.image; } | + | + { collate = this.getNextToken().image; } | { s.add(this); } [name = SimpleIdentifier()] checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) @@ -553,20 +633,22 @@ SqlAlterTable modifyColumn(Span s, String scope, SqlIdentifier id, SqlAlterTable ) )* )* + [ 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); + columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), name, type.withNullable(nullable), e, strategy, autoIncrement, comment, primaryKey, collate); } ) { if (alterTable == null) { - return new SqlAlterModifyColumn(s.end(this), id, columnDec); + return new SqlAlterModifyColumn(s.end(this), id, columnDec, afterCol); } else { SqlAlterModifyColumn alterModifyCol = (SqlAlterModifyColumn)alterTable; alterModifyCol.addSqlColumn(columnDec); + alterModifyCol.addAlterColumn(afterCol); return alterModifyCol; } } @@ -617,6 +699,7 @@ SqlAlterTable changeColumn(Span s, String scope, SqlIdentifier id): { SqlIdentifier refTable = null; String updateRefOpt = null; String deleteRefOpt = null; + String collate = "utf8_bin"; } { name = SimpleIdentifier() newName = SimpleIdentifier() ( @@ -649,6 +732,8 @@ SqlAlterTable changeColumn(Span s, String scope, SqlIdentifier id): { (|) { comment = token.image; } | + | + { collate = this.getNextToken().image;} | { s.add(this); } [name = SimpleIdentifier()] checkExpr = Expression(ExprContext.ACCEPT_SUB_QUERY) @@ -667,7 +752,7 @@ SqlAlterTable changeColumn(Span s, String scope, SqlIdentifier id): { strategy = nullable ? ColumnStrategy.NULLABLE : ColumnStrategy.NOT_NULLABLE; } - columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), name, type.withNullable(nullable), e, strategy, autoIncrement, comment, primaryKey); + columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), name, type.withNullable(nullable), e, strategy, autoIncrement, comment, primaryKey, collate); } )? { diff --git a/dingo-calcite/src/main/codegen/includes/parserImpls.ftl b/dingo-calcite/src/main/codegen/includes/parserImpls.ftl index 36d178b48a..44ce7e3f64 100644 --- a/dingo-calcite/src/main/codegen/includes/parserImpls.ftl +++ b/dingo-calcite/src/main/codegen/includes/parserImpls.ftl @@ -155,6 +155,10 @@ void TableElement(List list) : SqlIdentifier refTable = null; String updateRefOpt = null; String deleteRefOpt = null; + String collate = "utf8_bin"; + Properties prop = null; + String indexAlg = null; + String indexLockOpt = null; } { LOOKAHEAD(2) id = SimpleIdentifier() @@ -187,7 +191,8 @@ void TableElement(List list) : | (|) { comment = token.image; } | - + { collate = this.getNextToken().image; } + | | { s.add(this); } [name = SimpleIdentifier()] @@ -199,7 +204,7 @@ void TableElement(List list) : strategy = nullable ? ColumnStrategy.NULLABLE : ColumnStrategy.NOT_NULLABLE; } - columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), id, type.withNullable(nullable), e, strategy, autoIncrement, comment, primaryKey); + columnDec = DingoSqlDdlNodes.createColumn(s.add(id).end(this), id, type.withNullable(nullable), e, strategy, autoIncrement, comment, primaryKey, collate); list.add(columnDec); } ) @@ -240,6 +245,9 @@ void TableElement(List list) : | properties = readProperties() )* + prop = indexOption() + [ indexAlg = indexAlg()] + [ indexLockOpt = indexLockOpt()] { list.add(new SqlIndexDeclaration(s.end(this), index, columnList, withColumnList, properties, partitionDefinition, replica, indexType, engine, false)); @@ -267,6 +275,9 @@ void TableElement(List list) : [ {replica = Integer.parseInt(getNextToken().image);} ] + prop = indexOption() + [ indexAlg = indexAlg()] + [ indexLockOpt = indexLockOpt()] | { s.add(this); } columnList = ParenthesizedSimpleIdentifierList() { @@ -602,18 +613,28 @@ Number number(): { ) } + SqlCreate SqlCreateView(Span s, boolean replace) : { final SqlIdentifier id; SqlNodeList columnList = null; final SqlNode query; + String user = null; + String host = null; + String alg = null; + String security = null; + String checkOpt = null; } { + [ (||)] + [ user = strIdent() [ strIdent() { host = token.image; } ]] + [ (|)] id = CompoundIdentifier() [ columnList = ParenthesizedSimpleIdentifierList() ] - query = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY) { - return SqlDdlNodes.createView(s.end(this), replace, id, columnList, - query); + query = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY) + [ ( {checkOpt = "cascaded";}| {checkOpt = "local";})