This is an automated email from the ASF dual-hosted git repository.

huajianlan pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 30a1ffe221a [chore](nereids) Added compatibility with mysql alias 
filter (#39810)
30a1ffe221a is described below

commit 30a1ffe221ad59e5e5db2ee7a5bc44ada9b93012
Author: toms <94617906+toms1...@users.noreply.github.com>
AuthorDate: Mon Aug 26 14:53:10 2024 +0800

    [chore](nereids) Added compatibility with mysql alias filter (#39810)
    
    throw table name/alias conflict exception to keep same behavior with mysql
    
    for example:
    ```sql
    select * from test.a b, test.b
    ```
    
    error:
    ```
    Not unique table/alias: 'b'
    ```
---
 .../java/org/apache/doris/analysis/Analyzer.java   |   3 +-
 .../trees/plans/logical/LogicalSubQueryAlias.java  |  15 +-
 .../data/ddl_p0/test_create_view_nereids.out       | 365 +++++++++++++++++++++
 .../data/nereids_syntax_p0/filter_with_alias.out   |  24 ++
 .../nereids_syntax_p0/filter_with_alias.groovy     |  81 +++++
 5 files changed, 486 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
index 18a4fa68507..b17182abbee 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
@@ -689,7 +689,8 @@ public class Analyzer {
     public TupleDescriptor registerTableRef(TableRef ref) throws 
AnalysisException {
         String uniqueAlias = ref.getUniqueAlias();
         if (uniqueTableAliasSet.contains(uniqueAlias)) {
-            ErrorReport.reportAnalysisException(ErrorCode.ERR_NONUNIQ_TABLE, 
uniqueAlias);
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_NONUNIQ_TABLE,
+                    uniqueAlias.substring(uniqueAlias.lastIndexOf('.') + 1));
         }
         uniqueTableAliasSet.add(uniqueAlias);
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSubQueryAlias.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSubQueryAlias.java
index 2dae1f0f636..a74553beb21 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSubQueryAlias.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSubQueryAlias.java
@@ -29,9 +29,11 @@ import org.apache.doris.nereids.util.Utils;
 
 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.List;
 import java.util.Objects;
 import java.util.Optional;
@@ -85,8 +87,19 @@ public class LogicalSubQueryAlias<CHILD_TYPE extends Plan> 
extends LogicalUnary<
             } 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);
         }
diff --git a/regression-test/data/ddl_p0/test_create_view_nereids.out 
b/regression-test/data/ddl_p0/test_create_view_nereids.out
new file mode 100644
index 00000000000..8ee98fa7021
--- /dev/null
+++ b/regression-test/data/ddl_p0/test_create_view_nereids.out
@@ -0,0 +1,365 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !test_view_1 --
+1      [1, 2, 3]
+2      [10, -2, 8]
+3      [-1, 20, 0]
+
+-- !test_view_2 --
+1      [1, 2, 3]       [1, 1, 1]
+2      [10, -2, 8]     [1, 0, 1]
+3      [-1, 20, 0]     [0, 1, 0]
+
+-- !test_view_3 --
+1      [1, 2, 3]       [1, 2, 3]       [1, 2, 3]
+2      [10, -2, 8]     [10, 8] [10, 8]
+3      [-1, 20, 0]     [20]    [20]
+
+-- !test_view_4 --
+1      [1, 2, 3]       [1, 2, 3]       [1, 2, 3]
+2      [10, -2, 8]     [10, 8] [10, 8]
+3      [-1, 20, 0]     [20]    [20]
+
+-- !test_view_5 --
+1      [1, 2, 3]       [1, 1, 1]
+2      [10, -2, 8]     [1, 0, 1]
+3      [-1, 20, 0]     [0, 1, 0]
+
+-- !test_view_6 --
+v1     CREATE VIEW `v1` AS SELECT\n      
`internal`.`regression_test_ddl_p0`.`view_column_name_test_nereids`.`error_code`,
 \n      1, \n      'string', \n      now(), \n      
dayofyear(`internal`.`regression_test_ddl_p0`.`view_column_name_test_nereids`.`op_time`),
 \n      cast 
(`internal`.`regression_test_ddl_p0`.`view_column_name_test_nereids`.`source` 
AS BIGINT), \n      
min(`internal`.`regression_test_ddl_p0`.`view_column_name_test_nereids`.`timestamp`)
 OVER (\n        ORDER BY \n         [...]
+
+-- !test_with_as --
+1      1       2
+1      1       4
+1      3       6
+2      1       3
+2      1       4
+2      1       7
+2      3       5
+2      3       9
+2      4       2
+3      2       8
+3      5       \N
+3      5       6
+3      5       6
+3      5       8
+4      5       6
+6      \N      6
+6      7       1
+
+-- !test_with_as_sql --
+test_view_with_as      CREATE VIEW `test_view_with_as` AS (\n            with 
`t1` as (select `internal`.`regression_test_ddl_p0`.`mal_test_view`.`pk`, 
`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`),  `t2` as (select 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`pk`, 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`, 
`internal`.`regression_test_ddl_p0`.`mal_ [...]
+
+-- !test_union --
+1      1       2
+1      1       2
+1      1       4
+1      1       4
+1      3       6
+1      3       6
+2      1       3
+2      1       3
+2      1       4
+2      1       4
+2      1       7
+2      1       7
+2      3       5
+2      3       5
+2      3       9
+2      3       9
+2      4       2
+2      4       2
+3      2       8
+3      2       8
+3      5       \N
+3      5       \N
+3      5       6
+3      5       6
+3      5       6
+3      5       6
+3      5       8
+3      5       8
+4      5       6
+4      5       6
+6      \N      6
+6      \N      6
+6      7       1
+6      7       1
+
+-- !test_union_sql --
+test_view_union        CREATE VIEW `test_view_union` AS (select 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`pk` AS `c1`, 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a` AS `c2`, 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`b` AS `c3` from 
`internal`.`regression_test_ddl_p0`.`mal_test_view` Union all SELECT 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`pk`, 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`, 
`internal`.`regression_test_ddl_p0`.`mal_test_view` [...]
+
+-- !test_count_star --
+17
+
+-- !test_count_star_sql --
+test_view_count_star   CREATE VIEW `test_view_count_star` AS (select count(*) 
AS `c1` from `internal`.`regression_test_ddl_p0`.`mal_test_view` having 
count(*) > 0);   utf8mb4 utf8mb4_0900_bin
+
+-- !test_expression --
+\N     \N      6
+2      4       2
+2      4       3
+2      4       4
+2      4       4
+2      4       7
+3      5       8
+4      6       5
+4      6       6
+4      6       9
+5      7       2
+6      8       \N
+6      8       6
+6      8       6
+6      8       6
+6      8       8
+8      10      1
+
+-- !test_expression_sql --
+test_view_expression   CREATE VIEW `test_view_expression` AS (select 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`+1 AS `c1`, 
abs(`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`)+2+1 AS `c2`, 
cast(`internal`.`regression_test_ddl_p0`.`mal_test_view`.`b` as varchar(10)) AS 
`c3` from `internal`.`regression_test_ddl_p0`.`mal_test_view`);      utf8mb4 
utf8mb4_0900_bin
+
+-- !test_alias --
+\N     \N      6
+2      4       2
+2      4       3
+2      4       4
+2      4       4
+2      4       7
+3      5       8
+4      6       5
+4      6       6
+4      6       9
+5      7       2
+6      8       \N
+6      8       6
+6      8       6
+6      8       6
+6      8       8
+8      10      1
+
+-- !test_alias_sql --
+test_view_alias        CREATE VIEW `test_view_alias` AS (\n        select 
`t`.`c8` AS `c1`, `t`.`c2` AS `c2`, `t`.`c1` AS `c3` from (select 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`+1 
`c8`,abs(`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`)+2+1 as `c2`, 
cast(`internal`.`regression_test_ddl_p0`.`mal_test_view`.`b` as varchar(10)) as 
`c1` from `internal`.`regression_test_ddl_p0`.`mal_test_view`) `t`);      
utf8mb4 utf8mb4_0900_bin
+
+-- !test_star_except --
+\N     6
+1      2
+1      3
+1      4
+1      4
+1      7
+2      8
+3      5
+3      6
+3      9
+4      2
+5      \N
+5      6
+5      6
+5      6
+5      8
+7      1
+
+-- !test_star_except_sql --
+test_view_star_except  CREATE VIEW `test_view_star_except` AS 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`;        utf8mb4 
utf8mb4_0900_bin
+
+-- !test_create_view_from_view --
+1      1       2
+1      1       4
+1      3       6
+2      1       3
+2      1       4
+2      1       7
+2      3       5
+2      3       9
+2      4       2
+3      2       8
+3      5       \N
+3      5       6
+3      5       6
+3      5       8
+4      5       6
+6      \N      6
+6      7       1
+
+-- !test_create_view_from_view_sql --
+test_view_from_view    CREATE VIEW `test_view_from_view` AS select 
`internal`.`regression_test_ddl_p0`.`test_view_with_as`.`pk` AS `c1`, 
`internal`.`regression_test_ddl_p0`.`test_view_with_as`.`a` AS `c2`, 
`internal`.`regression_test_ddl_p0`.`test_view_with_as`.`b` AS `c3` from 
`internal`.`regression_test_ddl_p0`.`test_view_with_as`;        utf8mb4 
utf8mb4_0900_bin
+
+-- !test_backquote_in_view_define --
+\N     6
+1      2
+1      3
+1      4
+1      4
+1      7
+2      8
+3      5
+3      6
+3      9
+4      2
+5      \N
+5      6
+5      6
+5      6
+5      8
+7      1
+
+-- !test_backquote_in_view_define_sql --
+test_backquote_in_view_define  CREATE VIEW `test_backquote_in_view_define` AS 
select `internal`.`regression_test_ddl_p0`.`mal_test_view`.`a` AS `ab``c`, 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`b` AS `c2` from 
`internal`.`regression_test_ddl_p0`.`mal_test_view`;     utf8mb4 
utf8mb4_0900_bin
+
+-- !test_backquote_in_table_alias --
+\N     6
+1      2
+1      3
+1      4
+1      4
+1      7
+2      8
+3      5
+3      6
+3      9
+4      2
+5      \N
+5      6
+5      6
+5      6
+5      8
+7      1
+
+-- !test_backquote_in_table_alias_sql --
+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
+1      10      A       60
+2      20      B       30
+2      20      B       60
+3      30      C       30
+3      30      C       60
+4      40      D       30
+4      40      D       60
+
+-- !test_generate_sql --
+test_view_generate     CREATE VIEW `test_view_generate` AS select 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`, 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`value1`, 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`value2`, `t1`.`age` 
from `internal`.`regression_test_ddl_p0`.`create_view_table1` lateral view 
EXPLODE(ARRAY(30,60)) `t1` as `age`;      utf8mb4 utf8mb4_0900_bin
+
+-- !test_generate_with_column --
+1      10      A       0
+2      20      B       0
+2      20      B       1
+3      30      C       0
+3      30      C       1
+3      30      C       2
+4      40      D       0
+4      40      D       1
+4      40      D       2
+4      40      D       3
+
+-- !test_generate_with_column_sql --
+test_view_generate_with_column CREATE VIEW `test_view_generate_with_column` AS 
select `internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`, 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`value1`, 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`value2`, `t1`.`age` 
from `internal`.`regression_test_ddl_p0`.`create_view_table1` lateral view 
EXPLODE_numbers(`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`) 
`t1` as `age`; utf8mb4 utf8mb4_0900_bin
+
+-- !test_col_alias --
+1      10
+2      20
+3      30
+4      40
+
+-- !test_col_alias_sql --
+test_view_col_alias    CREATE VIEW `test_view_col_alias` AS select 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id` as `c1`, 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`value1` as `c2` from 
`internal`.`regression_test_ddl_p0`.`create_view_table1`;     utf8mb4 
utf8mb4_0900_bin
+
+-- !test_col_alias_with_specific_name --
+1      10
+2      20
+3      30
+4      40
+
+-- !test_col_alias_with_specific_name_sql --
+test_view_col_alias_specific_name      CREATE VIEW 
`test_view_col_alias_specific_name` AS select 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id` AS `col1`, 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`value1` AS `col2` 
from `internal`.`regression_test_ddl_p0`.`create_view_table1`;   utf8mb4 
utf8mb4_0900_bin
+
+-- !test_table_alias --
+1      10
+2      20
+3      30
+4      40
+
+-- !test_table_alias_sql --
+test_view_table_alias  CREATE VIEW `test_view_table_alias` AS select `t`.`c1`, 
`t`.`c2` from (\n            select 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id` as `c1`, 
`internal`.`regression_test_ddl_p0`.`create_view_table1`.`value1` as `c2` from 
`internal`.`regression_test_ddl_p0`.`create_view_table1` limit 10) as `t`;    
utf8mb4 utf8mb4_0900_bin
+
+-- !test_join_table_alias --
+1      10
+2      20
+3      30
+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 
`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`;  ut [...]
+
+-- !test_alias_udf --
+1****1 1
+2****2 2
+3****3 3
+4****4 4
+
+-- !test_alias_udf_sql --
+test_view_alias_udf    CREATE VIEW `test_view_alias_udf` AS (select 
`regression_test_ddl_p0`.`alias_function_create_view_test`(`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`)
 as `c1`,abs(`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`) 
from `internal`.`regression_test_ddl_p0`.`create_view_table1`);       utf8mb4 
utf8mb4_0900_bin
+
+-- !test_alias_with_db_udf --
+1****1 1
+2****2 2
+3****3 3
+4****4 4
+
+-- !test_alias_with_db_udf_sql --
+test_view_alias_udf_with_db    CREATE VIEW `test_view_alias_udf_with_db` AS 
(select 
`regression_test_ddl_p0`.`alias_function_create_view_test`(`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`)
 as `c1`,abs(`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`) 
from `internal`.`regression_test_ddl_p0`.`create_view_table1`);       utf8mb4 
utf8mb4_0900_bin
+
+-- !test_udf_sql --
+test_view_udf  CREATE VIEW `test_view_udf` AS (select 
`regression_test_ddl_p0`.`alias_function_create_view_test`(`internal`.`regression_test_ddl_p0`.`create_view_table1`.`id`)
 as `c1`, 
`regression_test_ddl_p0`.`java_udf_create_view_test`('2011-01-01','2011-01-02'),\n
        
`regression_test_ddl_p0`.`java_udf_create_view_test`('2011-01-01','2011-01-03') 
from `internal`.`regression_test_ddl_p0`.`create_view_table1`);     utf8mb4 
utf8mb4_0900_bin
+
+-- !test_udf --
+1****1 false   false
+2****2 false   false
+3****3 false   false
+4****4 false   false
+
+-- !test_with_as_with_columns --
+1      1       2
+1      1       4
+1      3       6
+2      1       3
+2      1       4
+2      1       7
+2      3       5
+2      3       9
+2      4       2
+3      2       8
+3      5       \N
+3      5       6
+3      5       6
+3      5       8
+4      5       6
+6      \N      6
+6      7       1
+
+-- !test_with_as_with_columns_sql --
+test_view_with_as_with_columns CREATE VIEW `test_view_with_as_with_columns` AS 
(\n            with `t1`(`c1`,`c2`,`c3`) as (select 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`pk`, 
`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`),  `t2` as (select 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`pk`, 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`, [...]
+
+-- !test_having --
+2      2
+3      3
+4      2
+4      4
+5      5
+6      3
+7      7
+8      4
+9      3
+10     5
+14     7
+15     5
+
+-- !test_having_sql --
+test_having    CREATE VIEW `test_having` AS select 
sum(`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`) over(partition by 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a` order by 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`pk`) as `c1` , 
`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a` from 
`internal`.`regression_test_ddl_p0`.`mal_test_view` group by grouping 
sets((`internal`.`regression_test_ddl_p0`.`mal_test_view`.`a`),(`internal`.`regression_test_ddl_p0`.`
 [...]
+
+-- !complicated_view1 --
+1      100     1
+2      200     1
+
+-- !complicated_view1_sql --
+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`.`regress [...]
+
diff --git a/regression-test/data/nereids_syntax_p0/filter_with_alias.out 
b/regression-test/data/nereids_syntax_p0/filter_with_alias.out
new file mode 100644
index 00000000000..9f98ed3a49e
--- /dev/null
+++ b/regression-test/data/nereids_syntax_p0/filter_with_alias.out
@@ -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
+
diff --git a/regression-test/suites/nereids_syntax_p0/filter_with_alias.groovy 
b/regression-test/suites/nereids_syntax_p0/filter_with_alias.groovy
new file mode 100644
index 00000000000..e40ab3e3ae1
--- /dev/null
+++ b/regression-test/suites/nereids_syntax_p0/filter_with_alias.groovy
@@ -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 'filter_alias_test.test'"
+    }
+
+    // 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'"
+    }
+
+    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;"
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to