Search in sources :

Example 1 with TestQuery

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

the class JoinableFactoryWrapperTest method test_createSegmentMapFn_usableClause.

@Test
public void test_createSegmentMapFn_usableClause() {
    final LookupDataSource lookupDataSource = new LookupDataSource("lookyloo");
    final JoinConditionAnalysis conditionAnalysis = JoinConditionAnalysis.forExpression("x == \"j.x\"", "j.", ExprMacroTable.nil());
    final PreJoinableClause clause = new PreJoinableClause("j.", lookupDataSource, JoinType.LEFT, conditionAnalysis);
    JoinableFactoryWrapper joinableFactoryWrapper = new JoinableFactoryWrapper(new JoinableFactory() {

        @Override
        public boolean isDirectlyJoinable(DataSource dataSource) {
            return dataSource.equals(lookupDataSource);
        }

        @Override
        public Optional<Joinable> build(DataSource dataSource, JoinConditionAnalysis condition) {
            if (dataSource.equals(lookupDataSource) && condition.equals(conditionAnalysis)) {
                return Optional.of(LookupJoinable.wrap(new MapLookupExtractor(ImmutableMap.of("k", "v"), false)));
            } else {
                return Optional.empty();
            }
        }
    });
    final Function<SegmentReference, SegmentReference> segmentMapFn = joinableFactoryWrapper.createSegmentMapFn(null, ImmutableList.of(clause), new AtomicLong(), new TestQuery(new TableDataSource("test"), new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("0/100"))), false, new HashMap()));
    Assert.assertNotSame(Function.identity(), segmentMapFn);
}
Also used : TestQuery(org.apache.druid.query.TestQuery) PreJoinableClause(org.apache.druid.query.planning.PreJoinableClause) Optional(java.util.Optional) HashMap(java.util.HashMap) SegmentReference(org.apache.druid.segment.SegmentReference) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) DataSource(org.apache.druid.query.DataSource) TableDataSource(org.apache.druid.query.TableDataSource) AtomicLong(java.util.concurrent.atomic.AtomicLong) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) NullHandlingTest(org.apache.druid.common.config.NullHandlingTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)1 DataSource (org.apache.druid.query.DataSource)1 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)1 LookupDataSource (org.apache.druid.query.LookupDataSource)1 TableDataSource (org.apache.druid.query.TableDataSource)1 TestQuery (org.apache.druid.query.TestQuery)1 MapLookupExtractor (org.apache.druid.query.extraction.MapLookupExtractor)1 PreJoinableClause (org.apache.druid.query.planning.PreJoinableClause)1 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)1 SegmentReference (org.apache.druid.segment.SegmentReference)1 Test (org.junit.Test)1