@ -77,6 +77,7 @@ import java.util.stream.Stream;
import static org.apache.flink.configuration.CoreOptions.ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL ;
import static org.apache.flink.configuration.CoreOptions.ALWAYS_PARENT_FIRST_LOADER_PATTERNS_ADDITIONAL ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatThrownBy ;
/** Integration test for {@link FlinkPipelineComposer}. */
/** Integration test for {@link FlinkPipelineComposer}. */
class FlinkPipelineTransformITCase {
class FlinkPipelineTransformITCase {
@ -196,8 +197,8 @@ class FlinkPipelineTransformITCase {
null ,
null ,
null ) ) ,
null ) ) ,
Arrays . asList (
Arrays . asList (
"CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT ,`name` STRING,`age` INT}, primaryKeys=id, options=()}",
"CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT NOT NULL ,`name` STRING,`age` INT}, primaryKeys=id, options=()}",
"CreateTableEvent{tableId=default_namespace.default_schema.mytable2, schema=columns={`id` BIGINT ,`name` VARCHAR(255),`age` TINYINT,`description` STRING}, primaryKeys=id, options=()}",
"CreateTableEvent{tableId=default_namespace.default_schema.mytable2, schema=columns={`id` BIGINT NOT NULL ,`name` VARCHAR(255),`age` TINYINT,`description` STRING}, primaryKeys=id, options=()}",
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[3, Carol, 15, student], op=INSERT, meta=()}" ) ) ;
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[3, Carol, 15, student], op=INSERT, meta=()}" ) ) ;
}
}
@ -218,9 +219,9 @@ class FlinkPipelineTransformITCase {
null ,
null ,
null ) ) ,
null ) ) ,
Arrays . asList (
Arrays . asList (
"CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT ,`name` STRING,`age` INT}, primaryKeys=id, options=()}",
"CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT NOT NULL ,`name` STRING,`age` INT}, primaryKeys=id, options=()}",
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[1, Alice, 18], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[1, Alice, 18], op=INSERT, meta=()}" ,
"CreateTableEvent{tableId=default_namespace.default_schema.mytable2, schema=columns={`id` BIGINT ,`name` VARCHAR(255),`age` TINYINT,`description` STRING}, primaryKeys=id, options=()}",
"CreateTableEvent{tableId=default_namespace.default_schema.mytable2, schema=columns={`id` BIGINT NOT NULL ,`name` VARCHAR(255),`age` TINYINT,`description` STRING}, primaryKeys=id, options=()}",
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[3, Carol, 15, student], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[3, Carol, 15, student], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[4, Derrida, 25, student], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[4, Derrida, 25, student], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[4, Derrida, 25, student], after=[], op=DELETE, meta=()}" ) ) ;
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[4, Derrida, 25, student], after=[], op=DELETE, meta=()}" ) ) ;
@ -370,6 +371,151 @@ class FlinkPipelineTransformITCase {
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[4, DERRIDA, 25, student], after=[], op=DELETE, meta=()}" ) ) ;
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[4, DERRIDA, 25, student], after=[], op=DELETE, meta=()}" ) ) ;
}
}
@ParameterizedTest
@EnumSource
@Disabled ( "to be fixed in FLINK-37132" )
void testMultiTransformSchemaColumnsCompatibilityWithNullProjection (
ValuesDataSink . SinkApi sinkApi ) {
TransformDef nullProjection =
new TransformDef (
"default_namespace.default_schema.mytable2" ,
null ,
"age < 18" ,
null ,
null ,
null ,
null ,
null ) ;
assertThatThrownBy (
( ) - >
runGenericTransformTest (
sinkApi ,
Arrays . asList (
nullProjection ,
new TransformDef (
"default_namespace.default_schema.mytable2" ,
// reference part column
"id,UPPER(name) AS name" ,
"age >= 18" ,
null ,
null ,
null ,
null ,
null ) ) ,
Collections . emptyList ( ) ) )
. rootCause ( )
. isExactlyInstanceOf ( IllegalStateException . class )
. hasMessage (
"Unable to merge schema columns={`id` BIGINT,`name` VARCHAR(255),`age` TINYINT,`description` STRING}, primaryKeys=id, options=() "
+ "and columns={`id` BIGINT,`name` STRING}, primaryKeys=id, options=() with different column counts." ) ;
}
@ParameterizedTest
@EnumSource
@Disabled ( "to be fixed in FLINK-37132" )
void testMultiTransformSchemaColumnsCompatibilityWithEmptyProjection (
ValuesDataSink . SinkApi sinkApi ) {
TransformDef emptyProjection =
new TransformDef (
"default_namespace.default_schema.mytable2" ,
"" ,
"age < 18" ,
null ,
null ,
null ,
null ,
null ) ;
assertThatThrownBy (
( ) - >
runGenericTransformTest (
sinkApi ,
Arrays . asList (
emptyProjection ,
new TransformDef (
"default_namespace.default_schema.mytable2" ,
// reference part column
"id,UPPER(name) AS name" ,
"age >= 18" ,
null ,
null ,
null ,
null ,
null ) ) ,
Collections . emptyList ( ) ) )
. rootCause ( )
. isExactlyInstanceOf ( IllegalStateException . class )
. hasMessage (
"Unable to merge schema columns={`id` BIGINT,`name` VARCHAR(255),`age` TINYINT,`description` STRING}, primaryKeys=id, options=() "
+ "and columns={`id` BIGINT,`name` STRING}, primaryKeys=id, options=() with different column counts." ) ;
}
@ParameterizedTest
@EnumSource
void testMultiTransformWithNullEmptyAsteriskProjections ( ValuesDataSink . SinkApi sinkApi )
throws Exception {
TransformDef nullProjection =
new TransformDef (
"default_namespace.default_schema.mytable2" ,
null ,
"age < 18" ,
null ,
null ,
null ,
null ,
null ) ;
TransformDef emptyProjection =
new TransformDef (
"default_namespace.default_schema.mytable2" ,
"" ,
"age < 18" ,
null ,
null ,
null ,
null ,
null ) ;
TransformDef asteriskProjection =
new TransformDef (
"default_namespace.default_schema.mytable2" ,
"*" ,
"age < 18" ,
null ,
null ,
null ,
null ,
null ) ;
runGenericTransformTest (
sinkApi ,
Arrays . asList (
// Setting projection as null, '', or * should be equivalent
nullProjection ,
emptyProjection ,
asteriskProjection ,
new TransformDef (
"default_namespace.default_schema.mytable2" ,
// reference all column
"id,UPPER(name) AS name,age,description" ,
"age >= 18" ,
null ,
null ,
null ,
null ,
null ) ) ,
Arrays . asList (
"CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT,`name` STRING,`age` INT}, primaryKeys=id, options=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[1, Alice, 18], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[2, Bob, 20], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[2, Bob, 20], after=[2, Bob, 30], op=UPDATE, meta=()}" ,
"CreateTableEvent{tableId=default_namespace.default_schema.mytable2, schema=columns={`id` BIGINT NOT NULL,`name` STRING,`age` TINYINT,`description` STRING}, primaryKeys=id, options=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[3, Carol, 15, student], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[], after=[4, DERRIDA, 25, student], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable2, before=[4, DERRIDA, 25, student], after=[], op=DELETE, meta=()}" ) ) ;
}
/** This tests if transform generates metadata info correctly. */
/** This tests if transform generates metadata info correctly. */
@ParameterizedTest
@ParameterizedTest
@EnumSource
@EnumSource
@ -1447,7 +1593,7 @@ class FlinkPipelineTransformITCase {
assertThat ( outputEvents )
assertThat ( outputEvents )
. containsExactly (
. containsExactly (
// Initial stage
// Initial stage
"CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT ,`name` STRING,`age` INT}, primaryKeys=id, options=()}",
"CreateTableEvent{tableId=default_namespace.default_schema.mytable1, schema=columns={`id` INT NOT NULL ,`name` STRING,`age` INT}, primaryKeys=id, options=()}",
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[2, Barcarolle, 22], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[2, Barcarolle, 22], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[3, Cecily, 23], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[], after=[3, Cecily, 23], op=INSERT, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[3, Cecily, 23], after=[3, Colin, 24], op=UPDATE, meta=()}" ,
"DataChangeEvent{tableId=default_namespace.default_schema.mytable1, before=[3, Cecily, 23], after=[3, Colin, 24], op=UPDATE, meta=()}" ,