Skip to content

Commit

Permalink
Improve error message for unsupported function call (#7609) (#7877)
Browse files Browse the repository at this point in the history
  • Loading branch information
kishansairam9 committed Dec 12, 2021
1 parent 12edbdb commit fb12a50
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Expand Up @@ -228,8 +228,13 @@ public static TransformFunction get(@Nullable QueryContext queryContext, Express
// Scalar function
FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments);
if (functionInfo == null) {
throw new BadQueryRequestException(
if (FunctionRegistry.containsFunction(functionName)) {
throw new BadQueryRequestException(
String.format("Unsupported function: %s with %d parameters", functionName, numArguments));
} else {
throw new BadQueryRequestException(
String.format("Unsupported function: %s not found", functionName));
}
}
transformFunction = new ScalarTransformFunctionWrapper(functionInfo);
}
Expand Down
Expand Up @@ -38,8 +38,15 @@ public class PostAggregationFunction {
public PostAggregationFunction(String functionName, ColumnDataType[] argumentTypes) {
int numArguments = argumentTypes.length;
FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments);
Preconditions
.checkArgument(functionInfo != null, "Unsupported function: %s with %s parameters", functionName, numArguments);
if (functionInfo == null) {
if (FunctionRegistry.containsFunction(functionName)) {
throw new IllegalArgumentException(
String.format("Unsupported function: %s with %d parameters", functionName, numArguments));
} else {
throw new IllegalArgumentException(
String.format("Unsupported function: %s not found", functionName));
}
}
_functionInvoker = new FunctionInvoker(functionInfo);
Class<?>[] parameterClasses = _functionInvoker.getParameterClasses();
PinotDataType[] parameterTypes = _functionInvoker.getParameterTypes();
Expand Down
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pinot.segment.local.function;

import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -70,8 +69,15 @@ private ExecutableNode planExecution(ExpressionContext expression) {
}
String functionName = function.getFunctionName();
FunctionInfo functionInfo = FunctionRegistry.getFunctionInfo(functionName, numArguments);
Preconditions.checkState(functionInfo != null, "Unsupported function: %s with %s parameters", functionName,
numArguments);
if (functionInfo == null) {
if (FunctionRegistry.containsFunction(functionName)) {
throw new IllegalStateException(
String.format("Unsupported function: %s with %d parameters", functionName, numArguments));
} else {
throw new IllegalStateException(
String.format("Unsupported function: %s not found", functionName));
}
}
return new FunctionExecutionNode(functionInfo, childNodes);
default:
throw new IllegalStateException();
Expand Down

0 comments on commit fb12a50

Please sign in to comment.