ClickHouse / clickhouse-java

ClickHouse Java Clients & JDBC Driver
https://clickhouse.com
Apache License 2.0
1.45k stars 536 forks source link

Why not `ClickHouseBinaryFormatReader` extends `Iterator` or `Stream` interface ? #1963

Open abcfy2 opened 14 hours ago

abcfy2 commented 14 hours ago

Describe your feedback

I think ClickHouseBinaryFormatReader should also extends Iterator or Stream interface, that will make handle large result set very easy to use Java Stream API.

Code example

Maybe this will be a use case:

QueryResponse response = this.client.query("select * from mytable").get();
ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(response);

// if ClickHouseBinaryFormatReader extends Stream, we can use
reader.map(....).filter(...)

// if ClickHouseBinaryFormatReader extends Iterator, we can use
StreamSupport.stream(Spliterators.spliteratorUnknownSize(reader, 0), false).map(...).filter(...)

Thanks.