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-17151][table] Align Calcite's and Flink's SYMBOL types #18107

Closed
wants to merge 1 commit into from

Conversation

twalthr
Copy link
Contributor

@twalthr twalthr commented Dec 14, 2021

What is the purpose of the change

This reworks how we handle symbols throughout the stack. It removes the need for a conversion class and align the behavior with Calcite's representation of symbols. Even though we change a @PublicEvolving class this should have little impact for users as this type is not exposed through the API.

Brief change log

  • Simplify SymbolType
  • Remove usages of RAW type for symbols.

Verifying this change

This change is already covered by existing tests, such as (please describe 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, 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? JavaDocs

@flinkbot
Copy link
Collaborator

flinkbot commented Dec 14, 2021

CI report:

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

@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 5cb0193 (Tue Dec 14 15:01:30 UTC 2021)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!
  • This pull request references an unassigned Jira ticket. According to the code contribution guide, tickets need to be assigned before starting with the implementation work.

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

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

Looks good, I left a few comments/questions.

*/
@SuppressWarnings("unused")
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is used for the argument of the constructor

Copy link
Contributor

Choose a reason for hiding this comment

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

Then maybe only move it there on top of the ctor?

Copy link
Contributor

Choose a reason for hiding this comment

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

or like this: public SymbolType(@SuppressWarnings("unused") Class<T> clazz) { ?

@@ -45,7 +44,8 @@ public SymbolArgumentTypeStrategy(Class<? extends Enum<? extends TableSymbol>> s
public Optional<DataType> inferArgumentType(
CallContext callContext, int argumentPos, boolean throwOnFailure) {
final DataType argumentType = callContext.getArgumentDataTypes().get(argumentPos);
if (argumentType.getLogicalType().getTypeRoot() != LogicalTypeRoot.SYMBOL) {
if (argumentType.getLogicalType().getTypeRoot() != LogicalTypeRoot.SYMBOL
|| !callContext.isArgumentLiteral(argumentPos)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed now? is it tested somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is always needed before calling getArgumentValue as written in the JavaDocs. A user would need to create a weird expression to have a symbol that is not a literal.

symbolClass.getSimpleName(),
symbolType.getDefaultConversion().getSimpleName());
callContext
.getArgumentValue(argumentPos, Enum.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused, but if L58, we don't have a symbolClass, can we still have an Enum here?
is there a test covering this, and the "invalid" case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SymbolArgumentTypeStrategyTest is testing this path. We are in control of creating symbols so we can safely assume an Enum here. Everything else is highly unlikely. For the invalid case I would need to create an invalid expression. The alternative would have been an InvalidArgumentException.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's easy to have a test like that, would be nice for completeness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, that is not easy. As I said, I would need to create a completely invalid expression. Maybe some constructor checks would already prevent that.

Copy link
Contributor

@slinkydeveloper slinkydeveloper left a comment

Choose a reason for hiding this comment

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

Just a minor issue, otherwise LGTM

Comment on lines +59 to 65
public SymbolType(boolean isNullable) {
super(isNullable, LogicalTypeRoot.SYMBOL);
}

public Class<T> getSymbolClass() {
return symbolClass;
public SymbolType() {
this(true);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps create 2 singletons? As I see in different places you either instantiate new SymbolType() and new SymbolType(false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's do this as a followup. We can do the same with IntType and many other predefined types. I was also thinking about reducing the creation of objects.

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM, responded to the original comments, thx for explaining!

@twalthr twalthr closed this in a79e004 Dec 15, 2021
niklassemmler pushed a commit to niklassemmler/flink that referenced this pull request Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants