Search in sources :

Example 6 with IndexedTableJoinable

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

the class JoinFilterAnalyzerTest method test_filterPushDown_factToRegionExprToCountryLeftFilterOnCountryNameWithMultiLevelMode.

@Test
public void test_filterPushDown_factToRegionExprToCountryLeftFilterOnCountryNameWithMultiLevelMode() {
    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 = JoinFilterAnalyzer.computeJoinFilterPreAnalysis(new JoinFilterPreAnalysisKey(new JoinFilterRewriteConfig(true, true, true, QueryContexts.DEFAULT_ENABLE_REWRITE_JOIN_TO_FILTER, QueryContexts.DEFAULT_ENABLE_JOIN_FILTER_REWRITE_MAX_SIZE), joinableClauses, VirtualColumns.EMPTY, originalFilter));
    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) JoinFilterPreAnalysisKey(org.apache.druid.segment.join.filter.JoinFilterPreAnalysisKey) JoinFilterSplit(org.apache.druid.segment.join.filter.JoinFilterSplit) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) JoinFilterRewriteConfig(org.apache.druid.segment.join.filter.rewrite.JoinFilterRewriteConfig) Test(org.junit.Test)

Example 7 with IndexedTableJoinable

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

the class HashJoinSegmentStorageAdapterTest method test_makeCursors_errorOnNonKeyBasedJoin.

@Test
public void test_makeCursors_errorOnNonKeyBasedJoin() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Cannot build hash-join matcher on non-key-based condition: " + "Equality{leftExpr=x, rightColumn='countryName'}");
    List<JoinableClause> joinableClauses = ImmutableList.of(new JoinableClause(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, new IndexedTableJoinable(countriesTable), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("x == \"%scountryName\"", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX), FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, ExprMacroTable.nil())));
    JoinFilterPreAnalysis joinFilterPreAnalysis = makeDefaultConfigPreAnalysis(null, joinableClauses, VirtualColumns.EMPTY);
    JoinTestHelper.readCursors(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), joinableClauses, joinFilterPreAnalysis).makeCursors(null, Intervals.ETERNITY, VirtualColumns.EMPTY, Granularities.ALL, false, null), ImmutableList.of());
}
Also used : JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) Test(org.junit.Test)

Example 8 with IndexedTableJoinable

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

the class HashJoinSegmentStorageAdapterTest method test_hasBuiltInFiltersForMultipleJoinableClausesWithVariousJoinTypes.

@Test
public void test_hasBuiltInFiltersForMultipleJoinableClausesWithVariousJoinTypes() {
    Assert.assertTrue(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), ImmutableList.of(factToRegion(JoinType.INNER), regionToCountry(JoinType.LEFT)), null).hasBuiltInFilters());
    Assert.assertTrue(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), ImmutableList.of(factToRegion(JoinType.RIGHT), regionToCountry(JoinType.INNER), factToCountryOnNumber(JoinType.FULL)), null).hasBuiltInFilters());
    Assert.assertFalse(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), ImmutableList.of(factToRegion(JoinType.LEFT), regionToCountry(JoinType.LEFT)), null).hasBuiltInFilters());
    Assert.assertFalse(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), ImmutableList.of(factToRegion(JoinType.LEFT), new JoinableClause(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, new IndexedTableJoinable(countriesTable), JoinType.INNER, JoinConditionAnalysis.forExpression("'true'", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, ExprMacroTable.nil()))), null).hasBuiltInFilters());
}
Also used : IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) Test(org.junit.Test)

Example 9 with IndexedTableJoinable

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

the class HashJoinSegmentStorageAdapterTest method test_makeCursors_factToCountryAlwaysFalse.

@Test
public void test_makeCursors_factToCountryAlwaysFalse() {
    List<JoinableClause> joinableClauses = ImmutableList.of(new JoinableClause(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, new IndexedTableJoinable(countriesTable), JoinType.LEFT, JoinConditionAnalysis.forExpression("0", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX, ExprMacroTable.nil())));
    Filter filter = new SelectorDimFilter("channel", "#de.wikipedia", null).toFilter();
    JoinFilterPreAnalysis joinFilterPreAnalysis = makeDefaultConfigPreAnalysis(filter, joinableClauses, VirtualColumns.EMPTY);
    JoinTestHelper.verifyCursors(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), joinableClauses, joinFilterPreAnalysis).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[] { "Diskussion:Sebastian Schulz", null }));
}
Also used : JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Filter(org.apache.druid.query.filter.Filter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) Test(org.junit.Test)

Example 10 with IndexedTableJoinable

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

the class HashJoinSegmentStorageAdapterTest method test_makeCursors_factToRegionTheWrongWay.

@Test
public void test_makeCursors_factToRegionTheWrongWay() {
    // Joins using only regionIsoCode, which is wrong since they are not unique internationally.
    List<JoinableClause> joinableClauses = ImmutableList.of(new JoinableClause(FACT_TO_REGION_PREFIX, new IndexedTableJoinable(regionsTable), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("\"%sregionIsoCode\" == regionIsoCode", FACT_TO_REGION_PREFIX), FACT_TO_REGION_PREFIX, ExprMacroTable.nil())));
    Filter filter = new SelectorDimFilter("regionIsoCode", "VA", null).toFilter();
    JoinFilterPreAnalysis joinFilterPreAnalysis = makeDefaultConfigPreAnalysis(filter, joinableClauses, VirtualColumns.EMPTY);
    JoinTestHelper.verifyCursors(new HashJoinSegmentStorageAdapter(factSegment.asStorageAdapter(), joinableClauses, joinFilterPreAnalysis).makeCursors(filter, Intervals.ETERNITY, VirtualColumns.EMPTY, Granularities.ALL, false, null), ImmutableList.of("page", "regionIsoCode", "countryIsoCode", FACT_TO_REGION_PREFIX + "regionName", FACT_TO_REGION_PREFIX + "countryIsoCode"), ImmutableList.of(new Object[] { "Giusy Ferreri discography", "VA", "IT", "Provincia di Varese", "IT" }, new Object[] { "Giusy Ferreri discography", "VA", "IT", "Virginia", "US" }, new Object[] { "Roma-Bangkok", "VA", "IT", "Provincia di Varese", "IT" }, new Object[] { "Roma-Bangkok", "VA", "IT", "Virginia", "US" }, new Object[] { "Old Anatolian Turkish", "VA", "US", "Provincia di Varese", "IT" }, new Object[] { "Old Anatolian Turkish", "VA", "US", "Virginia", "US" }));
}
Also used : JoinFilterPreAnalysis(org.apache.druid.segment.join.filter.JoinFilterPreAnalysis) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) SelectorFilter(org.apache.druid.segment.filter.SelectorFilter) OrDimFilter(org.apache.druid.query.filter.OrDimFilter) ExpressionDimFilter(org.apache.druid.query.filter.ExpressionDimFilter) Filter(org.apache.druid.query.filter.Filter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) IndexedTableJoinable(org.apache.druid.segment.join.table.IndexedTableJoinable) 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