-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Motivation
We seem to currently lack a mechanism to extract and operate on elements of collection-valued properties in a collection of entities. For example, given:
[
{ "id": 1, "tags": ["a", "b"] },
{ "id": 2, "tags": ["b", "c"] }
]
There seems to be standard way to query for the unique set of tags ["a", "b", "c"]
using
$apply`. This capability is essential for analytics, faceted search, and tag-based filtering scenarios.
Overview
This proposal introduces a new transformation keyword, flatten
and distinct, to the apply
system query option in OData. It enables composable projection of scalar values from collection-valued properties, allowing operations such as deduplication (distinct()
), aggregation, and filtering to be performed on the flattened stream.
3.1 Transformation Grammar Extension
flatten
transformation :
Extend the $apply
transformation grammar to include:
apply = ... / flatten
flatten = "flatten" "(" propertyPath [ "as" alias ] ")"
Where:
• propertyPath
is a collection-valued property.
• alias
is an optional identifier used to name the flattened scalar value.
which transforms the collection into collection of the values of the given property path with property name given by the alias
[
{ "tag": "a" },
{ "tag": "b" },
{ "tag": "c" }
]
note: flatten sounds a little bit colloquial but is on the other hand closer to English than flatMap or selectMany which are terms from functional languages and algebraic data processing
distinct
transformation :
Extend the $apply
transformation grammar to include:
apply = ... / distinct
distinct= "distinct()"
which transforms the collection into the collection of the same structure with duplicate values removed (TODO: precise meaning of duplicate, is this structural equality ?)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status