-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding basic null predicate support (#4943)
Adding null predicate support in reference to Issue #4230 This PR adds limited support for "IS NULL" and "IS NOT NULL" filter predicates. Currently this only works for leaf filter predicates.
- Loading branch information
1 parent
8619391
commit 09db4d9
Showing
15 changed files
with
345 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,7 @@ public enum FilterKind { | |
BETWEEN, | ||
IN, | ||
NOT_IN, | ||
REGEXP_LIKE | ||
REGEXP_LIKE, | ||
IS_NULL, | ||
IS_NOT_NULL | ||
} |
84 changes: 84 additions & 0 deletions
84
pinot-common/src/main/java/org/apache/pinot/pql/parsers/pql2/ast/IsNullPredicateAstNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* 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.pinot.pql.parsers.pql2.ast; | ||
|
||
import java.util.Collections; | ||
import org.apache.pinot.common.request.Expression; | ||
import org.apache.pinot.common.request.FilterOperator; | ||
import org.apache.pinot.common.utils.request.FilterQueryTree; | ||
import org.apache.pinot.common.utils.request.HavingQueryTree; | ||
import org.apache.pinot.common.utils.request.RequestUtils; | ||
import org.apache.pinot.pql.parsers.Pql2CompilationException; | ||
|
||
|
||
/** | ||
* AST node for IS predicates (foo IS NULL, foo IS NOT NULL). | ||
*/ | ||
public class IsNullPredicateAstNode extends PredicateAstNode { | ||
|
||
private final boolean _isNegation; | ||
|
||
public IsNullPredicateAstNode(boolean notNodeExists) { | ||
_isNegation = notNodeExists; | ||
} | ||
|
||
@Override | ||
public void addChild(AstNode childNode) { | ||
if (childNode instanceof IdentifierAstNode) { | ||
if (_identifier == null) { | ||
_identifier = ((IdentifierAstNode) childNode).getName(); | ||
} else { | ||
throw new Pql2CompilationException("Only one column supported in IS predicate."); | ||
} | ||
} else if (childNode instanceof FunctionCallAstNode) { | ||
throw new Pql2CompilationException("Function not supported in IS predicate"); | ||
} else if (childNode instanceof LiteralAstNode) { | ||
throw new Pql2CompilationException("Constants not supported in IS predicate"); | ||
} else { | ||
super.addChild(childNode); | ||
} | ||
} | ||
|
||
@Override | ||
public FilterQueryTree buildFilterQueryTree() { | ||
if (_identifier == null) { | ||
throw new Pql2CompilationException("IS predicate has no identifier"); | ||
} | ||
if (_isNegation) { | ||
return new FilterQueryTree(_identifier, Collections.EMPTY_LIST, FilterOperator.IS_NOT_NULL, null); | ||
} | ||
return new FilterQueryTree(_identifier, Collections.EMPTY_LIST, FilterOperator.IS_NULL, null); | ||
} | ||
|
||
@Override | ||
public Expression buildFilterExpression() { | ||
if (_identifier == null) { | ||
throw new Pql2CompilationException("IS predicate has no identifier"); | ||
} | ||
String filterName = _isNegation ? FilterKind.IS_NOT_NULL.name() : FilterKind.IS_NULL.name(); | ||
Expression expression = RequestUtils.getFunctionExpression(filterName); | ||
expression.getFunctionCall().addToOperands(RequestUtils.createIdentifierExpression(_identifier)); | ||
return expression; | ||
} | ||
|
||
@Override | ||
public HavingQueryTree buildHavingQueryTree() { | ||
throw new Pql2CompilationException("IS NOT? NULL predicate is not supported in HAVING clause."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,9 @@ enum FilterOperator { | |
RANGE, | ||
REGEXP_LIKE, | ||
NOT_IN, | ||
IN | ||
IN, | ||
IS_NULL, | ||
IS_NOT_NULL | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
pinot-core/src/main/java/org/apache/pinot/core/common/predicate/IsNotNullPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* 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.pinot.core.common.predicate; | ||
|
||
import org.apache.pinot.core.common.Predicate; | ||
|
||
|
||
public class IsNotNullPredicate extends Predicate { | ||
public IsNotNullPredicate(String column) { | ||
super(column, Type.IS_NOT_NULL, null); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Predicate: type: " + getType() + ", left : " + getLhs() + "\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ore/src/main/java/org/apache/pinot/core/realtime/impl/ThreadSafeMutableRoaringBitmap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* 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.pinot.core.realtime.impl; | ||
|
||
import org.roaringbitmap.buffer.MutableRoaringBitmap; | ||
|
||
|
||
/** | ||
* Helper wrapper class for {@link MutableRoaringBitmap} to make it thread-safe. | ||
*/ | ||
public class ThreadSafeMutableRoaringBitmap { | ||
private MutableRoaringBitmap _mutableRoaringBitmap; | ||
|
||
public ThreadSafeMutableRoaringBitmap() { | ||
_mutableRoaringBitmap = new MutableRoaringBitmap(); | ||
} | ||
|
||
public ThreadSafeMutableRoaringBitmap(int firstDocId) { | ||
_mutableRoaringBitmap = new MutableRoaringBitmap(); | ||
_mutableRoaringBitmap.add(firstDocId); | ||
} | ||
|
||
public void checkAndAdd(int docId) { | ||
if (!_mutableRoaringBitmap.contains(docId)) { | ||
synchronized (this) { | ||
_mutableRoaringBitmap.add(docId); | ||
} | ||
} | ||
} | ||
|
||
public boolean contains(int docId) { | ||
return _mutableRoaringBitmap.contains(docId); | ||
} | ||
|
||
public synchronized MutableRoaringBitmap getMutableRoaringBitmap() { | ||
return _mutableRoaringBitmap.clone(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.