@@ -20,24 +20,53 @@ public class MergeConflictResultWrapper {
20
20
private final Lazy <ByteBuffer > oldValueByteBufferProvider ;
21
21
private final RmdWithValueSchemaId oldRmdWithValueSchemaId ;
22
22
private final ChunkedValueManifestContainer oldValueManifestContainer ;
23
+
24
+ // Serialized and potentially compressed updated value bytes
23
25
private final ByteBuffer updatedValueBytes ;
24
26
private final ByteBuffer updatedRmdBytes ;
25
27
28
+ /**
29
+ * Best-effort deserialized value provider that provides the updated value for PUT/UPDATE and the old value for
30
+ * DELETE.
31
+ */
32
+ private final Lazy <GenericRecord > valueProvider ;
33
+
26
34
public MergeConflictResultWrapper (
27
35
MergeConflictResult mergeConflictResult ,
28
36
Lazy <ByteBufferValueRecord <ByteBuffer >> oldValueProvider ,
29
37
Lazy <ByteBuffer > oldValueByteBufferProvider ,
30
38
RmdWithValueSchemaId oldRmdWithValueSchemaId ,
31
39
ChunkedValueManifestContainer oldValueManifestContainer ,
32
40
ByteBuffer updatedValueBytes ,
33
- ByteBuffer updatedRmdBytes ) {
41
+ ByteBuffer updatedRmdBytes ,
42
+ Function <Integer , RecordDeserializer <GenericRecord >> deserializerProvider ) {
34
43
this .mergeConflictResult = mergeConflictResult ;
35
44
this .oldValueProvider = oldValueProvider ;
36
45
this .oldValueByteBufferProvider = oldValueByteBufferProvider ;
37
46
this .oldRmdWithValueSchemaId = oldRmdWithValueSchemaId ;
38
47
this .oldValueManifestContainer = oldValueManifestContainer ;
39
48
this .updatedValueBytes = updatedValueBytes ;
40
49
this .updatedRmdBytes = updatedRmdBytes ;
50
+ if (updatedValueBytes == null ) {
51
+ // this is a DELETE
52
+ ByteBufferValueRecord <ByteBuffer > oldValue = oldValueProvider .get ();
53
+ if (oldValue == null || oldValue .value () == null ) {
54
+ this .valueProvider = Lazy .of (() -> null );
55
+ } else {
56
+ this .valueProvider =
57
+ Lazy .of (() -> deserializerProvider .apply (oldValue .writerSchemaId ()).deserialize (oldValue .value ()));
58
+ }
59
+ } else {
60
+ // this is a PUT or UPDATE
61
+ if (mergeConflictResult .getDeserializedValue ().isPresent ()) {
62
+ this .valueProvider = Lazy .of (() -> mergeConflictResult .getDeserializedValue ().get ());
63
+ } else {
64
+ // Use mergeConflictResult.getNewValue() here since updatedValueBytes could be compressed.
65
+ this .valueProvider = Lazy .of (
66
+ () -> deserializerProvider .apply (mergeConflictResult .getValueSchemaId ())
67
+ .deserialize (mergeConflictResult .getNewValue ()));
68
+ }
69
+ }
41
70
}
42
71
43
72
public MergeConflictResult getMergeConflictResult () {
@@ -74,24 +103,7 @@ public ByteBuffer getUpdatedRmdBytes() {
74
103
* 2. returns the old value for DELETE (null for non-existent key).
75
104
* 3. returns null if the value is not available.
76
105
*/
77
- public Lazy <GenericRecord > getNewValueProvider (
78
- Function <Integer , RecordDeserializer <GenericRecord >> deserializerProvider ) {
79
- if (updatedValueBytes == null ) {
80
- // this is a DELETE
81
- ByteBufferValueRecord <ByteBuffer > oldValue = oldValueProvider .get ();
82
- if (oldValue == null || oldValue .value () == null ) {
83
- return Lazy .of (() -> null );
84
- }
85
- return Lazy .of (() -> deserializerProvider .apply (oldValue .writerSchemaId ()).deserialize (oldValue .value ()));
86
- } else {
87
- // this is a PUT or UPDATE
88
- if (mergeConflictResult .getValueDeserialized ().isPresent ()) {
89
- return Lazy .of (() -> mergeConflictResult .getValueDeserialized ().get ());
90
- }
91
- // Use mergeConflictResult.getNewValue() here and not updatedValueBytes for non-compressed value bytes.
92
- return Lazy .of (
93
- () -> deserializerProvider .apply (mergeConflictResult .getValueSchemaId ())
94
- .deserialize (mergeConflictResult .getNewValue ()));
95
- }
106
+ public Lazy <GenericRecord > getNewValueProvider () {
107
+ return valueProvider ;
96
108
}
97
109
}
0 commit comments