use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlErrorAbstractTest method checkTimeout.
protected void checkTimeout(boolean useClient) {
// Start two instances and fill them with data
instance1 = newHazelcastInstance(false);
instance2 = newHazelcastInstance(true);
client = newClient();
// Execute query on the instance1.
SqlStatement query = new SqlStatement("select v from table(generate_stream(1))").setTimeoutMillis(1L);
HazelcastSqlException error = assertSqlException(useClient ? client : instance1, query);
assertTrue(error.getMessage().contains("CANCEL_FORCEFUL"));
}
use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlErrorTest method testMemberLeaveDuringQueryAfterImmediateShutdown.
@Test
public void testMemberLeaveDuringQueryAfterImmediateShutdown() {
// Start two instances
instance1 = newHazelcastInstance(false);
instance2 = newHazelcastInstance(true);
SqlStatement streamingQuery = new SqlStatement("SELECT * FROM TABLE(GENERATE_STREAM(1000))");
// Start query with immediate shutdown afterwards
HazelcastSqlException error = assertSqlExceptionWithShutdown(instance1, streamingQuery);
assertInstanceOf(HazelcastInstanceNotActiveException.class, findRootCause(error));
}
use of com.hazelcast.sql.SqlStatement 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.SqlStatement in project hazelcast by hazelcast.
the class SqlIndexCastTest method checkComparison.
private void checkComparison(ExpressionType<?> typeFrom, QueryDataTypeFamily typeTo, boolean expectedIndexUsage) {
String sql = "SELECT field1 FROM " + MAP_NAME + " WHERE CAST(field1 AS " + typeTo + ") = CAST(? as " + typeTo + ")";
SqlStatement statement = new SqlStatement(sql).addParameter(null);
checkIndexUsage(statement, typeFrom, expectedIndexUsage);
}
use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlIndexResolutionTest method checkIndexUsage.
private void checkIndexUsage(IMap<?, ?> map, boolean firstResolved, boolean secondResolved) {
String field1Literal = toLiteral(type1, type1.valueFrom());
String field2Literal = toLiteral(type2, type2.valueFrom());
// The second component could be used if both components are resolved.
Usage expectedUsage;
if (firstResolved) {
if (secondResolved) {
// Both components were resolved
expectedUsage = Usage.BOTH;
} else {
// Only one component is resolved
if (composite && indexType == IndexType.HASH) {
// Composite HASH index with the first component only cannot be used, because it requires range requests
expectedUsage = Usage.NONE;
} else {
// Otherwise, used the first component
expectedUsage = Usage.ONE;
}
}
} else {
// No components were resolved
expectedUsage = Usage.NONE;
}
SqlStatement sql = new SqlStatement("SELECT * FROM " + map.getName() + " WHERE field1=" + field1Literal + " AND field2=" + field2Literal);
checkIndexUsage(sql, map.getName(), expectedUsage);
}
Aggregations