use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeExcludingMetadataColumnsDuplicate.
@Test
public void mergeExcludingMetadataColumnsDuplicate() {
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(), false));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.METADATA, MergingStrategy.EXCLUDING);
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())).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeIncludingGeneratedColumnsFailsOnDuplicate.
@Test
public void mergeIncludingGeneratedColumnsFailsOnDuplicate() {
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")));
thrown.expect(ValidationException.class);
thrown.expectMessage("A generated column named 'two' already exists in the base table. You " + "might want to specify EXCLUDING GENERATED or OVERWRITING GENERATED");
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 mergeWatermarks.
@Test
public void mergeWatermarks() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "one + 1")).add(TableColumn.physical("timestamp", DataTypes.TIMESTAMP())).watermark("timestamp", "timestamp - INTERVAL '5' SECOND", DataTypes.TIMESTAMP()).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("timestamp", DataTypes.TIMESTAMP())).watermark("timestamp", "timestamp - INTERVAL '5' SECOND", DataTypes.TIMESTAMP()).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 mergeExcludingWatermarksDuplicate.
@Test
public void mergeExcludingWatermarksDuplicate() {
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.EXCLUDING);
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.table.api.TableSchema in project flink by apache.
the class MergeTableLikeUtilTest method mergeExcludingConstraintsOnDuplicate.
@Test
public void mergeExcludingConstraintsOnDuplicate() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT().notNull())).add(TableColumn.physical("two", DataTypes.STRING().notNull())).add(TableColumn.physical("three", DataTypes.FLOAT().notNull())).primaryKey("constraint-42", new String[] { "one", "two", "three" }).build();
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.CONSTRAINTS, MergingStrategy.EXCLUDING);
TableSchema mergedSchema = util.mergeTables(mergingStrategies, sourceSchema, Collections.emptyList(), Collections.emptyList(), primaryKey("one", "two"));
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT().notNull())).add(TableColumn.physical("two", DataTypes.STRING().notNull())).add(TableColumn.physical("three", DataTypes.FLOAT().notNull())).primaryKey("PK_3531879", new String[] { "one", "two" }).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
Aggregations