Search in sources :

Example 1 with IndexedTableJoinable

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

the class HashJoinSegmentStorageAdapterTest method test_makeCursors_factToCountryUsingExpression.

@Test
public void test_makeCursors_factToCountryUsingExpression() {
    List<JoinableClause> joinableClauses = ImmutableList.of(new JoinableClause(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, new IndexedTableJoinable(countriesTable), JoinType.INNER, JoinConditionAnalysis.forExpression(StringUtils.format("\"%scountryIsoCode\" == concat(substring(countryIsoCode, 0, 1),'L')", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX), FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, ExprMacroTable.nil())));
    JoinFilterPreAnalysis joinFilterPreAnalysis = makeDefaultConfigPreAnalysis(null, joinableClauses, VirtualColumns.EMPTY);
    JoinTestHelper.verifyCursors(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), joinableClauses, joinFilterPreAnalysis).makeCursors(null, Intervals.ETERNITY, VirtualColumns.EMPTY, Granularities.ALL, false, null), ImmutableList.of("page", "countryIsoCode", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryIsoCode", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryName"), ImmutableList.of(new Object[] { "Golpe de Estado en Chile de 1973", "CL", "CL", "Chile" }, new Object[] { "Didier Leclair", "CA", "CL", "Chile" }, new Object[] { "Les Argonautes", "CA", "CL", "Chile" }, new Object[] { "Sarah Michelle Gellar", "CA", "CL", "Chile" }));
}
Also used : JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) Test(org.junit.Test)

Example 2 with IndexedTableJoinable

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

the class HashJoinSegmentTest method setUp.

@Before
public void setUp() throws IOException {
    allReferencesAcquireCount = 0;
    allReferencesCloseCount = 0;
    referencedSegmentAcquireCount = 0;
    referencedSegmentClosedCount = 0;
    indexedTableJoinableReferenceAcquireCount = 0;
    indexedTableJoinableReferenceCloseCount = 0;
    j0Closed = false;
    j1Closed = false;
    baseSegment = new QueryableIndexSegment(JoinTestHelper.createFactIndexBuilder(temporaryFolder.newFolder()).buildMMappedIndex(), SegmentId.dummy("facts"));
    List<JoinableClause> joinableClauses = ImmutableList.of(new JoinableClause("j0.", new IndexedTableJoinable(JoinTestHelper.createCountriesIndexedTable()) {

        @Override
        public Optional<Closeable> acquireReferences() {
            if (!j0Closed) {
                indexedTableJoinableReferenceAcquireCount++;
                Closer closer = Closer.create();
                closer.register(() -> indexedTableJoinableReferenceCloseCount++);
                return Optional.of(closer);
            }
            return Optional.empty();
        }
    }, JoinType.LEFT, JoinConditionAnalysis.forExpression("1", "j0.", ExprMacroTable.nil())), new JoinableClause("j1.", new IndexedTableJoinable(JoinTestHelper.createRegionsIndexedTable()) {

        @Override
        public Optional<Closeable> acquireReferences() {
            if (!j1Closed) {
                indexedTableJoinableReferenceAcquireCount++;
                Closer closer = Closer.create();
                closer.register(() -> indexedTableJoinableReferenceCloseCount++);
                return Optional.of(closer);
            }
            return Optional.empty();
        }
    }, JoinType.LEFT, JoinConditionAnalysis.forExpression("1", "j1.", ExprMacroTable.nil())));
    referencedSegment = ReferenceCountingSegment.wrapRootGenerationSegment(baseSegment);
    SegmentReference testWrapper = new SegmentReference() {

        @Override
        public Optional<Closeable> acquireReferences() {
            Closer closer = Closer.create();
            return referencedSegment.acquireReferences().map(closeable -> {
                referencedSegmentAcquireCount++;
                closer.register(closeable);
                closer.register(() -> referencedSegmentClosedCount++);
                return closer;
            });
        }

        @Override
        public SegmentId getId() {
            return referencedSegment.getId();
        }

        @Override
        public Interval getDataInterval() {
            return referencedSegment.getDataInterval();
        }

        @Nullable
        @Override
        public QueryableIndex asQueryableIndex() {
            return referencedSegment.asQueryableIndex();
        }

        @Override
        public StorageAdapter asStorageAdapter() {
            return referencedSegment.asStorageAdapter();
        }

        @Override
        public void close() {
            referencedSegment.close();
        }
    };
    hashJoinSegment = new HashJoinSegment(testWrapper, null, joinableClauses, null) {

        @Override
        public Optional<Closeable> acquireReferences() {
            Closer closer = Closer.create();
            return super.acquireReferences().map(closeable -> {
                allReferencesAcquireCount++;
                closer.register(closeable);
                closer.register(() -> allReferencesCloseCount++);
                return closer;
            });
        }
    };
}
Also used : QueryableIndexSegment(org.apache.druid.segment.QueryableIndexSegment) Closer(org.apache.druid.java.util.common.io.Closer) CoreMatchers(org.hamcrest.CoreMatchers) Closer(org.apache.druid.java.util.common.io.Closer) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) QueryableIndex(org.apache.druid.segment.QueryableIndex) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) IOException(java.io.IOException) ReferenceCountingSegment(org.apache.druid.segment.ReferenceCountingSegment) StorageAdapter(org.apache.druid.segment.StorageAdapter) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) SegmentReference(org.apache.druid.segment.SegmentReference) Interval(org.joda.time.Interval) List(java.util.List) Rule(org.junit.Rule) ImmutableList(com.google.common.collect.ImmutableList) Closeable(java.io.Closeable) Optional(java.util.Optional) SegmentId(org.apache.druid.timeline.SegmentId) Assert(org.junit.Assert) QueryableIndexSegment(org.apache.druid.segment.QueryableIndexSegment) ExpectedException(org.junit.rules.ExpectedException) TemporaryFolder(org.junit.rules.TemporaryFolder) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Optional(java.util.Optional) Closeable(java.io.Closeable) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) SegmentReference(org.apache.druid.segment.SegmentReference) Before(org.junit.Before)

Example 3 with IndexedTableJoinable

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

the class JoinFilterAnalyzerTest method test_filterPushDown_factToRegionToCountryLeftFilterOnRHSJoinConditionColumnsHelper.

private void test_filterPushDown_factToRegionToCountryLeftFilterOnRHSJoinConditionColumnsHelper(boolean hasLhsExpressionInJoinCondition) {
    Filter expressionFilter = new ExpressionDimFilter("\"rtc.countryIsoCode\" == 'CA'", ExprMacroTable.nil()).toFilter();
    Filter specialSelectorFilter = new SelectorFilter("rtc.countryIsoCode", "CA") {

        @Override
        public boolean supportsRequiredColumnRewrite() {
            return false;
        }
    };
    Filter originalFilter = new AndFilter(ImmutableList.of(new SelectorFilter("r1.regionIsoCode", "ON"), new SelectorFilter("rtc.countryIsoCode", "CA"), specialSelectorFilter, new BoundFilter(new BoundDimFilter("rtc.countryIsoCode", "CA", "CB", false, false, null, null, null)), expressionFilter, new InDimFilter("rtc.countryIsoCode", ImmutableSet.of("CA", "CA2", "CA3"), null, null).toFilter(), new OrFilter(ImmutableList.of(new SelectorFilter("channel", "#fr.wikipedia"), new SelectorFilter("rtc.countryIsoCode", "QQQ"), new BoundFilter(new BoundDimFilter("rtc.countryIsoCode", "YYY", "ZZZ", false, false, null, null, null)))), new OrFilter(ImmutableList.of(new SelectorFilter("namespace", "Main"), new SelectorFilter("rtc.countryIsoCode", "ABCDEF"), new SelectorFilter("rtc.countryName", "Canada"), new BoundFilter(new BoundDimFilter("rtc.countryIsoCode", "XYZXYZ", "XYZXYZ", false, false, null, null, null))))));
    JoinableClause factToRegionClause;
    if (hasLhsExpressionInJoinCondition) {
        factToRegionClause = new JoinableClause(FACT_TO_REGION_PREFIX, new IndexedTableJoinable(regionsTable), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("\"%sregionIsoCode\" == upper(lower(regionIsoCode)) && \"%scountryIsoCode\" == upper(lower(countryIsoCode))", FACT_TO_REGION_PREFIX, FACT_TO_REGION_PREFIX), FACT_TO_REGION_PREFIX, ExprMacroTable.nil()));
    } else {
        factToRegionClause = factToRegion(JoinType.LEFT);
    }
    List<JoinableClause> joinableClauses = ImmutableList.of(factToRegionClause, regionToCountry(JoinType.LEFT));
    JoinFilterPreAnalysis joinFilterPreAnalysis = makeDefaultConfigPreAnalysis(originalFilter, joinableClauses, VirtualColumns.EMPTY);
    HashJoinSegmentStorageAdapter adapter = new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), joinableClauses, joinFilterPreAnalysis);
    String rewrittenCountryIsoCodeColumnName = hasLhsExpressionInJoinCondition ? "JOIN-FILTER-PUSHDOWN-VIRTUAL-COLUMN-1" : "countryIsoCode";
    String rewrittenRegionIsoCodeColumnName = hasLhsExpressionInJoinCondition ? "JOIN-FILTER-PUSHDOWN-VIRTUAL-COLUMN-0" : "regionIsoCode";
    Set<VirtualColumn> expectedVirtualColumns;
    if (hasLhsExpressionInJoinCondition) {
        expectedVirtualColumns = ImmutableSet.of(new ExpressionVirtualColumn(rewrittenRegionIsoCodeColumnName, "(upper [(lower [regionIsoCode])])", ColumnType.STRING, ExprMacroTable.nil()), new ExpressionVirtualColumn(rewrittenCountryIsoCodeColumnName, "(upper [(lower [countryIsoCode])])", ColumnType.STRING, ExprMacroTable.nil()));
    } else {
        expectedVirtualColumns = ImmutableSet.of();
    }
    JoinTestHelper.verifyCursors(adapter.makeCursors(originalFilter, Intervals.ETERNITY, VirtualColumns.EMPTY, Granularities.ALL, false, null), ImmutableList.of("page", FACT_TO_REGION_PREFIX + "regionName", REGION_TO_COUNTRY_PREFIX + "countryName"), ImmutableList.of(new Object[] { "Didier Leclair", "Ontario", "Canada" }));
    JoinFilterSplit expectedFilterSplit = new JoinFilterSplit(new AndFilter(ImmutableList.of(new SelectorFilter(rewrittenRegionIsoCodeColumnName, "ON"), new SelectorFilter(rewrittenCountryIsoCodeColumnName, "CA"), new InDimFilter(rewrittenCountryIsoCodeColumnName, ImmutableSet.of("CA"), null, null).toFilter(), new BoundFilter(new BoundDimFilter(rewrittenCountryIsoCodeColumnName, "CA", "CB", false, false, null, null, null)), new InDimFilter(rewrittenCountryIsoCodeColumnName, ImmutableSet.of("CA", "CA2", "CA3"), null, null).toFilter(), new OrFilter(ImmutableList.of(new SelectorFilter("channel", "#fr.wikipedia"), new SelectorFilter(rewrittenCountryIsoCodeColumnName, "QQQ"), new BoundFilter(new BoundDimFilter(rewrittenCountryIsoCodeColumnName, "YYY", "ZZZ", false, false, null, null, null)))), new OrFilter(ImmutableList.of(new SelectorFilter("namespace", "Main"), new SelectorFilter(rewrittenCountryIsoCodeColumnName, "ABCDEF"), new InDimFilter(rewrittenCountryIsoCodeColumnName, ImmutableSet.of("CA"), null, null).toFilter(), new BoundFilter(new BoundDimFilter(rewrittenCountryIsoCodeColumnName, "XYZXYZ", "XYZXYZ", false, false, null, null, null)))))), new AndFilter(ImmutableList.of(specialSelectorFilter, expressionFilter, new OrFilter(ImmutableList.of(new SelectorFilter("namespace", "Main"), new SelectorFilter("rtc.countryIsoCode", "ABCDEF"), new SelectorFilter("rtc.countryName", "Canada"), new BoundFilter(new BoundDimFilter("rtc.countryIsoCode", "XYZXYZ", "XYZXYZ", false, false, null, null, null)))))), expectedVirtualColumns);
    JoinFilterSplit actualFilterSplit = JoinFilterAnalyzer.splitFilter(joinFilterPreAnalysis);
    Assert.assertEquals(expectedFilterSplit, actualFilterSplit);
}
Also used : BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) BoundFilter(org.apache.druid.segment.filter.BoundFilter) JoinFilterSplit(org.apache.druid.segment.join.filter.JoinFilterSplit) OrFilter(org.apache.druid.segment.filter.OrFilter) AndFilter(org.apache.druid.segment.filter.AndFilter) SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) FalseFilter(org.apache.druid.segment.filter.FalseFilter) OrFilter(org.apache.druid.segment.filter.OrFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) AndFilter(org.apache.druid.segment.filter.AndFilter) BoundFilter(org.apache.druid.segment.filter.BoundFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Filter(org.apache.druid.query.filter.Filter) InDimFilter(org.apache.druid.query.filter.InDimFilter) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) VirtualColumn(org.apache.druid.segment.VirtualColumn) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter)

Example 4 with IndexedTableJoinable

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

the class JoinFilterAnalyzerTest method test_filterPushDown_factToRegionExprToCountryLeftFilterOnCountryName.

@Test
public void test_filterPushDown_factToRegionExprToCountryLeftFilterOnCountryName() {
    Filter originalFilter = new SelectorFilter("rtc.countryName", "United States");
    JoinableClause regionExprToCountry = new JoinableClause(REGION_TO_COUNTRY_PREFIX, new IndexedTableJoinable(countriesTable), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("reverse(\"%scountryIsoCode\") == \"%scountryIsoCode\"", FACT_TO_REGION_PREFIX, REGION_TO_COUNTRY_PREFIX), REGION_TO_COUNTRY_PREFIX, ExprMacroTable.nil()));
    List<JoinableClause> joinableClauses = ImmutableList.of(factToRegion(JoinType.LEFT), regionExprToCountry);
    JoinFilterPreAnalysis joinFilterPreAnalysis = makeDefaultConfigPreAnalysis(originalFilter, joinableClauses, VirtualColumns.EMPTY);
    HashJoinSegmentStorageAdapter adapter = new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), joinableClauses, joinFilterPreAnalysis);
    JoinTestHelper.verifyCursors(adapter.makeCursors(originalFilter, Intervals.ETERNITY, VirtualColumns.EMPTY, Granularities.ALL, false, null), ImmutableList.of("page", FACT_TO_REGION_PREFIX + "regionName", REGION_TO_COUNTRY_PREFIX + "countryName"), ImmutableList.of(new Object[] { "Cream Soda", "Ainigriv", "United States" }));
    JoinFilterSplit expectedFilterSplit = new JoinFilterSplit(null, new SelectorFilter("rtc.countryName", "United States"), ImmutableSet.of());
    JoinFilterSplit actualFilterSplit = JoinFilterAnalyzer.splitFilter(joinFilterPreAnalysis);
    Assert.assertEquals(expectedFilterSplit, actualFilterSplit);
}
Also used : SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) FalseFilter(org.apache.druid.segment.filter.FalseFilter) OrFilter(org.apache.druid.segment.filter.OrFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) AndFilter(org.apache.druid.segment.filter.AndFilter) BoundFilter(org.apache.druid.segment.filter.BoundFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Filter(org.apache.druid.query.filter.Filter) JoinFilterSplit(org.apache.druid.segment.join.filter.JoinFilterSplit) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) Test(org.junit.Test)

Example 5 with IndexedTableJoinable

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

the class JoinFilterAnalyzerTest method test_filterPushDown_factConcatExpressionToCountryLeftFilterOnChannelAndCountryName.

@Test
public void test_filterPushDown_factConcatExpressionToCountryLeftFilterOnChannelAndCountryName() {
    JoinableClause factExprToCountry = new JoinableClause(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, new IndexedTableJoinable(countriesTable), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("\"%scountryIsoCode\" == concat(countryIsoCode, regionIsoCode)", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX), FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, ExprMacroTable.nil()));
    List<JoinableClause> joinableClauses = ImmutableList.of(factExprToCountry);
    Filter filter = new AndFilter(ImmutableList.of(new SelectorFilter("channel", "#en.wikipedia"), new SelectorFilter("c1.countryName", "Usca")));
    JoinFilterPreAnalysis joinFilterPreAnalysis = makeDefaultConfigPreAnalysis(filter, joinableClauses, VirtualColumns.EMPTY);
    HashJoinSegmentStorageAdapter adapter = new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), joinableClauses, joinFilterPreAnalysis);
    JoinTestHelper.verifyCursors(adapter.makeCursors(filter, Intervals.ETERNITY, VirtualColumns.EMPTY, Granularities.ALL, false, null), ImmutableList.of("page", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryName"), ImmutableList.of(new Object[] { "President of India", "Usca" }, new Object[] { "Otjiwarongo Airport", "Usca" }, new Object[] { "Carlo Curti", "Usca" }));
    ExpressionVirtualColumn expectedVirtualColumn = new ExpressionVirtualColumn("JOIN-FILTER-PUSHDOWN-VIRTUAL-COLUMN-0", "concat(countryIsoCode, regionIsoCode)", ColumnType.STRING, ExprMacroTable.nil());
    JoinFilterSplit expectedFilterSplit = new JoinFilterSplit(new AndFilter(ImmutableList.of(new SelectorFilter("channel", "#en.wikipedia"), new InDimFilter("JOIN-FILTER-PUSHDOWN-VIRTUAL-COLUMN-0", ImmutableSet.of("USCA"), null, null).toFilter())), new SelectorFilter("c1.countryName", "Usca"), ImmutableSet.of(expectedVirtualColumn));
    JoinFilterSplit actualFilterSplit = JoinFilterAnalyzer.splitFilter(joinFilterPreAnalysis);
    Assert.assertEquals(expectedFilterSplit.getBaseTableFilter(), actualFilterSplit.getBaseTableFilter());
    Assert.assertEquals(expectedFilterSplit.getJoinTableFilter(), actualFilterSplit.getJoinTableFilter());
    ExpressionVirtualColumn actualVirtualColumn = (ExpressionVirtualColumn) actualFilterSplit.getPushDownVirtualColumns().iterator().next();
    compareExpressionVirtualColumns(expectedVirtualColumn, actualVirtualColumn);
}
Also used : AndFilter(org.apache.druid.segment.filter.AndFilter) SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) FalseFilter(org.apache.druid.segment.filter.FalseFilter) OrFilter(org.apache.druid.segment.filter.OrFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) AndFilter(org.apache.druid.segment.filter.AndFilter) BoundFilter(org.apache.druid.segment.filter.BoundFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Filter(org.apache.druid.query.filter.Filter) JoinFilterSplit(org.apache.druid.segment.join.filter.JoinFilterSplit) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) InDimFilter(org.apache.druid.query.filter.InDimFilter) Test(org.junit.Test)

Aggregations

IndexedTableJoinable (org.apache.druid.segment.join.table.IndexedTableJoinable)23 JoinFilterPreAnalysis (org.apache.druid.segment.join.filter.JoinFilterPreAnalysis)19 Test (org.junit.Test)19 ExpressionDimFilter (org.apache.druid.query.filter.ExpressionDimFilter)13 Filter (org.apache.druid.query.filter.Filter)13 SelectorFilter (org.apache.druid.segment.filter.SelectorFilter)13 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)9 InDimFilter (org.apache.druid.query.filter.InDimFilter)9 AndFilter (org.apache.druid.segment.filter.AndFilter)9 BoundFilter (org.apache.druid.segment.filter.BoundFilter)9 FalseFilter (org.apache.druid.segment.filter.FalseFilter)9 OrFilter (org.apache.druid.segment.filter.OrFilter)9 JoinFilterSplit (org.apache.druid.segment.join.filter.JoinFilterSplit)8 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)4 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)4 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)4 JoinFilterPreAnalysisKey (org.apache.druid.segment.join.filter.JoinFilterPreAnalysisKey)3 JoinFilterRewriteConfig (org.apache.druid.segment.join.filter.rewrite.JoinFilterRewriteConfig)3 Optional (java.util.Optional)2 ExprMacroTable (org.apache.druid.math.expr.ExprMacroTable)2