![]() |
Hazelcast C++ Client
Hazelcast C++ Client Library
|
A service to execute SQL statements. More...
#include <sql_service.h>
Public Member Functions | |
template<typename... Params> | |
boost::future< std::shared_ptr< sql_result > > | execute (const std::string &query, const Params &... params) |
Convenient method to execute a distributed query with the given parameter values. More... | |
boost::future< std::shared_ptr< sql_result > > | execute (const sql_statement &statement) |
Executes an SQL statement. More... | |
A service to execute SQL statements.
In order to use the service, Jet engine must be enabled on the server side - SQL statements are executed as Jet jobs. On members, the
must be on the classpath, otherwise an exception will be thrown; on client, it is not necessary.
Hazelcast is currently able to execute distributed SQL queries using the following connectors:
When an SQL statement is submitted to a member, it is parsed and optimized hazelcast-sql module, that is based on Apache Calcite. During optimization a statement is converted into a directed acyclic graph (DAG) that is sent to cluster members for execution. Results are sent back to the originating member asynchronously and returned to the user via sql_result.
SQL statements are not atomic. INSERT/SINK can fail and commit part of the data.
Before you can access any object using SQL, a mapping has to be created. See the reference manual for the CREATE MAPPING command.
When a query is executed, an sql_result is returned. You may get row iterator from the result. The result must be closed at the end. The code snippet below demonstrates a typical usage pattern:
auto hz = hazelcast::new_client().get(); try { // Get the SQL service from the client and execute a query auto result = hz.get_sql().execute("SELECT * FROM person").get(); for (auto it = result.page_iterator(); it; (++it).get()) { // iterate over the rows in the page for (auto const &row : (*it).rows()) { auto person_id = row.get<int64_t>("personId"); auto name = row.get<std::string>("name"); ... } } // Close the result when done. result.close().get(); } catch (hazelcast::client::exception &e) { std::cerr << "Query failed: " << e.what() << std::endl; }
Definition at line 88 of file sql_service.h.
boost::future< std::shared_ptr< sql_result > > hazelcast::client::sql::sql_service::execute | ( | const sql_statement & | statement | ) |
Executes an SQL statement.
statement | statement to be executed |
hazelcast_sql_exception | in case of execution error |
Definition at line 57 of file sql.cpp.
|
inline |
Convenient method to execute a distributed query with the given parameter values.
Converts passed SQL string and parameter values into an sql_statement object and invokes execute(const sql_statement& statement).
sql | SQL string |
arguments | query parameter values that will be passed to sql_statement::add_parameter(const Param& param) |
illegal_argument | if the SQL string is empty |
hazelcast_sql_exception | in case of execution error |
Definition at line 110 of file sql_service.h.