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-18005][table] Implement type inference for CAST #12411

Closed
wants to merge 5 commits into from

Conversation

twalthr
Copy link
Contributor

@twalthr twalthr commented May 29, 2020

What is the purpose of the change

Updates CAST to the new type inference.

Brief change log

See commit messages.

Verifying this change

This change is already covered by existing tests.

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): yes
  • 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? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

@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 a09af4c (Fri May 29 12:27: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 May 29, 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

Copy link
Contributor

@dawidwys dawidwys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. My biggest concern right now is that we do not check that the second argument is a TypeLiteral. If my understanding is correct theoretically it could be any expression.

@@ -919,7 +920,8 @@
new BuiltInFunctionDefinition.Builder()
.name("cast")
.kind(SCALAR)
.outputTypeStrategy(TypeStrategies.MISSING)
.inputTypeStrategy(SPECIFIC_FOR_CAST)
.outputTypeStrategy(nullable(ConstantArgumentCount.to(0), TypeStrategies.argument(1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like using the ArgumentCount here. It is used for completely different purpose than it was originally intended. It serves as a range here. I know Java lacks a proper range support, but in this case I think we could use int[] here.

And then we could write it like:

nullable(IntStream.rangeClosed(0, 1).toArray(), TypeStrategies.argument(1)) // if we need to select multiple consecutive arguments

nullable(new int[] {0, 3}, TypeStrategies.argument(1)) // if we need to select non consecutive arguments

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After an offline discussion we said it's okay as it has very limited scope. The array approach has the downside that it does not support natively open ended ranges.

public static final InputTypeStrategy SPECIFIC_FOR_CAST = sequence(
InputTypeStrategies.ANY,
and(
InputTypeStrategies.ANY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean you can pass any expression as the second argument? Shouldn't we check that it is a TypeLiteralExpression somehow?

nullable(explicit(DataTypes.BOOLEAN().nullable())))
.inputTypes(DataTypes.BIGINT().notNull(), DataTypes.VARCHAR(2).notNull())
"Cascading to not null type but only consider first two argument",
nullable(ConstantArgumentCount.between(1, 2), explicit(DataTypes.BOOLEAN().nullable())))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it 0 or 1 indexed? If 0 then those are not the first two.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, a copy paste mistake. thanks.

Copy link
Contributor

@dawidwys dawidwys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small comments otherwise good to go.

public Optional<List<DataType>> inferInputTypes(CallContext callContext, boolean throwOnFailure) {
// check for type literal
if (!callContext.isArgumentLiteral(1) || !callContext.getArgumentValue(1, DataType.class).isPresent()) {
return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: throw an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning empty would result in a invalid input argument types. I think this is good enough for a case that should never happen.

nullable(explicit(DataTypes.BOOLEAN().nullable())))
.inputTypes(DataTypes.BIGINT().notNull(), DataTypes.VARCHAR(2).notNull())
"Cascading to not null type but only consider first two argument",
nullable(ConstantArgumentCount.between(1, 2), explicit(DataTypes.BOOLEAN().nullable())))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

@@ -919,7 +920,8 @@
new BuiltInFunctionDefinition.Builder()
.name("cast")
.kind(SCALAR)
.outputTypeStrategy(TypeStrategies.MISSING)
.inputTypeStrategy(SPECIFIC_FOR_CAST)
.outputTypeStrategy(nullable(ConstantArgumentCount.to(0), TypeStrategies.argument(1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After an offline discussion we said it's okay as it has very limited scope. The array approach has the downside that it does not support natively open ended ranges.

@twalthr twalthr closed this in 1d4bd2b Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants