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

[hotfix][docs]fix flink sql Cascading Window TVF Aggregation exception #18414

Merged
merged 4 commits into from
Jan 24, 2022
Merged

[hotfix][docs]fix flink sql Cascading Window TVF Aggregation exception #18414

merged 4 commits into from
Jan 24, 2022

Conversation

simenliuxing
Copy link
Contributor

What is the purpose of the change

Aliases need to be used under Cascading Window Aggregation, otherwise an error will be reported, but there is no such thing in the documentation, so I fixed it

Brief change log

Fix errors in documentation, add aliases

Verifying this change

This change is a trivial rework / code cleanup 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, 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? (no)

@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 3c3aede (Thu Jan 20 07:11:16 UTC 2022)

✅no warnings

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 Jan 20, 2022

CI report:

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

@simenliuxing
Copy link
Contributor Author

@MartijnVisser Can you review it for me?

Copy link
Contributor

@beyond1920 beyond1920 left a comment

Choose a reason for hiding this comment

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

@simenliuxing Thanks for contribution. LGTM.
Only left a few comments here.

@@ -199,7 +199,7 @@ The following shows a cascading window aggregation where the first window aggreg
```sql
-- tumbling 5 minutes for each supplier_id
CREATE VIEW window1 AS
SELECT window_start, window_end, window_time as rowtime, SUM(price) as partial_price
SELECT window_start as window1_start, window_end as window1_end, window_time as rowtime, SUM(price) as partial_price
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some comments here to explain that we need alias here to avoid name conflict?

Copy link
Contributor Author

@simenliuxing simenliuxing Jan 21, 2022

Choose a reason for hiding this comment

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

@beyond1920

When i use sql as below:

-- tumbling 5 minutes for each supplier_id
CREATE VIEW window1 AS
SELECT window_start as window1_start, window_end as window1_end, window_time as rowtime, SUM(price) as partial_price
  FROM TABLE(
    TUMBLE(TABLE Bid, DESCRIPTOR(bidtime), INTERVAL '5' MINUTES))
  GROUP BY supplier_id, window_start, window_end, window_time;

-- tumbling 10 minutes on the first window
SELECT window_start, window_end, SUM(partial_price) as total_price
  FROM TABLE(
      TUMBLE(TABLE window1, DESCRIPTOR(rowtime), INTERVAL '10' MINUTES))
  GROUP BY window_start, window_end;

The following exception occurs:

Caused by: org.apache.calcite.sql.validate.SqlValidatorException: Column 'window_start' is ambiguous
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
   at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:467)
   at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:560)
   ... 41 more

I think the following piece of sql cannot identify whether window_start is from window1 or from built-in.
But the following sql is for Group Window Aggregation, the required window_start and window_end are not from window1, So I renamed window_start and window_end in the above sql.

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 not sure if that a proper fix is changing the documentation. I would expect that we should address the issue to avoid getting the 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.

ok i see. this is the result of other communication with me
https://issues.apache.org/jira/browse/FLINK-25700?filter=-2

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. If that's the case, then I guess we should indeed update this documentation :) I would then only slightly modify the alias to make it more clearer, something like:

Suggested change
SELECT window_start as window1_start, window_end as window1_end, window_time as rowtime, SUM(price) as partial_price
SELECT window_start as window_5mintumble_start, window_end as window_5mintumble_end, window_time as rowtime, SUM(price) as partial_price

or

Suggested change
SELECT window_start as window1_start, window_end as window1_end, window_time as rowtime, SUM(price) as partial_price
SELECT window_start as window_5mintumblepersupplier_start, window_end as window_5mintumblepersupplier_end, window_time as rowtime, SUM(price) as partial_price

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion, I have revised

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me, what do you think @beyond1920 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@simenliuxing Thanks for explain.
I mean to add some comments in documents to explain that we need alias here to avoid name conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@beyond1920
Sorry for misunderstanding, I have added the comment

@@ -199,7 +199,8 @@ The following shows a cascading window aggregation where the first window aggreg
```sql
-- tumbling 5 minutes for each supplier_id
CREATE VIEW window1 AS
SELECT window_start, window_end, window_time as rowtime, SUM(price) as partial_price
-- under the Cascading Window Aggregation to avoid field ambiguity window_start and window_end need to be renamed
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-- under the Cascading Window Aggregation to avoid field ambiguity window_start and window_end need to be renamed
-- Note: The window start and window end fields of inner Window TVF are optional in the select clause. However, if they appear in the clause, they need to be aliased to prevent name conflicting with the window start and window end of the outer Window TVF.

WDTY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good to me, I have revised

@beyond1920
Copy link
Contributor

Merged. Thanks for contribution @simenliuxing

@beyond1920 beyond1920 merged commit 2a3ff01 into apache:master Jan 24, 2022
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants