Skip to content

Commit ee2c01d

Browse files
ajaaymsduskis
authored andcommitted
---
yaml --- r: 14765 b: refs/heads/autosynth-asset c: d6b2c21 h: refs/heads/master i: 14763: 72d8ec4
1 parent 9c9d7b8 commit ee2c01d

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

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

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ refs/heads/autosynth-vision: b8e47d76578b5f150ef530072ea7e485e2b02ca0
122122
refs/heads/spanner: b01127f885b4611bf1852abb0ce481eeb7fcc131
123123
refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b
124124
refs/tags/v0.69.0: 78f67a29e8b9c46ba01de566a2eae0fd1c03edea
125-
refs/heads/autosynth-asset: 64f3b2be23eab15df420e5890f14409fa52c8411
125+
refs/heads/autosynth-asset: d6b2c21e731a4307128d79d65daa64893e421a5a
126126
refs/heads/autosynth-automl: d4315b3596bac160e3439432c54435f44b09953e
127127
refs/heads/autosynth-bigquerydatatransfer: 2a9f3938237f85a8919602d74011326580ff387f
128128
refs/heads/autosynth-bigquerystorage: 99aee05df348f39d98b6fb23c292006f1d2a6c28

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