Hey, I have a datastream which I need to join with...
# troubleshooting
m
Hey, I have a datastream which I need to join with a static table using JDBC, and then move back to datastream. The problem is I get
Table sink '*anonymous_datastream_sink$1*' doesn't support consuming update and delete changes which is produced by node Join
Is there a way handle the join like an append-only stream instead of dynamic table? (I saw I can move to changelog instead of datastream, but it gets really confusing with the watermarks, and cumbersome to write)
Copy code
public class Main {

    public static class myPojo {
        public String id;

        public myPojo() {
            // Empty ctor
        }

        public myPojo(String id) {
            this.id = id;
        }
    }

    public static class myPojoExtra extends myPojo {
        public String extra_data;

        public myPojoExtra() {
            // Empty ctor
        }
    }

    public static void createStaticTable(StreamTableEnvironment tEnv) {
        // Define a table schema
        Schema schema = Schema.newBuilder()
                .column("id", DataTypes.STRING())
                .column("extra_data", DataTypes.STRING())
                .build();

        // Create a table
        tEnv.createTable("StaticTable", 
                TableDescriptor.forConnector("filesystem")
                .schema(schema)
                .option("path", "file:///tmp/flink")
                .format("json")
                .build());

        // Insert data
        tEnv.executeSql("INSERT INTO StaticTable VALUES ('a', 'xxxx'), ('b', 'yyyy')");
    }


    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env =  StreamExecutionEnvironment.getExecutionEnvironment();
        env.setRuntimeMode(RuntimeExecutionMode.STREAMING);
        final StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);

        // Start with datastream
        DataStreammyPojo source = env.fromElements(new myPojo("a"), new myPojo("b"));
        tEnv.createTemporaryView("tempView", source);
        // Simulate JDBC table with filesystem table
        createStaticTable(tEnv);
        
        // Join with static table
        Table result = tEnv.sqlQuery("SELECT * FROM tempView LEFT JOIN StaticTable USING (id)");
        DataStreammyPojoExtra ds = tEnv.toDataStream(result, myPojoExtra.class);
        ds.print();
        // ds.print();
        env.execute("");
    }
}
m
I feel like I’ve seen this posted (and answered) this also on another channel. Let’s not cross post on multiple channels please
m
Hey thanks for the answer, it was on Stackoverflow, not another channel in slack 🙏
y
@Matan Perelmuter Try implementing your own sink to print out the messages:
Copy code
ds.addSink(new SinkFunction[myPojoExtra] {
      override def invoke(value: myPojoExtra, context: SinkFunction.Context): Unit = println(value)
    })