Skip to content

Conversation

knassre-bodo
Copy link
Contributor

@knassre-bodo knassre-bodo commented Aug 26, 2025

Followup to #417, performs the following rewrites on relational algebra expressions involving UNMASK operations:

  • UNMASK(expr) == literal -> expr == MASK(literal)
  • UNMASK(expr) != literal -> expr != MASK(literal)
  • ISIN(UNMASK(expr), [literal1, literal2, ...]) -> ISIN(expr, [MASK(literal1), MASK(literal2), ...])

These rewrites are done through an additional shuttle run during relational simplification, which is only activated if the environment variable PYDOUGH_ENABLE_MASK_REWRITES is set to 1.

Comment on lines +310 to +311
# If the literal is a list or tuple, convert each element
# individually and create an array literal.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed because now, with the recent changes, a "list literal" can contain non-literal expressions, e.g. a list of function calls [MASK("foo"), MASK("bar")]

@knassre-bodo knassre-bodo marked this pull request as ready for review September 29, 2025 21:28
Base automatically changed from kian/masked_relational_rewrite to main September 30, 2025 01:24
"server masked": true,
"unprotect protocol": "PTY_UNPROTECT({}, 'deName')",
"protect protocol": "PTY_PROTECT({}, 'deName)",
"protect protocol": "PTY_PROTECT({}, 'deName')",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed earlier, cuases a bug in this PR because protect protocol isn't actually used until now.

@knassre-bodo knassre-bodo requested review from a team, hadia206, john-sanchez31 and juankx-bodo and removed request for a team September 30, 2025 17:29
Copy link
Contributor

@john-sanchez31 john-sanchez31 left a comment

Choose a reason for hiding this comment

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

Good job Kian!

Copy link
Contributor

@hadia206 hadia206 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.
I just have some questions

- `UNMASK(x) IN (literal1, ..., literalN)` -> `x IN (MASK(literal1), ..., MASK(literalN))`
"""

def protect_literal_comparison(
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, the name should be rewrite_masked_literal_comparison

Comment on lines +21 to +25
- `UNMASK(x) == literal` -> `x == MASK(literal)`
- `literal == UNMASK(x)` -> `MASK(literal) == x`
- `UNMASK(x) != literal` -> `x != MASK(literal)`
- `literal != UNMASK(x)` -> `MASK(literal) != x`
- `UNMASK(x) IN (literal1, ..., literalN)` -> `x IN (MASK(literal1), ..., MASK(literalN))`
Copy link
Contributor

Choose a reason for hiding this comment

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

Questions:
1- What would happen if the literal value is None ?
2- Is it possible to have nested calls? UNMASK(UNMASK(x)) == literal. If yes, then how would that be handled?
3- Why only equality/inequality? What about other comparison operations (>, >=, <, <=)?

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.

3 participants