Search in sources :

Example 1 with LookupExtractorFactoryContainerProvider

use of org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider in project druid by druid-io.

the class BaseCalciteQueryTest method setMapperInjectableValues.

public final void setMapperInjectableValues(ObjectMapper mapper, Map<String, Object> injectables) {
    // duplicate the injectable values from CalciteTests.INJECTOR initialization, mainly to update the injectable
    // macro table, or whatever else you feel like injecting to a mapper
    LookupExtractorFactoryContainerProvider lookupProvider = CalciteTests.INJECTOR.getInstance(LookupExtractorFactoryContainerProvider.class);
    mapper.setInjectableValues(new InjectableValues.Std(injectables).addValue(ExprMacroTable.class.getName(), createMacroTable()).addValue(ObjectMapper.class.getName(), mapper).addValue(DataSegment.PruneSpecsHolder.class, DataSegment.PruneSpecsHolder.DEFAULT).addValue(LookupExtractorFactoryContainerProvider.class.getName(), lookupProvider));
}
Also used : LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) DataSegment(org.apache.druid.timeline.DataSegment) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable)

Example 2 with LookupExtractorFactoryContainerProvider

use of org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider in project druid by druid-io.

the class JoinAndLookupBenchmark method setup.

@Setup()
public void setup() throws IOException {
    tmpDir = FileUtils.createTempDir();
    ColumnConfig columnConfig = () -> columnCacheSizeBytes;
    index = JoinTestHelper.createFactIndexBuilder(columnConfig, tmpDir, rows).buildMMappedIndex();
    final String prefix = "c.";
    baseSegment = new QueryableIndexSegment(index, SegmentId.dummy("join"));
    List<JoinableClause> joinableClausesLookupStringKey = ImmutableList.of(new JoinableClause(prefix, LookupJoinable.wrap(JoinTestHelper.createCountryIsoCodeToNameLookup()), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("countryIsoCode == \"%sk\"", prefix), prefix, ExprMacroTable.nil())));
    JoinFilterPreAnalysis preAnalysisLookupStringKey = JoinFilterAnalyzer.computeJoinFilterPreAnalysis(new JoinFilterPreAnalysisKey(new JoinFilterRewriteConfig(false, false, false, false, 0), joinableClausesLookupStringKey, VirtualColumns.EMPTY, null));
    hashJoinLookupStringKeySegment = new HashJoinSegment(ReferenceCountingSegment.wrapRootGenerationSegment(baseSegment), null, joinableClausesLookupStringKey, preAnalysisLookupStringKey);
    List<JoinableClause> joinableClausesLookupLongKey = ImmutableList.of(new JoinableClause(prefix, LookupJoinable.wrap(JoinTestHelper.createCountryIsoCodeToNameLookup()), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("countryIsoCode == \"%sk\"", prefix), prefix, ExprMacroTable.nil())));
    JoinFilterPreAnalysis preAnalysisLookupLongKey = JoinFilterAnalyzer.computeJoinFilterPreAnalysis(new JoinFilterPreAnalysisKey(new JoinFilterRewriteConfig(false, false, false, false, 0), joinableClausesLookupLongKey, VirtualColumns.EMPTY, null));
    hashJoinLookupLongKeySegment = new HashJoinSegment(ReferenceCountingSegment.wrapRootGenerationSegment(baseSegment), null, joinableClausesLookupLongKey, preAnalysisLookupLongKey);
    List<JoinableClause> joinableClausesIndexedTableStringKey = ImmutableList.of(new JoinableClause(prefix, new IndexedTableJoinable(JoinTestHelper.createCountriesIndexedTable()), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("countryIsoCode == \"%scountryIsoCode\"", prefix), prefix, ExprMacroTable.nil())));
    JoinFilterPreAnalysis preAnalysisIndexedStringKey = JoinFilterAnalyzer.computeJoinFilterPreAnalysis(new JoinFilterPreAnalysisKey(new JoinFilterRewriteConfig(false, false, false, false, 0), joinableClausesLookupLongKey, VirtualColumns.EMPTY, null));
    hashJoinIndexedTableStringKeySegment = new HashJoinSegment(ReferenceCountingSegment.wrapRootGenerationSegment(baseSegment), null, joinableClausesIndexedTableStringKey, preAnalysisIndexedStringKey);
    List<JoinableClause> joinableClausesIndexedTableLongKey = ImmutableList.of(new JoinableClause(prefix, new IndexedTableJoinable(JoinTestHelper.createCountriesIndexedTable()), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("countryNumber == \"%scountryNumber\"", prefix), prefix, ExprMacroTable.nil())));
    JoinFilterPreAnalysis preAnalysisIndexedLongKey = JoinFilterAnalyzer.computeJoinFilterPreAnalysis(new JoinFilterPreAnalysisKey(new JoinFilterRewriteConfig(false, false, false, false, 0), joinableClausesIndexedTableLongKey, VirtualColumns.EMPTY, null));
    hashJoinIndexedTableLongKeySegment = new HashJoinSegment(ReferenceCountingSegment.wrapRootGenerationSegment(baseSegment), null, joinableClausesIndexedTableLongKey, preAnalysisIndexedLongKey);
    final Map<String, String> countryCodeToNameMap = JoinTestHelper.createCountryIsoCodeToNameLookup().getMap();
    final Map<String, String> countryNumberToNameMap = JoinTestHelper.createCountryNumberToNameLookup().getMap();
    final ExprMacroTable exprMacroTable = new ExprMacroTable(ImmutableList.of(new LookupExprMacro(new LookupExtractorFactoryContainerProvider() {

        @Override
        public Set<String> getAllLookupNames() {
            return ImmutableSet.of(LOOKUP_COUNTRY_CODE_TO_NAME, LOOKUP_COUNTRY_NUMBER_TO_NAME);
        }

        @Override
        public Optional<LookupExtractorFactoryContainer> get(String lookupName) {
            if (LOOKUP_COUNTRY_CODE_TO_NAME.equals(lookupName)) {
                return Optional.of(new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(countryCodeToNameMap, false)));
            } else if (LOOKUP_COUNTRY_NUMBER_TO_NAME.equals(lookupName)) {
                return Optional.of(new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(countryNumberToNameMap, false)));
            } else {
                return Optional.empty();
            }
        }
    })));
    lookupVirtualColumns = VirtualColumns.create(ImmutableList.of(new ExpressionVirtualColumn(LOOKUP_COUNTRY_CODE_TO_NAME, "lookup(countryIsoCode, '" + LOOKUP_COUNTRY_CODE_TO_NAME + "')", ColumnType.STRING, exprMacroTable), new ExpressionVirtualColumn(LOOKUP_COUNTRY_NUMBER_TO_NAME, "lookup(countryNumber, '" + LOOKUP_COUNTRY_NUMBER_TO_NAME + "')", ColumnType.STRING, exprMacroTable)));
}
Also used : QueryableIndexSegment(org.apache.druid.segment.QueryableIndexSegment) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ColumnConfig(org.apache.druid.segment.column.ColumnConfig) Optional(java.util.Optional) MapLookupExtractorFactory(org.apache.druid.query.lookup.MapLookupExtractorFactory) JoinFilterPreAnalysisKey(org.apache.druid.segment.join.filter.JoinFilterPreAnalysisKey) LookupExprMacro(org.apache.druid.query.expression.LookupExprMacro) JoinFilterRewriteConfig(org.apache.druid.segment.join.filter.rewrite.JoinFilterRewriteConfig) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) JoinableClause(org.apache.druid.segment.join.JoinableClause) HashJoinSegment(org.apache.druid.segment.join.HashJoinSegment) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) LookupExtractorFactoryContainer(org.apache.druid.query.lookup.LookupExtractorFactoryContainer) Setup(org.openjdk.jmh.annotations.Setup)

Example 3 with LookupExtractorFactoryContainerProvider

use of org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider in project druid by druid-io.

the class JoinableFactoryModuleTest method makeInjectorWithProperties.

private Injector makeInjectorWithProperties(Module... otherModules) {
    final LookupExtractorFactoryContainerProvider lookupProvider = LookupEnabledTestExprMacroTable.createTestLookupProvider(Collections.emptyMap());
    final ImmutableList.Builder<Module> modulesBuilder = ImmutableList.<Module>builder().add(new JoinableFactoryModule()).add(binder -> binder.bind(LookupExtractorFactoryContainerProvider.class).toInstance(lookupProvider)).add(binder -> binder.bind(SegmentManager.class).toInstance(EasyMock.createMock(SegmentManager.class))).add(binder -> binder.bindScope(LazySingleton.class, Scopes.SINGLETON));
    for (final Module otherModule : otherModules) {
        modulesBuilder.add(otherModule);
    }
    return Guice.createInjector(modulesBuilder.build());
}
Also used : Module(com.google.inject.Module) SegmentManager(org.apache.druid.server.SegmentManager) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) Key(com.google.inject.Key) LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) NoopJoinableFactory(org.apache.druid.segment.join.NoopJoinableFactory) Before(org.junit.Before) LookupDataSource(org.apache.druid.query.LookupDataSource) InlineDataSource(org.apache.druid.query.InlineDataSource) LookupEnabledTestExprMacroTable(org.apache.druid.query.expression.LookupEnabledTestExprMacroTable) DataSource(org.apache.druid.query.DataSource) Set(java.util.Set) NoopDataSource(org.apache.druid.segment.join.NoopDataSource) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) MapJoinableFactory(org.apache.druid.segment.join.MapJoinableFactory) Scopes(com.google.inject.Scopes) Injector(com.google.inject.Injector) BroadcastTableJoinableFactory(org.apache.druid.segment.join.BroadcastTableJoinableFactory) InlineJoinableFactory(org.apache.druid.segment.join.InlineJoinableFactory) LookupJoinableFactory(org.apache.druid.segment.join.LookupJoinableFactory) Guice(com.google.inject.Guice) Assert(org.junit.Assert) TypeLiteral(com.google.inject.TypeLiteral) Collections(java.util.Collections) SegmentManager(org.apache.druid.server.SegmentManager) ImmutableList(com.google.common.collect.ImmutableList) LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) Module(com.google.inject.Module)

Example 4 with LookupExtractorFactoryContainerProvider

use of org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider in project druid by druid-io.

the class SqlModuleTest method makeInjectorWithProperties.

private Injector makeInjectorWithProperties(final Properties props) {
    return Guice.createInjector(ImmutableList.of(new DruidGuiceExtensions(), new LifecycleModule(), new ServerModule(), new JacksonModule(), (Module) binder -> {
        binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
        binder.bind(JsonConfigurator.class).in(LazySingleton.class);
        binder.bind(Properties.class).toInstance(props);
        binder.bind(ExprMacroTable.class).toInstance(ExprMacroTable.nil());
        binder.bind(AuthorizerMapper.class).toInstance(CalciteTests.TEST_AUTHORIZER_MAPPER);
        binder.bind(Escalator.class).toInstance(new NoopEscalator());
        binder.bind(ServiceEmitter.class).toInstance(serviceEmitter);
        binder.bind(RequestLogger.class).toInstance(new NoopRequestLogger());
        binder.bind(new TypeLiteral<Supplier<DefaultQueryConfig>>() {
        }).toInstance(Suppliers.ofInstance(new DefaultQueryConfig(null)));
        binder.bind(FilteredServerInventoryView.class).toInstance(inventoryView);
        binder.bind(TimelineServerView.class).toInstance(timelineServerView);
        binder.bind(DruidLeaderClient.class).annotatedWith(Coordinator.class).toInstance(druidLeaderClient);
        binder.bind(DruidLeaderClient.class).annotatedWith(IndexingService.class).toInstance(druidLeaderClient);
        binder.bind(DruidNodeDiscoveryProvider.class).toInstance(druidNodeDiscoveryProvider);
        binder.bind(GenericQueryMetricsFactory.class).toInstance(genericQueryMetricsFactory);
        binder.bind(QuerySegmentWalker.class).toInstance(querySegmentWalker);
        binder.bind(QueryToolChestWarehouse.class).toInstance(queryToolChestWarehouse);
        binder.bind(LookupExtractorFactoryContainerProvider.class).toInstance(lookupExtractorFactoryContainerProvider);
        binder.bind(JoinableFactory.class).toInstance(joinableFactory);
        binder.bind(SegmentLoader.class).toInstance(segmentLoader);
        binder.bind(QuerySchedulerProvider.class).in(LazySingleton.class);
        binder.bind(QueryScheduler.class).toProvider(QuerySchedulerProvider.class).in(LazySingleton.class);
    }, new SqlModule(props), new TestViewManagerModule()));
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) DruidGuiceExtensions(org.apache.druid.guice.DruidGuiceExtensions) Properties(java.util.Properties) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) ServerModule(org.apache.druid.guice.ServerModule) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) NoopEscalator(org.apache.druid.server.security.NoopEscalator) Escalator(org.apache.druid.server.security.Escalator) NoopEscalator(org.apache.druid.server.security.NoopEscalator) TypeLiteral(com.google.inject.TypeLiteral) QuerySchedulerProvider(org.apache.druid.server.QuerySchedulerProvider) IndexingService(org.apache.druid.client.indexing.IndexingService) RequestLogger(org.apache.druid.server.log.RequestLogger) NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) JsonConfigurator(org.apache.druid.guice.JsonConfigurator) LookupExtractorFactoryContainerProvider(org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) TimelineServerView(org.apache.druid.client.TimelineServerView) QueryToolChestWarehouse(org.apache.druid.query.QueryToolChestWarehouse) LifecycleModule(org.apache.druid.guice.LifecycleModule) FilteredServerInventoryView(org.apache.druid.client.FilteredServerInventoryView) NoopRequestLogger(org.apache.druid.server.log.NoopRequestLogger) GenericQueryMetricsFactory(org.apache.druid.query.GenericQueryMetricsFactory) Coordinator(org.apache.druid.client.coordinator.Coordinator) JacksonModule(org.apache.druid.jackson.JacksonModule) SegmentLoader(org.apache.druid.segment.loading.SegmentLoader) DruidNodeDiscoveryProvider(org.apache.druid.discovery.DruidNodeDiscoveryProvider) Module(com.google.inject.Module) LifecycleModule(org.apache.druid.guice.LifecycleModule) JacksonModule(org.apache.druid.jackson.JacksonModule) DruidModule(org.apache.druid.initialization.DruidModule) ServerModule(org.apache.druid.guice.ServerModule) Validator(javax.validation.Validator)

Aggregations

LookupExtractorFactoryContainerProvider (org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider)4 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)3 Module (com.google.inject.Module)2 TypeLiteral (com.google.inject.TypeLiteral)2 Set (java.util.Set)2 JoinableFactory (org.apache.druid.segment.join.JoinableFactory)2 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 Scopes (com.google.inject.Scopes)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Validator (javax.validation.Validator)1 FilteredServerInventoryView (org.apache.druid.client.FilteredServerInventoryView)1 TimelineServerView (org.apache.druid.client.TimelineServerView)1