Search in sources :

Example 1 with SchemaConfig

use of org.apache.drill.exec.store.SchemaConfig in project drill by apache.

the class FragmentContextImpl method getQueryContextRootSchema.

private SchemaPlus getQueryContextRootSchema() {
    boolean isImpersonationEnabled = isImpersonationEnabled();
    // If impersonation is enabled, we want to view the schema as query user and suppress authorization errors. As for
    // InfoSchema purpose we want to show tables the user has permissions to list or query. If  impersonation is
    // disabled view the schema as Drillbit process user and throw authorization errors to client.
    SchemaConfig schemaConfig = SchemaConfig.newBuilder(isImpersonationEnabled ? queryContext.getQueryUserName() : ImpersonationUtil.getProcessUserName(), queryContext).setIgnoreAuthErrors(isImpersonationEnabled).build();
    return queryContext.getRootSchema(schemaConfig);
}
Also used : SchemaConfig(org.apache.drill.exec.store.SchemaConfig)

Example 2 with SchemaConfig

use of org.apache.drill.exec.store.SchemaConfig in project drill by apache.

the class FragmentContext method getRootSchema.

public SchemaPlus getRootSchema() {
    if (queryContext == null) {
        fail(new UnsupportedOperationException("Schema tree can only be created in root fragment. " + "This is a non-root fragment."));
        return null;
    }
    final boolean isImpersonationEnabled = isImpersonationEnabled();
    // If impersonation is enabled, we want to view the schema as query user and suppress authorization errors. As for
    // InfoSchema purpose we want to show tables the user has permissions to list or query. If  impersonation is
    // disabled view the schema as Drillbit process user and throw authorization errors to client.
    SchemaConfig schemaConfig = SchemaConfig.newBuilder(isImpersonationEnabled ? queryContext.getQueryUserName() : ImpersonationUtil.getProcessUserName(), queryContext).setIgnoreAuthErrors(isImpersonationEnabled).build();
    return queryContext.getRootSchema(schemaConfig);
}
Also used : SchemaConfig(org.apache.drill.exec.store.SchemaConfig)

Example 3 with SchemaConfig

use of org.apache.drill.exec.store.SchemaConfig in project drill by axbaretto.

the class FragmentContextImpl method getFullRootSchema.

public SchemaPlus getFullRootSchema() {
    if (queryContext == null) {
        fail(new UnsupportedOperationException("Schema tree can only be created in root fragment. " + "This is a non-root fragment."));
        return null;
    }
    final boolean isImpersonationEnabled = isImpersonationEnabled();
    // If impersonation is enabled, we want to view the schema as query user and suppress authorization errors. As for
    // InfoSchema purpose we want to show tables the user has permissions to list or query. If  impersonation is
    // disabled view the schema as Drillbit process user and throw authorization errors to client.
    SchemaConfig schemaConfig = SchemaConfig.newBuilder(isImpersonationEnabled ? queryContext.getQueryUserName() : ImpersonationUtil.getProcessUserName(), queryContext).setIgnoreAuthErrors(isImpersonationEnabled).build();
    return queryContext.getFullRootSchema(schemaConfig);
}
Also used : SchemaConfig(org.apache.drill.exec.store.SchemaConfig)

Example 4 with SchemaConfig

use of org.apache.drill.exec.store.SchemaConfig 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 5 with SchemaConfig

use of org.apache.drill.exec.store.SchemaConfig in project drill by apache.

the class FragmentContextImpl method getFragmentContextRootSchema.

private SchemaPlus getFragmentContextRootSchema() {
    boolean isImpersonationEnabled = isImpersonationEnabled();
    SchemaConfig schemaConfig = SchemaConfig.newBuilder(isImpersonationEnabled ? contextInformation.getQueryUser() : ImpersonationUtil.getProcessUserName(), new FragmentSchemaConfigInfoProvider(fragmentOptions, contextInformation.getQueryUser(), context)).setIgnoreAuthErrors(isImpersonationEnabled).build();
    return schemaTreeProvider.createRootSchema(schemaConfig);
}
Also used : SchemaConfig(org.apache.drill.exec.store.SchemaConfig)

Aggregations

SchemaConfig (org.apache.drill.exec.store.SchemaConfig)5 MetricRegistry (com.codahale.metrics.MetricRegistry)1 DrillBuf (io.netty.buffer.DrillBuf)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 AliasRegistryProvider (org.apache.drill.exec.alias.AliasRegistryProvider)1 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)1 ValueHolder (org.apache.drill.exec.expr.holders.ValueHolder)1 QueryContext (org.apache.drill.exec.ops.QueryContext)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 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)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