Search in sources :

Example 6 with JoinConditionAnalysis

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

the class SegmentManagerBroadcastJoinIndexedTableTest method emptyCacheKeyForUnsupportedCondition.

@Test
public void emptyCacheKeyForUnsupportedCondition() {
    final DataSource dataSource = new GlobalTableDataSource(TABLE_NAME);
    JoinConditionAnalysis condition = EasyMock.mock(JoinConditionAnalysis.class);
    EasyMock.expect(condition.canHashJoin()).andReturn(false);
    EasyMock.replay(condition);
    Assert.assertNull(joinableFactory.build(dataSource, condition).orElse(null));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) DataSource(org.apache.druid.query.DataSource) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 7 with JoinConditionAnalysis

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

the class IndexedTableJoinableTest method makeJoinMatcherWithDimensionSelectorOnString.

@Test
public void makeJoinMatcherWithDimensionSelectorOnString() {
    final JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression("x == \"j.str\"", PREFIX, ExprMacroTable.nil());
    final JoinMatcher joinMatcher = target.makeJoinMatcher(dummyColumnSelectorFactory, condition, false, false, Closer.create());
    final DimensionSelector selector = joinMatcher.getColumnSelectorFactory().makeDimensionSelector(DefaultDimensionSpec.of("str"));
    // getValueCardinality
    Assert.assertEquals(4, selector.getValueCardinality());
    // nameLookupPossibleInAdvance
    Assert.assertTrue(selector.nameLookupPossibleInAdvance());
    // lookupName
    Assert.assertEquals("foo", selector.lookupName(0));
    Assert.assertEquals("bar", selector.lookupName(1));
    Assert.assertEquals("baz", selector.lookupName(2));
    Assert.assertNull(selector.lookupName(3));
    // lookupId
    Assert.assertNull(selector.idLookup());
}
Also used : DimensionSelector(org.apache.druid.segment.DimensionSelector) ConstantDimensionSelector(org.apache.druid.segment.ConstantDimensionSelector) JoinMatcher(org.apache.druid.segment.join.JoinMatcher) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Example 8 with JoinConditionAnalysis

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

the class LookupJoinMatcherTest method testCreateConditionAlwaysFalseShouldReturnSuccessfullyAndNotThrowException.

@Test
public void testCreateConditionAlwaysFalseShouldReturnSuccessfullyAndNotThrowException() {
    JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression("0", PREFIX, ExprMacroTable.nil());
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, false);
    Assert.assertNotNull(target);
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, true);
    Assert.assertNotNull(target);
}
Also used : JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Example 9 with JoinConditionAnalysis

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

the class LookupJoinMatcherTest method testMatchConditionSometimesTrueSometimesFalse.

@Test
public void testMatchConditionSometimesTrueSometimesFalse() {
    final int index = 1;
    SingleIndexedInt row = new SingleIndexedInt();
    row.setValue(index);
    Mockito.doReturn(dimensionSelector).when(leftSelectorFactory).makeDimensionSelector(ArgumentMatchers.any(DimensionSpec.class));
    Mockito.doReturn(row).when(dimensionSelector).getRow();
    Mockito.doReturn("foo").when(dimensionSelector).lookupName(index);
    Mockito.doReturn("bar").when(extractor).apply("foo");
    JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression(StringUtils.format("\"%sk\" == foo", PREFIX), PREFIX, ExprMacroTable.nil());
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, true);
    // Test match
    target.matchCondition();
    Assert.assertTrue(target.hasMatch());
    verifyMatch("foo", "bar");
    // Test no more
    target.nextMatch();
    Assert.assertFalse(target.hasMatch());
}
Also used : DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) SingleIndexedInt(org.apache.druid.segment.data.SingleIndexedInt) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Example 10 with JoinConditionAnalysis

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

the class LookupJoinMatcherTest method testMatchMultiValuedRowShouldThrowException.

@Test(expected = QueryUnsupportedException.class)
public void testMatchMultiValuedRowShouldThrowException() {
    ArrayBasedIndexedInts row = new ArrayBasedIndexedInts(new int[] { 2, 4, 6 });
    Mockito.doReturn(dimensionSelector).when(leftSelectorFactory).makeDimensionSelector(ArgumentMatchers.any(DimensionSpec.class));
    Mockito.doReturn(row).when(dimensionSelector).getRow();
    JoinConditionAnalysis condition = JoinConditionAnalysis.forExpression(StringUtils.format("\"%sk\" == foo", PREFIX), PREFIX, ExprMacroTable.nil());
    target = LookupJoinMatcher.create(extractor, leftSelectorFactory, condition, true);
    // Test match should throw exception
    target.matchCondition();
}
Also used : DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ArrayBasedIndexedInts(org.apache.druid.segment.data.ArrayBasedIndexedInts) JoinConditionAnalysis(org.apache.druid.segment.join.JoinConditionAnalysis) Test(org.junit.Test)

Aggregations

JoinConditionAnalysis (org.apache.druid.segment.join.JoinConditionAnalysis)12 Test (org.junit.Test)10 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 DataSource (org.apache.druid.query.DataSource)3 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)3 Optional (java.util.Optional)2 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1