Skip to content

Commit

Permalink
Support STRPOS pushdown to Pinot; Fix missing configuration property …
Browse files Browse the repository at this point in the history
…pinot.query-options error
  • Loading branch information
nizarhejazi authored and highker committed Oct 31, 2022
1 parent 6edfac9 commit 816187a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ public String getControllerUrl()
return controllerUrls.get(ThreadLocalRandom.current().nextInt(controllerUrls.size()));
}

@NotNull
public String getQueryOptions()
{
return queryOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,24 +340,40 @@ private PinotExpression handleFunction(
Function<VariableReferenceExpression, Selection> context)
{
String functionName = function.getDisplayName().toLowerCase(ENGLISH);
List<RowExpression> arguments = function.getArguments();
switch (functionName) {
case "lower":
case "trim":
return derived(String.format(
"%s(%s)",
functionName,
function.getArguments().get(0).accept(this, context).getDefinition()));
arguments.get(0).accept(this, context).getDefinition()));
case "concat":
// Pinot's concat function is a bit different from Presto's, taking only two arguments (and a separator) at a time.
// We nest and repeat concat function calls to handle additional arguments.
int numArguments = function.getArguments().size();
int numArguments = arguments.size();
return derived(String.format(
"%s%s%s",
Strings.repeat(String.format("%s(", functionName), numArguments - 1),
getExpressionOrConstantString(function.getArguments().get(0), context),
function.getArguments().subList(1, numArguments).stream()
arguments.subList(1, numArguments).stream()
.map(argument -> String.format(", %s, '')", getExpressionOrConstantString(argument, context)))
.collect(Collectors.joining(""))));
case "strpos":
// Pinot strings are 0-indexed, while Presto strings are 1-indexed.
if (arguments.size() == 2) {
return derived(String.format(
"%s(%s,%s) + 1",
functionName,
arguments.get(0).accept(this, context).getDefinition(),
arguments.get(1).accept(this, context).getDefinition()));
}
return derived(String.format(
"%s(%s,%s,%s) + 1",
functionName,
arguments.get(0).accept(this, context).getDefinition(),
arguments.get(1).accept(this, context).getDefinition(),
arguments.get(2).accept(this, context).getDefinition()));
default:
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("function %s not supported in filter yet", function.getDisplayName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public void testFilterExpressionConverter()
testFilter("CONCAT(city, ', CA', city) IN ('San Jose', 'Campbell')",
"(concat(concat(\"city\", ', CA', ''), \"city\", '') IN ('San Jose', 'Campbell'))", sessionHolder);

// strpos
testFilter("STRPOS(\"city\", 'Seattle') = 1", "(strpos(\"city\",'Seattle') + 1 = 1)", sessionHolder);

// case, coalesce, if
testFilter("CASE WHEN city = 'Campbell' THEN regionid ELSE 0 END",
"CASE true WHEN (\"city\" = 'Campbell') THEN \"regionId\" ELSE 0 END", sessionHolder);
Expand Down

0 comments on commit 816187a

Please sign in to comment.