You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "jnh5y (via GitHub)" <gi...@apache.org> on 2023/11/02 15:38:11 UTC
Re: [PR] [FLINK-33412] Implement type inference for reinterpret_cast function [flink]
jnh5y commented on code in PR #23633:
URL: https://github.com/apache/flink/pull/23633#discussion_r1380349827
##########
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:
Can/should DATEs, TIME_WITHOUT_TIME_ZONEs, INTERVAL_YEAR_MONTH be castable to a BIGINT?
--
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-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org