35
35
import com .apple .foundationdb .record .provider .common .StoreTimer ;
36
36
import com .apple .foundationdb .record .provider .foundationdb .FDBRecordStoreBase ;
37
37
import com .apple .foundationdb .record .provider .foundationdb .FDBStoreTimer ;
38
- import com .apple .foundationdb .record .query .plan .explain .ExplainPlanVisitor ;
39
38
import com .apple .foundationdb .record .query .plan .cascades .AliasMap ;
40
39
import com .apple .foundationdb .record .query .plan .cascades .CorrelationIdentifier ;
41
40
import com .apple .foundationdb .record .query .plan .cascades .Quantifier ;
50
49
import com .apple .foundationdb .record .query .plan .cascades .values .ObjectValue ;
51
50
import com .apple .foundationdb .record .query .plan .cascades .values .Value ;
52
51
import com .apple .foundationdb .record .query .plan .cascades .values .translation .TranslationMap ;
52
+ import com .apple .foundationdb .record .query .plan .explain .ExplainPlanVisitor ;
53
53
import com .apple .foundationdb .record .query .plan .serialization .PlanSerialization ;
54
54
import com .google .auto .service .AutoService ;
55
55
import com .google .common .collect .ImmutableList ;
@@ -370,7 +370,8 @@ public PRecordQueryStreamingAggregationPlan toProto(@Nonnull final PlanSerializa
370
370
}
371
371
builder .setGroupingKeyAlias (groupingKeyAlias .getId ())
372
372
.setAggregateAlias (aggregateAlias .getId ())
373
- .setCompleteResultValue (completeResultValue .toValueProto (serializationContext ));
373
+ .setCompleteResultValue (completeResultValue .toValueProto (serializationContext ))
374
+ .setIsCreateDefaultOnEmpty (isCreateDefaultOnEmpty );
374
375
return builder .build ();
375
376
}
376
377
@@ -384,15 +385,18 @@ public PRecordQueryPlan toRecordQueryPlanProto(@Nonnull final PlanSerializationC
384
385
@ Nonnull
385
386
public static RecordQueryStreamingAggregationPlan fromProto (@ Nonnull final PlanSerializationContext serializationContext ,
386
387
@ Nonnull final PRecordQueryStreamingAggregationPlan recordQueryStreamingAggregationPlanProto ) {
387
- return new RecordQueryStreamingAggregationPlan (Quantifier .Physical .fromProto (serializationContext , Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getInner ())),
388
- PlanSerialization .getFieldOrNull (recordQueryStreamingAggregationPlanProto ,
389
- PRecordQueryStreamingAggregationPlan ::hasGroupingKeyValue ,
390
- m -> Value .fromValueProto (serializationContext , m .getGroupingKeyValue ())),
391
- (AggregateValue )Value .fromValueProto (serializationContext , Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getAggregateValue ())),
392
- CorrelationIdentifier .of (Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getGroupingKeyAlias ())),
393
- CorrelationIdentifier .of (Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getAggregateAlias ())),
394
- Value .fromValueProto (serializationContext , Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getCompleteResultValue ())),
395
- recordQueryStreamingAggregationPlanProto .hasIsCreateDefaultOnEmpty () ? recordQueryStreamingAggregationPlanProto .getIsCreateDefaultOnEmpty () : true );
388
+ // Note: it is important for proper deserialization (at least of things that interact with the serializationContext's cache of
389
+ // referenced values and plans) that we deserialize the values in the same order as they are serialized, or we may
390
+ // not
391
+ final Quantifier .Physical inner = Quantifier .Physical .fromProto (serializationContext , Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getInner ()));
392
+ final AggregateValue aggregateValue = (AggregateValue ) Value .fromValueProto (serializationContext , Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getAggregateValue ()));
393
+ @ Nullable final Value groupingKeyValue = PlanSerialization .getFieldOrNull (recordQueryStreamingAggregationPlanProto , PRecordQueryStreamingAggregationPlan ::hasGroupingKeyValue ,
394
+ m -> Value .fromValueProto (serializationContext , m .getGroupingKeyValue ()));
395
+ final CorrelationIdentifier groupingKeyAlias = CorrelationIdentifier .of (Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getGroupingKeyAlias ()));
396
+ final CorrelationIdentifier aggregateAlias = CorrelationIdentifier .of (Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getAggregateAlias ()));
397
+ final Value completeResultValue = Value .fromValueProto (serializationContext , Objects .requireNonNull (recordQueryStreamingAggregationPlanProto .getCompleteResultValue ()));
398
+ final boolean isCreateDefaultOnEmpty = recordQueryStreamingAggregationPlanProto .hasIsCreateDefaultOnEmpty () ? recordQueryStreamingAggregationPlanProto .getIsCreateDefaultOnEmpty () : true ;
399
+ return new RecordQueryStreamingAggregationPlan (inner , groupingKeyValue , aggregateValue , groupingKeyAlias , aggregateAlias , completeResultValue , isCreateDefaultOnEmpty );
396
400
}
397
401
398
402
@ Nonnull
0 commit comments