hequn8128 commented on a change in pull request #11414: [FLINK-16606][python]
Throw exceptions for the data types which are not currently supported
URL: https://github.com/apache/flink/pull/11414#discussion_r393463005
##########
File path: flink-python/pyflink/table/types.py
##########
@@ -1621,33 +1621,77 @@ def _to_java_type(data_type):
BigIntType: Types.LONG(),
FloatType: Types.FLOAT(),
DoubleType: Types.DOUBLE(),
- DecimalType: Types.DECIMAL(),
DateType: Types.SQL_DATE(),
- TimeType: Types.SQL_TIME(),
- TimestampType: Types.SQL_TIMESTAMP(),
- LocalZonedTimestampType: Types.SQL_TIMESTAMP(),
- CharType: Types.STRING(),
- VarCharType: Types.STRING(),
- BinaryType: Types.PRIMITIVE_ARRAY(Types.BYTE()),
- VarBinaryType: Types.PRIMITIVE_ARRAY(Types.BYTE())
}
- # NullType
- if isinstance(data_type, NullType):
- # null type is still not supported in Java
- raise NotImplementedError
-
# basic types
- elif type(data_type) in _python_java_types_mapping:
+ if type(data_type) in _python_java_types_mapping:
return _python_java_types_mapping[type(data_type)]
+ # DecimalType
+ elif isinstance(data_type, DecimalType):
+ if data_type.precision == 38 and data_type.scale == 18:
+ return Types.DECIMAL()
+ else:
+ raise TypeError("The precision must be 38 and the scale must be 18
for DecimalType, "
+ "got %s" % repr(data_type))
+
+ # TimeType
+ elif isinstance(data_type, TimeType):
+ if data_type.precision == 0:
+ return Types.SQL_TIME()
+ else:
+ raise TypeError("The precision must be 0 for TimeType, got %s" %
repr(data_type))
+
+ # TimestampType
+ elif isinstance(data_type, TimestampType):
+ if data_type.precision == 3:
+ return Types.SQL_TIMESTAMP()
+ else:
+ raise TypeError("The precision must be 3 for TimestampType, got
%s" % repr(data_type))
+
+ # LocalZonedTimestampType
+ elif isinstance(data_type, LocalZonedTimestampType):
+ if data_type.precision == 3:
+ return
gateway.jvm.org.apache.flink.api.common.typeinfo.Types.INSTANT
+ else:
+ raise TypeError("The precision must be 3 for
LocalZonedTimestampType, got %s"
+ % repr(data_type))
+
+ # VarCharType
+ elif isinstance(data_type, VarCharType):
+ if data_type.length == 0x7fffffff:
+ return Types.STRING()
+ else:
+ raise TypeError("The length limit must be 0x7fffffff(2147483647)
for VarCharType, "
+ "got %s" % repr(data_type))
+
+ # VarBinaryType
+ elif isinstance(data_type, VarBinaryType):
+ if data_type.length == 0x7fffffff:
+ return Types.PRIMITIVE_ARRAY(Types.BYTE())
+ else:
+ raise TypeError("The length limit must be 0x7fffffff(2147483647)
for VarBinaryType, "
+ "got %s" % repr(data_type))
+
# YearMonthIntervalType
elif isinstance(data_type, YearMonthIntervalType):
- return Types.INTERVAL_MONTHS()
+ if data_type.resolution ==
YearMonthIntervalType.YearMonthResolution.MONTH and \
+ data_type.precision == 2:
+ return Types.INTERVAL_MONTHS()
+ else:
+ raise TypeError("The resolution must be YearMonthResolution.MONTH
and the precision "
+ "must be 2 for YearMonthIntervalType, got %s" %
repr(data_type))
# DayTimeIntervalType
elif isinstance(data_type, DayTimeIntervalType):
- return Types.INTERVAL_MILLIS()
+ if data_type.resolution ==
DayTimeIntervalType.DayTimeResolution.SECOND and \
+ data_type.day_precision == 2 and
data_type.fractional_precision == 3:
+ return Types.INTERVAL_MILLIS()
+ else:
+ raise TypeError("The resolution must be DayTimeResolution.SECOND,
the day_precision "
+ "must be 2 and the fractional_precision must be 3
for "
+ "DayTimeIntervalType, got %s" % repr(data_type))
Review comment:
Maybe also add python notice document in the related APIs?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services