Skip to content

Testcontainers: Add ClickHouse JDBC test#97

Open
ostinru wants to merge 13 commits intoapache:mainfrom
ostinru:clickhouse-jdbc-tests
Open

Testcontainers: Add ClickHouse JDBC test#97
ostinru wants to merge 13 commits intoapache:mainfrom
ostinru:clickhouse-jdbc-tests

Conversation

@ostinru
Copy link
Copy Markdown
Collaborator

@ostinru ostinru commented Apr 8, 2026

Add ClickHouse JDBC tests

Add new tests to cover Cloudberry -> PXF -> JDBC path. In this test we are verifying that main data Cloudberry and ClickHouse types can be converted back and forth.

Test covers ClickHouse 24.x and 26.x versions. Open-source ClickHouse has short support lifetime.

I tested following clickhouse-jdbc drivers:

  • 0.6.x (jdbc-v1) - works well with old ClickHouse versions. In ClickHouse 25.10 jdbc-v1 got broken Version 25.10 breaks JBDC driver ClickHouse/clickhouse-java#2636 and all queries raised an "Magic is not correct" error message.
  • 0.9.4 - fixes "Magic" issues, however has issue with String <-> bytea conversion ERROR: PXF server error : Method: getBytes("bin") encountered an exception.
  • 0.9.7+ - works well

Add jdbc-pxf-drivers project

Add new jdbc-pxf-drivers project to server. It excluded from default DEB-package build. Explicit actions required to install jdbc-drivers.

Side quest

Cloudberry FDW serializes rows as Greenplum CSV => PXF TextRecordReader parses the CSV stream via univocity CSV parser => for BYTEA columns it calls pgUtilities.parseByteaLiteral() => which returns a ByteBuffer.

@ostinru ostinru marked this pull request as ready for review April 9, 2026 03:55
@ostinru ostinru requested a review from MisterRaindrop April 9, 2026 03:56
if (val instanceof byte[]) {
return (byte[]) val;
}
ByteBuffer bb = (ByteBuffer) val;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ByteBuffer bb = (ByteBuffer) val;

If the types do not match, a ClassCastException will be thrown directly is better?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug - it always expected byte[].

Original PXF authors got following error for FDW:

ERROR:  PXF server error : class java.io.DataInputStream cannot be cast to class [B (java.io.DataInputStream and [B are in module java.base of loader 'bootstrap')

I have seen:

ERROR:  PXF server error : class java.nio.HeapByteBuffer cannot be cast to class [B (java.nio.HeapByteBuffer and [B are in module java.base of loader 'bootstrap')

So, here I am extending old (external-table) behaviour with one more data type. So, if it will be some other type - we will see new ClassCastException here.

dependsOn ":pxf-jdbc-drivers:jar"
from(project(':pxf-jdbc-drivers').configurations.runtimeClasspath)
into("${buildDir}/stage/lib")
duplicatesStrategy = DuplicatesStrategy.INCLUDE
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INCLUDE duplicate files are all retained, with later ones silently overwriting earlier ones, so it's unclear which version ends up being the final one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Let's try FAIL. In this case it will force us to manually solve dependency hell.

*/

dependencies {
// PostgreSQL driver is used by PXF itself.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostgreSQL driver? this is clickhouse driver?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostgreSQL driver included[1] into PXF distribution by default. No need to add it to libs. So, I left a comment about this.

[1] https://github.com/apache/cloudberry-pxf/blob/main/server/pxf-jdbc/build.gradle#L28

// Zstd support for Avro/Parquet
// Compression support for Avro/Parquet
dependency("com.github.luben:zstd-jni:1.5.7-6")
dependency("at.yawk.lz4:lz4-java:1.10.3")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not org.lz4:lz4-java ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maven Central says that we should use at.yawk.lz4:lz4-java:
https://mvnrepository.com/artifact/org.lz4/lz4-java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants