Group

Relation-valued attribute

Signature

group(operand: Relation, attributes: AttrList, as: AttrName) -> Relation

Examples

group(suppliers, [:sid, :name, :status], :suppliers)
group(suppliers, [:city], :suppliers, allbut: true)

Description

Summarizes operand by all but the specified attributes and groups the latter under a relation-value attribute as.

This operator could be formally defined as the following shortcut:

def group(operand, attributes, as)
  extend(
    allbut(operand, attributes),
    as: ->(t){ project(matching(operand, Relation(t)), attributes) })
end
group(suppliers, [:sid, :name, :status], :suppliers)

This operators supports an ALL BUT variant, through the allbut option. When set to true, the operator keeps specified attributes and groups all remaining ones as a relation-valued attribute.

Implementation notes

This operator does not compile to SQL so far. Contributions are welcome to provide it with a SQL compilation for SQL DBMSs that support this kind of feature (e.g. PostgreSQL with JSON data type)