You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "snuyanzin (via GitHub)" <gi...@apache.org> on 2025/11/20 13:29:09 UTC

[PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

snuyanzin opened a new pull request, #27256:
URL: https://github.com/apache/flink/pull/27256

   ## What is the purpose of the change
   
   So far there are lots of code duplications in terms of unparse method in parser
   The PR is addressing this
   
   ## Brief change log
   
   parsre
   
   
   ## Verifying this change
   
   Existing parser/planner tests
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: ( no)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? ( no)
     - If yes, how is the feature documented? (not applicable)
   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin merged PR #27256:
URL: https://github.com/apache/flink/pull/27256


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2546089045


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateDatabase.java:
##########
@@ -19,107 +19,41 @@
 package org.apache.flink.sql.parser.ddl;
 
 import org.apache.calcite.sql.SqlCharStringLiteral;
-import org.apache.calcite.sql.SqlCreate;
 import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlNodeList;
-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 org.apache.calcite.util.ImmutableNullableList;
 
-import javax.annotation.Nullable;
-
 import java.util.List;
-import java.util.Optional;
 
 import static java.util.Objects.requireNonNull;
 
 /** CREATE Database DDL sql call. */
-public class SqlCreateDatabase extends SqlCreate {
+public class SqlCreateDatabase extends SqlCreateObject {
 
     public static final SqlSpecialOperator OPERATOR =
             new SqlSpecialOperator("CREATE DATABASE", SqlKind.OTHER_DDL);
 
-    private final SqlIdentifier databaseName;
-
-    private final SqlNodeList propertyList;
-
-    @Nullable private final SqlCharStringLiteral comment;
-
     public SqlCreateDatabase(
             SqlParserPos pos,
             SqlIdentifier databaseName,
             SqlNodeList propertyList,
             SqlCharStringLiteral comment,
             boolean ifNotExists) {
-        super(OPERATOR, pos, false, ifNotExists);
-        this.databaseName = requireNonNull(databaseName, "databaseName should not be null");
-        this.propertyList = requireNonNull(propertyList, "propertyList should not be null");
-        this.comment = comment;
-    }
-
-    @Override
-    public SqlOperator getOperator() {
-        return OPERATOR;
+        super(OPERATOR, pos, databaseName, false, false, ifNotExists, propertyList, comment);
+        requireNonNull(propertyList, "propertyList should not be null");
     }
 
     @Override
     public List<SqlNode> getOperandList() {
-        return ImmutableNullableList.of(databaseName, propertyList, comment);
-    }
-
-    public SqlIdentifier getDatabaseName() {
-        return databaseName;
-    }
-
-    public SqlNodeList getPropertyList() {
-        return propertyList;
-    }
-
-    public Optional<SqlCharStringLiteral> getComment() {
-        return Optional.ofNullable(comment);
-    }
-
-    public boolean isIfNotExists() {
-        return ifNotExists;
+        return ImmutableNullableList.of(getName(), getProperties(), getComment().orElse(null));
     }
 
     @Override
-    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
-        writer.keyword("CREATE DATABASE");
-        if (isIfNotExists()) {
-            writer.keyword("IF NOT EXISTS");
-        }
-        databaseName.unparse(writer, leftPrec, rightPrec);
-
-        if (comment != null) {
-            writer.newlineAndIndent();
-            writer.keyword("COMMENT");
-            comment.unparse(writer, leftPrec, rightPrec);
-        }
-
-        if (this.propertyList.size() > 0) {
-            writer.keyword("WITH");
-            SqlWriter.Frame withFrame = writer.startList("(", ")");
-            for (SqlNode property : propertyList) {
-                printIndent(writer);
-                property.unparse(writer, leftPrec, rightPrec);
-            }
-            writer.newlineAndIndent();
-            writer.endList(withFrame);
-        }
-    }
-
-    protected void printIndent(SqlWriter writer) {
-        writer.sep(",", false);
-        writer.newlineAndIndent();
-        writer.print("  ");
-    }
-
-    public String[] fullDatabaseName() {
-        return databaseName.names.toArray(new String[0]);
+    protected String getScope() {

Review Comment:
   scope is used by Calcite's `SqlCreate` in `unparse`



##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlCreateDatabase.java:
##########
@@ -19,107 +19,41 @@
 package org.apache.flink.sql.parser.ddl;
 
 import org.apache.calcite.sql.SqlCharStringLiteral;
-import org.apache.calcite.sql.SqlCreate;
 import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.SqlKind;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlNodeList;
-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 org.apache.calcite.util.ImmutableNullableList;
 
-import javax.annotation.Nullable;
-
 import java.util.List;
-import java.util.Optional;
 
 import static java.util.Objects.requireNonNull;
 
 /** CREATE Database DDL sql call. */
-public class SqlCreateDatabase extends SqlCreate {
+public class SqlCreateDatabase extends SqlCreateObject {
 
     public static final SqlSpecialOperator OPERATOR =
             new SqlSpecialOperator("CREATE DATABASE", SqlKind.OTHER_DDL);
 
-    private final SqlIdentifier databaseName;
-
-    private final SqlNodeList propertyList;
-
-    @Nullable private final SqlCharStringLiteral comment;
-
     public SqlCreateDatabase(
             SqlParserPos pos,
             SqlIdentifier databaseName,
             SqlNodeList propertyList,
             SqlCharStringLiteral comment,
             boolean ifNotExists) {
-        super(OPERATOR, pos, false, ifNotExists);
-        this.databaseName = requireNonNull(databaseName, "databaseName should not be null");
-        this.propertyList = requireNonNull(propertyList, "propertyList should not be null");
-        this.comment = comment;
-    }
-
-    @Override
-    public SqlOperator getOperator() {
-        return OPERATOR;
+        super(OPERATOR, pos, databaseName, false, false, ifNotExists, propertyList, comment);
+        requireNonNull(propertyList, "propertyList should not be null");
     }
 
     @Override
     public List<SqlNode> getOperandList() {
-        return ImmutableNullableList.of(databaseName, propertyList, comment);
-    }
-
-    public SqlIdentifier getDatabaseName() {
-        return databaseName;
-    }
-
-    public SqlNodeList getPropertyList() {
-        return propertyList;
-    }
-
-    public Optional<SqlCharStringLiteral> getComment() {
-        return Optional.ofNullable(comment);
-    }
-
-    public boolean isIfNotExists() {
-        return ifNotExists;
+        return ImmutableNullableList.of(getName(), getProperties(), getComment().orElse(null));
     }
 
     @Override
-    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
-        writer.keyword("CREATE DATABASE");
-        if (isIfNotExists()) {
-            writer.keyword("IF NOT EXISTS");
-        }
-        databaseName.unparse(writer, leftPrec, rightPrec);
-
-        if (comment != null) {
-            writer.newlineAndIndent();
-            writer.keyword("COMMENT");
-            comment.unparse(writer, leftPrec, rightPrec);
-        }
-
-        if (this.propertyList.size() > 0) {
-            writer.keyword("WITH");
-            SqlWriter.Frame withFrame = writer.startList("(", ")");
-            for (SqlNode property : propertyList) {
-                printIndent(writer);
-                property.unparse(writer, leftPrec, rightPrec);
-            }
-            writer.newlineAndIndent();
-            writer.endList(withFrame);
-        }
-    }
-
-    protected void printIndent(SqlWriter writer) {
-        writer.sep(",", false);
-        writer.newlineAndIndent();
-        writer.print("  ");
-    }
-
-    public String[] fullDatabaseName() {
-        return databaseName.names.toArray(new String[0]);
+    protected String getScope() {

Review Comment:
   scope is used by Calcite's `SqlCreate`/`SqlAlter` in `unparse`



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549184282


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAddPartitions.java:
##########
@@ -78,8 +78,8 @@ public List<SqlNode> getOperandList() {
     }
 
     @Override

Review Comment:
   We should remove the @Override as well as the method



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549698925


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlDistribution.java:
##########
@@ -51,18 +50,13 @@ public SqlDistribution(
             SqlParserPos pos,
             @Nullable String distributionKind,
             @Nullable SqlNodeList bucketColumns,
-            @Nullable SqlNumericLiteral bucketCount) {
-        super(pos);
+            SqlNumericLiteral bucketCount) {

Review Comment:
   Oops, it should be for `bucketColumns`  as it is always initialized in parser
   https://github.com/apache/flink/blob/e5f53f272dcdac4249e2433091fbacf0e1df2daf/flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl#L1519
   
   fixed



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2546109981


##########
flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java:
##########
@@ -174,23 +175,23 @@ void testUseCatalog() {
     @ParameterizedTest
     @CsvSource({"true,true", "true,false", "false,true", "false,false"})
     void testCreateCatalog(boolean ifNotExists, boolean comment) {
-        String ifNotExistsClause = ifNotExists ? "if not exists " : "";
-        String commentClause = comment ? "\ncomment 'HELLO' " : " ";
+        final String ifNotExistsClause = ifNotExists ? "if not exists " : "";
+        final String commentClause = comment ? "\ncomment 'HELLO'" : "";
 
         sql("create catalog "
                         + ifNotExistsClause
                         + "c1"
                         + commentClause
-                        + " WITH (\n"
+                        + "\nWITH (\n"

Review Comment:
   It also aligns behavior for `WITH` (always put on a new line)



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "twalthr (via GitHub)" <gi...@apache.org>.
twalthr commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549250391


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlDropObject.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.SqlDrop;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.util.ImmutableNullableList;
+
+import java.util.List;
+
+/** Base class for DROP DDL sql calls. */

Review Comment:
   ```suggestion
   /** Base class for DROP DDL SQL calls. */
   ```



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/SqlNodeToOperationConversion.java:
##########
@@ -579,22 +578,18 @@ private Operation convertCreateDatabase(SqlCreateDatabase sqlCreateDatabase) {
         String databaseName =
                 (fullDatabaseName.length == 1) ? fullDatabaseName[0] : fullDatabaseName[1];
         boolean ignoreIfExists = sqlCreateDatabase.isIfNotExists();
-        String databaseComment =
-                sqlCreateDatabase
-                        .getComment()
-                        .map(comment -> comment.getValueAs(NlsString.class).getValue())
-                        .orElse(null);
+        String databaseComment = OperationConverterUtils.getComment(sqlCreateDatabase.getComment());
         // set with properties
         final Map<String, String> properties =
-                OperationConverterUtils.getProperties(sqlCreateDatabase.getPropertyList());
+                OperationConverterUtils.getProperties(sqlCreateDatabase.getProperties());

Review Comment:
   also here let's return a Map<String, String> from the parser. We shouldn't expose parser internals to the caller.
   ```suggestion
                   sqlCreateDatabase.getProperties();
   ```



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/SqlNodeToOperationConversion.java:
##########
@@ -579,22 +578,18 @@ private Operation convertCreateDatabase(SqlCreateDatabase sqlCreateDatabase) {
         String databaseName =
                 (fullDatabaseName.length == 1) ? fullDatabaseName[0] : fullDatabaseName[1];
         boolean ignoreIfExists = sqlCreateDatabase.isIfNotExists();
-        String databaseComment =
-                sqlCreateDatabase
-                        .getComment()
-                        .map(comment -> comment.getValueAs(NlsString.class).getValue())
-                        .orElse(null);
+        String databaseComment = OperationConverterUtils.getComment(sqlCreateDatabase.getComment());

Review Comment:
   following my comment above:
   ```suggestion
           String databaseComment = sqlCreateDatabase.getComment();
   ```



##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlDistribution.java:
##########
@@ -51,18 +50,13 @@ public SqlDistribution(
             SqlParserPos pos,
             @Nullable String distributionKind,
             @Nullable SqlNodeList bucketColumns,
-            @Nullable SqlNumericLiteral bucketCount) {
-        super(pos);
+            SqlNumericLiteral bucketCount) {

Review Comment:
   why not nullable anymore?



##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterModelRename.java:
##########
@@ -51,12 +51,12 @@ public String[] fullNewModelName() {
 
     @Override
     public List<SqlNode> getOperandList() {
-        return List.of(modelName, newModelName);
+        return List.of(getName(), newModelName);

Review Comment:
   nit: we could also just use protected for `name` then `getName` could return String or will simply not be needed anymore.



##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterCatalogReset.java:
##########
@@ -62,15 +62,8 @@ public Set<String> getResetKeys() {
     }
 
     @Override
-    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
-        super.unparse(writer, leftPrec, rightPrec);
-        writer.keyword("RESET");
-        SqlWriter.Frame withFrame = writer.startList("(", ")");
-        for (SqlNode property : propertyKeyList) {
-            SqlUnparseUtils.printIndent(writer);
-            property.unparse(writer, leftPrec, rightPrec);
-        }
-        writer.newlineAndIndent();
-        writer.endList(withFrame);
+    public void unparseAlterOperation(SqlWriter writer, int leftPrec, int rightPrec) {
+        super.unparseAlterOperation(writer, leftPrec, rightPrec);
+        SqlUnparseUtils.unparseResetProperties(propertyKeyList, writer, leftPrec, rightPrec);

Review Comment:
   ```suggestion
           SqlUnparseUtils.unparseResetOptions(propertyKeyList, writer, leftPrec, rightPrec);
   ```



##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterCatalogComment.java:
##########
@@ -31,27 +34,26 @@
 /** ALTER CATALOG catalog_name COMMENT 'comment'. */
 public class SqlAlterCatalogComment extends SqlAlterCatalog {
 
-    private final SqlNode comment;
+    private final SqlCharStringLiteral comment;
 
     public SqlAlterCatalogComment(
-            SqlParserPos position, SqlIdentifier catalogName, SqlNode comment) {
+            SqlParserPos position, SqlIdentifier catalogName, SqlCharStringLiteral comment) {
         super(position, catalogName);
         this.comment = requireNonNull(comment, "comment cannot be null");
     }
 
     @Override
     public List<SqlNode> getOperandList() {
-        return ImmutableNullableList.of(catalogName, comment);
+        return ImmutableNullableList.of(getName(), comment);
     }
 
-    public SqlNode getComment() {
+    public SqlCharStringLiteral getComment() {

Review Comment:
   Can't we just return string already? No outside consumer really needs `SqlCharStringLiteral` anymore right?



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549685530


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/SqlNodeToOperationConversion.java:
##########
@@ -579,22 +578,18 @@ private Operation convertCreateDatabase(SqlCreateDatabase sqlCreateDatabase) {
         String databaseName =
                 (fullDatabaseName.length == 1) ? fullDatabaseName[0] : fullDatabaseName[1];
         boolean ignoreIfExists = sqlCreateDatabase.isIfNotExists();
-        String databaseComment =
-                sqlCreateDatabase
-                        .getComment()
-                        .map(comment -> comment.getValueAs(NlsString.class).getValue())
-                        .orElse(null);
+        String databaseComment = OperationConverterUtils.getComment(sqlCreateDatabase.getComment());
         // set with properties
         final Map<String, String> properties =
-                OperationConverterUtils.getProperties(sqlCreateDatabase.getPropertyList());
+                OperationConverterUtils.getProperties(sqlCreateDatabase.getProperties());

Review Comment:
   makes sense, added same for List<String>



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/SqlNodeToOperationConversion.java:
##########
@@ -579,22 +578,18 @@ private Operation convertCreateDatabase(SqlCreateDatabase sqlCreateDatabase) {
         String databaseName =
                 (fullDatabaseName.length == 1) ? fullDatabaseName[0] : fullDatabaseName[1];
         boolean ignoreIfExists = sqlCreateDatabase.isIfNotExists();
-        String databaseComment =
-                sqlCreateDatabase
-                        .getComment()
-                        .map(comment -> comment.getValueAs(NlsString.class).getValue())
-                        .orElse(null);
+        String databaseComment = OperationConverterUtils.getComment(sqlCreateDatabase.getComment());
         // set with properties
         final Map<String, String> properties =
-                OperationConverterUtils.getProperties(sqlCreateDatabase.getPropertyList());
+                OperationConverterUtils.getProperties(sqlCreateDatabase.getProperties());

Review Comment:
   makes sense, added same also for `List<String>`



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549251376


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterModel.java:
##########
@@ -18,47 +18,28 @@
 
 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 MODEL [IF EXISTS] [[catalogName.]
  * dataBasesName.]modelName ...
  */
-public abstract class SqlAlterModel extends SqlCall {
+public abstract class SqlAlterModel extends SqlAlterObject {
 
-    public static final SqlSpecialOperator OPERATOR =
+    private static final SqlSpecialOperator OPERATOR =
             new SqlSpecialOperator("ALTER MODEL", SqlKind.OTHER_DDL);
 
-    protected final SqlIdentifier modelName;
     protected final boolean ifModelExists;
 
     public SqlAlterModel(SqlParserPos pos, SqlIdentifier modelName, boolean ifModelExists) {
-        super(pos);
-        this.modelName = requireNonNull(modelName, "modelName should not be null");
+        super(OPERATOR, pos, "MODEL", modelName);

Review Comment:
   Calcite will know that it should unparse as `ALTER MODEL`
   
   for more details take a look at https://github.com/apache/calcite/blob/49fa3edbb98e3f01fccc028c517e8abf78c1f49f/core/src/main/java/org/apache/calcite/sql/SqlAlter.java



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549246750


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterModel.java:
##########
@@ -18,47 +18,28 @@
 
 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 MODEL [IF EXISTS] [[catalogName.]
  * dataBasesName.]modelName ...
  */
-public abstract class SqlAlterModel extends SqlCall {
+public abstract class SqlAlterModel extends SqlAlterObject {
 
-    public static final SqlSpecialOperator OPERATOR =
+    private static final SqlSpecialOperator OPERATOR =
             new SqlSpecialOperator("ALTER MODEL", SqlKind.OTHER_DDL);
 
-    protected final SqlIdentifier modelName;
     protected final boolean ifModelExists;
 
     public SqlAlterModel(SqlParserPos pos, SqlIdentifier modelName, boolean ifModelExists) {
-        super(pos);
-        this.modelName = requireNonNull(modelName, "modelName should not be null");
+        super(OPERATOR, pos, "MODEL", modelName);

Review Comment:
   I am curious about what the scope "MODEL" does. It only seems to be there for ALTERs and not for CREATEs.   



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2546109981


##########
flink-table/flink-sql-parser/src/test/java/org/apache/flink/sql/parser/FlinkSqlParserImplTest.java:
##########
@@ -174,23 +175,23 @@ void testUseCatalog() {
     @ParameterizedTest
     @CsvSource({"true,true", "true,false", "false,true", "false,false"})
     void testCreateCatalog(boolean ifNotExists, boolean comment) {
-        String ifNotExistsClause = ifNotExists ? "if not exists " : "";
-        String commentClause = comment ? "\ncomment 'HELLO' " : " ";
+        final String ifNotExistsClause = ifNotExists ? "if not exists " : "";
+        final String commentClause = comment ? "\ncomment 'HELLO'" : "";
 
         sql("create catalog "
                         + ifNotExistsClause
                         + "c1"
                         + commentClause
-                        + " WITH (\n"
+                        + "\nWITH (\n"

Review Comment:
   It also aligns behavior for `WITH` (always put on a new line)
   However as a note: it doesn't impact `SHOW CREATE` output since for `SHOW CREATE` there is separate logic in `ShowCreateUtil`



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549251376


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterModel.java:
##########
@@ -18,47 +18,28 @@
 
 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 MODEL [IF EXISTS] [[catalogName.]
  * dataBasesName.]modelName ...
  */
-public abstract class SqlAlterModel extends SqlCall {
+public abstract class SqlAlterModel extends SqlAlterObject {
 
-    public static final SqlSpecialOperator OPERATOR =
+    private static final SqlSpecialOperator OPERATOR =
             new SqlSpecialOperator("ALTER MODEL", SqlKind.OTHER_DDL);
 
-    protected final SqlIdentifier modelName;
     protected final boolean ifModelExists;
 
     public SqlAlterModel(SqlParserPos pos, SqlIdentifier modelName, boolean ifModelExists) {
-        super(pos);
-        this.modelName = requireNonNull(modelName, "modelName should not be null");
+        super(OPERATOR, pos, "MODEL", modelName);

Review Comment:
   Calcite will know that it should unparse as `ALTER MODEL ...` 
   
   for more details take a look at https://github.com/apache/calcite/blob/49fa3edbb98e3f01fccc028c517e8abf78c1f49f/core/src/main/java/org/apache/calcite/sql/SqlAlter.java



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2546086190


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterTableAdd.java:
##########
@@ -62,8 +62,8 @@ public SqlAlterTableAdd(
     }
 
     @Override
-    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
-        super.unparse(writer, leftPrec, rightPrec);
+    public void unparseAlterOperation(SqlWriter writer, int leftPrec, int rightPrec) {
+        super.unparseAlterOperation(writer, leftPrec, rightPrec);
         writer.keyword("ADD");
         // unparse table schema and distribution
         unparseSchemaAndDistribution(writer, leftPrec, rightPrec);

Review Comment:
   distribution will be moved out of schema in following PR



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #27256:
URL: https://github.com/apache/flink/pull/27256#issuecomment-3558087920

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "8d5bc5589931183756e9a2a25ade7b1aac04bb4f",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "8d5bc5589931183756e9a2a25ade7b1aac04bb4f",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8d5bc5589931183756e9a2a25ade7b1aac04bb4f UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549184282


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAddPartitions.java:
##########
@@ -78,8 +78,8 @@ public List<SqlNode> getOperandList() {
     }
 
     @Override

Review Comment:
   We should remove the `@Override` as well as the method. This occurs else where also



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549184282


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAddPartitions.java:
##########
@@ -78,8 +78,8 @@ public List<SqlNode> getOperandList() {
     }
 
     @Override

Review Comment:
   We should remove the `@Override` as well as the method



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2546078530


##########
flink-table/flink-sql-parser/src/main/codegen/includes/parserImpls.ftl:
##########
@@ -144,7 +144,7 @@ SqlCreate SqlCreateCatalog(Span s, boolean replace) :
     SqlParserPos startPos;
     SqlIdentifier catalogName;
     SqlNodeList propertyList = SqlNodeList.EMPTY;
-    SqlNode comment = null;
+    SqlCharStringLiteral comment = null;

Review Comment:
   so far there were different approaches for comments
   the PR aligns them



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549206852


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterMaterializedTableRefresh.java:
##########
@@ -43,12 +43,12 @@ public SqlAlterMaterializedTableRefresh(
 
     @Override
     public List<SqlNode> getOperandList() {
-        return ImmutableNullableList.of(getTableName(), partitionSpec);
+        return ImmutableNullableList.of(getName(), partitionSpec);

Review Comment:
   I am curious about these changes to getName(). Seeing a table operation refer to getTableName() is very readable and explicit, and I assume works. If this was in a superclass that referred to things other than table I could see a motivation for this change. 



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549206852


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterMaterializedTableRefresh.java:
##########
@@ -43,12 +43,12 @@ public SqlAlterMaterializedTableRefresh(
 
     @Override
     public List<SqlNode> getOperandList() {
-        return ImmutableNullableList.of(getTableName(), partitionSpec);
+        return ImmutableNullableList.of(getName(), partitionSpec);

Review Comment:
   I am curious about these changes to getName(). Seeing a table operation refer to getTableName() is very readable and explicit, and I assume works. If this was in a superclass that referred to things other than table I could see a motivation for this change. 



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38702][table] Make `unparse` more reusable in parser [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #27256:
URL: https://github.com/apache/flink/pull/27256#discussion_r2549193750


##########
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAddPartitions.java:
##########
@@ -78,8 +78,8 @@ public List<SqlNode> getOperandList() {
     }
 
     @Override

Review Comment:
   why?
   
   it is related to `unparseAlterOperation` which is also overriden here 
   for more details have a look at https://github.com/apache/calcite/blob/49fa3edbb98e3f01fccc028c517e8abf78c1f49f/core/src/main/java/org/apache/calcite/sql/SqlAlter.java#L51



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org