Package com.clickhouse.client
Interface ClickHouseResponse
- All Superinterfaces:
AutoCloseable,Serializable
- All Known Implementing Classes:
ClickHouseSimpleResponse,ClickHouseStreamResponse
This encapsulates a server reponse. Depending on concrete implementation, it
could be either an in-memory list or a wrapped input stream with
ClickHouseDataProcessor attached 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ClickHouseResponseEmpty response that can never be closed. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()default ClickHouseRecordGets the first record only.default <T> TfirstRecord(Class<T> objClass) Gets the first record as mapped object.Gets list of columns.Gets input stream of the response.Gets summary of this response.booleanisClosed()Checks whether the response has been closed or not.default voidpipe(OutputStream output, int bufferSize) Pipes the contents of this response into the given output stream.records()Returns an iterable collection of records which can be walked through in a foreach loop.<T> Iterable<T>Returns an iterable collection of mapped objects which can be walked through in a foreach loop.default Stream<ClickHouseRecord>stream()Gets stream of records to process.default <T> Stream<T>Gets stream of mapped objects to process.
-
Field Details
-
EMPTY
Empty response that can never be closed.
-
-
Method Details
-
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
ClickHouseInputStream 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:
- non-null input stream for getting raw data returned from server
-
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)
-
firstRecord
Gets the first record as mapped object. Please userecords(Class)instead if you need to access the rest of records.- Type Parameters:
T- type of the mapped object- Parameters:
objClass- non-null class of the mapped object- Returns:
- mapped object of 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
- Throws:
UncheckedIOException- when failed to read data(e.g. deserialization)
-
records
Returns an iterable collection of mapped objects which can be walked through in a foreach loop. WhenobjClassis null orClickHouseRecord, it's same as callingrecords().- Type Parameters:
T- type of the mapped object- Parameters:
objClass- non-null class of the mapped object- Returns:
- non-null iterable collection
- Throws:
UncheckedIOException- when failed to read data(e.g. deserialization)
-
pipe
Pipes the contents of this response into the given output stream. Keep in mind that it's caller's responsibility to flush and close the output stream.- Parameters:
output- non-null output stream, which will remain openbufferSize- buffer size, 0 or negative value will be treated asClickHouseClientOption.BUFFER_SIZE- Throws:
IOException- when error occurred reading or writing data
-
stream
Gets stream of records to process.- Returns:
- stream of records
-
stream
Gets stream of mapped objects to process.- Returns:
- stream of mapped objects
-
close
void close()- Specified by:
closein interfaceAutoCloseable
-
isClosed
boolean isClosed()Checks whether the response has been closed or not.- Returns:
- true if the response has been closed; false otherwise
-