atoti.Table.query()#

Table.query(*columns, filter=None, max_rows=2147483646, timeout=datetime.timedelta(seconds=30))#

Query the table to retrieve some of its rows.

If the table has more than max_rows rows matching filter, the set of returned rows is unspecified and can change from one call to another.

As opposed to head(), the returned DataFrame will not be indexed by the table’s keys since columns may lack some of them.

Parameters:
  • columns (Column) – The columns to query. If empty, all the columns of the table will be queried.

  • filter (Condition[ColumnIdentifier, Literal['eq', 'ge', 'gt', 'le', 'lt', 'ne', 'isin'], Constant, ~typing.Literal['and', 'or'] | None] | None) – The filtering condition. Only rows matching this condition will be returned.

  • max_rows (int) – The maximum number of rows to return.

  • timeout (timedelta) – The duration the query execution can take before being aborted.

Return type:

DataFrame

Example

>>> df = pd.DataFrame(
...     columns=["Continent", "Country", "Currency", "Price"],
...     data=[
...         ("Europe", "France", "EUR", 200.0),
...         ("Europe", "Germany", "EUR", 150.0),
...         ("Europe", "United Kingdom", "GBP", 120.0),
...         ("America", "United states", "USD", 240.0),
...         ("America", "Mexico", "MXN", 270.0),
...     ],
... )
>>> table = session.read_pandas(
...     df,
...     keys=["Continent", "Country", "Currency"],
...     table_name="Prices",
... )
>>> result = table.query(filter=table["Price"] >= 200)
>>> result.set_index(list(table.keys)).sort_index()
                                  Price
Continent Country       Currency
America   Mexico        MXN       270.0
          United states USD       240.0
Europe    France        EUR       200.0