@Override @SuppressWarnings("unchecked") public <T> Expression predicate(BoundPredicate<T> pred) { PartitionField part = spec.getFieldBySourceId(pred.ref().fieldId()); if (part == null) { // the predicate has no partition column return alwaysTrue(); } UnboundPredicate<?> result = ((Transform<T, ?>) part.transform()).project(part.name(), pred); if (result != null) { return result; } // if the predicate could not be projected, it always matches return alwaysTrue(); } }
@Override @SuppressWarnings("unchecked") public <T> Expression predicate(BoundPredicate<T> pred) { PartitionField part = spec.getFieldBySourceId(pred.ref().fieldId()); if (part == null) { // the predicate has no partition column return alwaysFalse(); } UnboundPredicate<?> result = ((Transform<T, ?>) part.transform()) .projectStrict(part.name(), pred); if (result != null) { return result; } // if the predicate could not be projected, it never matches return alwaysFalse(); } }
@Override @SuppressWarnings("unchecked") public <T> Expression predicate(BoundPredicate<T> pred) { // Get the strict projection of this predicate in partition data, then use it to determine // whether to return the original predicate. The strict projection returns true iff the // original predicate would have returned true, so the predicate can be eliminated if the // strict projection evaluates to true. // // If there is no strict projection or if it evaluates to false, then return the predicate. PartitionField part = spec.getFieldBySourceId(pred.ref().fieldId()); if (part == null) { return pred; // not associated inclusive a partition field, can't be evaluated } UnboundPredicate<?> strictProjection = ((Transform<T, ?>) part.transform()) .projectStrict(part.name(), pred); if (strictProjection != null) { Expression bound = strictProjection.bind(spec.partitionType()); if (bound instanceof BoundPredicate) { // the predicate methods will evaluate and return alwaysTrue or alwaysFalse return super.predicate((BoundPredicate<?>) bound); } return bound; // use the non-predicate residual (e.g. alwaysTrue) } // if the predicate could not be projected, it must be in the residual return pred; }
@Test @SuppressWarnings("unchecked") public void testPartitionPath() { PartitionSpec spec = PartitionSpec.builderFor(SCHEMA) .hour("ts") .bucket("id", 10) .build(); Transform hour = spec.getFieldBySourceId(3).transform(); Transform bucket = spec.getFieldBySourceId(1).transform(); Literal<Long> ts = Literal.of("2017-12-01T10:12:55.038194").to(Types.TimestampType.withoutZone()); Object tsHour = hour.apply(ts.value()); Object idBucket = bucket.apply(1); Row partition = Row.of(tsHour, idBucket); Assert.assertEquals("Should produce expected partition key", "ts_hour=2017-12-01-10/id_bucket=" + idBucket, spec.partitionToPath(partition)); }