gianm commented on code in PR #15629: URL: https://github.com/apache/druid/pull/15629#discussion_r1443074801
########## processing/src/main/java/org/apache/druid/query/filter/DruidObjectPredicate.java: ########## @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.filter; + +import javax.annotation.Nullable; + +public interface DruidObjectPredicate<T> +{ + static <T> DruidObjectPredicate<T> alwaysFalse() Review Comment: This isn't really the right name, since it's not always false. So, we should change it to make the call sites more legible. Maybe a better name is `falseWithUnknownForNull()`? ########## processing/src/main/java/org/apache/druid/query/filter/vector/ArrayVectorValueMatcher.java: ########## @@ -77,16 +77,12 @@ public ReadableVectorMatch match(final ReadableVectorMatch mask, boolean include for (int i = 0; i < mask.getSelectionSize(); i++) { final int rowNum = mask.getSelection()[i]; Object o = vector[rowNum]; - if (includeUnknown && o == null && predicateFactory.isNullInputUnknown()) { - selection[numRows++] = rowNum; - } else if (o == null || o instanceof Object[]) { - if (predicate.apply((Object[]) o)) { - selection[numRows++] = rowNum; - } - } else { - if (predicate.apply(new Object[]{o})) { + if ((o == null || o instanceof Object[])) { Review Comment: The new code is definitely more readable! ########## processing/src/main/java/org/apache/druid/query/filter/DruidPredicateMatch.java: ########## @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.query.filter; + +/** + * Three-value logic result for matching values with predicates produced by {@link DruidPredicateFactory} + * + * @see DruidObjectPredicate + * @see DruidLongPredicate + * @see DruidFloatPredicate + * @see DruidDoublePredicate + */ +public enum DruidPredicateMatch +{ + /** + * Value does not match + */ + FALSE, + /** + * Value matches + */ + TRUE, + /** + * Value is unknown to match, for example from a null input to a predicate which does not match null as true or false + */ + UNKNOWN; + + /** + * Convenience method for {@link ValueMatcher} and {@link org.apache.druid.query.filter.vector.VectorValueMatcher} + * implementations to pass through the 'includeUnknown' parameter to the predicate match result. + */ + public boolean matches(boolean includeUknown) Review Comment: `includeUnknown` (spelling) ########## processing/src/main/java/org/apache/druid/query/filter/InDimFilter.java: ########## @@ -302,10 +304,14 @@ public BitmapColumnIndex getBitmapColumnIndex(ColumnIndexSelector selector) if (indexSupplier == null) { // column doesn't exist, match against null - return Filters.makeMissingColumnNullIndex( - predicateFactory.makeStringPredicate().apply(null), - selector - ); + DruidPredicateMatch match = predicateFactory.makeStringPredicate().apply(null); Review Comment: Move this logic into `Filters.makeMissingColumnNullIndex`, and change its signature to `makeMissingColumnNullIndex(DruidPredicateMatch matchesNull, final ColumnIndexSelector selector)`? Then this code would be a bit simpler, it would remain a call to `Filters.makeMissingColumnNullIndex`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
