@@ -255,16 +255,7 @@ impl<C: Context> Coalesce for Schema<C> {
255255 } ,
256256 ) => {
257257 self_agg. coalesce ( other_agg) ;
258- for ( name, other_schema) in other_fields {
259- match self_fields. entry ( name) {
260- Entry :: Occupied ( mut schema) => {
261- schema. get_mut ( ) . coalesce ( other_schema) ;
262- }
263- Entry :: Vacant ( entry) => {
264- entry. insert ( other_schema) ;
265- }
266- }
267- }
258+ coalesce_struct_fields ( self_fields, other_fields) ;
268259 }
269260 (
270261 Union {
@@ -370,16 +361,7 @@ impl<C: Context> Coalesce for Schema<C> {
370361 } ,
371362 ) => {
372363 self_agg. coalesce ( other_agg) ;
373- for ( name, other_schema) in other_fields {
374- match self_fields. entry ( name) {
375- Entry :: Occupied ( mut schema) => {
376- schema. get_mut ( ) . coalesce ( other_schema) ;
377- }
378- Entry :: Vacant ( entry) => {
379- entry. insert ( other_schema) ;
380- }
381- }
382- }
364+ coalesce_struct_fields ( self_fields, other_fields) ;
383365 return ;
384366 }
385367
@@ -393,6 +375,33 @@ impl<C: Context> Coalesce for Schema<C> {
393375 // If we were unable to find a match, push the schema to the alternatives:
394376 alternatives. push ( other) ;
395377 }
378+
379+ fn coalesce_struct_fields < C : Context > (
380+ self_fields : & mut OrderMap < std:: string:: String , Field < C > > ,
381+ other_fields : OrderMap < std:: string:: String , Field < C > > ,
382+ ) where
383+ Field < C > : Coalesce ,
384+ {
385+ // Fields in self but not in other were missing from other's documents.
386+ for ( name, field) in self_fields. iter_mut ( ) {
387+ if !other_fields. contains_key ( name) {
388+ field. status . may_be_missing = true ;
389+ }
390+ }
391+ for ( name, other_field) in other_fields {
392+ match self_fields. entry ( name) {
393+ Entry :: Occupied ( mut entry) => {
394+ entry. get_mut ( ) . coalesce ( other_field) ;
395+ }
396+ // Fields in other but not in self were missing from self's documents.
397+ Entry :: Vacant ( entry) => {
398+ let mut field = other_field;
399+ field. status . may_be_missing = true ;
400+ entry. insert ( field) ;
401+ }
402+ }
403+ }
404+ }
396405 }
397406}
398407
0 commit comments