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

Support multi-column-expr when doing a SELECT #4453

Merged
merged 2 commits into from
Jul 28, 2023

Conversation

Adriel-M
Copy link
Contributor

@Adriel-M Adriel-M commented Jul 27, 2023

@Adriel-M
Copy link
Contributor Author

A change to allow me to understand how multi_column_expr works.

In the future I want to support:

DELETE FROM table
WHERE (colA, colB) IN ((?, ?), (?, ?))

which will used to deleting by a composite primary key.

But this is not supported in sql-psi.

val parentParent = parentRule.parent as SqlMultiColumnExpr

// The first multiColumnExpression is the column list
parentParent.multiColumnExpressionList[0].exprList[idx].type()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I assume this will not return null?

From https://github.com/AlecStrong/sql-psi/blob/master/core/src/main/kotlin/com/alecstrong/sql/psi/core/sql.bnf#L237

these two expressions are not optional.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes

@Adriel-M Adriel-M marked this pull request as ready for review July 27, 2023 20:15
Comment on lines +1912 to +1913
| bindLong(0, id)
| bindString(1, name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The types look right here

Copy link
Collaborator

@hfhbd hfhbd left a comment

Choose a reason for hiding this comment

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

Very nice, thank you!

@hfhbd
Copy link
Collaborator

hfhbd commented Jul 28, 2023

@Adriel-M Please run './gradlew :spotlessApply' to fix the code violations.

@Adriel-M
Copy link
Contributor Author

@hfhbd linted

@Adriel-M
Copy link
Contributor Author

@hfhbd btw, the linked issue wouldn't be resolved.

IN isn't part of of multi_column_expr. It would probably need a new expr that looks something like:

multi_column_in_expr ::= multi_column_expression IN LP multi_column_expression (COMMA multi_column_expression) * RP {
  pin = 2
}

@hfhbd
Copy link
Collaborator

hfhbd commented Jul 28, 2023

@Adriel-M yeah you are right, will reopen it.

@hfhbd hfhbd merged commit aa889ee into cashapp:master Jul 28, 2023
6 checks passed
hfhbd pushed a commit that referenced this pull request Apr 2, 2024
* Support multi-column-expr when doing a SELECT

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants