Skip to content

Latest commit

 

History

History
166 lines (140 loc) · 7.01 KB

File metadata and controls

166 lines (140 loc) · 7.01 KB

Schema Import

1. Overview

The schema import tool import-schema.sh/bat is located in tools directory.

2. Detailed Functionality

2.1 Parameter

Short Param Full Param Description Required Default
-h --host Hostname No 127.0.0.1
-p --port Port number No 6667
-u --username Username No root
-pw --password Password, Supported for hidden input since V2.0.9.1 No TimechoDB@2021(Before V2.0.6 it is root)
-sql_dialect --sql_dialect Specifies whether the server usestree model ortable model No tree
-db --database Target database for import Yes -
-table --table Target table for import (only applies when-sql_dialect=table) No -
-s --source Local directory path containing script file(s) to import Yes
-fd --fail_dir Directory to save failed import files No
-lpf --lines_per_failed_file Maximum lines per failed file (only applies when-sql_dialect=table) No 100000Range:0 to Integer.Max=2147483647
-help --help Display help information No
-usessl --use_ssl Use SSL protocol. Supported since V2.0.9.1 No -
-ts --trust_store Trust store. Supports hidden input. Supported since V2.0.9.1 No -
-tpw --trust_store_password Trust store password. Supports hidden input. Supported since V2.0.9.1 No -

2.2 Command

# 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
# Before version 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 and later versions       
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 Examples

Import dump_database1.sql from /home into database2,

-- File content (dump_database1.sql):
DROP TABLE IF EXISTS table1;
CREATE TABLE table1(
        time TIMESTAMP TIME,
        region STRING TAG,
        plant_id STRING TAG,
        device_id STRING TAG,
        model_id STRING ATTRIBUTE,
        maintenance STRING ATTRIBUTE,
        temperature FLOAT FIELD,
        humidity FLOAT FIELD,
        status BOOLEAN FIELD,
        arrival_time TIMESTAMP FIELD
);
DROP TABLE IF EXISTS table2;
CREATE TABLE table2(
        time TIMESTAMP TIME,
        region STRING TAG,
        plant_id STRING TAG,
        device_id STRING TAG,
        model_id STRING ATTRIBUTE,
        maintenance STRING ATTRIBUTE,
        temperature FLOAT FIELD,
        humidity FLOAT FIELD,
        status BOOLEAN FIELD,
        arrival_time TIMESTAMP FIELD
);

Executing the command:

./import-schema.sh -sql_dialect table -s /home/dump_database1.sql -db database2 

# If database2 doesn't exist
The target database database2 does not exist

# If database2 exists
Import completely!

Verification:

# Before import
IoTDB:database2> show tables
+---------+-------+
|TableName|TTL(ms)|
+---------+-------+
+---------+-------+
Empty set.

# After import
IoTDB:database2> show tables details
+---------+-------+------+-------+
|TableName|TTL(ms)|Status|Comment|
+---------+-------+------+-------+
|   table2|    INF| USING|   null|
|   table1|    INF| USING|   null|
+---------+-------+------+-------+

IoTDB:database2> desc table1
+------------+---------+---------+
|  ColumnName| DataType| Category|
+------------+---------+---------+
|        time|TIMESTAMP|     TIME|
|      region|   STRING|      TAG|
|    plant_id|   STRING|      TAG|
|   device_id|   STRING|      TAG|
|    model_id|   STRING|ATTRIBUTE|
| maintenance|   STRING|ATTRIBUTE|
| temperature|    FLOAT|    FIELD|
|    humidity|    FLOAT|    FIELD|
|      status|  BOOLEAN|    FIELD|
|arrival_time|TIMESTAMP|    FIELD|
+------------+---------+---------+
 
IoTDB:database2> desc table2
+------------+---------+---------+
|  ColumnName| DataType| Category|
+------------+---------+---------+
|        time|TIMESTAMP|     TIME|
|      region|   STRING|      TAG|
|    plant_id|   STRING|      TAG|
|   device_id|   STRING|      TAG|
|    model_id|   STRING|ATTRIBUTE|
| maintenance|   STRING|ATTRIBUTE|
| temperature|    FLOAT|    FIELD|
|    humidity|    FLOAT|    FIELD|
|      status|  BOOLEAN|    FIELD|
|arrival_time|TIMESTAMP|    FIELD|
+------------+---------+---------+