Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

实际应用中有许多实体所采集的物理量相同,即具有相同的工况名称和类型,可以声明一个物理量模板来定义可采集的物理量集合。在实践中,物理量模板的使用可帮助减少元数据的资源占用。

...

应用场景与 SQL 设计

场景1:一个物理实体具有多个非对齐的时间序列

Code Block
languagesql
themeConfluence
// 创建时间序列
// 1. 完整语法(v0.12及之前)
create timeseries root.sg1.d1.s1 with datatype=FLOAT, encoding=RLE, compression=SNAPPY, tags(tag1=v1, tag2=v2), attributes(attr1=v1, attr2=v2)
create timeseries root.sg1.d1.s2 with datatype=FLOAT, encoding=RLE, compression=SNAPPY, tags(tag1=v1, tag2=v2), attributes(attr1=v1, attr2=v2)

// 2. 简化语法(v0.13开始支持,与之前语法兼容)
create timeseries root.sg1.d1.s1 FLOAT encoding=RLE compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2)
create timeseries root.sg1.d1.s2 FLOAT encoding=RLE compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2)

// 插入语句
insert into root.sg1.d1(time, s1) values(1,1)
insert into root.sg1.d1(time, s1, s2) values(1,1,2)

...

Code Block
languagesql
themeConfluence
// 在实体 root.sg1.d2 下创建一组对齐的时间序列
create aligned timeseries root.sg1.d2.(s1 FLOAT encoding=RLE, s2 INT32 encoding=Grollia compression=SNAPPY) compression=SNAPPY

// 注:
// 1.可以指定每条时间序列的编码(encoding)和压缩方式(compression),但是暂不支持指定别名(alias),props, attributes, tags 等。
// 2.未指定 compression 的时间序列,则采用系统默认配置;小括号外的 compression 定义时间列压缩方式和未显式声明的列的压缩方式。

// 插入语句,必须使用 aligned 插入语句关键词
insert into root.sg.d2(time, s1, s2) aligned values(1, 1, 2)
insert into root.sg.d2(time, s1) aligned values(2, 1)  //允许单独写某条时间序列,其他时间序列在该时间点上为空值

// 场景2所创建的对齐时间序列所属物理实体可以扩充时间序列,但需要在该物理实体下嵌套新实体。
// 例如,可以向d2下继续添加时间序列: 
create timeseries root.sg1.d2.t1.s1 FLOAT
create timeseries root.sg1.d2.v1.(s1 FLOAT, s2 FLOAT)

...

场景3:一个物理实体具有多组对齐的时间序列

Code Block
languagesql
themeConfluence
// 创建语句
create 

...

aligned

...

 timeseries root.

...

sg1.d3.

...

v1(s1 FLOAT, s2 INT32)
create 

...

aligned

...

 timeseries root.

...

sg1.d3.

...

v2(

...

s1 FLOAT, 

...

s2 INT32)
 

...

// 

...

插入语句,不能同时向多组对齐的时间序列中插入值
insert into root.

...

sg1.d3.v1(time, 

...

s1, s2)

...

 

...

aligned values(1, 

...

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

...

)
insert into root.

...

sg1.d3.v2(time, 

...

s1, s2)

...

 aligned values(1, 

...

1, 2)

...


...

注意:场景4所创建的多元时间序列是可以扩充的。例如,可以向d3下继续添加其他的一元或多元时间序列:

create timeseries root.sg.d3.s3 FLOAT

场景5:一个物理设备具有混合的多元序列和一元序列

...

insert into root.sg1.d3.v2(time, s2) aligned values(3, 4)

场景4:一个物理实体具有混合的非对齐和对齐的时间序列

Code Block
languagesql
themeConfluence
// 创建语句
create timeseries root.sg1.d4.t1.s1 FLOAT
create aligned timeseries root.sg1.d4.v1(s1 FLOAT, s2 INT32)
create aligned timeseries root.sg1.d4.v2(s1 FLOAT, s2 INT32)

// 插入语句,不能同时向非对齐和对齐的时间序列中插入值
insert into root.sg1.d4.t1(time, s1) values(1, 1)
insert into root.sg1.d4.v1(time, s1, s2) aligned values(1, 1, 2)
insert into root.sg1.d4.v1(time, s1) aligned values(2, 3)
insert into root.sg1.d4.v2(time, s1, s2) aligned values(1, 1, 2)
insert into root.sg1.d4.v2(time, s2) aligned values(3, 4)

三、Session API

注意:以下仅展示本次新增的 session API,其他 API 与旧有 API 相同的不在此展示,如:查询语句(executeRawDataQuery)。

1、多元时间序列相关 API

...

1、创建一组对齐的时间序列

Code Block
languagejava
themeConfluence
void createAlignedTimeseries(

...

	String prefixPath, // "root.sg.d1.陀螺仪" 

...

	List<String> measurements,

...

	List<TSDataType> dataTypes,

...

	List<TSEncoding> encodings, 

...

	CompressionType compressor, 

...

	List<String> measurementAliasList
);

2、插入Record

一个 Record 是一个设备一个时间戳下多个测点的数据,例如:

...