SQL

❗️

This is a legacy Apache Ignite documentation

The new documentation is hosted here: https://ignite.apache.org/docs/latest/

SQL has 2 kinds of queries:

  • Data Definition Language statements to manage caches and indices. Visit Ignite DDL for more information.
  • Data Manipulation Language statements to manage data. Visit Ignite DML for more information.

You can use thin client SQL API in the following ways:

  • IgniteClient#query(SqlFieldsQuery).getAll() to execute a non-SELECT statement (DDL or DML).
  • IgniteClient#query(SqlFieldsQuery) to execute a SELECT statement and get subset of the fields.

The SQL SELECT query returns results in pages so that only one page is loaded in the client's memory.

client.query(
    new SqlFieldsQuery(String.format(
        "CREATE TABLE IF NOT EXISTS Person (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"",
        Person.class.getName()
    )).setSchema("PUBLIC")
).getAll();

int key = 1;
Person val = new Person(key, "Person 1");

client.query(new SqlFieldsQuery(
    "INSERT INTO Person(id, name) VALUES(?, ?)"
).setArgs(val.getId(), val.getName()).setSchema("PUBLIC")).getAll();

Object cachedName = client.query(
    new SqlFieldsQuery("SELECT name from Person WHERE id=?").setArgs(key).setSchema("PUBLIC")
).getAll().iterator().next().iterator().next();

assertEquals(val.getName(), cachedName);