Nicholas Leong
12/19/2023, 9:41 AMStreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(4);
env.enableCheckpointing(200);
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
// Define the source (MySQL binary logs)
String sourceDDL =
"CREATE TABLE transactions_binlog (" +
" t_id BIGINT NOT NULL," +
" t_amount BIGINT," +
" t_customer_id BIGINT," +
" PRIMARY KEY (t_id) NOT ENFORCED " +
") WITH (" +
" 'connector' = 'mysql-cdc'," +
" 'hostname' = 'localhost'," +
" 'port' = '64781'," +
" 'username' = 'localhost'," +
" 'password' = ''," +
" 'database-name' = 'example_db'," +
" 'table-name' = 'Transactions'" +
")";
tableEnv.executeSql(sourceDDL);
// Create a data stream
Table result = tableEnv.sqlQuery("SELECT * FROM transactions_binlog");
DataStreamRow stream = tableEnv.toDataStream(result);
// DataStreamRow appendOnlyStream = stream.filter(row -> row.getKind() == RowKind.INSERT);
// Process the data stream
appendOnlyStream.print();Yuval Itzchakov
12/19/2023, 10:35 AMNicholas Leong
12/20/2023, 1:34 AMYuval Itzchakov
12/20/2023, 4:33 AMprint(), that will attach a sink that prints to STDOUT.Nicholas Leong
12/20/2023, 6:19 AMException in thread "main" org.apache.flink.table.api.TableException: Table sink '*anonymous_datastream_sink$1*' doesn't support consuming update and delete changes which is produced by node TableSourceScan(table=[[default_catalog, default_database, transactions_binlog]], fields=[t_id, t_amount, t_customer_id])
Any advice on overcoming this ?Yuval Itzchakov
12/25/2023, 4:23 AMappendOnlyStream.addSink(new SinkFunction[String] {
override def invoke(value: String, context: SinkFunction.Context): Unit = println(value)
})