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 8c3909e7848..7b28ce7850f 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 InbuiltFunctionEvaluator(String functionExpression) { 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 String toString() { } 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 00000000000..e9bb5f235f3 --- /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); + } +}