/** 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%'")); }
@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 } }
@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")); }