use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testAlterTableAddPkConstraint.
@Test
public void testAlterTableAddPkConstraint() throws Exception {
prepareNonManagedTable(false);
// Test alter add table constraint.
Operation operation = parse("alter table tb1 add constraint ct1 primary key(a, b) not enforced", SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(AlterTableAddConstraintOperation.class);
AlterTableAddConstraintOperation addConstraintOperation = (AlterTableAddConstraintOperation) operation;
assertThat(addConstraintOperation.asSummaryString()).isEqualTo("ALTER TABLE ADD CONSTRAINT: (identifier: [`cat1`.`db1`.`tb1`], " + "constraintName: [ct1], columns: [a, b])");
// Test alter table add pk on nullable column
assertThatThrownBy(() -> parse("alter table tb1 add constraint ct1 primary key(c) not enforced", SqlDialect.DEFAULT)).isInstanceOf(ValidationException.class).hasMessageContaining("Could not create a PRIMARY KEY 'ct1'. Column 'c' is nullable.");
}
use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testShowFullModules.
@Test
public void testShowFullModules() {
final String sql = "SHOW FULL MODULES";
Operation operation = parse(sql, SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(ShowModulesOperation.class);
final ShowModulesOperation showModulesOperation = (ShowModulesOperation) operation;
assertThat(showModulesOperation.requireFull()).isTrue();
assertThat(showModulesOperation.asSummaryString()).isEqualTo("SHOW FULL MODULES");
}
use of org.apache.flink.table.operations.Operation 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.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testReset.
@Test
public void testReset() {
Operation operation1 = parse("RESET", SqlDialect.DEFAULT);
assertThat(operation1).isInstanceOf(ResetOperation.class);
assertThat(((ResetOperation) operation1).getKey()).isNotPresent();
Operation operation2 = parse("RESET 'test-key'", SqlDialect.DEFAULT);
assertThat(operation2).isInstanceOf(ResetOperation.class);
assertThat(((ResetOperation) operation2).getKey()).isPresent();
assertThat(((ResetOperation) operation2).getKey()).hasValue("test-key");
}
use of org.apache.flink.table.operations.Operation in project flink by apache.
the class SqlToOperationConverterTest method testCreateDatabase.
@Test
public void testCreateDatabase() {
final String[] createDatabaseSqls = new String[] { "create database db1", "create database if not exists cat1.db1", "create database cat1.db1 comment 'db1_comment'", "create database cat1.db1 comment 'db1_comment' with ('k1' = 'v1', 'K2' = 'V2')" };
final String[] expectedCatalogs = new String[] { "builtin", "cat1", "cat1", "cat1" };
final String expectedDatabase = "db1";
final String[] expectedComments = new String[] { null, null, "db1_comment", "db1_comment" };
final boolean[] expectedIgnoreIfExists = new boolean[] { false, true, false, false };
Map<String, String> properties = new HashMap<>();
properties.put("k1", "v1");
properties.put("K2", "V2");
final Map[] expectedProperties = new Map[] { new HashMap<String, String>(), new HashMap<String, String>(), new HashMap<String, String>(), new HashMap(properties) };
for (int i = 0; i < createDatabaseSqls.length; i++) {
Operation operation = parse(createDatabaseSqls[i], SqlDialect.DEFAULT);
assertThat(operation).isInstanceOf(CreateDatabaseOperation.class);
final CreateDatabaseOperation createDatabaseOperation = (CreateDatabaseOperation) operation;
assertThat(createDatabaseOperation.getCatalogName()).isEqualTo(expectedCatalogs[i]);
assertThat(createDatabaseOperation.getDatabaseName()).isEqualTo(expectedDatabase);
assertThat(createDatabaseOperation.getCatalogDatabase().getComment()).isEqualTo(expectedComments[i]);
assertThat(createDatabaseOperation.isIgnoreIfExists()).isEqualTo(expectedIgnoreIfExists[i]);
assertThat(createDatabaseOperation.getCatalogDatabase().getProperties()).isEqualTo(expectedProperties[i]);
}
}
Aggregations