Skip to content

Commit 7f0acbe

Browse files
authored
feat: Query for data (#37)
1 parent bc00715 commit 7f0acbe

File tree

7 files changed

+473
-58
lines changed

7 files changed

+473
-58
lines changed

nisystemlink/clients/dataframe/_data_frame_client.py

+30
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,33 @@ def append_table_data(self, id: str, data: models.AppendTableDataRequest) -> Non
197197
data: The rows of data to append and any additional options.
198198
"""
199199
...
200+
201+
@post("tables/{id}/query-data", args=[Path, Body])
202+
def query_table_data(
203+
self, id: str, query: models.QueryTableDataRequest
204+
) -> models.PagedTableRows:
205+
"""Reads rows of data that match a filter from the table identified by its ID.
206+
207+
Args:
208+
id: Unique ID of a DataFrame table.
209+
query: The filtering and sorting to apply when reading data.
210+
211+
Returns:
212+
models.PagedTableRows: The table data and total number of rows with a continuation token.
213+
"""
214+
...
215+
216+
@post("tables/{id}/query-decimated-data", args=[Path, Body])
217+
def query_decimated_data(
218+
self, id: str, query: models.QueryDecimatedDataRequest
219+
) -> models.TableRows:
220+
"""Reads decimated rows of data from the table identified by its ID.
221+
222+
Args:
223+
id: Unique ID of a DataFrame table.
224+
query: The filtering and decimation options to apply when reading data.
225+
226+
Returns:
227+
models.TableRows: The decimated table data.
228+
"""
229+
...

nisystemlink/clients/dataframe/models/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
from ._order_by import OrderBy
1313
from ._paged_tables import PagedTables
1414
from ._paged_table_rows import PagedTableRows
15+
from ._query_decimated_data_request import (
16+
DecimationMethod,
17+
DecimationOptions,
18+
QueryDecimatedDataRequest,
19+
)
20+
from ._query_table_data_base import ColumnFilter, FilterOperation
21+
from ._query_table_data_request import ColumnOrderBy, QueryTableDataRequest
1522
from ._query_tables_request import QueryTablesRequest
1623
from ._table_metadata import TableMetadata
24+
from ._table_rows import TableRows
1725

1826
# flake8: noqa
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from enum import Enum
2+
from typing import List, Optional
3+
4+
from nisystemlink.clients.core._uplink._json_model import JsonModel
5+
6+
from ._query_table_data_base import QueryTableDataBase
7+
8+
9+
class DecimationMethod(str, Enum):
10+
"""Represents the different methods that can be used to decimate data."""
11+
12+
Lossy = "LOSSY"
13+
"""Creates an ``x_column`` ordered set and returns an uniformly distributed
14+
sample of rows with as many rows as the number specified as ``intervals.``"""
15+
16+
MaxMin = "MAX_MIN"
17+
"""Creates an ``x_column`` ordered set which will be divided in the number of
18+
``intervals`` specified. For each of the intervals, the maximum and minimum
19+
values for all the columns specified in ``y_columns`` will be returned."""
20+
21+
EntryExit = "ENTRY_EXIT"
22+
"""Creates an ``x_column`` ordered set which will be divided in the number of
23+
``intervals`` specified. For each of the intervals, the first and last row
24+
within the interval will be returned in addition to the maximum and minimum
25+
values for all the columns specified in ``y_columns``."""
26+
27+
28+
class DecimationOptions(JsonModel):
29+
"""Contains the parameters to use for data decimation."""
30+
31+
x_column: Optional[str] = None
32+
"""The name of the column that will be used as the x-axis for decimating the
33+
data. The column in the table that was specified as Index will be used if
34+
this field is excluded. Only numeric columns are supported. i.e. ``INT32``,
35+
``INT64``, ``FLOAT32``, ``FLOAT64`` and ``TIMESTAMP``."""
36+
37+
y_columns: Optional[List[str]] = None
38+
"""A list of columns to decimate by. This property is only needed when the
39+
specified method is ``MAX_MIN`` or ``ENTRY_EXIT``. Only numeric columns are
40+
supported. i.e. ``INT32``, ``INT64``, ``FLOAT32``, ``FLOAT64`` and
41+
``TIMESTAMP``."""
42+
43+
intervals: Optional[int] = None
44+
"""Number of intervals to use for decimation. Defaults to 1000."""
45+
46+
method: Optional[DecimationMethod] = None
47+
"""Specifies the method used to decimate the data. Defaults to
48+
:class:`DecimationMethod.Lossy`"""
49+
50+
51+
class QueryDecimatedDataRequest(QueryTableDataBase):
52+
"""Specifies the columns, filters and decimation parameters for a query."""
53+
54+
decimation: Optional[DecimationOptions] = None
55+
"""The decimation options to use when querying data. If not specified, the
56+
default is to use :class:`DecimationMethod.Lossy` with 1000 intervals over
57+
the table's index column."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from enum import Enum
2+
from typing import List, Optional
3+
4+
from nisystemlink.clients.core._uplink._json_model import JsonModel
5+
6+
7+
class FilterOperation(str, Enum):
8+
"""Represents the different operations that can be used in a filter."""
9+
10+
Equals = "EQUALS"
11+
NotEquals = "NOT_EQUALS"
12+
LessThan = "LESS_THAN"
13+
LessThanEquals = "LESS_THAN_EQUALS"
14+
GreaterThan = "GREATER_THAN"
15+
GreaterThanEquals = "GREATER_THAN_EQUALS"
16+
Contains = "CONTAINS"
17+
NotContains = "NOT_CONTAINS"
18+
19+
20+
class ColumnFilter(JsonModel):
21+
"""A filter to apply to the table data."""
22+
23+
column: str
24+
"""The name of the column to use for filtering."""
25+
26+
operation: FilterOperation
27+
"""How to compare the column's value with the specified value.
28+
29+
An error is returned if the column's data type does not support the specified operation:
30+
* String columns only support ``EQUALS``, ``NOT_EQUALS``, ``CONTAINS``, and ``NOT_CONTAINS``.
31+
* Non-string columns do not support ``CONTAINS`` or ``NOT_CONTAINS``.
32+
* When ``value`` is ``None``, the operation must be ``EQUALS`` or ``NOT_EQUALS``.
33+
* When ``value`` is ``NaN`` for a floating-point column, the operation must be ``NOT_EQUALS``.
34+
"""
35+
36+
value: Optional[str]
37+
"""The comparison value to use for filtering. An error will be returned if
38+
the value cannot be converted to the column's data type."""
39+
40+
41+
class QueryTableDataBase(JsonModel):
42+
"""Contains the common set of options when querying table data."""
43+
44+
columns: Optional[List[str]] = None
45+
"""The names of columns to include in the response. The response will
46+
include the columns in the same order specified in this parameter. All
47+
columns are included in the order specified at table creation if this
48+
property is excluded."""
49+
50+
filters: Optional[List[ColumnFilter]] = None
51+
"""A list of columns to filter by. Only rows whose columns contain values
52+
matching all of the specified filters are returned. The columns used for
53+
filtering do not need to be included in the columns list. When reading
54+
decimated data, the filters are applied before decimation."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from typing import List, Optional
2+
3+
from nisystemlink.clients.core._uplink._json_model import JsonModel
4+
from nisystemlink.clients.core._uplink._with_paging import WithPaging
5+
6+
from ._query_table_data_base import QueryTableDataBase
7+
8+
9+
class ColumnOrderBy(JsonModel):
10+
"""Specifies a column to order by and the ordering direction."""
11+
12+
column: str
13+
"""The name of the column to order by."""
14+
15+
descending: Optional[bool] = None
16+
"""Whether the ordering should be in descending order."""
17+
18+
19+
class QueryTableDataRequest(QueryTableDataBase, WithPaging):
20+
"""Contains the filtering and sorting options to use when querying table data."""
21+
22+
order_by: Optional[List[ColumnOrderBy]] = None
23+
"""A list of columns to order the results by. Multiple columns may be
24+
specified to order rows that have the same value for prior columns. The
25+
columns used for sorting do not need to be included in the columns list, in
26+
which case they are not returned. If ``order_by`` is not specified, then the
27+
order in which results are returned is undefined."""
28+
29+
take: Optional[int] = None
30+
"""Limits the returned list to the specified number of results."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from nisystemlink.clients.core._uplink._json_model import JsonModel
2+
3+
from ._data_frame import DataFrame
4+
5+
6+
class TableRows(JsonModel):
7+
"""Contains the result of a query for rows of decimated data."""
8+
9+
frame: DataFrame
10+
"""The data frame containing the rows of data."""

0 commit comments

Comments
 (0)