Hazelcast Node.js Client 4.2 is Released!

Hazelcast Node.js Client 4.2 is now available! In this post, you can find information on the main updates, including the brand-new SQL querying feature.

SQL Support

Node.js client now supports querying against the new, state-of-the-art SQL engine introduced in Hazelcast IMDG 4.1. With the new engine:

  • You can query with many new SQL expressions.
  • You can efficiently query large amounts of data.

SQL results are fetched page by page, keeping the client and server from using too much memory.

The new SQL feature is faster and more efficient than paging predicates, which execute the whole query for every request to a new page. Similar to paging predicates, the new SQL feature supports sorting via ORDER BY and pagination via LIMIT/OFFSET.

Keep in mind that SQL support is currently in beta, and the Node.js 4.2 client only supports Hazelcast IMDG 4.2.

Usage

A new SQL service that enables you to run SQL queries is added to the client. The execute method in the SQL service returns a SQL result that can be iterated over SQL rows. The iteration can be done easily using a for-await..of loop or with the next syntax.

You can configure the page size, timeout, schema, and expected result type of an SQL query.

Currently, the only supported SQL keyword is SELECT, but in the future, you can expect other operations; to do your CRUD operations using SQL.

Query parameter placeholders are specified with a question mark(?), the following is an example query string:

SELECT name, age FROM students WHERE age > ?

A value can be bound to question marks using query parameters.

Example

Suppose there are students in a map and we want to query the names of students who are older than 18. The query to do that is given below:

const result = client.getSqlService().execute('SELECT name FROM students WHERE age > ?', [18]);

for await (const row of result) {
    console.log(`Name: ${row['name']}`);
}

Another Example with ORDER BY and LIMIT

Suppose that this time we would like to find the names of the 3 eldest students in the map, sorted by their age. We will use the ORDER BY keyword and to make it work, we need to provide a SORTED index on the age property in the students map. Suppose there is a SORTED index in the map, then the query would be like this:

const result = client.getSqlService().execute('SELECT name FROM students ORDER BY age DESC LIMIT 3');

for await (const row of result) {
    console.log(`Name: ${row['name']}`);
}

The engine extracts columns from a key and a value and merges them into a single column set.

More on SQL

To learn the new SQL feature in detail, refer to Node.js client API documentation and SQL section of the Node.js client complete documentation and IMDG SQL documentation.

Bug Fixes and Enhancements

As always, this release includes bug fixes and enhancements. For the list of all changes, you can refer to the 4.2 release notes.

Closing words

Give our new SQL query feature a try and let us know your opinions. Don’t hesitate to reach out via Slack, Google Groups, or Twitter.