IMPALA-14165: Type coercion code accidentally omitted from analysis

On the first cut of creating the Calcite planner, the Calcite planner
was standalone and ran its own JniFrontend.

In the current version, the parsing, validating, and single node
planning is called from the Impala framework.

There is some code in the first cut regarding the
"ImpalaTypeCoercionFactory" class which handles deriving the correct
data type for various expressions, for instance (found in exprs.test):

select count(*) from alltypesagg where
10.1 in (tinyint_col, smallint_col, int_col, bigint_col, float_col, double_col)

Without this patch, the query returns the following error:
UDF ERROR: Decimal expression overflowed

This code can be found in CalciteValidator.java, but was accidentally omitted
from CalciteAnalysisDriver.

Change-Id: I74c4c714504400591d1ec6313f040191613c25d9
Reviewed-on: http://gerrit.cloudera.org:8080/23039
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Reviewed-by: Steve Carlin <scarlin@cloudera.com>
This commit is contained in:
Steve Carlin
2025-06-10 06:31:57 -07:00
parent 98b6c0208f
commit 922443da46
2 changed files with 13 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ import org.apache.impala.authorization.AuthorizationContext;
import org.apache.impala.authorization.AuthorizationFactory;
import org.apache.impala.calcite.operators.ImpalaOperatorTable;
import org.apache.impala.calcite.schema.ImpalaCalciteCatalogReader;
import org.apache.impala.calcite.type.ImpalaTypeCoercionFactory;
import org.apache.impala.calcite.type.ImpalaTypeSystemImpl;
import org.apache.impala.calcite.util.SimplifiedAnalyzer;
import org.apache.impala.calcite.validate.ImpalaConformance;
@@ -119,6 +120,8 @@ public class CalciteAnalysisDriver implements AnalysisDriver {
// without this)
.withIdentifierExpansion(true)
.withConformance(ImpalaConformance.INSTANCE)
.withTypeCoercionEnabled(true)
.withTypeCoercionFactory(new ImpalaTypeCoercionFactory())
);
validatedNode_ = sqlValidator_.validate(parsedStmt_.getParsedSqlNode());
return new CalciteAnalysisResult(this);

View File

@@ -1066,4 +1066,14 @@ INT, BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, STRING, STRING, TIM
select ds_hll_sketch(smallint_col) from functional_parquet.alltypessmall;
---- CATCH
Cannot infer return type for DS_HLL_SKETCH; operand types: [SMALLINT]
=====
---- QUERY
# This test case ensures that the TypeCoercion code is in place, which gets kicked
# in with the "in" clause
select count(*) from functional.alltypesagg
where 10.1 not in (tinyint_col, smallint_col, int_col, bigint_col, float_col, double_col)
---- RESULTS
8990
---- TYPES
bigint
====