使用Apache IoTDB进行IoT相关开发的架构设计与功能实现(3)
接下来我给大家继续介绍一下Apache IoTDB的数据类型和相关用法
在显示时间戳时,IoTDB可以支持长类型和日期时间显示类型。日期时间显示类型可以支持用户定义的时间格式。自定义时间格式的语法如下表所示:
**自定义时间格式的语法**
Symbol | Meaning | Presentation | Examples |
G | era | era | era |
C | century of era (>=0) | number | 20 |
Y | year of era (>=0) | year | 1996 |
x | weekyear | year | 1996 |
w | week of weekyear | number | 27 |
e | day of week | number | 2 |
E | day of week | text | Tuesday; Tue |
y | year | year | 1996 |
D | day of year | number | 189 |
M | month of year | month | July; Jul; 07 |
d | day of month | number | 10 |
a | halfday of day | text | PM |
K | hour of halfday (0~11) | number | 0 |
h | clockhour of halfday (1~12) | number | 12 |
H | hour of day (0~23) | number | 0 |
k | clockhour of day (1~24) | number | 24 |
m | minute of hour | number | 30 |
s | second of minute | number | 55 |
S | fraction of second | millis | 978 |
z | time zone | text | Pacific Standard Time; PST |
Z | time zone offset/id | zone | -0800; -08:00; America/Los_Angeles |
‘ | escape for text | delimiter | |
‘’ | single quote | literal | ‘ |
- 相对时间戳
相对时间是指相对于服务器时间的时间now()和DATETIME时间。
用法如下:
Duration = (Digit+ ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS'))+
RelativeTime = (now() | DATETIME) ((+|-) Duration)+
**持续时间单位的语法**
Symbol | Meaning | Presentation | Examples |
y | year | 1y=365 days | 1y |
mo | month | 1mo=30 days | 1mo |
w | week | 1w=7 days | 1w |
d | day | 1d=1 day | 1d |
h | hour | 1h=3600 seconds | 1h |
m | minute | 1m=60 seconds | 1m |
s | second | 1s=1 second | 1s |
ms | millisecond | 1ms=1000_000 nanoseconds | 1ms |
us | microsecond | 1us=1000 nanoseconds | 1us |
ns | nanosecond | 1ns=1 nanosecond | 1ns |
用法如下:
now() - 1d2h //1 day and 2 hours earlier than the current server time
now() - 1w //1 week earlier than the current server time
数据类型
IoTDB一共支持以下6种数据类型:
- BOOLEAN (布尔型)
- INT32 (整数型)
- INT64 (长整数型)
- FLOAT (单精度浮点)
- DOUBLE (双精度浮点)
- TEXT (字符串)
时间序列float和double类型可以指定最大点数,如果编码方法为,则为浮点数小数点后的位数RLE或者TS_2DIFF,如果未指定最大点数,系统将使用浮点精度在配置文件中iotdb-engine.properties。
对于浮点数据值,数据范围是(MAX_VALUE,整数型。MAX_VALUE),而不是Float。MAX_VALUE,而max_point_number是19,这是因为Java中函数Math.round(float)的限制。
对于双精度数据值,数据范围为(MAX_VALUE,长整数型。MAX_VALUE),而不是Double。MAX_VALUE,而max_point_number是19,这是因为Java(Long)中函数Math.round(double)的限制,MAX_VALUE=9.22E18。
当用户在系统中输入的数据的数据类型与时间序列的数据类型不对应时,系统将报告类型错误。如下所示,二阶差分编码不支持布尔类型:
IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF
error: encoding TS_2DIFF does not support BOOLEAN