jnh5y commented on code in PR #23633:
URL: https://github.com/apache/flink/pull/23633#discussion_r1380448415
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeCasts.java:
##########
@@ -288,6 +288,50 @@ public static boolean supportsExplicitCast(LogicalType
sourceType, LogicalType t
return supportsCasting(sourceType, targetType, true);
}
+ /**
+ * Returns whether the source type can be reinterpreted as the target type.
+ *
+ * <p>Reinterpret casts correspond to the SQL reinterpret_cast and
represent the logic behind a
+ * {@code REINTERPRET_CAST(sourceType AS targetType)} operation.
+ */
+ public static boolean supportsReinterpretCast(LogicalType sourceType,
LogicalType targetType) {
+ if (sourceType.getTypeRoot() == targetType.getTypeRoot()) {
+ return true;
+ }
+
+ switch (targetType.getTypeRoot()) {
+ case INTEGER:
+ switch (sourceType.getTypeRoot()) {
+ case DATE:
+ case TIME_WITHOUT_TIME_ZONE:
+ case INTERVAL_YEAR_MONTH:
+ return true;
+ default:
+ return false;
+ }
+ case BIGINT:
+ switch (sourceType.getTypeRoot()) {
+ case DATE:
+ case TIME_WITHOUT_TIME_ZONE:
+ case TIMESTAMP_WITHOUT_TIME_ZONE:
+ case INTERVAL_DAY_TIME:
+ case INTERVAL_YEAR_MONTH:
+ return true;
+ default:
+ return false;
+ }
+ case DATE:
+ case TIME_WITHOUT_TIME_ZONE:
+ case INTERVAL_YEAR_MONTH:
+ return sourceType.getTypeRoot() == INTEGER;
Review Comment:
>The switch is on the target type.
Doh, I was reading too quickly. I'll say that's slightly surprising. It
feels more natural to match on the first type first. (IMO.)
--
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]