use of com.google.cloud.spanner.pgadapter.parsers.ArrayParser in project pgadapter by GoogleCloudPlatform.
the class ParserTest method testLongArrayParsing.
@Test
public void testLongArrayParsing() {
Long[] value = { 1L, 2L, 3L };
// The binary format of a PG array should contain the OID of the element type and not the array
// OID. For INT8 that means 20 and not 1016
// See
// https://github.com/pgjdbc/pgjdbc/blob/60a81034fd003551fc863033f491b2d0ed1dfa80/pgjdbc/src/main/java/org/postgresql/jdbc/ArrayDecoding.java#L505
// We can test this more thoroughly when
// https://github.com/GoogleCloudPlatform/pgadapter/pull/36
// has been merged.
byte[] byteResult = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 3 };
byte[] stringResult = { '{', '1', ',', '2', ',', '3', '}' };
byte[] spannerResult = { '[', '1', ',', '2', ',', '3', ']' };
ResultSet resultSet = Mockito.mock(ResultSet.class);
when(resultSet.getColumnType(0)).thenReturn(Type.array(Type.int64()));
when(resultSet.getValue(0)).thenReturn(Value.int64Array(Arrays.asList(value)));
ArrayParser parser = new ArrayParser(resultSet, 0);
validate(parser, byteResult, stringResult, spannerResult);
}
use of com.google.cloud.spanner.pgadapter.parsers.ArrayParser in project pgadapter by GoogleCloudPlatform.
the class ParserTest method testStringArrayParsing.
@Test
public void testStringArrayParsing() {
String[] value = { "abc", "def", "jhi" };
// The binary format of a PG array should contain the OID of the element type and not the array
// OID. For VARCHAR that means 1043 and not 1015
// See
// https://github.com/pgjdbc/pgjdbc/blob/60a81034fd003551fc863033f491b2d0ed1dfa80/pgjdbc/src/main/java/org/postgresql/jdbc/ArrayDecoding.java#L505
// We can test this more thoroughly when
// https://github.com/GoogleCloudPlatform/pgadapter/pull/36
// has been merged.
byte[] byteResult = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 4, 19, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 97, 98, 99, 0, 0, 0, 3, 100, 101, 102, 0, 0, 0, 3, 106, 104, 105 };
byte[] stringResult = { '{', '"', 'a', 'b', 'c', '"', ',', '"', 'd', 'e', 'f', '"', ',', '"', 'j', 'h', 'i', '"', '}' };
byte[] spannerResult = { '[', '"', 'a', 'b', 'c', '"', ',', '"', 'd', 'e', 'f', '"', ',', '"', 'j', 'h', 'i', '"', ']' };
ResultSet resultSet = Mockito.mock(ResultSet.class);
when(resultSet.getColumnType(0)).thenReturn(Type.array(Type.string()));
when(resultSet.getValue(0)).thenReturn(Value.stringArray(Arrays.asList(value)));
ArrayParser parser = new ArrayParser(resultSet, 0);
validate(parser, byteResult, stringResult, spannerResult);
}
use of com.google.cloud.spanner.pgadapter.parsers.ArrayParser in project pgadapter by GoogleCloudPlatform.
the class ParserTest method testArrayArrayParsingFails.
@Test(expected = IllegalArgumentException.class)
public void testArrayArrayParsingFails() {
Long[] value = { 1L, 2L, 3L };
ResultSet resultSet = Mockito.mock(ResultSet.class);
when(resultSet.getColumnType(0)).thenReturn(Type.array(Type.array(Type.int64())));
new ArrayParser(resultSet, 0);
}
Aggregations