Search in sources :

Example 1 with SqlOptimizer

use of com.hazelcast.sql.impl.optimizer.SqlOptimizer in project hazelcast by hazelcast.

the class SqlServiceImpl method createOptimizer.

/**
 * Create either normal or not-implemented optimizer instance.
 *
 * @param nodeEngine Node engine.
 * @return Optimizer.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private SqlOptimizer createOptimizer(NodeEngine nodeEngine, QueryResultRegistry resultRegistry) {
    // 1. Resolve class name.
    String className = System.getProperty(OPTIMIZER_CLASS_PROPERTY_NAME, SQL_MODULE_OPTIMIZER_CLASS);
    // 2. Get the class.
    Class clazz;
    try {
        clazz = Class.forName(className);
    } catch (ClassNotFoundException e) {
        logger.log(SQL_MODULE_OPTIMIZER_CLASS.equals(className) ? Level.FINE : Level.WARNING, "Optimizer class \"" + className + "\" not found, falling back to " + DisabledSqlOptimizer.class.getName());
        return new DisabledSqlOptimizer();
    } catch (Exception e) {
        throw new HazelcastException("Failed to resolve optimizer class " + className + ": " + e.getMessage(), e);
    }
    // 3. Get required constructor.
    Constructor<SqlOptimizer> constructor;
    try {
        constructor = clazz.getConstructor(NodeEngine.class, QueryResultRegistry.class);
    } catch (ReflectiveOperationException e) {
        throw new HazelcastException("Failed to get the constructor for the optimizer class " + className + ": " + e.getMessage(), e);
    }
    // 4. Finally, get the instance.
    try {
        return constructor.newInstance(nodeEngine, resultRegistry);
    } catch (ReflectiveOperationException e) {
        throw new HazelcastException("Failed to instantiate the optimizer class " + className + ": " + e.getMessage(), e);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) HazelcastException(com.hazelcast.core.HazelcastException) QueryResultRegistry(com.hazelcast.sql.impl.state.QueryResultRegistry) DisabledSqlOptimizer(com.hazelcast.sql.impl.optimizer.DisabledSqlOptimizer) DisabledSqlOptimizer(com.hazelcast.sql.impl.optimizer.DisabledSqlOptimizer) SqlOptimizer(com.hazelcast.sql.impl.optimizer.SqlOptimizer) HazelcastException(com.hazelcast.core.HazelcastException) AccessControlException(java.security.AccessControlException)

Example 2 with SqlOptimizer

use of com.hazelcast.sql.impl.optimizer.SqlOptimizer 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)

Aggregations

SqlOptimizer (com.hazelcast.sql.impl.optimizer.SqlOptimizer)2 HazelcastException (com.hazelcast.core.HazelcastException)1 NodeEngine (com.hazelcast.spi.impl.NodeEngine)1 SqlServiceImpl (com.hazelcast.sql.impl.SqlServiceImpl)1 DisabledSqlOptimizer (com.hazelcast.sql.impl.optimizer.DisabledSqlOptimizer)1 QueryResultRegistry (com.hazelcast.sql.impl.state.QueryResultRegistry)1 AccessControlException (java.security.AccessControlException)1 Test (org.junit.Test)1