Search in sources :

Example 1 with SqlStatement

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);
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement)

Example 2 with SqlStatement

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");
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) Test(org.junit.Test)

Example 3 with SqlStatement

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

Example 4 with SqlStatement

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());
    }
}
Also used : JobSummary(com.hazelcast.jet.impl.JobSummary) JobSummary(com.hazelcast.jet.impl.JobSummary) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BeforeClass(org.junit.BeforeClass) QuickTest(com.hazelcast.test.annotation.QuickTest) JobConfig(com.hazelcast.jet.config.JobConfig) SqlStatement(com.hazelcast.sql.SqlStatement) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) TestBatchSqlConnector(com.hazelcast.jet.sql.impl.connector.test.TestBatchSqlConnector) Collectors(java.util.stream.Collectors) List(java.util.List) Future(java.util.concurrent.Future) Ignore(org.junit.Ignore) KEY_SQL_UNBOUNDED(com.hazelcast.jet.config.JobConfigArguments.KEY_SQL_UNBOUNDED) SqlResult(com.hazelcast.sql.SqlResult) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) JetClientInstanceImpl(com.hazelcast.jet.impl.JetClientInstanceImpl) JobStatus(com.hazelcast.jet.core.JobStatus) COMPLETED(com.hazelcast.jet.core.JobStatus.COMPLETED) KEY_SQL_QUERY_TEXT(com.hazelcast.jet.config.JobConfigArguments.KEY_SQL_QUERY_TEXT) Assert.assertEquals(org.junit.Assert.assertEquals) Job(com.hazelcast.jet.Job) SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with SqlStatement

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));
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) LocalTime(java.time.LocalTime) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) SqlStatement(com.hazelcast.sql.SqlStatement) OffsetDateTime(java.time.OffsetDateTime) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SqlStatement (com.hazelcast.sql.SqlStatement)29 SqlResult (com.hazelcast.sql.SqlResult)14 Test (org.junit.Test)11 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 SqlRow (com.hazelcast.sql.SqlRow)8 ArrayList (java.util.ArrayList)6 Job (com.hazelcast.jet.Job)3 JobConfig (com.hazelcast.jet.config.JobConfig)3 SqlService (com.hazelcast.sql.SqlService)3 SqlServiceImpl (com.hazelcast.sql.impl.SqlServiceImpl)3 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)3 HazelcastException (com.hazelcast.core.HazelcastException)2 ArrayDeque (java.util.ArrayDeque)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TimeoutException (java.util.concurrent.TimeoutException)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Data (com.hazelcast.internal.serialization.Data)1