@Override public RangeSet<String> getDimensionRangeSet(String dimension) { RangeSet<String> retSet = TreeRangeSet.create(); for (DimFilter field : fields) { RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension); if (rangeSet == null) { return null; } else { retSet.addAll(rangeSet); } } return retSet; }
for (String dimension : dimensions) { Optional<RangeSet<String>> optFilterRangeSet = dimensionRangeCache .computeIfAbsent(dimension, d -> Optional.fromNullable(dimFilter.getDimensionRangeSet(d)));
@Override public RangeSet<String> getDimensionRangeSet(String dimension) { RangeSet<String> retSet = null; for (DimFilter field : fields) { RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension); if (rangeSet != null) { if (retSet == null) { retSet = TreeRangeSet.create(rangeSet); } else { retSet.removeAll(rangeSet.complement()); } } } return retSet; }
/** * There are some special cases involving null that require special casing for And and Or instead of simply taking * the complement * * Example 1 : "NOT ( [0,INF) OR null)" The inside of NOT would evaluate to null, and the complement would also * be null. However, by breaking the NOT, this statement is "NOT([0,INF)) AND NOT(null)", which means it should * actually evaluate to (-INF, 0). * * Example 2 : "NOT ( [0,INF) AND null )" The inside of NOT would evaluate to [0,INF), and the complement would be * (-INF, 0). However the statement is actually "NOT([0,INF)) OR NOT(null)", and it should be evaluated to null. */ @Override public RangeSet<String> getDimensionRangeSet(String dimension) { if (field instanceof AndDimFilter) { List<DimFilter> fields = ((AndDimFilter) field).getFields(); return new OrDimFilter(Lists.transform(fields, NotDimFilter::new)).getDimensionRangeSet(dimension); } if (field instanceof OrDimFilter) { List<DimFilter> fields = ((OrDimFilter) field).getFields(); return new AndDimFilter(Lists.transform(fields, NotDimFilter::new)).getDimensionRangeSet(dimension); } if (field instanceof NotDimFilter) { return ((NotDimFilter) field).getField().getDimensionRangeSet(dimension); } RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension); return rangeSet == null ? null : rangeSet.complement(); }
@Test public void testAndFilter() { DimFilter and1 = new AndDimFilter(ImmutableList.of(selector1, selector2, in1)); Assert.assertEquals(empty, and1.getDimensionRangeSet("dim1")); Assert.assertNull(and1.getDimensionRangeSet("dim2")); DimFilter and2 = new AndDimFilter(ImmutableList.of(selector3, bound1, other1)); RangeSet expected2 = rangeSet(ImmutableList.of(Range.closed("from", "to"))); Assert.assertEquals(expected2, and2.getDimensionRangeSet("dim1")); DimFilter and3 = new AndDimFilter(ImmutableList.of(in2, bound1, bound2, bound3, bound4)); RangeSet expected3 = rangeSet(Range.openClosed("notincluded", "tillend")); Assert.assertEquals(expected3, and3.getDimensionRangeSet("dim1")); Assert.assertEquals(empty, and3.getDimensionRangeSet("dim2")); DimFilter and4 = new AndDimFilter(ImmutableList.of(in3, bound3)); RangeSet expected4 = rangeSet(point("null")); Assert.assertEquals(expected4, and4.getDimensionRangeSet("dim1")); DimFilter and5 = new AndDimFilter(ImmutableList.of(and3, in1)); RangeSet expected5 = rangeSet(ImmutableList.of(point("testing"), point("this"), point("tillend"))); Assert.assertEquals(expected5, and5.getDimensionRangeSet("dim1")); }
@Test public void testSimpleFilter() { RangeSet expected1 = rangeSet(point("a")); Assert.assertEquals(expected1, selector1.getDimensionRangeSet("dim1")); Assert.assertNull(selector1.getDimensionRangeSet("dim2")); RangeSet expected2 = rangeSet(point(null)); Assert.assertEquals(expected2, selector5.getDimensionRangeSet("dim1")); RangeSet expected3 = rangeSet(ImmutableList.of(point("testing"), point("this"), point("filter"), point("tillend"))); Assert.assertEquals(expected3, in1.getDimensionRangeSet("dim1")); RangeSet expected4 = rangeSet(ImmutableList.of(point("null"), point(null))); Assert.assertEquals(expected4, in3.getDimensionRangeSet("dim1")); RangeSet expected5 = ImmutableRangeSet.of(Range.closed("from", "to")); Assert.assertEquals(expected5, bound1.getDimensionRangeSet("dim1")); RangeSet expected6 = ImmutableRangeSet.of(Range.atMost("tillend")); Assert.assertEquals(expected6, bound2.getDimensionRangeSet("dim1")); RangeSet expected7 = ImmutableRangeSet.of(Range.greaterThan("notincluded")); Assert.assertEquals(expected7, bound3.getDimensionRangeSet("dim1")); Assert.assertNull(other1.getDimensionRangeSet("someDim")); Assert.assertNull(other2.getDimensionRangeSet("someOtherDim")); Assert.assertNull(other3.getDimensionRangeSet("dim")); Assert.assertNull(interval1.getDimensionRangeSet(ColumnHolder.TIME_COLUMN_NAME)); Assert.assertNull(interval2.getDimensionRangeSet("dim1")); }
@Test public void testFilterShards() { DimFilter filter1 = EasyMock.createMock(DimFilter.class); EasyMock.expect(filter1.getDimensionRangeSet("dim1")) .andReturn(rangeSet(ImmutableList.of(Range.lessThan("abc")))) .anyTimes(); EasyMock.expect(filter1.getDimensionRangeSet("dim2")) .andReturn(null) .anyTimes(); ShardSpec shard1 = shardSpec("dim1", true); ShardSpec shard2 = shardSpec("dim1", false); ShardSpec shard3 = shardSpec("dim1", false); ShardSpec shard4 = shardSpec("dim2", false); ShardSpec shard5 = shardSpec("dim2", false); ShardSpec shard6 = shardSpec("dim2", false); ShardSpec shard7 = shardSpec("dim2", false); List<ShardSpec> shards = ImmutableList.of(shard1, shard2, shard3, shard4, shard5, shard6, shard7); EasyMock.replay(filter1, shard1, shard2, shard3, shard4, shard5, shard6, shard7); Set<ShardSpec> expected1 = ImmutableSet.of(shard1, shard4, shard5, shard6, shard7); assertFilterResult(filter1, shards, expected1); }
@Test public void testOrFilter() { DimFilter or1 = new OrDimFilter(ImmutableList.of(selector1, selector2, selector5)); RangeSet expected1 = rangeSet(ImmutableList.of(point(null), point("a"), point("z"))); Assert.assertEquals(expected1, or1.getDimensionRangeSet("dim1")); DimFilter or2 = new OrDimFilter(ImmutableList.of(selector5, in1, in3)); RangeSet expected2 = rangeSet(ImmutableList.of(point("testing"), point("this"), point("filter"), point("tillend"), point("null"), point(null) )); Assert.assertEquals(expected2, or2.getDimensionRangeSet("dim1")); DimFilter or3 = new OrDimFilter(ImmutableList.of(bound1, bound2, bound3)); Assert.assertEquals(all, or3.getDimensionRangeSet("dim1")); DimFilter or4 = new OrDimFilter(ImmutableList.of(selector1, selector2, selector3, selector4, selector5)); Assert.assertNull(or4.getDimensionRangeSet("dim1")); Assert.assertNull(or4.getDimensionRangeSet("dim2")); DimFilter or5 = new OrDimFilter(ImmutableList.of(or1, or2, bound1)); RangeSet expected5 = rangeSet(ImmutableList.of(point(null), point("a"), point("filter"), Range.closed("from", "to"), point("z") )); Assert.assertEquals(expected5, or5.getDimensionRangeSet("dim1")); }
Assert.assertEquals(expected1, not1.getDimensionRangeSet("dim1")); Assert.assertNull(not1.getDimensionRangeSet("dim2")); Range.greaterThan("null") )); Assert.assertEquals(expected2, not2.getDimensionRangeSet("dim1")); } else { RangeSet expected2 = rangeSet(ImmutableList.of( Range.greaterThan("null") )); Assert.assertEquals(expected2, not2.getDimensionRangeSet("dim1")); Assert.assertEquals(expected3, not3.getDimensionRangeSet("dim1")); Assert.assertEquals(expected4, not4.getDimensionRangeSet("dim1")); Assert.assertEquals(expected5, not5.getDimensionRangeSet("dim1")); Assert.assertNull(not5.getDimensionRangeSet("dim2")); RangeSet expected6a = rangeSet(ImmutableList.of(Range.greaterThan("tillend"))); RangeSet expected6b = rangeSet(ImmutableList.of(Range.atMost("again"), Range.atLeast("exclusive"))); Assert.assertEquals(expected6a, not6.getDimensionRangeSet("dim1")); Assert.assertEquals(expected6b, not6.getDimensionRangeSet("dim2")); Range.open("this", "tillend"), Range.greaterThan("tillend") )); Assert.assertEquals(expected7, not7.getDimensionRangeSet("dim1")); Assert.assertNull(not7.getDimensionRangeSet("dim2"));
@Override public RangeSet<String> getDimensionRangeSet(String dimension) { RangeSet<String> retSet = TreeRangeSet.create(); for (DimFilter field : fields) { RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension); if (rangeSet == null) { return null; } else { retSet.addAll(rangeSet); } } return retSet; }
for (String dimension : dimensions) { Optional<RangeSet<String>> optFilterRangeSet = dimensionRangeCache .computeIfAbsent(dimension, d -> Optional.fromNullable(dimFilter.getDimensionRangeSet(d)));
@Override public RangeSet<String> getDimensionRangeSet(String dimension) { RangeSet<String> retSet = null; for (DimFilter field : fields) { RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension); if (rangeSet != null) { if (retSet == null) { retSet = TreeRangeSet.create(rangeSet); } else { retSet.removeAll(rangeSet.complement()); } } } return retSet; }
/** * There are some special cases involving null that require special casing for And and Or instead of simply taking * the complement * * Example 1 : "NOT ( [0,INF) OR null)" The inside of NOT would evaluate to null, and the complement would also * be null. However, by breaking the NOT, this statement is "NOT([0,INF)) AND NOT(null)", which means it should * actually evaluate to (-INF, 0). * * Example 2 : "NOT ( [0,INF) AND null )" The inside of NOT would evaluate to [0,INF), and the complement would be * (-INF, 0). However the statement is actually "NOT([0,INF)) OR NOT(null)", and it should be evaluated to null. */ @Override public RangeSet<String> getDimensionRangeSet(String dimension) { if (field instanceof AndDimFilter) { List<DimFilter> fields = ((AndDimFilter) field).getFields(); return new OrDimFilter(Lists.transform(fields, NotDimFilter::new)).getDimensionRangeSet(dimension); } if (field instanceof OrDimFilter) { List<DimFilter> fields = ((OrDimFilter) field).getFields(); return new AndDimFilter(Lists.transform(fields, NotDimFilter::new)).getDimensionRangeSet(dimension); } if (field instanceof NotDimFilter) { return ((NotDimFilter) field).getField().getDimensionRangeSet(dimension); } RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension); return rangeSet == null ? null : rangeSet.complement(); }