Expressions#
Vortex expressions represent simple filtering conditions on the rows of a Vortex array. For example, the following expression represents the set of rows for which the age column lies between 23 and 55:
>>> import vortex
>>> age = vortex.expr.column("age")
>>> (23 > age) & (age < 55)
A named column. |
|
An expression describes how to filter rows when reading an array from a file. |
- vortex.expr.column(name)#
A named column.
See also
Example
A filter that selects only those rows whose name is Joseph:
>>> name = vortex.expr.column("name") >>> filter = name == "Joseph"
See
Expr
for more examples.
- class vortex.expr.Expr#
An expression describes how to filter rows when reading an array from a file.
See also
Examples
All the examples read the following file.
>>> a = vortex.array([ ... {'name': 'Joseph', 'age': 25}, ... {'name': None, 'age': 31}, ... {'name': 'Angela', 'age': None}, ... {'name': 'Mikhail', 'age': 57}, ... {'name': None, 'age': None}, ... ]) >>> vortex.io.write_path(a, "a.vortex")
Read only those rows whose age column is greater than 35:
>>> e = vortex.io.read_path("a.vortex", row_filter = vortex.expr.column("age") > 35) >>> e.to_arrow_array() <pyarrow.lib.StructArray object at ...> -- is_valid: all not null -- child 0 type: int64 [ 57 ] -- child 1 type: string_view [ "Mikhail" ]
Read only those rows whose age column lies in (21, 33]. Notice that we must use parentheses because of the Python precedence rules for
&
:>>> age = vortex.expr.column("age") >>> e = vortex.io.read_path("a.vortex", row_filter = (age > 21) & (age <= 33)) >>> e.to_arrow_array() <pyarrow.lib.StructArray object at ...> -- is_valid: all not null -- child 0 type: int64 [ 25, 31 ] -- child 1 type: string_view [ "Joseph", null ]
Read only those rows whose name is Joseph:
>>> name = vortex.expr.column("name") >>> e = vortex.io.read_path("a.vortex", row_filter = name == "Joseph") >>> e.to_arrow_array() <pyarrow.lib.StructArray object at ...> -- is_valid: all not null -- child 0 type: int64 [ 25 ] -- child 1 type: string_view [ "Joseph" ]
Read all the rows whose name is _not_ Joseph
>>> name = vortex.expr.column("name") >>> e = vortex.io.read_path("a.vortex", row_filter = name != "Joseph") >>> e.to_arrow_array() <pyarrow.lib.StructArray object at ...> -- is_valid: all not null -- child 0 type: int64 [ null, 57 ] -- child 1 type: string_view [ "Angela", "Mikhail" ]
Read rows whose name is Angela or whose age is between 20 and 30, inclusive. Notice that the Angela row is included even though its age is null. Under SQL / Kleene semantics, true or null is true.
>>> name = vortex.expr.column("name") >>> e = vortex.io.read_path("a.vortex", row_filter = (name == "Angela") | ((age >= 20) & (age <= 30))) >>> e.to_arrow_array() <pyarrow.lib.StructArray object at ...> -- is_valid: all not null -- child 0 type: int64 [ 25, null ] -- child 1 type: string_view [ "Joseph", "Angela" ]