use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeExcludingGeneratedColumnsDuplicate.
@Test
public void mergeExcludingGeneratedColumnsDuplicate() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "one + 1")).build();
List<SqlNode> derivedColumns = Collections.singletonList(computedColumn("two", plus("one", "3")));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.GENERATED, MergingStrategy.EXCLUDING);
TableSchema mergedSchema = util.mergeTables(mergingStrategies, sourceSchema, derivedColumns, Collections.emptyList(), null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "`one` + 3")).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeOverwritingPhysicalColumnWithGeneratedColumn.
@Test
public void mergeOverwritingPhysicalColumnWithGeneratedColumn() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.physical("two", DataTypes.INT())).build();
List<SqlNode> derivedColumns = Collections.singletonList(computedColumn("two", plus("one", "3")));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.GENERATED, MergingStrategy.OVERWRITING);
thrown.expect(ValidationException.class);
thrown.expectMessage("A column named 'two' already exists in the table. " + "Duplicate columns exist in the compute column and regular column. ");
util.mergeTables(mergingStrategies, sourceSchema, derivedColumns, Collections.emptyList(), null);
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeGeneratedColumns.
@Test
public void mergeGeneratedColumns() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "one + 1")).build();
List<SqlNode> derivedColumns = Arrays.asList(regularColumn("three", DataTypes.INT()), computedColumn("four", plus("one", "3")));
TableSchema mergedSchema = util.mergeTables(getDefaultMergingStrategies(), sourceSchema, derivedColumns, Collections.emptyList(), null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "one + 1")).add(TableColumn.physical("three", DataTypes.INT())).add(TableColumn.computed("four", DataTypes.INT(), "`one` + 3")).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeOverwritingMetadataColumnsDuplicate.
@Test
public void mergeOverwritingMetadataColumnsDuplicate() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.metadata("two", DataTypes.INT())).build();
List<SqlNode> derivedColumns = Collections.singletonList(metadataColumn("two", DataTypes.BOOLEAN(), true));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.METADATA, MergingStrategy.OVERWRITING);
TableSchema mergedSchema = util.mergeTables(mergingStrategies, sourceSchema, derivedColumns, Collections.emptyList(), null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.metadata("two", DataTypes.BOOLEAN(), true)).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeIncludingConstraintsFailsOnDuplicate.
@Test
public void mergeIncludingConstraintsFailsOnDuplicate() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT().notNull())).add(TableColumn.physical("two", DataTypes.STRING().notNull())).add(TableColumn.physical("three", DataTypes.FLOAT())).primaryKey("constraint-42", new String[] { "one", "two" }).build();
thrown.expect(ValidationException.class);
thrown.expectMessage("The base table already has a primary key. You might want to specify " + "EXCLUDING CONSTRAINTS.");
util.mergeTables(getDefaultMergingStrategies(), sourceSchema, Collections.emptyList(), Collections.emptyList(), primaryKey("one", "two"));
}
Aggregations