元数据导入

1. 功能概述

元数据导入工具 import-schema.sh/bat 位于tools 目录下,能够将指定路径下创建元数据的脚本文件导入到 IoTDB 中。

2. 功能详解

2.1 参数介绍

参数缩写参数全称参数含义是否为必填项默认值
-h-- host主机名127.0.0.1
-p--port端口号6667
-u--username用户名root
-pw--password密码TimechoDB@2021 (V2.0.6.x 版本之前为 root)
-sql_dialect--sql_dialect选择 server 是树模型还是表模型,当前支持 tree 和 table 类型tree
-db--database将要导入的目标数据库-
-table--table将要导入的目标表,只在-sql_dialect为 table 类型下生效。-
-s--source待加载的脚本文件(夹)的本地目录路径。
-fd--fail_dir指定保存失败文件的目录
-lpf--lines_per_failed_file指定失败文件最大写入数据的行数,只在-sql_dialect为 table 类型下生效。100000范围:0~Integer.Max=2147483647
-help--help显示帮助信息

2.2 运行命令

# Unix/OS X
tools/import-schema.sh [-sql_dialect<sql_dialect>] -db<database> -table<table> 
     [-h <host>] [-p <port>] [-u <username>] [-pw <password>]
       -s <source> [-fd <fail_dir>] [-lpf <lines_per_failed_file>]
      
# Windows
# V2.0.4.x 版本之前
tools\import-schema.bat [-sql_dialect<sql_dialect>] -db<database> -table<table>  
        [-h <host>] [-p <port>] [-u <username>] [-pw <password>]
       -s <source> [-fd <fail_dir>] [-lpf <lines_per_failed_file>] 
       
# V2.0.4.x 版本及之后 
tools\windows\schema\import-schema.bat [-sql_dialect<sql_dialect>] -db<database> -table<table>  
        [-h <host>] [-p <port>] [-u <username>] [-pw <password>]
       -s <source> [-fd <fail_dir>] [-lpf <lines_per_failed_file>] 

2.3 运行示例

# 导入前
IoTDB> show timeseries root.treedb.**
+----------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
|Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType|
+----------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
+----------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+

# 执行导入命令
./import-schema.sh -sql_dialect tree -s /home/dump0_0.csv -db root.treedb

# 导入成功后验证
IoTDB> show timeseries root.treedb.**
+------------------------------+-----+-----------+--------+--------+-----------+----+----------+--------+------------------+--------+
|                    Timeseries|Alias|   Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType|
+------------------------------+-----+-----------+--------+--------+-----------+----+----------+--------+------------------+--------+
|root.treedb.device.temperature| null|root.treedb|  DOUBLE| GORILLA|        LZ4|null|      null|    null|              null|    BASE|
|   root.treedb.device.humidity| null|root.treedb|  DOUBLE| GORILLA|        LZ4|null|      null|    null|              null|    BASE|
+------------------------------+-----+-----------+--------+--------+-----------+----+----------+--------+------------------+--------+