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();
}
}
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;
}
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));
}
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());
}
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));
}
Aggregations