Use a operação CreateTimeseriesTable para criar uma tabela de séries temporais. Durante a criação, especifique as configurações da tabela e dos metadados das séries temporais. Conforme a necessidade do seu negócio, defina identificadores e campos de dados personalizados como colunas de chave primária, crie um analytical store ou um índice Lastpoint.
Notas de uso
-
O Tablestore SDK for Python V6.1.0 e versões posteriores oferecem suporte ao modelo TimeSeries. Verifique se você utiliza a versão correta do Tablestore SDK for Python.
NotaPara mais informações, consulte Histórico de versões do Python SDK.
O nome da tabela de séries temporais deve ser exclusivo na instância e não pode coincidir com o nome de uma tabela existente.
-
Crie apenas um analytical store por tabela de séries temporais. A soma total de analytical stores e índices Lastpoint não pode exceder 10.
NotaOs recursos de analytical store e índice Lastpoint têm suporte nas seguintes regiões: China (Hangzhou), China (Shanghai), China (Beijing) e China (Zhangjiakou).
Defina até quatro campos de dados como colunas de chave primária da tabela de séries temporais.
Ao especificar identificadores personalizados de séries temporais para uma tabela, adicione no máximo seis campos.
Pré-requisitos
Inicialize um cliente Tablestore. Para mais informações, consulte Inicializar um cliente Tablestore.
Parâmetros
A tabela a seguir descreve os parâmetros incluídos em request.
|
Parâmetro |
Descrição |
|
table_meta (obrigatório) |
Informações de esquema da tabela de séries temporais, compostas pelos seguintes itens:
|
|
analytical_stores (opcional) |
Informações de configuração do analytical store para séries temporais, compostas pelos seguintes itens:
|
|
lastpoint_index_metas (opcional) |
Informações de configuração do índice Lastpoint, compostas pelo seguinte item:
|
Exemplos
Criar uma tabela de séries temporais
O código de exemplo abaixo demonstra como criar uma tabela de séries temporais:
try:
# Set the retention period of data in the time series table to 172,800 seconds (two days).
tableOption = TimeseriesTableOptions(172800)
# Set the retention period of the time series metadata to -1 and specify that updates to attributes of time series metadata are allowed.
metaOption = TimeseriesMetaOptions(-1, True)
tableMeta = TimeseriesTableMeta("", tableOption, metaOption)
# Call the operation to create the time series table.
request = CreateTimeseriesTableRequest(tableMeta)
otsClient.create_timeseries_table(request)
print("create timeseries table success.")
except Exception as e:
# If an exception is thrown, the time series table fails to be created. Handle the exception.
print("create timeseries table failed. %s" % e)
Criar uma tabela de séries temporais com um analytical store
O exemplo a seguir ilustra a criação de uma tabela de séries temporais contendo um analytical store:
try:
# Set the retention period of data in the time series table to 172,800 seconds (two days).
tableOption = TimeseriesTableOptions(172800)
# Set the retention period of the time series metadata to -1 and specify that updates to attributes of time series metadata are allowed.
metaOption = TimeseriesMetaOptions(-1, True)
tableMeta = TimeseriesTableMeta("", tableOption, metaOption)
# Configure an analytical store.
analyticalStore = TimeseriesAnalyticalStore("default_analytical_store", -1, SyncType.SYNC_TYPE_FULL)
# Call the operation to create the time series table.
request = CreateTimeseriesTableRequest(tableMeta, [analyticalStore])
otsClient.create_timeseries_table(request)
print("create timeseries table success.")
except Exception as e:
# If an exception is thrown, the time series table fails to be created. Handle the exception.
print("create timeseries table failed. %s" % e)
Criar uma tabela de séries temporais com identificadores personalizados e campos de dados customizados como chaves primárias
Este trecho de código mostra como criar uma tabela de séries temporais utilizando os identificadores personalizados keyA, keyB e keyC, além de definir dois campos de dados, gid (tipo String) e uid (tipo Integer), como colunas de chave primária:
try:
# Set the retention period of data in the time series table to 86,400 seconds (one day).
tableOption = TimeseriesTableOptions(86400)
# Set the retention period of the time series metadata to -1 and specify that updates to attributes of time series metadata are allowed.
metaOption = TimeseriesMetaOptions(-1, True)
# Specify custom time series identifiers
timeseriesKeys = ["keyA", "keyB", "keyC"]
# Specify custom data fields as the primary key columns of the time series table.
fieldPrimaryKeys = [('gid', 'STRING'), ('uid', 'INTEGER')]
tableMeta = TimeseriesTableMeta("", tableOption, metaOption, timeseriesKeys,
fieldPrimaryKeys)
# Call the operation to create the time series table.
request = CreateTimeseriesTableRequest(tableMeta)
otsClient.create_timeseries_table(request)
print("create timeseries table success.")
except Exception as e:
# If an exception is thrown, the time series table fails to be created. Handle the exception.
print("create timeseries table failed. %s" % e)
Criar uma tabela de séries temporais com um índice Lastpoint
Utilize o código abaixo como referência para criar uma tabela de séries temporais com um índice Lastpoint:
try:
# Set the retention period of data in the time series table to 86,400 seconds (one day).
tableOption = TimeseriesTableOptions(86400)
# Set the retention period of the time series metadata to 604,800 seconds (seven days) and specify that updates to attributes of time series metadata are not allowed.
metaOption = TimeseriesMetaOptions(604800, False)
tableMeta = TimeseriesTableMeta("", tableOption, metaOption)
# Configure a Lastpoint index.
lastPointIndex = LastpointIndexMeta("")
# Call the operation to create the time series table.
request = CreateTimeseriesTableRequest(tableMeta, None, [lastPointIndex])
otsClient.create_timeseries_table(request)
print("create timeseries table success.")
except Exception as e:
# If an exception is thrown, the time series table fails to be created. Handle the exception.
print("create timeseries table failed. %s" % e)