Example #1
0
  @Test
  public void testValidateFails() throws SqlParseException {
    Planner planner = getPlanner();
    SqlNode parse = planner.parse("select * from \"emps\" where \"Xname\" like '%e%'");
    assertThat(
        parse.toString(), equalTo("SELECT *\n" + "FROM `emps`\n" + "WHERE `Xname` LIKE '%e%'"));

    try {
      SqlNode validate = planner.validate(parse);
      fail("expected error, got " + validate);
    } catch (ValidationException e) {
      assertThat(Util.getStackTrace(e), containsString("Column 'Xname' not found in any table"));
      // ok
    }
  }
Example #2
0
  @Test
  public void testParseAndConvert() throws Exception {
    Planner planner = getPlanner();
    SqlNode parse = planner.parse("select * from \"emps\" where \"name\" like '%e%'");
    assertThat(
        parse.toString(), equalTo("SELECT *\n" + "FROM `emps`\n" + "WHERE `name` LIKE '%e%'"));

    SqlNode validate = planner.validate(parse);
    RelNode rel = planner.convert(validate);
    assertThat(
        toString(rel),
        equalTo(
            "ProjectRel(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
                + "  FilterRel(condition=[LIKE($2, '%e%')])\n"
                + "    EnumerableTableAccessRel(table=[[hr, emps]])\n"));
  }
Example #3
0
 /** Unit test that parses, validates, converts and plans. */
 @Test
 public void testPlan() throws Exception {
   RuleSet ruleSet =
       RuleSets.ofList(
           MergeFilterRule.INSTANCE,
           JavaRules.ENUMERABLE_FILTER_RULE,
           JavaRules.ENUMERABLE_PROJECT_RULE);
   Planner planner = getPlanner(ruleSet);
   SqlNode parse = planner.parse("select * from \"emps\"");
   SqlNode validate = planner.validate(parse);
   RelNode convert = planner.convert(validate);
   RelTraitSet traitSet = planner.getEmptyTraitSet().replace(EnumerableConvention.INSTANCE);
   RelNode transform = planner.transform(0, traitSet, convert);
   assertThat(
       toString(transform),
       equalTo(
           "EnumerableProjectRel(empid=[$0], deptno=[$1], name=[$2], salary=[$3], commission=[$4])\n"
               + "  EnumerableTableAccessRel(table=[[hr, emps]])\n"));
 }