Skip to content

Commit

Permalink
build(deps): bump org.postgresql:postgresql from 42.7.1 to 42.7.2 (#1440
Browse files Browse the repository at this point in the history
)

* build(deps): bump org.postgresql:postgresql from 42.7.1 to 42.7.2

Bumps [org.postgresql:postgresql](https://github.com/pgjdbc/pgjdbc) from 42.7.1 to 42.7.2.
- [Release notes](https://github.com/pgjdbc/pgjdbc/releases)
- [Changelog](https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md)
- [Commits](https://github.com/pgjdbc/pgjdbc/commits)

---
updated-dependencies:
- dependency-name: org.postgresql:postgresql
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* test: query generation in JDBC driver changed

* fix: make query timezone aware

* chore: condition tests that cast to int4

* fix: int4 is also not supported on real Spangres

* chore: add where true clause

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Knut Olav Løite <koloite@gmail.com>
  • Loading branch information
dependabot[bot] and olavloite committed Feb 21, 2024
1 parent 59d3250 commit 25e8289
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.1</version>
<version>42.7.2</version>
</dependency>
<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public abstract class AbstractMockServerTest {
Statement.of(
"with "
+ PG_TYPE_PREFIX
+ "\nSELECT pg_type.oid, typname FROM pg_type LEFT JOIN (select ns.oid as nspoid, ns.nspname, r.r from pg_namespace as ns join ( select 1 as r, 'public' as nspname ) as r using ( nspname ) ) as sp ON sp.nspoid = typnamespace WHERE typname = 'jsonb' ORDER BY sp.r, pg_type.oid DESC LIMIT 1");
+ "\nSELECT pg_type.oid, typname FROM pg_type LEFT JOIN (select ns.oid as nspoid, ns.nspname, r.r from pg_namespace as ns join ( select 1 as r, 'public' as nspname ) as r using ( nspname ) ) as sp ON sp.nspoid = typnamespace WHERE typname = ('jsonb') ORDER BY sp.r, pg_type.oid DESC LIMIT 1");

protected static final ResultSet SELECT_JSONB_TYPE_BY_NAME_RESULT_SET =
ResultSet.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testSelectWithParameters() throws SQLException {
int totalRows = 0;
mockSpanner.putStatementResult(
StatementResult.query(
Statement.of("select * from random where some_col='some-value'"),
Statement.of("select * from random where some_col=('some-value')"),
new RandomResultSetGenerator(numRows).generate()));

try (Connection connection = DriverManager.getConnection(createUrl())) {
Expand Down
86 changes: 62 additions & 24 deletions src/test/java/com/google/cloud/spanner/pgadapter/ITJdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ public void testSelectWithParameters() throws SQLException {
statement.setBytes(++index, "test".getBytes(StandardCharsets.UTF_8));
}
statement.setDouble(++index, 3.14d);
statement.setInt(++index, 1);
// TODO: Remove when Spangres supports casting to int4
if (isSimpleMode) {
statement.setLong(++index, 1);
} else {
statement.setInt(++index, 1);
}
statement.setBigDecimal(++index, new BigDecimal("3.14"));
statement.setTimestamp(
++index, Timestamp.parseTimestamp("2022-01-27T17:51:30+01:00").toSqlTimestamp());
Expand Down Expand Up @@ -382,9 +387,12 @@ public void testSelectWithParameters() throws SQLException {
assertArrayEquals(
new String[] {"string1", null, "string2"},
(String[]) resultSet.getArray(++index).getArray());
assertArrayEquals(
new String[] {"{\"key\": \"value1\"}", null, "{\"key\": \"value2\"}"},
(String[]) resultSet.getArray(++index).getArray());
// TODO: Remove when Spangres supports casting to int4
if (!isSimpleMode) {
assertArrayEquals(
new String[] {"{\"key\": \"value1\"}", null, "{\"key\": \"value2\"}"},
(String[]) resultSet.getArray(++index).getArray());
}

assertFalse(resultSet.next());
}
Expand Down Expand Up @@ -412,7 +420,12 @@ public void testInsertWithParameters() throws SQLException {
statement.setBytes(++index, "bytes_test".getBytes(StandardCharsets.UTF_8));
}
statement.setDouble(++index, 10.1);
statement.setInt(++index, 100);
// TODO: Remove when the emulator supports casting to int4
if (isSimpleMode) {
statement.setLong(++index, 100);
} else {
statement.setInt(++index, 100);
}
statement.setBigDecimal(++index, new BigDecimal("6.626"));
statement.setTimestamp(
++index, Timestamp.parseTimestamp("2022-02-11T13:45:00.123456+01:00").toSqlTimestamp());
Expand All @@ -438,7 +451,11 @@ public void testInsertWithParameters() throws SQLException {
}
statement.setArray(
++index, connection.createArrayOf("float8", new Double[] {3.14d, null, -99.8}));
statement.setArray(++index, connection.createArrayOf("int", new Integer[] {-1, null, -2}));
// TODO: Remove when Spangres supports casting to int4
statement.setArray(
++index,
connection.createArrayOf(
isSimpleMode ? "bigint" : "int", new Integer[] {-1, null, -2}));
statement.setArray(
++index,
connection.createArrayOf(
Expand All @@ -461,15 +478,28 @@ public void testInsertWithParameters() throws SQLException {
statement.setArray(
++index,
connection.createArrayOf("varchar", new String[] {"string1", null, "string2"}));
statement.setArray(
++index,
connection.createArrayOf(
"jsonb",
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
}));
// TODO: Remove when the emulator supports casting to int4
if (!isSimpleMode) {
statement.setArray(
++index,
connection.createArrayOf(
"jsonb",
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
}));
} else {
statement.setArray(
++index,
connection.createArrayOf(
"varchar",
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
}));
}

assertEquals(1, statement.executeUpdate());
}
Expand Down Expand Up @@ -545,13 +575,16 @@ public void testInsertWithParameters() throws SQLException {
assertArrayEquals(
new String[] {"string1", null, "string2"},
(String[]) resultSet.getArray(++index).getArray());
assertArrayEquals(
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
},
(String[]) resultSet.getArray(++index).getArray());
// TODO: Remove when Spangres supports casting to int4
if (!isSimpleMode) {
assertArrayEquals(
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
},
(String[]) resultSet.getArray(++index).getArray());
}

assertFalse(resultSet.next());
}
Expand Down Expand Up @@ -583,7 +616,12 @@ public void testUpdateWithParameters() throws SQLException {
statement.setBytes(++index, "updated".getBytes(StandardCharsets.UTF_8));
}
statement.setDouble(++index, 3.14d * 2d);
statement.setInt(++index, 2);
// TODO: Remove when Spangres supports casting to int4
if (isSimpleMode) {
statement.setLong(++index, 2);
} else {
statement.setInt(++index, 2);
}
statement.setBigDecimal(++index, new BigDecimal("10.0"));
// Note that PostgreSQL does not support nanosecond precision, so the JDBC driver therefore
// truncates this value before it is sent to PG.
Expand Down Expand Up @@ -727,7 +765,7 @@ public void testRelationNotFoundError() throws SQLException {
assertThrows(PSQLException.class, preparedStatement::executeQuery);
if (preferQueryMode.equals("simple")) {
assertEquals(
"ERROR: relation \"non_existing_table\" does not exist - Statement: 'select * from non_existing_table where id=1'",
"ERROR: relation \"non_existing_table\" does not exist - Statement: 'select * from non_existing_table where id=('1'::int8)'",
exception.getMessage());
} else {
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import java.util.TimeZone;
import java.util.stream.Collectors;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -396,15 +395,17 @@ public void testQueryWithParameters() throws SQLException {
.timeToString(java.sql.Timestamp.from(Instant.from(zonedDateTime)), true);

String pgSql =
"select col_bigint, col_bool, col_bytea, col_float8, col_numeric, col_timestamptz, col_varchar, col_jsonb "
+ "from all_types "
+ "where col_bigint=1 "
+ "and col_bool='TRUE' "
+ "and col_float8=3.14 "
+ "and col_numeric=6.626 "
+ String.format("and col_timestamptz='%s' ", timestampString)
+ "and col_varchar='test' "
+ "and col_jsonb='{\"key\": \"value\"}'";
String.format(
"select col_bigint, col_bool, col_bytea, col_float8, col_numeric, col_timestamptz, col_varchar, col_jsonb "
+ "from all_types "
+ "where col_bigint=('1'::int8) "
+ "and col_bool=('TRUE') "
+ "and col_float8=('3.14'::double precision) "
+ "and col_numeric=('6.626'::numeric) "
+ "and col_timestamptz=('%s') "
+ "and col_varchar=('test') "
+ "and col_jsonb=('{\"key\": \"value\"}')",
timestampString);
String jdbcSql =
"select col_bigint, col_bool, col_bytea, col_float8, col_numeric, col_timestamptz, col_varchar, col_jsonb "
+ "from all_types "
Expand All @@ -419,6 +420,7 @@ public void testQueryWithParameters() throws SQLException {
StatementResult.query(com.google.cloud.spanner.Statement.of(pgSql), ALL_TYPES_RESULTSET));

try (Connection connection = DriverManager.getConnection(createUrl())) {
connection.createStatement().execute("set time zone 'utc'");
try (PreparedStatement preparedStatement = connection.prepareStatement(jdbcSql)) {
int index = 0;
preparedStatement.setLong(++index, 1L);
Expand Down Expand Up @@ -757,7 +759,6 @@ public void testMixedDdlBatchWithStartAndRun() throws SQLException {
assertEquals(0, requests.size());
}

@Ignore("https://github.com/pgjdbc/pgjdbc/issues/3007")
@Test
public void testImplicitBatchOfClientSideStatements() throws SQLException {
String sql = "set statement_timeout = '10s'; " + "show statement_timeout; ";
Expand Down

0 comments on commit 25e8289

Please sign in to comment.