Skip to content
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

Merged
merged 1 commit into from
Mar 18, 2020

Conversation

dianfu
Copy link
Contributor

@dianfu dianfu commented Mar 16, 2020

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,

  • the precision for TimeType could only be 0
  • the length for VarBinaryType/VarCharType could only be 0x7fffffff
  • the precision/scale for DecimalType could only be 38/18
  • the precision for TimestampType/LocalZonedTimestampType could only be 3
  • the resolution for DayTimeIntervalType could only be SECOND and the fractionalPrecision could only be 3
  • the resolution for YearMonthIntervalType could only be MONTH and the yearPrecision could only be 2
  • the CharType/BinaryType/ZonedTimestampType is not supported

We should throw exceptions for the cases not supported.

Brief change log

  • Update the types.py to throw exceptions when a data type is not supported

Verifying this change

This change is a trivial rework without any test coverage.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not applicable)

@hequn8128 hequn8128 self-assigned this Mar 16, 2020
@flinkbot
Copy link
Collaborator

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit ef1c121 (Mon Mar 16 08:17:02 UTC 2020)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

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 commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@flinkbot
Copy link
Collaborator

flinkbot commented Mar 16, 2020

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run travis re-run the last Travis build
  • @flinkbot run azure re-run the last Azure build

@dianfu dianfu force-pushed the FLINK-16606 branch 2 times, most recently from ba28e3b to 6223ae6 Compare March 17, 2020 02:11
Comment on lines +1632 to +1694
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))
Copy link
Contributor

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?

@dianfu
Copy link
Contributor Author

dianfu commented Mar 18, 2020

@hequn8128 Thanks for the good suggestions. Have updated the PR.

@dianfu
Copy link
Contributor Author

dianfu commented Mar 18, 2020

@hequn8128
Copy link
Contributor

@dianfu Thanks a lot for the update. Merging...

@hequn8128 hequn8128 merged commit b83060d into apache:master Mar 18, 2020
@dianfu dianfu deleted the FLINK-16606 branch June 10, 2020 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants