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 fea74a4f15 [multistage][hotfix] fix filter operator type convert
(#9450)
fea74a4f15 is described below
commit fea74a4f151339cd534090b4d5dccd3d82e385b6
Author: Rong Rong <[email protected]>
AuthorDate: Thu Sep 22 22:45:36 2022 -0700
[multistage][hotfix] fix filter operator type convert (#9450)
FilterOperand should use the non-cast result type,
- fix the current behavior to always use the left-hand side for type casting
- fixing type resulting in null issue
Co-authored-by: Rong Rong <[email protected]>
---
.../core/common/datablock/DataBlockUtils.java | 5 ++--
.../runtime/operator/operands/FilterOperand.java | 34 ++++++++++++++--------
.../runtime/operator/operands/LiteralOperand.java | 2 ++
.../pinot/query/runtime/QueryRunnerTest.java | 1 +
4 files changed, 28 insertions(+), 14 deletions(-)
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/common/datablock/DataBlockUtils.java
b/pinot-core/src/main/java/org/apache/pinot/core/common/datablock/DataBlockUtils.java
index 88cdf8f2db..da0e857017 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/common/datablock/DataBlockUtils.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/common/datablock/DataBlockUtils.java
@@ -38,10 +38,11 @@ public final class DataBlockUtils {
}
public static MetadataBlock getErrorDataBlock(Exception e) {
+ String errorMessage = e.getMessage() == null ? e.toString() :
e.getMessage();
if (e instanceof ProcessingException) {
- return getErrorDataBlock(Collections.singletonMap(((ProcessingException)
e).getErrorCode(), e.getMessage()));
+ return getErrorDataBlock(Collections.singletonMap(((ProcessingException)
e).getErrorCode(), errorMessage));
} else {
- return
getErrorDataBlock(Collections.singletonMap(QueryException.UNKNOWN_ERROR_CODE,
e.getMessage()));
+ return
getErrorDataBlock(Collections.singletonMap(QueryException.UNKNOWN_ERROR_CODE,
errorMessage));
}
}
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 d6ddc71292..8bf9298a9d 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
@@ -43,48 +43,48 @@ public abstract class FilterOperand extends
TransformOperand {
return new Predicate(functionCall.getFunctionOperands(), dataSchema) {
@Override
public Boolean apply(Object[] row) {
- return ((Comparable)
_lhs._resultType.convert(_lhs.apply(row))).compareTo(
- _lhs._resultType.convert(_rhs.apply(row))) == 0;
+ return ((Comparable)
_resultType.convert(_lhs.apply(row))).compareTo(
+ _resultType.convert(_rhs.apply(row))) == 0;
}
};
case "notEquals":
return new Predicate(functionCall.getFunctionOperands(), dataSchema) {
@Override
public Boolean apply(Object[] row) {
- return ((Comparable)
_lhs._resultType.convert(_lhs.apply(row))).compareTo(
- _lhs._resultType.convert(_rhs.apply(row))) != 0;
+ return ((Comparable)
_resultType.convert(_lhs.apply(row))).compareTo(
+ _resultType.convert(_rhs.apply(row))) != 0;
}
};
case "greaterThan":
return new Predicate(functionCall.getFunctionOperands(), dataSchema) {
@Override
public Boolean apply(Object[] row) {
- return ((Comparable)
_lhs._resultType.convert(_lhs.apply(row))).compareTo(
- _lhs._resultType.convert(_rhs.apply(row))) > 0;
+ return ((Comparable)
_resultType.convert(_lhs.apply(row))).compareTo(
+ _resultType.convert(_rhs.apply(row))) > 0;
}
};
case "greaterThanOrEqual":
return new Predicate(functionCall.getFunctionOperands(), dataSchema) {
@Override
public Boolean apply(Object[] row) {
- return ((Comparable)
_lhs._resultType.convert(_lhs.apply(row))).compareTo(
- _lhs._resultType.convert(_rhs.apply(row))) >= 0;
+ return ((Comparable)
_resultType.convert(_lhs.apply(row))).compareTo(
+ _resultType.convert(_rhs.apply(row))) >= 0;
}
};
case "lessThan":
return new Predicate(functionCall.getFunctionOperands(), dataSchema) {
@Override
public Boolean apply(Object[] row) {
- return ((Comparable)
_lhs._resultType.convert(_lhs.apply(row))).compareTo(
- _lhs._resultType.convert(_rhs.apply(row))) < 0;
+ return ((Comparable)
_resultType.convert(_lhs.apply(row))).compareTo(
+ _resultType.convert(_rhs.apply(row))) < 0;
}
};
case "lessThanOrEqual":
return new Predicate(functionCall.getFunctionOperands(), dataSchema) {
@Override
public Boolean apply(Object[] row) {
- return ((Comparable)
_lhs._resultType.convert(_lhs.apply(row))).compareTo(
- _lhs._resultType.convert(_rhs.apply(row))) <= 0;
+ return ((Comparable)
_resultType.convert(_lhs.apply(row))).compareTo(
+ _resultType.convert(_rhs.apply(row))) <= 0;
}
};
default:
@@ -150,10 +150,20 @@ public abstract class FilterOperand extends
TransformOperand {
private static abstract class Predicate extends FilterOperand {
protected final TransformOperand _lhs;
protected final TransformOperand _rhs;
+ protected final DataSchema.ColumnDataType _resultType;
public Predicate(List<RexExpression> functionOperands, DataSchema
dataSchema) {
_lhs = TransformOperand.toTransformOperand(functionOperands.get(0),
dataSchema);
_rhs = TransformOperand.toTransformOperand(functionOperands.get(1),
dataSchema);
+ if (_lhs._resultType != null && _lhs._resultType !=
DataSchema.ColumnDataType.OBJECT) {
+ _resultType = _lhs._resultType;
+ } else if (_rhs._resultType != null && _rhs._resultType !=
DataSchema.ColumnDataType.OBJECT) {
+ _resultType = _rhs._resultType;
+ } else {
+ // TODO: we should correctly throw exception here. Currently exception
thrown during constructor is not
+ // piped back to query dispatcher, thus we set it to null and
deliberately make the processing throw exception.
+ _resultType = null;
+ }
}
}
}
diff --git
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/LiteralOperand.java
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/LiteralOperand.java
index 46f534247f..fc73ea0273 100644
---
a/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/LiteralOperand.java
+++
b/pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/operands/LiteralOperand.java
@@ -18,6 +18,7 @@
*/
package org.apache.pinot.query.runtime.operator.operands;
+import org.apache.pinot.common.utils.DataSchema;
import org.apache.pinot.query.planner.logical.RexExpression;
@@ -26,6 +27,7 @@ public class LiteralOperand extends TransformOperand {
public LiteralOperand(RexExpression.Literal rexExpression) {
_value = rexExpression.getValue();
+ _resultType =
DataSchema.ColumnDataType.fromDataType(rexExpression.getDataType(), true);
}
@Override
diff --git
a/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java
b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java
index 0aeecd58cf..09bbbefd8e 100644
---
a/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java
+++
b/pinot-query-runtime/src/test/java/org/apache/pinot/query/runtime/QueryRunnerTest.java
@@ -283,6 +283,7 @@ public class QueryRunnerTest extends QueryRunnerTestBase {
// Test CAST
// - implicit CAST
new Object[]{"SELECT a.col1, a.col2, AVG(a.col3) FROM a GROUP BY
a.col1, a.col2"},
+ new Object[]{"SELECT a.col1, SUM(a.col3) FROM a GROUP BY a.col1 HAVING
MIN(a.col3) > 0.5"},
// - explicit CAST
new Object[]{"SELECT a.col1, CAST(SUM(a.col3) AS BIGINT) FROM a GROUP
BY a.col1"},
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]