Skip to content

Conversation

@seddonm1
Copy link
Contributor

@seddonm1 seddonm1 commented Aug 1, 2021

Which issue does this PR close?

Closes #809.

Rationale for this change

Due to the way the field qualification works a query this does not work as technically the field is qualified but the matching only works on complete matches between the field qualifier person and the schema qualifier public.person.

SELECT person.first_name FROM public.person

What changes are included in this PR?

This PR adds:

  • ability to partially match qualified fields against the schema.
  • a rewrite step in the logical planner to rewrite the partial match to a fully resolved qualifier so it can be used downstream.

Are there any user-facing changes?

No, just more standard Postgres SQL will work.

Copy link
Member

@houqp houqp left a comment

Choose a reason for hiding this comment

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

good catch 👍

@houqp houqp added bug Something isn't working sql SQL Planner labels Aug 2, 2021
@seddonm1
Copy link
Contributor Author

seddonm1 commented Aug 2, 2021

@houqp Thank you for your comments. I have addressed them and pushed the new code.

Copy link
Member

@houqp houqp left a comment

Choose a reason for hiding this comment

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

Thank you @seddonm1 !

@houqp houqp requested review from Dandandan, alamb and andygrove August 3, 2021 06:54
@seddonm1
Copy link
Contributor Author

seddonm1 commented Aug 3, 2021

thanks @houqp !

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 -- thanks @seddonm1 I have some stylistic questions, but the tests look good to me 👍


/// Rewrite aliases which are not-complete (e.g. ones that only include only table qualifier in a schema.table qualified relation)
fn rewrite_partial_qualifier(&self, expr: Expr, schema: &DFSchema) -> Expr {
match expr.clone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

given you are passing in expr here, I wonder if we could remove the call to clone and save a copy?

let expr = self.sql_expr_to_logical_expr(sql, schema)?;
let mut expr = self.sql_expr_to_logical_expr(sql, schema)?;
self.validate_schema_satisfies_exprs(schema, &[expr.clone()])?;
expr = self.rewrite_partial_qualifier(expr, schema);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should do the rewrite prior to calling validate_schema_satisfies_exprs?

@seddonm1
Copy link
Contributor Author

seddonm1 commented Aug 3, 2021

@alamb I have taken your feedback and managed to remove the dfschema.rs changes entirely. I think this is ready now.

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.

I think it looks very good -- thanks @seddonm1. Thank you.

@alamb alamb merged commit b8b0465 into apache:master Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qualified field resolution too strict

3 participants