Search in sources :

Example 1 with DruidOperatorTable

use of io.druid.sql.calcite.planner.DruidOperatorTable in project druid by druid-io.

the class DruidAvaticaHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    Calcites.setSystemProperties();
    walker = CalciteTests.createMockWalker(temporaryFolder.newFolder());
    final PlannerConfig plannerConfig = new PlannerConfig();
    final SchemaPlus rootSchema = Calcites.createRootSchema(CalciteTests.createMockSchema(walker, plannerConfig));
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    final DruidAvaticaHandler handler = new DruidAvaticaHandler(new DruidMeta(new PlannerFactory(rootSchema, walker, operatorTable, plannerConfig), AVATICA_CONFIG), new DruidNode("dummy", "dummy", 1), new AvaticaMonitor());
    final int port = new Random().nextInt(9999) + 10000;
    server = new Server(new InetSocketAddress("127.0.0.1", port));
    server.setHandler(handler);
    server.start();
    final String url = String.format("jdbc:avatica:remote:url=http://127.0.0.1:%d%s", port, DruidAvaticaHandler.AVATICA_PATH);
    client = DriverManager.getConnection(url);
    final Properties propertiesLosAngeles = new Properties();
    propertiesLosAngeles.setProperty("sqlTimeZone", "America/Los_Angeles");
    clientLosAngeles = DriverManager.getConnection(url, propertiesLosAngeles);
}
Also used : Server(org.eclipse.jetty.server.Server) InetSocketAddress(java.net.InetSocketAddress) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Properties(java.util.Properties) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) Random(java.util.Random) PlannerConfig(io.druid.sql.calcite.planner.PlannerConfig) PlannerFactory(io.druid.sql.calcite.planner.PlannerFactory) DruidNode(io.druid.server.DruidNode) Before(org.junit.Before)

Example 2 with DruidOperatorTable

use of io.druid.sql.calcite.planner.DruidOperatorTable in project druid by druid-io.

the class DruidStatementTest method setUp.

@Before
public void setUp() throws Exception {
    Calcites.setSystemProperties();
    walker = CalciteTests.createMockWalker(temporaryFolder.newFolder());
    final PlannerConfig plannerConfig = new PlannerConfig();
    final SchemaPlus rootSchema = Calcites.createRootSchema(CalciteTests.createMockSchema(walker, plannerConfig));
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    plannerFactory = new PlannerFactory(rootSchema, walker, operatorTable, plannerConfig);
}
Also used : PlannerConfig(io.druid.sql.calcite.planner.PlannerConfig) SchemaPlus(org.apache.calcite.schema.SchemaPlus) PlannerFactory(io.druid.sql.calcite.planner.PlannerFactory) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) Before(org.junit.Before)

Example 3 with DruidOperatorTable

use of io.druid.sql.calcite.planner.DruidOperatorTable 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 4 with DruidOperatorTable

use of io.druid.sql.calcite.planner.DruidOperatorTable in project druid by druid-io.

the class CalciteTests method createOperatorTable.

public static DruidOperatorTable createOperatorTable() {
    try {
        final Injector injector = Guice.createInjector(new Module() {

            @Override
            public void configure(final Binder binder) {
                // This Module is just to get a LookupReferencesManager with a usable "lookyloo" lookup.
                final LookupReferencesManager mock = EasyMock.createMock(LookupReferencesManager.class);
                EasyMock.expect(mock.get(EasyMock.eq("lookyloo"))).andReturn(new LookupExtractorFactory() {

                    @Override
                    public boolean start() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public boolean close() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public boolean replaces(@Nullable final LookupExtractorFactory other) {
                        throw new UnsupportedOperationException();
                    }

                    @Nullable
                    @Override
                    public LookupIntrospectHandler getIntrospectHandler() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public LookupExtractor get() {
                        return new MapLookupExtractor(ImmutableMap.of("a", "xa", "abc", "xabc"), false);
                    }
                }).anyTimes();
                EasyMock.replay(mock);
                binder.bind(LookupReferencesManager.class).toInstance(mock);
            }
        });
        final Set<SqlAggregator> aggregators = new HashSet<>();
        final Set<SqlExtractionOperator> extractionOperators = new HashSet<>();
        for (Class<? extends SqlAggregator> clazz : SqlModule.DEFAULT_AGGREGATOR_CLASSES) {
            aggregators.add(injector.getInstance(clazz));
        }
        for (Class<? extends SqlExtractionOperator> clazz : SqlModule.DEFAULT_EXTRACTION_OPERATOR_CLASSES) {
            extractionOperators.add(injector.getInstance(clazz));
        }
        return new DruidOperatorTable(aggregators, extractionOperators);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : LookupExtractorFactory(io.druid.query.lookup.LookupExtractorFactory) LookupReferencesManager(io.druid.query.lookup.LookupReferencesManager) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) LookupExtractor(io.druid.query.lookup.LookupExtractor) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) LookupIntrospectHandler(io.druid.query.lookup.LookupIntrospectHandler) Binder(com.google.inject.Binder) SqlExtractionOperator(io.druid.sql.calcite.expression.SqlExtractionOperator) Injector(com.google.inject.Injector) SqlAggregator(io.druid.sql.calcite.aggregation.SqlAggregator) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) Module(com.google.inject.Module) SqlModule(io.druid.sql.guice.SqlModule) Nullable(javax.annotation.Nullable) HashSet(java.util.HashSet)

Example 5 with DruidOperatorTable

use of io.druid.sql.calcite.planner.DruidOperatorTable in project druid by druid-io.

the class SqlResourceTest method setUp.

@Before
public void setUp() throws Exception {
    Calcites.setSystemProperties();
    walker = CalciteTests.createMockWalker(temporaryFolder.newFolder());
    final PlannerConfig plannerConfig = new PlannerConfig();
    final SchemaPlus rootSchema = Calcites.createRootSchema(CalciteTests.createMockSchema(walker, plannerConfig));
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    resource = new SqlResource(JSON_MAPPER, new PlannerFactory(rootSchema, walker, operatorTable, plannerConfig));
}
Also used : PlannerConfig(io.druid.sql.calcite.planner.PlannerConfig) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SqlResource(io.druid.sql.http.SqlResource) PlannerFactory(io.druid.sql.calcite.planner.PlannerFactory) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) Before(org.junit.Before)

Aggregations

DruidOperatorTable (io.druid.sql.calcite.planner.DruidOperatorTable)6 PlannerConfig (io.druid.sql.calcite.planner.PlannerConfig)5 PlannerFactory (io.druid.sql.calcite.planner.PlannerFactory)5 SchemaPlus (org.apache.calcite.schema.SchemaPlus)5 Before (org.junit.Before)4 Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)1 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)1 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)1 FilteredAggregatorFactory (io.druid.query.aggregation.FilteredAggregatorFactory)1 ApproximateHistogramAggregatorFactory (io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory)1 ApproximateHistogramDruidModule (io.druid.query.aggregation.histogram.ApproximateHistogramDruidModule)1 ApproximateHistogramFoldingAggregatorFactory (io.druid.query.aggregation.histogram.ApproximateHistogramFoldingAggregatorFactory)1 MapLookupExtractor (io.druid.query.extraction.MapLookupExtractor)1 LookupExtractor (io.druid.query.lookup.LookupExtractor)1 LookupExtractorFactory (io.druid.query.lookup.LookupExtractorFactory)1 LookupIntrospectHandler (io.druid.query.lookup.LookupIntrospectHandler)1 LookupReferencesManager (io.druid.query.lookup.LookupReferencesManager)1