Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support old Rust versions #1561

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1b4217c
feat: support old Rust versions
eitsupi Jan 18, 2023
996a783
fix: `version.workspace` was supported after Rust 1.64
eitsupi Jan 18, 2023
4dad46f
Revert "fix: `version.workspace` was supported after Rust 1.64"
eitsupi Jan 18, 2023
7a26d8c
Merge commit 'a19944fe7caf9e69d8573f7b3e341d0098a2d132' into test-0.4.1
eitsupi Jan 19, 2023
2513cfe
fix: support install prql-compiler from GitHub by Rust 1.61 and 1.64
eitsupi Jan 19, 2023
dcb61ba
Revert "fix: support install prql-compiler from GitHub by Rust 1.61 a…
eitsupi Jan 19, 2023
af8faf5
Merge commit '327298aa07d6a00cef7f913f9433e88d110d4b72' into try-0.4.2
eitsupi Jan 26, 2023
7b36611
fix: support install prql-compiler from GitHub by Rust 1.61 and 1.64
eitsupi Jan 26, 2023
7aae8c9
fix: support install prql-compiler from GitHub by Rust 1.61 and 1.64
eitsupi Jan 26, 2023
adb7735
Revert "fix: support install prql-compiler from GitHub by Rust 1.61 a…
eitsupi Jan 26, 2023
d00c1c9
Merge commit '2d9391253f41115d0d70fac90faeed36f5d63729' into support-…
eitsupi Feb 18, 2023
c9a1233
fix: support install prql-compiler from GitHub by Rust 1.61 and 1.64
eitsupi Feb 18, 2023
771004e
Revert "fix: support install prql-compiler from GitHub by Rust 1.61 a…
eitsupi Mar 15, 2023
b9daa54
Merge commit 'ef064e1a8c2de7e8340f7080169367f539e62a8c' into support-…
eitsupi Mar 15, 2023
cf4603d
fix: support install prql-compiler from GitHub by old Rust version
eitsupi Mar 15, 2023
ddd2cac
Revert "fix: support install prql-compiler from GitHub by old Rust ve…
eitsupi Apr 30, 2023
a33eac8
Merge commit '2d09a9f6f22831005c9bce3f8eb39e22beddd167' into support-…
eitsupi Apr 30, 2023
8423beb
fix: let else -> let if let else
eitsupi Apr 30, 2023
a384174
fix: support install prql-compiler from GitHub by old Rust version
eitsupi Apr 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions prql-compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[package]
description = "PRQL is a modern language for transforming data — a simple, powerful, pipelined SQL replacement."
edition = "2021"
license = "Apache-2.0"
name = "prql-compiler"

edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true
repository = "https://github.com/PRQL/prql"
version = "0.8.1"

metadata.msrv = "1.65.0"
metadata.msrv = "1.61.0"

[dependencies]
anyhow = {version = "1.0.57", features = ["backtrace"]}
Expand Down
4 changes: 3 additions & 1 deletion prql-compiler/src/semantic/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ impl Lowerer {
) -> Result<Vec<CId>> {
let mut r = Vec::with_capacity(exprs.len());
for expr in exprs {
let pl::ExprKind::All { except, .. } = expr.kind else {
let except = if let pl::ExprKind::All { except, .. } = expr.kind {
except
} else {
// base case
r.push(self.declare_as_column(expr, is_aggregation)?);
continue;
Expand Down
32 changes: 24 additions & 8 deletions prql-compiler/src/sql/gen_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ fn try_into_binary_op(expr: Expr, ctx: &mut Context) -> Result<Result<sql_ast::E
StringConcat,
];

let Some((decl, _)) = try_unpack(&expr, DECLS)? else {
let decl = if let Some((decl, _)) = try_unpack(&expr, DECLS)? {
decl
} else {
return Ok(Err(expr));
};

Expand All @@ -150,9 +152,12 @@ fn try_into_unary_op(expr: Expr, ctx: &mut Context) -> Result<Result<sql_ast::Ex
const DECLS: [super::std::FunctionDecl<1>; 2] = [STD_NEG, STD_NOT];
const OPS: [UnaryOperator; 2] = [Minus, Not];

let Some((decl, _)) = try_unpack(&expr, DECLS)? else {
let decl = if let Some((decl, _)) = try_unpack(&expr, DECLS)? {
decl
} else {
return Ok(Err(expr));
};

// this lookup is O(N), but 13 is not that big of a N
let decl_index = DECLS.iter().position(|x| x == &decl).unwrap();
let op = OPS[decl_index];
Expand Down Expand Up @@ -191,7 +196,9 @@ fn try_into_concat_function(expr: Expr, ctx: &mut Context) -> Result<Result<sql_
}

fn try_unpack_concat(expr: Expr) -> Result<Result<Vec<Expr>, Expr>> {
let Some((_, _)) = try_unpack(&expr, [STD_CONCAT])? else {
let () = if let Some((_, _)) = try_unpack(&expr, [STD_CONCAT])? {
()
} else {
return Ok(Err(expr));
};
let [left, right] = unpack(expr, STD_CONCAT);
Expand Down Expand Up @@ -531,8 +538,10 @@ pub(super) fn translate_select_item(cid: CId, ctx: &mut Context) -> Result<Selec
///
/// Outer Result contains an error, inner Result contains the unmatched expr.
fn try_into_is_null(expr: Expr, ctx: &mut Context) -> Result<Result<sql_ast::Expr, Expr>> {
let Some((decl, [a, b])) = try_unpack(&expr, [STD_EQ, STD_NE])? else {
return Ok(Err(expr))
let (decl, a, b) = if let Some((decl, [a, b])) = try_unpack(&expr, [STD_EQ, STD_NE])? {
(decl, a, b)
} else {
return Ok(Err(expr));
};

let take_a = if matches!(a.kind, ExprKind::Literal(Literal::Null)) {
Expand Down Expand Up @@ -565,14 +574,21 @@ fn try_into_is_null(expr: Expr, ctx: &mut Context) -> Result<Result<sql_ast::Exp
fn try_into_between(expr: Expr, ctx: &mut Context) -> Result<Result<sql_ast::Expr, Expr>> {
// validate that this expr matches the criteria

let Some((_, [a, b])) = try_unpack(&expr, [STD_AND])? else {
let (a, b) = if let Some((_, [a, b])) = try_unpack(&expr, [STD_AND])? {
(a, b)
} else {
return Ok(Err(expr));
};

let Some((_, [a_l, _a_r])) = try_unpack(a, [STD_GTE])? else {
let (a_l, a_r) = if let Some((_, [a_l, a_r])) = try_unpack(a, [STD_GTE])? {
(a_l, a_r)
} else {
return Ok(Err(expr));
};
let Some((_, [b_l, _b_r])) = try_unpack(b, [STD_LTE])? else {

let (b_l, b_r) = if let Some((_, [b_l, b_r])) = try_unpack(b, [STD_LTE])? {
(b_l, b_r)
} else {
return Ok(Err(expr));
};

Expand Down
30 changes: 20 additions & 10 deletions prql-compiler/src/sql/gen_projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ pub(super) fn try_into_exprs(
for cid in cids {
let decl = ctx.anchor.column_decls.get(&cid).unwrap();

let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl else {
// base case
res.push(translate_cid(cid, ctx)?);
continue;
};
let tiid = if let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl {
tiid
} else {
// base case
res.push(translate_cid(cid, ctx)?);
continue;
};

// star
let t = &ctx.anchor.table_instances[tiid];
Expand Down Expand Up @@ -72,7 +74,11 @@ pub(super) fn translate_wildcards(ctx: &AnchorContext, cols: Vec<CId>) -> (Vec<C
// requested.
// This function adds that column to the exclusion list.
fn exclude(star: &mut Option<(CId, HashSet<CId>)>, excluded: &mut Excluded) {
let Some((cid, in_star)) = star.take() else { return };
let (cid, in_star) = if let Some((cid, in_star)) = star.take() {
(cid, in_star)
} else {
return;
};
if in_star.is_empty() {
return;
}
Expand Down Expand Up @@ -128,9 +134,11 @@ pub(super) fn translate_select_items(
.map(|cid| {
let decl = ctx.anchor.column_decls.get(&cid).unwrap();

let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl else {
// general case
return translate_select_item(cid, ctx)
let tiid = if let ColumnDecl::RelationColumn(tiid, _, RelationColumn::Wildcard) = decl {
tiid
} else {
// base case
return translate_select_item(cid, ctx);
};

// wildcard case
Expand Down Expand Up @@ -161,7 +169,9 @@ fn translate_exclude(
) -> Option<WildcardAdditionalOptions> {
let excluded = as_col_names(&excluded, &ctx.anchor);

let Some(supported) = ctx.dialect.column_exclude() else {
let supported = if let Some(supported) = ctx.dialect.column_exclude() {
supported
} else {
// TODO: eventually this should throw an error
// I don't want to do this now, because we have no way around it.
// We could also ask the user to add table definitions.
Expand Down
36 changes: 31 additions & 5 deletions prql-compiler/src/sql/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ pub(super) fn union(pipeline: Vec<SqlTransform>) -> Vec<SqlTransform> {
let mut res = Vec::with_capacity(pipeline.len());
let mut pipeline = pipeline.into_iter().peekable();
while let Some(t) = pipeline.next() {
let Super(Append(bottom)) = t else {
let bottom = if let Super(Append(bottom)) = t {
bottom
} else {
res.push(t);
continue;
};
Expand Down Expand Up @@ -270,8 +272,21 @@ pub(super) fn except(pipeline: Vec<SqlTransform>, ctx: &Context) -> Result<Vec<S
if res.len() < 2 {
continue;
}
let Super(Join { side: JoinSide::Left, filter: join_cond, with }) = &res[res.len() - 2] else { continue };
let Super(Filter(filter)) = &res[res.len() - 1] else { continue };
let (with, join_cond) = if let Super(Join {
side: JoinSide::Left,
filter: join_cond,
with,
}) = &res[res.len() - 2]
{
(with, join_cond)
} else {
continue;
};
let filter = if let Super(Filter(filter)) = &res[res.len() - 1] {
filter
} else {
continue;
};

let top = AnchorContext::determine_select_columns(&res[0..res.len() - 2]);
let bottom = with.columns.iter().map(|(_, c)| *c).collect_vec();
Expand Down Expand Up @@ -352,7 +367,16 @@ pub(super) fn intersect(pipeline: Vec<SqlTransform>, ctx: &Context) -> Result<Ve
if res.is_empty() {
continue;
}
let Super(Join { side: JoinSide::Inner, filter: join_cond, with }) = &res[res.len() - 1] else { continue };
let (with, join_cond) = if let Super(Join {
side: JoinSide::Inner,
filter: join_cond,
with,
}) = &res[res.len() - 1]
{
(with, join_cond)
} else {
continue;
};

let top = AnchorContext::determine_select_columns(&res[0..res.len() - 1]);
let bottom = with.columns.iter().map(|(_, c)| *c).collect_vec();
Expand Down Expand Up @@ -514,7 +538,9 @@ impl RqFold for Normalizer {
..expr
};

let Some((decl, _)) = super::std::try_unpack(&expr, [super::std::STD_EQ])? else {
let decl = if let Some((decl, _)) = super::std::try_unpack(&expr, [super::std::STD_EQ])? {
decl
} else {
return Ok(expr);
};
let name = decl.name.to_string();
Expand Down