From edc1256d59c35f738d30615048a5dac7339f64e1 Mon Sep 17 00:00:00 2001 From: Astha Mohta Date: Wed, 20 Apr 2022 15:28:03 +0530 Subject: [PATCH 1/7] changes to support data, timestamp and arrays --- .../google/cloud/spanner/it/ITQueryTest.java | 41 +--- .../cloud/spanner/it/ITResultSetGetValue.java | 222 +++++++++++++++--- .../google/cloud/spanner/it/ITWriteTest.java | 115 +++------ 3 files changed, 240 insertions(+), 138 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java index f07bffc2d8f..017b8633952 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java @@ -19,31 +19,15 @@ import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; import static com.google.common.truth.Truth.assertThat; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import static org.junit.Assume.assumeFalse; import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.Database; -import com.google.cloud.spanner.DatabaseClient; -import com.google.cloud.spanner.Dialect; -import com.google.cloud.spanner.ErrorCode; -import com.google.cloud.spanner.IntegrationTestEnv; -import com.google.cloud.spanner.Mutation; -import com.google.cloud.spanner.ParallelIntegrationTest; +import com.google.cloud.spanner.*; import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; -import com.google.cloud.spanner.ResultSet; -import com.google.cloud.spanner.SpannerException; -import com.google.cloud.spanner.Statement; -import com.google.cloud.spanner.Struct; -import com.google.cloud.spanner.TimestampBound; -import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Type.StructField; -import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.base.Joiner; @@ -54,12 +38,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -355,7 +334,6 @@ public void bindTimestampNull() { @Test public void bindDate() { - assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL); Date d = Date.parseDate("2016-09-18"); Struct row = execute(Statement.newBuilder(selectValueQuery).bind("p1").to(d), Type.date()); assertThat(row.isNull(0)).isFalse(); @@ -364,7 +342,6 @@ public void bindDate() { @Test public void bindDateNull() { - assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL); Struct row = execute(Statement.newBuilder(selectValueQuery).bind("p1").to((Date) null), Type.date()); assertThat(row.isNull(0)).isTrue(); @@ -682,13 +659,12 @@ public void bindTimestampArrayNull() { @Test public void bindDateArray() { - assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL); Date d1 = Date.parseDate("2016-09-18"); Date d2 = Date.parseDate("2016-09-19"); Struct row = execute( - Statement.newBuilder("SELECT @v").bind("v").toDateArray(asList(d1, d2, null)), + Statement.newBuilder(selectValueQuery).bind("p1").toDateArray(asList(d1, d2, null)), Type.array(Type.date())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDateList(0)).containsExactly(d1, d2, null).inOrder(); @@ -696,10 +672,9 @@ public void bindDateArray() { @Test public void bindDateArrayEmpty() { - assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL); Struct row = execute( - Statement.newBuilder("SELECT @v").bind("v").toDateArray(Collections.emptyList()), + Statement.newBuilder(selectValueQuery).bind("p1").toDateArray(Collections.emptyList()), Type.array(Type.date())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDateList(0)).containsExactly(); @@ -707,10 +682,10 @@ public void bindDateArrayEmpty() { @Test public void bindDateArrayNull() { - assumeFalse("date type is not supported on POSTGRESQL", dialect.dialect == Dialect.POSTGRESQL); Struct row = execute( - Statement.newBuilder("SELECT @v").bind("v").toDateArray(null), Type.array(Type.date())); + Statement.newBuilder(selectValueQuery).bind("p1").toDateArray(null), + Type.array(Type.date())); assertThat(row.isNull(0)).isTrue(); } @@ -771,7 +746,7 @@ public void bindNumericArray_doesNotPreservePrecision() { Struct row = execute( - Statement.newBuilder("SELECT @v").bind("v").toNumericArray(asList(b1, b2, null)), + Statement.newBuilder(selectValueQuery).bind("p1").toNumericArray(asList(b1, b2, null)), Type.array(Type.numeric())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getBigDecimalList(0)) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java index e48b2f35fd0..b89e836f742 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java @@ -16,28 +16,13 @@ package com.google.cloud.spanner.it; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -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 static org.junit.Assert.*; import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.Database; -import com.google.cloud.spanner.DatabaseClient; -import com.google.cloud.spanner.Dialect; -import com.google.cloud.spanner.IntegrationTestEnv; -import com.google.cloud.spanner.Mutation; -import com.google.cloud.spanner.ParallelIntegrationTest; -import com.google.cloud.spanner.ResultSet; -import com.google.cloud.spanner.Statement; -import com.google.cloud.spanner.Struct; -import com.google.cloud.spanner.Type; +import com.google.cloud.spanner.*; import com.google.cloud.spanner.Type.StructField; -import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.primitives.Doubles; @@ -48,12 +33,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.*; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -128,7 +108,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 +254,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 +294,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 +411,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 +503,59 @@ public void testReadNullValuesInArrays() { } } + @Test + public void testReadNullValuesInArraysPostgreSQL() { + 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,7 +697,16 @@ 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")); @@ -578,6 +714,29 @@ public void testReadNonFloat64LiteralsPostgreSQL() { 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 +774,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 + .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); } } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java index d274cdb91f5..ec4ce0ac543 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java @@ -21,54 +21,22 @@ import static com.google.cloud.spanner.Type.json; import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import static org.junit.Assume.assumeFalse; import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.CommitResponse; -import com.google.cloud.spanner.Database; -import com.google.cloud.spanner.DatabaseClient; -import com.google.cloud.spanner.Dialect; -import com.google.cloud.spanner.ErrorCode; -import com.google.cloud.spanner.IntegrationTestEnv; -import com.google.cloud.spanner.Key; -import com.google.cloud.spanner.KeySet; -import com.google.cloud.spanner.Mutation; -import com.google.cloud.spanner.Options; -import com.google.cloud.spanner.ParallelIntegrationTest; -import com.google.cloud.spanner.ResultSet; -import com.google.cloud.spanner.SpannerException; -import com.google.cloud.spanner.Struct; -import com.google.cloud.spanner.TimestampBound; -import com.google.cloud.spanner.Value; +import com.google.cloud.spanner.*; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.collect.ImmutableList; import io.grpc.Context; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.*; +import java.util.concurrent.*; import org.hamcrest.MatcherAssert; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.*; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -126,7 +94,17 @@ public static List data() { + " Float64Value DOUBLE PRECISION," + " StringValue VARCHAR," + " BytesValue BYTEA," - + " NumericValue NUMERIC" + + " TimestampValue TIMESTAMPTZ," + + " DateValue DATE," + + " NumericValue NUMERIC," + + " BoolArrayValue BOOL[]," + + " Int64ArrayValue BIGINT[]," + + " Float64ArrayValue DOUBLE PRECISION[]," + + " StringArrayValue VARCHAR[]," + + " BytesArrayValue BYTEA[]," + + " TimestampArrayValue TIMESTAMPTZ[]," + + " DateArrayValue DATE[]," + + " NumericArrayValue NUMERIC[]" + ")"; private static final String GOOGLE_STANDARD_SQL_SCHEMA_WITHOUT_NUMERIC_AND_JSON = @@ -492,7 +470,6 @@ public void writeTimestamp() { @Test public void writeTimestampNull() { - assumeFalse("PostgreSQL does not yet support Timestamp", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("TimestampValue").to((Timestamp) null).build()); Struct row = readLastRow("TimestampValue"); assertThat(row.isNull(0)).isTrue(); @@ -500,7 +477,8 @@ public void writeTimestampNull() { @Test public void writeCommitTimestamp() { - assumeFalse("PostgreSQL does not yet support Timestamp", dialect.dialect == Dialect.POSTGRESQL); + assumeFalse( + "PostgreSQL does not yet support Commit Timestamp", dialect.dialect == Dialect.POSTGRESQL); Timestamp commitTimestamp = write(baseInsert().set("TimestampValue").to(Value.COMMIT_TIMESTAMP).build()); Struct row = readLastRow("TimestampValue"); @@ -509,7 +487,6 @@ public void writeCommitTimestamp() { @Test public void writeDate() { - assumeFalse("PostgreSQL does not yet support Date", dialect.dialect == Dialect.POSTGRESQL); Date date = Date.parseDate("2016-09-15"); write(baseInsert().set("DateValue").to(date).build()); Struct row = readLastRow("DateValue"); @@ -519,7 +496,6 @@ public void writeDate() { @Test public void writeDateNull() { - assumeFalse("PostgreSQL does not yet support Date", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("DateValue").to((Date) null).build()); Struct row = readLastRow("DateValue"); assertThat(row.isNull(0)).isTrue(); @@ -548,7 +524,6 @@ public void writeNumericNull() { @Test public void writeBoolArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("BoolArrayValue").toBoolArray((boolean[]) null).build()); Struct row = readLastRow("BoolArrayValue"); assertThat(row.isNull(0)).isTrue(); @@ -556,7 +531,6 @@ public void writeBoolArrayNull() { @Test public void writeBoolArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("BoolArrayValue").toBoolArray(new boolean[] {}).build()); Struct row = readLastRow("BoolArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -565,7 +539,6 @@ public void writeBoolArrayEmpty() { @Test public void writeBoolArray() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("BoolArrayValue").toBoolArray(Arrays.asList(true, null, false)).build()); Struct row = readLastRow("BoolArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -580,7 +553,6 @@ public void writeBoolArray() { @Test public void writeBoolArrayNoNulls() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("BoolArrayValue").toBoolArray(Arrays.asList(true, false)).build()); Struct row = readLastRow("BoolArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -589,7 +561,6 @@ public void writeBoolArrayNoNulls() { @Test public void writeInt64ArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("Int64ArrayValue").toInt64Array((long[]) null).build()); Struct row = readLastRow("Int64ArrayValue"); assertThat(row.isNull(0)).isTrue(); @@ -597,7 +568,6 @@ public void writeInt64ArrayNull() { @Test public void writeInt64ArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("Int64ArrayValue").toInt64Array(new long[] {}).build()); Struct row = readLastRow("Int64ArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -606,7 +576,6 @@ public void writeInt64ArrayEmpty() { @Test public void writeInt64Array() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("Int64ArrayValue").toInt64Array(Arrays.asList(1L, 2L, null)).build()); Struct row = readLastRow("Int64ArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -621,7 +590,6 @@ public void writeInt64Array() { @Test public void writeInt64ArrayNoNulls() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("Int64ArrayValue").toInt64Array(Arrays.asList(1L, 2L)).build()); Struct row = readLastRow("Int64ArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -630,7 +598,6 @@ public void writeInt64ArrayNoNulls() { @Test public void writeFloat64ArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("Float64ArrayValue").toFloat64Array((double[]) null).build()); Struct row = readLastRow("Float64ArrayValue"); assertThat(row.isNull(0)).isTrue(); @@ -638,7 +605,6 @@ public void writeFloat64ArrayNull() { @Test public void writeFloat64ArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("Float64ArrayValue").toFloat64Array(new double[] {}).build()); Struct row = readLastRow("Float64ArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -647,7 +613,6 @@ public void writeFloat64ArrayEmpty() { @Test public void writeFloat64Array() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write( baseInsert() .set("Float64ArrayValue") @@ -666,7 +631,6 @@ public void writeFloat64Array() { @Test public void writeFloat64ArrayNoNulls() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("Float64ArrayValue").toFloat64Array(Arrays.asList(1.0, 2.0)).build()); Struct row = readLastRow("Float64ArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -677,7 +641,6 @@ public void writeFloat64ArrayNoNulls() { @Test public void writeStringArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("StringArrayValue").toStringArray(null).build()); Struct row = readLastRow("StringArrayValue"); assertThat(row.isNull(0)).isTrue(); @@ -685,7 +648,6 @@ public void writeStringArrayNull() { @Test public void writeStringArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("StringArrayValue").toStringArray(Collections.emptyList()).build()); Struct row = readLastRow("StringArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -694,7 +656,6 @@ public void writeStringArrayEmpty() { @Test public void writeStringArray() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write( baseInsert().set("StringArrayValue").toStringArray(Arrays.asList("a", null, "b")).build()); Struct row = readLastRow("StringArrayValue"); @@ -753,7 +714,6 @@ public void writeJsonArrayNoNulls() { @Test public void writeBytesArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("BytesArrayValue").toBytesArray(null).build()); Struct row = readLastRow("BytesArrayValue"); assertThat(row.isNull(0)).isTrue(); @@ -761,7 +721,6 @@ public void writeBytesArrayNull() { @Test public void writeBytesArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("BytesArrayValue").toBytesArray(Collections.emptyList()).build()); Struct row = readLastRow("BytesArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -770,7 +729,6 @@ public void writeBytesArrayEmpty() { @Test public void writeBytesArray() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); List data = Arrays.asList(ByteArray.copyFrom("a"), ByteArray.copyFrom("b"), null); write(baseInsert().set("BytesArrayValue").toBytesArray(data).build()); Struct row = readLastRow("BytesArrayValue"); @@ -780,7 +738,6 @@ public void writeBytesArray() { @Test public void writeTimestampArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("TimestampArrayValue").toTimestampArray(null).build()); Struct row = readLastRow("TimestampArrayValue"); assertThat(row.isNull(0)).isTrue(); @@ -788,7 +745,6 @@ public void writeTimestampArrayNull() { @Test public void writeTimestampArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write( baseInsert().set("TimestampArrayValue").toTimestampArray(Collections.emptyList()).build()); Struct row = readLastRow("TimestampArrayValue"); @@ -798,7 +754,6 @@ public void writeTimestampArrayEmpty() { @Test public void writeTimestampArray() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z"); Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z"); write( @@ -813,7 +768,6 @@ public void writeTimestampArray() { @Test public void writeDateArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("DateArrayValue").toDateArray(null).build()); Struct row = readLastRow("DateArrayValue"); assertThat(row.isNull(0)).isTrue(); @@ -821,7 +775,6 @@ public void writeDateArrayNull() { @Test public void writeDateArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); write(baseInsert().set("DateArrayValue").toDateArray(Collections.emptyList()).build()); Struct row = readLastRow("DateArrayValue"); assertThat(row.isNull(0)).isFalse(); @@ -830,7 +783,6 @@ public void writeDateArrayEmpty() { @Test public void writeDateArray() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); Date d1 = Date.parseDate("2016-09-18"); Date d2 = Date.parseDate("2016-09-19"); write(baseInsert().set("DateArrayValue").toDateArray(Arrays.asList(d1, null, d2)).build()); @@ -841,7 +793,6 @@ public void writeDateArray() { @Test public void writeNumericArrayNull() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); write(baseInsert().set("NumericArrayValue").toNumericArray(null).build()); Struct row = readLastRow("NumericArrayValue"); @@ -850,17 +801,19 @@ public void writeNumericArrayNull() { @Test public void writeNumericArrayEmpty() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); write(baseInsert().set("NumericArrayValue").toNumericArray(ImmutableList.of()).build()); Struct row = readLastRow("NumericArrayValue"); assertThat(row.isNull(0)).isFalse(); - assertThat(row.getBigDecimalList(0)).containsExactly(); + if (dialect.dialect == Dialect.GOOGLE_STANDARD_SQL) { + assertThat(row.getBigDecimalList(0)).containsExactly(); + } else { + assertThat(row.getStringList(0)).containsExactly(); + } } @Test public void writeNumericArray() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); write( baseInsert() @@ -870,14 +823,16 @@ public void writeNumericArray() { .build()); Struct row = readLastRow("NumericArrayValue"); assertThat(row.isNull(0)).isFalse(); - assertThat(row.getBigDecimalList(0)) - .containsExactly(BigDecimal.valueOf(3141592, 6), BigDecimal.valueOf(6626, 3), null) - .inOrder(); + if (dialect.dialect == Dialect.GOOGLE_STANDARD_SQL) { + assertThat(row.getBigDecimalList(0)) + .containsExactly(BigDecimal.valueOf(3141592, 6), BigDecimal.valueOf(6626, 3), null); + } else { + assertThat(row.getStringList(0)).containsExactly("3.141592", "6.626", null).inOrder(); + } } @Test public void writeNumericArrayNoNulls() { - assumeFalse("PostgreSQL does not yet support Array", dialect.dialect == Dialect.POSTGRESQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); write( baseInsert() @@ -886,9 +841,15 @@ public void writeNumericArrayNoNulls() { .build()); Struct row = readLastRow("NumericArrayValue"); assertThat(row.isNull(0)).isFalse(); - assertThat(row.getBigDecimalList(0)) - .containsExactly(BigDecimal.valueOf(3141592, 6), BigDecimal.valueOf(6626, 3)) - .inOrder(); + if (dialect.dialect == Dialect.GOOGLE_STANDARD_SQL) { + assertThat(row.getBigDecimalList(0)) + .containsExactly(BigDecimal.valueOf(3141592, 6), BigDecimal.valueOf(6626, 3)); + } else { + assertThat(row.getStringList(0)) + .containsExactly( + BigDecimal.valueOf(3141592, 6).toString(), BigDecimal.valueOf(6626, 3).toString()) + .inOrder(); + } } @Test From e7184a3fd2314356322883b9b722ce882c32150d Mon Sep 17 00:00:00 2001 From: Astha Mohta Date: Wed, 20 Apr 2022 15:59:25 +0530 Subject: [PATCH 2/7] changes to support data, timestamp and arrays --- .../google/cloud/spanner/it/ITQueryTest.java | 44 ++++++++++---- .../cloud/spanner/it/ITResultSetGetValue.java | 34 ++++++++--- .../google/cloud/spanner/it/ITWriteTest.java | 59 +++++++++++++++---- 3 files changed, 106 insertions(+), 31 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java index 017b8633952..ff43ef35f16 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java @@ -16,32 +16,54 @@ package com.google.cloud.spanner.it; -import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; -import static com.google.common.truth.Truth.assertThat; -import static java.util.Arrays.asList; -import static org.junit.Assert.*; -import static org.junit.Assume.assumeFalse; - import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.*; +import com.google.cloud.spanner.Database; +import com.google.cloud.spanner.DatabaseClient; +import com.google.cloud.spanner.Dialect; +import com.google.cloud.spanner.ErrorCode; +import com.google.cloud.spanner.IntegrationTestEnv; +import com.google.cloud.spanner.Mutation; +import com.google.cloud.spanner.ParallelIntegrationTest; import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; +import com.google.cloud.spanner.ResultSet; +import com.google.cloud.spanner.SpannerException; +import com.google.cloud.spanner.Statement; +import com.google.cloud.spanner.Struct; +import com.google.cloud.spanner.TimestampBound; +import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Type.StructField; +import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.base.Joiner; import com.google.common.collect.Iterables; import com.google.spanner.v1.ResultSetStats; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.*; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; + +import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; +import static com.google.common.truth.Truth.assertThat; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeFalse; /** Integration tests for query execution. */ @Category(ParallelIntegrationTest.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java index b89e836f742..84d32673d20 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java @@ -16,16 +16,34 @@ package com.google.cloud.spanner.it; -import static org.junit.Assert.*; - import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.*; +import com.google.cloud.spanner.Database; +import com.google.cloud.spanner.DatabaseClient; +import com.google.cloud.spanner.Dialect; +import com.google.cloud.spanner.IntegrationTestEnv; +import com.google.cloud.spanner.Mutation; +import com.google.cloud.spanner.ParallelIntegrationTest; +import com.google.cloud.spanner.ResultSet; +import com.google.cloud.spanner.Statement; +import com.google.cloud.spanner.Struct; +import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Type.StructField; +import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.primitives.Doubles; +import org.junit.AfterClass; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; @@ -33,10 +51,12 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.junit.*; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; @Category(ParallelIntegrationTest.class) @RunWith(Parameterized.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java index ec4ce0ac543..0b24487183e 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java @@ -16,31 +16,64 @@ package com.google.cloud.spanner.it; -import static com.google.cloud.spanner.SpannerMatchers.isSpannerException; -import static com.google.cloud.spanner.Type.array; -import static com.google.cloud.spanner.Type.json; -import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.*; -import static org.junit.Assume.assumeFalse; - import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.*; +import com.google.cloud.spanner.CommitResponse; +import com.google.cloud.spanner.Database; +import com.google.cloud.spanner.DatabaseClient; +import com.google.cloud.spanner.Dialect; +import com.google.cloud.spanner.ErrorCode; +import com.google.cloud.spanner.IntegrationTestEnv; +import com.google.cloud.spanner.Key; +import com.google.cloud.spanner.KeySet; +import com.google.cloud.spanner.Mutation; +import com.google.cloud.spanner.Options; +import com.google.cloud.spanner.ParallelIntegrationTest; +import com.google.cloud.spanner.ResultSet; +import com.google.cloud.spanner.SpannerException; +import com.google.cloud.spanner.Struct; +import com.google.cloud.spanner.TimestampBound; +import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.collect.ImmutableList; import io.grpc.Context; -import java.math.BigDecimal; -import java.util.*; -import java.util.concurrent.*; import org.hamcrest.MatcherAssert; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static com.google.cloud.spanner.SpannerMatchers.isSpannerException; +import static com.google.cloud.spanner.Type.array; +import static com.google.cloud.spanner.Type.json; +import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeFalse; + /** Integration test for writing data to Cloud Spanner. */ @Category(ParallelIntegrationTest.class) @RunWith(Parameterized.class) From 9522e1d39f48d130799e3515a2fe2be5b5155bed Mon Sep 17 00:00:00 2001 From: Astha Mohta Date: Thu, 21 Apr 2022 11:34:55 +0530 Subject: [PATCH 3/7] linting --- .../google/cloud/spanner/it/ITQueryTest.java | 29 +++++++------ .../cloud/spanner/it/ITResultSetGetValue.java | 27 ++++++------ .../google/cloud/spanner/it/ITWriteTest.java | 41 +++++++++---------- 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java index ff43ef35f16..efced98444e 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java @@ -16,6 +16,15 @@ package com.google.cloud.spanner.it; +import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; +import static com.google.common.truth.Truth.assertThat; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeFalse; + import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; @@ -40,6 +49,11 @@ import com.google.common.base.Joiner; import com.google.common.collect.Iterables; import com.google.spanner.v1.ResultSetStats; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -50,21 +64,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; -import static com.google.common.truth.Truth.assertThat; -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeFalse; - /** Integration tests for query execution. */ @Category(ParallelIntegrationTest.class) @RunWith(Parameterized.class) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java index 84d32673d20..68aeb2a0e99 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITResultSetGetValue.java @@ -16,6 +16,12 @@ package com.google.cloud.spanner.it; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; @@ -34,6 +40,13 @@ import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.primitives.Doubles; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import org.junit.AfterClass; import org.junit.Assume; import org.junit.Before; @@ -44,20 +57,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; - @Category(ParallelIntegrationTest.class) @RunWith(Parameterized.class) public class ITResultSetGetValue { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java index 0b24487183e..2428e75c994 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITWriteTest.java @@ -16,6 +16,16 @@ package com.google.cloud.spanner.it; +import static com.google.cloud.spanner.SpannerMatchers.isSpannerException; +import static com.google.cloud.spanner.Type.array; +import static com.google.cloud.spanner.Type.json; +import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeFalse; + import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; @@ -39,17 +49,6 @@ import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.collect.ImmutableList; import io.grpc.Context; -import org.hamcrest.MatcherAssert; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; @@ -63,16 +62,16 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - -import static com.google.cloud.spanner.SpannerMatchers.isSpannerException; -import static com.google.cloud.spanner.Type.array; -import static com.google.cloud.spanner.Type.json; -import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeFalse; +import org.hamcrest.MatcherAssert; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; /** Integration test for writing data to Cloud Spanner. */ @Category(ParallelIntegrationTest.class) From 52799ffa1058b7d9533d4efd4dde68fb7f27a4a6 Mon Sep 17 00:00:00 2001 From: Astha Mohta Date: Fri, 22 Apr 2022 15:57:10 +0530 Subject: [PATCH 4/7] changes as per review --- .../google/cloud/spanner/it/ITQueryTest.java | 98 ++++++++++--------- 1 file changed, 54 insertions(+), 44 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java index efced98444e..a72dedc2b9e 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java @@ -16,53 +16,34 @@ package com.google.cloud.spanner.it; -import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; -import static com.google.common.truth.Truth.assertThat; -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeFalse; - import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.Database; -import com.google.cloud.spanner.DatabaseClient; -import com.google.cloud.spanner.Dialect; -import com.google.cloud.spanner.ErrorCode; -import com.google.cloud.spanner.IntegrationTestEnv; -import com.google.cloud.spanner.Mutation; -import com.google.cloud.spanner.ParallelIntegrationTest; +import com.google.cloud.spanner.*; import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; -import com.google.cloud.spanner.ResultSet; -import com.google.cloud.spanner.SpannerException; -import com.google.cloud.spanner.Statement; -import com.google.cloud.spanner.Struct; -import com.google.cloud.spanner.TimestampBound; -import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Type.StructField; -import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.base.Joiner; import com.google.common.collect.Iterables; import com.google.spanner.v1.ResultSetStats; +import org.junit.*; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; + +import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; +import static com.google.common.truth.Truth.assertThat; +import static java.util.Arrays.asList; +import static org.junit.Assert.*; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; /** Integration tests for query execution. */ @Category(ParallelIntegrationTest.class) @@ -711,10 +692,8 @@ public void bindDateArrayNull() { } @Test - public void bindNumericArray() { - assumeFalse( - "array numeric binding is not supported on POSTGRESQL", - dialect.dialect == Dialect.POSTGRESQL); + public void bindNumericArrayGoogleStandardSQL() { + assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); BigDecimal b1 = new BigDecimal("3.14"); BigDecimal b2 = new BigDecimal("6.626"); @@ -728,10 +707,20 @@ public void bindNumericArray() { } @Test - public void bindNumericArrayEmpty() { - assumeFalse( - "array numeric binding is not supported on POSTGRESQL", - dialect.dialect == Dialect.POSTGRESQL); + public void bindNumericArrayPostgreSQL() { + assumeTrue(dialect.dialect == Dialect.POSTGRESQL); + assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); + Struct row = + execute( + Statement.newBuilder(selectValueQuery).bind("p1").toPgNumericArray(asList("3.14", "6.626", null)), + Type.array(Type.pgNumeric())); + assertThat(row.isNull(0)).isFalse(); + assertThat(row.getStringList(0)).containsExactly("3.14", "6.626", null).inOrder(); + } + + @Test + public void bindNumericArrayEmptyGoogleStandardSQL() { + assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); Struct row = execute( @@ -744,11 +733,22 @@ public void bindNumericArrayEmpty() { } @Test - public void bindNumericArrayNull() { - assumeFalse( - "array numeric binding is not supported on POSTGRESQL", - dialect.dialect == Dialect.POSTGRESQL); + public void bindNumericArrayEmptyPostgreSQL() { + assumeTrue(dialect.dialect == Dialect.POSTGRESQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); + Struct row = + execute( + Statement.newBuilder(selectValueQuery) + .bind("p1") + .toPgNumericArray(Collections.emptyList()), + Type.array(Type.pgNumeric())); + assertThat(row.isNull(0)).isFalse(); + assertThat(row.getStringList(0)).containsExactly(); + } + + @Test + public void bindNumericArrayNullGoogleStandardSQL() { + assumeTrue(dialect.dialect == Dialect.GOOGLE_STANDARD_SQL); Struct row = execute( Statement.newBuilder(selectValueQuery).bind("p1").toNumericArray(null), @@ -756,6 +756,16 @@ public void bindNumericArrayNull() { assertThat(row.isNull(0)).isTrue(); } + @Test + public void bindNumericArrayNullPostgreSQL() { + assumeTrue(dialect.dialect == Dialect.POSTGRESQL); + Struct row = + execute( + Statement.newBuilder(selectValueQuery).bind("p1").toPgNumericArray(null), + Type.array(Type.pgNumeric())); + assertThat(row.isNull(0)).isTrue(); + } + @Test public void bindNumericArray_doesNotPreservePrecision() { assumeFalse( From 2c2b20898183e02ff3ac90a5d97603dca79bd7ce Mon Sep 17 00:00:00 2001 From: Astha Mohta Date: Fri, 22 Apr 2022 16:01:26 +0530 Subject: [PATCH 5/7] linting --- .../google/cloud/spanner/it/ITQueryTest.java | 70 ++++++++++++------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java index a72dedc2b9e..a691fbf78b4 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java @@ -16,34 +16,54 @@ package com.google.cloud.spanner.it; +import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; +import static com.google.common.truth.Truth.assertThat; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; + import com.google.cloud.ByteArray; import com.google.cloud.Date; import com.google.cloud.Timestamp; -import com.google.cloud.spanner.*; +import com.google.cloud.spanner.Database; +import com.google.cloud.spanner.DatabaseClient; +import com.google.cloud.spanner.Dialect; +import com.google.cloud.spanner.ErrorCode; +import com.google.cloud.spanner.IntegrationTestEnv; +import com.google.cloud.spanner.Mutation; +import com.google.cloud.spanner.ParallelIntegrationTest; import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; +import com.google.cloud.spanner.ResultSet; +import com.google.cloud.spanner.SpannerException; +import com.google.cloud.spanner.Statement; +import com.google.cloud.spanner.Struct; +import com.google.cloud.spanner.TimestampBound; +import com.google.cloud.spanner.Type; import com.google.cloud.spanner.Type.StructField; +import com.google.cloud.spanner.Value; import com.google.cloud.spanner.connection.ConnectionOptions; import com.google.cloud.spanner.testing.EmulatorSpannerHelper; import com.google.common.base.Joiner; import com.google.common.collect.Iterables; import com.google.spanner.v1.ResultSetStats; -import org.junit.*; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; - -import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator; -import static com.google.common.truth.Truth.assertThat; -import static java.util.Arrays.asList; -import static org.junit.Assert.*; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; /** Integration tests for query execution. */ @Category(ParallelIntegrationTest.class) @@ -711,9 +731,11 @@ public void bindNumericArrayPostgreSQL() { assumeTrue(dialect.dialect == Dialect.POSTGRESQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); Struct row = - execute( - Statement.newBuilder(selectValueQuery).bind("p1").toPgNumericArray(asList("3.14", "6.626", null)), - Type.array(Type.pgNumeric())); + execute( + Statement.newBuilder(selectValueQuery) + .bind("p1") + .toPgNumericArray(asList("3.14", "6.626", null)), + Type.array(Type.pgNumeric())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getStringList(0)).containsExactly("3.14", "6.626", null).inOrder(); } @@ -737,11 +759,11 @@ public void bindNumericArrayEmptyPostgreSQL() { assumeTrue(dialect.dialect == Dialect.POSTGRESQL); assumeFalse("Emulator does not yet support NUMERIC", EmulatorSpannerHelper.isUsingEmulator()); Struct row = - execute( - Statement.newBuilder(selectValueQuery) - .bind("p1") - .toPgNumericArray(Collections.emptyList()), - Type.array(Type.pgNumeric())); + execute( + Statement.newBuilder(selectValueQuery) + .bind("p1") + .toPgNumericArray(Collections.emptyList()), + Type.array(Type.pgNumeric())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getStringList(0)).containsExactly(); } @@ -760,9 +782,9 @@ public void bindNumericArrayNullGoogleStandardSQL() { public void bindNumericArrayNullPostgreSQL() { assumeTrue(dialect.dialect == Dialect.POSTGRESQL); Struct row = - execute( - Statement.newBuilder(selectValueQuery).bind("p1").toPgNumericArray(null), - Type.array(Type.pgNumeric())); + execute( + Statement.newBuilder(selectValueQuery).bind("p1").toPgNumericArray(null), + Type.array(Type.pgNumeric())); assertThat(row.isNull(0)).isTrue(); } From 771970e2f304dd8f17289e64174f0e7326c11863 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 25 Apr 2022 04:44:19 +0000 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ac0e45a1e0..2cd75f2c065 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-spanner' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-spanner:6.23.2' +implementation 'com.google.cloud:google-cloud-spanner:6.23.3' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.23.2" +libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.23.3" ``` ## Authentication From 23fd2f899c58171e68ac7d8c17b7a0817a4a4dbf Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 5 Jul 2022 15:58:12 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f8342f2a8e0..46ebf34800f 100644 --- a/README.md +++ b/README.md @@ -49,20 +49,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies ```Groovy -implementation platform('com.google.cloud:libraries-bom:25.3.0') +implementation platform('com.google.cloud:libraries-bom:25.4.0') implementation 'com.google.cloud:google-cloud-spanner' ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-spanner:6.25.1' +implementation 'com.google.cloud:google-cloud-spanner:6.25.7' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.25.1" +libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.25.7" ``` ## Authentication