/** * Logs a warning if the partition filter contains a field that is not part of the partitioning. */ private void warnIfInvalidPartitionFilter(PartitionFilter filter, Partitioning partitioning) { if (null == filter) { return; } for (Map.Entry<String, PartitionFilter.Condition<? extends Comparable>> entry : filter.getConditions().entrySet()) { if (!partitioning.getFields().containsKey(entry.getKey())) { LOG.warn("Partition filter cannot match any partitions in dataset '{}' because it contains field '{}' " + "that is not a valid partitioning field", getName(), entry.getKey()); } } }
/** * Logs a warning if the partition filter contains a field that is not part of the partitioning. */ private void warnIfInvalidPartitionFilter(PartitionFilter filter, Partitioning partitioning) { if (null == filter) { return; } for (Map.Entry<String, PartitionFilter.Condition<? extends Comparable>> entry : filter.getConditions().entrySet()) { if (!partitioning.getFields().containsKey(entry.getKey())) { LOG.warn("Partition filter cannot match any partitions in dataset '{}' because it contains field '{}' " + "that is not a valid partitioning field", getName(), entry.getKey()); } } }
/** * Match this filter against a partition key. The key matches iff it matches all conditions. * * @throws java.lang.IllegalArgumentException if one of the field types in the partition key are incompatible */ public boolean match(PartitionKey partitionKey) { for (Map.Entry<String, Condition<? extends Comparable>> condition : getConditions().entrySet()) { Comparable value = partitionKey.getField(condition.getKey()); if (value == null || !condition.getValue().match(value)) { return false; } } return true; }
@Test public void testBuilderNullRange() { PartitionFilter filter = PartitionFilter.builder() .addValueCondition("a", 1) .<Long>addRangeCondition("x", null, null) .build(); Assert.assertEquals(1, filter.getConditions().size()); // only the one for "a" Assert.assertNull(filter.getCondition("x")); }
.build(); Assert.assertEquals(4, filter.getConditions().size()); validateCondition(filter, "year", true, Partitioning.FieldType.INT, 2012, null, 2011, 2013); validateCondition(filter, "month", false, Partitioning.FieldType.INT, 4, 5, 6, null, 3, 7, 8);