- table insert monitor - watches a table for newly inserted records and can make use of those records elsewhere
- table update monitor - watches a table for updates and reports the number of records updated in each update request issued
- table delete monitor - watches a table for deletes and reports the number of records deleted in each delete request issued
GPUdbTableMonitor.Client class, which can create, process, & remove
table monitors.
Prerequisites
The prerequisites for running the table monitor example are listed below:- Python API
- Table monitor example script
Python API Installation
Depending on the target operating system, a Python virtual environment may need to be installed first: The native Kinetica Python API is accessible through the following means:Python Virtual Environment
A Python virtual environment is necessary to install in an operating environment where Python is externally managed.-
Install a Python virtual environment:
-
Activate the Python virtual environment:
PyPI
-
Install the API:
-
Test the installation:
If Import Successful is displayed, the API has been installed as is ready for use.
Git
-
In the desired directory, run the following, but be sure to replace
<kinetica-version>with the name of the installed Kinetica version, e.g.,v7.2: -
Change directory into the newly downloaded repository:
-
In the root directory of the unzipped repository, install the Kinetica API:
-
Test the installation (Python3 is necessary for running the API example):
Script Detail
In this example, a set of batches of randomly-generated weather data for a fixed set of cities will be inserted into a “history” table. A table monitor client (viaGPUdbTableMonitor.Client) will be created to
watch for those newly inserted records and update a “status” table of those
cities with their latest randomly-generated temperature values.
Afterwards, a set of updates will be made to the “status” table, followed by a
set of deletes. A second table monitor client will be created to watch for
these two event types and output the numbers of records updated & deleted to the
console.
There are four main components involved in this example:
- The “history” table, into which weather records will be inserted, in batch
- The “status” table, which reflects the latest weather data for each city
- The table monitor client for the “history” table, which will watch for inserts into the table and update the “status” table with those records
- The table monitor client for the “status” table, which will watch for updates & deletes on the table and output the corresponding records counts
- Imports & Aliases
- Creating a Table Monitor Client
- Displaying a Table’s Monitors
- Starting/Stopping the Table Monitor Client
Imports & Aliases
The first step is to import Kinetica libraries, aliasing some of the classes for ease of use. Other supporting libraries need to be imported, as well.Creating a Table Monitor Client
Next, create a connection to Kinetica.GPUdbTableMonitor.Client, the table monitor client class,
and configure it to monitor the “history” table, which will use the connection
to manage the table’s monitor as well as process the insert events on it.
show_status function that will be called by each event
handler to output the records in the “status” table.
Displaying a Table’s Monitors
After the table monitor clients have been created, confirm this by looking up the table monitors attached to the “history” & “status” tables and display the monitored event and event topic ID for each table monitor the tables have.Starting/Stopping the Table Monitor Client
To start the table monitor clients, instantiate each container class with a handle to the database and call their respectivestart functions.
stop functions.
Download & Run
Included below is a complete example of the Python Table Monitor API, containing all of the above code samples, as well as the loading of data into the “history” & “status” tables and the verification output of records. To run the complete sample, ensure the table_monitor.py file is in the current directory, and do the following:Run Example
As this script creates a schema and several database objects within
it, system admin permission is
required to run it.