Skip to content

Commit 5907ad5

Browse files
committed
chore(spanner): update logic
1 parent 65b3234 commit 5907ad5

File tree

1 file changed

+24
-13
lines changed
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner

1 file changed

+24
-13
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Mutation.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,12 @@ static com.google.spanner.v1.Mutation toProtoGetRandomMutation(
433433
if (proto != null) {
434434
com.google.spanner.v1.Mutation builtMutation = proto.build();
435435
out.add(builtMutation);
436-
allMutationsExcludingInsert.add(builtMutation);
436+
if (checkIfInsertMutationWithLargeValue(builtMutation, largeInsertMutation)) {
437+
largeInsertMutation = builtMutation;
438+
}
439+
if (!builtMutation.hasInsert()) {
440+
allMutationsExcludingInsert.add(builtMutation);
441+
}
437442
}
438443
proto = com.google.spanner.v1.Mutation.newBuilder();
439444
com.google.spanner.v1.Mutation.Delete.Builder delete =
@@ -457,12 +462,10 @@ static com.google.spanner.v1.Mutation toProtoGetRandomMutation(
457462
if (proto != null) {
458463
com.google.spanner.v1.Mutation builtMutation = proto.build();
459464
out.add(builtMutation);
460-
if (builtMutation.hasInsert()) {
461-
if (builtMutation.getInsert().getValuesCount()
462-
> largeInsertMutation.getInsert().getValuesCount()) {
463-
largeInsertMutation = builtMutation;
464-
}
465-
} else {
465+
if (checkIfInsertMutationWithLargeValue(builtMutation, largeInsertMutation)) {
466+
largeInsertMutation = builtMutation;
467+
}
468+
if (!builtMutation.hasInsert()) {
466469
allMutationsExcludingInsert.add(builtMutation);
467470
}
468471
}
@@ -493,12 +496,10 @@ static com.google.spanner.v1.Mutation toProtoGetRandomMutation(
493496
if (proto != null) {
494497
com.google.spanner.v1.Mutation builtMutation = proto.build();
495498
out.add(proto.build());
496-
if (builtMutation.hasInsert()) {
497-
if (builtMutation.getInsert().getValuesCount()
498-
> largeInsertMutation.getInsert().getValuesCount()) {
499-
largeInsertMutation = builtMutation;
500-
}
501-
} else {
499+
if (checkIfInsertMutationWithLargeValue(builtMutation, largeInsertMutation)) {
500+
largeInsertMutation = builtMutation;
501+
}
502+
if (!builtMutation.hasInsert()) {
502503
allMutationsExcludingInsert.add(builtMutation);
503504
}
504505
}
@@ -514,4 +515,14 @@ static com.google.spanner.v1.Mutation toProtoGetRandomMutation(
514515
return largeInsertMutation;
515516
}
516517
}
518+
519+
// Returns true if the input mutation is of type INSERT and has more values than the current
520+
// largest insert mutation.
521+
private static boolean checkIfInsertMutationWithLargeValue(
522+
com.google.spanner.v1.Mutation mutation,
523+
com.google.spanner.v1.Mutation largestInsertMutation) {
524+
return mutation.hasInsert()
525+
&& mutation.getInsert().getValuesCount()
526+
> largestInsertMutation.getInsert().getValuesCount();
527+
}
517528
}

0 commit comments

Comments
 (0)