use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testCreateViewWithDynamicTableOptions.
@Test
public void testCreateViewWithDynamicTableOptions() {
Map<String, String> prop = new HashMap<>();
prop.put("connector", "values");
prop.put("bounded", "true");
CatalogTable catalogTable = CatalogTable.of(Schema.newBuilder().column("f0", DataTypes.INT()).column("f1", DataTypes.VARCHAR(20)).build(), null, Collections.emptyList(), prop);
catalogManager.createTable(catalogTable, ObjectIdentifier.of("builtin", "default", "sourceA"), false);
final String sql = "" + "create view test_view as\n" + "select *\n" + "from sourceA /*+ OPTIONS('changelog-mode'='I') */";
Operation operation = parse(sql, SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(CreateViewOperation.class);
}
use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testSqlInsertWithDynamicTableOptions.
@Test
public void testSqlInsertWithDynamicTableOptions() {
final String sql = "insert into t1 /*+ OPTIONS('k1'='v1', 'k2'='v2') */\n" + "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(SinkModifyOperation.class);
SinkModifyOperation sinkModifyOperation = (SinkModifyOperation) operation;
Map<String, String> dynamicOptions = sinkModifyOperation.getDynamicOptions();
assertThat(dynamicOptions).isNotNull();
assertThat(dynamicOptions.size()).isEqualTo(2);
assertThat(dynamicOptions.toString()).isEqualTo("{k1=v1, k2=v2}");
}
use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testLoadModule.
@Test
public void testLoadModule() {
final String sql = "LOAD MODULE dummy WITH ('k1' = 'v1', 'k2' = 'v2')";
final String expectedModuleName = "dummy";
final Map<String, String> expectedOptions = new HashMap<>();
expectedOptions.put("k1", "v1");
expectedOptions.put("k2", "v2");
Operation operation = parse(sql, SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(LoadModuleOperation.class);
final LoadModuleOperation loadModuleOperation = (LoadModuleOperation) operation;
assertThat(loadModuleOperation.getModuleName()).isEqualTo(expectedModuleName);
assertThat(loadModuleOperation.getOptions()).isEqualTo(expectedOptions);
}
use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testShowModules.
@Test
public void testShowModules() {
final String sql = "SHOW MODULES";
Operation operation = parse(sql, SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(ShowModulesOperation.class);
final ShowModulesOperation showModulesOperation = (ShowModulesOperation) operation;
assertThat(showModulesOperation.requireFull()).isFalse();
assertThat(showModulesOperation.asSummaryString()).isEqualTo("SHOW MODULES");
}
use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testAlterTableDropConstraint.
@Test
public void testAlterTableDropConstraint() throws Exception {
prepareNonManagedTable(true);
// Test alter table add enforced
Operation operation = parse("alter table tb1 drop constraint ct1", SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(AlterTableDropConstraintOperation.class);
AlterTableDropConstraintOperation dropConstraint = (AlterTableDropConstraintOperation) operation;
assertThat(dropConstraint.asSummaryString()).isEqualTo("ALTER TABLE cat1.db1.tb1 DROP CONSTRAINT ct1");
assertThatThrownBy(() -> parse("alter table tb1 drop constraint ct2", SqlDialect.DEFAULT)).isInstanceOf(ValidationException.class).hasMessageContaining("CONSTRAINT [ct2] does not exist");
}
Aggregations