Package com.clickhouse.client
Interface ClickHouseResponse
-
- All Superinterfaces:
AutoCloseable,Serializable
- All Known Implementing Classes:
ClickHouseSimpleResponse,ClickHouseStreamResponse
public interface ClickHouseResponse extends AutoCloseable, Serializable
This encapsulates a server reponse. Depending on concrete implementation, it could be either an in-memory list or a wrapped input stream withClickHouseDataProcessorattached for deserialization. To get data returned from server, depending on actual needs, you have 3 options:- use
records()orstream()to get deserializedClickHouseRecordone at a time - use
firstRecord()if you're certain that all you need is the firstClickHouseRecord - use
getInputStream()orpipe(OutputStream, int)if you prefer to handle stream instead of deserialized data
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()default ClickHouseRecordfirstRecord()Gets the first record only.List<ClickHouseColumn>getColumns()Gets list of columns.InputStreamgetInputStream()Gets input stream of the response.ClickHouseResponseSummarygetSummary()Gets summary of this response.booleanisClosed()Checks whether the reponse has been closed or not.default voidpipe(OutputStream output, int bufferSize)Pipes the contents of this response into the given output stream.Iterable<ClickHouseRecord>records()Returns an iterable collection of records which can be walked through in a foreach loop.default Stream<ClickHouseRecord>stream()Gets stream of records to process.
-
-
-
Method Detail
-
getColumns
List<ClickHouseColumn> getColumns()
Gets list of columns.- Returns:
- non-null list of column
-
getSummary
ClickHouseResponseSummary getSummary()
Gets summary of this response. Keep in mind that the summary may change over time until response is closed.- Returns:
- non-null summary of this response
-
getInputStream
InputStream getInputStream()
Gets input stream of the response. In general, this is the most memory-efficient way for streaming data from server to client. However, this also means additional work is required for deserialization, especially when using a binary format.- Returns:
- input stream for getting raw data returned from server
-
firstRecord
default ClickHouseRecord firstRecord()
Gets the first record only. Please userecords()instead if you need to access the rest of records.- Returns:
- the first record
- Throws:
NoSuchElementException- when there's no record at allUncheckedIOException- when failed to read data(e.g. deserialization)
-
records
Iterable<ClickHouseRecord> records()
Returns an iterable collection of records which can be walked through in a foreach loop. Please pay attention that: 1)UncheckedIOExceptionmight be thrown when iterating through the collection; and 2) it's not supposed to be called for more than once.- Returns:
- non-null iterable collection
-
pipe
default void pipe(OutputStream output, int bufferSize) throws IOException
Pipes the contents of this response into the given output stream.- Parameters:
output- non-null output stream, which will remain openbufferSize- buffer size, 0 or negative value will be treated as 8192- Throws:
IOException- when error occurred reading or writing data
-
stream
default Stream<ClickHouseRecord> stream()
Gets stream of records to process.- Returns:
- stream of records
-
close
void close()
- Specified by:
closein interfaceAutoCloseable
-
isClosed
boolean isClosed()
Checks whether the reponse has been closed or not.- Returns:
- true if the response has been closed; false otherwise
-
-