Skip to content

Commit

Permalink
Review comment - update Analyzer.visitFlatten Javadoc to specify th…
Browse files Browse the repository at this point in the history
…at it also updates env, plus Javadoc formatting.

Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Feb 6, 2025
1 parent f6c1121 commit 735c265
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions core/src/main/java/org/opensearch/sql/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,20 +455,45 @@ public LogicalPlan visitEval(Eval node, AnalysisContext context) {

/**
* Builds and returns a {@link org.opensearch.sql.planner.logical.LogicalFlatten} corresponding to
* the given flatten node.
* the given flatten node, and adds the new fields to the current type environment.
*
* <p><b>Example</b>
*
* <p>Input Data:
*
* <p>[ struct: { integer: 0, nested_struct: { string: "value" } } ]
* <pre>
* [
* struct: {
* integer: 0,
* nested_struct: { string: "value" }
* }
* ]
* </pre>
*
* <p>Example 1: 'flatten struct'
* Query 1: <code>flatten struct</code>
*
* <p>[ struct: { integer: 0, nested_struct: { string: "value" } }, integer: 0, nested_struct: {
* string: "value" } ]
* <pre>
* [
* struct: {
* integer: 0,
* nested_struct: { string: "value" }
* },
* integer: 0,
* nested_struct: { string: "value" }
* ]
* </pre>
*
* <p>Example 2: 'flatten struct.nested_struct'
* Query 2: <code>flatten struct.nested_struct</code>
*
* <p>[ struct: { integer: 0, nested_struct: { string: "value" } string: "value" { ]
* <pre>
* [
* struct: {
* integer: 0,
* nested_struct: { string: "value" },
* string: "value"
* }
* ]
* </pre>
*/
@Override
public LogicalPlan visitFlatten(Flatten node, AnalysisContext context) {
Expand Down Expand Up @@ -515,8 +540,8 @@ public LogicalPlan visitFlatten(Flatten node, AnalysisContext context) {
addFieldsMap.put(newPath, type);
}

// [B] Update environment
// ----------------------
// [B] Add new fields to type environment
// --------------------------------------

for (Map.Entry<String, ExprType> entry : addFieldsMap.entrySet()) {
String name = entry.getKey();
Expand Down

0 comments on commit 735c265

Please sign in to comment.