use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class BetweenOperatorIntegrationTest method checkValues.
protected void checkValues(String sql, SqlColumnType expectedType, Object[] expectedResults, Object... params) {
List<SqlRow> rows = execute(sql, params);
assertEquals(expectedResults.length, rows.size());
if (rows.size() == 0) {
return;
}
if (rows.get(0).getObject(0) instanceof Integer) {
rows.sort(Comparator.comparingInt(a -> a.getObject(0)));
} else if (rows.get(0).getObject(0) instanceof Comparable) {
rows.sort((a, b) -> ((Comparable<?>) a.getObject(0)).compareTo(b.getObject(0)));
}
for (int i = 0; i < expectedResults.length; i++) {
SqlRow row = rows.get(i);
assertEquals(expectedType, row.getMetadata().getColumn(0).getType());
assertEquals(expectedResults[i], row.getObject(0));
}
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class IsNullPredicateIntegrationTest method keys.
private Set<Integer> keys(String sql, Object... params) {
List<SqlRow> rows = execute(sql, params);
if (rows.size() == 0) {
return Collections.emptySet();
}
assertEquals(1, rows.get(0).getMetadata().getColumnCount());
Set<Integer> keys = new HashSet<>();
for (SqlRow row : rows) {
int key = row.getObject(0);
boolean added = keys.add(key);
assertTrue("Key is not unique: " + key, added);
}
return keys;
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class RandFunctionIntegrationTest method testMultipleCallsInSingleQuery.
@Test
public void testMultipleCallsInSingleQuery() {
putAll(0, 1, 2, 3);
List<SqlRow> rows = execute("SELECT RAND(), RAND() FROM map");
assertEquals(4, rows.size());
Set<Double> values = new HashSet<>();
for (SqlRow row : rows) {
double value1 = row.getObject(0);
double value2 = row.getObject(1);
assertNotEquals(value1, value2);
values.add(value1);
}
assertTrue(values.size() > 1);
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class ExpressionTestSupport method checkValues0.
/**
* Execute a query, assert that it returns only 1 column and the values match the expectedResults array
* in any order. Assert the type and count of the results.
*
* @param sql the input query
* @param expectedType type of the returned value
* @param expectedResults expected result value. If it's {@link #SKIP_VALUE_CHECK},
* don't assert the value
* @param params query parameters
*/
protected void checkValues0(String sql, SqlColumnType expectedType, Object[] expectedResults, Object... params) {
List<SqlRow> rows = execute(sql, params);
int expectedResultCount = expectedResults.length;
assertEquals(expectedResultCount, rows.size());
Object[] values = new Object[expectedResultCount];
for (int i = 0; i < expectedResultCount; i++) {
SqlRow row = rows.get(i);
assertEquals(1, row.getMetadata().getColumnCount());
assertEquals(expectedType, row.getMetadata().getColumn(0).getType());
Object value = row.getObject(0);
values[i] = value;
}
assertThat(values).containsExactlyInAnyOrderElementsOf(Arrays.asList(expectedResults));
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class ExpressionTestSupport method checkValue0.
/**
* Execute a query, assert that it returns exactly 1 row and 1 column. Assert
* the type of the result and optionally the result value.
*
* @param sql the input query
* @param expectedType type of the returned value
* @param expectedResult expected result value. If it's {@link #SKIP_VALUE_CHECK},
* don't assert the value
* @param params query parameters
* @return the result value
*/
protected Object checkValue0(String sql, SqlColumnType expectedType, Object expectedResult, Object... params) {
List<SqlRow> rows = execute(sql, params);
assertEquals(1, rows.size());
SqlRow row = rows.get(0);
assertEquals(1, row.getMetadata().getColumnCount());
assertEquals(expectedType, row.getMetadata().getColumn(0).getType());
Object value = row.getObject(0);
if (expectedResult != SKIP_VALUE_CHECK) {
assertEquals(expectedResult, value);
}
return value;
}
Aggregations