Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d2283d7
java:不兼容的类型: 从int转换到char可能会有损失
Toms1999 Jul 12, 2024
1131d2f
[enhance]Added compatibility with mysql alias conflict
Toms1999 Jul 18, 2024
3bc745c
Revert "[enhance]Added compatibility with mysql alias conflict"
Toms1999 Jul 18, 2024
914fe46
Revert "Revert "[enhance]Added compatibility with mysql alias conflict""
Toms1999 Jul 18, 2024
bdda8f4
delete more
Toms1999 Jul 18, 2024
75bb1cb
add .out files
Toms1999 Jul 19, 2024
9181263
update
Toms1999 Jul 19, 2024
0ae164f
add two table but alias different and
Toms1999 Jul 22, 2024
1597fd3
add two table but alias different and
Toms1999 Jul 22, 2024
93a3b9d
delete error code about for and !
Toms1999 Jul 22, 2024
c35fc74
delete error code GlobalVariable.lowerCaseTableNames
Toms1999 Jul 22, 2024
9ccace1
refactor
Toms1999 Jul 22, 2024
5b49090
check style
Toms1999 Jul 22, 2024
996c5e0
Merge branch 'master' into mysql
Toms1999 Jul 22, 2024
2fc335b
fix alias conflict about test
Toms1999 Jul 22, 2024
e2b79ae
fix alias conflict about test
Toms1999 Jul 22, 2024
1487df5
Merge remote-tracking branch 'origin/mysql' into mysql
Toms1999 Jul 22, 2024
cd30a67
fix alias conflict about test
Toms1999 Jul 22, 2024
de35db4
fix alias conflict about test
Toms1999 Jul 22, 2024
77fbdeb
fix alias conflict about test
Toms1999 Jul 22, 2024
67d5e4a
add catalog/db conflict test
Toms1999 Jul 23, 2024
05c400e
update
Toms1999 Jul 23, 2024
f29b316
delete chinese comment
Toms1999 Jul 23, 2024
95c6c28
delete toString
Toms1999 Jul 23, 2024
9d7e334
check style alter
Toms1999 Jul 23, 2024
91d700a
delete test code
Toms1999 Jul 23, 2024
c766448
fix different db no conflict
Toms1999 Jul 24, 2024
686d710
add out file
Toms1999 Jul 25, 2024
8319304
add filter、agg、sort、limit logcial
Toms1999 Jul 25, 2024
3684b43
fix no db test
Toms1999 Jul 25, 2024
ed3c8c1
add out file
Toms1999 Jul 25, 2024
b26e1e1
add view and catalog logical
Toms1999 Jul 26, 2024
db0d79c
fix catalog sql
Toms1999 Jul 26, 2024
91cdd76
fix catalog sql
Toms1999 Jul 26, 2024
9ca712c
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Jul 31, 2024
a7dcaba
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Jul 31, 2024
bbeeb30
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Jul 31, 2024
b63067f
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Jul 31, 2024
84810dc
Merge branch 'master' into mysql
Toms1999 Jul 31, 2024
8bec952
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 6, 2024
ff07954
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 6, 2024
a8ca793
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 6, 2024
a36c53f
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 6, 2024
961026a
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 6, 2024
0c4850a
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 6, 2024
e9e26a5
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 6, 2024
e83ee86
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 7, 2024
b114772
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 7, 2024
6352b8d
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 15, 2024
7b2e50b
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 16, 2024
5bbccbe
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 19, 2024
d7ec8e5
Merge branch 'master' into mysql
Toms1999 Aug 20, 2024
db67bca
Merge branch 'master' into mysql
Toms1999 Aug 20, 2024
660c733
Merge branch 'master' into mysql
Toms1999 Aug 20, 2024
7c7ffc8
Merge branch 'master' into mysql
Toms1999 Aug 20, 2024
c085183
[chore](nereids) Added compatibility with mysql alias filter
Toms1999 Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -88,8 +90,19 @@ public List<Slot> computeOutput() {
} else {
columnAlias = originSlot.getName();
}
List<String> originQualifier = originSlot.getQualifier();

ArrayList<String> newQualifier = Lists.newArrayList(originQualifier);
if (newQualifier.size() >= qualifier.size()) {
for (int j = 0; j < qualifier.size(); j++) {
newQualifier.set(newQualifier.size() - qualifier.size() + j, qualifier.get(j));
}
} else if (newQualifier.isEmpty()) {
newQualifier.addAll(qualifier);
}

Slot qualified = originSlot
.withQualifier(qualifier)
.withQualifier(newQualifier)
.withName(columnAlias);
currentOutput.add(qualified);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public View getView() {
return view;
}

@Override
public LogicalProperties getLogicalProperties() {
return child().getLogicalProperties();
}

@Override
public Plan withGroupExpression(Optional<GroupExpression> groupExpression) {
return new LogicalView(view, child());
Expand Down Expand Up @@ -123,7 +118,16 @@ public int hashCode() {

@Override
public List<Slot> computeOutput() {
return child().getOutput();
List<Slot> childOutput = child().getOutput();
ImmutableList.Builder<Slot> currentOutput = ImmutableList.builder();
List<String> fullQualifiers = this.view.getFullQualifiers();
for (int i = 0; i < childOutput.size(); i++) {
Slot originSlot = childOutput.get(i);
Slot qualified = originSlot
.withQualifier(fullQualifiers);
currentOutput.add(qualified);
}
return currentOutput.build();
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions regression-test/data/ddl_p0/test_create_view_nereids.out
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ test_backquote_in_view_define CREATE VIEW `test_backquote_in_view_define` AS sel
7 1

-- !test_backquote_in_table_alias_sql --
test_backquote_in_table_alias CREATE VIEW `test_backquote_in_table_alias` AS select `ab``c`.`a` AS `c1`, `ab``c`.`b` AS `c2` from (select `internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`,`internal`.`regression_test_ddl_p0`.`mal_test_view`.`b` from `internal`.`regression_test_ddl_p0`.`mal_test_view`) `ab``c`; utf8mb4 utf8mb4_0900_bin
test_backquote_in_table_alias CREATE VIEW `test_backquote_in_table_alias` AS select `internal`.`regression_test_ddl_p0`.`ab``c`.`a` AS `c1`, `internal`.`regression_test_ddl_p0`.`ab``c`.`b` AS `c2` from (select `internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`,`internal`.`regression_test_ddl_p0`.`mal_test_view`.`b` from `internal`.`regression_test_ddl_p0`.`mal_test_view`) `ab``c`; utf8mb4 utf8mb4_0900_bin

-- !test_generate --
1 10 A 30
Expand Down Expand Up @@ -288,7 +288,7 @@ test_view_table_alias CREATE VIEW `test_view_table_alias` AS select `t`.`c1`, `t
4 40

-- !test_join_table_alias_sql --
test_view_join_table_alias CREATE VIEW `test_view_join_table_alias` AS select `t`.`c1`, `t`.`c2` from (\n select `t1`.`id` as `c1`, `t1`.`value1` as `c2` from `internal`.`regression_test_ddl_p0`.`create_view_table1` `t1` inner join `internal`.`regression_test_ddl_p0`.`create_view_table2` `t2` on `t1`.`id`=`t2`.`id` limit 10) as `t`; utf8mb4 utf8mb4_0900_bin
test_view_join_table_alias CREATE VIEW `test_view_join_table_alias` AS select `t`.`c1`, `t`.`c2` from (\n select `internal`.`regression_test_ddl_p0`.`t1`.`id` as `c1`, `internal`.`regression_test_ddl_p0`.`t1`.`value1` as `c2` from `internal`.`regression_test_ddl_p0`.`create_view_table1` `t1` inner join `internal`.`regression_test_ddl_p0`.`create_view_table2` `t2` on `internal`.`regression_test_ddl_p0`.`t1`.`id`=`internal`.`regression_test_ddl_p0`.`t2`.`id` limit 10) as `t`; utf8mb4 utf8mb4_0900_bin

-- !test_alias_udf --
1****1 1
Expand Down Expand Up @@ -361,5 +361,5 @@ test_having CREATE VIEW `test_having` AS select sum(`internal`.`regression_test_
2 200 1

-- !complicated_view1_sql --
test_view_complicated CREATE VIEW `test_view_complicated` AS SELECT `t`.`id`, `t`.`value3`, `t`.`row_num` FROM (\n SELECT `t1`.`id`, `tt`.`value3`, ROW_NUMBER() OVER (PARTITION BY `t1`.`id` ORDER BY `tt`.`value3` DESC) as `row_num`\n FROM (SELECT `internal`.`regression_test_ddl_p0`.`create_view_table1`.`id` FROM `internal`.`regression_test_ddl_p0`.`create_view_table1` GROUP BY `internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`) `t1`\n FULL OUTER JOIN (SELECT `internal`.`regression_test_ddl_p0`.`create_view_table2`.`value3`, `internal`.`regression_test_ddl_p0`.`create_view_table2`.`id`, MAX(`internal`.`regression_test_ddl_p0`.`create_view_table2`.`value4`) FROM `internal`.`regression_test_ddl_p0`.`create_view_table2` GROUP BY `internal`.`regression_test_ddl_p0`.`create_view_table2`.`value3`, `internal`.`regression_test_ddl_p0`.`create_view_table2`.`id`) `tt`\n ON `tt`.`id` = `t1`.`id`\n ORDER BY `t1`.`id`\n ) `t`\n WHERE `t`.`value3` < 280 AND (`t`.`id` < 3 or `t`.`id` >8); utf8mb4 utf8mb4_0900_bin
test_view_complicated CREATE VIEW `test_view_complicated` AS SELECT `internal`.`regression_test_ddl_p0`.`t`.`id`, `internal`.`regression_test_ddl_p0`.`t`.`value3`, `t`.`row_num` FROM (\n SELECT `internal`.`regression_test_ddl_p0`.`t1`.`id`, `internal`.`regression_test_ddl_p0`.`tt`.`value3`, ROW_NUMBER() OVER (PARTITION BY `internal`.`regression_test_ddl_p0`.`t1`.`id` ORDER BY `internal`.`regression_test_ddl_p0`.`tt`.`value3` DESC) as `row_num`\n FROM (SELECT `internal`.`regression_test_ddl_p0`.`create_view_table1`.`id` FROM `internal`.`regression_test_ddl_p0`.`create_view_table1` GROUP BY `internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`) `t1`\n FULL OUTER JOIN (SELECT `internal`.`regression_test_ddl_p0`.`create_view_table2`.`value3`, `internal`.`regression_test_ddl_p0`.`create_view_table2`.`id`, MAX(`internal`.`regression_test_ddl_p0`.`create_view_table2`.`value4`) FROM `internal`.`regression_test_ddl_p0`.`create_view_table2` GROUP BY `internal`.`regression_test_ddl_p0`.`create_view_table2`.`value3`, `internal`.`regression_test_ddl_p0`.`create_view_table2`.`id`) `tt`\n ON `internal`.`regression_test_ddl_p0`.`tt`.`id` = `internal`.`regression_test_ddl_p0`.`t1`.`id`\n ORDER BY `internal`.`regression_test_ddl_p0`.`t1`.`id`\n ) `t`\n WHERE `internal`.`regression_test_ddl_p0`.`t`.`value3` < 280 AND (`internal`.`regression_test_ddl_p0`.`t`.`id` < 3 or `internal`.`regression_test_ddl_p0`.`t`.`id` >8); utf8mb4 utf8mb4_0900_bin

24 changes: 24 additions & 0 deletions regression-test/data/nereids_syntax_p0/filter_with_alias.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !filter_select1 --
1 Alice

-- !filter_select2 --
1 Alice

-- !filter_select3 --
1 Alice

-- !filter_select4 --
1 Alice

-- !filter_select5 --
1 Alice

-- !filter_select6 --
1
2
3

-- !filter_select7 --
111

81 changes: 81 additions & 0 deletions regression-test/suites/nereids_syntax_p0/filter_with_alias.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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("filter_with_alias") {

sql "drop database if exists filter_alias_test;"

sql """ CREATE DATABASE IF NOT EXISTS `filter_alias_test` """

sql """
CREATE TABLE `filter_alias_test`.`test` (
`id` int(11) NOT NULL,
`name` varchar(255) NULL
) ENGINE = OLAP DUPLICATE KEY(`id`) COMMENT 'OLAP' DISTRIBUTED BY HASH(`id`) BUCKETS 10 PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false", "storage_format" = "V2",
"disable_auto_compaction" = "false"
);
"""

sql """
insert into `filter_alias_test`.`test` values (1, 'Alice'), (2, 'Bob'), (3, 'Carol');
"""
test {
sql " select * from internal.filter_alias_test.test b where internal.filter_alias_test.test.id = 1;"
exception "Unknown column 'id' in 'internal.filter_alias_test.test' in FILTER clause"
}

// Test using alias in WHERE clause directly
qt_filter_select1 """
select * from `filter_alias_test`.`test` b where b.id = 1;
"""

// Test using table name without alias in WHERE clause
qt_filter_select2 """
select * from `filter_alias_test`.`test` where id = 1;
"""


test {
sql " select * from filter_alias_test.test b where filter_alias_test.test.id = 1;"
exception "Unknown column 'id' in 'filter_alias_test.test' in FILTER clause"
}

qt_filter_select3 """
select * from filter_alias_test.test where filter_alias_test.test.id = 1;
"""

qt_filter_select4 """
select * from filter_alias_test.test b where filter_alias_test.b.id = 1;
"""

qt_filter_select5 """
select * from internal.filter_alias_test.test b where internal.filter_alias_test.b.id = 1;
"""

qt_filter_select6 """
select * from (select id from filter_alias_test.test as b ) as toms order by id;
"""

qt_filter_select7 """
select 111 from (select current_date() as toms) as toms2;
"""

sql "drop database if exists filter_alias_test;"

}