Skip to content

Add Expr::Exists to represent EXISTS subquery expression #2339

New issue

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

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

Already on GitHub? # to your account

Merged
merged 7 commits into from
Apr 26, 2022

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Apr 25, 2022

Which issue does this PR close?

Closes #2337 and is part of #2248

Rationale for this change

This is the first step towards supporting EXISTS subquery expressions. This work is partly based on work by @paveltiunov in cube-js@d14f0de

What changes are included in this PR?

  • Add Expr::Exists(Subquery) expression
  • Add LogicalPlan::Subquery, although that wasn't strictly necessary just to support EXISTS
  • Update optimizer rules
  • Add test that builds a plan with EXISTS using LogicalPlanBuilder

Are there any user-facing changes?

API change.

@andygrove andygrove added the api change Changes the API exposed to users of the crate label Apr 25, 2022
@andygrove andygrove self-assigned this Apr 25, 2022
@github-actions github-actions bot added ballista datafusion Changes in the datafusion crate labels Apr 25, 2022
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Very excited to see the PR 🚋 for subqueries leave the station, so to speak 👍


let outer_query = LogicalPlanBuilder::from(bar)
.project(vec![col("a")])?
.filter(exists(subquery))?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

// input: Arc::new(inputs[0].clone()),
// schema,
// }))
Err(DataFusionError::Plan("not implemented".to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err(DataFusionError::Plan("not implemented".to_string()))
Err(DataFusionError::Plan("subquery support is not full implemented yet".to_string()))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now implemented this section of code, although it is not exercised by any tests yet

@@ -180,6 +182,13 @@ pub fn approx_percentile_cont_with_weight(
}
}

/// Create an EXISTS subquery expression
pub fn exists(subquery: LogicalPlan) -> Expr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -180,6 +182,13 @@ pub fn approx_percentile_cont_with_weight(
}
}

/// Create an EXISTS subquery expression
pub fn exists(subquery: LogicalPlan) -> Expr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this function could take an Arc<LogicalPlan> so if someone already has one they can reuse it rather than making a copy to pass in here

@andygrove andygrove merged commit 6ae7d95 into apache:master Apr 26, 2022
@andygrove andygrove deleted the expr-exists branch April 26, 2022 02:25
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
api change Changes the API exposed to users of the crate datafusion Changes in the datafusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Expr::Exists to logical plan
2 participants