Repository: prql/prql
Pull request #468 (2022-05-08 20:02:44)

Add summary of punctutation
Somewhat copied from @aljazerzen's comment https://github.com/prql/prql/issues/437#issuecomment-1118248380



Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 06240a8a..aef8fd49 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -13,7 +13,7 @@ repos:
       - id: fmt
       - id: clippy
   - repo: https://github.com/tcort/markdown-link-check
-    rev: v3.10.0
+    rev: v3.10.2
     hooks:
       - id: markdown-link-check
         files: \.md$
diff --git a/Cargo.lock b/Cargo.lock
index 77ef4ec9..b5ef8db2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1382,7 +1382,7 @@ dependencies = [
 
 [[package]]
 name = "prql-js"
-version = "0.1.2"
+version = "0.1.3"
 dependencies = [
  "console_error_panic_hook",
  "prql-compiler",
diff --git a/Taskfile.yml b/Taskfile.yml
index 1fcd0107..b74edeff 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -26,7 +26,7 @@ tasks:
     desc: Install tools for PRQL development.
     cmds:
       # `--locked` installs from the underlying lock files (which is not the default?!)
-      - cargo install --locked cargo-insta default-target trunk mdbook mdbook-toc
+      - cargo install --locked cargo-insta default-target trunk mdbook mdbook-toc wasm-bindgen-cli
       - rustup target add wasm32-unknown-unknown
       - python3 -m pip install -U maturin
       - task: install-pre-commit
diff --git a/prql-compiler/benches/bench.rs b/prql-compiler/benches/bench.rs
index f3770888..c64fb9d6 100644
--- a/prql-compiler/benches/bench.rs
+++ b/prql-compiler/benches/bench.rs
@@ -8,7 +8,7 @@
 use criterion::{criterion_group, criterion_main, Criterion};
 use prql_compiler::*;
 
-const CONTENT: &str = include_str!("../../reference/tests/examples/examples/variables-0.prql");
+const CONTENT: &str = include_str!("../../reference/tests/prql/examples/variables-0.prql");
 fn compile_query() -> Result<String> {
     compile(CONTENT)
 }
diff --git a/prql-compiler/src/ast/ast_fold.rs b/prql-compiler/src/ast/ast_fold.rs
index 093a0ae8..88c664c8 100644
--- a/prql-compiler/src/ast/ast_fold.rs
+++ b/prql-compiler/src/ast/ast_fold.rs
@@ -183,7 +183,7 @@ pub fn fold_transform<T: ?Sized + AstFold>(
             by: fold.fold_nodes(by)?,
         }),
 
-        Transform::Filter(items) => Ok(Transform::Filter(fold.fold_nodes(items)?)),
+        Transform::Filter(f) => Ok(Transform::Filter(Box::new(fold.fold_node(*f)?))),
         Transform::Sort(items) => Ok(Transform::Sort(fold.fold_column_sorts(items)?)),
         Transform::Join { side, with, filter } => Ok(Transform::Join {
             side,
diff --git a/prql-compiler/src/ast/query.rs b/prql-compiler/src/ast/query.rs
index 1f2fb1e9..4939af08 100644
--- a/prql-compiler/src/ast/query.rs
+++ b/prql-compiler/src/ast/query.rs
@@ -33,7 +33,7 @@ pub struct Table {
 pub enum Transform {
     From(TableRef),
     Select(Vec<Node>),
-    Filter(Vec<Node>),
+    Filter(Box<Node>),
     Derive(Vec<Node>),
     Aggregate {
         assigns: Vec<Node>,
diff --git a/prql-compiler/src/semantic/transforms.rs b/prql-compiler/src/semantic/transforms.rs
index 9f6bb0fd..57525aad 100644
--- a/prql-compiler/src/semantic/transforms.rs
+++ b/prql-compiler/src/semantic/transforms.rs
@@ -29,7 +29,7 @@ pub fn cast_transform(func_call: FuncCall, span: Option<Span>) -> Result<Transfo
         "filter" => {
             let ([filter], []) = unpack(func_call, [])?;
 
-            Transform::Filter(filter.coerce_to_vec())
+            Transform::Filter(Box::new(filter))
         }
         "derive" => {
             let ([assigns], []) = unpack(func_call, [])?;
diff --git a/prql-compiler/src/sql/translator.rs b/prql-compiler/src/sql/translator.rs
index 0faa6ff7..e1b0cae9 100644
--- a/prql-compiler/src/sql/translator.rs
+++ b/prql-compiler/src/sql/translator.rs
@@ -204,18 +204,19 @@ fn sql_query_of_atomic_table(table: AtomicTable, dialect: &Dialect) -> Result<sq
     let (before, after) = transforms.split_at(aggregate_position);
 
     // Convert the filters in a pipeline into an Expr
+    #[allow(unstable_name_collisions)] // Same behavior as the std lib; we can remove this + itertools when that's released.
     fn filter_of_pipeline(pipeline: &[Transform]) -> Result<Option<Expr>> {
-        let filters: Vec<Vec<Node>> = pipeline
+        let filters: Vec<Node> = pipeline
             .iter()
             .filter_map(|t| match t {
-                Transform::Filter(filter) => Some(filter),
+                Transform::Filter(filter) => Some(*filter.clone()),
                 _ => None,
             })
-            .cloned()
+            .intersperse(Node::from(Item::Operator("and".to_owned())))
             .collect();
 
         Ok(if !filters.is_empty() {
-            Some((Item::Expr(combine_filters(filters))).try_into()?)
+            Some((Item::Expr(filters)).try_into()?)
         } else {
             None
         })
@@ -388,16 +389,6 @@ fn prepend_with_from(pipeline: &mut Pipeline, table: Option<TableRef>) {
     }
 }
 
-/// Combines filters by putting them in parentheses and then joining them with `and`.
-#[allow(unstable_name_collisions)] // Same behavior as the std lib; we can remove this + itertools when that's released.
-fn combine_filters(filters: Vec<Vec<Node>>) -> Vec<Node> {
-    filters
-        .into_iter()
-        .map(|f| Item::Expr(f).into())
-        .intersperse(Item::Raw("and".to_owned()).into())
-        .collect()
-}
-
 fn expr_of_i64(number: i64) -> Expr {
     Expr::Value(Value::Number(
         number.to_string(),
@@ -1463,4 +1454,47 @@ take 20
 
         Ok(())
     }
+
+    #[test]
+    fn test_filter() {
+        // https://github.com/prql/prql/issues/469
+        let query: Query = parse(
+            r###"
+        from employees
+        filter [age > 25, age < 40]
+        "###,
+        )
+        .unwrap();
+
+        assert!(resolve_and_translate(query).is_err());
+
+        assert_display_snapshot!((resolve_and_translate(parse(r###"
+        from employees
+        filter age > 25 and age < 40
+        "###,
+        ).unwrap()).unwrap()), @r###"
+        SELECT
+          employees.*
+        FROM
+          employees
+        WHERE
+          age > 25
+          AND age < 40
+        "###);
+
+        assert_display_snapshot!((resolve_and_translate(parse(r###"
+        from employees
+        filter age > 25
+        filter age < 40
+        "###,
+        ).unwrap()).unwrap()), @r###"
+        SELECT
+          employees.*
+        FROM
+          employees
+        WHERE
+          age > 25
+          AND age < 40
+        "###);
+    }
 }
diff --git a/prql-js/Cargo.toml b/prql-js/Cargo.toml
index 57b59b61..f6e4ad19 100644
--- a/prql-js/Cargo.toml
+++ b/prql-js/Cargo.toml
@@ -4,7 +4,7 @@ edition = "2018"
 license = "Apache-2.0"
 name = "prql-js"
 repository = "https://github.com/prql/prql"
-version = "0.1.2"
+version = "0.1.3"
 
 [lib]
 crate-type = ["cdylib", "rlib"]
diff --git a/prql-web/src/lib.rs b/prql-web/src/lib.rs
index 12d00a5a..8c3a9abc 100644
--- a/prql-web/src/lib.rs
+++ b/prql-web/src/lib.rs
@@ -20,7 +20,7 @@ enum Msg {
     TextChange,
 }
 
-const CONTENT: &str = include_str!("../../reference/tests/examples/examples/variables-0.prql");
+const CONTENT: &str = include_str!("../../reference/tests/prql/examples/variables-0.prql");
 
 fn default_options() -> IStandaloneEditorConstructionOptions {
     let minimap_options = IEditorMinimapOptions::default();
diff --git a/reference/highlight-prql.js b/reference/highlight-prql.js
index cfc0797b..0a5d92fb 100644
--- a/reference/highlight-prql.js
+++ b/reference/highlight-prql.js
@@ -22,8 +22,13 @@ formatting = function (hljs) {
 
             { // named arg
                 className: 'params',
-                begin: '\\w+:(?!\\s)',
-                // begin: String.raw('\w+:(?!\s)'),
+                begin: '\\w+\\s*:',
+                end: '',
+                relevance: 10
+            },
+            { // assign
+                className: 'variable',
+                begin: '\\w+\\s*=(?!=)',
                 end: '',
                 relevance: 10
             },
@@ -33,9 +38,9 @@ formatting = function (hljs) {
                 end: ' ',
                 relevance: 10
             },
-            { // s-string
+            { // interpolation string
                 className: 'attribute',
-                begin: 's"', end: '"',
+                begin: '(s|f)"', end: '"',
                 relevance: 10
             },
             { // normal string
@@ -43,7 +48,6 @@ formatting = function (hljs) {
                 begin: '"', end: '"',
                 relevance: 10
             },
-
         ]
     };
 }
diff --git a/reference/src/SUMMARY.md b/reference/src/SUMMARY.md
index ea90c348..d42fda8a 100644
--- a/reference/src/SUMMARY.md
+++ b/reference/src/SUMMARY.md
@@ -3,6 +3,16 @@
 - [Introduction](./introduction.md)
 - [Queries](./queries/README.md)
   - [Pipelines](./queries/pipelines.md)
+- [Transforms](./transforms.md)
+  - [From](./transforms/from.md)
+  - [Select](./transforms/select.md)
+  - [Derive](./transforms/derive.md)
+  - [Filter](./transforms/filter.md)
+  - [Sort](./transforms/sort.md)
+  - [Join](./transforms/join.md)
+  - [Take](./transforms/take.md)
+  - [Group](./transforms/group.md)
+  - [Aggregate](./transforms/aggregate.md)
 - [Language features](./language-features/README.md)
   - [Strings](./language-features/strings.md)
   - [F-Strings](./language-features/f-strings.md)
@@ -13,7 +23,6 @@
     <!--   - Regex — `REGEX_MATCH(foo, "\\w{3}")` -> `foo ~ r"\w{3}"`? Or -> `regex foo r"\w{3}"`? -->
   - [Regex]()
 
-- [Transforms](./transforms.md)
 - [Syntax](./syntax.md)
 - [Functions](./functions.md)
 - [Stdlib](./stdlib.md)
@@ -25,7 +34,4 @@
   - [Functions](./examples/functions.md)
   - [CTE (intermediate tables)](./examples/cte.md)
   - [Sql parameters](./examples/sql-parameters.md)
-  - [Employees 0](./examples/employees-0.md)
-  - [Employees 1](./examples/employees-1.md)
-  - [Employees 2](./examples/employees-2.md)
-  - [Employees 3](./examples/employees-3.md)
+  - [Employees](./examples/employees.md)
diff --git a/reference/src/examples/README.md b/reference/src/examples/README.md
index 598ffa91..90b0ff53 100644
--- a/reference/src/examples/README.md
+++ b/reference/src/examples/README.md
@@ -1,15 +1,7 @@
-Examples prefixed with employees are using [employees database](https://github.com/vrajmohan/pgsql-sample-data.git).
+# Examples
 
-Clone and init the database (requires a local PostgreSQL instance):
+These examples are rewritten from other languages such as SQL. They try to express real-world problems in PRQL, covering most of the language features. We are looking for different use-cases of data transformation, be it database queries, semnatic bussiness modeling or data cleaning.
 
-    $ psql -U postgres -c 'CREATE DATABASE employees;'
-    $ git clone https://github.com/vrajmohan/pgsql-sample-data.git
-    $ psql -U postgres -d employees -f pgsql-sample-data/employee/employees.dump
+If you want to help, translate some of your queries to PRQL and [open a PR](https://github.com/prql/prql/pulls) to add them here!
 
-Execute a PRQL query:
-
-    $ cargo run compile examples/employees/average-title-salary.prql | psql -U postgres -d employees
-
-Also print the query:
-
-    $ cargo run compile my_file.prql | { tee /dev/stderr; echo -e "\nResult:" >&2 } | psql -U postgres -d employees
+<!-- TODO: toc -->
diff --git a/reference/src/examples/employees-0.md b/reference/src/examples/employees-0.md
deleted file mode 100644
index 8c9d1666..00000000
--- a/reference/src/examples/employees-0.md
+++ /dev/null
@@ -1,23 +0,0 @@
-Task:
-
-> rank the employee titles according to the average salary for each department.
-
-My solution:
-- for each employee, find their average salary,
-- join employees with their departments and titles (duplicating employees for each of their titles and departments)
-- group by department and title, aggregating average salary
-- join with department to get department name
-
-```prql
-from salaries
-group [emp_no] (
-  aggregate [emp_salary = average salary]
-)
-join t=titles [emp_no]
-join dept_emp side:left [emp_no]
-group [dept_emp.dept_no, t.title] (
-  aggregate [avg_salary = average emp_salary]
-)
-join departments [dept_no]
-select [dept_name, title, avg_salary]
-```
diff --git a/reference/src/examples/employees-1.md b/reference/src/examples/employees-1.md
deleted file mode 100644
index f07cf0ab..00000000
--- a/reference/src/examples/employees-1.md
+++ /dev/null
@@ -1,24 +0,0 @@
-Task:
-
-> The company active pursues gender equality.
->
-> Prepare an analysis based on salaries and gender distribution by departments.
-
-```prql
-from employees
-join salaries [emp_no]
-group [emp_no, gender] (
-  aggregate [
-    emp_salary = average salary
-  ]
-)
-join de=dept_emp [emp_no] side:left
-group [de.dept_no, gender] (
-  aggregate [
-    salary_avg = average emp_salary,
-    salary_sd = stddev emp_salary,
-  ]
-)
-join departments [dept_no]
-select [dept_name, gender, salary_avg, salary_sd]
-```
diff --git a/reference/src/examples/employees-2.md b/reference/src/examples/employees-2.md
deleted file mode 100644
index e81c03c3..00000000
--- a/reference/src/examples/employees-2.md
+++ /dev/null
@@ -1,28 +0,0 @@
-Task:
-
-> The company active pursues gender equality.
-> Prepare an analysis based on salaries and gender distribution by managers.
-
-```prql
-from employees
-join salaries [emp_no]
-group [emp_no, gender] (
-  aggregate [
-    emp_salary = average salary
-  ]
-)
-join de=dept_emp [emp_no]
-join dm=dept_manager [
-  (dm.dept_no == de.dept_no) and s"(de.from_date, de.to_date) OVERLAPS (dm.from_date, dm.to_date)"
-]
-group [dm.emp_no, gender] (
-  aggregate [
-    salary_avg = average emp_salary,
-    salary_sd = stddev emp_salary
-  ]
-)
-derive mng_no = dm.emp_no
-join managers=employees [emp_no]
-derive mng_name = s"managers.first_name || ' ' || managers.last_name"
-select [mng_name, managers.gender, salary_avg, salary_sd]
-```
diff --git a/reference/src/examples/employees-3.md b/reference/src/examples/employees-3.md
deleted file mode 100644
index fad3510c..00000000
--- a/reference/src/examples/employees-3.md
+++ /dev/null
@@ -1,17 +0,0 @@
-Task:
-
-> Find distributions of titles, salaries and genders over different departments.
-
-```prql
-from de=dept_emp
-join s=salaries side:left [
-  (s.emp_no == de.emp_no),
-  s"({s.from_date}, {s.to_date}) OVERLAPS ({de.from_date}, {de.to_date})"
-]
-group [de.emp_no, de.dept_no] (
-  aggregate salary = (average s.salary)
-)
-join employees [emp_no]
-join titles [emp_no]
-select [dept_no, salary, employees.gender, titles.title]
-```
diff --git a/reference/src/examples/employees.md b/reference/src/examples/employees.md
new file mode 100644
index 00000000..176c3c7c
--- /dev/null
+++ b/reference/src/examples/employees.md
@@ -0,0 +1,112 @@
+# Employees
+
+These are homework tasks on [employees database](https://github.com/vrajmohan/pgsql-sample-data.git).
+
+Clone and init the database (requires a local PostgreSQL instance):
+
+    $ psql -U postgres -c 'CREATE DATABASE employees;'
+    $ git clone https://github.com/vrajmohan/pgsql-sample-data.git
+    $ psql -U postgres -d employees -f pgsql-sample-data/employee/employees.dump
+
+Execute a PRQL query:
+
+    $ cargo run compile examples/employees/average-title-salary.prql | psql -U postgres -d employees
+
+
+## Task 1
+
+> rank the employee titles according to the average salary for each department.
+
+My solution:
+- for each employee, find their average salary,
+- join employees with their departments and titles (duplicating employees for each of their titles and departments)
+- group by department and title, aggregating average salary
+- join with department to get department name
+
+```prql
+from salaries
+group [emp_no] (
+  aggregate [emp_salary = average salary]
+)
+join t=titles [emp_no]
+join dept_emp side:left [emp_no]
+group [dept_emp.dept_no, t.title] (
+  aggregate [avg_salary = average emp_salary]
+)
+join departments [dept_no]
+select [dept_name, title, avg_salary]
+```
+
+## Task 2
+
+> The company active pursues gender equality.
+>
+> Prepare an analysis based on salaries and gender distribution by departments.
+
+```prql
+from employees
+join salaries [emp_no]
+group [emp_no, gender] (
+  aggregate [
+    emp_salary = average salary
+  ]
+)
+join de=dept_emp [emp_no] side:left
+group [de.dept_no, gender] (
+  aggregate [
+    salary_avg = average emp_salary,
+    salary_sd = stddev emp_salary,
+  ]
+)
+join departments [dept_no]
+select [dept_name, gender, salary_avg, salary_sd]
+```
+
+## Task 3
+
+> The company active pursues gender equality.
+>
+> Prepare an analysis based on salaries and gender distribution by managers.
+
+```prql
+from employees
+join salaries [emp_no]
+group [emp_no, gender] (
+  aggregate [
+    emp_salary = average salary
+  ]
+)
+join de=dept_emp [emp_no]
+join dm=dept_manager [
+  (dm.dept_no == de.dept_no) and s"(de.from_date, de.to_date) OVERLAPS (dm.from_date, dm.to_date)"
+]
+group [dm.emp_no, gender] (
+  aggregate [
+    salary_avg = average emp_salary,
+    salary_sd = stddev emp_salary
+  ]
+)
+derive mng_no = dm.emp_no
+join managers=employees [emp_no]
+derive mng_name = s"managers.first_name || ' ' || managers.last_name"
+select [mng_name, managers.gender, salary_avg, salary_sd]
+```
+
+
+## Task 4
+
+> Find distributions of titles, salaries and genders over different departments.
+
+```prql
+from de=dept_emp
+join s=salaries side:left [
+  (s.emp_no == de.emp_no),
+  s"({s.from_date}, {s.to_date}) OVERLAPS ({de.from_date}, {de.to_date})"
+]
+group [de.emp_no, de.dept_no] (
+  aggregate salary = (average s.salary)
+)
+join employees [emp_no]
+join titles [emp_no]
+select [dept_no, salary, employees.gender, titles.title]
+```
diff --git a/reference/src/examples/misc.md b/reference/src/examples/misc.md
new file mode 100644
index 00000000..fb52377a
--- /dev/null
+++ b/reference/src/examples/misc.md
@@ -0,0 +1,36 @@
+# Misc
+
+This file contains many different queries I rewrote from various languages with
+intention of finding examples of where PRQL could be improved.
+
+A SQL query to find all stubs in email addresses of accounts associated with some
+prospect list in a MariaDB of a CRM system.
+```prql
+# TODO: this table should have a column `part` with values 1..5,
+# but such data declaration is not yet supported, see #286
+table parts = (
+    from seq_1_to_5
+)
+
+from pl=prospect_lists_prospects
+filter prospect_list_id == 'cc675eee-8bd1-237f-be5e-622ba511d65e'
+join a=accounts [a.id == pl.related_id]
+join er=email_addr_bean_rel [er.bean_id == a.id and er.primary_address == '1']
+join ea=email_addresses [ea.id == er.email_address_id]
+select ea.email_address
+derive prefix = s"regexp_replace(SUBSTRING_INDEX({email_address}, '@', 1), '[.0-9-_:]+', '.')"
+select stub = s"SUBSTRING_INDEX(SUBSTRING_INDEX({prefix}, '.', part), '.', -1)"
+select [email_address, stub]
+```
+
+European football clubs with ratings for each year. We want to normalize each year separately.
+```prql
+from club_ratings
+# TODO: this should produce `rating IS NOT NULL`
+filter rating != null
+# TODO: this is real ugly. `average rating` should not require parenthesis
+# TODO: why cannot we put comments in group's pipeline?
+group year (
+    derive [rating_norm = rating - (average rating) / (stddev rating)]
+)
+```
diff --git a/reference/src/queries/pipelines.md b/reference/src/queries/pipelines.md
index 54a3880c..78f66536 100644
--- a/reference/src/queries/pipelines.md
+++ b/reference/src/queries/pipelines.md
@@ -24,3 +24,14 @@ from employees
 derive gross_salary = (salary + payroll_tax)
 sort gross_salary
 ```
+
+PRQL compiler will try to represent as many transforms as possible with a single `SELECT` statement, and uses CTE (common table expression) for complex pipelines:
+
+```prql
+from e = employees
+derive gross_salary = (salary + payroll_tax)
+sort gross_salary
+take 10
+join d = department [dept_no]
+select [e.name, gross_salary, d.name]
+```
diff --git a/reference/src/syntax.md b/reference/src/syntax.md
index 92ca9631..908bf837 100644
--- a/reference/src/syntax.md
+++ b/reference/src/syntax.md
@@ -44,3 +44,16 @@ from tbl | select [col1, col2] | filter col1 == col2
 - This is no longer point-free, but that's a feature rather than a requirement.
   The alternative is subqueries, which are fine at small scale, but become
   difficult to digest as complexity increases.
+
+### Punctuation summary
+
+A summary of how PRQL uses punctuation
+
+| Syntax   | Usage                   | Example                                                                      |
+| -------- | ----------------------- | ---------------------------------------------------------------------------- |
+| `:`      | Named args & Parameters | `interp lower:0 1600 sat_score`                                              |
+| `=`      | Assigns & Aliases       | `derive temp_c = (temp_f | celsius_of_fahrenheit)` <br> `from e = employees` |
+| `==`     | Equality comparison     | `join s=salaries [s.employee_id == employees.id]`                            |
+| `->`     | Function definitions    | `func add a b -> a + b`                                                      |
+| `<type>` | Annotations             | `@2021-01-01<datetime>`                                                      |
+| `+`/`-`  | Sort order              | `sort [-amount, +date]`                                                      |
diff --git a/reference/src/transforms.md b/reference/src/transforms.md
index 3bddcf7c..581a0c6a 100644
--- a/reference/src/transforms.md
+++ b/reference/src/transforms.md
@@ -1,205 +1,21 @@
 # Transforms
 
-Core principle of the language is a pipeline, which is a series of sequential transformations of a table (or data frame). There is only a few different types of transformations:
-
-## From
-
-> specifies a data source
-
-```prql_no_test
-from {table reference}
-```
-
-#### Examples
-
-```prql
-from employees
-```
-
-## Select
-
-> picks columns based on their names
-
-```prql_no_test
-select [{expression}]
-```
-
-#### Examples
-
-```prql
-from employees
-select [first_name, last_name]
-```
-
-## Derive
-
-> adds new columns that are computed from existing columns
-
-```prql_no_test
-derive [{new_name} = {expression}]
-```
-
-#### Examples
-
-```prql
-from employees
-derive gross_salary = salary + payroll_tax
-```
-
-```prql
-from employees
-derive [
-  gross_salary = salary + payroll_tax,
-  gross_cost = gross_salary + benefits_cost
-]
-```
-
-## Filter
-
-> picks rows based on their values
-
-```prql_no_test
-filter {boolean expression}
-```
-
-#### Examples
-
-```prql_no_test
-from employees
-filter (length last_name < 3)
-```
-
-## Sort
-
-`sort` orders rows based on the values of one or more columns.
-
-```prql_no_test
-sort [{direction}{column}]
-```
-
-#### Arguments
-
-- One or multiple columns
-- Each column can be prefixed with:
-  - `+`, for ascending order, the default
-  - `-`, for descending order
-
-#### Examples
-
-```prql
-from employees
-sort age
-```
-
-```prql
-from employees
-sort (-age)
-```
-
-> Note that `sort -age` is not valid; `-age` needs to be surrounded by parentheses.
-
-```prql
-from employees
-sort [age, -tenure, +salary]
-```
-
-## Take
-
-> picks first n rows
-
-```prql_no_test
-take {n}
-```
-
-#### Examples
-
-```prql
-from employees
-take 10
-```
-
-## Join
-
-> adds columns from another table, matching rows based on a condition
-
-```prql_no_test
-join side:{inner|left|right|full} {table} {[conditions]}
-```
-
-#### Arguments
-
-- `side` decides which rows to include. Defaults to `inner`
-- table reference
-- list of conditions
-  - If all terms are column identifiers, this will compile to `USING(...)`. In this case, both of the tables must have specified column. The result will only contain one column instead one for each table.
-
-#### Examples
-
-```prql
-from employees
-join side:left positions [id==employee_id]
-```
-
-#### Examples
-
-```prql
-from employees
-join side:full positions [emp_no]
-```
-
-## Group
-
-A `group` transform maps a pipeline over a number of groups. The groups are determined by the
-columns passed to `group`'s first argument.
-
-The most conventional use of `group` is with `aggregate`:
-
-```prql
-from employees
-group [title, country] (
-  aggregate [
-    average salary,
-    ct = count
-  ]
-)
-```
-
-In concept, a transform in context of a `group` does the same transformation to the group as
-it would to the table — for example finding the employee who joined first:
-
-```prql
-from employees
-sort join_date
-take 1
-```
-
-To find the employee who joined first in each department, it's exactly the
-same pipeline, but within a `group` expression:
-
-> Not yet implemented, ref <https://github.com/prql/prql/issues/421>
-
-```prql_no_test
-from employees
-group role (
-  sort join_date  # taken from above
-  take 1
-)
-```
-
-## Aggregate
-
-> group rows by one or more columns
-
-```prql_no_test
-aggregate [{expression or assign operations}]
-```
-
-#### Examples
-
-```prql
-from employees
-aggregate [
-  average salary,
-  ct = count
-]
-```
+PRQL queries are a pipeline of transformations ("transforms"), where each transform takes
+the previous result and adjusts it in some way, before passing it onto to the
+next transform.
+
+Because PRQL focuses on modularity, we have far fewer transforms than SQL, each
+one fulfilling a specific purpose. That's often referred to as "orthogonality".
+
+These are the currently available transforms:
+<!-- Copied from `SUMMARY.md` -->
+| Transform                   | Purpose                                                             |
+| --------------------------- | ------------------------------------------------------------------- |
+| [Derive](./derive.md)       | Computes new columns                                                |
+| [Select](./select.md)       | Picks & computes columns                                            |
+| [Filter](./filter.md)       | Picks rows based on their values                                    |
+| [Sort](./sort.md)           | Orders rows based on the values of columns                          |
+| [Join](./join.md)           | Adds columns from another table, matching rows based on a condition |
+| [Take](./take.md)           | Picks rows based on their position                                  |
+| [Group](./group.md)         | Partitions rows into groups and applies a pipeline to each of them  |
+| [Aggregate](./aggregate.md) | Summarizes many rows into one row                                   |
diff --git a/reference/src/transforms/aggregate.md b/reference/src/transforms/aggregate.md
new file mode 100644
index 00000000..e79f1c4a
--- /dev/null
+++ b/reference/src/transforms/aggregate.md
@@ -0,0 +1,21 @@
+## Aggregate
+
+Summarizes many rows into one row.
+
+When applied:
+- without `group`, it produces one row from the whole table,
+- within a `group` pipeline, it produces one row from each group.
+
+```prql_no_test
+aggregate [{expression or assign operations}]
+```
+
+#### Examples
+
+```prql
+from employees
+aggregate [
+  average salary,
+  ct = count
+]
+```
diff --git a/reference/src/transforms/derive.md b/reference/src/transforms/derive.md
new file mode 100644
index 00000000..7744aa34
--- /dev/null
+++ b/reference/src/transforms/derive.md
@@ -0,0 +1,29 @@
+# Derive
+
+Computes one or more new columns.
+
+```prql_no_test
+derive [{new_name} = {expression}]
+```
+
+## Examples
+
+```prql
+from employees
+derive gross_salary = salary + payroll_tax
+```
+
+```prql
+from employees
+derive [
+  gross_salary = salary + payroll_tax,
+  gross_cost = gross_salary + benefits_cost
+]
+```
+
+It generally computes a column from existing columns, but can also take a
+literal, and doesn't require a `from`:
+
+```prql
+derive x = 5
+```
diff --git a/reference/src/transforms/filter.md b/reference/src/transforms/filter.md
new file mode 100644
index 00000000..fc597dba
--- /dev/null
+++ b/reference/src/transforms/filter.md
@@ -0,0 +1,19 @@
+# Filter
+
+Picks rows based on their values.
+
+```prql_no_test
+filter {boolean_expression}
+```
+
+## Examples
+
+```prql
+from employees
+filter age > 25
+```
+
+```prql
+from employees
+filter (age | in 25..40)
+```
diff --git a/reference/src/transforms/from.md b/reference/src/transforms/from.md
new file mode 100644
index 00000000..1597b1de
--- /dev/null
+++ b/reference/src/transforms/from.md
@@ -0,0 +1,21 @@
+# From
+
+Specifies a data source.
+
+```prql_no_test
+from {table_reference}
+```
+
+## Examples
+
+```prql
+from employees
+```
+
+
+To introduce an alias, use an assign expression:
+
+```prql
+from e = employees
+select e.first_name
+```
diff --git a/reference/src/transforms/group.md b/reference/src/transforms/group.md
new file mode 100644
index 00000000..bf6520d8
--- /dev/null
+++ b/reference/src/transforms/group.md
@@ -0,0 +1,43 @@
+# Group
+
+Partitions the rows into groups and applies a pipeline to each of the groups.
+
+```prql_no_test
+group [{key column}] {pipeline}
+```
+
+The partitioning of groups are determined by the `key column`s (first argument).
+
+The most conventional use of `group` is with `aggregate`:
+
+```prql
+from employees
+group [title, country] (
+  aggregate [
+    average salary,
+    ct = count
+  ]
+)
+```
+
+In concept, a transform in context of a `group` does the same transformation to the group as
+it would to the table — for example finding the employee who joined first:
+
+```prql
+from employees
+sort join_date
+take 1
+```
+
+To find the employee who joined first in each department, it's exactly the
+same pipeline, but within a `group` expression:
+
+> Not yet implemented, ref <https://github.com/prql/prql/issues/421>
+
+```prql_no_test
+from employees
+group role (
+  sort join_date  # taken from above
+  take 1
+)
+```
diff --git a/reference/src/transforms/join.md b/reference/src/transforms/join.md
new file mode 100644
index 00000000..3e19a7d5
--- /dev/null
+++ b/reference/src/transforms/join.md
@@ -0,0 +1,33 @@
+# Join
+
+Adds columns from another table, matching rows based on a condition.
+
+```prql_no_test
+join side:{inner|left|right|full} {table} {[conditions]}
+```
+
+## Arguments
+
+- `side` decides which rows to include. Defaults to `inner`
+- Table reference
+- List of conditions
+  - If all terms are column identifiers, this will compile to `USING(...)`. In
+    this case, both of the tables must have specified column. The result will
+    only contain one column for both tables.
+
+## Examples
+
+```prql
+from employees
+join side:left positions [id==employee_id]
+```
+
+```prql
+from employees
+join side:full positions [emp_no]
+```
+
+```prql
+from employees
+join side:left p=positions [id==employee_id]
+```
diff --git a/reference/src/transforms/select.md b/reference/src/transforms/select.md
new file mode 100644
index 00000000..d104bf7d
--- /dev/null
+++ b/reference/src/transforms/select.md
@@ -0,0 +1,32 @@
+# Select
+
+Picks and compute columns.
+
+```prql_no_test
+select [{assign_expression}]
+```
+
+## Examples
+
+```prql
+from employees
+select first_name
+```
+
+```prql
+from employees
+select [first_name, last_name]
+```
+
+```prql
+from employees
+select name = f"{first_name} {last_name}"
+```
+
+```prql
+from employees
+select [
+  name = f"{first_name} {last_name}",
+  age_eoy = dob - @2022-12-31,
+]
+```
diff --git a/reference/src/transforms/sort.md b/reference/src/transforms/sort.md
new file mode 100644
index 00000000..d17bf99e
--- /dev/null
+++ b/reference/src/transforms/sort.md
@@ -0,0 +1,34 @@
+# Sort
+
+Orders rows based on the values of one or more columns.
+
+```prql_no_test
+sort [{direction}{column}]
+```
+
+## Arguments
+
+- One or multiple columns
+- Each column can be prefixed with:
+  - `+`, for ascending order, the default
+  - `-`, for descending order
+
+## Examples
+
+```prql
+from employees
+sort age
+```
+
+```prql
+from employees
+sort (-age)
+```
+
+> Note that `sort -age` is not valid; `-age` needs to be surrounded by
+> parentheses like `(-age).
+
+```prql
+from employees
+sort [age, -tenure, +salary]
+```
diff --git a/reference/src/transforms/take.md b/reference/src/transforms/take.md
new file mode 100644
index 00000000..7c77aabb
--- /dev/null
+++ b/reference/src/transforms/take.md
@@ -0,0 +1,23 @@
+# Take
+
+Picks rows based on their position.
+
+```prql_no_test
+take {n}
+```
+
+## Examples
+
+```prql
+from employees
+take 10
+```
+
+## Todo
+
+We could support a range expression so we can get an offset:
+
+```prql_no_test
+from employees
+take 1..10
+```


Test patch:
diff --git a/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__materialize_2.snap b/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__materialize_2.snap
index d7d151a8..5b573253 100644
--- a/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__materialize_2.snap
+++ b/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__materialize_2.snap
@@ -9,22 +9,22 @@ expression: mat
       declared_at: 35
 - Transform:
     Filter:
-      - Expr:
-          - Ident: country
-          - Operator: "=="
-          - String: USA
+      Expr:
+        - Ident: country
+        - Operator: "=="
+        - String: USA
 - Transform:
     Filter:
-      - Expr:
-          - Expr:
-              - Expr:
-                  - Ident: salary
-                  - Operator: +
-                  - Ident: payroll_tax
-              - Operator: +
-              - Ident: benefits_cost
-          - Operator: ">"
-          - Raw: "0"
+      Expr:
+        - Expr:
+            - Expr:
+                - Ident: salary
+                - Operator: +
+                - Ident: payroll_tax
+            - Operator: +
+            - Ident: benefits_cost
+        - Operator: ">"
+        - Raw: "0"
 - Transform:
     Group:
       by:
@@ -92,20 +92,20 @@ expression: mat
                     - Ident: country
 - Transform:
     Filter:
-      - Expr:
-          - SString:
-              - String: SUM(
-              - Expr:
-                  Expr:
-                    - Expr:
-                        - Ident: salary
-                        - Operator: +
-                        - Ident: payroll_tax
-                    - Operator: +
-                    - Ident: benefits_cost
-              - String: )
-          - Operator: ">"
-          - Raw: "200"
+      Expr:
+        - SString:
+            - String: SUM(
+            - Expr:
+                Expr:
+                  - Expr:
+                      - Ident: salary
+                      - Operator: +
+                      - Ident: payroll_tax
+                  - Operator: +
+                  - Ident: benefits_cost
+            - String: )
+        - Operator: ">"
+        - Raw: "200"
 - Transform:
     Take: 20
 
diff --git a/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__replace_variables_2.snap b/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__replace_variables_2.snap
index 2cabb62b..7ed1a676 100644
--- a/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__replace_variables_2.snap
+++ b/prql-compiler/src/sql/snapshots/prql_compiler__sql__materializer__test__replace_variables_2.snap
@@ -9,22 +9,22 @@ expression: "&mat"
       declared_at: 35
 - Transform:
     Filter:
-      - Expr:
-          - Ident: country
-          - Operator: "=="
-          - String: USA
+      Expr:
+        - Ident: country
+        - Operator: "=="
+        - String: USA
 - Transform:
     Filter:
-      - Expr:
-          - Expr:
-              - Expr:
-                  - Ident: salary
-                  - Operator: +
-                  - Ident: payroll_tax
-              - Operator: +
-              - Ident: benefits_cost
-          - Operator: ">"
-          - Raw: "0"
+      Expr:
+        - Expr:
+            - Expr:
+                - Ident: salary
+                - Operator: +
+                - Ident: payroll_tax
+            - Operator: +
+            - Ident: benefits_cost
+        - Operator: ">"
+        - Raw: "0"
 - Transform:
     Group:
       by:
@@ -92,20 +92,20 @@ expression: "&mat"
                     - Ident: country
 - Transform:
     Filter:
-      - Expr:
-          - SString:
-              - String: SUM(
-              - Expr:
-                  Expr:
-                    - Expr:
-                        - Ident: salary
-                        - Operator: +
-                        - Ident: payroll_tax
-                    - Operator: +
-                    - Ident: benefits_cost
-              - String: )
-          - Operator: ">"
-          - Raw: "200"
+      Expr:
+        - SString:
+            - String: SUM(
+            - Expr:
+                Expr:
+                  - Expr:
+                      - Ident: salary
+                      - Operator: +
+                      - Ident: payroll_tax
+                  - Operator: +
+                  - Ident: benefits_cost
+            - String: )
+        - Operator: ">"
+        - Raw: "200"
 - Transform:
     Take: 20
 
diff --git a/reference/tests/examples/examples/cte-0.prql b/reference/tests/prql/examples/cte-0.prql
similarity index 100%
rename from reference/tests/examples/examples/cte-0.prql
rename to reference/tests/prql/examples/cte-0.prql
diff --git a/reference/tests/examples/examples/employees-0-0.prql b/reference/tests/prql/examples/employees-0.prql
similarity index 100%
rename from reference/tests/examples/examples/employees-0-0.prql
rename to reference/tests/prql/examples/employees-0.prql
diff --git a/reference/tests/examples/examples/employees-1-0.prql b/reference/tests/prql/examples/employees-1.prql
similarity index 100%
rename from reference/tests/examples/examples/employees-1-0.prql
rename to reference/tests/prql/examples/employees-1.prql
diff --git a/reference/tests/examples/examples/employees-2-0.prql b/reference/tests/prql/examples/employees-2.prql
similarity index 100%
rename from reference/tests/examples/examples/employees-2-0.prql
rename to reference/tests/prql/examples/employees-2.prql
diff --git a/reference/tests/examples/examples/employees-3-0.prql b/reference/tests/prql/examples/employees-3.prql
similarity index 100%
rename from reference/tests/examples/examples/employees-3-0.prql
rename to reference/tests/prql/examples/employees-3.prql
diff --git a/reference/tests/examples/examples/list-equivalence-0.prql b/reference/tests/prql/examples/list-equivalence-0.prql
similarity index 100%
rename from reference/tests/examples/examples/list-equivalence-0.prql
rename to reference/tests/prql/examples/list-equivalence-0.prql
diff --git a/reference/tests/examples/examples/list-equivalence-1.prql b/reference/tests/prql/examples/list-equivalence-1.prql
similarity index 100%
rename from reference/tests/examples/examples/list-equivalence-1.prql
rename to reference/tests/prql/examples/list-equivalence-1.prql
diff --git a/reference/tests/examples/examples/list-equivalence-2.prql b/reference/tests/prql/examples/list-equivalence-2.prql
similarity index 100%
rename from reference/tests/examples/examples/list-equivalence-2.prql
rename to reference/tests/prql/examples/list-equivalence-2.prql
diff --git a/reference/tests/examples/examples/list-equivalence-3.prql b/reference/tests/prql/examples/list-equivalence-3.prql
similarity index 100%
rename from reference/tests/examples/examples/list-equivalence-3.prql
rename to reference/tests/prql/examples/list-equivalence-3.prql
diff --git a/reference/tests/prql/examples/misc-0.prql b/reference/tests/prql/examples/misc-0.prql
new file mode 100644
index 00000000..16eac8f7
--- /dev/null
+++ b/reference/tests/prql/examples/misc-0.prql
@@ -0,0 +1,15 @@
+# TODO: this table should have a column `part` with values 1..5,
+# but such data declaration is not yet supported, see #286
+table parts = (
+    from seq_1_to_5
+)
+
+from pl=prospect_lists_prospects
+filter prospect_list_id == 'cc675eee-8bd1-237f-be5e-622ba511d65e'
+join a=accounts [a.id == pl.related_id]
+join er=email_addr_bean_rel [er.bean_id == a.id and er.primary_address == '1']
+join ea=email_addresses [ea.id == er.email_address_id]
+select ea.email_address
+derive prefix = s"regexp_replace(SUBSTRING_INDEX({email_address}, '@', 1), '[.0-9-_:]+', '.')"
+select stub = s"SUBSTRING_INDEX(SUBSTRING_INDEX({prefix}, '.', part), '.', -1)"
+select [email_address, stub]
diff --git a/reference/tests/prql/examples/misc-1.prql b/reference/tests/prql/examples/misc-1.prql
new file mode 100644
index 00000000..c258503e
--- /dev/null
+++ b/reference/tests/prql/examples/misc-1.prql
@@ -0,0 +1,8 @@
+from club_ratings
+# TODO: this should produce `rating IS NOT NULL`
+filter rating != null
+# TODO: this is real ugly. `average rating` should not require parenthesis
+# TODO: why cannot we put comments in group's pipeline?
+group year (
+    derive [rating_norm = rating - (average rating) / (stddev rating)]
+)
diff --git a/reference/tests/examples/examples/sql-parameters-0.prql b/reference/tests/prql/examples/sql-parameters-0.prql
similarity index 100%
rename from reference/tests/examples/examples/sql-parameters-0.prql
rename to reference/tests/prql/examples/sql-parameters-0.prql
diff --git a/reference/tests/examples/examples/variables-0.prql b/reference/tests/prql/examples/variables-0.prql
similarity index 100%
rename from reference/tests/examples/examples/variables-0.prql
rename to reference/tests/prql/examples/variables-0.prql
diff --git a/reference/tests/examples/examples/variables-1.prql b/reference/tests/prql/examples/variables-1.prql
similarity index 100%
rename from reference/tests/examples/examples/variables-1.prql
rename to reference/tests/prql/examples/variables-1.prql
diff --git a/reference/tests/examples/functions-0.prql b/reference/tests/prql/functions-0.prql
similarity index 100%
rename from reference/tests/examples/functions-0.prql
rename to reference/tests/prql/functions-0.prql
diff --git a/reference/tests/examples/functions-1.prql b/reference/tests/prql/functions-1.prql
similarity index 100%
rename from reference/tests/examples/functions-1.prql
rename to reference/tests/prql/functions-1.prql
diff --git a/reference/tests/examples/functions-2.prql b/reference/tests/prql/functions-2.prql
similarity index 100%
rename from reference/tests/examples/functions-2.prql
rename to reference/tests/prql/functions-2.prql
diff --git a/reference/tests/examples/functions-3.prql b/reference/tests/prql/functions-3.prql
similarity index 100%
rename from reference/tests/examples/functions-3.prql
rename to reference/tests/prql/functions-3.prql
diff --git a/reference/tests/examples/functions-4.prql b/reference/tests/prql/functions-4.prql
similarity index 100%
rename from reference/tests/examples/functions-4.prql
rename to reference/tests/prql/functions-4.prql
diff --git a/reference/tests/examples/introduction-0.prql b/reference/tests/prql/introduction-0.prql
similarity index 100%
rename from reference/tests/examples/introduction-0.prql
rename to reference/tests/prql/introduction-0.prql
diff --git a/reference/tests/examples/language-features/dates_and_times-0.prql b/reference/tests/prql/language-features/dates_and_times-0.prql
similarity index 100%
rename from reference/tests/examples/language-features/dates_and_times-0.prql
rename to reference/tests/prql/language-features/dates_and_times-0.prql
diff --git a/reference/tests/examples/language-features/dates_and_times-1.prql b/reference/tests/prql/language-features/dates_and_times-1.prql
similarity index 100%
rename from reference/tests/examples/language-features/dates_and_times-1.prql
rename to reference/tests/prql/language-features/dates_and_times-1.prql
diff --git a/reference/tests/examples/language-features/dates_and_times-2.prql b/reference/tests/prql/language-features/dates_and_times-2.prql
similarity index 100%
rename from reference/tests/examples/language-features/dates_and_times-2.prql
rename to reference/tests/prql/language-features/dates_and_times-2.prql
diff --git a/reference/tests/examples/language-features/dates_and_times-3.prql b/reference/tests/prql/language-features/dates_and_times-3.prql
similarity index 100%
rename from reference/tests/examples/language-features/dates_and_times-3.prql
rename to reference/tests/prql/language-features/dates_and_times-3.prql
diff --git a/reference/tests/examples/language-features/f-strings-0.prql b/reference/tests/prql/language-features/f-strings-0.prql
similarity index 100%
rename from reference/tests/examples/language-features/f-strings-0.prql
rename to reference/tests/prql/language-features/f-strings-0.prql
diff --git a/reference/tests/examples/language-features/f-strings-1.prql b/reference/tests/prql/language-features/f-strings-1.prql
similarity index 100%
rename from reference/tests/examples/language-features/f-strings-1.prql
rename to reference/tests/prql/language-features/f-strings-1.prql
diff --git a/reference/tests/examples/language-features/ranges-0.prql b/reference/tests/prql/language-features/ranges-0.prql
similarity index 100%
rename from reference/tests/examples/language-features/ranges-0.prql
rename to reference/tests/prql/language-features/ranges-0.prql
diff --git a/reference/tests/examples/language-features/s-strings-0.prql b/reference/tests/prql/language-features/s-strings-0.prql
similarity index 100%
rename from reference/tests/examples/language-features/s-strings-0.prql
rename to reference/tests/prql/language-features/s-strings-0.prql
diff --git a/reference/tests/examples/language-features/s-strings-1.prql b/reference/tests/prql/language-features/s-strings-1.prql
similarity index 100%
rename from reference/tests/examples/language-features/s-strings-1.prql
rename to reference/tests/prql/language-features/s-strings-1.prql
diff --git a/reference/tests/examples/language-features/strings-0.prql b/reference/tests/prql/language-features/strings-0.prql
similarity index 100%
rename from reference/tests/examples/language-features/strings-0.prql
rename to reference/tests/prql/language-features/strings-0.prql
diff --git a/reference/tests/examples/language-features/strings-1.prql b/reference/tests/prql/language-features/strings-1.prql
similarity index 100%
rename from reference/tests/examples/language-features/strings-1.prql
rename to reference/tests/prql/language-features/strings-1.prql
diff --git a/reference/tests/examples/language-features/strings-2.prql b/reference/tests/prql/language-features/strings-2.prql
similarity index 100%
rename from reference/tests/examples/language-features/strings-2.prql
rename to reference/tests/prql/language-features/strings-2.prql
diff --git a/reference/tests/examples/language-features/strings-3.prql b/reference/tests/prql/language-features/strings-3.prql
similarity index 100%
rename from reference/tests/examples/language-features/strings-3.prql
rename to reference/tests/prql/language-features/strings-3.prql
diff --git a/reference/tests/examples/queries/pipelines-0.prql b/reference/tests/prql/queries/pipelines-0.prql
similarity index 100%
rename from reference/tests/examples/queries/pipelines-0.prql
rename to reference/tests/prql/queries/pipelines-0.prql
diff --git a/reference/tests/examples/queries/pipelines-1.prql b/reference/tests/prql/queries/pipelines-1.prql
similarity index 100%
rename from reference/tests/examples/queries/pipelines-1.prql
rename to reference/tests/prql/queries/pipelines-1.prql
diff --git a/reference/tests/examples/queries/pipelines-2.prql b/reference/tests/prql/queries/pipelines-2.prql
similarity index 100%
rename from reference/tests/examples/queries/pipelines-2.prql
rename to reference/tests/prql/queries/pipelines-2.prql
diff --git a/reference/tests/prql/queries/pipelines-3.prql b/reference/tests/prql/queries/pipelines-3.prql
new file mode 100644
index 00000000..5c56385c
--- /dev/null
+++ b/reference/tests/prql/queries/pipelines-3.prql
@@ -0,0 +1,6 @@
+from e = employees
+derive gross_salary = (salary + payroll_tax)
+sort gross_salary
+take 10
+join d = department [dept_no]
+select [e.name, gross_salary, d.name]
diff --git a/reference/tests/examples/syntax-0.prql b/reference/tests/prql/syntax-0.prql
similarity index 100%
rename from reference/tests/examples/syntax-0.prql
rename to reference/tests/prql/syntax-0.prql
diff --git a/reference/tests/examples/syntax-1.prql b/reference/tests/prql/syntax-1.prql
similarity index 100%
rename from reference/tests/examples/syntax-1.prql
rename to reference/tests/prql/syntax-1.prql
diff --git a/reference/tests/examples/transforms-12.prql b/reference/tests/prql/transforms/aggregate-0.prql
similarity index 100%
rename from reference/tests/examples/transforms-12.prql
rename to reference/tests/prql/transforms/aggregate-0.prql
diff --git a/reference/tests/examples/transforms-2.prql b/reference/tests/prql/transforms/derive-0.prql
similarity index 100%
rename from reference/tests/examples/transforms-2.prql
rename to reference/tests/prql/transforms/derive-0.prql
diff --git a/reference/tests/examples/transforms-3.prql b/reference/tests/prql/transforms/derive-1.prql
similarity index 100%
rename from reference/tests/examples/transforms-3.prql
rename to reference/tests/prql/transforms/derive-1.prql
diff --git a/reference/tests/prql/transforms/derive-2.prql b/reference/tests/prql/transforms/derive-2.prql
new file mode 100644
index 00000000..ef0d109c
--- /dev/null
+++ b/reference/tests/prql/transforms/derive-2.prql
@@ -0,0 +1,1 @@
+derive x = 5
diff --git a/reference/tests/prql/transforms/filter-0.prql b/reference/tests/prql/transforms/filter-0.prql
new file mode 100644
index 00000000..6ecce44d
--- /dev/null
+++ b/reference/tests/prql/transforms/filter-0.prql
@@ -0,0 +1,2 @@
+from employees
+filter age > 25
diff --git a/reference/tests/prql/transforms/filter-1.prql b/reference/tests/prql/transforms/filter-1.prql
new file mode 100644
index 00000000..fe81ad79
--- /dev/null
+++ b/reference/tests/prql/transforms/filter-1.prql
@@ -0,0 +1,2 @@
+from employees
+filter (age | in 25..40)
diff --git a/reference/tests/examples/transforms-0.prql b/reference/tests/prql/transforms/from-0.prql
similarity index 100%
rename from reference/tests/examples/transforms-0.prql
rename to reference/tests/prql/transforms/from-0.prql
diff --git a/reference/tests/prql/transforms/from-1.prql b/reference/tests/prql/transforms/from-1.prql
new file mode 100644
index 00000000..f9ec0ba6
--- /dev/null
+++ b/reference/tests/prql/transforms/from-1.prql
@@ -0,0 +1,2 @@
+from e = employees
+select e.first_name
diff --git a/reference/tests/examples/transforms-10.prql b/reference/tests/prql/transforms/group-0.prql
similarity index 100%
rename from reference/tests/examples/transforms-10.prql
rename to reference/tests/prql/transforms/group-0.prql
diff --git a/reference/tests/examples/transforms-11.prql b/reference/tests/prql/transforms/group-1.prql
similarity index 100%
rename from reference/tests/examples/transforms-11.prql
rename to reference/tests/prql/transforms/group-1.prql
diff --git a/reference/tests/examples/transforms-8.prql b/reference/tests/prql/transforms/join-0.prql
similarity index 100%
rename from reference/tests/examples/transforms-8.prql
rename to reference/tests/prql/transforms/join-0.prql
diff --git a/reference/tests/examples/transforms-9.prql b/reference/tests/prql/transforms/join-1.prql
similarity index 100%
rename from reference/tests/examples/transforms-9.prql
rename to reference/tests/prql/transforms/join-1.prql
diff --git a/reference/tests/prql/transforms/join-2.prql b/reference/tests/prql/transforms/join-2.prql
new file mode 100644
index 00000000..2e80ce76
--- /dev/null
+++ b/reference/tests/prql/transforms/join-2.prql
@@ -0,0 +1,2 @@
+from employees
+join side:left p=positions [id==employee_id]
diff --git a/reference/tests/prql/transforms/select-0.prql b/reference/tests/prql/transforms/select-0.prql
new file mode 100644
index 00000000..ec44dd33
--- /dev/null
+++ b/reference/tests/prql/transforms/select-0.prql
@@ -0,0 +1,2 @@
+from employees
+select first_name
diff --git a/reference/tests/examples/transforms-1.prql b/reference/tests/prql/transforms/select-1.prql
similarity index 100%
rename from reference/tests/examples/transforms-1.prql
rename to reference/tests/prql/transforms/select-1.prql
diff --git a/reference/tests/prql/transforms/select-2.prql b/reference/tests/prql/transforms/select-2.prql
new file mode 100644
index 00000000..69ff35c8
--- /dev/null
+++ b/reference/tests/prql/transforms/select-2.prql
@@ -0,0 +1,2 @@
+from employees
+select name = f"{first_name} {last_name}"
diff --git a/reference/tests/prql/transforms/select-3.prql b/reference/tests/prql/transforms/select-3.prql
new file mode 100644
index 00000000..346904e5
--- /dev/null
+++ b/reference/tests/prql/transforms/select-3.prql
@@ -0,0 +1,5 @@
+from employees
+select [
+  name = f"{first_name} {last_name}",
+  age_eoy = dob - @2022-12-31,
+]
diff --git a/reference/tests/examples/transforms-4.prql b/reference/tests/prql/transforms/sort-0.prql
similarity index 100%
rename from reference/tests/examples/transforms-4.prql
rename to reference/tests/prql/transforms/sort-0.prql
diff --git a/reference/tests/examples/transforms-5.prql b/reference/tests/prql/transforms/sort-1.prql
similarity index 100%
rename from reference/tests/examples/transforms-5.prql
rename to reference/tests/prql/transforms/sort-1.prql
diff --git a/reference/tests/examples/transforms-6.prql b/reference/tests/prql/transforms/sort-2.prql
similarity index 100%
rename from reference/tests/examples/transforms-6.prql
rename to reference/tests/prql/transforms/sort-2.prql
diff --git a/reference/tests/examples/transforms-7.prql b/reference/tests/prql/transforms/take-0.prql
similarity index 100%
rename from reference/tests/examples/transforms-7.prql
rename to reference/tests/prql/transforms/take-0.prql
diff --git a/reference/tests/snapshot.rs b/reference/tests/snapshot.rs
index 333036fa..061b9e81 100644
--- a/reference/tests/snapshot.rs
+++ b/reference/tests/snapshot.rs
@@ -36,14 +36,14 @@ fn run_examples() -> Result<()> {
     // Note that on windows, we only get the next _line_, and so we exclude the
     // writing on Windows. ref https://github.com/prql/prql/issues/356
     #[cfg(not(target_family = "windows"))]
-    write_reference_examples()?;
-    run_reference_examples()?;
+    write_reference_prql()?;
+    run_reference_prql()?;
 
     Ok(())
 }
 
 /// Extract reference examples from the PRQL docs and write them to the
-/// `tests/examples` path, one in each file.
+/// `tests/prql` path, one in each file.
 // We could alternatively have used something like
 // https://github.com/earldouglas/codedown, but it's not much code, and it
 // requires no dependencies.
@@ -51,15 +51,15 @@ fn run_examples() -> Result<()> {
 // We allow dead_code because of the window issue described above. (Can we allow
 // it only for windows?)
 #[allow(dead_code)]
-fn write_reference_examples() -> Result<()> {
-    // Remove old examples, since we're going to rewrite them, and we don't want
+fn write_reference_prql() -> Result<()> {
+    // Remove old .prql files, since we're going to rewrite them, and we don't want
     // old files which wouldn't be rewritten from hanging around.
     // We use `trash`, since we don't want to be removing files with test code
     // in case there's a bug.
 
-    let examples_path = Path::new("tests/examples");
+    let examples_path = Path::new("tests/prql");
     if examples_path.exists() {
-        trash::delete(Path::new("tests/examples")).unwrap_or_else(|e| {
+        trash::delete(Path::new("tests/prql")).unwrap_or_else(|e| {
             warn!("Failed to delete old examples: {}", e);
         });
     }
@@ -73,7 +73,7 @@ fn write_reference_examples() -> Result<()> {
         .try_for_each(|dir_entry| {
             let text = fs::read_to_string(dir_entry.path())?;
             let mut parser = Parser::new(&text);
-            let mut examples = vec![];
+            let mut prql_blocks = vec![];
             while let Some(event) = parser.next() {
                 match event.clone() {
                     // At the start of a PRQL code block, push the _next_ item.
@@ -84,7 +84,7 @@ fn write_reference_examples() -> Result<()> {
                         if lang == "prql".into() =>
                     {
                         if let Some(Event::Text(text)) = parser.next() {
-                            examples.push(text);
+                            prql_blocks.push(text);
                         } else {
                             bail!("Expected text after PRQL code block");
                         }
@@ -94,20 +94,23 @@ fn write_reference_examples() -> Result<()> {
             }
 
             // Write each one to a new file.
-            examples.iter().enumerate().try_for_each(|(i, example)| {
-                let file_relative = &dir_entry
-                    .path()
-                    .strip_prefix("./src/")?
-                    .to_str()
-                    .unwrap()
-                    .trim_end_matches(".md");
-                let prql_path = format!("tests/examples/{file_relative}-{i}.prql");
+            prql_blocks
+                .iter()
+                .enumerate()
+                .try_for_each(|(i, example)| {
+                    let file_relative = &dir_entry
+                        .path()
+                        .strip_prefix("./src/")?
+                        .to_str()
+                        .unwrap()
+                        .trim_end_matches(".md");
+                    let prql_path = format!("tests/prql/{file_relative}-{i}.prql");
 
-                fs::create_dir_all(Path::new(&prql_path).parent().unwrap())?;
-                fs::write(prql_path, example.to_string())?;
+                    fs::create_dir_all(Path::new(&prql_path).parent().unwrap())?;
+                    fs::write(prql_path, example.to_string())?;
 
-                Ok::<(), anyhow::Error>(())
-            })?;
+                    Ok::<(), anyhow::Error>(())
+                })?;
             Ok(())
         })?;
 
@@ -115,8 +118,8 @@ fn write_reference_examples() -> Result<()> {
 }
 
 /// Snapshot the output of each example.
-fn run_reference_examples() -> Result<()> {
-    glob!("examples/**/*.prql", |path| {
+fn run_reference_prql() -> Result<()> {
+    glob!("prql/**/*.prql", |path| {
         let prql = fs::read_to_string(path).unwrap();
 
         if prql.contains("skip_test") {
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-3.prql.snap b/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-3.prql.snap
deleted file mode 100644
index eece9deb..00000000
--- a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-3.prql.snap
+++ /dev/null
@@ -1,10 +0,0 @@
----
-source: reference/tests/snapshot.rs
-expression: sql
-input_file: reference/tests/examples/language-features/dates_and_times-3.prql
----
-SELECT
-  projects.*,
-  start + INTERVAL '10' DAY AS first_check_in
-FROM
-  projects
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-12.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@aggregate-0.prql.snap
similarity index 65%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-12.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@aggregate-0.prql.snap
index b20d3b8a..37af4ab9 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-12.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@aggregate-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-12.prql
+input_file: reference/tests/prql/transforms/aggregate-0.prql
 ---
 SELECT
   AVG(salary),
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@cte-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@cte-0.prql.snap
similarity index 88%
rename from reference/tests/snapshots/snapshot__run_reference_examples@cte-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@cte-0.prql.snap
index 51a4a098..220a9c4b 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@cte-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@cte-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/cte-0.prql
+input_file: reference/tests/prql/examples/cte-0.prql
 ---
 WITH newest_employees AS (
   SELECT
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-0.prql.snap
similarity index 64%
rename from reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-0.prql.snap
index 5fbb282c..aee44b56 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/dates_and_times-0.prql
+input_file: reference/tests/prql/language-features/dates_and_times-0.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-1.prql.snap
similarity index 65%
rename from reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-1.prql.snap
index f1b48b07..7585e880 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/dates_and_times-1.prql
+input_file: reference/tests/prql/language-features/dates_and_times-1.prql
 ---
 SELECT
   orders.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-2.prql.snap
similarity index 61%
rename from reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-2.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-2.prql.snap
index 7fe9c765..fa4eac22 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-2.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-2.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/dates_and_times-2.prql
+input_file: reference/tests/prql/language-features/dates_and_times-2.prql
 ---
 SELECT
   TIMESTAMP '2020-01-01T13:19:55-0800' AS first_prql_commit
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-4.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-3.prql.snap
similarity index 64%
rename from reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-4.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-3.prql.snap
index 0219f3fd..744e82d9 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@dates_and_times-4.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@dates_and_times-3.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/dates_and_times-4.prql
+input_file: reference/tests/prql/language-features/dates_and_times-3.prql
 ---
 SELECT
   projects.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@derive-0.prql.snap
similarity index 70%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-2.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@derive-0.prql.snap
index a15d9c41..216e8c49 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-2.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@derive-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-2.prql
+input_file: reference/tests/prql/transforms/derive-0.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-3.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@derive-1.prql.snap
similarity index 76%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-3.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@derive-1.prql.snap
index 4102297c..2cc524e9 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-3.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@derive-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-3.prql
+input_file: reference/tests/prql/transforms/derive-1.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@derive-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@derive-2.prql.snap
new file mode 100644
index 00000000..4ad46221
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@derive-2.prql.snap
@@ -0,0 +1,7 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/derive-2.prql
+---
+SELECT
+  5 AS x
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@employees-0-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@employees-0.prql.snap
similarity index 89%
rename from reference/tests/snapshots/snapshot__run_reference_examples@employees-0-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@employees-0.prql.snap
index bd54ab15..7d7ef508 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@employees-0-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@employees-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/employees-0-0.prql
+input_file: reference/tests/prql/examples/employees-0.prql
 ---
 WITH table_0 AS (
   SELECT
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@employees-1-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@employees-1.prql.snap
similarity index 90%
rename from reference/tests/snapshots/snapshot__run_reference_examples@employees-1-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@employees-1.prql.snap
index cce958c8..dbf9ced5 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@employees-1-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@employees-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/employees-1-0.prql
+input_file: reference/tests/prql/examples/employees-1.prql
 ---
 WITH table_0 AS (
   SELECT
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@employees-2-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@employees-2.prql.snap
similarity index 92%
rename from reference/tests/snapshots/snapshot__run_reference_examples@employees-2-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@employees-2.prql.snap
index 65734c24..f9b2e30c 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@employees-2-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@employees-2.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/employees-2-0.prql
+input_file: reference/tests/prql/examples/employees-2.prql
 ---
 WITH table_0 AS (
   SELECT
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@employees-3-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@employees-3.prql.snap
similarity index 88%
rename from reference/tests/snapshots/snapshot__run_reference_examples@employees-3-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@employees-3.prql.snap
index 351351d1..ffca4351 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@employees-3-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@employees-3.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/employees-3-0.prql
+input_file: reference/tests/prql/examples/employees-3.prql
 ---
 WITH table_0 AS (
   SELECT
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@f-strings-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@f-strings-0.prql.snap
similarity index 61%
rename from reference/tests/snapshots/snapshot__run_reference_examples@f-strings-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@f-strings-0.prql.snap
index 72d574bf..d6a0bf41 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@f-strings-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@f-strings-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/f-strings-0.prql
+input_file: reference/tests/prql/language-features/f-strings-0.prql
 ---
 SELECT
   CONCAT(first, ' ', last) AS full_name
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@f-strings-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@f-strings-1.prql.snap
similarity index 71%
rename from reference/tests/snapshots/snapshot__run_reference_examples@f-strings-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@f-strings-1.prql.snap
index 17aaba61..351410d3 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@f-strings-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@f-strings-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/f-strings-1.prql
+input_file: reference/tests/prql/language-features/f-strings-1.prql
 ---
 SELECT
   CONCAT(
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@filter-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@filter-0.prql.snap
new file mode 100644
index 00000000..09dee802
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@filter-0.prql.snap
@@ -0,0 +1,11 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/filter-0.prql
+---
+SELECT
+  employees.*
+FROM
+  employees
+WHERE
+  age > 25
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@filter-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@filter-1.prql.snap
new file mode 100644
index 00000000..2678b0ba
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@filter-1.prql.snap
@@ -0,0 +1,12 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/filter-1.prql
+---
+SELECT
+  employees.*
+FROM
+  employees
+WHERE
+  age BETWEEN 25
+  AND 40
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@from-0.prql.snap
similarity index 63%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@from-0.prql.snap
index 9294a269..27688dfa 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@from-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-0.prql
+input_file: reference/tests/prql/transforms/from-0.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@from-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@from-1.prql.snap
new file mode 100644
index 00000000..45832934
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@from-1.prql.snap
@@ -0,0 +1,9 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/from-1.prql
+---
+SELECT
+  first_name
+FROM
+  employees AS e
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@functions-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@functions-0.prql.snap
similarity index 69%
rename from reference/tests/snapshots/snapshot__run_reference_examples@functions-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@functions-0.prql.snap
index 5aeb85db..d9ce9ecf 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@functions-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@functions-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/functions-0.prql
+input_file: reference/tests/prql/functions-0.prql
 ---
 SELECT
   cities.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@functions-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@functions-1.prql.snap
similarity index 78%
rename from reference/tests/snapshots/snapshot__run_reference_examples@functions-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@functions-1.prql.snap
index 2c29d32c..afbef2df 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@functions-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@functions-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/functions-1.prql
+input_file: reference/tests/prql/functions-1.prql
 ---
 SELECT
   students.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@functions-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@functions-2.prql.snap
similarity index 78%
rename from reference/tests/snapshots/snapshot__run_reference_examples@functions-2.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@functions-2.prql.snap
index a9fad61f..868df62c 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@functions-2.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@functions-2.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/functions-2.prql
+input_file: reference/tests/prql/functions-2.prql
 ---
 SELECT
   students.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@functions-3.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@functions-3.prql.snap
similarity index 69%
rename from reference/tests/snapshots/snapshot__run_reference_examples@functions-3.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@functions-3.prql.snap
index a7bcd85f..ca4f3108 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@functions-3.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@functions-3.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/functions-3.prql
+input_file: reference/tests/prql/functions-3.prql
 ---
 SELECT
   cities.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@functions-4.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@functions-4.prql.snap
similarity index 73%
rename from reference/tests/snapshots/snapshot__run_reference_examples@functions-4.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@functions-4.prql.snap
index 7cd32058..f652301b 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@functions-4.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@functions-4.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/functions-4.prql
+input_file: reference/tests/prql/functions-4.prql
 ---
 SELECT
   kettles.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-10.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@group-0.prql.snap
similarity index 74%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-10.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@group-0.prql.snap
index 0f64eb4e..916c8f6c 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-10.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@group-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-10.prql
+input_file: reference/tests/prql/transforms/group-0.prql
 ---
 SELECT
   title,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-11.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@group-1.prql.snap
similarity index 69%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-11.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@group-1.prql.snap
index 4c402627..01f2edb8 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-11.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@group-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-11.prql
+input_file: reference/tests/prql/transforms/group-1.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@introduction-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@introduction-0.prql.snap
similarity index 92%
rename from reference/tests/snapshots/snapshot__run_reference_examples@introduction-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@introduction-0.prql.snap
index 090e006f..c0181ede 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@introduction-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@introduction-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/introduction-0.prql
+input_file: reference/tests/prql/introduction-0.prql
 ---
 WITH table_0 AS (
   SELECT
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-8.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@join-0.prql.snap
similarity index 73%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-8.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@join-0.prql.snap
index d954b346..9cefe006 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-8.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@join-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-8.prql
+input_file: reference/tests/prql/transforms/join-0.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-9.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@join-1.prql.snap
similarity index 73%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-9.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@join-1.prql.snap
index 255ff6f0..da14bb97 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-9.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@join-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-9.prql
+input_file: reference/tests/prql/transforms/join-1.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@join-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@join-2.prql.snap
new file mode 100644
index 00000000..fe4679d3
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@join-2.prql.snap
@@ -0,0 +1,11 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/join-2.prql
+---
+SELECT
+  employees.*,
+  p.*
+FROM
+  employees
+  LEFT JOIN positions AS p ON id = employee_id
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-0.prql.snap
similarity index 57%
rename from reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-0.prql.snap
index 2833b9af..6e112eff 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/list-equivalence-0.prql
+input_file: reference/tests/prql/examples/list-equivalence-0.prql
 ---
 SELECT
   salary
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-1.prql.snap
similarity index 57%
rename from reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-1.prql.snap
index 85ab882b..92de1975 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/list-equivalence-1.prql
+input_file: reference/tests/prql/examples/list-equivalence-1.prql
 ---
 SELECT
   salary
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-3.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-2.prql.snap
similarity index 73%
rename from reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-3.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-2.prql.snap
index c57bddbd..d4007729 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-3.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-2.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/list-equivalence-3.prql
+input_file: reference/tests/prql/examples/list-equivalence-2.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-3.prql.snap
similarity index 73%
rename from reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-2.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-3.prql.snap
index 266d4531..11c57b4e 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@list-equivalence-2.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@list-equivalence-3.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/list-equivalence-2.prql
+input_file: reference/tests/prql/examples/list-equivalence-3.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@misc-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@misc-0.prql.snap
new file mode 100644
index 00000000..edcd0734
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@misc-0.prql.snap
@@ -0,0 +1,40 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/examples/misc-0.prql
+---
+WITH parts AS (
+  SELECT
+    seq_1_to_5.*
+  FROM
+    seq_1_to_5
+),
+table_0 AS (
+  SELECT
+    pl.*
+  FROM
+    prospect_lists_prospects AS pl
+  WHERE
+    prospect_list_id = 'cc675eee-8bd1-237f-be5e-622ba511d65e'
+)
+SELECT
+  ea.email_address,
+  SUBSTRING_INDEX(
+    SUBSTRING_INDEX(
+      regexp_replace(
+        SUBSTRING_INDEX(ea.email_address, '@', 1),
+        '[.0-9-_:]+',
+        '.'
+      ),
+      '.',
+      part
+    ),
+    '.',
+    -1
+  ) AS stub
+FROM
+  table_0
+  JOIN accounts AS a ON a.id = table_0.related_id
+  JOIN email_addr_bean_rel AS er ON er.bean_id = a.id
+  AND er.primary_address = '1'
+  JOIN email_addresses AS ea ON ea.id = er.email_address_id
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@misc-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@misc-1.prql.snap
new file mode 100644
index 00000000..7775a90f
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@misc-1.prql.snap
@@ -0,0 +1,12 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/examples/misc-1.prql
+---
+SELECT
+  club_ratings.*,
+  rating - AVG(rating) / STDDEV(rating) OVER (PARTITION BY year) AS rating_norm
+FROM
+  club_ratings
+WHERE
+  rating != null
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@pipelines-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-0.prql.snap
similarity index 61%
rename from reference/tests/snapshots/snapshot__run_reference_examples@pipelines-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@pipelines-0.prql.snap
index 3a8b5377..2236c04a 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@pipelines-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/queries/pipelines-0.prql
+input_file: reference/tests/prql/queries/pipelines-0.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@pipelines-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-1.prql.snap
similarity index 69%
rename from reference/tests/snapshots/snapshot__run_reference_examples@pipelines-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@pipelines-1.prql.snap
index 16cb2a72..840a1f99 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@pipelines-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/queries/pipelines-1.prql
+input_file: reference/tests/prql/queries/pipelines-1.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@pipelines-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-2.prql.snap
similarity index 72%
rename from reference/tests/snapshots/snapshot__run_reference_examples@pipelines-2.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@pipelines-2.prql.snap
index dfb90d3c..8f55e0ad 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@pipelines-2.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-2.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/queries/pipelines-2.prql
+input_file: reference/tests/prql/queries/pipelines-2.prql
 ---
 SELECT
   employees.*,
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-3.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-3.prql.snap
new file mode 100644
index 00000000..55ecc052
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@pipelines-3.prql.snap
@@ -0,0 +1,23 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/queries/pipelines-3.prql
+---
+WITH table_0 AS (
+  SELECT
+    e.*,
+    salary + payroll_tax AS gross_salary
+  FROM
+    employees AS e
+  ORDER BY
+    gross_salary
+  LIMIT
+    10
+)
+SELECT
+  table_0.name,
+  table_0.gross_salary,
+  d.name
+FROM
+  table_0
+  JOIN department AS d USING(dept_no)
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@ranges-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@ranges-0.prql.snap
similarity index 65%
rename from reference/tests/snapshots/snapshot__run_reference_examples@ranges-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@ranges-0.prql.snap
index 890de50a..a59ae1c5 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@ranges-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@ranges-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/ranges-0.prql
+input_file: reference/tests/prql/language-features/ranges-0.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@s-strings-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@s-strings-0.prql.snap
similarity index 56%
rename from reference/tests/snapshots/snapshot__run_reference_examples@s-strings-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@s-strings-0.prql.snap
index f3a53a64..10f247e1 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@s-strings-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@s-strings-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/s-strings-0.prql
+input_file: reference/tests/prql/language-features/s-strings-0.prql
 ---
 SELECT
   version() AS db_version
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@s-strings-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@s-strings-1.prql.snap
similarity index 57%
rename from reference/tests/snapshots/snapshot__run_reference_examples@s-strings-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@s-strings-1.prql.snap
index c13c4a85..98ee4b25 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@s-strings-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@s-strings-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/s-strings-1.prql
+input_file: reference/tests/prql/language-features/s-strings-1.prql
 ---
 SELECT
   AVG(salary)
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@select-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@select-0.prql.snap
new file mode 100644
index 00000000..d65cce6b
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@select-0.prql.snap
@@ -0,0 +1,9 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/select-0.prql
+---
+SELECT
+  first_name
+FROM
+  employees
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@select-1.prql.snap
similarity index 65%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@select-1.prql.snap
index cc798fb4..ec7c6f14 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@select-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-1.prql
+input_file: reference/tests/prql/transforms/select-1.prql
 ---
 SELECT
   first_name,
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@select-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@select-2.prql.snap
new file mode 100644
index 00000000..59d3d8df
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@select-2.prql.snap
@@ -0,0 +1,9 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/select-2.prql
+---
+SELECT
+  CONCAT(first_name, ' ', last_name) AS name
+FROM
+  employees
diff --git a/reference/tests/snapshots/snapshot__run_reference_prql@select-3.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@select-3.prql.snap
new file mode 100644
index 00000000..15df58d9
--- /dev/null
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@select-3.prql.snap
@@ -0,0 +1,10 @@
+---
+source: reference/tests/snapshot.rs
+expression: sql
+input_file: reference/tests/prql/transforms/select-3.prql
+---
+SELECT
+  CONCAT(first_name, ' ', last_name) AS name,
+  dob - DATE '2022-12-31' AS age_eoy
+FROM
+  employees
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-4.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@sort-0.prql.snap
similarity index 66%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-4.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@sort-0.prql.snap
index 7690de5a..955f4c22 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-4.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@sort-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-4.prql
+input_file: reference/tests/prql/transforms/sort-0.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-5.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@sort-1.prql.snap
similarity index 67%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-5.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@sort-1.prql.snap
index 65ee96ad..5be6fbd3 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-5.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@sort-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-5.prql
+input_file: reference/tests/prql/transforms/sort-1.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-6.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@sort-2.prql.snap
similarity index 71%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-6.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@sort-2.prql.snap
index 018de05f..e498a05c 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-6.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@sort-2.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-6.prql
+input_file: reference/tests/prql/transforms/sort-2.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@sql-parameters-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@sql-parameters-0.prql.snap
similarity index 61%
rename from reference/tests/snapshots/snapshot__run_reference_examples@sql-parameters-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@sql-parameters-0.prql.snap
index 6ff9ad2b..5d7ecee9 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@sql-parameters-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@sql-parameters-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/sql-parameters-0.prql
+input_file: reference/tests/prql/examples/sql-parameters-0.prql
 ---
 SELECT
   mytable.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@strings-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@strings-0.prql.snap
similarity index 55%
rename from reference/tests/snapshots/snapshot__run_reference_examples@strings-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@strings-0.prql.snap
index 4be09f0c..1cca239b 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@strings-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@strings-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/strings-1.prql
+input_file: reference/tests/prql/language-features/strings-0.prql
 ---
 SELECT
   'hello world' AS x
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@strings-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@strings-1.prql.snap
similarity index 55%
rename from reference/tests/snapshots/snapshot__run_reference_examples@strings-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@strings-1.prql.snap
index 38282067..4d119a54 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@strings-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@strings-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/strings-0.prql
+input_file: reference/tests/prql/language-features/strings-1.prql
 ---
 SELECT
   'hello world' AS x
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@strings-2.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@strings-2.prql.snap
similarity index 56%
rename from reference/tests/snapshots/snapshot__run_reference_examples@strings-2.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@strings-2.prql.snap
index 370820cf..3284970b 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@strings-2.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@strings-2.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/strings-2.prql
+input_file: reference/tests/prql/language-features/strings-2.prql
 ---
 SELECT
   '"hello world"' AS x
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@strings-3.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@strings-3.prql.snap
similarity index 58%
rename from reference/tests/snapshots/snapshot__run_reference_examples@strings-3.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@strings-3.prql.snap
index bdc5d4ff..17b9d215 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@strings-3.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@strings-3.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/language-features/strings-3.prql
+input_file: reference/tests/prql/language-features/strings-3.prql
 ---
 SELECT
   'I said "hello world"!' AS x
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@syntax-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@syntax-0.prql.snap
similarity index 68%
rename from reference/tests/snapshots/snapshot__run_reference_examples@syntax-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@syntax-0.prql.snap
index b482fa6f..a7893933 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@syntax-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@syntax-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/syntax-1.prql
+input_file: reference/tests/prql/syntax-0.prql
 ---
 SELECT
   col1,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@syntax-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@syntax-1.prql.snap
similarity index 68%
rename from reference/tests/snapshots/snapshot__run_reference_examples@syntax-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@syntax-1.prql.snap
index 71f69458..207a0819 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@syntax-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@syntax-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/syntax-0.prql
+input_file: reference/tests/prql/syntax-1.prql
 ---
 SELECT
   col1,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-7.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@take-0.prql.snap
similarity index 66%
rename from reference/tests/snapshots/snapshot__run_reference_examples@transforms-7.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@take-0.prql.snap
index e6d499e5..dd518987 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@transforms-7.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@take-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/transforms-7.prql
+input_file: reference/tests/prql/transforms/take-0.prql
 ---
 SELECT
   employees.*
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@variables-0.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@variables-0.prql.snap
similarity index 88%
rename from reference/tests/snapshots/snapshot__run_reference_examples@variables-0.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@variables-0.prql.snap
index 04fa6fea..3824204e 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@variables-0.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@variables-0.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/variables-0.prql
+input_file: reference/tests/prql/examples/variables-0.prql
 ---
 SELECT
   title,
diff --git a/reference/tests/snapshots/snapshot__run_reference_examples@variables-1.prql.snap b/reference/tests/snapshots/snapshot__run_reference_prql@variables-1.prql.snap
similarity index 84%
rename from reference/tests/snapshots/snapshot__run_reference_examples@variables-1.prql.snap
rename to reference/tests/snapshots/snapshot__run_reference_prql@variables-1.prql.snap
index 2b627a2f..009428c1 100644
--- a/reference/tests/snapshots/snapshot__run_reference_examples@variables-1.prql.snap
+++ b/reference/tests/snapshots/snapshot__run_reference_prql@variables-1.prql.snap
@@ -1,7 +1,7 @@
 ---
 source: reference/tests/snapshot.rs
 expression: sql
-input_file: reference/tests/examples/examples/variables-1.prql
+input_file: reference/tests/prql/examples/variables-1.prql
 ---
 WITH table_0 AS (
   SELECT