Search in sources :

Example 1 with DrillOperatorTable

use of org.apache.drill.exec.planner.sql.DrillOperatorTable 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)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)1 NonStrictExpectations (mockit.NonStrictExpectations)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 LogicalPlanPersistence (org.apache.drill.common.config.LogicalPlanPersistence)1 ScanResult (org.apache.drill.common.scanner.persistence.ScanResult)1 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)1 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)1 PlannerSettings (org.apache.drill.exec.planner.physical.PlannerSettings)1 DrillOperatorTable (org.apache.drill.exec.planner.sql.DrillOperatorTable)1 UserSession (org.apache.drill.exec.rpc.user.UserSession)1 QueryOptionManager (org.apache.drill.exec.server.options.QueryOptionManager)1 SessionOptionManager (org.apache.drill.exec.server.options.SessionOptionManager)1 SystemOptionManager (org.apache.drill.exec.server.options.SystemOptionManager)1 StoragePluginRegistry (org.apache.drill.exec.store.StoragePluginRegistry)1 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)1 LocalPersistentStoreProvider (org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider)1 ExecutionControls (org.apache.drill.exec.testing.ExecutionControls)1