Search in sources :

Example 1 with JoinConditionAnalysis

use of org.apache.druid.segment.join.JoinConditionAnalysis in project druid by druid-io.

the class ClientQuerySegmentWalkerTest method initWalker.

/**
 * Initialize (or reinitialize) our {@link #walker} and {@link #closer}.
 */
private void initWalker(final Map<String, String> serverProperties, QueryScheduler schedulerForTest) {
    final ObjectMapper jsonMapper = TestHelper.makeJsonMapper();
    final ServerConfig serverConfig = jsonMapper.convertValue(serverProperties, ServerConfig.class);
    final SegmentWrangler segmentWrangler = new MapSegmentWrangler(ImmutableMap.<Class<? extends DataSource>, SegmentWrangler>builder().put(InlineDataSource.class, new InlineSegmentWrangler()).build());
    final JoinableFactory globalFactory = new JoinableFactory() {

        @Override
        public boolean isDirectlyJoinable(DataSource dataSource) {
            return ((GlobalTableDataSource) dataSource).getName().equals(GLOBAL);
        }

        @Override
        public Optional<Joinable> build(DataSource dataSource, JoinConditionAnalysis condition) {
            return Optional.empty();
        }
    };
    final JoinableFactory joinableFactory = new MapJoinableFactory(ImmutableSet.of(globalFactory, new InlineJoinableFactory()), ImmutableMap.<Class<? extends JoinableFactory>, Class<? extends DataSource>>builder().put(InlineJoinableFactory.class, InlineDataSource.class).put(globalFactory.getClass(), GlobalTableDataSource.class).build());
    class CapturingWalker implements QuerySegmentWalker {

        private QuerySegmentWalker baseWalker;

        private ClusterOrLocal how;

        CapturingWalker(QuerySegmentWalker baseWalker, ClusterOrLocal how) {
            this.baseWalker = baseWalker;
            this.how = how;
        }

        @Override
        public <T> QueryRunner<T> getQueryRunnerForIntervals(Query<T> query, Iterable<Interval> intervals) {
            final QueryRunner<T> baseRunner = baseWalker.getQueryRunnerForIntervals(query, intervals);
            return (queryPlus, responseContext) -> {
                log.info("Query (%s): %s", how, queryPlus.getQuery());
                issuedQueries.add(new ExpectedQuery(queryPlus.getQuery(), how));
                return baseRunner.run(queryPlus, responseContext);
            };
        }

        @Override
        public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<SegmentDescriptor> specs) {
            final QueryRunner<T> baseRunner = baseWalker.getQueryRunnerForSegments(query, specs);
            return (queryPlus, responseContext) -> {
                log.info("Query (%s): %s", how, queryPlus.getQuery());
                issuedQueries.add(new ExpectedQuery(queryPlus.getQuery(), how));
                return baseRunner.run(queryPlus, responseContext);
            };
        }
    }
    walker = QueryStackTests.createClientQuerySegmentWalker(new CapturingWalker(QueryStackTests.createClusterQuerySegmentWalker(ImmutableMap.<String, VersionedIntervalTimeline<String, ReferenceCountingSegment>>builder().put(FOO, makeTimeline(FOO, FOO_INLINE)).put(BAR, makeTimeline(BAR, BAR_INLINE)).put(MULTI, makeTimeline(MULTI, MULTI_VALUE_INLINE)).put(GLOBAL, makeTimeline(GLOBAL, FOO_INLINE)).put(ARRAY, makeTimeline(ARRAY, ARRAY_INLINE)).put(ARRAY_UNKNOWN, makeTimeline(ARRAY_UNKNOWN, ARRAY_INLINE_UNKNOWN)).build(), joinableFactory, conglomerate, schedulerForTest), ClusterOrLocal.CLUSTER), new CapturingWalker(QueryStackTests.createLocalQuerySegmentWalker(conglomerate, segmentWrangler, joinableFactory, schedulerForTest), ClusterOrLocal.LOCAL), conglomerate, joinableFactory, serverConfig);
}
Also used : QueryToolChestTestHelper(org.apache.druid.query.QueryToolChestTestHelper) QueryPlus(org.apache.druid.query.QueryPlus) Arrays(java.util.Arrays) RowBasedSegment(org.apache.druid.segment.RowBasedSegment) SegmentWrangler(org.apache.druid.segment.SegmentWrangler) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Druids(org.apache.druid.query.Druids) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) After(org.junit.After) Map(java.util.Map) QueryRunner(org.apache.druid.query.QueryRunner) ManualQueryPrioritizationStrategy(org.apache.druid.server.scheduling.ManualQueryPrioritizationStrategy) Sequence(org.apache.druid.java.util.common.guava.Sequence) ShardSpec(org.apache.druid.timeline.partition.ShardSpec) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Closer(org.apache.druid.java.util.common.io.Closer) DataSource(org.apache.druid.query.DataSource) NumberedShardSpec(org.apache.druid.timeline.partition.NumberedShardSpec) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) MapJoinableFactory(org.apache.druid.segment.join.MapJoinableFactory) QueryContexts(org.apache.druid.query.QueryContexts) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) Objects(java.util.Objects) InlineJoinableFactory(org.apache.druid.segment.join.InlineJoinableFactory) QueryDataSource(org.apache.druid.query.QueryDataSource) List(java.util.List) MapSegmentWrangler(org.apache.druid.segment.MapSegmentWrangler) Optional(java.util.Optional) SegmentId(org.apache.druid.timeline.SegmentId) Logger(org.apache.druid.java.util.common.logger.Logger) ComparableList(org.apache.druid.segment.data.ComparableList) Joinable(org.apache.druid.segment.join.Joinable) Intervals(org.apache.druid.java.util.common.Intervals) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) JoinType(org.apache.druid.segment.join.JoinType) InlineSegmentWrangler(org.apache.druid.segment.InlineSegmentWrangler) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) DirectDruidClient(org.apache.druid.client.DirectDruidClient) ScanQuery(org.apache.druid.query.scan.ScanQuery) TopNQuery(org.apache.druid.query.topn.TopNQuery) ArrayList(java.util.ArrayList) Interval(org.joda.time.Interval) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) JoinDataSource(org.apache.druid.query.JoinDataSource) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) ComparableStringArray(org.apache.druid.segment.data.ComparableStringArray) GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) ExpectedException(org.junit.rules.ExpectedException) Sequences(org.apache.druid.java.util.common.guava.Sequences) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Before(org.junit.Before) VersionedIntervalTimeline(org.apache.druid.timeline.VersionedIntervalTimeline) InlineDataSource(org.apache.druid.query.InlineDataSource) GroupByStrategyV2(org.apache.druid.query.groupby.strategy.GroupByStrategyV2) ResponseContext(org.apache.druid.query.context.ResponseContext) ServerConfig(org.apache.druid.server.initialization.ServerConfig) TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GroupByQueryConfig(org.apache.druid.query.groupby.GroupByQueryConfig) QueryRunnerFactoryConglomerate(org.apache.druid.query.QueryRunnerFactoryConglomerate) Test(org.junit.Test) IOException(java.io.IOException) ReferenceCountingSegment(org.apache.druid.segment.ReferenceCountingSegment) TableDataSource(org.apache.druid.query.TableDataSource) Granularities(org.apache.druid.java.util.common.granularity.Granularities) TestHelper(org.apache.druid.segment.TestHelper) Rule(org.junit.Rule) UnionDataSource(org.apache.druid.query.UnionDataSource) NullHandling(org.apache.druid.common.config.NullHandling) RowSignature(org.apache.druid.segment.column.RowSignature) GroupByQueryHelper(org.apache.druid.query.groupby.GroupByQueryHelper) ResourceLimitExceededException(org.apache.druid.query.ResourceLimitExceededException) ColumnType(org.apache.druid.segment.column.ColumnType) NoQueryLaningStrategy(org.apache.druid.server.scheduling.NoQueryLaningStrategy) SegmentDescriptor(org.apache.druid.query.SegmentDescriptor) Assert(org.junit.Assert) Comparator(java.util.Comparator) Collections(java.util.Collections) ReferenceCountingSegment(org.apache.druid.segment.ReferenceCountingSegment) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) ScanQuery(org.apache.druid.query.scan.ScanQuery) TopNQuery(org.apache.druid.query.topn.TopNQuery) Query(org.apache.druid.query.Query) GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) MapJoinableFactory(org.apache.druid.segment.join.MapJoinableFactory) InlineJoinableFactory(org.apache.druid.segment.join.InlineJoinableFactory) JoinableFactory(org.apache.druid.segment.join.JoinableFactory) DataSource(org.apache.druid.query.DataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) JoinDataSource(org.apache.druid.query.JoinDataSource) InlineDataSource(org.apache.druid.query.InlineDataSource) TableDataSource(org.apache.druid.query.TableDataSource) UnionDataSource(org.apache.druid.query.UnionDataSource) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) InlineSegmentWrangler(org.apache.druid.segment.InlineSegmentWrangler) ServerConfig(org.apache.druid.server.initialization.ServerConfig) SegmentWrangler(org.apache.druid.segment.SegmentWrangler) MapSegmentWrangler(org.apache.druid.segment.MapSegmentWrangler) InlineSegmentWrangler(org.apache.druid.segment.InlineSegmentWrangler) InlineDataSource(org.apache.druid.query.InlineDataSource) Joinable(org.apache.druid.segment.join.Joinable) MapSegmentWrangler(org.apache.druid.segment.MapSegmentWrangler) InlineJoinableFactory(org.apache.druid.segment.join.InlineJoinableFactory) MapJoinableFactory(org.apache.druid.segment.join.MapJoinableFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with JoinConditionAnalysis

use of org.apache.druid.segment.join.JoinConditionAnalysis in project druid by druid-io.

the class LookupJoinMatcherTest method testMatchConditionAlwaysTrue.

@Test
public void testMatchConditionAlwaysTrue() {
    JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression("1", PREFIX, ExprMacroTable.nil());
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, true);
    // Test match first
    target.matchCondition();
    Assert.assertTrue(target.hasMatch());
    verifyMatch("foo", "bar");
    // Test match second
    target.nextMatch();
    Assert.assertTrue(target.hasMatch());
    verifyMatch("null", "");
    // Test match third
    target.nextMatch();
    Assert.assertTrue(target.hasMatch());
    verifyMatch("empty String", "");
    // Test match forth
    target.nextMatch();
    Assert.assertTrue(target.hasMatch());
    verifyMatch("", "empty_string");
    // Test no more
    target.nextMatch();
    Assert.assertFalse(target.hasMatch());
}
Also used : JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Example 3 with JoinConditionAnalysis

use of org.apache.druid.segment.join.JoinConditionAnalysis in project druid by druid-io.

the class LookupJoinMatcherTest method testMatchConditionAlwaysFalse.

@Test
public void testMatchConditionAlwaysFalse() {
    JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression("0", PREFIX, ExprMacroTable.nil());
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, true);
    // Test match first
    target.matchCondition();
    Assert.assertFalse(target.hasMatch());
    verifyMatch(null, null);
}
Also used : JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Example 4 with JoinConditionAnalysis

use of org.apache.druid.segment.join.JoinConditionAnalysis in project druid by druid-io.

the class LookupJoinMatcherTest method testMatchEmptyRow.

@Test
public void testMatchEmptyRow() {
    ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[] {});
    Mockito.doReturn(dimensionSelector).when(leftSelectorFactory).makeDimensionSelector(ArgumentMatchers.any(DimensionSpec.class));
    Mockito.doReturn(row).when(dimensionSelector).getRow();
    JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression(StringUtils.format("\"%sk\" == foo", PREFIX), PREFIX, ExprMacroTable.nil());
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, true);
    target.matchCondition();
    Assert.assertFalse(target.hasMatch());
}
Also used : DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Example 5 with JoinConditionAnalysis

use of org.apache.druid.segment.join.JoinConditionAnalysis in project druid by druid-io.

the class LookupJoinMatcherTest method testCreateConditionAlwaysTrueShouldReturnSuccessfullyAndNotThrowException.

@Test
public void testCreateConditionAlwaysTrueShouldReturnSuccessfullyAndNotThrowException() {
    JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression("1", PREFIX, ExprMacroTable.nil());
    Mockito.doReturn(true).when(extractor).canIterate();
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, false);
    Assert.assertNotNull(target);
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, true);
    Assert.assertNotNull(target);
}
Also used : JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Aggregations

JoinConditionAnalysis (org.apache.druid.segment.join.JoinConditionAnalysis)12 Test (org.junit.Test)10 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 DataSource (org.apache.druid.query.DataSource)3 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)3 Optional (java.util.Optional)2 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1