luoyuxia commented on code in PR #20855:
URL: https://github.com/apache/flink/pull/20855#discussion_r992268530


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserUtils.java:
##########
@@ -1689,4 +1694,61 @@ public static boolean 
isFromTimeStampToDecimal(RelDataType srcType, RelDataType
         return srcType.getSqlTypeName().equals(SqlTypeName.TIMESTAMP)
                 && targetType.getSqlTypeName().equals(SqlTypeName.DECIMAL);
     }
+
+    /**
+     * Helps to migrate the new {@link Schema} to old API methods. HiveCatalog 
use deprecated {@link
+     * TableSchema}, other catalogs may use the new {@link Schema}. Currently, 
we use it to unify to
+     * {@link TableSchema}. It should be dropped after dropping {@link 
TableSchema}.
+     */
+    public static TableSchema fromUnresolvedSchema(Schema schema) {
+        final TableSchema.Builder builder = TableSchema.builder();
+
+        final DataType unresolvedType = DataTypes.TIMESTAMP(3);
+        schema.getColumns().stream()
+                .map(
+                        column -> {
+                            if (column instanceof 
Schema.UnresolvedPhysicalColumn) {
+                                final Schema.UnresolvedPhysicalColumn c =
+                                        (Schema.UnresolvedPhysicalColumn) 
column;
+                                return TableColumn.physical(
+                                        c.getName(), (DataType) 
c.getDataType());
+                            } else if (column instanceof 
Schema.UnresolvedMetadataColumn) {
+                                final Schema.UnresolvedMetadataColumn c =
+                                        (Schema.UnresolvedMetadataColumn) 
column;
+                                return TableColumn.metadata(
+                                        c.getName(),
+                                        (DataType) c.getDataType(),
+                                        c.getMetadataKey(),
+                                        c.isVirtual());
+                            } else if (column instanceof 
Schema.UnresolvedComputedColumn) {
+                                final Schema.UnresolvedComputedColumn c =
+                                        (Schema.UnresolvedComputedColumn) 
column;
+                                return TableColumn.computed(
+                                        c.getName(),
+                                        unresolvedType,

Review Comment:
   `DataTypes.TIMESTAMP(3)`  will be used in two places, so I prefer to create 
a local variable `unresolvedType ` and make these two places use the variable.



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

Reply via email to