dawidwys commented on code in PR #25779:
URL: https://github.com/apache/flink/pull/25779#discussion_r1878200411


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/catalog/SqlCatalogViewTable.java:
##########
@@ -56,6 +60,62 @@ public SqlCatalogViewTable(
     public RelNode convertToRel(ToRelContext context) {
         RelNode original =
                 context.expandView(rowType, view.getExpandedQuery(), viewPath, 
names).project();
-        return RelOptUtil.createCastRel(original, rowType, true);
+        RelDataType castTargetType =
+                adaptTimeAttributes(
+                        original.getRowType(), rowType, 
context.getCluster().getTypeFactory());
+        return RelOptUtil.createCastRel(original, castTargetType, true);
+    }
+
+    private static RelDataType adaptTimeAttributes(
+            RelDataType queryType, RelDataType targetType, RelDataTypeFactory 
typeFactory) {
+        if (queryType instanceof RelRecordType) {
+            if (RelOptUtil.areRowTypesEqual(queryType, targetType, true)) {
+                return targetType;
+            } else if (targetType.getFieldCount() != 
queryType.getFieldCount()) {
+                throw new IllegalArgumentException(
+                        "Field counts are not equal: queryType ["
+                                + queryType
+                                + "]"
+                                + " castRowType ["
+                                + targetType
+                                + "]");
+            } else {
+                return adaptTimeAttributeInRecord(
+                        (RelRecordType) queryType, (RelRecordType) targetType, 
typeFactory);
+            }
+        } else {
+            return adaptTimeAttributeInSimpleType(queryType, targetType, 
typeFactory);

Review Comment:
   1. Time attributes can not be nested in other collection types
   2. The logic is an adapted copy of Calcite's `RelDataTypeFactory#copyType`



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