Skip to content

Complex Type Expressions

These APIs are available on arrays, maps and structs.

ArrayValue (Value)

Methods

length(self)

Compute the length of an array.

Examples:

>>> import ibis
>>> a = ibis.array([1, 2, 3])
>>> a.length()
ArrayLength((1, 2, 3))

Returns:

Type Description
ir.IntegerValue

The integer length of self

unnest(self)

Unnest an array.

Returns:

Type Description
ir.Value

Unnested array

StructValue (Value)

Attributes

fields: Mapping[str, dt.DataType] cached property writable

Return a mapping from field name to field type of the struct.

names: Sequence[str] cached property writable

Return the field names of the struct.

types: Sequence[dt.DataType] cached property writable

Return the field types of the struct.

Methods

destructure(self)

Destructure self into a DestructValue.

When assigned, a destruct value will be destructured and assigned to multiple columns.

Returns:

Type Description
DestructValue

A destruct value expression.

lift(self)

Project the fields of self into a table.

This method is useful when analyzing data that has deeply nested structs or arrays of structs. lift can be chained to avoid repeating column names and table references.

See also Table.unpack.

Examples:

>>> schema = dict(a="struct<b: float, c: string>", d="string")
>>> t = ibis.table(schema, name="t")
>>> t
UnboundTable: t
  a struct<b: float64, c: string>
  d string
>>> t.a.lift()
r0 := UnboundTable: t
  a struct<b: float64, c: string>
  d string

Selection[r0] selections: b: StructField(r0.a, field='b') c: StructField(r0.a, field='c')

Returns:

Type Description
ir.Table

A projection with this struct expression's fields.

MapValue (Value)

Methods

get(self, key, default=None)

Return the value for key from expr or the default if key is not in the map.

Parameters:

Name Type Description Default
key ir.Value

Expression to use for key

required
default ir.Value | None

Expression to return if key is not a key in expr

None

Examples:

>>> import ibis
>>> m = ibis.map({"a": 1, "b": 2})
>>> m.get("a")
MapValueOrDefaultForKey(frozendict({'a': 1, 'b': 2}), key='a', default=None)
>>> m.get("c", 3)
MapValueOrDefaultForKey(frozendict({'a': 1, 'b': 2}), key='c', default=3)
>>> m.get("d")
MapValueOrDefaultForKey(frozendict({'a': 1, 'b': 2}), key='d', default=None)

Returns:

Type Description
ir.Value

The element type of self

keys(self)

Extract the keys of a map.

Examples:

>>> import ibis
>>> m = ibis.map({"a": 1, "b": 2})
>>> m.keys()
MapKeys(frozendict({'a': 1, 'b': 2}))

Returns:

Type Description
ir.ArrayValue

The keys of self

length(self)

Return the number of key-value pairs in the map.

Examples:

>>> import ibis
>>> m = ibis.map({"a": 1, "b": 2})
>>> m.length()
MapLength(frozendict({'a': 1, 'b': 2}))

Returns:

Type Description
ir.IntegerValue

The number of elements in self

values(self)

Extract the values of a map.

Examples:

>>> import ibis
>>> m = ibis.map({"a": 1, "b": 2})
>>> m.keys()
MapKeys(frozendict({'a': 1, 'b': 2}))

Returns:

Type Description
ir.ArrayValue

The values of self


Last update: August 5, 2022