1515package dev .cel .runtime .planner ;
1616
1717import dev .cel .common .exceptions .CelAttributeNotFoundException ;
18+ import dev .cel .common .values .OptionalValue ;
1819import dev .cel .common .values .SelectableValue ;
1920import java .util .Map ;
2021
@@ -31,21 +32,34 @@ public String value() {
3132 @ Override
3233 @ SuppressWarnings ("unchecked" ) // Qualifications on maps/structs must be a string
3334 public Object qualify (Object obj ) {
35+ if (obj instanceof OptionalValue ) {
36+ OptionalValue <?, ?> opt = (OptionalValue <?, ?>) obj ;
37+ if (!opt .isZeroValue ()) {
38+ Object inner = opt .value ();
39+ if (!(inner instanceof SelectableValue ) && !(inner instanceof Map )) {
40+ throw CelAttributeNotFoundException .forFieldResolution (value );
41+ }
42+ }
43+ }
44+
3445 if (obj instanceof SelectableValue ) {
3546 return ((SelectableValue <String >) obj ).select (value );
36- } else if (obj instanceof Map ) {
37- Map <String , Object > map = (Map <String , Object >) obj ;
38- if (!map .containsKey (value )) {
39- throw CelAttributeNotFoundException .forMissingMapKey (value );
40- }
47+ }
4148
49+ if (obj instanceof Map ) {
50+ Map <?, ?> map = (Map <?, ?>) obj ;
4251 Object mapVal = map .get (value );
4352
44- if (mapVal == null ) {
45- throw CelAttributeNotFoundException .of (
46- String .format ("Map value cannot be null for key: %s" , value ));
53+ if (mapVal != null ) {
54+ return mapVal ;
55+ }
56+
57+ if (!map .containsKey (value )) {
58+ throw CelAttributeNotFoundException .forMissingMapKey (value );
4759 }
48- return map .get (value );
60+
61+ throw CelAttributeNotFoundException .of (
62+ String .format ("Map value cannot be null for key: %s" , value ));
4963 }
5064
5165 throw CelAttributeNotFoundException .forFieldResolution (value );
0 commit comments