blob: 98939e73879ebdf0e8dec8f9369a9bfaffb3eeb7 [file] [log] [blame]
(window.webpackJsonp=window.webpackJsonp||[]).push([[716],{1110:function(t,e,v){"use strict";v.r(e);var _=v(29),a=Object(_.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"数据模型"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数据模型"}},[t._v("#")]),t._v(" 数据模型")]),t._v(" "),e("p",[t._v("我们以风电场物联网场景为例,说明如何在 IoTDB 中创建一个正确的数据模型。")]),t._v(" "),e("p",[t._v("根据企业组织结构和设备实体层次结构,我们将其物联网数据模型表示为如下图所示的属性层级组织结构,即电力集团层-风电场层-实体层-物理量层。其中 ROOT 为根节点,物理量层的每一个节点为叶子节点。IoTDB 采用树形结构定义数据模式,以从 ROOT 节点到叶子节点的路径来命名一个时间序列,层次间以“.”连接。例如,下图最左侧路径对应的时间序列名称为"),e("code",[t._v("ROOT.ln.wf01.wt01.status")]),t._v("。")]),t._v(" "),e("img",{staticStyle:{width:"100%","max-width":"800px","max-height":"600px","margin-left":"auto","margin-right":"auto",display:"block"},attrs:{src:"https://user-images.githubusercontent.com/19167280/123542457-5f511d00-d77c-11eb-8006-562d83069baa.png"}}),t._v(" "),e("p",[t._v("在上图所描述的实际场景中,有许多实体所采集的物理量相同,即具有相同的工况名称和类型,因此,可以声明一个"),e("strong",[t._v("元数据模板")]),t._v("来定义可采集的物理量集合。在实践中,元数据模板的使用可帮助减少元数据的资源占用,详细内容参见 "),e("RouterLink",{attrs:{to:"/zh/UserGuide/V0.13.x/Data-Concept/Schema-Template.html"}},[t._v("元数据模板文档")]),t._v("。")],1),t._v(" "),e("p",[t._v("IoTDB 模型结构涉及的基本概念在下文将做详细叙述。")]),t._v(" "),e("h2",{attrs:{id:"物理量、实体、存储组、路径"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#物理量、实体、存储组、路径"}},[t._v("#")]),t._v(" 物理量、实体、存储组、路径")]),t._v(" "),e("h3",{attrs:{id:"物理量-measurement"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#物理量-measurement"}},[t._v("#")]),t._v(" 物理量(Measurement)")]),t._v(" "),e("p",[e("strong",[t._v("物理量")]),t._v(",也称工况或字段(field),是在实际场景中检测装置所记录的测量信息,且可以按一定规律变换成为电信号或其他所需形式的信息输出并发送给 IoTDB。在 IoTDB 当中,存储的所有数据及路径,都是以物理量为单位进行组织。")]),t._v(" "),e("h3",{attrs:{id:"实体-entity"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#实体-entity"}},[t._v("#")]),t._v(" 实体(Entity)")]),t._v(" "),e("p",[e("strong",[t._v("一个物理实体")]),t._v(",也称设备(device),是在实际场景中拥有物理量的设备或装置。在 IoTDB 当中,所有的物理量都有其对应的归属实体。")]),t._v(" "),e("h3",{attrs:{id:"存储组-storage-group"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#存储组-storage-group"}},[t._v("#")]),t._v(" 存储组(Storage group)")]),t._v(" "),e("p",[e("strong",[t._v("一组物理实体")]),t._v(",用户可以将任意前缀路径设置成存储组。如有 4 条时间序列"),e("code",[t._v("root.ln.wf01.wt01.status")]),t._v(", "),e("code",[t._v("root.ln.wf01.wt01.temperature")]),t._v(", "),e("code",[t._v("root.ln.wf02.wt02.hardware")]),t._v(", "),e("code",[t._v("root.ln.wf02.wt02.status")]),t._v(",路径"),e("code",[t._v("root.ln")]),t._v("下的两个实体 "),e("code",[t._v("wt01")]),t._v(", "),e("code",[t._v("wt02")]),t._v("可能属于同一个业主,或者同一个制造商,这时候就可以将前缀路径"),e("code",[t._v("root.ln")]),t._v("指定为一个存储组。未来"),e("code",[t._v("root.ln")]),t._v("下增加了新的实体,也将属于该存储组。")]),t._v(" "),e("p",[t._v("一个存储组中的所有实体的数据会存储在同一个文件夹下,不同存储组的实体数据会存储在磁盘的不同文件夹下,从而实现物理隔离。")]),t._v(" "),e("blockquote",[e("p",[t._v("注意 1:不允许将一个完整路径(如上例的"),e("code",[t._v("root.ln.wf01.wt01.status")]),t._v(") 设置成存储组。")]),t._v(" "),e("p",[t._v("注意 2:一个时间序列其前缀必须属于某个存储组。在创建时间序列之前,用户必须设定该序列属于哪个存储组(Storage Group)。只有设置了存储组的时间序列才可以被持久化在磁盘上。")])]),t._v(" "),e("p",[t._v("一个前缀路径一旦被设定成存储组后就不可以再更改这个存储组的设定。")]),t._v(" "),e("p",[t._v("一个存储组设定后,其对应的前缀路径的祖先层级与孩子及后裔层级也不允许再设置存储组(如,"),e("code",[t._v("root.ln")]),t._v("设置存储组后,root 层级与"),e("code",[t._v("root.ln.wf01")]),t._v("不允许被设置为存储组)。")]),t._v(" "),e("p",[t._v("存储组节点名只支持中英文字符、数字、下划线和中划线的组合。例如"),e("code",[t._v("root. 存储组_1-组1")]),t._v(" 。")]),t._v(" "),e("h3",{attrs:{id:"路径-path"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#路径-path"}},[t._v("#")]),t._v(" 路径(Path)")]),t._v(" "),e("p",[t._v("路径("),e("code",[t._v("path")]),t._v(")是指符合以下约束的表达式:")]),t._v(" "),e("div",{staticClass:"language-sql line-numbers-mode"},[e("pre",{pre:!0,attrs:{class:"language-sql"}},[e("code",[t._v("path \n : layer_name "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v("'.'")]),t._v(" layer_name"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nlayer_name\n : wildcard? id wildcard?\n "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" wildcard\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nwildcard \n : "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v("'*'")]),t._v(" \n "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("|")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v("'**'")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])]),t._v(" "),e("div",{staticClass:"line-numbers-wrapper"},[e("span",{staticClass:"line-number"},[t._v("1")]),e("br"),e("span",{staticClass:"line-number"},[t._v("2")]),e("br"),e("span",{staticClass:"line-number"},[t._v("3")]),e("br"),e("span",{staticClass:"line-number"},[t._v("4")]),e("br"),e("span",{staticClass:"line-number"},[t._v("5")]),e("br"),e("span",{staticClass:"line-number"},[t._v("6")]),e("br"),e("span",{staticClass:"line-number"},[t._v("7")]),e("br"),e("span",{staticClass:"line-number"},[t._v("8")]),e("br"),e("span",{staticClass:"line-number"},[t._v("9")]),e("br"),e("span",{staticClass:"line-number"},[t._v("10")]),e("br"),e("span",{staticClass:"line-number"},[t._v("11")]),e("br")])]),e("p",[t._v("其中,对 "),e("code",[t._v("id")]),t._v(" 的定义可以参考"),e("RouterLink",{attrs:{to:"/zh/UserGuide/V0.13.x/Reference/Syntax-Conventions.html"}},[t._v("语法约定")]),t._v("。")],1),t._v(" "),e("p",[t._v("我们称一个路径中由 "),e("code",[t._v("'.'")]),t._v(" 分割的部分叫做层级("),e("code",[t._v("layer_name")]),t._v(")。例如:"),e("code",[t._v("root.a.b.c")]),t._v("为一个层级为 4 的路径。")]),t._v(" "),e("p",[t._v("下面是对层级("),e("code",[t._v("layer_name")]),t._v(")的约束:")]),t._v(" "),e("ul",[e("li",[e("p",[e("code",[t._v("root")]),t._v(" 作为一个保留字符,它只允许出现在下文提到的时间序列的开头,若其他层级出现 "),e("code",[t._v("root")]),t._v(",则无法解析,提示报错。")])]),t._v(" "),e("li",[e("p",[t._v("除了时间序列的开头的层级("),e("code",[t._v("root")]),t._v(")外,其他的层级支持的字符如下:")]),t._v(" "),e("ul",[e("li",[t._v("中文字符"),e("code",[t._v('"\\u2E80"')]),t._v("到"),e("code",[t._v('"\\u9FFF"')])]),t._v(" "),e("li",[e("code",[t._v('"_","@","#","$"')])]),t._v(" "),e("li",[e("code",[t._v('"A"')]),t._v("到"),e("code",[t._v('"Z"')]),t._v(","),e("code",[t._v('"a"')]),t._v("到"),e("code",[t._v('"z"')]),t._v(","),e("code",[t._v('"0"')]),t._v("到"),e("code",[t._v('"9"')])])])]),t._v(" "),e("li",[e("p",[t._v("除了时间序列的开头的层级("),e("code",[t._v("root")]),t._v(")和存储组层级外,层级还支持使用被 ` 或者 "),e("code",[t._v('"')]),t._v(" 符号引用的特殊字符串作为其名称。需要注意的是,被引用的字符串不可带有 "),e("code",[t._v(".")]),t._v(" 字符。下面是一些合法的例子:")]),t._v(" "),e("ul",[e("li",[t._v('root.sg."select"."+-from="."where""where"""."$",6 个层级分别为 root, sg, select, +-from, where"where", $')]),t._v(" "),e("li",[t._v('root.sg.````.`select`.`+="from"`.`$`,6 个层级分别为 root, sg, `, select, +-"from", $')])])]),t._v(" "),e("li",[e("p",[t._v("层级 ("),e("code",[t._v("layer_name")]),t._v(") 不允许以数字开头,除非层级 ("),e("code",[t._v("layer_name")]),t._v(") 以 ` 或 "),e("code",[t._v('"')]),t._v(" 引用。")])]),t._v(" "),e("li",[e("p",[t._v("特别地,如果系统在 Windows 系统上部署,那么存储组层级名称是大小写不敏感的。例如,同时创建"),e("code",[t._v("root.ln")]),t._v(" 和 "),e("code",[t._v("root.LN")]),t._v(" 是不被允许的。")])])]),t._v(" "),e("h3",{attrs:{id:"路径模式-path-pattern"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#路径模式-path-pattern"}},[t._v("#")]),t._v(" 路径模式(Path Pattern)")]),t._v(" "),e("p",[t._v("为了使得在表达多个时间序列的时候更加方便快捷,IoTDB 为用户提供带通配符"),e("code",[t._v("*")]),t._v("或"),e("code",[t._v("**")]),t._v("的路径。用户可以利用两种通配符构造出期望的路径模式。通配符可以出现在路径中的任何层。")]),t._v(" "),e("p",[e("code",[t._v("*")]),t._v("在路径中表示一层。例如"),e("code",[t._v("root.vehicle.*.sensor1")]),t._v("代表的是以"),e("code",[t._v("root.vehicle")]),t._v("为前缀,以"),e("code",[t._v("sensor1")]),t._v("为后缀,层次等于 4 层的路径。")]),t._v(" "),e("p",[e("code",[t._v("**")]),t._v("在路径中表示是("),e("code",[t._v("*")]),t._v(")+,即为一层或多层"),e("code",[t._v("*")]),t._v("。例如"),e("code",[t._v("root.vehicle.device1.**")]),t._v("代表的是"),e("code",[t._v("root.vehicle.device1.*")]),t._v(", "),e("code",[t._v("root.vehicle.device1.*.*")]),t._v(", "),e("code",[t._v("root.vehicle.device1.*.*.*")]),t._v("等所有以"),e("code",[t._v("root.vehicle.device1")]),t._v("为前缀路径的大于等于 4 层的路径;"),e("code",[t._v("root.vehicle.**.sensor1")]),t._v("代表的是以"),e("code",[t._v("root.vehicle")]),t._v("为前缀,以"),e("code",[t._v("sensor1")]),t._v("为后缀,层次大于等于 4 层的路径。")]),t._v(" "),e("blockquote",[e("p",[t._v("注意:"),e("code",[t._v("*")]),t._v("和"),e("code",[t._v("**")]),t._v("不能放在路径开头。")])]),t._v(" "),e("h2",{attrs:{id:"时间序列"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#时间序列"}},[t._v("#")]),t._v(" 时间序列")]),t._v(" "),e("h3",{attrs:{id:"时间戳-timestamp"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#时间戳-timestamp"}},[t._v("#")]),t._v(" 时间戳 (Timestamp)")]),t._v(" "),e("p",[t._v("时间戳是一个数据到来的时间点,其中包括绝对时间戳和相对时间戳,详细描述参见 "),e("RouterLink",{attrs:{to:"/zh/UserGuide/V0.13.x/Data-Concept/Data-Type.html"}},[t._v("数据类型文档")]),t._v("。")],1),t._v(" "),e("h3",{attrs:{id:"数据点-data-point"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数据点-data-point"}},[t._v("#")]),t._v(" 数据点(Data Point)")]),t._v(" "),e("p",[e("strong",[t._v("一个“时间戳-值”对")]),t._v("。")]),t._v(" "),e("h3",{attrs:{id:"时间序列-timeseries"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#时间序列-timeseries"}},[t._v("#")]),t._v(" 时间序列(Timeseries)")]),t._v(" "),e("p",[e("strong",[t._v("一个物理实体的某个物理量在时间轴上的记录")]),t._v(",是数据点的序列。")]),t._v(" "),e("p",[t._v("一个实体的一个物理量对应一个时间序列,即实体+物理量=时间序列。")]),t._v(" "),e("p",[t._v("时间序列也被称测点(meter)、时间线(timeline)。实时数据库中常被称作标签(tag)、参数(parameter)。")]),t._v(" "),e("p",[t._v("例如,ln 电力集团、wf01 风电场的实体 wt01 有名为 status 的物理量,则它的时间序列可以表示为:"),e("code",[t._v("root.ln.wf01.wt01.status")]),t._v("。")]),t._v(" "),e("h3",{attrs:{id:"对齐时间序列-aligned-timeseries"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#对齐时间序列-aligned-timeseries"}},[t._v("#")]),t._v(" 对齐时间序列(Aligned Timeseries)")]),t._v(" "),e("p",[t._v("在实际应用中,存在某些实体的多个物理量"),e("strong",[t._v("同时采样")]),t._v(",形成在时间列上对齐的多条时间序列。")]),t._v(" "),e("p",[t._v("通过使用对齐的时间序列,在插入数据时,一组对齐序列的时间戳列在内存和磁盘中仅需存储一次,而不是每个时间序列存储一次。")]),t._v(" "),e("p",[t._v("对齐的一组时间序列最好同时创建。")]),t._v(" "),e("p",[t._v("不可以在对齐序列所属的实体下创建非对齐的序列,不可以在非对齐序列所属的实体下创建对齐序列。")]),t._v(" "),e("p",[t._v("查询数据时,可以对于每一条时间序列单独查询。")]),t._v(" "),e("p",[t._v("插入数据时,对齐的时间序列中某列的某些行允许有空值。")]),t._v(" "),e("img",{staticStyle:{width:"100%","max-width":"800px","max-height":"600px","margin-left":"auto","margin-right":"auto",display:"block"},attrs:{src:"https://user-images.githubusercontent.com/19167280/114125919-f4850800-9929-11eb-8211-81d4c04af1ec.png"}}),t._v(" "),e("p",[t._v("在后续数据定义语言、数据操作语言和 Java 原生接口章节,将对涉及到对齐时间序列的各种操作进行逐一介绍。")])])}),[],!1,null,null,null);e.default=a.exports}}]);