lsyldliu commented on code in PR #20855: URL: https://github.com/apache/flink/pull/20855#discussion_r991797046
########## 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) { Review Comment: The `TableSchema` has been deprecated, does we can use the new `Schema`? If not, I think we should create an issue to migrate `TableSchema` to `Schema` for hive. ########## flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserBaseSemanticAnalyzer.java: ########## @@ -520,10 +523,46 @@ public static String getUnescapedUnqualifiedTableName(HiveParserASTNode node) { * Get dequoted name from a table/column node. * * @param tableOrColumnNode the table or column node - * @return for table node, db.tab or tab. for column node column. + * @return for table node, return the table that users specific like catalog.db.tab, db.tab or + * tab. For column node column, return col. */ - public static String getUnescapedName(HiveParserASTNode tableOrColumnNode) { - return getUnescapedName(tableOrColumnNode, null); + public static String getUnescapedName(HiveParserASTNode tableOrColumnNode) + throws SemanticException { + return getUnescapedName(tableOrColumnNode, null, null); + } + + public static String getUnescapedName( + HiveParserASTNode tableOrColumnNode, String currentCatalog, String currentDatabase) Review Comment: Nit: currentCatalog and currentDatabase add `@Nullable` annotation. ########## 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: Why not use `DataTypes.TIMESTAMP(3)` directly? ########## flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSemanticAnalyzer.java: ########## @@ -2158,6 +2074,44 @@ public String getAutogenColAliasPrfxLbl() { return this.autogenColAliasPrfxLbl; } + public CatalogBaseTable getCatalogBaseTable(String tableName, HiveParserQB qb) { + return getCatalogBaseTable(tableName, qb, true); + } + + public CatalogBaseTable getCatalogBaseTable( Review Comment: Nit: add `@Nullable` annotation. -- 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-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org