-
Notifications
You must be signed in to change notification settings - Fork 20
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
When using %context.getResourceKey() inside a forEach branch within a unionAll, Pathling throws an InvalidUserInputError:
InvalidUserInputError: Function 'getResourceKey', input: Type mismatch: expected ResourceCollection but got Collection
Per the SQL on FHIR spec, %context within a forEach inside a unionAll should refer to the resource root. Pathling appears to resolve %context as a generic Collection rather than a ResourceCollection, which causes getResourceKey() to reject the input.
Minimal reproduction
from pathling import PathlingContext
pc = PathlingContext.create(enable_extensions=True)
ds = pc.read.ndjson("/path/to/ndjson")
view_json = """
{
"resourceType": "ViewDefinition",
"resource": "Observation",
"status": "draft",
"name": "test",
"where": [
{"path": "category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/observation-category' and code = 'vital-signs').exists()"}
],
"select": [
{
"unionAll": [
{
"column": [
{"name": "id", "path": "getResourceKey()", "type": "string"},
{"name": "code_value", "path": "code.coding.first().code", "type": "code"},
{"name": "value_number", "path": "value.ofType(Quantity).value", "type": "decimal"}
]
},
{
"forEach": "component",
"column": [
{"name": "id", "path": "%context.getResourceKey()", "type": "string"},
{"name": "code_value", "path": "code.coding.first().code", "type": "code"},
{"name": "value_number", "path": "value.ofType(Quantity).value", "type": "decimal"}
]
}
]
}
]
}
"""
df = ds.view(json=view_json) # Throws InvalidUserInputErrorWorkaround
Move resource-level columns (those using getResourceKey(), subject.getReferenceKey(), etc.) into a separate top-level select outside the unionAll, and keep only the differing columns inside the unionAll branches:
{
"select": [
{
"column": [
{"name": "id", "path": "getResourceKey()", "type": "string"}
]
},
{
"unionAll": [
{
"column": [
{"name": "code_value", "path": "code.coding.first().code", "type": "code"}
]
},
{
"forEach": "component",
"column": [
{"name": "code_value", "path": "code.coding.first().code", "type": "code"}
]
}
]
}
]
}Environment
- pathling 9.4.0
- PySpark 4.0.2
- Python 3.14.2
- macOS (Darwin 25.3.0, arm64)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done