This is an automated email from the ASF dual-hosted git repository.
rongr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new bf70071bc1 [hotfix][multistage] support filter boolean ref & literal
(#9597)
bf70071bc1 is described below
commit bf70071bc1d488e7b2ad7aeeb832b1e5da230e0c
Author: Rong Rong <[email protected]>
AuthorDate: Wed Oct 19 11:16:13 2022 -0700
[hotfix][multistage] support filter boolean ref & literal (#9597)
* add input ref support
* add literal boolean support
* fix type casting after datablock util changes
Co-authored-by: Rong Rong <[email protected]>
---
.../runtime/blocks/TransferableBlockUtils.java | 9 ++--
.../runtime/operator/operands/FilterOperand.java | 54 ++++++++++++++++++++--
.../java/org/apache/pinot/query/QueryTestSet.java | 2 +
3 files changed, 56 insertions(+), 9 deletions(-)
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/blocks/TransferableBlockUtils.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/blocks/TransferableBlockUtils.java
index 00e0cf5297..2934f74759 100644
---
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/blocks/TransferableBlockUtils.java
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/blocks/TransferableBlockUtils.java
@@ -27,7 +27,6 @@ import org.apache.pinot.common.datablock.BaseDataBlock;
import org.apache.pinot.common.datablock.DataBlockUtils;
import org.apache.pinot.common.datablock.RowDataBlock;
import org.apache.pinot.common.utils.DataSchema;
-import org.apache.pinot.core.query.selection.SelectionOperatorUtils;
public final class TransferableBlockUtils {
@@ -81,10 +80,8 @@ public final class TransferableBlockUtils {
}
public static Object[] getRow(TransferableBlock transferableBlock, int
rowId) {
- if (transferableBlock.isContainerBlock() && transferableBlock.getType() ==
BaseDataBlock.Type.ROW) {
- return transferableBlock.getContainer().get(rowId);
- } else {
- return
SelectionOperatorUtils.extractRowFromDataTable(transferableBlock.getDataBlock(),
rowId);
- }
+ Preconditions.checkState(transferableBlock.getType() ==
BaseDataBlock.Type.ROW,
+ "TransferableBlockUtils doesn't support get row from non-ROW-based
data block type yet!");
+ return transferableBlock.getContainer().get(rowId);
}
}
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java
index 8bf9298a9d..922b422a59 100644
---
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/FilterOperand.java
@@ -24,14 +24,33 @@ import java.util.List;
import org.apache.pinot.common.utils.DataSchema;
import org.apache.pinot.query.planner.logical.RexExpression;
import org.apache.pinot.query.runtime.operator.OperatorUtils;
+import org.apache.pinot.spi.data.FieldSpec;
public abstract class FilterOperand extends TransformOperand {
- @SuppressWarnings({"unchecked", "rawtypes"})
public static FilterOperand toFilterOperand(RexExpression rexExpression,
DataSchema dataSchema) {
- Preconditions.checkState(rexExpression instanceof
RexExpression.FunctionCall);
- RexExpression.FunctionCall functionCall = (RexExpression.FunctionCall)
rexExpression;
+ if (rexExpression instanceof RexExpression.FunctionCall) {
+ return toFilterOperand((RexExpression.FunctionCall) rexExpression,
dataSchema);
+ } else if (rexExpression instanceof RexExpression.InputRef) {
+ return toFilterOperand((RexExpression.InputRef) rexExpression,
dataSchema);
+ } else if (rexExpression instanceof RexExpression.Literal) {
+ return toFilterOperand((RexExpression.Literal) rexExpression);
+ } else {
+ throw new UnsupportedOperationException("Unsupported expression on
filter conversion: " + rexExpression);
+ }
+ }
+
+ public static FilterOperand toFilterOperand(RexExpression.Literal literal) {
+ return new BooleanLiteral(literal);
+ }
+
+ public static FilterOperand toFilterOperand(RexExpression.InputRef inputRef,
DataSchema dataSchema) {
+ return new BooleanInputRef(inputRef, dataSchema);
+ }
+
+ public static FilterOperand toFilterOperand(RexExpression.FunctionCall
functionCall, DataSchema dataSchema) {
+
switch
(OperatorUtils.canonicalizeFunctionName(functionCall.getFunctionName())) {
case "AND":
return new And(functionCall.getFunctionOperands(), dataSchema);
@@ -95,6 +114,35 @@ public abstract class FilterOperand extends
TransformOperand {
@Override
public abstract Boolean apply(Object[] row);
+ private static class BooleanInputRef extends FilterOperand {
+ private final RexExpression.InputRef _inputRef;
+
+ public BooleanInputRef(RexExpression.InputRef inputRef, DataSchema
dataSchema) {
+
Preconditions.checkState(dataSchema.getColumnDataType(inputRef.getIndex())
+ == DataSchema.ColumnDataType.BOOLEAN);
+ _inputRef = inputRef;
+ }
+
+ @Override
+ public Boolean apply(Object[] row) {
+ return (boolean) row[_inputRef.getIndex()];
+ }
+ }
+
+ private static class BooleanLiteral extends FilterOperand {
+ private final Object _literalValue;
+
+ public BooleanLiteral(RexExpression.Literal literal) {
+ Preconditions.checkState(literal.getDataType() ==
FieldSpec.DataType.BOOLEAN);
+ _literalValue = literal.getValue();
+ }
+
+ @Override
+ public Boolean apply(Object[] row) {
+ return (boolean) _literalValue;
+ }
+ }
+
private static class And extends FilterOperand {
List<FilterOperand> _childOperands;
public And(List<RexExpression> childExprs, DataSchema dataSchema) {
diff --git
a/pinot-query-runtime/src/test/java/org/apache/pinot/query/QueryTestSet.java
b/pinot-query-runtime/src/test/java/org/apache/pinot/query/QueryTestSet.java
index 12adcd7e5c..7a9c914125 100644
--- a/pinot-query-runtime/src/test/java/org/apache/pinot/query/QueryTestSet.java
+++ b/pinot-query-runtime/src/test/java/org/apache/pinot/query/QueryTestSet.java
@@ -114,6 +114,8 @@ public class QueryTestSet {
// Inequality JOIN & partial filter pushdown
new Object[]{"SELECT * FROM a JOIN b ON a.col1 = b.col2 WHERE a.col3
>= 0 AND a.col3 > b.col3"},
+ new Object[]{"SELECT * FROM a JOIN b ON a.col1 = b.col2 WHERE a.col3
>= 0 AND "
+ + "((a.col1 <> 'foo' AND b.col2 <> 'bar') or (a.col1 <> 'bar' AND
b.col2 <> 'foo'))"},
new Object[]{"SELECT * FROM a, b WHERE a.col1 > b.col2 AND a.col3 >
b.col3"},
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]