Use Tablestore SDK for Java to create an analytical store for an existing time series table for cost-effective, long-term storage and analysis of time series data.
Prerequisites
Install Tablestore SDK for Java and initialize a time series model client. Analytical store operations require Tablestore SDK for Java 5.15.0 or later. We recommend that you use the latest version.
Create a time series model instance in a region that supports analytical stores. For information about supported regions and the feature, see Analytical store.
Feature description
Call the createTimeseriesAnalyticalStore method to create an analytical store for an existing time series table. The analytical store automatically synchronizes data from the time series table. Its TTL is independent of the TTL of the time series table, and queries on the analytical store do not affect reads from or writes to the time series table.
public CreateTimeseriesAnalyticalStoreResponse createTimeseriesAnalyticalStore(CreateTimeseriesAnalyticalStoreRequest request) throws TableStoreException, ClientException
You can use one of the following synchronization modes when you create an analytical store:
SYNC_TYPE_FULL: synchronizes existing data and data that is written after the analytical store is created. This is the default mode.SYNC_TYPE_INCR: synchronizes only data that is written after the analytical store is created.
The synchronization mode cannot be changed after the analytical store is created. Select the mode based on whether you need to analyze existing data.
You can create only one analytical store for a time series table. A time series table can have up to 10 Lastpoint indexes and analytical stores in total.
The following sample code creates an analytical store named example_analytical_store for the example_timeseries_table table. Data in the analytical store does not expire, and full synchronization is used.
TimeseriesClient timeseriesClient = client.asTimeseriesClient();
TimeseriesAnalyticalStore analyticalStore =
new TimeseriesAnalyticalStore("example_analytical_store");
analyticalStore.setTimeToLive(-1);
analyticalStore.setSyncOption(AnalyticalStoreSyncType.SYNC_TYPE_FULL);
CreateTimeseriesAnalyticalStoreRequest request =
new CreateTimeseriesAnalyticalStoreRequest(
"example_timeseries_table", analyticalStore);
timeseriesClient.createTimeseriesAnalyticalStore(request);
After the analytical store is created, data is synchronized in the background. You can call describeTimeseriesAnalyticalStore to check the synchronization status. For more information, see Query analytical store information.
Parameters
CreateTimeseriesAnalyticalStoreRequest contains the following parameters.
|
Name |
Type |
Description |
|
timeseriesTableName (required) |
|
The name of the time series table. |
|
analyticalStore (required) |
|
The analytical store configuration. |
Analytical store configuration
analyticalStore is of the TimeseriesAnalyticalStore type and contains the following parameters.
|
Name |
Type |
Description |
|
analyticalStoreName (required) |
|
The name of the analytical store. |
|
timeToLive (optional) |
|
The analytical store TTL in seconds. Default value: |
|
syncOption (optional) |
|
The data synchronization mode. Default value: |