Skip to content

unparser: a searched CASE is written as a searched CASE - #65

Merged
stbischof merged 1 commit into
eclipse-daanse:mainfrom
dbulahov:case-unparser
Nov 26, 2026
Merged

stbischof merged 1 commit into
eclipse-daanse:mainfrom
dbulahov:case-unparser

Conversation

@dbulahov

Copy link
Copy Markdown
Contributor

What does this PR do?

SimpleUnparser matched CaseOperationAtom without reading its name, so the searched form (_CaseTest) was written like the simple one (_CaseMatch): the first condition became the operand. CASE WHEN [Measures].[A] > 1 THEN 1 ELSE 0 END came back as CASE [Measures].[A] > 1 WHEN 1 THEN 0 END, valid MDX with another meaning. An ELSE without a WHEN was dropped (CASE a ELSE d END gave CASE a END), and CASE END threw IndexOutOfBoundsException.

The unparser now writes each form by its name; an unknown name, or a simple CASE without its operand, is refused with IllegalArgumentException. CaseOperationAtom gains the constants CASE_MATCH and CASE_TEST, used by both grammars and the unparser.

Tests: unparser.simple SimpleUnparserExpressionTest, combinedtest RoundTripTest (searched and mixed nesting, ccc and cccx), parser.tck ExpressionTest pins the _CaseTest atom.

SimpleUnparser matched CaseOperationAtom without reading its name, so the
searched form (_CaseTest) was written like the simple one (_CaseMatch): the
first condition became the operand. CASE WHEN [Measures].[A] > 1 THEN 1
ELSE 0 END came back as CASE [Measures].[A] > 1 WHEN 1 THEN 0 END, valid MDX
with another meaning. An ELSE without a WHEN was dropped (CASE a ELSE d END
gave CASE a END), and CASE END threw IndexOutOfBoundsException.

The unparser now writes each form by its name; an unknown name, or a simple
CASE without its operand, is refused with IllegalArgumentException.
CaseOperationAtom gains the constants CASE_MATCH and CASE_TEST, used by both
grammars and the unparser.

Tests: unparser.simple SimpleUnparserExpressionTest, combinedtest
RoundTripTest (searched and mixed nesting, ccc and cccx), parser.tck
ExpressionTest pins the _CaseTest atom.

Signed-off-by: dbulahov <bulahovdenis@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

@stbischof
stbischof merged commit e2c5a37 into eclipse-daanse:main Nov 26, 2026
14 checks passed
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.

2 participants