Search in sources :

Example 11 with PreJoinableClause

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

the class JoinableFactoryWrapperTest method test_computeJoinDataSourceCacheKey_usableClauses.

@Test
public void test_computeJoinDataSourceCacheKey_usableClauses() {
    PreJoinableClause clause1 = makeGlobalPreJoinableClause("dataSource_1", "x == \"j.x\"", "j.");
    PreJoinableClause clause2 = makeGlobalPreJoinableClause("dataSource_2", "x == \"h.x\"", "h.");
    DataSourceAnalysis analysis = EasyMock.mock(DataSourceAnalysis.class);
    EasyMock.expect(analysis.getPreJoinableClauses()).andReturn(Arrays.asList(clause1, clause2)).anyTimes();
    EasyMock.expect(analysis.getJoinBaseTableFilter()).andReturn(Optional.empty()).anyTimes();
    EasyMock.replay(analysis);
    JoinableFactoryWrapper joinableFactoryWrapper = new JoinableFactoryWrapper(new JoinableFactoryWithCacheKey());
    Optional<byte[]> cacheKey = joinableFactoryWrapper.computeJoinDataSourceCacheKey(analysis);
    Assert.assertTrue(cacheKey.isPresent());
}
Also used : PreJoinableClause(org.apache.druid.query.planning.PreJoinableClause) DataSourceAnalysis(org.apache.druid.query.planning.DataSourceAnalysis) NullHandlingTest(org.apache.druid.common.config.NullHandlingTest) Test(org.junit.Test)

Example 12 with PreJoinableClause

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

the class JoinableFactoryWrapperTest method test_computeJoinDataSourceCacheKey_keyChangesWithJoinable.

@Test
public void test_computeJoinDataSourceCacheKey_keyChangesWithJoinable() {
    DataSourceAnalysis analysis = EasyMock.mock(DataSourceAnalysis.class);
    EasyMock.expect(analysis.getJoinBaseTableFilter()).andReturn(Optional.empty()).anyTimes();
    JoinableFactoryWrapper joinableFactoryWrapper = new JoinableFactoryWrapper(new JoinableFactoryWithCacheKey());
    PreJoinableClause clause1 = makeGlobalPreJoinableClause("dataSource_1", "x == \"j.x\"", "j.");
    EasyMock.expect(analysis.getPreJoinableClauses()).andReturn(Collections.singletonList(clause1)).anyTimes();
    EasyMock.replay(analysis);
    Optional<byte[]> cacheKey1 = joinableFactoryWrapper.computeJoinDataSourceCacheKey(analysis);
    Assert.assertTrue(cacheKey1.isPresent());
    Assert.assertNotEquals(0, cacheKey1.get().length);
    PreJoinableClause clause2 = makeGlobalPreJoinableClause("dataSource_2", "x == \"j.x\"", "j.");
    EasyMock.reset(analysis);
    EasyMock.expect(analysis.getPreJoinableClauses()).andReturn(Collections.singletonList(clause2)).anyTimes();
    EasyMock.expect(analysis.getJoinBaseTableFilter()).andReturn(Optional.empty()).anyTimes();
    EasyMock.replay(analysis);
    Optional<byte[]> cacheKey2 = joinableFactoryWrapper.computeJoinDataSourceCacheKey(analysis);
    Assert.assertTrue(cacheKey2.isPresent());
    Assert.assertFalse(Arrays.equals(cacheKey1.get(), cacheKey2.get()));
}
Also used : PreJoinableClause(org.apache.druid.query.planning.PreJoinableClause) DataSourceAnalysis(org.apache.druid.query.planning.DataSourceAnalysis) NullHandlingTest(org.apache.druid.common.config.NullHandlingTest) Test(org.junit.Test)

Example 13 with PreJoinableClause

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

the class JoinableFactoryWrapperTest method test_createSegmentMapFn_unusableClause.

@Test
public void test_createSegmentMapFn_unusableClause() {
    final LookupDataSource lookupDataSource = new LookupDataSource("lookyloo");
    final PreJoinableClause clause = new PreJoinableClause("j.", lookupDataSource, JoinType.LEFT, JoinConditionAnalysis.forExpression("x == \"j.x\"", "j.", ExprMacroTable.nil()));
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("dataSource is not joinable");
    final Function<SegmentReference, SegmentReference> ignored = NOOP_JOINABLE_FACTORY_WRAPPER.createSegmentMapFn(null, ImmutableList.of(clause), new AtomicLong(), null);
}
Also used : PreJoinableClause(org.apache.druid.query.planning.PreJoinableClause) AtomicLong(java.util.concurrent.atomic.AtomicLong) LookupDataSource(org.apache.druid.query.LookupDataSource) SegmentReference(org.apache.druid.segment.SegmentReference) NullHandlingTest(org.apache.druid.common.config.NullHandlingTest) Test(org.junit.Test)

Example 14 with PreJoinableClause

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

the class JoinableFactoryWrapperTest method test_computeJoinDataSourceCacheKey_keyChangesWithBaseFilter.

@Test
public void test_computeJoinDataSourceCacheKey_keyChangesWithBaseFilter() {
    DataSourceAnalysis analysis = EasyMock.mock(DataSourceAnalysis.class);
    EasyMock.expect(analysis.getJoinBaseTableFilter()).andReturn(Optional.of(TrueDimFilter.instance())).anyTimes();
    JoinableFactoryWrapper joinableFactoryWrapper = new JoinableFactoryWrapper(new JoinableFactoryWithCacheKey());
    PreJoinableClause clause1 = makeGlobalPreJoinableClause("dataSource_1", "abc == xyz", "ab");
    EasyMock.expect(analysis.getPreJoinableClauses()).andReturn(Collections.singletonList(clause1)).anyTimes();
    EasyMock.replay(analysis);
    Optional<byte[]> cacheKey1 = joinableFactoryWrapper.computeJoinDataSourceCacheKey(analysis);
    Assert.assertTrue(cacheKey1.isPresent());
    Assert.assertNotEquals(0, cacheKey1.get().length);
    PreJoinableClause clause2 = makeGlobalPreJoinableClause("dataSource_1", "abc == xyz", "ab");
    EasyMock.reset(analysis);
    EasyMock.expect(analysis.getPreJoinableClauses()).andReturn(Collections.singletonList(clause2)).anyTimes();
    EasyMock.expect(analysis.getJoinBaseTableFilter()).andReturn(Optional.of(FalseDimFilter.instance())).anyTimes();
    EasyMock.replay(analysis);
    Optional<byte[]> cacheKey2 = joinableFactoryWrapper.computeJoinDataSourceCacheKey(analysis);
    Assert.assertTrue(cacheKey2.isPresent());
    Assert.assertFalse(Arrays.equals(cacheKey1.get(), cacheKey2.get()));
}
Also used : PreJoinableClause(org.apache.druid.query.planning.PreJoinableClause) DataSourceAnalysis(org.apache.druid.query.planning.DataSourceAnalysis) NullHandlingTest(org.apache.druid.common.config.NullHandlingTest) Test(org.junit.Test)

Example 15 with PreJoinableClause

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

the class JoinableClauses method checkPreJoinableClausesForDuplicatesAndShadowing.

private static void checkPreJoinableClausesForDuplicatesAndShadowing(final List<PreJoinableClause> preJoinableClauses) {
    List<String> prefixes = new ArrayList<>();
    for (PreJoinableClause clause : preJoinableClauses) {
        prefixes.add(clause.getPrefix());
    }
    JoinPrefixUtils.checkPrefixesForDuplicatesAndShadowing(prefixes);
}
Also used : PreJoinableClause(org.apache.druid.query.planning.PreJoinableClause) ArrayList(java.util.ArrayList)

Aggregations

PreJoinableClause (org.apache.druid.query.planning.PreJoinableClause)16 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)11 DataSourceAnalysis (org.apache.druid.query.planning.DataSourceAnalysis)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ISE (org.apache.druid.java.util.common.ISE)3 LookupDataSource (org.apache.druid.query.LookupDataSource)3 SegmentReference (org.apache.druid.segment.SegmentReference)3 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 IAE (org.apache.druid.java.util.common.IAE)2 DataSource (org.apache.druid.query.DataSource)2 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)2 TableDataSource (org.apache.druid.query.TableDataSource)2 CacheKeyBuilder (org.apache.druid.query.cache.CacheKeyBuilder)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 HashMultiset (com.google.common.collect.HashMultiset)1