MCPcopy Create free account
hub / github.com/PRQL/prql / union

Function union

prqlc/prqlc/src/sql/pq/preprocess.rs:277–303  ·  view source on GitHub ↗

Creates [SqlTransform::Union] from [Transform::Append]

(
    pipeline: Vec<SqlTransform>,
    ctx: &mut Context,
)

Source from the content-addressed store, hash-verified

275
276/// Creates [SqlTransform::Union] from [Transform::Append]
277pub(in crate::sql) fn union(
278 pipeline: Vec<SqlTransform>,
279 ctx: &mut Context,
280) -> Result<Vec<SqlTransform>> {
281 use SqlTransform::*;
282 use Transform::*;
283
284 let mut res = Vec::with_capacity(pipeline.len());
285 let mut pipeline = pipeline.into_iter().peekable();
286 while let Some(t) = pipeline.next() {
287 let Super(Append(bottom)) = t else {
288 res.push(t);
289 continue;
290 };
291 let bottom = ctx.anchor.create_relation_instance(bottom, HashMap::new());
292
293 let distinct = if let Some(Distinct) = &pipeline.peek() {
294 pipeline.next();
295 true
296 } else {
297 false
298 };
299
300 res.push(SqlTransform::Union { bottom, distinct });
301 }
302 Ok(res)
303}
304
305/// Creates [SqlTransform::Except] from [Transform::Join] and [Transform::Filter]
306pub(in crate::sql) fn except(

Callers 1

preprocessFunction · 0.85

Calls 5

lenMethod · 0.80
into_iterMethod · 0.80
nextMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected