Skip to content

Commit

Permalink
add postgres comparison to python test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiayu Liu committed May 8, 2021
1 parent b8805d4 commit aead845
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 5 deletions.
49 changes: 47 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ on:
pull_request:

jobs:

# build the library, a compilation step used by multiple steps below
linux-build-lib:
name: Build Libraries on AMD64 Rust ${{ matrix.rust }}
Expand Down Expand Up @@ -133,6 +132,52 @@ jobs:
# snmalloc requires cmake so build without default features
cargo test --no-default-features
integration-test:
name: "Integration Test"
needs: [linux-build-lib]
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db_test
ports:
- 5432/tcp
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Allow access of psql
run: |
# make sure psql can access the server
echo "$POSTGRES_HOST:$POSTGRES_PORT:$POSTGRES_DB:$POSTGRES_USER:$POSTGRES_PASSWORD" | tee ~/.pgpass
chmod 0600 ~/.pgpass
psql -d "$POSTGRES_DB" -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -c 'select 1 as num'
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
POSTGRES_DB: db_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
- name: Compare Results
run: |
# run integration test
find integration-tests -type f -name '*.sql' \
-exec python integration-tests/compare_sql_output.py {} \;
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
POSTGRES_DB: db_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

windows-and-macos:
name: Test on ${{ matrix.os }} Rust ${{ matrix.rust }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -242,7 +287,7 @@ jobs:
- name: Run Miri Checks
env:
RUST_BACKTRACE: full
RUST_LOG: 'trace'
RUST_LOG: "trace"
run: |
export MIRIFLAGS="-Zmiri-disable-isolation"
cargo miri setup
Expand Down
6 changes: 3 additions & 3 deletions datafusion/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The DataFusion CLI is a command-line interactive SQL utility that allows queries

Use the following commands to clone this repository and run the CLI. This will require the Rust toolchain to be installed. Rust can be installed from [https://rustup.rs/](https://rustup.rs/).

```sh
```bash
git clone https://github.com/apache/arrow-datafusion
cd arrow-datafusion/datafusion-cli
cargo run --release
Expand All @@ -35,7 +35,7 @@ cargo run --release

Use the following commands to clone this repository and build a Docker image containing the CLI tool. Note that there is `.dockerignore` file in the root of the repository that may need to be deleted in order for this to work.

```sh
```bash
git clone https://github.com/apache/arrow-datafusion
cd arrow-datafusion
docker build -f datafusion-cli/Dockerfile . --tag datafusion-cli
Expand Down Expand Up @@ -64,7 +64,7 @@ Type `exit` or `quit` to exit the CLI.
Parquet data sources can be registered by executing a `CREATE EXTERNAL TABLE` SQL statement. It is not necessary to provide schema information for Parquet files.

```sql
CREATE EXTERNAL TABLE taxi
CREATE EXTERNAL TABLE taxi
STORED AS PARQUET
LOCATION '/mnt/nyctaxi/tripdata.parquet';
```
Expand Down
66 changes: 66 additions & 0 deletions integration-tests/compare_sql_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import difflib
import os
import subprocess
import sys


def compare_sql_output(fname: str):
with open(fname, "r") as infile:
got = subprocess.check_output(
["cargo", "run", "--release", "-q", "--bin", "datafusion-cli"],
stdin=infile,
)

pg_db, pg_user, pg_host, pg_port = [
os.environ.get(i)
for i in ("POSTGRES_DB", "POSTGRES_USER", "POSTGRES_HOST", "POSTGRES_PORT")
]
expected = subprocess.check_output(
[
"psql",
"-d",
pg_db,
"-h",
pg_host,
"-p",
pg_port,
"-U",
pg_user,
"-X",
"-f",
fname,
]
)
got, expected = (
expected.decode("utf-8").splitlines(keepends=True),
got.decode("utf-8").splitlines(keepends=True),
)

result = difflib.ndiff(got, expected)

print("".join(result), end="")


def main():
for fname in sys.argv[1:]:
compare_sql_output(fname)


if __name__ == "__main__":
main()
22 changes: 22 additions & 0 deletions integration-tests/sqls/simple_math_expressions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at

-- http://www.apache.org/licenses/LICENSE-2.0

-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

SELECT
abs(-1.1) as abs,
exp(2.0) as exp,
sin(3.0) as sin,
cos(4.0) as cos,
tan(5.0) as tan;
17 changes: 17 additions & 0 deletions integration-tests/sqls/simple_select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at

-- http://www.apache.org/licenses/LICENSE-2.0

-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

SELECT 1 as num;

0 comments on commit aead845

Please sign in to comment.