/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-1586">[CALCITE-1586] * JDBC adapter generates wrong SQL if UNION has more than two inputs</a>. */ @Test public void testThreeQueryUnion() { String query = "SELECT \"product_id\" FROM \"product\" " + " UNION ALL " + "SELECT \"product_id\" FROM \"sales_fact_1997\" " + " UNION ALL " + "SELECT \"product_class_id\" AS product_id FROM \"product_class\""; String expected = "SELECT \"product_id\"\n" + "FROM \"foodmart\".\"product\"\n" + "UNION ALL\n" + "SELECT \"product_id\"\n" + "FROM \"foodmart\".\"sales_fact_1997\"\n" + "UNION ALL\n" + "SELECT \"product_class_id\" AS \"PRODUCT_ID\"\n" + "FROM \"foodmart\".\"product_class\""; final HepProgram program = new HepProgramBuilder().addRuleClass(UnionMergeRule.class).build(); final RuleSet rules = RuleSets.ofList(UnionMergeRule.INSTANCE); sql(query) .optimize(rules, new HepPlanner(program)) .ok(expected); }
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-1586">[CALCITE-1586] * JDBC adapter generates wrong SQL if UNION has more than two inputs</a>. */ @Test public void testThreeQueryUnion() { String query = "SELECT \"product_id\" FROM \"product\" " + " UNION ALL " + "SELECT \"product_id\" FROM \"sales_fact_1997\" " + " UNION ALL " + "SELECT \"product_class_id\" AS product_id FROM \"product_class\""; String expected = "SELECT \"product_id\"\n" + "FROM \"foodmart\".\"product\"\n" + "UNION ALL\n" + "SELECT \"product_id\"\n" + "FROM \"foodmart\".\"sales_fact_1997\"\n" + "UNION ALL\n" + "SELECT \"product_class_id\" AS \"PRODUCT_ID\"\n" + "FROM \"foodmart\".\"product_class\""; final HepProgram program = new HepProgramBuilder().addRuleClass(UnionMergeRule.class).build(); final RuleSet rules = RuleSets.ofList(UnionMergeRule.INSTANCE); sql(query) .optimize(rules, new HepPlanner(program)) .ok(expected); }