Amir Hossein Sharifzadeh
02/28/2023, 5:43 PMDian Fu
03/01/2023, 5:37 AMSerializationSchema and DeserializationSchema is just a wrapper of the Java ones, see [1] for more details. You could provide custom Java SerializationSchema and DeserializationSchema implementations and use them in Python. Actually the built-in SerializationSchema and DeserializationSchema implementations currently available in PyFlink are also wrappers of the Java ones. See [2] for more details.
[1] https://github.com/apache/flink/blob/master/flink-python/pyflink/common/serialization.py#L31
[2] https://github.com/apache/flink/blob/master/flink-python/pyflink/datastream/formats/json.pyAmir Hossein Sharifzadeh
03/01/2023, 9:09 PMenv = StreamExecutionEnvironment.get_execution_environment()
t_env = StreamTableEnvironment.create(stream_execution_environment=env)
t_env.get_config().get_configuration().set_boolean("python.fn-execution.memory.managed", True)
t_empadbkgd = f"""
CREATE TABLE bkgd_table(
raw_id INT,
raw_data STRING
) WITH (
'connector' = 'kafka',
'topic' = 'empadraw',
'properties.bootstrap.servers' = 'kafka:9092',
'properties.group.id' = 'MY_GRP',
'scan.startup.mode' = 'latest-offset',
'format' = 'json'
)
"""
So, if I have a deserialize function here, how may I pass it into my table to deserialize the message?Dian Fu
03/02/2023, 1:54 AMI don't use consumer but get the messages directly and process them once they arrive , isn’t the table bkgd_table defined in the sample code a Kafka consumer which consumes message from Kafka?
• The config option `'format' = 'json'`has already declared that the format of the data stored in Kafka is JSON. It will deserialize it for you atomically when consuming from Kafka. I’m confused that where you want your custom deserialize function to be used?Amir Hossein Sharifzadeh
03/02/2023, 3:29 PMDian Fu
03/03/2023, 1:34 AMDeserializationFormatFactory and SerializationFormatFactory. Also note that the name of the format is defined here [2].
To use it, you need firstly build a fat jar which contains all the dependencies(refer to json [3] as an example) and then use it in PyFlink as following [4]. After placing it into the classpath via [4], it will find it according to the custom format name using Java SPI mechanism.
[1] https://github.com/apache/flink/blob/master/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonFormatFactory.java#L59
[2] https://github.com/apache/flink/blob/master/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonFormatFactory.java#L134
[3] https://github.com/apache/flink/blob/master/flink-formats/flink-json/pom.xml#L141
[4] https://nightlies.apache.org/flink/flink-docs-release-1.16/docs/dev/python/dependency_management/#jar-dependenciesAmir Hossein Sharifzadeh
03/03/2023, 1:56 AMDian Fu
03/03/2023, 2:38 AM