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