Search in sources :

Example 31 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlIndexConverterMismatchTest method testMismatch.

/**
 * @see MapIndexScanExecIterator#getIndexEntries
 */
@SuppressWarnings({ "StatementWithEmptyBody", "JavadocReference" })
@Ignore("https://github.com/hazelcast/hazelcast/issues/19287")
@Test
public void testMismatch() {
    ExpressionBiValue value1 = new ExpressionBiValue.IntegerIntegerVal();
    value1.field1(10);
    value1.field2(10);
    ExpressionBiValue value2 = new ExpressionBiValue.StringIntegerVal();
    value2.field1("10");
    value2.field2(10);
    map.put(getLocalKey(member1, key -> key), value1);
    map.put(getLocalKey(member2, key -> key), value2);
    try {
        try (SqlResult result = member1.getSql().execute("SELECT key FROM " + MAP_NAME + " WHERE field1=1")) {
            for (SqlRow ignore : result) {
            // No-op.
            }
        }
        fail("Must fail!");
    } catch (HazelcastSqlException e) {
        assertEquals(SqlErrorCode.INDEX_INVALID, e.getCode());
        Throwable ex = findRootQueryException(e);
        assertEquals("Cannot use the index \"index\" of the IMap \"map\" because it has component \"field1\" of type VARCHAR, but INTEGER was expected", ex.getMessage());
    }
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) ArrayList(java.util.ArrayList) MapConfig(com.hazelcast.config.MapConfig) IndexType(com.hazelcast.config.IndexType) MapIndexScanExecIterator(com.hazelcast.sql.impl.exec.scan.index.MapIndexScanExecIterator) After(org.junit.After) Assert.fail(org.junit.Assert.fail) SqlRow(com.hazelcast.sql.SqlRow) Parameterized(org.junit.runners.Parameterized) QueryException(com.hazelcast.sql.impl.QueryException) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Collection(java.util.Collection) HazelcastParallelParametersRunnerFactory(com.hazelcast.test.HazelcastParallelParametersRunnerFactory) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) IndexConfig(com.hazelcast.config.IndexConfig) List(java.util.List) Ignore(org.junit.Ignore) SqlResult(com.hazelcast.sql.SqlResult) SqlErrorCode(com.hazelcast.sql.impl.SqlErrorCode) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) Ignore(org.junit.Ignore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlClientCursorCleanupTest method testExceptionOnFetch.

@Test
public void testExceptionOnFetch() {
    IMap<Integer, Person> map = member.getMap(MAP_NAME);
    map.put(0, new Person());
    map.put(1, new Person());
    map.put(2, new Person());
    try {
        SqlResult result = client.getSql().execute(statement());
        for (SqlRow ignore : result) {
            fail = true;
        }
        fail("Must fail");
    } catch (Exception e) {
        assertNoState();
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) IOException(java.io.IOException) Test(org.junit.Test)

Example 33 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlNoDeserializationTest method testMember.

@Test
public void testMember() {
    try (SqlResult res = instance().getSql().execute(SQL)) {
        for (SqlRow row : res) {
            SqlRowImpl row0 = (SqlRowImpl) row;
            row0.getObjectRaw(0);
            row0.getObjectRaw(1);
            checkFailure(row, true);
            checkFailure(row, false);
        }
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlRowImpl(com.hazelcast.sql.impl.SqlRowImpl) SqlResult(com.hazelcast.sql.SqlResult) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlNoSerializationTest method check.

private void check(String sql, boolean expectedIndexUsage) {
    checkIndexUsage(new SqlStatement(sql), expectedIndexUsage);
    try (SqlResult res = instance().getSql().execute(sql)) {
        int count = 0;
        for (SqlRow row : res) {
            Object key = row.getObject(0);
            Object value = row.getObject(1);
            assertTrue(key instanceof Key);
            assertTrue(value instanceof Value);
            count++;
        }
        assertEquals(1, count);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult)

Example 35 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlSecurityCallbackTest method check.

private void check(String sql, boolean useIndex) {
    // Execute twice to make sure that permission is checked when the plan is cached.
    for (int i = 0; i < 2; i++) {
        TestSqlSecurityContext securityContext = new TestSqlSecurityContext();
        try (SqlResult ignored = ((SqlServiceImpl) instance().getSql()).execute(new SqlStatement(sql), securityContext)) {
            // Check whether the index is used as expected.
            checkIndexUsage(sql, useIndex);
            // Check permissions.
            assertThat(securityContext.getPermissions()).contains(new MapPermission(mapName, ActionConstants.ACTION_READ));
        }
    }
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) SqlServiceImpl(com.hazelcast.sql.impl.SqlServiceImpl) MapPermission(com.hazelcast.security.permission.MapPermission)

Aggregations

SqlResult (com.hazelcast.sql.SqlResult)60 Test (org.junit.Test)38 SqlRow (com.hazelcast.sql.SqlRow)31 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 SqlStatement (com.hazelcast.sql.SqlStatement)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ArrayList (java.util.ArrayList)9 Job (com.hazelcast.jet.Job)8 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)8 SqlService (com.hazelcast.sql.SqlService)8 JobConfig (com.hazelcast.jet.config.JobConfig)7 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)6 HashMap (java.util.HashMap)5 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 TimeoutException (java.util.concurrent.TimeoutException)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 IndexConfig (com.hazelcast.config.IndexConfig)3