-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: changes to support data, timestamp and arrays in IT tests #1840
Changes from 3 commits
edc1256
e7184a3
9522e1d
52799ff
2c2b208
771970e
0ee5cc8
23fd2f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assume.assumeFalse; | ||
|
||
import com.google.cloud.ByteArray; | ||
import com.google.cloud.Date; | ||
|
@@ -128,7 +127,17 @@ public static void beforeClass() | |
+ "float64 DOUBLE PRECISION," | ||
+ "numeric NUMERIC," | ||
+ "string VARCHAR," | ||
+ "bytes BYTEA" | ||
+ "bytes BYTEA," | ||
+ "timestamp TIMESTAMPTZ," | ||
+ "date DATE," | ||
+ "boolArray BOOL[]," | ||
+ "int64Array BIGINT[]," | ||
+ "float64Array DOUBLE PRECISION[]," | ||
+ "numericArray NUMERIC[]," | ||
+ "stringArray VARCHAR[]," | ||
+ "bytesArray BYTEA[]," | ||
+ "dateArray DATE[]," | ||
+ "timestampArray TIMESTAMPTZ[]" | ||
+ ")")); | ||
postgreSQLClient = env.getTestHelper().getDatabaseClient(postgreSQLDatabase); | ||
} | ||
|
@@ -264,6 +273,32 @@ public void testReadNonNullValuesPostgreSQL() { | |
.to("stringValue") | ||
.set("bytes") | ||
.to(ByteArray.copyFrom("bytesValue")) | ||
.set("date") | ||
.to(Date.fromYearMonthDay(2021, 1, 2)) | ||
.set("timestamp") | ||
.to(Timestamp.ofTimeSecondsAndNanos(1, 0)) | ||
.set("boolArray") | ||
.toBoolArray(new boolean[] {false, true}) | ||
.set("int64Array") | ||
.toInt64Array(new long[] {100L, 200L}) | ||
.set("float64Array") | ||
.toFloat64Array(new double[] {1000D, 2000D}) | ||
.set("numericArray") | ||
.toNumericArray(Arrays.asList(new BigDecimal("10000"), new BigDecimal("20000"))) | ||
.set("stringArray") | ||
.toStringArray(Arrays.asList("string1", "string2")) | ||
.set("bytesArray") | ||
.toBytesArray( | ||
Arrays.asList(ByteArray.copyFrom("bytes1"), ByteArray.copyFrom("bytes2"))) | ||
.set("timestampArray") | ||
.toTimestampArray( | ||
Arrays.asList( | ||
Timestamp.ofTimeSecondsAndNanos(10, 0), | ||
Timestamp.ofTimeSecondsAndNanos(20, 0))) | ||
.set("dateArray") | ||
.toDateArray( | ||
Arrays.asList( | ||
Date.fromYearMonthDay(2021, 2, 3), Date.fromYearMonthDay(2021, 3, 4))) | ||
.build())); | ||
|
||
try (ResultSet resultSet = | ||
|
@@ -278,6 +313,34 @@ public void testReadNonNullValuesPostgreSQL() { | |
assertEquals(Value.pgNumeric("30"), resultSet.getValue("numeric")); | ||
assertEquals(Value.string("stringValue"), resultSet.getValue("string")); | ||
assertEquals(Value.bytes(ByteArray.copyFrom("bytesValue")), resultSet.getValue("bytes")); | ||
assertEquals( | ||
Value.timestamp(Timestamp.ofTimeSecondsAndNanos(1, 0)), resultSet.getValue("timestamp")); | ||
assertEquals(Value.date(Date.fromYearMonthDay(2021, 1, 2)), resultSet.getValue("date")); | ||
assertEquals(Value.boolArray(new boolean[] {false, true}), resultSet.getValue("boolarray")); | ||
assertEquals(Value.int64Array(new long[] {100L, 200L}), resultSet.getValue("int64array")); | ||
assertArrayEquals( | ||
new double[] {1000D, 2000D}, | ||
Doubles.toArray(resultSet.getValue("float64array").getFloat64Array()), | ||
1e-15); | ||
assertEquals( | ||
Value.pgNumericArray(Arrays.asList("10000", "20000")), | ||
resultSet.getValue("numericarray")); | ||
assertEquals( | ||
Value.stringArray(Arrays.asList("string1", "string2")), | ||
resultSet.getValue("stringarray")); | ||
assertEquals( | ||
Value.bytesArray( | ||
Arrays.asList(ByteArray.copyFrom("bytes1"), ByteArray.copyFrom("bytes2"))), | ||
resultSet.getValue("bytesarray")); | ||
assertEquals( | ||
Value.timestampArray( | ||
Arrays.asList( | ||
Timestamp.ofTimeSecondsAndNanos(10, 0), Timestamp.ofTimeSecondsAndNanos(20, 0))), | ||
resultSet.getValue("timestamparray")); | ||
assertEquals( | ||
Value.dateArray( | ||
Arrays.asList(Date.fromYearMonthDay(2021, 2, 3), Date.fromYearMonthDay(2021, 3, 4))), | ||
resultSet.getValue("datearray")); | ||
} | ||
} | ||
|
||
|
@@ -367,12 +430,42 @@ public void testReadNullValuesPostgreSQL() { | |
assertThrows(IllegalStateException.class, () -> resultSet.getValue("string").getString()); | ||
assertTrue(resultSet.getValue("bytes").isNull()); | ||
assertThrows(IllegalStateException.class, () -> resultSet.getValue("bytes").getBytes()); | ||
assertTrue(resultSet.getValue("timestamp").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("timestamp").getTimestamp()); | ||
assertTrue(resultSet.getValue("date").isNull()); | ||
assertThrows(IllegalStateException.class, () -> resultSet.getValue("date").getDate()); | ||
assertTrue(resultSet.getValue("boolarray").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("boolarray").getBoolArray()); | ||
assertTrue(resultSet.getValue("int64array").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("int64array").getInt64Array()); | ||
assertTrue(resultSet.getValue("float64array").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("float64array").getFloat64Array()); | ||
assertTrue(resultSet.getValue("numericarray").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("numericarray").getNumericArray()); | ||
assertTrue(resultSet.getValue("stringarray").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("stringarray").getStringArray()); | ||
assertTrue(resultSet.getValue("bytesarray").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("bytesarray").getBytesArray()); | ||
assertTrue(resultSet.getValue("timestamparray").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, | ||
() -> resultSet.getValue("timestamparray").getTimestampArray()); | ||
assertTrue(resultSet.getValue("datearray").isNull()); | ||
assertThrows( | ||
IllegalStateException.class, () -> resultSet.getValue("datearray").getDateArray()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testReadNullValuesInArrays() { | ||
assumeFalse("PostgreSQL does not yet support Arrays", dialect.dialect == Dialect.POSTGRESQL); | ||
public void testReadNullValuesInArraysGoogleStandardSQL() { | ||
Assume.assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL); | ||
databaseClient.write( | ||
Collections.singletonList( | ||
Mutation.newInsertBuilder(TABLE_NAME) | ||
|
@@ -429,6 +522,59 @@ public void testReadNullValuesInArrays() { | |
} | ||
} | ||
|
||
@Test | ||
public void testReadNullValuesInArraysPostgreSQL() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need separate tests for GoogleSQL and PostgreSQL in this case? They seem to be equal. Or am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. structs and json are not supported and column names are different as PG requires explicit quotes for case |
||
Assume.assumeTrue(dialect.dialect == Dialect.POSTGRESQL); | ||
databaseClient.write( | ||
Collections.singletonList( | ||
Mutation.newInsertBuilder(TABLE_NAME) | ||
.set("Id") | ||
.to(3L) | ||
.set("boolArray") | ||
.toBoolArray(Arrays.asList(true, null)) | ||
.set("int64Array") | ||
.toInt64Array(Arrays.asList(null, 2L)) | ||
.set("float64Array") | ||
.toFloat64Array(Arrays.asList(null, 10D)) | ||
.set("numericArray") | ||
.toNumericArray(Arrays.asList(new BigDecimal("10000"), null)) | ||
.set("stringArray") | ||
.toStringArray(Arrays.asList(null, "string2")) | ||
.set("bytesArray") | ||
.toBytesArray(Arrays.asList(ByteArray.copyFrom("bytes1"), null)) | ||
.set("timestampArray") | ||
.toTimestampArray(Arrays.asList(null, Timestamp.ofTimeSecondsAndNanos(20, 0))) | ||
.set("dateArray") | ||
.toDateArray(Arrays.asList(Date.fromYearMonthDay(2021, 2, 3), null)) | ||
.build())); | ||
|
||
try (ResultSet resultSet = | ||
databaseClient | ||
.singleUse() | ||
.executeQuery(Statement.of("SELECT * FROM " + TABLE_NAME + " WHERE Id = 3"))) { | ||
resultSet.next(); | ||
|
||
assertEquals(Value.int64(3L), resultSet.getValue("id")); | ||
assertEquals(Value.boolArray(Arrays.asList(true, null)), resultSet.getValue("boolarray")); | ||
assertEquals(Value.int64Array(Arrays.asList(null, 2L)), resultSet.getValue("int64array")); | ||
assertNull(resultSet.getValue("float64array").getFloat64Array().get(0)); | ||
assertEquals(10D, resultSet.getValue("float64array").getFloat64Array().get(1), DELTA); | ||
assertEquals( | ||
Value.pgNumericArray(Arrays.asList("10000", null)), resultSet.getValue("numericarray")); | ||
assertEquals( | ||
Value.stringArray(Arrays.asList(null, "string2")), resultSet.getValue("stringarray")); | ||
assertEquals( | ||
Value.bytesArray(Arrays.asList(ByteArray.copyFrom("bytes1"), null)), | ||
resultSet.getValue("bytesarray")); | ||
assertEquals( | ||
Value.timestampArray(Arrays.asList(null, Timestamp.ofTimeSecondsAndNanos(20, 0))), | ||
resultSet.getValue("timestamparray")); | ||
assertEquals( | ||
Value.dateArray(Arrays.asList(Date.fromYearMonthDay(2021, 2, 3), null)), | ||
resultSet.getValue("datearray")); | ||
} | ||
} | ||
|
||
@Test | ||
public void testReadNonFloat64LiteralsGoogleStandardSQL() { | ||
Assume.assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL); | ||
|
@@ -570,14 +716,46 @@ public void testReadNonFloat64LiteralsPostgreSQL() { | |
+ "1 AS int64," | ||
+ "CAST('100' AS numeric) AS numeric," | ||
+ "'stringValue' AS string," | ||
+ "CAST('bytesValue' AS BYTEA) AS bytes"))) { | ||
+ "CAST('bytesValue' AS BYTEA) AS bytes," | ||
+ "CAST('1970-01-01T00:00:01 UTC' AS TIMESTAMPTZ) AS timestamp," | ||
+ "CAST('2021-02-03' AS DATE) AS date," | ||
+ "ARRAY[false, true] AS boolArray," | ||
+ "ARRAY[1, 2] AS int64Array," | ||
+ "ARRAY[CAST('100' AS NUMERIC), CAST('200' AS NUMERIC)] AS numericArray," | ||
+ "ARRAY['string1', 'string2'] AS stringArray," | ||
+ "ARRAY[CAST('bytes1' AS BYTEA), CAST('bytes2' AS BYTEA)] AS bytesArray," | ||
+ "ARRAY[CAST('1970-01-01T00:00:01 UTC' AS TIMESTAMPTZ), CAST('1970-01-01T00:00:02 UTC' AS TIMESTAMPTZ)] AS timestampArray," | ||
+ "ARRAY[CAST('2020-01-02' AS DATE), CAST('2021-02-03' AS DATE)] AS dateArray"))) { | ||
resultSet.next(); | ||
|
||
assertEquals(Value.bool(true), resultSet.getValue("bool")); | ||
assertEquals(Value.int64(1L), resultSet.getValue("int64")); | ||
assertEquals(Value.pgNumeric("100"), resultSet.getValue("numeric")); | ||
assertEquals(Value.string("stringValue"), resultSet.getValue("string")); | ||
assertEquals(Value.bytes(ByteArray.copyFrom("bytesValue")), resultSet.getValue("bytes")); | ||
assertEquals( | ||
Value.timestamp(Timestamp.ofTimeSecondsAndNanos(1, 0)), resultSet.getValue("timestamp")); | ||
assertEquals(Value.date(Date.fromYearMonthDay(2021, 2, 3)), resultSet.getValue("date")); | ||
assertEquals(Value.boolArray(new boolean[] {false, true}), resultSet.getValue("boolarray")); | ||
assertEquals(Value.int64Array(new long[] {1L, 2L}), resultSet.getValue("int64array")); | ||
assertEquals( | ||
Value.pgNumericArray(Arrays.asList("100", "200")), resultSet.getValue("numericarray")); | ||
assertEquals( | ||
Value.stringArray(Arrays.asList("string1", "string2")), | ||
resultSet.getValue("stringarray")); | ||
assertEquals( | ||
Value.bytesArray( | ||
Arrays.asList(ByteArray.copyFrom("bytes1"), ByteArray.copyFrom("bytes2"))), | ||
resultSet.getValue("bytesarray")); | ||
assertEquals( | ||
Value.timestampArray( | ||
Arrays.asList( | ||
Timestamp.ofTimeSecondsAndNanos(1, 0), Timestamp.ofTimeSecondsAndNanos(2, 0))), | ||
resultSet.getValue("timestamparray")); | ||
assertEquals( | ||
Value.dateArray( | ||
Arrays.asList(Date.fromYearMonthDay(2020, 1, 2), Date.fromYearMonthDay(2021, 2, 3))), | ||
resultSet.getValue("datearray")); | ||
} | ||
} | ||
|
||
|
@@ -615,9 +793,16 @@ public void testReadFloat64LiteralsGoogleStandardSQL() { | |
public void testReadFloat64LiteralsPostgreSQL() { | ||
Assume.assumeTrue(dialect.dialect == Dialect.POSTGRESQL); | ||
try (ResultSet resultSet = | ||
databaseClient.singleUse().executeQuery(Statement.of("SELECT 10.0 AS float64"))) { | ||
databaseClient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need a separate test case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
.singleUse() | ||
.executeQuery( | ||
Statement.of("SELECT 10.0 AS float64, " + "ARRAY[20.0, 30.0] AS float64Array"))) { | ||
resultSet.next(); | ||
assertEquals(10D, resultSet.getValue("float64").getFloat64(), DELTA); | ||
assertArrayEquals( | ||
new double[] {20D, 30D}, | ||
Doubles.toArray(resultSet.getValue("float64array").getFloat64Array()), | ||
DELTA); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case seem to be disabled for PostgreSQL still. Is that intentional?
The same also seems to be the case for other numeric array tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed those, adding it