danny0405 commented on a change in pull request #13352:
URL: https://github.com/apache/flink/pull/13352#discussion_r486044814



##########
File path: 
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlTableColumn.java
##########
@@ -65,34 +67,55 @@ public SqlTableColumn(SqlIdentifier name,
                this.comment = comment;
        }
 
+       public SqlTableColumn(SqlIdentifier name,
+                       SqlNode expr,
+                       @Nullable SqlCharStringLiteral comment,
+                       SqlParserPos pos) {
+               super(pos);
+               this.name = requireNonNull(name, "Column name should not be 
null");
+               this.expr = requireNonNull(expr, "Column expression should not 
be null");
+               this.comment = comment;
+       }
+
        @Override
        public SqlOperator getOperator() {
                return OPERATOR;
        }
 
        @Override
        public List<SqlNode> getOperandList() {
-               return ImmutableNullableList.of(name, type, comment);
+               return isComputed() ?
+                       ImmutableNullableList.of(name, expr, comment) :
+                       ImmutableNullableList.of(name, type, comment);
        }
 
        @Override
        public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
                this.name.unparse(writer, leftPrec, rightPrec);
-               writer.print(" ");
-               this.type.unparse(writer, leftPrec, rightPrec);
-               if (!this.type.getNullable()) {
-                       // Default is nullable.
-                       writer.keyword("NOT NULL");
-               }
-               if (this.constraint != null) {
-                       this.constraint.unparse(writer, leftPrec, rightPrec);
+               if (isComputed()) {
+                       writer.keyword("AS");
+                       this.expr.unparse(writer, leftPrec, rightPrec);
+               } else {
+                       writer.print(" ");
+                       this.type.unparse(writer, leftPrec, rightPrec);
+                       if (!this.type.getNullable()) {
+                               // Default is nullable.
+                               writer.keyword("NOT NULL");
+                       }
+                       if (this.constraint != null) {
+                               this.constraint.unparse(writer, leftPrec, 
rightPrec);
+                       }
                }
                if (this.comment != null) {
                        writer.print(" COMMENT ");
                        this.comment.unparse(writer, leftPrec, rightPrec);
                }
        }
 
+       public boolean isComputed() {
+               return type == null && expr != null;
+       }

Review comment:
       - Can be `isGenerated` to be synced with `TableColumn`
   - `return expr != null;` is enough




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to