Skip to content

Commit

Permalink
[BugFix] Fix analyzer exception for generated column rewrite (#51755)
Browse files Browse the repository at this point in the history
Signed-off-by: srlch <[email protected]>
(cherry picked from commit f02fabf)
  • Loading branch information
srlch authored and mergify[bot] committed Oct 11, 2024
1 parent 13a4963 commit db164ed
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,23 @@ private void reAnalyzeExpressionBasedOnCurrentScope(SelectRelation childSelectRe
}

// 3. analyze generated column expression based on current scope
Map<Expr, SlotRef> analyzedGeneratedExprToColumnRef = new HashMap<>();
for (Map.Entry<Expr, SlotRef> entry : generatedExprToColumnRef.entrySet()) {
entry.getKey().reset();
entry.getValue().reset();

try {
ExpressionAnalyzer.analyzeExpression(entry.getKey(), new AnalyzeState(), scope, session);
ExpressionAnalyzer.analyzeExpression(entry.getValue(), new AnalyzeState(), scope, session);
} catch (Exception ignore) {
// ignore generated column rewrite if hit any exception
generatedExprToColumnRef.clear();
// skip this generated column rewrite if hit any exception
// some exception is reasonable because some of illegal generated column
// rewrite will be rejected by ananlyzer exception.
continue;
}
analyzedGeneratedExprToColumnRef.put(entry.getKey(), entry.getValue());
}
resultGeneratedExprToColumnRef.putAll(generatedExprToColumnRef);
resultGeneratedExprToColumnRef.putAll(analyzedGeneratedExprToColumnRef);
}

@Override
Expand Down
48 changes: 48 additions & 0 deletions test/sql/test_materialized_column/R/test_generated_column_rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,52 @@ None
-- !result
DROP table t_generated_column_complex_rewrite_3;
-- result:
-- !result
CREATE TABLE `t_generated_column_complex_rewrite_4` (
`pday` int(11) NOT NULL COMMENT ""
) ENGINE=OLAP
PRIMARY KEY(`pday`)
PARTITION BY (`pday`)
DISTRIBUTED BY HASH(`pday`)
PROPERTIES (
"compression" = "LZ4",
"enable_persistent_index" = "true",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);
-- result:
-- !result
CREATE TABLE `t_generated_column_complex_rewrite_5` (
`id` bigint(20) NOT NULL COMMENT "",
`json_string` varchar(1048576) NOT NULL COMMENT "",
`col1` varchar(65533) NULL AS get_json_string(`json_string`, 'a') COMMENT "",
`col2` varchar(65533) NULL AS get_json_string(`json_string`, 'b') COMMENT ""
) ENGINE=OLAP
PRIMARY KEY(`id`)
DISTRIBUTED BY HASH(`id`)
PROPERTIES (
"compression" = "LZ4",
"enable_persistent_index" = "true",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);
-- result:
-- !result
INSERT INTO t_generated_column_complex_rewrite_4 values (1);
-- result:
-- !result
INSERT INTO t_generated_column_complex_rewrite_5 values (1,"{\"a\" : \"b\"}");
-- result:
-- !result
select * from (select t4.* from t_generated_column_complex_rewrite_4 as t4 left join t_generated_column_complex_rewrite_5 as t5 on t4.pday = t5.id) result;
-- result:
1
-- !result
DROP TABLE t_generated_column_complex_rewrite_4;
-- result:
-- !result
DROP TABLE t_generated_column_complex_rewrite_5;
-- result:
-- !result
38 changes: 38 additions & 0 deletions test/sql/test_materialized_column/T/test_generated_column_rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,41 @@ PROPERTIES (
INSERT INTO t_generated_column_complex_rewrite_3 VALUES (1);
function: assert_explain_contains('SELECT COUNT(*) FROM t_generated_column_complex_rewrite_3 WHERE cast(id + 10 as string) IS NOT NULL', 'col')
DROP table t_generated_column_complex_rewrite_3;

CREATE TABLE `t_generated_column_complex_rewrite_4` (
`pday` int(11) NOT NULL COMMENT ""
) ENGINE=OLAP
PRIMARY KEY(`pday`)
PARTITION BY (`pday`)
DISTRIBUTED BY HASH(`pday`)
PROPERTIES (
"compression" = "LZ4",
"enable_persistent_index" = "true",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);

CREATE TABLE `t_generated_column_complex_rewrite_5` (
`id` bigint(20) NOT NULL COMMENT "",
`json_string` varchar(1048576) NOT NULL COMMENT "",
`col1` varchar(65533) NULL AS get_json_string(`json_string`, 'a') COMMENT "",
`col2` varchar(65533) NULL AS get_json_string(`json_string`, 'b') COMMENT ""
) ENGINE=OLAP
PRIMARY KEY(`id`)
DISTRIBUTED BY HASH(`id`)
PROPERTIES (
"compression" = "LZ4",
"enable_persistent_index" = "true",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);

INSERT INTO t_generated_column_complex_rewrite_4 values (1);
INSERT INTO t_generated_column_complex_rewrite_5 values (1,"{\"a\" : \"b\"}");

select * from (select t4.* from t_generated_column_complex_rewrite_4 as t4 left join t_generated_column_complex_rewrite_5 as t5 on t4.pday = t5.id) result;

DROP TABLE t_generated_column_complex_rewrite_4;
DROP TABLE t_generated_column_complex_rewrite_5;

0 comments on commit db164ed

Please sign in to comment.