Search in sources :

Example 21 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus 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)

Example 22 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project druid by druid-io.

the class QuantileSqlAggregatorTest method setUp.

@Before
public void setUp() throws Exception {
    Calcites.setSystemProperties();
    // Note: this is needed in order to properly register the serde for Histogram.
    new ApproximateHistogramDruidModule().configure(null);
    final QueryableIndex index = IndexBuilder.create().tmpDir(temporaryFolder.newFolder()).indexMerger(TestHelper.getTestIndexMergerV9()).schema(new IncrementalIndexSchema.Builder().withMetrics(new AggregatorFactory[] { new CountAggregatorFactory("cnt"), new DoubleSumAggregatorFactory("m1", "m1"), new ApproximateHistogramAggregatorFactory("hist_m1", "m1", null, null, null, null) }).withRollup(false).build()).rows(CalciteTests.ROWS1).buildMMappedIndex();
    walker = new SpecificSegmentsQuerySegmentWalker(CalciteTests.queryRunnerFactoryConglomerate()).add(DataSegment.builder().dataSource(DATA_SOURCE).interval(index.getDataInterval()).version("1").shardSpec(new LinearShardSpec(0)).build(), index);
    final PlannerConfig plannerConfig = new PlannerConfig();
    final SchemaPlus rootSchema = Calcites.createRootSchema(CalciteTests.createMockSchema(walker, plannerConfig));
    final DruidOperatorTable operatorTable = new DruidOperatorTable(ImmutableSet.<SqlAggregator>of(new QuantileSqlAggregator()), ImmutableSet.<SqlExtractionOperator>of());
    plannerFactory = new PlannerFactory(rootSchema, walker, operatorTable, plannerConfig);
}
Also used : DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) ApproximateHistogramDruidModule(io.druid.query.aggregation.histogram.ApproximateHistogramDruidModule) LinearShardSpec(io.druid.timeline.partition.LinearShardSpec) IndexBuilder(io.druid.segment.IndexBuilder) SchemaPlus(org.apache.calcite.schema.SchemaPlus) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) ApproximateHistogramFoldingAggregatorFactory(io.druid.query.aggregation.histogram.ApproximateHistogramFoldingAggregatorFactory) FilteredAggregatorFactory(io.druid.query.aggregation.FilteredAggregatorFactory) ApproximateHistogramAggregatorFactory(io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory) DoubleSumAggregatorFactory(io.druid.query.aggregation.DoubleSumAggregatorFactory) DruidOperatorTable(io.druid.sql.calcite.planner.DruidOperatorTable) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) SpecificSegmentsQuerySegmentWalker(io.druid.sql.calcite.util.SpecificSegmentsQuerySegmentWalker) QueryableIndex(io.druid.segment.QueryableIndex) PlannerConfig(io.druid.sql.calcite.planner.PlannerConfig) PlannerFactory(io.druid.sql.calcite.planner.PlannerFactory) ApproximateHistogramAggregatorFactory(io.druid.query.aggregation.histogram.ApproximateHistogramAggregatorFactory) Before(org.junit.Before)

Example 23 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class PlanningBase method testSqlPlan.

protected void testSqlPlan(String sqlCommands) throws Exception {
    final String[] sqlStrings = sqlCommands.split(";");
    final LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(config);
    provider.start();
    final ScanResult scanResult = ClassPathScanner.fromPrescan(config);
    final LogicalPlanPersistence logicalPlanPersistence = new LogicalPlanPersistence(config, scanResult);
    final SystemOptionManager systemOptions = new SystemOptionManager(logicalPlanPersistence, provider);
    systemOptions.init();
    @SuppressWarnings("resource") final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(systemOptions).build();
    final SessionOptionManager sessionOptions = (SessionOptionManager) userSession.getOptions();
    final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions);
    final ExecutionControls executionControls = new ExecutionControls(queryOptions, DrillbitEndpoint.getDefaultInstance());
    new NonStrictExpectations() {

        {
            dbContext.getMetrics();
            result = new MetricRegistry();
            dbContext.getAllocator();
            result = allocator;
            dbContext.getConfig();
            result = config;
            dbContext.getOptionManager();
            result = systemOptions;
            dbContext.getStoreProvider();
            result = provider;
            dbContext.getClasspathScan();
            result = scanResult;
            dbContext.getLpPersistence();
            result = logicalPlanPersistence;
        }
    };
    final StoragePluginRegistry registry = new StoragePluginRegistryImpl(dbContext);
    registry.init();
    final FunctionImplementationRegistry functionRegistry = new FunctionImplementationRegistry(config);
    final DrillOperatorTable table = new DrillOperatorTable(functionRegistry, systemOptions);
    final SchemaPlus root = SimpleCalciteSchema.createRootSchema(false);
    registry.getSchemaFactory().registerSchemas(SchemaConfig.newBuilder("foo", context).build(), root);
    new NonStrictExpectations() {

        {
            context.getNewDefaultSchema();
            result = root;
            context.getLpPersistence();
            result = new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config));
            context.getStorage();
            result = registry;
            context.getFunctionRegistry();
            result = functionRegistry;
            context.getSession();
            result = UserSession.Builder.newBuilder().setSupportComplexTypes(true).build();
            context.getCurrentEndpoint();
            result = DrillbitEndpoint.getDefaultInstance();
            context.getActiveEndpoints();
            result = ImmutableList.of(DrillbitEndpoint.getDefaultInstance());
            context.getPlannerSettings();
            result = new PlannerSettings(queryOptions, functionRegistry);
            context.getOptions();
            result = queryOptions;
            context.getConfig();
            result = config;
            context.getDrillOperatorTable();
            result = table;
            context.getAllocator();
            result = allocator;
            context.getExecutionControls();
            result = executionControls;
            dbContext.getLpPersistence();
            result = logicalPlanPersistence;
        }
    };
    for (final String sql : sqlStrings) {
        if (sql.trim().isEmpty()) {
            continue;
        }
        @SuppressWarnings("unused") final PhysicalPlan p = DrillSqlWorker.getPlan(context, sql);
    }
}
Also used : SessionOptionManager(org.apache.drill.exec.server.options.SessionOptionManager) StoragePluginRegistry(org.apache.drill.exec.store.StoragePluginRegistry) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) LocalPersistentStoreProvider(org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager) QueryOptionManager(org.apache.drill.exec.server.options.QueryOptionManager) MetricRegistry(com.codahale.metrics.MetricRegistry) SchemaPlus(org.apache.calcite.schema.SchemaPlus) LogicalPlanPersistence(org.apache.drill.common.config.LogicalPlanPersistence) ExecutionControls(org.apache.drill.exec.testing.ExecutionControls) UserSession(org.apache.drill.exec.rpc.user.UserSession) StoragePluginRegistryImpl(org.apache.drill.exec.store.StoragePluginRegistryImpl) NonStrictExpectations(mockit.NonStrictExpectations) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) DrillOperatorTable(org.apache.drill.exec.planner.sql.DrillOperatorTable)

Example 24 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class HBaseSchemaFactory method registerSchemas.

@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException {
    HBaseSchema schema = new HBaseSchema(schemaName);
    SchemaPlus hPlus = parent.add(schemaName, schema);
    schema.setHolder(hPlus);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 25 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class FileSystemSchemaFactory method registerSchemas.

@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException {
    FileSystemSchema schema = new FileSystemSchema(schemaName, schemaConfig);
    SchemaPlus plusOfThis = parent.add(schema.getName(), schema);
    schema.setPlus(plusOfThis);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Aggregations

SchemaPlus (org.apache.calcite.schema.SchemaPlus)33 Table (org.apache.calcite.schema.Table)8 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)6 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)6 DruidOperatorTable (io.druid.sql.calcite.planner.DruidOperatorTable)5 PlannerConfig (io.druid.sql.calcite.planner.PlannerConfig)5 PlannerFactory (io.druid.sql.calcite.planner.PlannerFactory)5 StreamableTable (org.apache.calcite.schema.StreamableTable)5 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)4 SqlNode (org.apache.calcite.sql.SqlNode)4 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)4 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)4 TridentRel (org.apache.storm.sql.planner.trident.rel.TridentRel)4 Before (org.junit.Before)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CompilerUtil (org.apache.storm.sql.compiler.CompilerUtil)3 CalciteCatalogReader (org.apache.calcite.prepare.CalciteCatalogReader)2 UserSession (org.apache.drill.exec.rpc.user.UserSession)2 DrillFileSystem (org.apache.drill.exec.store.dfs.DrillFileSystem)2