Skip to content

ORDER BY CASE WHEN ... END fails with NullPointerException on baseExpr.identifier #3777

@invidious9000

Description

@invidious9000

Environment

  • ArcadeDB v26.4.1-SNAPSHOT (latest)

Reproduction

CREATE VERTEX TYPE Concept
CREATE PROPERTY Concept.id STRING
CREATE PROPERTY Concept.status STRING
INSERT INTO Concept SET id = 'c1', status = 'open'
INSERT INTO Concept SET id = 'c2', status = 'settled'

-- FAILS:
SELECT id, status FROM Concept
ORDER BY CASE WHEN status = 'open' THEN 0 ELSE 1 END
LIMIT 10

Error: Failed to build ORDER BY item: Cannot read field "suffix" because "baseExpr.identifier" is null

What works

CASE WHEN in SELECT works fine. Ordering by the alias also works:

-- OK:
SELECT id, status, CASE WHEN status = 'open' THEN 0 ELSE 1 END AS sort_key
FROM Concept ORDER BY sort_key LIMIT 10

Expected

Inline CASE expressions in ORDER BY should work the same as in other SQL databases.

Workaround

Move the CASE expression to SELECT with an alias, ORDER BY the alias.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions