Chame a operação CreateTimeseriesTable para criar uma tabela de séries temporais. Ao criar a tabela, especifique as informações de configuração relacionadas a ela e aos metadados da série temporal. Além disso, você pode especificar identificadores personalizados e campos de dados personalizados como colunas de chave primária, criar um analytical store e criar um índice Lastpoint conforme a necessidade do seu negócio.
Notas de uso
-
O Tablestore SDK for Python V6.1.0 e versões posteriores suportam o modelo TimeSeries. Certifique-se de usar a versão correta do Tablestore SDK for Python.
NotaPara mais informações, consulte Python SDK version history.
O nome da tabela de séries temporais deve ser exclusivo na instância e não pode ser igual ao nome de uma tabela existente.
-
Crie apenas um analytical store para cada tabela de séries temporais. O número 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).
Especifique até quatro campos de dados como colunas de chave primária da tabela.
Ao especificar identificadores personalizados para a tabela, adicione no máximo seis campos.
Pré-requisitos
Um cliente Tablestore inicializado. Para mais informações, consulte Initialize a Tablestore client.
Parâmetros
A tabela a seguir descreve os parâmetros incluídos em request.
|
Parâmetro |
Descrição |
|
table_meta (obrigatório) |
As informações de esquema da tabela de séries temporais, que consistem nos seguintes itens:
|
|
analytical_stores (opcional) |
As informações de configuração do analytical store for time series, que consistem nos seguintes itens:
|
|
lastpoint_index_metas (opcional) |
As informações de configuração do Lastpoint index, que consistem no seguinte item:
|
Exemplos
Crie uma tabela de séries temporais
O código de exemplo a seguir mostra 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)
Crie uma tabela de séries temporais com um analytical store
O código de exemplo a seguir mostra como criar uma tabela de séries temporais com 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)
Crie uma tabela de séries temporais com identificadores e campos de dados personalizados especificados como colunas de chave primária
O código de exemplo a seguir mostra como criar uma tabela de séries temporais com os identificadores personalizados keyA, keyB e keyC, e dois campos de dados gid (tipo String) e uid (tipo Integer) especificados 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)
Crie uma tabela de séries temporais com um índice Lastpoint
O código de exemplo a seguir mostra como 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)