@@ -321,14 +321,32 @@ private Inclusion getFieldInclusion(Path field, ProjectionList p, Path context)
321
321
LOGGER .debug ("Checking if a projection list projects {}" , field );
322
322
Inclusion lastResult = Inclusion .undecided ;
323
323
List <Projection > items = p .getItems ();
324
+ // Iterate projection list backwards. This way, the last projection expression that makes a decision on the field wins
325
+ // There are exceptions to this below
324
326
ListIterator <Projection > itemsItr = items .listIterator (items .size ());
325
327
while (itemsItr .hasPrevious ()) {
326
328
Inclusion ret = itemsItr .previous ().getFieldInclusion (field , context );
327
329
if (ret != Inclusion .undecided ) {
328
- lastResult = ret ;
329
- break ;
330
+ // This projection expression makes a decision on the field
331
+ // If the decision is explicit, then return it
332
+ if (ret == Inclusion .explicit_inclusion ||
333
+ ret == Inclusion .explicit_exclusion ) {
334
+ lastResult =ret ;
335
+ break ;
336
+ }
337
+
338
+ // Here, ret is implicit inclusion or implicit exclusion
339
+ // If lastResult is undecided, then keep this decision
340
+ // If lastResult is not undecided, then it is an implicit decision, and that stays
341
+ if (lastResult ==Inclusion .undecided ) {
342
+ lastResult = ret ;
343
+ }
330
344
}
331
345
}
346
+ // Here: if we have a projection list with:
347
+ // [ explicit_inclusion, implicit_inclusion ]
348
+ // we return explicit_inclusion. Same with
349
+ // [ implicit_inclusion, explicit_inclusion]
332
350
LOGGER .debug ("Projection list projects {}: {}" , field , lastResult );
333
351
return lastResult ;
334
352
}
0 commit comments