Search in sources :

Example 1 with SqlLifecycleFactory

use of org.apache.druid.sql.SqlLifecycleFactory in project druid by druid-io.

the class BaseCalciteQueryTest method analyzeResources.

public Set<ResourceAction> analyzeResources(PlannerConfig plannerConfig, String sql, AuthenticationResult authenticationResult) {
    SqlLifecycleFactory lifecycleFactory = getSqlLifecycleFactory(plannerConfig, createOperatorTable(), createMacroTable(), CalciteTests.TEST_AUTHORIZER_MAPPER, queryJsonMapper);
    SqlLifecycle lifecycle = lifecycleFactory.factorize();
    lifecycle.initialize(sql, ImmutableMap.of());
    return lifecycle.runAnalyzeResources(authenticationResult).getResourceActions();
}
Also used : SqlLifecycle(org.apache.druid.sql.SqlLifecycle) SqlLifecycleFactory(org.apache.druid.sql.SqlLifecycleFactory)

Example 2 with SqlLifecycleFactory

use of org.apache.druid.sql.SqlLifecycleFactory in project druid by druid-io.

the class SqlResourceTest method setUp.

@Before
public void setUp() throws Exception {
    final QueryScheduler scheduler = new QueryScheduler(5, ManualQueryPrioritizationStrategy.INSTANCE, new HiLoQueryLaningStrategy(40), new ServerConfig()) {

        @Override
        public <T> Sequence<T> run(Query<?> query, Sequence<T> resultSequence) {
            return super.run(query, new LazySequence<T>(() -> {
                if (sleep) {
                    try {
                        // pretend to be a query that is waiting on results
                        Thread.sleep(500);
                    } catch (InterruptedException ignored) {
                    }
                }
                return resultSequence;
            }));
        }
    };
    executorService = MoreExecutors.listeningDecorator(Execs.multiThreaded(8, "test_sql_resource_%s"));
    walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder(), scheduler);
    final PlannerConfig plannerConfig = new PlannerConfig() {

        @Override
        public boolean shouldSerializeComplexValues() {
            return false;
        }
    };
    final DruidSchemaCatalog rootSchema = CalciteTests.createMockRootSchema(conglomerate, walker, plannerConfig, CalciteTests.TEST_AUTHORIZER_MAPPER);
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    final ExprMacroTable macroTable = CalciteTests.createExprMacroTable();
    req = EasyMock.createStrictMock(HttpServletRequest.class);
    EasyMock.expect(req.getRemoteAddr()).andReturn(null).once();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(CalciteTests.REGULAR_USER_AUTH_RESULT).anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(CalciteTests.REGULAR_USER_AUTH_RESULT).anyTimes();
    req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true);
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(CalciteTests.REGULAR_USER_AUTH_RESULT).anyTimes();
    EasyMock.replay(req);
    testRequestLogger = new TestRequestLogger();
    final PlannerFactory plannerFactory = new PlannerFactory(rootSchema, CalciteTests.createMockQueryMakerFactory(walker, conglomerate), operatorTable, macroTable, plannerConfig, CalciteTests.TEST_AUTHORIZER_MAPPER, CalciteTests.getJsonMapper(), CalciteTests.DRUID_SCHEMA_NAME);
    lifecycleManager = new SqlLifecycleManager() {

        @Override
        public void add(String sqlQueryId, SqlLifecycle lifecycle) {
            super.add(sqlQueryId, lifecycle);
            if (lifecycleAddLatch != null) {
                lifecycleAddLatch.countDown();
            }
        }
    };
    final ServiceEmitter emitter = new NoopServiceEmitter();
    sqlLifecycleFactory = new SqlLifecycleFactory(plannerFactory, emitter, testRequestLogger, scheduler) {

        @Override
        public SqlLifecycle factorize() {
            return new TestSqlLifecycle(plannerFactory, emitter, testRequestLogger, scheduler, System.currentTimeMillis(), System.nanoTime(), validateAndAuthorizeLatchSupplier, planLatchSupplier, executeLatchSupplier, sequenceMapFnSupplier);
        }
    };
    resource = new SqlResource(JSON_MAPPER, CalciteTests.TEST_AUTHORIZER_MAPPER, sqlLifecycleFactory, lifecycleManager, new ServerConfig());
}
Also used : SqlLifecycleManager(org.apache.druid.sql.SqlLifecycleManager) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) QueryScheduler(org.apache.druid.server.QueryScheduler) BaseQuery(org.apache.druid.query.BaseQuery) Query(org.apache.druid.query.Query) HiLoQueryLaningStrategy(org.apache.druid.server.scheduling.HiLoQueryLaningStrategy) SqlLifecycle(org.apache.druid.sql.SqlLifecycle) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Sequence(org.apache.druid.java.util.common.guava.Sequence) LazySequence(org.apache.druid.java.util.common.guava.LazySequence) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) DruidOperatorTable(org.apache.druid.sql.calcite.planner.DruidOperatorTable) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) TestRequestLogger(org.apache.druid.server.log.TestRequestLogger) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfig(org.apache.druid.server.initialization.ServerConfig) PlannerConfig(org.apache.druid.sql.calcite.planner.PlannerConfig) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) PlannerFactory(org.apache.druid.sql.calcite.planner.PlannerFactory) SqlLifecycleFactory(org.apache.druid.sql.SqlLifecycleFactory) Before(org.junit.Before)

Example 3 with SqlLifecycleFactory

use of org.apache.druid.sql.SqlLifecycleFactory in project druid by druid-io.

the class BaseCalciteQueryTest method getSqlLifecycleFactory.

public SqlLifecycleFactory getSqlLifecycleFactory(PlannerConfig plannerConfig, DruidOperatorTable operatorTable, ExprMacroTable macroTable, AuthorizerMapper authorizerMapper, ObjectMapper objectMapper) {
    final InProcessViewManager viewManager = new InProcessViewManager(CalciteTests.DRUID_VIEW_MACRO_FACTORY);
    DruidSchemaCatalog rootSchema = CalciteTests.createMockRootSchema(conglomerate, walker, plannerConfig, viewManager, new NoopDruidSchemaManager(), authorizerMapper);
    final PlannerFactory plannerFactory = new PlannerFactory(rootSchema, new TestQueryMakerFactory(CalciteTests.createMockQueryLifecycleFactory(walker, conglomerate), objectMapper), operatorTable, macroTable, plannerConfig, authorizerMapper, objectMapper, CalciteTests.DRUID_SCHEMA_NAME);
    final SqlLifecycleFactory sqlLifecycleFactory = CalciteTests.createSqlLifecycleFactory(plannerFactory);
    viewManager.createView(plannerFactory, "aview", "SELECT SUBSTRING(dim1, 1, 1) AS dim1_firstchar FROM foo WHERE dim2 = 'a'");
    viewManager.createView(plannerFactory, "bview", "SELECT COUNT(*) FROM druid.foo\n" + "WHERE __time >= CURRENT_TIMESTAMP + INTERVAL '1' DAY AND __time < TIMESTAMP '2002-01-01 00:00:00'");
    viewManager.createView(plannerFactory, "cview", "SELECT SUBSTRING(bar.dim1, 1, 1) AS dim1_firstchar, bar.dim2 as dim2, dnf.l2 as l2\n" + "FROM (SELECT * from foo WHERE dim2 = 'a') as bar INNER JOIN druid.numfoo dnf ON bar.dim2 = dnf.dim2");
    viewManager.createView(plannerFactory, "dview", "SELECT SUBSTRING(dim1, 1, 1) AS numfoo FROM foo WHERE dim2 = 'a'");
    viewManager.createView(plannerFactory, "forbiddenView", "SELECT __time, SUBSTRING(dim1, 1, 1) AS dim1_firstchar, dim2 FROM foo WHERE dim2 = 'a'");
    viewManager.createView(plannerFactory, "restrictedView", "SELECT __time, dim1, dim2, m1 FROM druid.forbiddenDatasource WHERE dim2 = 'a'");
    viewManager.createView(plannerFactory, "invalidView", "SELECT __time, dim1, dim2, m1 FROM druid.invalidDatasource WHERE dim2 = 'a'");
    return sqlLifecycleFactory;
}
Also used : NoopDruidSchemaManager(org.apache.druid.sql.calcite.schema.NoopDruidSchemaManager) InProcessViewManager(org.apache.druid.sql.calcite.view.InProcessViewManager) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) PlannerFactory(org.apache.druid.sql.calcite.planner.PlannerFactory) SqlLifecycleFactory(org.apache.druid.sql.SqlLifecycleFactory)

Aggregations

SqlLifecycleFactory (org.apache.druid.sql.SqlLifecycleFactory)3 SqlLifecycle (org.apache.druid.sql.SqlLifecycle)2 PlannerFactory (org.apache.druid.sql.calcite.planner.PlannerFactory)2 DruidSchemaCatalog (org.apache.druid.sql.calcite.schema.DruidSchemaCatalog)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LazySequence (org.apache.druid.java.util.common.guava.LazySequence)1 Sequence (org.apache.druid.java.util.common.guava.Sequence)1 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)1 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)1 BaseQuery (org.apache.druid.query.BaseQuery)1 Query (org.apache.druid.query.Query)1 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)1 QueryScheduler (org.apache.druid.server.QueryScheduler)1 ServerConfig (org.apache.druid.server.initialization.ServerConfig)1 TestRequestLogger (org.apache.druid.server.log.TestRequestLogger)1 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)1 HiLoQueryLaningStrategy (org.apache.druid.server.scheduling.HiLoQueryLaningStrategy)1 SqlLifecycleManager (org.apache.druid.sql.SqlLifecycleManager)1 DruidOperatorTable (org.apache.druid.sql.calcite.planner.DruidOperatorTable)1 PlannerConfig (org.apache.druid.sql.calcite.planner.PlannerConfig)1