clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

getBlob implementation

Open AndrewRazumovskiy opened this issue 3 months ago • 6 comments

Use case

Download binary files from CH

Describe the solution you'd like

Implement

  1. Class - ResultSetImpl Method - getBinaryStream(String columnLabel)

  2. Class - ResultSetImpl Method - getBlob(String columnLabel)

Describe the alternatives you've considered

QuerySettings querySettings = new QuerySettings(); querySettings.setFormat(ClickHouseFormat.RawBLOB); QueryResponse queryResponse = connection.unwrap(ConnectionImpl.class) .getClient() .query("select ...", querySettings) .get();

Additional context

AndrewRazumovskiy avatar Sep 02 '25 08:09 AndrewRazumovskiy

Good day, @AndrewRazumovskiy ! Thank you for your suggestion!

Would you please describe your use-case?

Thanks!

chernser avatar Sep 02 '25 15:09 chernser

I store raw binary files in CH (png, pdf, txt, excel), and I want to download them as is, in binary mode

AndrewRazumovskiy avatar Sep 03 '25 09:09 AndrewRazumovskiy

@AndrewRazumovskiy

Thank you for the response! Do you need Blob for some framework?

However method com.clickhouse.jdbc.ResultSetImpl#getBytes(int) or com.clickhouse.jdbc.ResultSetImpl#getBinaryStream(int) is more straightforward option because has less wrapping classes. I assume there is a column of String type that you want to retrieve.

chernser avatar Sep 03 '25 14:09 chernser

ResultSetImpl#getBytes throws "Column is not of array type" ResultSetImpl#getBinaryStream returns "BinaryStream is not yet supported" (v0.9.1)

AndrewRazumovskiy avatar Sep 03 '25 16:09 AndrewRazumovskiy

I tried to use jooq, but in the end fall back to native java

AndrewRazumovskiy avatar Sep 03 '25 16:09 AndrewRazumovskiy

ResultSetImpl#getBytes throws "Column is not of array type" ResultSetImpl#getBinaryStream returns "BinaryStream is not yet supported" (v0.9.1) This will be fixed in 0.9.3 (should be ready by end of this month). Here is the issue for that https://github.com/ClickHouse/clickhouse-java/issues/2263

I tried to use jooq, but in the end fall back to native java Jooq as I know is built on top of JDBC and it just adds extra layer of abstractions. We always recommend using clickhouse-java until JDBC is the requirement.

chernser avatar Sep 03 '25 16:09 chernser