use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlInsertWindowBoundsTest method test_windowBoundsSameTypeAsDescriptor_INT.
@Test
public void test_windowBoundsSameTypeAsDescriptor_INT() {
String name = randomName();
TestStreamSqlConnector.create(sqlService, name, asList("ts", "name"), asList(INTEGER, VARCHAR), row(1, "Alice"), row(10, null));
String interval = "1";
final SqlRow row = instance().getSql().execute(sql(name, interval)).iterator().next();
final SqlRowMetadata metadata = row.getMetadata();
assertThat(metadata.getColumn(0).getType()).isEqualTo(SqlColumnType.INTEGER);
assertThat((Object) row.getObject(0)).isInstanceOf(SqlColumnType.INTEGER.getValueClass());
assertThat(metadata.getColumn(1).getType()).isEqualTo(SqlColumnType.INTEGER);
assertThat((Object) row.getObject(1)).isInstanceOf(SqlColumnType.INTEGER.getValueClass());
assertThat(metadata.getColumn(2).getType()).isEqualTo(SqlColumnType.INTEGER);
assertThat((Object) row.getObject(2)).isInstanceOf(SqlColumnType.INTEGER.getValueClass());
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlInsertWindowBoundsTest method test_windowBoundsSameTypeAsDescriptor_DATE.
@Test
public void test_windowBoundsSameTypeAsDescriptor_DATE() {
String name = randomName();
TestStreamSqlConnector.create(sqlService, name, asList("ts", "name"), asList(DATE, VARCHAR), row(LocalDate.of(1970, 1, 1).toString(), "Alice"), row(LocalDate.of(1970, 1, 5).toString(), null));
String interval = "INTERVAL '1' DAY";
final SqlRow row = instance().getSql().execute(sql(name, interval)).iterator().next();
final SqlRowMetadata metadata = row.getMetadata();
assertThat(metadata.getColumn(0).getType()).isEqualTo(SqlColumnType.DATE);
assertThat((Object) row.getObject(0)).isInstanceOf(SqlColumnType.DATE.getValueClass());
assertThat(metadata.getColumn(1).getType()).isEqualTo(SqlColumnType.DATE);
assertThat((Object) row.getObject(1)).isInstanceOf(SqlColumnType.DATE.getValueClass());
assertThat(metadata.getColumn(2).getType()).isEqualTo(SqlColumnType.DATE);
assertThat((Object) row.getObject(2)).isInstanceOf(SqlColumnType.DATE.getValueClass());
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlInsertWindowBoundsTest method test_windowBoundsSameTypeAsDescriptor_TIMESTAMP_TZ.
@Test
public void test_windowBoundsSameTypeAsDescriptor_TIMESTAMP_TZ() {
String name = randomName();
TestStreamSqlConnector.create(sqlService, name, asList("ts", "name"), asList(TIMESTAMP_WITH_TIME_ZONE, VARCHAR), row(timestampTz(0L).toString(), "Alice"), row(timestampTz(10L).toString(), null));
String interval = "INTERVAL '0.001' SECOND";
final SqlRow row = instance().getSql().execute(sql(name, interval)).iterator().next();
final SqlRowMetadata metadata = row.getMetadata();
Class<?> valueClass = SqlColumnType.TIMESTAMP_WITH_TIME_ZONE.getValueClass();
assertThat(metadata.getColumn(0).getType()).isEqualTo(SqlColumnType.TIMESTAMP_WITH_TIME_ZONE);
assertThat((Object) row.getObject(0)).isInstanceOf(valueClass);
assertThat(metadata.getColumn(1).getType()).isEqualTo(SqlColumnType.TIMESTAMP_WITH_TIME_ZONE);
assertThat((Object) row.getObject(1)).isInstanceOf(valueClass);
assertThat(metadata.getColumn(2).getType()).isEqualTo(SqlColumnType.TIMESTAMP_WITH_TIME_ZONE);
assertThat((Object) row.getObject(2)).isInstanceOf(valueClass);
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlResultImplTest method when_closed_then_iteratorFails.
@Test
public // test for https://github.com/hazelcast/hazelcast-jet/issues/2697
void when_closed_then_iteratorFails() {
SqlResult sqlResult = instance().getSql().execute("select * from table(generate_stream(1))");
sqlResult.close();
Iterator<SqlRow> iterator = sqlResult.iterator();
assertThatThrownBy(() -> iterator.forEachRemaining(ConsumerEx.noop()));
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlSplitBrainTest method test_indexScan.
@Test
public // test for https://github.com/hazelcast/hazelcast/issues/19472
void test_indexScan() throws InterruptedException {
Thread[] threads = new Thread[2];
AtomicBoolean done = new AtomicBoolean();
AtomicInteger numQueries = new AtomicInteger();
Consumer<HazelcastInstance[]> beforeSplit = instances -> {
IMap<Integer, Integer> m = instances[0].getMap("m");
for (int i = 0; i < 10_000; i++) {
m.put(i, i);
}
m.addIndex(new IndexConfig().addAttribute("this"));
SqlTestSupport.createMapping(instances[0], "m", Integer.class, Integer.class);
for (int i = 0, threadsLength = threads.length; i < threadsLength; i++) {
HazelcastInstance inst = createHazelcastClient();
threads[i] = new Thread(() -> {
int numQueriesLocal = 0;
while (!done.get()) {
try {
// noinspection StatementWithEmptyBody
for (SqlRow ignored : inst.getSql().execute("select * from m where this>100 and this<1000")) {
// do nothing
}
} catch (Throwable e) {
logger.info(e);
}
numQueriesLocal++;
}
numQueries.addAndGet(numQueriesLocal);
});
threads[i].start();
sleepSeconds(1);
}
};
testSplitBrain(1, 1, beforeSplit, null, null);
done.set(true);
boolean stuck = false;
for (Thread t : threads) {
t.join(5000);
if (t.isAlive()) {
logger.info("thread " + t + " stuck");
stuck = true;
}
}
logger.info("num queries executed: " + numQueries.get());
if (stuck) {
fail("some threads were stuck");
}
}
Aggregations