use of com.google.cloud.ByteArray in project beam by apache.
the class MutationKeyEncoder method encodeKey.
private void encodeKey(OrderedCode orderedCode, String tableName, Key key) {
List<SpannerSchema.KeyPart> parts = schema.getKeyParts(tableName);
Iterator<Object> it = key.getParts().iterator();
for (SpannerSchema.KeyPart part : parts) {
Object value = it.next();
if (value == null) {
if (part.isDesc()) {
orderedCode.writeInfinityDecreasing();
} else {
orderedCode.writeInfinity();
}
} else {
if (value instanceof Boolean) {
writeNumber(orderedCode, part, (long) ((Boolean) value ? 0 : 1));
} else if (value instanceof Long) {
writeNumber(orderedCode, part, (long) value);
} else if (value instanceof Double) {
writeNumber(orderedCode, part, Double.doubleToLongBits((double) value));
} else if (value instanceof String) {
writeString(orderedCode, part, (String) value);
} else if (value instanceof ByteArray) {
writeBytes(orderedCode, part, (ByteArray) value);
} else if (value instanceof Timestamp) {
writeTimestamp(orderedCode, part, (Timestamp) value);
} else if (value instanceof Date) {
writeNumber(orderedCode, part, encodeDate((Date) value));
} else {
throw new IllegalArgumentException("Unknown key part " + value);
}
}
}
}
use of com.google.cloud.ByteArray in project spanner-jdbc by olavloite.
the class CloudSpannerConversionUtilTest method testToCloudSpannerBytes.
@Test
public void testToCloudSpannerBytes() {
byte[][] input = new byte[][] { "AA".getBytes(), "BB".getBytes() };
List<ByteArray> output = CloudSpannerConversionUtil.toCloudSpannerBytes(input);
ByteArray inp1 = ByteArray.copyFrom("AA".getBytes());
ByteArray inp2 = ByteArray.copyFrom("BB".getBytes());
assertArrayEquals(new ByteArray[] { inp1, inp2 }, output.toArray());
}
Aggregations