-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
fix: adhoc metrics #30202
base: master
Are you sure you want to change the base?
fix: adhoc metrics #30202
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really excited to see this happening! Minor nit + question on some of the removed logic
@@ -1177,46 +1106,31 @@ class InsertRLSState(StrEnum): | |||
FOUND_TABLE = "FOUND_TABLE" | |||
|
|||
|
|||
def has_table_query(token_list: TokenList) -> bool: | |||
def has_table_query(expression: str, engine: str) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd maybe using statement
instead of expression
in this context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it can be an actual expression, since we use for validating adhoc metrics — it could be COUNT(*)
, eg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, let's rewrite this take a statement, and we can wrap it in a SELECT ()
where we have only an expression.
# Recurse into child token list | ||
if isinstance(token, TokenList) and has_table_query(token): | ||
return True | ||
|
||
# Found a source keyword (FROM/JOIN) | ||
if imt(token, m=[(Keyword, "FROM"), (Keyword, "JOIN")]): | ||
state = InsertRLSState.SEEN_SOURCE | ||
|
||
# Found identifier/keyword after FROM/JOIN | ||
elif state == InsertRLSState.SEEN_SOURCE and ( | ||
isinstance(token, sqlparse.sql.Identifier) or token.ttype == Keyword | ||
): | ||
return True | ||
|
||
# Found nothing, leaving source | ||
elif state == InsertRLSState.SEEN_SOURCE and token.ttype != Whitespace: | ||
state = InsertRLSState.SCANNING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these no longer needed for injecting RLS state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, confusingly here we're just using the InsertRLSState
enum do to the table scan.
(I also have a PR almost ready where I move all the RLS functions to sqlglot
.)
SUMMARY
Rewrite
has_table_query
to usesqlglot
instead ofsqlparse
.Part of SIP-117.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
The current tests pass. Also added a regression that was not passing with
sqlparse
.ADDITIONAL INFORMATION