Beispiel #1
0
 @Test
 public void testParseFails() throws SqlParseException {
   Planner planner = getPlanner();
   try {
     SqlNode parse = planner.parse("select * * from \"emps\"");
     fail("expected error, got " + parse);
   } catch (SqlParseException e) {
     assertThat(e.getMessage(), containsString("Encountered \"*\" at line 1, column 10."));
   }
 }
Beispiel #2
0
 /** Tests that Hive dialect does not generate "AS". */
 @Test
 public void testHiveDialect() throws SqlParseException {
   Planner planner = getPlanner();
   SqlNode parse =
       planner.parse(
           "select * from (select * from \"emps\") as t\n" + "where \"name\" like '%e%'");
   final SqlDialect hiveDialect = new SqlDialect(SqlDialect.DatabaseProduct.HIVE, "Hive", null);
   assertThat(
       parse.toSqlString(hiveDialect).getSql(),
       equalTo("SELECT *\n" + "FROM (SELECT *\n" + "FROM emps) T\n" + "WHERE name LIKE '%e%'"));
 }
Beispiel #3
0
 /**
  * Tests that planner throws an error if you pass to {@link
  * Planner#convert(org.eigenbase.sql.SqlNode)} a {@link org.eigenbase.sql.SqlNode} that has been
  * parsed but not validated.
  */
 @Test
 public void testConvertWithoutValidateFails() throws Exception {
   Planner planner = getPlanner();
   SqlNode parse = planner.parse("select * from \"emps\"");
   try {
     RelNode rel = planner.convert(parse);
     fail("expected error, got " + rel);
   } catch (IllegalArgumentException e) {
     assertThat(
         e.getMessage(), containsString("cannot move from STATE_3_PARSED to STATE_4_VALIDATED"));
   }
 }
Beispiel #4
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
    }
  }
Beispiel #5
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"));
  }
Beispiel #6
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"));
 }