use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.
the class MergeTableLikeUtilTest method mergeOverwritingWatermarksDuplicate.
@Test
public void mergeOverwritingWatermarksDuplicate() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.physical("timestamp", DataTypes.TIMESTAMP())).watermark("timestamp", "timestamp - INTERVAL '5' SECOND", DataTypes.TIMESTAMP()).build();
List<SqlWatermark> derivedWatermarkSpecs = Collections.singletonList(new SqlWatermark(SqlParserPos.ZERO, identifier("timestamp"), boundedStrategy("timestamp", "10")));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.WATERMARKS, MergingStrategy.OVERWRITING);
TableSchema mergedSchema = util.mergeTables(mergingStrategies, sourceSchema, Collections.emptyList(), derivedWatermarkSpecs, null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.physical("timestamp", DataTypes.TIMESTAMP())).watermark("timestamp", "`timestamp` - INTERVAL '10' SECOND", DataTypes.TIMESTAMP()).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.
the class MergeTableLikeUtilTest method mergeOverwritingComputedColumnWithMetadataColumn.
@Test
public void mergeOverwritingComputedColumnWithMetadataColumn() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "one + 3")).build();
List<SqlNode> derivedColumns = Collections.singletonList(metadataColumn("two", DataTypes.BOOLEAN(), false));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.METADATA, MergingStrategy.OVERWRITING);
thrown.expect(ValidationException.class);
thrown.expectMessage("A column named 'two' already exists in the base table." + " Metadata columns can only overwrite other metadata columns.");
util.mergeTables(mergingStrategies, sourceSchema, derivedColumns, Collections.emptyList(), null);
}
use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.
the class MergeTableLikeUtilTest method excludingAllMergeStrategyExpansion.
@Test
public void excludingAllMergeStrategyExpansion() {
List<SqlTableLikeOption> inputOptions = Collections.singletonList(new SqlTableLikeOption(MergingStrategy.EXCLUDING, FeatureOption.ALL));
Map<FeatureOption, MergingStrategy> mergingStrategies = util.computeMergingStrategies(inputOptions);
assertThat(mergingStrategies.get(FeatureOption.OPTIONS), is(MergingStrategy.EXCLUDING));
assertThat(mergingStrategies.get(FeatureOption.PARTITIONS), is(MergingStrategy.EXCLUDING));
assertThat(mergingStrategies.get(FeatureOption.CONSTRAINTS), is(MergingStrategy.EXCLUDING));
assertThat(mergingStrategies.get(FeatureOption.GENERATED), is(MergingStrategy.EXCLUDING));
assertThat(mergingStrategies.get(FeatureOption.WATERMARKS), is(MergingStrategy.EXCLUDING));
}
use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy 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.sql.parser.ddl.SqlTableLike.MergingStrategy 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);
}
Aggregations