Table data service
This guide covers using the Table Data Service API to integrate custom data services into Deephaven workflows.
To use the Table Data Service API, you must create an implementation of its backend, which will be used to construct the Table Data Service itself. The API provides a series of classes with abstract methods that can be used as a template in a custom implementation. This guide covers all of the necessary components of the backend, along with an example implementation.
Note
This feature is currently experimental. The API and its characteristics are subject to change.
TableDataService API
The Python TableDataService API simplifies how the engine thinks about data being served by a remote service or database. It provides a way for users to consume data from external sources into Deephaven in the format of PyArrow tables, which can back Deephaven tables in both static and refreshing contexts.
Each class in the API has some requirements when creating an implementation. The following sections describe the requirements for each class and give an example.
TableKey
A TableKey is a unique identifier for a table. An implementation must have the following methods:
__hash__: Create a hash of the key.__eq__: Compare two keys for equality. IfTableKey1 == TableKey2is true, thenhash(TableKey1) == hash(TableKey2)must also be true.
The following code block contains an example implementation of a TableKey, aptly named TableKeyImpl. It implements both of the required methods, along with a __str__ method for key validation.
TableLocationKey
A TableLocationKey is a unique identifier for a location within a table. An implementation has the same methods required as a TableKey implementation:
__hash__: Create a hash of the key.__eq__: Compare two keys for equality. IfTableLocationKey1 == TableLocationKey2is true, thenhash(TableLocationKey1) == hash(TableLocationKey2)must also be true.
The following code block contains an example implementation of a TableLocationKey, aptly named TableLocationKeyImpl. It implements both of the required methods, along with a __str__ method for key validation.
TableDataServiceBackend
A TableDataServiceBackend is the interface that must be implemented to provide data to the TableDataService. It has a series of abstract methods that must be implemented to provide the necessary information to the TableDataService. The methods are:
table_schema: Fetch the schema of a table.table_locations: Fetch the locations of a table.table_location_size: Fetch the size of a table location.column_values: Fetch column values.susbcribe_to_table_locations: Subscribe to existing and future table locations.subscribe_to_table_location_size: Subscribe to existing and future table location sizes.
The following code blocks contain example implementations of a TableDataServiceBackend, named TestBackend, and TestTable, a custom table implementation used by the backend. The backend implements all six required methods, along with some additional methods to add tables and locations to the backend.
A custom table implementation for the backend
A TableDataServiceBackend implementation
TableDataService
The TableDataService is the main class that users interact with. It is instantiated using the TableDataServiceBackend implementation, along with other optional parameters.
The TableDataService class has two methods:
-
Creates a table backed by the data service backend. It is given a unique
TableKeyand is told whether the table is static or refreshing. -
Creates a partitioned table backed by the data service backend. It is given a unique
TableKeyand is told whether the table is static or refreshing.
The usage section of the example below calls make_table to create a table from a table data service.
Example
The example presented in this guide uses the code presented in the sections above to demonstrate how to use the TableDataService API to fetch a table in both static and refreshing contexts. The example is split into two parts, each in its own subsection.
Backend data service implementation
The following code block provides a backend implementation for a data service. It shows how to:
- Implement a sample
TableDataServiceBackend. - Manually manipulate the
TableDataServiceBackendto demonstrate the behavior of static and refreshing scenarios. - Create a custom table implementation and add it to the backend.
- Fetch a table from that backend in both static and refreshing contexts.
A backend data service implementation
Usage
The following code block demonstrates how to use the backend implementation to fetch a table in both static and refreshing contexts.
Usage of the example table data service backend
With the table open and visible in the IDE, more data can be appended with subsequent calls to add_ticker_data.