-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-16606][python] Throw exceptions for the data types which are not currently supported #11414
Conversation
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit ef1c121 (Mon Mar 16 08:17:02 UTC 2020) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
ba28e3b
to
6223ae6
Compare
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add python notice document in the related APIs?
…ot currently supported
@hequn8128 Thanks for the good suggestions. Have updated the PR. |
@dianfu Thanks a lot for the update. Merging... |
What is the purpose of the change
Currently, there are still cases where a data type isn't supported as the Python data type will be firstly converted to TypeInformation which will lose a few information, e.g,
SECOND
and the fractionalPrecision could only be 3MONTH
and theyearPrecision
could only be 2We should throw exceptions for the cases not supported.
Brief change log
Verifying this change
This change is a trivial rework without any test coverage.
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (no)Documentation