This is an automated email from the ASF dual-hosted git repository.
stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
The following commit(s) were added to refs/heads/master by this push:
new 54c0074b3 IMPALA-14405 ADDENDUM: Catch exception for bad column names
54c0074b3 is described below
commit 54c0074b33b3273d23c2426730dafbcea1b5b49f
Author: Steve Carlin <[email protected]>
AuthorDate: Wed Nov 5 06:31:20 2025 -0800
IMPALA-14405 ADDENDUM: Catch exception for bad column names
This commit is a fix on top of IMPALA-14405 for the Calcite
planner. The original commit matches column names from the
expression in the select clause.
For instance, if the query is "select 1 + 1", the label in
impala-shell will be "1 + 1". It accomplished this by
retrieving the string from the SqlNode object through the
MySql dialect.
However, when the expression doesn't succeed in the MySql
dialect, an AssertionError gets thrown, causing the query to
fail. We don't want the query to fail, we just want to go
back to using the Calcite expression, e.g. EXPR$0. This
occurred with this specific query:
"select timestamp_col + interval 3 nanoseconds"
So now the exception is caught and the default label name
is used. Eventually we should try to match what Impala has,
but this is a harder problem to fix.
Change-Id: I6c4d76a25fb2486eb1ef19485bce7888d45d282f
Reviewed-on: http://gerrit.cloudera.org:8080/23665
Reviewed-by: Riza Suminto <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
Reviewed-by: Steve Carlin <[email protected]>
---
.../calcite/service/CalciteRelNodeConverter.java | 19 +++++++++++++------
.../functional-query/queries/QueryTest/calcite.test | 8 ++++++++
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteRelNodeConverter.java
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteRelNodeConverter.java
index 6d90281e3..72f693c92 100644
---
a/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteRelNodeConverter.java
+++
b/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteRelNodeConverter.java
@@ -177,12 +177,19 @@ public class CalciteRelNodeConverter implements
CompilerStep {
for (SqlNode selectItem : getSelectList(validatedNode)) {
String fieldName = SqlValidatorUtil.alias(selectItem, 0);
if (fieldName.startsWith("EXPR$")) {
- // If it's a Calcite generated field name, it will be of the form
"EXPR$"
- // We get the actual SQL expression using the toSqlString method. There
- // is no Impala Dialect yet, so using MySql dialect to get the field
- // name. The language chosen is irrelevant because we only are using it
- // to grab the expression as/is to use for the label.
- fieldName = selectItem.toSqlString(MysqlSqlDialect.DEFAULT).getSql();
+ try {
+ // If it's a Calcite generated field name, it will be of the form
"EXPR$"
+ // We get the actual SQL expression using the toSqlString method.
There
+ // is no Impala Dialect yet, so using MySql dialect to get the field
+ // name. The language chosen is irrelevant because we only are using
it
+ // to grab the expression as/is to use for the label.
+ fieldName = selectItem.toSqlString(MysqlSqlDialect.DEFAULT).getSql();
+ } catch (Error e) {
+ // The MysqlDialect may throw an exception if the column name is not
+ // compatible with Mysql. So we catch the exception and just use the
+ // EXPR$ column name.
+ LOG.debug("Could not use label for {}, using default.", selectItem);
+ }
}
fieldNamesBuilder.add(fieldName.toLowerCase());
}
diff --git a/testdata/workloads/functional-query/queries/QueryTest/calcite.test
b/testdata/workloads/functional-query/queries/QueryTest/calcite.test
index 685b2c363..3723375b4 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/calcite.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/calcite.test
@@ -1122,6 +1122,14 @@ int
row_regex: .*PlannerType: CalcitePlanner.*
====
---- QUERY
+# IMPALA-14561: Should not be using MySqlDialect to capture labels
+select timestamp_col + interval 3 milliseconds from functional.alltypestiny;
+---- LABELS
+expr$0
+---- RUNTIME_PROFILE
+row_regex: .*PlannerType: CalcitePlanner.*
+====
+---- QUERY
select cast('nan' as double), cast('inf' as float);
---- RESULTS
NaN,Inf