Repository navigation
Support flatten command with Calcite - #3747
Conversation
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
| { | ||
| "mappings": { | ||
| "properties": { | ||
| "message": { |
There was a problem hiding this comment.
message is Json Object, why index as nested field. Usually, Json Array is indexed as nested field.
There was a problem hiding this comment.
Yes, using object here is more clear. Fixed.
However, the boundary between array and object is blurry in OpenSearch. Both object and array fields can store a struct or an array of structs. Both nested and object works in this case.
|
|
||
| Note that ``flatten`` does not work on arrays. Please use ``expand`` command | ||
| to expand an array field into multiple rows instead. If the field is an nested | ||
| array of structs, only the first element of the array will be flattened. |
There was a problem hiding this comment.
If the field is an nested array of structs,
Why work on Array of structs if flatten does not work on Array?
There was a problem hiding this comment.
It's because although not expected, an object/nested field can store arrays. I have updated the doc to make it easier to understand.
| * <p>The flatten command is used to flatten a struct field into multiple fields. This | ||
| * implementation simply projects the flattened fields and renames them according to the provided | ||
| * aliases or the field names in the struct. This is possible because the struct / object field | ||
| * are always read in a flattened manner in OpenSearch. |
There was a problem hiding this comment.
Could u explain flattened manner in OpenSearch? what is expected result from OpenSearch
There was a problem hiding this comment.
Flatten extracts the fields in a struct into separate other fields in the document:
E.g. For
{"name": "Jack", "address": {"state": "Oregon", "city": "Portland"}}
Flattening address will result in
{"name": "Jack", "address": {"state": "Oregon", "city": "Portland"}, "state": "Oregon", "city": "Portland"}
(Also copied to PR description)
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
Signed-off-by: Yuanchun Shen <[email protected]>
| * @return RelNode representing the visited logical plan | ||
| */ | ||
| @Override | ||
| public RelNode visitFlatten(Flatten node, CalcitePlanContext context) { |
There was a problem hiding this comment.
Seems the implementation relies on the flattened nested fields in the RelRowType, but it may not work for PPL:
source = index | fields message| flatten message
There was a problem hiding this comment.
It fails this test case indeed. Trying to fix it.
qianheng-aws
left a comment
There was a problem hiding this comment.
Need test for this case:
source = index | fields message| flatten message
…er fields Signed-off-by: Yuanchun Shen <[email protected]>
|
|
||
| Limitations | ||
| =========== | ||
| * ``flatten`` after ``fields`` is not supported under the current |
There was a problem hiding this comment.
Change to:
flatten command may not work as expected when its flattened fields are invisible.
For example in query source=my-index | fields message | flatten message,
the flatten message command doesn't work since some flattened fields such as message.info and message.author after command fields message are invisible.
As an alternative, you can change to source=my-index | flatten message
Signed-off-by: Yuanchun Shen <[email protected]>
* WIP: Implementing flatten Signed-off-by: Yuanchun Shen <[email protected]> * Update flatten IT Signed-off-by: Yuanchun Shen <[email protected]> * Support flatten with aliases Signed-off-by: Yuanchun Shen <[email protected]> * Document flatten command Signed-off-by: Yuanchun Shen <[email protected]> * Improve docs for flatten Signed-off-by: Yuanchun Shen <[email protected]> * Fix unix test for flatten command Signed-off-by: Yuanchun Shen <[email protected]> * Remove redundant *from 3.1.0* tag in appendcol's doc Signed-off-by: Yuanchun Shen <[email protected]> * Unify command doc's language Signed-off-by: Yuanchun Shen <[email protected]> * Revert "Unify command doc's language" This reverts commit 8750e2f. Signed-off-by: Yuanchun Shen <[email protected]> * Remove since from flatten's doc Signed-off-by: Yuanchun Shen <[email protected]> * Update doc of flatten command Signed-off-by: Yuanchun Shen <[email protected]> * Test flatten null fields Signed-off-by: Yuanchun Shen <[email protected]> * Add an ignored test case and limitation explainations for flatten after fields Signed-off-by: Yuanchun Shen <[email protected]> * Rephrase flatten limitations Signed-off-by: Yuanchun Shen <[email protected]> --------- Signed-off-by: Yuanchun Shen <[email protected]> Signed-off-by: xinyual <[email protected]>
Description
Implement
flattencommand that flattens a nested struct / object field into separate fields in a document.Flatten extracts the fields in a struct into separate other fields in the document:
E.g. For
Flattening
addresswill result inRelated Issues
Resolves #3712
Check List
--signoff.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.