Search in sources :

Example 1 with NamedDruidSchema

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

the class ExternalTableScanRuleTest method testMatchesWhenExternalScanUnsupported.

@Test
public void testMatchesWhenExternalScanUnsupported() throws ValidationException {
    final PlannerContext plannerContext = PlannerContext.create(// The actual query isn't important for this test
    "DUMMY", CalciteTests.createOperatorTable(), CalciteTests.createExprMacroTable(), CalciteTests.getJsonMapper(), new PlannerConfig(), new DruidSchemaCatalog(EasyMock.createMock(SchemaPlus.class), ImmutableMap.of("druid", new NamedDruidSchema(EasyMock.createMock(DruidSchema.class), "druid"), NamedViewSchema.NAME, new NamedViewSchema(EasyMock.createMock(ViewSchema.class)))), ImmutableMap.of());
    plannerContext.setQueryMaker(CalciteTests.createMockQueryMakerFactory(EasyMock.createMock(QuerySegmentWalker.class), EasyMock.createMock(QueryRunnerFactoryConglomerate.class)).buildForSelect(EasyMock.createMock(RelRoot.class), plannerContext));
    ExternalTableScanRule rule = new ExternalTableScanRule(plannerContext);
    rule.matches(EasyMock.createMock(RelOptRuleCall.class));
    Assert.assertEquals("SQL query requires scanning external datasources that is not suported.", plannerContext.getPlanningError());
}
Also used : QueryRunnerFactoryConglomerate(org.apache.druid.query.QueryRunnerFactoryConglomerate) PlannerContext(org.apache.druid.sql.calcite.planner.PlannerContext) NamedViewSchema(org.apache.druid.sql.calcite.schema.NamedViewSchema) PlannerConfig(org.apache.druid.sql.calcite.planner.PlannerConfig) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) NamedDruidSchema(org.apache.druid.sql.calcite.schema.NamedDruidSchema) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) Test(org.junit.Test)

Example 2 with NamedDruidSchema

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

the class CalciteTests method createMockRootSchema.

public static DruidSchemaCatalog createMockRootSchema(final QueryRunnerFactoryConglomerate conglomerate, final SpecificSegmentsQuerySegmentWalker walker, final PlannerConfig plannerConfig, @Nullable final ViewManager viewManager, final DruidSchemaManager druidSchemaManager, final AuthorizerMapper authorizerMapper) {
    DruidSchema druidSchema = createMockSchema(conglomerate, walker, plannerConfig, druidSchemaManager);
    SystemSchema systemSchema = CalciteTests.createMockSystemSchema(druidSchema, walker, plannerConfig, authorizerMapper);
    LookupSchema lookupSchema = CalciteTests.createMockLookupSchema();
    ViewSchema viewSchema = viewManager != null ? new ViewSchema(viewManager) : null;
    SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();
    Set<NamedSchema> namedSchemas = new HashSet<>();
    namedSchemas.add(new NamedDruidSchema(druidSchema, CalciteTests.DRUID_SCHEMA_NAME));
    namedSchemas.add(new NamedSystemSchema(plannerConfig, systemSchema));
    namedSchemas.add(new NamedLookupSchema(lookupSchema));
    if (viewSchema != null) {
        namedSchemas.add(new NamedViewSchema(viewSchema));
    }
    DruidSchemaCatalog catalog = new DruidSchemaCatalog(rootSchema, namedSchemas.stream().collect(Collectors.toMap(NamedSchema::getSchemaName, x -> x)));
    InformationSchema informationSchema = new InformationSchema(catalog, authorizerMapper);
    rootSchema.add(CalciteTests.DRUID_SCHEMA_NAME, druidSchema);
    rootSchema.add(CalciteTests.INFORMATION_SCHEMA_NAME, informationSchema);
    rootSchema.add(NamedSystemSchema.NAME, systemSchema);
    rootSchema.add(NamedLookupSchema.NAME, lookupSchema);
    if (viewSchema != null) {
        rootSchema.add(NamedViewSchema.NAME, viewSchema);
    }
    return catalog;
}
Also used : SystemSchema(org.apache.druid.sql.calcite.schema.SystemSchema) NamedSystemSchema(org.apache.druid.sql.calcite.schema.NamedSystemSchema) NamedViewSchema(org.apache.druid.sql.calcite.schema.NamedViewSchema) DruidSchema(org.apache.druid.sql.calcite.schema.DruidSchema) NamedDruidSchema(org.apache.druid.sql.calcite.schema.NamedDruidSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus) InformationSchema(org.apache.druid.sql.calcite.schema.InformationSchema) NamedSchema(org.apache.druid.sql.calcite.schema.NamedSchema) NamedDruidSchema(org.apache.druid.sql.calcite.schema.NamedDruidSchema) NamedLookupSchema(org.apache.druid.sql.calcite.schema.NamedLookupSchema) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) NamedLookupSchema(org.apache.druid.sql.calcite.schema.NamedLookupSchema) LookupSchema(org.apache.druid.sql.calcite.schema.LookupSchema) ViewSchema(org.apache.druid.sql.calcite.schema.ViewSchema) NamedViewSchema(org.apache.druid.sql.calcite.schema.NamedViewSchema) NamedSystemSchema(org.apache.druid.sql.calcite.schema.NamedSystemSchema) HashSet(java.util.HashSet)

Aggregations

DruidSchemaCatalog (org.apache.druid.sql.calcite.schema.DruidSchemaCatalog)2 NamedDruidSchema (org.apache.druid.sql.calcite.schema.NamedDruidSchema)2 NamedViewSchema (org.apache.druid.sql.calcite.schema.NamedViewSchema)2 HashSet (java.util.HashSet)1 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 QueryRunnerFactoryConglomerate (org.apache.druid.query.QueryRunnerFactoryConglomerate)1 QuerySegmentWalker (org.apache.druid.query.QuerySegmentWalker)1 PlannerConfig (org.apache.druid.sql.calcite.planner.PlannerConfig)1 PlannerContext (org.apache.druid.sql.calcite.planner.PlannerContext)1 DruidSchema (org.apache.druid.sql.calcite.schema.DruidSchema)1 InformationSchema (org.apache.druid.sql.calcite.schema.InformationSchema)1 LookupSchema (org.apache.druid.sql.calcite.schema.LookupSchema)1 NamedLookupSchema (org.apache.druid.sql.calcite.schema.NamedLookupSchema)1 NamedSchema (org.apache.druid.sql.calcite.schema.NamedSchema)1 NamedSystemSchema (org.apache.druid.sql.calcite.schema.NamedSystemSchema)1 SystemSchema (org.apache.druid.sql.calcite.schema.SystemSchema)1 ViewSchema (org.apache.druid.sql.calcite.schema.ViewSchema)1 Test (org.junit.Test)1