Retrieves a list of field names from a record.
keys(x:record) -> list<string>
Description
Section titled “Description”The keys
function returns a list of strings containing all field names from
the input record x
.
x: record
Section titled “x: record”The record whose field names you want to retrieve.
Examples
Section titled “Examples”Get all field names from a record
Section titled “Get all field names from a record”from {x: 1, y: "hello", z: true}select field_names = this.keys()
{ field_names: ["x", "y", "z"],}
Use keys to dynamically access record fields
Section titled “Use keys to dynamically access record fields”You can combine keys
with sorting and element access to dynamically select
fields from records. For example, the following collects the values from the
element with the first key alphabetically in each record:
from ( {foo: 10, bar: 20, baz: 30}, {foo: 100, bar: 200}, {baz: 300, qux: 400}, {},)summarize first_sorted_key = this[this.keys().sort().first()]?.collect()
{ first_sorted_key: [20, 200, 300],}
Use keys to get distribution of available fields
Section titled “Use keys to get distribution of available fields”from ( {foo: 10, bar: 20, baz: 30}, {foo: 100, bar: 200}, {baz: 300, qux: 400}, {},)select key = this.keys()unroll keytop key
{name: "foo", count: 2}{name: "bar", count: 2}{name: "baz", count: 2}{name: "qux", count: 1}