Hello everybody. I am trying to run statements wit...
# troubleshooting
l
Hello everybody. I am trying to run statements with a Kafka source through the REST endpoint of the
sql-gateway.sh
but I cannot seam to make it work. I am running everything in Kubernetes, on the latest
apache/flink:latest
image. I downloaded the
flink-sql-connector-kafka-3.0.2-1.18.jar
jar file and I am testing the statement first through the
sql-client.sh
:
Copy code
sql-client.sh -j flink-sql-connector-kafka-3.0.2-1.18.jar
The statement is (I'm using Confluent Kafka):
Copy code
CREATE TABLE input_1 (product STRING, amount INT) 
WITH (
  'connector' = 'kafka', 
  'topic' = 'purchases', 
  'format' = 'json', 
  'properties.group.id' = 'test', 
  'scan.startup.mode' = 'earliest-offset', 
  'properties.bootstrap.servers' = 'broker:9092', 
  'properties.security.protocol' = 'SASL_SSL', 
  'properties.sasl.mechanism' = 'PLAIN', 
  'properties.sasl.jaas.config' = 'org.apache.flink.kafka.shaded.org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="pass";'
);
when I then try
Copy code
select * from input_1;
everything works correctly. But now I am trying to send the statement through the
sql-gateway.sh
. As I cannot (don't know how to) pass the JAR to the command, I added the
flink-sql-connector-kafka-3.0.2-1.18.jar
file to the
/opt/flink/lib
directory and am starting the
sql-gateway
like this:
Copy code
sql-gateway.sh start -Dsql-gateway.endpoint.rest.address=0.0.0.0
I can see that the jar is loaded with
ps -Af
Copy code
flink       1982       1 18 19:18 pts/0    00:00:02 /opt/java/openjdk/bin/java -XX:+IgnoreUnrecognizedVMOptions -Dlog.file=/opt/flink/log/flink--sql-gateway-0-flink-jobmanager-68d8645577-hndpz.log -Dlog4j.configuration=file:/opt/flink/conf/log4j.properties -Dlog4j.configurationFile=file:/opt/flink/conf/log4j.properties -Dlogback.configurationFile=file:/opt/flink/conf/logback.xml -classpath /opt/flink/lib/flink-cep-1.18.1.jar:/opt/flink/lib/flink-connector-files-1.18.1.jar:/opt/flink/lib/flink-csv-1.18.1.jar:/opt/flink/lib/flink-json-1.18.1.jar:/opt/flink/lib/flink-scala_2.12-1.18.1.jar:/opt/flink/lib/flink-sql-connector-kafka-3.0.2-1.18.jar:/opt/flink/lib/flink-table-api-java-uber-1.18.1.jar:/opt/flink/lib/flink-table-planner-loader-1.18.1.jar:/opt/flink/lib/flink-table-runtime-1.18.1.jar:/opt/flink/lib/log4j-1.2-api-2.17.1.jar:/opt/flink/lib/log4j-api-2.17.1.jar:/opt/flink/lib/log4j-core-2.17.1.jar:/opt/flink/lib/log4j-slf4j-impl-2.17.1.jar:/opt/flink/lib/flink-dist-1.18.1.jar:/opt/flink/opt/flink-sql-gateway-1.18.1.jar:/opt/flink/opt/flink-python-1.18.1.jar::: org.apache.flink.table.gateway.SqlGateway -Dsql-gateway.endpoint.rest.address=0.0.0.0
The REST point works correctly on port
8083
, I can create the session and I can post the query
Copy code
curl -X POST flink-jobmanager:8083/v1/sessions/
curl -X POST flink-jobmanager:8083/v1/sessions/id/statements/ --data @statement1 (succeeds and returns an operational handle)
curl -X POST flink-jobmanager:8083/v1/sessions/id/statements/ --data '{"statement": "select * from input_1;"}' (succeeds and returns an operational handle)
And when I try to get the result,
Copy code
curl -X GET flink-jobmanager:8083/v1/sessions/id/operations/id/result/0 | jq .
I am getting the error `Unknown Source`:
Copy code
org.apache.flink.streaming.runtime.tasks.StreamTaskException: Cannot load user class: org.apache.flink.connector.kafka.source.KafkaSource
java.lang.Thread.run(Unknown Source)\nCaused by: java.lang.ClassNotFoundException: org.apache.flink.connector.kafka.source.KafkaSource\n\tat java.base/java.net.URLClassLoader.findClass(Unknown Source)\n\tat java.base/java.lang.ClassLoader.loadClass(Unknown Source)\n\tat org.apache.flink.util.FlinkUserCodeClassLoader.loadClassWithoutExceptionHandling(FlinkUserCodeClassLoader.java:67)\n\tat
So I guess I am not loading properly the
flink-sql-connector-kafka-3.0.2-1.18.jar
file so that I can use it through the Flink
sql-gateway
. My question is: what am I doing wrong and what is the recommended way to load the Kafka connector jar (in Flink or in the Flink gateway), so that I can execute statements to Kafka as a source, through the REST API of the Flink Gateway. Sorry for the lengthy post 🙌 , I tried a few things, searched through the documentation and am stuck at the moment. Please help 🙏
I am assuming it is the correct JAR file, as the
sql-client.sh
works properly.
h
It’s because the
apache/flink:latest
image doesn’t have
flink-sql-connector-kafka-3.0.2-1.18.jar
by default, you should build your own flink image, add that jar file and run again
🙌 1
l
Thanks @hùng trần việt 🙏 I guess just adding the
flink-sql-connector-kafka-3.0.2-1.18.jar
to the
/opt/flink/lib
directory should work? Or should I do something else?
h
Yes, just adding jar file to
/opt/flink/lib/
directory.
🙏 1
l
Just a note if someone else stumbles upon this problem. The latest
flink-sql-connector-kafka-3.0.2-1.18.jar
is not compatible with the current
apache/flink:latest
. What worked for me is the previous Flink version: • Docker image:
flink:1.17.2-scala_2.12-java8
• Connector:
flink-sql-connector-kafka-1.17.2.jar
m
This is not correct
The 1.18 connector version works with Flink 1.18
If not, file a Jira. But it is being used extensively in production clusters so I would first suspect a local configuration problem
l
Ok, thanks @Martijn Visser! Probably something I missed, that is why it was very strange to me that this can be a compatibility issue. I'll try to set it up one more time and in case it doesn't work - I'll open an issue. Thanks for the support all 🙏