@@ -55,44 +55,36 @@ public ExprValue next() {
55
55
*/
56
56
private static ExprValue flattenExprValueAtPath (ExprValue rootExprValue , String path ) {
57
57
58
- Matcher matcher = ExprValueUtils .QUALIFIED_NAME_SEPARATOR_PATTERN .matcher (path );
59
58
Map <String , ExprValue > exprValueMap = ExprValueUtils .getTupleValue (rootExprValue );
60
59
61
- // [A] Flatten nested struct value
62
- // -------------------------------
63
-
64
- if (matcher .find ()) {
65
- String currentPathComponent = path .substring (0 , matcher .start ());
66
- String remainingPath = path .substring (matcher .end ());
67
-
68
- if (!exprValueMap .containsKey (currentPathComponent )) {
69
- return rootExprValue ;
70
- }
71
-
72
- ExprValue childExprValue = exprValueMap .get (currentPathComponent );
73
- if (childExprValue .isNull () || childExprValue .isMissing ()) {
74
- return rootExprValue ;
75
- }
76
-
77
- ExprValue flattenedExprValue =
78
- flattenExprValueAtPath (exprValueMap .get (currentPathComponent ), remainingPath );
79
- exprValueMap .put (currentPathComponent , flattenedExprValue );
80
- return ExprTupleValue .fromExprValueMap (exprValueMap );
81
- }
82
-
83
- // [B] Flatten child struct value
84
- // ------------------------------
60
+ // Get current path component.
61
+ Matcher matcher = ExprValueUtils .QUALIFIED_NAME_SEPARATOR_PATTERN .matcher (path );
62
+ boolean fieldIsNested = matcher .find ();
63
+ String currentPathComponent = fieldIsNested ? path .substring (0 , matcher .start ()) : path ;
85
64
86
- if (!exprValueMap .containsKey (path )) {
65
+ // Check for undefined, null, or missing values.
66
+ if (!exprValueMap .containsKey (currentPathComponent )) {
87
67
return rootExprValue ;
88
68
}
89
69
90
- ExprValue childExprValue = exprValueMap .get (path );
70
+ ExprValue childExprValue = exprValueMap .get (currentPathComponent );
91
71
if (childExprValue .isNull () || childExprValue .isMissing ()) {
92
72
return rootExprValue ;
93
73
}
94
74
95
- exprValueMap .putAll (ExprValueUtils .getTupleValue (childExprValue ));
75
+ // Get flattened values and add them to the field map.
76
+ Map <String , ExprValue > flattenedExprValueMap ;
77
+ if (fieldIsNested ) {
78
+ String remainingPath = path .substring (matcher .end ());
79
+ flattenedExprValueMap =
80
+ Map .of (
81
+ currentPathComponent ,
82
+ flattenExprValueAtPath (exprValueMap .get (currentPathComponent ), remainingPath ));
83
+ } else {
84
+ flattenedExprValueMap = ExprValueUtils .getTupleValue (childExprValue );
85
+ }
86
+
87
+ exprValueMap .putAll (flattenedExprValueMap );
96
88
return ExprTupleValue .fromExprValueMap (exprValueMap );
97
89
}
98
90
}
0 commit comments