Register coercions in Join analysis
addCoercionForJoinCriteria relies on previously registered coercions.
analyzer.analyze does not register coercions while analyzeExpression
does.
In case of `join on (cast ('a' as char(1)) = cast ('a' as char(2)))`
it would fail without having coercions registered before.
@@ -963,7 +963,9 @@ class StatementAnalyzer
// we do it further down when after we determine which subexpressions apply to left vs right tuple)
ExpressionAnalyzer analyzer = ExpressionAnalyzer.create(analysis, session, metadata, sqlParser, accessControl);
- Type clauseType = analyzer.analyze(expression, output);
+ // need to register coercions in case when join criteria requires coercion (e.g. join on char(1) = char(2))
+ ExpressionAnalysis expressionAnalysis = analyzeExpression(expression, output);
+ Type clauseType = expressionAnalysis.getType(expression);
if (!clauseType.equals(BOOLEAN)) {
if (!clauseType.equals(UNKNOWN)) {
throw new SemanticException(TYPE_MISMATCH, expression, "JOIN ON clause must evaluate to a boolean: actual type %s", clauseType);
@@ -977,7 +979,7 @@ class StatementAnalyzer
// expressionInterpreter/optimizer only understands a subset of expression types
// TODO: remove this when the new expression tree is implemented
Expression canonicalized = CanonicalizeExpressions.canonicalizeExpression(expression);
- analyzer.analyze(canonicalized, output);
+ analyzeExpression(canonicalized, output);
Object optimizedExpression = expressionOptimizer(canonicalized, metadata, session, analyzer.getExpressionTypes()).optimize(NoOpSymbolResolver.INSTANCE);
