In Memory Tables · Attributes · Practice Question
Add, Confirm, and Remove a Grouped Attribute
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)- Add a grouped attribute to column
a. - Confirm that the attribute was applied.
- Remove the attribute again.
Solution
Add the attribute
update `g#a from `t@[`t;`a;`g#]Confirm the attribute
meta tattr t[`a]attr exec a from tattr @[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 `tapplies 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 tshows 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.