Search in sources :

Example 26 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class SqlClientCursorCleanupTest method testExceptionOnExecute.

@Test
public void testExceptionOnExecute() {
    IMap<Integer, Person> map = member.getMap(MAP_NAME);
    map.put(0, new Person());
    map.put(1, new Person());
    fail = true;
    try {
        SqlResult result = client.getSql().execute(statement());
        for (SqlRow ignore : result) {
        // No-op.
        }
        fail("Must fail");
    } catch (Exception e) {
        assertNoState();
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) IOException(java.io.IOException) Test(org.junit.Test)

Example 27 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class SqlIndexAbstractTest method sqlKeys.

private Set<Integer> sqlKeys(boolean withIndex, String sql, List<Object> params) {
    SqlStatement query = new SqlStatement(sql);
    if (!params.isEmpty()) {
        query.setParameters(params);
    }
    Set<Integer> keys = new HashSet<>();
    try (SqlResult result = instance().getSql().execute(query)) {
        for (SqlRow row : result) {
            keys.add(row.getObject(0));
        }
    }
    return keys;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SqlRow(com.hazelcast.sql.SqlRow) SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) HashSet(java.util.HashSet)

Example 28 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class SqlCompactTest method test_topLevelFieldExtraction.

@Test
public void test_topLevelFieldExtraction() {
    String name = randomName();
    sqlService.execute("CREATE MAPPING " + name + '(' + "id INT EXTERNAL NAME \"__key.id\" " + ", name VARCHAR" + " ) " + "TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_KEY_COMPACT_TYPE_NAME + "'='" + PERSON_ID_TYPE_NAME + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + PERSON_TYPE_NAME + '\'' + ")");
    clientSqlService.execute("SINK INTO " + name + " (id, name) VALUES (1, 'Alice')");
    Iterator<SqlRow> rowIterator = clientSqlService.execute("SELECT __key, this FROM " + name).iterator();
    SqlRow row = rowIterator.next();
    assertFalse(rowIterator.hasNext());
    assertEquals(GenericRecordBuilder.compact(PERSON_ID_TYPE_NAME).setNullableInt32("id", 1).build(), row.getObject(0));
    assertEquals(GenericRecordBuilder.compact(PERSON_TYPE_NAME).setString("name", "Alice").build(), row.getObject(1));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) Test(org.junit.Test)

Example 29 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class SqlCompactTest method test_writingToTopLevelWhileNestedFieldMapped_implicit.

@Test
public void test_writingToTopLevelWhileNestedFieldMapped_implicit() {
    String mapName = randomName();
    sqlService.execute("CREATE MAPPING " + mapName + "(" + "__key INT" + ", name VARCHAR" + ") TYPE " + IMapSqlConnector.TYPE_NAME + "\n" + "OPTIONS (\n" + '\'' + OPTION_KEY_FORMAT + "'='" + JAVA_FORMAT + "'\n" + ", '" + OPTION_KEY_CLASS + "'='" + Integer.class.getName() + "'\n" + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + "'\n" + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + PERSON_TYPE_NAME + "'\n" + ")");
    assertThatThrownBy(() -> sqlService.execute("SINK INTO " + mapName + "(__key, this) VALUES(1, null)").iterator().next()).hasMessageContaining("Writing to top-level fields of type OBJECT not supported");
    clientSqlService.execute("SINK INTO " + mapName + " VALUES (1, 'foo')");
    Iterator<SqlRow> resultIter = clientSqlService.execute("SELECT __key, this, name FROM " + mapName).iterator();
    SqlRow row = resultIter.next();
    assertEquals(1, (int) row.getObject(0));
    assertInstanceOf(GenericRecord.class, row.getObject(1));
    assertEquals("foo", row.getObject(2));
    assertFalse(resultIter.hasNext());
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) Test(org.junit.Test)

Example 30 with SqlRow

use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.

the class SqlPortableTest method test_topLevelFieldExtraction.

@Test
public void test_topLevelFieldExtraction() {
    String name = randomName();
    sqlService.execute("CREATE MAPPING " + name + ' ' + "TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='" + PORTABLE_FORMAT + '\'' + ", '" + OPTION_KEY_FACTORY_ID + "'='" + PERSON_ID_FACTORY_ID + '\'' + ", '" + OPTION_KEY_CLASS_ID + "'='" + PERSON_ID_CLASS_ID + '\'' + ", '" + OPTION_KEY_CLASS_VERSION + "'='" + PERSON_ID_CLASS_VERSION + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + PORTABLE_FORMAT + '\'' + ", '" + OPTION_VALUE_FACTORY_ID + "'='" + PERSON_FACTORY_ID + '\'' + ", '" + OPTION_VALUE_CLASS_ID + "'='" + PERSON_CLASS_ID + '\'' + ", '" + OPTION_VALUE_CLASS_VERSION + "'='" + PERSON_CLASS_VERSION + '\'' + ")");
    sqlService.execute("SINK INTO " + name + " (id, name) VALUES (1, 'Alice')");
    Iterator<SqlRow> rowIterator = sqlService.execute("SELECT __key, this FROM " + name).iterator();
    SqlRow row = rowIterator.next();
    assertFalse(rowIterator.hasNext());
    assertEquals(new PortableGenericRecordBuilder(personIdClassDefinition).setInt32("id", 1).build(), row.getObject(0));
    assertEquals(new PortableGenericRecordBuilder(personClassDefinition).setInt32("id", 0).setString("name", "Alice").build(), row.getObject(1));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) PortableGenericRecordBuilder(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecordBuilder) Test(org.junit.Test)

Aggregations

SqlRow (com.hazelcast.sql.SqlRow)65 Test (org.junit.Test)35 SqlResult (com.hazelcast.sql.SqlResult)29 QuickTest (com.hazelcast.test.annotation.QuickTest)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)17 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)13 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)11 ArrayList (java.util.ArrayList)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 SqlStatement (com.hazelcast.sql.SqlStatement)7 SqlService (com.hazelcast.sql.SqlService)5 HashSet (java.util.HashSet)5 SqlColumnType (com.hazelcast.sql.SqlColumnType)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 HazelcastException (com.hazelcast.core.HazelcastException)2 ExpressionBiValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)2 IMap (com.hazelcast.map.IMap)2 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)2