use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeOverwritingGeneratedColumnsDuplicate.
@Test
public void mergeOverwritingGeneratedColumnsDuplicate() {
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.OVERWRITING);
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 mergePhysicalColumns.
@Test
public void mergePhysicalColumns() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.physical("two", DataTypes.STRING())).build();
List<SqlNode> derivedColumns = Arrays.asList(regularColumn("three", DataTypes.INT()), regularColumn("four", DataTypes.STRING()));
TableSchema mergedSchema = util.mergeTables(getDefaultMergingStrategies(), sourceSchema, derivedColumns, Collections.emptyList(), null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.physical("two", DataTypes.STRING())).add(TableColumn.physical("three", DataTypes.INT())).add(TableColumn.physical("four", DataTypes.STRING())).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeIncludingMetadataColumnsFailsOnDuplicate.
@Test
public void mergeIncludingMetadataColumnsFailsOnDuplicate() {
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.INT(), false));
thrown.expect(ValidationException.class);
thrown.expectMessage("A metadata column named 'two' already exists in the base table. You " + "might want to specify EXCLUDING METADATA or OVERWRITING METADATA");
util.mergeTables(getDefaultMergingStrategies(), sourceSchema, derivedColumns, Collections.emptyList(), null);
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeWithIncludeFailsOnDuplicateRegularColumn.
@Test
public void mergeWithIncludeFailsOnDuplicateRegularColumn() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).build();
List<SqlNode> derivedColumns = Arrays.asList(regularColumn("two", DataTypes.INT()), regularColumn("two", DataTypes.INT()), regularColumn("four", DataTypes.STRING()));
thrown.expect(ValidationException.class);
thrown.expectMessage("A regular Column named 'two' already exists in the table.");
util.mergeTables(getDefaultMergingStrategies(), sourceSchema, derivedColumns, Collections.emptyList(), null);
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeMetadataColumns.
@Test
public void mergeMetadataColumns() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.metadata("two", DataTypes.INT(), false)).add(TableColumn.computed("c", DataTypes.INT(), "ABS(two)")).build();
List<SqlNode> derivedColumns = Arrays.asList(regularColumn("three", DataTypes.INT()), metadataColumn("four", DataTypes.INT(), true));
TableSchema mergedSchema = util.mergeTables(getDefaultMergingStrategies(), sourceSchema, derivedColumns, Collections.emptyList(), null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.metadata("two", DataTypes.INT(), false)).add(TableColumn.computed("c", DataTypes.INT(), "ABS(two)")).add(TableColumn.physical("three", DataTypes.INT())).add(TableColumn.metadata("four", DataTypes.INT(), true)).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
Aggregations