配置其他容器池

您可以创建容器池来管理如何将时间系列数据插入到多个容器。您可以按循环顺序,或者使用用户定义的方法将数据插入到容器中。

如果要使用容器池策略而不是循环顺序,那么在向容器池插入数据前必须编写用户定义的容器池策略函数。有关更多信息,请参阅用户定义的容器池策略

要创建容器池并使用容器池策略向容器中存储数据,请执行以下操作:

  1. 通过运行 TSContainerCreate 过程来创建容器。
  2. 通过使用 TSContainerSetPool 过程将每个容器添加到容器池。
  3. 通过在 TSContainerPoolRoundRobin 函数中包含容器池名称,或通过在 container 参数中包含用户定义的容器池策略函数,将数据插入到时间系列中。

示例

该示例使用 TimeSeries 子类型 smartmeter_row(位于表 smartmeters 中的列 rawreadings 内)。假设您要在自己创建的容器池中的三个容器内存储时间系列的数据。

以下语句为 TimeSeries 子类型 smartmeter_row 创建三个容器:

EXECUTE PROCEDURE TSContainerCreate
                    ('ctn_sm0','tsspace0','smartmeter_row',0,0);
EXECUTE PROCEDURE TSContainerCreate
                    ('ctn_sm1','tsspace1','smartmeter_row',0,0);
EXECUTE PROCEDURE TSContainerCreate
                    ('ctn_sm2','tsspace2','smartmeter_row',0,0);

以下语句将容器添加到容器池 readings 中:

EXECUTE PROCEDURE TSContainerSetPool('ctn_sm0','readings');
EXECUTE PROCEDURE TSContainerSetPool('ctn_sm1','readings');
EXECUTE PROCEDURE TSContainerSetPool('ctn_sm2','readings');

以下语句将时间系列数据插入到列 rawreadings 中。使用指定容器池 readingsTSContainerPoolRoundRobin 函数而不是 container 参数中的容器名称。

INSERT INTO smartmeters(meter_id,rawreadings)
     VALUES('met00001','origin(2006-01-01 00:00:00.00000),
            calendar(smartmeter),regular,threshold(0),
            container(TSContainerPoolRoundRobin(readings)),
                [(33070,-13.00,100.00,9.98e+34),
                 (19347,-4.00,100.00,1.007e+35),
                 (17782,-18.00,100.00,9.83e+34)]');

在 INSERT 语句运行期间,TSContainerPoolRoundRobin 函数使用以下值运行:

TSContainerPoolRoundRobin('smartmeters','rawreadings', 
                          'smartmeter_row',0,'readings')

TSContainerPoolRoundRobin 函数按字母顺序排列容器名称,并将容器名称 ctn_sm0 返回到 INSERT 语句,数据存储在 ctn_sm0 容器中。TSContainerPoolRoundRobin 函数指定将下一条 INSERT 语句返回的数据存储在容器 ctn_sm1 中,并将第三条 INSERT 语句返回的数据存储在容器 ctn_sm2 中。对于第四条 INSERT 语句,TSContainerPoolRoundRobin 函数返回到容器列表的开头处并指定将数据存储在容器 ctn_sm0 中,依此类推。