Search in sources :

Example 21 with SqlRow

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());
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with SqlRow

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());
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with SqlRow

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);
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with SqlRow

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()));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with SqlRow

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");
    }
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) RunWith(org.junit.runner.RunWith) MAX_BACKUP_COUNT(com.hazelcast.internal.partition.IPartition.MAX_BACKUP_COUNT) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) IndexConfig(com.hazelcast.config.IndexConfig) Consumer(java.util.function.Consumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JetSplitBrainTestSupport(com.hazelcast.jet.core.JetSplitBrainTestSupport) Assert.fail(org.junit.Assert.fail) SqlRow(com.hazelcast.sql.SqlRow) IMap(com.hazelcast.map.IMap) SqlRow(com.hazelcast.sql.SqlRow) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMap(com.hazelcast.map.IMap) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

SqlRow (com.hazelcast.sql.SqlRow)65 Test (org.junit.Test)35 SqlResult (com.hazelcast.sql.SqlResult)29 QuickTest (com.hazelcast.test.annotation.QuickTest)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)17 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)13 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)11 ArrayList (java.util.ArrayList)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 SqlStatement (com.hazelcast.sql.SqlStatement)7 SqlService (com.hazelcast.sql.SqlService)5 HashSet (java.util.HashSet)5 SqlColumnType (com.hazelcast.sql.SqlColumnType)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 HazelcastException (com.hazelcast.core.HazelcastException)2 ExpressionBiValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)2 IMap (com.hazelcast.map.IMap)2 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)2