I have datastream with POJO with ObjectNode field....
# troubleshooting
m
I have datastream with POJO with ObjectNode field. I'd like to move to table API (in order to do join with JDBC) and back to datastream. It seems impossible to use ObjectNode if moving to table API, I tried to add DataTypeHint but then I get the error below. Is it really not possible and I should just use String?
Copy code
Query schema: [id: STRING, data: RAW('com.fasterxml.jackson.databind.node.ObjectNode', '...')]
Sink schema:  [id: STRING, data: RAW('java.lang.Object', '...')]
Copy code
public class Main {

    public static class myPojo {
        public String id;
        public @DataTypeHint("RAW") ObjectNode data;

        public myPojo() {
            // Empty ctor
        }

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

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

        JsonNodeFactory factory = JsonNodeFactory.instance;
        DataStream<myPojo> source = env.fromElements(new myPojo("a", factory.objectNode()), new myPojo("b", factory.objectNode()));

        tEnv.createTemporaryView("temp_view", source);
        Table result = tEnv.sqlQuery("SELECT * FROM temp_view");
        DataStream<myPojo> ds = tEnv.toDataStream(result, myPojo.class);

        ds.print();
        env.execute("");
    }
}
m
In my opinion, a class that uses ObjectNode as field doesn’t qualify as a POJO. I think POJOs can only contain primitives, enums, primitive wrapper types, String, temporal types. In some cases, a POJO can be composed of multiple POJOS. Kryo can probably serialize the type of POJO I described with little configuration. Have you tried registering a Kryo serializer for ObjectNode though ?
m
I'm new to java, wasn't aware of Kyro, will try to explore it Thanks 🙂
k
Also instead of JSONNode, You can try using the static structure for your table. It will gives you much flexibility to your code and If you don’t have static type try by creating field a JsonString and perform operation by extracting JSON from them.