Skip to content

Commit 694ff47

Browse files
committed
Merge branch 'main' into nulls-last
2 parents e83d1fd + 2e03033 commit 694ff47

File tree

17 files changed

+91
-27
lines changed

17 files changed

+91
-27
lines changed

.github/workflows/nightly.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- uses: actions/checkout@v3
4848
- uses: gaurav-nelson/github-action-markdown-link-check@v1
4949
with:
50-
config-file: .config/.markdown-link-check-global.json
50+
config-file: .config/.markdown-link-check-all.json
5151

5252
time-compilation:
5353
runs-on: ubuntu-latest
@@ -64,17 +64,17 @@ jobs:
6464
update-rust-toolchain:
6565
runs-on: ubuntu-latest
6666
# Don't run on forks; will attempt to create a PR into the fork...
67-
# if: ${{ !github.event.pull_request.head.repo.fork }}
67+
if: ${{ !github.event.pull_request.head.repo.fork }}
6868

69-
# Disabling until we resolve what version Debian supports, ref https://github.com/PRQL/prql/pull/1561
70-
if: false
69+
# Note that this doesn't change the minimum supported version, only the
70+
# default to run on. The minimum is defined by Cargo.toml's metadata.msrv.
7171
steps:
7272
- name: 📂 Checkout code
7373
uses: actions/checkout@v3
7474
- uses: a-kenji/update-rust-toolchain@main
7575
with:
7676
# Discussion in #1561
77-
minor-version-delta: 3
77+
minor-version-delta: 1
7878
toolchain-path: "./rust-toolchain.toml"
7979
pr-title: "build: Update rust toolchain version"
8080

.github/workflows/test-all.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,12 @@ jobs:
144144
with:
145145
crate: cargo-msrv
146146
# Note this currently uses a manually maintained key in
147-
# `prql-compiler/Cargo.toml`, because of
147+
# `prql-compiler/Cargo.toml` (and `prql-compiler/prqlc/Cargo.toml` below), because of
148148
# https://github.com/foresterre/cargo-msrv/issues/590
149-
- name: Verify minimum rust version
149+
- name: Verify minimum rust version — prql-compiler
150150
# Ideally we'd check all crates, ref https://github.com/foresterre/cargo-msrv/issues/295
151151
working-directory: prql-compiler
152152
run: cargo msrv verify
153+
- name: Verify minimum rust version — prqlc
154+
working-directory: prql-compiler/prqlc
155+
run: cargo msrv verify

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 0.8.2 — [unreleased]
44

5+
_The following unreleased features are only available in the `main` branch. They
6+
will become the public version at the next release._
7+
58
**Features**:
69

710
- Add a `~=` regex search operator (@max-sixty, #2458). An example:
@@ -26,6 +29,15 @@
2629
[Regex docs](https://prql-lang.org/book/language-features/regex.html) for more
2730
details.
2831

32+
- Change to function syntax: `let f = x -> ...` See
33+
https://github.com/PRQL/prql/blob/main/web/book/src/queries/functions.md
34+
35+
- Modules allow importing declarations from other files: See
36+
https://github.com/PRQL/prql/blob/main/web/book/src/internals/modules.md
37+
38+
- Relation literals create in-line tables or array literals: See
39+
https://github.com/PRQL/prql/pull/2605
40+
2941
**Fixes**:
3042

3143
**Documentation**:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ To stay in touch with PRQL:
127127
This repo is composed of:
128128

129129
- **[prql-compiler](./prql-compiler/)** — the compiler, written in rust, whose
130-
main role is to compile PRQL into SQL. It also includes `prqlc`, the CLI.
130+
main role is to compile PRQL into SQL. It also includes
131+
[prqlc](./prql-compiler/prqlc/), the CLI.
131132
- **[web](./web/)** — our web content: the [Book][prql book],
132133
[Website][prql website], and [Playground][prql playground].
133134
- **[bindings](./bindings/)** — bindings from various languages to

prql-compiler/prqlc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ repository.workspace = true
88
rust-version.workspace = true
99
version.workspace = true
1010

11+
metadata.msrv = "1.65.0"
12+
1113
[target.'cfg(not(target_family="wasm"))'.dependencies]
1214
anyhow = {version = "1.0.57"}
1315
ariadne = "0.2.0"

prql-compiler/src/ast/rq/fold.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ pub fn fold_transform<T: ?Sized + RqFold>(
171171
partition: fold.fold_cids(partition)?,
172172
compute: fold.fold_cids(compute)?,
173173
},
174-
175174
Select(ids) => Select(fold.fold_cids(ids)?),
176175
Filter(i) => Filter(fold.fold_expr(i)?),
177176
Sort(sorts) => Sort(fold_column_sorts(fold, sorts)?),

prql-compiler/src/sql/dialect.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ pub(super) trait DialectHandler: Any + Debug {
158158
true
159159
}
160160

161+
fn supports_distinct_on(&self) -> bool {
162+
false
163+
}
164+
161165
fn translate_regex(
162166
&self,
163167
search: sql_ast::Expr,
@@ -370,6 +374,10 @@ impl DialectHandler for DuckDbDialect {
370374
false
371375
}
372376

377+
fn supports_distinct_on(&self) -> bool {
378+
true
379+
}
380+
373381
fn translate_regex(
374382
&self,
375383
search: sql_ast::Expr,

prql-compiler/src/sql/gen_query.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,29 @@ fn translate_select_pipeline(
107107
let order_by = pipeline.pluck(|t| t.into_sort());
108108
let takes = pipeline.pluck(|t| t.into_take());
109109
let is_distinct = pipeline.iter().any(|t| matches!(t, SqlTransform::Distinct));
110+
let distinct_ons = pipeline.pluck(|t| t.into_distinct_on());
110111
let distinct = if is_distinct {
111112
Some(sql_ast::Distinct::Distinct)
113+
} else if !distinct_ons.is_empty() {
114+
// FIXME: this "works" but is very hacky — it's using the
115+
// `translate_select_item` to translate each id into an Expr — is that
116+
// correct?
117+
//
118+
// Do we know we won't have more than one DistinctOn? We have that for
119+
// `Distinct`. But this will panic if we have more than one.
120+
// And if there the `SelectItem` is not an `UnnamedExpr`, it'll panic.
121+
Some(sql_ast::Distinct::On(
122+
distinct_ons
123+
.into_iter()
124+
.exactly_one()?
125+
.into_iter()
126+
.map(|id| translate_select_item(id, ctx).unwrap())
127+
.map(|item| match item {
128+
SelectItem::UnnamedExpr(expr) => expr,
129+
_ => unreachable!(),
130+
})
131+
.collect::<Vec<sql_ast::Expr>>(),
132+
))
112133
} else {
113134
None
114135
};

prql-compiler/src/sql/srq/anchor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ pub(super) fn get_requirements(
475475
Super(Sort(_)) => (Complexity::Aggregation, true),
476476
Super(Take(_)) => (Complexity::Plain, false),
477477
Super(Transform::Join { .. }) => (Complexity::Plain, false),
478-
479478
_ => unreachable!(),
480479
};
481480

prql-compiler/src/sql/srq/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub enum SqlTransform<Rel = RelationExpr, Super = rq::Transform> {
9898
},
9999

100100
Distinct,
101+
DistinctOn(Vec<rq::CId>),
101102
Except {
102103
bottom: Rel,
103104
distinct: bool,
@@ -173,6 +174,7 @@ pub fn fold_sql_transform<
173174
},
174175

175176
SqlTransform::Distinct => SqlTransform::Distinct,
177+
SqlTransform::DistinctOn(ids) => SqlTransform::DistinctOn(fold.fold_cids(ids)?),
176178
SqlTransform::Union { bottom, distinct } => SqlTransform::Union {
177179
bottom: fold.fold_rel(bottom)?,
178180
distinct,

prql-compiler/src/sql/srq/preprocess.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ pub(in crate::sql) fn distinct(
130130

131131
if take_only_first && sort.is_empty() && matching_columns {
132132
res.push(SqlTransform::Distinct);
133-
continue;
133+
} else if ctx.dialect.supports_distinct_on() {
134+
res.push(SqlTransform::DistinctOn(partition));
135+
} else {
136+
// convert `take range` into:
137+
// derive _rn = s"ROW NUMBER"
138+
// filter (_rn | in range)
139+
res.extend(create_filter_by_row_number(range, sort, partition, ctx));
134140
}
135-
136-
// convert `take range` into:
137-
// derive _rn = s"ROW NUMBER"
138-
// filter (_rn | in range)
139-
res.extend(create_filter_by_row_number(range, sort, partition, ctx));
140141
}
141142
_ => {
142143
res.push(transform);

prql-compiler/src/tests/test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,23 @@ fn test_distinct() {
14851485
"###);
14861486
}
14871487

1488+
#[test]
1489+
fn test_distinct_on() {
1490+
assert_display_snapshot!((compile(r###"
1491+
prql target:sql.duckdb
1492+
1493+
from x
1494+
select [class, begins]
1495+
group [begins] (take 1)
1496+
"###).unwrap()), @r###"
1497+
SELECT
1498+
DISTINCT ON (begins) class,
1499+
begins
1500+
FROM
1501+
x
1502+
"###);
1503+
}
1504+
14881505
#[test]
14891506
fn test_join() {
14901507
assert_display_snapshot!((compile(r###"

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[toolchain]
2-
channel = "1.65.0"
2+
channel = "1.66.0"
33
components = ["rustfmt", "clippy"]
44
# We want two targets: wasm32, and the default target for the platform, which we
55
# don't list here. (i.e. we use each platform to test each platform)

web/book/src/contributing/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ general channels such as GitHub or Discord, feel free to reach out to:
9191

9292
- [**@aljazerzen**](https://github.com/aljazerzen) — Aljaž Mur Eržen
9393
- [**@max-sixty**](https://github.com/max-sixty) — Maximilian Roos
94-
- [**@eitsupi**](https://twitter.com/eitsupi) — SHIMA Tatsuya
94+
- [**@eitsupi**](https://github.com/eitsupi) — SHIMA Tatsuya
9595
- [**@snth**](https://github.com/snth) — Tobias Brandt
9696

9797
### Core team Emeritus

web/book/src/integrations/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
PRQL is building integrations with lots of external tools, including:
44

5-
- [dbt](./dbt.md)
65
- [Jupyter](./jupyter.md)
76
- [DuckDB](./duckdb.md)
87
- [Prefect](./prefect.md)

web/playground/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
]
1313
},
1414
"dependencies": {
15-
"@duckdb/duckdb-wasm": "^1.24.0",
15+
"@duckdb/duckdb-wasm": "^1.26.0",
1616
"@monaco-editor/react": "^4.5.0",
1717
"@testing-library/jest-dom": "^5.16.5",
1818
"@testing-library/react": "^14.0.0",

0 commit comments

Comments
 (0)