Jagan Nalla
07/20/2023, 3:18 AMJagan Nalla
07/20/2023, 3:19 AMdef setup_user_created_source_table(t_env, cfg):
te_user_created_source_ddl = """
create table %s(
id string,
name string,
email string
) WITH (
'connector' = 'kafka',
'property-version' = 'universal',
'topic' = '%s',
'properties.bootstrap.servers' = '%s',
'properties.group.id' = '%s',
'scan.startup.mode' = 'latest-offset',
'format' = 'json'
)
"""
# register table and return it
t_env.execute_sql(te_user_created_source_ddl %("user_created_source", "user_created_source_topic", "localhost:29092", "user_created_source_group_1"))
user_created_source_table = t_env.from_path("user_created_source")
return user_created_source_table
def setup_user_created_sink(st_env, cfg):
te_user_created_sink_ddl = """
CREATE TABLE %s(
the_kafka_key STRING,
id STRING,
name STRING,
email STRING
) WITH (
'connector' = 'kafka',
'topic' = '%s',
'properties.bootstrap.servers' = '%s',
'key.format' = 'raw',
'key.fields' = 'the_kafka_key',
'value.format' = 'avro-confluent',
'value.avro-confluent.url' = '<http://localhost:8082>',
'value.fields-include' = 'EXCEPT_KEY'
)
"""
# register table and return it
st_env.execute_sql(te_user_created_sink_ddl%("user_created_sink", "user_created_sink", "localhost:29092"))
setup_user_created_sink_table = st_env.from_path("user_created_sink")
return setup_user_created_sink_tableJagan Nalla
07/20/2023, 3:20 AMimport sys
from common import setup_user_created_source_table, setup_stream_table_environment ,setup_user_created_sink
PARALLELISM=1
def execute_join(env, st_env, cfg):
user_created_source_table = setup_user_created_source_table(st_env, cfg)
user_created_sink_table = setup_user_created_sink(st_env, cfg)
query = """
SELECT id as the_kafka_key, id, name, email from user_created_source
"""
print(query)
# sys.stdout.flush()
user_created_source_table = st_env.sql_query(query)
# user_created_source_table.execute().print()
user_created_source_table.execute_insert("user_created_sink").wait()
def execute():
print("EXECUTING USER CREATED")
sys.stdout.flush()
env, st_env, cfg = setup_stream_table_environment()
st_env.get_config().set("pipeline.name", "user_created")
env.set_parallelism(PARALLELISM)
execute_join(env, st_env, cfg)
if __name__ == '__main__':
execute()Jagan Nalla
07/20/2023, 3:21 AMCaused by: java.io.IOException: Failed to deserialize consumer record due to
at org.apache.flink.connector.kafka.source.reader.KafkaRecordEmitter.emitRecord(KafkaRecordEmitter.java:56)
at org.apache.flink.connector.kafka.source.reader.KafkaRecordEmitter.emitRecord(KafkaRecordEmitter.java:33)
at org.apache.flink.connector.base.source.reader.SourceReaderBase.pollNext(SourceReaderBase.java:143)
at org.apache.flink.streaming.api.operators.SourceOperator.emitNext(SourceOperator.java:385)
at org.apache.flink.streaming.runtime.io.StreamTaskSourceInput.emitNext(StreamTaskSourceInput.java:68)
at org.apache.flink.streaming.runtime.io.StreamOneInputProcessor.processInput(StreamOneInputProcessor.java:65)
at org.apache.flink.streaming.runtime.tasks.StreamTask.processInput(StreamTask.java:542)
at org.apache.flink.streaming.runtime.tasks.mailbox.MailboxProcessor.runMailboxLoop(MailboxProcessor.java:231)
at org.apache.flink.streaming.runtime.tasks.StreamTask.runMailboxLoop(StreamTask.java:831)
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:780)
at org.apache.flink.runtime.taskmanager.Task.runWithSystemExitMonitoring(Task.java:935)
at org.apache.flink.runtime.taskmanager.Task.restoreAndInvoke(Task.java:914)
at org.apache.flink.runtime.taskmanager.Task.doRun(Task.java:728)
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:550)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.io.IOException: Failed to deserialize consumer record ConsumerRecord(topic = user_created_source_topic, partition = 0, leaderEpoch = 0, offset = 9, CreateTime = 1689822946536, serialized key size = -1, serialized value size = 59, headers = RecordHeaders(headers = [], isReadOnly = false), key = null, value = [B@429303c6).
at org.apache.flink.connector.kafka.source.reader.deserializer.KafkaDeserializationSchemaWrapper.deserialize(KafkaDeserializationSchemaWrapper.java:57)
at org.apache.flink.connector.kafka.source.reader.KafkaRecordEmitter.emitRecord(KafkaRecordEmitter.java:53)
... 14 more
Caused by: org.apache.flink.streaming.runtime.tasks.ExceptionInChainedOperatorException: Could not forward element to next operator
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:99)
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:57)
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:29)
at org.apache.flink.streaming.runtime.tasks.SourceOperatorStreamTask$AsyncDataOutputToOutput.emitRecord(SourceOperatorStreamTask.java:313)
at org.apache.flink.streaming.api.operators.source.SourceOutputWithWatermarks.collect(SourceOutputWithWatermarks.java:110)
at org.apache.flink.connector.kafka.source.reader.KafkaRecordEmitter$SourceOutputWrapper.collect(KafkaRecordEmitter.java:67)
at org.apache.flink.api.common.serialization.DeserializationSchema.deserialize(DeserializationSchema.java:84)
at org.apache.flink.streaming.connectors.kafka.table.DynamicKafkaDeserializationSchema.deserialize(DynamicKafkaDeserializationSchema.java:113)
at org.apache.flink.connector.kafka.source.reader.deserializer.KafkaDeserializationSchemaWrapper.deserialize(KafkaDeserializationSchemaWrapper.java:54)
... 15 more
Caused by: org.apache.flink.streaming.runtime.tasks.ExceptionInChainedOperatorException: Could not forward element to next operator
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:99)
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:57)
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:29)
at org.apache.flink.streaming.api.operators.CountingOutput.collect(CountingOutput.java:56)
at org.apache.flink.streaming.api.operators.CountingOutput.collect(CountingOutput.java:29)
at StreamExecCalc$7.processElement(Unknown Source)
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:82)
... 23 more
Caused by: java.lang.RuntimeException: Failed to serialize row.
at org.apache.flink.formats.avro.AvroRowDataSerializationSchema.serialize(AvroRowDataSerializationSchema.java:90)
at org.apache.flink.formats.avro.AvroRowDataSerializationSchema.serialize(AvroRowDataSerializationSchema.java:40)
at org.apache.flink.streaming.connectors.kafka.table.DynamicKafkaRecordSerializationSchema.serialize(DynamicKafkaRecordSerializationSchema.java:116)
at org.apache.flink.streaming.connectors.kafka.table.DynamicKafkaRecordSerializationSchema.serialize(DynamicKafkaRecordSerializationSchema.java:36)
at org.apache.flink.connector.kafka.sink.KafkaWriter.write(KafkaWriter.java:196)
at org.apache.flink.streaming.runtime.operators.sink.SinkWriterOperator.processElement(SinkWriterOperator.java:160)
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:82)
... 29 more
Caused by: org.apache.flink.util.WrappingRuntimeException: Failed to serialize schema registry.
at org.apache.flink.formats.avro.RegistryAvroSerializationSchema.serialize(RegistryAvroSerializationSchema.java:90)
at org.apache.flink.formats.avro.AvroRowDataSerializationSchema.serialize(AvroRowDataSerializationSchema.java:88)
... 35 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.base/java.net.PlainSocketImpl.waitForConnect(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
at java.base/java.net.Socket.connect(Socket.java:608)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:508)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:603)
at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:276)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:375)
at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:396)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1253)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1015)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1367)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1342)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.rest.RestService.sendHttpRequest(RestService.java:265)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.rest.RestService.httpRequest(RestService.java:364)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:507)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:498)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:471)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.registerAndGetId(CachedSchemaRegistryClient.java:221)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.register(CachedSchemaRegistryClient.java:283)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.register(CachedSchemaRegistryClient.java:259)
at org.apache.flink.avro.registry.confluent.shaded.io.confluent.kafka.schemaregistry.client.SchemaRegistryClient.register(SchemaRegistryClient.java:42)
at org.apache.flink.formats.avro.registry.confluent.ConfluentSchemaRegistryCoder.writeSchema(ConfluentSchemaRegistryCoder.java:85)
at org.apache.flink.formats.avro.RegistryAvroSerializationSchema.serialize(RegistryAvroSerializationSchema.java:85)
... 36 moreMartijn Visser
07/20/2023, 7:45 AMuser_created_source_topicJagan Nalla
07/20/2023, 12:09 PMuser_created_source_topic
I produced this message b'{"id": "1", "name": "peter", "email": "<mailto:peter86@gmail.com|peter86@gmail.com>"}' to the topic user_created_source_topic and able to print in flink job.
When I sink source topic table then I'm getting error.Martijn Visser
07/20/2023, 12:50 PMMartijn Visser
07/20/2023, 12:50 PMConnection refused: connect so can Flink actually connect to SR?Martijn Visser
07/20/2023, 12:51 PMJagan Nalla
07/20/2023, 12:58 PMJagan Nalla
07/20/2023, 12:59 PMMartijn Visser
07/20/2023, 12:59 PMMartijn Visser
07/20/2023, 1:00 PMJagan Nalla
07/20/2023, 1:01 PMJagan Nalla
07/20/2023, 1:02 PMschema-registry:
image: confluentinc/cp-schema-registry:7.2.1
hostname: schema-registry
container_name: schema-registry
depends_on:
- broker
ports:
- "8091:8091"
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'broker:29092'
SCHEMA_REGISTRY_LISTENERS: <http://0.0.0.0:8091>Jagan Nalla
07/21/2023, 4:20 PMJagan Nalla
07/21/2023, 5:45 PMMartijn Visser
07/21/2023, 5:47 PMJagan Nalla
07/21/2023, 5:48 PMMartijn Visser
07/21/2023, 6:37 PMJagan Nalla
07/22/2023, 10:06 AM