Files
doris/regression-test/data/ddl_p0/test_create_view.out
JingDas 263631e983 [improvement](meta) Infer the column name when create view if the column is expression (#24990)
## Proposed changes

Infer the column name when create view if the column is expression

## Further comments
expr column name infer strategy as following:
|      expr       |                example                    |           column name(before)             | Inferred column name(if position is 2)  |
|  -------------  | ---------------------------------------   | ------------------------------            | --------------------------------------  |
| function        | dayofyear()                               | dayofyear()                               | __dayofyear_1                           |
| cast            | cast(1 as bigint)                         | CAST(1 AS BIGINT)                         | __cast_1                                |
| anylyticExpr    | min()                                     | min()                                     | __min_1                                 |
| predicate       | 1 in (1,2,3,4)                            | 1 IN (1, 2, 3, 4)                         | __in_predicate_1                        |
| literal         | 1 or 'string_var_name'                    | 1 or 'string_var_name'                    | __literal_1                             |
| arithmeticExpr  | &                                         | ... & ...                                 | __arithmetic_expr_1                     |
| identifier      | a or b                                    | a or b                                    | a or b                                  |
| case            | CASE WHEN remark = 's' THEN 1 ELSE 2 END  | CASE WHEN remark = 's' THEN 1 ELSE 2 END  | __case_1                                |
| window          | min(timestamp) OVER (...)                 | min(timestamp) OVER(...)                  | __min_1                                 |


SQL for example:
```sql
CREATE VIEW v1 AS 
SELECT 
  error_code,
  1, 
  'string', 
  now(), 
  dayofyear(op_time), 
  cast (source AS BIGINT), 
  min(`timestamp`) OVER (
    ORDER BY 
      op_time DESC ROWS BETWEEN UNBOUNDED PRECEDING
      AND 1 FOLLOWING
  ), 
  1 > 2,
  2 + 3,
  1 IN (1, 2, 3, 4), 
  remark LIKE '%like', 
  CASE WHEN remark = 's' THEN 1 ELSE 2 END,
  TRUE | FALSE 
FROM 
  db_test.table_test1
```

the output column name is as following:
```
error_code
__literal_1
__literal_2
__now_3
__dayofyear_4
__cast_expr_5
__min_6
__binary_predicate_7
__arithmetic_expr_8
__in_predicate_9
__like_predicate_10
__case_expr_11
__arithmetic_expr_12
```
2023-10-09 04:14:01 -05:00

30 lines
1.3 KiB
Plaintext

-- 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` COMMENT 'VIEW' AS SELECT `error_code` AS `error_code`, 1 AS `__literal_1`, 'string' AS `__literal_2`, now() AS `__now_3`, dayofyear(`op_time`) AS `__dayofyear_4`, CAST(`source` AS BIGINT) AS `__cast_expr_5`, min(`timestamp`) OVER (ORDER BY `op_time` DESC NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND 1 FOLLOWING) AS `__min_6`, 1 > 2 AS `__binary_predicate_7`, (2 + 3) AS `__arithmetic_expr_8`, 1 IN (1, 2, 3, 4) AS `__in_predicate_9`, `remark` LIKE '%like' AS `__like_predicate_10`, CASE WHEN `remark` = 's' THEN 1 ELSE 2 END AS `__case_expr_11`, (CAST(TRUE AS BIGINT) | CAST(FALSE AS BIGINT)) AS `__arithmetic_expr_12` FROM `default_cluster:regression_test_ddl_p0`.`view_column_name_test`;