Search in sources :

Example 1 with SqlServiceImpl

use of com.hazelcast.sql.impl.SqlServiceImpl in project hazelcast by hazelcast.

the class SqlSchemaPropagationTest method check.

private void check(HazelcastInstance target) {
    // Set the wrapped optimizer to track optimization requests.
    SqlServiceImpl service = (SqlServiceImpl) instance().getSql();
    // Execute the query from the target without schema.
    SqlStatement statement = new SqlStatement("SELECT __key FROM map");
    List<SqlRow> rows = executeStatement(target, statement);
    assertEquals(1, rows.size());
    assertEquals(1, (int) rows.get(0).getObject(0));
    assertEquals(1, service.getPlanCache().size());
    List<List<String>> originalSearchPaths = Iterables.getOnlyElement(extractSearchPaths());
    // Execute the query from the target with schema.
    statement.setSchema(SCHEMA_NAME);
    rows = executeStatement(target, statement);
    assertEquals(1, rows.size());
    assertEquals(1, (int) rows.get(0).getObject(0));
    assertEquals(2, service.getPlanCache().size());
    List<List<List<String>>> searchPaths = extractSearchPaths();
    List<List<String>> expectedSearchPaths = new ArrayList<>(originalSearchPaths);
    expectedSearchPaths.add(0, asList(CATALOG, SCHEMA_NAME));
    assertThat(searchPaths).containsExactlyInAnyOrder(originalSearchPaths, expectedSearchPaths);
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlStatement(com.hazelcast.sql.SqlStatement) SqlServiceImpl(com.hazelcast.sql.impl.SqlServiceImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Arrays.asList(java.util.Arrays.asList)

Example 2 with SqlServiceImpl

use of com.hazelcast.sql.impl.SqlServiceImpl in project hazelcast by hazelcast.

the class OptimizerInstantiationTest method testCreate.

@Test
public void testCreate() {
    SqlServiceImpl service = ((HazelcastInstanceProxy) instance()).getOriginal().node.getNodeEngine().getSqlService();
    SqlOptimizer optimizer = service.getOptimizer();
    assertNotNull(optimizer);
    assertEquals(CalciteSqlOptimizer.class, optimizer.getClass());
}
Also used : SqlServiceImpl(com.hazelcast.sql.impl.SqlServiceImpl) SqlOptimizer(com.hazelcast.sql.impl.optimizer.SqlOptimizer) Test(org.junit.Test)

Example 3 with SqlServiceImpl

use of com.hazelcast.sql.impl.SqlServiceImpl in project hazelcast by hazelcast.

the class SqlClientCursorCleanupTest method assertNoState.

private void assertNoState() {
    SqlInternalService service = ((SqlServiceImpl) member.getSql()).getInternalService();
    assertEquals(0, service.getResultRegistry().getResultCount());
    assertEquals(0, service.getClientStateRegistry().getCursorCount());
}
Also used : SqlServiceImpl(com.hazelcast.sql.impl.SqlServiceImpl) SqlInternalService(com.hazelcast.sql.impl.SqlInternalService)

Example 4 with SqlServiceImpl

use of com.hazelcast.sql.impl.SqlServiceImpl in project hazelcast by hazelcast.

the class PhoneHomeTest method testSqlQueriesSubmitted.

@Test
public void testSqlQueriesSubmitted() {
    Map<String, String> parameters = phoneHome.phoneHome(true);
    assertEquals(parameters.get(PhoneHomeMetrics.SQL_QUERIES_SUBMITTED.getRequestParameterName()), "0");
    SqlServiceImpl sqlService = node.getNodeEngine().getSqlService();
    try {
        sqlService.execute("SELECT * FROM map");
    } catch (Exception e) {
        ignore(e);
    }
    parameters = phoneHome.phoneHome(true);
    assertEquals(parameters.get(PhoneHomeMetrics.SQL_QUERIES_SUBMITTED.getRequestParameterName()), "1");
}
Also used : SqlServiceImpl(com.hazelcast.sql.impl.SqlServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with SqlServiceImpl

use of com.hazelcast.sql.impl.SqlServiceImpl 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

SqlServiceImpl (com.hazelcast.sql.impl.SqlServiceImpl)7 SqlStatement (com.hazelcast.sql.SqlStatement)3 Test (org.junit.Test)2 Data (com.hazelcast.internal.serialization.Data)1 MapPermission (com.hazelcast.security.permission.MapPermission)1 SqlResult (com.hazelcast.sql.SqlResult)1 SqlRow (com.hazelcast.sql.SqlRow)1 AbstractSqlResult (com.hazelcast.sql.impl.AbstractSqlResult)1 SqlInternalService (com.hazelcast.sql.impl.SqlInternalService)1 SqlOptimizer (com.hazelcast.sql.impl.optimizer.SqlOptimizer)1 NoOpSqlSecurityContext (com.hazelcast.sql.impl.security.NoOpSqlSecurityContext)1 SqlSecurityContext (com.hazelcast.sql.impl.security.SqlSecurityContext)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1