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
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 a09af4c (Fri May 29 12:27: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:
|
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.
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))) |
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.
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
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.
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, |
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.
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()))) |
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.
is it 0 or 1 indexed? If 0 then those are not the first two.
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.
bump
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.
yes, a copy paste mistake. thanks.
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.
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(); |
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.
nit: throw an exception?
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.
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()))) |
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.
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))) |
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.
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.
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:
@Public(Evolving)
: yesDocumentation