-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](nereids)fix first_value/lead/lag window function bug in nereids #17315
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -811,12 +811,18 @@ public PlanFragment visitPhysicalWindow(PhysicalWindow<? extends Plan> physicalW | |
|
|
||
| if (partitionExprs.isEmpty() && orderByElements.isEmpty()) { | ||
| if (inputPlanFragment.isPartitioned()) { | ||
| inputPlanFragment = createParentFragment(inputPlanFragment, DataPartition.UNPARTITIONED, context); | ||
|
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. when fragment.root is exchange, it is wrong to call createParentFragment(fragment, ...) |
||
| PlanFragment parentFragment = new PlanFragment(context.nextFragmentId(), analyticEvalNode, | ||
| DataPartition.UNPARTITIONED); | ||
| context.addPlanFragment(parentFragment); | ||
| connectChildFragment(analyticEvalNode, 0, parentFragment, inputPlanFragment, context); | ||
| inputPlanFragment = parentFragment; | ||
| } else { | ||
| inputPlanFragment.addPlanRoot(analyticEvalNode); | ||
| } | ||
| } else { | ||
| analyticEvalNode.setNumInstances(inputPlanFragment.getPlanRoot().getNumInstances()); | ||
| inputPlanFragment.addPlanRoot(analyticEvalNode); | ||
| } | ||
| addPlanRoot(inputPlanFragment, analyticEvalNode, physicalWindow); | ||
| return inputPlanFragment; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
regression-test/data/nereids_function_p0/window_function/first_value_window.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- This file is automatically generated. You should know what you did if you want to edit this | ||
| -- !select_default -- | ||
| 21 04-21-11 1 1 | ||
| 22 04-22-10-21 0 0 | ||
| 22 04-22-10-21 1 1 | ||
| 23 04-23-10 1 1 | ||
| 24 02-24-10-21 1 1 | ||
|
|
21 changes: 21 additions & 0 deletions
21
regression-test/data/nereids_function_p0/window_function/lag_lead_window.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| -- This file is automatically generated. You should know what you did if you want to edit this | ||
| -- !select_default -- | ||
| a aa /wyyt-image/2021/11/13/595345040188712460.jpg unknown | ||
| b aa /wyyt-image/2022/04/13/1434607674511761493.jpg unknown | ||
| c cc /wyyt-image/2022/04/13/1434607674511761493.jpg /wyyt-image/2022/04/13/1434607674511761493.jpg | ||
|
|
||
| -- !select_default2 -- | ||
| a aa /wyyt-image/2021/11/13/595345040188712460.jpg | ||
| b aa /wyyt-image/2022/04/13/1434607674511761493.jpg /wyyt-image/2022/04/13/1434607674511761493.jpg | ||
| c cc /wyyt-image/2022/04/13/1434607674511761493.jpg | ||
|
|
||
| -- !select_default -- | ||
| a 2022-09-06T00:00 2022-09-06T00:00 | ||
| b 2022-09-06T00:00:01 2022-09-06T00:00 | ||
| c 2022-09-06T00:00:02 2022-09-06T00:00:01 | ||
|
|
||
| -- !select_default -- | ||
| a 2022-09-06T00:00 2022-08-30T00:00 | ||
| b 2022-09-06T00:00:01 2022-09-06T00:00 | ||
| c 2022-09-06T00:00:02 2022-09-06T00:00:01 | ||
|
|
6 changes: 6 additions & 0 deletions
6
regression-test/data/nereids_p0/join/outer_join_with_empty_node.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- This file is automatically generated. You should know what you did if you want to edit this | ||
| -- !select -- | ||
|
|
||
| -- !select -- | ||
| 1 1 1 | ||
|
|
49 changes: 49 additions & 0 deletions
49
regression-test/suites/nereids_function_p0/window_function/first_value_window.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| suite("nereids_first_value_window") { | ||
| sql 'use regression_test_nereids_function_p0' | ||
| sql 'set enable_nereids_planner=true' | ||
| sql 'set enable_fallback_to_original_planner=false' | ||
| def tableName = "nereids_first_value_window_state" | ||
|
|
||
| sql """ DROP TABLE IF EXISTS ${tableName} """ | ||
| sql """ | ||
| CREATE TABLE IF NOT EXISTS ${tableName} ( | ||
| `myday` INT, | ||
| `time_col` VARCHAR(40) NOT NULL, | ||
| `state` INT | ||
| ) ENGINE=OLAP | ||
| DUPLICATE KEY(`myday`,time_col,state) | ||
| COMMENT "OLAP" | ||
| DISTRIBUTED BY HASH(`myday`) BUCKETS 2 | ||
| PROPERTIES ( | ||
| "replication_num" = "1", | ||
| "in_memory" = "false", | ||
| "storage_format" = "V2" | ||
| ); | ||
| """ | ||
|
|
||
| sql """ INSERT INTO ${tableName} VALUES | ||
| (21,"04-21-11",1), | ||
| (22,"04-22-10-21",0), | ||
| (22,"04-22-10-21",1), | ||
| (23,"04-23-10",1), | ||
| (24,"02-24-10-21",1); """ | ||
|
|
||
| qt_select_default """ select *,first_value(state) over(partition by myday order by time_col range between current row and unbounded following) from ${tableName} order by myday, time_col, state; """ | ||
| } |
58 changes: 58 additions & 0 deletions
58
regression-test/suites/nereids_function_p0/window_function/lag_lead_window.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| suite("nereids_lag_lead_window") { | ||
| sql 'use regression_test_nereids_function_p0' | ||
| sql 'set enable_nereids_planner=true' | ||
| sql 'set enable_fallback_to_original_planner=false' | ||
| def tableName = "wftest" | ||
|
|
||
|
|
||
| sql """ DROP TABLE IF EXISTS ${tableName} """ | ||
| sql """ | ||
| CREATE TABLE IF NOT EXISTS ${tableName} ( `aa` varchar(10) NULL COMMENT "", `bb` text NULL COMMENT "", `cc` text NULL COMMENT "" ) | ||
| ENGINE=OLAP UNIQUE KEY(`aa`) DISTRIBUTED BY HASH(`aa`) BUCKETS 3 | ||
| PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "in_memory" = "false", "storage_format" = "V2" ); | ||
| """ | ||
|
|
||
| sql """ INSERT INTO ${tableName} VALUES | ||
| ('a','aa','/wyyt-image/2021/11/13/595345040188712460.jpg'), | ||
| ('b','aa','/wyyt-image/2022/04/13/1434607674511761493.jpg'), | ||
| ('c','cc','/wyyt-image/2022/04/13/1434607674511761493.jpg') """ | ||
|
|
||
| qt_select_default """ | ||
| select aa, bb, min(cc) over(PARTITION by cc order by aa) , | ||
| lag(cc,1,'unknown') over (PARTITION by cc order by aa) as lag_cc | ||
| from ${tableName} | ||
| order by aa; """ | ||
|
|
||
| qt_select_default2 """ select aa, bb, min(cc) over(PARTITION by cc order by aa) , | ||
| lead(cc,1,'') over (PARTITION by cc order by aa) as lead_cc | ||
| from ${tableName} | ||
| order by aa; """ | ||
| sql """ DROP TABLE IF EXISTS test1 """ | ||
| sql """ CREATE TABLE IF NOT EXISTS test1 (id varchar(255), create_time datetime) | ||
| DISTRIBUTED BY HASH(id) PROPERTIES("replication_num" = "1"); """ | ||
| sql """ INSERT INTO test1 VALUES | ||
| ('a','2022-09-06 00:00:00'), | ||
| ('b','2022-09-06 00:00:01'), | ||
| ('c','2022-09-06 00:00:02') """ | ||
| qt_select_default """ select id, create_time, lead(create_time, 1, '2022-09-06 00:00:00') over | ||
| (order by create_time desc) as "prev_time" from test1 order by id; """ | ||
| qt_select_default """ select id, create_time, lead(create_time, 1, date_sub('2022-09-06 00:00:00', interval 7 day)) over (order by create_time desc) as "prev_time" from test1 order by id; """ | ||
| sql """ DROP TABLE IF EXISTS test1 """ | ||
| } |
83 changes: 83 additions & 0 deletions
83
regression-test/suites/nereids_p0/join/outer_join_with_empty_node.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| suite("nereids_outer_join_with_empty_node") { | ||
| sql "SET enable_nereids_planner=true" | ||
| sql "SET enable_fallback_to_original_planner=false" | ||
|
|
||
| sql """ | ||
| drop table if exists outer_join_with_empty_node_t1; | ||
| """ | ||
|
|
||
| sql """ | ||
| drop table if exists outer_join_with_empty_node_t2; | ||
| """ | ||
|
|
||
| sql """ | ||
| CREATE TABLE IF NOT EXISTS `outer_join_with_empty_node_t1` ( | ||
| `k1` int(11) NULL COMMENT "", | ||
| `k2` int(11) NULL COMMENT "" | ||
| ) ENGINE=OLAP | ||
| DUPLICATE KEY(`k1`, `k2`) | ||
| COMMENT "OLAP" | ||
| DISTRIBUTED BY HASH(`k1`) BUCKETS 1 | ||
| PROPERTIES ( | ||
| "replication_allocation" = "tag.location.default: 1", | ||
| "in_memory" = "false", | ||
| "storage_format" = "V2" | ||
| ); | ||
| """ | ||
|
|
||
| sql """ | ||
| CREATE TABLE IF NOT EXISTS `outer_join_with_empty_node_t2` ( | ||
| `j1` int(11) NULL COMMENT "", | ||
| `j2` int(11) NULL COMMENT "" | ||
| ) ENGINE=OLAP | ||
| DUPLICATE KEY(`j1`, `j2`) | ||
| COMMENT "OLAP" | ||
| DISTRIBUTED BY HASH(`j1`) BUCKETS 1 | ||
| PROPERTIES ( | ||
| "replication_allocation" = "tag.location.default: 1", | ||
| "in_memory" = "false", | ||
| "storage_format" = "V2" | ||
| ); | ||
| """ | ||
|
|
||
| sql """ | ||
| insert into outer_join_with_empty_node_t1 values(1, 1); | ||
| """ | ||
|
|
||
| sql """ | ||
| insert into outer_join_with_empty_node_t2 values(1, 1); | ||
| """ | ||
|
|
||
| qt_select """ | ||
| select * from outer_join_with_empty_node_t1 left join (select max(j1) over() as x from outer_join_with_empty_node_t2)a on outer_join_with_empty_node_t1.k1=a.x where 1=0; | ||
| """ | ||
|
|
||
| qt_select """ | ||
| select * from outer_join_with_empty_node_t1 left join (select max(j1) over() as x from outer_join_with_empty_node_t2)a on outer_join_with_empty_node_t1.k1=a.x where 1=1; | ||
| """ | ||
|
|
||
| sql """ | ||
| drop table if exists outer_join_with_empty_node_t1; | ||
| """ | ||
|
|
||
| sql """ | ||
| drop table if exists outer_join_with_empty_node_t2; | ||
| """ | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
seems the default value must be const, so if it's nullable_column, the default value must be NULL?
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.
new nereids planner may add a cast to literal string internally like:
select id, create_time, lead(create_time, 1, '2022-09-06 00:00:00') over (order by create_time desc) as "prev_time" from test1;->
select id, create_time, lead(create_time, 1, cast('2022-09-06 00:00:00' as datetime)) over (order by create_time desc) as "prev_time" from test1;so, the above code is added for compatibility of nereids planner