You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ossie.apache.org by "mattsenicksigma (via GitHub)" <gi...@apache.org> on 2026/09/20 21:19:46 UTC

[PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

mattsenicksigma opened a new pull request, #433:
URL: https://github.com/apache/ossie/pull/433

   ## Summary
   
   Fixes #426.
   
   `_render_sql_node` had no branch for `exp.Neg`, so `sql_to_sigma_formula` returned `None` for any negated SQL expression — even though the forward path (`-[X]` → `-"X"`) correctly emits `exp.Neg`.
   
   - Add an `exp.Neg` branch to `_render_sql_node` in `sigma_formula.py`
   - Add two parametrized test cases covering the repros from the issue: `-"X"` → `-[X]` and `-1` → `-1`
   
   No extra parentheses are needed: binary operator nodes already self-parenthesize in `_render_sql_node` (e.g. `Add` → `([A] + [B])`), so a bare `-` prefix handles all cases correctly.
   
   ## Test plan
   
   - [x] `uv run pytest tests/test_sigma_formula.py` — 53/53 passed including the two new negation cases
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on PR #433:
URL: https://github.com/apache/ossie/pull/433#issuecomment-5772134728

   I'm doing a new pass on this one. Thanks!


-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "mattsenicksigma (via GitHub)" <gi...@apache.org>.
mattsenicksigma commented on PR #433:
URL: https://github.com/apache/ossie/pull/433#issuecomment-5772180846

   Was just about to type a reply!
   
   Appreciate the thorough review. Likely should not have taken the issue suggestion at face value.
   
   Testing commands:
   ```
   cd converters/sigma
   uv run pytest tests/test_sigma_formula.py
   ```
   
   I am actively in the process of updating our deployment job at Sigma to be based on Ossie files rather than multiple semantic definitions, so I am hoping to find more bugs in near future/make formula conversion stronger, as there are some weird quirks in the dialect. Hoping that adding some `bi-sql-examples` for Sigma will aid in this repo's knowledgebase as well
   


-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #433:
URL: https://github.com/apache/ossie/pull/433#discussion_r4068968057


##########
converters/sigma/src/ossie_sigma/sigma_formula.py:
##########
@@ -690,6 +690,8 @@ def _render_sql_node(node: exp.Expression, dataset_alias: Optional[str]) -> str:
         return f"({_render_sql_node(node.this, dataset_alias)} AND {_render_sql_node(node.expression, dataset_alias)})"
     if isinstance(node, exp.Or):
         return f"({_render_sql_node(node.this, dataset_alias)} OR {_render_sql_node(node.expression, dataset_alias)})"
+    if isinstance(node, exp.Neg):

Review Comment:
   Yes, I agree, just wondering 😄 



-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #433:
URL: https://github.com/apache/ossie/pull/433#discussion_r4059685178


##########
converters/sigma/src/ossie_sigma/sigma_formula.py:
##########
@@ -690,6 +690,8 @@ def _render_sql_node(node: exp.Expression, dataset_alias: Optional[str]) -> str:
         return f"({_render_sql_node(node.this, dataset_alias)} AND {_render_sql_node(node.expression, dataset_alias)})"
     if isinstance(node, exp.Or):
         return f"({_render_sql_node(node.this, dataset_alias)} OR {_render_sql_node(node.expression, dataset_alias)})"
+    if isinstance(node, exp.Neg):

Review Comment:
   I think this regresses two input classes from a safe failure into an unsafe one.
   
   The bar `-{inner}` assumes every child renders self-delimited. Two reachable children don't: `DPipe`/`Concat` is the one binary operator branch that doesn't self parenthesize, and `Not` emits a bare `NOT (...)`.
   
   Today I believe it degrades visibly: the column drops and an `EXPRESSION_NOT_TRANSLATABLE` issue is logged. After this change it produces a formula our own `parse_formula`, and per `_resolve_formula` docstring the data model API validates the whole document before applying, so that fails the entire create/update upload rather than one column.
   
   I suggest to use:
   
   ```python
   if isinstance(node, exp.Neg):
            inner = _render_sql_node(node.this, dataset_alias)
            if isinstance(node.this, (exp.Column, exp.Literal)):
                return f"-{inner}"
            return f"-({inner})"
   ```
   
   The redundant parens on cases like `-SUM([X])` -> `(SUM([X]))` are harmless.
   
   Also the PR description justification ("binary operator nodes already self-parenthesize in `_render_sql_node`) isn't accurate for the Concat branch, which is what makes the bare prefix unsafe here. Maybe worth correcting so the next reviewer doesn't rely on it 😄 



##########
converters/sigma/tests/test_sigma_formula.py:
##########
@@ -129,6 +129,8 @@ def test_is_plain_column_ref():
         ("SUM(ss_ext_sales_price)", "store_sales", "Sum([ss_ext_sales_price])"),
         ("COUNT(DISTINCT customer_id)", "customer", "CountDistinct([customer_id])"),
         ("CASE WHEN status = 'won' THEN 1 ELSE 0 END", "deals", 'If((["status"] = "won"), 1, 0)'.replace('["status"]', "[status]")),
+        ('-"X"', "T", "-[X]"),

Review Comment:
   This is related to the other comment.
   
   These assert string equality on the two simplest inputs, so nothing here would crash. I have two proposals:
   
   1. Add `assert parse_formula(result) is not None` to `test_reverse_translation_basic`, that alone catches the `-(NOT "A")` regression, and several pre-existing emit-an-invalid-formula bugs.
   2. Add the compound cases:
   
   ```
           ('-(NOT "A")', "T", "-(NOT ([A]))"),
           ('-("A" || "B")', "T", "-([A] & [B])"),
           ('-("A" + "B")', "T", "-(([A] + [B]))"),
           ('-(-"A")', "T", "-(-[A])"),
   ```
   
   Nit: `('-"X"', "T", "-[X]")` passes `dataset_alias="T"` that the case never exercises, since the column is unqualified, `'-"T","X"'` would.



-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "mattsenicksigma (via GitHub)" <gi...@apache.org>.
mattsenicksigma commented on code in PR #433:
URL: https://github.com/apache/ossie/pull/433#discussion_r4068944752


##########
converters/sigma/tests/test_sigma_formula.py:
##########
@@ -129,6 +129,8 @@ def test_is_plain_column_ref():
         ("SUM(ss_ext_sales_price)", "store_sales", "Sum([ss_ext_sales_price])"),
         ("COUNT(DISTINCT customer_id)", "customer", "CountDistinct([customer_id])"),
         ("CASE WHEN status = 'won' THEN 1 ELSE 0 END", "deals", 'If((["status"] = "won"), 1, 0)'.replace('["status"]', "[status]")),
+        ('-"X"', "T", "-[X]"),

Review Comment:
   gave this some thought:
   
   1. added this check, seems overall net stronger to check
   
   2. Added these test cases
   
   on the nit, i've added a new test case below to look to exercise alias collapsing and updated the two pre-existing negation test cases to have `None` dataset aliases to serve as direct tests of the negation behaviour
   
   ```
           ('-"T"."X"', "T", "-[X]"),
   ```



-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "mattsenicksigma (via GitHub)" <gi...@apache.org>.
mattsenicksigma commented on code in PR #433:
URL: https://github.com/apache/ossie/pull/433#discussion_r4068875484


##########
converters/sigma/src/ossie_sigma/sigma_formula.py:
##########
@@ -690,6 +690,8 @@ def _render_sql_node(node: exp.Expression, dataset_alias: Optional[str]) -> str:
         return f"({_render_sql_node(node.this, dataset_alias)} AND {_render_sql_node(node.expression, dataset_alias)})"
     if isinstance(node, exp.Or):
         return f"({_render_sql_node(node.this, dataset_alias)} OR {_render_sql_node(node.expression, dataset_alias)})"
+    if isinstance(node, exp.Neg):

Review Comment:
   I pondered this one over and this makes sense, the self-parenthesizing behaviour seems visibly false now, agreed on returning the parentheses as additional safety and implemented this as such. This certainly seems permissible.



-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on code in PR #433:
URL: https://github.com/apache/ossie/pull/433#discussion_r4068969716


##########
converters/sigma/tests/test_sigma_formula.py:
##########
@@ -129,6 +129,8 @@ def test_is_plain_column_ref():
         ("SUM(ss_ext_sales_price)", "store_sales", "Sum([ss_ext_sales_price])"),
         ("COUNT(DISTINCT customer_id)", "customer", "CountDistinct([customer_id])"),
         ("CASE WHEN status = 'won' THEN 1 ELSE 0 END", "deals", 'If((["status"] = "won"), 1, 0)'.replace('["status"]', "[status]")),
+        ('-"X"', "T", "-[X]"),

Review Comment:
   That's great! Thanks for that, it helps!



-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on PR #433:
URL: https://github.com/apache/ossie/pull/433#issuecomment-5772194798

   @mattsenicksigma sounds good 😊 Happy to help 😀 


-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(sigma): handle unary negation in sql_to_sigma_formula reverse translation [ossie]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre merged PR #433:
URL: https://github.com/apache/ossie/pull/433


-- 
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: issues-unsubscribe@ossie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org