-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[FLINK-27741][table-planner] Fix NPE when use dense_rank() and rank()… #19797
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ class OverAggregateTest extends TableTestBase { | |
|
||
private val util = batchTestUtil() | ||
util.addTableSource[(Int, Long, String)]("MyTable", 'a, 'b, 'c) | ||
util.addTableSource[(Int, Long, String, Long)]("MyTableWithProctime", 'a, 'b, 'c, 'proctime) | ||
|
||
@Test | ||
def testOverWindowWithoutPartitionByOrderBy(): Unit = { | ||
|
@@ -47,6 +48,18 @@ class OverAggregateTest extends TableTestBase { | |
util.verifyExecPlan("SELECT c, SUM(a) OVER (ORDER BY b) FROM MyTable") | ||
} | ||
|
||
@Test | ||
def testDenseRankOnOrder(): Unit = { | ||
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. The plan tests in batch mode appear not to be able to capture the modifications introduced by this PR, and I apologize for mentioning the unit test for the plan earlier. I've attempted this case, and it seems only possible to test it within an integration test in stream mode. I propose we can add another testRankOnOver test specifically for testing the RANK() function. Additionally, there seems to be a potential risk of encountering a NPE in // ---------- 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.
this I didn't get, there is already
yep, makes sense, I extracted the logic and reused it for §createPercentRankAggFunction` as well 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. What I mean is to add a test 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. Besides plans there are already a test in 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. Oh, I missed it. Pardon me... |
||
util.verifyExecPlan( | ||
"SELECT a, DENSE_RANK() OVER (PARTITION BY a ORDER BY proctime) FROM MyTableWithProctime") | ||
} | ||
|
||
@Test | ||
def testRankOnOver(): Unit = { | ||
util.verifyExecPlan( | ||
"SELECT a, RANK() OVER (PARTITION BY a ORDER BY proctime) FROM MyTableWithProctime") | ||
} | ||
|
||
@Test | ||
def testDiffPartitionKeysWithSameOrderKeys(): Unit = { | ||
val sqlQuery = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,66 @@ class OverAggregateITCase(mode: StateBackendMode) extends StreamingWithStateTest | |
assertThat(sink.getAppendResults.sorted).isEqualTo(expected.sorted) | ||
} | ||
|
||
@TestTemplate | ||
def testDenseRankOnOver(): Unit = { | ||
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. Maybe you can add some test cases for testing plan, not only just for ITCases. 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. Hi, @xuyangzhong . Thanks for your review and sorry for delay response. I didn't find the UT of AggFunctionFactory, so I borrowed the test for ROW_NUMBER. And I haven't waited for the community's reply, I can add corresponding unit tests later if necessary. |
||
val t = failingDataSource(TestData.tupleData5) | ||
.toTable(tEnv, 'a, 'b, 'c, 'd, 'e, 'proctime.proctime) | ||
tEnv.createTemporaryView("MyTable", t) | ||
val sqlQuery = "SELECT a, DENSE_RANK() OVER (PARTITION BY a ORDER BY proctime) FROM MyTable" | ||
|
||
val sink = new TestingAppendSink | ||
tEnv.sqlQuery(sqlQuery).toDataStream.addSink(sink) | ||
env.execute() | ||
|
||
val expected = List( | ||
"1,1", | ||
"2,1", | ||
"2,2", | ||
"3,1", | ||
"3,2", | ||
"3,3", | ||
"4,1", | ||
"4,2", | ||
"4,3", | ||
"4,4", | ||
"5,1", | ||
"5,2", | ||
"5,3", | ||
"5,4", | ||
"5,5") | ||
assertThat(expected.sorted).isEqualTo(sink.getAppendResults.sorted) | ||
} | ||
|
||
@TestTemplate | ||
def testRankOnOver(): Unit = { | ||
val t = failingDataSource(TestData.tupleData5) | ||
.toTable(tEnv, 'a, 'b, 'c, 'd, 'e, 'proctime.proctime) | ||
tEnv.createTemporaryView("MyTable", t) | ||
val sqlQuery = "SELECT a, RANK() OVER (PARTITION BY a ORDER BY proctime) FROM MyTable" | ||
|
||
val sink = new TestingAppendSink | ||
tEnv.sqlQuery(sqlQuery).toDataStream.addSink(sink) | ||
env.execute() | ||
|
||
val expected = List( | ||
"1,1", | ||
"2,1", | ||
"2,2", | ||
"3,1", | ||
"3,2", | ||
"3,3", | ||
"4,1", | ||
"4,2", | ||
"4,3", | ||
"4,4", | ||
"5,1", | ||
"5,2", | ||
"5,3", | ||
"5,4", | ||
"5,5") | ||
assertThat(expected.sorted).isEqualTo(sink.getAppendResults.sorted) | ||
} | ||
|
||
@TestTemplate | ||
def testProcTimeBoundedPartitionedRowsOver(): Unit = { | ||
val t = failingDataSource(TestData.tupleData5) | ||
|
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, I just wander why this value should be changed ?
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.
@xuyangzhong The default value of true will cause the sort value to be unchanged, which I don't think conforms to the semantics of sorting.