betodealmeida opened a new pull request, #39976:
URL: https://github.com/apache/superset/pull/39976

   <!---
   Please write the PR title following the conventions at 
https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   
   Today, in order to apply RLS we need to:
   
   1. Parse the SQL into an AST;
   2. Modify the AST;
   3. Render the AST into SQL.
   
   Because we support 50+ different databases, and not all of them have a 
`sqlglot` dialect, this roundtrip can produce invalid or incorrect SQL. One 
common error is that non-standard SQL functions get replaced by standard SQL 
functions when parsed with the generic parser; other common problem is 
non-standard syntax failing to parser.
   
   We currently have 2 different methods to apply RLS:
   
   1. `RLSMethod.AS_PREDICATE`: injects predicates whenever an associated table 
is referenced.
   2. `RLSMethod.AS_SUBQUERY`: converts the table reference into a subquery 
with the associated predicate.
   
   This PR introduces a third, experimental, method callled 
`RLSMethod.AS_PREDICATE_SPLICE`. It's meant to be used for DB where the current 
flow is unreliable. It works the following way:
   
   1. The SQL is parsed into an AST;
   2. We traverse the AST, but instead of modifying it we keep track of the 
offsets in the original SQL where the predicate would be injected;
   3. We insert the predicates in the original string, from right to left.
   
   This way the SQL doesn't have to go all the way through the 
string->AST->string roundtrip. It just needs to be parsed.
   
   
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   N/A
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to