diff --git a/prqlc/prqlc/src/sql/pq/anchor.rs b/prqlc/prqlc/src/sql/pq/anchor.rs index b502f7b1b9ce..60c8c14cfa50 100644 --- a/prqlc/prqlc/src/sql/pq/anchor.rs +++ b/prqlc/prqlc/src/sql/pq/anchor.rs @@ -660,32 +660,6 @@ impl<'a> CidRedirector<'a> { fold_column_sorts(&mut redirector, sorts).unwrap() } - - // revert sort columns back to their original pre-split columns - pub fn revert_sorts( - sorts: Vec>, - ctx: &'a mut AnchorContext, - ) -> Vec> { - sorts - .into_iter() - .map(|sort| { - let decl = ctx.column_decls.get(&sort.column).unwrap(); - if let ColumnDecl::RelationColumn(riid, cid, _) = decl { - let cid_redirects = &ctx.relation_instances[riid].cid_redirects; - for (source, target) in cid_redirects.iter() { - if target == cid { - log::debug!("reverting {target:?} back to {source:?}"); - return ColumnSort { - direction: sort.direction, - column: *source, - }; - } - } - } - sort - }) - .collect() - } } impl RqFold for CidRedirector<'_> { diff --git a/prqlc/prqlc/src/sql/pq/gen_query.rs b/prqlc/prqlc/src/sql/pq/gen_query.rs index 6eca031327cc..8deade3c7cc4 100644 --- a/prqlc/prqlc/src/sql/pq/gen_query.rs +++ b/prqlc/prqlc/src/sql/pq/gen_query.rs @@ -180,7 +180,9 @@ impl PqMapper for TransformCompiler<' pub(super) fn compile_relation_instance(riid: RIId, ctx: &mut Context) -> Result { ctx.anchor.positional_mapping.activate_mapping(&riid); - let table_ref = &ctx.anchor.relation_instances.get(&riid).unwrap().table_ref; + let rel_instance = &ctx.anchor.relation_instances[&riid]; + let nb_redirects = rel_instance.cid_redirects.len(); + let table_ref = &rel_instance.table_ref; let source = table_ref.source; let decl = ctx.anchor.table_decls.get_mut(&table_ref.source).unwrap(); @@ -200,6 +202,56 @@ pub(super) fn compile_relation_instance(riid: RIId, ctx: &mut Context) -> Result } let relation = compile_relation(sql_relation, ctx)?; + + if let pq::SqlRelation::AtomicPipeline(pipeline) = &relation { + // Finding the last select statement of the pipeline + let last_select_columns = pipeline.iter().rev().find_map(|transform| match transform { + pq::SqlTransform::Select(cids) => Some(cids), + _ => None, + }); + + log::debug!("last select CIds for {riid:?}: {last_select_columns:?}"); + + // If the pipeline ends with a select, we must recompute its CId redirects + if let Some(cids) = last_select_columns { + // Only recompute the CId redirects if there are exactly as many columns in the + // SELECT as there are CId redirects. This probably means that it is a projecting + // select added by `anchor_split` + if nb_redirects == cids.len() { + log::debug!( + "recomputing cid_redirects for {riid:?}. current redirects: {:?}", + ctx.anchor.relation_instances[&riid].cid_redirects + ); + // Inefficient but only way to ensure that the new redirects match the original cids + let new_redirects = cids + .iter() + .zip(&ctx.anchor.relation_instances[&riid].original_cids) + .map(|(new_cid, original_cid)| { + let key_for_value = ctx.anchor.relation_instances[&riid] + .cid_redirects + .iter() + .find_map(|(k, v)| if v == original_cid { Some(k) } else { None }) + .unwrap(); + + ( + *new_cid, + ctx.anchor.relation_instances[&riid].cid_redirects[key_for_value], + ) + }) + .collect(); + + log::debug!( + "recomputed cid_redirects for {riid:?}. new redirects: {new_redirects:?}", + ); + + ctx.anchor + .relation_instances + .get_mut(&riid) + .unwrap() + .cid_redirects = new_redirects; + } + } + } ctx.ctes.push(pq::Cte { tid: source, kind: pq::CteKind::Normal(relation), diff --git a/prqlc/prqlc/src/sql/pq/postprocess.rs b/prqlc/prqlc/src/sql/pq/postprocess.rs index 64f45a913ea7..b6a3b2ecf7c3 100644 --- a/prqlc/prqlc/src/sql/pq/postprocess.rs +++ b/prqlc/prqlc/src/sql/pq/postprocess.rs @@ -2,7 +2,7 @@ //! //! Currently only moves [SqlTransform::Sort]s. -use std::collections::{HashMap, HashSet}; +use std::collections::{HashMap, HashSet, VecDeque}; use itertools::Itertools; @@ -10,7 +10,8 @@ use super::anchor::CidRedirector; use super::ast::*; use crate::ir::generic::ColumnSort; use crate::ir::pl::Ident; -use crate::ir::rq::{CId, RqFold, TId}; +use crate::ir::rq::{CId, ExprKind, RqFold, TId}; +use crate::sql::pq::context::{ColumnDecl, RIId}; use crate::sql::Context; use crate::Result; @@ -41,6 +42,110 @@ struct SortingInference<'a> { ctx: &'a mut Context, } +impl SortingInference<'_> { + /// Prepares the last sorting that will be appended to the pipeline of the `SqlQuery` by + /// `fold_sql_query`. It does so by reverting all columns in the sorting to their very first + /// form, and then transforming their value in the final select, while applying + /// renaming/aliasing when possible. This cannot be done directly in `fold_sql_transforms` + /// because renames are not considered to be SQL transforms. + fn alias_last_sorting(&mut self, mut last_sorting: Sorting, final_select: &[CId]) -> Sorting { + log::debug!("unaliasing last sorting: {last_sorting:?}"); + let redirects = self + .ctx + .anchor + .relation_instances + .iter() + .map(|(riid, rel_inst)| (riid, &rel_inst.cid_redirects)) + .collect::>(); + + // a map of column -> alias + let column_aliases = self + .ctx + .anchor + .column_decls + .values() + .filter_map(|col| { + if let ColumnDecl::Compute(compute) = col { + if let ExprKind::ColumnRef(referenced_id) = compute.expr.kind { + Some((referenced_id, compute.id)) + } else { + None + } + } else { + None + } + }) + .collect::>(); + log::debug!(".. column aliases: {column_aliases:?}"); + + // column -> list of tables that did a revert + let mut reverts: HashMap> = HashMap::new(); + log::debug!(".. reverting all columns to their original value"); + last_sorting.iter_mut().for_each(|sort| { + let mut riids = VecDeque::new(); + let mut changed = true; + while changed { + changed = false; + if let Some(ColumnDecl::RelationColumn(riid, cid, _)) = + self.ctx.anchor.column_decls.get(&sort.column) + { + let cid_redirects = redirects[riid]; + for (source, target) in cid_redirects.iter() { + if target == cid { + log::debug!( + ".. reverting {target:?} back to {source:?} via redirects of {riid:?}" + ); + sort.column = *source; + changed = true; + riids.push_front(*riid); + break; + } + } + } + } + reverts.insert(sort.column, riids); + }); + log::debug!(".. done reverting all columns to their original value: {last_sorting:?}"); + + log::debug!(".. reverting columns forward and aliasing them"); + // reverting forward + last_sorting.iter_mut().for_each(|sort| { + let col_reverts = &reverts[&sort.column]; + for riid in col_reverts { + if final_select.contains(&sort.column) { + log::debug!( + ".. sort column {:?} is in the final select columns, skip reverting", + &sort.column + ); + return; + } + // try renaming + if column_aliases.contains_key(&sort.column) { + let alias = column_aliases[&sort.column]; + log::debug!("..aliasing {:?} as {alias:?}", &sort.column); + sort.column = alias; + } + // try de-reverting with the target table + let cid_mappings = redirects[riid]; + if cid_mappings.contains_key(&sort.column) { + log::debug!( + ".. reverting {:?} forward to {:?} via redirects of {riid:?} ({:?})", + &sort.column, + &cid_mappings[&sort.column], + &cid_mappings + ); + sort.column = cid_mappings[&sort.column]; + } + } + }); + + log::debug!("aliased and reverted last sorting forward: {last_sorting:?}"); + + last_sorting + } +} + +#[derive(Debug)] struct CteSorting { sorting: Sorting, } @@ -50,6 +155,7 @@ impl RqFold for SortingInference<'_> {} impl PqFold for SortingInference<'_> { fn fold_sql_query(&mut self, query: SqlQuery) -> Result { let mut ctes = Vec::with_capacity(query.ctes.len()); + for cte in query.ctes { log::debug!("infer_sorts: {0:?}", cte.tid); let cte = self.fold_cte(cte)?; @@ -68,10 +174,38 @@ impl PqFold for SortingInference<'_> { self.main_relation = true; let mut main_relation = self.fold_sql_relation(query.main_relation)?; log::debug!("--== last_sorting {0:?}", self.last_sorting); + let last_sorting = self.last_sorting.drain(..).collect::>(); // push a sort at the back of the main pipeline if let SqlRelation::AtomicPipeline(pipeline) = &mut main_relation { - pipeline.push(SqlTransform::Sort(self.last_sorting.drain(..).collect())); + let from_id = pipeline + .iter() + .find_map(|transform| match transform { + SqlTransform::From(rel) => Some(rel.riid), + _ => None, + }) + .unwrap(); + + let final_select = pipeline + .iter() + .rev() + .find_map(|transform| match transform { + SqlTransform::Select(select) => Some(select), + _ => None, + }) + .unwrap(); + log::debug!("--== final select: {final_select:?}"); + + let unaliased_last_sorting = self.alias_last_sorting(last_sorting, final_select); + log::debug!("--== unaliased last sorting: {unaliased_last_sorting:?}"); + let redirected_last_sorting = CidRedirector::redirect_sorts( + unaliased_last_sorting, + &from_id, + &mut self.ctx.anchor, + ); + log::debug!("--== redirected last sorting: {redirected_last_sorting:?}"); + + pipeline.push(SqlTransform::Sort(redirected_last_sorting)); } Ok(SqlQuery { @@ -143,6 +277,7 @@ impl PqMapper for SortingInference<'_> { } result.push(transform) } + log::debug!("-- relation sorting {sorting:?}"); if !self.main_relation { // if this is a CTE, make sure that its SELECT includes the @@ -156,12 +291,6 @@ impl PqMapper for SortingInference<'_> { select.push(cid); } } - - // now revert the sort columns so that the output - // sorting reflects the input column cids, needed to - // ensure proper column reference lookup in the final - // steps - sorting = CidRedirector::revert_sorts(sorting, &mut self.ctx.anchor); } // remember sorting for this pipeline diff --git a/prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql b/prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql new file mode 100644 index 000000000000..bd5fdc50f6b2 --- /dev/null +++ b/prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql @@ -0,0 +1,6 @@ +s"SELECT album_id,title,artist_id FROM albums" +group {artist_id} (aggregate { album_title_count = count this.`title`}) +sort {this.artist_id, this.album_title_count} +derive {new_album_count = this.album_title_count} +select {this.artist_id, this.new_album_count} +join side:left ( s"SELECT artist_id,name as artist_name FROM artists" ) (this.artist_id == that.artist_id) diff --git a/prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql b/prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql new file mode 100644 index 000000000000..b32018ef0f8f --- /dev/null +++ b/prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql @@ -0,0 +1,7 @@ +s"SELECT album_id,title,artist_id FROM albums" +group {artist_id} (aggregate { album_title_count = count this.`title`}) +sort {this.artist_id, this.album_title_count} +filter (this.album_title_count) > 10 +derive {new_album_count = this.album_title_count} +select {this.artist_id, this.new_album_count} +join side:left ( s"SELECT artist_id,name as artist_name FROM artists" ) (this.artist_id == that.artist_id) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort.snap index 70a9b3342df6..316c6109df32 100644 --- a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort.snap +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort.snap @@ -30,4 +30,4 @@ SELECT FROM table_1 ORDER BY - _expr_0 + d1 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort_derive_select_join.snap new file mode 100644 index 000000000000..2124399d62d7 --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort_derive_select_join.snap @@ -0,0 +1,58 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql +--- +WITH table_0 AS ( + SELECT + album_id, + title, + artist_id + FROM + albums +), +table_4 AS ( + SELECT + artist_id, + COUNT(*) AS _expr_0 + FROM + table_0 + GROUP BY + artist_id +), +table_2 AS ( + SELECT + artist_id, + _expr_0 AS new_album_count, + _expr_0 + FROM + table_4 +), +table_1 AS ( + SELECT + artist_id, + name as artist_name + FROM + artists +), +table_3 AS ( + SELECT + table_2.artist_id, + table_2.new_album_count, + table_1.artist_id AS _expr_1, + table_1.artist_name, + table_2._expr_0 + FROM + table_2 + LEFT OUTER JOIN table_1 ON table_2.artist_id = table_1.artist_id +) +SELECT + artist_id, + new_album_count, + _expr_1, + artist_name +FROM + table_3 +ORDER BY + artist_id, + new_album_count diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort_filter_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort_filter_derive_select_join.snap new file mode 100644 index 000000000000..c92a5d5538df --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__compile__group_sort_filter_derive_select_join.snap @@ -0,0 +1,58 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nfilter (this.album_title_count) > 10\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql +--- +WITH table_0 AS ( + SELECT + album_id, + title, + artist_id + FROM + albums +), +table_3 AS ( + SELECT + artist_id, + COUNT(*) AS _expr_0 + FROM + table_0 + GROUP BY + artist_id +), +table_4 AS ( + SELECT + artist_id, + _expr_0 AS new_album_count, + _expr_0 + FROM + table_3 + WHERE + _expr_0 > 10 +), +table_2 AS ( + SELECT + artist_id, + new_album_count, + _expr_0 + FROM + table_4 +), +table_1 AS ( + SELECT + artist_id, + name as artist_name + FROM + artists +) +SELECT + table_2.artist_id, + table_2.new_album_count, + table_1.artist_id, + table_1.artist_name +FROM + table_2 + LEFT OUTER JOIN table_1 ON table_2.artist_id = table_1.artist_id +ORDER BY + table_2.artist_id, + table_2.new_album_count diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__debug_lineage__group_sort_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__debug_lineage__group_sort_derive_select_join.snap new file mode 100644 index 000000000000..7e5692de57b0 --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__debug_lineage__group_sort_derive_select_join.snap @@ -0,0 +1,400 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql +--- +frames: +- - 1:66-117 + - columns: + - !Single + name: + - _literal_126 + - artist_id + target_id: 127 + target_name: null + - !Single + name: + - album_title_count + target_id: 146 + target_name: null + inputs: + - id: 126 + name: _literal_126 + table: + - default_db + - _literal_126 +- - 1:119-164 + - columns: + - !Single + name: + - _literal_126 + - artist_id + target_id: 127 + target_name: null + - !Single + name: + - album_title_count + target_id: 146 + target_name: null + inputs: + - id: 126 + name: _literal_126 + table: + - default_db + - _literal_126 +- - 1:165-214 + - columns: + - !Single + name: + - _literal_126 + - artist_id + target_id: 127 + target_name: null + - !Single + name: + - album_title_count + target_id: 146 + target_name: null + - !Single + name: + - new_album_count + target_id: 156 + target_name: null + inputs: + - id: 126 + name: _literal_126 + table: + - default_db + - _literal_126 +- - 1:215-260 + - columns: + - !Single + name: + - _literal_126 + - artist_id + target_id: 159 + target_name: null + - !Single + name: + - new_album_count + target_id: 160 + target_name: null + inputs: + - id: 126 + name: _literal_126 + table: + - default_db + - _literal_126 +- - 1:261-367 + - columns: + - !Single + name: + - _literal_126 + - artist_id + target_id: 159 + target_name: null + - !Single + name: + - new_album_count + target_id: 160 + target_name: null + - !All + input_id: 113 + except: [] + inputs: + - id: 126 + name: _literal_126 + table: + - default_db + - _literal_126 + - id: 113 + name: _literal_113 + table: + - default_db + - _literal_113 +nodes: +- id: 113 + kind: SString + span: 1:278-330 + parent: 167 +- id: 126 + kind: SString + span: 1:0-46 + parent: 149 +- id: 127 + kind: Ident + span: 1:54-63 + ident: !Ident + - this + - _literal_126 + - artist_id + targets: + - 126 + parent: 128 +- id: 128 + kind: Tuple + span: 1:53-64 + children: + - 127 + parent: 149 +- id: 146 + kind: RqOperator + span: 1:98-116 + alias: album_title_count + targets: + - 147 + parent: 148 +- id: 147 + kind: Literal +- id: 148 + kind: Tuple + span: 1:76-117 + children: + - 146 + parent: 149 +- id: 149 + kind: 'TransformCall: Aggregate' + span: 1:66-117 + children: + - 126 + - 148 + - 128 + parent: 155 +- id: 152 + kind: Ident + span: 1:125-139 + ident: !Ident + - this + - _literal_126 + - artist_id + targets: + - 127 + parent: 155 +- id: 153 + kind: Ident + span: 1:141-163 + ident: !Ident + - this + - album_title_count + targets: + - 146 + parent: 155 +- id: 155 + kind: 'TransformCall: Sort' + span: 1:119-164 + children: + - 149 + - 152 + - 153 + parent: 158 +- id: 156 + kind: Ident + span: 1:191-213 + alias: new_album_count + ident: !Ident + - this + - album_title_count + targets: + - 146 + parent: 157 +- id: 157 + kind: Tuple + span: 1:172-214 + children: + - 156 + parent: 158 +- id: 158 + kind: 'TransformCall: Derive' + span: 1:165-214 + children: + - 155 + - 157 + parent: 162 +- id: 159 + kind: Ident + span: 1:223-237 + ident: !Ident + - this + - _literal_126 + - artist_id + targets: + - 127 + parent: 161 +- id: 160 + kind: Ident + span: 1:239-259 + ident: !Ident + - this + - new_album_count + targets: + - 156 + parent: 161 +- id: 161 + kind: Tuple + span: 1:222-260 + children: + - 159 + - 160 + parent: 162 +- id: 162 + kind: 'TransformCall: Select' + span: 1:215-260 + children: + - 158 + - 161 + parent: 167 +- id: 163 + kind: RqOperator + span: 1:334-366 + targets: + - 165 + - 166 + parent: 167 +- id: 165 + kind: Ident + span: 1:334-348 + ident: !Ident + - this + - _literal_126 + - artist_id + targets: + - 159 +- id: 166 + kind: Ident + span: 1:352-366 + ident: !Ident + - that + - _literal_113 + - artist_id + targets: + - 113 +- id: 167 + kind: 'TransformCall: Join' + span: 1:261-367 + children: + - 162 + - 113 + - 163 +ast: + name: Project + stmts: + - VarDef: + kind: Main + name: main + value: + Pipeline: + exprs: + - SString: + - !String SELECT album_id,title,artist_id FROM albums + span: 1:0-46 + - FuncCall: + name: + Ident: + - group + span: 1:47-52 + args: + - Tuple: + - Ident: + - artist_id + span: 1:54-63 + span: 1:53-64 + - FuncCall: + name: + Ident: + - aggregate + span: 1:66-75 + args: + - Tuple: + - FuncCall: + name: + Ident: + - count + span: 1:98-103 + args: + - Ident: + - this + - title + span: 1:104-116 + span: 1:98-116 + alias: album_title_count + span: 1:76-117 + span: 1:66-117 + span: 1:47-118 + - FuncCall: + name: + Ident: + - sort + span: 1:119-123 + args: + - Tuple: + - Ident: + - this + - artist_id + span: 1:125-139 + - Ident: + - this + - album_title_count + span: 1:141-163 + span: 1:124-164 + span: 1:119-164 + - FuncCall: + name: + Ident: + - derive + span: 1:165-171 + args: + - Tuple: + - Ident: + - this + - album_title_count + span: 1:191-213 + alias: new_album_count + span: 1:172-214 + span: 1:165-214 + - FuncCall: + name: + Ident: + - select + span: 1:215-221 + args: + - Tuple: + - Ident: + - this + - artist_id + span: 1:223-237 + - Ident: + - this + - new_album_count + span: 1:239-259 + span: 1:222-260 + span: 1:215-260 + - FuncCall: + name: + Ident: + - join + span: 1:261-265 + args: + - SString: + - !String SELECT artist_id,name as artist_name FROM artists + span: 1:278-330 + - Binary: + left: + Ident: + - this + - artist_id + span: 1:334-348 + op: Eq + right: + Ident: + - that + - artist_id + span: 1:352-366 + span: 1:334-366 + named_args: + side: + Ident: + - left + span: 1:271-275 + span: 1:261-367 + span: 1:0-367 + span: 1:0-367 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__debug_lineage__group_sort_filter_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__debug_lineage__group_sort_filter_derive_select_join.snap new file mode 100644 index 000000000000..4b5c1093b2c0 --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__debug_lineage__group_sort_filter_derive_select_join.snap @@ -0,0 +1,463 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nfilter (this.album_title_count) > 10\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql +--- +frames: +- - 1:66-117 + - columns: + - !Single + name: + - _literal_129 + - artist_id + target_id: 130 + target_name: null + - !Single + name: + - album_title_count + target_id: 149 + target_name: null + inputs: + - id: 129 + name: _literal_129 + table: + - default_db + - _literal_129 +- - 1:119-164 + - columns: + - !Single + name: + - _literal_129 + - artist_id + target_id: 130 + target_name: null + - !Single + name: + - album_title_count + target_id: 149 + target_name: null + inputs: + - id: 129 + name: _literal_129 + table: + - default_db + - _literal_129 +- - 1:165-201 + - columns: + - !Single + name: + - _literal_129 + - artist_id + target_id: 130 + target_name: null + - !Single + name: + - album_title_count + target_id: 149 + target_name: null + inputs: + - id: 129 + name: _literal_129 + table: + - default_db + - _literal_129 +- - 1:202-251 + - columns: + - !Single + name: + - _literal_129 + - artist_id + target_id: 130 + target_name: null + - !Single + name: + - album_title_count + target_id: 149 + target_name: null + - !Single + name: + - new_album_count + target_id: 164 + target_name: null + inputs: + - id: 129 + name: _literal_129 + table: + - default_db + - _literal_129 +- - 1:252-297 + - columns: + - !Single + name: + - _literal_129 + - artist_id + target_id: 167 + target_name: null + - !Single + name: + - new_album_count + target_id: 168 + target_name: null + inputs: + - id: 129 + name: _literal_129 + table: + - default_db + - _literal_129 +- - 1:298-404 + - columns: + - !Single + name: + - _literal_129 + - artist_id + target_id: 167 + target_name: null + - !Single + name: + - new_album_count + target_id: 168 + target_name: null + - !All + input_id: 113 + except: [] + inputs: + - id: 129 + name: _literal_129 + table: + - default_db + - _literal_129 + - id: 113 + name: _literal_113 + table: + - default_db + - _literal_113 +nodes: +- id: 113 + kind: SString + span: 1:315-367 + parent: 175 +- id: 129 + kind: SString + span: 1:0-46 + parent: 152 +- id: 130 + kind: Ident + span: 1:54-63 + ident: !Ident + - this + - _literal_129 + - artist_id + targets: + - 129 + parent: 131 +- id: 131 + kind: Tuple + span: 1:53-64 + children: + - 130 + parent: 152 +- id: 149 + kind: RqOperator + span: 1:98-116 + alias: album_title_count + targets: + - 150 + parent: 151 +- id: 150 + kind: Literal +- id: 151 + kind: Tuple + span: 1:76-117 + children: + - 149 + parent: 152 +- id: 152 + kind: 'TransformCall: Aggregate' + span: 1:66-117 + children: + - 129 + - 151 + - 131 + parent: 158 +- id: 155 + kind: Ident + span: 1:125-139 + ident: !Ident + - this + - _literal_129 + - artist_id + targets: + - 130 + parent: 158 +- id: 156 + kind: Ident + span: 1:141-163 + ident: !Ident + - this + - album_title_count + targets: + - 149 + parent: 158 +- id: 158 + kind: 'TransformCall: Sort' + span: 1:119-164 + children: + - 152 + - 155 + - 156 + parent: 163 +- id: 159 + kind: RqOperator + span: 1:172-201 + targets: + - 161 + - 162 + parent: 163 +- id: 161 + kind: Ident + span: 1:173-195 + ident: !Ident + - this + - album_title_count + targets: + - 149 +- id: 162 + kind: Literal + span: 1:199-201 +- id: 163 + kind: 'TransformCall: Filter' + span: 1:165-201 + children: + - 158 + - 159 + parent: 166 +- id: 164 + kind: Ident + span: 1:228-250 + alias: new_album_count + ident: !Ident + - this + - album_title_count + targets: + - 149 + parent: 165 +- id: 165 + kind: Tuple + span: 1:209-251 + children: + - 164 + parent: 166 +- id: 166 + kind: 'TransformCall: Derive' + span: 1:202-251 + children: + - 163 + - 165 + parent: 170 +- id: 167 + kind: Ident + span: 1:260-274 + ident: !Ident + - this + - _literal_129 + - artist_id + targets: + - 130 + parent: 169 +- id: 168 + kind: Ident + span: 1:276-296 + ident: !Ident + - this + - new_album_count + targets: + - 164 + parent: 169 +- id: 169 + kind: Tuple + span: 1:259-297 + children: + - 167 + - 168 + parent: 170 +- id: 170 + kind: 'TransformCall: Select' + span: 1:252-297 + children: + - 166 + - 169 + parent: 175 +- id: 171 + kind: RqOperator + span: 1:371-403 + targets: + - 173 + - 174 + parent: 175 +- id: 173 + kind: Ident + span: 1:371-385 + ident: !Ident + - this + - _literal_129 + - artist_id + targets: + - 167 +- id: 174 + kind: Ident + span: 1:389-403 + ident: !Ident + - that + - _literal_113 + - artist_id + targets: + - 113 +- id: 175 + kind: 'TransformCall: Join' + span: 1:298-404 + children: + - 170 + - 113 + - 171 +ast: + name: Project + stmts: + - VarDef: + kind: Main + name: main + value: + Pipeline: + exprs: + - SString: + - !String SELECT album_id,title,artist_id FROM albums + span: 1:0-46 + - FuncCall: + name: + Ident: + - group + span: 1:47-52 + args: + - Tuple: + - Ident: + - artist_id + span: 1:54-63 + span: 1:53-64 + - FuncCall: + name: + Ident: + - aggregate + span: 1:66-75 + args: + - Tuple: + - FuncCall: + name: + Ident: + - count + span: 1:98-103 + args: + - Ident: + - this + - title + span: 1:104-116 + span: 1:98-116 + alias: album_title_count + span: 1:76-117 + span: 1:66-117 + span: 1:47-118 + - FuncCall: + name: + Ident: + - sort + span: 1:119-123 + args: + - Tuple: + - Ident: + - this + - artist_id + span: 1:125-139 + - Ident: + - this + - album_title_count + span: 1:141-163 + span: 1:124-164 + span: 1:119-164 + - FuncCall: + name: + Ident: + - filter + span: 1:165-171 + args: + - Binary: + left: + Ident: + - this + - album_title_count + span: 1:173-195 + op: Gt + right: + Literal: + Integer: 10 + span: 1:199-201 + span: 1:172-201 + span: 1:165-201 + - FuncCall: + name: + Ident: + - derive + span: 1:202-208 + args: + - Tuple: + - Ident: + - this + - album_title_count + span: 1:228-250 + alias: new_album_count + span: 1:209-251 + span: 1:202-251 + - FuncCall: + name: + Ident: + - select + span: 1:252-258 + args: + - Tuple: + - Ident: + - this + - artist_id + span: 1:260-274 + - Ident: + - this + - new_album_count + span: 1:276-296 + span: 1:259-297 + span: 1:252-297 + - FuncCall: + name: + Ident: + - join + span: 1:298-302 + args: + - SString: + - !String SELECT artist_id,name as artist_name FROM artists + span: 1:315-367 + - Binary: + left: + Ident: + - this + - artist_id + span: 1:371-385 + op: Eq + right: + Ident: + - that + - artist_id + span: 1:389-403 + span: 1:371-403 + named_args: + side: + Ident: + - left + span: 1:308-312 + span: 1:298-404 + span: 1:0-404 + span: 1:0-404 diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_derive_select_join.snap new file mode 100644 index 000000000000..9ee4497fa641 --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_derive_select_join.snap @@ -0,0 +1,11 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql +--- +s"SELECT album_id,title,artist_id FROM albums" +group {artist_id} (aggregate {album_title_count = count this.title}) +sort {this.artist_id, this.album_title_count} +derive {new_album_count = this.album_title_count} +select {this.artist_id, this.new_album_count} +join side:left s"SELECT artist_id,name as artist_name FROM artists" this.artist_id == that.artist_id diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_filter_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_filter_derive_select_join.snap new file mode 100644 index 000000000000..9d068a1d0fb4 --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__fmt__group_sort_filter_derive_select_join.snap @@ -0,0 +1,12 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nfilter (this.album_title_count) > 10\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql +--- +s"SELECT album_id,title,artist_id FROM albums" +group {artist_id} (aggregate {album_title_count = count this.title}) +sort {this.artist_id, this.album_title_count} +filter this.album_title_count > 10 +derive {new_album_count = this.album_title_count} +select {this.artist_id, this.new_album_count} +join side:left s"SELECT artist_id,name as artist_name FROM artists" this.artist_id == that.artist_id diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_derive_select_join.snap new file mode 100644 index 000000000000..698b478902a6 --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_derive_select_join.snap @@ -0,0 +1,76 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: tokens +input_file: prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql +--- +Tokens( + [ + 0..0: Start, + 0..46: Interpolation('s', "SELECT album_id,title,artist_id FROM albums"), + 46..47: NewLine, + 47..52: Ident("group"), + 53..54: Control('{'), + 54..63: Ident("artist_id"), + 63..64: Control('}'), + 65..66: Control('('), + 66..75: Ident("aggregate"), + 76..77: Control('{'), + 78..95: Ident("album_title_count"), + 96..97: Control('='), + 98..103: Ident("count"), + 104..108: Ident("this"), + 108..109: Control('.'), + 109..116: Ident("title"), + 116..117: Control('}'), + 117..118: Control(')'), + 118..119: NewLine, + 119..123: Ident("sort"), + 124..125: Control('{'), + 125..129: Ident("this"), + 129..130: Control('.'), + 130..139: Ident("artist_id"), + 139..140: Control(','), + 141..145: Ident("this"), + 145..146: Control('.'), + 146..163: Ident("album_title_count"), + 163..164: Control('}'), + 164..165: NewLine, + 165..171: Ident("derive"), + 172..173: Control('{'), + 173..188: Ident("new_album_count"), + 189..190: Control('='), + 191..195: Ident("this"), + 195..196: Control('.'), + 196..213: Ident("album_title_count"), + 213..214: Control('}'), + 214..215: NewLine, + 215..221: Ident("select"), + 222..223: Control('{'), + 223..227: Ident("this"), + 227..228: Control('.'), + 228..237: Ident("artist_id"), + 237..238: Control(','), + 239..243: Ident("this"), + 243..244: Control('.'), + 244..259: Ident("new_album_count"), + 259..260: Control('}'), + 260..261: NewLine, + 261..265: Ident("join"), + 266..270: Ident("side"), + 270..271: Control(':'), + 271..275: Ident("left"), + 276..277: Control('('), + 278..330: Interpolation('s', "SELECT artist_id,name as artist_name FROM artists"), + 331..332: Control(')'), + 333..334: Control('('), + 334..338: Ident("this"), + 338..339: Control('.'), + 339..348: Ident("artist_id"), + 349..351: Eq, + 352..356: Ident("that"), + 356..357: Control('.'), + 357..366: Ident("artist_id"), + 366..367: Control(')'), + 367..368: NewLine, + ], +) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_filter_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_filter_derive_select_join.snap new file mode 100644 index 000000000000..e98eee3ae94d --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__lex__group_sort_filter_derive_select_join.snap @@ -0,0 +1,85 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: tokens +input_file: prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql +--- +Tokens( + [ + 0..0: Start, + 0..46: Interpolation('s', "SELECT album_id,title,artist_id FROM albums"), + 46..47: NewLine, + 47..52: Ident("group"), + 53..54: Control('{'), + 54..63: Ident("artist_id"), + 63..64: Control('}'), + 65..66: Control('('), + 66..75: Ident("aggregate"), + 76..77: Control('{'), + 78..95: Ident("album_title_count"), + 96..97: Control('='), + 98..103: Ident("count"), + 104..108: Ident("this"), + 108..109: Control('.'), + 109..116: Ident("title"), + 116..117: Control('}'), + 117..118: Control(')'), + 118..119: NewLine, + 119..123: Ident("sort"), + 124..125: Control('{'), + 125..129: Ident("this"), + 129..130: Control('.'), + 130..139: Ident("artist_id"), + 139..140: Control(','), + 141..145: Ident("this"), + 145..146: Control('.'), + 146..163: Ident("album_title_count"), + 163..164: Control('}'), + 164..165: NewLine, + 165..171: Ident("filter"), + 172..173: Control('('), + 173..177: Ident("this"), + 177..178: Control('.'), + 178..195: Ident("album_title_count"), + 195..196: Control(')'), + 197..198: Control('>'), + 199..201: Literal(Integer(10)), + 201..202: NewLine, + 202..208: Ident("derive"), + 209..210: Control('{'), + 210..225: Ident("new_album_count"), + 226..227: Control('='), + 228..232: Ident("this"), + 232..233: Control('.'), + 233..250: Ident("album_title_count"), + 250..251: Control('}'), + 251..252: NewLine, + 252..258: Ident("select"), + 259..260: Control('{'), + 260..264: Ident("this"), + 264..265: Control('.'), + 265..274: Ident("artist_id"), + 274..275: Control(','), + 276..280: Ident("this"), + 280..281: Control('.'), + 281..296: Ident("new_album_count"), + 296..297: Control('}'), + 297..298: NewLine, + 298..302: Ident("join"), + 303..307: Ident("side"), + 307..308: Control(':'), + 308..312: Ident("left"), + 313..314: Control('('), + 315..367: Interpolation('s', "SELECT artist_id,name as artist_name FROM artists"), + 368..369: Control(')'), + 370..371: Control('('), + 371..375: Ident("this"), + 375..376: Control('.'), + 376..385: Ident("artist_id"), + 386..388: Eq, + 389..393: Ident("that"), + 393..394: Control('.'), + 394..403: Ident("artist_id"), + 403..404: Control(')'), + 404..405: NewLine, + ], +) diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__results__group_sort_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__results__group_sort_derive_select_join.snap new file mode 100644 index 000000000000..60b703a6502a --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__results__group_sort_derive_select_join.snap @@ -0,0 +1,209 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_derive_select_join.prql +--- +1,2,1,AC/DC +2,2,2,Accept +3,1,3,Aerosmith +4,1,4,Alanis Morissette +5,1,5,Alice In Chains +6,2,6,Antônio Carlos Jobim +7,1,7,Apocalyptica +8,3,8,Audioslave +9,1,9,BackBeat +10,1,10,Billy Cobham +11,2,11,Black Label Society +12,2,12,Black Sabbath +13,1,13,Body Count +14,1,14,Bruce Dickinson +15,1,15,Buddy Guy +16,2,16,Caetano Veloso +17,1,17,Chico Buarque +18,2,18,Chico Science & Nação Zumbi +19,2,19,Cidade Negra +20,1,20,Cláudio Zoli +21,4,21,Various Artists +22,14,22,Led Zeppelin +23,1,23,Frank Zappa & Captain Beefheart +24,1,24,Marcos Valle +27,3,27,Gilberto Gil +36,1,36,O Rappa +37,1,37,Ed Motta +41,1,41,Elis Regina +42,2,42,Milton Nascimento +46,1,46,Jorge Ben +50,10,50,Metallica +51,3,51,Queen +52,2,52,Kiss +53,2,53,Spyro Gyra +54,2,54,Green Day +55,1,55,David Coverdale +56,1,56,Gonzaguinha +57,1,57,Os Mutantes +58,11,58,Deep Purple +59,3,59,Santana +68,3,68,Miles Davis +69,1,69,Gene Krupa +70,1,70,Toquinho & Vinícius +72,1,72,Vinícius De Moraes +76,2,76,Creedence Clearwater Revival +77,2,77,Cássia Eller +78,1,78,Def Leppard +79,1,79,Dennis Chambers +80,2,80,Djavan +81,2,81,Eric Clapton +82,4,82,Faith No More +83,1,83,Falamansa +84,4,84,Foo Fighters +85,1,85,Frank Sinatra +86,1,86,Funk Como Le Gusta +87,1,87,Godsmack +88,3,88,Guns N' Roses +89,1,89,Incognito +90,21,90,Iron Maiden +91,1,91,James Brown +92,3,92,Jamiroquai +93,1,93,JET +94,1,94,Jimi Hendrix +95,1,95,Joe Satriani +96,1,96,Jota Quest +97,1,97,João Suplicy +98,1,98,Judas Priest +99,2,99,Legião Urbana +100,1,100,Lenny Kravitz +101,2,101,Lulu Santos +102,1,102,Marillion +103,1,103,Marisa Monte +104,1,104,Marvin Gaye +105,1,105,Men At Work +106,1,106,Motörhead +108,1,108,Mônica Marianno +109,1,109,Mötley Crüe +110,2,110,Nirvana +111,1,111,O Terço +112,1,112,Olodum +113,3,113,Os Paralamas Do Sucesso +114,6,114,Ozzy Osbourne +115,1,115,Page & Plant +116,1,116,Passengers +117,1,117,Paul D'Ianno +118,5,118,Pearl Jam +120,1,120,Pink Floyd +121,1,121,Planet Hemp +122,1,122,R.E.M. Feat. Kate Pearson +124,3,124,R.E.M. +125,1,125,Raimundos +126,1,126,Raul Seixas +127,3,127,Red Hot Chili Peppers +128,1,128,Rush +130,2,130,Skank +131,2,131,Smashing Pumpkins +132,1,132,Soundgarden +133,1,133,Stevie Ray Vaughan & Double Trouble +134,1,134,Stone Temple Pilots +135,1,135,System Of A Down +136,1,136,Terry Bozzio, Tony Levin & Steve Stevens +137,2,137,The Black Crowes +138,1,138,The Clash +139,2,139,The Cult +140,1,140,The Doors +141,1,141,The Police +142,3,142,The Rolling Stones +143,2,143,The Tea Party +144,1,144,The Who +145,2,145,Tim Maia +146,2,146,Titãs +147,2,147,Battlestar Galactica +148,1,148,Heroes +149,4,149,Lost +150,10,150,U2 +151,1,151,UB40 +152,4,152,Van Halen +153,1,153,Velvet Revolver +155,1,155,Zeca Pagodinho +156,3,156,The Office +157,1,157,Dread Zeppelin +158,1,158,Battlestar Galactica (Classic) +159,1,159,Aquaman +179,1,179,Scorpions +180,1,180,House Of Pain +196,1,196,Cake +197,1,197,Aisha Duo +198,1,198,Habib Koité and Bamada +199,1,199,Karsh Kale +200,1,200,The Posies +201,1,201,Luciana Souza/Romero Lubambo +202,1,202,Aaron Goldberg +203,1,203,Nicolaus Esterhazy Sinfonia +204,1,204,Temple of the Dog +205,1,205,Chris Cornell +206,1,206,Alberto Turco & Nova Schola Gregoriana +207,1,207,Richard Marlow & The Choir of Trinity College, Cambridge +208,2,208,English Concert & Trevor Pinnock +209,1,209,Anne-Sophie Mutter, Herbert Von Karajan & Wiener Philharmoniker +210,1,210,Hilary Hahn, Jeffrey Kahane, Los Angeles Chamber Orchestra & Margaret Batjer +211,1,211,Wilhelm Kempff +212,1,212,Yo-Yo Ma +213,1,213,Scholars Baroque Ensemble +214,1,214,Academy of St. Martin in the Fields & Sir Neville Marriner +215,1,215,Academy of St. Martin in the Fields Chamber Ensemble & Sir Neville Marriner +216,1,216,Berliner Philharmoniker, Claudio Abbado & Sabine Meyer +217,1,217,Royal Philharmonic Orchestra & Sir Thomas Beecham +218,1,218,Orchestre Révolutionnaire et Romantique & John Eliot Gardiner +219,1,219,Britten Sinfonia, Ivor Bolton & Lesley Garrett +220,1,220,Chicago Symphony Chorus, Chicago Symphony Orchestra & Sir Georg Solti +221,1,221,Sir Georg Solti & Wiener Philharmoniker +222,1,222,Academy of St. Martin in the Fields, John Birch, Sir Neville Marriner & Sylvia McNair +223,1,223,London Symphony Orchestra & Sir Charles Mackerras +224,1,224,Barry Wordsworth & BBC Concert Orchestra +225,1,225,Herbert Von Karajan, Mirella Freni & Wiener Philharmoniker +226,3,226,Eugene Ormandy +227,1,227,Luciano Pavarotti +228,1,228,Leonard Bernstein & New York Philharmonic +229,1,229,Boston Symphony Orchestra & Seiji Ozawa +230,1,230,Aaron Copland & London Symphony Orchestra +231,1,231,Ton Koopman +232,1,232,Sergei Prokofiev & Yuri Temirkanov +233,1,233,Chicago Symphony Orchestra & Fritz Reiner +234,1,234,Orchestra of The Age of Enlightenment +235,1,235,Emanuel Ax, Eugene Ormandy & Philadelphia Orchestra +236,1,236,James Levine +237,1,237,Berliner Philharmoniker & Hans Rosbaud +238,1,238,Maurizio Pollini +240,1,240,Gustav Mahler +241,1,241,Felix Schmidt, London Symphony Orchestra & Rafael Frühbeck de Burgos +242,1,242,Edo de Waart & San Francisco Symphony +243,1,243,Antal Doráti & London Symphony Orchestra +244,1,244,Choir Of Westminster Abbey & Simon Preston +245,2,245,Michael Tilson Thomas & San Francisco Symphony +246,1,246,Chor der Wiener Staatsoper, Herbert Von Karajan & Wiener Philharmoniker +247,1,247,The King's Singers +248,3,248,Berliner Philharmoniker & Herbert Von Karajan +249,1,249,Sir Georg Solti, Sumi Jo & Wiener Philharmoniker +250,1,250,Christopher O'Riley +251,1,251,Fretwork +252,2,252,Amy Winehouse +253,1,253,Calexico +254,1,254,Otto Klemperer & Philharmonia Orchestra +255,1,255,Yehudi Menuhin +256,1,256,Philharmonia Orchestra & Sir Neville Marriner +257,1,257,Academy of St. Martin in the Fields, Sir Neville Marriner & Thurston Dart +258,1,258,Les Arts Florissants & William Christie +259,1,259,The 12 Cellists of The Berlin Philharmonic +260,1,260,Adrian Leaper & Doreen de Feis +261,1,261,Roger Norrington, London Classical Players +262,1,262,Charles Dutoit & L'Orchestre Symphonique de Montréal +263,1,263,Equale Brass Ensemble, John Eliot Gardiner & Munich Monteverdi Orchestra and Choir +264,1,264,Kent Nagano and Orchestre de l'Opéra de Lyon +265,1,265,Julian Bream +266,1,266,Martin Roscoe +267,1,267,Göteborgs Symfoniker & Neeme Järvi +268,1,268,Itzhak Perlman +269,1,269,Michele Campanella +270,1,270,Gerald Moore +271,1,271,Mela Tenenbaum, Pro Musica Prague & Richard Kapp +272,1,272,Emerson String Quartet +273,1,273,C. Monteverdi, Nigel Rogers - Chiaroscuro; London Baroque; London Cornett & Sackbu +274,1,274,Nash Ensemble +275,1,275,Philip Glass Ensemble diff --git a/prqlc/prqlc/tests/integration/snapshots/integration__queries__results__group_sort_filter_derive_select_join.snap b/prqlc/prqlc/tests/integration/snapshots/integration__queries__results__group_sort_filter_derive_select_join.snap new file mode 100644 index 000000000000..350d5bbef422 --- /dev/null +++ b/prqlc/prqlc/tests/integration/snapshots/integration__queries__results__group_sort_filter_derive_select_join.snap @@ -0,0 +1,8 @@ +--- +source: prqlc/prqlc/tests/integration/queries.rs +expression: "s\"SELECT album_id,title,artist_id FROM albums\"\ngroup {artist_id} (aggregate { album_title_count = count this.`title`})\nsort {this.artist_id, this.album_title_count}\nfilter (this.album_title_count) > 10\nderive {new_album_count = this.album_title_count}\nselect {this.artist_id, this.new_album_count}\njoin side:left ( s\"SELECT artist_id,name as artist_name FROM artists\" ) (this.artist_id == that.artist_id)\n" +input_file: prqlc/prqlc/tests/integration/queries/group_sort_filter_derive_select_join.prql +--- +22,14,22,Led Zeppelin +58,11,58,Deep Purple +90,21,90,Iron Maiden diff --git a/prqlc/prqlc/tests/integration/sql.rs b/prqlc/prqlc/tests/integration/sql.rs index d61fbcd1fd19..3b16d3a30735 100644 --- a/prqlc/prqlc/tests/integration/sql.rs +++ b/prqlc/prqlc/tests/integration/sql.rs @@ -934,7 +934,7 @@ fn test_sort_in_nested_join_with_extra_derive_and_select() { select {this.my_new_col, this.new_name, this.other_new_name} ) (this.id == that.my_new_col) "#).unwrap(), - @r#" + @r" WITH table_1 AS ( SELECT CONCAT('artist: ', name) AS my_new_col, @@ -958,7 +958,7 @@ fn test_sort_in_nested_join_with_extra_derive_and_select() { my_new_col, new_name, other_new_name, - FIRST_VALUE(name) AS _expr_0 + _expr_0 FROM table_2 ) @@ -970,7 +970,7 @@ fn test_sort_in_nested_join_with_extra_derive_and_select() { FROM albums LEFT OUTER JOIN table_0 ON albums.id = table_0.my_new_col - "# + " ); } @@ -1237,7 +1237,7 @@ fn test_sorts_01() { FROM table_0 ORDER BY - _expr_0 + renamed "); }