Package com.clickhouse.client
Class ClickHouseRequest<SelfT extends ClickHouseRequest<SelfT>>
- java.lang.Object
-
- com.clickhouse.client.ClickHouseRequest<SelfT>
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ClickHouseRequest.Mutation
public class ClickHouseRequest<SelfT extends ClickHouseRequest<SelfT>> extends Object implements Serializable
Request object holding references toClickHouseClient,ClickHouseNode, format, sql, options and settings etc. for execution.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClickHouseRequest.MutationMutation request.
-
Field Summary
Fields Modifier and Type Field Description protected ClickHouseConfigChangeListener<ClickHouseRequest<?>>changeListenerprotected ClickHouseConfigconfigprotected List<ClickHouseExternalTable>externalTablesprotected ClickHouseDeferredValue<ClickHouseInputStream>inputprotected AtomicReference<ClickHouseRequestManager>managerRefprotected Map<String,String>namedParametersprotected Map<ClickHouseOption,Serializable>optionsprotected ClickHouseDeferredValue<ClickHouseOutputStream>outputprotected ClickHouseParameterizedQuerypreparedQueryprotected StringqueryIdprotected Function<ClickHouseNodeSelector,ClickHouseNode>serverprotected BiConsumer<ClickHouseNode,ClickHouseNode>serverListenerprotected AtomicReference<ClickHouseNode>serverRefprotected Map<String,Serializable>settingsprotected Stringsqlprotected List<String>statementsprotected AtomicReference<ClickHouseTransaction>txRef
-
Constructor Summary
Constructors Modifier Constructor Description protectedClickHouseRequest(ClickHouseClient client, Function<ClickHouseNodeSelector,ClickHouseNode> server, AtomicReference<ClickHouseNode> ref, Map<ClickHouseOption,Serializable> options, boolean sealed)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description SelfTaddExternal(ClickHouseExternalTable table)Adds an external table.protected <T> TchangeProperty(String property, T oldValue, T newValue)protected ClickHouseNodechangeServer(ClickHouseNode currentServer, ClickHouseNode newServer)protected voidcheckSealed()SelfTclearSession()Clears session configuration including session id, session check(whether to validate the id), and session timeout.SelfTcompressServerResponse(boolean enable)Enable or disable compression of server response.SelfTcompressServerResponse(boolean enable, ClickHouseCompression compressAlgorithm)Enable or disable compression of server response.SelfTcompressServerResponse(boolean enable, ClickHouseCompression compressAlgorithm, int compressLevel)Enable or disable compression of server response.SelfTcompressServerResponse(ClickHouseCompression compressAlgorithm)Enable or disable compression of server response.ClickHouseRequest<SelfT>copy()Creates a copy of this request including listeners.SelfTdecompressClientRequest(boolean enable)Enable or disable compression of client request.SelfTdecompressClientRequest(boolean enable, ClickHouseCompression compressAlgorithm)Enable or disable compression of client request.SelfTdecompressClientRequest(boolean enable, ClickHouseCompression compressAlgorithm, int compressLevel)Enable or disable compression of client request.SelfTdecompressClientRequest(ClickHouseCompression compressAlgorithm)Enable or disable compression of client request.CompletableFuture<ClickHouseResponse>execute()Executes the request.ClickHouseResponseexecuteAndWait()Synchronous version ofexecute().ClickHouseResponseexecuteWithinTransaction()Executes the request within an implicit transaction.ClickHouseResponseexecuteWithinTransaction(boolean useImplicitTransaction)Deprecated.will be removed in the future, once the minimum supported version of ClickHouse is 22.7 or aboveSelfTexternal(ClickHouseExternalTable table, ClickHouseExternalTable... more)Sets one or more external tables.SelfTexternal(Collection<ClickHouseExternalTable> tables)Sets external tables.SelfTformat(ClickHouseFormat format)Sets format to be used for communication between server and client.ClickHouseConfigChangeListener<ClickHouseRequest<?>>getChangeListener()protected ClickHouseClientgetClient()Gets client associated with the request.ClickHouseConfiggetConfig()Gets request configuration.List<ClickHouseExternalTable>getExternalTables()Gets immutable list of external tables.ClickHouseFormatgetFormat()Gets data format used for communication between server and client.ClickHouseFormatgetInputFormat()Gets data format used for input(e.g.Optional<ClickHouseInputStream>getInputStream()Gets input stream.ClickHouseRequestManagergetManager()Gets manager for the request, which defaults toClickHouseRequestManager.getInstance().Optional<ClickHouseOutputStream>getOutputStream()Gets output stream.ClickHouseParameterizedQuerygetPreparedQuery()Gets prepared query, which is a loosely parsed query with the origianl query and list of parameters.protected StringgetQuery()Gets query, either set byquery()ortable().Optional<String>getQueryId()Gets query id.ClickHouseNodegetServer()Gets the server currently connected to.BiConsumer<ClickHouseNode,ClickHouseNode>getServerListener()Optional<String>getSessionId()Gets session id.Map<String,Object>getSettings()Gets immutable settings.List<String>getStatements()Gets list of SQL statements.List<String>getStatements(boolean withSettings)Gets list of SQL statements.ClickHouseTransactiongetTransaction()booleanhasInputStream()Checks if the request contains any input stream.booleanhasOutputStream()Checks if the response should be redirected to an output stream, which was defined by one ofoutput(*)methods.booleanisSealed()Checks if the request is sealed(immutable).booleanisTransactional()Checks if the request is bounded with a transaction.SelfTmanager(ClickHouseRequestManager manager)Sets request manager which is responsible for generating query ID and session ID, as well as transaction creation.SelfToption(ClickHouseOption option, Serializable value)Sets an option.SelfToptions(Map<ClickHouseOption,Serializable> options)Sets all options.SelfToptions(Properties options)Sets all options.SelfToutput(ClickHouseDeferredValue<ClickHouseOutputStream> output)Sets output stream, to which response will be redirected.SelfToutput(ClickHouseFile file)Sets output file, to which response will be redirected.SelfToutput(ClickHouseOutputStream output)Sets output stream, to which response will be redirected.SelfToutput(OutputStream output)Sets output stream, to which response will be redirected.SelfToutput(String file)Sets output file, to which response will be redirected.SelfToutput(String file, ClickHouseCompression compression)Sets compressed output file, to which response will be redirected.SelfTparams(ClickHouseValue[] values)Sets parameters wrapped byClickHouseValue.SelfTparams(ClickHouseValue value, ClickHouseValue... more)Sets parameters wrapped byClickHouseValue.SelfTparams(Object[] values)Set raw parameters, which will later be stringified usingClickHouseValues.convertToSqlExpression(Object).SelfTparams(Object value, Object... more)Set raw parameters, which will later be stringified usingClickHouseValues.convertToSqlExpression(Object).SelfTparams(String[] values)Sets stringified parameters which are used to substitude named parameters in SQL query without further transformation and validation.SelfTparams(String value, String... more)Sets stringified parameters which are used to substitude named parameters in SQL query without further transformation and validation.SelfTparams(Collection<String> values)Sets stringified parameters.SelfTparams(Map<String,String> namedParams)Sets named parameters.SelfTquery(ClickHouseParameterizedQuery query)Sets parameterized query.SelfTquery(ClickHouseParameterizedQuery query, String queryId)Sets parameterized query and optinally query id.SelfTquery(String sql)Sets query.SelfTquery(String query, String queryId)Sets query and optinally query id.SelfTremoveExternal(ClickHouseExternalTable external)Removes an external table.SelfTremoveExternal(String name)Removes an external table by name.SelfTremoveOption(ClickHouseOption option)Removes an option.SelfTremoveSetting(String setting)Removes a setting.SelfTreset()Resets the request to start all over.protected voidresetCache()ClickHouseRequest<SelfT>seal()Creates a sealed request, which is an immutable copy of the current request.SelfTsession(String sessionId)Sets current session using custom id.SelfTsession(String sessionId, Boolean check)Sets session.SelfTsession(String sessionId, Boolean check, Integer timeout)Sets current session.SelfTsession(String sessionId, Integer timeout)Sets current session.SelfTset(String setting, Serializable value)Sets a setting.SelfTset(String setting, String value)Sets a setting.SelfTsetChangeListener(ClickHouseConfigChangeListener<ClickHouseRequest<?>> listener)Sets thread-safe change listener.SelfTsetServerListener(BiConsumer<ClickHouseNode,ClickHouseNode> listener)Sets thread-safe server change listener.SelfTsettings(Map<String,Serializable> settings)Sets all server settings.SelfTtable(String table)Sets target table.SelfTtable(String table, String queryId)Sets target table and optionally query id.SelfTtransaction()Creates and starts a transaction.SelfTtransaction(int timeout)Creates and starts a transaction immediately.SelfTtransaction(ClickHouseTransaction transaction)Sets transaction.SelfTuse(String database)Changes current database.ClickHouseRequest.Mutationwrite()Creates a new request for mutation.
-
-
-
Field Detail
-
managerRef
protected final AtomicReference<ClickHouseRequestManager> managerRef
-
server
protected final Function<ClickHouseNodeSelector,ClickHouseNode> server
-
serverRef
protected final AtomicReference<ClickHouseNode> serverRef
-
txRef
protected final AtomicReference<ClickHouseTransaction> txRef
-
externalTables
protected final List<ClickHouseExternalTable> externalTables
-
options
protected final Map<ClickHouseOption,Serializable> options
-
settings
protected final Map<String,Serializable> settings
-
input
protected transient ClickHouseDeferredValue<ClickHouseInputStream> input
-
output
protected transient ClickHouseDeferredValue<ClickHouseOutputStream> output
-
queryId
protected String queryId
-
sql
protected String sql
-
preparedQuery
protected ClickHouseParameterizedQuery preparedQuery
-
changeListener
protected transient ClickHouseConfigChangeListener<ClickHouseRequest<?>> changeListener
-
serverListener
protected transient BiConsumer<ClickHouseNode,ClickHouseNode> serverListener
-
config
protected transient ClickHouseConfig config
-
-
Constructor Detail
-
ClickHouseRequest
protected ClickHouseRequest(ClickHouseClient client, Function<ClickHouseNodeSelector,ClickHouseNode> server, AtomicReference<ClickHouseNode> ref, Map<ClickHouseOption,Serializable> options, boolean sealed)
-
-
Method Detail
-
changeProperty
protected <T> T changeProperty(String property, T oldValue, T newValue)
-
changeServer
protected ClickHouseNode changeServer(ClickHouseNode currentServer, ClickHouseNode newServer)
-
checkSealed
protected void checkSealed()
-
getClient
protected ClickHouseClient getClient()
Gets client associated with the request.- Returns:
- non-null client
-
getQuery
protected String getQuery()
Gets query, either set byquery()ortable().- Returns:
- sql query
-
resetCache
protected void resetCache()
-
copy
public ClickHouseRequest<SelfT> copy()
Creates a copy of this request including listeners. Please pay attention that the same node reference (returned fromgetServer()) will be copied to the new request as well, meaning failover will change node for both requests.- Returns:
- copy of this request
-
getManager
public ClickHouseRequestManager getManager()
Gets manager for the request, which defaults toClickHouseRequestManager.getInstance().- Returns:
- non-null request manager
-
isSealed
public boolean isSealed()
Checks if the request is sealed(immutable).- Returns:
- true if the request is sealed; false otherwise
-
isTransactional
public boolean isTransactional()
Checks if the request is bounded with a transaction.- Returns:
- true if the request is bounded with a transaction; false otherwise
-
hasInputStream
public boolean hasInputStream()
Checks if the request contains any input stream.- Returns:
- true if there's input stream; false otherwise
-
hasOutputStream
public boolean hasOutputStream()
Checks if the response should be redirected to an output stream, which was defined by one ofoutput(*)methods.- Returns:
- true if response should be redirected to an output stream; false otherwise
-
getServer
public final ClickHouseNode getServer()
Gets the server currently connected to. The initial value was determined by theFunctionpassed to constructor, and it may be changed over time when failover is enabled.- Returns:
- non-null node
-
getConfig
public ClickHouseConfig getConfig()
Gets request configuration.- Returns:
- request configuration
-
getTransaction
public ClickHouseTransaction getTransaction()
-
getChangeListener
public final ClickHouseConfigChangeListener<ClickHouseRequest<?>> getChangeListener()
-
getServerListener
public final BiConsumer<ClickHouseNode,ClickHouseNode> getServerListener()
-
getInputStream
public Optional<ClickHouseInputStream> getInputStream()
Gets input stream.- Returns:
- input stream
-
getOutputStream
public Optional<ClickHouseOutputStream> getOutputStream()
Gets output stream.- Returns:
- output stream
-
getExternalTables
public List<ClickHouseExternalTable> getExternalTables()
Gets immutable list of external tables.- Returns:
- immutable list of external tables
-
getFormat
public ClickHouseFormat getFormat()
Gets data format used for communication between server and client.- Returns:
- data format used for communication between server and client
-
getInputFormat
public ClickHouseFormat getInputFormat()
Gets data format used for input(e.g. writing data into server).- Returns:
- data format for input
-
getPreparedQuery
public ClickHouseParameterizedQuery getPreparedQuery()
Gets prepared query, which is a loosely parsed query with the origianl query and list of parameters.- Returns:
- prepared query
-
getSettings
public Map<String,Object> getSettings()
Gets immutable settings.- Returns:
- immutable settings
-
getStatements
public List<String> getStatements()
Gets list of SQL statements. Same asgetStatements(true).- Returns:
- list of SQL statements
-
getStatements
public List<String> getStatements(boolean withSettings)
Gets list of SQL statements.- Parameters:
withSettings- true to treat settings as SQL statement; false otherwise- Returns:
- list of SQL statements
-
compressServerResponse
public SelfT compressServerResponse(boolean enable)
Enable or disable compression of server response. Pay attention thatClickHouseClientOption.COMPRESS_ALGORITHMandClickHouseClientOption.COMPRESS_LEVELwill be used.- Parameters:
enable- true to enable compression of server response; false otherwise- Returns:
- the request itself
-
compressServerResponse
public SelfT compressServerResponse(ClickHouseCompression compressAlgorithm)
Enable or disable compression of server response. Pay attention thatClickHouseClientOption.COMPRESS_ALGORITHMandClickHouseClientOption.COMPRESS_LEVELwill be used.- Parameters:
compressAlgorithm- compression algorihtm, null orClickHouseCompression.NONEmeans no compression- Returns:
- the request itself
-
compressServerResponse
public SelfT compressServerResponse(boolean enable, ClickHouseCompression compressAlgorithm)
Enable or disable compression of server response. Pay attention thatClickHouseClientOption.COMPRESS_LEVELwill be used.- Parameters:
enable- true to enable compression of server response; false otherwisecompressAlgorithm- compression algorithm, null is treated asClickHouseCompression.NONEorClickHouseClientOption.COMPRESS_ALGORITHMdepending on whether enabled- Returns:
- the request itself
-
compressServerResponse
public SelfT compressServerResponse(boolean enable, ClickHouseCompression compressAlgorithm, int compressLevel)
Enable or disable compression of server response.- Parameters:
enable- true to enable compression of server response; false otherwisecompressAlgorithm- compression algorithm, null is treated asClickHouseCompression.NONEorClickHouseClientOption.COMPRESS_ALGORITHMdepending on whether enabledcompressLevel- compression level- Returns:
- the request itself
-
decompressClientRequest
public SelfT decompressClientRequest(boolean enable)
Enable or disable compression of client request. Pay attention thatClickHouseClientOption.DECOMPRESS_ALGORITHMandClickHouseClientOption.DECOMPRESS_LEVELwill be used.- Parameters:
enable- true to enable compression of client request; false otherwise- Returns:
- the request itself
-
decompressClientRequest
public SelfT decompressClientRequest(ClickHouseCompression compressAlgorithm)
Enable or disable compression of client request. Pay attention thatClickHouseClientOption.DECOMPRESS_LEVELwill be used.- Parameters:
compressAlgorithm- compression algorithm, null is treated asClickHouseCompression.NONEorClickHouseClientOption.DECOMPRESS_ALGORITHMdepending on whether enabled- Returns:
- the request itself
-
decompressClientRequest
public SelfT decompressClientRequest(boolean enable, ClickHouseCompression compressAlgorithm)
Enable or disable compression of client request. Pay attention thatClickHouseClientOption.DECOMPRESS_LEVELwill be used.- Parameters:
enable- true to enable compression of client request; false otherwisecompressAlgorithm- compression algorithm, null is treated asClickHouseCompression.NONEorClickHouseClientOption.DECOMPRESS_ALGORITHMdepending on whether enabled- Returns:
- the request itself
-
decompressClientRequest
public SelfT decompressClientRequest(boolean enable, ClickHouseCompression compressAlgorithm, int compressLevel)
Enable or disable compression of client request.- Parameters:
enable- true to enable compression of client request; false otherwisecompressAlgorithm- compression algorithm, null is treated asClickHouseCompression.NONEcompressLevel- compression level- Returns:
- the request itself
-
addExternal
public SelfT addExternal(ClickHouseExternalTable table)
Adds an external table.- Parameters:
table- non-null external table- Returns:
- the request itself
-
external
public SelfT external(ClickHouseExternalTable table, ClickHouseExternalTable... more)
Sets one or more external tables.- Parameters:
table- non-null external tablemore- more external tables- Returns:
- the request itself
-
external
public SelfT external(Collection<ClickHouseExternalTable> tables)
Sets external tables.- Parameters:
tables- non-null external tables- Returns:
- the request itself
-
format
public SelfT format(ClickHouseFormat format)
Sets format to be used for communication between server and client.- Parameters:
format- preferred format,nullmeans reset to default- Returns:
- the request itself
-
manager
public SelfT manager(ClickHouseRequestManager manager)
Sets request manager which is responsible for generating query ID and session ID, as well as transaction creation.- Parameters:
manager- request manager- Returns:
- the request itself
-
option
public SelfT option(ClickHouseOption option, Serializable value)
Sets an option.optionis for configuring client's behaviour, whilesettingis for server.- Parameters:
option- optionvalue- value- Returns:
- the request itself
-
options
public SelfT options(Map<ClickHouseOption,Serializable> options)
Sets all options.optionis for configuring client's behaviour, whilesettingis for server.- Parameters:
options- options- Returns:
- the request itself
-
options
public SelfT options(Properties options)
Sets all options.optionis for configuring client's behaviour, whilesettingis for server.- Parameters:
options- options- Returns:
- the request itself
-
output
public SelfT output(ClickHouseFile file)
Sets output file, to which response will be redirected.- Parameters:
file- non-null output file- Returns:
- the request itself
-
output
public SelfT output(String file)
Sets output file, to which response will be redirected.- Parameters:
file- non-empty path to the file- Returns:
- the request itself
-
output
public SelfT output(String file, ClickHouseCompression compression)
Sets compressed output file, to which response will be redirected.- Parameters:
file- non-empty path to the filecompression- compression algorithm,nullorClickHouseCompression.NONEmeans no compression- Returns:
- the request itself
-
output
public SelfT output(OutputStream output)
Sets output stream, to which response will be redirected.- Parameters:
output- non-null output stream- Returns:
- the request itself
-
output
public SelfT output(ClickHouseOutputStream output)
Sets output stream, to which response will be redirected.- Parameters:
output- non-null output stream- Returns:
- the request itself
-
output
public SelfT output(ClickHouseDeferredValue<ClickHouseOutputStream> output)
Sets output stream, to which response will be redirected.- Parameters:
output- non-null output stream- Returns:
- the request itself
-
params
public SelfT params(Collection<String> values)
Sets stringified parameters. Be aware of SQL injection risk as mentioned inparams(String, String...).- Parameters:
values- stringified parameters- Returns:
- the request itself
-
params
public SelfT params(ClickHouseValue value, ClickHouseValue... more)
Sets parameters wrapped byClickHouseValue. Safer but a bit slower thanparams(String, String...). Consider to reuse ClickHouseValue object and its update methods for less overhead in batch processing.- Parameters:
value- parametermore- more parameters- Returns:
- the request itself
-
params
public SelfT params(ClickHouseValue[] values)
Sets parameters wrapped byClickHouseValue. Safer but a bit slower thanparams(String, String...). Consider to reuse ClickHouseValue object and its update methods for less overhead in batch processing.- Parameters:
values- parameters- Returns:
- the request itself
-
params
public SelfT params(String value, String... more)
Sets stringified parameters which are used to substitude named parameters in SQL query without further transformation and validation. Keep in mind that stringified parameter is a SQL expression, meaning it could be a sub-query(SQL injection) in addition to value like number and string.- Parameters:
value- stringified parametermore- more stringified parameters- Returns:
- the request itself
-
params
public SelfT params(String[] values)
Sets stringified parameters which are used to substitude named parameters in SQL query without further transformation and validation. Keep in mind that stringified parameter is a SQL expression, meaning it could be a sub-query(SQL injection) in addition to value like number and string.- Parameters:
values- stringified parameters- Returns:
- the request itself
-
params
public SelfT params(Object value, Object... more)
Set raw parameters, which will later be stringified usingClickHouseValues.convertToSqlExpression(Object). Although it is convenient to use, it's NOT recommended in most cases except for a few parameters and/or testing.- Parameters:
value- raw parametermore- more raw parameters- Returns:
- the request itself
-
params
public SelfT params(Object[] values)
Set raw parameters, which will later be stringified usingClickHouseValues.convertToSqlExpression(Object). Although it is convenient to use, it's NOT recommended in most cases except for a few parameters and/or testing.- Parameters:
values- raw parameters- Returns:
- the request itself
-
params
public SelfT params(Map<String,String> namedParams)
Sets named parameters. Be aware of SQL injection risk as mentioned inparams(String, String...).- Parameters:
namedParams- named parameters- Returns:
- the request itself
-
query
public SelfT query(ClickHouseParameterizedQuery query)
Sets parameterized query. Same asquery(query, null).- Parameters:
query- non-null parameterized query- Returns:
- the request itself
-
query
public SelfT query(String sql)
Sets query. Same asquery(sql, null).- Parameters:
sql- non-empty query- Returns:
- the request itself
-
query
public SelfT query(ClickHouseParameterizedQuery query, String queryId)
Sets parameterized query and optinally query id.- Parameters:
query- non-null parameterized queryqueryId- query id, null means no query id- Returns:
- the request itself
-
query
public SelfT query(String query, String queryId)
Sets query and optinally query id.- Parameters:
query- non-empty queryqueryId- query id, null means no query id- Returns:
- the request itself
-
settings
public SelfT settings(Map<String,Serializable> settings)
Sets all server settings.- Parameters:
settings- settings- Returns:
- the request itself
-
clearSession
public SelfT clearSession()
Clears session configuration including session id, session check(whether to validate the id), and session timeout. Transaction will be removed as well.- Returns:
- the request itself
-
session
public SelfT session(String sessionId)
Sets current session using custom id. Same assession(sessionId, null, null).- Parameters:
sessionId- session id, null means no session- Returns:
- the request itself
-
session
public SelfT session(String sessionId, Boolean check)
Sets session. Same assession(sessionId, check, null).- Parameters:
sessionId- session id, null means no sessioncheck- whether the server should check if the session id exists or not- Returns:
- the request itself
-
session
public SelfT session(String sessionId, Integer timeout)
Sets current session. Same assession(sessionId, null, timeout).- Parameters:
sessionId- session id, null means no sessiontimeout- timeout in seconds- Returns:
- the request itself
-
session
public SelfT session(String sessionId, Boolean check, Integer timeout)
Sets current session.- Parameters:
sessionId- session id, null means no sessioncheck- whether the server should check if the session id exists or nottimeout- timeout in seconds- Returns:
- the request itself
-
set
public SelfT set(String setting, Serializable value)
Sets a setting. See https://clickhouse.tech/docs/en/operations/settings/settings/ for more information.- Parameters:
setting- non-empty setting to setvalue- value of the setting- Returns:
- the request itself
-
set
public SelfT set(String setting, String value)
Sets a setting. See https://clickhouse.tech/docs/en/operations/settings/settings/ for more information.- Parameters:
setting- non-empty setting to setvalue- value of the setting- Returns:
- the request itself
-
setChangeListener
public final SelfT setChangeListener(ClickHouseConfigChangeListener<ClickHouseRequest<?>> listener)
Sets thread-safe change listener. Please keep in mind that the same listener might be shared by multiple requests.- Parameters:
listener- thread-safe change listener which may or may not be null- Returns:
- the request itself
-
setServerListener
public final SelfT setServerListener(BiConsumer<ClickHouseNode,ClickHouseNode> listener)
Sets thread-safe server change listener. Please keep in mind that the same listener might be shared by multiple requests.- Parameters:
listener- thread-safe server listener which may or may not be null- Returns:
- the request itself
-
table
public SelfT table(String table)
Sets target table. Same astable(table, null).- Parameters:
table- non-empty table name- Returns:
- the request itself
-
table
public SelfT table(String table, String queryId)
Sets target table and optionally query id. This will generate a query likeSELECT * FROM [table]and override the one set byquery(String, String).- Parameters:
table- non-empty table namequeryId- query id, null means no query id- Returns:
- the request itself
-
transaction
public SelfT transaction() throws ClickHouseException
Creates and starts a transaction. Same astransaction(0).- Returns:
- the request itself
- Throws:
ClickHouseException- when failed to start or reuse transaction
-
transaction
public SelfT transaction(int timeout) throws ClickHouseException
Creates and starts a transaction immediately. Please pay attention that unlike other methods in this class, it will connect to ClickHouse server, allocate session and start transaction right away.- Parameters:
timeout- transaction timeout in seconds, zero or negative means same as session timeout- Returns:
- the request itself
- Throws:
ClickHouseException- when failed to start or reuse transaction
-
transaction
public SelfT transaction(ClickHouseTransaction transaction) throws ClickHouseException
Sets transaction. Any existing transaction, regardless its state, will be replaced by the given one.- Parameters:
transaction- transaction- Returns:
- the request itself
- Throws:
ClickHouseException- when failed to set transaction
-
use
public SelfT use(String database)
Changes current database.- Parameters:
database- database name,nullmeans reset to default- Returns:
- the request itself
-
removeExternal
public SelfT removeExternal(ClickHouseExternalTable external)
Removes an external table.- Parameters:
external- non-null external table- Returns:
- the request itself
-
removeExternal
public SelfT removeExternal(String name)
Removes an external table by name.- Parameters:
name- non-empty external table name- Returns:
- the request itself
-
removeOption
public SelfT removeOption(ClickHouseOption option)
Removes an option.- Parameters:
option- option to be removed- Returns:
- the request itself
-
removeSetting
public SelfT removeSetting(String setting)
Removes a setting.- Parameters:
setting- name of the setting- Returns:
- the request itself
-
reset
public SelfT reset()
Resets the request to start all over.- Returns:
- the request itself
-
seal
public ClickHouseRequest<SelfT> seal()
Creates a sealed request, which is an immutable copy of the current request. Listeners won't be copied to the sealed instance, because it's immutable.- Returns:
- sealed request, an immutable copy of the current request
-
write
public ClickHouseRequest.Mutation write()
Creates a new request for mutation.- Returns:
- request for mutation
-
execute
public CompletableFuture<ClickHouseResponse> execute()
Executes the request. Same asclient.execute(request.seal()).- Returns:
- non-null future to get response
- Throws:
CompletionException- when error occurred during execution
-
executeAndWait
public ClickHouseResponse executeAndWait() throws ClickHouseException
Synchronous version ofexecute().- Returns:
- non-null response
- Throws:
ClickHouseException- when error occurred during execution
-
executeWithinTransaction
public ClickHouseResponse executeWithinTransaction() throws ClickHouseException
Executes the request within an implicit transaction. New transaction will be always created and started right before the query, and it will be committed or rolled back afterwards automatically.- Returns:
- non-null response
- Throws:
ClickHouseException- when error occurred during execution
-
executeWithinTransaction
@Deprecated public ClickHouseResponse executeWithinTransaction(boolean useImplicitTransaction) throws ClickHouseException
Deprecated.will be removed in the future, once the minimum supported version of ClickHouse is 22.7 or aboveExecutes the request within an implicit transaction. WhenuseImplicitTransactionis set totrue, it enforces the client to useimplicit_transactionsetting which is only available in ClickHouse 22.7+. Otherwise, new transaction will be always created and started right before the query, and it will be committed or rolled back afterwards automatically.- Parameters:
useImplicitTransaction-trueto use native implicit transaction requiring ClickHouse 22.7+ with minimum overhead(no session on server side and no additional objects on client side); false to use auto-commit transaction- Returns:
- non-null response
- Throws:
ClickHouseException- when error occurred during execution
-
-