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 with ClickHouseDataProcessor attached for deserialization. To get data returned from server, depending on actual needs, you have 3 options:
  • Field Details

  • Method Details

    • getColumns

      List<ClickHouseColumn> getColumns()
      Gets list of columns.
      Returns:
      non-null list of column
    • 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

      default ClickHouseRecord firstRecord()
      Gets the first record only. Please use records() instead if you need to access the rest of records.
      Returns:
      the first record
      Throws:
      NoSuchElementException - when there's no record at all
      UncheckedIOException - when failed to read data(e.g. deserialization)
    • firstRecord

      default <T> T firstRecord(Class<T> objClass)
      Gets the first record as mapped object. Please use records(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 all
      UncheckedIOException - when failed to read data(e.g. deserialization)
    • records

      Returns an iterable collection of records which can be walked through in a foreach loop. Please pay attention that: 1) UncheckedIOException might 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

      <T> Iterable<T> records(Class<T> objClass)
      Returns an iterable collection of mapped objects which can be walked through in a foreach loop. When objClass is null or ClickHouseRecord, it's same as calling records().
      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

      default void pipe(OutputStream output, int bufferSize) throws IOException
      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 open
      bufferSize - buffer size, 0 or negative value will be treated as ClickHouseClientOption.BUFFER_SIZE
      Throws:
      IOException - when error occurred reading or writing data
    • stream

      default Stream<ClickHouseRecord> stream()
      Gets stream of records to process.
      Returns:
      stream of records
    • stream

      default <T> Stream<T> stream(Class<T> objClass)
      Gets stream of mapped objects to process.
      Returns:
      stream of mapped objects
    • close

      void close()
      Specified by:
      close in interface AutoCloseable
    • isClosed

      boolean isClosed()
      Checks whether the response has been closed or not.
      Returns:
      true if the response has been closed; false otherwise