Support PPL format command - #5659
Conversation
PR Reviewer Guide 🔍(Review updated until commit 6c89411)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 6c89411 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 669bee1
Suggestions 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.
There was a problem hiding this comment.
Removed the engine-specific wording.
| - 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.
There was a problem hiding this comment.
Rewritten in user-facing terms with concrete valid and invalid examples.
| | Parameter | Default | Description | | ||
| | --- | --- | --- | | ||
| | `mvsep` | `OR` | Separator between values from a multivalue field. | | ||
| | `maxresults` | `0` | Maximum input rows to include. `0` means unlimited. | |
There was a problem hiding this comment.
Clarified maxresults. In case of implicit subsearch, subsearch will formats result rows capped by subsearch.maxout settings. But even this is legit, the OpenSearch query_string execution could error out due to indices.query.bool.max_clause_countlimit
| 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?
There was a problem hiding this comment.
Updated search.md with bracketed subsearch behavior and examples.
There was a problem hiding this comment.
Yes, this feature works with append command combination. Added tests for append inside the subsearch and after the parent dynamic search.
| 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.
There was a problem hiding this comment.
Replaced it with a regular final class.
| }; | ||
| } | ||
|
|
||
| private String buildRuntimeQuery(String[] queryParts) { |
There was a problem hiding this comment.
buildRuntimeQuery is a function of DynamicQueryStringSpec
There was a problem hiding this comment.
Moved buildRuntimeQuery into 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?
There was a problem hiding this comment.
Added validation and user-facing errors for non-text results and invalid generated predicates.
There was a problem hiding this comment.
Generally, the scalar type fields could be always converted to string. But the multiset type or array type are not supported, the error message will tell user to avoid it.
| public boolean hasImplicitSubquery() { | ||
| return queryString == null; | ||
| } |
There was a problem hiding this comment.
queryString and subsearch can not co-exist?
There was a problem hiding this comment.
They can coexist in the original search expression. Detection now inspects the expression tree, so static and subsearch predicates are handled together.
| } | ||
|
|
||
| @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?
There was a problem hiding this comment.
search a IN [subquery] is not valid search syntax; search IN accepts a literal list. Relational IN [subquery] is supported in where, and an integration test now covers it after an implicit-format search.
Signed-off-by: Songkan Tang <songkant@amazon.com>
|
Persistent review updated to latest commit 6c89411 |
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.