fsk119 commented on code in PR #19193: URL: https://github.com/apache/flink/pull/19193#discussion_r913421428
########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterTableSchema.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.ddl.constraint.SqlTableConstraint; + +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 javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; +import java.util.Optional; + +/** Abstract class to describe statements which are used to alter table schema. */ +public abstract class SqlAlterTableSchema extends SqlAlterTable { + + protected final SqlNodeList columnList; + @Nullable protected final SqlWatermark watermark; + protected final List<SqlTableConstraint> constraints; + + public SqlAlterTableSchema( + SqlParserPos pos, + SqlIdentifier tableName, + SqlNodeList columnList, + @Nullable SqlWatermark sqlWatermark, + List<SqlTableConstraint> constraints) { + super(pos, tableName); + this.columnList = columnList; + this.watermark = sqlWatermark; + this.constraints = constraints; + } + + @Nonnull + @Override + public List<SqlNode> getOperandList() { + return ImmutableNullableList.of( + getTableName(), + columnList, + watermark, + new SqlNodeList(constraints, SqlParserPos.ZERO)); + } + + public SqlNodeList getColumns() { + return columnList; + } + + public Optional<SqlWatermark> getWatermark() { + return Optional.ofNullable(watermark); + } + + public List<SqlTableConstraint> getConstraints() { + return constraints; + } + + @Override + public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { + super.unparse(writer, leftPrec, rightPrec); + } Review Comment: If it invokes `super`, I think we can remove this. ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterTableSchema.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.ddl.constraint.SqlTableConstraint; + +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 javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; +import java.util.Optional; + +/** Abstract class to describe statements which are used to alter table schema. */ +public abstract class SqlAlterTableSchema extends SqlAlterTable { + + protected final SqlNodeList columnList; + @Nullable protected final SqlWatermark watermark; + protected final List<SqlTableConstraint> constraints; + + public SqlAlterTableSchema( + SqlParserPos pos, + SqlIdentifier tableName, + SqlNodeList columnList, + @Nullable SqlWatermark sqlWatermark, + List<SqlTableConstraint> constraints) { + super(pos, tableName); + this.columnList = columnList; + this.watermark = sqlWatermark; + this.constraints = constraints; + } + + @Nonnull + @Override + public List<SqlNode> getOperandList() { + return ImmutableNullableList.of( + getTableName(), + columnList, + watermark, + new SqlNodeList(constraints, SqlParserPos.ZERO)); Review Comment: nit: It's better to align with `SqlCreateTable`. ``` return ImmutableNullableList.of( getTableName(), columnList, new SqlNodeList(constraints, SqlParserPos.ZERO), watermark); ``` ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/SqlTableUtils.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; + +import org.apache.flink.sql.parser.ddl.SqlWatermark; +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; + +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlWriter; + +import java.util.List; + +/** Utils methods for table DDLs. */ +public class SqlTableUtils { Review Comment: SqlUnparseUtils? ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/SqlTableUtils.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; + +import org.apache.flink.sql.parser.ddl.SqlWatermark; +import org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint; + +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlWriter; + +import java.util.List; + +/** Utils methods for table DDLs. */ Review Comment: Utils to unparse DDLs ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/position/SqlColumnPosSpec.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.position; + +import org.apache.calcite.sql.SqlLiteral; +import org.apache.calcite.sql.parser.SqlParserPos; + +/** Enumeration of SQL column position specification. */ +public enum SqlColumnPosSpec { + FIRST("FIRST"), + AFTER("AFTER"), + LAST("LAST"); Review Comment: The issue doesn't mention `LAST` and no test covers this. I just think do we need `last` now? ########## flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterTableSchema.java: ########## @@ -0,0 +1,81 @@ +/* + * 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.ddl.constraint.SqlTableConstraint; + +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 javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.List; +import java.util.Optional; + +/** Abstract class to describe statements which are used to alter table schema. */ +public abstract class SqlAlterTableSchema extends SqlAlterTable { + + protected final SqlNodeList columnList; + @Nullable protected final SqlWatermark watermark; + protected final List<SqlTableConstraint> constraints; + + public SqlAlterTableSchema( + SqlParserPos pos, + SqlIdentifier tableName, + SqlNodeList columnList, + @Nullable SqlWatermark sqlWatermark, + List<SqlTableConstraint> constraints) { Review Comment: nit: would be better with the order of `constraints`, `watermark`. -- 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]
