Hello, we implemented a simple enrichment using th...
# troubleshooting
r
Hello, we implemented a simple enrichment using the TableAPI (code below). Flink's default behavior is to load the MySQL database into memory and set this task as 'FINISHED' when done, while processing the Kafka records from the streaming source. Now, we wanted this enrichment to be able to handle changes to the database. For this purpose, we started looking at the 'mysql-cdc' connector, which brought multiple problems. The sink connector now had to be an 'upsert-kafka' connector. There were missing libraries besides the 'flink-connector-mysql-cdc-3.0.1.jar'. First, the 'connect-api-3.5.0.jar' due to a 'java.lang.ClassNotFoundException: org.apache.kafka.connect.data.Schema'. Then 'HikariCP-5.1.0.jar' due to 'java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariConfig', and now I have a 'java.lang.NoSuchMethodError: 'org.antlr.v4.runtime.tree.TerminalNode io.debezium.ddl.parser.mysql.generated.MySqlParser$DefaultValueContext.NULL_LITERAL()'. 1-Does anybody know how to overcome this error? 2-Has anybody used this 'mysql-cdc' connector succefully? 3-Do you have ideias on other approaches to reach the expected outcome? Thanks!
Copy code
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        String create_syslog_source_table = "CREATE TABLE syslog_raw (\n" +
                "    message_timestamp STRING,\n" +
                "    hostname STRING,\n" +
                "    app STRING,\n" +
                "    ID INT,\n" +
                "    ip_address STRING,\n" +
                "    description STRING\n" +
                ") WITH (\n" +
                "    'connector' = 'kafka',\n" +
                "    'topic' = 'syslog-generated',\n" +
                "    'scan.startup.mode' = 'earliest-offset',\n" +
                "    'properties.bootstrap.servers' = 'kafka-kafka-bootstrap:9095',\n" +
                "    'properties.group.id' = 'syslog',\n" +
                "    'format' = 'json'\n" +
                ")";
        tableEnv.executeSql(create_syslog_source_table);

        // Register the MySQL table with Flink SQL API
        String create_mysql_table = "CREATE TABLE iptable (\n" +
                "    ip_address STRING,\n" +
                "    hostname STRING,\n" +
                "    spi STRING,\n" +
                "    network STRING,\n" +
                "    region STRING\n" +
                ") WITH (\n" +
                "    'connector' = 'mysql-cdc',\n" +
                "    'hostname' = 'mysql',\n" +
                "    'port' = '3306',\n" +
                "    'database-name' = 'flink',\n" +
                "    'table-name' = 'your_table_name',\n" +
                "    'username' = 'flink',\n" +
                "    'password' = 'password',\n" +
                "    'scan.incremental.snapshot.enabled' = 'true',\n" +
                "    'scan.incremental.snapshot.chunk.key-column' = 'ip_address'\n" +
                ")";
        tableEnv.executeSql(create_mysql_table);

        String create_syslog_enriched_table = "CREATE TABLE syslog_enriched (\n" +
                "    message_timestamp STRING,\n" +
                "    hostname STRING,\n" +
                "    app STRING,\n" +
                "    ip_address_k STRING,\n" +
                "    ip_address_m STRING,\n" +
                "    hostname_m STRING,\n" +
                "    PRIMARY KEY (ip_address_k) NOT ENFORCED\n" +
                ") WITH (\n" +
                "    'connector' = 'upsert-kafka',\n" +
                "    'topic' = 'syslog-enriched',\n" +
                "    'properties.bootstrap.servers' = 'kafka-kafka-bootstrap:9095',\n" +
                "    'properties.group.id' = 'syslog-enr',\n" +
                "    'value.format' = 'json',\n" +
                "    'key.format' = 'json'\n" +
                ")";
        tableEnv.executeSql(create_syslog_enriched_table);

        // Create a new table containing the result of the join
        String insertQuery = "INSERT INTO syslog_enriched " +
                "SELECT k.message_timestamp, k.hostname, k.app, k.ip_address, m.ip_address, m.hostname " +
                "FROM syslog_raw AS k " +
                "JOIN iptable AS m ON k.ip_address = m.ip_address";

        // Execute the query
        tableEnv.executeSql(insertQuery);
Copy code
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        String create_syslog_source_table = "CREATE TABLE syslog_raw (\n" +
                "    message_timestamp STRING,\n" +
                "    hostname STRING,\n" +
                "    app STRING,\n" +
                "    ID INT,\n" +
                "    ip_address STRING,\n" +
                "    description STRING\n" +
                ") WITH (\n" +
                "    'connector' = 'kafka',\n" +
                "    'topic' = 'syslog-generated',\n" +
                "    'scan.startup.mode' = 'earliest-offset',\n" +
                "    'properties.bootstrap.servers' = 'kafka-kafka-bootstrap:9095',\n" +
                "    'properties.group.id' = 'syslog',\n" +
                "    'format' = 'json'\n" +
                ")";
        tableEnv.executeSql(create_syslog_source_table);

        // Register the MySQL table with Flink SQL API
        String create_mysql_table = "CREATE TABLE iptable (\n" +
                "    ip_address STRING,\n" +
                "    hostname STRING,\n" +
                "    spi STRING,\n" +
                "    network STRING,\n" +
                "    region STRING\n" +
                ") WITH (\n" +
                "    'connector' = 'jdbc',\n" +
                "    'url' = 'jdbc:mysql://mysql:3306/flink',\n" +
                "    'table-name' = 'your_table_name',\n" +
                "    'username' = 'flink',\n" +
                "    'password' = 'password',\n" +
                "    'driver' = 'com.mysql.jdbc.Driver'\n" +
                ")";
        tableEnv.executeSql(create_mysql_table);

        String create_syslog_enriched_table = "CREATE TABLE syslog_enriched (\n" +
                "    message_timestamp STRING,\n" +
                "    hostname STRING,\n" +
                "    app STRING,\n" +
                "    ip_address_k STRING,\n" +
                "    ip_address_m STRING,\n" +
                "    hostname_m STRING\n" +
                ") WITH (\n" +
                "    'connector' = 'kafka',\n" +
                "    'topic' = 'syslog-enriched',\n" +
                "    'scan.startup.mode' = 'earliest-offset',\n" +
                "    'properties.bootstrap.servers' = 'kafka-kafka-bootstrap:9095',\n" +
                "    'properties.group.id' = 'syslog-enr',\n" +
                "    'format' = 'json'\n" +
                ")";
        tableEnv.executeSql(create_syslog_enriched_table);

        // Create a new table containing the result of the join
        String insertQuery = "INSERT INTO syslog_enriched " +
                "SELECT k.message_timestamp, k.hostname, k.app, k.ip_address, m.ip_address, m.hostname " +
                "FROM syslog_raw AS k " +
                "JOIN iptable AS m ON k.ip_address = m.ip_address";

        // Execute the query
        tableEnv.executeSql(insertQuery);