Querying IMap
The following subsections describe how you can access Hazelcast map objects and perform queries on them.
Names
The SQL service exposes IMap
objects as tables in the predefined partitioned
schema using exact names. This schema is in the SQL service search path so that
you can access the IMap
objects with or without the schema name.
Schema and table names are case-sensitive; you can access the employee
map, for example,
as employee
or partitioned.employee
, but not as Employee
:
SELECT * FROM employee
SELECT * FROM partitioned.employee
Fields
The SQL service resolves fields accessible from the SQL automatically. The
service reads the first local entry pair of the IMap
to construct the
list of fields. If the IMap
does not have local entries on the member where
the query is started, then the list of fields cannot be resolved, and an
exception is thrown.
Field names are case-sensitive.
Key and Value Objects
An IMap
entry consists of a key and a value. These are accessible
through the __key
and this
aliases. The following query returns
the keys and values of all entries in a map:
SELECT __key, this FROM employee
Key and Value Fields
You may also access the nested fields of a key or a value. The list of exposed fields depends on the serialization format, as described below:
-
For Java objects (
Serializable
,DataSerializable
,IdentifiedDataSerializable
), the object is deserialized if needed and then analyzed using the reflection mechanism. Only public fields and getters are taken into account. A public field is exposed using its exact name. A getter is exposed using the JavaBean naming conventions. -
For
Portable
objects, the fields that are written in thePortable.writePortable
method are exposed using their exact names. -
For
HazelcastJsonValue
objects, see the Querying JSON Strings section.
Consider the Employee
class from the example above; the SQL service can access
the following fields:
Name |
Type |
|
|
|
|
Together with the key and value objects, you may query the following fields from
IMap<Long, Employee>
:
SELECT __key, this, name, age FROM employee
If both the key and value have fields with the same name, then the field of the value is exposed.
"SELECT *" Queries
You may use the SELECT * FROM <table>
syntax to get all the table fields.
The __key
and this
fields are returned by the SELECT *
queries if they do not
have nested fields. For IMap<Long, Employee>
, the following query does
not return the this
field, because the value has nested fields name
and age
:
-- Returns __key, name, age
SELECT * FROM employee
Indexes
The SQL service can use IMap
indexes to speed up the execution of certain queries.
SORTED
and HASH
indexes are supported.
See the Indexing Queries section for more information on IMap
index creation.
High-Density Memory Store
You can query the IMap
objects with InMemoryFormat.NATIVE
if they have
at least one index.
See Configuring with System Properties for more information on setting system properties.