Skip to content

Commit

Permalink
feat!: std.sql.read_csv is compiled to read_csv in SQL by default (
Browse files Browse the repository at this point in the history
…#3599)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
eitsupi and pre-commit-ci[bot] authored Oct 4, 2023
1 parent 1c56448 commit 55d9996
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

**Features**:

- _Breaking_: The `std.sql.read_csv` function is now compiled to `read_csv` by
default. Please set the target `sql.duckdb` to use the DuckDB's
`read_csv_auto` function as previously. (@eitsupi, #3599)
- Add `std.prql_version` function to return PRQL version (@hulxv, #3533)
- Add support for hex escape sequences in strings. Example `"Hello \x51"`.
(@vanillajonathan, #3568)
Expand Down Expand Up @@ -231,7 +234,7 @@ A small selection of the changes:
- New arithmetic operators. These compile to different function or operator
depending on the target.

- _Breaking:_ Operator `/` now always performs floating division (@aljazerzen,
- _Breaking_: Operator `/` now always performs floating division (@aljazerzen,
#2684). _TODO: add link to division operator docs_

- Truncated integer division operator `//` (@aljazerzen, #2684).
Expand Down
4 changes: 3 additions & 1 deletion crates/prql-compiler/src/sql/std.sql.prql
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let upper = column -> s"UPPER({column:0})"

# Source-reading functions, primarily for DuckDB
let read_parquet = source -> s"read_parquet({source:0})"
let read_csv = source -> s"read_csv_auto({source:0})"
let read_csv = source -> s"read_csv({source:0})"

@{binding_strength=11}
let mul = l r -> null
Expand Down Expand Up @@ -156,6 +156,8 @@ module duckdb {
let div_i = l r -> s"TRUNC({l:11} / {r:11})"

let regex_search = text pattern -> s"REGEXP_MATCHES({text:0}, {pattern:0})"

let read_csv = source -> s"read_csv_auto({source:0})"
}

module mssql {
Expand Down
2 changes: 1 addition & 1 deletion crates/prql-compiler/src/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3477,7 +3477,7 @@ fn test_loop_2() {
SELECT
*
FROM
read_csv_auto('employees.csv')
read_csv('employees.csv')
),
table_0 AS (
SELECT
Expand Down
17 changes: 14 additions & 3 deletions web/book/src/how-do-i/read-files.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# How do I: read files?

There are a couple of functions designed for DuckDB:
There are a couple of functions mainly designed for DuckDB:

```prql
from (read_parquet 'artists.parquet')
join (read_csv 'albums.csv') (==track_id)
prql target:sql.duckdb
from (read_parquet "artists.parquet")
join (read_csv "albums.csv") (==track_id)
```

```admonish note
Expand All @@ -16,6 +18,15 @@ please log an issue and it's a fairly easy addition.
We may be able to reduce the boilerplate `WITH table_x AS SELECT * FROM...` in future versions.
```

When specifying file names directly in the `FROM` clause without using
functions, which is allowed in DuckDB, enclose the file names in backticks
` `` ` as follows:

```prql
from `artists.parquet`
```

## See also

- [Target and Version](../project/target.md)
- [How do I: create ad-hoc relations?](./relation-literals.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: web/book/tests/documentation/book.rs
expression: "from `artists.parquet`\n"
---
SELECT
*
FROM
"artists.parquet"

0 comments on commit 55d9996

Please sign in to comment.