blob: 7739c0f7d09fd73f3c9114dadc626a5236d784de [file] [log] [blame]
(window.webpackJsonp=window.webpackJsonp||[]).push([[410],{981:function(t,s,a){"use strict";a.r(s);var _=a(70),v=Object(_.a)({},(function(){var t=this,s=t.$createElement,a=t._self._c||s;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h2",{attrs:{id:"spark-tsfile"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#spark-tsfile"}},[t._v("#")]),t._v(" Spark-TsFile")]),t._v(" "),a("h3",{attrs:{id:"about-tsfile-spark-connector"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#about-tsfile-spark-connector"}},[t._v("#")]),t._v(" About TsFile-Spark-Connector")]),t._v(" "),a("p",[t._v("TsFile-Spark-Connector对Tsfile类型的外部数据源实现Spark的支持。 这使用户可以通过Spark读取,写入和查询Tsfile。")]),t._v(" "),a("p",[t._v("使用此连接器,您可以")]),t._v(" "),a("ul",[a("li",[t._v("从本地文件系统或hdfs加载单个TsFile到Spark")]),t._v(" "),a("li",[t._v("将本地文件系统或hdfs中特定目录中的所有文件加载到Spark中")]),t._v(" "),a("li",[t._v("将数据从Spark写入TsFile")])]),t._v(" "),a("h3",{attrs:{id:"system-requirements"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#system-requirements"}},[t._v("#")]),t._v(" System Requirements")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("Spark Version")]),t._v(" "),a("th",[t._v("Scala Version")]),t._v(" "),a("th",[t._v("Java Version")]),t._v(" "),a("th",[t._v("TsFile")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[a("code",[t._v("2.4.3")])]),t._v(" "),a("td",[a("code",[t._v("2.11.8")])]),t._v(" "),a("td",[a("code",[t._v("1.8")])]),t._v(" "),a("td",[a("code",[t._v("0.13.0-SNAPSHOT")])])])])]),t._v(" "),a("blockquote",[a("p",[t._v("注意:有关如何下载和使用TsFile的更多信息,请参见以下链接:https://github.com/apache/iotdb/tree/master/tsfile\n注意:spark版本目前仅支持2.4.3, 其他版本可能存在不适配的问题, 目前已知2.4.7的版本存在不适配的问题")])]),t._v(" "),a("h3",{attrs:{id:"快速开始"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#快速开始"}},[t._v("#")]),t._v(" 快速开始")]),t._v(" "),a("h4",{attrs:{id:"本地模式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#本地模式"}},[t._v("#")]),t._v(" 本地模式")]),t._v(" "),a("p",[t._v("在本地模式下使用TsFile-Spark-Connector启动Spark:")]),t._v(" "),a("div",{staticClass:"language- line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("./<spark-shell-path> --jars tsfile-spark-connector.jar,tsfile-{version}-jar-with-dependencies.jar,hadoop-tsfile-{version}-jar-with-dependencies.jar\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br")])]),a("ul",[a("li",[t._v("<spark-shell-path>是您的spark-shell的真实路径。")]),t._v(" "),a("li",[t._v("多个jar包用逗号分隔,没有任何空格。")]),t._v(" "),a("li",[t._v("有关如何获取TsFile的信息,请参见https://github.com/apache/iotdb/tree/master/tsfile。")]),t._v(" "),a("li",[t._v("获取到dependency 包:"),a("code",[t._v("mvn clean package -DskipTests -P get-jar-with-dependencies")])])]),t._v(" "),a("h4",{attrs:{id:"分布式模式"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#分布式模式"}},[t._v("#")]),t._v(" 分布式模式")]),t._v(" "),a("p",[t._v("在分布式模式下使用TsFile-Spark-Connector启动Spark(即,Spark集群通过spark-shell连接):")]),t._v(" "),a("div",{staticClass:"language- line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v(". /<spark-shell-path> --jars tsfile-spark-connector.jar,tsfile-{version}-jar-with-dependencies.jar,hadoop-tsfile-{version}-jar-with-dependencies.jar --master spark://ip:7077\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br")])]),a("p",[t._v("注意:")]),t._v(" "),a("ul",[a("li",[t._v("<spark-shell-path>是您的spark-shell的真实路径。")]),t._v(" "),a("li",[t._v("多个jar包用逗号分隔,没有任何空格。")]),t._v(" "),a("li",[t._v("有关如何获取TsFile的信息,请参见https://github.com/apache/iotdb/tree/master/tsfile。")])]),t._v(" "),a("h3",{attrs:{id:"数据类型对应"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#数据类型对应"}},[t._v("#")]),t._v(" 数据类型对应")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("TsFile数据类型")]),t._v(" "),a("th",[t._v("SparkSQL数据类型")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("BOOLEAN")]),t._v(" "),a("td",[t._v("BooleanType")])]),t._v(" "),a("tr",[a("td",[t._v("INT32")]),t._v(" "),a("td",[t._v("IntegerType")])]),t._v(" "),a("tr",[a("td",[t._v("INT64")]),t._v(" "),a("td",[t._v("LongType")])]),t._v(" "),a("tr",[a("td",[t._v("FLOAT")]),t._v(" "),a("td",[t._v("FloatType")])]),t._v(" "),a("tr",[a("td",[t._v("DOUBLE")]),t._v(" "),a("td",[t._v("DoubleType")])]),t._v(" "),a("tr",[a("td",[t._v("TEXT")]),t._v(" "),a("td",[t._v("StringType")])])])]),t._v(" "),a("h3",{attrs:{id:"模式推断"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#模式推断"}},[t._v("#")]),t._v(" 模式推断")]),t._v(" "),a("p",[t._v("显示TsFile的方式取决于架构。 以以下TsFile结构为例:TsFile模式中有三个度量:状态,温度和硬件。 这三种测量的基本信息如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("名称")]),t._v(" "),a("th",[t._v("类型")]),t._v(" "),a("th",[t._v("编码")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("状态")]),t._v(" "),a("td",[t._v("Boolean")]),t._v(" "),a("td",[t._v("PLAIN")])]),t._v(" "),a("tr",[a("td",[t._v("温度")]),t._v(" "),a("td",[t._v("Float")]),t._v(" "),a("td",[t._v("RLE")])]),t._v(" "),a("tr",[a("td",[t._v("硬件")]),t._v(" "),a("td",[t._v("Text")]),t._v(" "),a("td",[t._v("PLAIN")])])])]),t._v(" "),a("p",[t._v("TsFile中的现有数据如下:")]),t._v(" "),a("ul",[a("li",[t._v("d1:root.ln.wf01.wt01")]),t._v(" "),a("li",[t._v("d2:root.ln.wf02.wt02")])]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("time")]),t._v(" "),a("th",[t._v("d1.status")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("d1.temperature")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("d2.hardware")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("d2.status")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("1")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("2")]),t._v(" "),a("td",[t._v('"aaa"')]),t._v(" "),a("td",[t._v("1")]),t._v(" "),a("td",[t._v("True")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("2")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("4")]),t._v(" "),a("td",[t._v('"bbb"')]),t._v(" "),a("td",[t._v("2")]),t._v(" "),a("td",[t._v("False")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("3")]),t._v(" "),a("td",[t._v("2.1")]),t._v(" "),a("td",[t._v("6")]),t._v(" "),a("td",[t._v('"ccc"')]),t._v(" "),a("td",[t._v("4")]),t._v(" "),a("td",[t._v("True")])])])]),t._v(" "),a("p",[t._v("相应的SparkSQL表如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("time")]),t._v(" "),a("th",[t._v("root.ln.wf02.wt02.temperature")]),t._v(" "),a("th",[t._v("root.ln.wf02.wt02.status")]),t._v(" "),a("th",[t._v("root.ln.wf02.wt02.hardware")]),t._v(" "),a("th",[t._v("root.ln.wf01.wt01.temperature")]),t._v(" "),a("th",[t._v("root.ln.wf01.wt01.status")]),t._v(" "),a("th",[t._v("root.ln.wf01.wt01.hardware")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("false")]),t._v(" "),a("td",[t._v("aaa")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.1")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("bbb")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("false")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("6")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("ccc")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])])])]),t._v(" "),a("p",[t._v("您还可以使用如下所示的窄表形式:(您可以参阅第6部分,了解如何使用窄表形式)")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("time")]),t._v(" "),a("th",[t._v("device_name")]),t._v(" "),a("th",[t._v("status")]),t._v(" "),a("th",[t._v("hardware")]),t._v(" "),a("th",[t._v("temperature")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt01")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.2")])]),t._v(" "),a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.2")])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("false")]),t._v(" "),a("td",[t._v("aaa")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt01")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.1")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("true")]),t._v(" "),a("td",[t._v("bbb")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt01")]),t._v(" "),a("td",[t._v("false")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("6")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("ccc")]),t._v(" "),a("td",[t._v("null")])])])]),t._v(" "),a("h3",{attrs:{id:"scala-api"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#scala-api"}},[t._v("#")]),t._v(" Scala API")]),t._v(" "),a("p",[t._v("注意:请记住预先分配必要的读写权限。")]),t._v(" "),a("ul",[a("li",[t._v("示例1:从本地文件系统读取")])]),t._v(" "),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" wide_df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nwide_df"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" narrow_df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nnarrow_df"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br"),a("span",{staticClass:"line-number"},[t._v("6")]),a("br")])]),a("ul",[a("li",[t._v("示例2:从hadoop文件系统读取")])]),t._v(" "),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" wide_df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nwide_df"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" narrow_df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \nnarrow_df"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br"),a("span",{staticClass:"line-number"},[t._v("6")]),a("br")])]),a("ul",[a("li",[t._v("示例3:从特定目录读取")])]),t._v(" "),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/usr/hadoop"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br")])]),a("p",[t._v("注1:现在不支持目录中所有TsFile的全局时间排序。")]),t._v(" "),a("p",[t._v("注2:具有相同名称的度量应具有相同的架构。")]),t._v(" "),a("ul",[a("li",[t._v("示例4:广泛形式的查询")])]),t._v(" "),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("createOrReplaceTempView"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"tsfile_table"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" newDf "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sql"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"select * from tsfile_table where `device_1.sensor_1`>0 and `device_1.sensor_2` < 22"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nnewDf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br")])]),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("createOrReplaceTempView"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"tsfile_table"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" newDf "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sql"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"select count(*) from tsfile_table"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nnewDf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br")])]),a("ul",[a("li",[t._v("示例5:缩小形式的查询")])]),t._v(" "),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("createOrReplaceTempView"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"tsfile_table"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" newDf "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sql"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("\"select * from tsfile_table where device_name = 'root.ln.wf02.wt02' and temperature > 5\"")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nnewDf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br")])]),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("createOrReplaceTempView"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"tsfile_table"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" newDf "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("sql"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"select count(*) from tsfile_table"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nnewDf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br")])]),a("ul",[a("li",[t._v("例6:写宽格式")])]),t._v(" "),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// we only support wide_form table to write")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("write"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/output"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" newDf "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/output"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nnewDf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br"),a("span",{staticClass:"line-number"},[t._v("6")]),a("br"),a("span",{staticClass:"line-number"},[t._v("7")]),a("br"),a("span",{staticClass:"line-number"},[t._v("8")]),a("br"),a("span",{staticClass:"line-number"},[t._v("9")]),a("br")])]),a("ul",[a("li",[t._v("例7:写窄格式")])]),t._v(" "),a("div",{staticClass:"language-scala line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-scala"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// we only support wide_form table to write")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("org"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("apache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("iotdb"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")])]),t._v("_\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" df "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/test.tsfile"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\ndf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("write"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/output"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("val")]),t._v(" newDf "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" spark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("read"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("tsfile"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"hdfs://localhost:9000/output"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nnewDf"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("show\n")])]),t._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[t._v("1")]),a("br"),a("span",{staticClass:"line-number"},[t._v("2")]),a("br"),a("span",{staticClass:"line-number"},[t._v("3")]),a("br"),a("span",{staticClass:"line-number"},[t._v("4")]),a("br"),a("span",{staticClass:"line-number"},[t._v("5")]),a("br"),a("span",{staticClass:"line-number"},[t._v("6")]),a("br"),a("span",{staticClass:"line-number"},[t._v("7")]),a("br"),a("span",{staticClass:"line-number"},[t._v("8")]),a("br"),a("span",{staticClass:"line-number"},[t._v("9")]),a("br")])]),a("p",[t._v("附录A:模式推断的旧设计")]),t._v(" "),a("p",[t._v("显示TsFile的方式与TsFile Schema有关。 以以下TsFile结构为例:TsFile架构中有三个度量:状态,温度和硬件。 这三个度量的基本信息如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("名称")]),t._v(" "),a("th",[t._v("类型")]),t._v(" "),a("th",[t._v("编码")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("状态")]),t._v(" "),a("td",[t._v("Boolean")]),t._v(" "),a("td",[t._v("PLAIN")])]),t._v(" "),a("tr",[a("td",[t._v("温度")]),t._v(" "),a("td",[t._v("Float")]),t._v(" "),a("td",[t._v("RLE")])]),t._v(" "),a("tr",[a("td",[t._v("硬件")]),t._v(" "),a("td",[t._v("Text")]),t._v(" "),a("td",[t._v("PLAIN")])])])]),t._v(" "),a("p",[t._v("文件中的现有数据如下:")]),t._v(" "),a("ul",[a("li",[t._v("delta_object1: root.ln.wf01.wt01")]),t._v(" "),a("li",[t._v("delta_object2: root.ln.wf02.wt02")]),t._v(" "),a("li",[t._v("delta_object3: :root.sgcc.wf03.wt01")])]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("time")]),t._v(" "),a("th",[t._v("delta_object1.status")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("delta_object1.temperature")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("delta_object2.hardware")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("delta_object2.status")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("delta_object3.status")]),t._v(" "),a("th",[t._v("time")]),t._v(" "),a("th",[t._v("delta_object3.temperature")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("1")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("2")]),t._v(" "),a("td",[t._v('"aaa"')]),t._v(" "),a("td",[t._v("1")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("2")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("3")]),t._v(" "),a("td",[t._v("3.3")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("2")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("4")]),t._v(" "),a("td",[t._v('"bbb"')]),t._v(" "),a("td",[t._v("2")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("3")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("6")]),t._v(" "),a("td",[t._v("6.6")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("3")]),t._v(" "),a("td",[t._v("2.1")]),t._v(" "),a("td",[t._v("6")]),t._v(" "),a("td",[t._v('"ccc"')]),t._v(" "),a("td",[t._v("4")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("4")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("8")]),t._v(" "),a("td",[t._v("8.8")])]),t._v(" "),a("tr",[a("td",[t._v("7")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("4")]),t._v(" "),a("td",[t._v("2.0")]),t._v(" "),a("td",[t._v("8")]),t._v(" "),a("td",[t._v('"ddd"')]),t._v(" "),a("td",[t._v("5")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("6")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("9")]),t._v(" "),a("td",[t._v("9.9")])])])]),t._v(" "),a("p",[t._v("有两种显示方法:")]),t._v(" "),a("ul",[a("li",[t._v("默认方式")])]),t._v(" "),a("p",[t._v("将创建两列来存储设备的完整路径:time(LongType)和delta_object(StringType)。")]),t._v(" "),a("ul",[a("li",[a("code",[t._v("time")]),t._v(":时间戳记,LongType")]),t._v(" "),a("li",[a("code",[t._v("delta_object")]),t._v(":Delta_object ID,StringType")])]),t._v(" "),a("p",[t._v("接下来,为每个度量创建一列以存储特定数据。 SparkSQL表结构如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("time(LongType)")]),t._v(" "),a("th",[t._v("delta_object(StringType)")]),t._v(" "),a("th",[t._v("status(BooleanType)")]),t._v(" "),a("th",[t._v("temperature(FloatType)")]),t._v(" "),a("th",[t._v("hardware(StringType)")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("root.ln.wf01.wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("root.ln.wf01.wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"aaa"')])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("root.sgcc.wf03.wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("root.ln.wf01.wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("2.1")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("root.sgcc.wf03.wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("3.3")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("root.ln.wf01.wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.0")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"bbb"')])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("root.sgcc.wf03.wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("root.ln.wf01.wt01")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("root.sgcc.wf03.wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("6")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"ccc"')])]),t._v(" "),a("tr",[a("td",[t._v("6")]),t._v(" "),a("td",[t._v("root.sgcc.wf03.wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("6.6")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("7")]),t._v(" "),a("td",[t._v("root.ln.wf01.wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("8")]),t._v(" "),a("td",[t._v("root.ln.wf02.wt02")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"ddd"')])]),t._v(" "),a("tr",[a("td",[t._v("8")]),t._v(" "),a("td",[t._v("root.sgcc.wf03.wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("8.8")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("9")]),t._v(" "),a("td",[t._v("root.sgcc.wf03.wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("9.9")]),t._v(" "),a("td",[t._v("null")])])])]),t._v(" "),a("ul",[a("li",[t._v("展开delta_object列")])]),t._v(" "),a("p",[t._v("通过“。”将设备列展开为多个列,忽略根目录“root”。方便进行更丰富的聚合操作。如果用户想使用这种显示方式,需要在表创建语句中设置参数“delta_object_name”(参考本手册5.1节中的示例5),在本例中,将参数“delta_object_name”设置为“root.device.turbine”。路径层的数量必须是一对一的。此时,除了“根”层之外,为设备路径的每一层创建一列。列名是参数中的名称,值是设备相应层的名称。接下来,将为每个度量创建一个列来存储特定的数据。")]),t._v(" "),a("p",[t._v("那么SparkSQL表结构如下:")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("time(LongType)")]),t._v(" "),a("th",[t._v("group(StringType)")]),t._v(" "),a("th",[t._v("field(StringType)")]),t._v(" "),a("th",[t._v("device(StringType)")]),t._v(" "),a("th",[t._v("status(BooleanType)")]),t._v(" "),a("th",[t._v("temperature(FloatType)")]),t._v(" "),a("th",[t._v("hardware(StringType)")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf01")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("1")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf02")]),t._v(" "),a("td",[t._v("wt02")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf01")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.2")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf02")]),t._v(" "),a("td",[t._v("wt02")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"aaa"')])]),t._v(" "),a("tr",[a("td",[t._v("2")]),t._v(" "),a("td",[t._v("sgcc")]),t._v(" "),a("td",[t._v("wf03")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf01")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("2.1")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("3")]),t._v(" "),a("td",[t._v("sgcc")]),t._v(" "),a("td",[t._v("wf03")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("3.3")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf01")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("2.0")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf02")]),t._v(" "),a("td",[t._v("wt02")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"bbb"')])]),t._v(" "),a("tr",[a("td",[t._v("4")]),t._v(" "),a("td",[t._v("sgcc")]),t._v(" "),a("td",[t._v("wf03")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf01")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf02")]),t._v(" "),a("td",[t._v("wt02")]),t._v(" "),a("td",[t._v("False")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("5")]),t._v(" "),a("td",[t._v("sgcc")]),t._v(" "),a("td",[t._v("wf03")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("6")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf02")]),t._v(" "),a("td",[t._v("wt02")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"ccc"')])]),t._v(" "),a("tr",[a("td",[t._v("6")]),t._v(" "),a("td",[t._v("sgcc")]),t._v(" "),a("td",[t._v("wf03")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("6.6")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("7")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf01")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("True")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("8")]),t._v(" "),a("td",[t._v("ln")]),t._v(" "),a("td",[t._v("wf02")]),t._v(" "),a("td",[t._v("wt02")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v('"ddd"')])]),t._v(" "),a("tr",[a("td",[t._v("8")]),t._v(" "),a("td",[t._v("sgcc")]),t._v(" "),a("td",[t._v("wf03")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("8.8")]),t._v(" "),a("td",[t._v("null")])]),t._v(" "),a("tr",[a("td",[t._v("9")]),t._v(" "),a("td",[t._v("sgcc")]),t._v(" "),a("td",[t._v("wf03")]),t._v(" "),a("td",[t._v("wt01")]),t._v(" "),a("td",[t._v("null")]),t._v(" "),a("td",[t._v("9.9")]),t._v(" "),a("td",[t._v("null")])])])]),t._v(" "),a("p",[t._v("TsFile-Spark-Connector可以通过SparkSQL在SparkSQL中以表的形式显示一个或多个tsfile。它还允许用户指定一个目录或使用通配符来匹配多个目录。如果有多个tsfile,那么所有tsfile中的度量值的并集将保留在表中,并且具有相同名称的度量值在默认情况下具有相同的数据类型。注意,如果存在名称相同但数据类型不同的情况,TsFile-Spark-Connector将不能保证结果的正确性。")]),t._v(" "),a("p",[t._v("写入过程是将数据aframe写入一个或多个tsfile。默认情况下,需要包含两个列:time和delta_object。其余的列用作测量。如果用户希望将第二个表结构写回TsFile,可以设置“delta_object_name”参数(请参阅本手册5.1节的5.1节)。")]),t._v(" "),a("p",[t._v("附录B:旧注")]),t._v(" "),a("p",[t._v("注意:检查Spark根目录中的jar软件包,并将libthrift-0.9.2.jar和libfb303-0.9.2.jar分别替换为libthrift-0.9.1.jar和libfb303-0.9.1.jar。")])])}),[],!1,null,null,null);s.default=v.exports}}]);