Search in sources :

Example 1 with StringTuple

use of org.apache.druid.data.input.StringTuple in project druid by druid-io.

the class RangePartitionCachingLocalSegmentAllocatorTest method testAllocate.

@SuppressWarnings("SameParameterValue")
private void testAllocate(InputRow row, Interval interval, int bucketId) {
    StringTuple partitionEnd = getPartitionEnd(interval, bucketId);
    testAllocate(row, interval, bucketId, partitionEnd);
}
Also used : StringTuple(org.apache.druid.data.input.StringTuple)

Example 2 with StringTuple

use of org.apache.druid.data.input.StringTuple in project druid by druid-io.

the class RangePartitionMultiPhaseParallelIndexingTest method assertValuesInRange.

private static void assertValuesInRange(List<StringTuple> values, DataSegment segment) {
    DimensionRangeShardSpec shardSpec = (DimensionRangeShardSpec) segment.getShardSpec();
    StringTuple start = shardSpec.getStartTuple();
    StringTuple end = shardSpec.getEndTuple();
    Assert.assertTrue(shardSpec.toString(), start != null || end != null);
    for (StringTuple value : values) {
        if (start != null) {
            Assert.assertThat(value.compareTo(start), Matchers.greaterThanOrEqualTo(0));
        }
        if (end != null) {
            if (value == null) {
                Assert.assertNull("null values should be in first partition", start);
            } else {
                Assert.assertThat(value.compareTo(end), Matchers.lessThan(0));
            }
        }
    }
}
Also used : DimensionRangeShardSpec(org.apache.druid.timeline.partition.DimensionRangeShardSpec) StringTuple(org.apache.druid.data.input.StringTuple)

Example 3 with StringTuple

use of org.apache.druid.data.input.StringTuple in project druid by druid-io.

the class StringSketchMergerTest method mergesCorrectly.

@Test
public void mergesCorrectly() {
    StringTuple string1 = StringTuple.create("a");
    StringSketch sketch1 = new StringSketch();
    sketch1.put(string1);
    StringTuple string2 = StringTuple.create("mn");
    StringSketch sketch2 = new StringSketch();
    sketch2.put(string2);
    StringTuple string3 = StringTuple.create("z");
    StringSketch sketch3 = new StringSketch();
    sketch3.put(string3);
    target.merge(sketch2);
    target.merge(sketch1);
    target.merge(sketch3);
    StringDistribution merged = target.getResult();
    PartitionBoundaries partitions = merged.getEvenPartitionsByMaxSize(1);
    Assert.assertEquals(3, partitions.size());
    Assert.assertNull(partitions.get(0));
    Assert.assertEquals(string2, partitions.get(1));
    Assert.assertNull(partitions.get(2));
}
Also used : StringTuple(org.apache.druid.data.input.StringTuple) PartitionBoundaries(org.apache.druid.timeline.partition.PartitionBoundaries) Test(org.junit.Test)

Example 4 with StringTuple

use of org.apache.druid.data.input.StringTuple in project druid by druid-io.

the class DimensionRangeShardSpecTest method testPossibleInDomain_withNullValues.

@Test
public void testPossibleInDomain_withNullValues() {
    setDimensions("planet", "country", "city");
    final StringTuple start = StringTuple.create("Earth", "India", "Delhi");
    // null in end translates to INF
    final StringTuple end = StringTuple.create("Krypton", null, "Kryptonopolis");
    final RangeSet<String> universalSet = TreeRangeSet.create();
    universalSet.add(Range.all());
    ShardSpec shard = new DimensionRangeShardSpec(dimensions, start, end, 0, null);
    Map<String, RangeSet<String>> domain = new HashMap<>();
    // (-INF, INF) * (-INF, INF) * (-INF, INF)
    populateDomain(domain, universalSet, // EffectiveDomain[:1].size > 1 -> ACCEPT
    universalSet, universalSet);
    assertTrue(shard.possibleInDomain(domain));
    // {Earth} * (-INF, INF) * (-INF, INF)
    populateDomain(domain, getRangeSet(Range.singleton("Earth")), // EffectiveDomain[:1] == {start[:1]}
    universalSet, // EffectiveDomain[:2].size > 1 -> ACCEPT
    universalSet);
    assertTrue(shard.possibleInDomain(domain));
    // (-INF, Earth) U (Krypton, INF) * (-INF, INF) * (-INF, INF)
    populateDomain(domain, getUnion(getRangeSet(Range.lessThan("Earth")), getRangeSet(Range.greaterThan("Krypton"))), // EffectiveDomain[:1] = {} -> PRUNE
    universalSet, universalSet);
    assertFalse(shard.possibleInDomain(domain));
    // (-INF, INF) * (-INF, France) * (-INF, INF)
    populateDomain(domain, universalSet, // EffectiveDomain[:1].size > 2 -> ACCEPT
    getRangeSet(Range.lessThan("France")), universalSet);
    assertTrue(shard.possibleInDomain(domain));
    // {Jupiter} * (Foo) * {Bar}
    populateDomain(domain, getRangeSet(Range.singleton("Jupiter")), // EffectiveDomain[:1] != {} OR {start[:1]} OR {end[:1]} -> ACCEPT
    getRangeSet(Range.singleton("Foo")), getRangeSet(Range.singleton("Bar")));
    assertTrue(shard.possibleInDomain(domain));
    // {Krypton} * (-INF, France] * {Paris}
    populateDomain(domain, getRangeSet(Range.singleton("Krypton")), // EffectiveDomain[:1] == {end[:1]}
    getRangeSet(Range.atMost("France")), // EffectiveDomain[:2].size > 1 -> ACCEPT
    universalSet);
    assertTrue(shard.possibleInDomain(domain));
}
Also used : HashMap(java.util.HashMap) RangeSet(com.google.common.collect.RangeSet) TreeRangeSet(com.google.common.collect.TreeRangeSet) StringTuple(org.apache.druid.data.input.StringTuple) Test(org.junit.Test)

Example 5 with StringTuple

use of org.apache.druid.data.input.StringTuple in project druid by druid-io.

the class DimensionRangeShardSpecTest method testPossibleInDomain_nonNullValues_acceptanceScenarios.

@Test
public void testPossibleInDomain_nonNullValues_acceptanceScenarios() {
    setDimensions("planet", "country", "city");
    final StringTuple start = StringTuple.create("Earth", "France", "Paris");
    final StringTuple end = StringTuple.create("Earth", "USA", "New York");
    final RangeSet<String> universalSet = TreeRangeSet.create();
    universalSet.add(Range.all());
    ShardSpec shard = new DimensionRangeShardSpec(dimensions, start, end, 0, null);
    Map<String, RangeSet<String>> domain = new HashMap<>();
    // (-INF, INF) * (-INF, INF) * (-INF, INF)
    populateDomain(domain, universalSet, // EffectiveDomain[:1] == {Earth} == {start[:1]} == {end[:1]}
    universalSet, // EffectiveDomain[:2].size > 1 -> ACCEPT
    universalSet);
    assertTrue(shard.possibleInDomain(domain));
    // {Earth} * (-INF, INF) * (-INF, INF)
    populateDomain(domain, getRangeSet(Range.singleton("Earth")), // EffectiveDomain[:1] == {Earth} == {start[:1]} == {end[:1]}
    universalSet, // EffectiveDomain[:2].size > 1 -> ACCEPT
    universalSet);
    assertTrue(shard.possibleInDomain(domain));
    // (-INF, INF) * [USA, INF) * {New York}
    populateDomain(domain, universalSet, // EffectiveDomain[:1] == {Earth} == {start[:1]} == {end[:1]}
    getRangeSet(Range.atLeast("USA")), // EffectiveDomain[:2] == {end[:2]}
    getRangeSet(Range.singleton("New York")));
    // EffectiveDomain[:].size > 0 -> ACCEPT
    assertTrue(shard.possibleInDomain(domain));
    // (-INF, INF) * (-INF, "France"] * (Paris, INF)
    populateDomain(domain, universalSet, // EffectiveDomain[:1] == {Earth} == {start[:1]} == {end[:1]}
    getRangeSet(Range.atMost("France")), // EffectiveDomain[:2] == {<Earth, France>} == {start[:2]}
    getRangeSet(Range.greaterThan("Paris")));
    assertTrue(shard.possibleInDomain(domain));
    // {Earth} * {India} * Any Non-empty set
    populateDomain(domain, getRangeSet(Range.singleton("Earth")), // EffectiveDomain[:1] == {Earth} == {start[:1]} == {end[:1]}
    getRangeSet(Range.singleton("India")), // EffectiveDomain[:2] == {<Earth, India>} != {start[:2]} OR {end[:2]}
    getRangeSet(Range.greaterThan("New York")));
    assertTrue(shard.possibleInDomain(domain));
}
Also used : HashMap(java.util.HashMap) RangeSet(com.google.common.collect.RangeSet) TreeRangeSet(com.google.common.collect.TreeRangeSet) StringTuple(org.apache.druid.data.input.StringTuple) Test(org.junit.Test)

Aggregations

StringTuple (org.apache.druid.data.input.StringTuple)11 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 RangeSet (com.google.common.collect.RangeSet)4 TreeRangeSet (com.google.common.collect.TreeRangeSet)4 Interval (org.joda.time.Interval)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 InputRow (org.apache.druid.data.input.InputRow)1 StringDistribution (org.apache.druid.indexing.common.task.batch.parallel.distribution.StringDistribution)1 StringSketch (org.apache.druid.indexing.common.task.batch.parallel.distribution.StringSketch)1 DataSegment (org.apache.druid.timeline.DataSegment)1 DimensionRangeShardSpec (org.apache.druid.timeline.partition.DimensionRangeShardSpec)1 PartitionBoundaries (org.apache.druid.timeline.partition.PartitionBoundaries)1