Source:
<code>protected Scope visitJoin(Join node, Optional<Scope> scope) { JoinCriteria criteria = node.getCriteria().orElse(null); if (criteria instanceof NaturalJoin) { throw new SemanticException(NOT_SUPPORTED, node, "Natural join not supported"); } Scope left = process(node.getLeft(), scope); Scope right = process(node.getRight(), isLateralRelation(node.getRight()) ? Optional.of(left) : scope); if (criteria instanceof JoinUsing) { return analyzeJoinUsing(node, ((JoinUsing) criteria).getColumns(), scope, left, right); } Scope output = createAndAssignScope(node, scope, left.getRelationType().joinWith(right.getRelationType())); if (node.getType() == Join.Type.CROSS || node.getType() == Join.Type.IMPLICIT) { return output; } else if (criteria instanceof JoinOn) { Expression expression = ((JoinOn) criteria).getExpression(); 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); } analysis.addCoercion(expression, BOOLEAN, false); } Analyzer.verifyNoAggregateWindowOrGroupingFunctions(metadata.getFunctionRegistry(), expression, "JOIN clause"); <START> analysis.recordSubqueries(node, expressionAnalysis); <END> analysis.setJoinCriteria(node, expression); } else { throw new UnsupportedOperationException("unsupported join criteria: " + criteria.getClass().getName()); } return output; }</code><technical_language>is removed? synthesize expression? This store coercion information is gathered analysis time</technical_language>

Target:
protected Scope visitJoin(Join node, Optional<Scope> scope) { JoinCriteria criteria = node.getCriteria().orElse(null); if (criteria instanceof NaturalJoin) { throw new SemanticException(NOT_SUPPORTED, node, "Natural join not supported"); } Scope left = process(node.getLeft(), scope); Scope right = process(node.getRight(), isLateralRelation(node.getRight()) ? Optional.of(left) : scope); if (criteria instanceof JoinUsing) { if (SystemSessionProperties.isLegacyJoinUsingEnabled(session)) { return analyzeLegacyJoinUsing(node, ((JoinUsing) criteria).getColumns(), scope, left, right); } return analyzeJoinUsing(node, ((JoinUsing) criteria).getColumns(), scope, left, right); } Scope output = createAndAssignScope(node, scope, left.getRelationType().joinWith(right.getRelationType())); if (node.getType() == Join.Type.CROSS || node.getType() == Join.Type.IMPLICIT) { return output; } else if (criteria instanceof JoinOn) { Expression expression = ((JoinOn) criteria).getExpression(); 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); } analysis.addCoercion(expression, BOOLEAN, false); } Analyzer.verifyNoAggregateWindowOrGroupingFunctions(metadata.getFunctionRegistry(), expression, "JOIN clause"); analysis.recordSubqueries(node, expressionAnalysis); analysis.setJoinCriteria(node, expression); } else { throw new UnsupportedOperationException("unsupported join criteria: " + criteria.getClass().getName()); } return output; }