Skip to content

Commit 3710cc8

Browse files
ajaaymsduskis
authored andcommitted
---
yaml --- r: 14409 b: refs/heads/autosynth-video-intelligence c: d6b2c21 h: refs/heads/master i: 14407: aeb8740
1 parent b28d432 commit 3710cc8

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

  • branches/autosynth-video-intelligence/google-cloud-clients/google-cloud-spanner/src

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ refs/heads/autosynth-container: f6384095f50b31bfc8208542a49181e158d3681c
117117
refs/heads/autosynth-dataproc: bc74a8841bc1693d7945d991d15979df550b1fd1
118118
refs/heads/autosynth-monitoring: e67db7395a868e5f6ecc3476eb4a91c47abd4234
119119
refs/heads/autosynth-pubsub: fd363d13793a853214eb8193c922b28c54e7a6b3
120-
refs/heads/autosynth-video-intelligence: 64f3b2be23eab15df420e5890f14409fa52c8411
120+
refs/heads/autosynth-video-intelligence: d6b2c21e731a4307128d79d65daa64893e421a5a
121121
refs/heads/autosynth-vision: d758c43ba2ef4f4f7ad07b722617cb39fe3f29db
122122
refs/heads/spanner: 54a5e197bfe0a004e13c190427f46c3413ab572d
123123
refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b

branches/autosynth-video-intelligence/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-video-intelligence/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)