use of org.apache.flink.table.planner.parse.CalciteParser in project flink by apache.
the class SqlToOperationConverterTest method testSqlExecuteWithInsert.
@Test
public void testSqlExecuteWithInsert() {
final String sql = "execute insert into t1 select a, b, c, d from t2 where a > 1";
FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
Operation operation = parse(sql, planner, parser);
assertThat(operation).isInstanceOf(SinkModifyOperation.class);
}
use of org.apache.flink.table.planner.parse.CalciteParser in project flink by apache.
the class SqlToOperationConverterTest method parse.
private Operation parse(String sql, SqlDialect sqlDialect) {
FlinkPlannerImpl planner = getPlannerBySqlDialect(sqlDialect);
final CalciteParser parser = getParserBySqlDialect(sqlDialect);
SqlNode node = parser.parse(sql);
return SqlToOperationConverter.convert(planner, catalogManager, node).get();
}
use of org.apache.flink.table.planner.parse.CalciteParser in project flink by apache.
the class SqlToOperationConverterTest method testCreateTable.
@Test
public void testCreateTable() {
final String sql = "CREATE TABLE tbl1 (\n" + " a bigint,\n" + " b varchar, \n" + " c int, \n" + " d varchar" + ")\n" + " PARTITIONED BY (a, d)\n" + " with (\n" + " 'connector' = 'kafka', \n" + " 'kafka.topic' = 'log.test'\n" + ")\n";
FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
Operation operation = parse(sql, planner, parser);
assertThat(operation).isInstanceOf(CreateTableOperation.class);
CreateTableOperation op = (CreateTableOperation) operation;
CatalogTable catalogTable = op.getCatalogTable();
assertThat(catalogTable.getPartitionKeys()).hasSameElementsAs(Arrays.asList("a", "d"));
assertThat(catalogTable.getSchema().getFieldNames()).isEqualTo(new String[] { "a", "b", "c", "d" });
assertThat(catalogTable.getSchema().getFieldDataTypes()).isEqualTo(new DataType[] { DataTypes.BIGINT(), DataTypes.VARCHAR(Integer.MAX_VALUE), DataTypes.INT(), DataTypes.VARCHAR(Integer.MAX_VALUE) });
}
use of org.apache.flink.table.planner.parse.CalciteParser in project flink by apache.
the class SqlToOperationConverterTest method testSqlRichExplainWithSelect.
@Test
public void testSqlRichExplainWithSelect() {
final String sql = "explain plan for select a, b, c, d from t2";
FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
Operation operation = parse(sql, planner, parser);
assertThat(operation).isInstanceOf(ExplainOperation.class);
}
use of org.apache.flink.table.planner.parse.CalciteParser in project flink by apache.
the class SqlExprToRexConverterImpl method expand.
@Override
public String expand(String expr) {
final CalciteParser parser = planner.parser();
final SqlNode node = parser.parseExpression(expr);
final SqlNode validated = planner.validateExpression(node, inputRowType, outputType);
return validated.toSqlString(sqlDialect).getSql();
}
Aggregations