Skip to content

Commit 4a3b8eb

Browse files
feat(c/driver/postgresql): add validation suite and override tests (#3821)
This PR contains: - Setup validataion suite for the postgresql driver. (128 tests pass. 0 failing. Decimal ingest test, and decimal bind tests were skipped due to bug and the fix has not been merged yet. #3787) - PostgreSQL specific test overrides - Update postgresql integration test in CI workflow to run validation tests - Update RAT license exlusions file to ignore the .lock files and test sql files. There was a small change made in the c/driver/postgresql/result_helper.cc due to the segfault when the number of query parameters doesn't match the number of result columns. The test that triggered the bug was calling get_parameter_schema() on `SELECT 1 + $1 + $2` . This query has 2 parameters but returns only 1 result column (the computed sum). The code was incorrectly using PQfname(result_, i) to retrieve parameter names, but PQfname() actually retrieves result column names from the result set. When iterating through parameters, the first iteration (i=0) would work fine accessing column 0, but the second iteration (i=1) would access an out-of-range column. PQfname() returns NULL for out-of-range column numbers, and passing this NULL pointer to AppendChild() as a C string causes the segfault.
1 parent 22b954d commit 4a3b8eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2902
-13
lines changed

.github/workflows/integration.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ jobs:
248248
./ci/scripts/cpp_test.sh "$(pwd)/build"
249249
./ci/scripts/python_test.sh "$(pwd)" "$(pwd)/build"
250250
docker compose down
251+
- name: Install pixi
252+
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659 # v0.8.1
253+
with:
254+
pixi-version: v0.62.1
255+
- name: Run PostgreSQL Validation Suite
256+
run: |
257+
env POSTGRES_VERSION=15 docker compose up --wait --detach postgres-test
258+
cd c/driver/postgresql/validation
259+
pixi run validate
260+
docker compose down
251261
- name: Test PostgreSQL Driver - postgres 16
252262
env:
253263
BUILD_ALL: "0"

c/driver/postgresql/connection.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,10 @@ AdbcStatusCode PostgresConnection::GetInfo(struct AdbcConnection* connection,
541541
break;
542542
case ADBC_INFO_DRIVER_VERSION:
543543
// TODO(lidavidm): fill in driver version
544-
infos.push_back({info_codes[i], "(unknown)"});
544+
infos.push_back({info_codes[i], "unknown"});
545545
break;
546546
case ADBC_INFO_DRIVER_ARROW_VERSION:
547-
infos.push_back({info_codes[i], NANOARROW_VERSION});
547+
infos.push_back({info_codes[i], "v" NANOARROW_VERSION});
548548
break;
549549
case ADBC_INFO_DRIVER_ADBC_VERSION:
550550
infos.push_back({info_codes[i], ADBC_VERSION_1_1_0});

c/driver/postgresql/postgresql_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class PostgresQuirks : public adbc_validation::DriverQuirks {
203203
case ADBC_INFO_DRIVER_NAME:
204204
return "ADBC PostgreSQL Driver";
205205
case ADBC_INFO_DRIVER_VERSION:
206-
return "(unknown)";
206+
return "unknown";
207207
case ADBC_INFO_VENDOR_NAME:
208208
return "PostgreSQL";
209209
default:
@@ -291,7 +291,7 @@ TEST_F(PostgresConnectionTest, GetInfoMetadata) {
291291
}
292292
case ADBC_INFO_DRIVER_VERSION: {
293293
ArrowStringView val = ArrowArrayViewGetStringUnsafe(str_child, offset);
294-
EXPECT_EQ("(unknown)", std::string(val.data, val.size_bytes));
294+
EXPECT_EQ("unknown", std::string(val.data, val.size_bytes));
295295
break;
296296
}
297297
case ADBC_INFO_VENDOR_NAME: {

c/driver/postgresql/result_helper.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ Status PqResultHelper::ResolveParamTypes(PostgresTypeResolver& type_resolver,
143143
const Oid pg_oid = PQparamtype(result_, i);
144144
PostgresType pg_type;
145145
if (type_resolver.Find(pg_oid, &pg_type, &na_error) != NANOARROW_OK) {
146-
Status status = Status::NotImplemented("[libpq] Parameter #", i + 1, " (\"",
147-
PQfname(result_, i),
148-
"\") has unknown type code ", pg_oid);
146+
std::string param_name = "$" + std::to_string(i + 1);
147+
Status status =
148+
Status::NotImplemented("[libpq] Parameter #", i + 1, " (\"", param_name,
149+
"\") has unknown type code ", pg_oid);
149150
ClearResult();
150151
return status;
151152
}
152153

153-
root_type.AppendChild(PQfname(result_, i), pg_type);
154+
std::string param_name = "$" + std::to_string(i + 1);
155+
root_type.AppendChild(param_name.c_str(), pg_type);
154156
}
155157

156158
*param_types = root_type;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
validation-report.xml
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# PostgreSQL ADBC Driver Validation Suite
21+
22+
This directory contains a Python-based validation suite for the PostgreSQL ADBC driver.
23+
24+
## Testing
25+
26+
A running instance of PostgreSQL is required. For example, using Docker:
27+
28+
```shell
29+
$ docker run -it --rm \
30+
-e POSTGRES_PASSWORD=password \
31+
-e POSTGRES_DB=postgres \
32+
-p 5432:5432 \
33+
postgres
34+
```
35+
36+
Alternatively use the `docker compose` provided by ADBC to manage the test
37+
database container.
38+
39+
```shell
40+
$ docker compose up postgres-test
41+
# When finished:
42+
# docker compose down postgres-test
43+
```
44+
45+
Then, to run the tests, set the environment variable specifying the
46+
PostgreSQL URI before running tests:
47+
48+
```shell
49+
$ export ADBC_POSTGRESQL_TEST_URI=postgresql://localhost:5432/postgres?user=postgres&password=password
50+
```
51+
52+
### 5. Run Tests
53+
54+
#### Using pixi:
55+
56+
```bash
57+
cd c/driver/postgresql/validation
58+
pixi run validate
59+
```

0 commit comments

Comments
 (0)