Skip to content

Commit

Permalink
Spotless
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Feb 7, 2025
1 parent b19d28b commit 766fd65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.opensearch.sql.planner.physical;

import static org.opensearch.sql.utils.PathUtils.SEPARATOR_PATTERN;

import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -17,7 +19,6 @@
import org.opensearch.sql.data.model.ExprValue;
import org.opensearch.sql.data.model.ExprValueUtils;
import org.opensearch.sql.expression.ReferenceExpression;
import org.opensearch.sql.utils.PathUtils;

/** Flattens the specified field from the input and returns the result. */
@Getter
Expand Down Expand Up @@ -50,13 +51,14 @@ public ExprValue next() {
}

/**
* Flattens the {@link ExprTupleValue} at the specified path and returns the update value. If the
* value is null or missing, the unmodified value is returned.
* Flattens the {@link ExprTupleValue} at the specified path within the given root value and
* returns the result. Returns the unmodified root value if it does not contain a value at the
* specified path.
*/
private static ExprValue flattenExprValueAtPath(ExprValue exprValue, String path) {
private static ExprValue flattenExprValueAtPath(ExprValue rootExprValue, String path) {

Matcher matcher = PathUtils.SEPARATOR_PATTERN.matcher(path);
Map<String, ExprValue> exprValueMap = ExprValueUtils.getTupleValue(exprValue);
Matcher matcher = SEPARATOR_PATTERN.matcher(path);
Map<String, ExprValue> exprValueMap = ExprValueUtils.getTupleValue(rootExprValue);

// [A] Flatten nested struct value
// -------------------------------
Expand All @@ -66,12 +68,12 @@ private static ExprValue flattenExprValueAtPath(ExprValue exprValue, String path
String remainingPath = path.substring(matcher.end());

if (!exprValueMap.containsKey(currentPathComponent)) {
return exprValue;
return rootExprValue;
}

ExprValue childExprValue = exprValueMap.get(currentPathComponent);
if (childExprValue.isNull() || childExprValue.isMissing()) {
return exprValue;
return rootExprValue;
}

ExprValue flattenedExprValue =
Expand All @@ -84,7 +86,7 @@ private static ExprValue flattenExprValueAtPath(ExprValue exprValue, String path
// ------------------------------

if (!exprValueMap.containsKey(path)) {
return exprValue;
return rootExprValue;
}

ExprValue childExprValue = exprValueMap.get(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,9 @@ void testStructNestedDeep() {

@Test
void testInvalidName() {
Exception ex;

ex = assertThrows(SemanticCheckException.class, () -> executeFlatten("invalid"));
assertEquals(
"can't resolve Symbol(namespace=FIELD_NAME, name=invalid) in type env", ex.getMessage());

ex = assertThrows(SemanticCheckException.class, () -> executeFlatten(".invalid"));
assertEquals(
"can't resolve Symbol(namespace=FIELD_NAME, name=.invalid) in type env", ex.getMessage());

ex = assertThrows(SemanticCheckException.class, () -> executeFlatten("invalid."));
assertEquals(
"can't resolve Symbol(namespace=FIELD_NAME, name=invalid.) in type env", ex.getMessage());
assertThrows(SemanticCheckException.class, () -> executeFlatten("invalid"));
assertThrows(SemanticCheckException.class, () -> executeFlatten(".invalid"));
assertThrows(SemanticCheckException.class, () -> executeFlatten("invalid."));
}

@Test
Expand Down

0 comments on commit 766fd65

Please sign in to comment.