Search in sources :

Example 1 with NamedSchema

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

the class DruidAvaticaHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder());
    final PlannerConfig plannerConfig = new PlannerConfig();
    final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable();
    final ExprMacroTable macroTable = CalciteTests.createExprMacroTable();
    final DruidSchemaCatalog rootSchema = CalciteTests.createMockRootSchema(conglomerate, walker, plannerConfig, CalciteTests.TEST_AUTHORIZER_MAPPER);
    testRequestLogger = new TestRequestLogger();
    injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
            binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
            binder.bind(AuthenticatorMapper.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_MAPPER);
            binder.bind(AuthorizerMapper.class).toInstance(CalciteTests.TEST_AUTHORIZER_MAPPER);
            binder.bind(Escalator.class).toInstance(CalciteTests.TEST_AUTHENTICATOR_ESCALATOR);
            binder.bind(RequestLogger.class).toInstance(testRequestLogger);
            binder.bind(DruidSchemaCatalog.class).toInstance(rootSchema);
            for (NamedSchema schema : rootSchema.getNamedSchemas().values()) {
                Multibinder.newSetBinder(binder, NamedSchema.class).addBinding().toInstance(schema);
            }
            binder.bind(QueryLifecycleFactory.class).toInstance(CalciteTests.createMockQueryLifecycleFactory(walker, conglomerate));
            binder.bind(DruidOperatorTable.class).toInstance(operatorTable);
            binder.bind(ExprMacroTable.class).toInstance(macroTable);
            binder.bind(PlannerConfig.class).toInstance(plannerConfig);
            binder.bind(String.class).annotatedWith(DruidSchemaName.class).toInstance(CalciteTests.DRUID_SCHEMA_NAME);
            binder.bind(AvaticaServerConfig.class).toInstance(AVATICA_CONFIG);
            binder.bind(ServiceEmitter.class).to(NoopServiceEmitter.class);
            binder.bind(QuerySchedulerProvider.class).in(LazySingleton.class);
            binder.bind(QueryScheduler.class).toProvider(QuerySchedulerProvider.class).in(LazySingleton.class);
            binder.bind(QueryMakerFactory.class).to(NativeQueryMakerFactory.class);
        }
    }));
    druidMeta = injector.getInstance(DruidMeta.class);
    final AbstractAvaticaHandler handler = this.getAvaticaHandler(druidMeta);
    final int port = ThreadLocalRandom.current().nextInt(9999) + 10000;
    server = new Server(new InetSocketAddress("127.0.0.1", port));
    server.setHandler(handler);
    server.start();
    url = this.getJdbcConnectionString(port);
    client = DriverManager.getConnection(url, "regularUser", "druid");
    superuserClient = DriverManager.getConnection(url, CalciteTests.TEST_SUPERUSER_NAME, "druid");
    clientNoTrailingSlash = DriverManager.getConnection(StringUtils.maybeRemoveTrailingSlash(url), CalciteTests.TEST_SUPERUSER_NAME, "druid");
    final Properties propertiesLosAngeles = new Properties();
    propertiesLosAngeles.setProperty("sqlTimeZone", "America/Los_Angeles");
    propertiesLosAngeles.setProperty("user", "regularUserLA");
    propertiesLosAngeles.setProperty(BaseQuery.SQL_QUERY_ID, DUMMY_SQL_QUERY_ID);
    clientLosAngeles = DriverManager.getConnection(url, propertiesLosAngeles);
}
Also used : QueryScheduler(org.apache.druid.server.QueryScheduler) Server(org.eclipse.jetty.server.Server) InetSocketAddress(java.net.InetSocketAddress) AbstractAvaticaHandler(org.apache.calcite.avatica.server.AbstractAvaticaHandler) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) NamedSchema(org.apache.druid.sql.calcite.schema.NamedSchema) Properties(java.util.Properties) DruidOperatorTable(org.apache.druid.sql.calcite.planner.DruidOperatorTable) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) TestRequestLogger(org.apache.druid.server.log.TestRequestLogger) Binder(com.google.inject.Binder) LazySingleton(org.apache.druid.guice.LazySingleton) PlannerConfig(org.apache.druid.sql.calcite.planner.PlannerConfig) DruidSchemaCatalog(org.apache.druid.sql.calcite.schema.DruidSchemaCatalog) NativeQueryMakerFactory(org.apache.druid.sql.calcite.run.NativeQueryMakerFactory) Module(com.google.inject.Module) Before(org.junit.Before)

Example 2 with NamedSchema

use of org.apache.druid.sql.calcite.schema.NamedSchema 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 NamedSchema (org.apache.druid.sql.calcite.schema.NamedSchema)2 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 AbstractAvaticaHandler (org.apache.calcite.avatica.server.AbstractAvaticaHandler)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 LazySingleton (org.apache.druid.guice.LazySingleton)1 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)1 QueryScheduler (org.apache.druid.server.QueryScheduler)1 TestRequestLogger (org.apache.druid.server.log.TestRequestLogger)1 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)1 DruidOperatorTable (org.apache.druid.sql.calcite.planner.DruidOperatorTable)1 PlannerConfig (org.apache.druid.sql.calcite.planner.PlannerConfig)1 NativeQueryMakerFactory (org.apache.druid.sql.calcite.run.NativeQueryMakerFactory)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