use of org.apache.druid.query.JoinDataSource in project druid by druid-io.
the class DataSourceAnalysis method flattenJoin.
/**
* Flatten a datasource into two parts: the left-hand side datasource (the 'base' datasource), and a list of join
* clauses, if any.
*
* @throws IllegalArgumentException if dataSource cannot be fully flattened.
*/
private static Triple<DataSource, DimFilter, List<PreJoinableClause>> flattenJoin(final JoinDataSource dataSource) {
DataSource current = dataSource;
DimFilter currentDimFilter = null;
final List<PreJoinableClause> preJoinableClauses = new ArrayList<>();
while (current instanceof JoinDataSource) {
final JoinDataSource joinDataSource = (JoinDataSource) current;
current = joinDataSource.getLeft();
if (currentDimFilter != null) {
throw new IAE("Left filters are only allowed when left child is direct table access");
}
currentDimFilter = joinDataSource.getLeftFilter();
preJoinableClauses.add(new PreJoinableClause(joinDataSource.getRightPrefix(), joinDataSource.getRight(), joinDataSource.getJoinType(), joinDataSource.getConditionAnalysis()));
}
// Join clauses were added in the order we saw them while traversing down, but we need to apply them in the
// going-up order. So reverse them.
Collections.reverse(preJoinableClauses);
return Triple.of(current, currentDimFilter, preJoinableClauses);
}
use of org.apache.druid.query.JoinDataSource in project druid by druid-io.
the class DataSourceAnalysisTest method testJoinSimpleLeftLeaningWithLeftFilter.
@Test
public void testJoinSimpleLeftLeaningWithLeftFilter() {
final JoinDataSource joinDataSource = join(join(join(TABLE_FOO, LOOKUP_LOOKYLOO, "1.", JoinType.INNER, TrueDimFilter.instance()), INLINE, "2.", JoinType.LEFT), subquery(LOOKUP_LOOKYLOO), "3.", JoinType.FULL);
final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(joinDataSource);
Assert.assertTrue(analysis.isConcreteBased());
Assert.assertTrue(analysis.isConcreteTableBased());
Assert.assertFalse(analysis.isGlobal());
Assert.assertFalse(analysis.isQuery());
Assert.assertEquals(joinDataSource, analysis.getDataSource());
Assert.assertEquals(TABLE_FOO, analysis.getBaseDataSource());
Assert.assertEquals(Optional.of(TABLE_FOO), analysis.getBaseTableDataSource());
Assert.assertEquals(TrueDimFilter.instance(), analysis.getJoinBaseTableFilter().orElse(null));
Assert.assertEquals(Optional.empty(), analysis.getBaseUnionDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseUnionDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseQuery());
Assert.assertEquals(Optional.empty(), analysis.getBaseQuerySegmentSpec());
Assert.assertEquals(ImmutableList.of(new PreJoinableClause("1.", LOOKUP_LOOKYLOO, JoinType.INNER, joinClause("1.")), new PreJoinableClause("2.", INLINE, JoinType.LEFT, joinClause("2.")), new PreJoinableClause("3.", subquery(LOOKUP_LOOKYLOO), JoinType.FULL, joinClause("3."))), analysis.getPreJoinableClauses());
Assert.assertTrue(analysis.isJoin());
}
use of org.apache.druid.query.JoinDataSource in project druid by druid-io.
the class DataSourceAnalysisTest method testJoinOverTableSubquery.
@Test
public void testJoinOverTableSubquery() {
final JoinDataSource joinDataSource = join(TABLE_FOO, subquery(TABLE_FOO), "1.", JoinType.INNER, TrueDimFilter.instance());
final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(joinDataSource);
Assert.assertFalse(analysis.isConcreteBased());
Assert.assertFalse(analysis.isConcreteTableBased());
Assert.assertFalse(analysis.isGlobal());
Assert.assertFalse(analysis.isQuery());
Assert.assertEquals(joinDataSource, analysis.getDataSource());
Assert.assertEquals(TABLE_FOO, analysis.getBaseDataSource());
Assert.assertEquals(TrueDimFilter.instance(), analysis.getJoinBaseTableFilter().orElse(null));
Assert.assertEquals(Optional.of(TABLE_FOO), analysis.getBaseTableDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseUnionDataSource());
Assert.assertEquals(ImmutableList.of(new PreJoinableClause("1.", subquery(TABLE_FOO), JoinType.INNER, joinClause("1."))), analysis.getPreJoinableClauses());
Assert.assertTrue(analysis.isJoin());
}
use of org.apache.druid.query.JoinDataSource in project druid by druid-io.
the class DataSourceAnalysisTest method testJoinLookupToLookup.
@Test
public void testJoinLookupToLookup() {
final JoinDataSource joinDataSource = join(LOOKUP_LOOKYLOO, LOOKUP_LOOKYLOO, "1.", JoinType.INNER);
final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(joinDataSource);
Assert.assertTrue(analysis.isConcreteBased());
Assert.assertFalse(analysis.isConcreteTableBased());
Assert.assertTrue(analysis.isGlobal());
Assert.assertFalse(analysis.isQuery());
Assert.assertEquals(joinDataSource, analysis.getDataSource());
Assert.assertEquals(LOOKUP_LOOKYLOO, analysis.getBaseDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseTableDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseUnionDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseQuery());
Assert.assertEquals(Optional.empty(), analysis.getBaseQuerySegmentSpec());
Assert.assertEquals(Optional.empty(), analysis.getJoinBaseTableFilter());
Assert.assertEquals(ImmutableList.of(new PreJoinableClause("1.", LOOKUP_LOOKYLOO, JoinType.INNER, joinClause("1."))), analysis.getPreJoinableClauses());
Assert.assertTrue(analysis.isJoin());
}
use of org.apache.druid.query.JoinDataSource in project druid by druid-io.
the class DataSourceAnalysisTest method testJoinSimpleLeftLeaning.
@Test
public void testJoinSimpleLeftLeaning() {
// Join of a table onto a variety of simple joinable objects (lookup, inline, subquery) with a left-leaning
// structure (no right children are joins themselves).
final JoinDataSource joinDataSource = join(join(join(TABLE_FOO, LOOKUP_LOOKYLOO, "1.", JoinType.INNER), INLINE, "2.", JoinType.LEFT), subquery(LOOKUP_LOOKYLOO), "3.", JoinType.FULL);
final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(joinDataSource);
Assert.assertTrue(analysis.isConcreteBased());
Assert.assertTrue(analysis.isConcreteTableBased());
Assert.assertFalse(analysis.isGlobal());
Assert.assertFalse(analysis.isQuery());
Assert.assertEquals(joinDataSource, analysis.getDataSource());
Assert.assertEquals(TABLE_FOO, analysis.getBaseDataSource());
Assert.assertEquals(Optional.of(TABLE_FOO), analysis.getBaseTableDataSource());
Assert.assertEquals(Optional.empty(), analysis.getJoinBaseTableFilter());
Assert.assertEquals(Optional.empty(), analysis.getBaseUnionDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseUnionDataSource());
Assert.assertEquals(Optional.empty(), analysis.getBaseQuery());
Assert.assertEquals(Optional.empty(), analysis.getBaseQuerySegmentSpec());
Assert.assertEquals(ImmutableList.of(new PreJoinableClause("1.", LOOKUP_LOOKYLOO, JoinType.INNER, joinClause("1.")), new PreJoinableClause("2.", INLINE, JoinType.LEFT, joinClause("2.")), new PreJoinableClause("3.", subquery(LOOKUP_LOOKYLOO), JoinType.FULL, joinClause("3."))), analysis.getPreJoinableClauses());
Assert.assertTrue(analysis.isJoin());
}
Aggregations