lsyldliu commented on code in PR #24737: URL: https://github.com/apache/flink/pull/24737#discussion_r1583020783
########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterMaterializedTableFreshness.java: ########## @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlIntervalLiteral; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import java.util.List; + +/** + * SqlNode to describe ALTER MATERIALIZED TABLE [catalogName.] [dataBasesName.]tableName INTERVAL Review Comment: SqlNode to describe ALTER MATERIALIZED TABLE [catalogName.] [dataBasesName.]tableName SET FRESHNESS = INTERVAL ########## flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl: ########## @@ -1773,6 +1773,101 @@ SqlCreate SqlCreateMaterializedTable(Span s, boolean replace, boolean isTemporar } } +/** +* Parses alter materialized table. +*/ + +SqlAlterMaterializedTable SqlAlterMaterializedTable() : +{ + SqlParserPos startPos; + SqlIdentifier tableIdentifier; + SqlNodeList propertyList = SqlNodeList.EMPTY; + SqlNodeList propertyKeyList = SqlNodeList.EMPTY; + SqlNodeList partSpec = null; + SqlNode freshness = null; +} +{ + <ALTER> <MATERIALIZED> <TABLE> { startPos = getPos();} + tableIdentifier = CompoundIdentifier() + ( + <SUSPEND> + { + return new SqlAlterMaterializedTableSuspend(startPos, tableIdentifier); + } Review Comment: ditto ########## flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl: ########## @@ -1773,6 +1773,101 @@ SqlCreate SqlCreateMaterializedTable(Span s, boolean replace, boolean isTemporar } } +/** +* Parses alter materialized table. +*/ + +SqlAlterMaterializedTable SqlAlterMaterializedTable() : +{ + SqlParserPos startPos; + SqlIdentifier tableIdentifier; + SqlNodeList propertyList = SqlNodeList.EMPTY; + SqlNodeList propertyKeyList = SqlNodeList.EMPTY; + SqlNodeList partSpec = null; + SqlNode freshness = null; +} +{ + <ALTER> <MATERIALIZED> <TABLE> { startPos = getPos();} + tableIdentifier = CompoundIdentifier() + ( + <SUSPEND> + { + return new SqlAlterMaterializedTableSuspend(startPos, tableIdentifier); + } + | + <RESUME> + [ <WITH> propertyList = TableProperties() ] + { + return new SqlAlterMaterializedTableResume( + startPos, + tableIdentifier, + propertyList); + } + | + <REFRESH> + [ <PARTITION> { + partSpec = new SqlNodeList(getPos()); + PartitionSpecCommaList(partSpec); + } + ] + { + return new SqlAlterMaterializedTableRefresh( + startPos.plus(getPos()), + tableIdentifier, + partSpec); + } + | + <SET> + ( + <FRESHNESS> <EQ> freshness = Expression(ExprContext.ACCEPT_NON_QUERY) { + if (!(freshness instanceof SqlIntervalLiteral)) { + throw SqlUtil.newContextException( + getPos(), + ParserResource.RESOURCE.unsupportedFreshnessType()); Review Comment: If you want to reuse this exception message, I think we should modify ParserResource#unsupportedFreshnessType message to: "MATERIALIZED TABLE only supports define interval type FRESHNESS.", what do you think? ########## flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl: ########## @@ -1773,6 +1773,101 @@ SqlCreate SqlCreateMaterializedTable(Span s, boolean replace, boolean isTemporar } } +/** +* Parses alter materialized table. +*/ + +SqlAlterMaterializedTable SqlAlterMaterializedTable() : +{ + SqlParserPos startPos; + SqlIdentifier tableIdentifier; + SqlNodeList propertyList = SqlNodeList.EMPTY; + SqlNodeList propertyKeyList = SqlNodeList.EMPTY; + SqlNodeList partSpec = null; Review Comment: ```suggestion SqlNodeList partSpec = SqlNodeList.EMPTY; ``` ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterMaterializedTableOptions.java: ########## @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.flink.sql.parser.SqlUnparseUtils; + +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.util.ImmutableNullableList; + +import java.util.List; + +/** + * SqlNode to describe ALTER MATERIALIZED TABLE [catalog_name.][db_name.]table_name SET REFRESH_MODE Review Comment: typo, this is set options> 'SET ( name=value [, name=value]*)' ########## flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl: ########## @@ -1773,6 +1773,101 @@ SqlCreate SqlCreateMaterializedTable(Span s, boolean replace, boolean isTemporar } } +/** +* Parses alter materialized table. +*/ + Review Comment: Remove blank line ########## flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl: ########## @@ -1773,6 +1773,101 @@ SqlCreate SqlCreateMaterializedTable(Span s, boolean replace, boolean isTemporar } } +/** +* Parses alter materialized table. +*/ + +SqlAlterMaterializedTable SqlAlterMaterializedTable() : +{ + SqlParserPos startPos; + SqlIdentifier tableIdentifier; + SqlNodeList propertyList = SqlNodeList.EMPTY; + SqlNodeList propertyKeyList = SqlNodeList.EMPTY; + SqlNodeList partSpec = null; + SqlNode freshness = null; +} +{ + <ALTER> <MATERIALIZED> <TABLE> { startPos = getPos();} + tableIdentifier = CompoundIdentifier() + ( + <SUSPEND> + { Review Comment: indent two spaces ########## flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/MaterializedTableStatementParserTest.java: ########## @@ -199,6 +199,187 @@ void testReplaceMaterializedTable() { sql(sql).fails("REPLACE MATERIALIZED TABLE is not supported."); } + @Test + void testAlterMaterializedTableSuspend() { + final String sql = "ALTER MATERIALIZED TABLE tb1 SUSPEND"; + final String expect = "ALTER MATERIALIZED TABLE `TB1` SUSPEND"; + sql(sql).ok(expect); + + final String sql2 = "ALTER MATERIALIZED TABLE tb1 SUSPEND ^PARTITION^"; + sql(sql2) + .fails( + "Encountered \"PARTITION\" at line 1, column 38.\n" + + "Was expecting:\n" + + " <EOF> \n" + + " "); + + final String sql3 = "ALTER MATERIALIZED TABLE tb^1^"; + sql(sql3) + .fails( + "Encountered \"<EOF>\" at line 1, column 28.\n" + + "Was expecting one of:\n" + + " \"RESET\" ...\n" + + " \"SET\" ...\n" + + " \"SUSPEND\" ...\n" + + " \"REFRESH\" ...\n" + + " \"RESUME\" ...\n" + + " \".\" ...\n" + + " "); + } + + @Test + void testAlterMaterializedTableResume() { + final String sql1 = Review Comment: add a test case without specify the WITH keyword. ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterMaterializedTable.java: ########## @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.sql.parser.ddl; + +import org.apache.calcite.sql.SqlCall; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlSpecialOperator; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.parser.SqlParserPos; + +import static java.util.Objects.requireNonNull; + +/** + * Abstract class to describe statements like ALTER MATERIALIZED TABLE [catalogName.] + * [dataBasesName.]tableName ... + */ +public abstract class SqlAlterMaterializedTable extends SqlCall { + + public static final SqlSpecialOperator OPERATOR = + new SqlSpecialOperator("ALTER MATERIALIZED TABLE", SqlKind.ALTER_TABLE); + + protected final SqlIdentifier tableName; Review Comment: tableName -> tableIdentifier -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
