Hey, I'm using Flink connected to my Postgres and ...
# troubleshooting
j
Hey, I'm using Flink connected to my Postgres and MySql with CDC connectors. I'm implementing a new DynamicTableSink to save the results of my query (join 3 tables from both DB) to 3rd party KV store. For some reason, I'm not getting
UPDATE_BEFORE
and
UPDATE_AFTER
, but only
INSERT
or
DELETE
row kinds. I implemented
Copy code
@Override
public ChangelogMode getChangelogMode(ChangelogMode requestedMode) {

    ChangelogMode.Builder builder = ChangelogMode.newBuilder();

    builder.addContainedKind(RowKind.UPDATE_BEFORE);
    builder.addContainedKind(RowKind.UPDATE_AFTER);
    builder.addContainedKind(RowKind.INSERT);
    builder.addContainedKind(RowKind.DELETE);

    return builder.build();
}
Do you have any idea what I am doing wrong?
Copy code
public static void main(String[] args) throws Exception {

		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
		EnvironmentSettings settings = EnvironmentSettings.newInstance().inStreamingMode().build();
		StreamTableEnvironment tEnv = StreamTableEnvironment.create(env, settings);
		env.enableCheckpointing(3000);
		

		
		tEnv.executeSql("CREATE TABLE products (\n" +
				"    id INT,\n" +
				"    name STRING,\n" +
				"    description STRING,\n" +
				"    PRIMARY KEY (id) NOT ENFORCED\n" +
				") WITH (\n" +
				"    'connector' = 'mysql-cdc',\n" +
				"    'hostname' = 'localhost',\n" +
				"    'port' = '3306',\n" +
				"    'username' = 'root',\n" +
				"    'password' = '123456',\n" +
				"    'database-name' = 'mydb',\n" +
				"    'table-name' = 'products',\n" +
				"    'server-time-zone' = 'UTC'\n" +
				")");

		tEnv.executeSql("CREATE TABLE orders (\n" +
				"   order_id INT,\n" +
				"   order_date TIMESTAMP(0),\n" +
				"   customer_name STRING,\n" +
				"   price DECIMAL(10, 5),\n" +
				"   product_id INT,\n" +
				"   order_status BOOLEAN,\n" +
				"   PRIMARY KEY (order_id) NOT ENFORCED\n" +
				") WITH (\n" +
				"   'connector' = 'mysql-cdc',\n" +
				"   'hostname' = 'localhost',\n" +
				"   'port' = '3306',\n" +
				"   'username' = 'root',\n" +
				"   'password' = '123456',\n" +
				"   'database-name' = 'mydb',\n" +
				"   'table-name' = 'orders',\n" +
				"   'server-time-zone' = 'UTC'\n" +
				");");
		// Query the table or perform other operations using Flink Table API

		tEnv.executeSql("CREATE TABLE shipments (\n" +
				"   shipment_id INT,\n" +
				"   order_id INT,\n" +
				"   origin STRING,\n" +
				"   destination STRING,\n" +
				"   is_arrived BOOLEAN,\n" +
				"   PRIMARY KEY (shipment_id) NOT ENFORCED\n" +
				") WITH (\n" +
				"   'connector' = 'postgres-cdc',\n" +
				"   'hostname' = 'localhost',\n" +
				"   'port' = '5432',\n" +
				"   'username' = 'postgres',\n" +
				"   'password' = 'postgres',\n" +
				"   'database-name' = 'postgres',\n" +
				"   'schema-name' = 'public',\n" +
				"   'table-name' = 'shipments',\n" +
				"   'slot.name' = 'flink_local'\n" +
				");");

		tEnv.executeSql("CREATE TABLE enriched_orders (\n" +
				"   order_id INT,\n" +
				"   order_date TIMESTAMP(0),\n" +
				"   customer_name STRING,\n" +
				"   price DECIMAL(10, 5),\n" +
				"   product_id INT,\n" +
				"   order_status BOOLEAN,\n" +
				"   product_name STRING,\n" +
				"   product_description STRING,\n" +
				"   shipment_id INT,\n" +
				"   origin STRING,\n" +
				"   destination STRING,\n" +
				"   is_arrived BOOLEAN,\n" +
				"   PRIMARY KEY (order_id) NOT ENFORCED\n" +
				") WITH (\n" +
				"     'connector' = 'my_custom_sink_table',\n" +
				"     'targetUrl' = 'http://localhost:9200'\n" +
				");");

		tEnv.executeSql("INSERT INTO enriched_orders\n" +
				"SELECT o.*, p.name, p.description, s.shipment_id, s.origin, s.destination, s.is_arrived\n" +
				"FROM orders AS o\n"+
				"LEFT JOIN products AS p ON o.product_id = p.id\n" +
				"LEFT JOIN shipments AS s ON o.order_id = s.order_id\n" +
				"WHERE o.price>0;");


		env.execute("Flink Table API Example");