-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[FLINK-39293][table-planner] Fix MATCH_RECOGNIZE uses through view #27907
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these changes related to the issue yo are trying to solve?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Essentially, this pull request is a partial revert of FLINK-38493, so I also had to revert the test changes. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,7 +150,7 @@ class ViewsExpandingTest(tableTestUtil: TableTestBase => TableTestUtil) extends | |
| .getTable(objectID.toObjectPath) | ||
| assertThat( | ||
| view.asInstanceOf[CatalogView].getExpandedQuery | ||
| ).isEqualTo("SELECT CONCAT('a', 'bc', 'def')") | ||
| ).isEqualTo("SELECT `CONCAT`('a', 'bc', 'def')") | ||
| } | ||
|
|
||
| @TestTemplate | ||
|
|
@@ -172,7 +172,7 @@ class ViewsExpandingTest(tableTestUtil: TableTestBase => TableTestUtil) extends | |
| .getTable(objectID.toObjectPath) | ||
| assertThat( | ||
| view.asInstanceOf[CatalogView].getExpandedQuery | ||
| ).isEqualTo("SELECT `default_catalog`.`default_database`.`func`(1, CAST(2 AS BIGINT), 'abc')") | ||
| ).isEqualTo("SELECT `default_catalog`.`default_database`.`func`(1, 2, 'abc')") | ||
| } | ||
|
|
||
| @TestTemplate | ||
|
|
@@ -201,12 +201,12 @@ class ViewsExpandingTest(tableTestUtil: TableTestBase => TableTestUtil) extends | |
| assertThat( | ||
| view.asInstanceOf[CatalogView].getExpandedQuery | ||
| ).isEqualTo( | ||
| "SELECT `EXPR$0`.`f0`, `EXPR$0`.`rowNum`\n" | ||
| "SELECT *\n" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider adding a second test variant with explicit columns alongside this one? |
||
| + "FROM (SELECT `source`.`f0`, " | ||
| + "ROW_NUMBER() " | ||
| + "OVER (PARTITION BY `source`.`f0` ORDER BY `source`.`f0` DESC) AS `rowNum`\n" | ||
| + "FROM `default_catalog`.`default_database`.`source` AS `source`) AS `EXPR$0`\n" | ||
| + "WHERE `EXPR$0`.`rowNum` = 1") | ||
| + "FROM `default_catalog`.`default_database`.`source`)\n" | ||
| + "WHERE `rowNum` = 1") | ||
| } | ||
|
|
||
| private def createSqlView(originTable: String): CatalogView = { | ||
|
|
||
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.
ideally we should keep it as is as it gives fully expanded sql and
expandSqlIdentifiersdoesn't do that (for instance it doesn't expand star).I tend to think that rather than fixing here it should be fixed in Calcite
for more details look at https://issues.apache.org/jira/browse/CALCITE-7465, https://issues.apache.org/jira/browse/CALCITE-7466, https://issues.apache.org/jira/browse/CALCITE-7467, probably something else
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.
also https://issues.apache.org/jira/browse/CALCITE-7470
Uh oh!
There was an error while loading. Please reload this page.
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.
The problem, as I see it, is somewhat similar to the LATERAL issue:
expandSqlIdentifierswas being used until the Calcite version (problem resolved) was updated.Is correct usage of
MATCH_RECOGNIZEinCREATE VIEWsyntax important to us? If so, we can keep usingexpandSqlIdentifiersuntil upgrading Calcite version (1.42.0).What do you think?
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.
this is not entirely true
LATERALwas fixed in https://issues.apache.org/jira/browse/CALCITE-7217 and https://issues.apache.org/jira/browse/CALCITE-7312 which are 1.41.0 and 1.42.0 (not even released yet) and Flink master depends on 1.36.0Calcite upgrade task is not an easy one because of lots of customizations
So we just port fixes from Calcite and remove such fixes when upgrade to certain version
for that reason you can find calcite classes in Flink repo e.g. here https://github.com/apache/flink/tree/master/flink-table/flink-table-planner/src/main/java/org/apache/calcite
Uh oh!
There was an error while loading. Please reload this page.
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 would follow similar approach for
MATCH_RECOGNIZEhowever first need to be sure that all cases are fixed in Calcite, for now I'm aware of at least 3-5 more cases which have to be fixedfor instance https://issues.apache.org/jira/browse/CALCITE-7471
Uh oh!
There was an error while loading. Please reload this page.
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, indeed, you are right.
But then I don't understand why solution for FLINK-38493 is correct. Can you help me to understand?
Code before FLINK-38493

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.
it was a workaround because of a bug with
LATERALin Calcite and there was a huge comment trying to explain why we need it.The problem became more serious with MATERIALIZED TABLEs where we might want to use expanded query.
Also if you try to look at other vendors: they also expand star which Flink didn't do.
With this issue we see that we are in a lack of tests for
MATCH_RECOGNIZE(looks like Calcite as well) and that's why it was not detected earlier.for short term we could consider rolling it back, however so far nobody was heavily complaining that hot fix is urgently required. In this case I think we still have time to fix it in a proper way
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 explaining
Now it's clear
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.
Hi both - thanks for the discussion and clarification.
I tend to build my SQL as a series of views, making it more composable and easier to read. E.g (pseudo):
Are there other ways to achieve the same effect without this bug being fixed? My concern is that I now have to write (pseduo):
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.
for. now it is impossible if you use 2.2.0
the fixes in Calcite are still in progress however not ported to Flink repo yet (since not all cases are fixed)
I hope to have it done this/next week, however it means that the fixes might land to Flink branches only. Releases should be done separately