use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlPrimitiveTest method assertTopicEventually.
private static void assertTopicEventually(String name, String sql, List<Object> arguments, Map<Integer, String> expected) {
SqlStatement statement = new SqlStatement(sql);
arguments.forEach(statement::addParameter);
sqlService.execute(statement);
kafkaTestSupport.assertTopicContentsEventually(name, expected, false);
}
use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlLimitTest method limitWithNegativeDynamicParameter.
@Test
public void limitWithNegativeDynamicParameter() {
SqlStatement statement = new SqlStatement("SELECT * FROM TABLE(GENERATE_STREAM(5)) LIMIT ?");
statement.setParameters(singletonList(-1));
assertThatThrownBy(() -> sqlService.execute(statement).iterator().next()).isInstanceOf(HazelcastSqlException.class).hasMessageContaining("LIMIT value cannot be negative");
}
use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlMetadataInJobConfigTest method test_selectMetadata_client.
@Test
public void test_selectMetadata_client() {
String sql = "SELECT * FROM table(generate_stream(1))";
try (SqlResult ignored = client().getSql().execute(new SqlStatement(sql).setCursorBufferSize(1))) {
List<Job> runningJobs = getJobsByStatus(RUNNING);
assertEquals(1, runningJobs.size());
JobConfig config = runningJobs.get(0).getConfig();
assertEquals(sql, config.getArgument(KEY_SQL_QUERY_TEXT));
assertEquals(Boolean.TRUE, config.getArgument(KEY_SQL_UNBOUNDED));
}
}
use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlMetadataInJobConfigTest method test_selectMetadata_clientJobSummary.
@Test
public void test_selectMetadata_clientJobSummary() {
String sql = "SELECT * FROM table(generate_stream(1))";
try (SqlResult ignored = client().getSql().execute(new SqlStatement(sql).setCursorBufferSize(1))) {
List<JobSummary> jobSummaries = ((JetClientInstanceImpl) client().getJet()).getJobSummaryList().stream().filter(jobSummary -> jobSummary.getStatus() == RUNNING).collect(Collectors.toList());
assertEquals(1, jobSummaries.size());
JobSummary jobSummary = jobSummaries.get(0);
// TODO uncomment this when doing https://github.com/hazelcast/hazelcast/issues/20372
// assertNotNull(jobSummary.getSqlSummary());
// assertEquals(sql, jobSummary.getSqlSummary().getQuery());
// assertEquals(Boolean.TRUE, jobSummary.getSqlSummary().isUnbounded());
}
}
use of com.hazelcast.sql.SqlStatement in project hazelcast by hazelcast.
the class SqlParameterTest method testParameters.
@Test
public void testParameters() {
boolean valBoolean = true;
byte valByte = 1;
short valShort = 2;
int valInt = 3;
long valLong = 4;
float valFloat = 5;
double valDouble = 6;
BigDecimal valDecimal = BigDecimal.valueOf(7);
String valString = "str";
LocalDate valLocalDate = LocalDate.now();
LocalTime valLocalTime = LocalTime.now();
LocalDateTime valLocalDateTime = LocalDateTime.now();
OffsetDateTime valOffsetDateTime = OffsetDateTime.now();
CustomObject valObject = new CustomObject(1);
SqlStatement statement = new SqlStatement("SELECT " + "CAST(? as BOOLEAN), " + "CAST(? as TINYINT), " + "CAST(? as SMALLINT), " + "CAST(? as INTEGER), " + "CAST(? as BIGINT), " + "CAST(? as REAL), " + "CAST(? as DOUBLE), " + "CAST(? as DECIMAL), " + "CAST(? as VARCHAR), " + "CAST(? as DATE), " + "CAST(? as TIME), " + "CAST(? as TIMESTAMP), " + "CAST(? as TIMESTAMP WITH TIME ZONE), " + "CAST(? as OBJECT), " + "CAST(? as OBJECT) " + "FROM " + MAP_NAME);
statement.addParameter(valBoolean);
statement.addParameter(valByte);
statement.addParameter(valShort);
statement.addParameter(valInt);
statement.addParameter(valLong);
statement.addParameter(valFloat);
statement.addParameter(valDouble);
statement.addParameter(valDecimal);
statement.addParameter(valString);
statement.addParameter(valLocalDate);
statement.addParameter(valLocalTime);
statement.addParameter(valLocalDateTime);
statement.addParameter(valOffsetDateTime);
statement.addParameter(valObject);
statement.addParameter(null);
try (SqlResult res = targetInstance().getSql().execute(statement)) {
for (SqlRow row : res) {
assertEquals(valBoolean, row.getObject(0));
assertEquals(valByte, (byte) row.getObject(1));
assertEquals(valShort, (short) row.getObject(2));
assertEquals(valInt, (int) row.getObject(3));
assertEquals(valLong, (long) row.getObject(4));
assertEquals(valFloat, row.getObject(5), 0f);
assertEquals(valDouble, row.getObject(6), 0d);
assertEquals(valDecimal, row.getObject(7));
assertEquals(valString, row.getObject(8));
assertEquals(valLocalDate, row.getObject(9));
assertEquals(valLocalTime, row.getObject(10));
assertEquals(valLocalDateTime, row.getObject(11));
assertEquals(valOffsetDateTime, row.getObject(12));
assertEquals(valObject, row.getObject(13));
assertNull(row.getObject(14));
}
}
}
Aggregations