Back to Attributes

In Memory Tables · Attributes · Practice Question

Add, Confirm, and Remove a Grouped Attribute

Sign in to track your progress

Question

Given a table t with a symbol column a, for example:

t:([] a:`x`y`x`z`y; b:1 2 3 4 5)
  1. Add a grouped attribute to column a.
  2. Confirm that the attribute was applied.
  3. Remove the attribute again.

Solution

Add the attribute

update `g#a from `t
@[`t;`a;`g#]

Confirm the attribute

meta t
attr t[`a]
attr exec a from t
attr @[t;`a]

Remove the attribute

update `#a from `t
@[`t;`a;`#]

Explanation

Adding the attribute

The grouped attribute (`g#) builds a hash index over a column, speeding up grouped operations (by, group, equality where clauses) on columns with many repeated values, regardless of whether the column is sorted.

update `g#a from `t

applies it via qSQL — note the table name is passed as a symbol (`t) so the update happens in place. @[t;a;g#]reaches the same result using amend: apply the function ``g# `` to column a of t.

Confirming the attribute

meta t

shows an a (attribute) column alongside each column's type — a g there confirms the grouped attribute is set. attr t[a]asks the column itself directly and returns the attribute symbol (``g ``); attr exec a from t and attr @[t;a]are two more ways of pulling the same column out oftbefore askingattr` about it.

Removing the attribute

`# (with nothing before the #) clears whatever attribute is currently set — update #a from t and @[t;a;#]` are the qSQL and amend forms of the same removal, mirroring exactly how the attribute was applied in the first place.