Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
hazelcast::client::sql::sql_statement Class Reference

Definition of an SQL statement. More...

#include <sql_statement.h>

Public Member Functions

 sql_statement (hazelcast_client &client, std::string query)
 Creates a statement with the given query.
const std::string & sql () const
sql_statementsql (std::string sql_string)
 Sets the SQL string to be executed.
template<typename... Param>
sql_statementset_parameters (Param... params)
 Sets the values for statement parameters.
template<typename Param>
sql_statementadd_parameter (const Param &value)
 Adds a single parameter value to the end of the parameter values list.
sql_statementclear_parameters ()
 Clears statement parameter values.
int32_t cursor_buffer_size () const
 Gets the cursor buffer size (measured in the number of rows).
sql_statementcursor_buffer_size (int32_t size)
 Sets the cursor buffer size (measured in the number of rows).
std::chrono::milliseconds timeout () const
 Gets the execution timeout in milliseconds.
sql_statementtimeout (std::chrono::milliseconds timeout)
 Sets the execution timeout in milliseconds.
sql_expected_result_type expected_result_type () const
 Gets the expected result type.
sql_statementexpected_result_type (sql_expected_result_type type)
 Sets the expected result type.
std::shared_ptr< std::atomic< int32_t > > partition_argument_index () const
 Get the partition argument index value.
const boost::optional< std::string > & schema () const
 Gets the schema name.
sql_statementschema (boost::optional< std::string > schema)
 Sets the schema name.

Static Public Attributes

static constexpr std::chrono::milliseconds TIMEOUT_NOT_SET { -1 }
 Value for the timeout that is not set.
static constexpr std::chrono::milliseconds TIMEOUT_DISABLED { 0 }
 Value for the timeout that is disabled, meaning there's no time limit to run a query.
static constexpr std::chrono::milliseconds DEFAULT_TIMEOUT
 Default timeout.
static constexpr int32_t DEFAULT_CURSOR_BUFFER_SIZE = 4096
 Default cursor buffer size.

Detailed Description

Definition of an SQL statement.

This object is mutable. Properties are read once before the execution is started. Changes to properties do not affect the behavior of already running statements.

Definition at line 41 of file sql_statement.h.

Constructor & Destructor Documentation

◆ sql_statement()

hazelcast::client::sql::sql_statement::sql_statement ( hazelcast_client & client,
std::string query )

Creates a statement with the given query.

Parameters
clientThe hazelcast client to be used for the statement.
queryThe query string.

Definition at line 461 of file sql.cpp.

462 : serialized_parameters_{}
463 , cursor_buffer_size_{ DEFAULT_CURSOR_BUFFER_SIZE }
464 , timeout_{ TIMEOUT_NOT_SET }
465 , expected_result_type_{ sql_expected_result_type::any }
466 , schema_{}
467 , partition_argument_index_{ std::make_shared<std::atomic<int32_t>>(-1) }
468 , serialization_service_(
469 spi::ClientContext(client).get_serialization_service())
470{
471 sql(std::move(query));
472}
static constexpr int32_t DEFAULT_CURSOR_BUFFER_SIZE
Default cursor buffer size.
const std::string & sql() const
Definition sql.cpp:488
static constexpr std::chrono::milliseconds TIMEOUT_NOT_SET
Value for the timeout that is not set.

Member Function Documentation

◆ add_parameter()

template<typename Param>
sql_statement & hazelcast::client::sql::sql_statement::add_parameter ( const Param & value)

Adds a single parameter value to the end of the parameter values list.

Parameters
valueparameter value
Returns
this instance for chaining
See also
set_parameters()
clear_parameters()

Definition at line 262 of file sql_statement.h.

263{
264 serialized_parameters_.emplace_back(serialization_service_.to_data(param));
265
266 return *this;
267}

◆ clear_parameters()

sql_statement & hazelcast::client::sql::sql_statement::clear_parameters ( )

Clears statement parameter values.

Returns
this instance for chaining
See also
set_parameters()
template<typename Param> add_parameter(const Param& value)

Definition at line 504 of file sql.cpp.

505{
506 serialized_parameters_.clear();
507
508 return *this;
509}

◆ cursor_buffer_size() [1/2]

int32_t hazelcast::client::sql::sql_statement::cursor_buffer_size ( ) const

Gets the cursor buffer size (measured in the number of rows).

Returns
cursor buffer size (measured in the number of rows)

Definition at line 512 of file sql.cpp.

513{
514 return cursor_buffer_size_;
515}

◆ cursor_buffer_size() [2/2]

sql_statement & hazelcast::client::sql::sql_statement::cursor_buffer_size ( int32_t size)

Sets the cursor buffer size (measured in the number of rows).

When a statement is submitted for execution, a sql_result is returned as a result. When rows are ready to be consumed, they are put into an internal buffer of the cursor. This parameter defines the maximum number of rows in that buffer. When the threshold is reached, the backpressure mechanism will slow down the execution, possibly to a complete halt, to prevent out-of-memory.

Only positive values are allowed.

The default value is expected to work well for most workloads. A bigger buffer size may give you a slight performance boost for queries with large result sets at the cost of increased memory consumption.

Defaults to sql_statement::DEFAULT_CURSOR_BUFFER_SIZE.

Parameters
sizecursor buffer size (measured in the number of rows)
Returns
this instance for chaining
See also
hazelcast::client::sql::sql_service::execute(const sql_statement& statement)
hazelcast::client::sql::sql_result

Definition at line 518 of file sql.cpp.

519{
520 util::Preconditions::check_positive(
521 size,
522 (boost::format("Cursor buffer size must be positive: %s") % size).str());
523 cursor_buffer_size_ = size;
524
525 return *this;
526}

◆ expected_result_type() [1/2]

sql::sql_expected_result_type hazelcast::client::sql::sql_statement::expected_result_type ( ) const

Gets the expected result type.

Returns
expected result type

Definition at line 565 of file sql.cpp.

566{
567 return expected_result_type_;
568}

◆ expected_result_type() [2/2]

sql_statement & hazelcast::client::sql::sql_statement::expected_result_type ( sql_expected_result_type type)

Sets the expected result type.

Parameters
typeexpected result type
Returns
this instance for chaining

◆ partition_argument_index()

std::shared_ptr< std::atomic< int32_t > > hazelcast::client::sql::sql_statement::partition_argument_index ( ) const

Get the partition argument index value.

Returns
partition argument index, -1 if not set.

Definition at line 578 of file sql.cpp.

579{
580 return partition_argument_index_;
581}

◆ schema() [1/2]

const boost::optional< std::string > & hazelcast::client::sql::sql_statement::schema ( ) const

Gets the schema name.

Returns
the schema name or
boost::none
if there is none

Definition at line 552 of file sql.cpp.

553{
554 return schema_;
555}

◆ schema() [2/2]

sql_statement & hazelcast::client::sql::sql_statement::schema ( boost::optional< std::string > schema)

Sets the schema name.

The engine will try to resolve the non-qualified object identifiers from the statement in the given schema. If not found, the default search path will be used, which looks for objects in the predefined schemas

"partitioned"

and

"public"

.

The schema name is case sensitive. For example,

"foo"

and

"Foo"

are different schemas.

The default value is

boost::none

meaning only the default search path is used.

Parameters
schemathe current schema name
Returns
this instance for chaining

Definition at line 558 of file sql.cpp.

559{
560 schema_ = std::move(schema);
561 return *this;
562}
const boost::optional< std::string > & schema() const
Gets the schema name.
Definition sql.cpp:552

◆ set_parameters()

template<typename... Param>
sql_statement & hazelcast::client::sql::sql_statement::set_parameters ( Param... params)

Sets the values for statement parameters.

You may define parameter placeholders in the statement with the
"?"
character. For every placeholder, a value must be provided.

When the method is called, the contents of the list are copied. Subsequent changes to the original list don't change the statement parameters.

Parameters
valuethe first statement parameter
other_paramsthe other statement parameters if exist
Returns
this instance for chaining
See also
template<typename Param> add_parameter(const Param& value)
clear_parameters()

Definition at line 271 of file sql_statement.h.

272{
273 int _[] = { 0, ((void)add_parameter(params), 0)... };
274 (void)_;
275 return *this;
276}
sql_statement & add_parameter(const Param &value)
Adds a single parameter value to the end of the parameter values list.

◆ sql() [1/2]

const std::string & hazelcast::client::sql::sql_statement::sql ( ) const
Returns
The sql string to be executed

Definition at line 488 of file sql.cpp.

489{
490 return sql_;
491}

◆ sql() [2/2]

sql_statement & hazelcast::client::sql::sql_statement::sql ( std::string sql_string)

Sets the SQL string to be executed.

The SQL string cannot be empty.

Parameters
sql_stringSQL string
Returns
this instance for chaining
Exceptions
hazelcast::client::exception::illegal_argumentif passed SQL string is empty

Definition at line 494 of file sql.cpp.

495{
496 util::Preconditions::check_not_empty(sql_string, "SQL cannot be empty");
497
498 sql_ = std::move(sql_string);
499
500 return *this;
501}

◆ timeout() [1/2]

std::chrono::milliseconds hazelcast::client::sql::sql_statement::timeout ( ) const

Gets the execution timeout in milliseconds.

Returns
execution timeout in milliseconds

Definition at line 529 of file sql.cpp.

530{
531 return timeout_;
532}

◆ timeout() [2/2]

sql_statement & hazelcast::client::sql::sql_statement::timeout ( std::chrono::milliseconds timeout)

Sets the execution timeout in milliseconds.

If the timeout is reached for a running statement, it will be cancelled forcefully.

Zero value means no timeout. sql_statement::TIMEOUT_NOT_SET means that the value from sql_config::statement_timeout() will be used. Other negative values are prohibited.

Defaults to sql_statement::TIMEOUT_NOT_SET .

Parameters
timeoutexecution timeout in milliseconds, \c0 for no timeout, -1 to user member's default timeout
Returns
this instance for chaining
See also
sql_config::statement_timeout()

Definition at line 535 of file sql.cpp.

536{
537 auto timeout_msecs = timeout.count();
538 if (timeout_msecs < 0 && timeout != TIMEOUT_NOT_SET) {
539 throw exception::illegal_argument(
540 "sql_statement::timeout(std::chrono::milliseconds timeout)",
541 (boost::format("Timeout must be non-negative or -1: %1% msecs") %
542 timeout_msecs)
543 .str());
544 }
545
546 timeout_ = timeout;
547
548 return *this;
549}
std::chrono::milliseconds timeout() const
Gets the execution timeout in milliseconds.
Definition sql.cpp:529

Member Data Documentation

◆ DEFAULT_CURSOR_BUFFER_SIZE

int32_t hazelcast::client::sql::sql_statement::DEFAULT_CURSOR_BUFFER_SIZE = 4096
staticconstexpr

Default cursor buffer size.

Definition at line 61 of file sql_statement.h.

◆ DEFAULT_TIMEOUT

std::chrono::milliseconds hazelcast::client::sql::sql_statement::DEFAULT_TIMEOUT
staticconstexpr
Initial value:

Default timeout.

Definition at line 57 of file sql_statement.h.

◆ TIMEOUT_DISABLED

std::chrono::milliseconds hazelcast::client::sql::sql_statement::TIMEOUT_DISABLED { 0 }
staticconstexpr

Value for the timeout that is disabled, meaning there's no time limit to run a query.

Definition at line 54 of file sql_statement.h.

54{ 0 };

◆ TIMEOUT_NOT_SET

std::chrono::milliseconds hazelcast::client::sql::sql_statement::TIMEOUT_NOT_SET { -1 }
staticconstexpr

Value for the timeout that is not set.

The value of sql_config::statement_timeout_millis will be used.

Definition at line 48 of file sql_statement.h.

48{ -1 };

The documentation for this class was generated from the following files: