diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 7b645b8..5aff956 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -9079,11 +9079,21 @@ private Operator genUnionPlan(String unionalias, String leftalias, unionoutRR.put(unionalias, field, unionColInfo); } - if (!(leftOp instanceof UnionOperator)) { + // For Spark, we rely on the generated SelectOperator to do the type casting. + // Consider: + // SEL_1 (int) SEL_2 (int) SEL_3 (double) + // If we first merge SEL_1 and SEL_2 into a UNION_1, and then merge UNION_1 + // with SEL_3 to get UNION_2, then no SelectOperator will be inserted. Hence error + // will happen afterwards. The solution here is to insert one after UNION_1, which + // cast int to double. + boolean isSpark = HiveConf.getVar(conf, + HiveConf.ConfVars.HIVE_EXECUTION_ENGINE).equals("spark"); + + if (isSpark || !(leftOp instanceof UnionOperator)) { leftOp = genInputSelectForUnion(leftOp, leftmap, leftalias, unionoutRR, unionalias); } - if (!(rightOp instanceof UnionOperator)) { + if (isSpark || !(rightOp instanceof UnionOperator)) { rightOp = genInputSelectForUnion(rightOp, rightmap, rightalias, unionoutRR, unionalias); }