Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ fail-fast = false
failure-output = "final"
slow-timeout = {period = "500ms", terminate-after = 4}

[[profile.default.overrides]]
# compileall does many passes over the same query, so it takes a bit longer
filter = 'package(prqlc) & test(queries::compileall::)'
slow-timeout = {period = "10s", terminate-after = 2}

[[profile.default.overrides]]
filter = 'package(prqlc) & test(queries::results::)'
slow-timeout = {period = "10s", terminate-after = 4}
Expand Down
70 changes: 59 additions & 11 deletions prqlc/prqlc/tests/integration/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{env, fs};
use insta::assert_debug_snapshot;
use insta::{assert_snapshot, with_settings};
use prqlc::sql::Dialect;
use prqlc::sql::SupportLevel;
use prqlc::{Options, Target};
use test_each_file::test_each_path;

Expand Down Expand Up @@ -50,6 +51,64 @@ mod compile {
}
}

fn should_run_query(dialect: Dialect, prql: &str) -> bool {
let dialect_str = dialect.to_string().to_lowercase();

match dialect.support_level() {
SupportLevel::Supported => !prql.contains(&format!("{dialect_str}:skip")),
SupportLevel::Unsupported => prql.contains(&format!("{dialect_str}:test")),
SupportLevel::Nascent => false,
}
}

mod compileall {
use super::*;
use similar::TextDiff;
use strum::IntoEnumIterator;

test_each_path! { in "./prqlc/prqlc/tests/integration/queries" => run }

fn run(prql_path: &Path) {
let test_name = prql_path.file_stem().unwrap().to_str().unwrap();
let prql = fs::read_to_string(prql_path).unwrap();
if prql.contains("generic:skip") {
return;
}

// first compile with the generic dialect
let target = Target::Sql(Some(Dialect::Generic));
let options = Options::default().no_signature().with_target(target);

let generic_sql = prqlc::compile(&prql, &options).unwrap();

// next compile with each dialect
let mut diffsnap = "".to_owned();
for dialect in Dialect::iter() {
if !should_run_query(dialect, &prql) {
continue;
}

let dialect_target = Target::Sql(Some(dialect));
let dialect_options = Options::default()
.no_signature()
.with_target(dialect_target);

let dialect_sql = prqlc::compile(&prql, &dialect_options).unwrap();

let diff = TextDiff::from_lines(&generic_sql, &dialect_sql);
diffsnap = format!(
"{diffsnap}\n{}",
diff.unified_diff()
.context_radius(10)
.header("generic", &dialect.to_string())
);
}
with_settings!({ input_file => prql_path }, {
assert_snapshot!(test_name, diffsnap, &prql)
});
}
}

mod fmt {
use super::*;

Expand Down Expand Up @@ -96,23 +155,12 @@ mod debug_lineage {
mod results {

use itertools::Itertools;
use prqlc::sql::SupportLevel;

use super::*;
use crate::dbs::{batch_to_csv, runners};

test_each_path! { in "./prqlc/prqlc/tests/integration/queries" => run }

fn should_run_query(dialect: Dialect, prql: &str) -> bool {
let dialect_str = dialect.to_string().to_lowercase();

match dialect.support_level() {
SupportLevel::Supported => !prql.contains(&format!("{dialect_str}:skip")),
SupportLevel::Unsupported => prql.contains(&format!("{dialect_str}:test")),
SupportLevel::Nascent => false,
}
}

fn run(prql_path: &Path) {
let test_name = prql_path.file_stem().unwrap().to_str().unwrap();
let prql = fs::read_to_string(prql_path).unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: prqlc/prqlc/tests/integration/queries.rs
expression: "# mysql:skip\n# clickhouse:skip\n# glaredb:skip (the string_agg function is not supported)\nfrom tracks\nfilter genre_id == 100\nderive empty_name = name == ''\naggregate {sum track_id, concat_array name, all empty_name, any empty_name}\n"
input_file: prqlc/prqlc/tests/integration/queries/aggregation.prql
---
--- generic
+++ sqlite
@@ -1,9 +1,9 @@
SELECT
COALESCE(SUM(track_id), 0),
- COALESCE(STRING_AGG(name, ''), ''),
- COALESCE(BOOL_AND(name = ''), TRUE),
- COALESCE(BOOL_OR(name = ''), FALSE)
+ COALESCE(GROUP_CONCAT(name, ''), ''),
+ COALESCE(MIN(name = '') > 0, TRUE),
+ COALESCE(MAX(name = '') > 0, FALSE)
FROM
tracks
WHERE
genre_id = 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: prqlc/prqlc/tests/integration/queries.rs
expression: "from invoices\nselect { customer_id, invoice_id, billing_country }\ntake 10..15\nappend (\n from invoices\n select { customer_id, invoice_id, billing_country }\n take 40..45\n)\nselect { billing_country, invoice_id }\n"
input_file: prqlc/prqlc/tests/integration/queries/append_select.prql
---

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
source: prqlc/prqlc/tests/integration/queries.rs
expression: "from invoices\nselect { customer_id, invoice_id, total }\ntake 5\nappend (\n from invoice_items\n select { invoice_line_id, invoice_id, unit_price }\n take 5\n)\nselect { a = customer_id * 2, b = math.round 1 (invoice_id * total) }\n"
input_file: prqlc/prqlc/tests/integration/queries/append_select_compute.prql
---
--- generic
+++ glaredb
@@ -23,13 +23,13 @@
) AS table_2
UNION
ALL
SELECT
*
FROM
table_0
)
SELECT
customer_id * 2 AS a,
- ROUND(invoice_id * total, 1) AS b
+ ROUND((invoice_id * total)::numeric, 1) AS b
FROM
table_1


--- generic
+++ postgres
@@ -23,13 +23,13 @@
) AS table_2
UNION
ALL
SELECT
*
FROM
table_0
)
SELECT
customer_id * 2 AS a,
- ROUND(invoice_id * total, 1) AS b
+ ROUND((invoice_id * total)::numeric, 1) AS b
FROM
table_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: prqlc/prqlc/tests/integration/queries.rs
expression: "from invoices\nselect { customer_id, invoice_id, billing_country }\ntake 5\nappend (\n from employees\n select { employee_id, employee_id, country }\n take 5\n)\nappend (\n from invoice_items\n select { invoice_line_id, invoice_id, null }\n take 5\n)\nselect { billing_country, invoice_id }\n"
input_file: prqlc/prqlc/tests/integration/queries/append_select_multiple_with_null.prql
---

Loading
Loading