public interface SqlService
In order to use the service, Jet engine must be enabled - SQL statements are executed as
Jet jobs. On members, the hazelcast-sql.jar
must be on the classpath, otherwise
an exception will be thrown; on client, it is not necessary.
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 SqlResult
.
SQL statements are not atomic. INSERT/SINK can fail and commit part of the data.
When a query is executed, an SqlResult
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:
HazelcastInstance instance = ...; try (SqlResult result = instance.sql().execute("SELECT * FROM person")) { for (SqlRow row : result) { long personId = row.getObject("personId"); String name = row.getObject("name"); ... } }
Modifier and Type | Method and Description |
---|---|
SqlResult |
execute(SqlStatement statement)
Executes an SQL statement.
|
default SqlResult |
execute(String sql,
Object... arguments)
Convenient method to execute a distributed query with the given
parameter values.
|
@Nonnull default SqlResult execute(@Nonnull String sql, Object... arguments)
Converts passed SQL string and parameter values into an SqlStatement
object and invokes execute(SqlStatement)
.
sql
- SQL stringarguments
- query parameter values that will be passed to SqlStatement.setParameters(List)
NullPointerException
- if the SQL string is nullIllegalArgumentException
- if the SQL string is emptyHazelcastSqlException
- in case of execution errorSqlService
,
SqlStatement
,
execute(SqlStatement)
@Nonnull SqlResult execute(@Nonnull SqlStatement statement)
statement
- statement to be executedNullPointerException
- if the statement is nullHazelcastSqlException
- in case of execution errorSqlService
Copyright © 2021 Hazelcast, Inc.. All rights reserved.