Skip to content

Commit 80abb09

Browse files
authored
include test data and add aggregation tests in integration test (#425)
* include test data * bump
1 parent 2b5b009 commit 80abb09

File tree

6 files changed

+122
-12
lines changed

6 files changed

+122
-12
lines changed

.github/workflows/rust.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ jobs:
155155
--health-retries 5
156156
steps:
157157
- uses: actions/checkout@v2
158+
with:
159+
submodules: true
158160
- uses: actions/setup-python@v2
159161
with:
160162
python-version: "3.8"
@@ -167,7 +169,22 @@ jobs:
167169
# make sure psql can access the server
168170
echo "$POSTGRES_HOST:$POSTGRES_PORT:$POSTGRES_DB:$POSTGRES_USER:$POSTGRES_PASSWORD" | tee ~/.pgpass
169171
chmod 0600 ~/.pgpass
170-
psql -d "$POSTGRES_DB" -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -c 'select now() as now'
172+
psql -d "$POSTGRES_DB" -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -c 'CREATE TABLE IF NOT EXISTS test (
173+
c1 character varying NOT NULL,
174+
c2 integer NOT NULL,
175+
c3 smallint NOT NULL,
176+
c4 smallint NOT NULL,
177+
c5 integer NOT NULL,
178+
c6 bigint NOT NULL,
179+
c7 smallint NOT NULL,
180+
c8 integer NOT NULL,
181+
c9 bigint NOT NULL,
182+
c10 character varying NOT NULL,
183+
c11 double precision NOT NULL,
184+
c12 double precision NOT NULL,
185+
c13 character varying NOT NULL
186+
);'
187+
psql -d "$POSTGRES_DB" -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -c "\copy test FROM '$(pwd)/testing/data/csv/aggregate_test_100.csv' WITH (FORMAT csv, HEADER true);"
171188
env:
172189
POSTGRES_HOST: localhost
173190
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}

datafusion-cli/src/main.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ pub async fn main() {
5858
)
5959
.arg(
6060
Arg::with_name("file")
61-
.help("Execute commands from file, then exit")
61+
.help("Execute commands from file(s), then exit")
6262
.short("f")
6363
.long("file")
64+
.multiple(true)
6465
.validator(is_valid_file)
6566
.takes_value(true),
6667
)
@@ -112,22 +113,25 @@ pub async fn main() {
112113
let quiet = matches.is_present("quiet");
113114
let print_options = PrintOptions { format, quiet };
114115

115-
if let Some(file_path) = matches.value_of("file") {
116-
let file = File::open(file_path)
117-
.unwrap_or_else(|err| panic!("cannot open file '{}': {}", file_path, err));
118-
let mut reader = BufReader::new(file);
119-
exec_from_lines(&mut reader, execution_config, print_options).await;
116+
if let Some(file_paths) = matches.values_of("file") {
117+
let files = file_paths
118+
.map(|file_path| File::open(file_path).unwrap())
119+
.collect::<Vec<_>>();
120+
let mut ctx = ExecutionContext::with_config(execution_config);
121+
for file in files {
122+
let mut reader = BufReader::new(file);
123+
exec_from_lines(&mut ctx, &mut reader, print_options.clone()).await;
124+
}
120125
} else {
121126
exec_from_repl(execution_config, print_options).await;
122127
}
123128
}
124129

125130
async fn exec_from_lines(
131+
ctx: &mut ExecutionContext,
126132
reader: &mut BufReader<File>,
127-
execution_config: ExecutionConfig,
128133
print_options: PrintOptions,
129134
) {
130-
let mut ctx = ExecutionContext::with_config(execution_config);
131135
let mut query = "".to_owned();
132136

133137
for line in reader.lines() {
@@ -139,7 +143,7 @@ async fn exec_from_lines(
139143
let line = line.trim_end();
140144
query.push_str(line);
141145
if line.ends_with(';') {
142-
match exec_and_print(&mut ctx, print_options.clone(), query).await {
146+
match exec_and_print(ctx, print_options.clone(), query).await {
143147
Ok(_) => {}
144148
Err(err) => println!("{:?}", err),
145149
}
@@ -156,7 +160,7 @@ async fn exec_from_lines(
156160

157161
// run the left over query if the last statement doesn't contain ‘;’
158162
if !query.is_empty() {
159-
match exec_and_print(&mut ctx, print_options, query).await {
163+
match exec_and_print(ctx, print_options, query).await {
160164
Ok(_) => {}
161165
Err(err) => println!("{:?}", err),
162166
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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, software
12+
-- distributed under the License is distributed on an "AS IS" BASIS,
13+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
-- See the License for the specific language governing permissions and
15+
-- limitations under the License.
16+
17+
CREATE EXTERNAL TABLE test (
18+
c1 VARCHAR NOT NULL,
19+
c2 INT NOT NULL,
20+
c3 SMALLINT NOT NULL,
21+
c4 SMALLINT NOT NULL,
22+
c5 INT NOT NULL,
23+
c6 BIGINT NOT NULL,
24+
c7 SMALLINT NOT NULL,
25+
c8 INT NOT NULL,
26+
c9 BIGINT NOT NULL,
27+
c10 VARCHAR NOT NULL,
28+
c11 FLOAT NOT NULL,
29+
c12 DOUBLE NOT NULL,
30+
c13 VARCHAR NOT NULL
31+
)
32+
STORED AS CSV
33+
WITH HEADER ROW
34+
LOCATION 'testing/data/csv/aggregate_test_100.csv';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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, software
12+
-- distributed under the License is distributed on an "AS IS" BASIS,
13+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
-- See the License for the specific language governing permissions and
15+
-- limitations under the License.
16+
17+
SELECT
18+
count(*) AS count_all,
19+
count(c3) AS count_c3,
20+
avg(c3) AS avg,
21+
sum(c3) AS sum,
22+
max(c3) AS max,
23+
min(c3) AS min
24+
FROM test;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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, software
12+
-- distributed under the License is distributed on an "AS IS" BASIS,
13+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
-- See the License for the specific language governing permissions and
15+
-- limitations under the License.
16+
17+
18+
select
19+
c2,
20+
sum(c3) sum_c3,
21+
avg(c3) avg_c3,
22+
max(c3) max_c3,
23+
min(c3) min_c3,
24+
count(c3) count_c3
25+
from test
26+
group by c2
27+
order by c2;

integration-tests/test_psql_parity.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@
3232
)
3333
]
3434

35+
CREATE_TABLE_SQL_FILE = "integration-tests/create_test_table.sql"
36+
3537

3638
def generate_csv_from_datafusion(fname: str):
3739
return subprocess.check_output(
3840
[
3941
"./target/debug/datafusion-cli",
4042
"-f",
43+
CREATE_TABLE_SQL_FILE,
44+
"-f",
4145
fname,
4246
"--format",
4347
"csv",
@@ -70,7 +74,7 @@ class PsqlParityTest(unittest.TestCase):
7074
def test_parity(self):
7175
root = Path(os.path.dirname(__file__)) / "sqls"
7276
files = set(root.glob("*.sql"))
73-
self.assertEqual(len(files), 2, msg="tests are missed")
77+
self.assertEqual(len(files), 4, msg="tests are missed")
7478
for fname in files:
7579
with self.subTest(fname=fname):
7680
datafusion_output = pd.read_csv(

0 commit comments

Comments
 (0)