Skip to content

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
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

}

/// 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.

}

/// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Expr::Exists to logical plan

2 participants