This is an automated email from the ASF dual-hosted git repository.
jackie 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 499b661e2b Bugfix. Maintain literal data type during function
evaluation (#12607)
499b661e2b is described below
commit 499b661e2b14a0446c723c890ef61c0a59c43188
Author: Shounak kulkarni <[email protected]>
AuthorDate: Fri Mar 8 22:54:29 2024 +0500
Bugfix. Maintain literal data type during function evaluation (#12607)
---
.../local/function/InbuiltFunctionEvaluator.java | 9 ++--
.../function/InbuiltFunctionEvaluatorTest.java | 51 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 5 deletions(-)
diff --git
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluator.java
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluator.java
index 8c3909e784..7b28ce7850 100644
---
a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluator.java
+++
b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluator.java
@@ -55,8 +55,7 @@ public class InbuiltFunctionEvaluator implements
FunctionEvaluator {
private ExecutableNode planExecution(ExpressionContext expression) {
switch (expression.getType()) {
case LITERAL:
- // TODO: pass literal with type into ConstantExecutionNode.
- return new
ConstantExecutionNode(expression.getLiteral().getStringValue());
+ return new ConstantExecutionNode(expression.getLiteral().getValue());
case IDENTIFIER:
String columnName = expression.getIdentifier();
ColumnExecutionNode columnExecutionNode = new
ColumnExecutionNode(columnName, _arguments.size());
@@ -276,14 +275,14 @@ public class InbuiltFunctionEvaluator implements
FunctionEvaluator {
}
private static class ConstantExecutionNode implements ExecutableNode {
- final String _value;
+ final Object _value;
- ConstantExecutionNode(String value) {
+ ConstantExecutionNode(Object value) {
_value = value;
}
@Override
- public String execute(GenericRow row) {
+ public Object execute(GenericRow row) {
return _value;
}
diff --git
a/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluatorTest.java
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluatorTest.java
new file mode 100644
index 0000000000..e9bb5f235f
--- /dev/null
+++
b/pinot-segment-local/src/test/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluatorTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.segment.local.function;
+
+import org.apache.pinot.common.function.FunctionUtils;
+import org.apache.pinot.common.utils.PinotDataType;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+
+public class InbuiltFunctionEvaluatorTest {
+
+ @Test
+ public void booleanLiteralTest() {
+ checkBooleanLiteralExpression("true", 1);
+ checkBooleanLiteralExpression("false", 0);
+ checkBooleanLiteralExpression("True", 1);
+ checkBooleanLiteralExpression("False", 0);
+ checkBooleanLiteralExpression("1", 1);
+ checkBooleanLiteralExpression("0", 0);
+ }
+
+ private void checkBooleanLiteralExpression(String expression, int value) {
+ InbuiltFunctionEvaluator evaluator = new
InbuiltFunctionEvaluator(expression);
+ Object output = evaluator.evaluate(new GenericRow());
+ Class<?> outputValueClass = output.getClass();
+ PinotDataType outputType = FunctionUtils.getArgumentType(outputValueClass);
+ assertNotNull(outputType);
+ // as INT is the stored type for BOOLEAN
+ assertEquals(outputType.toInt(output), value);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]