Search in sources :

Example 1 with QueryOptionManager

use of org.apache.drill.exec.server.options.QueryOptionManager in project drill by axbaretto.

the class SetOptionHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, ForemanSetupException {
    final SqlSetOption option = unwrap(sqlNode, SqlSetOption.class);
    final SqlNode value = option.getValue();
    if (value != null && !(value instanceof SqlLiteral)) {
        throw UserException.validationError().message("Drill does not support assigning non-literal values in SET statements.").build(logger);
    }
    final String scope = option.getScope();
    final OptionValue.OptionScope optionScope;
    if (scope == null) {
        // No scope mentioned assumed SESSION
        optionScope = OptionScope.SESSION;
    } else {
        switch(scope.toLowerCase()) {
            case "session":
                optionScope = OptionScope.SESSION;
                break;
            case "system":
                optionScope = OptionScope.SYSTEM;
                break;
            default:
                throw UserException.validationError().message("Invalid OPTION scope %s. Scope must be SESSION or SYSTEM.", scope).build(logger);
        }
    }
    final QueryOptionManager options = context.getOptions();
    if (optionScope == OptionScope.SYSTEM) {
        // administrative privileges.
        if (context.isUserAuthenticationEnabled() && !ImpersonationUtil.hasAdminPrivileges(context.getQueryUserName(), ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(options), ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(options))) {
            throw UserException.permissionError().message("Not authorized to change SYSTEM options.").build(logger);
        }
    }
    final String optionName = option.getName().toString();
    // Currently, we convert multi-part identifier to a string.
    final OptionManager chosenOptions = options.getOptionManager(optionScope);
    if (value != null) {
        // SET option
        final Object literalObj = sqlLiteralToObject((SqlLiteral) value);
        chosenOptions.setLocalOption(optionName, literalObj);
    } else {
        // RESET option
        if ("ALL".equalsIgnoreCase(optionName)) {
            chosenOptions.deleteAllLocalOptions();
        } else {
            chosenOptions.deleteLocalOption(optionName);
        }
    }
    return DirectPlan.createDirectPlan(context, true, String.format("%s updated.", optionName));
}
Also used : OptionScope(org.apache.drill.exec.server.options.OptionValue.OptionScope) QueryOptionManager(org.apache.drill.exec.server.options.QueryOptionManager) OptionValue(org.apache.drill.exec.server.options.OptionValue) SqlSetOption(org.apache.calcite.sql.SqlSetOption) NlsString(org.apache.calcite.util.NlsString) SqlLiteral(org.apache.calcite.sql.SqlLiteral) OptionManager(org.apache.drill.exec.server.options.OptionManager) QueryOptionManager(org.apache.drill.exec.server.options.QueryOptionManager) SqlNode(org.apache.calcite.sql.SqlNode)

Example 2 with QueryOptionManager

use of org.apache.drill.exec.server.options.QueryOptionManager in project drill by axbaretto.

the class PlanningBase method testSqlPlan.

protected void testSqlPlan(String sqlCommands) throws Exception {
    final DrillbitContext dbContext = mock(DrillbitContext.class);
    final QueryContext context = mock(QueryContext.class);
    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, config);
    systemOptions.init();
    @SuppressWarnings("resource") final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(systemOptions).build();
    final SessionOptionManager sessionOptions = userSession.getOptions();
    final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions);
    final ExecutionControls executionControls = new ExecutionControls(queryOptions, DrillbitEndpoint.getDefaultInstance());
    when(dbContext.getMetrics()).thenReturn(new MetricRegistry());
    when(dbContext.getAllocator()).thenReturn(allocator);
    when(dbContext.getConfig()).thenReturn(config);
    when(dbContext.getOptionManager()).thenReturn(systemOptions);
    when(dbContext.getStoreProvider()).thenReturn(provider);
    when(dbContext.getClasspathScan()).thenReturn(scanResult);
    when(dbContext.getLpPersistence()).thenReturn(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 = CalciteSchema.createRootSchema(false, false).plus();
    registry.getSchemaFactory().registerSchemas(SchemaConfig.newBuilder("foo", context).build(), root);
    when(context.getNewDefaultSchema()).thenReturn(root);
    when(context.getLpPersistence()).thenReturn(new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config)));
    when(context.getStorage()).thenReturn(registry);
    when(context.getFunctionRegistry()).thenReturn(functionRegistry);
    when(context.getSession()).thenReturn(UserSession.Builder.newBuilder().withOptionManager(sessionOptions).setSupportComplexTypes(true).build());
    when(context.getCurrentEndpoint()).thenReturn(DrillbitEndpoint.getDefaultInstance());
    when(context.getActiveEndpoints()).thenReturn(ImmutableList.of(DrillbitEndpoint.getDefaultInstance()));
    when(context.getPlannerSettings()).thenReturn(new PlannerSettings(queryOptions, functionRegistry));
    when(context.getOptions()).thenReturn(queryOptions);
    when(context.getConfig()).thenReturn(config);
    when(context.getDrillOperatorTable()).thenReturn(table);
    when(context.getAllocator()).thenReturn(allocator);
    when(context.getExecutionControls()).thenReturn(executionControls);
    when(context.getLpPersistence()).thenReturn(logicalPlanPersistence);
    for (final String sql : sqlStrings) {
        if (sql.trim().isEmpty()) {
            continue;
        }
        @SuppressWarnings("unused") final PhysicalPlan p = DrillSqlWorker.getPlan(context, sql);
    }
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) 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) QueryContext(org.apache.drill.exec.ops.QueryContext) 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) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) DrillOperatorTable(org.apache.drill.exec.planner.sql.DrillOperatorTable)

Example 3 with QueryOptionManager

use of org.apache.drill.exec.server.options.QueryOptionManager in project drill by apache.

the class PlanningBase method testSqlPlan.

protected void testSqlPlan(String sqlCommands) throws Exception {
    final DrillbitContext dbContext = mock(DrillbitContext.class);
    final QueryContext context = mock(QueryContext.class);
    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, config);
    systemOptions.init();
    final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(systemOptions).build();
    final SessionOptionManager sessionOptions = userSession.getOptions();
    final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions);
    final ExecutionControls executionControls = new ExecutionControls(queryOptions, DrillbitEndpoint.getDefaultInstance());
    when(dbContext.getMetrics()).thenReturn(new MetricRegistry());
    when(dbContext.getAllocator()).thenReturn(allocator);
    when(dbContext.getConfig()).thenReturn(config);
    when(dbContext.getOptionManager()).thenReturn(systemOptions);
    when(dbContext.getStoreProvider()).thenReturn(provider);
    when(dbContext.getClasspathScan()).thenReturn(scanResult);
    when(dbContext.getLpPersistence()).thenReturn(logicalPlanPersistence);
    final StoragePluginRegistry registry = new StoragePluginRegistryImpl(dbContext);
    registry.init();
    final FunctionImplementationRegistry functionRegistry = new FunctionImplementationRegistry(config);
    final DrillOperatorTable table = new DrillOperatorTable(functionRegistry, systemOptions);
    SchemaConfig schemaConfig = SchemaConfig.newBuilder("foo", context).build();
    SchemaPlus root = DynamicSchema.createRootSchema(registry, schemaConfig, new AliasRegistryProvider(dbContext));
    when(context.getNewDefaultSchema()).thenReturn(root);
    when(context.getLpPersistence()).thenReturn(new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config)));
    when(context.getStorage()).thenReturn(registry);
    when(context.getFunctionRegistry()).thenReturn(functionRegistry);
    when(context.getSession()).thenReturn(UserSession.Builder.newBuilder().withOptionManager(sessionOptions).setSupportComplexTypes(true).build());
    when(context.getCurrentEndpoint()).thenReturn(DrillbitEndpoint.getDefaultInstance());
    when(context.getActiveEndpoints()).thenReturn(ImmutableList.of(DrillbitEndpoint.getDefaultInstance()));
    when(context.getPlannerSettings()).thenReturn(new PlannerSettings(queryOptions, functionRegistry));
    when(context.getOptions()).thenReturn(queryOptions);
    when(context.getConfig()).thenReturn(config);
    when(context.getDrillOperatorTable()).thenReturn(table);
    when(context.getAllocator()).thenReturn(allocator);
    when(context.getExecutionControls()).thenReturn(executionControls);
    when(context.getLpPersistence()).thenReturn(logicalPlanPersistence);
    // mocks for org.apache.drill.TestTpchPlanning#tpch06 test.
    // With changes for decimal types, subtract udf for decimals is used.
    when(context.getManagedBuffer()).thenReturn(allocator.buffer(4));
    when(context.getConstantValueHolder(eq("0.03"), eq(TypeProtos.MinorType.VARDECIMAL), Matchers.<Function<DrillBuf, ValueHolder>>any())).thenReturn(ValueHolderHelper.getVarDecimalHolder(allocator.buffer(4), "0.03"));
    when(context.getConstantValueHolder(eq("0.01"), eq(TypeProtos.MinorType.VARDECIMAL), Matchers.<Function<DrillBuf, ValueHolder>>any())).thenReturn(ValueHolderHelper.getVarDecimalHolder(allocator.buffer(4), "0.01"));
    when(context.getOption(anyString())).thenCallRealMethod();
    for (final String sql : sqlStrings) {
        if (sql.trim().isEmpty()) {
            continue;
        }
        @SuppressWarnings("unused") final PhysicalPlan p = DrillSqlWorker.getPlan(context, sql);
    }
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) SessionOptionManager(org.apache.drill.exec.server.options.SessionOptionManager) SchemaConfig(org.apache.drill.exec.store.SchemaConfig) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LogicalPlanPersistence(org.apache.drill.common.config.LogicalPlanPersistence) AliasRegistryProvider(org.apache.drill.exec.alias.AliasRegistryProvider) UserSession(org.apache.drill.exec.rpc.user.UserSession) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) DrillOperatorTable(org.apache.drill.exec.planner.sql.DrillOperatorTable) DrillBuf(io.netty.buffer.DrillBuf) StoragePluginRegistry(org.apache.drill.exec.store.StoragePluginRegistry) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) MetricRegistry(com.codahale.metrics.MetricRegistry) SchemaPlus(org.apache.calcite.schema.SchemaPlus) QueryContext(org.apache.drill.exec.ops.QueryContext) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) ExecutionControls(org.apache.drill.exec.testing.ExecutionControls) StoragePluginRegistryImpl(org.apache.drill.exec.store.StoragePluginRegistryImpl)

Example 4 with QueryOptionManager

use of org.apache.drill.exec.server.options.QueryOptionManager in project drill by apache.

the class ResetOptionHandler method getPlan.

/**
 * Handles {@link DrillSqlResetOption} query
 */
@Override
public final PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException {
    QueryOptionManager options = context.getOptions();
    SqlSetOption statement = unwrap(sqlNode, SqlSetOption.class);
    OptionScope optionScope = getScope(statement, context.getOptions());
    if (optionScope == OptionValue.OptionScope.SYSTEM) {
        checkAdminPrivileges(options);
    }
    OptionManager optionManager = options.getOptionManager(optionScope);
    String optionName = statement.getName().toString();
    if ("ALL".equalsIgnoreCase(optionName)) {
        optionManager.deleteAllLocalOptions();
    } else {
        optionManager.deleteLocalOption(optionName);
    }
    return DirectPlan.createDirectPlan(context, true, String.format("%s updated.", optionName));
}
Also used : OptionScope(org.apache.drill.exec.server.options.OptionValue.OptionScope) QueryOptionManager(org.apache.drill.exec.server.options.QueryOptionManager) SqlSetOption(org.apache.calcite.sql.SqlSetOption) OptionManager(org.apache.drill.exec.server.options.OptionManager) QueryOptionManager(org.apache.drill.exec.server.options.QueryOptionManager)

Aggregations

QueryOptionManager (org.apache.drill.exec.server.options.QueryOptionManager)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2 SchemaPlus (org.apache.calcite.schema.SchemaPlus)2 SqlSetOption (org.apache.calcite.sql.SqlSetOption)2 LogicalPlanPersistence (org.apache.drill.common.config.LogicalPlanPersistence)2 ScanResult (org.apache.drill.common.scanner.persistence.ScanResult)2 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)2 QueryContext (org.apache.drill.exec.ops.QueryContext)2 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)2 PlannerSettings (org.apache.drill.exec.planner.physical.PlannerSettings)2 DrillOperatorTable (org.apache.drill.exec.planner.sql.DrillOperatorTable)2 UserSession (org.apache.drill.exec.rpc.user.UserSession)2 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)2 OptionManager (org.apache.drill.exec.server.options.OptionManager)2 OptionScope (org.apache.drill.exec.server.options.OptionValue.OptionScope)2 SessionOptionManager (org.apache.drill.exec.server.options.SessionOptionManager)2 SystemOptionManager (org.apache.drill.exec.server.options.SystemOptionManager)2 StoragePluginRegistry (org.apache.drill.exec.store.StoragePluginRegistry)2 StoragePluginRegistryImpl (org.apache.drill.exec.store.StoragePluginRegistryImpl)2 LocalPersistentStoreProvider (org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider)2