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);
}
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());
}
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);
}
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());
}
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);
}
Aggregations