Hi everyone, I'm attempting to write stream data ...
# troubleshooting
f
Hi everyone, I'm attempting to write stream data to Apache Phoenix. My Flink version is 1.16.0, and I am reading data from Kafka and filtering it. After that, I am trying to use the JDBC Sink class to write the data. The code is shared below. However, I am encountering a '*Could not initialize class org.apache.phoenix.jdbc.PhoenixDriver'* error when attempting to write to Apache Phoenix. I am using Apache Phoenix on Cloudera CDP Private on-premises. I would appreciate your assistance with this issue. My dependency jar files for apache phoenix. phoenix-client-embedded-hbase-2.2-5.1.1.7.1.7.2000-305.jar phoenix-core-5.1.1.7.1.7.2000-305.jar phoenix-core-5.1.1.jar
Copy code
SinkFunction<BillDataMapper> jdbcSink = JdbcSink.sink("INSERT INTO MYDB.FLINKTEST (GSM, AMOUNT) VALUES (?, ?)",
		(ps, data) ->{
			ps.setString(1, data.getGsm());
			ps.setString(2, Double.toString(data.getBillAmount()));
		},
		JdbcExecutionOptions.builder()
				.withMaxRetries(3)
				.withBatchSize(100)
				.withBatchIntervalMs(3000)
				.build(),
		new JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
				.withUrl("jdbc:phoenix:myflink.local,myflink.local,myflink.local,:2181:/hbase:myuser@SYSTEM.LOCAL:/home/mypc/mypc.keytab")
				.withDriverName("org.apache.phoenix.jdbc.PhoenixDriver")
				.withConnectionCheckTimeoutSeconds(60)
				.build());

billStream.addSink(jdbcSink);
billStream.print();
p
Are you adding those dependencies to your Dockerfile?
f
I'm using linux environment and added these jars file info /flink/lib path. I didn't added all of them. I tried one by one.
Copy code
<dependency>
    <groupId>org.apache.phoenix</groupId>
    <artifactId>phoenix-core</artifactId>
    <version>5.1.1.7.1.7.2000-305</version>
    <scope>provided</scope>
</dependency>
For example, I try with this and get error, then try with another jar dependency
p
The class
...jdbc.PhoenixDriver
is present on which jar? Is this jar packed with your environment?
f
This jdbc.PhoenixDriver class is in each three jar files
this is what I tried for phoenix-core-5.1.1... jar when I import
p
It’s strange. Because by the error it says the class is not found. Are you sure your Flink app is loading the path
/flink/lib
?
f
I encountered ClassNotFoundError when I was reading from kafka, then I added kafka dependency jar files (flink-connector-kafka, kafka-clients) and solved this error.
p
Are you trying to restore from a checkpoint or something like it?
f
No I didn't implement checkpoint. I'm just reading from kafka and parsing to pojo class. Then, trying to write apache phoenix using JdbcSink
p
With the info I have ATM I don’t think I can give you another lead.
s
NoClassDefFoundError
couold not only mean class not found, also it could mean
ExceptionInInitializerError
happened earlier... this could happen if some jars from
/flink/lib
depend on one set of dependencies and versions and Phoenix jar depends on different versions... so I would double check dependencies for both against conflicts in versions
p
If you need a sparring partner to check, I can book 30-45 min to try to solve together