Search in sources :

Example 1 with DruidSchema

use of io.druid.sql.calcite.schema.DruidSchema in project druid by druid-io.

the class CalciteQueryTest method getResults.

private List<Object[]> getResults(final PlannerContext plannerContext, final String sql) throws Exception {
    final PlannerConfig plannerConfig = plannerContext.getPlannerConfig();
    final DruidSchema druidSchema = CalciteTests.createMockSchema(walker, plannerConfig);
    final SchemaPlus rootSchema = Calcites.createRootSchema(druidSchema);
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    final PlannerFactory plannerFactory = new PlannerFactory(rootSchema, walker, operatorTable, plannerConfig);
    try (DruidPlanner planner = plannerFactory.createPlanner(plannerContext.getQueryContext())) {
        final PlannerResult plan = planner.plan(sql);
        return Sequences.toList(plan.run(), Lists.<Object[]>newArrayList());
    }
}
Also used : PlannerConfig(io.druid.sql.calcite.planner.PlannerConfig) DruidPlanner(io.druid.sql.calcite.planner.DruidPlanner) DruidSchema(io.druid.sql.calcite.schema.DruidSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus) PlannerFactory(io.druid.sql.calcite.planner.PlannerFactory) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) PlannerResult(io.druid.sql.calcite.planner.PlannerResult)

Example 2 with DruidSchema

use of io.druid.sql.calcite.schema.DruidSchema in project druid by druid-io.

the class CalciteTests method createMockSchema.

public static DruidSchema createMockSchema(final SpecificSegmentsQuerySegmentWalker walker, final PlannerConfig plannerConfig) {
    final DruidSchema schema = new DruidSchema(walker, new TestServerInventoryView(walker.getSegments()), plannerConfig);
    schema.start();
    try {
        schema.awaitInitialization();
    } catch (InterruptedException e) {
        throw Throwables.propagate(e);
    }
    schema.stop();
    return schema;
}
Also used : DruidSchema(io.druid.sql.calcite.schema.DruidSchema)

Aggregations

DruidSchema (io.druid.sql.calcite.schema.DruidSchema)2 DruidOperatorTable (io.druid.sql.calcite.planner.DruidOperatorTable)1 DruidPlanner (io.druid.sql.calcite.planner.DruidPlanner)1 PlannerConfig (io.druid.sql.calcite.planner.PlannerConfig)1 PlannerFactory (io.druid.sql.calcite.planner.PlannerFactory)1 PlannerResult (io.druid.sql.calcite.planner.PlannerResult)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1