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

refactor: Remove double-negatives #2007

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion prql-compiler/src/sql/gen_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub(super) fn translate_cid(cid: CId, ctx: &mut Context) -> Result<sql_ast::Expr
}

pub(super) fn translate_star(ctx: &Context, span: Option<Span>) -> Result<String> {
if ctx.query.forbid_stars {
if !ctx.query.allow_stars {
Err(
Error::new_simple("Target dialect does not support * in this position.")
.with_span(span)
Expand Down
8 changes: 4 additions & 4 deletions prql-compiler/src/sql/gen_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn table_factor_of_table_ref(table_ref: TableRef, ctx: &mut Context) -> Result<T
// ensure that the table is declared
if let Some(sql_relation) = decl.relation.take() {
// if we cannot use CTEs
if ctx.query.forbid_ctes {
if !ctx.query.allow_ctes {
// restore relation for other references
decl.relation = Some(sql_relation.clone());

Expand Down Expand Up @@ -284,9 +284,9 @@ fn sql_select_query_of_pipeline(
.into_iter()
.next();
let group_by: Vec<CId> = aggregate.map(|(part, _)| part).unwrap_or_default();
ctx.query.forbid_stars = !ctx.dialect.stars_in_group();
ctx.query.allow_stars = ctx.dialect.stars_in_group();
let group_by = try_into_exprs(group_by, ctx, None)?;
ctx.query.forbid_stars = false;
ctx.query.allow_stars = true;

ctx.query.pre_projection = false;

Expand Down Expand Up @@ -428,7 +428,7 @@ fn sql_of_loop(pipeline: Vec<SqlTransform>, ctx: &mut Context) -> Result<Vec<Sql

// compile step (without producing CTEs)
ctx.push_query();
ctx.query.forbid_ctes = true;
ctx.query.allow_ctes = false;

let step = query_to_set_expr(sql_query_of_pipeline(step, ctx)?, ctx);

Expand Down
21 changes: 16 additions & 5 deletions prql-compiler/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct Context {
pub ctes: Vec<sqlparser::ast::Cte>,
}

#[derive(Default, Clone)]
#[derive(Clone)]
struct QueryOpts {
/// When true, column references will not include table names prefixes.
pub omit_ident_prefix: bool,
Expand All @@ -80,11 +80,22 @@ struct QueryOpts {
/// - ORDER BY needs `pre_projection=false`.
pub pre_projection: bool,

/// When true, queries will contain nested sub-queries instead of WITH CTEs.
pub forbid_ctes: bool,
/// When false, queries will contain nested sub-queries instead of WITH CTEs.
pub allow_ctes: bool,

/// When true, * are not allowed.
pub forbid_stars: bool,
/// When false, * are not allowed.
pub allow_stars: bool,
}

impl Default for QueryOpts {
fn default() -> Self {
QueryOpts {
omit_ident_prefix: false,
pre_projection: false,
allow_ctes: true,
allow_stars: true,
}
}
}

impl Context {
Expand Down