Search in sources :

Example 6 with FeatureOption

use of org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption 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));
}
Also used : FeatureOption(org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption) TableSchema(org.apache.flink.table.api.TableSchema) SqlWatermark(org.apache.flink.sql.parser.ddl.SqlWatermark) MergingStrategy(org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy) Test(org.junit.Test)

Example 7 with FeatureOption

use of org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption 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);
}
Also used : FeatureOption(org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption) TableSchema(org.apache.flink.table.api.TableSchema) MergingStrategy(org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 8 with FeatureOption

use of org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption 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));
}
Also used : FeatureOption(org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption) SqlTableLikeOption(org.apache.flink.sql.parser.ddl.SqlTableLike.SqlTableLikeOption) MergingStrategy(org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy) Test(org.junit.Test)

Example 9 with FeatureOption

use of org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption 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));
}
Also used : FeatureOption(org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption) TableSchema(org.apache.flink.table.api.TableSchema) MergingStrategy(org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 10 with FeatureOption

use of org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption 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);
}
Also used : FeatureOption(org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption) TableSchema(org.apache.flink.table.api.TableSchema) MergingStrategy(org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Aggregations

FeatureOption (org.apache.flink.sql.parser.ddl.SqlTableLike.FeatureOption)13 MergingStrategy (org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy)13 Test (org.junit.Test)12 TableSchema (org.apache.flink.table.api.TableSchema)10 SqlNode (org.apache.calcite.sql.SqlNode)7 SqlTableLikeOption (org.apache.flink.sql.parser.ddl.SqlTableLike.SqlTableLikeOption)3 SqlWatermark (org.apache.flink.sql.parser.ddl.SqlWatermark)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 SqlDataTypeSpec (org.apache.calcite.sql.SqlDataTypeSpec)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1