在当前的数据模型中,存在一元和多元(对齐)两种时间序列。其中多元时间序列包含多个分量,这些分量必须同时创建、同时插入值,删除时也必须同时删除,但可以对分量进行单独查询。

由于一元序列和多元序列的分量具有相似性,在查询、写入的时候容易引发歧义。


例1:在 vector 场景下考虑查询语句的语义。

元数据包含:

  • 两条一元时间序列:root.sg1.d1.s1、root.sg1.d1.d2.s1
  • 多元时间序列:root.sg1.d1.vector1,包含s1、s2两个分量

考虑以下 SQL 的语义:

select * from root.d1
select ** from root.d1
select s1 from root.d1.*
select s1 from root.d1.**


例2:在 vector 场景下考虑对以下语句是否应该支持。

// 场景1:一个物理设备具有多个一元序列
create timeseries root.sg1.d1.s1 FLOAT
create timeseries root.sg1.d1.s2 FLOAT

insert into root.sg1.d1(time, s1) values(1,1)
insert into root.sg1.d1(time, s1, s2) values(1,1,2)

// 场景2:一个物理设备具有一个多元序列
create aligned timeseries root.sg1.d1.v1(s1 FLOAT, s2 INT32)

insert into root.sg1.d1(time, v1(s1, s2)) values(1,(1,2))
insert into root.sg1.d1(time, v1(s1)) values(2,(1)) //多元序列允许某列的某些行有空值,如时间戳2下只有s1有值,s2无值,则只需:
insert into root.sg1.d1(time, v1(s2)) values(3,(2))

// 场景3:一个物理设备具有多个多元序列
create aligned timeseries root.sg1.d1.陀螺仪(s1 FLOAT, s2 INT32)
create aligned timeseries root.sg1.d1.GPS(s3 FLOAT, s4 INT32)

insert into root.sg1.d1(time, 陀螺仪(s1, s2), GPS(s3, s4)) values(1, (1, 2),(3,4))
insert into root.sg1.d1(time, 陀螺仪(s1, s2)) values(1, (1, 2))

// 场景4:一个物理设备具有混合的多元序列和一元序列
create aligned timeseries root.sg1.d1.GPS(s1 FLOAT, s1 INT32)
create timeseries root.sg1.d1.s1 FLOAT

insert into root.sg1.d1(time, GPS(s1, s2), s1) values(1, (3,4), 5)


可见,在当前的数据模型下,一元序列、多元序列、多元序列的分量之间的关系比较模糊,容易引发歧义。

一种可行的方案是:消除分量的概念,vector 层作为设备,vector 的分量作为时间序列。元数据中设备结点增加一个 align 属性,表示直接挂载在该设备下的物理量是否对齐(即共享时间列)。


基于以上设计,元数据查询、数据查询语句没有变化。

对于创建时间序列:一个设备下挂载的物理量可以是多条非对齐的时间序列,可以是一组对齐的时间序列,但不能部分对齐。对齐的时间序列创建时需要使用 aligned 关键词,创建之后可以增加或删除(分量)。

对于数据插入:为适应自动创建 Schema,向对齐时间序列插入数据必须加 aligned 关键词不能同时向多组对齐时间序列插入,不能同时向对齐和非对齐的时间序列插入。


例如:

// 场景1:一个物理设备具有多个非对齐的时间序列
create timeseries root.sg1.d1.s1 FLOAT
create timeseries root.sg1.d1.s2 FLOAT

insert into root.sg1.d1(time, s1) values(1,1)
insert into root.sg1.d1(time, s1, s2) values(1,1,2)

// 场景2:一个物理设备具有一组对齐的时间序列
create aligned timeseries root.sg1.d1.v1(s1 FLOAT, s2 INT32)  // 如果仅有一组对齐的时间序列,可以去除 v1 这一层

insert into root.sg1.d1.v1(time, s1, s2) aligned values(1,1,2)
insert into root.sg1.d1.v1(time, s1) aligned values(2,2)
insert into root.sg1.d1.v1(time, s2) aligned values(3,3)

 // 场景3:一个物理设备具有多组对齐的时间序列
create aligned timeseries root.sg1.d1.v1(s1 FLOAT, s2 INT32)
create aligned timeseries root.sg1.d1.v2(s3 FLOAT, s4 INT32)

// 场景4:一个物理设备具有混合的对齐、非对齐的时间序列
create aligned timeseries root.sg1.d1.v1(s1 FLOAT, s2 INT32)
create timeseries root.sg1.d1.s1 FLOAT



  • No labels