Skip to content

Commit ca10854

Browse files
ajaaymsduskis
authored andcommitted
---
yaml --- r: 13919 b: refs/heads/autosynth-compute c: d6b2c21 h: refs/heads/master i: 13917: d69ad21 13915: 02f01de 13911: 0f5693a 13903: 5564a5c 13887: a6ea688
1 parent e1d1dab commit ca10854

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

  • branches/autosynth-compute/google-cloud-clients/google-cloud-spanner/src

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ refs/tags/v0.64.0: 456e8fbd129deced3ca025f239a2d8a82bde1d0a
112112
refs/tags/v0.65.0: 10939381ffe0b8da32db4fe3087c86e3aa7f3e55
113113
refs/tags/v0.66.0: ed6a3f57cbdaa20339a1995f7d7d53b172a5b8ef
114114
refs/tags/v0.67.0: 30b56f02092efc6f3c3667650ea8b8825003e0b7
115-
refs/heads/autosynth-compute: 64f3b2be23eab15df420e5890f14409fa52c8411
115+
refs/heads/autosynth-compute: d6b2c21e731a4307128d79d65daa64893e421a5a
116116
refs/heads/autosynth-container: d0346e84b1f26e3dc10444450a998f357a43bcef
117117
refs/heads/autosynth-dataproc: bc74a8841bc1693d7945d991d15979df550b1fd1
118118
refs/heads/autosynth-monitoring: 120f508e0065f4ce39cf0e6a69a08138773f2cfb

branches/autosynth-compute/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Key.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ ListValue toProto() {
281281
} else if (part instanceof ByteArray) {
282282
builder.addValuesBuilder().setStringValue(((ByteArray) part).toBase64());
283283
} else if (part instanceof Timestamp) {
284-
builder.addValuesBuilder().setStringValue(((Timestamp) part).toString());
284+
builder.addValuesBuilder().setStringValue(part.toString());
285+
} else if (part instanceof Date) {
286+
builder.addValuesBuilder().setStringValue(part.toString());
285287
} else {
286288
throw new AssertionError("Illegal key part: " + part.getClass());
287289
}

branches/autosynth-compute/google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/KeyTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.google.cloud.Date;
2424
import com.google.cloud.Timestamp;
2525
import com.google.common.testing.EqualsTester;
26+
import com.google.protobuf.ListValue;
27+
import com.google.protobuf.NullValue;
2628
import org.junit.Test;
2729
import org.junit.runner.RunWith;
2830
import org.junit.runners.JUnit4;
@@ -189,4 +191,35 @@ public void serialization() throws Exception {
189191
reserializeAndAssert(Key.of(Date.parseDate("2015-09-15")));
190192
reserializeAndAssert(Key.of(1, 2, 3));
191193
}
194+
195+
@Test
196+
public void toProto() {
197+
String timestamp = "2015-09-15T00:00:00Z";
198+
String date = "2015-09-15";
199+
Key k =
200+
Key.newBuilder()
201+
.append((Boolean) null)
202+
.append(true)
203+
.append(32)
204+
.append(64L)
205+
.append(2.0f)
206+
.append(4.0d)
207+
.append("x")
208+
.append(ByteArray.copyFrom("y"))
209+
.append(Timestamp.parseTimestamp(timestamp))
210+
.append(Date.parseDate(date))
211+
.build();
212+
ListValue.Builder builder = ListValue.newBuilder();
213+
builder.addValuesBuilder().setNullValue(NullValue.NULL_VALUE);
214+
builder.addValuesBuilder().setBoolValue(true);
215+
builder.addValuesBuilder().setStringValue("32");
216+
builder.addValuesBuilder().setStringValue("64");
217+
builder.addValuesBuilder().setNumberValue(2.0f);
218+
builder.addValuesBuilder().setNumberValue(4.0d);
219+
builder.addValuesBuilder().setStringValue("x");
220+
builder.addValuesBuilder().setStringValue("eQ==");
221+
builder.addValuesBuilder().setStringValue(timestamp);
222+
builder.addValuesBuilder().setStringValue(date);
223+
assertThat(k.toProto()).isEqualTo(builder.build());
224+
}
192225
}

0 commit comments

Comments
 (0)