use of org.apache.druid.query.filter.InDimFilter in project druid by druid-io.
the class JoinFilterAnalyzerTest method test_filterPushDown_factExpressionsToRegionToCountryLeftFilterOnChannelAndCountryName.
@Test
public void test_filterPushDown_factExpressionsToRegionToCountryLeftFilterOnChannelAndCountryName() {
JoinableClause factExprToRegon = new JoinableClause(FACT_TO_REGION_PREFIX, new IndexedTableJoinable(regionsTable), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("\"%sregionIsoCode\" == reverse(regionIsoCode) && \"%scountryIsoCode\" == reverse(countryIsoCode)", FACT_TO_REGION_PREFIX, FACT_TO_REGION_PREFIX), FACT_TO_REGION_PREFIX, ExprMacroTable.nil()));
List<JoinableClause> joinableClauses = ImmutableList.of(factExprToRegon, regionToCountry(JoinType.LEFT));
Filter originalFilter = new AndFilter(ImmutableList.of(new SelectorFilter("channel", "#en.wikipedia"), new SelectorFilter("rtc.countryName", "States United")));
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[] { "Old Anatolian Turkish", "Ainigriv", "States United" }));
JoinFilterSplit expectedFilterSplit = new JoinFilterSplit(new AndFilter(ImmutableList.of(new SelectorFilter("channel", "#en.wikipedia"), new InDimFilter("JOIN-FILTER-PUSHDOWN-VIRTUAL-COLUMN-0", ImmutableSet.of("SU"), null, null).toFilter())), new SelectorFilter("rtc.countryName", "States United"), ImmutableSet.of());
JoinFilterSplit actualFilterSplit = JoinFilterAnalyzer.splitFilter(joinFilterPreAnalysis);
ExpressionVirtualColumn expectedVirtualColumn = new ExpressionVirtualColumn("JOIN-FILTER-PUSHDOWN-VIRTUAL-COLUMN-0", "reverse(countryIsoCode)", ColumnType.STRING, ExprMacroTable.nil());
Assert.assertEquals(expectedFilterSplit.getBaseTableFilter(), actualFilterSplit.getBaseTableFilter());
Assert.assertEquals(expectedFilterSplit.getJoinTableFilter(), actualFilterSplit.getJoinTableFilter());
ExpressionVirtualColumn actualVirtualColumn = (ExpressionVirtualColumn) actualFilterSplit.getPushDownVirtualColumns().iterator().next();
compareExpressionVirtualColumns(expectedVirtualColumn, actualVirtualColumn);
}
use of org.apache.druid.query.filter.InDimFilter in project druid by druid-io.
the class JoinFilterAnalyzerTest method test_filterPushDown_factToRegionOneColumnToTwoRHSColumnsAndFilterOnRHS.
@Test
public void test_filterPushDown_factToRegionOneColumnToTwoRHSColumnsAndFilterOnRHS() {
JoinableClause factExprToRegon = new JoinableClause(FACT_TO_REGION_PREFIX, new IndexedTableJoinable(regionsTable), JoinType.LEFT, JoinConditionAnalysis.forExpression(StringUtils.format("\"%sregionIsoCode\" == regionIsoCode && \"%scountryIsoCode\" == regionIsoCode", FACT_TO_REGION_PREFIX, FACT_TO_REGION_PREFIX), FACT_TO_REGION_PREFIX, ExprMacroTable.nil()));
List<JoinableClause> joinableClauses = ImmutableList.of(factExprToRegon);
Filter originalFilter = new OrFilter(ImmutableList.of(new SelectorFilter("r1.regionName", "Fourems Province"), new SelectorFilter("r1.regionIsoCode", "AAAA")));
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"), ImmutableList.of(new Object[] { "History of Fourems", "Fourems Province" }));
JoinFilterSplit expectedFilterSplit = new JoinFilterSplit(new OrFilter(ImmutableList.of(new InDimFilter("regionIsoCode", ImmutableSet.of("MMMM"), null, null).toFilter(), new SelectorFilter("regionIsoCode", "AAAA"))), originalFilter, ImmutableSet.of());
JoinFilterSplit actualFilterSplit = JoinFilterAnalyzer.splitFilter(joinFilterPreAnalysis);
Assert.assertEquals(expectedFilterSplit, actualFilterSplit);
}
use of org.apache.druid.query.filter.InDimFilter in project druid by druid-io.
the class JoinFilterAnalyzerTest method test_filterPushDown_factToCountryRightWithFilterOnChannelAndJoinable.
@Test
public void test_filterPushDown_factToCountryRightWithFilterOnChannelAndJoinable() {
List<JoinableClause> joinableClauses = ImmutableList.of(factToCountryOnIsoCode(JoinType.RIGHT));
Filter originalFilter = new AndFilter(ImmutableList.of(new SelectorFilter("channel", "#de.wikipedia"), new SelectorFilter(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryName", "Germany")));
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", "countryIsoCode", "countryNumber", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryIsoCode", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryName", FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryNumber"), ImmutableList.of(new Object[] { "Diskussion:Sebastian Schulz", "DE", 3L, "DE", "Germany", 3L }));
JoinFilterSplit expectedFilterSplit = new JoinFilterSplit(new AndFilter(ImmutableList.of(new SelectorFilter("channel", "#de.wikipedia"), new InDimFilter("countryIsoCode", ImmutableSet.of("DE"), null, null).toFilter())), new SelectorFilter(FACT_TO_COUNTRY_ON_ISO_CODE_PREFIX + "countryName", "Germany"), ImmutableSet.of());
JoinFilterSplit actualFilterSplit = JoinFilterAnalyzer.splitFilter(joinFilterPreAnalysis);
Assert.assertEquals(expectedFilterSplit, actualFilterSplit);
}
use of org.apache.druid.query.filter.InDimFilter in project druid by druid-io.
the class JoinableFactoryWrapperTest method test_convertJoinsToFilters_dontConvertJoinsDependedOnByLaterJoins2.
@Test
public void test_convertJoinsToFilters_dontConvertJoinsDependedOnByLaterJoins2() {
final ImmutableList<JoinableClause> clauses = ImmutableList.of(new JoinableClause("j.", LookupJoinable.wrap(new MapLookupExtractor(TEST_LOOKUP, false)), JoinType.INNER, JoinConditionAnalysis.forExpression("x == \"j.k\"", "j.", ExprMacroTable.nil())), new JoinableClause("_j.", LookupJoinable.wrap(new MapLookupExtractor(TEST_LOOKUP, false)), JoinType.INNER, JoinConditionAnalysis.forExpression("x == \"_j.k\"", "_j.", ExprMacroTable.nil())), new JoinableClause("__j.", LookupJoinable.wrap(new MapLookupExtractor(TEST_LOOKUP, false)), JoinType.LEFT, JoinConditionAnalysis.forExpression("\"_j.v\" == \"__j.k\"", "__j.", ExprMacroTable.nil())));
final Pair<List<Filter>, List<JoinableClause>> conversion = JoinableFactoryWrapper.convertJoinsToFilters(clauses, ImmutableSet.of("x"), Integer.MAX_VALUE);
Assert.assertEquals(Pair.of(ImmutableList.of(new InDimFilter("x", TEST_LOOKUP_KEYS)), clauses.subList(1, clauses.size())), conversion);
}
use of org.apache.druid.query.filter.InDimFilter in project druid by druid-io.
the class JoinableFactoryWrapperTest method test_convertJoinsToFilters_convertTwoInnerJoins.
@Test
public void test_convertJoinsToFilters_convertTwoInnerJoins() {
final ImmutableList<JoinableClause> clauses = ImmutableList.of(new JoinableClause("j.", LookupJoinable.wrap(new MapLookupExtractor(TEST_LOOKUP, false)), JoinType.INNER, JoinConditionAnalysis.forExpression("x == \"j.k\"", "j.", ExprMacroTable.nil())), new JoinableClause("_j.", LookupJoinable.wrap(new MapLookupExtractor(TEST_LOOKUP, false)), JoinType.INNER, JoinConditionAnalysis.forExpression("x == \"_j.k\"", "_j.", ExprMacroTable.nil())), new JoinableClause("__j.", LookupJoinable.wrap(new MapLookupExtractor(TEST_LOOKUP, false)), JoinType.LEFT, JoinConditionAnalysis.forExpression("x == \"__j.k\"", "__j.", ExprMacroTable.nil())));
final Pair<List<Filter>, List<JoinableClause>> conversion = JoinableFactoryWrapper.convertJoinsToFilters(clauses, ImmutableSet.of("x"), Integer.MAX_VALUE);
Assert.assertEquals(Pair.of(ImmutableList.of(new InDimFilter("x", TEST_LOOKUP_KEYS), new InDimFilter("x", TEST_LOOKUP_KEYS)), ImmutableList.of(clauses.get(2))), conversion);
}
Aggregations