Search in sources :

Example 1 with MergingStrategy

use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy 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));
}
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 2 with MergingStrategy

use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy 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));
}
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 3 with MergingStrategy

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

Example 4 with MergingStrategy

use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.

the class MergeTableLikeUtilTest method includingAllOverwriteOptionsMergeStrategyExpansion.

@Test
public void includingAllOverwriteOptionsMergeStrategyExpansion() {
    List<SqlTableLikeOption> inputOptions = Arrays.asList(new SqlTableLikeOption(MergingStrategy.EXCLUDING, FeatureOption.ALL), new SqlTableLikeOption(MergingStrategy.INCLUDING, FeatureOption.CONSTRAINTS));
    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.INCLUDING));
    assertThat(mergingStrategies.get(FeatureOption.GENERATED), is(MergingStrategy.EXCLUDING));
    assertThat(mergingStrategies.get(FeatureOption.METADATA), 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 5 with MergingStrategy

use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.

the class MergeTableLikeUtilTest method includingAllMergeStrategyExpansion.

@Test
public void includingAllMergeStrategyExpansion() {
    List<SqlTableLikeOption> inputOptions = Collections.singletonList(new SqlTableLikeOption(MergingStrategy.INCLUDING, FeatureOption.ALL));
    Map<FeatureOption, MergingStrategy> mergingStrategies = util.computeMergingStrategies(inputOptions);
    assertThat(mergingStrategies.get(FeatureOption.OPTIONS), is(MergingStrategy.INCLUDING));
    assertThat(mergingStrategies.get(FeatureOption.PARTITIONS), is(MergingStrategy.INCLUDING));
    assertThat(mergingStrategies.get(FeatureOption.CONSTRAINTS), is(MergingStrategy.INCLUDING));
    assertThat(mergingStrategies.get(FeatureOption.GENERATED), is(MergingStrategy.INCLUDING));
    assertThat(mergingStrategies.get(FeatureOption.WATERMARKS), is(MergingStrategy.INCLUDING));
}
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)

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