Skip to content
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

[BugFix] Fix analyzer exception for generated column rewrite (backport #51755) #51806

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -183,19 +183,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;
Loading