static long sizeOf(Mutation m) {
    if (m.getOperation() == Mutation.Op.DELETE) {
      return sizeOf(m.getKeySet());
    }
    long result = 0;
    for (Value v : m.getValues()) {
      switch (v.getType().getCode()) {
        case ARRAY:
          result += estimateArrayValue(v);
          break;
        case STRUCT:
          throw new IllegalArgumentException("Structs are not supported in mutation.");
        default:
          result += estimatePrimitiveValue(v);
      }
    }
    return result;
  }
@Test
  public void primitives() throws Exception {
    Mutation int64 = Mutation.newInsertOrUpdateBuilder("test").set("one").to(1).build();
    Mutation float32 = Mutation.newInsertOrUpdateBuilder("test").set("one").to(1.3f).build();
    Mutation float64 = Mutation.newInsertOrUpdateBuilder("test").set("one").to(2.9).build();
    Mutation bool = Mutation.newInsertOrUpdateBuilder("test").set("one").to(false).build();
    Mutation numeric =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .to(new BigDecimal("12345678901234567890.123456789"))
            .build();
    Mutation pgNumeric =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .to(Value.pgNumeric("12345678901234567890.123456789"))
            .build();
    Mutation pgNumericNaN =
        Mutation.newInsertOrUpdateBuilder("test").set("one").to(Value.pgNumeric("NaN")).build();
    Mutation json =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .to(Value.json("{\"key1\":\"value1\", \"key2\":\"value2\"}"))
            .build();
    Mutation deleteDouble = Mutation.delete("test", Key.of(1223.));
    Mutation jsonb =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .to(Value.pgJsonb("{\"key123\":\"value123\", \"key321\":\"value321\"}"))
            .build();

    assertThat(MutationSizeEstimator.sizeOf(int64), is(8L));
    assertThat(MutationSizeEstimator.sizeOf(float32), is(4L));
    assertThat(MutationSizeEstimator.sizeOf(float64), is(8L));
    assertThat(MutationSizeEstimator.sizeOf(bool), is(1L));
    assertThat(MutationSizeEstimator.sizeOf(numeric), is(30L));
    assertThat(MutationSizeEstimator.sizeOf(pgNumeric), is(30L));
    assertThat(MutationSizeEstimator.sizeOf(pgNumericNaN), is(3L));
    assertThat(MutationSizeEstimator.sizeOf(json), is(34L));
    assertThat(MutationSizeEstimator.sizeOf(deleteDouble), is(8L));
    assertThat(MutationSizeEstimator.sizeOf(jsonb), is(42L));
  }