Support PPL format command - #5659
Conversation
PR Reviewer Guide 🔍(Review updated until commit 669bee1)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 669bee1
Previous suggestionsSuggestions up to commit da0ec85
|
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
Signed-off-by: Songkan Tang <songkant@amazon.com>
da0ec85 to
669bee1
Compare
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit 669bee1.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
|
Persistent review updated to latest commit 669bee1 |
| @@ -0,0 +1,132 @@ | |||
| # format | |||
There was a problem hiding this comment.
enable doc-test for format command.
| "{\"query\": \"search source=%s [ search source=%s name=alice | fields name | head" | ||
| + " 1 ] | fields name\"}", |
There was a problem hiding this comment.
Test query not releated to format command.
| ```ppl | ||
| source=logs | ||
| | fields status, method | ||
| | format maxresults=2 "[" "[" "&&" "]" "||" "]" | ||
| ``` |
| ```ppl | ||
| source=logs | ||
| | where status=999 | ||
| | fields status | ||
| | format emptystr="no matching data" | ||
| ``` |
|
|
||
| ## Limitations | ||
|
|
||
| - Implicit format requires the Calcite query engine. |
There was a problem hiding this comment.
Why mention calcite engine specific? It is our default execution engine.
| - When upstream ordering metadata is available, row collection carries it into the aggregate order | ||
| key. Without an explicit upstream `sort`, distributed execution does not guarantee row order. |
There was a problem hiding this comment.
This is not a real limitation.
| | format emptystr="no matching data" | ||
| ``` | ||
|
|
||
| ## Limitations |
There was a problem hiding this comment.
Polish limitation section. make it user friendly.
| | Parameter | Default | Description | | ||
| | --- | --- | --- | | ||
| | `mvsep` | `OR` | Separator between values from a multivalue field. | | ||
| | `maxresults` | `0` | Maximum input rows to include. `0` means unlimited. | |
| searchPredicate | ||
| : searchExpression EOF | ||
| ; |
There was a problem hiding this comment.
this is enhancement of search command, please update search command doc.
There was a problem hiding this comment.
Does this feature works with append + search command?
| searchPredicate | ||
| : searchExpression EOF | ||
| ; |
There was a problem hiding this comment.
Does this feature works with append + search command?
| import org.opensearch.sql.calcite.SearchPredicateCompiler; | ||
|
|
||
| /** Runtime query-string input consumed by a correlated OpenSearch scan. */ | ||
| public record DynamicQueryStringSpec( |
There was a problem hiding this comment.
avoid using record. hard to backport.
| }; | ||
| } | ||
|
|
||
| private String buildRuntimeQuery(String[] queryParts) { |
There was a problem hiding this comment.
buildRuntimeQuery is a function of DynamicQueryStringSpec
| SearchPredicateCompiler compiler) { | ||
|
|
||
| /** Splits concatenation so only subsearch outputs are parsed as PPL predicates. */ | ||
| public static DynamicQueryStringSpec create( |
| .setCorrelates(implementor::getCorrelVariableGetter); | ||
| List<Expression> queryParts = | ||
| translator.translateList(pushDownContext.getDynamicQueryString().queryParts()).stream() | ||
| .map(expression -> (Expression) Expressions.convert_(expression, String.class)) |
There was a problem hiding this comment.
what if the results can not be convert to string? what is customer facing error message?
| public boolean hasImplicitSubquery() { | ||
| return queryString == null; | ||
| } |
There was a problem hiding this comment.
queryString and subsearch can not co-exist?
| } | ||
|
|
||
| @Test | ||
| public void testImplicitFormatExecutesRawSearchField() throws IOException { |
There was a problem hiding this comment.
source = outer a in [ source = inner | fields a ] is as same as source = outer [ source = inner | fields a ]. the dynamic string pushdown works for both cases?
Description
Adds the PPL format command, which collapses tabular results into a single search-expression string. It supports configurable row, column, and multivalue delimiters; maxresults; emptystr; null handling; and quote/backslash escaping.
The command also supports runtime search predicates produced by subsearches:
The subsearch result is formatted into one scalar search string and combined with the static parent predicate before the OpenSearch request is executed. Explicit format output remains a normal one-row result and can continue through later pipeline commands.
Design
Testing
Related Issues
Related to #5233
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.