From 07a85cef3ab85b5c652a977232452f211a701ef3 Mon Sep 17 00:00:00 2001 From: W1y1r <2730956796@qq.com> Date: Mon, 24 Feb 2025 17:46:14 +0800 Subject: [PATCH 1/2] Adjust document structure --- src/.vuepress/navbar/en.ts | 8 +- src/.vuepress/navbar/zh.ts | 8 +- src/.vuepress/sidebar/V1.3.0-2/en.ts | 192 - src/.vuepress/sidebar/V1.3.0-2/zh.ts | 175 - .../sidebar/{V1.3.3 => V1.3.x}/en.ts | 32 +- .../sidebar/{V1.3.3 => V1.3.x}/zh.ts | 32 +- src/.vuepress/sidebar/en.ts | 2 +- src/.vuepress/sidebar/zh.ts | 2 +- src/.vuepress/sidebar_timecho/V1.3.0-2/en.ts | 209 - src/.vuepress/sidebar_timecho/V1.3.0-2/zh.ts | 186 - .../sidebar_timecho/{V1.3.3 => V1.3.x}/en.ts | 30 +- .../sidebar_timecho/{V1.3.3 => V1.3.x}/zh.ts | 30 +- src/.vuepress/sidebar_timecho/en.ts | 2 +- src/.vuepress/sidebar_timecho/zh.ts | 2 +- .../API/Programming-CSharp-Native-API.md | 0 .../API/Programming-Cpp-Native-API.md | 0 .../API/Programming-Data-Subscription.md | 0 .../API/Programming-Go-Native-API.md | 0 .../API/Programming-JDBC.md | 0 .../API/Programming-Java-Native-API.md | 0 .../API/Programming-Kafka.md | 0 .../API/Programming-MQTT.md | 0 .../API/Programming-NodeJS-Native-API.md | 0 .../API/Programming-ODBC.md | 0 .../API/Programming-OPC-UA_timecho.md | 0 .../API/Programming-Python-Native-API.md | 0 .../API/Programming-Rust-Native-API.md | 0 .../{V1.3.3 => V1.3.x}/API/RestServiceV1.md | 0 .../{V1.3.3 => V1.3.x}/API/RestServiceV2.md | 0 .../Background-knowledge/Cluster-Concept.md | 0 .../Cluster-Concept_apache.md | 0 .../Cluster-Concept_timecho.md | 0 .../Background-knowledge/Data-Type.md | 0 .../Data-Model-and-Terminology.md | 0 .../Navigating_Time_Series_Data.md | 0 .../Basic-Concept/Operate-Metadata.md | 0 .../Basic-Concept/Operate-Metadata_apache.md | 0 .../Basic-Concept/Operate-Metadata_timecho.md | 0 .../Basic-Concept/Query-Data.md | 0 .../Basic-Concept/Write-Delete-Data.md | 0 .../AINode_Deployment_apache.md | 0 .../AINode_Deployment_timecho.md | 0 .../Cluster-Deployment_apache.md | 0 .../Cluster-Deployment_timecho.md | 0 .../Database-Resources.md | 0 .../Docker-Deployment_apache.md | 0 .../Docker-Deployment_timecho.md | 0 .../Dual-Active-Deployment_timecho.md | 0 .../Environment-Requirements.md | 0 .../IoTDB-Package.md | 0 .../IoTDB-Package_apache.md | 0 .../IoTDB-Package_timecho.md | 0 .../Monitoring-panel-deployment.md | 0 .../Stand-Alone-Deployment_apache.md | 0 .../Stand-Alone-Deployment_timecho.md | 0 .../workbench-deployment_timecho.md | 0 .../Ecosystem-Integration/DBeaver.md | 0 .../Ecosystem-Integration/DataEase.md | 0 .../Ecosystem-Integration/Flink-IoTDB.md | 0 .../Ecosystem-Integration/Flink-TsFile.md | 0 .../Grafana-Connector.md | 0 .../Ecosystem-Integration/Grafana-Plugin.md | 0 .../Ecosystem-Integration/Hive-TsFile.md | 0 .../Ignition-IoTDB-plugin_timecho.md | 0 .../Kubernetes_apache.md | 0 .../Kubernetes_timecho.md | 0 .../Ecosystem-Integration/NiFi-IoTDB.md | 0 .../Ecosystem-Integration/Spark-IoTDB.md | 0 .../Ecosystem-Integration/Spark-TsFile.md | 0 .../Ecosystem-Integration/Telegraf.md | 0 .../Ecosystem-Integration/Thingsboard.md | 0 .../Ecosystem-Integration/Zeppelin-IoTDB.md | 0 .../FAQ/Frequently-asked-questions.md | 0 .../IoTDB-Introduction_apache.md | 0 .../IoTDB-Introduction_timecho.md | 0 .../IoTDB-Introduction/Scenario.md | 0 .../QuickStart/QuickStart.md | 0 .../QuickStart/QuickStart_apache.md | 0 .../QuickStart/QuickStart_timecho.md | 0 .../Reference/Common-Config-Manual-old.md | 2065 +++++++ .../Reference/Common-Config-Manual.md | 0 .../Reference/ConfigNode-Config-Manual-old.md | 223 + .../Reference/ConfigNode-Config-Manual.md | 0 .../Reference/DataNode-Config-Manual-old.md} | 0 .../DataNode-Config-Manual-old_apache.md | 500 ++ .../DataNode-Config-Manual-old_timecho.md | 592 ++ .../Reference/DataNode-Config-Manual.md | 0 .../DataNode-Config-Manual_apache.md | 0 .../DataNode-Config-Manual_timecho.md | 0 .../{V1.3.3 => V1.3.x}/Reference/Keywords.md | 0 .../Reference/Modify-Config-Manual.md | 0 .../Reference/Status-Codes.md | 0 .../Reference/Syntax-Rule.md | 0 .../SQL-Manual/Function-and-Expression.md | 0 .../SQL-Manual/Operator-and-Expression.md | 0 .../SQL-Manual/SQL-Manual.md | 0 .../SQL-Manual/UDF-Libraries.md | 0 .../SQL-Manual/UDF-Libraries_apache.md | 0 .../SQL-Manual/UDF-Libraries_timecho.md | 0 .../Cluster-data-partitioning.md | 0 .../Encoding-and-Compression.md | 0 .../Technical-Insider/Publication.md | 0 .../Tools-System/Benchmark.md | 0 .../{V1.3.3 => V1.3.x}/Tools-System/CLI.md | 0 .../Tools-System/Data-Export-Tool.md | 0 .../Tools-System/Data-Import-Export-Tool.md | 278 + .../Tools-System/Data-Import-Tool.md | 0 .../Tools-System/Maintenance-Tool_apache.md | 0 .../Tools-System/Maintenance-Tool_timecho.md | 0 .../Tools-System/Monitor-Tool.md | 0 .../Tools-System/Monitor-Tool_apache.md | 0 .../Tools-System/Monitor-Tool_timecho.md | 0 .../Tools-System/TsFile-Import-Export-Tool.md | 428 ++ .../Tools-System/Workbench_timecho.md | 0 .../User-Manual/AINode_apache.md | 0 .../User-Manual/AINode_timecho.md | 0 .../User-Manual/Audit-Log_timecho.md | 0 .../User-Manual/Authority-Management.md | 0 .../User-Manual/Data-Recovery.md | 0 .../User-Manual/Data-Sync-old_apache.md | 542 ++ .../User-Manual/Data-Sync-old_timecho.md | 613 ++ .../User-Manual/Data-Sync_apache.md | 0 .../User-Manual/Data-Sync_timecho.md | 0 .../User-Manual/Data-subscription.md | 0 .../User-Manual/Database-Programming.md | 0 .../User-Manual/IoTDB-View_timecho.md | 0 .../User-Manual/Load-Balance.md | 0 .../User-Manual/Query-Performance-Analysis.md | 0 .../User-Manual/Streaming_apache.md | 0 .../User-Manual/Streaming_timecho.md | 0 .../User-Manual/Tiered-Storage_timecho.md | 0 .../{V1.3.3 => V1.3.x}/User-Manual/Trigger.md | 0 .../User-Manual/UDF-development.md | 0 .../User-defined-function_apache.md | 0 .../User-defined-function_timecho.md | 0 .../User-Manual/White-List_timecho.md | 0 .../{V1.3.3 => V1.3.x}/UserGuideReadme.md | 0 .../API/Programming-Cpp-Native-API.md | 433 -- .../V1.3.0-2/API/Programming-JDBC.md | 208 - .../API/Programming-Java-Native-API.md | 501 -- .../V1.3.0-2/API/Programming-MQTT.md | 179 - .../API/Programming-Python-Native-API.md | 717 --- .../UserGuide/V1.3.0-2/API/RestServiceV1.md | 941 --- .../UserGuide/V1.3.0-2/API/RestServiceV2.md | 980 --- .../V1.3.0-2/Basic-Concept/Cluster-Concept.md | 55 - .../Data-Model-and-Terminology.md | 140 - .../V1.3.0-2/Basic-Concept/Data-Type.md | 179 - .../Basic-Concept/Encoding-and-Compression.md | 121 - .../AINode_Deployment_timecho.md | 545 -- .../Cluster-Deployment_apache.md | 345 -- .../Cluster-Deployment_timecho.md | 387 -- .../Database-Resources.md | 200 - .../IoTDB-Package_apache.md | 45 - .../Monitoring-panel-deployment.md | 682 --- .../Slow-Query-Management.md | 35 - .../Stand-Alone-Deployment_apache.md | 179 - .../Stand-Alone-Deployment_timecho.md | 220 - .../workbench-deployment_timecho.md | 248 - .../Ecosystem-Integration/DataEase.md | 229 - .../Ecosystem-Integration/Grafana-Plugin.md | 288 - .../Ignition-IoTDB-plugin_timecho.md | 274 - .../Ecosystem-Integration/Spark-IoTDB.md | 229 - .../Ecosystem-Integration/Telegraf-IoTDB.md | 110 - .../Ecosystem-Integration/Thingsboard.md | 99 - .../FAQ/Frequently-asked-questions.md | 261 - .../IoTDB-Introduction/Architecture.md | 44 - .../V1.3.0-2/IoTDB-Introduction/Features.md | 59 - .../IoTDB-Introduction_apache.md | 76 - .../IoTDB-Introduction_timecho.md | 266 - .../IoTDB-Introduction/Performance.md | 36 - .../IoTDB-Introduction/Publication.md | 42 - .../V1.3.0-2/QuickStart/QuickStart_apache.md | 80 - .../V1.3.0-2/QuickStart/QuickStart_timecho.md | 92 - .../Reference/Function-and-Expression.md | 3200 ---------- .../Reference/Modify-Config-Manual.md | 72 - .../Reference/UDF-Libraries_timecho.md | 5281 ---------------- .../V1.3.0-2/SQL-Manual/SQL-Manual.md | 1970 ------ .../V1.3.0-2/Tools-System/Benchmark.md | 352 -- src/zh/UserGuide/V1.3.0-2/Tools-System/CLI.md | 276 - .../Tools-System/Maintenance-Tool_apache.md | 229 - .../Tools-System/Maintenance-Tool_timecho.md | 1001 --- .../Tools-System/Monitor-Tool_apache.md | 168 - .../Tools-System/Monitor-Tool_timecho.md | 168 - .../Tools-System/Workbench_timecho.md | 31 - .../User-Manual/Database-Programming.md | 1032 ---- .../User-Manual/IoTDB-View_timecho.md | 546 -- .../V1.3.0-2/User-Manual/Maintennance.md | 351 -- .../User-Manual/Operate-Metadata_apache.md | 1283 ---- .../User-Manual/Operate-Metadata_timecho.md | 1285 ---- .../User-Manual/Operator-and-Expression.md | 552 -- .../V1.3.0-2/User-Manual/Query-Data.md | 3041 ---------- .../Security-Management_timecho.md | 158 - .../V1.3.0-2/User-Manual/Streaming_apache.md | 813 --- .../V1.3.0-2/User-Manual/Streaming_timecho.md | 858 --- .../V1.3.0-2/User-Manual/Syntax-Rule.md | 289 - .../User-Manual/Tiered-Storage_timecho.md | 97 - .../User-Manual/User-defined-function.md | 210 - .../V1.3.0-2/User-Manual/Write-Delete-Data.md | 258 - src/zh/UserGuide/V1.3.0-2/UserGuideReadme.md | 30 - .../API/Programming-CSharp-Native-API.md | 274 - .../V1.3.3/API/Programming-Go-Native-API.md | 84 - .../UserGuide/V1.3.3/API/Programming-Kafka.md | 118 - .../API/Programming-NodeJS-Native-API.md | 201 - .../UserGuide/V1.3.3/API/Programming-ODBC.md | 146 - .../V1.3.3/API/Programming-Rust-Native-API.md | 200 - .../Navigating_Time_Series_Data.md | 67 - .../V1.3.3/Basic-Concept/Operate-Metadata.md | 23 - .../Docker-Deployment_apache.md | 412 -- .../Docker-Deployment_timecho.md | 474 -- .../Dual-Active-Deployment_timecho.md | 163 - .../Environment-Requirements.md | 208 - .../IoTDB-Package_timecho.md | 46 - .../V1.3.3/Ecosystem-Integration/DBeaver.md | 83 - .../Ecosystem-Integration/Flink-IoTDB.md | 121 - .../Ecosystem-Integration/Flink-TsFile.md | 178 - .../Grafana-Connector.md | 184 - .../Ecosystem-Integration/Hive-TsFile.md | 167 - .../Ecosystem-Integration/NiFi-IoTDB.md | 140 - .../Ecosystem-Integration/Spark-TsFile.md | 320 - .../Zeppelin-IoTDB_apache.md | 174 - .../Zeppelin-IoTDB_timecho.md | 174 - .../V1.3.3/IoTDB-Introduction/Scenario.md | 95 - src/zh/UserGuide/V1.3.3/Reference/Keywords.md | 227 - .../V1.3.3/Reference/Status-Codes.md | 178 - .../V1.3.3/SQL-Manual/UDF-Libraries.md | 23 - .../V1.3.3/SQL-Manual/UDF-Libraries_apache.md | 5346 ----------------- .../Cluster-data-partitioning.md | 110 - .../V1.3.3/User-Manual/AINode_timecho.md | 650 -- .../User-Manual/Authority-Management.md | 510 -- .../UserGuide/V1.3.3/User-Manual/Trigger.md | 467 -- .../V1.3.3/User-Manual/UDF-development.md | 721 --- .../API/Programming-CSharp-Native-API.md | 0 .../API/Programming-Cpp-Native-API.md | 0 .../API/Programming-Data-Subscription.md | 0 .../API/Programming-Go-Native-API.md | 0 .../API/Programming-JDBC.md | 0 .../API/Programming-Java-Native-API.md | 0 .../API/Programming-Kafka.md | 0 .../API/Programming-MQTT.md | 0 .../API/Programming-NodeJS-Native-API.md | 0 .../API/Programming-ODBC.md | 0 .../API/Programming-OPC-UA_timecho.md | 0 .../API/Programming-Python-Native-API.md | 0 .../API/Programming-Rust-Native-API.md | 0 .../{V1.3.3 => V1.3.x}/API/RestServiceV1.md | 0 .../{V1.3.3 => V1.3.x}/API/RestServiceV2.md | 0 .../Background-knowledge/Cluster-Concept.md | 0 .../Cluster-Concept_apache.md | 0 .../Cluster-Concept_timecho.md | 0 .../Background-knowledge/Data-Type.md | 0 .../Data-Model-and-Terminology.md | 0 .../Navigating_Time_Series_Data.md | 0 .../Basic-Concept}/Operate-Metadata.md | 0 .../Basic-Concept/Operate-Metadata_apache.md | 0 .../Basic-Concept/Operate-Metadata_timecho.md | 0 .../Basic-Concept/Query-Data.md | 0 .../Basic-Concept/Write-Delete-Data.md | 0 .../AINode_Deployment_apache.md | 0 .../AINode_Deployment_timecho.md | 0 .../Cluster-Deployment_apache.md | 0 .../Cluster-Deployment_timecho.md | 0 .../Database-Resources.md | 0 .../Docker-Deployment_apache.md | 0 .../Docker-Deployment_timecho.md | 0 .../Dual-Active-Deployment_timecho.md | 0 .../Environment-Requirements.md | 0 .../IoTDB-Package_apache.md | 0 .../IoTDB-Package_timecho.md | 0 .../Monitoring-panel-deployment.md | 0 .../Slow-Query-Management.md | 0 .../Stand-Alone-Deployment_apache.md | 0 .../Stand-Alone-Deployment_timecho.md | 0 .../workbench-deployment_timecho.md | 0 .../Ecosystem-Integration/DBeaver.md | 0 .../Ecosystem-Integration/DataEase.md | 0 .../Ecosystem-Integration/Flink-IoTDB.md | 0 .../Ecosystem-Integration/Flink-TsFile.md | 0 .../Grafana-Connector.md | 0 .../Ecosystem-Integration/Grafana-Plugin.md | 0 .../Ecosystem-Integration/Hive-TsFile.md | 0 .../Ignition-IoTDB-plugin_timecho.md | 0 .../Kubernetes_apache.md | 0 .../Kubernetes_timecho.md | 0 .../Ecosystem-Integration/NiFi-IoTDB.md | 0 .../Ecosystem-Integration/Spark-IoTDB.md | 0 .../Ecosystem-Integration/Spark-TsFile.md | 0 .../Ecosystem-Integration/Telegraf.md | 0 .../Ecosystem-Integration/Thingsboard.md | 0 .../Zeppelin-IoTDB_apache.md | 0 .../Zeppelin-IoTDB_timecho.md | 0 .../FAQ/Frequently-asked-questions.md | 0 .../IoTDB-Introduction_apache.md | 0 .../IoTDB-Introduction_timecho.md | 0 .../Release-history_apache.md | 0 .../Release-history_timecho.md | 0 .../IoTDB-Introduction/Scenario.md | 0 .../QuickStart/QuickStart.md | 0 .../QuickStart/QuickStart_apache.md | 0 .../QuickStart/QuickStart_timecho.md | 0 .../Reference/Common-Config-Manual-old.md} | 0 .../Reference/Common-Config-Manual.md | 0 .../ConfigNode-Config-Manual-old.md} | 0 .../Reference/ConfigNode-Config-Manual.md | 0 .../Reference/DataNode-Config-Manual-old.md} | 0 .../DataNode-Config-Manual-old_apache.md} | 0 .../DataNode-Config-Manual-old_timecho.md} | 0 .../Reference/DataNode-Config-Manual.md} | 2 +- .../DataNode-Config-Manual_apache.md | 0 .../DataNode-Config-Manual_timecho.md | 0 .../Reference/Keywords.md | 0 .../Reference/Modify-Config-Manual.md | 0 .../Reference/Status-Codes.md | 0 .../Reference/Syntax-Rule.md | 0 .../Reference/UDF-Libraries_apache.md | 0 .../SQL-Manual/Function-and-Expression.md | 0 .../SQL-Manual/Operator-and-Expression.md | 0 .../SQL-Manual/SQL-Manual.md | 0 .../SQL-Manual}/UDF-Libraries.md | 0 .../SQL-Manual}/UDF-Libraries_apache.md | 0 .../SQL-Manual/UDF-Libraries_timecho.md | 0 .../Cluster-data-partitioning.md | 0 .../Encoding-and-Compression.md | 0 .../Technical-Insider/Publication.md | 0 .../Tools-System/Benchmark.md | 0 .../{V1.3.3 => V1.3.x}/Tools-System/CLI.md | 0 .../Tools-System/Data-Export-Tool.md | 0 .../Tools-System/Data-Import-Export-Tool.md | 0 .../Tools-System/Data-Import-Tool.md | 0 .../Tools-System/Maintenance-Tool_apache.md | 0 .../Tools-System/Maintenance-Tool_timecho.md | 0 .../Tools-System/Monitor-Tool.md | 0 .../Tools-System/Monitor-Tool_apache.md | 0 .../Tools-System/Monitor-Tool_timecho.md | 0 .../Tools-System/TsFile-Import-Export-Tool.md | 0 .../Tools-System/Workbench_timecho.md | 0 .../User-Manual/AINode_apache.md | 0 .../User-Manual/AINode_timecho.md | 0 .../User-Manual/Audit-Log_timecho.md | 0 .../User-Manual/Authority-Management.md | 0 .../User-Manual/Data-Recovery.md | 0 .../User-Manual/Data-Sync-old_apache.md} | 0 .../User-Manual/Data-Sync-old_timecho.md} | 0 .../User-Manual/Data-Sync_apache.md | 0 .../User-Manual/Data-Sync_timecho.md | 0 .../User-Manual/Data-subscription.md | 0 .../User-Manual/Database-Programming.md | 0 .../User-Manual/IoTDB-View_timecho.md | 0 .../User-Manual/Load-Balance.md | 0 .../User-Manual/Query-Performance-Analysis.md | 0 .../User-Manual/Streaming_apache.md | 0 .../User-Manual/Streaming_timecho.md | 0 .../User-Manual/Tiered-Storage_timecho.md | 0 .../User-Manual/Trigger.md | 0 .../User-Manual}/UDF-development.md | 0 .../User-defined-function_apache.md | 0 .../User-defined-function_timecho.md | 0 .../User-Manual/White-List_timecho.md | 0 .../{V1.3.3 => V1.3.x}/UserGuideReadme.md | 0 358 files changed, 5348 insertions(+), 46165 deletions(-) delete mode 100644 src/.vuepress/sidebar/V1.3.0-2/en.ts delete mode 100644 src/.vuepress/sidebar/V1.3.0-2/zh.ts rename src/.vuepress/sidebar/{V1.3.3 => V1.3.x}/en.ts (88%) rename src/.vuepress/sidebar/{V1.3.3 => V1.3.x}/zh.ts (88%) delete mode 100644 src/.vuepress/sidebar_timecho/V1.3.0-2/en.ts delete mode 100644 src/.vuepress/sidebar_timecho/V1.3.0-2/zh.ts rename src/.vuepress/sidebar_timecho/{V1.3.3 => V1.3.x}/en.ts (89%) rename src/.vuepress/sidebar_timecho/{V1.3.3 => V1.3.x}/zh.ts (89%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-CSharp-Native-API.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Cpp-Native-API.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Data-Subscription.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Go-Native-API.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-JDBC.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Java-Native-API.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Kafka.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-MQTT.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-NodeJS-Native-API.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-ODBC.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-OPC-UA_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Python-Native-API.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Rust-Native-API.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/RestServiceV1.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/API/RestServiceV2.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Cluster-Concept.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Cluster-Concept_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Cluster-Concept_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Data-Type.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Data-Model-and-Terminology.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Navigating_Time_Series_Data.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Operate-Metadata.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Operate-Metadata_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Operate-Metadata_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Query-Data.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Write-Delete-Data.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/AINode_Deployment_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/AINode_Deployment_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Cluster-Deployment_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Cluster-Deployment_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Database-Resources.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Docker-Deployment_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Docker-Deployment_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Environment-Requirements.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/IoTDB-Package.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/IoTDB-Package_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/IoTDB-Package_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Monitoring-panel-deployment.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/workbench-deployment_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/DBeaver.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/DataEase.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Flink-IoTDB.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Flink-TsFile.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Grafana-Connector.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Grafana-Plugin.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Hive-TsFile.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Kubernetes_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Kubernetes_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/NiFi-IoTDB.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Spark-IoTDB.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Spark-TsFile.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Telegraf.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Thingsboard.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Zeppelin-IoTDB.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/FAQ/Frequently-asked-questions.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/IoTDB-Introduction/IoTDB-Introduction_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/IoTDB-Introduction/IoTDB-Introduction_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/IoTDB-Introduction/Scenario.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/QuickStart/QuickStart.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/QuickStart/QuickStart_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/QuickStart/QuickStart_timecho.md (100%) create mode 100644 src/UserGuide/V1.3.x/Reference/Common-Config-Manual-old.md rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/Common-Config-Manual.md (100%) create mode 100644 src/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual-old.md rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/ConfigNode-Config-Manual.md (100%) rename src/UserGuide/{V1.3.3/Reference/DataNode-Config-Manual.md => V1.3.x/Reference/DataNode-Config-Manual-old.md} (100%) create mode 100644 src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_apache.md create mode 100644 src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_timecho.md rename src/{zh/UserGuide/V1.3.0-2 => UserGuide/V1.3.x}/Reference/DataNode-Config-Manual.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/DataNode-Config-Manual_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/DataNode-Config-Manual_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/Keywords.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/Modify-Config-Manual.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/Status-Codes.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Reference/Syntax-Rule.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/Function-and-Expression.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/Operator-and-Expression.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/SQL-Manual.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/UDF-Libraries.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/UDF-Libraries_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/UDF-Libraries_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Technical-Insider/Cluster-data-partitioning.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Technical-Insider/Encoding-and-Compression.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Technical-Insider/Publication.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Benchmark.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/CLI.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Data-Export-Tool.md (100%) create mode 100644 src/UserGuide/V1.3.x/Tools-System/Data-Import-Export-Tool.md rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Data-Import-Tool.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Maintenance-Tool_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Maintenance-Tool_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Monitor-Tool.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Monitor-Tool_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Monitor-Tool_timecho.md (100%) create mode 100644 src/UserGuide/V1.3.x/Tools-System/TsFile-Import-Export-Tool.md rename src/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Workbench_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/AINode_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/AINode_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Audit-Log_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Authority-Management.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-Recovery.md (100%) create mode 100644 src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_apache.md create mode 100644 src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_timecho.md rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-Sync_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-Sync_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-subscription.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Database-Programming.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/IoTDB-View_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Load-Balance.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Query-Performance-Analysis.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Streaming_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Streaming_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Tiered-Storage_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Trigger.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/UDF-development.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/User-defined-function_apache.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/User-defined-function_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/White-List_timecho.md (100%) rename src/UserGuide/{V1.3.3 => V1.3.x}/UserGuideReadme.md (100%) delete mode 100644 src/zh/UserGuide/V1.3.0-2/API/Programming-Cpp-Native-API.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/API/Programming-JDBC.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/API/Programming-Java-Native-API.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/API/Programming-MQTT.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/API/Programming-Python-Native-API.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/API/RestServiceV1.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/API/RestServiceV2.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Basic-Concept/Cluster-Concept.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Model-and-Terminology.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Type.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Basic-Concept/Encoding-and-Compression.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/AINode_Deployment_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Database-Resources.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/IoTDB-Package_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Monitoring-panel-deployment.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Slow-Query-Management.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/workbench-deployment_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/DataEase.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Grafana-Plugin.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Spark-IoTDB.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Telegraf-IoTDB.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Thingsboard.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/FAQ/Frequently-asked-questions.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Architecture.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Features.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Performance.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Publication.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Reference/Function-and-Expression.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Reference/Modify-Config-Manual.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Reference/UDF-Libraries_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/SQL-Manual/SQL-Manual.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Tools-System/Benchmark.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Tools-System/CLI.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/Tools-System/Workbench_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Database-Programming.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/IoTDB-View_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Maintennance.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Operator-and-Expression.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Query-Data.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Security-Management_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_apache.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Syntax-Rule.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Tiered-Storage_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/User-defined-function.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/User-Manual/Write-Delete-Data.md delete mode 100644 src/zh/UserGuide/V1.3.0-2/UserGuideReadme.md delete mode 100644 src/zh/UserGuide/V1.3.3/API/Programming-CSharp-Native-API.md delete mode 100644 src/zh/UserGuide/V1.3.3/API/Programming-Go-Native-API.md delete mode 100644 src/zh/UserGuide/V1.3.3/API/Programming-Kafka.md delete mode 100644 src/zh/UserGuide/V1.3.3/API/Programming-NodeJS-Native-API.md delete mode 100644 src/zh/UserGuide/V1.3.3/API/Programming-ODBC.md delete mode 100644 src/zh/UserGuide/V1.3.3/API/Programming-Rust-Native-API.md delete mode 100644 src/zh/UserGuide/V1.3.3/Basic-Concept/Navigating_Time_Series_Data.md delete mode 100644 src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata.md delete mode 100644 src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_apache.md delete mode 100644 src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Environment-Requirements.md delete mode 100644 src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/DBeaver.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-IoTDB.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-TsFile.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Connector.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Hive-TsFile.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/NiFi-IoTDB.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Spark-TsFile.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_apache.md delete mode 100644 src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Scenario.md delete mode 100644 src/zh/UserGuide/V1.3.3/Reference/Keywords.md delete mode 100644 src/zh/UserGuide/V1.3.3/Reference/Status-Codes.md delete mode 100644 src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries.md delete mode 100644 src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_apache.md delete mode 100644 src/zh/UserGuide/V1.3.3/Technical-Insider/Cluster-data-partitioning.md delete mode 100644 src/zh/UserGuide/V1.3.3/User-Manual/AINode_timecho.md delete mode 100644 src/zh/UserGuide/V1.3.3/User-Manual/Authority-Management.md delete mode 100644 src/zh/UserGuide/V1.3.3/User-Manual/Trigger.md delete mode 100644 src/zh/UserGuide/V1.3.3/User-Manual/UDF-development.md rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/API/Programming-CSharp-Native-API.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Cpp-Native-API.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Data-Subscription.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/API/Programming-Go-Native-API.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-JDBC.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Java-Native-API.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/API/Programming-Kafka.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-MQTT.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/API/Programming-NodeJS-Native-API.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/API/Programming-ODBC.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-OPC-UA_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/Programming-Python-Native-API.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/API/Programming-Rust-Native-API.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/RestServiceV1.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/API/RestServiceV2.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Cluster-Concept.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Cluster-Concept_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Cluster-Concept_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Background-knowledge/Data-Type.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Data-Model-and-Terminology.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Basic-Concept/Navigating_Time_Series_Data.md (100%) rename src/zh/UserGuide/{V1.3.0-2/User-Manual => V1.3.x/Basic-Concept}/Operate-Metadata.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Operate-Metadata_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Operate-Metadata_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Query-Data.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Basic-Concept/Write-Delete-Data.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/AINode_Deployment_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/AINode_Deployment_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Cluster-Deployment_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Cluster-Deployment_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Database-Resources.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Deployment-and-Maintenance/Docker-Deployment_apache.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Deployment-and-Maintenance/Docker-Deployment_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Deployment-and-Maintenance/Environment-Requirements.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/IoTDB-Package_apache.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Deployment-and-Maintenance/IoTDB-Package_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Monitoring-panel-deployment.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Slow-Query-Management.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Deployment-and-Maintenance/workbench-deployment_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/DBeaver.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/DataEase.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/Flink-IoTDB.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/Flink-TsFile.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/Grafana-Connector.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Grafana-Plugin.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/Hive-TsFile.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Kubernetes_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Kubernetes_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/NiFi-IoTDB.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Spark-IoTDB.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/Spark-TsFile.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Telegraf.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Ecosystem-Integration/Thingsboard.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/Zeppelin-IoTDB_apache.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/FAQ/Frequently-asked-questions.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/IoTDB-Introduction/IoTDB-Introduction_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/IoTDB-Introduction/IoTDB-Introduction_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/IoTDB-Introduction/Release-history_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/IoTDB-Introduction/Release-history_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/IoTDB-Introduction/Scenario.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/QuickStart/QuickStart.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/QuickStart/QuickStart_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/QuickStart/QuickStart_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2/Reference/Common-Config-Manual.md => V1.3.x/Reference/Common-Config-Manual-old.md} (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Reference/Common-Config-Manual.md (100%) rename src/zh/UserGuide/{V1.3.0-2/Reference/ConfigNode-Config-Manual.md => V1.3.x/Reference/ConfigNode-Config-Manual-old.md} (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Reference/ConfigNode-Config-Manual.md (100%) rename src/zh/UserGuide/{V1.3.3/Reference/DataNode-Config-Manual.md => V1.3.x/Reference/DataNode-Config-Manual-old.md} (100%) rename src/zh/UserGuide/{V1.3.0-2/Reference/DataNode-Config-Manual_apache.md => V1.3.x/Reference/DataNode-Config-Manual-old_apache.md} (100%) rename src/zh/UserGuide/{V1.3.0-2/Reference/DataNode-Config-Manual_timecho.md => V1.3.x/Reference/DataNode-Config-Manual-old_timecho.md} (100%) rename src/zh/UserGuide/{V1.3.3/QuickStart/QuickStart.md => V1.3.x/Reference/DataNode-Config-Manual.md} (94%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Reference/DataNode-Config-Manual_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Reference/DataNode-Config-Manual_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Reference/Keywords.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Reference/Modify-Config-Manual.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Reference/Status-Codes.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Reference/Syntax-Rule.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Reference/UDF-Libraries_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/Function-and-Expression.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/Operator-and-Expression.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/SQL-Manual.md (100%) rename src/zh/UserGuide/{V1.3.0-2/Reference => V1.3.x/SQL-Manual}/UDF-Libraries.md (100%) rename src/zh/UserGuide/{V1.3.3/Reference => V1.3.x/SQL-Manual}/UDF-Libraries_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/SQL-Manual/UDF-Libraries_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2/Basic-Concept => V1.3.x/Technical-Insider}/Cluster-data-partitioning.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Technical-Insider/Encoding-and-Compression.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Technical-Insider/Publication.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Benchmark.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/CLI.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Data-Export-Tool.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Tools-System/Data-Import-Export-Tool.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Data-Import-Tool.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Maintenance-Tool_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Maintenance-Tool_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Monitor-Tool.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Monitor-Tool_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Monitor-Tool_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/Tools-System/TsFile-Import-Export-Tool.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/Tools-System/Workbench_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/AINode_apache.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/User-Manual/AINode_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Audit-Log_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/User-Manual/Authority-Management.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-Recovery.md (100%) rename src/zh/UserGuide/{V1.3.0-2/User-Manual/Data-Sync_apache.md => V1.3.x/User-Manual/Data-Sync-old_apache.md} (100%) rename src/zh/UserGuide/{V1.3.0-2/User-Manual/Data-Sync_timecho.md => V1.3.x/User-Manual/Data-Sync-old_timecho.md} (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-Sync_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-Sync_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Data-subscription.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Database-Programming.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/IoTDB-View_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Load-Balance.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Query-Performance-Analysis.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Streaming_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Streaming_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/Tiered-Storage_timecho.md (100%) rename src/zh/UserGuide/{V1.3.0-2 => V1.3.x}/User-Manual/Trigger.md (100%) rename src/zh/UserGuide/{V1.3.0-2/Reference => V1.3.x/User-Manual}/UDF-development.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/User-defined-function_apache.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/User-defined-function_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/User-Manual/White-List_timecho.md (100%) rename src/zh/UserGuide/{V1.3.3 => V1.3.x}/UserGuideReadme.md (100%) diff --git a/src/.vuepress/navbar/en.ts b/src/.vuepress/navbar/en.ts index 803a6c697..55cbb8d50 100644 --- a/src/.vuepress/navbar/en.ts +++ b/src/.vuepress/navbar/en.ts @@ -24,12 +24,8 @@ export const enNavbar = navbar([ children: [ { text: 'v2.0.x', link: '/UserGuide/latest/QuickStart/QuickStart_apache' }, { - text: 'v1.3.3', - link: '/UserGuide/V1.3.3/QuickStart/QuickStart_apache', - }, - { - text: 'v1.3.0/1/2', - link: '/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache', + text: 'v1.3.x', + link: '/UserGuide/V1.3.x/QuickStart/QuickStart_apache', }, { text: 'v1.2.x', link: '/UserGuide/V1.2.x/QuickStart/QuickStart' }, { text: 'v0.13.x', link: '/UserGuide/V0.13.x/QuickStart/QuickStart' }, diff --git a/src/.vuepress/navbar/zh.ts b/src/.vuepress/navbar/zh.ts index 9761b2423..d4a9801df 100644 --- a/src/.vuepress/navbar/zh.ts +++ b/src/.vuepress/navbar/zh.ts @@ -28,12 +28,8 @@ export const zhNavbar = navbar([ link: '/zh/UserGuide/latest/QuickStart/QuickStart_apache', }, { - text: 'v1.3.3', - link: '/zh/UserGuide/V1.3.3/QuickStart/QuickStart_apache', - }, - { - text: 'v1.3.0/1/2', - link: '/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache', + text: 'v1.3.x', + link: '/zh/UserGuide/V1.3.x/QuickStart/QuickStart_apache', }, { text: 'v1.2.x', link: '/zh/UserGuide/V1.2.x/QuickStart/QuickStart' }, { text: 'v0.13.x', link: '/zh/UserGuide/V0.13.x/QuickStart/QuickStart' }, diff --git a/src/.vuepress/sidebar/V1.3.0-2/en.ts b/src/.vuepress/sidebar/V1.3.0-2/en.ts deleted file mode 100644 index 7019eeded..000000000 --- a/src/.vuepress/sidebar/V1.3.0-2/en.ts +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const enSidebar = { - '/UserGuide/V1.3.0-2/': [ - { - text: 'IoTDB User Guide (V1.3.0/1/2)', - children: [], - }, - { - text: 'About IoTDB', - collapsible: true, - prefix: 'IoTDB-Introduction/', - // children: 'structure', - children: [ - { text: 'What is IoTDB', link: 'IoTDB-Introduction_apache' }, - { text: 'Features', link: 'Features' }, - { text: 'System Architecture', link: 'Architecture' }, - { text: 'Performance', link: 'Performance' }, - { text: 'Scenario', link: 'Scenario' }, - { text: 'Academic Achievement', link: 'Publication' }, - ], - }, - { - text: 'Quick Start', - link: 'QuickStart/QuickStart_apache', - }, - { - text: 'Basic Concept', - collapsible: true, - prefix: 'Basic-Concept/', - // children: 'structure', - children: [ - { - text: 'Navigating Time Series Data', - link: 'Navigating_Time_Series_Data', - }, - { text: 'Data Model', link: 'Data-Model-and-Terminology' }, - { text: 'Data Type', link: 'Data-Type' }, - { text: 'Encoding and Compression', link: 'Encoding-and-Compression' }, - { text: 'Cluster-related Concepts', link: 'Cluster-Concept' }, - { - text: 'Data Partitioning & Load Balancing', - link: 'Cluster-data-partitioning', - }, - ], - }, - { - text: 'Deployment & Maintenance', - collapsible: true, - prefix: 'Deployment-and-Maintenance/', - // children: 'structure', - children: [ - { text: 'Obtain IoTDB', link: 'IoTDB-Package_apache' }, - { text: 'Database Resources', link: 'Database-Resources' }, - { text: 'Environment Requirements', link: 'Environment-Requirements' }, - { - text: 'Stand-Alone Deployment', - link: 'Stand-Alone-Deployment_apache', - }, - { text: 'Cluster Deployment', link: 'Cluster-Deployment_apache' }, - { text: 'Docker Deployment', link: 'Docker-Deployment_apache' }, - ], - }, - - { - text: 'User Manual', - collapsible: true, - prefix: 'User-Manual/', - // children: 'structure', - children: [ - { text: 'Syntax Rule', link: 'Syntax-Rule' }, - { text: 'Operate Metadata', link: 'Operate-Metadata_apache' }, - { text: 'Write & Delete Data', link: 'Write-Delete-Data' }, - { text: 'Query Data', link: 'Query-Data' }, - { text: 'Operator and Expression', link: 'Operator-and-Expression' }, - { text: 'Stream Processing', link: 'Streaming_apache' }, - { text: 'Data Sync', link: 'Data-Sync_apache' }, - { text: 'Database Programming', link: 'Database-Programming' }, - { text: 'UDF', link: 'User-defined-function' }, - { text: 'Database Administration', link: 'Authority-Management' }, - { text: 'Maintennance', link: 'Maintennance' }, - ], - }, - { - text: 'Tools System', - collapsible: true, - prefix: 'Tools-System/', - // children: 'structure', - children: [ - { text: 'Command Line Interface (CLI)', link: 'CLI' }, - { text: 'Monitor Tool', link: 'Monitor-Tool_apache' }, - { text: 'Benchmark Tool', link: 'Benchmark' }, - { text: 'Maintenance Tool', link: 'Maintenance-Tool_apache' }, - { text: 'Data Import Export Script', link: 'Data-Import-Export-Tool' }, - { - text: 'TsFile Import Export Script', - link: 'TsFile-Import-Export-Tool', - }, - ], - }, - { - text: 'API', - collapsible: true, - prefix: 'API/', - // children: 'structure', - children: [ - { text: 'Java Native API', link: 'Programming-Java-Native-API' }, - { text: 'Python Native API', link: 'Programming-Python-Native-API' }, - { text: 'C++ Native API', link: 'Programming-Cpp-Native-API' }, - { text: 'Go Native API', link: 'Programming-Go-Native-API' }, - { text: 'C# Native API', link: 'Programming-CSharp-Native-API' }, - { text: 'Node.js Native API', link: 'Programming-NodeJS-Native-API' }, - { text: 'Rust Native API', link: 'Programming-Rust-Native-API' }, - { text: 'JDBC (Not Recommend)', link: 'Programming-JDBC' }, - { text: 'MQTT Protocol', link: 'Programming-MQTT' }, - { text: 'Kafka', link: 'Programming-Kafka' }, - { text: 'REST API V1 (Not Recommend)', link: 'RestServiceV1' }, - { text: 'REST API V2', link: 'RestServiceV2' }, - ], - }, - { - text: 'Ecosystem Integration', - collapsible: true, - prefix: 'Ecosystem-Integration/', - // children: 'structure', - children: [ - { text: 'Apache Flink(IoTDB)', link: 'Flink-IoTDB' }, - { text: 'Apache Flink(TsFile)', link: 'Flink-TsFile' }, - { text: 'Apache Hive(TsFile)', link: 'Hive-TsFile' }, - { text: 'Apache NiFi', link: 'NiFi-IoTDB' }, - { text: 'Apache Spark(TsFile)', link: 'Spark-TsFile' }, - { text: 'Apache Spark(IoTDB)', link: 'Spark-IoTDB' }, - { text: 'Apache Zeppelin', link: 'Zeppelin-IoTDB_apache' }, - { text: 'DBeaver', link: 'DBeaver' }, - { text: 'Grafana(IoTDB)', link: 'Grafana-Connector' }, - { text: 'Grafana Plugin', link: 'Grafana-Plugin' }, - { text: 'ThingsBoard', link: 'Thingsboard' }, - ], - }, - { - text: 'SQL Manual', - collapsible: true, - prefix: 'SQL-Manual/', - // children: 'structure', - children: [{ text: 'SQL Manual', link: 'SQL-Manual' }], - }, - { - text: 'FAQ', - collapsible: true, - prefix: 'FAQ/', - // children: 'structure', - children: [ - { - text: 'Frequently Asked Questions', - link: 'Frequently-asked-questions', - }, - ], - }, - { - text: 'Reference', - collapsible: true, - prefix: 'Reference/', - // children: 'structure', - children: [ - { text: 'UDF Libraries', link: 'UDF-Libraries_apache' }, - { text: 'UDF development', link: 'UDF-development' }, - { text: 'Function and Expression', link: 'Function-and-Expression' }, - { text: 'Common Config Manual', link: 'Common-Config-Manual' }, - { text: 'ConfigNode Config Manual', link: 'ConfigNode-Config-Manual' }, - { text: 'DataNode Config Manual', link: 'DataNode-Config-Manual_apache' }, - { text: 'Status Codes', link: 'Status-Codes' }, - { text: 'Keywords', link: 'Keywords' }, - ], - }, - ], -}; diff --git a/src/.vuepress/sidebar/V1.3.0-2/zh.ts b/src/.vuepress/sidebar/V1.3.0-2/zh.ts deleted file mode 100644 index fc2fa90a4..000000000 --- a/src/.vuepress/sidebar/V1.3.0-2/zh.ts +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const zhSidebar = { - '/zh/UserGuide/V1.3.0-2/': [ - { - text: 'IoTDB用户手册 (V1.3.0/1/2)', - children: [], - }, - { - text: '关于IoTDB', - collapsible: true, - prefix: 'IoTDB-Introduction/', - // children: 'structure', 使用该方式自动获取文件夹下的文件 - children: [ - { text: '产品简介', link: 'IoTDB-Introduction_apache' }, - { text: '主要功能特点', link: 'Features' }, - { text: '系统架构', link: 'Architecture' }, - { text: '性能特点', link: 'Performance' }, - { text: '应用场景', link: 'Scenario' }, - { text: '学术成果', link: 'Publication' }, - ], - }, - { - text: '快速上手', - link: 'QuickStart/QuickStart_apache', - }, - { - text: '基础概念', - collapsible: true, - prefix: 'Basic-Concept/', - // children: 'structure', - children: [ - { text: '走进时序数据', link: 'Navigating_Time_Series_Data' }, - { text: '数据模型', link: 'Data-Model-and-Terminology' }, - { text: '数据类型', link: 'Data-Type' }, - { text: '编码和压缩', link: 'Encoding-and-Compression' }, - { text: '集群相关概念', link: 'Cluster-Concept' }, - { text: '数据分区与负载均衡', link: 'Cluster-data-partitioning' }, - ], - }, - { - text: '部署与运维', - collapsible: true, - prefix: 'Deployment-and-Maintenance/', - // children: 'structure', - children: [ - { text: '安装包获取', link: 'IoTDB-Package_apache' }, - { text: '资源规划', link: 'Database-Resources' }, - { text: '环境配置', link: 'Environment-Requirements' }, - { text: '单机版部署', link: 'Stand-Alone-Deployment_apache' }, - { text: '集群版部署', link: 'Cluster-Deployment_apache' }, - { text: 'Docker部署', link: 'Docker-Deployment_apache' }, - ], - }, - - { - text: '使用手册', - collapsible: true, - prefix: 'User-Manual/', - // children: 'structure', - children: [ - { text: '语法约定', link: 'Syntax-Rule' }, - { text: '元数据管理', link: 'Operate-Metadata_apache' }, - { text: '数据写入与删除', link: 'Write-Delete-Data' }, - { text: '数据查询', link: 'Query-Data' }, - { text: '运算符、函数和表达式', link: 'Operator-and-Expression' }, - { text: '流处理框架', link: 'Streaming_apache' }, - { text: '数据同步', link: 'Data-Sync_apache' }, - { text: '数据库编程', link: 'Database-Programming' }, - { text: '用户自定义函数', link: 'User-defined-function' }, - { text: '权限管理', link: 'Authority-Management' }, - { text: '运维语句', link: 'Maintennance' }, - ], - }, - { - text: '工具体系', - collapsible: true, - prefix: 'Tools-System/', - // children: 'structure', - children: [ - { text: 'SQL命令行终端 (CLI)', link: 'CLI' }, - { text: '监控工具', link: 'Monitor-Tool_apache' }, - { text: '测试工具', link: 'Benchmark' }, - { text: '运维工具', link: 'Maintenance-Tool_apache' }, - { text: '数据导入导出脚本', link: 'Data-Import-Export-Tool' }, - { text: 'TsFile导入导出脚本', link: 'TsFile-Import-Export-Tool' }, - ], - }, - { - text: '应用编程接口', - collapsible: true, - prefix: 'API/', - // children: 'structure', - children: [ - { text: 'Java原生接口', link: 'Programming-Java-Native-API' }, - { text: 'Python原生接口', link: 'Programming-Python-Native-API' }, - { text: 'C++原生接口', link: 'Programming-Cpp-Native-API' }, - { text: 'Go原生接口', link: 'Programming-Go-Native-API' }, - { text: 'C#原生接口', link: 'Programming-CSharp-Native-API' }, - { text: 'Node.js原生接口', link: 'Programming-NodeJS-Native-API' }, - { text: 'Rust原生接口', link: 'Programming-Rust-Native-API' }, - { text: 'JDBC (不推荐)', link: 'Programming-JDBC' }, - { text: 'MQTT协议', link: 'Programming-MQTT' }, - { text: 'Kafka', link: 'Programming-Kafka' }, - { text: 'REST API V1 (不推荐)', link: 'RestServiceV1' }, - { text: 'REST API V2', link: 'RestServiceV2' }, - ], - }, - { - text: '系统集成', - collapsible: true, - prefix: 'Ecosystem-Integration/', - // children: 'structure', - children: [ - { text: 'Apache Flink(IoTDB)', link: 'Flink-IoTDB' }, - { text: 'Apache Flink(TsFile)', link: 'Flink-TsFile' }, - { text: 'Apache Hive(TsFile)', link: 'Hive-TsFile' }, - { text: 'Apache NiFi', link: 'NiFi-IoTDB' }, - { text: 'Apache Spark(TsFile)', link: 'Spark-TsFile' }, - { text: 'Apache Spark(IoTDB)', link: 'Spark-IoTDB' }, - { text: 'Apache Zeppelin', link: 'Zeppelin-IoTDB_apache' }, - { text: 'DBeaver', link: 'DBeaver' }, - { text: 'Grafana(IoTDB)', link: 'Grafana-Connector' }, - { text: 'Grafana插件', link: 'Grafana-Plugin' }, - { text: 'ThingsBoard', link: 'Thingsboard' }, - ], - }, - { - text: 'SQL手册', - collapsible: true, - prefix: 'SQL-Manual/', - // children: 'structure', - children: [{ text: 'SQL手册', link: 'SQL-Manual' }], - }, - { - text: 'FAQ', - collapsible: true, - prefix: 'FAQ/', - // children: 'structure', - children: [{ text: '常见问题', link: 'Frequently-asked-questions' }], - }, - { - text: '附录', - collapsible: true, - prefix: 'Reference/', - // children: 'structure', - children: [ - { text: 'UDF函数库', link: 'UDF-Libraries_apache' }, - { text: 'UDF开发', link: 'UDF-development' }, - { text: '内置函数与表达式', link: 'Function-and-Expression' }, - { text: '配置参数', link: 'Common-Config-Manual' }, - { text: 'ConfigNode配置参数', link: 'ConfigNode-Config-Manual' }, - { text: 'DataNode配置参数', link: 'DataNode-Config-Manual_apache' }, - { text: '状态码', link: 'Status-Codes' }, - { text: '关键字', link: 'Keywords' }, - ], - }, - ], -}; diff --git a/src/.vuepress/sidebar/V1.3.3/en.ts b/src/.vuepress/sidebar/V1.3.x/en.ts similarity index 88% rename from src/.vuepress/sidebar/V1.3.3/en.ts rename to src/.vuepress/sidebar/V1.3.x/en.ts index 867de90ab..e60473940 100644 --- a/src/.vuepress/sidebar/V1.3.3/en.ts +++ b/src/.vuepress/sidebar/V1.3.x/en.ts @@ -17,9 +17,9 @@ */ export const enSidebar = { - '/UserGuide/V1.3.3/': [ + '/UserGuide/V1.3.x/': [ { - text: 'IoTDB User Guide (V1.3.3)', + text: 'IoTDB User Guide (V1.3.x)', children: [], }, { @@ -97,8 +97,15 @@ export const enSidebar = { prefix: 'User-Manual/', // children: 'structure', children: [ - { text: 'Data Sync', link: 'Data-Sync_apache' }, - { text: 'Data Subscription', link: 'Data-subscription' }, + { + text: 'Data Sync', + collapsible: true, + children: [ + { text: 'Data Sync(V1.3.0/1/2)', link: 'Data-Sync-old_apache' }, + { text: 'Data Sync(V1.3.3)', link: 'Data-Sync_apache' }, + ], + }, + { text: 'Data Subscription(V1.3.4)', link: 'Data-subscription' }, { text: 'AI Capability', link: 'AINode_apache' }, { text: 'Security Management', @@ -139,8 +146,10 @@ export const enSidebar = { { text: 'Monitor Tool', link: 'Monitor-Tool_apache' }, { text: 'Benchmark Tool', link: 'Benchmark' }, { text: 'Cluster Management Tool', link: 'Maintenance-Tool_apache' }, - { text: 'Data Import', link: 'Data-Import-Tool' }, - { text: 'Data Export', link: 'Data-Export-Tool' }, + { text: 'Data Import Export(V1.3.0/1/2)', link: 'Data-Import-Export-Tool' }, + { text: 'TsFile Import Export(V1.3.0/1/2)', link: 'TsFile-Import-Export-Tool' }, + { text: 'Data Import(V1.3.3)', link: 'Data-Import-Tool' }, + { text: 'Data Export(V1.3.3)', link: 'Data-Export-Tool' }, ], }, { @@ -240,7 +249,16 @@ export const enSidebar = { // children: 'structure', children: [ { - text: 'Config Manual', + text: 'Config Manual(V1.3.0/1/2)', + collapsible: true, + children: [ + { text: 'Common Config Manual', link: 'Common-Config-Manual-old' }, + { text: 'ConfigNode Config Manual', link: 'ConfigNode-Config-Manual-old' }, + { text: 'DataNode Config Manual', link: 'DataNode-Config-Manual-old_apache' }, + ], + }, + { + text: 'Config Manual(V1.3.3)', collapsible: true, children: [ { text: 'Common Config Manual', link: 'Common-Config-Manual' }, diff --git a/src/.vuepress/sidebar/V1.3.3/zh.ts b/src/.vuepress/sidebar/V1.3.x/zh.ts similarity index 88% rename from src/.vuepress/sidebar/V1.3.3/zh.ts rename to src/.vuepress/sidebar/V1.3.x/zh.ts index dd6974d83..11fd28f48 100644 --- a/src/.vuepress/sidebar/V1.3.3/zh.ts +++ b/src/.vuepress/sidebar/V1.3.x/zh.ts @@ -17,9 +17,9 @@ */ export const zhSidebar = { - '/zh/UserGuide/V1.3.3/': [ + '/zh/UserGuide/V1.3.x/': [ { - text: 'IoTDB用户手册 (V1.3.3)', + text: 'IoTDB用户手册 (V1.3.x)', children: [], }, { @@ -86,8 +86,15 @@ export const zhSidebar = { prefix: 'User-Manual/', // children: 'structure', children: [ - { text: '数据同步', link: 'Data-Sync_apache' }, - { text: '数据订阅', link: 'Data-subscription' }, + { + text: '数据同步', + collapsible: true, + children: [ + { text: '数据同步(V1.3.0/1/2)', link: 'Data-Sync-old_apache' }, + { text: '数据同步(V1.3.3)', link: 'Data-Sync_apache' }, + ], + }, + { text: '数据订阅(V1.3.4)', link: 'Data-subscription' }, { text: 'AI能力', link: 'AINode_apache' }, { text: '安全管理', @@ -126,8 +133,10 @@ export const zhSidebar = { { text: '监控工具', link: 'Monitor-Tool_apache' }, { text: '测试工具', link: 'Benchmark' }, { text: '集群管理工具', link: 'Maintenance-Tool_apache' }, - { text: '数据导入', link: 'Data-Import-Tool' }, - { text: '数据导出', link: 'Data-Export-Tool' }, + { text: '数据导入导出(V1.3.0/1/2)', link: 'Data-Import-Export-Tool' }, + { text: 'TsFile导入导出(V1.3.0/1/2)', link: 'TsFile-Import-Export-Tool' }, + { text: '数据导入(V1.3.3)', link: 'Data-Import-Tool' }, + { text: '数据导出(V1.3.3)', link: 'Data-Export-Tool' }, ], }, { @@ -218,7 +227,16 @@ export const zhSidebar = { // children: 'structure', children: [ { - text: '配置参数', + text: '配置参数(V1.3.0/1/2)', + collapsible: true, + children: [ + { text: '配置参数', link: 'Common-Config-Manual-old' }, + { text: 'ConfigNode配置参数', link: 'ConfigNode-Config-Manual-old' }, + { text: 'DataNode配置参数', link: 'DataNode-Config-Manual-old_apache' }, + ], + }, + { + text: '配置参数(V1.3.3)', collapsible: true, children: [ { text: '配置参数', link: 'Common-Config-Manual' }, diff --git a/src/.vuepress/sidebar/en.ts b/src/.vuepress/sidebar/en.ts index ac3521da1..54754222b 100644 --- a/src/.vuepress/sidebar/en.ts +++ b/src/.vuepress/sidebar/en.ts @@ -19,7 +19,7 @@ import { sidebar } from 'vuepress-theme-hope'; import { enSidebar as V201xTableSidebar } from './V2.0.x/en-Table.js'; import { enSidebar as V201xTreeSidebar } from './V2.0.x/en-Tree.js'; -import { enSidebar as V103xSidebar } from './V1.3.3/en.js'; +import { enSidebar as V103xSidebar } from './V1.3.x/en.js'; import { enSidebar as V1030Sidebar } from './V1.3.0-2/en.js'; import { enSidebar as V102xSidebar } from './V1.2.x/en.js'; import { enSidebar as V013xSidebar } from './V0.13.x/en.js'; diff --git a/src/.vuepress/sidebar/zh.ts b/src/.vuepress/sidebar/zh.ts index 94c612a3f..dd061704e 100644 --- a/src/.vuepress/sidebar/zh.ts +++ b/src/.vuepress/sidebar/zh.ts @@ -19,7 +19,7 @@ import { sidebar } from 'vuepress-theme-hope'; import { zhSidebar as V201xTableSidebar } from './V2.0.x/zh-Table.js'; import { zhSidebar as V201xTreeSidebar } from './V2.0.x/zh-Tree.js'; -import { zhSidebar as V103xSidebar } from './V1.3.3/zh.js'; +import { zhSidebar as V103xSidebar } from './V1.3.x/zh.js'; import { zhSidebar as V1030Sidebar } from './V1.3.0-2/zh.js'; import { zhSidebar as V102xSidebar } from './V1.2.x/zh.js'; import { zhSidebar as V013xSidebar } from './V0.13.x/zh.js'; diff --git a/src/.vuepress/sidebar_timecho/V1.3.0-2/en.ts b/src/.vuepress/sidebar_timecho/V1.3.0-2/en.ts deleted file mode 100644 index c0bfe0878..000000000 --- a/src/.vuepress/sidebar_timecho/V1.3.0-2/en.ts +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const enSidebar = { - '/UserGuide/V1.3.0-2/': [ - { - text: 'IoTDB User Guide', - children: [], - }, - { - text: 'About IoTDB', - collapsible: true, - prefix: 'IoTDB-Introduction/', - // children: 'structure', - children: [ - { text: 'What is IoTDB', link: 'IoTDB-Introduction_timecho' }, - { text: 'Features', link: 'Features' }, - { text: 'System Architecture', link: 'Architecture' }, - { text: 'Performance', link: 'Performance' }, - { text: 'Scenario', link: 'Scenario' }, - { text: 'Academic Achievement', link: 'Publication' }, - ], - }, - { - text: 'Quick Start', - link: 'QuickStart/QuickStart_timecho', - }, - { - text: 'Basic Concept', - collapsible: true, - prefix: 'Basic-Concept/', - // children: 'structure', - children: [ - { - text: 'Navigating Time Series Data', - link: 'Navigating_Time_Series_Data', - }, - { text: 'Data Model', link: 'Data-Model-and-Terminology' }, - { text: 'Data Type', link: 'Data-Type' }, - { text: 'Encoding and Compression', link: 'Encoding-and-Compression' }, - { text: 'Cluster-related Concepts', link: 'Cluster-Concept' }, - { - text: 'Data Partitioning & Load Balancing', - link: 'Cluster-data-partitioning', - }, - ], - }, - { - text: 'Deployment & Maintenance', - collapsible: true, - prefix: 'Deployment-and-Maintenance/', - // children: 'structure', - children: [ - { text: 'Obtain TimechoDB', link: 'IoTDB-Package_timecho' }, - { text: 'Database Resources', link: 'Database-Resources' }, - { text: 'Environment Requirements', link: 'Environment-Requirements' }, - { - text: 'Stand-Alone Deployment', - link: 'Stand-Alone-Deployment_timecho', - }, - { text: 'Cluster Deployment', link: 'Cluster-Deployment_timecho' }, - { - text: 'Dual Active Deployment', - link: 'Dual-Active-Deployment_timecho', - }, - { text: 'Docker Deployment', link: 'Docker-Deployment_timecho' }, - { text: 'AINode Deployment', link: 'AINode_Deployment_timecho' }, - { - text: 'Monitoring Panel Deployment', - link: 'Monitoring-panel-deployment', - }, - { text: 'Workbench Deployment', link: 'workbench-deployment_timecho' }, - ], - }, - - { - text: 'User Manual', - collapsible: true, - prefix: 'User-Manual/', - // children: 'structure', - children: [ - { text: 'Syntax Rule', link: 'Syntax-Rule' }, - { text: 'Operate Metadata', link: 'Operate-Metadata_timecho' }, - { text: 'Write & Delete Data', link: 'Write-Delete-Data' }, - { text: 'Query Data', link: 'Query-Data' }, - { text: 'Operator and Expression', link: 'Operator-and-Expression' }, - { text: 'Stream Processing', link: 'Streaming_timecho' }, - { text: 'Data Sync', link: 'Data-Sync_timecho' }, - { text: 'Tiered Storage', link: 'Tiered-Storage_timecho' }, - { text: 'View', link: 'IoTDB-View_timecho' }, - { text: 'AI Capability', link: 'AINode_timecho' }, - { text: 'Database Programming', link: 'Database-Programming' }, - { text: 'UDF', link: 'User-defined-function' }, - { text: 'Security Management', link: 'Security-Management_timecho' }, - { text: 'Database Administration', link: 'Authority-Management' }, - { text: 'Maintennance', link: 'Maintennance' }, - ], - }, - { - text: 'Tools System', - collapsible: true, - prefix: 'Tools-System/', - // children: 'structure', - children: [ - { text: 'Command Line Interface (CLI)', link: 'CLI' }, - { text: 'Workbench', link: 'Workbench_timecho' }, - { text: 'Monitor Tool', link: 'Monitor-Tool_timecho' }, - { text: 'Benchmark Tool', link: 'Benchmark' }, - { text: 'Maintenance Tool', link: 'Maintenance-Tool_timecho' }, - { text: 'Data Import Export Script', link: 'Data-Import-Export-Tool' }, - { - text: 'TsFile Import Export Script', - link: 'TsFile-Import-Export-Tool', - }, - ], - }, - { - text: 'API', - collapsible: true, - prefix: 'API/', - // children: 'structure', - children: [ - { text: 'Java Native API', link: 'Programming-Java-Native-API' }, - { text: 'Python Native API', link: 'Programming-Python-Native-API' }, - { text: 'C++ Native API', link: 'Programming-Cpp-Native-API' }, - { text: 'Go Native API', link: 'Programming-Go-Native-API' }, - { text: 'C# Native API', link: 'Programming-CSharp-Native-API' }, - { text: 'Node.js Native API', link: 'Programming-NodeJS-Native-API' }, - { text: 'Rust Native API', link: 'Programming-Rust-Native-API' }, - { text: 'JDBC (Not Recommend)', link: 'Programming-JDBC' }, - { text: 'MQTT Protocol', link: 'Programming-MQTT' }, - { text: 'Kafka', link: 'Programming-Kafka' }, - { text: 'REST API V1 (Not Recommend)', link: 'RestServiceV1' }, - { text: 'REST API V2', link: 'RestServiceV2' }, - ], - }, - { - text: 'Ecosystem Integration', - collapsible: true, - prefix: 'Ecosystem-Integration/', - // children: 'structure', - children: [ - { text: 'Apache Flink(IoTDB)', link: 'Flink-IoTDB' }, - { text: 'Apache Flink(TsFile)', link: 'Flink-TsFile' }, - { text: 'Apache Hive(TsFile)', link: 'Hive-TsFile' }, - { text: 'Apache NiFi', link: 'NiFi-IoTDB' }, - { text: 'Apache Spark(TsFile)', link: 'Spark-TsFile' }, - { text: 'Apache Spark(IoTDB)', link: 'Spark-IoTDB' }, - { text: 'Apache Zeppelin', link: 'Zeppelin-IoTDB_timecho' }, - { text: 'DataEase', link: 'DataEase' }, - { text: 'DBeaver', link: 'DBeaver' }, - { text: 'Ignition', link: 'Ignition-IoTDB-plugin_timecho' }, - { text: 'Grafana(IoTDB)', link: 'Grafana-Connector' }, - { text: 'Grafana Plugin', link: 'Grafana-Plugin' }, - { text: 'ThingsBoard', link: 'Thingsboard' }, - ], - }, - { - text: 'SQL Manual', - collapsible: true, - prefix: 'SQL-Manual/', - // children: 'structure', - children: [{ text: 'SQL Manual', link: 'SQL-Manual' }], - }, - { - text: 'FAQ', - collapsible: true, - prefix: 'FAQ/', - // children: 'structure', - children: [ - { - text: 'Frequently Asked Questions', - link: 'Frequently-asked-questions', - }, - ], - }, - { - text: 'Reference', - collapsible: true, - prefix: 'Reference/', - // children: 'structure', - children: [ - { text: 'UDF Libraries', link: 'UDF-Libraries_timecho' }, - { text: 'UDF development', link: 'UDF-development' }, - { text: 'Function and Expression', link: 'Function-and-Expression' }, - { text: 'Common Config Manual', link: 'Common-Config-Manual' }, - { text: 'ConfigNode Config Manual', link: 'ConfigNode-Config-Manual' }, - { text: 'DataNode Config Manual', link: 'DataNode-Config-Manual_timecho' }, - { text: 'Status Codes', link: 'Status-Codes' }, - { text: 'Keywords', link: 'Keywords' }, - ], - }, - ], -}; diff --git a/src/.vuepress/sidebar_timecho/V1.3.0-2/zh.ts b/src/.vuepress/sidebar_timecho/V1.3.0-2/zh.ts deleted file mode 100644 index d045bae42..000000000 --- a/src/.vuepress/sidebar_timecho/V1.3.0-2/zh.ts +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const zhSidebar = { - '/zh/UserGuide/V1.3.0-2/': [ - { - text: 'IoTDB用户手册', - children: [], - }, - { - text: '关于IoTDB', - collapsible: true, - prefix: 'IoTDB-Introduction/', - // children: 'structure', 使用该方式自动获取文件夹下的文件 - children: [ - { text: '产品简介', link: 'IoTDB-Introduction_timecho' }, - { text: '主要功能特点', link: 'Features' }, - { text: '系统架构', link: 'Architecture' }, - { text: '性能特点', link: 'Performance' }, - { text: '应用场景', link: 'Scenario' }, - { text: '学术成果', link: 'Publication' }, - ], - }, - { - text: '快速上手', - link: 'QuickStart/QuickStart_timecho', - }, - { - text: '基础概念', - collapsible: true, - prefix: 'Basic-Concept/', - // children: 'structure', - children: [ - { text: '走进时序数据', link: 'Navigating_Time_Series_Data' }, - { text: '数据模型', link: 'Data-Model-and-Terminology' }, - { text: '数据类型', link: 'Data-Type' }, - { text: '编码和压缩', link: 'Encoding-and-Compression' }, - { text: '集群相关概念', link: 'Cluster-Concept' }, - { text: '数据分区与负载均衡', link: 'Cluster-data-partitioning' }, - ], - }, - { - text: '部署与运维', - collapsible: true, - prefix: 'Deployment-and-Maintenance/', - // children: 'structure', - children: [ - { text: '安装包获取', link: 'IoTDB-Package_timecho' }, - { text: '资源规划', link: 'Database-Resources' }, - { text: '环境配置', link: 'Environment-Requirements' }, - { text: '单机版部署', link: 'Stand-Alone-Deployment_timecho' }, - { text: '集群版部署', link: 'Cluster-Deployment_timecho' }, - { text: '双活版部署', link: 'Dual-Active-Deployment_timecho' }, - { text: 'Docker部署', link: 'Docker-Deployment_timecho' }, - { text: 'AINode部署', link: 'AINode_Deployment_timecho' }, - { text: '监控面板部署', link: 'Monitoring-panel-deployment' }, - { text: '可视化控制台部署', link: 'workbench-deployment_timecho' }, - ], - }, - - { - text: '使用手册', - collapsible: true, - prefix: 'User-Manual/', - // children: 'structure', - children: [ - { text: '语法约定', link: 'Syntax-Rule' }, - { text: '元数据管理', link: 'Operate-Metadata_timecho' }, - { text: '数据写入与删除', link: 'Write-Delete-Data' }, - { text: '数据查询', link: 'Query-Data' }, - { text: '运算符和表达式', link: 'Operator-and-Expression' }, - { text: '流处理框架', link: 'Streaming_timecho' }, - { text: '数据同步', link: 'Data-Sync_timecho' }, - { text: '多级存储', link: 'Tiered-Storage_timecho' }, - { text: '视图', link: 'IoTDB-View_timecho' }, - { text: 'AI能力', link: 'AINode_timecho' }, - { text: '数据库编程', link: 'Database-Programming' }, - { text: '用户自定义函数', link: 'User-defined-function' }, - { text: '安全控制', link: 'Security-Management_timecho' }, - { text: '权限管理', link: 'Authority-Management' }, - { text: '运维语句', link: 'Maintennance' }, - ], - }, - { - text: '工具体系', - collapsible: true, - prefix: 'Tools-System/', - // children: 'structure', - children: [ - { text: 'SQL命令行终端 (CLI)', link: 'CLI' }, - { text: '可视化控制台', link: 'Workbench_timecho' }, - { text: '监控工具', link: 'Monitor-Tool_timecho' }, - { text: '测试工具', link: 'Benchmark' }, - { text: '运维工具', link: 'Maintenance-Tool_timecho' }, - { text: '数据导入导出脚本', link: 'Data-Import-Export-Tool' }, - { text: 'TsFile导入导出脚本', link: 'TsFile-Import-Export-Tool' }, - ], - }, - { - text: '应用编程接口', - collapsible: true, - prefix: 'API/', - // children: 'structure', - children: [ - { text: 'Java原生接口', link: 'Programming-Java-Native-API' }, - { text: 'Python原生接口', link: 'Programming-Python-Native-API' }, - { text: 'C++原生接口', link: 'Programming-Cpp-Native-API' }, - { text: 'Go原生接口', link: 'Programming-Go-Native-API' }, - { text: 'C#原生接口', link: 'Programming-CSharp-Native-API' }, - { text: 'Node.js原生接口', link: 'Programming-NodeJS-Native-API' }, - { text: 'Rust', link: 'Programming-Rust-Native-API' }, - { text: 'JDBC (不推荐)', link: 'Programming-JDBC' }, - { text: 'MQTT协议', link: 'Programming-MQTT' }, - { text: 'Kafka', link: 'Programming-Kafka' }, - { text: 'REST API V1 (不推荐)', link: 'RestServiceV1' }, - { text: 'REST API V2', link: 'RestServiceV2' }, - ], - }, - { - text: '系统集成', - collapsible: true, - prefix: 'Ecosystem-Integration/', - // children: 'structure', - children: [ - { text: 'Apache Flink(IoTDB)', link: 'Flink-IoTDB' }, - { text: 'Apache Flink(TsFile)', link: 'Flink-TsFile' }, - { text: 'Apache Hive(TsFile)', link: 'Hive-TsFile' }, - { text: 'Apache NiFi', link: 'NiFi-IoTDB' }, - { text: 'Apache Spark(TsFile)', link: 'Spark-TsFile' }, - { text: 'Apache Spark(IoTDB)', link: 'Spark-IoTDB' }, - { text: 'Apache Zeppelin', link: 'Zeppelin-IoTDB_timecho' }, - { text: 'DataEase', link: 'DataEase' }, - { text: 'DBeaver', link: 'DBeaver' }, - { text: 'Ignition', link: 'Ignition-IoTDB-plugin_timecho' }, - { text: 'Grafana(IoTDB)', link: 'Grafana-Connector' }, - { text: 'Grafana插件', link: 'Grafana-Plugin' }, - { text: 'ThingsBoard', link: 'Thingsboard' }, - ], - }, - { - text: 'SQL手册', - collapsible: true, - prefix: 'SQL-Manual/', - // children: 'structure', - children: [{ text: 'SQL手册', link: 'SQL-Manual' }], - }, - { - text: 'FAQ', - collapsible: true, - prefix: 'FAQ/', - // children: 'structure', - children: [{ text: '常见问题', link: 'Frequently-asked-questions' }], - }, - { - text: '附录', - collapsible: true, - prefix: 'Reference/', - // children: 'structure', - children: [ - { text: 'UDF函数库', link: 'UDF-Libraries_timecho' }, - { text: 'UDF开发', link: 'UDF-development' }, - { text: '内置函数与表达式', link: 'Function-and-Expression' }, - { text: '配置参数', link: 'Common-Config-Manual' }, - { text: 'ConfigNode配置参数', link: 'ConfigNode-Config-Manual' }, - { text: 'DataNode配置参数', link: 'DataNode-Config-Manual_timecho' }, - { text: '状态码', link: 'Status-Codes' }, - { text: '关键字', link: 'Keywords' }, - ], - }, - ], -}; diff --git a/src/.vuepress/sidebar_timecho/V1.3.3/en.ts b/src/.vuepress/sidebar_timecho/V1.3.x/en.ts similarity index 89% rename from src/.vuepress/sidebar_timecho/V1.3.3/en.ts rename to src/.vuepress/sidebar_timecho/V1.3.x/en.ts index acd7d2683..f9a981801 100644 --- a/src/.vuepress/sidebar_timecho/V1.3.3/en.ts +++ b/src/.vuepress/sidebar_timecho/V1.3.x/en.ts @@ -17,7 +17,7 @@ */ export const enSidebar = { - '/UserGuide/V1.3.3/': [ + '/UserGuide/V1.3.x/': [ { text: 'IoTDB User Guide', children: [], @@ -106,8 +106,15 @@ export const enSidebar = { prefix: 'User-Manual/', // children: 'structure', children: [ - { text: 'Data Sync', link: 'Data-Sync_timecho' }, - { text: 'Data Subscription', link: 'Data-subscription' }, + { + text: 'Data Sync', + collapsible: true, + children: [ + { text: 'Data Sync(V1.3.0/1/2)', link: 'Data-Sync-old_timecho' }, + { text: 'Data Sync(V1.3.3)', link: 'Data-Sync_timecho' }, + ], + }, + { text: 'Data Subscription(V1.3.4)', link: 'Data-subscription' }, { text: 'AI Capability', link: 'AINode_timecho' }, { text: 'Security Management', @@ -153,8 +160,10 @@ export const enSidebar = { { text: 'Monitor Tool', link: 'Monitor-Tool_timecho' }, { text: 'Benchmark Tool', link: 'Benchmark' }, { text: 'Cluster Management Tool', link: 'Maintenance-Tool_timecho' }, - { text: 'Data Import', link: 'Data-Import-Tool' }, - { text: 'Data Export', link: 'Data-Export-Tool' }, + { text: 'Data Import Export(V1.3.0/1/2)', link: 'Data-Import-Export-Tool' }, + { text: 'TsFile Import Export(V1.3.0/1/2)', link: 'TsFile-Import-Export-Tool' }, + { text: 'Data Import(V1.3.3)', link: 'Data-Import-Tool' }, + { text: 'Data Export(V1.3.3)', link: 'Data-Export-Tool' }, ], }, { @@ -257,7 +266,16 @@ export const enSidebar = { // children: 'structure', children: [ { - text: 'Config Manual', + text: 'Config Manual(V1.3.0/1/2)', + collapsible: true, + children: [ + { text: 'Common Config Manual', link: 'Common-Config-Manual-old' }, + { text: 'ConfigNode Config Manual', link: 'ConfigNode-Config-Manual-old' }, + { text: 'DataNode Config Manual', link: 'DataNode-Config-Manual-old_timecho' }, + ], + }, + { + text: 'Config Manual(V1.3.3)', collapsible: true, children: [ { text: 'Common Config Manual', link: 'Common-Config-Manual' }, diff --git a/src/.vuepress/sidebar_timecho/V1.3.3/zh.ts b/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts similarity index 89% rename from src/.vuepress/sidebar_timecho/V1.3.3/zh.ts rename to src/.vuepress/sidebar_timecho/V1.3.x/zh.ts index 7bae1f719..443f24dbc 100644 --- a/src/.vuepress/sidebar_timecho/V1.3.3/zh.ts +++ b/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts @@ -17,7 +17,7 @@ */ export const zhSidebar = { - '/zh/UserGuide/V1.3.3/': [ + '/zh/UserGuide/V1.3.x/': [ { text: 'IoTDB用户手册', children: [], @@ -89,8 +89,15 @@ export const zhSidebar = { prefix: 'User-Manual/', // children: 'structure', children: [ - { text: '数据同步', link: 'Data-Sync_timecho' }, - { text: '数据订阅', link: 'Data-subscription' }, + { + text: '数据同步', + collapsible: true, + children: [ + { text: '数据同步(V1.3.0/1/2)', link: 'Data-Sync-old_timecho' }, + { text: '数据同步(V1.3.3)', link: 'Data-Sync_timecho' }, + ], + }, + { text: '数据订阅(V1.3.4)', link: 'Data-subscription' }, { text: 'AI能力', link: 'AINode_timecho' }, { text: '安全管理', @@ -136,8 +143,10 @@ export const zhSidebar = { { text: '监控工具', link: 'Monitor-Tool_timecho' }, { text: '测试工具', link: 'Benchmark' }, { text: '集群管理工具', link: 'Maintenance-Tool_timecho' }, - { text: '数据导入', link: 'Data-Import-Tool' }, - { text: '数据导出', link: 'Data-Export-Tool' }, + { text: '数据导入导出(V1.3.0/1/2)', link: 'Data-Import-Export-Tool' }, + { text: 'TsFile导入导出(V1.3.0/1/2)', link: 'TsFile-Import-Export-Tool' }, + { text: '数据导入(V1.3.3)', link: 'Data-Import-Tool' }, + { text: '数据导出(V1.3.3)', link: 'Data-Export-Tool' }, ], }, { @@ -231,7 +240,16 @@ export const zhSidebar = { // children: 'structure', children: [ { - text: '配置参数', + text: '配置参数(V1.3.0/1/2)', + collapsible: true, + children: [ + { text: '配置参数', link: 'Common-Config-Manual-old' }, + { text: 'ConfigNode配置参数', link: 'ConfigNode-Config-Manual-old' }, + { text: 'DataNode配置参数', link: 'DataNode-Config-Manual-old_timecho' }, + ], + }, + { + text: '配置参数(V1.3.3)', collapsible: true, children: [ { text: '配置参数', link: 'Common-Config-Manual' }, diff --git a/src/.vuepress/sidebar_timecho/en.ts b/src/.vuepress/sidebar_timecho/en.ts index d82778c65..507c1136b 100644 --- a/src/.vuepress/sidebar_timecho/en.ts +++ b/src/.vuepress/sidebar_timecho/en.ts @@ -19,7 +19,7 @@ import { sidebar } from 'vuepress-theme-hope'; import { enSidebar as V201xTableSidebar } from './V2.0.x/en-Table.js'; import { enSidebar as V201xTreeSidebar } from './V2.0.x/en-Tree.js'; -import { enSidebar as V103xSidebar } from './V1.3.3/en.js'; +import { enSidebar as V103xSidebar } from './V1.3.x/en.js'; import { enSidebar as V1030Sidebar } from './V1.3.0-2/en.js'; import { enSidebar as V102xSidebar } from './V1.2.x/en.js'; import { enSidebar as V101xSidebar } from './V1.1.x/en.js'; diff --git a/src/.vuepress/sidebar_timecho/zh.ts b/src/.vuepress/sidebar_timecho/zh.ts index 64d4ba9f0..791e4c60e 100644 --- a/src/.vuepress/sidebar_timecho/zh.ts +++ b/src/.vuepress/sidebar_timecho/zh.ts @@ -19,7 +19,7 @@ import { sidebar } from 'vuepress-theme-hope'; import { zhSidebar as V201xTableSidebar } from './V2.0.x/zh-Table.js'; import { zhSidebar as V201xTreeSidebar } from './V2.0.x/zh-Tree.js'; -import { zhSidebar as V103xSidebar } from './V1.3.3/zh.js'; +import { zhSidebar as V103xSidebar } from './V1.3.x/zh.js'; import { zhSidebar as V1030Sidebar } from './V1.3.0-2/zh.js'; import { zhSidebar as V102xSidebar } from './V1.2.x/zh.js'; import { zhSidebar as V101xSidebar } from './V1.1.x/zh.js'; diff --git a/src/UserGuide/V1.3.3/API/Programming-CSharp-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-CSharp-Native-API.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-CSharp-Native-API.md rename to src/UserGuide/V1.3.x/API/Programming-CSharp-Native-API.md diff --git a/src/UserGuide/V1.3.3/API/Programming-Cpp-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-Cpp-Native-API.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-Cpp-Native-API.md rename to src/UserGuide/V1.3.x/API/Programming-Cpp-Native-API.md diff --git a/src/UserGuide/V1.3.3/API/Programming-Data-Subscription.md b/src/UserGuide/V1.3.x/API/Programming-Data-Subscription.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-Data-Subscription.md rename to src/UserGuide/V1.3.x/API/Programming-Data-Subscription.md diff --git a/src/UserGuide/V1.3.3/API/Programming-Go-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-Go-Native-API.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-Go-Native-API.md rename to src/UserGuide/V1.3.x/API/Programming-Go-Native-API.md diff --git a/src/UserGuide/V1.3.3/API/Programming-JDBC.md b/src/UserGuide/V1.3.x/API/Programming-JDBC.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-JDBC.md rename to src/UserGuide/V1.3.x/API/Programming-JDBC.md diff --git a/src/UserGuide/V1.3.3/API/Programming-Java-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-Java-Native-API.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-Java-Native-API.md rename to src/UserGuide/V1.3.x/API/Programming-Java-Native-API.md diff --git a/src/UserGuide/V1.3.3/API/Programming-Kafka.md b/src/UserGuide/V1.3.x/API/Programming-Kafka.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-Kafka.md rename to src/UserGuide/V1.3.x/API/Programming-Kafka.md diff --git a/src/UserGuide/V1.3.3/API/Programming-MQTT.md b/src/UserGuide/V1.3.x/API/Programming-MQTT.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-MQTT.md rename to src/UserGuide/V1.3.x/API/Programming-MQTT.md diff --git a/src/UserGuide/V1.3.3/API/Programming-NodeJS-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-NodeJS-Native-API.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-NodeJS-Native-API.md rename to src/UserGuide/V1.3.x/API/Programming-NodeJS-Native-API.md diff --git a/src/UserGuide/V1.3.3/API/Programming-ODBC.md b/src/UserGuide/V1.3.x/API/Programming-ODBC.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-ODBC.md rename to src/UserGuide/V1.3.x/API/Programming-ODBC.md diff --git a/src/UserGuide/V1.3.3/API/Programming-OPC-UA_timecho.md b/src/UserGuide/V1.3.x/API/Programming-OPC-UA_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-OPC-UA_timecho.md rename to src/UserGuide/V1.3.x/API/Programming-OPC-UA_timecho.md diff --git a/src/UserGuide/V1.3.3/API/Programming-Python-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-Python-Native-API.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-Python-Native-API.md rename to src/UserGuide/V1.3.x/API/Programming-Python-Native-API.md diff --git a/src/UserGuide/V1.3.3/API/Programming-Rust-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-Rust-Native-API.md similarity index 100% rename from src/UserGuide/V1.3.3/API/Programming-Rust-Native-API.md rename to src/UserGuide/V1.3.x/API/Programming-Rust-Native-API.md diff --git a/src/UserGuide/V1.3.3/API/RestServiceV1.md b/src/UserGuide/V1.3.x/API/RestServiceV1.md similarity index 100% rename from src/UserGuide/V1.3.3/API/RestServiceV1.md rename to src/UserGuide/V1.3.x/API/RestServiceV1.md diff --git a/src/UserGuide/V1.3.3/API/RestServiceV2.md b/src/UserGuide/V1.3.x/API/RestServiceV2.md similarity index 100% rename from src/UserGuide/V1.3.3/API/RestServiceV2.md rename to src/UserGuide/V1.3.x/API/RestServiceV2.md diff --git a/src/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept.md b/src/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept.md similarity index 100% rename from src/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept.md rename to src/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept.md diff --git a/src/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_apache.md b/src/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_apache.md rename to src/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_apache.md diff --git a/src/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_timecho.md b/src/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_timecho.md rename to src/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_timecho.md diff --git a/src/UserGuide/V1.3.3/Background-knowledge/Data-Type.md b/src/UserGuide/V1.3.x/Background-knowledge/Data-Type.md similarity index 100% rename from src/UserGuide/V1.3.3/Background-knowledge/Data-Type.md rename to src/UserGuide/V1.3.x/Background-knowledge/Data-Type.md diff --git a/src/UserGuide/V1.3.3/Basic-Concept/Data-Model-and-Terminology.md b/src/UserGuide/V1.3.x/Basic-Concept/Data-Model-and-Terminology.md similarity index 100% rename from src/UserGuide/V1.3.3/Basic-Concept/Data-Model-and-Terminology.md rename to src/UserGuide/V1.3.x/Basic-Concept/Data-Model-and-Terminology.md diff --git a/src/UserGuide/V1.3.3/Basic-Concept/Navigating_Time_Series_Data.md b/src/UserGuide/V1.3.x/Basic-Concept/Navigating_Time_Series_Data.md similarity index 100% rename from src/UserGuide/V1.3.3/Basic-Concept/Navigating_Time_Series_Data.md rename to src/UserGuide/V1.3.x/Basic-Concept/Navigating_Time_Series_Data.md diff --git a/src/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata.md b/src/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata.md similarity index 100% rename from src/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata.md rename to src/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata.md diff --git a/src/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_apache.md b/src/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_apache.md rename to src/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_apache.md diff --git a/src/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_timecho.md b/src/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_timecho.md rename to src/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_timecho.md diff --git a/src/UserGuide/V1.3.3/Basic-Concept/Query-Data.md b/src/UserGuide/V1.3.x/Basic-Concept/Query-Data.md similarity index 100% rename from src/UserGuide/V1.3.3/Basic-Concept/Query-Data.md rename to src/UserGuide/V1.3.x/Basic-Concept/Query-Data.md diff --git a/src/UserGuide/V1.3.3/Basic-Concept/Write-Delete-Data.md b/src/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md similarity index 100% rename from src/UserGuide/V1.3.3/Basic-Concept/Write-Delete-Data.md rename to src/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_apache.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_apache.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_apache.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_timecho.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_timecho.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_timecho.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_apache.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_apache.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_apache.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_timecho.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_timecho.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_timecho.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Database-Resources.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Database-Resources.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Database-Resources.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Database-Resources.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_apache.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_apache.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_apache.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_timecho.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_timecho.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_timecho.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Environment-Requirements.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Environment-Requirements.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Environment-Requirements.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Environment-Requirements.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_apache.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_apache.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_apache.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_timecho.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_timecho.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_timecho.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Monitoring-panel-deployment.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Monitoring-panel-deployment.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Monitoring-panel-deployment.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Monitoring-panel-deployment.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md diff --git a/src/UserGuide/V1.3.3/Deployment-and-Maintenance/workbench-deployment_timecho.md b/src/UserGuide/V1.3.x/Deployment-and-Maintenance/workbench-deployment_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Deployment-and-Maintenance/workbench-deployment_timecho.md rename to src/UserGuide/V1.3.x/Deployment-and-Maintenance/workbench-deployment_timecho.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/DBeaver.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/DBeaver.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/DBeaver.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/DBeaver.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/DataEase.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/DataEase.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/DataEase.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/DataEase.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Flink-IoTDB.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Flink-IoTDB.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Flink-IoTDB.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Flink-IoTDB.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Flink-TsFile.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Flink-TsFile.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Flink-TsFile.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Flink-TsFile.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Connector.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Connector.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Connector.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Connector.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Plugin.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Plugin.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Plugin.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Plugin.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Hive-TsFile.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Hive-TsFile.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Hive-TsFile.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Hive-TsFile.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_apache.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_apache.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_apache.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_timecho.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_timecho.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_timecho.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/NiFi-IoTDB.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/NiFi-IoTDB.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/NiFi-IoTDB.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/NiFi-IoTDB.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Spark-IoTDB.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Spark-IoTDB.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Spark-IoTDB.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Spark-IoTDB.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Spark-TsFile.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Spark-TsFile.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Spark-TsFile.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Spark-TsFile.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Telegraf.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Telegraf.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Telegraf.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Telegraf.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Thingsboard.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Thingsboard.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Thingsboard.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Thingsboard.md diff --git a/src/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB.md b/src/UserGuide/V1.3.x/Ecosystem-Integration/Zeppelin-IoTDB.md similarity index 100% rename from src/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB.md rename to src/UserGuide/V1.3.x/Ecosystem-Integration/Zeppelin-IoTDB.md diff --git a/src/UserGuide/V1.3.3/FAQ/Frequently-asked-questions.md b/src/UserGuide/V1.3.x/FAQ/Frequently-asked-questions.md similarity index 100% rename from src/UserGuide/V1.3.3/FAQ/Frequently-asked-questions.md rename to src/UserGuide/V1.3.x/FAQ/Frequently-asked-questions.md diff --git a/src/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_apache.md b/src/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_apache.md rename to src/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_apache.md diff --git a/src/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_timecho.md b/src/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_timecho.md rename to src/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_timecho.md diff --git a/src/UserGuide/V1.3.3/IoTDB-Introduction/Scenario.md b/src/UserGuide/V1.3.x/IoTDB-Introduction/Scenario.md similarity index 100% rename from src/UserGuide/V1.3.3/IoTDB-Introduction/Scenario.md rename to src/UserGuide/V1.3.x/IoTDB-Introduction/Scenario.md diff --git a/src/UserGuide/V1.3.3/QuickStart/QuickStart.md b/src/UserGuide/V1.3.x/QuickStart/QuickStart.md similarity index 100% rename from src/UserGuide/V1.3.3/QuickStart/QuickStart.md rename to src/UserGuide/V1.3.x/QuickStart/QuickStart.md diff --git a/src/UserGuide/V1.3.3/QuickStart/QuickStart_apache.md b/src/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/QuickStart/QuickStart_apache.md rename to src/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md diff --git a/src/UserGuide/V1.3.3/QuickStart/QuickStart_timecho.md b/src/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/QuickStart/QuickStart_timecho.md rename to src/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md diff --git a/src/UserGuide/V1.3.x/Reference/Common-Config-Manual-old.md b/src/UserGuide/V1.3.x/Reference/Common-Config-Manual-old.md new file mode 100644 index 000000000..2c84562db --- /dev/null +++ b/src/UserGuide/V1.3.x/Reference/Common-Config-Manual-old.md @@ -0,0 +1,2065 @@ + + +# Common Configuration + +IoTDB common files for ConfigNode and DataNode are under `conf`. + +* `iotdb-common.properties`:IoTDB system configurations. + + +## Effective +Different configuration parameters take effect in the following three ways: + ++ **Only allowed to be modified in first start up:** Can't be modified after first start, otherwise the ConfigNode/DataNode cannot start. ++ **After restarting system:** Can be modified after the ConfigNode/DataNode first start, but take effect after restart. ++ **hot-load:** Can be modified while the ConfigNode/DataNode is running, and trigger through sending the command(sql) `load configuration` or `set configuration` to the IoTDB server by client or session. + +## Configuration File + +### Replication Configuration + +* config\_node\_consensus\_protocol\_class + +| Name | config\_node\_consensus\_protocol\_class | +|:-----------:|:-----------------------------------------------------------------------| +| Description | Consensus protocol of ConfigNode replicas, only support RatisConsensus | +| Type | String | +| Default | org.apache.iotdb.consensus.ratis.RatisConsensus | +| Effective | Only allowed to be modified in first start up | + +* schema\_replication\_factor + +| Name | schema\_replication\_factor | +|:-----------:|:-----------------------------------------------------------------| +| Description | Schema replication num | +| Type | int32 | +| Default | 1 | +| Effective | Take effect on **new created Databases** after restarting system | + +* schema\_region\_consensus\_protocol\_class + +| Name | schema\_region\_consensus\_protocol\_class | +|:-----------:|:--------------------------------------------------------------------------------------------------------------------------------------------:| +| Description | Consensus protocol of schema replicas,larger than 1 replicas could only use RatisConsensus | +| Type | String | +| Default | org.apache.iotdb.consensus.ratis.RatisConsensus | +| Effective | Only allowed to be modified in first start up | + +* data\_replication\_factor + +| Name | data\_replication\_factor | +|:-----------:|:-----------------------------------------------------------------| +| Description | Data replication num | +| Type | int32 | +| Default | 1 | +| Effective | Take effect on **new created Databases** after restarting system | + +* data\_region\_consensus\_protocol\_class + +| Name | data\_region\_consensus\_protocol\_class | +|:-----------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | Consensus protocol of data replicasa,larger than 1 replicas could use IoTConsensus or RatisConsensus | +| Type | String | +| Default | org.apache.iotdb.consensus.simple.SimpleConsensus | +| Effective | Only allowed to be modified in first start up | + +### Load balancing Configuration + +* series\_partition\_slot\_num + +| Name | series\_slot\_num | +|:-----------:|:----------------------------------------------| +| Description | Slot num of series partition | +| Type | int32 | +| Default | 10000 | +| Effective | Only allowed to be modified in first start up | + +* series\_partition\_executor\_class + +| Name | series\_partition\_executor\_class | +|:-----------:|:------------------------------------------------------------------| +| Description | Series partition hash function | +| Type | String | +| Default | org.apache.iotdb.commons.partition.executor.hash.BKDRHashExecutor | +| Effective | Only allowed to be modified in first start up | + +* schema\_region\_group\_extension\_policy + +| Name | schema\_region\_group\_extension\_policy | +|:-----------:|:------------------------------------------| +| Description | The extension policy of SchemaRegionGroup | +| Type | string | +| Default | AUTO | +| Effective | After restarting system | + +* default\_schema\_region\_group\_num\_per\_database + +| Name | default\_schema\_region\_group\_num\_per\_database | +|:-----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | The number of SchemaRegionGroups that each Database has when using the CUSTOM-SchemaRegionGroup extension policy. The least number of SchemaRegionGroups that each Database has when using the AUTO-SchemaRegionGroup extension policy. | +| Type | int | +| Default | 1 | +| Effective | After restarting system | + +* schema\_region\_per\_data\_node + +| Name | schema\_region\_per\_data\_node | +|:-----------:|:---------------------------------------------------------------------------| +| Description | The maximum number of SchemaRegion expected to be managed by each DataNode | +| Type | double | +| Default | 1.0 | +| Effective | After restarting system | + +* data\_region\_group\_extension\_policy + +| Name | data\_region\_group\_extension\_policy | +|:-----------:|:----------------------------------------| +| Description | The extension policy of DataRegionGroup | +| Type | string | +| Default | AUTO | +| Effective | After restarting system | + +* default\_data\_region\_group\_num\_per\_database + +| Name | default\_data\_region\_group\_num\_per\_database | +|:-----------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | The number of DataRegionGroups that each Database has when using the CUSTOM-DataRegionGroup extension policy. The least number of DataRegionGroups that each Database has when using the AUTO-DataRegionGroup extension policy. | +| Type | int | +| Default | 1 | +| Effective | After restarting system | + +* data\_region\_per\_processor + +| Name | data\_region\_per\_processor | +|:-----------:|:--------------------------------------------------------------------------| +| Description | The maximum number of DataRegion expected to be managed by each processor | +| Type | double | +| Default | 1.0 | +| Effective | After restarting system | + +* enable\_data\_partition\_inherit\_policy + +| Name | enable\_data\_partition\_inherit\_policy | +|:-----------:|:---------------------------------------------------| +| Description | Whether to enable the DataPartition inherit policy | +| Type | Boolean | +| Default | false | +| Effective | After restarting system | + +* leader\_distribution\_policy + +| Name | leader\_distribution\_policy | +|:-----------:|:--------------------------------------------------------| +| Description | The policy of cluster RegionGroups' leader distribution | +| Type | String | +| Default | MIN_COST_FLOW | +| Effective | After restarting system | + +* enable\_auto\_leader\_balance\_for\_ratis + +| Name | enable\_auto\_leader\_balance\_for\_ratis\_consensus | +|:-----------:|:-------------------------------------------------------------------| +| Description | Whether to enable auto leader balance for Ratis consensus protocol | +| Type | Boolean | +| Default | false | +| Effective | After restarting system | + +* enable\_auto\_leader\_balance\_for\_iot\_consensus + +| Name | enable\_auto\_leader\_balance\_for\_iot\_consensus | +|:-----------:|:----------------------------------------------------------------| +| Description | Whether to enable auto leader balance for IoTConsensus protocol | +| Type | Boolean | +| Default | true | +| Effective | After restarting system | + +### Cluster Management + +* time\_partition\_interval + +| Name | time\_partition\_interval | +|:-----------:|:--------------------------------------------------------------| +| Description | Time partition interval of data when ConfigNode allocate data | +| Type | Long | +| Unit | ms | +| Default | 604800000 | +| Effective | Only allowed to be modified in first start up | + +* heartbeat\_interval\_in\_ms + +| Name | heartbeat\_interval\_in\_ms | +|:-----------:|:----------------------------------------| +| Description | Heartbeat interval in the cluster nodes | +| Type | Long | +| Unit | ms | +| Default | 1000 | +| Effective | After restarting system | + +* disk\_space\_warning\_threshold + +| Name | disk\_space\_warning\_threshold | +|:-----------:|:--------------------------------| +| Description | Disk remaining threshold | +| Type | double(percentage) | +| Default | 0.05 | +| Effective | After restarting system | + +### Memory Control Configuration + +* datanode\_memory\_proportion + +|Name| datanode\_memory\_proportion | +|:---:|:-------------------------------------------------------------------------------------------------------------| +|Description| Memory Allocation Ratio: StorageEngine, QueryEngine, SchemaEngine, StreamingEngine, Consensus and Free Memory | +|Type| Ratio | +|Default| 3:3:1:1:1:1 | +|Effective| After restarting system | + +* schema\_memory\_allocate\_proportion + +|Name| schema\_memory\_allocate\_proportion | +|:---:|:----------------------------------------------------------------------------------------| +|Description| Schema Memory Allocation Ratio: SchemaRegion, SchemaCache, PartitionCache and LastCache | +|Type| Ratio | +|Default| 5:3:1:1 | +|Effective| After restarting system | + +* storage\_engine\_memory\_proportion + +|Name| storage\_engine\_memory\_proportion | +|:---:|:------------------------------------| +|Description| Memory allocation ratio in StorageEngine: Write, Compaction | +|Type| Ratio | +|Default| 8:2 | +|Effective| After restarting system | + +* write\_memory\_proportion + +|Name| write\_memory\_proportion | +|:---:|:----------------------------------------------------------------| +|Description| Memory allocation ratio in writing: Memtable, TimePartitionInfo | +|Type| Ratio | +|Default| 19:1 | +|Effective| After restarting system | + +* concurrent\_writing\_time\_partition + +|Name| concurrent\_writing\_time\_partition | +|:---:|:---| +|Description| This config decides how many time partitions in a database can be inserted concurrently
For example, your partitionInterval is 86400 and you want to insert data in 5 different days, | +|Type|int32| +|Default| 1 | +|Effective|After restarting system| + +* primitive\_array\_size + +| Name | primitive\_array\_size | +|:-----------:|:----------------------------------------------------------| +| Description | primitive array size (length of each array) in array pool | +| Type | Int32 | +| Default | 64 | +| Effective | After restart system | + +* chunk\_metadata\_size\_proportion + +|Name| chunk\_metadata\_size\_proportion | +|:---:|:------------------------------------| +|Description| size proportion for chunk metadata maintains in memory when writing tsfile | +|Type| Double | +|Default| 0.1 | +|Effective|After restart system| + +* flush\_proportion + +| Name | flush\_proportion | +|:-----------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | Ratio of write memory for invoking flush disk, 0.4 by default If you have extremely high write load (like batch=1000), it can be set lower than the default value like 0.2 | +| Type | Double | +| Default | 0.4 | +| Effective | After restart system | + +* buffered\_arrays\_memory\_proportion + +|Name| buffered\_arrays\_memory\_proportion | +|:---:|:---| +|Description| Ratio of write memory allocated for buffered arrays | +|Type| Double | +|Default| 0.6 | +|Effective|After restart system| + +* reject\_proportion + +|Name| reject\_proportion | +|:---:|:---| +|Description| Ratio of write memory for rejecting insertion | +|Type| Double | +|Default| 0.8 | +|Effective|After restart system| + +* write\_memory\_variation\_report\_proportion + +| Name | write\_memory\_variation\_report\_proportion | +| :---------: | :----------------------------------------------------------- | +| Description | if memory cost of data region increased more than proportion of allocated memory for write, report to system | +| Type | Double | +| Default | 0.001 | +| Effective | After restarting system | + +* check\_period\_when\_insert\_blocked + +|Name| check\_period\_when\_insert\_blocked | +|:---:|:----------------------------------------------------------------------------| +|Description| when an inserting is rejected, waiting period (in ms) to check system again | +|Type| Int32 | +|Default| 50 | +|Effective| After restart system | + +* io\_task\_queue\_size\_for\_flushing + +|Name| io\_task\_queue\_size\_for\_flushing | +|:---:|:----------------------------------------------| +|Description| size of ioTaskQueue. The default value is 10 | +|Type| Int32 | +|Default| 10 | +|Effective| After restart system | + +* enable\_query\_memory\_estimation + +|Name| enable\_query\_memory\_estimation | +|:---:|:----------------------------------| +|Description| If true, we will estimate each query's possible memory footprint before executing it and deny it if its estimated memory exceeds current free memory | +|Type| bool | +|Default| true | +|Effective|hot-load| + +* partition\_cache\_size + +|Name| partition\_cache\_size | +|:---:|:---| +|Description| The max num of partition info record cached on DataNode. | +|Type| Int32 | +|Default| 1000 | +|Effective|After restarting system| + +### Schema Engine Configuration + +* schema\_engine\_mode + +| Name | schema\_engine\_mode | +|:-----------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | Schema engine mode, supporting Memory and PBTree modes; PBTree mode support evict the timeseries schema temporarily not used in memory at runtime, and load it into memory from disk when needed. This parameter must be the same on all DataNodes in one cluster. | +| Type | string | +| Default | Memory | +| Effective | Only allowed to be modified in first start up | + +* mlog\_buffer\_size + +|Name| mlog\_buffer\_size | +|:---:|:---| +|Description| size of log buffer in each metadata operation plan(in byte) | +|Type|int32| +|Default| 1048576 | +|Effective|After restart system| + +* sync\_mlog\_period\_in\_ms + +| Name | sync\_mlog\_period\_in\_ms | +| :---------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Description | The cycle when metadata log is periodically forced to be written to disk(in milliseconds). If force_mlog_period_in_ms = 0 it means force metadata log to be written to disk after each refreshment | +| Type | Int64 | +| Default | 100 | +| Effective | After restarting system | + +* tag\_attribute\_flush\_interval + +|Name| tag\_attribute\_flush\_interval | +|:---:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +|Description| interval num for tag and attribute records when force flushing to disk. When a certain amount of tag and attribute records is reached, they will be force flushed to disk. It is possible to lose at most tag_attribute_flush_interval records | +|Type| int32 | +|Default| 1000 | +|Effective| Only allowed to be modified in first start up | + +* tag\_attribute\_total\_size + +|Name| tag\_attribute\_total\_size | +|:---:|:---| +|Description| The maximum persistence size of tags and attributes of each time series.| +|Type| int32 | +|Default| 700 | +|Effective|Only allowed to be modified in first start up| + +* schema\_region\_device\_node\_cache\_size + +|Name| schema\_region\_device\_node\_cache\_size | +|:---:|:--------------------------------| +|Description| The max num of device node, used for speeding up device query, cached in schemaRegion. | +|Type| Int32 | +|Default| 10000 | +|Effective|After restarting system| + +* max\_measurement\_num\_of\_internal\_request + +|Name| max\_measurement\_num\_of\_internal\_request | +|:---:|:--------------------------------| +|Description| When there's too many measurements in one create timeseries plan, the plan will be split to several sub plan, with measurement num no more than this param.| +|Type| Int32 | +|Default| 10000 | +|Effective|After restarting system| + +### Configurations for creating schema automatically + +* enable\_auto\_create\_schema + +| Name | enable\_auto\_create\_schema | +| :---------: | :---------------------------------------------------------------------------- | +| Description | whether auto create the time series when a non-existed time series data comes | +| Type | true or false | +| Default | true | +| Effective | After restarting system | + +* default\_storage\_group\_level + +| Name | default\_storage\_group\_level | +| :---------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Description | Database level when creating schema automatically is enabled. For example, if we receives a data point from root.sg0.d1.s2, we will set root.sg0 as the database if database level is 1. (root is level 0) | +| Type | integer | +| Default | 1 | +| Effective | After restarting system | + +* boolean\_string\_infer\_type + +| Name | boolean\_string\_infer\_type | +| :---------: | :------------------------------------------------------------ | +| Description | To which type the values "true" and "false" should be reslved | +| Type | BOOLEAN or TEXT | +| Default | BOOLEAN | +| Effective | After restarting system | + +* integer\_string\_infer\_type + +| Name | integer\_string\_infer\_type | +| :---------: | :---------------------------------------------------------------------- | +| Description | To which type an integer string like "67" in a query should be resolved | +| Type | INT32, INT64, DOUBLE, FLOAT or TEXT | +| Default | DOUBLE | +| Effective | After restarting system | + +* floating\_string\_infer\_type + +| Name | floating\_string\_infer\_type | +| :---------: | :------------------------------------------------------------------------------ | +| Description | To which type a floating number string like "6.7" in a query should be resolved | +| Type | DOUBLE, FLOAT or TEXT | +| Default | DOUBLE | +| Effective | After restarting system | + +* nan\_string\_infer\_type + +| Name | nan\_string\_infer\_type | +| :---------: |:----------------------------------------------------------| +| Description | To which type the value NaN in a query should be resolved | +| Type | DOUBLE, FLOAT or TEXT | +| Default | DOUBLE | +| Effective | After restarting system | + +### Query Configurations + +* read\_consistency\_level + +| Name | mpp\_data\_exchange\_core\_pool\_size | +|:-----------:|:---------------------------------------------| +| Description | The read consistency level,
1. strong(Default, read from the leader replica)
2. weak(Read from a random replica) | +| Type | string | +| Default | strong | +| Effective | After restarting system | + +* meta\_data\_cache\_enable + +|Name| meta\_data\_cache\_enable | +|:---:|:---| +|Description| Whether to cache meta data(BloomFilter, ChunkMetadata and TimeSeriesMetadata) or not.| +|Type|Boolean| +|Default| true | +|Effective| After restarting system| + +* chunk\_timeseriesmeta\_free\_memory\_proportion + +|Name| chunk\_timeseriesmeta\_free\_memory\_proportion | +|:---:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +|Description| Read memory Allocation Ratio: BloomFilterCache : ChunkCache : TimeSeriesMetadataCache : Coordinator : Operators : DataExchange : timeIndex in TsFileResourceList : others. | +|Default| 1 : 100 : 200 : 300 : 400 | +|Effective| After restarting system | + +* enable\_last\_cache + +|Name| enable\_last\_cache | +|:---:|:---| +|Description| Whether to enable LAST cache. | +|Type| Boolean | +|Default| true | +|Effective|After restarting system| + +* max\_deduplicated\_path\_num + +|Name| max\_deduplicated\_path\_num | +|:---:|:---| +|Description| allowed max numbers of deduplicated path in one query. | +|Type| Int32 | +|Default| 1000 | +|Effective|After restarting system| + +* mpp\_data\_exchange\_core\_pool\_size + +| Name | mpp\_data\_exchange\_core\_pool\_size | +|:-----------:|:---------------------------------------------| +| Description | Core size of ThreadPool of MPP data exchange | +| Type | int32 | +| Default | 10 | +| Effective | After restarting system | + +* mpp\_data\_exchange\_max\_pool\_size + +| Name | mpp\_data\_exchange\_max\_pool\_size | +| :---------: | :------------------------------------------ | +| Description | Max size of ThreadPool of MPP data exchange | +| Type | int32 | +| Default | 10 | +| Effective | After restarting system | + +* mpp\_data\_exchange\_keep\_alive\_time\_in\_ms + +|Name| mpp\_data\_exchange\_keep\_alive\_time\_in\_ms | +|:---:|:---| +|Description| Max waiting time for MPP data exchange | +|Type| long | +|Default| 1000 | +|Effective|After restarting system| + +* driver\_task\_execution\_time\_slice\_in\_ms + +| Name | driver\_task\_execution\_time\_slice\_in\_ms | +| :---------: | :------------------------------------------- | +| Description | Maximum execution time of a DriverTask | +| Type | int32 | +| Default | 100 | +| Effective | After restarting system | + +* max\_tsblock\_size\_in\_bytes + +| Name | max\_tsblock\_size\_in\_bytes | +| :---------: | :---------------------------- | +| Description | Maximum capacity of a TsBlock | +| Type | int32 | +| Default | 1024 * 1024 (1 MB) | +| Effective | After restarting system | + +* max\_tsblock\_line\_numbers + +| Name | max\_tsblock\_line\_numbers | +| :---------: | :------------------------------------------ | +| Description | Maximum number of lines in a single TsBlock | +| Type | int32 | +| Default | 1000 | +| Effective | After restarting system | + +* slow\_query\_threshold + +|Name| slow\_query\_threshold | +|:---:|:----------------------------------------| +|Description| Time cost(ms) threshold for slow query. | +|Type| Int32 | +|Default| 30000 | +|Effective| Trigger | + +* query\_timeout\_threshold + +|Name| query\_timeout\_threshold | +|:---:|:---| +|Description| The max executing time of query. unit: ms | +|Type| Int32 | +|Default| 60000 | +|Effective| After restarting system| + +* max\_allowed\_concurrent\_queries + +|Name| max\_allowed\_concurrent\_queries | +|:---:|:---| +|Description| The maximum allowed concurrently executing queries. | +|Type| Int32 | +|Default| 1000 | +|Effective|After restarting system| + +* query\_thread\_count + +|Name| query\_thread\_count | +|:---:|:---------------------------------------------------------------------------------------------------------------------| +|Description| How many threads can concurrently execute query statement. When <= 0, use CPU core number. | +|Type| Int32 | +|Default | CPU core number | +|Effective| After restarting system | + +* batch\_size + +|Name| batch\_size | +|:---:|:---| +|Description| The amount of data iterate each time in server (the number of data strips, that is, the number of different timestamps.) | +|Type| Int32 | +|Default| 100000 | +|Effective|After restarting system| + +### Storage Engine Configuration + +* timestamp\_precision + +| Name | timestamp\_precision | +| :----------: | :-------------------------- | +| Description | timestamp precision,support ms、us、ns | +| Type | String | +| Default | ms | +| Effective | Only allowed to be modified in first start up | + +* default\_ttl\_in\_ms + +| Name | default\_ttl\_in\_ms | +|:---:|:--------------| +|Description| Define the maximum age of data for which each tier is responsible | +|Type| long | +|Default| -1 | +|Effective| After restarting system | + +* max\_waiting\_time\_when\_insert\_blocked + +| Name | max\_waiting\_time\_when\_insert\_blocked | +| :---------: |:------------------------------------------------------------------------------| +| Description | When the waiting time(in ms) of an inserting exceeds this, throw an exception | +| Type | Int32 | +| Default | 10000 | +| Effective | After restarting system | + +* handle\_system\_error + +| Name | handle\_system\_error | +| :---------: |:-------------------------------------------------------| +| Description | What will the system do when unrecoverable error occurs| +| Type | String | +| Default | CHANGE\_TO\_READ\_ONLY | +| Effective | After restarting system | + +* write\_memory\_variation\_report\_proportion + +| Name | write\_memory\_variation\_report\_proportion | +| :---------: | :----------------------------------------------------------------------------------------------------------- | +| Description | if memory cost of data region increased more than proportion of allocated memory for write, report to system | +| Type | Double | +| Default | 0.001 | +| Effective | After restarting system | + +* enable\_timed\_flush\_seq\_memtable + +| Name | enable\_timed\_flush\_seq\_memtable | +|:-----------:|:------------------------------------------------| +| Description | whether to enable timed flush sequence memtable | +| Type | Boolean | +| Default | true | +| Effective | hot-load | + +* seq\_memtable\_flush\_interval\_in\_ms + +| Name | seq\_memtable\_flush\_interval\_in\_ms | +|:-----------:|:---------------------------------------------------------------------------------------------------------| +| Description | if a memTable's created time is older than current time minus this, the memtable will be flushed to disk | +| Type | int32 | +| Default | 10800000 | +| Effective | hot-load | + +* seq\_memtable\_flush\_check\_interval\_in\_ms + +|Name| seq\_memtable\_flush\_check\_interval\_in\_ms | +|:---:|:---| +|Description| the interval to check whether sequence memtables need flushing | +|Type|int32| +|Default| 600000 | +|Effective| hot-load | + +* enable\_timed\_flush\_unseq\_memtable + +|Name| enable\_timed\_flush\_unseq\_memtable | +|:---:|:---| +|Description| whether to enable timed flush unsequence memtable | +|Type|Boolean| +|Default| false | +|Effective| hot-load | + +* unseq\_memtable\_flush\_interval\_in\_ms + +| Name | unseq\_memtable\_flush\_interval\_in\_ms | +|:-----------:|:---------------------------------------------------------------------------------------------------------| +| Description | if a memTable's created time is older than current time minus this, the memtable will be flushed to disk | +| Type | int32 | +| Default | 600000 | +| Effective | hot-load | + +* unseq\_memtable\_flush\_check\_interval\_in\_ms + +|Name| unseq\_memtable\_flush\_check\_interval\_in\_ms | +|:---:|:---| +|Description| the interval to check whether unsequence memtables need flushing | +|Type|int32| +|Default| 30000 | +|Effective| hot-load | + +* tvlist\_sort\_algorithm + +|Name| tvlist\_sort\_algorithm | +|:---:|:--------------------------------------------------| +|Description| the sort algorithm used in the memtable's TVList | +|Type| String | +|Default| TIM | +|Effective| After restarting system | + +* avg\_series\_point\_number\_threshold + +|Name| avg\_series\_point\_number\_threshold | +|:---:|:-------------------------------------------------------| +|Description| max average number of point of each series in memtable | +|Type| int32 | +|Default| 100000 | +|Effective| After restarting system | + +* flush\_thread\_count + +|Name| flush\_thread\_count | +|:---:|:---| +|Description| The thread number used to perform the operation when IoTDB writes data in memory to disk. If the value is less than or equal to 0, then the number of CPU cores installed on the machine is used. The default is 0.| +|Type| int32 | +|Default| 0 | +|Effective|After restarting system| + +* enable\_partial\_insert + +|Name| enable\_partial\_insert | +|:---:|:---| +|Description| Whether continue to write other measurements if some measurements are failed in one insertion.| +|Type| Boolean | +|Default| true | +|Effective|After restarting system| + +* recovery\_log\_interval\_in\_ms + +|Name| recovery\_log\_interval\_in\_ms | +|:---:|:------------------------------------------------------------------------| +|Description| the interval to log recover progress of each region when starting iotdb | +|Type| Int32 | +|Default| 5000 | +|Effective| After restarting system | + +* 0.13\_data\_insert\_adapt + +|Name| 0.13\_data\_insert\_adapt | +|:---:|:----------------------------------------------------------------------| +|Description| if using v0.13 client to insert data, set this configuration to true. | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + + +* device\_path\_cache\_size + +| Name | device\_path\_cache\_size | +|:---------:|:--------------------------------------------------------------------------------------------------------------------------| +|Description| The max size of the device path cache. This cache is for avoiding initialize duplicated device id object in write process | +| Type | Int32 | +| Default | 500000 | +| Effective | After restarting system | + +* insert\_multi\_tablet\_enable\_multithreading\_column\_threshold + +| Name | insert\_multi\_tablet\_enable\_multithreading\_column\_threshold | +| :---------: | :--------------------------------------------------------------------------------------------- | +| Description | When the insert plan column count reaches the specified threshold, multi-threading is enabled. | +| Type | int32 | +| Default | 10 | +| Effective | After restarting system | + +### Compaction Configurations + +* enable\_seq\_space\_compaction + +| Name | enable\_seq\_space\_compaction | +| :---------: |:---------------------------------------------| +| Description | enable the compaction between sequence files | +| Type | Boolean | +| Default | true | +| Effective | hot-load | + +* enable\_unseq\_space\_compaction + +| Name | enable\_unseq\_space\_compaction | +| :---------: |:-----------------------------------------------| +| Description | enable the compaction between unsequence files | +| Type | Boolean | +| Default | true | +| Effective | hot-load | + +* enable\_cross\_space\_compaction + +| Name | enable\_cross\_space\_compaction | +| :---------: |:------------------------------------------------------------------| +| Description | enable the compaction between sequence files and unsequence files | +| Type | Boolean | +| Default | true | +| Effective | hot-load | + +* cross\_selector + +|Name| cross\_selector | +|:---:|:-------------------------------------------------| +|Description| the task selector type of cross space compaction | +|Type| String | +|Default| rewrite | +|Effective| After restart system | + +* cross\_performer + +|Name| cross\_performer | +|:---:|:---------------------------------------------------| +|Description| the task performer type of cross space compaction. The options are read_point and fast, read_point is the default and fast is still under test | +|Type| String | +|Default| read\_point | +|Effective| After restart system | + +* inner\_seq\_selector + +|Name| inner\_seq\_selector | +|:---:|:----------------------------------------------------------| +|Description| the task selector type of inner sequence space compaction | +|Type| String | +|Default| size\_tiered | +|Effective| After restart system | + +* inner\_seq\_performer + +|Name| inner\_seq\_peformer | +|:---:|:--------------------------------------------------------------------------------------------------------------------------------------------------------| +|Description| the task performer type of inner sequence space compaction. The options are read_chunk and fast, read_chunk is the default and fast is still under test | +|Type| String | +|Default| read\_chunk | +|Effective| After restart system | + +* inner\_unseq\_selector + +|Name| inner\_unseq\_selector | +|:---:|:------------------------------------------------------------| +|Description| the task selector type of inner unsequence space compaction | +|Type| String | +|Default| size\_tiered | +|Effective| After restart system | + +* inner\_unseq\_performer + +|Name| inner\_unseq\_peformer | +|:---:|:--------------------------------------------------------------| +|Description| the task performer type of inner unsequence space compaction. The options are read_point and fast, read_point is the default and fast is still under test | +|Type| String | +|Default| read\_point | +|Effective| After restart system | + +* compaction\_priority + +| Name | compaction\_priority | +| :---------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Description | Priority of compaction task. When it is BALANCE, system executes all types of compaction equally; when it is INNER\_CROSS, system takes precedence over executing inner space compaction task; when it is CROSS\_INNER, system takes precedence over executing cross space compaction task | +| Type | String | +| Default | BALANCE | +| Effective | After restart system | + +* target\_compaction\_file\_size + +| Name | target\_compaction\_file\_size | +| :---------: |:-----------------------------------| +| Description | The target file size in compaction | +| Type | Int64 | +| Default | 2147483648 | +| Effective | hot-load | + +* target\_chunk\_size + +| Name | target\_chunk\_size | +| :---------: | :--------------------------------- | +| Description | The target size of compacted chunk | +| Type | Int64 | +| Default | 1048576 | +| Effective | After restart system | + +* target\_chunk\_point\_num + +|Name| target\_chunk\_point\_num | +|:---:|:---| +|Description| The target point number of compacted chunk | +|Type| int32 | +|Default| 100000 | +|Effective|After restart system| + +* chunk\_size\_lower\_bound\_in\_compaction + +| Name | chunk\_size\_lower\_bound\_in\_compaction | +| :---------: |:----------------------------------------------------------------------------------------| +| Description | A source chunk will be deserialized in compaction when its size is less than this value | +| Type | Int64 | +| Default | 10240 | +| Effective | After restart system | + +* chunk\_point\_num\_lower\_bound\_in\_compaction + +|Name| chunk\_point\_num\_lower\_bound\_in\_compaction | +|:---:|:---------------------------------------------------------------------------------------------| +|Description| A source chunk will be deserialized in compaction when its point num is less than this value | +|Type| int32 | +|Default| 1000 | +|Effective| After restart system | + +* max\_inner\_compaction\_candidate\_file\_num + +|Name| max\_inner\_compaction\_candidate\_file\_num | +|:---:|:---------------------------------------------------------| +|Description| The max num of files encounter in inner space compaction | +|Type| int32 | +|Default| 30 | +|Effective| hot-load | + +* max\_cross\_compaction\_file\_num + +|Name| max\_cross\_compaction\_candidate\_file\_num | +|:---:|:---------------------------------------------------------| +|Description| The max num of files encounter in cross space compaction | +|Type| int32 | +|Default| 500 | +|Effective| hot-load | + +* max\_cross\_compaction\_file\_size + +|Name| max\_cross\_compaction\_candidate\_file\_size | +|:---:|:----------------------------------------------------------| +|Description| The max size of files encounter in cross space compaction | +|Type| Int64 | +|Default| 5368709120 | +|Effective| hot-load | + +* compaction\_thread\_count + +|Name| compaction\_thread\_count | +|:---:|:---------------------------------| +|Description| thread num to execute compaction | +|Type| int32 | +|Default| 10 | +|Effective| hot-load | + +* compaction\_schedule\_interval\_in\_ms + +| Name | compaction\_schedule\_interval\_in\_ms | +| :---------: | :------------------------------------- | +| Description | interval of scheduling compaction | +| Type | Int64 | +| Default | 60000 | +| Effective | After restart system | + +* compaction\_write\_throughput\_mb\_per\_sec + +|Name| compaction\_write\_throughput\_mb\_per\_sec | +|:---:|:-----------------------------------------------| +|Description| The write rate of all compaction tasks in MB/s | +|Type| int32 | +|Default| 16 | +|Effective| hot-load | + +* compaction\_read\_throughput\_mb\_per\_sec + +|Name| compaction\_read\_throughput\_mb\_per\_sec | +|:---:|:------------------------------------------------| +|Description| The read rate of all compaction tasks in MB/s, values less than or equal to 0 means no limit | +|Type| int32 | +|Default| 0 | +|Effective| hot-load | + +* compaction\_read\_operation\_per\_sec + +|Name| compaction\_read\_operation\_per\_sec | +|:---:|:---------------------------------------------------------------------------------------------------------------| +|Description| The read operation of all compaction tasks can reach per second, values less than or equal to 0 means no limit | +|Type| int32 | +|Default| 0 | +|Effective| hot-load | + +* sub\_compaction\_thread\_count + +|Name| sub\_compaction\_thread\_count | +|:---:|:--------------------------------------------------------------------------| +|Description| the number of sub-compaction threads to accelerate cross space compaction | +|Type| Int32 | +|Default| 4 | +|Effective| hot-load | + +* enable\_tsfile\_validation + +| Name | enable\_tsfile\_validation | +|:-----------:|:--------------------------------------------------------------------------| +| Description | Verify that TSfiles generated by Flush, Load, and Compaction are correct. | +| Type | boolean | +| Default | false | +| Effective | hot-load | + +* candidate\_compaction\_task\_queue\_size + +|Name| candidate\_compaction\_task\_queue\_size | +|:---:|:--------------------------------------------| +|Description| The size of candidate compaction task queue | +|Type| Int32 | +|Default| 50 | +|Effective| After restart system | + +* compaction\_schedule\_thread\_num + +|Name| compaction\_schedule\_thread\_num | +|:---:|:--------------------------------------------------------------------------| +|Description| The number of threads to be set up to select compaction task. | +|Type| Int32 | +|Default| 4 | +|Effective| hot-load | + +### Write Ahead Log Configuration + +* wal\_mode + +| Name | wal\_mode | +|:-----------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | The write mode of wal. For DISABLE mode, the system will disable wal. For SYNC mode, the system will submit wal synchronously, write request will not return until its wal is fsynced to the disk successfully. For ASYNC mode, the system will submit wal asynchronously, write request will return immediately no matter its wal is fsynced to the disk successfully. | +| Type | String | +| Default | ASYNC | +| Effective | After restart system | + +* max\_wal\_nodes\_num + +| Name | max\_wal\_nodes\_num | +|:-----------:|:---------------------------------------------------------------------------------------------------------------------------------------| +| Description | Max number of wal nodes, each node corresponds to one wal directory. The default value 0 means the number is determined by the system. | +| Type | int32 | +| Default | 0 | +| Effective | After restart system | + +* wal\_async\_mode\_fsync\_delay\_in\_ms + +| Name | wal\_async\_mode\_fsync\_delay\_in\_ms | +|:-----------:|:--------------------------------------------------------------------------------| +| Description | Duration a wal flush operation will wait before calling fsync in the async mode | +| Type | int32 | +| Default | 1000 | +| Effective | hot-load | + +* wal\_sync\_mode\_fsync\_delay\_in\_ms + +| Name | wal\_sync\_mode\_fsync\_delay\_in\_ms | +|:-----------:|:-------------------------------------------------------------------------------| +| Description | Duration a wal flush operation will wait before calling fsync in the sync mode | +| Type | int32 | +| Default | 3 | +| Effective | hot-load | + +* wal\_buffer\_size\_in\_byte + +| Name | wal\_buffer\_size\_in\_byte | +|:-----------:|:-----------------------------| +| Description | Buffer size of each wal node | +| Type | int32 | +| Default | 33554432 | +| Effective | After restart system | + +* wal\_buffer\_queue\_capacity + +| Name | wal\_buffer\_queue\_capacity | +|:-----------:|:-------------------------------------------| +| Description | Blocking queue capacity of each wal buffer | +| Type | int32 | +| Default | 500 | +| Effective | After restart system | + +* wal\_file\_size\_threshold\_in\_byte + +| Name | wal\_file\_size\_threshold\_in\_byte | +|:-----------:|:-------------------------------------| +| Description | Size threshold of each wal file | +| Type | int32 | +| Default | 31457280 | +| Effective | hot-load | + +* wal\_min\_effective\_info\_ratio + +| Name | wal\_min\_effective\_info\_ratio | +|:-----------:|:----------------------------------------------------| +| Description | Minimum ratio of effective information in wal files | +| Type | double | +| Default | 0.1 | +| Effective | hot-load | + +* wal\_memtable\_snapshot\_threshold\_in\_byte + +| Name | wal\_memtable\_snapshot\_threshold\_in\_byte | +|:-----------:|:----------------------------------------------------------------| +| Description | MemTable size threshold for triggering MemTable snapshot in wal | +| Type | int64 | +| Default | 8388608 | +| Effective | hot-load | + +* max\_wal\_memtable\_snapshot\_num + +| Name | max\_wal\_memtable\_snapshot\_num | +|:-----------:|:--------------------------------------| +| Description | MemTable's max snapshot number in wal | +| Type | int32 | +| Default | 1 | +| Effective | hot-load | + +* delete\_wal\_files\_period\_in\_ms + +| Name | delete\_wal\_files\_period\_in\_ms | +|:-----------:|:------------------------------------------------------------| +| Description | The period when outdated wal files are periodically deleted | +| Type | int64 | +| Default | 20000 | +| Effective | hot-load | + +### TsFile Configurations + +* group\_size\_in\_byte + +|Name|group\_size\_in\_byte| +|:---:|:---| +|Description|The data size written to the disk per time| +|Type|int32| +|Default| 134217728 | +|Effective|hot-load| + +* page\_size\_in\_byte + +|Name| page\_size\_in\_byte | +|:---:|:---| +|Description|The maximum size of a single page written in memory when each column in memory is written (in bytes)| +|Type|int32| +|Default| 65536 | +|Effective|hot-load| + +* max\_number\_of\_points\_in\_page + +|Name| max\_number\_of\_points\_in\_page | +|:---:|:-----------------------------------------------------------------------------------| +|Description| The maximum number of data points (timestamps - valued groups) contained in a page | +|Type| int32 | +|Default| 10000 | +|Effective| hot-load | + +* pattern\_matching\_threshold + +|Name| pattern\_matching\_threshold | +|:---:|:-----------------------------------| +|Description| Max matching time of regex pattern | +|Type| int32 | +|Default| 1000000 | +|Effective| hot-load | + +* max\_degree\_of\_index\_node + +|Name| max\_degree\_of\_index\_node | +|:---:|:---| +|Description|The maximum degree of the metadata index tree (that is, the max number of each node's children)| +|Type|int32| +|Default| 256 | +|Effective|Only allowed to be modified in first start up| + +* max\_string\_length + +|Name| max\_string\_length | +|:---:|:---| +|Description|The maximum length of a single string (number of character)| +|Type|int32| +|Default| 128 | +|Effective|hot-load| + +* value\_encoder + +| Name | value\_encoder | +| :---------: | :------------------------------------ | +| Description | Encoding type of value column | +| Type | Enum String: “TS_2DIFF”,“PLAIN”,“RLE” | +| Default | PLAIN | +| Effective | hot-load | + +* float\_precision + +|Name| float\_precision | +|:---:|:---| +|Description| The precision of the floating point number.(The number of digits after the decimal point) | +|Type|int32| +|Default| The default is 2 digits. Note: The 32-bit floating point number has a decimal precision of 7 bits, and the 64-bit floating point number has a decimal precision of 15 bits. If the setting is out of the range, it will have no practical significance. | +|Effective|hot-load| + +* compressor + +| Name | compressor | +|:-----------:|:-----------------------------------------------------------------------| +| Description | Data compression method; Time compression method in aligned timeseries | +| Type | Enum String : "UNCOMPRESSED", "SNAPPY", "LZ4", "ZSTD", "LZMA2" | +| Default | SNAPPY | +| Effective | hot-load | + +* bloomFilterErrorRate + +| Name | bloomFilterErrorRate | +| :---------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Description | The false positive rate of bloom filter in each TsFile. Bloom filter checks whether a given time series is in the tsfile before loading metadata. This can improve the performance of loading metadata and skip the tsfile that doesn't contain specified time series. If you want to learn more about its mechanism, you can refer to: [wiki page of bloom filter](https://en.wikipedia.org/wiki/Bloom_filter). | +| Type | float, (0, 1) | +| Default | 0.05 | +| Effective | After restarting system | + + +### Authorization Configuration + +* authorizer\_provider\_class + +| Name | authorizer\_provider\_class | +| :--------------------: | :------------------------------------------------------ | +| Description | the class name of the authorization service | +| Type | String | +| Default | org.apache.iotdb.commons.auth.authorizer.LocalFileAuthorizer | +| Effective | After restarting system | +| Other available values | org.apache.iotdb.commons.auth.authorizer.OpenIdAuthorizer | + +* openID\_url + +| Name | openID\_url | +| :---------: | :----------------------------------------------- | +| Description | the openID server if OpenIdAuthorizer is enabled | +| Type | String (a http url) | +| Default | no | +| Effective | After restarting system | + +* iotdb\_server\_encrypt\_decrypt\_provider + +| Name | iotdb\_server\_encrypt\_decrypt\_provider | +| :---------: | :------------------------------------------------------------- | +| Description | The Class for user password encryption | +| Type | String | +| Default | org.apache.iotdb.commons.security.encrypt.MessageDigestEncrypt | +| Effective | Only allowed to be modified in first start up | + +* iotdb\_server\_encrypt\_decrypt\_provider\_parameter + +| Name | iotdb\_server\_encrypt\_decrypt\_provider\_parameter | +| :---------: | :--------------------------------------------------------------- | +| Description | Parameters used to initialize the user password encryption class | +| Type | String | +| Default | 空 | +| Effective | After restarting system | + +* author\_cache\_size + +| Name | author\_cache\_size | +| :---------: | :-------------------------- | +| Description | Cache size of user and role | +| Type | int32 | +| Default | 1000 | +| Effective | After restarting system | + +* author\_cache\_expire\_time + +| Name | author\_cache\_expire\_time | +| :---------: | :------------------------------------------------ | +| Description | Cache expire time of user and role, Unit: minutes | +| Type | int32 | +| Default | 30 | +| Effective | After restarting system | + +### UDF Configuration + +* udf\_initial\_byte\_array\_length\_for\_memory\_control + +| Name | udf\_initial\_byte\_array\_length\_for\_memory\_control | +| :---------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Description | Used to estimate the memory usage of text fields in a UDF query. It is recommended to set this value to be slightly larger than the average length of all texts. | +| Type | int32 | +| Default | 48 | +| Effective | After restarting system | + +* udf\_memory\_budget\_in\_mb + +| Name | udf\_memory\_budget\_in\_mb | +| :---------: | :--------------------------------------------------------------------------------------------------------- | +| Description | How much memory may be used in ONE UDF query (in MB). The upper limit is 20% of allocated memory for read. | +| Type | Float | +| Default | 30.0 | +| Effective | After restarting system | + +* udf\_reader\_transformer\_collector\_memory\_proportion + +| Name | udf\_reader\_transformer\_collector\_memory\_proportion | +| :---------: | :---------------------------------------------------------------------------------------------------------------------------------- | +| Description | UDF memory allocation ratio for reader, transformer and collector. The parameter form is a : b : c, where a, b, and c are integers. | +| Type | String | +| Default | 1:1:1 | +| Effective | After restarting system | + +* udf\_root\_dir + +| Name | udf\_root\_dir | +| :---------: | :------------------------ | +| Description | Root directory of UDF | +| Type | String | +| Default | ext/udf(Windows:ext\\udf) | +| Effective | After restarting system | + +* udf\_lib\_dir + +| Name | udf\_lib\_dir | +| :---------: | :--------------------------- | +| Description | UDF log and jar file dir | +| Type | String | +| Default | ext/udf(Windows:ext\\udf) | +| Effective | After restarting system | + +### Trigger Configuration + + +* trigger\_lib\_dir + +| Name | trigger\_lib\_dir | +| :---------: |:------------------------| +| Description | Trigger JAR file dir | +| Type | String | +| Default | ext/trigger | +| Effective | After restarting system | + +* stateful\_trigger\_retry\_num\_when\_not\_found + +| Name | stateful\_trigger\_retry\_num\_when\_not\_found | +| :---------: |:-----------------------------------------------------------------------------------| +| Description | How many times we will retry to found an instance of stateful trigger on DataNodes | +| Type | Int32 | +| Default | 3 | +| Effective | After restarting system | + + +### SELECT-INTO + +* into\_operation\_buffer\_size\_in\_byte + +| Name | into\_operation\_buffer\_size\_in\_byte | +| :---------: | :---------------------------------------------------------------------------------------------------------------------------------- | +| Description | When the select-into statement is executed, the maximum memory occupied by the data to be written (unit: Byte) | +| Type | int64 | +| Default | 100MB | +| Effective | hot-load | + + +* select\_into\_insert\_tablet\_plan\_row\_limit + +| Name | select\_into\_insert\_tablet\_plan\_row\_limit | +| :---------: | :---------------------------------------------------------------------------------------------------------------------------------- | +| Description | The maximum number of rows that can be processed in insert-tablet-plan when executing select-into statements. When <= 0, use 10000. | +| Type | int32 | +| Default | 10000 | +| Effective | hot-load | + +* into\_operation\_execution\_thread\_count + +| Name | into\_operation\_execution\_thread\_count | +| :---------: | :------------------------------------------------------------ | +| Description | The number of threads in the thread pool that execute insert-tablet tasks | +| Type | int32 | +| Default | 2 | +| Effective | After restarting system | + +### Continuous Query + +* continuous\_query\_execution\_thread + +| Name | continuous\_query\_execution\_thread | +| :---------: | :------------------------------------------------------------ | +| Description | How many threads will be set up to perform continuous queries | +| Type | int32 | +| Default | max(1, the / 2) | +| Effective | After restarting system | + +* continuous\_query\_min\_every\_interval + +| Name | continuous\_query\_min\_every\_interval | +| :---------: | :-------------------------------------------------- | +| Description | Minimum every interval to perform continuous query. | +| Type | duration | +| Default | 1s | +| Effective | After restarting system | + +### PIPE Configuration + +##### Version 1.3.0: + +* pipe_lib_dir + +| **Name** | **pipe_lib_dir** | +| ------------ | -------------------------- | +| Description | Directory for storing custom Pipe plugins | +| Type | string | +| Default Value | ext/pipe | +| Effective | Not currently supported for modification | + +* pipe_subtask_executor_max_thread_num + +| **Name** | **pipe_subtask_executor_max_thread_num** | +| ------------ | ------------------------------------------------------------ | +| Description | The maximum number of threads that can be used for processors and sinks in Pipe subtasks. The actual value will be the minimum of pipe_subtask_executor_max_thread_num and the maximum of 1 and half of the CPU core count. | +| Type | int | +| Default Value | 5 | +| Effective | After restarting system | + +* pipe_connector_timeout_ms + +| **Name** | **pipe_connector_timeout_ms** | +| ------------ | --------------------------------------------- | +| Description | The connection timeout for Thrift clients in milliseconds. | +| Type | int | +| Default Value | 900000 | +| Effective | After restarting system | + +* pipe_async_connector_selector_number + +| **Name** | **pipe_async_connector_selector_number** | +| ------------ | ------------------------------------------------------------ | +| Description | The maximum number of threads for processing execution results in the iotdb-thrift-async-connector plugin. | +| Type | int | +| Default Value | 1 | +| Effective | After restarting system | + +* pipe_async_connector_core_client_number + +| **Name** | **pipe_async_connector_core_client_number** | +| ------------ | ------------------------------------------------------------ | +| Description | The maximum number of clients that can be used in the iotdb-thrift-async-connector plugin. | +| Type | int | +| Default Value | 8 | +| Effective | After restarting system | + +* pipe_async_connector_max_client_number + +| **Name** | **pipe_async_connector_max_client_number** | +| ------------ | ------------------------------------------------------------ | +| Description | The maximum number of clients that can be used in the iotdb-thrift-async-connector plugin. | +| Type | int | +| Default Value | 16 | +| Effective | After restarting system | + +* pipe_air_gap_receiver_enabled + +| **Name** | **pipe_air_gap_receiver_enabled** | +| ------------ | ------------------------------------------------------------ | +| Description | Whether to enable receiving Pipe data through a gateway. The receiver can only return 0 or 1 in TCP mode to indicate whether the data was successfully received. | +| Type | Boolean | +| Default Value | false | +| Effective | After restarting system | + +* pipe_air_gap_receiver_enabled + +| **Name** | **pipe_air_gap_receiver_port** | +| ------------ | ------------------------------------ | +| Description | The port used by the server to receive Pipe data through a gateway. | +| Type | int | +| Default Value | 9780 | +| Effective | After restarting system | + +##### Version 1.3.1/2: + +* pipe_lib_dir + +| **Name** | **pipe_lib_dir** | +| ------------ | -------------------------- | +| Description | Directory for storing custom Pipe plugins | +| Type | string | +| Default Value | ext/pipe | +| Effective | Not currently supported for modification | + +* pipe_subtask_executor_max_thread_num + +| **Name** | **pipe_subtask_executor_max_thread_num** | +| ------------ | ------------------------------------------------------------ | +| Description | The maximum number of threads that can be used for processors and sinks in Pipe subtasks. The actual value will be the minimum of pipe_subtask_executor_max_thread_num and the maximum of 1 and half of the CPU core count. | +| Type | int | +| Default Value | 5 | +| Effective | After restarting system | + +* pipe_sink_timeout_ms + +| **Name** | **pipe_sink_timeout_ms** | +| ------------ | --------------------------------------------- | +| Description | The connection timeout for Thrift clients in milliseconds. | +| Type | int | +| Default Value | 900000 | +| Effective | After restarting system | + +* pipe_sink_selector_number + +| **Name** | **pipe_sink_selector_number** | +| ------------ | ------------------------------------------------------------ | +| Description | The maximum number of threads for processing execution results in the iotdb-thrift-async-sink plugin. It is recommended to set this value to be less than or equal to pipe_sink_max_client_number. | +| Type | int | +| Default Value | 4 | +| Effective | After restarting system | + +* pipe_sink_max_client_number + +| **Name** | **pipe_sink_max_client_number** | +| ------------ | ----------------------------------------------------------- | +| Description | The maximum number of clients that can be used in the iotdb-thrift-async-sink plugin. | +| Type | int | +| Default Value | 16 | +| Effective | After restarting system | + +* pipe_air_gap_receiver_enabled + +| **Name** | **pipe_air_gap_receiver_enabled** | +| ------------ | ------------------------------------------------------------ | +| Description | Whether to enable receiving Pipe data through a gateway. The receiver can only return 0 or 1 in TCP mode to indicate whether the data was successfully received. | +| Type | Boolean | +| Default Value | false | +| Effective | After restarting system | + +* pipe_air_gap_receiver_port + +| **Name** | **pipe_air_gap_receiver_port** | +| ------------ | ------------------------------------ | +| Description | The port used by the server to receive Pipe data through a gateway. | +| Type | int | +| Default Value | 9780 | +| Effective | After restarting system | + +### IOTConsensus Configuration + +* data_region_iot_max_log_entries_num_per_batch + +| Name | data_region_iot_max_log_entries_num_per_batch | +| :---------: | :------------------------------------------------ | +| Description | The maximum log entries num in IoTConsensus Batch | +| Type | int32 | +| Default | 1024 | +| Effective | After restarting system | + +* data_region_iot_max_size_per_batch + +| Name | data_region_iot_max_size_per_batch | +| :---------: | :------------------------------------- | +| Description | The maximum size in IoTConsensus Batch | +| Type | int32 | +| Default | 16MB | +| Effective | After restarting system | + +* data_region_iot_max_pending_batches_num + +| Name | data_region_iot_max_pending_batches_num | +| :---------: | :---------------------------------------------- | +| Description | The maximum pending batches num in IoTConsensus | +| Type | int32 | +| Default | 12 | +| Effective | After restarting system | + +* data_region_iot_max_memory_ratio_for_queue + +| Name | data_region_iot_max_memory_ratio_for_queue | +| :---------: | :------------------------------------------------- | +| Description | The maximum memory ratio for queue in IoTConsensus | +| Type | double | +| Default | 0.6 | +| Effective | After restarting system | + +### RatisConsensus Configuration + +* config\_node\_ratis\_log\_appender\_buffer\_size\_max + +| Name | config\_node\_ratis\_log\_appender\_buffer\_size\_max | +|:------:|:-----------------------------------------------| +| Description | confignode max payload size for a single log-sync-RPC from leader to follower | +| Type | int32 | +| Default | 4MB | +| Effective | After restarting system | + + +* schema\_region\_ratis\_log\_appender\_buffer\_size\_max + +| Name | schema\_region\_ratis\_log\_appender\_buffer\_size\_max | +|:------:|:-------------------------------------------------| +| Description | schema region max payload size for a single log-sync-RPC from leader to follower | +| Type | int32 | +| Default | 4MB | +| Effective | After restarting system | + +* data\_region\_ratis\_log\_appender\_buffer\_size\_max + +| Name | data\_region\_ratis\_log\_appender\_buffer\_size\_max | +|:------:|:-----------------------------------------------| +| Description | data region max payload size for a single log-sync-RPC from leader to follower | +| Type | int32 | +| Default | 4MB | +| Effective | After restarting system | + +* config\_node\_ratis\_snapshot\_trigger\_threshold + +| Name | config\_node\_ratis\_snapshot\_trigger\_threshold | +|:------:|:---------------------------------------------| +| Description | confignode trigger a snapshot when snapshot_trigger_threshold logs are written | +| Type | int32 | +| Default | 400,000 | +| Effective | After restarting system | + +* schema\_region\_ratis\_snapshot\_trigger\_threshold + +| Name | schema\_region\_ratis\_snapshot\_trigger\_threshold | +|:------:|:-----------------------------------------------| +| Description | schema region trigger a snapshot when snapshot_trigger_threshold logs are written | +| Type | int32 | +| Default | 400,000 | +| Effective | After restarting system | + +* data\_region\_ratis\_snapshot\_trigger\_threshold + +| Name | data\_region\_ratis\_snapshot\_trigger\_threshold | +|:------:|:---------------------------------------------| +| Description | data region trigger a snapshot when snapshot_trigger_threshold logs are written | +| Type | int32 | +| Default | 400,000 | +| Effective | After restarting system | + +* config\_node\_ratis\_log\_unsafe\_flush\_enable + +| Name | config\_node\_ratis\_log\_unsafe\_flush\_enable | +|:------:|:---------------------------------------------------| +| Description | confignode allows flushing Raft Log asynchronously | +| Type | boolean | +| Default | false | +| Effective | After restarting system | + +* schema\_region\_ratis\_log\_unsafe\_flush\_enable + +| Name | schema\_region\_ratis\_log\_unsafe\_flush\_enable | +|:------:|:------------------------------------------------------| +| Description | schema region allows flushing Raft Log asynchronously | +| Type | boolean | +| Default | false | +| Effective | After restarting system | + +* data\_region\_ratis\_log\_unsafe\_flush\_enable + +| Name | data\_region\_ratis\_log\_unsafe\_flush\_enable | +|:------:|:----------------------------------------------------| +| Description | data region allows flushing Raft Log asynchronously | +| Type | boolean | +| Default | false | +| Effective | After restarting system | + +* config\_node\_ratis\_log\_segment\_size\_max\_in\_byte + +| Name | config\_node\_ratis\_log\_segment\_size\_max\_in\_byte | +|:------:|:-----------------------------------------------| +| Description | confignode max capacity of a single Log segment file | +| Type | int32 | +| Default | 24MB | +| Effective | After restarting system | + +* schema\_region\_ratis\_log\_segment\_size\_max\_in\_byte + +| Name | schema\_region\_ratis\_log\_segment\_size\_max\_in\_byte | +|:------:|:-------------------------------------------------| +| Description | schema region max capacity of a single Log segment file | +| Type | int32 | +| Default | 24MB | +| Effective | After restarting system | + +* data\_region\_ratis\_log\_segment\_size\_max\_in\_byte + +| Name | data\_region\_ratis\_log\_segment\_size\_max\_in\_byte | +|:------:|:-----------------------------------------------| +| Description | data region max capacity of a single Log segment file | +| Type | int32 | +| Default | 24MB | +| Effective | After restarting system | + +* config\_node\_ratis\_grpc\_flow\_control\_window + +| Name | config\_node\_ratis\_grpc\_flow\_control\_window | +|:------:|:-----------------------------------------------------------------------------| +| Description | confignode flow control window for ratis grpc log appender | +| Type | int32 | +| Default | 4MB | +| Effective | After restarting system | + +* schema\_region\_ratis\_grpc\_flow\_control\_window + +| Name | schema\_region\_ratis\_grpc\_flow\_control\_window | +|:------:|:---------------------------------------------| +| Description | schema region flow control window for ratis grpc log appender | +| Type | int32 | +| Default | 4MB | +| Effective | After restarting system | + +* data\_region\_ratis\_grpc\_flow\_control\_window + +| Name | data\_region\_ratis\_grpc\_flow\_control\_window | +|:------:|:-------------------------------------------| +| Description | data region flow control window for ratis grpc log appender | +| Type | int32 | +| Default | 4MB | +| Effective | After restarting system | + +* config\_node\_ratis\_grpc\_leader\_outstanding\_appends\_max + +| Name | config\_node\_ratis\_grpc\_leader\_outstanding\_appends\_max | +| :---------: | :----------------------------------------------------- | +| Description | config node grpc pipeline concurrency threshold | +| Type | int32 | +| Default | 128 | +| Effective | After restarting system | + +* schema\_region\_ratis\_grpc\_leader\_outstanding\_appends\_max + +| Name | schema\_region\_ratis\_grpc\_leader\_outstanding\_appends\_max | +| :---------: | :------------------------------------------------------ | +| Description | schema region grpc pipeline concurrency threshold | +| Type | int32 | +| Default | 128 | +| Effective | After restarting system | + +* data\_region\_ratis\_grpc\_leader\_outstanding\_appends\_max + +| Name | data\_region\_ratis\_grpc\_leader\_outstanding\_appends\_max | +| :---------: | :---------------------------------------------------- | +| Description | data region grpc pipeline concurrency threshold | +| Type | int32 | +| Default | 128 | +| Effective | After restarting system | + +* config\_node\_ratis\_log\_force\_sync\_num + +| Name | config\_node\_ratis\_log\_force\_sync\_num | +| :---------: | :------------------------------------ | +| Description | config node fsync threshold | +| Type | int32 | +| Default | 128 | +| Effective | After restarting system | + +* schema\_region\_ratis\_log\_force\_sync\_num + +| Name | schema\_region\_ratis\_log\_force\_sync\_num | +| :---------: | :-------------------------------------- | +| Description | schema region fsync threshold | +| Type | int32 | +| Default | 128 | +| Effective | After restarting system | + +* data\_region\_ratis\_log\_force\_sync\_num + +| Name | data\_region\_ratis\_log\_force\_sync\_num | +| :---------: | :----------------------------------- | +| Description | data region fsync threshold | +| Type | int32 | +| Default | 128 | +| Effective | After restarting system | + +* config\_node\_ratis\_rpc\_leader\_election\_timeout\_min\_ms + +| Name | config\_node\_ratis\_rpc\_leader\_election\_timeout\_min\_ms | +|:------:|:-----------------------------------------------------| +| Description | confignode min election timeout for leader election | +| Type | int32 | +| Default | 2000ms | +| Effective | After restarting system | + +* schema\_region\_ratis\_rpc\_leader\_election\_timeout\_min\_ms + +| Name | schema\_region\_ratis\_rpc\_leader\_election\_timeout\_min\_ms | +|:------:|:-------------------------------------------------------| +| Description | schema region min election timeout for leader election | +| Type | int32 | +| Default | 2000ms | +| Effective | After restarting system | + +* data\_region\_ratis\_rpc\_leader\_election\_timeout\_min\_ms + +| Name | data\_region\_ratis\_rpc\_leader\_election\_timeout\_min\_ms | +|:------:|:-----------------------------------------------------| +| Description | data region min election timeout for leader election | +| Type | int32 | +| Default | 2000ms | +| Effective | After restarting system | + +* config\_node\_ratis\_rpc\_leader\_election\_timeout\_max\_ms + +| Name | config\_node\_ratis\_rpc\_leader\_election\_timeout\_max\_ms | +|:------:|:-----------------------------------------------------| +| Description | confignode max election timeout for leader election | +| Type | int32 | +| Default | 2000ms | +| Effective | After restarting system | + +* schema\_region\_ratis\_rpc\_leader\_election\_timeout\_max\_ms + +| Name | schema\_region\_ratis\_rpc\_leader\_election\_timeout\_max\_ms | +|:------:|:-------------------------------------------------------| +| Description | schema region max election timeout for leader election | +| Type | int32 | +| Default | 2000ms | +| Effective | After restarting system | + +* data\_region\_ratis\_rpc\_leader\_election\_timeout\_max\_ms + +| Name | data\_region\_ratis\_rpc\_leader\_election\_timeout\_max\_ms | +|:------:|:-----------------------------------------------------| +| Description | data region max election timeout for leader election | +| Type | int32 | +| Default | 2000ms | +| Effective | After restarting system | + +* config\_node\_ratis\_request\_timeout\_ms + +| Name | config\_node\_ratis\_request\_timeout\_ms | +|:------:|:-------------------------------------| +| Description | confignode ratis client retry threshold | +| Type | int32 | +| Default | 10s | +| Effective | After restarting system | + +* schema\_region\_ratis\_request\_timeout\_ms + +| Name | schema\_region\_ratis\_request\_timeout\_ms | +|:------:|:---------------------------------------| +| Description | schema region ratis client retry threshold | +| Type | int32 | +| Default | 10s | +| Effective | After restarting system | + +* data\_region\_ratis\_request\_timeout\_ms + +| Name | data\_region\_ratis\_request\_timeout\_ms | +|:------:|:-------------------------------------| +| Description | data region ratis client retry threshold | +| Type | int32 | +| Default | 10s | +| Effective | After restarting system | + +* config\_node\_ratis\_max\_retry\_attempts + +| Name | config\_node\_ratis\_max\_retry\_attempts | +|:------:|:-------------------------------------------| +| Description | confignode ratis client max retry attempts | +| Type | int32 | +| Default | 10 | +| Effective | After restarting system | + +* config\_node\_ratis\_initial\_sleep\_time\_ms + +| Name | config\_node\_ratis\_initial\_sleep\_time\_ms | +|:------:|:-------------------------------------------------| +| Description | confignode ratis client retry initial sleep time | +| Type | int32 | +| Default | 100ms | +| Effective | After restarting system | + +* config\_node\_ratis\_max\_sleep\_time\_ms + +| Name | config\_node\_ratis\_max\_sleep\_time\_ms | +|:------:|:---------------------------------------------| +| Description | confignode ratis client retry max sleep time | +| Type | int32 | +| Default | 10s | +| Effective | After restarting system | + +* schema\_region\_ratis\_max\_retry\_attempts + +| Name | schema\_region\_ratis\_max\_retry\_attempts | +|:------:|:---------------------------------------| +| Description | schema region ratis client max retry attempts | +| Type | int32 | +| Default | 10 | +| Effective | After restarting system | + +* schema\_region\_ratis\_initial\_sleep\_time\_ms + +| Name | schema\_region\_ratis\_initial\_sleep\_time\_ms | +|:------:|:------------------------------------------| +| Description | schema region ratis client retry initial sleep time | +| Type | int32 | +| Default | 100ms | +| Effective | After restarting system | + +* schema\_region\_ratis\_max\_sleep\_time\_ms + +| Name | schema\_region\_ratis\_max\_sleep\_time\_ms | +|:------:|:--------------------------------------| +| Description | schema region ratis client retry max sleep time | +| Type | int32 | +| Default | 10s | +| Effective | After restarting system | + +* data\_region\_ratis\_max\_retry\_attempts + +| Name | data\_region\_ratis\_max\_retry\_attempts | +|:------:|:-------------------------------------| +| Description | data region ratis client max retry attempts | +| Type | int32 | +| Default | 10 | +| Effective | After restarting system | + +* data\_region\_ratis\_initial\_sleep\_time\_ms + +| Name | data\_region\_ratis\_initial\_sleep\_time\_ms | +|:------:|:----------------------------------------| +| Description | data region ratis client retry initial sleep time | +| Type | int32 | +| Default | 100ms | +| Effective | After restarting system | + +* data\_region\_ratis\_max\_sleep\_time\_ms + +| Name | data\_region\_ratis\_max\_sleep\_time\_ms | +|:------:|:------------------------------------| +| Description | data region ratis client retry max sleep time | +| Type | int32 | +| Default | 10s | +| Effective | After restarting system | + +* config\_node\_ratis\_preserve\_logs\_num\_when\_purge + +| Name | config\_node\_ratis\_preserve\_logs\_num\_when\_purge | +|:------:|:---------------------------------------------------------------| +| Description | confignode preserves certain logs when take snapshot and purge | +| Type | int32 | +| Default | 1000 | +| Effective | After restarting system | + +* schema\_region\_ratis\_preserve\_logs\_num\_when\_purge + +| Name | schema\_region\_ratis\_preserve\_logs\_num\_when\_purge | +|:------:|:------------------------------------------------------------------| +| Description | schema region preserves certain logs when take snapshot and purge | +| Type | int32 | +| Default | 1000 | +| Effective | After restarting system | + +* data\_region\_ratis\_preserve\_logs\_num\_when\_purge + +| Name | data\_region\_ratis\_preserve\_logs\_num\_when\_purge | +|:------:|:----------------------------------------------------------------| +| Description | data region preserves certain logs when take snapshot and purge | +| Type | int32 | +| Default | 1000 | +| Effective | After restarting system | + +### Procedure Configuration + +* procedure\_core\_worker\_thread\_count + +| Name | procedure\_core\_worker\_thread\_count | +| :---------: | :--------------------------------- | +| Description | The number of worker thread count | +| Type | int32 | +| Default | 4 | +| Effective | After restarting system | + +* procedure\_completed\_clean\_interval + +| Name | procedure\_completed\_clean\_interval | +| :---------: | :--------------------------------------------------- | +| Description | Time interval of completed procedure cleaner work in | +| Type | int32 | +| Unit | second | +| Default | 30 | +| Effective | After restarting system | + +* procedure\_completed\_evict\_ttl + +| Name | procedure\_completed\_evict\_ttl | +| :---------: | :----------------------------- | +| Description | The ttl of completed procedure | +| Type | int32 | +| Unit | second | +| Default | 800 | +| Effective | After restarting system | + +### MQTT Broker Configuration + +* enable\_mqtt\_service + +| Name | enable\_mqtt\_service。 | +|:-----------:|:------------------------------------| +| Description | Whether to enable the MQTT service | +| Type | Boolean | +| Default | False | +| Effective | hot-load | + +* mqtt\_host + +| Name | mqtt\_host | +|:-----------:|:---------------------------------------------| +| Description | The host to which the MQTT service is bound | +| Type | String | +| Default | 0.0.0.0 | +| Effective | hot-load | + +* mqtt\_port + +| Name | mqtt\_port | +|:-----------:|:--------------------------------------------| +| Description | The port to which the MQTT service is bound | +| Type | int32 | +| Default | 1883 | +| Effective | hot-load | + +* mqtt\_handler\_pool\_size + +|Name| mqtt\_handler\_pool\_size | +|:---:|:------------------------------------------------------------| +|Description| The size of the handler pool used to process MQTT messages | +|Type| int32 | +|Default| 1 | +|Effective| hot-load | + +* mqtt\_payload\_formatter + +| Name | mqtt\_payload\_formatter | +|:-----------:|:-------------------------------| +| Description | MQTT message payload formatter | +| Type | String | +| Default | JSON | +| Effective | hot-load | + +* mqtt\_max\_message\_size + +| Name | mqtt\_max\_message\_size | +|:------:|:-----------------------------------------| +| Description | Maximum length of MQTT message in bytes | +| Type | int32 | +| Default | 1048576 | +| Effective | hot-load | + + diff --git a/src/UserGuide/V1.3.3/Reference/Common-Config-Manual.md b/src/UserGuide/V1.3.x/Reference/Common-Config-Manual.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/Common-Config-Manual.md rename to src/UserGuide/V1.3.x/Reference/Common-Config-Manual.md diff --git a/src/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual-old.md b/src/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual-old.md new file mode 100644 index 000000000..fb0b3b384 --- /dev/null +++ b/src/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual-old.md @@ -0,0 +1,223 @@ + + +# ConfigNode Configuration + +IoTDB ConfigNode files are under `conf`. + +* `confignode-env.sh/bat`:Environment configurations, in which we could set the memory allocation of ConfigNode. + +* `iotdb-confignode.properties`:IoTDB system configurations. + +## Environment Configuration File(confignode-env.sh/bat) + +The environment configuration file is mainly used to configure the Java environment related parameters when ConfigNode is running, such as JVM related configuration. This part of the configuration is passed to the JVM when the ConfigNode starts. + +The details of each parameter are as follows: + +* MEMORY\_SIZE + +|Name|MEMORY\_SIZE| +|:---:|:---| +|Description|The memory size that IoTDB ConfigNode will use when startup | +|Type|String| +|Default|The default is three-tenths of the memory, with a maximum of 16G.| +|Effective|After restarting system| + +* ON\_HEAP\_MEMORY + +|Name|ON\_HEAP\_MEMORY| +|:---:|:---| +|Description|The heap memory size that IoTDB ConfigNode can use, Former Name: MAX\_HEAP\_SIZE | +|Type|String| +|Default| Calculate based on MEMORY\_SIZE.| +|Effective|After restarting system| + +* OFF\_HEAP\_MEMORY + +|Name|OFF\_HEAP\_MEMORY| +|:---:|:---| +|Description|The direct memory that IoTDB ConfigNode can use, Former Name: MAX\_DIRECT\_MEMORY\_SIZE | +|Type|String| +|Default| Calculate based on MEMORY\_SIZE.| +|Effective|After restarting system| + + +## ConfigNode Configuration File (iotdb-confignode.properties) + +The global configuration of cluster is in ConfigNode. + +### Config Node RPC Configuration + +* cn\_internal\_address + +| Name | cn\_internal\_address | +|:-----------:|:------------------------------------| +| Description | ConfigNode internal service address | +| Type | String | +| Default | 127.0.0.1 | +| Effective | Only allowed to be modified in first start up | + +* cn\_internal\_port + +|Name| cn\_internal\_port | +|:---:|:---| +|Description| ConfigNode internal service port| +|Type| Short Int : [0,65535] | +|Default| 10710 | +|Effective|Only allowed to be modified in first start up| + +### Consensus + +* cn\_consensus\_port + +|Name| cn\_consensus\_port | +|:---:|:---| +|Description| ConfigNode data Consensus Port | +|Type| Short Int : [0,65535] | +|Default| 10720 | +|Effective|Only allowed to be modified in first start up| + +### Target Config Nodes + +* cn\_seed\_config\_node + +|Name| cn\_seed\_config\_node | +|:---:|:----------------------------------------------------------------------| +|Description| Target ConfigNode address, for current ConfigNode to join the cluster | +|Type| String | +|Default| 127.0.0.1:10710 | +|Effective| Only allowed to be modified in first start up | + +### Directory configuration + +* cn\_system\_dir + +|Name| cn\_system\_dir | +|:---:|:---| +|Description| ConfigNode system data dir | +|Type| String | +|Default| data/system(Windows:data\\system) | +|Effective|After restarting system| + +* cn\_consensus\_dir + +|Name| cn\_consensus\_dir | +|:---:|:---------------------------------------------------------------| +|Description| ConfigNode Consensus protocol data dir | +|Type| String | +|Default| data/confignode/consensus(Windows:data\\confignode\\consensus) | +|Effective| After restarting system | + +### Thrift RPC configuration + +* cn\_rpc\_thrift\_compression\_enable + +|Name| cn\_rpc\_thrift\_compression\_enable | +|:---:|:---| +|Description| Whether enable thrift's compression (using GZIP).| +|Type|Boolean| +|Default| false | +|Effective|After restarting system| + +* cn\_rpc\_thrift\_compression\_enable + +|Name| cn\_rpc\_thrift\_compression\_enable | +|:---:|:---| +|Description| Whether enable thrift's compression (using GZIP).| +|Type|Boolean| +|Default| false | +|Effective|After restarting system| + +* cn\_rpc\_advanced\_compression\_enable + +|Name| cn\_rpc\_advanced\_compression\_enable | +|:---:|:---| +|Description| Whether enable thrift's advanced compression.| +|Type|Boolean| +|Default| false | +|Effective|After restarting system| + +* cn\_rpc\_max\_concurrent\_client\_num + +|Name| cn\_rpc\_max\_concurrent\_client\_num | +|:---:|:---| +|Description| Max concurrent rpc connections| +|Type| Short Int : [0,65535] | +|Description| 65535 | +|Effective|After restarting system| + +* cn\_thrift\_max\_frame\_size + +|Name| cn\_thrift\_max\_frame\_size | +|:---:|:---| +|Description| Max size of bytes of each thrift RPC request/response| +|Type| Long | +|Unit|Byte| +|Default| 536870912 | +|Effective|After restarting system| + +* cn\_thrift\_init\_buffer\_size + +|Name| cn\_thrift\_init\_buffer\_size | +|:---:|:---| +|Description| Initial size of bytes of buffer that thrift used | +|Type| long | +|Default| 1024 | +|Effective|After restarting system| + +* cn\_connection\_timeout\_ms + +| Name | cn\_connection\_timeout\_ms | +|:-----------:|:-------------------------------------------------------| +| Description | Thrift socket and connection timeout between nodes | +| Type | int | +| Default | 60000 | +| Effective | After restarting system | + +* cn\_selector\_thread\_nums\_of\_client\_manager + +| Name | cn\_selector\_thread\_nums\_of\_client\_manager | +|:-----------:|:-------------------------------------------------------------------------------| +| Description | selector thread (TAsyncClientManager) nums for async thread in a clientManager | +| Type | int | +| Default | 1 | +| Effective | After restarting system | + +* cn\_core\_client\_count\_for\_each\_node\_in\_client\_manager + +| Name | cn\_core\_client\_count\_for\_each\_node\_in\_client\_manager | +|:------------:|:---------------------------------------------------------------| +| Description | Number of core clients routed to each node in a ClientManager | +| Type | int | +| Default | 200 | +| Effective | After restarting system | + +* cn\_max\_client\_count\_for\_each\_node\_in\_client\_manager + +| Name | cn\_max\_client\_count\_for\_each\_node\_in\_client\_manager | +|:--------------:|:-------------------------------------------------------------| +| Description | Number of max clients routed to each node in a ClientManager | +| Type | int | +| Default | 300 | +| Effective | After restarting system | + +### Metric Configuration diff --git a/src/UserGuide/V1.3.3/Reference/ConfigNode-Config-Manual.md b/src/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/ConfigNode-Config-Manual.md rename to src/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual.md diff --git a/src/UserGuide/V1.3.3/Reference/DataNode-Config-Manual.md b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/DataNode-Config-Manual.md rename to src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old.md diff --git a/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_apache.md b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_apache.md new file mode 100644 index 000000000..ea3f63288 --- /dev/null +++ b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_apache.md @@ -0,0 +1,500 @@ + + +# DataNode Configuration Parameters + +We use the same configuration files for IoTDB DataNode and Standalone version, all under the `conf`. + +* `datanode-env.sh/bat`:Environment configurations, in which we could set the memory allocation of DataNode and Standalone. + +* `iotdb-datanode.properties`:IoTDB system configurations. + +## Hot Modification Configuration + +For the convenience of users, IoTDB provides users with hot modification function, that is, modifying some configuration parameters in `iotdb-datanode.properties` during the system operation and applying them to the system immediately. +In the parameters described below, these parameters whose way of `Effective` is `hot-load` support hot modification. + +Trigger way: The client sends the command(sql) `load configuration` or `set configuration` to the IoTDB server. + +## Environment Configuration File(datanode-env.sh/bat) + +The environment configuration file is mainly used to configure the Java environment related parameters when DataNode is running, such as JVM related configuration. This part of the configuration is passed to the JVM when the DataNode starts. + +The details of each parameter are as follows: + +* MEMORY\_SIZE + +|Name|MEMORY\_SIZE| +|:---:|:---| +|Description|The minimum heap memory size that IoTDB DataNode will use when startup | +|Type|String| +|Default| The default is a half of the memory.| +|Effective|After restarting system| + +* ON\_HEAP\_MEMORY + +|Name|ON\_HEAP\_MEMORY| +|:---:|:---| +|Description|The heap memory size that IoTDB DataNode can use, Former Name: MAX\_HEAP\_SIZE | +|Type|String| +|Default| Calculate based on MEMORY\_SIZE.| +|Effective|After restarting system| + +* OFF\_HEAP\_MEMORY + +|Name|OFF\_HEAP\_MEMORY| +|:---:|:---| +|Description|The direct memory that IoTDB DataNode can use, Former Name: MAX\_DIRECT\_MEMORY\_SIZE| +|Type|String| +|Default| Calculate based on MEMORY\_SIZE.| +|Effective|After restarting system| + +* JMX\_LOCAL + +|Name|JMX\_LOCAL| +|:---:|:---| +|Description|JMX monitoring mode, configured as yes to allow only local monitoring, no to allow remote monitoring| +|Type|Enum String: "true", "false"| +|Default|true| +|Effective|After restarting system| + +* JMX\_PORT + +|Name|JMX\_PORT| +|:---:|:---| +|Description|JMX listening port. Please confirm that the port is not a system reserved port and is not occupied| +|Type|Short Int: [0,65535]| +|Default|31999| +|Effective|After restarting system| + +* JMX\_IP + +|Name|JMX\_IP| +|:---:|:---| +|Description|JMX listening address. Only take effect if JMX\_LOCAL=false. 0.0.0.0 is never allowed| +|Type|String| +|Default|127.0.0.1| +|Effective|After restarting system| + +## JMX Authorization + +We **STRONGLY RECOMMENDED** you CHANGE the PASSWORD for the JMX remote connection. + +The user and passwords are in ${IOTDB\_CONF}/conf/jmx.password. + +The permission definitions are in ${IOTDB\_CONF}/conf/jmx.access. + +## DataNode/Standalone Configuration File (iotdb-datanode.properties) + +### Data Node RPC Configuration + +* dn\_rpc\_address + +|Name| dn\_rpc\_address | +|:---:|:-----------------------------------------------| +|Description| The client rpc service listens on the address. | +|Type| String | +|Default| 0.0.0.0 | +|Effective| After restarting system | + +* dn\_rpc\_port + +|Name| dn\_rpc\_port | +|:---:|:---| +|Description| The client rpc service listens on the port.| +|Type|Short Int : [0,65535]| +|Default| 6667 | +|Effective|After restarting system| + +* dn\_internal\_address + +|Name| dn\_internal\_address | +|:---:|:---| +|Description| DataNode internal service host/IP | +|Type| string | +|Default| 127.0.0.1 | +|Effective|Only allowed to be modified in first start up| + +* dn\_internal\_port + +|Name| dn\_internal\_port | +|:---:|:-------------------------------| +|Description| DataNode internal service port | +|Type| int | +|Default| 10730 | +|Effective| Only allowed to be modified in first start up | + +* dn\_mpp\_data\_exchange\_port + +|Name| mpp\_data\_exchange\_port | +|:---:|:---| +|Description| MPP data exchange port | +|Type| int | +|Default| 10740 | +|Effective|Only allowed to be modified in first start up| + +* dn\_schema\_region\_consensus\_port + +|Name| dn\_schema\_region\_consensus\_port | +|:---:|:---| +|Description| DataNode Schema replica communication port for consensus | +|Type| int | +|Default| 10750 | +|Effective|Only allowed to be modified in first start up| + +* dn\_data\_region\_consensus\_port + +|Name| dn\_data\_region\_consensus\_port | +|:---:|:---| +|Description| DataNode Data replica communication port for consensus | +|Type| int | +|Default| 10760 | +|Effective|Only allowed to be modified in first start up| + +* dn\_join\_cluster\_retry\_interval\_ms + +|Name| dn\_join\_cluster\_retry\_interval\_ms | +|:---:|:--------------------------------------------------------------------------| +|Description| The time of data node waiting for the next retry to join into the cluster | +|Type| long | +|Default| 5000 | +|Effective| After restarting system | + +### SSL Configuration + +* enable\_thrift\_ssl + +|Name| enable\_thrift\_ssl | +|:---:|:---------------------------| +|Description|When enable\_thrift\_ssl is configured as true, SSL encryption will be used for communication through dn\_rpc\_port | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* enable\_https + +|Name| enable\_https | +|:---:|:-------------------------| +|Description| REST Service Specifies whether to enable SSL configuration | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* key\_store\_path + +|Name| key\_store\_path | +|:---:|:-----------------| +|Description| SSL certificate path | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +* key\_store\_pwd + +|Name| key\_store\_pwd | +|:---:|:----------------| +|Description| SSL certificate password | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +### Target Config Nodes + +* dn\_seed\_config\_node + +|Name| dn\_seed\_config\_node | +|:---:|:------------------------------------------------| +|Description| ConfigNode Address for DataNode to join cluster | +|Type| String | +|Default| 127.0.0.1:10710 | +|Effective| Only allowed to be modified in first start up | + +### Connection Configuration + +* dn\_rpc\_thrift\_compression\_enable + +|Name| dn\_rpc\_thrift\_compression\_enable | +|:---:|:---| +|Description| Whether enable thrift's compression (using GZIP).| +|Type|Boolean| +|Default| false | +|Effective|After restarting system| + +* dn\_rpc\_advanced\_compression\_enable + +|Name| dn\_rpc\_advanced\_compression\_enable | +|:---:|:---| +|Description| Whether enable thrift's advanced compression.| +|Type|Boolean| +|Default| false | +|Effective|After restarting system| + +* dn\_rpc\_selector\_thread\_count + +|Name| dn\_rpc\_selector\_thread\_count | +|:---:|:-----------------------------------| +|Description| The number of rpc selector thread. | +|Type| int | +|Default| false | +|Effective| After restarting system | + +* dn\_rpc\_min\_concurrent\_client\_num + +|Name| dn\_rpc\_min\_concurrent\_client\_num | +|:---:|:-----------------------------------| +|Description| Minimum concurrent rpc connections | +|Type| Short Int : [0,65535] | +|Description| 1 | +|Effective| After restarting system | + +* dn\_rpc\_max\_concurrent\_client\_num + +|Name| dn\_rpc\_max\_concurrent\_client\_num | +|:---:|:---| +|Description| Max concurrent rpc connections| +|Type| Short Int : [0,65535] | +|Description| 65535 | +|Effective|After restarting system| + +* dn\_thrift\_max\_frame\_size + +|Name| dn\_thrift\_max\_frame\_size | +|:---:|:---| +|Description| Max size of bytes of each thrift RPC request/response| +|Type| Long | +|Unit|Byte| +|Default| 536870912 | +|Effective|After restarting system| + +* dn\_thrift\_init\_buffer\_size + +|Name| dn\_thrift\_init\_buffer\_size | +|:---:|:---| +|Description| Initial size of bytes of buffer that thrift used | +|Type| long | +|Default| 1024 | +|Effective|After restarting system| + +* dn\_connection\_timeout\_ms + +| Name | dn\_connection\_timeout\_ms | +|:-----------:|:---------------------------------------------------| +| Description | Thrift socket and connection timeout between nodes | +| Type | int | +| Default | 60000 | +| Effective | After restarting system | + +* dn\_core\_client\_count\_for\_each\_node\_in\_client\_manager + +| Name | dn\_core\_client\_count\_for\_each\_node\_in\_client\_manager | +|:------------:|:--------------------------------------------------------------| +| Description | Number of core clients routed to each node in a ClientManager | +| Type | int | +| Default | 200 | +| Effective | After restarting system | + +* dn\_max\_client\_count\_for\_each\_node\_in\_client\_manager + +| Name | dn\_max\_client\_count\_for\_each\_node\_in\_client\_manager | +|:--------------:|:-------------------------------------------------------------| +| Description | Number of max clients routed to each node in a ClientManager | +| Type | int | +| Default | 300 | +| Effective | After restarting system | + +### Dictionary Configuration + +* dn\_system\_dir + +| Name | dn\_system\_dir | +|:-----------:|:----------------------------------------------------------------------------| +| Description | The directories of system files. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/system (Windows: data\\datanode\\system) | +| Effective | After restarting system | + +* dn\_data\_dirs + +| Name | dn\_data\_dirs | +|:-----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | The directories of data files. Multiple directories are separated by comma. The starting directory of the relative path is related to the operating system. It is recommended to use an absolute path. If the path does not exist, the system will automatically create it. | +| Type | String[] | +| Default | data/datanode/data (Windows: data\\datanode\\data) | +| Effective | After restarting system | + +* dn\_multi\_dir\_strategy + +| Name | dn\_multi\_dir\_strategy | +|:-----------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | IoTDB's strategy for selecting directories for TsFile in tsfile_dir. You can use a simple class name or a full name of the class. The system provides the following three strategies:
1. SequenceStrategy: IoTDB selects the directory from tsfile\_dir in order, traverses all the directories in tsfile\_dir in turn, and keeps counting;
2. MaxDiskUsableSpaceFirstStrategy: IoTDB first selects the directory with the largest free disk space in tsfile\_dir;
You can complete a user-defined policy in the following ways:
1. Inherit the org.apache.iotdb.db.storageengine.rescon.disk.strategy.DirectoryStrategy class and implement its own Strategy method;
2. Fill in the configuration class with the full class name of the implemented class (package name plus class name, UserDfineStrategyPackage);
3. Add the jar file to the project. | +| Type | String | +| Default | SequenceStrategy | +| Effective | hot-load | + +* dn\_consensus\_dir + +| Name | dn\_consensus\_dir | +|:-----------:|:-------------------------------------------------------------------------------| +| Description | The directories of consensus files. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/consensus | +| Effective | After restarting system | + +* dn\_wal\_dirs + +| Name | dn\_wal\_dirs | +|:-----------:|:-------------------------------------------------------------------------| +| Description | Write Ahead Log storage path. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/wal | +| Effective | After restarting system | + +* dn\_tracing\_dir + +| Name | dn\_tracing\_dir | +|:-----------:|:----------------------------------------------------------------------------| +| Description | The tracing root directory path. It is recommended to use an absolute path. | +| Type | String | +| Default | datanode/tracing | +| Effective | After restarting system | + +* dn\_sync\_dir + +| Name | dn\_sync\_dir | +|:-----------:|:--------------------------------------------------------------------------| +| Description | The directories of sync files. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/sync | +| Effective | After restarting system | + +### Metric Configuration + +## Enable GC log + +GC log is off by default. +For performance tuning, you may want to collect the GC info. + +To enable GC log, just add a parameter "printgc" when you start the DataNode. + +```bash +nohup sbin/start-datanode.sh printgc >/dev/null 2>&1 & +``` +Or +```cmd +sbin\start-datanode.bat printgc +``` + +GC log is stored at `IOTDB_HOME/logs/gc.log`. +There will be at most 10 gc.log.* files and each one can reach to 10MB. + +### REST Service Configuration + +* enable\_rest\_service + +|Name| enable\_rest\_service | +|:---:|:--------------------------------------| +|Description| Whether to enable the Rest service | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* rest\_service\_port + +|Name| rest\_service\_port | +|:---:|:------------------| +|Description| The Rest service listens to the port number | +|Type| int32 | +|Default| 18080 | +|Effective| After restarting system | + +* enable\_swagger + +|Name| enable\_swagger | +|:---:|:-----------------------| +|Description| Whether to enable swagger to display rest interface information | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* rest\_query\_default\_row\_size\_limit + +|Name| rest\_query\_default\_row\_size\_limit | +|:---:|:------------------------------------------------------------------------------------------| +|Description| The maximum number of rows in a result set that can be returned by a query | +|Type| int32 | +|Default| 10000 | +|Effective| After restarting system | + +* cache\_expire + +|Name| cache\_expire | +|:---:|:--------------------------------------------------------| +|Description| Expiration time for caching customer login information | +|Type| int32 | +|Default| 28800 | +|Effective| After restarting system | + +* cache\_max\_num + +|Name| cache\_max\_num | +|:---:|:--------------| +|Description| The maximum number of users stored in the cache | +|Type| int32 | +|Default| 100 | +|Effective| After restarting system | + +* cache\_init\_num + +|Name| cache\_init\_num | +|:---:|:---------------| +|Description| Initial cache capacity | +|Type| int32 | +|Default| 10 | +|Effective| After restarting system | + + +* trust\_store\_path + +|Name| trust\_store\_path | +|:---:|:---------------| +|Description| keyStore Password (optional) | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +* trust\_store\_pwd + +|Name| trust\_store\_pwd | +|:---:|:---------------------------------| +|Description| trustStore Password (Optional) | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +* idle\_timeout + +|Name| idle\_timeout | +|:---:|:--------------| +|Description| SSL timeout duration, expressed in seconds | +|Type| int32 | +|Default| 5000 | +|Effective| After restarting system | + diff --git a/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_timecho.md b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_timecho.md new file mode 100644 index 000000000..9b2164402 --- /dev/null +++ b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_timecho.md @@ -0,0 +1,592 @@ + + +# DataNode Configuration Parameters + +We use the same configuration files for IoTDB DataNode and Standalone version, all under the `conf`. + +* `datanode-env.sh/bat`:Environment configurations, in which we could set the memory allocation of DataNode and Standalone. + +* `iotdb-datanode.properties`:IoTDB system configurations. + +## Hot Modification Configuration + +For the convenience of users, IoTDB provides users with hot modification function, that is, modifying some configuration parameters in `iotdb-datanode.properties` during the system operation and applying them to the system immediately. +In the parameters described below, these parameters whose way of `Effective` is `hot-load` support hot modification. + +Trigger way: The client sends the command(sql) `load configuration` or `set configuration` to the IoTDB server. + +## Environment Configuration File(datanode-env.sh/bat) + +The environment configuration file is mainly used to configure the Java environment related parameters when DataNode is running, such as JVM related configuration. This part of the configuration is passed to the JVM when the DataNode starts. + +The details of each parameter are as follows: + +* MEMORY\_SIZE + +|Name|MEMORY\_SIZE| +|:---:|:---| +|Description|The minimum heap memory size that IoTDB DataNode will use when startup | +|Type|String| +|Default| The default is a half of the memory.| +|Effective|After restarting system| + +* ON\_HEAP\_MEMORY + +|Name|ON\_HEAP\_MEMORY| +|:---:|:---| +|Description|The heap memory size that IoTDB DataNode can use, Former Name: MAX\_HEAP\_SIZE | +|Type|String| +|Default| Calculate based on MEMORY\_SIZE.| +|Effective|After restarting system| + +* OFF\_HEAP\_MEMORY + +|Name|OFF\_HEAP\_MEMORY| +|:---:|:---| +|Description|The direct memory that IoTDB DataNode can use, Former Name: MAX\_DIRECT\_MEMORY\_SIZE| +|Type|String| +|Default| Calculate based on MEMORY\_SIZE.| +|Effective|After restarting system| + +* JMX\_LOCAL + +|Name|JMX\_LOCAL| +|:---:|:---| +|Description|JMX monitoring mode, configured as yes to allow only local monitoring, no to allow remote monitoring| +|Type|Enum String: "true", "false"| +|Default|true| +|Effective|After restarting system| + +* JMX\_PORT + +|Name|JMX\_PORT| +|:---:|:---| +|Description|JMX listening port. Please confirm that the port is not a system reserved port and is not occupied| +|Type|Short Int: [0,65535]| +|Default|31999| +|Effective|After restarting system| + +* JMX\_IP + +|Name|JMX\_IP| +|:---:|:---| +|Description|JMX listening address. Only take effect if JMX\_LOCAL=false. 0.0.0.0 is never allowed| +|Type|String| +|Default|127.0.0.1| +|Effective|After restarting system| + +## JMX Authorization + +We **STRONGLY RECOMMENDED** you CHANGE the PASSWORD for the JMX remote connection. + +The user and passwords are in ${IOTDB\_CONF}/conf/jmx.password. + +The permission definitions are in ${IOTDB\_CONF}/conf/jmx.access. + +## DataNode/Standalone Configuration File (iotdb-datanode.properties) + +### Data Node RPC Configuration + +* dn\_rpc\_address + +|Name| dn\_rpc\_address | +|:---:|:-----------------------------------------------| +|Description| The client rpc service listens on the address. | +|Type| String | +|Default| 0.0.0.0 | +|Effective| After restarting system | + +* dn\_rpc\_port + +|Name| dn\_rpc\_port | +|:---:|:---| +|Description| The client rpc service listens on the port.| +|Type|Short Int : [0,65535]| +|Default| 6667 | +|Effective|After restarting system| + +* dn\_internal\_address + +|Name| dn\_internal\_address | +|:---:|:---| +|Description| DataNode internal service host/IP | +|Type| string | +|Default| 127.0.0.1 | +|Effective|Only allowed to be modified in first start up| + +* dn\_internal\_port + +|Name| dn\_internal\_port | +|:---:|:-------------------------------| +|Description| DataNode internal service port | +|Type| int | +|Default| 10730 | +|Effective| Only allowed to be modified in first start up | + +* dn\_mpp\_data\_exchange\_port + +|Name| mpp\_data\_exchange\_port | +|:---:|:---| +|Description| MPP data exchange port | +|Type| int | +|Default| 10740 | +|Effective|Only allowed to be modified in first start up| + +* dn\_schema\_region\_consensus\_port + +|Name| dn\_schema\_region\_consensus\_port | +|:---:|:---| +|Description| DataNode Schema replica communication port for consensus | +|Type| int | +|Default| 10750 | +|Effective|Only allowed to be modified in first start up| + +* dn\_data\_region\_consensus\_port + +|Name| dn\_data\_region\_consensus\_port | +|:---:|:---| +|Description| DataNode Data replica communication port for consensus | +|Type| int | +|Default| 10760 | +|Effective|Only allowed to be modified in first start up| + +* dn\_join\_cluster\_retry\_interval\_ms + +|Name| dn\_join\_cluster\_retry\_interval\_ms | +|:---:|:--------------------------------------------------------------------------| +|Description| The time of data node waiting for the next retry to join into the cluster | +|Type| long | +|Default| 5000 | +|Effective| After restarting system | + +### SSL Configuration + +* enable\_thrift\_ssl + +|Name| enable\_thrift\_ssl | +|:---:|:---------------------------| +|Description|When enable\_thrift\_ssl is configured as true, SSL encryption will be used for communication through dn\_rpc\_port | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* enable\_https + +|Name| enable\_https | +|:---:|:-------------------------| +|Description| REST Service Specifies whether to enable SSL configuration | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* key\_store\_path + +|Name| key\_store\_path | +|:---:|:-----------------| +|Description| SSL certificate path | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +* key\_store\_pwd + +|Name| key\_store\_pwd | +|:---:|:----------------| +|Description| SSL certificate password | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +### Target Config Nodes + +* dn\_seed\_config\_node + +|Name| dn\_seed\_config\_node | +|:---:|:------------------------------------------------| +|Description| ConfigNode Address for DataNode to join cluster | +|Type| String | +|Default| 127.0.0.1:10710 | +|Effective| Only allowed to be modified in first start up | + +### Connection Configuration + +* dn\_rpc\_thrift\_compression\_enable + +|Name| dn\_rpc\_thrift\_compression\_enable | +|:---:|:---| +|Description| Whether enable thrift's compression (using GZIP).| +|Type|Boolean| +|Default| false | +|Effective|After restarting system| + +* dn\_rpc\_advanced\_compression\_enable + +|Name| dn\_rpc\_advanced\_compression\_enable | +|:---:|:---| +|Description| Whether enable thrift's advanced compression.| +|Type|Boolean| +|Default| false | +|Effective|After restarting system| + +* dn\_rpc\_selector\_thread\_count + +|Name| dn\_rpc\_selector\_thread\_count | +|:---:|:-----------------------------------| +|Description| The number of rpc selector thread. | +|Type| int | +|Default| false | +|Effective| After restarting system | + +* dn\_rpc\_min\_concurrent\_client\_num + +|Name| dn\_rpc\_min\_concurrent\_client\_num | +|:---:|:-----------------------------------| +|Description| Minimum concurrent rpc connections | +|Type| Short Int : [0,65535] | +|Description| 1 | +|Effective| After restarting system | + +* dn\_rpc\_max\_concurrent\_client\_num + +|Name| dn\_rpc\_max\_concurrent\_client\_num | +|:---:|:---| +|Description| Max concurrent rpc connections| +|Type| Short Int : [0,65535] | +|Description| 65535 | +|Effective|After restarting system| + +* dn\_thrift\_max\_frame\_size + +|Name| dn\_thrift\_max\_frame\_size | +|:---:|:---| +|Description| Max size of bytes of each thrift RPC request/response| +|Type| Long | +|Unit|Byte| +|Default| 536870912 | +|Effective|After restarting system| + +* dn\_thrift\_init\_buffer\_size + +|Name| dn\_thrift\_init\_buffer\_size | +|:---:|:---| +|Description| Initial size of bytes of buffer that thrift used | +|Type| long | +|Default| 1024 | +|Effective|After restarting system| + +* dn\_connection\_timeout\_ms + +| Name | dn\_connection\_timeout\_ms | +|:-----------:|:---------------------------------------------------| +| Description | Thrift socket and connection timeout between nodes | +| Type | int | +| Default | 60000 | +| Effective | After restarting system | + +* dn\_core\_client\_count\_for\_each\_node\_in\_client\_manager + +| Name | dn\_core\_client\_count\_for\_each\_node\_in\_client\_manager | +|:------------:|:--------------------------------------------------------------| +| Description | Number of core clients routed to each node in a ClientManager | +| Type | int | +| Default | 200 | +| Effective | After restarting system | + +* dn\_max\_client\_count\_for\_each\_node\_in\_client\_manager + +| Name | dn\_max\_client\_count\_for\_each\_node\_in\_client\_manager | +|:--------------:|:-------------------------------------------------------------| +| Description | Number of max clients routed to each node in a ClientManager | +| Type | int | +| Default | 300 | +| Effective | After restarting system | + +### Dictionary Configuration + +* dn\_system\_dir + +| Name | dn\_system\_dir | +|:-----------:|:----------------------------------------------------------------------------| +| Description | The directories of system files. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/system (Windows: data\\datanode\\system) | +| Effective | After restarting system | + +* dn\_data\_dirs + +| Name | dn\_data\_dirs | +|:-----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | The directories of data files. Multiple directories are separated by comma. The starting directory of the relative path is related to the operating system. It is recommended to use an absolute path. If the path does not exist, the system will automatically create it. | +| Type | String[] | +| Default | data/datanode/data (Windows: data\\datanode\\data) | +| Effective | After restarting system | + +* dn\_multi\_dir\_strategy + +| Name | dn\_multi\_dir\_strategy | +|:-----------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Description | IoTDB's strategy for selecting directories for TsFile in tsfile_dir. You can use a simple class name or a full name of the class. The system provides the following three strategies:
1. SequenceStrategy: IoTDB selects the directory from tsfile\_dir in order, traverses all the directories in tsfile\_dir in turn, and keeps counting;
2. MaxDiskUsableSpaceFirstStrategy: IoTDB first selects the directory with the largest free disk space in tsfile\_dir;
You can complete a user-defined policy in the following ways:
1. Inherit the org.apache.iotdb.db.storageengine.rescon.disk.strategy.DirectoryStrategy class and implement its own Strategy method;
2. Fill in the configuration class with the full class name of the implemented class (package name plus class name, UserDfineStrategyPackage);
3. Add the jar file to the project. | +| Type | String | +| Default | SequenceStrategy | +| Effective | hot-load | + +* dn\_consensus\_dir + +| Name | dn\_consensus\_dir | +|:-----------:|:-------------------------------------------------------------------------------| +| Description | The directories of consensus files. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/consensus | +| Effective | After restarting system | + +* dn\_wal\_dirs + +| Name | dn\_wal\_dirs | +|:-----------:|:-------------------------------------------------------------------------| +| Description | Write Ahead Log storage path. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/wal | +| Effective | After restarting system | + +* dn\_tracing\_dir + +| Name | dn\_tracing\_dir | +|:-----------:|:----------------------------------------------------------------------------| +| Description | The tracing root directory path. It is recommended to use an absolute path. | +| Type | String | +| Default | datanode/tracing | +| Effective | After restarting system | + +* dn\_sync\_dir + +| Name | dn\_sync\_dir | +|:-----------:|:--------------------------------------------------------------------------| +| Description | The directories of sync files. It is recommended to use an absolute path. | +| Type | String | +| Default | data/datanode/sync | +| Effective | After restarting system | + +### Metric Configuration + +## Enable GC log + +GC log is off by default. +For performance tuning, you may want to collect the GC info. + +To enable GC log, just add a parameter "printgc" when you start the DataNode. + +```bash +nohup sbin/start-datanode.sh printgc >/dev/null 2>&1 & +``` +Or +```cmd +sbin\start-datanode.bat printgc +``` + +GC log is stored at `IOTDB_HOME/logs/gc.log`. +There will be at most 10 gc.log.* files and each one can reach to 10MB. + +### REST Service Configuration + +* enable\_rest\_service + +|Name| enable\_rest\_service | +|:---:|:--------------------------------------| +|Description| Whether to enable the Rest service | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* rest\_service\_port + +|Name| rest\_service\_port | +|:---:|:------------------| +|Description| The Rest service listens to the port number | +|Type| int32 | +|Default| 18080 | +|Effective| After restarting system | + +* enable\_swagger + +|Name| enable\_swagger | +|:---:|:-----------------------| +|Description| Whether to enable swagger to display rest interface information | +|Type| Boolean | +|Default| false | +|Effective| After restarting system | + +* rest\_query\_default\_row\_size\_limit + +|Name| rest\_query\_default\_row\_size\_limit | +|:---:|:------------------------------------------------------------------------------------------| +|Description| The maximum number of rows in a result set that can be returned by a query | +|Type| int32 | +|Default| 10000 | +|Effective| After restarting system | + +* cache\_expire + +|Name| cache\_expire | +|:---:|:--------------------------------------------------------| +|Description| Expiration time for caching customer login information | +|Type| int32 | +|Default| 28800 | +|Effective| After restarting system | + +* cache\_max\_num + +|Name| cache\_max\_num | +|:---:|:--------------| +|Description| The maximum number of users stored in the cache | +|Type| int32 | +|Default| 100 | +|Effective| After restarting system | + +* cache\_init\_num + +|Name| cache\_init\_num | +|:---:|:---------------| +|Description| Initial cache capacity | +|Type| int32 | +|Default| 10 | +|Effective| After restarting system | + + +* trust\_store\_path + +|Name| trust\_store\_path | +|:---:|:---------------| +|Description| keyStore Password (optional) | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +* trust\_store\_pwd + +|Name| trust\_store\_pwd | +|:---:|:---------------------------------| +|Description| trustStore Password (Optional) | +|Type| String | +|Default| "" | +|Effective| After restarting system | + +* idle\_timeout + +|Name| idle\_timeout | +|:---:|:--------------| +|Description| SSL timeout duration, expressed in seconds | +|Type| int32 | +|Default| 5000 | +|Effective| After restarting system | + +#### Storage engine configuration + +* dn\_default\_space\_move\_thresholds + +|Name| dn\_default\_space\_move\_thresholds | +|:---:|:--------------| +|Description| Version 1.3.0/1: Define the minimum remaining space ratio for each tier data catalogue; when the remaining space is less than this ratio, the data will be automatically migrated to the next tier; when the remaining storage space of the last tier falls below this threshold, the system will be set to READ_ONLY | +|Type| double | +|Default| 0.15 | +|Effective| hot-load | + + +* dn\_default\_space\_usage\_thresholds + +|Name| dn\_default\_space\_usage\_thresholds | +|:---:|:--------------| +|Description| Version 1.3.2: Define the minimum remaining space ratio for each tier data catalogue; when the remaining space is less than this ratio, the data will be automatically migrated to the next tier; when the remaining storage space of the last tier falls below this threshold, the system will be set to READ_ONLY | +|Type| double | +|Default| 0.85 | +|Effective| hot-load | + +* remote\_tsfile\_cache\_dirs + +|Name| remote\_tsfile\_cache\_dirs | +|:---:|:--------------| +|Description| Cache directory stored locally in the cloud | +|Type| string | +|Default| data/datanode/data/cache | +|Effective| After restarting system | + +* remote\_tsfile\_cache\_page\_size\_in\_kb + +|Name| remote\_tsfile\_cache\_page\_size\_in\_kb | +|:---:|:--------------| +|Description| Block size of locally cached files stored in the cloud | +|Type| int | +|Default| 20480 | +|Effective| After restarting system | + +* remote\_tsfile\_cache\_max\_disk\_usage\_in\_mb + +|Name| remote\_tsfile\_cache\_max\_disk\_usage\_in\_mb | +|:---:|:--------------| +|Description| Maximum Disk Occupancy Size for Cloud Storage Local Cache | +|Type| long | +|Default| 51200 | +|Effective| After restarting system | + +* object\_storage\_type + +|Name| object\_storage\_type | +|:---:|:--------------| +|Description| Cloud Storage Type | +|Type| string | +|Default| AWS_S3 | +|Effective| After restarting system | + +* object\_storage\_bucket + +|Name| object\_storage\_bucket | +|:---:|:--------------| +|Description| Name of cloud storage bucket | +|Type| string | +|Default| iotdb_data | +|Effective| After restarting system | + +* object\_storage\_endpoiont + +|Name| object\_storage\_endpoiont | +|:---:|:--------------| +|Description| endpoint of cloud storage | +|Type| string | +|Default| None | +|Effective| After restarting system | + +* object\_storage\_access\_key + +|Name| object\_storage\_access\_key | +|:---:|:--------------| +|Description| Authentication information stored in the cloud: key | +|Type| string | +|Default| None | +|Effective| After restarting system | + +* object\_storage\_access\_secret + +|Name| object\_storage\_access\_secret | +|:---:|:--------------| +|Description| Authentication information stored in the cloud: secret | +|Type| string | +|Default| None | +|Effective| After restarting system | diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/DataNode-Config-Manual.md b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Reference/DataNode-Config-Manual.md rename to src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual.md diff --git a/src/UserGuide/V1.3.3/Reference/DataNode-Config-Manual_apache.md b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/DataNode-Config-Manual_apache.md rename to src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual_apache.md diff --git a/src/UserGuide/V1.3.3/Reference/DataNode-Config-Manual_timecho.md b/src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/DataNode-Config-Manual_timecho.md rename to src/UserGuide/V1.3.x/Reference/DataNode-Config-Manual_timecho.md diff --git a/src/UserGuide/V1.3.3/Reference/Keywords.md b/src/UserGuide/V1.3.x/Reference/Keywords.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/Keywords.md rename to src/UserGuide/V1.3.x/Reference/Keywords.md diff --git a/src/UserGuide/V1.3.3/Reference/Modify-Config-Manual.md b/src/UserGuide/V1.3.x/Reference/Modify-Config-Manual.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/Modify-Config-Manual.md rename to src/UserGuide/V1.3.x/Reference/Modify-Config-Manual.md diff --git a/src/UserGuide/V1.3.3/Reference/Status-Codes.md b/src/UserGuide/V1.3.x/Reference/Status-Codes.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/Status-Codes.md rename to src/UserGuide/V1.3.x/Reference/Status-Codes.md diff --git a/src/UserGuide/V1.3.3/Reference/Syntax-Rule.md b/src/UserGuide/V1.3.x/Reference/Syntax-Rule.md similarity index 100% rename from src/UserGuide/V1.3.3/Reference/Syntax-Rule.md rename to src/UserGuide/V1.3.x/Reference/Syntax-Rule.md diff --git a/src/UserGuide/V1.3.3/SQL-Manual/Function-and-Expression.md b/src/UserGuide/V1.3.x/SQL-Manual/Function-and-Expression.md similarity index 100% rename from src/UserGuide/V1.3.3/SQL-Manual/Function-and-Expression.md rename to src/UserGuide/V1.3.x/SQL-Manual/Function-and-Expression.md diff --git a/src/UserGuide/V1.3.3/SQL-Manual/Operator-and-Expression.md b/src/UserGuide/V1.3.x/SQL-Manual/Operator-and-Expression.md similarity index 100% rename from src/UserGuide/V1.3.3/SQL-Manual/Operator-and-Expression.md rename to src/UserGuide/V1.3.x/SQL-Manual/Operator-and-Expression.md diff --git a/src/UserGuide/V1.3.3/SQL-Manual/SQL-Manual.md b/src/UserGuide/V1.3.x/SQL-Manual/SQL-Manual.md similarity index 100% rename from src/UserGuide/V1.3.3/SQL-Manual/SQL-Manual.md rename to src/UserGuide/V1.3.x/SQL-Manual/SQL-Manual.md diff --git a/src/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries.md b/src/UserGuide/V1.3.x/SQL-Manual/UDF-Libraries.md similarity index 100% rename from src/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries.md rename to src/UserGuide/V1.3.x/SQL-Manual/UDF-Libraries.md diff --git a/src/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_apache.md b/src/UserGuide/V1.3.x/SQL-Manual/UDF-Libraries_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_apache.md rename to src/UserGuide/V1.3.x/SQL-Manual/UDF-Libraries_apache.md diff --git a/src/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_timecho.md b/src/UserGuide/V1.3.x/SQL-Manual/UDF-Libraries_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_timecho.md rename to src/UserGuide/V1.3.x/SQL-Manual/UDF-Libraries_timecho.md diff --git a/src/UserGuide/V1.3.3/Technical-Insider/Cluster-data-partitioning.md b/src/UserGuide/V1.3.x/Technical-Insider/Cluster-data-partitioning.md similarity index 100% rename from src/UserGuide/V1.3.3/Technical-Insider/Cluster-data-partitioning.md rename to src/UserGuide/V1.3.x/Technical-Insider/Cluster-data-partitioning.md diff --git a/src/UserGuide/V1.3.3/Technical-Insider/Encoding-and-Compression.md b/src/UserGuide/V1.3.x/Technical-Insider/Encoding-and-Compression.md similarity index 100% rename from src/UserGuide/V1.3.3/Technical-Insider/Encoding-and-Compression.md rename to src/UserGuide/V1.3.x/Technical-Insider/Encoding-and-Compression.md diff --git a/src/UserGuide/V1.3.3/Technical-Insider/Publication.md b/src/UserGuide/V1.3.x/Technical-Insider/Publication.md similarity index 100% rename from src/UserGuide/V1.3.3/Technical-Insider/Publication.md rename to src/UserGuide/V1.3.x/Technical-Insider/Publication.md diff --git a/src/UserGuide/V1.3.3/Tools-System/Benchmark.md b/src/UserGuide/V1.3.x/Tools-System/Benchmark.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Benchmark.md rename to src/UserGuide/V1.3.x/Tools-System/Benchmark.md diff --git a/src/UserGuide/V1.3.3/Tools-System/CLI.md b/src/UserGuide/V1.3.x/Tools-System/CLI.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/CLI.md rename to src/UserGuide/V1.3.x/Tools-System/CLI.md diff --git a/src/UserGuide/V1.3.3/Tools-System/Data-Export-Tool.md b/src/UserGuide/V1.3.x/Tools-System/Data-Export-Tool.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Data-Export-Tool.md rename to src/UserGuide/V1.3.x/Tools-System/Data-Export-Tool.md diff --git a/src/UserGuide/V1.3.x/Tools-System/Data-Import-Export-Tool.md b/src/UserGuide/V1.3.x/Tools-System/Data-Import-Export-Tool.md new file mode 100644 index 000000000..3d082fe8f --- /dev/null +++ b/src/UserGuide/V1.3.x/Tools-System/Data-Import-Export-Tool.md @@ -0,0 +1,278 @@ + + +# Data Import Export Script + +IoTDB provides data import and export scripts (tools/export-data, tools/import-data, supported in versions 1.3.2 and above; for historical versions, tools/export-csv, tools/import-csv scripts can be used, see the reference link for usage [Document](./TsFile-Import-Export-Tool.md) ), which are used to facilitate the interaction between IoTDB internal data and external files, suitable for batch operations of single files or directories. + + +## Supported Data Formats + +- **CSV** : Plain text format for storing formatted data, which must be constructed according to the specified CSV format below. +- **SQL** : Files containing custom SQL statements. + +## export-data Script (Data Export) + +### Command + +```Bash +# Unix/OS X +>tools/export-data.sh -h -p -u -pw -t [-tf -datatype -q -s -tfn -lpf -type -aligned ] + +# Windows +>tools\export-data.bat -h -p -u -pw -t [-tf -datatype -q -s -tfn -lpf -type -aligned ] +``` + +Parameter Introduction: + +| Parameter | Definition | Required | Default | +|:-------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------|:-------------------------| +| -h | Database IP address | No | 127.0.0.1 | +| -p | Database port | No | 6667 | +| -u | Database connection username | No | root | +| -pw | Database connection password | No | root | +| -t | Output path for the exported CSV or SQL file(The parameter for V1.3.2 is `-td`) | Yes | | +| -datatype | Whether to print the corresponding data type behind the time series in the CSV file header, options are true or false | No | true | +| -q | Directly specify the query statement to be executed in the command (currently only supports some statements, see the table below for details).
Note: -q and -s parameters must be filled in one, and -q takes effect if both are filled. For detailed examples of supported SQL statements, please refer to the "SQL Statement Support Details" below. | No | | +| -s | Specify an SQL file, which may contain one or more SQL statements. If there are multiple SQL statements, they should be separated by newlines (returns). Each SQL statement corresponds to one or more output CSV or SQL files.
Note: -q and -s parameters must be filled in one, and -q takes effect if both are filled. For detailed examples of supported SQL statements, please refer to the "SQL Statement Support Details" below. | No | | +| -type | Specify the type of exported file, options are csv or sql | No | csv | +| -tf | Specify the time format. The time format must comply with the [ISO 8601](https://calendars.wikia.org/wiki/ISO_8601) standard or timestamp.
Note: Only effective when -type is csv | No | yyyy-MM-dd HH:mm:ss.SSSz | +| -lpf | Specify the maximum number of lines for the exported dump file(The parameter for V1.3.2 is `-linesPerFile`) | No | 10000 | +| -timeout | Specify the timeout time for session queries in milliseconds | No | -1 | + +SQL Statement Support Rules: + +1. Only query statements are supported; non-query statements (such as metadata management, system management, etc.) are not supported. For unsupported SQL, the program will automatically skip and output an error message. +2. In the current version of query statements, only the export of raw data is supported. If there are group by, aggregate functions, UDFs, or operational operators, they are not supported for export as SQL. When exporting raw data, please note that if exporting data from multiple devices, please use the align by device statement. Detailed examples are as follows: + +| | Supported for Export | Example | +|--------------------------------------------------------|----------------------|-----------------------------------------------| +| Raw data single device query | Supported | select * from root.s_0.d_0 | +| Raw data multi-device query (align by device) | Supported | select * from root.** align by device | +| Raw data multi-device query (without align by device) | Unsupported | select * from root.**
select * from root.s_0.* | + +### Running Examples + +- Export all data within a certain SQL execution range to a CSV file. +```Bash + # Unix/OS X + >tools/export-data.sh -t ./data/ -q 'select * from root.stock.**' + # Windows + >tools/export-data.bat -t ./data/ -q 'select * from root.stock.**' + ``` + +- Export Results + ```Bash + Time,root.stock.Legacy.0700HK.L1_BidPrice,root.stock.Legacy.0700HK.Type,root.stock.Legacy.0700HK.L1_BidSize,root.stock.Legacy.0700HK.Domain,root.stock.Legacy.0700HK.L1_BuyNo,root.stock.Legacy.0700HK.L1_AskPrice + 2024-07-29T18:37:18.700+08:00,0.9666617,3.0,0.021367407654674264,-6.0,false,0.8926191 + 2024-07-29T18:37:19.701+08:00,0.3057328,3.0,0.9965377284981661,-5.0,false,0.15167356 + ``` +- All data within the scope of all SQL statements in the SQL file is exported to CSV files. + ```Bash + # Unix/OS X + >tools/export-data.sh -t ./data/ -s export.sql + # Windows + >tools/export-data.bat -t ./data/ -s export.sql + ``` + +- Contents of export.sql File (Pointed to by -s Parameter) + ```SQL + select * from root.stock.** limit 100 + select * from root.db.** limit 100 + ``` + +- Export Result File 1 + ```Bash + Time,root.stock.Legacy.0700HK.L1_BidPrice,root.stock.Legacy.0700HK.Type,root.stock.Legacy.0700HK.L1_BidSize,root.stock.Legacy.0700HK.Domain,root.stock.Legacy.0700HK.L1_BuyNo,root.stock.Legacy.0700HK.L1_AskPrice + 2024-07-29T18:37:18.700+08:00,0.9666617,3.0,0.021367407654674264,-6.0,false,0.8926191 + 2024-07-29T18:37:19.701+08:00,0.3057328,3.0,0.9965377284981661,-5.0,false,0.15167356 + ``` + +- Export Result File 2 + ```Bash + Time,root.db.Random.RandomBoolean + 2024-07-22T17:16:05.820+08:00,true + 2024-07-22T17:16:02.597+08:00,false + ``` +- Export Data in SQL File to SQL Statements with Aligned Format + ```Bash + # Unix/OS X + >tools/export-data.sh -h 127.0.0.1 -p 6667 -u root -p root -t ./data/ -s export.sql -type sql -aligned true + # Windows + >tools/export-data.bat -h 127.0.0.1 -p 6667 -u root -p root -t ./data/ -s export.sql -type sql -aligned true + ``` + +- Export Results + ```Bash + INSERT INTO root.stock.Legacy.0700HK(TIMESTAMP,L1_BidPrice,Type,L1_BidSize,Domain,L1_BuyNo,L1_AskPrice) ALIGNED VALUES (1722249629831,0.62308747,2.0,0.012206747854849653,-6.0,false,0.14164352); + INSERT INTO root.stock.Legacy.0700HK(TIMESTAMP,L1_BidPrice,Type,L1_BidSize,Domain,L1_BuyNo,L1_AskPrice) ALIGNED VALUES (1722249630834,0.7520042,3.0,0.22760657101910464,-5.0,true,0.089064896); + INSERT INTO root.stock.Legacy.0700HK(TIMESTAMP,L1_BidPrice,Type,L1_BidSize,Domain,L1_BuyNo,L1_AskPrice) ALIGNED VALUES (1722249631835,0.3981064,3.0,0.6254559288663467,-6.0,false,0.9767922); + ``` +- Export Data in a Certain SQL Execution Range to a CSV File with Specified Time Format and Data Types + ```Bash + # Unix/OS X + >tools/export-data.sh -t ./data/ -tf 'yyyy-MM-dd HH:mm:ss' -datatype true -q "select * from root.stock.**" -type csv + # Windows + >tools/export-data.bat -t ./data/ -tf 'yyyy-MM-dd HH:mm:ss' -datatype true -q "select * from root.stock.**" -type csv + ``` + +- Export Results + ```Bash + Time,root.stock.Legacy.0700HK.L1_BidPrice(DOUBLE),root.stock.Legacy.0700HK.Type(DOUBLE),root.stock.Legacy.0700HK.L1_BidSize(DOUBLE),root.stock.Legacy.0700HK.Domain(DOUBLE),root.stock.Legacy.0700HK.L1_BuyNo(BOOLEAN),root.stock.Legacy.0700HK.L1_AskPrice(DOUBLE) + 2024-07-30 10:33:55,0.44574088,3.0,0.21476832811611501,-4.0,true,0.5951748 + 2024-07-30 10:33:56,0.6880933,3.0,0.6289119476165305,-5.0,false,0.114634395 + ``` + +## import-data Script (Data Import) + +### Import File Examples + +#### CSV File Example + +Note that before importing CSV data, special characters need to be handled as follows: + +1. If the text type field contains special characters such as `,`, it should be escaped with `\`. +2. You can import times in formats like `yyyy-MM-dd'T'HH:mm:ss`, `yyyy-MM-dd HH:mm:ss`, or `yyyy-MM-dd'T'HH:mm:ss.SSSZ`. +3. The time column `Time` should always be in the first column. + +Example 1: Time Aligned, No Data Types in Header + +```SQL +Time,root.test.t1.str,root.test.t2.str,root.test.t2.var +1970-01-01T08:00:00.001+08:00,"123hello world","123\,abc",100 +1970-01-01T08:00:00.002+08:00,"123",, +``` + +Example 2: Time Aligned, Data Types in Header(Text type data supports double quotation marks and non double quotation marks) + +```SQL +Time,root.test.t1.str(TEXT),root.test.t2.str(TEXT),root.test.t2.var(INT32) +1970-01-01T08:00:00.001+08:00,"123hello world","123\,abc",100 +1970-01-01T08:00:00.002+08:00,123,hello world,123 +1970-01-01T08:00:00.003+08:00,"123",, +1970-01-01T08:00:00.004+08:00,123,,12 +``` +Example 3: Device Aligned, No Data Types in Header + +```SQL +Time,Device,str,var +1970-01-01T08:00:00.001+08:00,root.test.t1,"123hello world", +1970-01-01T08:00:00.002+08:00,root.test.t1,"123", +1970-01-01T08:00:00.001+08:00,root.test.t2,"123\,abc",100 +``` + +Example 4: Device Aligned, Data Types in Header (Text type data supports double quotation marks and non double quotation marks) + +```SQL +Time,Device,str(TEXT),var(INT32) +1970-01-01T08:00:00.001+08:00,root.test.t1,"123hello world", +1970-01-01T08:00:00.002+08:00,root.test.t1,"123", +1970-01-01T08:00:00.001+08:00,root.test.t2,"123\,abc",100 +1970-01-01T08:00:00.002+08:00,root.test.t1,hello world,123 +``` + +#### SQL File Example + +> For unsupported SQL, illegal SQL, or failed SQL executions, they will be placed in the failed directory under the failed file (default to filename.failed). + +```SQL +INSERT INTO root.stock.Legacy.0700HK(TIMESTAMP,L1_BidPrice,Type,L1_BidSize,Domain,L1_BuyNo,L1_AskPrice) VALUES (1721728578812,0.21911979,4.0,0.7129878488375604,-5.0,false,0.65362453); +INSERT INTO root.stock.Legacy.0700HK(TIMESTAMP,L1_BidPrice,Type,L1_BidSize,Domain,L1_BuyNo,L1_AskPrice) VALUES (1721728579812,0.35814416,3.0,0.04674720094979623,-5.0,false,0.9365247); +INSERT INTO root.stock.Legacy.0700HK(TIMESTAMP,L1_BidPrice,Type,L1_BidSize,Domain,L1_BuyNo,L1_AskPrice) VALUES (1721728580813,0.20012152,3.0,0.9910098187911393,-4.0,true,0.70040536); +INSERT INTO root.stock.Legacy.0700HK(TIMESTAMP,L1_BidPrice,Type,L1_BidSize,Domain,L1_BuyNo,L1_AskPrice) VALUES (1721728581814,0.034122765,4.0,0.9313345284181858,-4.0,true,0.9945297); +``` + +### Command + +```Bash +# Unix/OS X +>tools/import-data.sh -h -p -u -pw -s [-fd <./failedDirectory> -aligned -batch -tp -typeInfer -lpf ] + +# Windows +>tools\import-data.bat -h -p -u -pw -s [-fd <./failedDirectory> -aligned -batch -tp -typeInfer -lpf ] +``` + +> Although IoTDB has the ability to infer types, it is still recommended to create metadata before importing data to avoid unnecessary type conversion errors. For example: + +```SQL +CREATE DATABASE root.fit.d1; +CREATE DATABASE root.fit.d2; +CREATE DATABASE root.fit.p; +CREATE TIMESERIES root.fit.d1.s1 WITH DATATYPE=INT32,ENCODING=RLE; +CREATE TIMESERIES root.fit.d1.s2 WITH DATATYPE=TEXT,ENCODING=PLAIN; +CREATE TIMESERIES root.fit.d2.s1 WITH DATATYPE=INT32,ENCODING=RLE; +CREATE TIMESERIES root.fit.d2.s3 WITH DATATYPE=INT32,ENCODING=RLE; +CREATE TIMESERIES root.fit.p.s1 WITH DATATYPE=INT32,ENCODING=RLE; +``` + +Parameter Introduction: + +| Parameter | Definition | Required | Default | +|:----------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------|:-------------------------------------------------| +| -h | Database IP address | No | 127.0.0.1 | +| -p | Database port | No | 6667 | +| -u | Database connection username | No | root | +| -pw | Database connection password | No | root | +| -s | Specify the data you want to import, here you can specify a file or folder. If a folder is specified, all files with the suffix CSV or SQL in the folder will be imported in bulk.(The parameter for V1.3.2 is `-f`) | Yes | | +| -fd | Specify the directory to store the failed SQL files. If this parameter is not specified, the failed files will be saved to the directory of the source data.
Note: For unsupported SQL, illegal SQL, and failed SQL, they will be placed in the failed file in the failed directory (default file name is. failed) | No | Add the suffix '. failed' to the source file name | +| -aligned | Specify whether to use the 'aligned' interface, with options of true or false. This parameter only takes effect when the imported file is a CSV file | No | false | +| -batch | Used to specify the number of points to be inserted for each batch of data (minimum value is 1, maximum value is Integer.MAX_VALUE). If the program reports' org.apache.hrift.transport ' If TTransportException: Frame size larger than protect max size is incorrect, you can adjust this parameter appropriately. | No | `100000` | +| -tp | Specify time precision, optional values include 'ms' (milliseconds),' ns' (nanoseconds), 'us' (microseconds) | No | `ms` | +| -lpf | Specify the number of lines to write data to each failed import file(The parameter for V1.3.2 is `-linesPerFailedFile`) | No | 10000 | +| -typeInfer | Used to specify type inference rules. For Example:.
Note: Used to specify type inference rules.`srcTsDataType` include `boolean`,`int`,`long`,`float`,`double`,`NaN`.`dstTsDataType` include `boolean`,`int`,`long`,`float`,`double`,`text`.when`srcTsDataType`is`boolean`, `dstTsDataType`can only be`boolean`or`text`.when`srcTsDataType`is`NaN`, `dstTsDataType`can only be`float`, `double`or`text`.when`srcTsDataType`is numeric, the precision of `dstTsDataType`needs to be higher than that of `srcTsDataType`.For example:`-typeInfer boolean=text,float=double` | No | | + +### Running Examples + +- Import the `dump0_0.sql` data in the current data directory into the local IoTDB database. + +```Bash +# Unix/OS X +>tools/import-data.sh -s ./data/dump0_0.sql +# Windows +>tools/import-data.bat -s ./data/dump0_0.sql +``` + +- Import all data in the current data directory in an aligned manner into the local IoTDB database. + +```Bash +# Unix/OS X +>tools/import-data.sh -s ./data/ -fd ./failed/ -aligned true +# Windows +>tools/import-data.bat -s ./data/ -fd ./failed/ -aligned true +``` + +- Import the `dump0_0.csv` data in the current data directory into the local IoTDB database. + +```Bash +# Unix/OS X +>tools/import-data.sh -s ./data/dump0_0.csv -fd ./failed/ +# Windows +>tools/import-data.bat -s ./data/dump0_0.csv -fd ./failed/ +``` + +- Import the `dump0_0.csv` data in the current data directory in an aligned manner, batch import 100,000 records into the IoTDB database on the host with IP `192.168.100.1`, record failures in the current `failed` directory, and limit each file to 1,000 records. + +```Bash +# Unix/OS X +>tools/import-data.sh -h 192.168.100.1 -p 6667 -u root -pw root -s ./data/dump0_0.csv -fd ./failed/ -aligned true -batch 100000 -tp ms -typeInfer boolean=text,float=double -lpf 1000 +# Windows +>tools/import-data.bat -h 192.168.100.1 -p 6667 -u root -pw root -s ./data/dump0_0.csv -fd ./failed/ -aligned true -batch 100000 -tp ms -typeInfer boolean=text,float=double -lpf 1000 +``` \ No newline at end of file diff --git a/src/UserGuide/V1.3.3/Tools-System/Data-Import-Tool.md b/src/UserGuide/V1.3.x/Tools-System/Data-Import-Tool.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Data-Import-Tool.md rename to src/UserGuide/V1.3.x/Tools-System/Data-Import-Tool.md diff --git a/src/UserGuide/V1.3.3/Tools-System/Maintenance-Tool_apache.md b/src/UserGuide/V1.3.x/Tools-System/Maintenance-Tool_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Maintenance-Tool_apache.md rename to src/UserGuide/V1.3.x/Tools-System/Maintenance-Tool_apache.md diff --git a/src/UserGuide/V1.3.3/Tools-System/Maintenance-Tool_timecho.md b/src/UserGuide/V1.3.x/Tools-System/Maintenance-Tool_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Maintenance-Tool_timecho.md rename to src/UserGuide/V1.3.x/Tools-System/Maintenance-Tool_timecho.md diff --git a/src/UserGuide/V1.3.3/Tools-System/Monitor-Tool.md b/src/UserGuide/V1.3.x/Tools-System/Monitor-Tool.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Monitor-Tool.md rename to src/UserGuide/V1.3.x/Tools-System/Monitor-Tool.md diff --git a/src/UserGuide/V1.3.3/Tools-System/Monitor-Tool_apache.md b/src/UserGuide/V1.3.x/Tools-System/Monitor-Tool_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Monitor-Tool_apache.md rename to src/UserGuide/V1.3.x/Tools-System/Monitor-Tool_apache.md diff --git a/src/UserGuide/V1.3.3/Tools-System/Monitor-Tool_timecho.md b/src/UserGuide/V1.3.x/Tools-System/Monitor-Tool_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Monitor-Tool_timecho.md rename to src/UserGuide/V1.3.x/Tools-System/Monitor-Tool_timecho.md diff --git a/src/UserGuide/V1.3.x/Tools-System/TsFile-Import-Export-Tool.md b/src/UserGuide/V1.3.x/Tools-System/TsFile-Import-Export-Tool.md new file mode 100644 index 000000000..1fbb9a519 --- /dev/null +++ b/src/UserGuide/V1.3.x/Tools-System/TsFile-Import-Export-Tool.md @@ -0,0 +1,428 @@ + + +# TsFile Import Export Script + +For different scenarios, IoTDB provides users with a variety of operation methods for batch importing data. This chapter introduces the two most commonly used methods for importing in the form of CSV text and importing in the form of TsFile files. + +## TsFile Load And Export Script + +### TsFile Load Tool + +#### Introduction + +The load external tsfile tool allows users to load tsfiles, delete a tsfile, or move a tsfile to target directory from the running Apache IoTDB instance. Alternatively, you can use scripts to load tsfiles into IoTDB, for more information. + +#### Load with SQL + +The user sends specified commands to the Apache IoTDB system through the Cli tool or JDBC to use the tool. + +##### Load Tsfiles + +The command to load tsfiles is `load [sglevel=int][verify=true/false][onSuccess=delete/none]`. + +This command has two usages: + +1. Load a single tsfile by specifying a file path (absolute path). + +The first parameter indicates the path of the tsfile to be loaded. This command has three options: sglevel, verify, onSuccess. + +SGLEVEL option. If the database correspond to the tsfile does not exist, the user can set the level of database through the fourth parameter. By default, it uses the database level which is set in `iotdb-common.properties`. + +VERIFY option. If this parameter is true, All timeseries in this loading tsfile will be compared with the timeseries in IoTDB. If existing a measurement which has different datatype with the measurement in IoTDB, the loading process will be stopped and exit. If consistence can be promised, setting false for this parameter will be a better choice. + +ONSUCCESS option. The default value is DELETE, which means the processing method of successfully loaded tsfiles, and DELETE means after the tsfile is successfully loaded, it will be deleted. NONE means after the tsfile is successfully loaded, it will be remained in the origin dir. + +If the `.resource` file corresponding to the file exists, it will be loaded into the data directory and engine of the Apache IoTDB. Otherwise, the corresponding `.resource` file will be regenerated from the tsfile file. + +Examples: + +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile'` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' verify=true` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' verify=false` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' sglevel=1` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' onSuccess=delete` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' verify=true sglevel=1` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' verify=false sglevel=1` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' verify=true onSuccess=none` +* `load '/Users/Desktop/data/1575028885956-101-0.tsfile' verify=false sglevel=1 onSuccess=delete` + +2. Load a batch of files by specifying a folder path (absolute path). + +The first parameter indicates the path of the tsfile to be loaded. The options above also works for this command. + +Examples: + +* `load '/Users/Desktop/data'` +* `load '/Users/Desktop/data' verify=false` +* `load '/Users/Desktop/data' verify=true` +* `load '/Users/Desktop/data' verify=true sglevel=1` +* `load '/Users/Desktop/data' verify=false sglevel=1 onSuccess=delete` + +**NOTICE**: When `$IOTDB_HOME$/conf/iotdb-common.properties` has `enable_auto_create_schema=true`, it will automatically create metadata in TSFILE, otherwise it will not be created automatically. + +#### Load with Script + +Run rewrite-tsfile.bat if you are in a Windows environment, or rewrite-tsfile.sh if you are on Linux or Unix. + +```bash +./load-tsfile.bat -f filePath [-h host] [-p port] [-u username] [-pw password] [--sgLevel int] [--verify true/false] [--onSuccess none/delete] +-f File/Directory to be load, required +-h IoTDB Host address, optional field, 127.0.0.1 by default +-p IoTDB port, optional field, 6667 by default +-u IoTDB user name, optional field, root by default +-pw IoTDB password, optional field, root by default +--sgLevel Sg level of loading Tsfile, optional field, default_storage_group_level in iotdb-common.properties by default +--verify Verify schema or not, optional field, True by default +--onSuccess Delete or remain origin TsFile after loading, optional field, none by default +``` + +##### Example + +Assuming that an IoTDB instance is running on server 192.168.0.101:6667, you want to load all TsFile files from the locally saved TsFile backup folder D:\IoTDB\data into this IoTDB instance. + +First move to the folder `$IOTDB_HOME/tools/`, open the command line, and execute + +```bash +./load-rewrite.bat -f D:\IoTDB\data -h 192.168.0.101 -p 6667 -u root -pw root +``` + +After waiting for the script execution to complete, you can check that the data in the IoTDB instance has been loaded correctly. + +##### Q&A + +- Cannot find or load the main class + - It may be because the environment variable $IOTDB_HOME is not set, please set the environment variable and try again +- -f option must be set! + - The input command is missing the -f field (file or folder path to be loaded) or the -u field (user name), please add it and re-execute +- What if the execution crashes in the middle and you want to reload? + - You re-execute the command just now, reloading the data will not affect the correctness after loading + +TsFile can help you export the result set in the format of TsFile file to the specified path by executing the sql, command line sql, and sql file. + +### TsFile Export Tool + +#### Syntax + +```shell +# Unix/OS X +> tools/export-tsfile.sh -h -p -u -pw -td [-f -q -s ] + +# Windows +> tools\export-tsfile.bat -h -p -u -pw -td [-f -q -s ] +``` + +* `-h `: + - The host address of the IoTDB service. +* `-p `: + - The port number of the IoTDB service. +* `-u `: + - The username of the IoTDB service. +* `-pw `: + - Password for IoTDB service. +* `-td `: + - Specify the output path for the exported TsFile file. +* `-f `: + - For the file name of the exported TsFile file, just write the file name, and cannot include the file path and suffix. If the sql file or console input contains multiple sqls, multiple files will be generated in the order of sql. + - Example: There are three SQLs in the file or command line, and -f param is "dump", then three TsFile files: dump0.tsfile、dump1.tsfile、dump2.tsfile will be generated in the target path. +* `-q `: + - Directly specify the query statement you want to execute in the command. + - Example: `select * from root.** limit 100` +* `-s `: + - Specify a SQL file that contains one or more SQL statements. If an SQL file contains multiple SQL statements, the SQL statements should be separated by newlines. Each SQL statement corresponds to an output TsFile file. +* `-t `: + - Specifies the timeout period for session queries, in milliseconds + + +In addition, if you do not use the `-s` and `-q` parameters, after the export script is started, you need to enter the query statement as prompted by the program, and different query results will be saved to different TsFile files. + +#### Example + +```shell +# Unix/OS X +> tools/export-tsfile.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ +# or +> tools/export-tsfile.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -q "select * from root.** align by device" +# Or +> tools/export-tsfile.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s ./sql.txt +# Or +> tools/export-tsfile.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s ./sql.txt -f myTsFile +# Or +> tools/export-tsfile.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s ./sql.txt -f myTsFile -t 10000 + +# Windows +> tools/export-tsfile.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ +# Or +> tools/export-tsfile.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -q "select * from root.** align by device" +# Or +> tools/export-tsfile.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s ./sql.txt +# Or +> tools/export-tsfile.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s ./sql.txt -f myTsFile +# Or +> tools/export-tsfile.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s ./sql.txt -f myTsFile -t 10000 +``` + +#### Q&A + +- It is recommended not to execute the write data command at the same time when loading data, which may lead to insufficient memory in the JVM. + +## CSV Tool + +The CSV tool can help you import data in CSV format to IoTDB or export data from IoTDB to a CSV file. + +### Usage of export-csv.sh + +#### Syntax + +```shell +# Unix/OS X +> tools/export-csv.sh -h -p -u -pw -td [-tf -datatype -q -s -linesPerFile ] + +# Windows +> tools\export-csv.bat -h -p -u -pw -td [-tf -datatype -q -s -linesPerFile ] +``` + +Description: + +* `-datatype`: + - true (by default): print the data type of timesries in the head line of CSV file. i.e., `Time, root.sg1.d1.s1(INT32), root.sg1.d1.s2(INT64)`. + - false: only print the timeseries name in the head line of the CSV file. i.e., `Time, root.sg1.d1.s1 , root.sg1.d1.s2` +* `-q `: + - specifying a query command that you want to execute + - example: `select * from root.** limit 100`, or `select * from root.** limit 100 align by device` +* `-s `: + - specifying a SQL file which can consist of more than one sql. If there are multiple SQLs in one SQL file, the SQLs should be separated by line breaks. And, for each SQL, a output CSV file will be generated. +* `-td `: + - specifying the directory that the data will be exported +* `-tf `: + - specifying a time format that you want. The time format have to obey [ISO 8601](https://calendars.wikia.org/wiki/ISO_8601) standard. If you want to save the time as the timestamp, then setting `-tf timestamp` + - example: `-tf yyyy-MM-dd\ HH:mm:ss` or `-tf timestamp` +* `-linesPerFile `: + - Specifying lines of each dump file, `10000` is default. + - example: `-linesPerFile 1` +* `-t `: + - Specifies the timeout period for session queries, in milliseconds + + +More, if you don't use one of `-s` and `-q`, you need to enter some queries after running the export script. The results of the different query will be saved to different CSV files. + +#### Example + +```shell +# Unix/OS X +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ +# Or +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss +# or +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -q "select * from root.** align by device" +# Or +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s sql.txt +# Or +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss -s sql.txt +# Or +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss -s sql.txt -linesPerFile 10 +# Or +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss -s sql.txt -linesPerFile 10 -t 10000 + +# Windows +> tools/export-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ +# Or +> tools/export-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss +# or +> tools/export-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -q "select * from root.** align by device" +# Or +> tools/export-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -s sql.txt +# Or +> tools/export-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss -s sql.txt +# Or +> tools/export-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss -s sql.txt -linesPerFile 10 +# Or +> tools/export-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -td ./ -tf yyyy-MM-dd\ HH:mm:ss -s sql.txt -linesPerFile 10 -t 10000 +``` + +#### Sample SQL file + +```sql +select * from root.**; +select * from root.** align by device; +``` + +The result of `select * from root.**` + +```sql +Time,root.ln.wf04.wt04.status(BOOLEAN),root.ln.wf03.wt03.hardware(TEXT),root.ln.wf02.wt02.status(BOOLEAN),root.ln.wf02.wt02.hardware(TEXT),root.ln.wf01.wt01.hardware(TEXT),root.ln.wf01.wt01.status(BOOLEAN) +1970-01-01T08:00:00.001+08:00,true,"v1",true,"v1",v1,true +1970-01-01T08:00:00.002+08:00,true,"v1",,,,true +``` + +The result of `select * from root.** align by device` + +```sql +Time,Device,hardware(TEXT),status(BOOLEAN) +1970-01-01T08:00:00.001+08:00,root.ln.wf01.wt01,"v1",true +1970-01-01T08:00:00.002+08:00,root.ln.wf01.wt01,,true +1970-01-01T08:00:00.001+08:00,root.ln.wf02.wt02,"v1",true +1970-01-01T08:00:00.001+08:00,root.ln.wf03.wt03,"v1", +1970-01-01T08:00:00.002+08:00,root.ln.wf03.wt03,"v1", +1970-01-01T08:00:00.001+08:00,root.ln.wf04.wt04,,true +1970-01-01T08:00:00.002+08:00,root.ln.wf04.wt04,,true +``` + +The data of boolean type signed by `true` and `false` without double quotes. And the text data will be enclosed in double quotes. + +#### Note + +Note that if fields exported by the export tool have the following special characters: + +1. `,`: the field will be escaped by `\`. + +### Usage of import-csv.sh + +#### Create Metadata (optional) + +```sql +CREATE DATABASE root.fit.d1; +CREATE DATABASE root.fit.d2; +CREATE DATABASE root.fit.p; +CREATE TIMESERIES root.fit.d1.s1 WITH DATATYPE=INT32,ENCODING=RLE; +CREATE TIMESERIES root.fit.d1.s2 WITH DATATYPE=TEXT,ENCODING=PLAIN; +CREATE TIMESERIES root.fit.d2.s1 WITH DATATYPE=INT32,ENCODING=RLE; +CREATE TIMESERIES root.fit.d2.s3 WITH DATATYPE=INT32,ENCODING=RLE; +CREATE TIMESERIES root.fit.p.s1 WITH DATATYPE=INT32,ENCODING=RLE; +``` + +IoTDB has the ability of type inference, so it is not necessary to create metadata before data import. However, we still recommend creating metadata before importing data using the CSV import tool, as this can avoid unnecessary type conversion errors. + +#### Sample CSV File to Be Imported + +The data aligned by time, and headers without data type. + +```sql +Time,root.test.t1.str,root.test.t2.str,root.test.t2.int +1970-01-01T08:00:00.001+08:00,"123hello world","123\,abc",100 +1970-01-01T08:00:00.002+08:00,"123",, +``` + +The data aligned by time, and headers with data type.(Text type data supports double quotation marks and no double quotation marks) + +```sql +Time,root.test.t1.str(TEXT),root.test.t2.str(TEXT),root.test.t2.int(INT32) +1970-01-01T08:00:00.001+08:00,"123hello world","123\,abc",100 +1970-01-01T08:00:00.002+08:00,123,hello world,123 +1970-01-01T08:00:00.003+08:00,"123",, +1970-01-01T08:00:00.004+08:00,123,,12 +``` + +The data aligned by device, and headers without data type. + +```sql +Time,Device,str,int +1970-01-01T08:00:00.001+08:00,root.test.t1,"123hello world", +1970-01-01T08:00:00.002+08:00,root.test.t1,"123", +1970-01-01T08:00:00.001+08:00,root.test.t2,"123\,abc",100 +``` + +The data aligned by device, and headers with data type.(Text type data supports double quotation marks and no double quotation marks) + +```sql +Time,Device,str(TEXT),int(INT32) +1970-01-01T08:00:00.001+08:00,root.test.t1,"123hello world", +1970-01-01T08:00:00.002+08:00,root.test.t1,hello world,123 +1970-01-01T08:00:00.003+08:00,root.test.t1,,123 +``` + +#### Syntax + +```shell +# Unix/OS X +> tools/import-csv.sh -h -p -u -pw -f [-fd <./failedDirectory>] [-aligned ] [-tp ] [-typeInfer ] +# Windows +> tools\import-csv.bat -h -p -u -pw -f [-fd <./failedDirectory>] [-aligned ] [-tp ] [-typeInfer ] +``` + +Description: + +* `-f`: + - the CSV file that you want to import, and it could be a file or a folder. If a folder is specified, all TXT and CSV files in the folder will be imported in batches. + - example: `-f filename.csv` + +* `-fd`: + - specifying a directory to save files which save failed lines. If you don't use this parameter, the failed file will be saved at original directory, and the filename will be the source filename with suffix `.failed`. + - example: `-fd ./failed/` + +* `-aligned`: + - whether to use the aligned interface? The option `false` is default. + - example: `-aligned true` + +* `-batch`: + - specifying the point's number of a batch. If the program throw the exception `org.apache.thrift.transport.TTransportException: Frame size larger than protect max size`, you can lower this parameter as appropriate. + - example: `-batch 100000`, `100000` is the default value. + +* `-tp `: + - specifying a time precision. Options includes `ms`(millisecond), `ns`(nanosecond), and `us`(microsecond), `ms` is default. + +* `-typeInfer `: + - specifying rules of type inference. + - Option `srcTsDataType` includes `boolean`,`int`,`long`,`float`,`double`,`NaN`. + - Option `dstTsDataType` includes `boolean`,`int`,`long`,`float`,`double`,`text`. + - When `srcTsDataType` is `boolean`, `dstTsDataType` should be between `boolean` and `text`. + - When `srcTsDataType` is `NaN`, `dstTsDataType` should be among `float`, `double` and `text`. + - When `srcTsDataType` is Numeric type, `dstTsDataType` precision should be greater than `srcTsDataType`. + - example: `-typeInfer boolean=text,float=double` + +* `-linesPerFailedFile `: + - Specifying lines of each failed file, `10000` is default. + - example: `-linesPerFailedFile 1` + +#### Example + +```sh +# Unix/OS X +> tools/import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd ./failed +# or +> tools/import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd ./failed +# or +> tools\import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd ./failed -tp ns +# or +> tools\import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd ./failed -tp ns -typeInfer boolean=text,float=double +# or +> tools\import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd ./failed -tp ns -typeInfer boolean=text,float=double -linesPerFailedFile 10 + +# Windows +> tools\import-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv +# or +> tools\import-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd .\failed +# or +> tools\import-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd .\failed -tp ns +# or +> tools\import-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd .\failed -tp ns -typeInfer boolean=text,float=double +# or +> tools\import-csv.bat -h 127.0.0.1 -p 6667 -u root -pw root -f example-filename.csv -fd .\failed -tp ns -typeInfer boolean=text,float=double -linesPerFailedFile 10 + +``` + +#### Note + +Note that the following special characters in fields need to be checked before importing: + +1. `,` : fields containing `,` should be escaped by `\`. +2. you can input time format like `yyyy-MM-dd'T'HH:mm:ss`, `yyy-MM-dd HH:mm:ss`, or `yyyy-MM-dd'T'HH:mm:ss.SSSZ`. +3. the `Time` column must be the first one. \ No newline at end of file diff --git a/src/UserGuide/V1.3.3/Tools-System/Workbench_timecho.md b/src/UserGuide/V1.3.x/Tools-System/Workbench_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/Tools-System/Workbench_timecho.md rename to src/UserGuide/V1.3.x/Tools-System/Workbench_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/AINode_apache.md b/src/UserGuide/V1.3.x/User-Manual/AINode_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/AINode_apache.md rename to src/UserGuide/V1.3.x/User-Manual/AINode_apache.md diff --git a/src/UserGuide/V1.3.3/User-Manual/AINode_timecho.md b/src/UserGuide/V1.3.x/User-Manual/AINode_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/AINode_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/AINode_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Audit-Log_timecho.md b/src/UserGuide/V1.3.x/User-Manual/Audit-Log_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Audit-Log_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/Audit-Log_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Authority-Management.md b/src/UserGuide/V1.3.x/User-Manual/Authority-Management.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Authority-Management.md rename to src/UserGuide/V1.3.x/User-Manual/Authority-Management.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Data-Recovery.md b/src/UserGuide/V1.3.x/User-Manual/Data-Recovery.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Data-Recovery.md rename to src/UserGuide/V1.3.x/User-Manual/Data-Recovery.md diff --git a/src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_apache.md b/src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_apache.md new file mode 100644 index 000000000..691dfd4e3 --- /dev/null +++ b/src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_apache.md @@ -0,0 +1,542 @@ + + +# Data Synchronisation + +Data synchronization is a typical requirement in industrial Internet of Things (IoT). Through data synchronization mechanisms, it is possible to achieve data sharing between IoTDB, and to establish a complete data link to meet the needs for internal and external network data interconnectivity, edge-cloud synchronization, data migration, and data backup. + +## Function Overview + +### Data Synchronization + +A data synchronization task consists of three stages: + +![](/img/sync_en_01.png) + +- Source Stage:This part is used to extract data from the source IoTDB, defined in the source section of the SQL statement. +- Process Stage:This part is used to process the data extracted from the source IoTDB, defined in the processor section of the SQL statement. +- Sink Stage:This part is used to send data to the target IoTDB, defined in the sink section of the SQL statement. + +By declaratively configuring the specific content of the three parts through SQL statements, flexible data synchronization capabilities can be achieved. Currently, data synchronization supports the synchronization of the following information, and you can select the synchronization scope when creating a synchronization task (the default is data.insert, which means synchronizing newly written data): + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Synchronization ScopeSynchronization Content Description
allAll scopes
data(Data)insertSynchronize newly written data
deleteSynchronize deleted data
schemadatabaseSynchronize database creation, modification or deletion operations
timeseriesSynchronize the definition and attributes of time series
TTLSynchronize the data retention time
auth-Synchronize user permissions and access control
+ +### Functional limitations and instructions + +The schema and auth synchronization functions have the following limitations: + +- When using schema synchronization, it is required that the consensus protocol of `Schema region` and `ConfigNode` must be the default ratis protocol, that is: In the `iotdb-common.properties` configuration file, both the `config_node_consensus_protocol_class` and `schema_region_consensus_protocol_class` configuration items are set to `org.apache.iotdb.consensus.ratis.RatisConsensus`. + +- To prevent potential conflicts, please turn off the automatic creation of metadata on the receiving end when enabling schema synchronization. You can do this by setting the `enable_auto_create_schema` configuration in the `iotdb-common.properties` configuration file to false. + +- When schema synchronization is enabled, the use of custom plugins is not supported. + +- During data synchronization tasks, please avoid performing any deletion operations to prevent inconsistent states between the two ends. + +## Usage Instructions + +Data synchronization tasks have three states: RUNNING, STOPPED, and DROPPED. The task state transitions are shown in the following diagram: + +V1.3.0 and earlier versions: + +After creation, it will not start immediately and needs to execute the `START PIPE` statement to start the task. + +![](/img/sync_en_02.png) + +V1.3.1 and later versions: + +After creation, the task will start directly, and when the task stops abnormally, the system will automatically attempt to restart the task. + +![](/img/Data-Sync02.png) + +Provide the following SQL statements for state management of synchronization tasks. + +### Create Task + +Use the `CREATE PIPE` statement to create a data synchronization task. The `PipeId` and `sink` attributes are required, while `source` and `processor` are optional. When entering the SQL, note that the order of the `SOURCE` and `SINK` plugins cannot be swapped. + +The SQL example is as follows: + +```SQL +CREATE PIPE -- PipeId is the name that uniquely identifies the task. +-- Data extraction plugin, optional plugin +WITH SOURCE ( + [ = ,], +) +-- Data processing plugin, optional plugin +WITH PROCESSOR ( + [ = ,], +) +-- Data connection plugin, required plugin +WITH SINK ( + [ = ,], +) +``` + +### Start Task + +Start processing data: + + +```SQL +START PIPE +``` + +### Stop Task + +Stop processing data: + +```SQL +STOP PIPE +``` + +### Delete Task + +Deletes the specified task: + +```SQL +DROP PIPE +``` + +Deleting a task does not require stopping the synchronization task first. + +### View Task + +View all tasks: + +```SQL +SHOW PIPES +``` + +To view a specified task: + +```SQL +SHOW PIPE +``` + +Example of the show pipes result for a pipe: + +```SQL ++--------------------------------+-----------------------+-------+---------------+--------------------+------------------------------------------------------------+----------------+ +| ID| CreationTime| State| PipeSource| PipeProcessor| PipeSink|ExceptionMessage| ++--------------------------------+-----------------------+-------+---------------+--------------------+------------------------------------------------------------+----------------+ +|3421aacb16ae46249bac96ce4048a220|2024-08-13T09:55:18.717|RUNNING| {}| {}|{{sink=iotdb-thrift-sink, sink.ip=127.0.0.1, sink.port=6668}}| | ++--------------------------------+-----------------------+-------+---------------+--------------------+------------------------------------------------------------+----------------+ +``` + +其中各列含义如下: + +- **ID**:The unique identifier for the synchronization task +- **CreationTime**:The time when the synchronization task was created +- **State**:The state of the synchronization task +- **PipeSource**:The source of the synchronized data stream +- **PipeProcessor**:The processing logic of the synchronized data stream during transmission +- **PipeSink**:The destination of the synchronized data stream +- **ExceptionMessage**:Displays the exception information of the synchronization task + + + + +### Synchronization Plugins + + +To make the overall architecture more flexible to match different synchronization scenario requirements, we support plugin assembly within the synchronization task framework. The system comes with some pre-installed common plugins that you can use directly. At the same time, you can also customize processor plugins and Sink plugins, and load them into the IoTDB system for use. You can view the plugins in the system (including custom and built-in plugins) with the following statement: + +```SQL +SHOW PIPEPLUGINS +``` + +The return result is as follows (version 1.3.2): + +```SQL +IoTDB> SHOW PIPEPLUGINS ++---------------------+----------+-------------------------------------------------------------------------------------------+----------------------------------------------------+ +| PluginName|PluginType| ClassName| PluginJar| ++---------------------+----------+-------------------------------------------------------------------------------------------+----------------------------------------------------+ +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.processor.donothing.DoNothingProcessor| | +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.connector.donothing.DoNothingConnector| | +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.extractor.iotdb.IoTDBExtractor| | +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| | +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| | ++---------------------+----------+-------------------------------------------------------------------------------------------+----------------------------------------------------+ +``` + + +Detailed introduction of pre-installed plugins is as follows (for detailed parameters of each plugin, please refer to the [Parameter Description](#reference-parameter-description) section): + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeCustom PluginPlugin NameDescriptionApplicable Version
source pluginNot Supportediotdb-sourceThe default extractor plugin, used to extract historical or real-time data from IoTDB1.2.x
processor pluginSupporteddo-nothing-processorThe default processor plugin, which does not process the incoming data1.2.x
sink pluginSupporteddo-nothing-sinkDoes not process the data that is sent out1.2.x
iotdb-thrift-sinkThe default sink plugin ( V1.3.1+ ), used for data transfer between IoTDB ( V1.2.0+ ) and IoTDB( V1.2.0+ ) . It uses the Thrift RPC framework to transfer data, with a multi-threaded async non-blocking IO model, high transfer performance, especially suitable for scenarios where the target end is distributed1.2.x
iotdb-thrift-ssl-sinkUsed for data transfer between IoTDB ( V1.3.1+ ) and IoTDB ( V1.2.0+ ). It uses the Thrift RPC framework to transfer data, with a single-threaded sync blocking IO model, suitable for scenarios with higher security requirements1.3.1+
+ +For importing custom plugins, please refer to the [Stream Processing](./Streaming_apache.md#custom-stream-processing-plugin-management) section. + +## Use examples + +### Full data synchronisation + +This example is used to demonstrate the synchronisation of all data from one IoTDB to another IoTDB with the data link as shown below: + +![](/img/pipe1.jpg) + +In this example, we can create a synchronization task named A2B to synchronize the full data from A IoTDB to B IoTDB. The iotdb-thrift-sink plugin (built-in plugin) for the sink is required. The URL of the data service port of the DataNode node on the target IoTDB needs to be configured through node-urls, as shown in the following example statement: + +```SQL +create pipe A2B +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +``` + +### Partial data synchronization + +This example is used to demonstrate the synchronisation of data from a certain historical time range (8:00pm 23 August 2023 to 8:00pm 23 October 2023) to another IoTDB, the data link is shown below: + +![](/img/pipe2.jpg) + +In this example, we can create a synchronization task named A2B. First, we need to define the range of data to be transferred in the source. Since the data being transferred is historical data (historical data refers to data that existed before the creation of the synchronization task), we need to configure the start-time and end-time of the data and the transfer mode mode. The URL of the data service port of the DataNode node on the target IoTDB needs to be configured through node-urls. + +The detailed statements are as follows: + +```SQL +create pipe A2B +WITH SOURCE ( + 'source'= 'iotdb-source', + 'realtime.mode' = 'stream' -- The extraction mode for newly inserted data (after pipe creation) + 'start-time' = '2023.08.23T08:00:00+00:00', -- The start event time for synchronizing all data, including start-time + 'end-time' = '2023.10.23T08:00:00+00:00' -- The end event time for synchronizing all data, including end-time +) +with SINK ( + 'sink'='iotdb-thrift-async-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +``` + +### Edge-cloud data transfer + +This example is used to demonstrate the scenario where data from multiple IoTDB is transferred to the cloud, with data from clusters B, C, and D all synchronized to cluster A, as shown in the figure below: + +![](/img/sync_en_03.png) + +In this example, to synchronize the data from clusters B, C, and D to A, the pipe between BA, CA, and DA needs to configure the `path` to limit the range, and to keep the edge and cloud data consistent, the pipe needs to be configured with `inclusion=all` to synchronize full data and metadata. The detailed statement is as follows: + +On B IoTDB, execute the following statement to synchronize data from B to A: + +```SQL +create pipe BA +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'path'='root.db.**', -- Limit the range +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +On C IoTDB, execute the following statement to synchronize data from C to A: + +```SQL +create pipe CA +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'path'='root.db.**', -- Limit the range +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +On D IoTDB, execute the following statement to synchronize data from D to A: + +```SQL +create pipe DA +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'path'='root.db.**', -- Limit the range +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +### Cascading data transfer + +This example is used to demonstrate the scenario where data is transferred in a cascading manner between multiple IoTDB, with data from cluster A synchronized to cluster B, and then to cluster C, as shown in the figure below: + +![](/img/sync_en_04.png) + +In this example, to synchronize the data from cluster A to C, the `forwarding-pipe-requests` needs to be set to `true` between BC. The detailed statement is as follows: + +On A IoTDB, execute the following statement to synchronize data from A to B: + +```SQL +create pipe AB +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +On B IoTDB, execute the following statement to synchronize data from B to C: + +```SQL +create pipe BC +with source ( + 'forwarding-pipe-requests' = 'true' -- Whether to forward data written by other Pipes +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6669', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + + +### Encrypted Synchronization (V1.3.1+) + +IoTDB supports the use of SSL encryption during the synchronization process, ensuring the secure transfer of data between different IoTDB instances. By configuring SSL-related parameters, such as the certificate address and password (`ssl.trust-store-path`)、(`ssl.trust-store-pwd`), data can be protected by SSL encryption during the synchronization process. + +For example, to create a synchronization task named A2B: + +```SQL +create pipe A2B +with sink ( + 'sink'='iotdb-thrift-ssl-sink', + 'node-urls'='127.0.0.1:6667', -- The URL of the data service port of the DataNode node on the target IoTDB + 'ssl.trust-store-path'='pki/trusted', -- The trust store certificate path required to connect to the target DataNode + 'ssl.trust-store-pwd'='root' -- The trust store certificate password required to connect to the target DataNode +) +``` + +## Reference: Notes + +You can adjust the parameters for data synchronization by modifying the IoTDB configuration file (`iotdb-common.properties`), such as the directory for storing synchronized data. The complete configuration is as follows: + +V1.3.0/1/2: + +```Properties +#################### +### Pipe Configuration +#################### + +# Uncomment the following field to configure the pipe lib directory. +# For Windows platform +# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is +# absolute. Otherwise, it is relative. +# pipe_lib_dir=ext\\pipe +# For Linux platform +# If its prefix is "/", then the path is absolute. Otherwise, it is relative. +# pipe_lib_dir=ext/pipe + +# The maximum number of threads that can be used to execute the pipe subtasks in PipeSubtaskExecutor. +# The actual value will be min(pipe_subtask_executor_max_thread_num, max(1, CPU core number / 2)). +# pipe_subtask_executor_max_thread_num=5 + +# The connection timeout (in milliseconds) for the thrift client. +# pipe_sink_timeout_ms=900000 + +# The maximum number of selectors that can be used in the sink. +# Recommend to set this value to less than or equal to pipe_sink_max_client_number. +# pipe_sink_selector_number=4 + +# The maximum number of clients that can be used in the sink. +# pipe_sink_max_client_number=16 + +``` + +## Reference: parameter description + +### source parameter(V1.3.0) + +| key | value | value range | required or not | default value | +| :------------------------------ | :----------------------------------------------------------- | :------------------------------------- | :------- | :------------- | +| source | iotdb-source | String: iotdb-source | required | - | +| source.pattern | Used to filter the path prefix of time series | String: any time series prefix | optional | root | +| source.history.enable | Whether to send historical data | Boolean: true / false | optional | true | +| source.history.start-time | The start event time for synchronizing historical data, including start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional | Long.MIN_VALUE | +| source.history.end-time | The end event time for synchronizing historical data, including end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional | Long.MAX_VALUE | +| source.realtime.mode | Extraction mode for newly inserted data (after pipe creation) | String: batch | Optional | batch | +| source.forwarding-pipe-requests | Whether to forward data written by other pipes (usually data synchronization) | Boolean: true | Optional | true | +| source.history.loose-range | When transferring tsfile, whether to relax the historical data (before pipe creation) range. "": Do not relax the range, select data strictly according to the set conditions "time": Relax the time range to avoid splitting TsFile, which can improve synchronization efficiency | String: "" / "time" | optional | Empty String | + +> 💎 **Explanation: Difference between Historical Data and Real-time Data** +> - **Historical Data**: All data with arrival time < the current system time when the pipe is created is called historical data. +> - **Real-time Data**:All data with arrival time >= the current system time when the pipe is created is called real-time data. +> - **Full Data**: Full data = Historical data + Real-time data +> +> 💎 **Explanation: Differences between Stream and Batch Data Extraction Modes** +> - **stream (recommended)**: In this mode, tasks process and send data in real-time. It is characterized by high timeliness and low throughput. +> - **batch**: In this mode, tasks process and send data in batches (according to the underlying data files). It is characterized by low timeliness and high throughput. + +### source Parameter(V1.3.1) + +> In versions 1.3.1 and above, the parameters no longer require additional source, processor, and sink prefixes. + +| key | value | value range | required or not | default value | +| :----------------------- | :----------------------------------------------------------- | :------------------------------------- | :------- | :------------- | +| source | iotdb-source | String: iotdb-source | Required | - | +| pattern | Used to filter the path prefix of time series | String: any time series prefix | Optional | root | +| start-time | The start event time for synchronizing all data, including start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MIN_VALUE | +| end-time | The end event time for synchronizing all data, including end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MAX_VALUE | +| realtime.mode | Extraction mode for newly inserted data (after pipe creation) | String: batch | Optional | batch | +| forwarding-pipe-requests | Whether to forward data written by other pipes (usually data synchronization) | Boolean: true | Optional | true | +| history.loose-range | When transferring tsfile, whether to relax the historical data (before pipe creation) range. "": Do not relax the range, select data strictly according to the set conditions "time": Relax the time range to avoid splitting TsFile, which can improve synchronization efficiency | String: "" / "time" | Optional | Empty String | + +> 💎 **Explanation**:To maintain compatibility with lower versions, history.enable, history.start-time, history.end-time, realtime.enable can still be used, but they are not recommended in the new version. +> +> 💎 **Explanation: Differences between Stream and Batch Data Extraction Modes** +> - **stream (recommended)**: In this mode, tasks process and send data in real-time. It is characterized by high timeliness and low throughput. +> - **batch**: In this mode, tasks process and send data in batches (according to the underlying data files). It is characterized by low timeliness and high throughput. + +### source Parameter(V1.3.2) + +> In versions 1.3.1 and above, the parameters no longer require additional source, processor, and sink prefixes. + +| key | value | value range | required or not | default value | +| :----------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | :------- | :------------- | +| source | iotdb-source | String: iotdb-source | Required | - | +| inclusion | Used to specify the range of data to be synchronized in the data synchronization task, including data, schema, and auth | String:all, data(insert,delete), schema(database,timeseries,ttl), auth | Optional | data.insert | +| inclusion.exclusion | Used to exclude specific operations from the range specified by inclusion, reducing the amount of data synchronized | String:all, data(insert,delete), schema(database,timeseries,ttl), auth | Optional | - | +| path | Used to filter the path pattern schema of time series and data to be synchronized / schema synchronization can only use pathpath is exact matching, parameters must be prefix paths or complete paths, i.e., cannot contain `"*"`, at most one `"**"` at the end of the path parameter | String:IoTDB pattern | Optional | root.** | +| pattern | Used to filter the path prefix of time series | String: Optional | Optional | root | +| start-time | The start event time for synchronizing all data, including start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MIN_VALUE | +| end-time | The end event time for synchronizing all data, including end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MAX_VALUE | +| realtime.mode | Extraction mode for newly inserted data (after pipe creation) | String: batch | Optional | batch | +| forwarding-pipe-requests | Whether to forward data written by other pipes (usually data synchronization) | Boolean: true | Optional | true | +| history.loose-range | When transferring tsfile, whether to relax the historical data (before pipe creation) range. "": Do not relax the range, select data strictly according to the set conditions "time": Relax the time range to avoid splitting TsFile, which can improve synchronization efficiency | String: "" 、 "time" | Optional | "" | +| mods.enable | Whether to send the mods file of tsfile | Boolean: true / false | Optional | false | + +> 💎 **Explanation**:To maintain compatibility with lower versions, history.enable, history.start-time, history.end-time, realtime.enable can still be used, but they are not recommended in the new version. +> +> 💎 **Explanation: Differences between Stream and Batch Data Extraction Modes** +> - **stream (recommended)**: In this mode, tasks process and send data in real-time. It is characterized by high timeliness and low throughput. +> - **batch**: In this mode, tasks process and send data in batches (according to the underlying data files). It is characterized by low timeliness and high throughput. + +### sink parameter + +> In versions 1.3.1 and above, the parameters no longer require additional source, processor, and sink prefixes. + +#### iotdb-thrift-sink( V1.3.0/1/2) + + +| key | value | value Range | required or not | Default Value | +| :--------------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | :------- | :----------- | +| sink | iotdb-thrift-sink or iotdb-thrift-async-sink | String: iotdb-thrift-sink or iotdb-thrift-async-sink | Required | | +| sink.node-urls | The URL of the data service port of any DataNode nodes on the target IoTDB (please note that synchronization tasks do not support forwarding to its own service) | String. Example: '127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669', '127.0.0.1:6667' | Required | - | +| sink.batch.enable | Whether to enable batched log transmission mode to improve transmission throughput and reduce IOPS | Boolean: true, false | Optional | true | +| sink.batch.max-delay-seconds | Effective when batched log transmission mode is enabled, it represents the maximum waiting time for a batch of data before sending (unit: s) | Integer | Optional | 1 | +| sink.batch.size-bytes | Effective when batched log transmission mode is enabled, it represents the maximum batch size for a batch of data (unit: byte) | Long | Optional | 16*1024*1024 | + + +#### iotdb-thrift-ssl-sink( V1.3.1/2) + +| key | value | value Range | required or not | Default Value | +| :---------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | :------- | :----------- | +| sink | iotdb-thrift-ssl-sink | String: iotdb-thrift-ssl-sink | Required | - | +| node-urls | The URL of the data service port of any DataNode nodes on the target IoTDB (please note that synchronization tasks do not support forwarding to its own service) | String. Example: '127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669', '127.0.0.1:6667' | Required | - | +| batch.enable | Whether to enable batched log transmission mode to improve transmission throughput and reduce IOPS | Boolean: true, false | Optional | true | +| batch.max-delay-seconds | Effective when batched log transmission mode is enabled, it represents the maximum waiting time for a batch of data before sending (unit: s) | Integer | Optional | 1 | +| batch.size-bytes | Effective when batched log transmission mode is enabled, it represents the maximum batch size for a batch of data (unit: byte) | Long | Optional | 16*1024*1024 | +| ssl.trust-store-path | The trust store certificate path required to connect to the target DataNode | String: certificate directory name, when configured as a relative directory, it is relative to the IoTDB root directory. Example: '127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669', '127.0.0.1:6667'| Required | - | +| ssl.trust-store-pwd | The trust store certificate password required to connect to the target DataNode | Integer | Required | - | + diff --git a/src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_timecho.md b/src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_timecho.md new file mode 100644 index 000000000..47671ea71 --- /dev/null +++ b/src/UserGuide/V1.3.x/User-Manual/Data-Sync-old_timecho.md @@ -0,0 +1,613 @@ + + +# Data Sync + +Data synchronization is a typical requirement in industrial Internet of Things (IoT). Through data synchronization mechanisms, it is possible to achieve data sharing between IoTDB, and to establish a complete data link to meet the needs for internal and external network data interconnectivity, edge-cloud synchronization, data migration, and data backup. + +## Function Overview + +### Data Synchronization + +A data synchronization task consists of three stages: + +![](/img/sync_en_01.png) + +- Source Stage:This part is used to extract data from the source IoTDB, defined in the source section of the SQL statement. +- Process Stage:This part is used to process the data extracted from the source IoTDB, defined in the processor section of the SQL statement. +- Sink Stage:This part is used to send data to the target IoTDB, defined in the sink section of the SQL statement. + +By declaratively configuring the specific content of the three parts through SQL statements, flexible data synchronization capabilities can be achieved. Currently, data synchronization supports the synchronization of the following information, and you can select the synchronization scope when creating a synchronization task (the default is data.insert, which means synchronizing newly written data): + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Synchronization ScopeSynchronization Content Description
allAll scopes
data(Data)insertSynchronize newly written data
deleteSynchronize deleted data
schemadatabaseSynchronize database creation, modification or deletion operations
timeseriesSynchronize the definition and attributes of time series
TTLSynchronize the data retention time
auth-Synchronize user permissions and access control
+ +### Functional limitations and instructions + +The schema and auth synchronization functions have the following limitations: + +- When using schema synchronization, it is required that the consensus protocol of `Schema region` and `ConfigNode` must be the default ratis protocol, that is: In the `iotdb-common.properties` configuration file, both the `config_node_consensus_protocol_class` and `schema_region_consensus_protocol_class` configuration items are set to `org.apache.iotdb.consensus.ratis.RatisConsensus`. + +- To prevent potential conflicts, please turn off the automatic creation of metadata on the receiving end when enabling schema synchronization. You can do this by setting the `enable_auto_create_schema` configuration in the `iotdb-common.properties` configuration file to false. + +- When schema synchronization is enabled, the use of custom plugins is not supported. + +- In a dual-active cluster, schema synchronization should avoid simultaneous operations on both ends. + +- During data synchronization tasks, please avoid performing any deletion operations to prevent inconsistent states between the two ends. + +## Usage Instructions + +Data synchronization tasks have three states: RUNNING, STOPPED, and DROPPED. The task state transitions are shown in the following diagram: + + +V1.3.0 and earlier versions: + +After creation, it will not start immediately and needs to execute the `START PIPE` statement to start the task. + +![](/img/sync_en_02.png) + +V1.3.1 and later versions: + +After creation, the task will start directly, and when the task stops abnormally, the system will automatically attempt to restart the task. + +![](/img/Data-Sync02.png) + +Provide the following SQL statements for state management of synchronization tasks. + +### Create Task + +Use the `CREATE PIPE` statement to create a data synchronization task. The `PipeId` and `sink` attributes are required, while `source` and `processor` are optional. When entering the SQL, note that the order of the `SOURCE` and `SINK` plugins cannot be swapped. + +The SQL example is as follows: + +```SQL +CREATE PIPE -- PipeId is the name that uniquely identifies the task. +-- Data extraction plugin, optional plugin +WITH SOURCE ( + [ = ,], +) +-- Data processing plugin, optional plugin +WITH PROCESSOR ( + [ = ,], +) +-- Data connection plugin, required plugin +WITH SINK ( + [ = ,], +) +``` + +### Start Task + +Start processing data: + +```SQL +START PIPE +``` + +### Stop Task + +Stop processing data: + +```SQL +STOP PIPE +``` + +### Delete Task + +Deletes the specified task: + +```SQL +DROP PIPE +``` + +Deleting a task does not require stopping the synchronization task first. + +### View Task + +View all tasks: + +```SQL +SHOW PIPES +``` + +To view a specified task: + +```SQL +SHOW PIPE +``` + +Example of the show pipes result for a pipe: + +```SQL ++--------------------------------+-----------------------+-------+---------------+--------------------+------------------------------------------------------------+----------------+ +| ID| CreationTime| State| PipeSource| PipeProcessor| PipeSink|ExceptionMessage| ++--------------------------------+-----------------------+-------+---------------+--------------------+------------------------------------------------------------+----------------+ +|3421aacb16ae46249bac96ce4048a220|2024-08-13T09:55:18.717|RUNNING| {}| {}|{{sink=iotdb-thrift-sink, sink.ip=127.0.0.1, sink.port=6668}}| | ++--------------------------------+-----------------------+-------+---------------+--------------------+------------------------------------------------------------+----------------+ +``` + +The meanings of each column are as follows: + +- **ID**:The unique identifier for the synchronization task +- **CreationTime**:The time when the synchronization task was created +- **State**:The state of the synchronization task +- **PipeSource**:The source of the synchronized data stream +- **PipeProcessor**:The processing logic of the synchronized data stream during transmission +- **PipeSink**:The destination of the synchronized data stream +- **ExceptionMessage**:Displays the exception information of the synchronization task + + +### Synchronization Plugins + +To make the overall architecture more flexible to match different synchronization scenario requirements, we support plugin assembly within the synchronization task framework. The system comes with some pre-installed common plugins that you can use directly. At the same time, you can also customize processor plugins and Sink plugins, and load them into the IoTDB system for use. You can view the plugins in the system (including custom and built-in plugins) with the following statement: + +```SQL +SHOW PIPEPLUGINS +``` + +The return result is as follows (version 1.3.2): + +```SQL +IoTDB> SHOW PIPEPLUGINS ++---------------------+----------+-------------------------------------------------------------------------------------------+----------------------------------------------------+ +| PluginName|PluginType| ClassName| PluginJar| ++---------------------+----------+-------------------------------------------------------------------------------------------+----------------------------------------------------+ +| DO-NOTHING-PROCESSOR| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.processor.donothing.DoNothingProcessor| | +| DO-NOTHING-SINK| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.connector.donothing.DoNothingConnector| | +| IOTDB-AIR-GAP-SINK| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.connector.iotdb.airgap.IoTDBAirGapConnector| | +| IOTDB-SOURCE| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.extractor.iotdb.IoTDBExtractor| | +| IOTDB-THRIFT-SINK| Builtin| org.apache.iotdb.commons.pipe.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector| | +|IOTDB-THRIFT-SSL-SINK| Builtin|org.apache.iotdb.commons.pipe.plugin.builtin.connector.iotdb.thrift.IoTDBThriftSslConnector| | ++---------------------+----------+-------------------------------------------------------------------------------------------+----------------------------------------------------+ +``` + +Detailed introduction of pre-installed plugins is as follows (for detailed parameters of each plugin, please refer to the [Parameter Description](#reference-parameter-description) section): + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeCustom PluginPlugin NameDescriptionApplicable Version
source pluginNot Supportediotdb-sourceThe default extractor plugin, used to extract historical or real-time data from IoTDB1.2.x
processor pluginSupporteddo-nothing-processorThe default processor plugin, which does not process the incoming data1.2.x
sink pluginSupporteddo-nothing-sinkDoes not process the data that is sent out1.2.x
iotdb-thrift-sinkThe default sink plugin ( V1.3.1+ ), used for data transfer between IoTDB ( V1.2.0+ ) and IoTDB( V1.2.0+ ) . It uses the Thrift RPC framework to transfer data, with a multi-threaded async non-blocking IO model, high transfer performance, especially suitable for scenarios where the target end is distributed1.2.x
iotdb-air-gap-sinkUsed for data synchronization across unidirectional data diodes from IoTDB ( V1.2.0+ ) to IoTDB ( V1.2.0+ ). Supported diode models include Nanrui Syskeeper 2000, etc1.2.x
iotdb-thrift-ssl-sinkUsed for data transfer between IoTDB ( V1.3.1+ ) and IoTDB ( V1.2.0+ ). It uses the Thrift RPC framework to transfer data, with a single-threaded sync blocking IO model, suitable for scenarios with higher security requirements1.3.1+
+ +For importing custom plugins, please refer to the [Stream Processing](./Streaming_timecho.md#custom-stream-processing-plugin-management) section. + +## Use examples + +### Full data synchronisation + +This example is used to demonstrate the synchronisation of all data from one IoTDB to another IoTDB with the data link as shown below: + +![](/img/pipe1.jpg) + +In this example, we can create a synchronization task named A2B to synchronize the full data from A IoTDB to B IoTDB. The iotdb-thrift-sink plugin (built-in plugin) for the sink is required. The URL of the data service port of the DataNode node on the target IoTDB needs to be configured through node-urls, as shown in the following example statement: + +```SQL +create pipe A2B +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +``` + +### Partial data synchronization + +This example is used to demonstrate the synchronisation of data from a certain historical time range (8:00pm 23 August 2023 to 8:00pm 23 October 2023) to another IoTDB, the data link is shown below: + +![](/img/pipe2.jpg) + +In this example, we can create a synchronization task named A2B. First, we need to define the range of data to be transferred in the source. Since the data being transferred is historical data (historical data refers to data that existed before the creation of the synchronization task), we need to configure the start-time and end-time of the data and the transfer mode mode. The URL of the data service port of the DataNode node on the target IoTDB needs to be configured through node-urls. + +The detailed statements are as follows: + +```SQL +create pipe A2B +WITH SOURCE ( + 'source'= 'iotdb-source', + 'realtime.mode' = 'stream' -- The extraction mode for newly inserted data (after pipe creation) + 'start-time' = '2023.08.23T08:00:00+00:00', -- The start event time for synchronizing all data, including start-time + 'end-time' = '2023.10.23T08:00:00+00:00' -- The end event time for synchronizing all data, including end-time +) +with SINK ( + 'sink'='iotdb-thrift-async-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +``` + +### Bidirectional data transfer + +This example is used to demonstrate the scenario where two IoTDB act as active-active pairs, with the data link shown in the figure below: + +![](/img/pipe3.jpg) + +In this example, to avoid infinite data loops, the `forwarding-pipe-requests` parameter on A and B needs to be set to `false`, indicating that data transmitted from another pipe is not forwarded, and to keep the data consistent on both sides, the pipe needs to be configured with `inclusion=all` to synchronize full data and metadata. + +The detailed statement is as follows: + +On A IoTDB, execute the following statement: + +```SQL +create pipe AB +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'forwarding-pipe-requests' = 'false' -- Do not forward data written by other Pipes +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +``` + +On B IoTDB, execute the following statement: + +```SQL +create pipe BA +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'forwarding-pipe-requests' = 'false' -- Do not forward data written by other Pipes +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6667', -- The URL of the data service port of the DataNode node on the target IoTDB +) +``` + +### Edge-cloud data transfer + +This example is used to demonstrate the scenario where data from multiple IoTDB is transferred to the cloud, with data from clusters B, C, and D all synchronized to cluster A, as shown in the figure below: + +![](/img/sync_en_03.png) + +In this example, to synchronize the data from clusters B, C, and D to A, the pipe between BA, CA, and DA needs to configure the `path` to limit the range, and to keep the edge and cloud data consistent, the pipe needs to be configured with `inclusion=all` to synchronize full data and metadata. The detailed statement is as follows: + +On B IoTDB, execute the following statement to synchronize data from B to A: + +```SQL +create pipe BA +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'path'='root.db.**', -- Limit the range +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +On C IoTDB, execute the following statement to synchronize data from C to A: + +```SQL +create pipe CA +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'path'='root.db.**', -- Limit the range +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +On D IoTDB, execute the following statement to synchronize data from D to A: + +```SQL +create pipe DA +with source ( + 'inclusion'='all', -- Indicates synchronization of full data, schema , and auth + 'path'='root.db.**', -- Limit the range +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +### Cascading data transfer + +This example is used to demonstrate the scenario where data is transferred in a cascading manner between multiple IoTDB, with data from cluster A synchronized to cluster B, and then to cluster C, as shown in the figure below: + +![](/img/sync_en_04.png) + +In this example, to synchronize the data from cluster A to C, the `forwarding-pipe-requests` needs to be set to `true` between BC. The detailed statement is as follows: + +On A IoTDB, execute the following statement to synchronize data from A to B: + +```SQL +create pipe AB +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6668', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +On B IoTDB, execute the following statement to synchronize data from B to C: + +```SQL +create pipe BC +with source ( + 'forwarding-pipe-requests' = 'true' -- Whether to forward data written by other Pipes +) +with sink ( + 'sink'='iotdb-thrift-sink', + 'node-urls' = '127.0.0.1:6669', -- The URL of the data service port of the DataNode node on the target IoTDB +) +) +``` + +### Cross-gate data transfer + +This example is used to demonstrate the scenario where data from one IoTDB is synchronized to another IoTDB through a unidirectional gateway, as shown in the figure below: + +![](/img/pipe5.jpg) + + +In this example, the iotdb-air-gap-sink plugin in the sink task needs to be used (currently supports some gateway models, for specific models, please contact Timecho staff for confirmation). After configuring the gateway, execute the following statement on A IoTDB. Fill in the node-urls with the URL of the data service port of the DataNode node on the target IoTDB configured by the gateway, as detailed below: + +```SQL +create pipe A2B +with sink ( + 'sink'='iotdb-air-gap-sink', + 'node-urls' = '10.53.53.53:9780', -- The URL of the data service port of the DataNode node on the target IoTDB +``` + + +### Encrypted Synchronization (V1.3.1+) + +IoTDB supports the use of SSL encryption during the synchronization process, ensuring the secure transfer of data between different IoTDB instances. By configuring SSL-related parameters, such as the certificate address and password (`ssl.trust-store-path`)、(`ssl.trust-store-pwd`), data can be protected by SSL encryption during the synchronization process. + +For example, to create a synchronization task named A2B: + +```SQL +create pipe A2B +with sink ( + 'sink'='iotdb-thrift-ssl-sink', + 'node-urls'='127.0.0.1:6667', -- The URL of the data service port of the DataNode node on the target IoTDB + 'ssl.trust-store-path'='pki/trusted', -- The trust store certificate path required to connect to the target DataNode + 'ssl.trust-store-pwd'='root' -- The trust store certificate password required to connect to the target DataNode +) +``` + +## Reference: Notes + +You can adjust the parameters for data synchronization by modifying the IoTDB configuration file (`iotdb-common.properties`), such as the directory for storing synchronized data. The complete configuration is as follows: + +V1.3.0/1/2: + +```Properties +#################### +### Pipe Configuration +#################### + +# Uncomment the following field to configure the pipe lib directory. +# For Windows platform +# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is +# absolute. Otherwise, it is relative. +# pipe_lib_dir=ext\\pipe +# For Linux platform +# If its prefix is "/", then the path is absolute. Otherwise, it is relative. +# pipe_lib_dir=ext/pipe + +# The maximum number of threads that can be used to execute the pipe subtasks in PipeSubtaskExecutor. +# The actual value will be min(pipe_subtask_executor_max_thread_num, max(1, CPU core number / 2)). +# pipe_subtask_executor_max_thread_num=5 + +# The connection timeout (in milliseconds) for the thrift client. +# pipe_sink_timeout_ms=900000 + +# The maximum number of selectors that can be used in the sink. +# Recommend to set this value to less than or equal to pipe_sink_max_client_number. +# pipe_sink_selector_number=4 + +# The maximum number of clients that can be used in the sink. +# pipe_sink_max_client_number=16 + +# Whether to enable receiving pipe data through air gap. +# The receiver can only return 0 or 1 in tcp mode to indicate whether the data is received successfully. +# pipe_air_gap_receiver_enabled=false + +# The port for the server to receive pipe data through air gap. +# pipe_air_gap_receiver_port=9780 +``` + +## Reference: parameter description + +### source parameter(V1.3.0) + +| key | value | value range | required or not | default value | +| :------------------------------ | :----------------------------------------------------------- | :------------------------------------- | :------- | :------------- | +| source | iotdb-source | String: iotdb-source | required | - | +| source.pattern | Used to filter the path prefix of time series | String: any time series prefix | optional | root | +| source.history.enable | Whether to send historical data | Boolean: true / false | optional | true | +| source.history.start-time | The start event time for synchronizing historical data, including start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional | Long.MIN_VALUE | +| source.history.end-time | The end event time for synchronizing historical data, including end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional | Long.MAX_VALUE | +| source.realtime.enable | Whether to send real-time data | Boolean: true / false | optional | true | +| source.realtime.mode | The extraction mode for newly inserted data (after pipe creation) | String: stream, batch | optional | stream | +| source.forwarding-pipe-requests | Whether to forward data written by other Pipes (usually data synchronization) | Boolean: true, false | optional | true | +| source.history.loose-range | When transferring tsfile, whether to relax the historical data (before pipe creation) range. "": Do not relax the range, select data strictly according to the set conditions "time": Relax the time range to avoid splitting TsFile, which can improve synchronization efficiency | String: "" / "time" | optional | Empty String | + +> 💎 **Explanation: Difference between Historical Data and Real-time Data** +> - **Historical Data**: All data with arrival time < the current system time when the pipe is created is called historical data. +> - **Real-time Data**:All data with arrival time >= the current system time when the pipe is created is called real-time data. +> - **Full Data**: Full data = Historical data + Real-time data +> +> 💎 **Explanation: Differences between Stream and Batch Data Extraction Modes** +> - **stream (recommended)**: In this mode, tasks process and send data in real-time. It is characterized by high timeliness and low throughput. +> - **batch**: In this mode, tasks process and send data in batches (according to the underlying data files). It is characterized by low timeliness and high throughput. + +### source parameter(V1.3.1) + +> In versions 1.3.1 and above, the parameters no longer require additional source, processor, and sink prefixes. + +| key | value | value range | required or not | default value | +| :----------------------- | :----------------------------------------------------------- | :------------------------------------- | :------- | :------------- | +| source | iotdb-source | String: iotdb-source | Required | - | +| pattern | Used to filter the path prefix of time series | String: any time series prefix | Optional | root | +| start-time | The start event time for synchronizing all data, including start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MIN_VALUE | +| end-time | The end event time for synchronizing all data, including end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MAX_VALUE | +| realtime.mode | The extraction mode for newly inserted data (after pipe creation) | String: stream, batch | Optional | stream | +| forwarding-pipe-requests | Whether to forward data written by other Pipes (usually data synchronization) | Boolean: true, false | Optional | true | +| history.loose-range | When transferring tsfile, whether to relax the historical data (before pipe creation) range. "": Do not relax the range, select data strictly according to the set conditions "time": Relax the time range to avoid splitting TsFile, which can improve synchronization efficiency | String: "" / "time" | Optional | Empty String | + +> 💎 **Explanation**:To maintain compatibility with lower versions, history.enable, history.start-time, history.end-time, realtime.enable can still be used, but they are not recommended in the new version. +> +> 💎 **Explanation: Differences between Stream and Batch Data Extraction Modes** +> - **stream (recommended)**: In this mode, tasks process and send data in real-time. It is characterized by high timeliness and low throughput. +> - **batch**: In this mode, tasks process and send data in batches (according to the underlying data files). It is characterized by low timeliness and high throughput. + +### source parameter(V1.3.2) + +> In versions 1.3.1 and above, the parameters no longer require additional source, processor, and sink prefixes. + +| key | value | value range | required or not | default value | +| :----------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | :------- | :------------- | +| source | iotdb-source | String: iotdb-source | Required | - | +| inclusion | Used to specify the range of data to be synchronized in the data synchronization task, including data, schema, and auth | String:all, data(insert,delete), schema(database,timeseries,ttl), auth | Optional | data.insert | +| inclusion.exclusion | Used to exclude specific operations from the range specified by inclusion, reducing the amount of data synchronized | String:all, data(insert,delete), schema(database,timeseries,ttl), auth | Optional | - | +| path | Used to filter the path pattern schema of time series and data to be synchronized / schema synchronization can only use pathpath is exact matching, parameters must be prefix paths or complete paths, i.e., cannot contain `"*"`, at most one `"**"` at the end of the path parameter | String:IoTDB pattern | Optional | root.** | +| pattern | Used to filter the path prefix of time series | String: Optional | Optional | root | +| start-time | The start event time for synchronizing all data, including start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MIN_VALUE | +| end-time | The end event time for synchronizing all data, including end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | Optional | Long.MAX_VALUE | +| realtime.mode | The extraction mode for newly inserted data (after pipe creation) | String: stream, batch | Optional | stream | +| forwarding-pipe-requests | Whether to forward data written by other Pipes (usually data synchronization) | Boolean: true, false | Optional | true | +| history.loose-range | When transferring tsfile, whether to relax the historical data (before pipe creation) range. "": Do not relax the range, select data strictly according to the set conditions "time": Relax the time range to avoid splitting TsFile, which can improve synchronization efficiency | String: "" 、 "time" | Optional | "" | +| mods.enable | Whether to send the mods file of tsfile | Boolean: true / false | Optional | false | + +> 💎 **Explanation**:To maintain compatibility with lower versions, history.enable, history.start-time, history.end-time, realtime.enable can still be used, but they are not recommended in the new version. +> +> 💎 **Explanation: Differences between Stream and Batch Data Extraction Modes** +> - **stream (recommended)**: In this mode, tasks process and send data in real-time. It is characterized by high timeliness and low throughput. +> - **batch**: In this mode, tasks process and send data in batches (according to the underlying data files). It is characterized by low timeliness and high throughput. + +### sink parameter + +> In versions 1.3.1 and above, the parameters no longer require additional source, processor, and sink prefixes. + +#### iotdb-thrift-sink( V1.3.0/1/2) + + +| key | value | value Range | required or not | Default Value | +| :--------------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | :------- | :----------- | +| sink | iotdb-thrift-sink or iotdb-thrift-async-sink | String: iotdb-thrift-sink or iotdb-thrift-async-sink | Required | | +| sink.node-urls | The URL of the data service port of any DataNode nodes on the target IoTDB (please note that synchronization tasks do not support forwarding to its own service) | String. Example: '127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669', '127.0.0.1:6667' | Required | - | +| sink.batch.enable | Whether to enable batched log transmission mode to improve transmission throughput and reduce IOPS | Boolean: true, false | Optional | true | +| sink.batch.max-delay-seconds | Effective when batched log transmission mode is enabled, it represents the maximum waiting time for a batch of data before sending (unit: s) | Integer | Optional | 1 | +| sink.batch.size-bytes | Effective when batched log transmission mode is enabled, it represents the maximum batch size for a batch of data (unit: byte) | Long | Optional | 16*1024*1024 | + +#### iotdb-air-gap-sink( V1.3.0/1/2) + +| key | value | value Range | required or not | Default Value | +| :--------------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | :------- | :----------- | +| sink | iotdb-air-gap-sink | String: iotdb-air-gap-sink | Required | - | +| sink.node-urls | The URL of the data service port of any DataNode nodes on the target IoTDB | String. Example: :'127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669', '127.0.0.1:6667' | Required | - | +| sink.air-gap.handshake-timeout-ms | The timeout duration of the handshake request when the sender and receiver first attempt to establish a connection, unit: ms | Integer | Optional | 5000 | + + +#### iotdb-thrift-ssl-sink( V1.3.1/2) + +| key | value | value Range | required or not | Default Value | +| :---------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- | :------- | :----------- | +| sink | iotdb-thrift-ssl-sink | String: iotdb-thrift-ssl-sink | Required | - | +| node-urls | The URL of the data service port of any DataNode nodes on the target IoTDB (please note that synchronization tasks do not support forwarding to its own service) | String. Example: '127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669', '127.0.0.1:6667' | Required | - | +| batch.enable | Whether to enable batched log transmission mode to improve transmission throughput and reduce IOPS | Boolean: true, false | Optional | true | +| batch.max-delay-seconds | Effective when batched log transmission mode is enabled, it represents the maximum waiting time for a batch of data before sending (unit: s) | Integer | Optional | 1 | +| batch.size-bytes | Effective when batched log transmission mode is enabled, it represents the maximum batch size for a batch of data (unit: byte) | Long | Optional | 16*1024*1024 | +| ssl.trust-store-path | The trust store certificate path required to connect to the target DataNode | String: certificate directory name, when configured as a relative directory, it is relative to the IoTDB root directory. Example: '127.0.0.1:6667,127.0.0.1:6668,127.0.0.1:6669', '127.0.0.1:6667'| Required | - | +| ssl.trust-store-pwd | The trust store certificate password required to connect to the target DataNode | Integer | Required | - | diff --git a/src/UserGuide/V1.3.3/User-Manual/Data-Sync_apache.md b/src/UserGuide/V1.3.x/User-Manual/Data-Sync_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Data-Sync_apache.md rename to src/UserGuide/V1.3.x/User-Manual/Data-Sync_apache.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Data-Sync_timecho.md b/src/UserGuide/V1.3.x/User-Manual/Data-Sync_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Data-Sync_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/Data-Sync_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Data-subscription.md b/src/UserGuide/V1.3.x/User-Manual/Data-subscription.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Data-subscription.md rename to src/UserGuide/V1.3.x/User-Manual/Data-subscription.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Database-Programming.md b/src/UserGuide/V1.3.x/User-Manual/Database-Programming.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Database-Programming.md rename to src/UserGuide/V1.3.x/User-Manual/Database-Programming.md diff --git a/src/UserGuide/V1.3.3/User-Manual/IoTDB-View_timecho.md b/src/UserGuide/V1.3.x/User-Manual/IoTDB-View_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/IoTDB-View_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/IoTDB-View_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Load-Balance.md b/src/UserGuide/V1.3.x/User-Manual/Load-Balance.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Load-Balance.md rename to src/UserGuide/V1.3.x/User-Manual/Load-Balance.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Query-Performance-Analysis.md b/src/UserGuide/V1.3.x/User-Manual/Query-Performance-Analysis.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Query-Performance-Analysis.md rename to src/UserGuide/V1.3.x/User-Manual/Query-Performance-Analysis.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Streaming_apache.md b/src/UserGuide/V1.3.x/User-Manual/Streaming_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Streaming_apache.md rename to src/UserGuide/V1.3.x/User-Manual/Streaming_apache.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Streaming_timecho.md b/src/UserGuide/V1.3.x/User-Manual/Streaming_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Streaming_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/Streaming_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Tiered-Storage_timecho.md b/src/UserGuide/V1.3.x/User-Manual/Tiered-Storage_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Tiered-Storage_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/Tiered-Storage_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/Trigger.md b/src/UserGuide/V1.3.x/User-Manual/Trigger.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/Trigger.md rename to src/UserGuide/V1.3.x/User-Manual/Trigger.md diff --git a/src/UserGuide/V1.3.3/User-Manual/UDF-development.md b/src/UserGuide/V1.3.x/User-Manual/UDF-development.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/UDF-development.md rename to src/UserGuide/V1.3.x/User-Manual/UDF-development.md diff --git a/src/UserGuide/V1.3.3/User-Manual/User-defined-function_apache.md b/src/UserGuide/V1.3.x/User-Manual/User-defined-function_apache.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/User-defined-function_apache.md rename to src/UserGuide/V1.3.x/User-Manual/User-defined-function_apache.md diff --git a/src/UserGuide/V1.3.3/User-Manual/User-defined-function_timecho.md b/src/UserGuide/V1.3.x/User-Manual/User-defined-function_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/User-defined-function_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/User-defined-function_timecho.md diff --git a/src/UserGuide/V1.3.3/User-Manual/White-List_timecho.md b/src/UserGuide/V1.3.x/User-Manual/White-List_timecho.md similarity index 100% rename from src/UserGuide/V1.3.3/User-Manual/White-List_timecho.md rename to src/UserGuide/V1.3.x/User-Manual/White-List_timecho.md diff --git a/src/UserGuide/V1.3.3/UserGuideReadme.md b/src/UserGuide/V1.3.x/UserGuideReadme.md similarity index 100% rename from src/UserGuide/V1.3.3/UserGuideReadme.md rename to src/UserGuide/V1.3.x/UserGuideReadme.md diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-Cpp-Native-API.md b/src/zh/UserGuide/V1.3.0-2/API/Programming-Cpp-Native-API.md deleted file mode 100644 index ba499ff45..000000000 --- a/src/zh/UserGuide/V1.3.0-2/API/Programming-Cpp-Native-API.md +++ /dev/null @@ -1,433 +0,0 @@ - - -# C++ 原生接口 - -## 依赖 - -- Java 8+ -- Flex -- Bison 2.7+ -- Boost 1.56+ -- OpenSSL 1.0+ -- GCC 5.5.0+ - - -## 安装 - -### 安装相关依赖 - -- **MAC** -1. 安装 Bison : - - 使用下面 brew 命令安装 bison 版本: - ```shell - brew install bison - ``` - -2. 安装 Boost :确保安装最新的 Boost 版本。 - - ```shell - brew install boost - ``` - -3. 检查 OpenSSL :确保 openssl 库已安装,默认的 openssl 头文件路径为"/usr/local/opt/openssl/include" - - 如果在编译过程中出现找不到 openssl 的错误,尝试添加`-Dopenssl.include.dir=""` - - -- **Ubuntu 16.04+ 或其他 Debian 系列** - - 使用以下命令安装所赖: - - ```shell - sudo apt-get update - sudo apt-get install gcc g++ bison flex libboost-all-dev libssl-dev - ``` - - -- **CentOS 7.7+/Fedora/Rocky Linux 或其他 Red-hat 系列** - - 使用 yum 命令安装依赖: - - ```shell - sudo yum update - sudo yum install gcc gcc-c++ boost-devel bison flex openssl-devel - ``` - - -- **Windows** - -1. 构建编译环境 - - 安装 MS Visual Studio(推荐安装 2019+ 版本):安装时需要勾选 Visual Studio C/C++ IDE and compiler(supporting CMake, Clang, MinGW)。 - - 下载安装 [CMake](https://cmake.org/download/) - -2. 下载安装 Flex、Bison - - 下载 [Win_Flex_Bison](https://sourceforge.net/projects/winflexbison/) - - 下载后需要将可执行文件重命名为 flex.exe 和 bison.exe 以保证编译时能够被找到,添加可执行文件的目录到 PATH 环境变量中。 - -3. 安装 Boost 库 - - 下载 [Boost](https://www.boost.org/users/download/) - - 本地编译 Boost :依次执行 bootstrap.bat 和 b2.exe - - 添加 Boost 安装目录到 PATH 环境变量中,例如 `C:\Program Files (x86)\boost_1_78_0` - -4. 安装 OpenSSL - - 下载安装 [OpenSSL](http://slproweb.com/products/Win32OpenSSL.html) - - 添加 OpenSSL 下的 include 目录到 PATH 环境变量中。 - - - -### 执行编译 - -从 git 克隆源代码: -```shell -git clone https://github.com/apache/iotdb.git -``` - -默认的主分支是 master 分支,如果你想使用某个发布版本,请切换分支 (如 1.3.2 版本): -```shell -git checkout rc/1.3.2 -``` - -在 IoTDB 根目录下执行 maven 编译: - -- Mac 或 glibc 版本 >= 2.32 的 Linux - ```shell - ./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp - ``` - -- glibc 版本 >= 2.31 的 Linux - ```shell - ./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Diotdb-tools-thrift.version=0.14.1.1-old-glibc-SNAPSHOT - ``` - -- glibc 版本 >= 2.17 的 Linux - ```shell - ./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Diotdb-tools-thrift.version=0.14.1.1-glibc223-SNAPSHOT - ``` - -- 使用 Visual Studio 2022 的 Windows - ```batch - .\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp - ``` - -- 使用 Visual Studio 2019 的 Windows - ```batch - .\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Dcmake.generator="Visual Studio 16 2019" -Diotdb-tools-thrift.version=0.14.1.1-msvc142-SNAPSHOT - ``` - - 如果没有将 Boost 库地址加入 PATH 环境变量,在编译命令中还需添加相关参数,例如:`-DboostIncludeDir="C:\Program Files (x86)\boost_1_78_0" -DboostLibraryDir="C:\Program Files (x86)\boost_1_78_0\stage\lib"` - -编译成功后,打包好的库文件位于 `iotdb-client/client-cpp/target` 中,同时可以在 `example/client-cpp-example/target` 下找到编译好的示例程序。 - -### 编译 Q&A - -Q:Linux 上的环境有哪些要求呢? - -A: -- 已知依赖的 glibc (x86_64 版本) 最低版本要求为 2.17,GCC 最低版本为 5.5 -- 已知依赖的 glibc (ARM 版本) 最低版本要求为 2.31,GCC 最低版本为 10.2 -- 如果不满足上面的要求,可以尝试自己本地编译 Thrift - - 下载 https://github.com/apache/iotdb-bin-resources/tree/iotdb-tools-thrift-v0.14.1.0/iotdb-tools-thrift 这里的代码 - - 执行 `./mvnw clean install` - - 回到 iotdb 代码目录执行 `./mvnw clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp` - - -Q:Linux 编译报错`undefined reference to '_libc_sinle_thread'`如何处理? - -A: -- 该问题是用于默认的预编译 Thrift 依赖了过高的 glibc 版本导致的 -- 可以尝试在编译的 maven 命令中增加 `-Diotdb-tools-thrift.version=0.14.1.1-glibc223-SNAPSHOT` 或者 `-Diotdb-tools-thrift.version=0.14.1.1-old-glibc-SNAPSHOT` - -Q:如果在 Windows 上需要使用 Visual Studio 2017 或更早版本进行编译,要怎么做? - -A: -- 可以尝试自己本地编译 Thrift 后再进行客户端的编译 - - 下载 https://github.com/apache/iotdb-bin-resources/tree/iotdb-tools-thrift-v0.14.1.0/iotdb-tools-thrift 这里的代码 - - 执行 `.\mvnw.cmd clean install` - - 回到 iotdb 代码目录执行 `.\mvnw.cmd clean package -pl example/client-cpp-example -am -DskipTests -P with-cpp -Dcmake.generator="Visual Studio 15 2017"` - - -## 基本接口说明 - -下面将给出 Session 接口的简要介绍和原型定义: - -### 初始化 - -- 开启 Session -```cpp -void open(); -``` - -- 开启 Session,并决定是否开启 RPC 压缩 -```cpp -void open(bool enableRPCCompression); -``` - 注意: 客户端的 RPC 压缩开启状态需和服务端一致。 - -- 关闭 Session -```cpp -void close(); -``` - -### 数据定义接口(DDL) - -#### Database 管理 - -- 设置 database -```cpp -void setStorageGroup(const std::string &storageGroupId); -``` - -- 删除单个或多个 database -```cpp -void deleteStorageGroup(const std::string &storageGroup); -void deleteStorageGroups(const std::vector &storageGroups); -``` - -#### 时间序列管理 - -- 创建单个或多个非对齐时间序列 -```cpp -void createTimeseries(const std::string &path, TSDataType::TSDataType dataType, TSEncoding::TSEncoding encoding, - CompressionType::CompressionType compressor); - -void createMultiTimeseries(const std::vector &paths, - const std::vector &dataTypes, - const std::vector &encodings, - const std::vector &compressors, - std::vector> *propsList, - std::vector> *tagsList, - std::vector> *attributesList, - std::vector *measurementAliasList); -``` - -- 创建对齐时间序列 -```cpp -void createAlignedTimeseries(const std::string &deviceId, - const std::vector &measurements, - const std::vector &dataTypes, - const std::vector &encodings, - const std::vector &compressors); -``` - -- 删除一个或多个时间序列 -```cpp -void deleteTimeseries(const std::string &path); -void deleteTimeseries(const std::vector &paths); -``` - -- 检查时间序列是否存在 -```cpp -bool checkTimeseriesExists(const std::string &path); -``` - -#### 元数据模版 - -- 创建元数据模板 -```cpp -void createSchemaTemplate(const Template &templ); -``` - -- 挂载元数据模板 -```cpp -void setSchemaTemplate(const std::string &template_name, const std::string &prefix_path); -``` -请注意,如果一个子树中有多个孩子节点需要使用模板,可以在其共同父母节点上使用 setSchemaTemplate 。而只有在已有数据点插入模板对应的物理量时,模板才会被设置为激活状态,进而被 show timeseries 等查询检测到。 - -- 卸载元数据模板 -```cpp -void unsetSchemaTemplate(const std::string &prefix_path, const std::string &template_name); -``` -注意:目前不支持从曾经在`prefixPath`路径及其后代节点使用模板插入数据后(即使数据已被删除)卸载模板。 - -- 在创建概念元数据模板以后,还可以通过以下接口增加或删除模板内的物理量。请注意,已经挂载的模板不能删除内部的物理量。 -```cpp -// 为指定模板新增一组对齐的物理量,若其父节点在模板中已经存在,且不要求对齐,则报错 -void addAlignedMeasurementsInTemplate(const std::string &template_name, - const std::vector &measurements, - const std::vector &dataTypes, - const std::vector &encodings, - const std::vector &compressors); - -// 为指定模板新增一个对齐物理量, 若其父节点在模板中已经存在,且不要求对齐,则报错 -void addAlignedMeasurementsInTemplate(const std::string &template_name, - const std::string &measurement, - TSDataType::TSDataType dataType, - TSEncoding::TSEncoding encoding, - CompressionType::CompressionType compressor); - -// 为指定模板新增一个不对齐物理量, 若其父节在模板中已经存在,且要求对齐,则报错 -void addUnalignedMeasurementsInTemplate(const std::string &template_name, - const std::vector &measurements, - const std::vector &dataTypes, - const std::vector &encodings, - const std::vector &compressors); - -// 为指定模板新增一组不对齐的物理量, 若其父节在模板中已经存在,且要求对齐,则报错 -void addUnalignedMeasurementsInTemplate(const std::string &template_name, - const std::string &measurement, - TSDataType::TSDataType dataType, - TSEncoding::TSEncoding encoding, - CompressionType::CompressionType compressor); - -// 从指定模板中删除一个节点及其子树 -void deleteNodeInTemplate(const std::string &template_name, const std::string &path); -``` - -- 对于已经创建的元数据模板,还可以通过以下接口查询模板信息: -```cpp -// 查询返回目前模板中所有物理量的数量 -int countMeasurementsInTemplate(const std::string &template_name); - -// 检查模板内指定路径是否为物理量 -bool isMeasurementInTemplate(const std::string &template_name, const std::string &path); - -// 检查在指定模板内是否存在某路径 -bool isPathExistInTemplate(const std::string &template_name, const std::string &path); - -// 返回指定模板内所有物理量的路径 -std::vector showMeasurementsInTemplate(const std::string &template_name); - -// 返回指定模板内某前缀路径下的所有物理量的路径 -std::vector showMeasurementsInTemplate(const std::string &template_name, const std::string &pattern); -``` - - -### 数据操作接口(DML) - -#### 数据写入 - -> 推荐使用 insertTablet 帮助提高写入效率。 - -- 插入一个 Tablet,Tablet 是一个设备若干行数据块,每一行的列都相同。 - - 写入效率高。 - - 支持写入空值:空值处可以填入任意值,然后通过 BitMap 标记空值。 -```cpp -void insertTablet(Tablet &tablet); -``` - -- 插入多个 Tablet -```cpp -void insertTablets(std::unordered_map &tablets); -``` - -- 插入一个 Record,一个 Record 是一个设备一个时间戳下多个测点的数据 -```cpp -void insertRecord(const std::string &deviceId, int64_t time, const std::vector &measurements, - const std::vector &types, const std::vector &values); -``` - -- 插入多个 Record -```cpp -void insertRecords(const std::vector &deviceIds, - const std::vector ×, - const std::vector> &measurementsList, - const std::vector> &typesList, - const std::vector> &valuesList); -``` - -- 插入同属于一个 device 的多个 Record -```cpp -void insertRecordsOfOneDevice(const std::string &deviceId, - std::vector ×, - std::vector> &measurementsList, - std::vector> &typesList, - std::vector> &valuesList); -``` - -#### 带有类型推断的写入 - -服务器需要做类型推断,可能会有额外耗时,速度较无需类型推断的写入慢。 - -```cpp -void insertRecord(const std::string &deviceId, int64_t time, const std::vector &measurements, - const std::vector &values); - - -void insertRecords(const std::vector &deviceIds, - const std::vector ×, - const std::vector> &measurementsList, - const std::vector> &valuesList); - - -void insertRecordsOfOneDevice(const std::string &deviceId, - std::vector ×, - std::vector> &measurementsList, - const std::vector> &valuesList); -``` - -#### 对齐时间序列写入 - -对齐时间序列的写入使用 insertAlignedXXX 接口,其余与上述接口类似: - -- insertAlignedRecord -- insertAlignedRecords -- insertAlignedRecordsOfOneDevice -- insertAlignedTablet -- insertAlignedTablets - -#### 数据删除 - -- 删除一个或多个时间序列在某个时间范围的数据 -```cpp -void deleteData(const std::string &path, int64_t endTime); -void deleteData(const std::vector &paths, int64_t endTime); -void deleteData(const std::vector &paths, int64_t startTime, int64_t endTime); -``` - -### IoTDB-SQL 接口 - -- 执行查询语句 -```cpp -unique_ptr executeQueryStatement(const std::string &sql); -``` - -- 执行非查询语句 -```cpp -void executeNonQueryStatement(const std::string &sql); -``` - - -## 示例代码 - -示例工程源代码: - -- `example/client-cpp-example/src/SessionExample.cpp` -- `example/client-cpp-example/src/AlignedTimeseriesSessionExample.cpp` (使用对齐时间序列) - -编译成功后,示例代码工程位于 `example/client-cpp-example/target` - -## FAQ - -### Thrift 编译相关问题 - -1. MAC:本地 Maven 编译 Thrift 时如出现以下链接的问题,可以尝试将 xcode-commandline 版本从 12 降低到 11.5 - https://stackoverflow.com/questions/63592445/ld-unsupported-tapi-file-type-tapi-tbd-in-yaml-file/65518087#65518087 - - -2. Windows:Maven 编译 Thrift 时需要使用 wget 下载远端文件,可能出现以下报错: - ``` - Failed to delete cached file C:\Users\Administrator\.m2\repository\.cache\download-maven-plugin\index.ser - ``` - - 解决方法: - - 尝试删除 ".m2\repository\\.cache\" 目录并重试。 - - 在添加 pom 文件对应的 download-maven-plugin 中添加 "\true\" diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-JDBC.md b/src/zh/UserGuide/V1.3.0-2/API/Programming-JDBC.md deleted file mode 100644 index 7b8e93650..000000000 --- a/src/zh/UserGuide/V1.3.0-2/API/Programming-JDBC.md +++ /dev/null @@ -1,208 +0,0 @@ - - -# JDBC (不推荐) - -*注意: 目前的JDBC实现仅是为与第三方工具连接使用的。使用JDBC(执行插入语句时)无法提供高性能写入。 -对于Java应用,我们推荐使用[Java 原生接口](./Programming-Java-Native-API.md)* - -## 依赖 - -* JDK >= 1.8 -* Maven >= 3.6 - -## 安装方法 - -在根目录下执行下面的命令: -```shell -mvn clean install -pl iotdb-client/jdbc -am -DskipTests -``` - -### 在 MAVEN 中使用 IoTDB JDBC - -```xml - - - org.apache.iotdb - iotdb-jdbc - 1.3.1 - - -``` - -### 示例代码 - -本章提供了如何建立数据库连接、执行 SQL 和显示查询结果的示例。 - -要求您已经在工程中包含了数据库编程所需引入的包和 JDBC class. - -**注意:为了更快地插入,建议使用 executeBatch()** - -```java -import java.sql.*; -import org.apache.iotdb.jdbc.IoTDBSQLException; - -public class JDBCExample { - /** - * Before executing a SQL statement with a Statement object, you need to create a Statement object using the createStatement() method of the Connection object. - * After creating a Statement object, you can use its execute() method to execute a SQL statement - * Finally, remember to close the 'statement' and 'connection' objects by using their close() method - * For statements with query results, we can use the getResultSet() method of the Statement object to get the result set. - */ - public static void main(String[] args) throws SQLException { - Connection connection = getConnection(); - if (connection == null) { - System.out.println("get connection defeat"); - return; - } - Statement statement = connection.createStatement(); - //Create database - try { - statement.execute("CREATE DATABASE root.demo"); - }catch (IoTDBSQLException e){ - System.out.println(e.getMessage()); - } - - //SHOW DATABASES - statement.execute("SHOW DATABASES"); - outputResult(statement.getResultSet()); - - //Create time series - //Different data type has different encoding methods. Here use INT32 as an example - try { - statement.execute("CREATE TIMESERIES root.demo.s0 WITH DATATYPE=INT32,ENCODING=RLE;"); - }catch (IoTDBSQLException e){ - System.out.println(e.getMessage()); - } - //Show time series - statement.execute("SHOW TIMESERIES root.demo"); - outputResult(statement.getResultSet()); - //Show devices - statement.execute("SHOW DEVICES"); - outputResult(statement.getResultSet()); - //Count time series - statement.execute("COUNT TIMESERIES root"); - outputResult(statement.getResultSet()); - //Count nodes at the given level - statement.execute("COUNT NODES root LEVEL=3"); - outputResult(statement.getResultSet()); - //Count timeseries group by each node at the given level - statement.execute("COUNT TIMESERIES root GROUP BY LEVEL=3"); - outputResult(statement.getResultSet()); - - - //Execute insert statements in batch - statement.addBatch("insert into root.demo(timestamp,s0) values(1,1);"); - statement.addBatch("insert into root.demo(timestamp,s0) values(2,15);"); - statement.addBatch("insert into root.demo(timestamp,s0) values(2,17);"); - statement.addBatch("insert into root.demo(timestamp,s0) values(4,12);"); - statement.executeBatch(); - statement.clearBatch(); - - //Full query statement - String sql = "select * from root.demo"; - ResultSet resultSet = statement.executeQuery(sql); - System.out.println("sql: " + sql); - outputResult(resultSet); - - //Exact query statement - sql = "select s0 from root.demo where time = 4;"; - resultSet= statement.executeQuery(sql); - System.out.println("sql: " + sql); - outputResult(resultSet); - - //Time range query - sql = "select s0 from root.demo where time >= 2 and time < 5;"; - resultSet = statement.executeQuery(sql); - System.out.println("sql: " + sql); - outputResult(resultSet); - - //Aggregate query - sql = "select count(s0) from root.demo;"; - resultSet = statement.executeQuery(sql); - System.out.println("sql: " + sql); - outputResult(resultSet); - - //Delete time series - statement.execute("delete timeseries root.demo.s0"); - - //close connection - statement.close(); - connection.close(); - } - - public static Connection getConnection() { - // JDBC driver name and database URL - String driver = "org.apache.iotdb.jdbc.IoTDBDriver"; - String url = "jdbc:iotdb://127.0.0.1:6667/"; - // set rpc compress mode - // String url = "jdbc:iotdb://127.0.0.1:6667?rpc_compress=true"; - - // Database credentials - String username = "root"; - String password = "root"; - - Connection connection = null; - try { - Class.forName(driver); - connection = DriverManager.getConnection(url, username, password); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } - return connection; - } - - /** - * This is an example of outputting the results in the ResultSet - */ - private static void outputResult(ResultSet resultSet) throws SQLException { - if (resultSet != null) { - System.out.println("--------------------------"); - final ResultSetMetaData metaData = resultSet.getMetaData(); - final int columnCount = metaData.getColumnCount(); - for (int i = 0; i < columnCount; i++) { - System.out.print(metaData.getColumnLabel(i + 1) + " "); - } - System.out.println(); - while (resultSet.next()) { - for (int i = 1; ; i++) { - System.out.print(resultSet.getString(i)); - if (i < columnCount) { - System.out.print(", "); - } else { - System.out.println(); - break; - } - } - } - System.out.println("--------------------------\n"); - } - } -} -``` - -可以在 url 中指定 version 参数: -```java -String url = "jdbc:iotdb://127.0.0.1:6667?version=V_1_0"; -``` -version 表示客户端使用的 SQL 语义版本,用于升级 0.13 时兼容 0.12 的 SQL 语义,可能取值有:`V_0_12`、`V_0_13`、`V_1_0`。 diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-Java-Native-API.md b/src/zh/UserGuide/V1.3.0-2/API/Programming-Java-Native-API.md deleted file mode 100644 index d21862b19..000000000 --- a/src/zh/UserGuide/V1.3.0-2/API/Programming-Java-Native-API.md +++ /dev/null @@ -1,501 +0,0 @@ - - -# Java 原生接口 - -## 安装 - -### 依赖 - -* JDK >= 1.8 -* Maven >= 3.6 - - - -### 在 MAVEN 中使用原生接口 - -```xml - - - org.apache.iotdb - iotdb-session - ${project.version} - - -``` - -## 语法说明 - - - 对于 IoTDB-SQL 接口:传入的 SQL 参数需要符合 [语法规范](../User-Manual/Syntax-Rule.md#字面值常量) ,并且针对 JAVA 字符串进行反转义,如双引号前需要加反斜杠。(即:经 JAVA 转义之后与命令行执行的 SQL 语句一致。) - - 对于其他接口: - - 经参数传入的路径或路径前缀中的节点: 在 SQL 语句中需要使用反引号(`)进行转义的,此处均需要进行转义。 - - 经参数传入的标识符(如模板名):在 SQL 语句中需要使用反引号(`)进行转义的,均可以不用进行转义。 - - 语法说明相关代码示例可以参考:`example/session/src/main/java/org/apache/iotdb/SyntaxConventionRelatedExample.java` - -## 基本接口说明 - -下面将给出 Session 对应的接口的简要介绍和对应参数: - -### 初始化 - -* 初始化 Session - -``` java -// 全部使用默认配置 -session = new Session.Builder.build(); - -// 指定一个可连接节点 -session = - new Session.Builder() - .host(String host) - .port(int port) - .build(); - -// 指定多个可连接节点 -session = - new Session.Builder() - .nodeUrls(List nodeUrls) - .build(); - -// 其他配置项 -session = - new Session.Builder() - .fetchSize(int fetchSize) - .username(String username) - .password(String password) - .thriftDefaultBufferSize(int thriftDefaultBufferSize) - .thriftMaxFrameSize(int thriftMaxFrameSize) - .enableRedirection(boolean enableRedirection) - .version(Version version) - .build(); -``` - -其中,version 表示客户端使用的 SQL 语义版本,用于升级 0.13 时兼容 0.12 的 SQL 语义,可能取值有:`V_0_12`、`V_0_13`、`V_1_0`。 - - -* 开启 Session - -``` java -void open() -``` - -* 开启 Session,并决定是否开启 RPC 压缩 - -``` java -void open(boolean enableRPCCompression) -``` - -注意: 客户端的 RPC 压缩开启状态需和服务端一致 - -* 关闭 Session - -``` java -void close() -``` - -### 数据定义接口 DDL - -#### Database 管理 - -* 设置 database - -``` java -void setStorageGroup(String storageGroupId) -``` - -* 删除单个或多个 database - -``` java -void deleteStorageGroup(String storageGroup) -void deleteStorageGroups(List storageGroups) -``` -#### 时间序列管理 - -* 创建单个或多个时间序列 - -``` java -void createTimeseries(String path, TSDataType dataType, - TSEncoding encoding, CompressionType compressor, Map props, - Map tags, Map attributes, String measurementAlias) - -void createMultiTimeseries(List paths, List dataTypes, - List encodings, List compressors, - List> propsList, List> tagsList, - List> attributesList, List measurementAliasList) -``` - -* 创建对齐时间序列 - -``` -void createAlignedTimeseries(String prefixPath, List measurements, - List dataTypes, List encodings, - List compressors, List measurementAliasList); -``` - -注意:目前**暂不支持**使用传感器别名。 - -* 删除一个或多个时间序列 - -``` java -void deleteTimeseries(String path) -void deleteTimeseries(List paths) -``` - -* 检测时间序列是否存在 - -``` java -boolean checkTimeseriesExists(String path) -``` - -#### 元数据模版 - -* 创建元数据模板,可以通过先后创建 Template、MeasurementNode 的对象,描述模板内物理量结构与类型、编码方式、压缩方式等信息,并通过以下接口创建模板 - -``` java -public void createSchemaTemplate(Template template); - -Class Template { - private String name; - private boolean directShareTime; - Map children; - public Template(String name, boolean isShareTime); - - public void addToTemplate(Node node); - public void deleteFromTemplate(String name); - public void setShareTime(boolean shareTime); -} - -Abstract Class Node { - private String name; - public void addChild(Node node); - public void deleteChild(Node node); -} - -Class MeasurementNode extends Node { - TSDataType dataType; - TSEncoding encoding; - CompressionType compressor; - public MeasurementNode(String name, - TSDataType dataType, - TSEncoding encoding, - CompressionType compressor); -} -``` - -通过上述类的实例描述模板时,Template 内应当仅能包含单层的 MeasurementNode,具体可以参见如下示例: - -``` java -MeasurementNode nodeX = new MeasurementNode("x", TSDataType.FLOAT, TSEncoding.RLE, CompressionType.SNAPPY); -MeasurementNode nodeY = new MeasurementNode("y", TSDataType.FLOAT, TSEncoding.RLE, CompressionType.SNAPPY); -MeasurementNode nodeSpeed = new MeasurementNode("speed", TSDataType.DOUBLE, TSEncoding.GORILLA, CompressionType.SNAPPY); - -// This is the template we suggest to implement -Template flatTemplate = new Template("flatTemplate"); -template.addToTemplate(nodeX); -template.addToTemplate(nodeY); -template.addToTemplate(nodeSpeed); - -createSchemaTemplate(flatTemplate); -``` - -* 完成模板挂载操作后,可以通过如下的接口在给定的设备上使用模板注册序列,或者也可以直接向相应的设备写入数据以自动使用模板注册序列。 - -``` java -void createTimeseriesUsingSchemaTemplate(List devicePathList) -``` - -* 将名为'templateName'的元数据模板挂载到'prefixPath'路径下,在执行这一步之前,你需要创建名为'templateName'的元数据模板 -* **请注意,我们强烈建议您将模板设置在 database 或 database 下层的节点中,以更好地适配未来版本更新及各模块的协作** - -``` java -void setSchemaTemplate(String templateName, String prefixPath) -``` - -- 将模板挂载到 MTree 上之后,你可以随时查询所有模板的名称、某模板被设置到 MTree 的所有路径、所有正在使用某模板的所有路径,即如下接口: - -``` java -/** @return All template names. */ -public List showAllTemplates(); - -/** @return All paths have been set to designated template. */ -public List showPathsTemplateSetOn(String templateName); - -/** @return All paths are using designated template. */ -public List showPathsTemplateUsingOn(String templateName) -``` - -- 如果你需要删除某一个模板,请确保在进行删除之前,MTree 上已经没有节点被挂载了模板,对于已经被挂载模板的节点,可以用如下接口卸载模板; - - -``` java -void unsetSchemaTemplate(String prefixPath, String templateName); -public void dropSchemaTemplate(String templateName); -``` - -* 请注意,如果一个子树中有多个孩子节点需要使用模板,可以在其共同父母节点上使用 setSchemaTemplate 。而只有在已有数据点插入模板对应的物理量时,模板才会被设置为激活状态,进而被 show timeseries 等查询检测到。 -* 卸载'prefixPath'路径下的名为'templateName'的元数据模板。你需要保证给定的路径'prefixPath'下需要有名为'templateName'的元数据模板。 - -注意:目前不支持从曾经在'prefixPath'路径及其后代节点使用模板插入数据后(即使数据已被删除)卸载模板。 - - -### 数据操作接口 DML - -#### 数据写入 - -推荐使用 insertTablet 帮助提高写入效率 - -* 插入一个 Tablet,Tablet 是一个设备若干行数据块,每一行的列都相同 - * **写入效率高** - * **支持批量写入** - * **支持写入空值**:空值处可以填入任意值,然后通过 BitMap 标记空值 - -``` java -void insertTablet(Tablet tablet) - -public class Tablet { - /** deviceId of this tablet */ - public String prefixPath; - /** the list of measurement schemas for creating the tablet */ - private List schemas; - /** timestamps in this tablet */ - public long[] timestamps; - /** each object is a primitive type array, which represents values of one measurement */ - public Object[] values; - /** each bitmap represents the existence of each value in the current column. */ - public BitMap[] bitMaps; - /** the number of rows to include in this tablet */ - public int rowSize; - /** the maximum number of rows for this tablet */ - private int maxRowNumber; - /** whether this tablet store data of aligned timeseries or not */ - private boolean isAligned; -} -``` - -* 插入多个 Tablet - -``` java -void insertTablets(Map tablets) -``` - -* 插入一个 Record,一个 Record 是一个设备一个时间戳下多个测点的数据。这里的 value 是 Object 类型,相当于提供了一个公用接口,后面可以通过 TSDataType 将 value 强转为原类型 - - 其中,Object 类型与 TSDataType 类型的对应关系如下表所示: - - | TSDataType | Object | - | ---------- | -------------- | - | BOOLEAN | Boolean | - | INT32 | Integer | - | INT64 | Long | - | FLOAT | Float | - | DOUBLE | Double | - | TEXT | String, Binary | - -``` java -void insertRecord(String prefixPath, long time, List measurements, - List types, List values) -``` - -* 插入多个 Record - -``` java -void insertRecords(List deviceIds, - List times, - List> measurementsList, - List> typesList, - List> valuesList) -``` - -* 插入同属于一个 device 的多个 Record - -``` java -void insertRecordsOfOneDevice(String deviceId, List times, - List> measurementsList, List> typesList, - List> valuesList) -``` - -#### 带有类型推断的写入 - -当数据均是 String 类型时,我们可以使用如下接口,根据 value 的值进行类型推断。例如:value 为 "true" ,就可以自动推断为布尔类型。value 为 "3.2" ,就可以自动推断为数值类型。服务器需要做类型推断,可能会有额外耗时,速度较无需类型推断的写入慢 - -* 插入一个 Record,一个 Record 是一个设备一个时间戳下多个测点的数据 - -``` java -void insertRecord(String prefixPath, long time, List measurements, List values) -``` - -* 插入多个 Record - -``` java -void insertRecords(List deviceIds, List times, - List> measurementsList, List> valuesList) -``` - -* 插入同属于一个 device 的多个 Record - -``` java -void insertStringRecordsOfOneDevice(String deviceId, List times, - List> measurementsList, List> valuesList) -``` - -#### 对齐时间序列的写入 - -对齐时间序列的写入使用 insertAlignedXXX 接口,其余与上述接口类似: - -* insertAlignedRecord -* insertAlignedRecords -* insertAlignedRecordsOfOneDevice -* insertAlignedStringRecordsOfOneDevice -* insertAlignedTablet -* insertAlignedTablets - -#### 数据删除 - -* 删除一个或多个时间序列在某个时间点前或这个时间点的数据 - -``` java -void deleteData(String path, long endTime) -void deleteData(List paths, long endTime) -``` - -#### 数据查询 - -* 时间序列原始数据范围查询: - - 指定的查询时间范围为左闭右开区间,包含开始时间但不包含结束时间。 - -``` java -SessionDataSet executeRawDataQuery(List paths, long startTime, long endTime); -``` - -* 最新点查询: - - 查询最后一条时间戳大于等于某个时间点的数据。 - ``` java - SessionDataSet executeLastDataQuery(List paths, long lastTime); - ``` - - 快速查询单设备下指定序列最新点,支持重定向;如果您确认使用的查询路径是合法的,可将`isLegalPathNodes`置为true以避免路径校验带来的性能损失。 - ``` java - SessionDataSet executeLastDataQueryForOneDevice( - String db, String device, List sensors, boolean isLegalPathNodes); - ``` - -* 聚合查询: - - 支持指定查询时间范围。指定的查询时间范围为左闭右开区间,包含开始时间但不包含结束时间。 - - 支持按照时间区间分段查询。 - -``` java -SessionDataSet executeAggregationQuery(List paths, List aggregations); - -SessionDataSet executeAggregationQuery( - List paths, List aggregations, long startTime, long endTime); - -SessionDataSet executeAggregationQuery( - List paths, - List aggregations, - long startTime, - long endTime, - long interval); - -SessionDataSet executeAggregationQuery( - List paths, - List aggregations, - long startTime, - long endTime, - long interval, - long slidingStep); -``` - -### IoTDB-SQL 接口 - -* 执行查询语句 - -``` java -SessionDataSet executeQueryStatement(String sql) -``` - -* 执行非查询语句 - -``` java -void executeNonQueryStatement(String sql) -``` - -### 写入测试接口 (用于分析网络带宽) - -不实际写入数据,只将数据传输到 server 即返回 - -* 测试 insertRecord - -``` java -void testInsertRecord(String deviceId, long time, List measurements, List values) - -void testInsertRecord(String deviceId, long time, List measurements, - List types, List values) -``` - -* 测试 testInsertRecords - -``` java -void testInsertRecords(List deviceIds, List times, - List> measurementsList, List> valuesList) - -void testInsertRecords(List deviceIds, List times, - List> measurementsList, List> typesList, - List> valuesList) -``` - -* 测试 insertTablet - -``` java -void testInsertTablet(Tablet tablet) -``` - -* 测试 insertTablets - -``` java -void testInsertTablets(Map tablets) -``` - -### 示例代码 - -浏览上述接口的详细信息,请参阅代码 ```session/src/main/java/org/apache/iotdb/session/Session.java``` - -使用上述接口的示例代码在 ```example/session/src/main/java/org/apache/iotdb/SessionExample.java``` - -使用对齐时间序列和元数据模板的示例可以参见 `example/session/src/main/java/org/apache/iotdb/AlignedTimeseriesSessionExample.java` - -## 针对原生接口的连接池 - -我们提供了一个针对原生接口的连接池 (`SessionPool`),使用该接口时,你只需要指定连接池的大小,就可以在使用时从池中获取连接。 -如果超过 60s 都没得到一个连接的话,那么会打印一条警告日志,但是程序仍将继续等待。 - -当一个连接被用完后,他会自动返回池中等待下次被使用; -当一个连接损坏后,他会从池中被删除,并重建一个连接重新执行用户的操作; -你还可以像创建 Session 那样在创建 SessionPool 时指定多个可连接节点的 url,以保证分布式集群中客户端的高可用性。 - -对于查询操作: - -1. 使用 SessionPool 进行查询时,得到的结果集是`SessionDataSet`的封装类`SessionDataSetWrapper`; -2. 若对于一个查询的结果集,用户并没有遍历完且不再想继续遍历时,需要手动调用释放连接的操作`closeResultSet`; -3. 若对一个查询的结果集遍历时出现异常,也需要手动调用释放连接的操作`closeResultSet`. -4. 可以调用 `SessionDataSetWrapper` 的 `getColumnNames()` 方法得到结果集列名 - -使用示例可以参见 `session/src/test/java/org/apache/iotdb/session/pool/SessionPoolTest.java` - -或 `example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java` diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-MQTT.md b/src/zh/UserGuide/V1.3.0-2/API/Programming-MQTT.md deleted file mode 100644 index 23fda8d8a..000000000 --- a/src/zh/UserGuide/V1.3.0-2/API/Programming-MQTT.md +++ /dev/null @@ -1,179 +0,0 @@ - - -# MQTT 协议 - -[MQTT](http://mqtt.org/) 是机器对机器(M2M)/“物联网”连接协议。 - -它被设计为一种非常轻量级的发布/订阅消息传递。 - -对于与需要较小代码占用和/或网络带宽非常宝贵的远程位置的连接很有用。 - -IoTDB 支持 MQTT v3.1(OASIS 标准)协议。 -IoTDB 服务器包括内置的 MQTT 服务,该服务允许远程设备将消息直接发送到 IoTDB 服务器。 - - - -## 内置 MQTT 服务 -内置的 MQTT 服务提供了通过 MQTT 直接连接到 IoTDB 的能力。 它侦听来自 MQTT 客户端的发布消息,然后立即将数据写入存储。 -MQTT 主题与 IoTDB 时间序列相对应。 -消息有效载荷可以由 Java SPI 加载的`PayloadFormatter`格式化为事件,默认实现为`JSONPayloadFormatter` - 默认的`json`格式化程序支持两种 json 格式以及由他们组成的json数组,以下是 MQTT 消息有效负载示例: - -```json - { - "device":"root.sg.d1", - "timestamp":1586076045524, - "measurements":["s1","s2"], - "values":[0.530635,0.530635] - } -``` -或者 -```json - { - "device":"root.sg.d1", - "timestamps":[1586076045524,1586076065526], - "measurements":["s1","s2"], - "values":[[0.530635,0.530635], [0.530655,0.530695]] - } -``` -或者以上两者的JSON数组形式。 - - - -## MQTT 配置 -默认情况下,IoTDB MQTT 服务从`${IOTDB_HOME}/${IOTDB_CONF}/iotdb-common.properties`加载配置。 - -配置如下: - -| 名称 | 描述 | 默认 | -| ------------- |:-------------:|:------:| -| enable_mqtt_service | 是否启用 mqtt 服务 | false | -| mqtt_host | mqtt 服务绑定主机 | 127.0.0.1 | -| mqtt_port | mqtt 服务绑定端口 | 1883 | -| mqtt_handler_pool_size | 处理 mqtt 消息的处理程序池大小 | 1 | -| mqtt_payload_formatter | mqtt 消息有效负载格式化程序 | json | -| mqtt_max_message_size | mqtt 消息最大长度(字节)| 1048576 | - -## 示例代码 -以下是 mqtt 客户端将消息发送到 IoTDB 服务器的示例。 - - ```java -MQTT mqtt = new MQTT(); -mqtt.setHost("127.0.0.1", 1883); -mqtt.setUserName("root"); -mqtt.setPassword("root"); - -BlockingConnection connection = mqtt.blockingConnection(); -connection.connect(); - -Random random = new Random(); -for (int i = 0; i < 10; i++) { - String payload = String.format("{\n" + - "\"device\":\"root.sg.d1\",\n" + - "\"timestamp\":%d,\n" + - "\"measurements\":[\"s1\"],\n" + - "\"values\":[%f]\n" + - "}", System.currentTimeMillis(), random.nextDouble()); - - connection.publish("root.sg.d1.s1", payload.getBytes(), QoS.AT_LEAST_ONCE, false); -} - -connection.disconnect(); - ``` - - -## 自定义 MQTT 消息格式 - -事实上可以通过简单编程来实现 MQTT 消息的格式自定义。 -可以在源码的 `example/mqtt-customize` 项目中找到一个简单示例。 - -步骤: -1. 创建一个 Java 项目,增加如下依赖 -```xml - - org.apache.iotdb - iotdb-server - 1.3.0-SNAPSHOT - -``` -2. 创建一个实现类,实现接口 `org.apache.iotdb.db.mqtt.protocol.PayloadFormatter` - -```java -package org.apache.iotdb.mqtt.server; - -import io.netty.buffer.ByteBuf; -import org.apache.iotdb.db.protocol.mqtt.Message; -import org.apache.iotdb.db.protocol.mqtt.PayloadFormatter; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class CustomizedJsonPayloadFormatter implements PayloadFormatter { - - @Override - public List format(ByteBuf payload) { - // Suppose the payload is a json format - if (payload == null) { - return null; - } - - String json = payload.toString(StandardCharsets.UTF_8); - // parse data from the json and generate Messages and put them into List ret - List ret = new ArrayList<>(); - // this is just an example, so we just generate some Messages directly - for (int i = 0; i < 2; i++) { - long ts = i; - Message message = new Message(); - message.setDevice("d" + i); - message.setTimestamp(ts); - message.setMeasurements(Arrays.asList("s1", "s2")); - message.setValues(Arrays.asList("4.0" + i, "5.0" + i)); - ret.add(message); - } - return ret; - } - - @Override - public String getName() { - // set the value of mqtt_payload_formatter in iotdb-common.properties as the following string: - return "CustomizedJson"; - } -} -``` -3. 修改项目中的 `src/main/resources/META-INF/services/org.apache.iotdb.db.protocol.mqtt.PayloadFormatter` 文件: - 将示例中的文件内容清除,并将刚才的实现类的全名(包名.类名)写入文件中。注意,这个文件中只有一行。 - 在本例中,文件内容为: `org.apache.iotdb.mqtt.server.CustomizedJsonPayloadFormatter` -4. 编译项目生成一个 jar 包: `mvn package -DskipTests` - - -在 IoTDB 服务端: -1. 创建 ${IOTDB_HOME}/ext/mqtt/ 文件夹, 将刚才的 jar 包放入此文件夹。 -2. 打开 MQTT 服务参数. (`enable_mqtt_service=true` in `conf/iotdb-common.properties`) -3. 用刚才的实现类中的 getName() 方法的返回值 设置为 `conf/iotdb-common.properties` 中 `mqtt_payload_formatter` 的值, - , 在本例中,为 `CustomizedJson` -4. 启动 IoTDB -5. 搞定 - -More: MQTT 协议的消息不限于 json,你还可以用任意二进制。通过如下函数获得: -`payload.forEachByte()` or `payload.array`。 diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-Python-Native-API.md b/src/zh/UserGuide/V1.3.0-2/API/Programming-Python-Native-API.md deleted file mode 100644 index a012bbc6f..000000000 --- a/src/zh/UserGuide/V1.3.0-2/API/Programming-Python-Native-API.md +++ /dev/null @@ -1,717 +0,0 @@ - - -# Python 原生接口 - -## 依赖 - -在使用 Python 原生接口包前,您需要安装 thrift (>=0.13) 依赖。 - -## 如何使用 (示例) - -首先下载包:`pip3 install apache-iotdb` - -您可以从这里得到一个使用该包进行数据读写的例子:[Session Example](https://github.com/apache/iotdb/blob/rc/1.3.0/iotdb-client/client-py/SessionExample.py) - -关于对齐时间序列读写的例子:[Aligned Timeseries Session Example](https://github.com/apache/iotdb/blob/rc/1.3.0/iotdb-client/client-py/SessionAlignedTimeseriesExample.py) - -(您需要在文件的头部添加`import iotdb`) - -或者: - -```python -from iotdb.Session import Session - -ip = "127.0.0.1" -port_ = "6667" -username_ = "root" -password_ = "root" -session = Session(ip, port_, username_, password_) -session.open(False) -zone = session.get_time_zone() -session.close() -``` -## 基本接口说明 - -下面将给出 Session 对应的接口的简要介绍和对应参数: - -### 初始化 - -* 初始化 Session - -```python -session = Session( - ip="127.0.0.1", - port="6667", - user="root", - password="root", - fetch_size=1024, - zone_id="UTC+8", - enable_redirection=True -) -``` - -* 初始化可连接多节点的 Session - -```python -session = Session.init_from_node_urls( - node_urls=["127.0.0.1:6667", "127.0.0.1:6668", "127.0.0.1:6669"], - user="root", - password="root", - fetch_size=1024, - zone_id="UTC+8", - enable_redirection=True -) -``` - -* 开启 Session,并决定是否开启 RPC 压缩 - -```python -session.open(enable_rpc_compression=False) -``` - -注意: 客户端的 RPC 压缩开启状态需和服务端一致 - -* 关闭 Session - -```python -session.close() -``` -### 通过SessionPool管理session连接 - -利用SessionPool管理session,不需要再考虑如何重用session。当session连接到达pool的最大值时,获取session的请求会被阻塞,可以通过参数设置阻塞等待时间。每次session使用完需要使用putBack方法将session归还到SessionPool中管理。 - -#### 创建SessionPool - -```python -pool_config = PoolConfig(host=ip,port=port, user_name=username, - password=password, fetch_size=1024, - time_zone="UTC+8", max_retry=3) -max_pool_size = 5 -wait_timeout_in_ms = 3000 - -# 通过配置参数创建连接池 -session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) -``` -#### 通过分布式节点创建SessionPool -```python -pool_config = PoolConfig(node_urls=node_urls=["127.0.0.1:6667", "127.0.0.1:6668", "127.0.0.1:6669"], user_name=username, - password=password, fetch_size=1024, - time_zone="UTC+8", max_retry=3) -max_pool_size = 5 -wait_timeout_in_ms = 3000 -``` - -#### 通过SessionPool获取session,使用完手动调用PutBack - -```python -session = session_pool.get_session() -session.set_storage_group(STORAGE_GROUP_NAME) -session.create_time_series( - TIMESERIES_PATH, TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY -) -# 使用完调用putBack归还 -session_pool.put_back(session) -# 关闭sessionPool时同时关闭管理的session -session_pool.close() -``` - -## 数据定义接口 DDL - -### Database 管理 - -* 设置 database - -```python -session.set_storage_group(group_name) -``` - -* 删除单个或多个 database - -```python -session.delete_storage_group(group_name) -session.delete_storage_groups(group_name_lst) -``` -### 时间序列管理 - -* 创建单个或多个时间序列 - -```python -session.create_time_series(ts_path, data_type, encoding, compressor, - props=None, tags=None, attributes=None, alias=None) - -session.create_multi_time_series( - ts_path_lst, data_type_lst, encoding_lst, compressor_lst, - props_lst=None, tags_lst=None, attributes_lst=None, alias_lst=None -) -``` - -* 创建对齐时间序列 - -```python -session.create_aligned_time_series( - device_id, measurements_lst, data_type_lst, encoding_lst, compressor_lst -) -``` - -注意:目前**暂不支持**使用传感器别名。 - -* 删除一个或多个时间序列 - -```python -session.delete_time_series(paths_list) -``` - -* 检测时间序列是否存在 - -```python -session.check_time_series_exists(path) -``` - -## 数据操作接口 DML - -### 数据写入 - -推荐使用 insert_tablet 帮助提高写入效率 - -* 插入一个 Tablet,Tablet 是一个设备若干行数据块,每一行的列都相同 - * **写入效率高** - * **支持写入空值** (0.13 版本起) - -Python API 里目前有两种 Tablet 实现 - -* 普通 Tablet - -```python -values_ = [ - [False, 10, 11, 1.1, 10011.1, "test01"], - [True, 100, 11111, 1.25, 101.0, "test02"], - [False, 100, 1, 188.1, 688.25, "test03"], - [True, 0, 0, 0, 6.25, "test04"], -] -timestamps_ = [1, 2, 3, 4] -tablet_ = Tablet( - device_id, measurements_, data_types_, values_, timestamps_ -) -session.insert_tablet(tablet_) - -values_ = [ - [None, 10, 11, 1.1, 10011.1, "test01"], - [True, None, 11111, 1.25, 101.0, "test02"], - [False, 100, None, 188.1, 688.25, "test03"], - [True, 0, 0, 0, None, None], -] -timestamps_ = [16, 17, 18, 19] -tablet_ = Tablet( - device_id, measurements_, data_types_, values_, timestamps_ -) -session.insert_tablet(tablet_) -``` -* Numpy Tablet - -相较于普通 Tablet,Numpy Tablet 使用 [numpy.ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) 来记录数值型数据。 -内存占用和序列化耗时会降低很多,写入效率也会有很大提升。 - -**注意** -1. Tablet 中的每一列时间戳和值记录为一个 ndarray -2. Numpy Tablet 只支持大端类型数据,ndarray 构建时如果不指定数据类型会使用小端,因此推荐在构建 ndarray 时指定下面例子中类型使用大端。如果不指定,IoTDB Python客户端也会进行大小端转换,不影响使用正确性。 - -```python -import numpy as np -data_types_ = [ - TSDataType.BOOLEAN, - TSDataType.INT32, - TSDataType.INT64, - TSDataType.FLOAT, - TSDataType.DOUBLE, - TSDataType.TEXT, -] -np_values_ = [ - np.array([False, True, False, True], TSDataType.BOOLEAN.np_dtype()), - np.array([10, 100, 100, 0], TSDataType.INT32.np_dtype()), - np.array([11, 11111, 1, 0], TSDataType.INT64.np_dtype()), - np.array([1.1, 1.25, 188.1, 0], TSDataType.FLOAT.np_dtype()), - np.array([10011.1, 101.0, 688.25, 6.25], TSDataType.DOUBLE.np_dtype()), - np.array(["test01", "test02", "test03", "test04"], TSDataType.TEXT.np_dtype()), -] -np_timestamps_ = np.array([1, 2, 3, 4], TSDataType.INT64.np_dtype()) -np_tablet_ = NumpyTablet( - device_id, measurements_, data_types_, np_values_, np_timestamps_ -) -session.insert_tablet(np_tablet_) - -# insert one numpy tablet with None into the database. -np_values_ = [ - np.array([False, True, False, True], TSDataType.BOOLEAN.np_dtype()), - np.array([10, 100, 100, 0], TSDataType.INT32.np_dtype()), - np.array([11, 11111, 1, 0], TSDataType.INT64.np_dtype()), - np.array([1.1, 1.25, 188.1, 0], TSDataType.FLOAT.np_dtype()), - np.array([10011.1, 101.0, 688.25, 6.25], TSDataType.DOUBLE.np_dtype()), - np.array(["test01", "test02", "test03", "test04"], TSDataType.TEXT.np_dtype()), -] -np_timestamps_ = np.array([98, 99, 100, 101], TSDataType.INT64.np_dtype()) -np_bitmaps_ = [] -for i in range(len(measurements_)): - np_bitmaps_.append(BitMap(len(np_timestamps_))) -np_bitmaps_[0].mark(0) -np_bitmaps_[1].mark(1) -np_bitmaps_[2].mark(2) -np_bitmaps_[4].mark(3) -np_bitmaps_[5].mark(3) -np_tablet_with_none = NumpyTablet( - device_id, measurements_, data_types_, np_values_, np_timestamps_, np_bitmaps_ -) -session.insert_tablet(np_tablet_with_none) -``` - -* 插入多个 Tablet - -```python -session.insert_tablets(tablet_lst) -``` - -* 插入一个 Record,一个 Record 是一个设备一个时间戳下多个测点的数据。 - -```python -session.insert_record(device_id, timestamp, measurements_, data_types_, values_) -``` - -* 插入多个 Record - -```python -session.insert_records( - device_ids_, time_list_, measurements_list_, data_type_list_, values_list_ - ) -``` - -* 插入同属于一个 device 的多个 Record - -```python -session.insert_records_of_one_device(device_id, time_list, measurements_list, data_types_list, values_list) -``` - -### 带有类型推断的写入 - -当数据均是 String 类型时,我们可以使用如下接口,根据 value 的值进行类型推断。例如:value 为 "true" ,就可以自动推断为布尔类型。value 为 "3.2" ,就可以自动推断为数值类型。服务器需要做类型推断,可能会有额外耗时,速度较无需类型推断的写入慢 - -```python -session.insert_str_record(device_id, timestamp, measurements, string_values) -``` - -### 对齐时间序列的写入 - -对齐时间序列的写入使用 insert_aligned_xxx 接口,其余与上述接口类似: - -* insert_aligned_record -* insert_aligned_records -* insert_aligned_records_of_one_device -* insert_aligned_tablet -* insert_aligned_tablets - - -## IoTDB-SQL 接口 - -* 执行查询语句 - -```python -session.execute_query_statement(sql) -``` - -* 执行非查询语句 - -```python -session.execute_non_query_statement(sql) -``` - -* 执行语句 - -```python -session.execute_statement(sql) -``` - - -## 元数据模版接口 -### 构建元数据模版 -1. 首先构建 Template 类 -2. 添加子节点 MeasurementNode -3. 调用创建元数据模版接口 - -```python -template = Template(name=template_name, share_time=True) - -m_node_x = MeasurementNode("x", TSDataType.FLOAT, TSEncoding.RLE, Compressor.SNAPPY) -m_node_y = MeasurementNode("y", TSDataType.FLOAT, TSEncoding.RLE, Compressor.SNAPPY) -m_node_z = MeasurementNode("z", TSDataType.FLOAT, TSEncoding.RLE, Compressor.SNAPPY) - -template.add_template(m_node_x) -template.add_template(m_node_y) -template.add_template(m_node_z) - -session.create_schema_template(template) -``` -### 修改模版节点信息 -修改模版节点,其中修改的模版必须已经被创建。以下函数能够在已经存在的模版中增加或者删除物理量 -* 在模版中增加实体 -```python -session.add_measurements_in_template(template_name, measurements_path, data_types, encodings, compressors, is_aligned) -``` - -* 在模版中删除物理量 -```python -session.delete_node_in_template(template_name, path) -``` - -### 挂载元数据模板 -```python -session.set_schema_template(template_name, prefix_path) -``` - -### 卸载元数据模版 -```python -session.unset_schema_template(template_name, prefix_path) -``` - -### 查看元数据模版 -* 查看所有的元数据模版 -```python -session.show_all_templates() -``` -* 查看元数据模版中的物理量个数 -```python -session.count_measurements_in_template(template_name) -``` - -* 判断某个节点是否为物理量,该节点必须已经在元数据模版中 -```python -session.count_measurements_in_template(template_name, path) -``` - -* 判断某个路径是否在元数据模版中,这个路径有可能不在元数据模版中 -```python -session.is_path_exist_in_template(template_name, path) -``` - -* 查看某个元数据模板下的物理量 -```python -session.show_measurements_in_template(template_name) -``` - -* 查看挂载了某个元数据模板的路径前缀 -```python -session.show_paths_template_set_on(template_name) -``` - -* 查看使用了某个元数据模板(即序列已创建)的路径前缀 -```python -session.show_paths_template_using_on(template_name) -``` - -### 删除元数据模版 -删除已经存在的元数据模版,不支持删除已经挂载的模版 -```python -session.drop_schema_template("template_python") -``` - - -## 对 Pandas 的支持 - -我们支持将查询结果轻松地转换为 [Pandas Dataframe](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html)。 - -SessionDataSet 有一个方法`.todf()`,它的作用是消费 SessionDataSet 中的数据,并将数据转换为 pandas dataframe。 - -例子: - -```python -from iotdb.Session import Session - -ip = "127.0.0.1" -port_ = "6667" -username_ = "root" -password_ = "root" -session = Session(ip, port_, username_, password_) -session.open(False) -result = session.execute_query_statement("SELECT ** FROM root") - -# Transform to Pandas Dataset -df = result.todf() - -session.close() - -# Now you can work with the dataframe -df = ... -``` - -## IoTDB Testcontainer - -Python 客户端对测试的支持是基于`testcontainers`库 (https://testcontainers-python.readthedocs.io/en/latest/index.html) 的,如果您想使用该特性,就需要将其安装到您的项目中。 - -要在 Docker 容器中启动(和停止)一个 IoTDB 数据库,只需这样做: - -```python -class MyTestCase(unittest.TestCase): - - def test_something(self): - with IoTDBContainer() as c: - session = Session("localhost", c.get_exposed_port(6667), "root", "root") - session.open(False) - result = session.execute_query_statement("SHOW TIMESERIES") - print(result) - session.close() -``` - -默认情况下,它会拉取最新的 IoTDB 镜像 `apache/iotdb:latest`进行测试,如果您想指定待测 IoTDB 的版本,您只需要将版本信息像这样声明:`IoTDBContainer("apache/iotdb:0.12.0")`,此时,您就会得到一个`0.12.0`版本的 IoTDB 实例。 - -## IoTDB DBAPI - -IoTDB DBAPI 遵循 Python DB API 2.0 规范 (https://peps.python.org/pep-0249/),实现了通过Python语言访问数据库的通用接口。 - -### 例子 -+ 初始化 - -初始化的参数与Session部分保持一致(sqlalchemy_mode参数除外,该参数仅在SQLAlchemy方言中使用) -```python -from iotdb.dbapi import connect - -ip = "127.0.0.1" -port_ = "6667" -username_ = "root" -password_ = "root" -conn = connect(ip, port_, username_, password_,fetch_size=1024,zone_id="UTC+8",sqlalchemy_mode=False) -cursor = conn.cursor() -``` -+ 执行简单的SQL语句 -```python -cursor.execute("SELECT ** FROM root") -for row in cursor.fetchall(): - print(row) -``` - -+ 执行带有参数的SQL语句 - -IoTDB DBAPI 支持pyformat风格的参数 -```python -cursor.execute("SELECT ** FROM root WHERE time < %(time)s",{"time":"2017-11-01T00:08:00.000"}) -for row in cursor.fetchall(): - print(row) -``` - -+ 批量执行带有参数的SQL语句 -```python -seq_of_parameters = [ - {"timestamp": 1, "temperature": 1}, - {"timestamp": 2, "temperature": 2}, - {"timestamp": 3, "temperature": 3}, - {"timestamp": 4, "temperature": 4}, - {"timestamp": 5, "temperature": 5}, -] -sql = "insert into root.cursor(timestamp,temperature) values(%(timestamp)s,%(temperature)s)" -cursor.executemany(sql,seq_of_parameters) -``` - -+ 关闭连接 -```python -cursor.close() -conn.close() -``` - -## IoTDB SQLAlchemy Dialect(实验性) -IoTDB的SQLAlchemy方言主要是为了适配Apache superset而编写的,该部分仍在完善中,请勿在生产环境中使用! -### 元数据模型映射 -SQLAlchemy 所使用的数据模型为关系数据模型,这种数据模型通过表格来描述不同实体之间的关系。 -而 IoTDB 的数据模型为层次数据模型,通过树状结构来对数据进行组织。 -为了使 IoTDB 能够适配 SQLAlchemy 的方言,需要对 IoTDB 中原有的数据模型进行重新组织, -把 IoTDB 的数据模型转换成 SQLAlchemy 的数据模型。 - -IoTDB 中的元数据有: - -1. Database:数据库 -2. Path:存储路径 -3. Entity:实体 -4. Measurement:物理量 - -SQLAlchemy 中的元数据有: -1. Schema:数据模式 -2. Table:数据表 -3. Column:数据列 - -它们之间的映射关系为: - -| SQLAlchemy中的元数据 | IoTDB中对应的元数据 | -| -------------------- | ---------------------------------------------- | -| Schema | Database | -| Table | Path ( from database to entity ) + Entity | -| Column | Measurement | - -下图更加清晰的展示了二者的映射关系: - -![sqlalchemy-to-iotdb](/img/UserGuide/API/IoTDB-SQLAlchemy/sqlalchemy-to-iotdb.png?raw=true) - -### 数据类型映射 -| IoTDB 中的数据类型 | SQLAlchemy 中的数据类型 | -|--------------|-------------------| -| BOOLEAN | Boolean | -| INT32 | Integer | -| INT64 | BigInteger | -| FLOAT | Float | -| DOUBLE | Float | -| TEXT | Text | -| LONG | BigInteger | -### Example - -+ 执行语句 - -```python -from sqlalchemy import create_engine - -engine = create_engine("iotdb://root:root@127.0.0.1:6667") -connect = engine.connect() -result = connect.execute("SELECT ** FROM root") -for row in result.fetchall(): - print(row) -``` - -+ ORM (目前只支持简单的查询) - -```python -from sqlalchemy import create_engine, Column, Float, BigInteger, MetaData -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker - -metadata = MetaData( - schema='root.factory' -) -Base = declarative_base(metadata=metadata) - - -class Device(Base): - __tablename__ = "room2.device1" - Time = Column(BigInteger, primary_key=True) - temperature = Column(Float) - status = Column(Float) - - -engine = create_engine("iotdb://root:root@127.0.0.1:6667") - -DbSession = sessionmaker(bind=engine) -session = DbSession() - -res = session.query(Device.status).filter(Device.temperature > 1) - -for row in res: - print(row) -``` - -## 给开发人员 - -### 介绍 - -这是一个使用 thrift rpc 接口连接到 IoTDB 的示例。在 Windows 和 Linux 上操作几乎是一样的,但要注意路径分隔符等不同之处。 - -### 依赖 - -首选 Python3.7 或更高版本。 - -必须安装 thrift(0.11.0 或更高版本)才能将 thrift 文件编译为 Python 代码。下面是官方的安装教程,最终,您应该得到一个 thrift 可执行文件。 - -``` -http://thrift.apache.org/docs/install/ -``` - -在开始之前,您还需要在 Python 环境中安装`requirements_dev.txt`中的其他依赖: -```shell -pip install -r requirements_dev.txt -``` - -### 编译 thrift 库并调试 - -在 IoTDB 源代码文件夹的根目录下,运行`mvn clean generate-sources -pl iotdb-client/client-py -am`, - -这个指令将自动删除`iotdb/thrift`中的文件,并使用新生成的 thrift 文件重新填充该文件夹。 - -这个文件夹在 git 中会被忽略,并且**永远不应该被推到 git 中!** - -**注意**不要将`iotdb/thrift`上传到 git 仓库中 ! - -### Session 客户端 & 使用示例 - -我们将 thrift 接口打包到`client-py/src/iotdb/session.py `中(与 Java 版本类似),还提供了一个示例文件`client-py/src/SessionExample.py`来说明如何使用 Session 模块。请仔细阅读。 - -另一个简单的例子: - -```python -from iotdb.Session import Session - -ip = "127.0.0.1" -port_ = "6667" -username_ = "root" -password_ = "root" -session = Session(ip, port_, username_, password_) -session.open(False) -zone = session.get_time_zone() -session.close() -``` - -### 测试 - -请在`tests`文件夹中添加自定义测试。 - -要运行所有的测试,只需在根目录中运行`pytest . `即可。 - -**注意**一些测试需要在您的系统上使用 docker,因为测试的 IoTDB 实例是使用 [testcontainers](https://testcontainers-python.readthedocs.io/en/latest/index.html) 在 docker 容器中启动的。 - -### 其他工具 - -[black](https://pypi.org/project/black/) 和 [flake8](https://pypi.org/project/flake8/) 分别用于自动格式化和 linting。 -它们可以通过 `black .` 或 `flake8 .` 分别运行。 - -## 发版 - -要进行发版, - -只需确保您生成了正确的 thrift 代码, - -运行了 linting 并进行了自动格式化, - -然后,确保所有测试都正常通过(通过`pytest . `), - -最后,您就可以将包发布到 pypi 了。 - -### 准备您的环境 - -首先,通过`pip install -r requirements_dev.txt`安装所有必要的开发依赖。 - -### 发版 - -有一个脚本`release.sh`可以用来执行发版的所有步骤。 - -这些步骤包括: - -* 删除所有临时目录(如果存在) - -* (重新)通过 mvn 生成所有必须的源代码 - -* 运行 linting (flke8) - -* 通过 pytest 运行测试 - -* Build - -* 发布到 pypi diff --git a/src/zh/UserGuide/V1.3.0-2/API/RestServiceV1.md b/src/zh/UserGuide/V1.3.0-2/API/RestServiceV1.md deleted file mode 100644 index 86e15c01f..000000000 --- a/src/zh/UserGuide/V1.3.0-2/API/RestServiceV1.md +++ /dev/null @@ -1,941 +0,0 @@ - - -# RESTful API V1(不推荐) -IoTDB 的 RESTful 服务可用于查询、写入和管理操作,它使用 OpenAPI 标准来定义接口并生成框架。 - -## 开启RESTful 服务 -RESTful 服务默认情况是关闭的 - - 找到IoTDB安装目录下面的`conf/iotdb-datanode.properties`文件,将 `enable_rest_service` 设置为 `true` 以启用该模块。 - - ```properties - enable_rest_service=true - ``` - -## 鉴权 -除了检活接口 `/ping`,RESTful 服务使用了基础(basic)鉴权,每次 URL 请求都需要在 header 中携带 `'Authorization': 'Basic ' + base64.encode(username + ':' + password)`。 - -示例中使用的用户名为:`root`,密码为:`root`,对应的 Basic 鉴权 Header 格式为 - -``` -Authorization: Basic cm9vdDpyb290 -``` - -- 若用户名密码认证失败,则返回如下信息: - - HTTP 状态码:`401` - - 返回结构体如下 - ```json - { - "code": 600, - "message": "WRONG_LOGIN_PASSWORD_ERROR" - } - ``` - -- 若未设置 `Authorization`,则返回如下信息: - - HTTP 状态码:`401` - - 返回结构体如下 - ```json - { - "code": 603, - "message": "UNINITIALIZED_AUTH_ERROR" - } - ``` - -## 接口 - -### ping - -ping 接口可以用于线上服务检活。 - -请求方式:`GET` - -请求路径:`http://ip:port/ping -` -请求示例: - -```shell -$ curl http://127.0.0.1:18080/ping -``` - -返回的 HTTP 状态码: - -- `200`:当前服务工作正常,可以接收外部请求。 -- `503`:当前服务出现异常,不能接收外部请求。 - -响应参数: - -|参数名称 |参数类型 |参数描述| -| ------------ | ------------ | ------------| -| code | integer | 状态码 | -| message | string | 信息提示 | - -响应示例: - -- HTTP 状态码为 `200` 时: - - ```json - { - "code": 200, - "message": "SUCCESS_STATUS" - } - ``` - -- HTTP 状态码为 `503` 时: - - ```json - { - "code": 500, - "message": "thrift service is unavailable" - } - ``` - -> `/ping` 接口访问不需要鉴权。 - -### query - -query 接口可以用于处理数据查询和元数据查询。 - -请求方式:`POST` - -请求头:`application/json` - -请求路径:`http://ip:port/rest/v1/query` - -参数说明: - -| 参数名称 |参数类型 |是否必填|参数描述| -|-----------| ------------ | ------------ |------------ | -| sql | string | 是 | | -| rowLimit | integer | 否 | 一次查询能返回的结果集的最大行数。
如果不设置该参数,将使用配置文件的 `rest_query_default_row_size_limit` 作为默认值。
当返回结果集的行数超出限制时,将返回状态码 `411`。 | - -响应参数: - -| 参数名称 |参数类型 |参数描述| -|--------------| ------------ | ------------| -| expressions | array | 用于数据查询时结果集列名的数组,用于元数据查询时为`null`| -| columnNames | array | 用于元数据查询结果集列名数组,用于数据查询时为`null` | -| timestamps | array | 时间戳列,用于元数据查询时为`null` | -| values |array|二维数组,第一维与结果集列名数组的长度相同,第二维数组代表结果集的一列| - -请求示例如下所示: - -提示:为了避免OOM问题,不推荐使用select * from root.xx.** 这种查找方式。 - -1. 请求示例 表达式查询: - ```shell - curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select s3, s4, s3 + 1 from root.sg27 limit 2"}' http://127.0.0.1:18080/rest/v1/query -``` - - - 响应示例: - -```json -{ - "expressions": [ - "root.sg27.s3", - "root.sg27.s4", - "root.sg27.s3 + 1" - ], - "columnNames": null, - "timestamps": [ - 1635232143960, - 1635232153960 - ], - "values": [ - [ - 11, - null - ], - [ - false, - true - ], - [ - 12.0, - null - ] - ] -} -``` - -2. 请求示例 show child paths: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show child paths root"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "child paths" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ] - ] -} -``` - -3. 请求示例 show child nodes: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show child nodes root"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "child nodes" - ], - "timestamps": null, - "values": [ - [ - "sg27", - "sg28" - ] - ] -} -``` - -4. 请求示例 show all ttl: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show all ttl"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "database", - "ttl" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ], - [ - null, - null - ] - ] -} -``` - -5. 请求示例 show ttl: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show ttl on root.sg27"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "database", - "ttl" - ], - "timestamps": null, - "values": [ - [ - "root.sg27" - ], - [ - null - ] - ] -} -``` - -6. 请求示例 show functions: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show functions"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "function name", - "function type", - "class name (UDF)" - ], - "timestamps": null, - "values": [ - [ - "ABS", - "ACOS", - "ASIN", - ... - ], - [ - "built-in UDTF", - "built-in UDTF", - "built-in UDTF", - ... - ], - [ - "org.apache.iotdb.db.query.udf.builtin.UDTFAbs", - "org.apache.iotdb.db.query.udf.builtin.UDTFAcos", - "org.apache.iotdb.db.query.udf.builtin.UDTFAsin", - ... - ] - ] -} -``` - -7. 请求示例 show timeseries: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show timeseries"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "timeseries", - "alias", - "database", - "dataType", - "encoding", - "compression", - "tags", - "attributes" - ], - "timestamps": null, - "values": [ - [ - "root.sg27.s3", - "root.sg27.s4", - "root.sg28.s3", - "root.sg28.s4" - ], - [ - null, - null, - null, - null - ], - [ - "root.sg27", - "root.sg27", - "root.sg28", - "root.sg28" - ], - [ - "INT32", - "BOOLEAN", - "INT32", - "BOOLEAN" - ], - [ - "RLE", - "RLE", - "RLE", - "RLE" - ], - [ - "SNAPPY", - "SNAPPY", - "SNAPPY", - "SNAPPY" - ], - [ - null, - null, - null, - null - ], - [ - null, - null, - null, - null - ] - ] -} -``` - -8. 请求示例 show latest timeseries: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show latest timeseries"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "timeseries", - "alias", - "database", - "dataType", - "encoding", - "compression", - "tags", - "attributes" - ], - "timestamps": null, - "values": [ - [ - "root.sg28.s4", - "root.sg27.s4", - "root.sg28.s3", - "root.sg27.s3" - ], - [ - null, - null, - null, - null - ], - [ - "root.sg28", - "root.sg27", - "root.sg28", - "root.sg27" - ], - [ - "BOOLEAN", - "BOOLEAN", - "INT32", - "INT32" - ], - [ - "RLE", - "RLE", - "RLE", - "RLE" - ], - [ - "SNAPPY", - "SNAPPY", - "SNAPPY", - "SNAPPY" - ], - [ - null, - null, - null, - null - ], - [ - null, - null, - null, - null - ] - ] -} -``` - -9. 请求示例 count timeseries: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"count timeseries root.**"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "count" - ], - "timestamps": null, - "values": [ - [ - 4 - ] - ] -} -``` - -10. 请求示例 count nodes: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"count nodes root.** level=2"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "count" - ], - "timestamps": null, - "values": [ - [ - 4 - ] - ] -} -``` - -11. 请求示例 show devices: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show devices"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "devices", - "isAligned" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ], - [ - "false", - "false" - ] - ] -} -``` - -12. 请求示例 show devices with database: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show devices with database"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "devices", - "database", - "isAligned" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ], - [ - "root.sg27", - "root.sg28" - ], - [ - "false", - "false" - ] - ] -} -``` - -13. 请求示例 list user: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"list user"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "user" - ], - "timestamps": null, - "values": [ - [ - "root" - ] - ] -} -``` - -14. 请求示例 原始聚合查询: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(*) from root.sg27"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": [ - "count(root.sg27.s3)", - "count(root.sg27.s4)" - ], - "columnNames": null, - "timestamps": [ - 0 - ], - "values": [ - [ - 1 - ], - [ - 2 - ] - ] -} -``` - -15. 请求示例 group by level: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(*) from root.** group by level = 1"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "count(root.sg27.*)", - "count(root.sg28.*)" - ], - "timestamps": null, - "values": [ - [ - 3 - ], - [ - 3 - ] - ] -} -``` - -16. 请求示例 group by: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(*) from root.sg27 group by([1635232143960,1635232153960),1s)"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": [ - "count(root.sg27.s3)", - "count(root.sg27.s4)" - ], - "columnNames": null, - "timestamps": [ - 1635232143960, - 1635232144960, - 1635232145960, - 1635232146960, - 1635232147960, - 1635232148960, - 1635232149960, - 1635232150960, - 1635232151960, - 1635232152960 - ], - "values": [ - [ - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - [ - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - ] -} -``` - -17. 请求示例 last: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select last s3 from root.sg27"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "columnNames": [ - "timeseries", - "value", - "dataType" - ], - "timestamps": [ - 1635232143960 - ], - "values": [ - [ - "root.sg27.s3" - ], - [ - "11" - ], - [ - "INT32" - ] - ] -} -``` - -18. 请求示例 disable align: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select * from root.sg27 disable align"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "code": 407, - "message": "disable align clauses are not supported." -} -``` - -19. 请求示例 align by device: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(s3) from root.sg27 align by device"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "code": 407, - "message": "align by device clauses are not supported." -} -``` - -20. 请求示例 select into: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select s3, s4 into root.sg29.s1, root.sg29.s2 from root.sg27"}' http://127.0.0.1:18080/rest/v1/query -``` - -- 响应示例: - -```json -{ - "code": 407, - "message": "select into clauses are not supported." -} -``` - -### nonQuery - -请求方式:`POST` - -请求头:`application/json` - -请求路径:`http://ip:port/rest/v1/nonQuery` - -参数说明: - -|参数名称 |参数类型 |是否必填|参数描述| -| ------------ | ------------ | ------------ |------------ | -| sql | string | 是 | | - -请求示例: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"CREATE DATABASE root.ln"}' http://127.0.0.1:18080/rest/v1/nonQuery -``` - -响应参数: - -|参数名称 |参数类型 |参数描述| -| ------------ | ------------ | ------------| -| code | integer | 状态码 | -| message | string | 信息提示 | - -响应示例: -```json -{ - "code": 200, - "message": "SUCCESS_STATUS" -} -``` - - - -### insertTablet - -请求方式:`POST` - -请求头:`application/json` - -请求路径:`http://ip:port/rest/v1/insertTablet` - -参数说明: - -| 参数名称 |参数类型 |是否必填|参数描述| -|--------------| ------------ | ------------ |------------ | -| timestamps | array | 是 | 时间列 | -| measurements | array | 是 | 测点名称 | -| dataTypes | array | 是 | 数据类型 | -| values | array | 是 | 值列,每一列中的值可以为 `null` | -| isAligned | boolean | 是 | 是否是对齐时间序列 | -| deviceId | string | 是 | 设备名称 | - -请求示例: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"timestamps":[1635232143960,1635232153960],"measurements":["s3","s4"],"dataTypes":["INT32","BOOLEAN"],"values":[[11,null],[false,true]],"isAligned":false,"deviceId":"root.sg27"}' http://127.0.0.1:18080/rest/v1/insertTablet -``` - -响应参数: - -|参数名称 |参数类型 |参数描述| -| ------------ | ------------ | ------------| -| code | integer | 状态码 | -| message | string | 信息提示 | - -响应示例: -```json -{ - "code": 200, - "message": "SUCCESS_STATUS" -} -``` - - -## 配置 - -配置位于 `iotdb-datanode.properties` 中。 - - - -* 将 `enable_rest_service` 设置为 `true` 以启用该模块,而将 `false` 设置为禁用该模块。默认情况下,该值为 `false`。 - -```properties -enable_rest_service=true -``` - -* 仅在 `enable_rest_service=true` 时生效。将 `rest_service_port `设置为数字(1025~65535),以自定义REST服务套接字端口。默认情况下,值为 `18080`。 - -```properties -rest_service_port=18080 -``` - -* 将 'enable_swagger' 设置 'true' 启用swagger来展示rest接口信息, 而设置为 'false' 关闭该功能. 默认情况下,该值为 `false`。 - -```properties -enable_swagger=false -``` - -* 一次查询能返回的结果集最大行数。当返回结果集的行数超出参数限制时,您只会得到在行数范围内的结果集,且将得到状态码`411`。 - -```properties -rest_query_default_row_size_limit=10000 -``` - -* 缓存客户登录信息的过期时间(用于加速用户鉴权的速度,单位为秒,默认是8个小时) - -```properties -cache_expire=28800 -``` - -* 缓存中存储的最大用户数量(默认是100) - -```properties -cache_max_num=100 -``` - -* 缓存初始容量(默认是10) - -```properties -cache_init_num=10 -``` - -* REST Service 是否开启 SSL 配置,将 `enable_https` 设置为 `true` 以启用该模块,而将 `false` 设置为禁用该模块。默认情况下,该值为 `false`。 - -```properties -enable_https=false -``` - -* keyStore 所在路径(非必填) - -```properties -key_store_path= -``` - - -* keyStore 密码(非必填) - -```properties -key_store_pwd= -``` - - -* trustStore 所在路径(非必填) - -```properties -trust_store_path= -``` - -* trustStore 密码(非必填) - -```properties -trust_store_pwd= -``` - - -* SSL 超时时间,单位为秒 - -```properties -idle_timeout=5000 -``` diff --git a/src/zh/UserGuide/V1.3.0-2/API/RestServiceV2.md b/src/zh/UserGuide/V1.3.0-2/API/RestServiceV2.md deleted file mode 100644 index cf6d3bfce..000000000 --- a/src/zh/UserGuide/V1.3.0-2/API/RestServiceV2.md +++ /dev/null @@ -1,980 +0,0 @@ - - -# RESTful API V2 -IoTDB 的 RESTful 服务可用于查询、写入和管理操作,它使用 OpenAPI 标准来定义接口并生成框架。 - -## 开启RESTful 服务 -RESTful 服务默认情况是关闭的 - - 找到IoTDB安装目录下面的`conf/iotdb-datanode.properties`文件,将 `enable_rest_service` 设置为 `true` 以启用该模块。 - - ```properties - enable_rest_service=true - ``` - -## 鉴权 -除了检活接口 `/ping`,RESTful 服务使用了基础(basic)鉴权,每次 URL 请求都需要在 header 中携带 `'Authorization': 'Basic ' + base64.encode(username + ':' + password)`。 - -示例中使用的用户名为:`root`,密码为:`root`,对应的 Basic 鉴权 Header 格式为 - -``` -Authorization: Basic cm9vdDpyb290 -``` - -- 若用户名密码认证失败,则返回如下信息: - - HTTP 状态码:`401` - - 返回结构体如下 - ```json - { - "code": 600, - "message": "WRONG_LOGIN_PASSWORD_ERROR" - } - ``` - -- 若未设置 `Authorization`,则返回如下信息: - - HTTP 状态码:`401` - - 返回结构体如下 - ```json - { - "code": 603, - "message": "UNINITIALIZED_AUTH_ERROR" - } - ``` - -## 接口 - -### ping - -ping 接口可以用于线上服务检活。 - -请求方式:`GET` - -请求路径:http://ip:port/ping - -请求示例: - -```shell -$ curl http://127.0.0.1:18080/ping -``` - -返回的 HTTP 状态码: - -- `200`:当前服务工作正常,可以接收外部请求。 -- `503`:当前服务出现异常,不能接收外部请求。 - -响应参数: - -|参数名称 |参数类型 |参数描述| -| ------------ | ------------ | ------------| -| code | integer | 状态码 | -| message | string | 信息提示 | - -响应示例: - -- HTTP 状态码为 `200` 时: - - ```json - { - "code": 200, - "message": "SUCCESS_STATUS" - } - ``` - -- HTTP 状态码为 `503` 时: - - ```json - { - "code": 500, - "message": "thrift service is unavailable" - } - ``` - -> `/ping` 接口访问不需要鉴权。 - -### query - -query 接口可以用于处理数据查询和元数据查询。 - -请求方式:`POST` - -请求头:`application/json` - -请求路径: `http://ip:port/rest/v2/query` - -参数说明: - -| 参数名称 |参数类型 |是否必填|参数描述| -|-----------| ------------ | ------------ |------------ | -| sql | string | 是 | | -| row_limit | integer | 否 | 一次查询能返回的结果集的最大行数。
如果不设置该参数,将使用配置文件的 `rest_query_default_row_size_limit` 作为默认值。
当返回结果集的行数超出限制时,将返回状态码 `411`。 | - -响应参数: - -| 参数名称 |参数类型 |参数描述| -|--------------| ------------ | ------------| -| expressions | array | 用于数据查询时结果集列名的数组,用于元数据查询时为`null`| -| column_names | array | 用于元数据查询结果集列名数组,用于数据查询时为`null` | -| timestamps | array | 时间戳列,用于元数据查询时为`null` | -| values |array|二维数组,第一维与结果集列名数组的长度相同,第二维数组代表结果集的一列| - -请求示例如下所示: - -提示:为了避免OOM问题,不推荐使用select * from root.xx.** 这种查找方式。 - -1. 请求示例 表达式查询: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select s3, s4, s3 + 1 from root.sg27 limit 2"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": [ - "root.sg27.s3", - "root.sg27.s4", - "root.sg27.s3 + 1" - ], - "column_names": null, - "timestamps": [ - 1635232143960, - 1635232153960 - ], - "values": [ - [ - 11, - null - ], - [ - false, - true - ], - [ - 12.0, - null - ] - ] -} -``` - -2.请求示例 show child paths: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show child paths root"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "child paths" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ] - ] -} -``` - -3. 请求示例 show child nodes: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show child nodes root"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "child nodes" - ], - "timestamps": null, - "values": [ - [ - "sg27", - "sg28" - ] - ] -} -``` - -4. 请求示例 show all ttl: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show all ttl"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "database", - "ttl" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ], - [ - null, - null - ] - ] -} -``` - -5. 请求示例 show ttl: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show ttl on root.sg27"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "database", - "ttl" - ], - "timestamps": null, - "values": [ - [ - "root.sg27" - ], - [ - null - ] - ] -} -``` - -6. 请求示例 show functions: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show functions"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "function name", - "function type", - "class name (UDF)" - ], - "timestamps": null, - "values": [ - [ - "ABS", - "ACOS", - "ASIN", - ... - ], - [ - "built-in UDTF", - "built-in UDTF", - "built-in UDTF", - ... - ], - [ - "org.apache.iotdb.db.query.udf.builtin.UDTFAbs", - "org.apache.iotdb.db.query.udf.builtin.UDTFAcos", - "org.apache.iotdb.db.query.udf.builtin.UDTFAsin", - ... - ] - ] -} -``` - -7. 请求示例 show timeseries: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show timeseries"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "timeseries", - "alias", - "database", - "dataType", - "encoding", - "compression", - "tags", - "attributes" - ], - "timestamps": null, - "values": [ - [ - "root.sg27.s3", - "root.sg27.s4", - "root.sg28.s3", - "root.sg28.s4" - ], - [ - null, - null, - null, - null - ], - [ - "root.sg27", - "root.sg27", - "root.sg28", - "root.sg28" - ], - [ - "INT32", - "BOOLEAN", - "INT32", - "BOOLEAN" - ], - [ - "RLE", - "RLE", - "RLE", - "RLE" - ], - [ - "SNAPPY", - "SNAPPY", - "SNAPPY", - "SNAPPY" - ], - [ - null, - null, - null, - null - ], - [ - null, - null, - null, - null - ] - ] -} -``` - -8. 请求示例 show latest timeseries: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show latest timeseries"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "timeseries", - "alias", - "database", - "dataType", - "encoding", - "compression", - "tags", - "attributes" - ], - "timestamps": null, - "values": [ - [ - "root.sg28.s4", - "root.sg27.s4", - "root.sg28.s3", - "root.sg27.s3" - ], - [ - null, - null, - null, - null - ], - [ - "root.sg28", - "root.sg27", - "root.sg28", - "root.sg27" - ], - [ - "BOOLEAN", - "BOOLEAN", - "INT32", - "INT32" - ], - [ - "RLE", - "RLE", - "RLE", - "RLE" - ], - [ - "SNAPPY", - "SNAPPY", - "SNAPPY", - "SNAPPY" - ], - [ - null, - null, - null, - null - ], - [ - null, - null, - null, - null - ] - ] -} -``` - -9. 请求示例 count timeseries: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"count timeseries root.**"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "count" - ], - "timestamps": null, - "values": [ - [ - 4 - ] - ] -} -``` - -10. 请求示例 count nodes: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"count nodes root.** level=2"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "count" - ], - "timestamps": null, - "values": [ - [ - 4 - ] - ] -} -``` - -11. 请求示例 show devices: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show devices"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "devices", - "isAligned" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ], - [ - "false", - "false" - ] - ] -} -``` - -12. 请求示例 show devices with database: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"show devices with database"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "devices", - "database", - "isAligned" - ], - "timestamps": null, - "values": [ - [ - "root.sg27", - "root.sg28" - ], - [ - "root.sg27", - "root.sg28" - ], - [ - "false", - "false" - ] - ] -} -``` - -13. 请求示例 list user: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"list user"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "user" - ], - "timestamps": null, - "values": [ - [ - "root" - ] - ] -} -``` - -14. 请求示例 原始聚合查询: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(*) from root.sg27"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": [ - "count(root.sg27.s3)", - "count(root.sg27.s4)" - ], - "column_names": null, - "timestamps": [ - 0 - ], - "values": [ - [ - 1 - ], - [ - 2 - ] - ] -} -``` - -15. 请求示例 group by level: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(*) from root.** group by level = 1"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "count(root.sg27.*)", - "count(root.sg28.*)" - ], - "timestamps": null, - "values": [ - [ - 3 - ], - [ - 3 - ] - ] -} -``` - -16. 请求示例 group by: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(*) from root.sg27 group by([1635232143960,1635232153960),1s)"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": [ - "count(root.sg27.s3)", - "count(root.sg27.s4)" - ], - "column_names": null, - "timestamps": [ - 1635232143960, - 1635232144960, - 1635232145960, - 1635232146960, - 1635232147960, - 1635232148960, - 1635232149960, - 1635232150960, - 1635232151960, - 1635232152960 - ], - "values": [ - [ - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - [ - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] - ] -} -``` - -17. 请求示例 last: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select last s3 from root.sg27"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "expressions": null, - "column_names": [ - "timeseries", - "value", - "dataType" - ], - "timestamps": [ - 1635232143960 - ], - "values": [ - [ - "root.sg27.s3" - ], - [ - "11" - ], - [ - "INT32" - ] - ] -} -``` - -18. 请求示例 disable align: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select * from root.sg27 disable align"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "code": 407, - "message": "disable align clauses are not supported." -} -``` - -19. 请求示例 align by device: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select count(s3) from root.sg27 align by device"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "code": 407, - "message": "align by device clauses are not supported." -} -``` - -20. 请求示例 select into: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"select s3, s4 into root.sg29.s1, root.sg29.s2 from root.sg27"}' http://127.0.0.1:18080/rest/v2/query -``` - -- 响应示例: - -```json -{ - "code": 407, - "message": "select into clauses are not supported." -} -``` - -### nonQuery - -请求方式:`POST` - -请求头:`application/json` - -请求路径:`http://ip:port/rest/v2/nonQuery` - -参数说明: - -|参数名称 |参数类型 |是否必填|参数描述| -| ------------ | ------------ | ------------ |------------ | -| sql | string | 是 | | - -请求示例: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"sql":"CREATE DATABASE root.ln"}' http://127.0.0.1:18080/rest/v2/nonQuery -``` - -响应参数: - -|参数名称 |参数类型 |参数描述| -| ------------ | ------------ | ------------| -| code | integer | 状态码 | -| message | string | 信息提示 | - -响应示例: -```json -{ - "code": 200, - "message": "SUCCESS_STATUS" -} -``` - - - -### insertTablet - -请求方式:`POST` - -请求头:`application/json` - -请求路径:`http://ip:port/rest/v2/insertTablet` - -参数说明: - -| 参数名称 |参数类型 |是否必填|参数描述| -|--------------| ------------ | ------------ |------------ | -| timestamps | array | 是 | 时间列 | -| measurements | array | 是 | 测点名称 | -| data_types | array | 是 | 数据类型 | -| values | array | 是 | 值列,每一列中的值可以为 `null` | -| is_aligned | boolean | 是 | 是否是对齐时间序列 | -| device | string | 是 | 设备名称 | - -请求示例: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"timestamps":[1635232143960,1635232153960],"measurements":["s3","s4"],"data_types":["INT32","BOOLEAN"],"values":[[11,null],[false,true]],"is_aligned":false,"device":"root.sg27"}' http://127.0.0.1:18080/rest/v2/insertTablet -``` - -响应参数: - -|参数名称 |参数类型 |参数描述| -| ------------ | ------------ | ------------| -| code | integer | 状态码 | -| message | string | 信息提示 | - -响应示例: -```json -{ - "code": 200, - "message": "SUCCESS_STATUS" -} -``` - -### insertRecords - -请求方式:`POST` - -请求头:`application/json` - -请求路径:`http://ip:port/rest/v2/insertRecords` - -参数说明: - -| 参数名称 |参数类型 |是否必填|参数描述| -|-------------------| ------------ | ------------ |------------ | -| timestamps | array | 是 | 时间列 | -| measurements_list | array | 是 | 测点名称 | -| data_types_list | array | 是 | 数据类型 | -| values_list | array | 是 | 值列,每一列中的值可以为 `null` | -| devices | string | 是 | 设备名称 | -| is_aligned | string | 是 | 是否是对齐时间序列 | - -请求示例: -```shell -curl -H "Content-Type:application/json" -H "Authorization:Basic cm9vdDpyb290" -X POST --data '{"timestamps":[1635232113960,1635232151960,1635232143960,1635232143960],"measurements_list":[["s33","s44"],["s55","s66"],["s77","s88"],["s771","s881"]],"data_types_list":[["INT32","INT64"],["FLOAT","DOUBLE"],["FLOAT","DOUBLE"],["BOOLEAN","TEXT"]],"values_list":[[1,11],[2.1,2],[4,6],[false,"cccccc"]],"is_aligned":false,"devices":["root.s1","root.s1","root.s1","root.s3"]}' http://127.0.0.1:18080/rest/v2/insertRecords -``` - -响应参数: - -|参数名称 |参数类型 |参数描述| -| ------------ | ------------ | ------------| -| code | integer | 状态码 | -| message | string | 信息提示 | - -响应示例: -```json -{ - "code": 200, - "message": "SUCCESS_STATUS" -} -``` - - -## 配置 - -配置位于 `iotdb-datanode.properties` 中。 - - - -* 将 `enable_rest_service` 设置为 `true` 以启用该模块,而将 `false` 设置为禁用该模块。默认情况下,该值为 `false`。 - -```properties -enable_rest_service=true -``` - -* 仅在 `enable_rest_service=true` 时生效。将 `rest_service_port `设置为数字(1025~65535),以自定义REST服务套接字端口。默认情况下,值为 `18080`。 - -```properties -rest_service_port=18080 -``` - -* 将 'enable_swagger' 设置 'true' 启用swagger来展示rest接口信息, 而设置为 'false' 关闭该功能. 默认情况下,该值为 `false`。 - -```properties -enable_swagger=false -``` - -* 一次查询能返回的结果集最大行数。当返回结果集的行数超出参数限制时,您只会得到在行数范围内的结果集,且将得到状态码`411`。 - -```properties -rest_query_default_row_size_limit=10000 -``` - -* 缓存客户登录信息的过期时间(用于加速用户鉴权的速度,单位为秒,默认是8个小时) - -```properties -cache_expire=28800 -``` - -* 缓存中存储的最大用户数量(默认是100) - -```properties -cache_max_num=100 -``` - -* 缓存初始容量(默认是10) - -```properties -cache_init_num=10 -``` - -* REST Service 是否开启 SSL 配置,将 `enable_https` 设置为 `true` 以启用该模块,而将 `false` 设置为禁用该模块。默认情况下,该值为 `false`。 - -```properties -enable_https=false -``` - -* keyStore 所在路径(非必填) - -```properties -key_store_path= -``` - - -* keyStore 密码(非必填) - -```properties -key_store_pwd= -``` - - -* trustStore 所在路径(非必填) - -```properties -trust_store_path= -``` - -* trustStore 密码(非必填) - -```properties -trust_store_pwd= -``` - - -* SSL 超时时间,单位为秒 - -```properties -idle_timeout=5000 -``` diff --git a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Cluster-Concept.md b/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Cluster-Concept.md deleted file mode 100644 index f853a8e05..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Cluster-Concept.md +++ /dev/null @@ -1,55 +0,0 @@ - - -# 集群相关概念 -下图展示了一个常见的 IoTDB 3C3D1A(3 个 ConfigNode、3 个 DataNode 和 1 个 AINode)的集群部署模式: - - -其中包括了 IoTDB 集群使用中用户常接触到的几个概念,包括: -- **节点**(ConfigNode、DataNode、AINode); -- **槽**(SchemaSlot、DataSlot); -- **Region**(SchemaRegion、DataRegion); -- ***副本组***。 - -下文将重点对以上概念进行介绍。 - -## 节点 -IoTDB 集群包括三种节点(进程),**ConfigNode**(管理节点),**DataNode**(数据节点)和 **AINode**(分析节点),如下所示: -- **ConfigNode**:存储集群的配置信息、数据库的元数据、时间序列元数据和数据的路由信息,监控集群节点并实施负载均衡,所有 ConfigNode 之间互为全量备份,如上图中的 ConfigNode-1,ConfigNode-2 和 ConfigNode-3 所示。ConfigNode 不直接接收客户端读写请求,它会通过一系列[负载均衡算法](https://iotdb.apache.org/zh/UserGuide/latest/Technical-Insider/Cluster-data-partitioning.html)对集群中元数据和数据的分布提供指导。 -- **DataNode**:负责时间序列元数据和数据的读写,每个 DataNode 都能接收客户端读写请求并提供相应服务,如上图中的 DataNode-1,DataNode-2 和 DataNode-3 所示。接收客户端读写请求时,若 DataNode 缓存有对应的路由信息,它能直接在本地执行或是转发这些请求;否则它会向 ConfigNode 询问并缓存路由信息,以加速后续请求的服务效率。 -- **AINode**:负责与 ConfigNode 和 DataNode 交互来扩展 IoTDB 集群对时间序列进行智能分析的能力,支持从外部引入已有机器学习模型进行注册,并使用注册的模型在指定时序数据上通过简单 SQL 语句完成时序分析任务的过程,将模型的创建、管理及推理融合在数据库引擎中。目前已提供常见时序分析场景(例如预测与异常检测)的机器学习算法或自研模型。 - -## 槽 -IoTDB 内部将元数据和数据划分成多个更小的、更易于管理的单元,每个单元称为一个**槽**。槽是一个逻辑概念,在 IoTDB 集群中,**元数据槽**和**数据槽**定义如下: -- **元数据槽**(SchemaSlot):一部分元数据集合,元数据槽总数固定,默认数量为 1000,IoTDB 使用哈希算法将所有设备均匀地分配到这些元数据槽中。 -- **数据槽**(DataSlot):一部分数据集合,在元数据槽的基础上,将对应设备的数据按时间范围划分为数据槽,默认的时间范围为 7 天。 - -## Region -在 IoTDB 中,元数据和数据被复制到各个 DataNode 以获得集群高可用性。然而以槽为粒度进行复制会增加集群管理成本、降低写入吞吐。因此 IoTDB 引入 **Region** 这一概念,将元数据槽和数据槽分别分配给 SchemaRegion 和 DataRegion 后,以 Region 为单位进行复制。**SchemRegion** 和 **DataRegion** 的详细定义如下: -- **SchemaRegion**:元数据存储和复制的基本单元,集群每个数据库的所有元数据槽会被均匀分配给该数据库的所有 SchemaRegion。拥有相同 RegionID 的 SchemaRegion 互为副本,如上图中 SchemaRegion-1 拥有三个副本,分别放置于 DataNode-1,DataNode-2 和 DataNode-3。 -- **DataRegion**:数据存储和复制的基本单元,集群每个数据库的所有数据槽会被均匀分配给该数据库的所有 DataRegion。拥有相同 RegionID 的 DataRegion 互为副本,如上图中 DataRegion-2 拥有两个副本,分别放置于 DataNode-1 和 DataNode-2。 - -## 副本组 -Region 的副本对集群的容灾能力至关重要。对于每个 Region 的所有副本,它们的角色分为 **leader** 和 **follower**,共同提供读写服务。不同架构下的副本组配置推荐如下: -| 类别 | 配置项 | 单机推荐配置 | 分布式推荐配置 | -| :-: | :-: | :-: | :-: | -| 元数据 | schema_replication_factor | 1 | 3 | -| 数据 | data_replication_factor | 1 | 2 | \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Model-and-Terminology.md b/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Model-and-Terminology.md deleted file mode 100644 index a42a895b8..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Model-and-Terminology.md +++ /dev/null @@ -1,140 +0,0 @@ - - -# 数据模型 - -我们以风电场物联网场景为例,说明如何在 IoTDB 中创建一个正确的数据模型。 - -根据企业组织结构和设备实体层次结构,我们将其物联网数据模型表示为如下图所示的属性层级组织结构,即电力集团层-风电场层-实体层-物理量层。其中 ROOT 为根节点,物理量层的每一个节点为叶子节点。IoTDB 采用树形结构定义数据模式,以从 ROOT 节点到叶子节点的路径来命名一个时间序列,层次间以“.”连接。例如,下图最左侧路径对应的时间序列名称为`ROOT.ln.wf01.wt01.status`。 - - - -在上图所描述的实际场景中,有许多实体所采集的物理量相同,即具有相同的工况名称和类型,因此,可以声明一个**元数据模板**来定义可采集的物理量集合。在实践中,元数据模板的使用可帮助减少元数据的资源占用,详细内容参见 [元数据模板](../User-Manual/Operate-Metadata.md#元数据模板管理)。 - -IoTDB 模型结构涉及的基本概念在下文将做详细叙述。 - -## 数据库(Database) - -用户可以将任意前缀路径设置成数据库。如有 4 条时间序列`root.ln.wf01.wt01.status`, `root.ln.wf01.wt01.temperature`, `root.ln.wf02.wt02.hardware`, `root.ln.wf02.wt02.status`,路径`root.ln`下的两个实体 `wf01`, `wf02`可能属于同一个业主,或者同一个制造商,这时候就可以将前缀路径`root.ln`指定为一个数据库。未来`root.ln`下增加了新的实体,也将属于该数据库。 - -一个 database 中的所有数据会存储在同一批文件夹下,不同 database 的数据会存储在磁盘的不同文件夹下,从而实现物理隔离。一般情况下建议设置 1 个 database。 - -> 注意 1:不允许将一个完整路径(如上例的`root.ln.wf01.wt01.status`) 设置成 database。 -> -> 注意 2:一个时间序列其前缀必须属于某个 database。在创建时间序列之前,用户必须设定该序列属于哪个database。只有设置了 database 的时间序列才可以被持久化在磁盘上。 -> -> 注意 3:被设置为数据库的路径总字符数不能超过64,包括路径开头的`root.`这5个字符。 - -一个前缀路径一旦被设定成 database 后就不可以再更改这个 database 的设定。 - -一个 database 设定后,其对应的前缀路径的祖先层级与孩子及后裔层级也不允许再设置 database(如,`root.ln`设置 database 后,root 层级与`root.ln.wf01`不允许被设置为 database)。 - -Database 节点名只支持中英文字符、数字和下划线的组合。例如`root.数据库_1` 。 - -**无模式写入**:可以在未定义元数据时, 通过 insert 语句直接写入数据,数据库中将自动识别并注册所需的元数据,实现自动建模。 - -## 设备(Device) - -**一个物理设备**,也称实体(Entity),是在实际场景中拥有物理量的设备或装置。在 IoTDB 当中,所有的物理量都有其对应的归属实体。实体无需手动创建,默认为倒数第二层。实体是管理的一组时间序列的组合,可以是一个物理设备、测量装置、传感器集合等。 - - -## 物理量(Measurement) - -**物理量**,也称工况或字段(field),是在实际场景中检测装置所记录的测量信息,且可以按一定规律变换成为电信号或其他所需形式的信息输出并发送给 IoTDB。在 IoTDB 当中,存储的所有数据及路径,都是以物理量为单位进行组织。 - -## 时间序列 - -### 时间戳 (Timestamp) - -时间戳是一个数据到来的时间点,其中包括绝对时间戳和相对时间戳,详细描述参见 [数据类型文档](./Data-Type.md)。 - -### 数据点(Data Point) - -**一个“时间戳-值”对**。 - -### 时间序列(Timeseries) - -**一个物理实体的某个物理量在时间轴上的记录**,是数据点的序列。 - -一个实体的一个物理量对应一个时间序列,即实体+物理量=时间序列。 - -时间序列也被称测点(meter)、时间线(timeline)。实时数据库中常被称作标签(tag)、参数(parameter)。 IoTDB管理的测点数量可达数十亿以上。 - -例如,ln 电力集团、wf01 风电场的实体 wt01 有名为 status 的物理量,则它的时间序列可以表示为:`root.ln.wf01.wt01.status`。 - -### 对齐时间序列(Aligned Timeseries) - -在实际应用中,存在某些实体的多个物理量**同时采样**,形成一组时间列相同的时间序列,这样的一组时间序列在Apache IoTDB中可以建模为对齐时间序列。 - -在插入数据时,一组对齐序列的时间戳列在内存和磁盘中仅需存储一次,而不是每个时间序列存储一次。 - -对齐的一组时间序列最好同时创建。 - -不可以在对齐序列所属的实体下创建非对齐的序列,不可以在非对齐序列所属的实体下创建对齐序列。 - -查询数据时,可以对于每一条时间序列单独查询。 - -插入数据时,对齐的时间序列中某列的某些行允许有空值。 - - - -在后续数据定义语言、数据操作语言和 Java 原生接口章节,将对涉及到对齐时间序列的各种操作进行逐一介绍。 - -## 路径(Path) - -路径(`path`)是指符合以下约束的表达式: - -```sql -path - : nodeName ('.' nodeName)* - ; - -nodeName - : wildcard? identifier wildcard? - | wildcard - ; - -wildcard - : '*' - | '**' - ; -``` - -我们称一个路径中由 `'.'` 分割的部分叫做路径结点名(`nodeName`)。例如:`root.a.b.c`为一个层级为 4 的路径。 - -下面是对路径结点名(`nodeName`)的约束: - -* `root` 作为一个保留字符,它只允许出现在下文提到的时间序列的开头,若其他层级出现 `root`,则无法解析,提示报错。 -* 除了时间序列的开头的层级(`root`)外,其他的层级支持的字符如下: - * [ 0-9 a-z A-Z _ ] (字母,数字,下划线) - * ['\u2E80'..'\u9FFF'] (UNICODE 中文字符) -* 特别地,如果系统在 Windows 系统上部署,那么 database 路径结点名是大小写不敏感的。例如,同时创建`root.ln` 和 `root.LN` 是不被允许的。 -* 如果需要在路径结点名中用特殊字符,可以用反引号引用路径结点名,具体使用方法可以参考[语法约定](../User-Manual/Syntax-Rule.md)。 - -## 路径模式(Path Pattern) - -为了使得在表达多个时间序列的时候更加方便快捷,IoTDB 为用户提供带通配符`*`或`**`的路径。用户可以利用两种通配符构造出期望的路径模式。通配符可以出现在路径中的任何层。 - -`*`在路径中表示一层。例如`root.vehicle.*.sensor1`代表的是以`root.vehicle`为前缀,以`sensor1`为后缀,层次等于 4 层的路径。 - -`**`在路径中表示是(`*`)+,即为一层或多层`*`。例如`root.vehicle.device1.**`代表的是`root.vehicle.device1.*`, `root.vehicle.device1.*.*`, `root.vehicle.device1.*.*.*`等所有以`root.vehicle.device1`为前缀路径的大于等于 4 层的路径;`root.vehicle.**.sensor1`代表的是以`root.vehicle`为前缀,以`sensor1`为后缀,层次大于等于 4 层的路径。 - -> 注意:`*`和`**`不能放在路径开头。 diff --git a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Type.md b/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Type.md deleted file mode 100644 index a8527e86b..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Data-Type.md +++ /dev/null @@ -1,179 +0,0 @@ - - -# 数据类型 - -## 基本数据类型 - -IoTDB 支持以下六种数据类型: - -* BOOLEAN(布尔值) -* INT32(整型) -* INT64(长整型) -* FLOAT(单精度浮点数) -* DOUBLE(双精度浮点数) -* TEXT(长字符串) - - -### 浮点数精度配置 - -对于 **FLOAT** 与 **DOUBLE** 类型的序列,如果编码方式采用 `RLE`或 `TS_2DIFF`,可以在创建序列时通过 `MAX_POINT_NUMBER` 属性指定浮点数的小数点后位数。 - -例如, -```sql -CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=FLOAT, ENCODING=RLE, 'MAX_POINT_NUMBER'='2'; -``` - -若不指定,系统会按照配置文件 `iotdb-common.properties` 中的 [float_precision](../Reference/Common-Config-Manual.md) 项配置(默认为 2 位)。 - -### 数据类型兼容性 - -当写入数据的类型与序列注册的数据类型不一致时, -- 如果序列数据类型不兼容写入数据类型,系统会给出错误提示。 -- 如果序列数据类型兼容写入数据类型,系统会进行数据类型的自动转换,将写入的数据类型更正为注册序列的类型。 - -各数据类型的兼容情况如下表所示: - -| 序列数据类型 | 支持的写入数据类型 | -|--------------|--------------------------| -| BOOLEAN | BOOLEAN | -| INT32 | INT32 | -| INT64 | INT32 INT64 | -| FLOAT | INT32 FLOAT | -| DOUBLE | INT32 INT64 FLOAT DOUBLE | -| TEXT | TEXT | - -## 时间戳类型 - -时间戳是一个数据到来的时间点,其中包括绝对时间戳和相对时间戳。 - -### 绝对时间戳 - -IOTDB 中绝对时间戳分为二种,一种为 LONG 类型,一种为 DATETIME 类型(包含 DATETIME-INPUT, DATETIME-DISPLAY 两个小类)。 - -在用户在输入时间戳时,可以使用 LONG 类型的时间戳或 DATETIME-INPUT 类型的时间戳,其中 DATETIME-INPUT 类型的时间戳支持格式如表所示: - -
- -**DATETIME-INPUT 类型支持格式** - - -| format | -| :--------------------------- | -| yyyy-MM-dd HH:mm:ss | -| yyyy/MM/dd HH:mm:ss | -| yyyy.MM.dd HH:mm:ss | -| yyyy-MM-dd HH:mm:ssZZ | -| yyyy/MM/dd HH:mm:ssZZ | -| yyyy.MM.dd HH:mm:ssZZ | -| yyyy/MM/dd HH:mm:ss.SSS | -| yyyy-MM-dd HH:mm:ss.SSS | -| yyyy.MM.dd HH:mm:ss.SSS | -| yyyy-MM-dd HH:mm:ss.SSSZZ | -| yyyy/MM/dd HH:mm:ss.SSSZZ | -| yyyy.MM.dd HH:mm:ss.SSSZZ | -| ISO8601 standard time format | - - -
- - -IoTDB 在显示时间戳时可以支持 LONG 类型以及 DATETIME-DISPLAY 类型,其中 DATETIME-DISPLAY 类型可以支持用户自定义时间格式。自定义时间格式的语法如表所示: - -
- -**DATETIME-DISPLAY 自定义时间格式的语法** - - -| 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)+ - ``` - -
- - **The syntax of the duration unit** - - - | 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 天 2 小时的时间 - now() - 1w //比服务器时间早 1 周的时间 - ``` - - > 注意:'+'和'-'的左右两边必须有空格 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Encoding-and-Compression.md b/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Encoding-and-Compression.md deleted file mode 100644 index b27c0c9c2..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Encoding-and-Compression.md +++ /dev/null @@ -1,121 +0,0 @@ - - -# 编码和压缩 - -## 编码方式 - -### 基本编码方式 - -为了提高数据的存储效率,需要在数据写入的过程中对数据进行编码,从而减少磁盘空间的使用量。在写数据以及读数据的过程中都能够减少 I/O 操作的数据量从而提高性能。IoTDB 支持多种针对不同类型的数据的编码方法: - -1. PLAIN 编码(PLAIN) - - PLAIN 编码,默认的编码方式,即不编码,支持多种数据类型,压缩和解压缩的时间效率较高,但空间存储效率较低。 - -2. 二阶差分编码(TS_2DIFF) - - 二阶差分编码,比较适合编码单调递增或者递减的序列数据,不适合编码波动较大的数据。 - -3. 游程编码(RLE) - - 游程编码,比较适合存储某些数值连续出现的序列,不适合编码大部分情况下前后值不一样的序列数据。 - - 游程编码也可用于对浮点数进行编码,但在创建时间序列的时候需指定保留小数位数(MAX_POINT_NUMBER,具体指定方式参见本文 [SQL 参考文档](../SQL-Manual/SQL-Manual.md))。比较适合存储某些浮点数值连续出现的序列数据,不适合存储对小数点后精度要求较高以及前后波动较大的序列数据。 - - > 游程编码(RLE)和二阶差分编码(TS_2DIFF)对 float 和 double 的编码是有精度限制的,默认保留 2 位小数。推荐使用 GORILLA。 - -4. GORILLA 编码(GORILLA) - - GORILLA 编码是一种无损编码,它比较适合编码前后值比较接近的数值序列,不适合编码前后波动较大的数据。 - - 当前系统中存在两个版本的 GORILLA 编码实现,推荐使用`GORILLA`,不推荐使用`GORILLA_V1`(已过时)。 - - 使用限制:使用 Gorilla 编码 INT32 数据时,需要保证序列中不存在值为`Integer.MIN_VALUE`的数据点;使用 Gorilla 编码 INT64 数据时,需要保证序列中不存在值为`Long.MIN_VALUE`的数据点。 - -5. 字典编码 (DICTIONARY) - - 字典编码是一种无损编码。它适合编码基数小的数据(即数据去重后唯一值数量小)。不推荐用于基数大的数据。 - -6. ZIGZAG 编码 - - ZigZag编码将有符号整型映射到无符号整型,适合比较小的整数。 - -7. CHIMP 编码 - - CHIMP 是一种无损编码。它是一种新的流式浮点数据压缩算法,可以节省存储空间。这个编码适用于前后值比较接近的数值序列,对波动小和随机噪声少的序列数据更加友好。 - - 使用限制:如果对 INT32 类型数据使用 CHIMP 编码,需要确保数据点中没有 `Integer.MIN_VALUE`。 如果对 INT64 类型数据使用 CHIMP 编码,需要确保数据点中没有 `Long.MIN_VALUE`。 - -8. SPRINTZ 编码 - - SPRINTZ编码是一种无损编码,将原始时序数据分别进行预测、Zigzag编码、位填充和游程编码。SPRINTZ编码适合差分值的绝对值较小(即波动较小)的时序数据,不适合差分值较大(即波动较大)的时序数据。 - -9. RLBE 编码 - - RLBE编码是一种无损编码,将差分编码,位填充编码,游程长度,斐波那契编码和拼接等编码思想结合到一起。RLBE编码适合递增且递增值较小的时序数据,不适合波动较大的时序数据。 - -### 数据类型与编码的对应关系 - -前文介绍的五种编码适用于不同的数据类型,若对应关系错误,则无法正确创建时间序列。数据类型与支持其编码的编码方式对应关系总结如下表所示。 - -| **数据类型** | **推荐编码(默认)** | **支持的编码** | -| ------------ | ---------------------- | ----------------------------------------------------------- | -| BOOLEAN | RLE | PLAIN, RLE | -| INT32 | TS_2DIFF | PLAIN, RLE, TS_2DIFF, GORILLA, ZIGZAG, CHIMP, SPRINTZ, RLBE | -| INT64 | TS_2DIFF | PLAIN, RLE, TS_2DIFF, GORILLA, ZIGZAG, CHIMP, SPRINTZ, RLBE | -| FLOAT | GORILLA | PLAIN, RLE, TS_2DIFF, GORILLA, CHIMP, SPRINTZ, RLBE | -| DOUBLE | GORILLA | PLAIN, RLE, TS_2DIFF, GORILLA, CHIMP, SPRINTZ, RLBE | -| TEXT | PLAIN | PLAIN, DICTIONARY | - - -当用户输入的数据类型与编码方式不对应时,系统会提示错误。如下所示,二阶差分编码不支持布尔类型: - -``` -IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF -Msg: 507: encoding TS_2DIFF does not support BOOLEAN -``` - -## 压缩方式 - -当时间序列写入并按照指定的类型编码为二进制数据后,IoTDB 会使用压缩技术对该数据进行压缩,进一步提升空间存储效率。虽然编码和压缩都旨在提升存储效率,但编码技术通常只适合特定的数据类型(如二阶差分编码只适合与 INT32 或者 INT64 编码,存储浮点数需要先将他们乘以 10m 以转换为整数),然后将它们转换为二进制流。压缩方式(SNAPPY)针对二进制流进行压缩,因此压缩方式的使用不再受数据类型的限制。 - -### 基本压缩方式 - -IoTDB 允许在创建一个时间序列的时候指定该列的压缩方式。现阶段 IoTDB 支持以下几种压缩方式: - -* UNCOMPRESSED(不压缩) -* SNAPPY 压缩 -* LZ4 压缩(推荐压缩方式) -* GZIP 压缩 -* ZSTD 压缩 -* LZMA2 压缩 - -压缩方式的指定语法详见本文 [SQL 参考文档](../SQL-Manual/SQL-Manual.md)。 - -### 压缩比统计信息 - -压缩比统计信息文件:data/datanode/system/compression_ratio - -* ratio_sum: memtable压缩比的总和 -* memtable_flush_time: memtable刷盘的总次数 - -通过 `ratio_sum / memtable_flush_time` 可以计算出平均压缩比 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/AINode_Deployment_timecho.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/AINode_Deployment_timecho.md deleted file mode 100644 index c77da0e83..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/AINode_Deployment_timecho.md +++ /dev/null @@ -1,545 +0,0 @@ - -# AINode 部署 - -## AINode介绍 - -### 能力介绍 - -AINode 是 IoTDB 在 ConfigNode、DataNode 后提供的第三种内生节点,该节点通过与 IoTDB 集群的 DataNode、ConfigNode 的交互,扩展了对时间序列进行机器学习分析的能力,支持从外部引入已有机器学习模型进行注册,并使用注册的模型在指定时序数据上通过简单 SQL 语句完成时序分析任务的过程,将模型的创建、管理及推理融合在数据库引擎中。目前已提供常见时序分析场景(例如预测与异常检测)的机器学习算法或自研模型。 - -### 交付方式 - 是 IoTDB 集群外的额外套件,独立安装包,独立激活(如需试用或使用,请联系天谋科技商务或技术支持)。 - -### 部署模式 -
- - -
- -## 安装准备 - -### 安装包获取 - - 用户可以下载AINode的软件安装包,下载并解压后即完成AINode的安装。 - - 解压后安装包(`iotdb-enterprise-ainode-.zip`),安装包解压后目录结构如下: -| **目录** | **类型** | **说明** | -| ------------ | -------- | ------------------------------------------------ | -| lib | 文件夹 | AINode编译后的二进制可执行文件以及相关的代码依赖 | -| sbin | 文件夹 | AINode的运行脚本,可以启动,移除和停止AINode | -| conf | 文件夹 | 包含AINode的配置项,具体包含以下配置项 | -| LICENSE | 文件 | 证书 | -| NOTICE | 文件 | 提示 | -| README_ZH.md | 文件 | markdown格式的中文版说明 | -| `README.md` | 文件 | 使用说明 | - -### 环境准备 -- 建议操作环境: Ubuntu, CentOS, MacOS - -- 运行环境 - - 联网环境下 Python >= 3.8即可,且带有 pip 和 venv 工具;非联网环境下需要使用 Python 3.8版本,并从 [此处](https://cloud.tsinghua.edu.cn/d/4c1342f6c272439aa96c/?p=%2Flibs&mode=list) 下载对应操作系统的zip压缩包(注意下载依赖需选择libs文件夹中的zip压缩包,如下图),并将文件夹下的所有文件拷贝到 `iotdb-enterprise-ainode-` 文件夹中 `lib` 文件夹下,并按下文步骤启动AINode。 - - - - - 环境变量中需存在 Python 解释器且可以通过 `python` 指令直接调用 - - 建议在 `iotdb-enterprise-ainode-` 文件夹下,新建 Python 解释器 venv 虚拟环境。如安装 3.8.0 版本虚拟环境,语句如下: - - ```shell - # 安装3.8.0版本的venv,创建虚拟环境,文件夹名为 `venv` - ../Python-3.8.0/python -m venv `venv` - ``` -## 安装步骤 - -### 安装 AINode - -1. AINode 激活 - - 要求 IoTDB 处于正常运行状态,且 license 中有 AINode 模块授权(通常 license 中不具有 AINode 授权,可联系天谋商务或技术支持人员获取 AINode 模块授权)。 - - 激活 AINode 模块授权方式如下: - - 方式一:激活文件拷贝激活 - - 重新启动 confignode 节点后,进入 activation 文件夹, 将 system_info 文件复制给天谋工作人员,并告知工作人员申请 AINode 独立授权; - - 收到工作人员返回的 license 文件; - - 将 license 文件放入对应节点的 activation 文件夹下; -- 方式二:激活脚本激活 - - 获取激活所需机器码,进入安装目录的 `sbin` 目录,执行激活脚本: - ```shell - cd sbin - ./start-activate.sh - ``` - - 显示如下信息,请将机器码(即该串字符)复制给天谋工作人员,并告知工作人员申请 AINode 独立授权: - ```shell - Please copy the system_info's content and send it to Timecho: - 01-KU5LDFFN-PNBEHDRH - Please enter license: - ``` - - 将工作人员返回的激活码输入上一步的命令行提示处 `Please enter license:`,如下提示: - ```shell - Please enter license: - Jw+MmF+AtexsfgNGOFgTm83BgXbq0zT1+fOfPvQsLlj6ZsooHFU6HycUSEGC78eT1g67KPvkcLCUIsz2QpbyVmPLr9x1+kVjBubZPYlVpsGYLqLFc8kgpb5vIrPLd3hGLbJ5Ks8fV1WOVrDDVQq89YF2atQa2EaB9EAeTWd0bRMZ+s9ffjc/1Zmh9NSP/T3VCfJcJQyi7YpXWy5nMtcW0gSV+S6fS5r7a96PjbtE0zXNjnEhqgRzdU+mfO8gVuUNaIy9l375cp1GLpeCh6m6pF+APW1CiXLTSijK9Qh3nsL5bAOXNeob5l+HO5fEMgzrW8OJPh26Vl6ljKUpCvpTiw== - License has been stored to sbin/../activation/license - Import completed. Please start cluster and excute 'show cluster' to verify activation status - ``` -- 更新 license 后,重新启动 DataNode 节点,进入 IoTDB 的 sbin 目录下,启动 datanode: - ```shell - cd sbin - ./start-datanode.sh -d #-d参数将在后台进行启动 - ``` - - 2. 检查Linux的内核架构 - ```shell - uname -m - ``` - - 3. 导入Python环境[下载](https://repo.anaconda.com/miniconda/) - - 推荐下载py311版本应用,导入至用户根目录下 iotdb专用文件夹 中 - - 4. 切换至iotdb专用文件夹安装Python环境 - - 以 Miniconda3-py311_24.5.0-0-Linux-x86_64 为例: - - ```shell - bash ./Miniconda3-py311_24.5.0-0-Linux-x86_64.sh - ``` - > 根据提示键入“回车”、“长按空格”、“回车”、“yes”、“yes”
- > 关闭当前SSH窗口重新连接 - - 5. 创建专用环境 - - ```shell - conda create -n ainode_py python=3.11.9 - ``` - - 根据提示键入“y” - - 6. 激活专用环境 - - ```shell - conda activate ainode_py - ``` - - 7. 验证Python版本 - - ```shell - python --version - ``` - 8. 下载导入AINode到专用文件夹,切换到专用文件夹并解压安装包 - - ```shell - unzip iotdb-enterprise-ainode-1.3.3.2.zip - ``` - - 9. 配置项修改 - - ```shell - vi iotdb-enterprise-ainode-1.3.3.2/conf/iotdb-ainode.properties - ``` - 配置项修改:[详细信息](#配置项修改) - > ain_seed_config_node=iotdb-1:10710(集群通讯节点IP:通讯节点端口)
- > ain_inference_rpc_address=iotdb-3(运行AINode的服务器IP) - - 10. 更换Python源 - - ```shell - pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ - ``` - - 11. 启动AINode节点 - - ```shell - nohup bash iotdb-enterprise-ainode-1.3.3.2/sbin/start-ainode.sh > myout.file 2>& 1 & - ``` - > 回到系统默认环境:conda deactivate - -### 配置项修改 -AINode 支持修改一些必要的参数。可以在 `conf/iotdb-ainode.properties` 文件中找到下列参数并进行持久化的修改: - -| **名称** | **描述** | **类型** | **默认值** | **改后生效方式** | -| :----------------------------- | ------------------------------------------------------------ | ------- | ------------------ | ---------------------------- | -| cluster_name | AINode 要加入集群的标识 | string | defaultCluster | 仅允许在第一次启动服务前修改 | -| ain_seed_config_node | AINode 启动时注册的 ConfigNode 地址 | String | 127.0.0.1:10710 | 仅允许在第一次启动服务前修改 | -| ain_inference_rpc_address | AINode 提供服务与通信的地址,内部服务通讯接口 | String | 127.0.0.1 | 仅允许在第一次启动服务前修改 | -| ain_inference_rpc_port | AINode 提供服务与通信的端口 | String | 10810 | 仅允许在第一次启动服务前修改 | -| ain_system_dir | AINode 元数据存储路径,相对路径的起始目录与操作系统相关,建议使用绝对路径 | String | data/AINode/system | 仅允许在第一次启动服务前修改 | -| ain_models_dir | AINode 存储模型文件的路径,相对路径的起始目录与操作系统相关,建议使用绝对路径 | String | data/AINode/models | 仅允许在第一次启动服务前修改 | -| ain_logs_dir | AINode 存储日志的路径,相对路径的起始目录与操作系统相关,建议使用绝对路径 | String | logs/AINode | 重启后生效 | -| ain_thrift_compression_enabled | AINode 是否启用 thrift 的压缩机制,0-不启动、1-启动 | Boolean | 0 | 重启后生效 | -### 启动 AINode - - 在完成 Seed-ConfigNode 的部署后,可以通过添加 AINode 节点来支持模型的注册和推理功能。在配置项中指定 IoTDB 集群的信息后,可以执行相应的指令来启动 AINode,加入 IoTDB 集群。 - -#### 联网环境启动 - -##### 启动命令 - -```shell - # 启动命令 - # Linux 和 MacOS 系统 - bash sbin/start-ainode.sh - - # Windows 系统 - sbin\start-ainode.bat - - # 后台启动命令(长期运行推荐) - # Linux 和 MacOS 系统 - nohup bash sbin/start-ainode.sh > myout.file 2>& 1 & - - # Windows 系统 - nohup bash sbin\start-ainode.bat > myout.file 2>& 1 & - ``` - -##### 详细语法 - -```shell - # 启动命令 - # Linux 和 MacOS 系统 - bash sbin/start-ainode.sh -i -r -n - - # Windows 系统 - sbin\start-ainode.bat -i -r -n - ``` - -##### 参数介绍: - -| **名称** | **标签** | **描述** | **是否必填** | **类型** | **默认值** | **输入方式** | -| ------------------- | ---- | ------------------------------------------------------------ | -------- | ------ | ---------------- | ---------------------- | -| ain_interpreter_dir | -i | AINode 所安装在的虚拟环境的解释器路径,需要使用绝对路径 | 否 | String | 默认读取环境变量 | 调用时输入或持久化修改 | -| ain_force_reinstall | -r | 该脚本在检查 AINode 安装情况的时候是否检查版本,如果检查则在版本不对的情况下会强制安装 lib 里的 whl 安装包 | 否 | Bool | false | 调用时输入 | -| ain_no_dependencies | -n | 指定在安装 AINode 的时候是否安装依赖,如果指定则仅安装 AINode 主程序而不安装依赖。 | 否 | Bool | false | 调用时输入 | - - 如不想每次启动时指定对应参数,也可以在 `conf` 文件夹下的`ainode-env.sh` 和 `ainode-env.bat` 脚本中持久化修改参数(目前支持持久化修改 ain_interpreter_dir 参数)。 - - `ainode-env.sh` : - ```shell - # The defaulte venv environment is used if ain_interpreter_dir is not set. Please use absolute path without quotation mark - # ain_interpreter_dir= - ``` - `ainode-env.bat` : -```shell - @REM The defaulte venv environment is used if ain_interpreter_dir is not set. Please use absolute path without quotation mark - @REM set ain_interpreter_dir= - ``` - 在写入参数值的后解除对应行的注释并保存即可在下一次执行脚本时生效。 - -#### 示例 - -##### 直接启动: - -```shell - # 启动命令 - # Linux 和 MacOS 系统 - bash sbin/start-ainode.sh - # Windows 系统 - sbin\start-ainode.bat - - - # 后台启动命令(长期运行推荐) - # Linux 和 MacOS 系统 - nohup bash sbin/start-ainode.sh > myout.file 2>& 1 & - # Windows 系统 - nohup bash sbin\start-ainode.bat > myout.file 2>& 1 & - ``` - -##### 更新启动: -如果 AINode 的版本进行了更新(如更新了 `lib` 文件夹),可使用此命令。首先要保证 AINode 已经停止运行,然后通过 `-r` 参数重启,该参数会根据 `lib` 下的文件重新安装 AINode。 - -```shell - # 更新启动命令 - # Linux 和 MacOS 系统 - bash sbin/start-ainode.sh -r - # Windows 系统 - sbin\start-ainode.bat -r - - - # 后台更新启动命令(长期运行推荐) - # Linux 和 MacOS 系统 - nohup bash sbin/start-ainode.sh -r > myout.file 2>& 1 & - # Windows 系统 - nohup bash sbin\start-ainode.bat -r > myout.file 2>& 1 & - ``` -#### 非联网环境启动 - -##### 启动命令 - -```shell - # 启动命令 - # Linux 和 MacOS 系统 - bash sbin/start-ainode.sh - - # Windows 系统 - sbin\start-ainode.bat - - # 后台启动命令(长期运行推荐) - # Linux 和 MacOS 系统 - nohup bash sbin/start-ainode.sh > myout.file 2>& 1 & - - # Windows 系统 - nohup bash sbin\start-ainode.bat > myout.file 2>& 1 & - ``` - -##### 详细语法 - -```shell - # 启动命令 - # Linux 和 MacOS 系统 - bash sbin/start-ainode.sh -i -r -n - - # Windows 系统 - sbin\start-ainode.bat -i -r -n - ``` - -##### 参数介绍: - -| **名称** | **标签** | **描述** | **是否必填** | **类型** | **默认值** | **输入方式** | -| ------------------- | ---- | ------------------------------------------------------------ | -------- | ------ | ---------------- | ---------------------- | -| ain_interpreter_dir | -i | AINode 所安装在的虚拟环境的解释器路径,需要使用绝对路径 | 否 | String | 默认读取环境变量 | 调用时输入或持久化修改 | -| ain_force_reinstall | -r | 该脚本在检查 AINode 安装情况的时候是否检查版本,如果检查则在版本不对的情况下会强制安装 lib 里的 whl 安装包 | 否 | Bool | false | 调用时输入 | - -> 注意:非联网环境下安装失败时,首先检查是否选择了平台对应的安装包,其次确认python版本为3.8(由于下载的安装包限制了python版本,3.7、3.9等其他都不行) - -#### 示例 - -##### 直接启动: - -```shell - # 启动命令 - # Linux 和 MacOS 系统 - bash sbin/start-ainode.sh - # Windows 系统 - sbin\start-ainode.bat - - - # 后台启动命令(长期运行推荐) - # Linux 和 MacOS 系统 - nohup bash sbin/start-ainode.sh > myout.file 2>& 1 & - # Windows 系统 - nohup bash sbin\start-ainode.bat > myout.file 2>& 1 & - ``` - -### 检测 AINode 节点状态 - -AINode 启动过程中会自动将新的 AINode 加入 IoTDB 集群。启动 AINode 后可以在 命令行中输入 SQL 来查询,集群中看到 AINode 节点,其运行状态为 Running(如下展示)表示加入成功。 - -```shell -IoTDB> show cluster -+------+----------+-------+---------------+------------+-------+-----------+ -|NodeID| NodeType| Status|InternalAddress|InternalPort|Version| BuildInfo| -+------+----------+-------+---------------+------------+-------+-----------+ -| 0|ConfigNode|Running| 127.0.0.1| 10710|UNKNOWN|190e303-dev| -| 1| DataNode|Running| 127.0.0.1| 10730|UNKNOWN|190e303-dev| -| 2| AINode|Running| 127.0.0.1| 10810|UNKNOWN|190e303-dev| -+------+----------+-------+---------------+------------+-------+-----------+ -``` - -### 停止 AINode - -如果需要停止正在运行的 AINode 节点,则执行相应的关闭脚本。 - -#### 停止命令 - -```shell - # Linux / MacOS - bash sbin/stop-ainode.sh - - #Windows - sbin\stop-ainode.bat - ``` - -##### 详细语法 - -```shell - # Linux / MacOS - bash sbin/stop-ainode.sh -t/: - - #Windows - sbin\stop-ainode.bat -t/: - ``` - -##### 参数介绍: - - | **名称** | **标签** | **描述** | **是否必填** | **类型** | **默认值** | **输入方式** | -| ----------------- | ---- | ------------------------------------------------------------ | -------- | ------ | ------ | ---------- | -| ain_remove_target | -t | AINode 关闭时可以指定待移除的目标 AINode 的 Node ID、地址和端口号,格式为`/:` | 否 | String | 无 | 调用时输入 | - -#### 示例 -```shell - # Linux / MacOS - bash sbin/stop-ainode.sh - - # Windows - sbin\stop-ainode.bat - ``` -停止 AINode 后,还可以在集群中看到 AINode 节点,其运行状态为 UNKNOWN(如下展示),此时无法使用 AINode 功能。 - - ```shell -IoTDB> show cluster -+------+----------+-------+---------------+------------+-------+-----------+ -|NodeID| NodeType| Status|InternalAddress|InternalPort|Version| BuildInfo| -+------+----------+-------+---------------+------------+-------+-----------+ -| 0|ConfigNode|Running| 127.0.0.1| 10710|UNKNOWN|190e303-dev| -| 1| DataNode|Running| 127.0.0.1| 10730|UNKNOWN|190e303-dev| -| 2| AINode|UNKNOWN| 127.0.0.1| 10790|UNKNOWN|190e303-dev| -+------+----------+-------+---------------+------------+-------+-----------+ -``` -如果需要重新启动该节点,需重新执行启动脚本。 - -### 移除 AINode - -当需要把一个 AINode 节点移出集群时,可以执行移除脚本。移除和停止脚本的差别是:停止是在集群中保留 AINode 节点但停止 AINode 服务,移除则是把 AINode 节点从集群中移除出去。 - - #### 移除命令 - -```shell - # Linux / MacOS - bash sbin/remove-ainode.sh - - # Windows - sbin\remove-ainode.bat - ``` - -##### 详细语法 - -```shell - # Linux / MacOS - bash sbin/remove-ainode.sh -i -t/: -r -n - - # Windows - sbin\remove-ainode.bat -i -t/: -r -n - ``` - -##### 参数介绍: - - | **名称** | **标签** | **描述** | **是否必填** | **类型** | **默认值** | **输入方式** | -| ------------------- | ---- | ------------------------------------------------------------ | -------- | ------ | ---------------- | --------------------- | -| ain_interpreter_dir | -i | AINode 所安装在的虚拟环境的解释器路径,需要使用绝对路径 | 否 | String | 默认读取环境变量 | 调用时输入+持久化修改 | -| ain_remove_target | -t | AINode 关闭时可以指定待移除的目标 AINode 的 Node ID、地址和端口号,格式为`/:` | 否 | String | 无 | 调用时输入 | -| ain_force_reinstall | -r | 该脚本在检查 AINode 安装情况的时候是否检查版本,如果检查则在版本不对的情况下会强制安装 lib 里的 whl 安装包 | 否 | Bool | false | 调用时输入 | -| ain_no_dependencies | -n | 指定在安装 AINode 的时候是否安装依赖,如果指定则仅安装 AINode 主程序而不安装依赖。 | 否 | Bool | false | 调用时输入 | - - 如不想每次启动时指定对应参数,也可以在 `conf` 文件夹下的`ainode-env.sh` 和 `ainode-env.bat` 脚本中持久化修改参数(目前支持持久化修改 ain_interpreter_dir 参数)。 - - `ainode-env.sh` : - ```shell - # The defaulte venv environment is used if ain_interpreter_dir is not set. Please use absolute path without quotation mark - # ain_interpreter_dir= - ``` - `ainode-env.bat` : -```shell - @REM The defaulte venv environment is used if ain_interpreter_dir is not set. Please use absolute path without quotation mark - @REM set ain_interpreter_dir= - ``` - 在写入参数值的后解除对应行的注释并保存即可在下一次执行脚本时生效。 - -#### 示例 - -##### 直接移除: - - ```shell - # Linux / MacOS - bash sbin/remove-ainode.sh - - # Windows - sbin\remove-ainode.bat - ``` - 移除节点后,将无法查询到节点的相关信息。 - - ```shell -IoTDB> show cluster -+------+----------+-------+---------------+------------+-------+-----------+ -|NodeID| NodeType| Status|InternalAddress|InternalPort|Version| BuildInfo| -+------+----------+-------+---------------+------------+-------+-----------+ -| 0|ConfigNode|Running| 127.0.0.1| 10710|UNKNOWN|190e303-dev| -| 1| DataNode|Running| 127.0.0.1| 10730|UNKNOWN|190e303-dev| -+------+----------+-------+---------------+------------+-------+-----------+ -``` -##### 指定移除: - -如果用户丢失了 data 文件夹下的文件,可能 AINode 本地无法主动移除自己,需要用户指定节点号、地址和端口号进行移除,此时我们支持用户按照以下方法输入参数进行删除。 - - ```shell - # Linux / MacOS - bash sbin/remove-ainode.sh -t /: - - # Windows - sbin\remove-ainode.bat -t /: - ``` - -## 常见问题 - -### 启动AINode时出现找不到venv模块的报错 - - 当使用默认方式启动 AINode 时,会在安装包目录下创建一个 python 虚拟环境并安装依赖,因此要求安装 venv 模块。通常来说 python3.8 及以上的版本会自带 venv,但对于一些系统自带的 python 环境可能并不满足这一要求。出现该报错时有两种解决方案(二选一): - - 在本地安装 venv 模块,以 ubuntu 为例,可以通过运行以下命令来安装 python 自带的 venv 模块。或者从 python 官网安装一个自带 venv 的 python 版本。 - - ```shell -apt-get install python3.8-venv -``` - 安装 3.8.0 版本的 venv 到 AINode 里面 在 AINode 路径下 - - ```shell -../Python-3.8.0/python -m venv venv(文件夹名) -``` - 在运行启动脚本时通过 `-i` 指定已有的 python 解释器路径作为 AINode 的运行环境,这样就不再需要创建一个新的虚拟环境。 - - ### python中的SSL模块没有被正确安装和配置,无法处理HTTPS资源 -WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. -可以安装 OpenSSLS 后,再重新构建 python 来解决这个问题 -> Currently Python versions 3.6 to 3.9 are compatible with OpenSSL 1.0.2, 1.1.0, and 1.1.1. - - Python 要求我们的系统上安装有 OpenSSL,具体安装方法可见[链接](https://stackoverflow.com/questions/56552390/how-to-fix-ssl-module-in-python-is-not-available-in-centos) - - ```shell -sudo apt-get install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev uuid-dev lzma-dev liblzma-dev -sudo -E ./configure --with-ssl -make -sudo make install -``` - - ### pip版本较低 - - windows下出现类似“error:Microsoft Visual C++ 14.0 or greater is required...”的编译问题 - - 出现对应的报错,通常是 c++版本或是 setuptools 版本不足,可以在 - - ```shell -./python -m pip install --upgrade pip -./python -m pip install --upgrade setuptools -``` - - - ### 安装编译python - - 使用以下指定从官网下载安装包并解压: - ```shell -.wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz -tar Jxf Python-3.8.0.tar.xz -``` - 编译安装对应的 python 包: - ```shell -cd Python-3.8.0 -./configure prefix=/usr/local/python3 -make -sudo make install -python3 --version -``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_apache.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_apache.md deleted file mode 100644 index 6c8d0b3be..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_apache.md +++ /dev/null @@ -1,345 +0,0 @@ - -# 集群版部署 - -本小节将以IoTDB经典集群部署架构3C3D(3个ConfigNode和3个DataNode)为例,介绍如何部署集群,即通常所说的3C3D集群。3C3D集群架构图如下: - -
- -
- -## 注意事项 - -1. 安装前请确认系统已参照[系统配置](./Environment-Requirements.md)准备完成。 - -2. 部署时推荐优先使用`hostname`进行IP配置,可避免后期修改主机ip导致数据库无法启动的问题。设置hostname需要在目标服务器上配置/etc/hosts,如本机ip是192.168.1.3,hostname是iotdb-1,则可以使用以下命令设置服务器的 hostname,并使用hostname配置IoTDB的`cn_internal_address`、`dn_internal_address`。 - - ``` shell - echo "192.168.1.3 iotdb-1" >> /etc/hosts - ``` - -3. 有些参数首次启动后不能修改,请参考下方的"参数配置"章节来进行设置。 - -4. 无论是在linux还是windows中,请确保IoTDB的安装路径中不含空格和中文,避免软件运行异常。 - -5. 请注意,安装部署IoTDB时需要保持使用同一个用户进行操作,您可以: -- 使用 root 用户(推荐):使用 root 用户可以避免权限等问题。 -- 使用固定的非 root 用户: - - 使用同一用户操作:确保在启动、停止等操作均保持使用同一用户,不要切换用户。 - - 避免使用 sudo:尽量避免使用 sudo 命令,因为它会以 root 用户权限执行命令,可能会引起权限混淆或安全问题。 - -## 准备步骤 - -1. 准备IoTDB数据库安装包 :apache-iotdb-{version}-all-bin.zip(安装包获取见:[链接](../Deployment-and-Maintenance/IoTDB-Package_apache.md)) - -2. 按环境要求配置好操作系统环境(系统环境配置见:[链接](../Deployment-and-Maintenance/Environment-Requirements.md)) - -## 安装步骤 - -假设现在有3台linux服务器,IP地址和服务角色分配如下: - -| 节点ip | 主机名 | 服务 | -| ----------- | ------- | -------------------- | -| 192.168.1.3 | iotdb-1 | ConfigNode、DataNode | -| 192.168.1.4 | iotdb-2 | ConfigNode、DataNode | -| 192.168.1.5 | iotdb-3 | ConfigNode、DataNode | - -### 设置主机名 - -在3台机器上分别配置主机名,设置主机名需要在目标服务器上配置`/etc/hosts`,使用如下命令: - -```Bash -echo "192.168.1.3 iotdb-1" >> /etc/hosts -echo "192.168.1.4 iotdb-2" >> /etc/hosts -echo "192.168.1.5 iotdb-3" >> /etc/hosts -``` - -### 参数配置 - -解压安装包并进入安装目录 - -```Plain -unzip apache-iotdb-{version}-all-bin.zip -cd apache-iotdb-{version}-all-bin -``` - -#### 环境脚本配置 - -- `./conf/confignode-env.sh` 配置 - - | **配置项** | **说明** | **默认值** | **推荐值** | 备注 | - | :---------- | :------------------------------------- | :--------- | :----------------------------------------------- | :----------- | - | MEMORY_SIZE | IoTDB ConfigNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -- `./conf/datanode-env.sh` 配置 - - | **配置项** | **说明** | **默认值** | **推荐值** | 备注 | - | :---------- | :----------------------------------- | :--------- | :----------------------------------------------- | :----------- | - | MEMORY_SIZE | IoTDB DataNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -#### 通用配置 - -打开通用配置文件`./conf/iotdb-common.properties`,可根据部署方式设置以下参数: - -| 配置项 | 说明 | 192.168.1.3 | 192.168.1.4 | 192.168.1.5 | -| ------------------------- | ---------------------------------------- | -------------- | -------------- | -------------- | -| cluster_name | 集群名称 | defaultCluster | defaultCluster | defaultCluster | -| schema_replication_factor | 元数据副本数,DataNode数量不应少于此数目 | 3 | 3 | 3 | -| data_replication_factor | 数据副本数,DataNode数量不应少于此数目 | 2 | 2 | 2 | - -#### ConfigNode 配置 - -打开ConfigNode配置文件`./conf/iotdb-confignode.properties`,设置以下参数 - -| 配置项 | 说明 | 默认 | 推荐值 | 192.168.1.3 | 192.168.1.4 | 192.168.1.5 | 备注 | -| ------------------- | ------------------------------------------------------------ | --------------- | ------------------------------------------------------- | ------------- | ------------- | ------------- | ------------------ | -| cn_internal_address | ConfigNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | iotdb-1 | iotdb-2 | iotdb-3 | 首次启动后不能修改 | -| cn_internal_port | ConfigNode在集群内部通讯使用的端口 | 10710 | 10710 | 10710 | 10710 | 10710 | 首次启动后不能修改 | -| cn_consensus_port | ConfigNode副本组共识协议通信使用的端口 | 10720 | 10720 | 10720 | 10720 | 10720 | 首次启动后不能修改 | -| cn_seed_config_node | 节点注册加入集群时连接的ConfigNode 的地址,cn_internal_address:cn_internal_port | 127.0.0.1:10710 | 第一个CongfigNode的cn_internal_address:cn_internal_port | iotdb-1:10710 | iotdb-1:10710 | iotdb-1:10710 | 首次启动后不能修改 | - -#### DataNode 配置 - -打开DataNode配置文件 `./conf/iotdb-datanode.properties`,设置以下参数: - -| 配置项 | 说明 | 默认 | 推荐值 | 192.168.1.3 | 192.168.1.4 | 192.168.1.5 | 备注 | -| ------------------------------- | ------------------------------------------------------------ | --------------- | ------------------------------------------------------- | ------------- | ------------- | ------------- | ------------------ | -| dn_rpc_address | 客户端 RPC 服务的地址 | 127.0.0.1 | 推荐使用所在服务器的**IPV4地址或hostname** | iotdb-1 |iotdb-2 | iotdb-3 | 重启服务生效 | -| dn_rpc_port | 客户端 RPC 服务的端口 | 6667 | 6667 | 6667 | 6667 | 6667 | 重启服务生效 | -| dn_internal_address | DataNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | iotdb-1 | iotdb-2 | iotdb-3 | 首次启动后不能修改 | -| dn_internal_port | DataNode在集群内部通信使用的端口 | 10730 | 10730 | 10730 | 10730 | 10730 | 首次启动后不能修改 | -| dn_mpp_data_exchange_port | DataNode用于接收数据流使用的端口 | 10740 | 10740 | 10740 | 10740 | 10740 | 首次启动后不能修改 | -| dn_data_region_consensus_port | DataNode用于数据副本共识协议通信使用的端口 | 10750 | 10750 | 10750 | 10750 | 10750 | 首次启动后不能修改 | -| dn_schema_region_consensus_port | DataNode用于元数据副本共识协议通信使用的端口 | 10760 | 10760 | 10760 | 10760 | 10760 | 首次启动后不能修改 | -| dn_seed_config_node | 节点注册加入集群时连接的ConfigNode地址,即cn_internal_address:cn_internal_port | 127.0.0.1:10710 | 第一个CongfigNode的cn_internal_address:cn_internal_port | iotdb-1:10710 | iotdb-1:10710 | iotdb-1:10710 | 首次启动后不能修改 | - -> ❗️注意:VSCode Remote等编辑器无自动保存配置功能,请确保修改的文件被持久化保存,否则配置项无法生效 - -### 启动ConfigNode节点 - -先启动第一个iotdb-1的confignode, 保证种子confignode节点先启动,然后依次启动第2和第3个confignode节点 - -```Bash -cd sbin -./start-confignode.sh -d #“-d”参数将在后台进行启动 -``` -如果启动失败,请参考[常见问题](#常见问题)。 - -### 启动DataNode 节点 - - 分别进入iotdb的`sbin`目录下,依次启动3个datanode节点: - -```Bash -cd sbin -./start-datanode.sh -d # “-d”参数将在后台进行启动 -``` - -### 验证部署 - -可直接执行`./sbin`目录下的Cli启动脚本: - -```Plain -./start-cli.sh -h ip(本机ip或域名) -p 端口号(6667) -``` - - 成功启动后,出现如下界面显示IOTDB安装成功。 - -![](/img/%E5%BC%80%E6%BA%90%E6%88%90%E5%8A%9F.png) - -​ 可以使用`show cluster` 命令查看集群信息: - -![](/img/%E5%BC%80%E6%BA%90%E7%89%88%20show%20cluter.png) - -> 出现`ACTIVATED(W)`为被动激活,表示此ConfigNode没有license文件(或没有签发时间戳最新的license文件),其激活依赖于集群中其它Activate状态的ConfigNode。此时建议检查license文件是否已放入license文件夹,没有请放入license文件,若已存在license文件,可能是此节点license文件与其他节点信息不一致导致,请联系天谋工作人员重新申请. - -## 节点维护步骤 - -### ConfigNode节点维护 - -ConfigNode节点维护分为ConfigNode添加和移除两种操作,有两个常见使用场景: -- 集群扩展:如集群中只有1个ConfigNode时,希望增加ConfigNode以提升ConfigNode节点高可用性,则可以添加2个ConfigNode,使得集群中有3个ConfigNode。 -- 集群故障恢复:1个ConfigNode所在机器发生故障,使得该ConfigNode无法正常运行,此时可以移除该ConfigNode,然后添加一个新的ConfigNode进入集群。 - -> ❗️注意,在完成ConfigNode节点维护后,需要保证集群中有1或者3个正常运行的ConfigNode。2个ConfigNode不具备高可用性,超过3个ConfigNode会导致性能损失。 - -#### 添加ConfigNode节点 - -脚本命令: -```shell -# Linux / MacOS -# 首先切换到IoTDB根目录 -sbin/start-confignode.sh - -# Windows -# 首先切换到IoTDB根目录 -sbin/start-confignode.bat -``` - -参数介绍: - -| 参数 | 描述 | 是否为必填项 | -| :--- | :--------------------------------------------- | :----------- | -| -v | 显示版本信息 | 否 | -| -f | 在前台运行脚本,不将其放到后台 | 否 | -| -d | 以守护进程模式启动,即在后台运行 | 否 | -| -p | 指定一个文件来存放进程ID,用于进程管理 | 否 | -| -c | 指定配置文件夹的路径,脚本会从这里加载配置文件 | 否 | -| -g | 打印垃圾回收(GC)的详细信息 | 否 | -| -H | 指定Java堆转储文件的路径,当JVM内存溢出时使用 | 否 | -| -E | 指定JVM错误日志文件的路径 | 否 | -| -D | 定义系统属性,格式为 key=value | 否 | -| -X | 直接传递 -XX 参数给 JVM | 否 | -| -h | 帮助指令 | 否 | - -#### 移除ConfigNode节点 - -首先通过CLI连接集群,通过`show confignodes`确认想要移除ConfigNode的内部地址与端口号: - -```Bash -IoTDB> show confignodes -+------+-------+---------------+------------+--------+ -|NodeID| Status|InternalAddress|InternalPort| Role| -+------+-------+---------------+------------+--------+ -| 0|Running| 127.0.0.1| 10710| Leader| -| 1|Running| 127.0.0.1| 10711|Follower| -| 2|Running| 127.0.0.1| 10712|Follower| -+------+-------+---------------+------------+--------+ -Total line number = 3 -It costs 0.030s -``` - -然后使用脚本将DataNode移除。脚本命令: - -```Bash -# Linux / MacOS -sbin/remove-confignode.sh [confignode_id] -或 -./sbin/remove-confignode.sh [cn_internal_address:cn_internal_port] - -#Windows -sbin/remove-confignode.bat [confignode_id] -或 -./sbin/remove-confignode.bat [cn_internal_address:cn_internal_port] -``` - -### DataNode节点维护 - -DataNode节点维护有两个常见场景: - -- 集群扩容:出于集群能力扩容等目的,添加新的DataNode进入集群 -- 集群故障恢复:一个DataNode所在机器出现故障,使得该DataNode无法正常运行,此时可以移除该DataNode,并添加新的DataNode进入集群 - -> ❗️注意,为了使集群能正常工作,在DataNode节点维护过程中以及维护完成后,正常运行的DataNode总数不得少于数据副本数(通常为2),也不得少于元数据副本数(通常为3)。 - -#### 添加DataNode节点 - -脚本命令: - -```Bash -# Linux / MacOS -# 首先切换到IoTDB根目录 -sbin/start-datanode.sh - -# Windows -# 首先切换到IoTDB根目录 -sbin/start-datanode.bat -``` - -参数介绍: - -| 缩写 | 描述 | 是否为必填项 | -| :--- | :--------------------------------------------- | :----------- | -| -v | 显示版本信息 | 否 | -| -f | 在前台运行脚本,不将其放到后台 | 否 | -| -d | 以守护进程模式启动,即在后台运行 | 否 | -| -p | 指定一个文件来存放进程ID,用于进程管理 | 否 | -| -c | 指定配置文件夹的路径,脚本会从这里加载配置文件 | 否 | -| -g | 打印垃圾回收(GC)的详细信息 | 否 | -| -H | 指定Java堆转储文件的路径,当JVM内存溢出时使用 | 否 | -| -E | 指定JVM错误日志文件的路径 | 否 | -| -D | 定义系统属性,格式为 key=value | 否 | -| -X | 直接传递 -XX 参数给 JVM | 否 | -| -h | 帮助指令 | 否 | - -说明:在添加DataNode后,随着新的写入到来(以及旧数据过期,如果设置了TTL),集群负载会逐渐向新的DataNode均衡,最终在所有节点上达到存算资源的均衡。 - -#### 移除DataNode节点 - -首先通过CLI连接集群,通过`show datanodes`确认想要移除的DataNode的RPC地址与端口号: - -```Bash -IoTDB> show datanodes -+------+-------+----------+-------+-------------+---------------+ -|NodeID| Status|RpcAddress|RpcPort|DataRegionNum|SchemaRegionNum| -+------+-------+----------+-------+-------------+---------------+ -| 1|Running| 0.0.0.0| 6667| 0| 0| -| 2|Running| 0.0.0.0| 6668| 1| 1| -| 3|Running| 0.0.0.0| 6669| 1| 0| -+------+-------+----------+-------+-------------+---------------+ -Total line number = 3 -It costs 0.110s -``` - -然后使用脚本将DataNode移除。脚本命令: - -```Bash -# Linux / MacOS -sbin/remove-datanode.sh [dn_rpc_address:dn_rpc_port] - -#Windows -sbin/remove-datanode.bat [dn_rpc_address:dn_rpc_port] -``` - -## 常见问题 - -1. Confignode节点启动失败 - - 步骤 1: 请查看启动日志,检查是否修改了某些首次启动后不可改的参数。 - - 步骤 2: 请查看启动日志,检查是否出现其他异常。日志中若存在异常现象,请联系天谋技术支持人员咨询解决方案。 - - 步骤 3: 如果是首次部署或者数据可删除,也可按下述步骤清理环境,重新部署后,再次启动。 - - 步骤 4: 清理环境: - - a. 结束所有 ConfigNode 和 DataNode 进程。 - - ```Bash - # 1. 停止 ConfigNode 和 DataNode 服务 - sbin/stop-standalone.sh - - # 2. 检查是否还有进程残留 - jps - # 或者 - ps -ef|gerp iotdb - - # 3. 如果有进程残留,则手动kill - kill -9 - # 如果确定机器上仅有1个iotdb,可以使用下面命令清理残留进程 - ps -ef|grep iotdb|grep -v grep|tr -s ' ' ' ' |cut -d ' ' -f2|xargs kill -9 - ``` - b. 删除 data 和 logs 目录。 - - 说明:删除 data 目录是必要的,删除 logs 目录是为了纯净日志,非必需。 - ```Bash - cd /data/iotdb - rm -rf data logs - ``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_timecho.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_timecho.md deleted file mode 100644 index f12ad4427..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Cluster-Deployment_timecho.md +++ /dev/null @@ -1,387 +0,0 @@ - -# 集群版部署 - -本小节描述如何手动部署包括3个ConfigNode和3个DataNode的实例,即通常所说的3C3D集群。 -
- -
- -## 注意事项 - -1. 安装前请确认系统已参照[系统配置](./Environment-Requirements.md)准备完成。 - -2. 部署时推荐优先使用`hostname`进行IP配置,可避免后期修改主机ip导致数据库无法启动的问题。设置hostname需要在目标服务器上配置/etc/hosts,如本机ip是192.168.1.3,hostname是iotdb-1,则可以使用以下命令设置服务器的 hostname,并使用hostname配置IoTDB的`cn_internal_address`、`dn_internal_address`。`dn_internal_address`。 - - ``` shell - echo "192.168.1.3 iotdb-1" >> /etc/hosts - ``` - -3. 有些参数首次启动后不能修改,请参考下方的"参数配置"章节来进行设置。 - -4. 无论是在linux还是windows中,请确保IoTDB的安装路径中不含空格和中文,避免软件运行异常。 - -5. 请注意,安装部署(包括激活和使用软件)IoTDB时需要保持使用同一个用户进行操作,您可以: -- 使用 root 用户(推荐):使用 root 用户可以避免权限等问题。 -- 使用固定的非 root 用户: - - 使用同一用户操作:确保在启动、激活、停止等操作均保持使用同一用户,不要切换用户。 - - 避免使用 sudo:尽量避免使用 sudo 命令,因为它会以 root 用户权限执行命令,可能会引起权限混淆或安全问题。 - -6. 推荐部署监控面板,可以对重要运行指标进行监控,随时掌握数据库运行状态,监控面板可以联系商务获取,部署监控面板步骤可以参考:[监控面板部署](./Monitoring-panel-deployment.md) - -## 准备步骤 - -1. 准备IoTDB数据库安装包 :iotdb-enterprise-{version}-bin.zip(安装包获取见:[链接](../Deployment-and-Maintenance/IoTDB-Package_timecho.md)) -2. 按环境要求配置好操作系统环境(系统环境配置见:[链接](../Deployment-and-Maintenance/Environment-Requirements.md)) - -## 安装步骤 - -假设现在有3台linux服务器,IP地址和服务角色分配如下: - -| 节点ip | 主机名 | 服务 | -| ----------- | ------- | -------------------- | -| 192.168.1.3 | iotdb-1 | ConfigNode、DataNode | -| 192.168.1.4 | iotdb-2 | ConfigNode、DataNode | -| 192.168.1.5 | iotdb-3 | ConfigNode、DataNode | - -### 设置主机名 - -在3台机器上分别配置主机名,设置主机名需要在目标服务器上配置`/etc/hosts`,使用如下命令: - -```Bash -echo "192.168.1.3 iotdb-1" >> /etc/hosts -echo "192.168.1.4 iotdb-2" >> /etc/hosts -echo "192.168.1.5 iotdb-3" >> /etc/hosts -``` - -### 参数配置 - -解压安装包并进入安装目录 - -```Plain -unzip iotdb-enterprise-{version}-bin.zip -cd iotdb-enterprise-{version}-bin -``` - -#### 环境脚本配置 - -- `./conf/confignode-env.sh`配置 - - | **配置项** | **说明** | **默认值** | **推荐值** | 备注 | - | :---------- | :------------------------------------- | :--------- | :----------------------------------------------- | :----------- | - | MEMORY_SIZE | IoTDB ConfigNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -- `./conf/datanode-env.sh`配置 - - | **配置项** | **说明** | **默认值** | **推荐值** | 备注 | - | :---------- | :----------------------------------- | :--------- | :----------------------------------------------- | :----------- | - | MEMORY_SIZE | IoTDB DataNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -#### 通用配置 - -打开通用配置文件`./conf/iotdb-common.properties`,可根据部署方式设置以下参数: - -| 配置项 | 说明 | 192.168.1.3 | 192.168.1.4 | 192.168.1.5 | -| ------------------------- | ---------------------------------------- | -------------- | -------------- | -------------- | -| cluster_name | 集群名称 | defaultCluster | defaultCluster | defaultCluster | -| schema_replication_factor | 元数据副本数,DataNode数量不应少于此数目 | 3 | 3 | 3 | -| data_replication_factor | 数据副本数,DataNode数量不应少于此数目 | 2 | 2 | 2 | - -#### ConfigNode 配置 - -打开ConfigNode配置文件`./conf/iotdb-confignode.properties`,设置以下参数 - -| 配置项 | 说明 | 默认 | 推荐值 | 192.168.1.3 | 192.168.1.4 | 192.168.1.5 | 备注 | -| ------------------- | ------------------------------------------------------------ | --------------- | ------------------------------------------------------- | ------------- | ------------- | ------------- | ------------------ | -| cn_internal_address | ConfigNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | iotdb-1 | iotdb-2 | iotdb-3 | 首次启动后不能修改 | -| cn_internal_port | ConfigNode在集群内部通讯使用的端口 | 10710 | 10710 | 10710 | 10710 | 10710 | 首次启动后不能修改 | -| cn_consensus_port | ConfigNode副本组共识协议通信使用的端口 | 10720 | 10720 | 10720 | 10720 | 10720 | 首次启动后不能修改 | -| cn_seed_config_node | 节点注册加入集群时连接的ConfigNode 的地址,cn_internal_address:cn_internal_port | 127.0.0.1:10710 | 第一个CongfigNode的cn_internal_address:cn_internal_port | iotdb-1:10710 | iotdb-1:10710 | iotdb-1:10710 | 首次启动后不能修改 | - -#### DataNode 配置 - -打开DataNode配置文件 `./conf/iotdb-datanode.properties`,设置以下参数: - -| 配置项 | 说明 | 默认 | 推荐值 | 192.168.1.3 | 192.168.1.4 | 192.168.1.5 | 备注 | -| ------------------------------- | ------------------------------------------------------------ | --------------- | ------------------------------------------------------- | ------------- | ------------- | ------------- | ------------------ | -| dn_rpc_address | 客户端 RPC 服务的地址 | 127.0.0.1 | 推荐使用所在服务器的**IPV4地址或hostname** | iotdb-1 |iotdb-2 | iotdb-3 | 重启服务生效 | -| dn_rpc_port | 客户端 RPC 服务的端口 | 66673.0 | 6667 | 6667 | 6667 | 6667 | 重启服务生效 | -| dn_internal_address | DataNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | iotdb-1 | iotdb-2 | iotdb-3 | 首次启动后不能修改 | -| dn_internal_port | DataNode在集群内部通信使用的端口 | 10730 | 10730 | 10730 | 10730 | 10730 | 首次启动后不能修改 | -| dn_mpp_data_exchange_port | DataNode用于接收数据流使用的端口 | 10740 | 10740 | 10740 | 10740 | 10740 | 首次启动后不能修改 | -| dn_data_region_consensus_port | DataNode用于数据副本共识协议通信使用的端口 | 10750 | 10750 | 10750 | 10750 | 10750 | 首次启动后不能修改 | -| dn_schema_region_consensus_port | DataNode用于元数据副本共识协议通信使用的端口 | 10760 | 10760 | 10760 | 10760 | 10760 | 首次启动后不能修改 | -| dn_seed_config_node | 节点注册加入集群时连接的ConfigNode地址,即cn_internal_address:cn_internal_port | 127.0.0.1:10710 | 第一个CongfigNode的cn_internal_address:cn_internal_port | iotdb-1:10710 | iotdb-1:10710 | iotdb-1:10710 | 首次启动后不能修改 | - -> ❗️注意:VSCode Remote等编辑器无自动保存配置功能,请确保修改的文件被持久化保存,否则配置项无法生效 - -### 启动ConfigNode节点 - -先启动第一个iotdb-1的confignode, 保证种子confignode节点先启动,然后依次启动第2和第3个confignode节点 - -```Bash -cd sbin -./start-confignode.sh -d #“-d”参数将在后台进行启动 -``` -如果启动失败,请参考[常见问题](#常见问题)。 - -### 激活数据库 - -#### 方式一:激活文件拷贝激活 - -- 依次启动3个confignode节点后,每台机器各自的`activation`文件夹, 分别拷贝每台机器的`system_info`文件给天谋工作人员; -- 工作人员将返回每个ConfigNode节点的license文件,这里会返回3个license文件; -- 将3个license文件分别放入对应的ConfigNode节点的`activation`文件夹下; - -#### 方式二:激活脚本激活 - -- 依次获取3台机器的机器码,分别进入安装目录的`sbin`目录,执行激活脚本`start-activate.sh`: - - ```Bash - cd sbin - ./start-activate.sh - ``` - -- 显示如下信息,这里显示的是1台机器的机器码 : - - ```Bash - Please copy the system_info's content and send it to Timecho: - Y17hFA0xRCE1TmkVxILuxxxxxxxxxxxxxxxxxxxxxxxxxxxxW5P52KCccFMVeHTc= - Please enter license: - ``` - -- 其他2个节点依次执行激活脚本`start-activate.sh`,然后将获取的3台机器的机器码都复制给天谋工作人员 -- 工作人员会返回3段激活码,正常是与提供的3个机器码的顺序对应的,请分别将各自的激活码粘贴到上一步的命令行提示处 `Please enter license:`,如下提示: - - ```Bash - Please enter license: - Jw+MmF+Atxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5bAOXNeob5l+HO5fEMgzrW8OJPh26Vl6ljKUpCvpTiw== - License has been stored to sbin/../activation/license - Import completed. Please start cluster and excute 'show cluster' to verify activation status - ``` - -### 启动DataNode 节点 - - 分别进入iotdb的`sbin`目录下,依次启动3个datanode节点: - -```Go -cd sbin -./start-datanode.sh -d #-d参数将在后台进行启动 -``` - -### 验证部署 - -可直接执行`./sbin`目录下的Cli启动脚本: - -```Plain -./start-cli.sh -h ip(本机ip或域名) -p 端口号(6667) -``` - - 成功启动后,出现如下界面显示IOTDB安装成功。 - -![](/img/%E4%BC%81%E4%B8%9A%E7%89%88%E6%88%90%E5%8A%9F.png) - -出现安装成功界面后,继续看下是否激活成功,使用 `show cluster`命令 - -当看到最右侧显示`ACTIVATED`表示激活成功 - -![](/img/%E4%BC%81%E4%B8%9A%E7%89%88%E6%BF%80%E6%B4%BB.png) - -> 出现`ACTIVATED(W)`为被动激活,表示此ConfigNode没有license文件(或没有签发时间戳最新的license文件),其激活依赖于集群中其它Activate状态的ConfigNode。此时建议检查license文件是否已放入license文件夹,没有请放入license文件,若已存在license文件,可能是此节点license文件与其他节点信息不一致导致,请联系天谋工作人员重新申请. - - -## 节点维护步骤 - -### ConfigNode节点维护 - -ConfigNode节点维护分为ConfigNode添加和移除两种操作,有两个常见使用场景: -- 集群扩展:如集群中只有1个ConfigNode时,希望增加ConfigNode以提升ConfigNode节点高可用性,则可以添加2个ConfigNode,使得集群中有3个ConfigNode。 -- 集群故障恢复:1个ConfigNode所在机器发生故障,使得该ConfigNode无法正常运行,此时可以移除该ConfigNode,然后添加一个新的ConfigNode进入集群。 - -> ❗️注意,在完成ConfigNode节点维护后,需要保证集群中有1或者3个正常运行的ConfigNode。2个ConfigNode不具备高可用性,超过3个ConfigNode会导致性能损失。 - -#### 添加ConfigNode节点 - -脚本命令: -```shell -# Linux / MacOS -# 首先切换到IoTDB根目录 -sbin/start-confignode.sh - -# Windows -# 首先切换到IoTDB根目录 -sbin/start-confignode.bat -``` - -参数介绍: - -| 参数 | 描述 | 是否为必填项 | -| :--- | :--------------------------------------------- | :----------- | -| -v | 显示版本信息 | 否 | -| -f | 在前台运行脚本,不将其放到后台 | 否 | -| -d | 以守护进程模式启动,即在后台运行 | 否 | -| -p | 指定一个文件来存放进程ID,用于进程管理 | 否 | -| -c | 指定配置文件夹的路径,脚本会从这里加载配置文件 | 否 | -| -g | 打印垃圾回收(GC)的详细信息 | 否 | -| -H | 指定Java堆转储文件的路径,当JVM内存溢出时使用 | 否 | -| -E | 指定JVM错误日志文件的路径 | 否 | -| -D | 定义系统属性,格式为 key=value | 否 | -| -X | 直接传递 -XX 参数给 JVM | 否 | -| -h | 帮助指令 | 否 | - -#### 移除ConfigNode节点 - -首先通过CLI连接集群,通过`show confignodes`确认想要移除ConfigNode的内部地址与端口号: - -```Bash -IoTDB> show confignodes -+------+-------+---------------+------------+--------+ -|NodeID| Status|InternalAddress|InternalPort| Role| -+------+-------+---------------+------------+--------+ -| 0|Running| 127.0.0.1| 10710| Leader| -| 1|Running| 127.0.0.1| 10711|Follower| -| 2|Running| 127.0.0.1| 10712|Follower| -+------+-------+---------------+------------+--------+ -Total line number = 3 -It costs 0.030s -``` - -然后使用脚本将DataNode移除。脚本命令: - -```Bash -# Linux / MacOS -sbin/remove-confignode.sh [confignode_id] -或 -./sbin/remove-confignode.sh [cn_internal_address:cn_internal_port] - -#Windows -sbin/remove-confignode.bat [confignode_id] -或 -./sbin/remove-confignode.bat [cn_internal_address:cn_internal_port] -``` - -### DataNode节点维护 - -DataNode节点维护有两个常见场景: - -- 集群扩容:出于集群能力扩容等目的,添加新的DataNode进入集群 -- 集群故障恢复:一个DataNode所在机器出现故障,使得该DataNode无法正常运行,此时可以移除该DataNode,并添加新的DataNode进入集群 - -> ❗️注意,为了使集群能正常工作,在DataNode节点维护过程中以及维护完成后,正常运行的DataNode总数不得少于数据副本数(通常为2),也不得少于元数据副本数(通常为3)。 - -#### 添加DataNode节点 - -脚本命令: - -```Bash -# Linux / MacOS -# 首先切换到IoTDB根目录 -sbin/start-datanode.sh - -# Windows -# 首先切换到IoTDB根目录 -sbin/start-datanode.bat -``` - -参数介绍: - -| 缩写 | 描述 | 是否为必填项 | -| :--- | :--------------------------------------------- | :----------- | -| -v | 显示版本信息 | 否 | -| -f | 在前台运行脚本,不将其放到后台 | 否 | -| -d | 以守护进程模式启动,即在后台运行 | 否 | -| -p | 指定一个文件来存放进程ID,用于进程管理 | 否 | -| -c | 指定配置文件夹的路径,脚本会从这里加载配置文件 | 否 | -| -g | 打印垃圾回收(GC)的详细信息 | 否 | -| -H | 指定Java堆转储文件的路径,当JVM内存溢出时使用 | 否 | -| -E | 指定JVM错误日志文件的路径 | 否 | -| -D | 定义系统属性,格式为 key=value | 否 | -| -X | 直接传递 -XX 参数给 JVM | 否 | -| -h | 帮助指令 | 否 | - -说明:在添加DataNode后,随着新的写入到来(以及旧数据过期,如果设置了TTL),集群负载会逐渐向新的DataNode均衡,最终在所有节点上达到存算资源的均衡。 - -#### 移除DataNode节点 - -首先通过CLI连接集群,通过`show datanodes`确认想要移除的DataNode的RPC地址与端口号: - -```Bash -IoTDB> show datanodes -+------+-------+----------+-------+-------------+---------------+ -|NodeID| Status|RpcAddress|RpcPort|DataRegionNum|SchemaRegionNum| -+------+-------+----------+-------+-------------+---------------+ -| 1|Running| 0.0.0.0| 6667| 0| 0| -| 2|Running| 0.0.0.0| 6668| 1| 1| -| 3|Running| 0.0.0.0| 6669| 1| 0| -+------+-------+----------+-------+-------------+---------------+ -Total line number = 3 -It costs 0.110s -``` - -然后使用脚本将DataNode移除。脚本命令: - -```Bash -# Linux / MacOS -sbin/remove-datanode.sh [dn_rpc_address:dn_rpc_port] - -#Windows -sbin/remove-datanode.bat [dn_rpc_address:dn_rpc_port] -``` - -## 常见问题 - -1. 部署过程中多次提示激活失败 - - 使用 `ls -al` 命令:使用 `ls -al` 命令检查安装包根目录的所有者信息是否为当前用户。 - - 检查激活目录:检查 `./activation` 目录下的所有文件,所有者信息是否为当前用户。 - -2. Confignode节点启动失败 - - 步骤 1: 请查看启动日志,检查是否修改了某些首次启动后不可改的参数。 - - 步骤 2: 请查看启动日志,检查是否出现其他异常。日志中若存在异常现象,请联系天谋技术支持人员咨询解决方案。 - - 步骤 3: 如果是首次部署或者数据可删除,也可按下述步骤清理环境,重新部署后,再次启动。 - - 步骤 4: 清理环境: - - a. 结束所有 ConfigNode 和 DataNode 进程。 - - ```Bash - # 1. 停止 ConfigNode 和 DataNode 服务 - sbin/stop-standalone.sh - - # 2. 检查是否还有进程残留 - jps - # 或者 - ps -ef|gerp iotdb - - # 3. 如果有进程残留,则手动kill - kill -9 - # 如果确定机器上仅有1个iotdb,可以使用下面命令清理残留进程 - ps -ef|grep iotdb|grep -v grep|tr -s ' ' ' ' |cut -d ' ' -f2|xargs kill -9 - ``` - b. 删除 data 和 logs 目录。 - - 说明:删除 data 目录是必要的,删除 logs 目录是为了纯净日志,非必需。 - ```Bash - cd /data/iotdb - rm -rf data logs - ``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Database-Resources.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Database-Resources.md deleted file mode 100644 index 7f21736d3..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Database-Resources.md +++ /dev/null @@ -1,200 +0,0 @@ - -# 资源规划 -## CPU - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
序列数(采集频率<=1HZ)CPU节点数
单机双活分布式
10W以内2核-4核123
30W以内4核-8核123
50W以内8核-16核123
100W以内16核-32核123
200w以内32核-48核123
1000w以内48核12请联系天谋商务咨询
1000w以上请联系天谋商务咨询
- -## 内存 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
序列数(采集频率<=1HZ)内存节点数
单机双活分布式
10W以内4G-8G123
30W以内12G-32G123
50W以内24G-48G123
100W以内32G-96G123
200w以内64G-128G123
1000w以内128G12请联系天谋商务咨询
1000w以上请联系天谋商务咨询
- -## 存储(磁盘) -### 存储空间 -计算公式:测点数量 * 采样频率(Hz)* 每个数据点大小(Byte,不同数据类型不一样,见下表) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
数据点大小计算表
数据类型 时间戳(字节)值(字节)数据点总大小(字节)
开关量(Boolean)819
整型(INT32)/ 单精度浮点数(FLOAT)8412
长整型(INT64)/ 双精度浮点数(DOUBLE)8816
字符串(TEXT)8平均为a8+a
- - -示例:1000设备,每个设备100 测点,共 100000 序列,INT32 类型。采样频率1Hz(每秒一次),存储1年,3副本。 -- 完整计算公式:1000设备 * 100测点 * 12字节每数据点 * 86400秒每天 * 365天每年 * 3副本/10压缩比 / 1024 / 1024 / 1024 / 1024 =11T -- 简版计算公式:1000 * 100 * 12 * 86400 * 365 * 3 / 10 / 1024 / 1024 / 1024 / 1024 = 11T -### 存储配置 -1000w 点位以上或查询负载较大,推荐配置 SSD。 -## 网络(网卡) -在写入吞吐不超过1000万点/秒时,需配置千兆网卡;当写入吞吐超过 1000万点/秒时,需配置万兆网卡。 -| **写入吞吐(数据点/秒)** | **网卡速率** | -| ------------------- | ------------- | -| <1000万 | 1Gbps(千兆) | -| >=1000万 | 10Gbps(万兆) | -## 其他说明 -IoTDB 具有集群秒级扩容能力,扩容节点数据可不迁移,因此您无需担心按现有数据情况估算的集群能力有限,未来您可在需要扩容时为集群加入新的节点。 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/IoTDB-Package_apache.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/IoTDB-Package_apache.md deleted file mode 100644 index 3af9f56bf..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/IoTDB-Package_apache.md +++ /dev/null @@ -1,45 +0,0 @@ - -# 安装包获取 - -## 安装包获取方式 - -安装包可直接在Apache IoTDB官网获取:https://iotdb.apache.org/zh/Download/ - -## 安装包结构 - -解压后安装包(`apache-iotdb--all-bin.zip`),安装包解压后目录结构如下: - -| **目录** | **类型** | **说明** | -| ---------------- | -------- | ------------------------------------------------------------ | -| conf | 文件夹 | 配置文件目录,包含 ConfigNode、DataNode、JMX 和 logback 等配置文件 | -| data | 文件夹 | 默认的数据文件目录,包含 ConfigNode 和 DataNode 的数据文件。(启动程序后才会生成该目录) | -| lib | 文件夹 | IoTDB可执行库文件目录 | -| licenses | 文件夹 | 开源社区证书文件目录 | -| logs | 文件夹 | 默认的日志文件目录,包含 ConfigNode 和 DataNode 的日志文件(启动程序后才会生成该目录) | -| sbin | 文件夹 | 主要脚本目录,包含启、停等脚本等 | -| tools | 文件夹 | 系统周边工具目录 | -| ext | 文件夹 | pipe,trigger,udf插件的相关文件(需要使用时用户自行创建) | -| LICENSE | 文件 | 证书 | -| NOTICE | 文件 | 提示 | -| README_ZH\.md | 文件 | markdown格式的中文版说明 | -| README\.md | 文件 | 使用说明 | -| RELEASE_NOTES\.md | 文件 | 版本说明 | \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Monitoring-panel-deployment.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Monitoring-panel-deployment.md deleted file mode 100644 index 1bdeaf9d8..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Monitoring-panel-deployment.md +++ /dev/null @@ -1,682 +0,0 @@ - -# 监控面板部署 - -IoTDB配套监控面板是IoTDB企业版配套工具之一。它旨在解决IoTDB及其所在操作系统的监控问题,主要包括:操作系统资源监控、IoTDB性能监控,及上百项内核监控指标,从而帮助用户监控集群健康状态,并进行集群调优和运维。本文将以常见的3C3D集群(3个Confignode和3个Datanode)为例,为您介绍如何在IoTDB的实例中开启系统监控模块,并且使用Prometheus + Grafana的方式完成对系统监控指标的可视化。 - -## 安装准备 - -1. 安装 IoTDB:需先安装IoTDB V1.0 版本及以上企业版,您可联系商务或技术支持获取 -2. 获取 IoTDB 监控面板安装包:基于企业版 IoTDB 的数据库监控面板,您可联系商务或技术支持获取 - -## 安装步骤 - -### 步骤一:IoTDB开启监控指标采集 - -1. 打开监控配置项。IoTDB中监控有关的配置项默认是关闭的,在部署监控面板前,您需要打开相关配置项(注意开启监控配置后需要重启服务)。 - -| 配置项 | 所在配置文件 | 配置说明 | -| :--------------------------------- | :------------------------------- | :----------------------------------------------------------- | -| cn_metric_reporter_list | conf/iotdb-confignode.properties | 将配置项取消注释,值设置为PROMETHEUS | -| cn_metric_level | conf/iotdb-confignode.properties | 将配置项取消注释,值设置为IMPORTANT | -| cn_metric_prometheus_reporter_port | conf/iotdb-confignode.properties | 将配置项取消注释,可保持默认设置9091,如设置其他端口,不与其他端口冲突即可 | -| dn_metric_reporter_list | conf/iotdb-datanode.properties | 将配置项取消注释,值设置为PROMETHEUS | -| dn_metric_level | conf/iotdb-datanode.properties | 将配置项取消注释,值设置为IMPORTANT | -| dn_metric_prometheus_reporter_port | conf/iotdb-datanode.properties | 将配置项取消注释,可默认设置为9092,如设置其他端口,不与其他端口冲突即可 | - -以3C3D集群为例,需要修改的监控配置如下: - -| 节点ip | 主机名 | 集群角色 | 配置文件路径 | 配置项 | -| ----------- | ------- | ---------- | -------------------------------- | ------------------------------------------------------------ | -| 192.168.1.3 | iotdb-1 | confignode | conf/iotdb-confignode.properties | cn_metric_reporter_list=PROMETHEUS cn_metric_level=IMPORTANT cn_metric_prometheus_reporter_port=9091 | -| 192.168.1.4 | iotdb-2 | confignode | conf/iotdb-confignode.properties | cn_metric_reporter_list=PROMETHEUS cn_metric_level=IMPORTANT cn_metric_prometheus_reporter_port=9091 | -| 192.168.1.5 | iotdb-3 | confignode | conf/iotdb-confignode.properties | cn_metric_reporter_list=PROMETHEUS cn_metric_level=IMPORTANT cn_metric_prometheus_reporter_port=9091 | -| 192.168.1.3 | iotdb-1 | datanode | conf/iotdb-datanode.properties | dn_metric_reporter_list=PROMETHEUS dn_metric_level=IMPORTANT dn_metric_prometheus_reporter_port=9092 | -| 192.168.1.4 | iotdb-2 | datanode | conf/iotdb-datanode.properties | dn_metric_reporter_list=PROMETHEUS dn_metric_level=IMPORTANT dn_metric_prometheus_reporter_port=9092 | -| 192.168.1.5 | iotdb-3 | datanode | conf/iotdb-datanode.properties | dn_metric_reporter_list=PROMETHEUS dn_metric_level=IMPORTANT dn_metric_prometheus_reporter_port=9092 | - -2. 重启所有节点。修改3个节点的监控指标配置后,可重新启动所有节点的confignode和datanode服务: - -```shell -./sbin/stop-standalone.sh #先停止confignode和datanode -./sbin/start-confignode.sh -d #启动confignode -./sbin/start-datanode.sh -d #启动datanode -``` - -3. 重启后,通过客户端确认各节点的运行状态,若状态都为Running,则为配置成功: - -![](/img/%E5%90%AF%E5%8A%A8.png) - -### 步骤二:安装、配置Prometheus - -> 此处以prometheus安装在服务器192.168.1.3为例。 - -1. 下载 Prometheus 安装包,要求安装 V2.30.3 版本及以上,可前往 Prometheus 官网下载(https://prometheus.io/docs/introduction/first_steps/) -2. 解压安装包,进入解压后的文件夹: - -```Shell -tar xvfz prometheus-*.tar.gz -cd prometheus-* -``` - -3. 修改配置。修改配置文件prometheus.yml如下 - 1. 新增confignode任务收集ConfigNode的监控数据 - 2. 新增datanode任务收集DataNode的监控数据 - -```shell -global: - scrape_interval: 15s - evaluation_interval: 15s -scrape_configs: - - job_name: "prometheus" - static_configs: - - targets: ["localhost:9090"] - - job_name: "confignode" - static_configs: - - targets: ["iotdb-1:9091","iotdb-2:9091","iotdb-3:9091"] - honor_labels: true - - job_name: "datanode" - static_configs: - - targets: ["iotdb-1:9092","iotdb-2:9092","iotdb-3:9092"] - honor_labels: true -``` - -4. 启动Prometheus。Prometheus 监控数据的默认过期时间为15天,在生产环境中,建议将其调整为180天以上,以对更长时间的历史监控数据进行追踪,启动命令如下所示: - -```Shell -./prometheus --config.file=prometheus.yml --storage.tsdb.retention.time=180d -``` - -5. 确认启动成功。在浏览器中输入 http://192.168.1.3:9090,进入Prometheus,点击进入Status下的Target界面,当看到State均为Up时表示配置成功并已经联通。 - -
- - -
- - - -6. 点击Targets中左侧链接可以跳转到网页监控,查看相应节点的监控信息: - -![](/img/%E8%8A%82%E7%82%B9%E7%9B%91%E6%8E%A7.png) - -### 步骤三:安装grafana并配置数据源 - -> 此处以Grafana安装在服务器192.168.1.3为例。 - -1. 下载 Grafana 安装包,要求安装 V8.4.2 版本及以上,可以前往Grafana官网下载(https://grafana.com/grafana/download) -2. 解压并进入对应文件夹 - -```Shell -tar -zxvf grafana-*.tar.gz -cd grafana-* -``` - -3. 启动Grafana: - -```Shell -./bin/grafana-server web -``` - -4. 登录Grafana。在浏览器中输入 http://192.168.1.3:3000(或修改后的端口),进入Grafana,默认初始用户名和密码均为 admin。 - -5. 配置数据源。在Connections中找到Data sources,新增一个data source并配置Data Source为Prometheus - -![](/img/%E6%B7%BB%E5%8A%A0%E9%85%8D%E7%BD%AE.png) - -在配置Data Source时注意Prometheus所在的URL,配置好后点击Save & Test 出现 Data source is working 提示则为配置成功 - -![](/img/%E9%85%8D%E7%BD%AE%E6%88%90%E5%8A%9F.png) - -### 步骤四:导入IoTDB Grafana看板 - -1. 进入Grafana,选择Dashboards: - - ![](/img/%E9%9D%A2%E6%9D%BF%E9%80%89%E6%8B%A9.png) - -2. 点击右侧 Import 按钮 - - ![](/img/Import%E6%8C%89%E9%92%AE.png) - -3. 使用upload json file的方式导入Dashboard - - ![](/img/%E5%AF%BC%E5%85%A5Dashboard.png) - -4. 选择IoTDB监控面板中其中一个面板的json文件,这里以选择 Apache IoTDB ConfigNode Dashboard为例(监控面板安装包获取参见本文【安装准备】): - - ![](/img/%E9%80%89%E6%8B%A9%E9%9D%A2%E6%9D%BF.png) - -5. 选择数据源为Prometheus,然后点击Import - - ![](/img/%E9%80%89%E6%8B%A9%E6%95%B0%E6%8D%AE%E6%BA%90.png) - -6. 之后就可以看到导入的Apache IoTDB ConfigNode Dashboard监控面板 - - ![](/img/%E9%9D%A2%E6%9D%BF.png) - -7. 同样地,我们可以导入Apache IoTDB DataNode Dashboard、Apache Performance Overview Dashboard、Apache System Overview Dashboard,可看到如下的监控面板: - -
- - - -
- -8. 至此,IoTDB监控面板就全部导入完成了,现在可以随时查看监控信息了。 - - ![](/img/%E9%9D%A2%E6%9D%BF%E6%B1%87%E6%80%BB.png) - -## 附录、监控指标详解 - -### 系统面板(System Dashboard) - -该面板展示了当前系统CPU、内存、磁盘、网络资源的使用情况已经JVM的部分状况。 - -#### CPU - -- CPU Core:CPU 核数 -- CPU Load: - - System CPU Load:整个系统在采样时间内 CPU 的平均负载和繁忙程度 - - Process CPU Load:IoTDB 进程在采样时间内占用的 CPU 比例 -- CPU Time Per Minute:系统每分钟内所有进程的 CPU 时间总和 - -#### Memory - -- System Memory:当前系统内存的使用情况。 - - Commited vm size: 操作系统分配给正在运行的进程使用的虚拟内存的大小。 - - Total physical memory:系统可用物理内存的总量。 - - Used physical memory:系统已经使用的内存总量。包含进程实际使用的内存量和操作系统 buffers/cache 占用的内存。 -- System Swap Memory:交换空间(Swap Space)内存用量。 -- Process Memory:IoTDB 进程使用内存的情况。 - - Max Memory:IoTDB 进程能够从操作系统那里最大请求到的内存量。(datanode-env/confignode-env 配置文件中配置分配的内存大小) - - Total Memory:IoTDB 进程当前已经从操作系统中请求到的内存总量。 - - Used Memory:IoTDB 进程当前已经使用的内存总量。 - -#### Disk - -- Disk Space: - - Total disk space:IoTDB 可使用的最大磁盘空间。 - - Used disk space:IoTDB 已经使用的磁盘空间。 -- Log Number Per Minute:采样时间内每分钟 IoTDB 各级别日志数量的平均值。 -- File Count:IoTDB 相关文件数量 - - all:所有文件数量 - - TsFile:TsFile 数量 - - seq:顺序 TsFile 数量 - - unseq:乱序 TsFile 数量 - - wal:WAL 文件数量 - - cross-temp:跨空间合并 temp 文件数量 - - inner-seq-temp:顺序空间内合并 temp 文件数量 - - innser-unseq-temp:乱序空间内合并 temp 文件数量 - - mods:墓碑文件数量 -- Open File Count:系统打开的文件句柄数量 -- File Size:IoTDB 相关文件的大小。各子项分别是对应文件的大小。 -- Disk I/O Busy Rate:等价于 iostat 中的 %util 指标,一定程度上反映磁盘的繁忙程度。各子项分别是对应磁盘的指标。 -- Disk I/O Throughput:系统各磁盘在一段时间 I/O Throughput 的平均值。各子项分别是对应磁盘的指标。 -- Disk I/O Ops:等价于 iostat 中的 r/s 、w/s、rrqm/s、wrqm/s 四个指标,指的是磁盘每秒钟进行 I/O 的次数。read 和 write 指的是磁盘执行单次 I/O 的次数,由于块设备有相应的调度算法,在某些情况下可以将多个相邻的 I/O 合并为一次进行,merged-read 和 merged-write 指的是将多个 I/O 合并为一个 I/O 进行的次数。 -- Disk I/O Avg Time:等价于 iostat 的 await,即每个 I/O 请求的平均时延。读和写请求分开记录。 -- Disk I/O Avg Size:等价于 iostat 的 avgrq-sz,反映了每个 I/O 请求的大小。读和写请求分开记录。 -- Disk I/O Avg Queue Size:等价于 iostat 中的 avgqu-sz,即 I/O 请求队列的平均长度。 -- I/O System Call Rate:进程调用读写系统调用的频率,类似于 IOPS。 -- I/O Throughput:进程进行 I/O 的吞吐量,分为 actual_read/write 和 attempt_read/write 两类。actual read 和 actual write 指的是进程实际导致块设备进行 I/O 的字节数,不包含被 Page Cache 处理的部分。 - -#### JVM - -- GC Time Percentage:节点 JVM 在过去一分钟的时间窗口内,GC 耗时所占的比例 -- GC Allocated/Promoted Size Detail: 节点 JVM 平均每分钟晋升到老年代的对象大小,新生代/老年代和非分代新申请的对象大小 -- GC Data Size Detail:节点 JVM 长期存活的对象大小和对应代际允许的最大值 -- Heap Memory:JVM 堆内存使用情况。 - - Maximum heap memory:JVM 最大可用的堆内存大小。 - - Committed heap memory:JVM 已提交的堆内存大小。 - - Used heap memory:JVM 已经使用的堆内存大小。 - - PS Eden Space:PS Young 区的大小。 - - PS Old Space:PS Old 区的大小。 - - PS Survivor Space:PS Survivor 区的大小。 - - ...(CMS/G1/ZGC 等) -- Off Heap Memory:堆外内存用量。 - - direct memory:堆外直接内存。 - - mapped memory:堆外映射内存。 -- GC Number Per Minute:节点 JVM 平均每分钟进行垃圾回收的次数,包括 YGC 和 FGC -- GC Time Per Minute:节点 JVM 平均每分钟进行垃圾回收的耗时,包括 YGC 和 FGC -- GC Number Per Minute Detail:节点 JVM 平均每分钟由于不同 cause 进行垃圾回收的次数,包括 YGC 和 FGC -- GC Time Per Minute Detail:节点 JVM 平均每分钟由于不同 cause 进行垃圾回收的耗时,包括 YGC 和 FGC -- Time Consumed Of Compilation Per Minute:每分钟 JVM 用于编译的总时间 -- The Number of Class: - - loaded:JVM 目前已经加载的类的数量 - - unloaded:系统启动至今 JVM 卸载的类的数量 -- The Number of Java Thread:IoTDB 目前存活的线程数。各子项分别为各状态的线程数。 - -#### Network - -eno 指的是到公网的网卡,lo 是虚拟网卡。 - -- Net Speed:网卡发送和接收数据的速度 -- Receive/Transmit Data Size:网卡发送或者接收的数据包大小,自系统重启后算起 -- Packet Speed:网卡发送和接收数据包的速度,一次 RPC 请求可以对应一个或者多个数据包 -- Connection Num:当前选定进程的 socket 连接数(IoTDB只有 TCP) - -### 整体性能面板(Performance Overview Dashboard) - -#### Cluster Overview - -- Total CPU Core: 集群机器 CPU 总核数 -- DataNode CPU Load: 集群各DataNode 节点的 CPU 使用率 -- 磁盘 - - Total Disk Space: 集群机器磁盘总大小 - - DataNode Disk Usage: 集群各 DataNode 的磁盘使用率 -- Total Timeseries: 集群管理的时间序列总数(含副本),实际时间序列数需结合元数据副本数计算 -- Cluster: 集群 ConfigNode 和 DataNode 节点数量 -- Up Time: 集群启动至今的时长 -- Total Write Point Per Second: 集群每秒写入总点数(含副本),实际写入总点数需结合数据副本数分析 -- 内存 - - Total System Memory: 集群机器系统内存总大小 - - Total Swap Memory: 集群机器交换内存总大小 - - DataNode Process Memory Usage: 集群各 DataNode 的内存使用率 -- Total File Number: 集群管理文件总数量 -- Cluster System Overview: 集群机器概述,包括平均 DataNode 节点内存占用率、平均机器磁盘使用率 -- Total DataBase: 集群管理的 Database 总数(含副本) -- Total DataRegion: 集群管理的 DataRegion 总数 -- Total SchemaRegion: 集群管理的 SchemaRegion 总数 - -#### Node Overview - -- CPU Core: 节点所在机器的 CPU 核数 -- Disk Space: 节点所在机器的磁盘大小 -- Timeseries: 节点所在机器管理的时间序列数量(含副本) -- System Overview: 节点所在机器的系统概述,包括 CPU 负载、进程内存使用比率、磁盘使用比率 -- Write Point Per Second: 节点所在机器的每秒写入速度(含副本) -- System Memory: 节点所在机器的系统内存大小 -- Swap Memory: 节点所在机器的交换内存大小 -- File Number: 节点管理的文件数 - -#### Performance - -- Session Idle Time: 节点的 session 连接的总空闲时间和总忙碌时间 -- Client Connection: 节点的客户端连接情况,包括总连接数和活跃连接数 -- Time Consumed Of Operation: 节点的各类型操作耗时,包括平均值和P99 -- Average Time Consumed Of Interface: 节点的各个 thrift 接口平均耗时 -- P99 Time Consumed Of Interface: 节点的各个 thrift 接口的 P99 耗时数 -- Task Number: 节点的各项系统任务数量 -- Average Time Consumed of Task: 节点的各项系统任务的平均耗时 -- P99 Time Consumed of Task: 节点的各项系统任务的 P99 耗时 -- Operation Per Second: 节点的每秒操作数 -- 主流程 - - Operation Per Second Of Stage: 节点主流程各阶段的每秒操作数 - - Average Time Consumed Of Stage: 节点主流程各阶段平均耗时 - - P99 Time Consumed Of Stage: 节点主流程各阶段 P99 耗时 -- Schedule 阶段 - - OPS Of Schedule: 节点 schedule 阶段各子阶段每秒操作数 - - Average Time Consumed Of Schedule Stage: 节点 schedule 阶段各子阶段平均耗时 - - P99 Time Consumed Of Schedule Stage: 节点的 schedule 阶段各子阶段 P99 耗时 -- Local Schedule 各子阶段 - - OPS Of Local Schedule Stage: 节点 local schedule 各子阶段每秒操作数 - - Average Time Consumed Of Local Schedule Stage: 节点 local schedule 阶段各子阶段平均耗时 - - P99 Time Consumed Of Local Schedule Stage: 节点的 local schedule 阶段各子阶段 P99 耗时 -- Storage 阶段 - - OPS Of Storage Stage: 节点 storage 阶段各子阶段每秒操作数 - - Average Time Consumed Of Storage Stage: 节点 storage 阶段各子阶段平均耗时 - - P99 Time Consumed Of Storage Stage: 节点 storage 阶段各子阶段 P99 耗时 -- Engine 阶段 - - OPS Of Engine Stage: 节点 engine 阶段各子阶段每秒操作数 - - Average Time Consumed Of Engine Stage: 节点的 engine 阶段各子阶段平均耗时 - - P99 Time Consumed Of Engine Stage: 节点 engine 阶段各子阶段的 P99 耗时 - -#### System - -- CPU Load: 节点的 CPU 负载 -- CPU Time Per Minute: 节点的每分钟 CPU 时间,最大值和 CPU 核数相关 -- GC Time Per Minute: 节点的平均每分钟 GC 耗时,包括 YGC 和 FGC -- Heap Memory: 节点的堆内存使用情况 -- Off Heap Memory: 节点的非堆内存使用情况 -- The Number Of Java Thread: 节点的 Java 线程数量情况 -- File Count: 节点管理的文件数量情况 -- File Size: 节点管理文件大小情况 -- Log Number Per Minute: 节点的每分钟不同类型日志情况 - -### ConfigNode 面板(ConfigNode Dashboard) - -该面板展示了集群中所有管理节点的表现情况,包括分区、节点信息、客户端连接情况统计等。 - -#### Node Overview - -- Database Count: 节点的数据库数量 -- Region - - DataRegion Count: 节点的 DataRegion 数量 - - DataRegion Current Status: 节点的 DataRegion 的状态 - - SchemaRegion Count: 节点的 SchemaRegion 数量 - - SchemaRegion Current Status: 节点的 SchemaRegion 的状态 -- System Memory: 节点的系统内存大小 -- Swap Memory: 节点的交换区内存大小 -- ConfigNodes: 节点所在集群的 ConfigNode 的运行状态 -- DataNodes: 节点所在集群的 DataNode 情况 -- System Overview: 节点的系统概述,包括系统内存、磁盘使用、进程内存以及CPU负载 - -#### NodeInfo - -- Node Count: 节点所在集群的节点数量,包括 ConfigNode 和 DataNode -- ConfigNode Status: 节点所在集群的 ConfigNode 节点的状态 -- DataNode Status: 节点所在集群的 DataNode 节点的状态 -- SchemaRegion Distribution: 节点所在集群的 SchemaRegion 的分布情况 -- SchemaRegionGroup Leader Distribution: 节点所在集群的 SchemaRegionGroup 的 Leader 分布情况 -- DataRegion Distribution: 节点所在集群的 DataRegion 的分布情况 -- DataRegionGroup Leader Distribution: 节点所在集群的 DataRegionGroup 的 Leader 分布情况 - -#### Protocol - -- 客户端数量统计 - - Active Client Num: 节点各线程池的活跃客户端数量 - - Idle Client Num: 节点各线程池的空闲客户端数量 - - Borrowed Client Count: 节点各线程池的借用客户端数量 - - Created Client Count: 节点各线程池的创建客户端数量 - - Destroyed Client Count: 节点各线程池的销毁客户端数量 -- 客户端时间情况 - - Client Mean Active Time: 节点各线程池客户端的平均活跃时间 - - Client Mean Borrow Wait Time: 节点各线程池的客户端平均借用等待时间 - - Client Mean Idle Time: 节点各线程池的客户端平均空闲时间 - -#### Partition Table - -- SchemaRegionGroup Count: 节点所在集群的 Database 的 SchemaRegionGroup 的数量 -- DataRegionGroup Count: 节点所在集群的 Database 的 DataRegionGroup 的数量 -- SeriesSlot Count: 节点所在集群的 Database 的 SeriesSlot 的数量 -- TimeSlot Count: 节点所在集群的 Database 的 TimeSlot 的数量 -- DataRegion Status: 节点所在集群的 DataRegion 状态 -- SchemaRegion Status: 节点所在集群的 SchemaRegion 的状态 - -#### Consensus - -- Ratis Stage Time: 节点的 Ratis 各阶段耗时 -- Write Log Entry: 节点的 Ratis 写 Log 的耗时 -- Remote / Local Write Time: 节点的 Ratis 的远程写入和本地写入的耗时 -- Remote / Local Write QPS: 节点 Ratis 的远程和本地写入的 QPS -- RatisConsensus Memory: 节点 Ratis 共识协议的内存使用 - -### DataNode 面板(DataNode Dashboard) - -该面板展示了集群中所有数据节点的监控情况,包含写入耗时、查询耗时、存储文件数等。 - -#### Node Overview - -- The Number Of Entity: 节点管理的实体情况 -- Write Point Per Second: 节点的每秒写入速度 -- Memory Usage: 节点的内存使用情况,包括 IoT Consensus 各部分内存占用、SchemaRegion内存总占用和各个数据库的内存占用。 - -#### Protocol - -- 节点操作耗时 - - The Time Consumed Of Operation (avg): 节点的各项操作的平均耗时 - - The Time Consumed Of Operation (50%): 节点的各项操作耗时的中位数 - - The Time Consumed Of Operation (99%): 节点的各项操作耗时的P99 -- Thrift统计 - - The QPS Of Interface: 节点各个 Thrift 接口的 QPS - - The Avg Time Consumed Of Interface: 节点各个 Thrift 接口的平均耗时 - - Thrift Connection: 节点的各类型的 Thrfit 连接数量 - - Thrift Active Thread: 节点各类型的活跃 Thrift 连接数量 -- 客户端统计 - - Active Client Num: 节点各线程池的活跃客户端数量 - - Idle Client Num: 节点各线程池的空闲客户端数量 - - Borrowed Client Count: 节点的各线程池借用客户端数量 - - Created Client Count: 节点各线程池的创建客户端数量 - - Destroyed Client Count: 节点各线程池的销毁客户端数量 - - Client Mean Active Time: 节点各线程池的客户端平均活跃时间 - - Client Mean Borrow Wait Time: 节点各线程池的客户端平均借用等待时间 - - Client Mean Idle Time: 节点各线程池的客户端平均空闲时间 - -#### Storage Engine - -- File Count: 节点管理的各类型文件数量 -- File Size: 节点管理的各类型文件大小 -- TsFile - - TsFile Total Size In Each Level: 节点管理的各级别 TsFile 文件总大小 - - TsFile Count In Each Level: 节点管理的各级别 TsFile 文件数量 - - Avg TsFile Size In Each Level: 节点管理的各级别 TsFile 文件的平均大小 -- Task Number: 节点的 Task 数量 -- The Time Consumed of Task: 节点的 Task 的耗时 -- Compaction - - Compaction Read And Write Per Second: 节点的每秒钟合并读写速度 - - Compaction Number Per Minute: 节点的每分钟合并数量 - - Compaction Process Chunk Status: 节点合并不同状态的 Chunk 的数量 - - Compacted Point Num Per Minute: 节点每分钟合并的点数 - -#### Write Performance - -- Write Cost(avg): 节点写入耗时平均值,包括写入 wal 和 memtable -- Write Cost(50%): 节点写入耗时中位数,包括写入 wal 和 memtable -- Write Cost(99%): 节点写入耗时的P99,包括写入 wal 和 memtable -- WAL - - WAL File Size: 节点管理的 WAL 文件总大小 - - WAL File Num: 节点管理的 WAL 文件数量 - - WAL Nodes Num: 节点管理的 WAL Node 数量 - - Make Checkpoint Costs: 节点创建各类型的 CheckPoint 的耗时 - - WAL Serialize Total Cost: 节点 WAL 序列化总耗时 - - Data Region Mem Cost: 节点不同的DataRegion的内存占用、当前实例的DataRegion的内存总占用、当前集群的 DataRegion 的内存总占用 - - Serialize One WAL Info Entry Cost: 节点序列化一个WAL Info Entry 耗时 - - Oldest MemTable Ram Cost When Cause Snapshot: 节点 WAL 触发 oldest MemTable snapshot 时 MemTable 大小 - - Oldest MemTable Ram Cost When Cause Flush: 节点 WAL 触发 oldest MemTable flush 时 MemTable 大小 - - Effective Info Ratio Of WALNode: 节点的不同 WALNode 的有效信息比 - - WAL Buffer - - WAL Buffer Cost: 节点 WAL flush SyncBuffer 耗时,包含同步和异步两种 - - WAL Buffer Used Ratio: 节点的 WAL Buffer 的使用率 - - WAL Buffer Entries Count: 节点的 WAL Buffer 的条目数量 -- Flush统计 - - Flush MemTable Cost(avg): 节点 Flush 的总耗时和各个子阶段耗时的平均值 - - Flush MemTable Cost(50%): 节点 Flush 的总耗时和各个子阶段耗时的中位数 - - Flush MemTable Cost(99%): 节点 Flush 的总耗时和各个子阶段耗时的 P99 - - Flush Sub Task Cost(avg): 节点的 Flush 平均子任务耗时平均情况,包括排序、编码、IO 阶段 - - Flush Sub Task Cost(50%): 节点的 Flush 各个子任务的耗时中位数情况,包括排序、编码、IO 阶段 - - Flush Sub Task Cost(99%): 节点的 Flush 平均子任务耗时P99情况,包括排序、编码、IO 阶段 -- Pending Flush Task Num: 节点的处于阻塞状态的 Flush 任务数量 -- Pending Flush Sub Task Num: 节点阻塞的 Flush 子任务数量 -- Tsfile Compression Ratio Of Flushing MemTable: 节点刷盘 Memtable 时对应的 TsFile 压缩率 -- Flush TsFile Size Of DataRegions: 节点不同 DataRegion 的每次刷盘时对应的 TsFile 大小 -- Size Of Flushing MemTable: 节点刷盘的 Memtable 的大小 -- Points Num Of Flushing MemTable: 节点不同 DataRegion 刷盘时的点数 -- Series Num Of Flushing MemTable: 节点的不同 DataRegion 的 Memtable 刷盘时的时间序列数 -- Average Point Num Of Flushing MemChunk: 节点 MemChunk 刷盘的平均点数 - -#### Schema Engine - -- Schema Engine Mode: 节点的元数据引擎模式 -- Schema Consensus Protocol: 节点的元数据共识协议 -- Schema Region Number: 节点管理的 SchemaRegion 数量 -- Schema Region Memory Overview: 节点的 SchemaRegion 的内存数量 -- Memory Usgae per SchemaRegion: 节点 SchemaRegion 的平均内存使用大小 -- Cache MNode per SchemaRegion: 节点每个 SchemaRegion 中 cache node 个数 -- MLog Length and Checkpoint: 节点每个 SchemaRegion 的当前 mlog 的总长度和检查点位置(仅 SimpleConsensus 有效) -- Buffer MNode per SchemaRegion: 节点每个 SchemaRegion 中 buffer node 个数 -- Activated Template Count per SchemaRegion: 节点每个SchemaRegion中已激活的模版数 -- 时间序列统计 - - Timeseries Count per SchemaRegion: 节点 SchemaRegion 的平均时间序列数 - - Series Type: 节点不同类型的时间序列数量 - - Time Series Number: 节点的时间序列总数 - - Template Series Number: 节点的模板时间序列总数 - - Template Series Count per SchemaRegion: 节点每个SchemaRegion中通过模版创建的序列数 -- IMNode统计 - - Pinned MNode per SchemaRegion: 节点每个 SchemaRegion 中 Pinned 的 IMNode 节点数 - - Pinned Memory per SchemaRegion: 节点每个 SchemaRegion 中 Pinned 的 IMNode 节点的内存占用大小 - - Unpinned MNode per SchemaRegion: 节点每个 SchemaRegion 中 Unpinned 的 IMNode 节点数 - - Unpinned Memory per SchemaRegion: 节点每个 SchemaRegion 中 Unpinned 的 IMNode 节点的内存占用大小 - - Schema File Memory MNode Number: 节点全局 pinned 和 unpinned 的 IMNode 节点数 - - Release and Flush MNode Rate: 节点每秒 release 和 flush 的 IMNode 数量 -- Cache Hit Rate: 节点的缓存命中率 -- Release and Flush Thread Number: 节点当前活跃的 Release 和 Flush 线程数量 -- Time Consumed of Relead and Flush (avg): 节点触发 cache 释放和 buffer 刷盘耗时的平均值 -- Time Consumed of Relead and Flush (99%): 节点触发 cache 释放和 buffer 刷盘的耗时的 P99 - -#### Query Engine - -- 各阶段耗时 - - The time consumed of query plan stages(avg): 节点查询各阶段耗时的平均值 - - The time consumed of query plan stages(50%): 节点查询各阶段耗时的中位数 - - The time consumed of query plan stages(99%): 节点查询各阶段耗时的P99 -- 执行计划分发耗时 - - The time consumed of plan dispatch stages(avg): 节点查询执行计划分发耗时的平均值 - - The time consumed of plan dispatch stages(50%): 节点查询执行计划分发耗时的中位数 - - The time consumed of plan dispatch stages(99%): 节点查询执行计划分发耗时的P99 -- 执行计划执行耗时 - - The time consumed of query execution stages(avg): 节点查询执行计划执行耗时的平均值 - - The time consumed of query execution stages(50%): 节点查询执行计划执行耗时的中位数 - - The time consumed of query execution stages(99%): 节点查询执行计划执行耗时的P99 -- 算子执行耗时 - - The time consumed of operator execution stages(avg): 节点查询算子执行耗时的平均值 - - The time consumed of operator execution(50%): 节点查询算子执行耗时的中位数 - - The time consumed of operator execution(99%): 节点查询算子执行耗时的P99 -- 聚合查询计算耗时 - - The time consumed of query aggregation(avg): 节点聚合查询计算耗时的平均值 - - The time consumed of query aggregation(50%): 节点聚合查询计算耗时的中位数 - - The time consumed of query aggregation(99%): 节点聚合查询计算耗时的P99 -- 文件/内存接口耗时 - - The time consumed of query scan(avg): 节点查询文件/内存接口耗时的平均值 - - The time consumed of query scan(50%): 节点查询文件/内存接口耗时的中位数 - - The time consumed of query scan(99%): 节点查询文件/内存接口耗时的P99 -- 资源访问数量 - - The usage of query resource(avg): 节点查询资源访问数量的平均值 - - The usage of query resource(50%): 节点查询资源访问数量的中位数 - - The usage of query resource(99%): 节点查询资源访问数量的P99 -- 数据传输耗时 - - The time consumed of query data exchange(avg): 节点查询数据传输耗时的平均值 - - The time consumed of query data exchange(50%): 节点查询数据传输耗时的中位数 - - The time consumed of query data exchange(99%): 节点查询数据传输耗时的P99 -- 数据传输数量 - - The count of Data Exchange(avg): 节点查询的数据传输数量的平均值 - - The count of Data Exchange: 节点查询的数据传输数量的分位数,包括中位数和P99 -- 任务调度数量与耗时 - - The number of query queue: 节点查询任务调度数量 - - The time consumed of query schedule time(avg): 节点查询任务调度耗时的平均值 - - The time consumed of query schedule time(50%): 节点查询任务调度耗时的中位数 - - The time consumed of query schedule time(99%): 节点查询任务调度耗时的P99 - -#### Query Interface - -- 加载时间序列元数据 - - The time consumed of load timeseries metadata(avg): 节点查询加载时间序列元数据耗时的平均值 - - The time consumed of load timeseries metadata(50%): 节点查询加载时间序列元数据耗时的中位数 - - The time consumed of load timeseries metadata(99%): 节点查询加载时间序列元数据耗时的P99 -- 读取时间序列 - - The time consumed of read timeseries metadata(avg): 节点查询读取时间序列耗时的平均值 - - The time consumed of read timeseries metadata(50%): 节点查询读取时间序列耗时的中位数 - - The time consumed of read timeseries metadata(99%): 节点查询读取时间序列耗时的P99 -- 修改时间序列元数据 - - The time consumed of timeseries metadata modification(avg): 节点查询修改时间序列元数据耗时的平均值 - - The time consumed of timeseries metadata modification(50%): 节点查询修改时间序列元数据耗时的中位数 - - The time consumed of timeseries metadata modification(99%): 节点查询修改时间序列元数据耗时的P99 -- 加载Chunk元数据列表 - - The time consumed of load chunk metadata list(avg): 节点查询加载Chunk元数据列表耗时的平均值 - - The time consumed of load chunk metadata list(50%): 节点查询加载Chunk元数据列表耗时的中位数 - - The time consumed of load chunk metadata list(99%): 节点查询加载Chunk元数据列表耗时的P99 -- 修改Chunk元数据 - - The time consumed of chunk metadata modification(avg): 节点查询修改Chunk元数据耗时的平均值 - - The time consumed of chunk metadata modification(50%): 节点查询修改Chunk元数据耗时的总位数 - - The time consumed of chunk metadata modification(99%): 节点查询修改Chunk元数据耗时的P99 -- 按照Chunk元数据过滤 - - The time consumed of chunk metadata filter(avg): 节点查询按照Chunk元数据过滤耗时的平均值 - - The time consumed of chunk metadata filter(50%): 节点查询按照Chunk元数据过滤耗时的中位数 - - The time consumed of chunk metadata filter(99%): 节点查询按照Chunk元数据过滤耗时的P99 -- 构造Chunk Reader - - The time consumed of construct chunk reader(avg): 节点查询构造Chunk Reader耗时的平均值 - - The time consumed of construct chunk reader(50%): 节点查询构造Chunk Reader耗时的中位数 - - The time consumed of construct chunk reader(99%): 节点查询构造Chunk Reader耗时的P99 -- 读取Chunk - - The time consumed of read chunk(avg): 节点查询读取Chunk耗时的平均值 - - The time consumed of read chunk(50%): 节点查询读取Chunk耗时的中位数 - - The time consumed of read chunk(99%): 节点查询读取Chunk耗时的P99 -- 初始化Chunk Reader - - The time consumed of init chunk reader(avg): 节点查询初始化Chunk Reader耗时的平均值 - - The time consumed of init chunk reader(50%): 节点查询初始化Chunk Reader耗时的中位数 - - The time consumed of init chunk reader(99%): 节点查询初始化Chunk Reader耗时的P99 -- 通过 Page Reader 构造 TsBlock - - The time consumed of build tsblock from page reader(avg): 节点查询通过 Page Reader 构造 TsBlock 耗时的平均值 - - The time consumed of build tsblock from page reader(50%): 节点查询通过 Page Reader 构造 TsBlock 耗时的中位数 - - The time consumed of build tsblock from page reader(99%): 节点查询通过 Page Reader 构造 TsBlock 耗时的P99 -- 查询通过 Merge Reader 构造 TsBlock - - The time consumed of build tsblock from merge reader(avg): 节点查询通过 Merge Reader 构造 TsBlock 耗时的平均值 - - The time consumed of build tsblock from merge reader(50%): 节点查询通过 Merge Reader 构造 TsBlock 耗时的中位数 - - The time consumed of build tsblock from merge reader(99%): 节点查询通过 Merge Reader 构造 TsBlock 耗时的P99 - -#### Query Data Exchange - -查询的数据交换耗时。 - -- 通过 source handle 获取 TsBlock - - The time consumed of source handle get tsblock(avg): 节点查询通过 source handle 获取 TsBlock 耗时的平均值 - - The time consumed of source handle get tsblock(50%): 节点查询通过 source handle 获取 TsBlock 耗时的中位数 - - The time consumed of source handle get tsblock(99%): 节点查询通过 source handle 获取 TsBlock 耗时的P99 -- 通过 source handle 反序列化 TsBlock - - The time consumed of source handle deserialize tsblock(avg): 节点查询通过 source handle 反序列化 TsBlock 耗时的平均值 - - The time consumed of source handle deserialize tsblock(50%): 节点查询通过 source handle 反序列化 TsBlock 耗时的中位数 - - The time consumed of source handle deserialize tsblock(99%): 节点查询通过 source handle 反序列化 TsBlock 耗时的P99 -- 通过 sink handle 发送 TsBlock - - The time consumed of sink handle send tsblock(avg): 节点查询通过 sink handle 发送 TsBlock 耗时的平均值 - - The time consumed of sink handle send tsblock(50%): 节点查询通过 sink handle 发送 TsBlock 耗时的中位数 - - The time consumed of sink handle send tsblock(99%): 节点查询通过 sink handle 发送 TsBlock 耗时的P99 -- 回调 data block event - - The time consumed of on acknowledge data block event task(avg): 节点查询回调 data block event 耗时的平均值 - - The time consumed of on acknowledge data block event task(50%): 节点查询回调 data block event 耗时的中位数 - - The time consumed of on acknowledge data block event task(99%): 节点查询回调 data block event 耗时的P99 -- 获取 data block task - - The time consumed of get data block task(avg): 节点查询获取 data block task 耗时的平均值 - - The time consumed of get data block task(50%): 节点查询获取 data block task 耗时的中位数 - - The time consumed of get data block task(99%): 节点查询获取 data block task 耗时的 P99 - -#### Query Related Resource - -- MppDataExchangeManager: 节点查询时 shuffle sink handle 和 source handle 的数量 -- LocalExecutionPlanner: 节点可分配给查询分片的剩余内存 -- FragmentInstanceManager: 节点正在运行的查询分片上下文信息和查询分片的数量 -- Coordinator: 节点上记录的查询数量 -- MemoryPool Size: 节点查询相关的内存池情况 -- MemoryPool Capacity: 节点查询相关的内存池的大小情况,包括最大值和剩余可用值 -- DriverScheduler: 节点查询相关的队列任务数量 - -#### Consensus - IoT Consensus - -- 内存使用 - - IoTConsensus Used Memory: 节点的 IoT Consensus 的内存使用情况,包括总使用内存大小、队列使用内存大小、同步使用内存大小 -- 节点间同步情况 - - IoTConsensus Sync Index: 节点的 IoT Consensus 的 不同 DataRegion 的 SyncIndex 大小 - - IoTConsensus Overview: 节点的 IoT Consensus 的总同步差距和缓存的请求数量 - - IoTConsensus Search Index Rate: 节点 IoT Consensus 不同 DataRegion 的写入 SearchIndex 的增长速率 - - IoTConsensus Safe Index Rate: 节点 IoT Consensus 不同 DataRegion 的同步 SafeIndex 的增长速率 - - IoTConsensus LogDispatcher Request Size: 节点 IoT Consensus 不同 DataRegion 同步到其他节点的请求大小 - - Sync Lag: 节点 IoT Consensus 不同 DataRegion 的同步差距大小 - - Min Peer Sync Lag: 节点 IoT Consensus 不同 DataRegion 向不同副本的最小同步差距 - - Sync Speed Diff Of Peers: 节点 IoT Consensus 不同 DataRegion 向不同副本同步的最大差距 - - IoTConsensus LogEntriesFromWAL Rate: 节点 IoT Consensus 不同 DataRegion 从 WAL 获取日志的速率 - - IoTConsensus LogEntriesFromQueue Rate: 节点 IoT Consensus 不同 DataRegion 从 队列获取日志的速率 -- 不同执行阶段耗时 - - The Time Consumed Of Different Stages (avg): 节点 IoT Consensus 不同执行阶段的耗时的平均值 - - The Time Consumed Of Different Stages (50%): 节点 IoT Consensus 不同执行阶段的耗时的中位数 - - The Time Consumed Of Different Stages (99%): 节点 IoT Consensus 不同执行阶段的耗时的P99 - -#### Consensus - DataRegion Ratis Consensus - -- Ratis Stage Time: 节点 Ratis 不同阶段的耗时 -- Write Log Entry: 节点 Ratis 写 Log 不同阶段的耗时 -- Remote / Local Write Time: 节点 Ratis 在本地或者远端写入的耗时 -- Remote / Local Write QPS: 节点 Ratis 在本地或者远端写入的 QPS -- RatisConsensus Memory: 节点 Ratis 的内存使用情况 - -#### Consensus - SchemaRegion Ratis Consensus - -- Ratis Stage Time: 节点 Ratis 不同阶段的耗时 -- Write Log Entry: 节点 Ratis 写 Log 各阶段的耗时 -- Remote / Local Write Time: 节点 Ratis 在本地或者远端写入的耗时 -- Remote / Local Write QPS: 节点 Ratis 在本地或者远端写入的QPS -- RatisConsensus Memory: 节点 Ratis 内存使用情况 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Slow-Query-Management.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Slow-Query-Management.md deleted file mode 100644 index f2348f2dc..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Slow-Query-Management.md +++ /dev/null @@ -1,35 +0,0 @@ - - -# 慢查询管理 - -IoTDB 会将慢查询输出到单独的日志文件 log_datanode_slow_sql.log 中,并记录其执行耗时。 - -## 配置慢查询的阈值 - -IoTDB 在 `iotdb-common.properties` 提供了 `slow_query_threshold` 配置项,单位是毫秒,默认是30秒,超过此参数指定的阈值,便会被判断为慢查询,待其查询执行结束后,将其记录在 log_datanode_slow_sql.log 中。 - -## 慢查询日志示例 - -``` -2023-07-31 20:15:00,533 [pool-27-IoTDB-ClientRPC-Processor-1$20230731_121500_00003_1] INFO o.a.i.d.q.p.Coordinator:225 - Cost: 42593 ms, sql is select * from root.db.** -``` - diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md deleted file mode 100644 index 2a090ad69..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md +++ /dev/null @@ -1,179 +0,0 @@ - -# 单机版部署 - -## 注意事项 - -1. 安装前请确认系统已参照[系统配置](./Environment-Requirements.md)准备完成。 - -2. 部署时推荐优先使用`hostname`进行IP配置,可避免后期修改主机ip导致数据库无法启动的问题。设置hostname需要在目标服务器上配置/etc/hosts,如本机ip是192.168.1.3,hostname是iotdb-1,则可以使用以下命令设置服务器的 hostname,并使用hostname配置IoTDB的`cn_internal_address`、dn_internal_address、dn_rpc_address。 - - ```shell - echo "192.168.1.3 iotdb-1" >> /etc/hosts - ``` - -3. 部分参数首次启动后不能修改,请参考下方的【参数配置】章节进行设置。 - -4. 无论是在 linux 还是 windows 中,请确保 IoTDB 的安装路径中不含空格和中文,避免软件运行异常。 - -5. 请注意,安装部署IoTDB时需要保持使用同一个用户进行操作,您可以: -- 使用 root 用户(推荐):使用 root 用户可以避免权限等问题。 -- 使用固定的非 root 用户: - - 使用同一用户操作:确保在启动、停止等操作均保持使用同一用户,不要切换用户。 - - 避免使用 sudo:尽量避免使用 sudo 命令,因为它会以 root 用户权限执行命令,可能会引起权限混淆或安全问题。 - -## 安装步骤 - -### 解压安装包并进入安装目录 - -```shell -unzip apache-iotdb-{version}-all-bin.zip -cd apache-iotdb-{version}-all-bin -``` - -### 参数配置 - -#### 环境脚本配置 - -- ./conf/confignode-env.sh(./conf/confignode-env.bat)配置 - -| **配置项** | **说明** | **默认值** | **推荐值** | 备注 | -| ----------- | :------------------------------------: | :--------: | :----------------------------------------------: | :----------: | -| MEMORY_SIZE | IoTDB ConfigNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -- ./conf/datanode-env.sh(./conf/datanode-env.bat)配置 - -| **配置项** | **说明** | **默认值** | **推荐值** | 备注 | -| :---------: | :----------------------------------: | :--------: | :----------------------------------------------: | :----------: | -| MEMORY_SIZE | IoTDB DataNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -#### 系统通用配置 - -打开通用配置文件(./conf/iotdb-common.properties 文件),设置以下参数: - -| **配置项** | **说明** | **默认值** | **推荐值** | 备注 | -| :-----------------------: | :------------------------------: | :------------: | :----------------------------------------------: | :-----------------------: | -| cluster_name | 集群名称 | defaultCluster | 可根据需要设置集群名称,如无特殊需要保持默认即可 | 首次启动后不可修改 | -| schema_replication_factor | 元数据副本数,单机版此处设置为 1 | 1 | 1 | 默认1,首次启动后不可修改 | -| data_replication_factor | 数据副本数,单机版此处设置为 1 | 1 | 1 | 默认1,首次启动后不可修改 | - -#### ConfigNode 配置 - -打开ConfigNode配置文件(./conf/iotdb-confignode.properties文件),设置以下参数: - -| **配置项** | **说明** | **默认** | 推荐值 | **备注** | -| :-----------------: | :----------------------------------------------------------: | :-------------: | :----------------------------------------------: | :----------------: | -| cn_internal_address | ConfigNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | 首次启动后不能修改 | -| cn_internal_port | ConfigNode在集群内部通讯使用的端口 | 10710 | 10710 | 首次启动后不能修改 | -| cn_consensus_port | ConfigNode副本组共识协议通信使用的端口 | 10720 | 10720 | 首次启动后不能修改 | -| cn_seed_config_node | 节点注册加入集群时连接的ConfigNode 的地址,cn_internal_address:cn_internal_port | 127.0.0.1:10710 | cn_internal_address:cn_internal_port | 首次启动后不能修改 | - -#### DataNode 配置 - -打开DataNode配置文件 ./conf/iotdb-datanode.properties,设置以下参数: - -| **配置项** | **说明** | **默认** | 推荐值 | **备注** | -| :-----------------------------: | :----------------------------------------------------------: | :-------------: | :----------------------------------------------: | :----------------- | -| dn_rpc_address | 客户端 RPC 服务的地址 | 0.0.0.0 | 所在服务器的IPV4地址或hostname,推荐使用hostname | 重启服务生效 | -| dn_rpc_port | 客户端 RPC 服务的端口 | 6667 | 6667 | 重启服务生效 | -| dn_internal_address | DataNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | 首次启动后不能修改 | -| dn_internal_port | DataNode在集群内部通信使用的端口 | 10730 | 10730 | 首次启动后不能修改 | -| dn_mpp_data_exchange_port | DataNode用于接收数据流使用的端口 | 10740 | 10740 | 首次启动后不能修改 | -| dn_data_region_consensus_port | DataNode用于数据副本共识协议通信使用的端口 | 10750 | 10750 | 首次启动后不能修改 | -| dn_schema_region_consensus_port | DataNode用于元数据副本共识协议通信使用的端口 | 10760 | 10760 | 首次启动后不能修改 | -| dn_seed_config_node | 节点注册加入集群时连接的ConfigNode地址,即cn_internal_address:cn_internal_port | 127.0.0.1:10710 | cn_internal_address:cn_internal_port | 首次启动后不能修改 | - -> ❗️注意:VSCode Remote等编辑器无自动保存配置功能,请确保修改的文件被持久化保存,否则配置项无法生效 - -### 启动ConfigNode 节点 - -进入iotdb的sbin目录下,启动confignode - -```shell -./start-confignode.sh -d #“-d”参数将在后台进行启动 -``` -如果启动失败,请参考[常见问题](#常见问题)。 - -### 启动DataNode 节点 - - 进入iotdb的sbin目录下,启动datanode: - -```shell -cd sbin -./start-datanode.sh -d #-d参数将在后台进行启动 -``` - -### 验证部署 - -可直接执行 ./sbin 目录下的 Cli 启动脚本: - -```shell -./start-cli.sh -h ip(本机ip或域名) -p 端口号(6667) -``` - - 成功启动后,出现如下界面显示IoTDB安装成功。 - -![](/img/%E5%BC%80%E6%BA%90%E7%89%88%E5%90%AF%E5%8A%A8%E6%88%90%E5%8A%9F.png) - - -出现安装成功界面后,使用`show cluster`命令查看服务运行状态 - -当看到status都是running表示服务启动成功 - -![](/img/%E5%BC%80%E6%BA%90-%E5%8D%95%E6%9C%BAshow.jpeg) - -> 出现`ACTIVATED(W)`为被动激活,表示此ConfigNode没有license文件(或没有签发时间戳最新的license文件)。此时建议检查license文件是否已放入license文件夹,没有请放入license文件,若已存在license文件,可能是此节点license文件与其他节点信息不一致导致,请联系天谋工作人员重新申请. - -## 常见问题 - -1. Confignode节点启动失败 - - 步骤 1: 请查看启动日志,检查是否修改了某些首次启动后不可改的参数。 - - 步骤 2: 请查看启动日志,检查是否出现其他异常。日志中若存在异常现象,请联系天谋技术支持人员咨询解决方案。 - - 步骤 3: 如果是首次部署或者数据可删除,也可按下述步骤清理环境,重新部署后,再次启动。 - - 步骤 4: 清理环境: - - a. 结束所有 ConfigNode 和 DataNode 进程。 - - ```Bash - # 1. 停止 ConfigNode 和 DataNode 服务 - sbin/stop-standalone.sh - - # 2. 检查是否还有进程残留 - jps - # 或者 - ps -ef|gerp iotdb - - # 3. 如果有进程残留,则手动kill - kill -9 - # 如果确定机器上仅有1个iotdb,可以使用下面命令清理残留进程 - ps -ef|grep iotdb|grep -v grep|tr -s ' ' ' ' |cut -d ' ' -f2|xargs kill -9 - ``` - b. 删除 data 和 logs 目录。 - - 说明:删除 data 目录是必要的,删除 logs 目录是为了纯净日志,非必需。 - ```Bash - cd /data/iotdb - rm -rf data logs - ``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md deleted file mode 100644 index 7416a5c19..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md +++ /dev/null @@ -1,220 +0,0 @@ - -# 单机版部署 - -本章将介绍如何启动IoTDB单机实例,IoTDB单机实例包括 1 个ConfigNode 和1个DataNode(即通常所说的1C1D)。 - -## 注意事项 - -1. 安装前请确认系统已参照[系统配置](./Environment-Requirements.md)准备完成。 - -2. 部署时推荐优先使用`hostname`进行IP配置,可避免后期修改主机ip导致数据库无法启动的问题。设置hostname需要在目标服务器上配置/etc/hosts,如本机ip是192.168.1.3,hostname是iotdb-1,则可以使用以下命令设置服务器的 hostname,并使用hostname配置IoTDB的`cn_internal_address`、dn_internal_address、dn_rpc_address。 - - ```shell - echo "192.168.1.3 iotdb-1" >> /etc/hosts - ``` - -3. 部分参数首次启动后不能修改,请参考下方的【参数配置】章节进行设置 - -4. 无论是在 linux 还是 windows 中,请确保 IoTDB 的安装路径中不含空格和中文,避免软件运行异常。 - -5. 请注意,安装部署(包括激活和使用软件)IoTDB时需要保持使用同一个用户进行操作,您可以: -- 使用 root 用户(推荐):使用 root 用户可以避免权限等问题。 -- 使用固定的非 root 用户: - - 使用同一用户操作:确保在启动、激活、停止等操作均保持使用同一用户,不要切换用户。 - - 避免使用 sudo:尽量避免使用 sudo 命令,因为它会以 root 用户权限执行命令,可能会引起权限混淆或安全问题。 - -6. 推荐部署监控面板,可以对重要运行指标进行监控,随时掌握数据库运行状态,监控面板可以联系商务获取,部署监控面板步骤可以参考:[监控面板部署](./Monitoring-panel-deployment.md)。 - -## 安装步骤 - -### 解压安装包并进入安装目录 - -```shell -unzip iotdb-enterprise-{version}-bin.zip -cd iotdb-enterprise-{version}-bin -``` - -### 参数配置 - -#### 环境脚本配置 - -- ./conf/confignode-env.sh(./conf/confignode-env.bat)配置 - -| **配置项** | **说明** | **默认值** | **推荐值** | 备注 | -| :---------: | :------------------------------------: | :--------: | :----------------------------------------------: | :----------: | -| MEMORY_SIZE | IoTDB ConfigNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -- ./conf/datanode-env.sh(./conf/datanode-env.bat)配置 - -| **配置项** | **说明** | **默认值** | **推荐值** | 备注 | -| :---------: | :----------------------------------: | :--------: | :----------------------------------------------: | :----------: | -| MEMORY_SIZE | IoTDB DataNode节点可以使用的内存总量 | 空 | 可按需填写,填写后系统会根据填写的数值来分配内存 | 重启服务生效 | - -#### 系统通用配置 - -打开通用配置文件(./conf/iotdb-common.properties 文件),设置以下参数: - -| **配置项** | **说明** | **默认值** | **推荐值** | 备注 | -| :-----------------------: | :------------------------------: | :------------: | :----------------------------------------------: | :-----------------------: | -| cluster_name | 集群名称 | defaultCluster | 可根据需要设置集群名称,如无特殊需要保持默认即可 | 首次启动后不可修改 | -| schema_replication_factor | 元数据副本数,单机版此处设置为 1 | 1 | 1 | 默认1,首次启动后不可修改 | -| data_replication_factor | 数据副本数,单机版此处设置为 1 | 1 | 1 | 默认1,首次启动后不可修改 | - -#### ConfigNode配置 - -打开ConfigNode配置文件(./conf/iotdb-confignode.properties文件),设置以下参数: - -| **配置项** | **说明** | **默认** | 推荐值 | **备注** | -| :-----------------: | :----------------------------------------------------------: | :-------------: | :----------------------------------------------: | :----------------: | -| cn_internal_address | ConfigNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | 首次启动后不能修改 | -| cn_internal_port | ConfigNode在集群内部通讯使用的端口 | 10710 | 10710 | 首次启动后不能修改 | -| cn_consensus_port | ConfigNode副本组共识协议通信使用的端口 | 10720 | 10720 | 首次启动后不能修改 | -| cn_seed_config_node | 节点注册加入集群时连接的ConfigNode 的地址,cn_internal_address:cn_internal_port | 127.0.0.1:10710 | cn_internal_address:cn_internal_port | 首次启动后不能修改 | - -#### DataNode 配置 - -打开DataNode配置文件(./conf/iotdb-datanode.properties文件),设置以下参数: - -| **配置项** | **说明** | **默认** | 推荐值 | **备注** | -| :------------------------------ | :----------------------------------------------------------- | :-------------- | :----------------------------------------------- | :----------------- | -| dn_rpc_address | 客户端 RPC 服务的地址 | 0.0.0.0 | 所在服务器的IPV4地址或hostname,推荐使用hostname | 重启服务生效 | -| dn_rpc_port | 客户端 RPC 服务的端口 | 6667 | 6667 | 重启服务生效 | -| dn_internal_address | DataNode在集群内部通讯使用的地址 | 127.0.0.1 | 所在服务器的IPV4地址或hostname,推荐使用hostname | 首次启动后不能修改 | -| dn_internal_port | DataNode在集群内部通信使用的端口 | 10730 | 10730 | 首次启动后不能修改 | -| dn_mpp_data_exchange_port | DataNode用于接收数据流使用的端口 | 10740 | 10740 | 首次启动后不能修改 | -| dn_data_region_consensus_port | DataNode用于数据副本共识协议通信使用的端口 | 10750 | 10750 | 首次启动后不能修改 | -| dn_schema_region_consensus_port | DataNode用于元数据副本共识协议通信使用的端口 | 10760 | 10760 | 首次启动后不能修改 | -| dn_seed_config_node | 节点注册加入集群时连接的ConfigNode地址,即cn_internal_address:cn_internal_port | 127.0.0.1:10710 | cn_internal_address:cn_internal_port | 首次启动后不能修改 | - -> ❗️注意:VSCode Remote等编辑器无自动保存配置功能,请确保修改的文件被持久化保存,否则配置项无法生效 - -### 启动 ConfigNode 节点 - -进入iotdb的sbin目录下,启动confignode - -```shell -./start-confignode.sh -d #“-d”参数将在后台进行启动 -``` -如果启动失败,请参考[常见问题](#常见问题)。 - -### 激活数据库 - -#### 方式一:激活文件拷贝激活 - -- 启动confignode节点后,进入activation文件夹, 将 system_info文件复制给天谋工作人员 -- 收到工作人员返回的 license文件 -- 将license文件放入对应节点的activation文件夹下; - -#### 方式二:激活脚本激活 - -- 获取激活所需机器码,进入安装目录的sbin目录,执行激活脚本: - -```shell - cd sbin -./start-activate.sh -``` - -- 显示如下信息,请将机器码(即该串字符)复制给天谋工作人员: - -```shell -Please copy the system_info's content and send it to Timecho: -Y17hFA0xRCE1TmkVxILuCIEPc7uJcr5bzlXWiptw8uZTmTX5aThfypQdLUIhMljw075hNRSicyvyJR9JM7QaNm1gcFZPHVRWVXIiY5IlZkXdxCVc1erXMsbCqUYsR2R2Mw4PSpFJsUF5jHWSoFIIjQ2bmJFW5P52KCccFMVeHTc= -Please enter license: -``` - -- 将工作人员返回的激活码输入上一步的命令行提示处 `Please enter license:`,如下提示: - -```shell -Please enter license: -Jw+MmF+AtexsfgNGOFgTm83BgXbq0zT1+fOfPvQsLlj6ZsooHFU6HycUSEGC78eT1g67KPvkcLCUIsz2QpbyVmPLr9x1+kVjBubZPYlVpsGYLqLFc8kgpb5vIrPLd3hGLbJ5Ks8fV1WOVrDDVQq89YF2atQa2EaB9EAeTWd0bRMZ+s9ffjc/1Zmh9NSP/T3VCfJcJQyi7YpXWy5nMtcW0gSV+S6fS5r7a96PjbtE0zXNjnEhqgRzdU+mfO8gVuUNaIy9l375cp1GLpeCh6m6pF+APW1CiXLTSijK9Qh3nsL5bAOXNeob5l+HO5fEMgzrW8OJPh26Vl6ljKUpCvpTiw== -License has been stored to sbin/../activation/license -Import completed. Please start cluster and excute 'show cluster' to verify activation status -``` - -### 启动DataNode 节点 - -进入iotdb的sbin目录下,启动datanode: - -```shell -cd sbin -./start-datanode.sh -d #-d参数将在后台进行启动 -``` - -### 验证部署 - -可直接执行 ./sbin 目录下的 Cli 启动脚本: - -```shell -./start-cli.sh -h ip(本机ip或域名) -p 端口号(6667) -``` - -成功启动后,出现如下界面显示IOTDB安装成功。 - -![](/img/%E5%90%AF%E5%8A%A8%E6%88%90%E5%8A%9F.png) - -出现安装成功界面后,继续看下是否激活成功,使用`show cluster`命令 - -当看到最右侧显示ACTIVATED表示激活成功 - -![](/img/show%20cluster.png) - -> 出现`ACTIVATED(W)`为被动激活,表示此ConfigNode没有license文件(或没有签发时间戳最新的license文件)。此时建议检查license文件是否已放入license文件夹,没有请放入license文件,若已存在license文件,可能是此节点license文件与其他节点信息不一致导致,请联系天谋工作人员重新申请. - -## 常见问题 - -1. 部署过程中多次提示激活失败 - - 使用 `ls -al` 命令:使用 `ls -al` 命令检查安装包根目录的所有者信息是否为当前用户。 - - 检查激活目录:检查 `./activation` 目录下的所有文件,所有者信息是否为当前用户。 - -2. Confignode节点启动失败 - - 步骤 1: 请查看启动日志,检查是否修改了某些首次启动后不可改的参数。 - - 步骤 2: 请查看启动日志,检查是否出现其他异常。日志中若存在异常现象,请联系天谋技术支持人员咨询解决方案。 - - 步骤 3: 如果是首次部署或者数据可删除,也可按下述步骤清理环境,重新部署后,再次启动。 - - 步骤 4: 清理环境: - - a. 结束所有 ConfigNode 和 DataNode 进程。 - - ```Bash - # 1. 停止 ConfigNode 和 DataNode 服务 - sbin/stop-standalone.sh - - # 2. 检查是否还有进程残留 - jps - # 或者 - ps -ef|gerp iotdb - - # 3. 如果有进程残留,则手动kill - kill -9 - # 如果确定机器上仅有1个iotdb,可以使用下面命令清理残留进程 - ps -ef|grep iotdb|grep -v grep|tr -s ' ' ' ' |cut -d ' ' -f2|xargs kill -9 - ``` - b. 删除 data 和 logs 目录。 - - 说明:删除 data 目录是必要的,删除 logs 目录是为了纯净日志,非必需。 - ```Bash - cd /data/iotdb - rm -rf data logs - ``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/workbench-deployment_timecho.md b/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/workbench-deployment_timecho.md deleted file mode 100644 index 50d85992d..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/workbench-deployment_timecho.md +++ /dev/null @@ -1,248 +0,0 @@ - -# 可视化控制台部署 - -可视化控制台是IoTDB配套工具之一(类似 Navicat for MySQL)。它用于数据库部署实施、运维管理、应用开发各阶段的官方应用工具体系,让数据库的使用、运维和管理更加简单、高效,真正实现数据库低成本的管理和运维。本文档将帮助您安装Workbench。 -
-  -  -
- -## 安装准备 - -| 准备内容 | 名称 | 版本要求 | 官方链接 | -| :------: | :-----------------------: | :----------------------------------------------------------: | :----------------------------------------------------: | -| 操作系统 | Windows或Linux | - | - | -| 安装环境 | JDK | 需要 >= V1.8.0_162(推荐使用 11 或者 17,下载时请根据机器配置选择ARM或x64安装包) | https://www.oracle.com/java/technologies/downloads/ | -| 相关软件 | Prometheus | 需要 >=V2.30.3 | https://prometheus.io/download/ | -| 数据库 | IoTDB | 需要>=V1.2.0企业版 | 您可联系商务或技术支持获取 | -| 控制台 | IoTDB-Workbench-``| - | 您可根据附录版本对照表进行选择后联系商务或技术支持获取 | - -## 安装步骤 - -### 步骤一:IoTDB 开启监控指标采集 - -1. 打开监控配置项。IoTDB中监控有关的配置项默认是关闭的,在部署监控面板前,您需要打开相关配置项(注意开启监控配置后需要重启服务)。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
配置项所在配置文件配置说明
cn_metric_reporter_listconf/iotdb-confignode.properties将配置项取消注释,值设置为PROMETHEUS
cn_metric_level将配置项取消注释,值设置为IMPORTANT
cn_metric_prometheus_reporter_port将配置项取消注释,可保持默认设置9091,如设置其他端口,不与其他端口冲突即可
dn_metric_reporter_listconf/iotdb-datanode.properties将配置项取消注释,值设置为PROMETHEUS
dn_metric_level将配置项取消注释,值设置为IMPORTANT
dn_metric_prometheus_reporter_port将配置项取消注释,可保持默认设置9092,如设置其他端口,不与其他端口冲突即可
dn_metric_internal_reporter_type将配置项取消注释,值设置为IOTDB
enable_audit_logconf/iotdb-common.properties将配置项取消注释,值设置为true
audit_log_storage将配置项取消注释
audit_log_operation将配置项取消注释
- -2. 重启所有节点。修改3个节点的监控指标配置后,可重新启动所有节点的confignode和datanode服务: - - ```shell - ./sbin/stop-standalone.sh #先停止confignode和datanode - ./sbin/start-confignode.sh -d #启动confignode - ./sbin/start-datanode.sh -d #启动datanode - ``` - -3. 重启后,通过客户端确认各节点的运行状态,若状态都为Running,则为配置成功: - - ![](/img/%E5%90%AF%E5%8A%A8.png) - -### 步骤二:安装、配置Prometheus监控 - -1. 确保Prometheus安装完成(官方安装说明可参考:https://prometheus.io/docs/introduction/first_steps/) -2. 解压安装包,进入解压后的文件夹: - - ```Shell - tar xvfz prometheus-*.tar.gz - cd prometheus-* - ``` - -3. 修改配置。修改配置文件prometheus.yml如下 - 1. 新增confignode任务收集ConfigNode的监控数据 - 2. 新增datanode任务收集DataNode的监控数据 - - ```shell - global: - scrape_interval: 15s - evaluation_interval: 15s - scrape_configs: - - job_name: "prometheus" - static_configs: - - targets: ["localhost:9090"] - - job_name: "confignode" - static_configs: - - targets: ["iotdb-1:9091","iotdb-2:9091","iotdb-3:9091"] - honor_labels: true - - job_name: "datanode" - static_configs: - - targets: ["iotdb-1:9092","iotdb-2:9092","iotdb-3:9092"] - honor_labels: true - ``` - -4. 启动Prometheus。Prometheus 监控数据的默认过期时间为15天,在生产环境中,建议将其调整为180天以上,以对更长时间的历史监控数据进行追踪,启动命令如下所示: - - ```Shell - ./prometheus --config.file=prometheus.yml --storage.tsdb.retention.time=180d - ``` - -5. 确认启动成功。在浏览器中输入 `http://IP:port`,进入Prometheus,点击进入Status下的Target界面,当看到State均为Up时表示配置成功并已经联通。 - -
- - -
- -### 步骤三:安装Workbench - -#### Windows版: - -1. 进入iotdb-Workbench-``的config目录 - -2. 修改Workbench配置文件:进入`config`文件夹下修改配置文件`application-prod.properties`。若您是在本机安装则无需修改,若是部署在服务器上则需修改IP地址 - > Workbench可以部署在本地或者云服务器,只要能与 IoTDB 连接即可 - - | 配置项 | 修改前 | 修改后 | - | ---------------- | --------------------------------- | -------------------------------------- | - | pipe.callbackUrl | pipe.callbackUrl=`http://127.0.0.1` | pipe.callbackUrl=`http://<部署Workbench的IP地址>` | - - ![](/img/workbench-conf-1.png) - -3. 启动程序:请在IoTDB-Workbench-``的sbin文件夹下执行启动命令 - - ```shell - # 后台启动Workbench - start.bat -d - ``` - -4. 可以通过`jps`命令进行启动是否成功,如图所示即为启动成功: - - ![](/img/windows-jps.png) - -5. 验证是否成功:浏览器中打开:"http://服务器ip:配置文件中端口"进行访问,例如:"http://127.0.0.1:9190",当出现登录界面时即为成功 - - ![](/img/workbench.png) - -#### Linux版: - -1. 进入IoTDB-Workbench-``目录 - -2. 修改Workbench配置:进入`config`文件夹下修改配置文件`application-prod.properties`。若您是在本机安装则无需修改,若是部署在服务器上则需修改IP地址 - > Workbench可以部署在本地或者云服务器,只要能与 IoTDB 连接即可 - - | 配置项 | 修改前 | 修改后 | - | ---------------- | --------------------------------- | -------------------------------------- | - | pipe.callbackUrl | pipe.callbackUrl=`http://127.0.0.1` | pipe.callbackUrl=`http://<部署Workbench的IP地址>` | - - ![](/img/workbench-conf-1.png) - -3. 启动程序:请在IoTDB-Workbench-``的sbin文件夹下执行启动命令 - - ```shell - # 后台启动Workbench - ./start.sh -d - ``` - -4. 可以通过`jps`命令进行启动是否成功,如图所示即为启动成功: - - ![](/img/linux-jps.png) - -5. 验证是否成功:浏览器中打开 "`http://服务器ip:配置文件中端口`"进行访问,例如:"`http://127.0.0.1:9190`",当出现登录界面时即为成功 - - ![](/img/workbench.png) - -### 步骤四:配置实例信息 - -1. 配置实例信息:您只需要填写以下信息即可连接到实例 - - ![](/img/%E5%AE%9E%E4%BE%8B%E4%BF%A1%E6%81%AF.png) - - | 字段名称 | 是否为必填项 | 字段含义 | 默认值 | - | :---------------: | :------------: | :------------------------------------------------------------: | :------: | - | 连接类型 | 是 | 不同连接类型连接所填内容不同,支持选择“单机、集群、双活” | - | - | 实例名称 | 是 | 您可根据名称对不同实例进行区分,最多输入 50 个字符 | - | - | 实例信息 | 是 | 填写数据库的地址(iotdb/conf/iotdb-datanode.properties 文件中 dn_rpc_address 字段)以及端口号(dn_rpc_port字段)注:对于集群和双活点击“+”支持输入多个实例信息 | - | - | Prometheus 信息 | 否 | 填写“http://:/api/v1/query”即可通过首页查看部分监控信息,推荐您进行配置使用 | - | - | 用户名 | 是 | 填写IoTDB的用户名,支持输入 4~32 个字符,可使用英文大小写字母、数字、特殊字符(!@#$%^&*()_+-=) | root | - | 密码 | 否 | 填写IoTDB的密码,为了保证数据库的安全我们不会对密码进行保存,请您在每次连接实例或测试时自行填写 | root | - -2. 测试所填信息的准确性:您可以通过点击“测试”按钮对实例信息进行连接测试 - - ![](/img/%E5%AE%9E%E4%BE%8B%E4%BF%A1%E6%81%AF-%E6%B5%8B%E8%AF%95.png) - - -## 附录:IoTDB与控制台版本对照表 - -| 控制台版本号 | 版本说明 | 可支持IoTDB版本 | -| :------------: | :------------------------------------------------------------: | :----------------: | -| V1.5.1 | 新增AI分析功能以及模式匹配功能 | V1.3.2及以上版本 | -| V1.4.0 | 新增树模型展示及国际化 | V1.3.2及以上版本 | -| V1.3.1 | 分析功能新增分析方式,优化导入模版等功能 | V1.3.2及以上版本 | -| V1.3.0 | 新增数据库配置功能,优化部分版本细节 | V1.3.2及以上版本 | -| V1.2.6 | 优化各模块权限控制功能 | V1.3.1及以上版本 | -| V1.2.5 | 可视化功能新增“常用模版”概念,所有界面优化补充页面缓存等功能 | V1.3.0及以上版本 | -| V1.2.4 | 计算功能新增“导入、导出”功能,测点列表新增“时间对齐”字段 | V1.2.2及以上版本 | -| V1.2.3 | 首页新增“激活详情”,新增分析等功能 | V1.2.2及以上版本 | -| V1.2.2 | 优化“测点描述”展示内容等功能 | V1.2.2及以上版本 | -| V1.2.1 | 数据同步界面新增“监控面板”,优化Prometheus提示信息 | V1.2.2及以上版本 | -| V1.2.0 | 全新Workbench版本升级 | V1.2.0及以上版本 | - diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/DataEase.md b/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/DataEase.md deleted file mode 100644 index 643db2ed9..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/DataEase.md +++ /dev/null @@ -1,229 +0,0 @@ - -# DataEase - -## 产品概述 - -1. DataEase 简介 - - DataEase 是一个开源的数据可视化与分析工具,提供拖拽式的界面,使得用户能够轻松创建图表和仪表板,已支持 MySQL、SQL Server、Hive、ClickHouse、达梦等多种数据源,并且可以集成到其他应用程序中。能帮助用户快速洞察数据,做出决策。更多介绍详情请参考[DataEase 官网](https://www.fit2cloud.com/dataease/index.html) - -
- - -
- -2. DataEase-IoTDB 连接器介绍 - - IoTDB 可以通过API数据源的形式与DataEase实现高效集成,利用API数据源插件通过Session接口访问IoTDB数据。该插件支持定制化的数据处理功能,为用户提供了更大的灵活性和更多样化的数据操作选项。 -
- -
- -## 安装要求 - -| **准备内容** | **版本要求** | -| :-------------------- | :----------------------------------------------------------- | -| IoTDB | 版本无要求,安装请参考 IoTDB [部署指导](https://www.timecho.com/docs/zh/UserGuide/latest/Deployment-and-Maintenance/IoTDB-Package_timecho.html) | -| JDK | 建议 JDK11 及以上版本(推荐部署 JDK17 及以上版本) | -| DataEase | 要求 v1 系列 v1.18 版本,安装请参考 DataEase 官网[安装指导](https://dataease.io/docs/v2/installation/offline_INSTL_and_UPG/)(暂不支持 v2.x,其他版本适配请联系天谋商务) | -| DataEase-IoTDB 连接器 | 请联系天谋商务获取 | - -## 安装步骤 - -步骤一:请联系商务获取压缩包,解压缩安装包( iotdb-api-source-1.0.0.zip ) - -步骤二:解压后,修改`config`文件夹中的配置文件`application.properties` - -- 端口`server.port`可以按需进行修改 -- `iotdb.nodeUrls`需配置为待连接的 IoTDB 的实例的地址和端口 -- `iotdb.user`需配置为 IoTDB 的用户名 -- `iotdb.password`需配置为 IoTDB 的密码 - -```Properties -# 启动 IoTDB API Source 监听的端口 -server.port=8097 -# IoTDB 的实例地址,多个 nodeUrls 用 ; 分割 -iotdb.nodeUrls=127.0.0.1:6667 -# IoTDB 用户名 -iotdb.user=root -# IoTDB 密码 -iotdb.password=root -``` - -步骤三:启动 DataEase-IoTDB 连接器 - -- 前台启动 - -```Shell -./sbin/start.sh -``` - -- 后台启动(增加 -d 参数) - -```Shell -./sbin/start.sh -d -``` - -步骤四:启动后可以通过日志来查看是否启动成功。 - -```Shell - lsof -i:8097 // config 里启动 IoTDB API Source 监听的端口 -``` - -## 使用说明 - -### 登录 DataEase - -1. 登录 DataEase,访问地址 : `http://目标服务器IP地址:80` -
- -
- -### 配置数据源 - -1. 在导航条中跳转【数据源】界面 -
- -
- -2. 点击左上角 【 + 】,滑动到底部,选择【API】数据源 -
- -
- -3. 新建 API 数据源,自行设置基本信息中的【显示名称】,在数据表位置点击【添加】 -
- -
- -4. 在数据表名称字段中输入自定义的【名称】,请求类型选择 `Post`,地址填写 `http://[IoTDB API Source]:[port]/getData`,如果在本机操作且使用的是默认端口,地址应填写`http://127.0.0.1:8097/getData` -
- -
- -5. 在【请求参数】部分,选择【请求体】标签页,并确保格式设置为 JSON。请按照以下示例填写参数,其中: - timeseries:要查询的序列的完整路径(目前只支持查询一条序列) - limit:需要查询的条数(有效范围为 大于 0 且 小于 100000) - - ```JSON - { - "timeseries": "root.ln.wf03.wt03.speed", - "limit": 1000 - } - ``` -
- -
- -6. 点击【认证配置】标签页,选择【Basic Auth】作为认证方式,并准确输入 IoTDB 的用户名和密码 -
- -
- -7. 点击【下一步】,将在`data`部分看到接口返回结果。如下图展示接口中,返回了`time`、 `rownumber`和`value`信息,同时需要指定各字段数据类型。完成设置后,点击界面右下角的【保存】按钮。 -
- -
- -8. 保存后进入新建 API 数据源页面,点击右上角【保存】按钮。 -
- -
- -9. 保存数据源:保存后,可在 API 分类菜单下查看该数据源及其详细信息,或编辑该数据源。 -
- -
- -### 配置数据集 - -1. 创建 API 数据集:在导航条中跳转至数据集页面,点击页面左上角的 【 + 】 符号,选择【API 数据集】类型,选择此数据集所在的目录,即可进入新建 API 数据集页面。 -
- - -
- -2. 在新建 API 数据集页面,选择刚才新建的 API 数据源和包含在数据集中的对应数据表(下图左),并设置数据集名称(下图右)。设置完毕后,点击页面右上角的【保存】按钮以完成数据集的创建。 -
- - -
- -3. 选择刚刚创建的数据集,进入【字段管理】标签页,然后将所需的字段(如 rowNum)标记为维度。 -
- -
- -4. 配置更新频率:在【更新信息】页面上点击【添加任务】,设置以下信息: - - 任务名称:根据实际情况填写 - - 更新方式:选择【全量更新】 - - 执行频率:根据实际情况设置(考虑DataEase获取速度,建议设置为大于 5 秒更新一次),例如需要设置为每 5 秒更新,则可以选择【表达式设定】并在【cron 表达式】中设置为`0/5 * * * * ? *` - 配置完成后,点击页面右下角的【确认】按钮保存设置。 -
- -
- -5. 任务已成功添加。可以通过点击页面左上角的【执行记录】选项查看执行记录。 -
- -
- -### 配置仪表板 - -1. 在导航条中跳转至仪表板页面,可以点击【 + 】符号新建目录,并且在对应目录,点击【 + 】符号,然后从弹出的菜单中选择【新建仪表板】 -
- -
- -2. 按需进行设置后点击【确定】,以自定义设置为例,确定后进入新建仪表板页面 -
- -
- -3. 在新建仪表板页面,点击【视图】按钮以打开添加视图的弹窗。在弹窗中,选择之前创建的数据集,然后点击【下一步】继续操作。 -
- -
- -4. 在选择图表类型的步骤中,根据展示需求,选择一个合适的图表类型,如【基础折线图】。选择完毕后,点击【确认】按钮应用选择。 -
- -
- -5. 在图表配置界面,通过拖放操作将`rowNum`字段拖拽到类别轴(通常是 X 轴),将`value`字段拖拽到值轴(通常是 Y 轴)。 -
- -
- -6. 在图表的类别轴设置中,选择将排序方式设定为升序,这样数据将按照从小到大的顺序展示。设置数据刷新频率以确定图表更新的频率。完成这些设置后,您可以进一步调整图表的其他格式和样式选项,比如颜色、大小等,以满足展示需求。调整完后,点击页面右上角的【保存】按钮来保存图表配置。 ->由于 DataEase 在自动更新数据集后可能会导致原本按升序返回的 API 数据顺序错乱,所以需要在图表配置中手动指定排序方式。 -
- -
- -7. 退出编辑后查看效果 -
- -
\ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Grafana-Plugin.md b/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Grafana-Plugin.md deleted file mode 100644 index 9f598df8a..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Grafana-Plugin.md +++ /dev/null @@ -1,288 +0,0 @@ - - -# Grafana 插件 - -Grafana 是开源的指标量监测和可视化工具,可用于展示时序数据和应用程序运行分析。 - -在 IoTDB 项目中,我们开发了 Grafana 插件,该插件通过调用 IoTDB REST 服务来展现 IoTDB 中时序数据 ,提供了众多时序数据的可视化方法。Grafana 插件相较于 IoTDB-Grafana-Connector 连接器执行效率更高、支持的查询种类更多。只要在您部署环境允许的情况下,*我们都推荐直接使用 Grafana 插件而不使用 IoTDB-Grafana-Connector 连接器*。 - -## 部署 Grafana 插件 - -### 安装 Grafana - -* Grafana 组件下载地址:https://grafana.com/grafana/download -* 版本 >= 9.3.0 - -### grafana-plugin 获取 - -#### Grafana官方下载 apache-iotdb-datasource - -二进制文件下载地址:https://grafana.com/api/plugins/apache-iotdb-datasource/versions/1.0.0/download - -### grafana-plugin 插件安装 - -### 方式一 使用 grafana-cli 工具安装(推荐) - -* 使用 grafana-cli 工具从命令行安装 apache-iotdb-datasource,命令内容如下: - -```shell -grafana-cli plugins install apache-iotdb-datasource -``` - -### 方式二 使用Grafana 界面安装(推荐) - -从本地 Grafana 点击 Configuration -> Plugins -> 搜索 IoTDB 进行插件安装 - -### 方式三 手动安装grafana-plugin 插件(不推荐) - -* 拷贝上述生成的前端工程目标文件夹到 Grafana 的插件目录中 `${Grafana文件目录}\data\plugins\`。如果没有此目录可以手动建或者启动grafana会自动建立,当然也可以修改plugins的位置,具体请查看下面的修改Grafana 的插件目录位置说明。 - -* 启动Grafana服务,如果 Grafana 服务已启动,则需要停止Grafana服务,然后再启动Grafana。 - -更多有关Grafana详情,请点 [这里](https://grafana.com/docs/grafana/latest/plugins/installation/) - -### 启动 Grafana - -进入 Grafana 的安装目录,使用以下命令启动 Grafana: -* Windows 系统: - -```shell -bin\grafana-server.exe -``` -* Linux 系统: - -```shell -sudo service grafana-server start -``` -* MacOS 系统: - -```shell -brew services start grafana -``` -更多详情,请点 [这里](https://grafana.com/docs/grafana/latest/installation/) - - -### 配置 IoTDB REST 服务 - -进入 `{iotdb 目录}/conf`,打开 `iotdb-common.properties` 文件,并作如下修改: - -```properties -# Is the REST service enabled -enable_rest_service=true - -# the binding port of the REST service -rest_service_port=18080 -``` - -启动(重启)IoTDB 使配置生效,此时 IoTDB REST 服务处于运行状态。 - - - -## 使用 Grafana 插件 - -### 访问 Grafana dashboard - -Grafana 以网页的 dashboard 形式为您展示数据,在使用时请您打开浏览器,访问 `http://:`。 - -注:IP 为您的 Grafana 所在的服务器 IP,Port 为 Grafana 的运行端口(默认 3000)。 - -在本地试用时,Grafana dashboard 的默认地址为 `http://localhost:3000/`。 - -默认登录的用户名和密码都是 `admin`。 - - - -### 添加 IoTDB 数据源 - -点击左侧的 `设置` 图标,选择 `Data Source` 选项,然后再点击 `Add data source`。 - - - - - -选择 `Apache IoTDB` 数据源,`URL` 一栏填写 `http://:`。 - -Ip 为您的 IoTDB 服务器所在的宿主机 IP,port 为 REST 服务的运行端口(默认 18080)。 - -输入 IoTDB 服务器的 username 和 password,点击 `Save & Test`,出现 `Data source is working` 则提示配置成功。 - - - - - -### 创建一个新的 Panel - -点击左侧的 `Dashboards` 图标,选择 `Manage`,如下图所示: - - - -点击右上方的 `New Dashboard` 图标,选择 `Add an empty panel`,如下图所示: - - - -Grafana Plugin 支持SQL: Full Customized和SQL: Drop-down List 两种方式,默认是SQL: Full Customized方式。 - - - -#### SQL: Full Customized 输入方式 - -在 SELECT 输入框、FROM 输入框、WHERE输入框、CONTROL输入框中输入内容,其中 WHERE 和 CONTROL 输入框为非必填。 - -如果一个查询涉及多个表达式,我们可以点击 SELECT 输入框右侧的 `+` 来添加 SELECT 子句中的表达式,也可以点击 FROM 输入框右侧的 `+` 来添加路径前缀,如下图所示: - - - -SELECT 输入框中的内容可以是时间序列的后缀,可以是函数或自定义函数,可以是算数表达式,也可以是它们的嵌套表达式。您还可以使用 as 子句来重命名需要显示的结果序列名字。 - -下面是 SELECT 输入框中一些合法的输入举例: - -* `s1` -* `top_k(s1, 'k'='1') as top` -* `sin(s1) + cos(s1 + s2)` -* `udf(s1) as "中文别名"` - -FROM 输入框中的内容必须是时间序列的前缀路径,比如 `root.sg.d`。 - -WHERE 输入框为非必须填写项目,填写内容应当是查询的过滤条件,比如 `time > 0` 或者 `s1 < 1024 and s2 > 1024`。 - -CONTROL 输入框为非必须填写项目,填写内容应当是控制查询类型、输出格式的特殊子句。其中GROUP BY 输入框支持使用grafana的全局变量来获取当前时间区间变化`$__from`(起始时间)、`$__to`(结束时间),下面是 CONTROL 输入框中一些合法的输入举例: - -* `GROUP BY ([$__from, $__to), 1d)` -* `GROUP BY ([$__from, $__to),3h,1d)` -* `GROUP BY ([2017-11-01T00:00:00, 2017-11-07T23:00:00), 1d)` -* `GROUP BY ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d)` -* `GROUP BY ([$__from, $__to), 1m) FILL (PREVIOUSUNTILLAST)` -* `GROUP BY ([2017-11-07T23:50:00, 2017-11-07T23:59:00), 1m) FILL (PREVIOUSUNTILLAST)` -* `GROUP BY ([2017-11-07T23:50:00, 2017-11-07T23:59:00), 1m) FILL (PREVIOUS, 1m)` -* `GROUP BY ([2017-11-07T23:50:00, 2017-11-07T23:59:00), 1m) FILL (LINEAR, 5m, 5m)` -* `GROUP BY ((2017-11-01T00:00:00, 2017-11-07T23:00:00], 1d), LEVEL=1` -* `GROUP BY ([0, 20), 2ms, 3ms), LEVEL=1` - -提示:为了避免OOM问题,不推荐使用select * from root.xx.** 这种语句在Grafana plugin中使用。 - -#### SQL: Drop-down List 输入方式 -在 TIME-SERIES 选择框中选择一条时间序列、FUNCTION 选择一个函数、SAMPLING INTERVAL、SLIDING STEP、LEVEL、FILL 输入框中输入内容,其中 TIME-SERIESL 为必填项其余为非必填项。 - - - -### 变量与模板功能的支持 - -SQL: Full Customized和SQL: Drop-down List两种输入方式都支持 Grafana 的变量与模板功能,下面示例中使用SQL: Full Customized输入方式,SQL: Drop-down List与之类似。 - -创建一个新的 Panel 后,点击右上角的设置按钮,如下图所示: - - - -选择 `Variables`,点击 `Add variable` ,如下图所示: - - - -示例一:输入 `Name`,`Label`,选择Type的`Query`、在Query 中输入show child paths xx , 点击 `Update` 按钮,如下图所示: - - - -应用 Variables,在 `grafana panel` 中输入变量点击 `save` 按钮,如下图所示 - - - -示例二:变量嵌套使用,如下图所示 - - - - - - - -示例三:函数变量使用,如下图所示 - - - - -上图中Name 是变量名称也是将来我们在panel中使用的变量名称,Label是变量的展示名称如果为空就显示Name的变量反之则显示Label的名称, -Type下拉中有Query、Custom、Text box、Constant、DataSource、Interval、Ad hoc filters等这些都可以在IoTDB的Grafana Plugin 中使用 -更加详细介绍用法请查看官方手册(https://grafana.com/docs/grafana/latest/variables/) - -除了上面的示例外,还支持下面这些语句: -* `show databases` -* `show timeseries` -* `show child nodes` -* `show all ttl` -* `show latest timeseries` -* `show devices` -* `select xx from root.xxx limit xx 等sql 查询` - -* 提示:如果查询的字段中有布尔类型的数据,会将true转化成1,false转化成0结果值进行显示。 - -### 告警功能 -本插件支持 Grafana alert功能。在Grafana 9告警界面一共有6个Tab,分别是Alert rules、Contact points、Notification policies、Silences、Alert groups、Admin - -* `Alert rules` 告警规则列表,用于展示和配置告警规则 -* `Contact points` 为通知渠道,包括DingDing、Email、Slack、WebHook、Prometheus Alertmanager等 -* `Notification policies` 配置告警发送到哪个通道的路由,以及发送通知的时间和重复频率,静默配置 -* `Silences` 为配置告警静默时间段 -* `Alert groups` 告警组,配置的告警触发后会在这里显示 -* `Admin` 提供通过JSON方式修改告警配置 - -1. 在Grafana panel中,点击alerting按钮,如下图所示: - - - -2. 点击`Create alert rule from this panel`,如下图所示: - - - -3. 在第1步中设置查询和警报条件,Conditions 表示查询条件,可以配置多个组合查询条件。如下图所示: - - - -图中的查询条件:min() OF A IS BELOW 0,表示将A选项卡中的最小值在0一下就会触发条件,单击该函数可将其更改为另一个函数。 - -提示:警报规则中使用的查询不能包含任何模板变量。目前我们只支持条件之间的AND和OR运算符,它们是串行执行的。 -例如,我们按以下顺序有 3 个条件: 条件:B(计算为:TRUE)或条件:C(计算为:FALSE)和条件:D(计算为:TRUE) 所以结果将计算为((对或错)和对)=对。 - -4. 选择完指标及告警规则后点击`Preview`按钮,进行数据预览如下图所示: - - -5. 在第 2 步中,指定警报评估间隔,对于`Evaluate every`,指定评估频率。必须是 10 秒的倍数。例如,1m,30s。 -对于`Evaluate for`,指定在警报触发之前的持续时间。如下图所示: - - -6. 在第 3 步中,添加存储位置、规则组以及与规则关联的其他元数据。 其中`Rule name`指定规则的名称。规则名称必须是唯一的。 - - -7. 在第 4 步中,添加自定义标签。 从下拉列表中选择现有键值对添加自定义标签,或通过输入新键或值来添加新标签。如下图所示: - - - -8. 单击保存以保存规则或单击保存并退出以保存规则并返回到警报页面。 -9. 告警状态常用的有`Normal`、`Pending`、`Firing`等状态,如下图所示: - - - -10. 我们也可以为告警配置`Contact points`用来接收告警通知,更加详细操作可以参考官方文档(https://grafana.com/docs/grafana/latest/alerting/manage-notifications/create-contact-point/)。 - -想了解alert更多详细的操作可以查看官方文档https://grafana.com/docs/grafana/latest/alerting/ - -## 更多 - -更多关于 Grafana 操作详情可参看 Grafana 官方文档:http://docs.grafana.org/guides/getting_started/。 - diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md b/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md deleted file mode 100644 index b2404a38f..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md +++ /dev/null @@ -1,274 +0,0 @@ - -# Ignition - -## 产品概述 - -1. Ignition简介 - - Ignition 是一个基于WEB的监控和数据采集工具(SCADA)- 一个开放且可扩展的通用平台。Ignition可以让你更轻松地控制、跟踪、显示和分析企业的所有数据,提升业务能力。更多介绍详情请参考[Ignition官网](https://docs.inductiveautomation.com/docs/8.1/getting-started/introducing-ignition) - -2. Ignition-IoTDB Connector介绍 - - Ignition-IoTDB Connector分为两个模块:Ignition-IoTDB连接器、Ignition-IoTDB With JDBC。其中: - - - Ignition-IoTDB 连接器:提供了将 Ignition 采集到的数据存入 IoTDB 的能力,也支持在Components中进行数据读取,同时注入了 `system.iotdb.insert`和`system.iotdb.query`脚本接口用于方便在Ignition编程使用 - - Ignition-IoTDB With JDBC:Ignition-IoTDB With JDBC 可以在 `Transaction Groups` 模块中使用,不适用于 `Tag Historian`模块,可以用于自定义写入和查询。 - - 两个模块与Ignition的具体关系与内容如下图所示。 - - ![](/img/Ignition.png) - -## 安装要求 - -| **准备内容** | **版本要求** | -| :------------------------: | :------------------------------------------------------------: | -| IoTDB | 要求已安装V1.3.1及以上版本,安装请参考 IoTDB [部署指导](../Deployment-and-Maintenance/IoTDB-Package_timecho.md) | -| Ignition | 要求已安装 8.1.x版本(8.1.37及以上)的 8.1 版本,安装请参考 Ignition 官网[安装指导](https://docs.inductiveautomation.com/docs/8.1/getting-started/installing-and-upgrading)(其他版本适配请联系商务了解) | -| Ignition-IoTDB连接器模块 | 请联系商务获取 | -| Ignition-IoTDB With JDBC模块 | 下载地址:https://repo1.maven.org/maven2/org/apache/iotdb/iotdb-jdbc/ | - -## Ignition-IoTDB连接器使用说明 - -### 简介 - -Ignition-IoTDB连接器模块可以将数据存入与历史数据库提供程序关联的数据库连接中。数据根据其数据类型直接存储到 SQL 数据库中的表中,以及毫秒时间戳。根据每个标签上的值模式和死区设置,仅在更改时存储数据,从而避免重复和不必要的数据存储。 - -Ignition-IoTDB连接器提供了将 Ignition 采集到的数据存入 IoTDB 的能力。 - -### 安装步骤 - -步骤一:进入 `Config` - `System`- `Modules` 模块,点击最下方的`Install or Upgrade a Module...` - -![](/img/Ignition-IoTDB%E8%BF%9E%E6%8E%A5%E5%99%A8-1.png) - -步骤二:选择获取到的 `modl`,选择文件并上传,点击 `Install`,信任相关证书。 - -![](/img/ignition-3.png) - -步骤三:安装完成后可以看到如下内容 - -![](/img/Ignition-IoTDB%E8%BF%9E%E6%8E%A5%E5%99%A8-3.png) - -步骤四:进入 `Config` - `Tags`- `History` 模块,点击下方的`Create new Historical Tag Provider...` - -![](/img/Ignition-IoTDB%E8%BF%9E%E6%8E%A5%E5%99%A8-4.png) - -步骤五:选择 `IoTDB`并填写配置信息 - -![](/img/Ignition-IoTDB%E8%BF%9E%E6%8E%A5%E5%99%A8-5.png) - -配置内容如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
名称含义默认值备注
Main
Provider NameProvider 名称-
Enabled true为 true 时才能使用该 Provider
Description备注-
IoTDB Settings
Host Name目标IoTDB实例的地址-
Port Number目标IoTDB实例的端口6667
Username目标IoTDB的用户名-
Password目标IoTDB的密码-
Database Name要存储的数据库名称,以 root 开头,如 root.db-
Pool SizeSessionPool 的 Size50可以按需进行配置
Store and Forward Settings保持默认即可
- - -### 使用说明 - -#### 配置历史数据存储 - -- 配置好 `Provider` 后就可以在 `Designer` 中使用 `IoTDB Tag Historian` 了,就跟使用其他的 `Provider` 一样,右键点击对应 `Tag` 选择 `Edit tag(s)`,在 Tag Editor 中选择 History 分类 - - ![](/img/ignition-7.png) - -- 设置 `History Enabled` 为 `true`,并选择 `Storage Provider` 为上一步创建的 `Provider`,按需要配置其它参数,并点击 `OK`,然后保存项目。此时数据将会按照设置的内容持续的存入 `IoTDB` 实例中。 - - ![](/img/ignition-8.png) - -#### 读取数据 - -- 也可以在 Report 的 Data 标签下面直接选择存入 IoTDB 的 Tags - - ![](/img/ignition-9.png) - -- 在 Components 中也可以直接浏览相关数据 - - ![](/img/ignition-10.png) - -#### 脚本模块:该功能能够与 IoTDB 进行交互 - -1. system.iotdb.insert: - - -- 脚本说明:将数据写入到 IoTDB 实例中 - -- 脚本定义: - ``` shell - system.iotdb.insert(historian, deviceId, timestamps, measurementNames, measurementValues) - ``` - -- 参数: - - - `str historian`:对应的 IoTDB Tag Historian Provider 的名称 - - `str deviceId`:写入的 deviceId,不含配置的 database,如 Sine - - `long[] timestamps`:写入的数据点对于的时间戳列表 - - `str[] measurementNames`:写入的物理量的名称列表 - - `str[][] measurementValues`:写入的数据点数据,与时间戳列表和物理量名称列表对应 - -- 返回值:无 - -- 可用范围:Client, Designer, Gateway - -- 使用示例: - - ```shell - system.iotdb.insert("IoTDB", "Sine", [system.date.now()],["measure1","measure2"],[["val1","val2"]]) - ``` - -2. system.iotdb.query: - - -- 脚本说明:查询写到 IoTDB 实例中的数据 - -- 脚本定义: - ```shell - system.iotdb.query(historian, sql) - ``` - -- 参数: - - - `str historian`:对应的 IoTDB Tag Historian Provider 的名称 - - `str sql`:待查询的 sql 语句 - -- 返回值: - 查询的结果:`List>` - -- 可用范围:Client, Designer, Gateway -- 使用示例: - -```shell -system.iotdb.query("IoTDB", "select * from root.db.Sine where time > 1709563427247") -``` - -## Ignition-IoTDB With JDBC - -### 简介 - - Ignition-IoTDB With JDBC提供了一个 JDBC 驱动,允许用户使用标准的JDBC API 连接和查询 lgnition-loTDB 数据库 - -### 安装步骤 - - 步骤一:进入 `Config` - `Databases` -`Drivers` 模块,创建 `Translator` - -![](/img/Ignition-IoTDBWithJDBC-1.png) - - 步骤二:进入 `Config` - `Databases` -`Drivers` 模块,创建 `JDBC Driver`,选择上一步配置的 `Translator`并上传下载的 `IoTDB-JDBC`,Classname 配置为 `org.apache.iotdb.jdbc.IoTDBDriver` - -![](/img/Ignition-IoTDBWithJDBC-2.png) - -步骤三:进入 `Config` - `Databases` -`Connections` 模块,创建新的 `Connections`,`JDBC Driver` 选择上一步创建的 `IoTDB Driver`,配置相关信息后保存即可使用 - -![](/img/Ignition-IoTDBWithJDBC-3.png) - -### 使用说明 - -#### 数据写入 - - 在`Transaction Groups`中的 `Data Source`选择之前创建的 `Connection` - -- `Table name` 需设置为 root 开始的完整的设备路径 -- 取消勾选 `Automatically create table` -- `Store timestame to` 配置为 time - -不选择其他项,设置好字段,并 `Enabled` 后 数据会安装设置存入对应的 IoTDB - -![](/img/%E6%95%B0%E6%8D%AE%E5%86%99%E5%85%A5-1.png) - -#### 数据查询 - -- 在 `Database Query Browser` 中选择`Data Source`选择之前创建的 `Connection`,即可编写 SQL 语句查询 IoTDB 中的数据 - -![](/img/%E6%95%B0%E6%8D%AE%E6%9F%A5%E8%AF%A2-ponz.png) - diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Spark-IoTDB.md b/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Spark-IoTDB.md deleted file mode 100644 index 15312315a..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Spark-IoTDB.md +++ /dev/null @@ -1,229 +0,0 @@ - - -# Apache Spark(IoTDB) - -## 版本支持 - -支持的 Spark 与 Scala 版本如下: - -| Spark 版本 | Scala 版本 | -|----------------|--------------| -| `2.4.0-latest` | `2.11, 2.12` | - -## 注意事项 - -1. 当前版本的 `spark-iotdb-connector` 支持 `2.11` 与 `2.12` 两个版本的 Scala,暂不支持 `2.13` 版本。 -2. `spark-iotdb-connector` 支持在 Java、Scala 版本的 Spark 与 PySpark 中使用。 - -## 部署 - -`spark-iotdb-connector` 总共有两个使用场景,分别为 IDE 开发与 spark-shell 调试。 - -### IDE 开发 - -在 IDE 开发时,只需要在 `pom.xml` 文件中添加以下依赖即可: - -``` xml - - org.apache.iotdb - - spark-iotdb-connector_2.12.10 - ${iotdb.version} - -``` - -### `spark-shell` 调试 - -如果需要在 `spark-shell` 中使用 `spark-iotdb-connetcor`,需要先在官网下载 `with-dependencies` 版本的 jar 包。然后再将 jar 包拷贝到 `${SPARK_HOME}/jars` 目录中即可。 -执行以下命令即可: - -```shell -cp spark-iotdb-connector_2.12.10-${iotdb.version}.jar $SPARK_HOME/jars/ -``` - -此外,为了保证 spark 能使用 JDBC 和 IoTDB 连接,需要进行如下操作: - -运行如下命令来编译 IoTDB-JDBC 连接器: - -```shell -mvn clean package -pl iotdb-client/jdbc -am -DskipTests -P get-jar-with-dependencies -``` - -编译后的 jar 包在如下目录中: - -```shell -$IoTDB_HOME/iotdb-client/jdbc/target/iotdb-jdbc-{version}-SNAPSHOT-jar-with-dependencies.jar -``` - -最后再将 jar 包拷贝到 `${SPARK_HOME}/jars` 目录中即可。执行以下命令即可: - -```shell -cp iotdb-jdbc-{version}-SNAPSHOT-jar-with-dependencies.jar $SPARK_HOME/jars/ -``` - -## 使用 - -### 参数 - -| 参数 | 描述 | 默认值 | 使用范围 | 能否为空 | -|--------------|------------------------------------------------|------|------------|-------| -| url | 指定 IoTDB 的 JDBC 的 URL | null | read、write | false | -| user | IoTDB 的用户名 | root | read、write | true | -| password | IoTDB 的密码 | root | read、write | true | -| sql | 用于指定查询的 SQL 语句 | null | read | true | -| numPartition | 在 read 中用于指定 DataFrame 的分区数,在 write 中用于设置写入并发数 | 1 | read、write | true | -| lowerBound | 查询的起始时间戳(包含) | 0 | read | true | -| upperBound | 查询的结束时间戳(包含) | 0 | read | true | - -### 从 IoTDB 读取数据 - -以下是一个示例,演示如何从 IoTDB 中读取数据成为 DataFrame。 - -```scala -import org.apache.iotdb.spark.db._ - -val df = spark.read.format("org.apache.iotdb.spark.db") - .option("user", "root") - .option("password", "root") - .option("url", "jdbc:iotdb://127.0.0.1:6667/") - .option("sql", "select ** from root") // 查询 SQL - .option("lowerBound", "0") // 时间戳下界 - .option("upperBound", "100000000") // 时间戳上界 - .option("numPartition", "5") // 分区数 - .load - -df.printSchema() - -df.show() -``` - -### 将数据写入 IoTDB - -以下是一个示例,演示如何将数据写入 IoTDB。 - -```scala -// 构造窄表数据 -val df = spark.createDataFrame(List( - (1L, "root.test.d0", 1, 1L, 1.0F, 1.0D, true, "hello"), - (2L, "root.test.d0", 2, 2L, 2.0F, 2.0D, false, "world"))) - -val dfWithColumn = df.withColumnRenamed("_1", "Time") - .withColumnRenamed("_2", "Device") - .withColumnRenamed("_3", "s0") - .withColumnRenamed("_4", "s1") - .withColumnRenamed("_5", "s2") - .withColumnRenamed("_6", "s3") - .withColumnRenamed("_7", "s4") - .withColumnRenamed("_8", "s5") - -// 写入窄表数据 -dfWithColumn - .write - .format("org.apache.iotdb.spark.db") - .option("url", "jdbc:iotdb://127.0.0.1:6667/") - .save - -// 构造宽表数据 -val df = spark.createDataFrame(List( - (1L, 1, 1L, 1.0F, 1.0D, true, "hello"), - (2L, 2, 2L, 2.0F, 2.0D, false, "world"))) - -val dfWithColumn = df.withColumnRenamed("_1", "Time") - .withColumnRenamed("_2", "root.test.d0.s0") - .withColumnRenamed("_3", "root.test.d0.s1") - .withColumnRenamed("_4", "root.test.d0.s2") - .withColumnRenamed("_5", "root.test.d0.s3") - .withColumnRenamed("_6", "root.test.d0.s4") - .withColumnRenamed("_7", "root.test.d0.s5") - -// 写入宽表数据 -dfWithColumn.write.format("org.apache.iotdb.spark.db") - .option("url", "jdbc:iotdb://127.0.0.1:6667/") - .option("numPartition", "10") - .save -``` - -### 宽表与窄表转换 - -以下是如何转换宽表与窄表的示例: - -* 从宽到窄 - -```scala -import org.apache.iotdb.spark.db._ - -val wide_df = spark.read.format("org.apache.iotdb.spark.db").option("url", "jdbc:iotdb://127.0.0.1:6667/").option("sql", "select * from root.** where time < 1100 and time > 1000").load -val narrow_df = Transformer.toNarrowForm(spark, wide_df) -``` - -* 从窄到宽 - -```scala -import org.apache.iotdb.spark.db._ - -val wide_df = Transformer.toWideForm(spark, narrow_df) -``` - -## 宽表与窄表 - -以下 TsFile 结构为例:TsFile 模式中有三个度量:状态,温度和硬件。 这三种测量的基本信息如下: - -| 名称 | 类型 | 编码 | -|-----|---------|-------| -| 状态 | Boolean | PLAIN | -| 温度 | Float | RLE | -| 硬件 | Text | PLAIN | - -TsFile 中的现有数据如下: - -* `d1:root.ln.wf01.wt01` -* `d2:root.ln.wf02.wt02` - -| time | d1.status | time | d1.temperature | time | d2.hardware | time | d2.status | -|------|-----------|------|----------------|------|-------------|------|-----------| -| 1 | True | 1 | 2.2 | 2 | "aaa" | 1 | True | -| 3 | True | 2 | 2.2 | 4 | "bbb" | 2 | False | -| 5 | False | 3 | 2.1 | 6 | "ccc" | 4 | True | - -宽(默认)表形式如下: - -| Time | root.ln.wf02.wt02.temperature | root.ln.wf02.wt02.status | root.ln.wf02.wt02.hardware | root.ln.wf01.wt01.temperature | root.ln.wf01.wt01.status | root.ln.wf01.wt01.hardware | -|------|-------------------------------|--------------------------|----------------------------|-------------------------------|--------------------------|----------------------------| -| 1 | null | true | null | 2.2 | true | null | -| 2 | null | false | aaa | 2.2 | null | null | -| 3 | null | null | null | 2.1 | true | null | -| 4 | null | true | bbb | null | null | null | -| 5 | null | null | null | null | false | null | -| 6 | null | null | ccc | null | null | null | - -你还可以使用窄表形式,如下所示: - -| Time | Device | status | hardware | temperature | -|------|-------------------|--------|----------|-------------| -| 1 | root.ln.wf02.wt01 | true | null | 2.2 | -| 1 | root.ln.wf02.wt02 | true | null | null | -| 2 | root.ln.wf02.wt01 | null | null | 2.2 | -| 2 | root.ln.wf02.wt02 | false | aaa | null | -| 3 | root.ln.wf02.wt01 | true | null | 2.1 | -| 4 | root.ln.wf02.wt02 | true | bbb | null | -| 5 | root.ln.wf02.wt01 | false | null | null | -| 6 | root.ln.wf02.wt02 | null | ccc | null | diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Telegraf-IoTDB.md b/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Telegraf-IoTDB.md deleted file mode 100644 index e9c64c16a..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Telegraf-IoTDB.md +++ /dev/null @@ -1,110 +0,0 @@ - - -# Telegraf -Telegraf 是一个开源代理工具,用于收集、处理和传输度量数据,由 InfluxData 开发。 -Telegraf 有以下这些特点: -* 插件体系结构: Telegraf 的强大之处在于其广泛的插件生态系统。它支持多种输入、输出和处理器插件,可以与各种数据源和目标无缝集成。 -* 数据收集: Telegraf 擅长从不同来源收集度量数据,例如系统指标、日志、数据库等。其多功能性使其适用于监视应用程序、基础架构和物联网设备。 -* 输出目标: 一旦收集到数据,可以将其发送到各种输出目标,包括流行的数据库如 InfluxDB。这种灵活性使 Telegraf 适应不同的监视和分析设置。 -* 配置简易: Telegraf 的配置使用 TOML 文件进行。这种简单性使用户能够轻松定义输入、输出和处理器,使定制变得简单明了。 -* 社区与支持: 作为开源项目,Telegraf 受益于活跃的社区。用户可以通过论坛和文档贡献插件、报告问题并寻求帮助。 - -# Telegraf IoTDB 输出插件 -这个输出插件保存 Telegraf 中的监控信息到 Apache IoTDB 的后端,支持 session 连接和数据写入。 - -## 注意事项 -1. 在使用这个插件前,需要配置 IP 地址,端口号,用户名,密码以及其他数据库服务器的信息,另外还有数据转换,时间单位和其他配置。 -2. 输出到 IoTDB 的路径需要满足章节 ‘语法约定’ 中的要求 -3. 查看 https://github.com/influxdata/telegraf/tree/master/plugins/outputs/iotdb 了解如何配置 Telegraf IoTDB Output 插件. - -## 示例 -以下是一个使用 Telegraf 收集 CPU 数据输出到 IoTDB 的示例。 -1. 使用 telegraf 命令生成配置文件 -``` -telegraf --sample-config --input-filter cpu --output-filter iotdb > cpu_iotdb.conf -``` -2. 修改 input cpu 插件的配置 -``` -# Read metrics about cpu usage -[[inputs.cpu]] - ## Whether to report per-cpu stats or not - percpu = true - ## Whether to report total system cpu stats or not - totalcpu = true - ## If true, collect raw CPU time metrics - collect_cpu_time = false - ## If true, compute and report the sum of all non-idle CPU states - report_active = false - ## If true and the info is available then add core_id and physical_id tags - core_tags = false - name_override = "root.demo.telgraf.cpu" -``` -3. 修改 output iotdb 插件的配置 -``` -# Save metrics to an IoTDB Database -[[outputs.iotdb]] - ## Configuration of IoTDB server connection - host = "127.0.0.1" - # port = "6667" - - ## Configuration of authentication - # user = "root" - # password = "root" - - ## Timeout to open a new session. - ## A value of zero means no timeout. - # timeout = "5s" - - ## Configuration of type conversion for 64-bit unsigned int - ## IoTDB currently DOES NOT support unsigned integers (version 13.x). - ## 32-bit unsigned integers are safely converted into 64-bit signed integers by the plugin, - ## however, this is not true for 64-bit values in general as overflows may occur. - ## The following setting allows to specify the handling of 64-bit unsigned integers. - ## Available values are: - ## - "int64" -- convert to 64-bit signed integers and accept overflows - ## - "int64_clip" -- convert to 64-bit signed integers and clip the values on overflow to 9,223,372,036,854,775,807 - ## - "text" -- convert to the string representation of the value - # uint64_conversion = "int64_clip" - - ## Configuration of TimeStamp - ## TimeStamp is always saved in 64bits int. timestamp_precision specifies the unit of timestamp. - ## Available value: - ## "second", "millisecond", "microsecond", "nanosecond"(default) - timestamp_precision = "millisecond" - - ## Handling of tags - ## Tags are not fully supported by IoTDB. - ## A guide with suggestions on how to handle tags can be found here: - ## https://iotdb.apache.org/UserGuide/Master/API/InfluxDB-Protocol.html - ## - ## Available values are: - ## - "fields" -- convert tags to fields in the measurement - ## - "device_id" -- attach tags to the device ID - ## - ## For Example, a metric named "root.sg.device" with the tags `tag1: "private"` and `tag2: "working"` and - ## fields `s1: 100` and `s2: "hello"` will result in the following representations in IoTDB - ## - "fields" -- root.sg.device, s1=100, s2="hello", tag1="private", tag2="working" - ## - "device_id" -- root.sg.device.private.working, s1=100, s2="hello" - convert_tags_to = "fields" -``` -4. 使用这个配置文件运行 Telegraf,一段时间后,可以在 IoTDB 中查询到收集的这些数据 - diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Thingsboard.md b/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Thingsboard.md deleted file mode 100644 index 551179c6b..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Thingsboard.md +++ /dev/null @@ -1,99 +0,0 @@ - -# ThingsBoard - -## 产品概述 - -1. ThingsBoard 简介 - - ThingsBoard 是一个开源物联网平台,可实现物联网项目的快速开发、管理和扩展。更多介绍详情请参考[ ThingsBoard 官网](https://thingsboard.io/docs/getting-started-guides/what-is-thingsboard/)。 - - ![](/img/ThingsBoard-1.png) - -2. ThingsBoard-IoTDB 简介 - - ThingsBoard-IoTDB 提供了将 ThingsBoard 中的数据存储到 IoTDB 的能力,也支持在 ThingsBoard 中读取 root.thingsboard 数据库下的数据信息。详细架构图如下图黄色标识所示。 - -### 关系示意图 - -![](/img/Thingsboard-2.png) - -## 安装要求 - -| 准备内容 | 版本要求 | -| :-------------------------- | :----------------------------------------------------------- | -| JDK | 要求已安装 17 及以上版本,具体下载请查看 [Oracle 官网](https://www.oracle.com/java/technologies/downloads/) | -| IoTDB | 要求已安装 V1.3.0 及以上版本,具体安装过程请参考[部署指导](https://www.timecho.com/docs/zh/UserGuide/latest/Deployment-and-Maintenance/IoTDB-Package_timecho.html) | -| ThingsBoard(IoTDB 适配版) | 安装包请联系商务获取,具体安装步骤参见下文 | - -## 安装步骤 - -具体安装步骤请参考 [ThingsBoard 官网](https://thingsboard.io/docs/user-guide/install/ubuntu/)。其中: - -- [ThingsBoard 官网](https://thingsboard.io/docs/user-guide/install/ubuntu/)中【步骤 2 ThingsBoard 服务安装】使用上方从商务获取的安装包进行安装(使用 ThingsBoard 官方安装包无法使用 iotdb) -- [ThingsBoard 官网](https://thingsboard.io/docs/user-guide/install/ubuntu/)中【步骤 3 配置 ThingsBoard 数据库-ThingsBoard 配置】步骤中需要按照下方内容添加环境变量 - -```Bash -# ThingsBoard 原有配置 -export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard -export SPRING_DATASOURCE_USERNAME=postgres -export SPRING_DATASOURCE_PASSWORD=PUT_YOUR_POSTGRESQL_PASSWORD_HERE ##修改为pg的密码 - -# 使用IoTDB需修改以下变量 -export DATABASE_TS_TYPE=iotdb ## 原配置为sql,将变量值改为iotdb - - -# 使用IoTDB需增加以下变量 -export DATABASE_TS_LATEST_TYPE=iotdb -export IoTDB_HOST=127.0.0.1 ## iotdb所在的ip地址 -export IoTDB_PORT=6667 ## iotdb的端口号,默认为6667 -export IoTDB_USER=root ## iotdb的用户名,默认为root -export IoTDB_PASSWORD=root ## iotdb的密码,默认为root -export IoTDB_CONNECTION_TIMEOUT=5000 ## iotdb超时时间设置 -export IoTDB_FETCH_SIZE=1024 ## 单次请求所拉取的数据条数,推荐设置为1024 -export IoTDB_MAX_SIZE=200 ##sessionpool内的最大数量,推荐设置为>=并发请求数 -export IoTDB_DATABASE=root.thingsboard ##thingsboard数据写入iotdb所存储的数据库,支持自定义 -``` - -## 使用说明 - -1. 创建设备并接入数据:在 Thingsboard 的实体-设备中创建设备并通过工业网关将数据发送到 ThingsBoard 指定设备中 - -![](/img/ThingsBoard-3.png) - -2. 设置规则链:在规则链库中对于“SD-032F 泵”设置告警规则并将该规则链设置为根链 - -
-  -  -
- -3. 查看告警记录:对于产生的告警记录已经通过点击“设备-告警”来进行查看 - -![](/img/ThingsBoard-6.png) - -4. 数据可视化:在“仪表板”中通过“新建仪表板-绑定设备-关联参数”进行可视化设置 - -
-  -  -
- diff --git a/src/zh/UserGuide/V1.3.0-2/FAQ/Frequently-asked-questions.md b/src/zh/UserGuide/V1.3.0-2/FAQ/Frequently-asked-questions.md deleted file mode 100644 index df33555f4..000000000 --- a/src/zh/UserGuide/V1.3.0-2/FAQ/Frequently-asked-questions.md +++ /dev/null @@ -1,261 +0,0 @@ - - - - -# 常见问题 - -## 一般问题 - -### 如何查询我的IoTDB版本? - -有几种方法可以识别您使用的 IoTDB 版本: - -* 启动 IoTDB 的命令行界面: - -``` -> ./start-cli.sh -p 6667 -pw root -u root -h localhost - _____ _________ ______ ______ -|_ _| | _ _ ||_ _ `.|_ _ \ - | | .--.|_/ | | \_| | | `. \ | |_) | - | | / .'`\ \ | | | | | | | __'. - _| |_| \__. | _| |_ _| |_.' /_| |__) | -|_____|'.__.' |_____| |______.'|_______/ version x.x.x -``` - -* 检查 pom.xml 文件: - -``` -x.x.x -``` - -* 使用 JDBC API: - -``` -String iotdbVersion = tsfileDatabaseMetadata.getDatabaseProductVersion(); -``` - -* 使用命令行接口: - -``` -IoTDB> show version -show version -+---------------+ -|version | -+---------------+ -|x.x.x | -+---------------+ -Total line number = 1 -It costs 0.241s -``` - -### 在哪里可以找到IoTDB的日志? - -假设您的根目录是: - -```shell -$ pwd -/workspace/iotdb - -$ ls -l -server/ -cli/ -pom.xml -Readme.md -... -``` - -假如 `$IOTDB_HOME = /workspace/iotdb/server/target/iotdb-server-{project.version}` - -假如 `$IOTDB_CLI_HOME = /workspace/iotdb/cli/target/iotdb-cli-{project.version}` - -在默认的设置里,logs 文件夹会被存储在```IOTDB_HOME/logs```。您可以在```IOTDB_HOME/conf```目录下的```logback.xml```文件中修改日志的级别和日志的存储路径。 - -### 在哪里可以找到IoTDB的数据文件? - -在默认的设置里,数据文件(包含 TsFile,metadata,WAL)被存储在```IOTDB_HOME/data/dtanode```文件夹。 - -### 如何知道IoTDB中存储了多少时间序列? - -使用 IoTDB 的命令行接口: - -``` -IoTDB> show timeseries -``` - -在返回的结果里,会展示`Total timeseries number`,这个数据就是 IoTDB 中 timeseries 的数量。 -a -在当前版本中,IoTDB 支持直接使用命令行接口查询时间序列的数量: - -``` -IoTDB> count timeseries -``` - -如果您使用的是 Linux 操作系统,您可以使用以下的 Shell 命令: - -``` -> grep "0,root" $IOTDB_HOME/data/system/schema/mlog.txt | wc -l -> 6 -``` - -### 可以使用Hadoop和Spark读取IoTDB中的TsFile吗? - -是的。IoTDB 与开源生态紧密结合。IoTDB 支持 [Hadoop](https://github.com/apache/iotdb-extras/tree/master/connectors/hadoop), [Spark](https://github.com/apache/iotdb-extras/tree/master/connectors/spark-iotdb-connector) 和 [Grafana](https://github.com/apache/iotdb-extras/tree/master/connectors/grafana-connector) 可视化工具。 - -### IoTDB如何处理重复的数据点? - -一个数据点是由一个完整的时间序列路径(例如:```root.vehicle.d0.s0```) 和时间戳唯一标识的。如果您使用与现有点相同的路径和时间戳提交一个新点,那么 IoTDB 将更新这个点的值,而不是插入一个新点。 - -### 我如何知道具体的timeseries的类型? - -在 IoTDB 的命令行接口中使用 SQL ```SHOW TIMESERIES ```: - -例如:如果您想知道所有 timeseries 的类型 \ 应该为 `root.**`。上面的 SQL 应该修改为: - -``` -IoTDB> show timeseries root.** -``` - -如果您想查询一个指定的时间序列,您可以修改 \ 为时间序列的完整路径。比如: - -``` -IoTDB> show timeseries root.fit.d1.s1 -``` - -您还可以在 timeseries 路径中使用通配符: - -``` -IoTDB> show timeseries root.fit.d1.* -``` - -### 如何更改IoTDB的客户端时间显示格式? - -IoTDB 客户端默认显示的时间是人类可读的(比如:```1970-01-01T08:00:00.001```),如果您想显示是时间戳或者其他可读格式,请在启动命令上添加参数```-disableISO8601```: - -``` -> $IOTDB_CLI_HOME/sbin/start-cli.sh -h 127.0.0.1 -p 6667 -u root -pw root -disableISO8601 -``` - -### 怎么处理来自`org.apache.ratis.grpc.server.GrpcLogAppender`的`IndexOutOfBoundsException`? - -这是我们的依赖Ratis 2.4.1的一个内部错误日志,不会对数据写入和读取造成任何影响。 -已经报告给Ratis社区,并会在未来的版本中修复。 - -### 预估内存不足报错如何处理? - -报错信息: -``` -301: There is not enough memory to execute current fragment instance, current remaining free memory is 86762854, estimated memory usage for current fragment instance is 270139392 -``` -报错分析: -datanode_memory_proportion参数控制分给查询的内存,chunk_timeseriesmeta_free_memory_proportion参数控制查询执行可用的内存。 -默认情况下分给查询的内存为堆内存*30%,查询执行可用的内存为查询内存的20%。 -报错显示当前剩余查询执行可用内存为86762854B=82.74MB,该查询预估使用执行内存270139392B=257.6MB。 - -一些可能的改进项: - -- 在不改变默认参数的前提下,调大IoTDB的堆内存大于 4.2G(4.2G * 1024MB=4300MB),4300M*30%*20%=258M>257.6M,可以满足要求。 -- 更改 datanode_memory_proportion 等参数,使查询执行可用内存>257.6MB。 -- 减少导出的时间序列数量。 -- 给查询语句添加 slimit 限制,也是减少查询时间序列的一种方案。 -- 添加 align by device,会按照device顺序进行输出,内存占用会降低至单device级别。 - - -## 分布式部署 FAQ - -### 集群启停 - -#### ConfigNode初次启动失败,如何排查原因? - -- ConfigNode初次启动时确保已清空data/confignode目录 -- 确保该ConfigNode使用到的没有被占用,没有与已启动的ConfigNode使用到的冲突 -- 确保该ConfigNode的cn_seed_config_node(指向存活的ConfigNode;如果该ConfigNode是启动的第一个ConfigNode,该值指向自身)配置正确 -- 确保该ConfigNode的配置项(共识协议、副本数等)等与cn_seed_config_node对应的ConfigNode集群一致 - -#### ConfigNode初次启动成功,show cluster的结果里为何没有该节点? - -- 检查cn_seed_config_node是否正确指向了正确的地址; 如果cn_seed_config_node指向了自身,则会启动一个新的ConfigNode集群 - -#### DataNode初次启动失败,如何排查原因? - -- DataNode初次启动时确保已清空data/datanode目录。 如果启动结果为“Reject DataNode restart.”则表示启动时可能没有清空data/datanode目录 -- 确保该DataNode使用到的没有被占用,没有与已启动的DataNode使用到的冲突 -- 确保该DataNode的dn_seed_config_node指向存活的ConfigNode - -#### 移除DataNode执行失败,如何排查? - -- 检查`remove-datanode`脚本的参数是否正确,是否传入了正确的ip:port或正确的dataNodeId -- 只有集群可用节点数量 > max(元数据副本数量, 数据副本数量)时,移除操作才允许被执行 -- 执行移除DataNode的过程会将该DataNode上的数据迁移到其他存活的DataNode,数据迁移以Region为粒度,如果某个Region迁移失败,则被移除的DataNode会一直处于Removing状态 -- 补充:处于Removing状态的节点,其节点上的Region也是Removing或Unknown状态,即不可用状态。 该Remvoing状态的节点也不会接受客户端的请求。如果要使Removing状态的节点变为可用,用户可以使用set system status to running 命令将该节点设置为Running状态;如果要使迁移失败的Region处于可用状态,可以使用migrate region from datanodeId1 to datanodeId2 命令将该不可用的Region迁移到其他存活的节点。另外IoTDB后续也会提供`remove-datanode.sh -f`命令,来强制移除节点(迁移失败的Region会直接丢弃) - -#### 挂掉的DataNode是否支持移除? - -- 当前集群副本数量大于1时可以移除。 如果集群副本数量等于1,则不支持移除。 在下个版本会推出强制移除的命令 - -#### 从0.13升级到1.0需要注意什么? - -- 0.13版本与1.0版本的文件目录结构是不同的,不能将0.13的data目录直接拷贝到1.0集群使用。如果需要将0.13的数据导入至1.0,可以使用LOAD功能 -- 0.13版本的默认RPC地址是0.0.0.0,1.0版本的默认RPC地址是127.0.0.1 - - -### 集群重启 - -#### 如何重启集群中的某个ConfigNode? - -- 第一步:通过`stop-confignode.sh`或kill进程方式关闭ConfigNode进程 -- 第二步:通过执行`start-confignode.sh`启动ConfigNode进程实现重启 -- 下个版本IoTDB会提供一键重启的操作 - -#### 如何重启集群中的某个DataNode? - -- 第一步:通过`stop-datanode.sh`或kill进程方式关闭DataNode进程 -- 第二步:通过执行`start-datanode.sh`启动DataNode进程实现重启 -- 下个版本IoTDB会提供一键重启的操作 - -#### 将某个ConfigNode移除后(remove-confignode),能否再利用该ConfigNode的data目录重启? - -- 不能。会报错:Reject ConfigNode restart. Because there are no corresponding ConfigNode(whose nodeId=xx) in the cluster. - -#### 将某个DataNode移除后(remove-datanode),能否再利用该DataNode的data目录重启? - -- 不能正常重启,启动结果为“Reject DataNode restart. Because there are no corresponding DataNode(whose nodeId=xx) in the cluster. Possible solutions are as follows:...” - -#### 用户看到某个ConfigNode/DataNode变成了Unknown状态,在没有kill对应进程的情况下,直接删除掉ConfigNode/DataNode对应的data目录,然后执行`start-confignode.sh`/`start-datanode.sh`,这种情况下能成功吗? - -- 无法启动成功,会报错端口已被占用 - -### 集群运维 - -#### Show cluster执行失败,显示“please check server status”,如何排查? - -- 确保ConfigNode集群一半以上的节点处于存活状态 -- 确保客户端连接的DataNode处于存活状态 - -#### 某一DataNode节点的磁盘文件损坏,如何修复这个节点? - -- 当前只能通过remove-datanode的方式进行实现。remove-datanode执行的过程中会将该DataNode上的数据迁移至其他存活的DataNode节点(前提是集群设置的副本数大于1) -- 下个版本IoTDB会提供一键修复节点的功能 - -#### 如何降低ConfigNode、DataNode使用的内存? - -- 在`conf/confignode-env.sh`、`conf/datanode-env.sh`文件可通过调整ON_HEAP_MEMORY、OFF_HEAP_MEMORY等选项可以调整ConfigNode、DataNode使用的最大堆内、堆外内存 - diff --git a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Architecture.md b/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Architecture.md deleted file mode 100644 index 3065e84ec..000000000 --- a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Architecture.md +++ /dev/null @@ -1,44 +0,0 @@ - - -# 系统架构 - -IoTDB 套件由若干个组件构成,共同形成“数据收集-数据写入-数据存储-数据查询-数据可视化-数据分析”等一系列功能。 - -如下图展示了使用 IoTDB 套件全部组件后形成的整体应用架构。下文称所有组件形成 IoTDB 套件,而 IoTDB 特指其中的时间序列数据库组件。 - - - -在上图中,用户可以通过 JDBC 将来自设备上传感器采集的时序数据、服务器负载和 CPU 内存等系统状态数据、消息队列中的时序数据、应用程序的时序数据或者其他数据库中的时序数据导入到本地或者远程的 IoTDB 中。用户还可以将上述数据直接写成本地(或位于 HDFS 上)的 TsFile 文件。 - -可以将 TsFile 文件写入到 HDFS 上,进而实现在 Hadoop 或 Spark 的数据处理平台上的诸如异常检测、机器学习等数据处理任务。 - -对于写入到 HDFS 或者本地的 TsFile 文件,可以利用 TsFile-Hadoop 或 TsFile-Spark 连接器允许 Hadoop 或 Spark 进行数据处理。 - -对于分析的结果,可以写回成 TsFile 文件。 - -IoTDB 和 TsFile 还提供了相应的客户端工具,满足用户查看和写入数据的 SQL 形式、脚本形式和图形化形式等多种需求。 - -IoTDB 提供了单机部署和集群部署两种模式。在集群部署模式下,IoTDB支持自动故障转移,确保系统在节点故障时能够快速切换到备用节点。切换时间可以达到秒级,从而最大限度地减少系统中断时间,且可保证切换后数据不丢失。当故障节点恢复正常,系统会自动将其重新纳入集群,确保集群的高可用性和可伸缩性。 - -IoTDB还支持读写分离模式部署,可以将读操作和写操作分别分配给不同的节点,从而实现负载均衡和提高系统的并发处理能力。 - -通过这些特性,IoTDB能够避免单点性能瓶颈和单点故障(SPOF),提供高可用性和可靠性的数据存储和管理解决方案。 diff --git a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Features.md b/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Features.md deleted file mode 100644 index 7c1d7bbc5..000000000 --- a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Features.md +++ /dev/null @@ -1,59 +0,0 @@ - - -# 主要功能特点 - -IoTDB 具有以下特点: - -* 灵活的部署方式 - * 云端一键部署 - * 终端解压即用 - * 终端-云端无缝连接(数据云端同步工具) -* 低硬件成本的存储解决方案 - * 高压缩比的磁盘存储(10 亿数据点硬盘成本低于 1.4 元) -* 目录结构的时间序列组织管理方式 - * 支持复杂结构的智能网联设备的时间序列组织 - * 支持大量同类物联网设备的时间序列组织 - * 可用模糊方式对海量复杂的时间序列目录结构进行检索 -* 高通量的时间序列数据读写 - * 支持百万级低功耗强连接设备数据接入(海量) - * 支持智能网联设备数据高速读写(高速) - * 以及同时具备上述特点的混合负载 -* 面向时间序列的丰富查询语义 - * 跨设备、跨传感器的时间序列时间对齐 - * 面向时序数据特征的计算 - * 提供面向时间维度的丰富聚合函数支持 -* 极低的学习门槛 - * 支持类 SQL 的数据操作 - * 提供 JDBC 的编程接口 - * 完善的导入导出工具 -* 完美对接开源生态环境 - * 支持开源数据分析生态系统:Hadoop、Spark - * 支持开源可视化工具对接:Grafana -* 统一的数据访问模式 - * 无需进行分库分表处理 - * 无需区分实时库和历史库 -* 高可用性支持 - * 支持HA分布式架构,系统提供7*24小时不间断的实时数据库服务 - * 应用访问系统,可以连接集群中的任何一个节点进行 - * 一个物理节点宕机或网络故障,不会影响系统的正常运行 - * 物理节点的增加、删除或过热,系统会自动进行计算/存储资源的负载均衡处理 - * 支持异构环境,不同类型、不同性能的服务器可以组建集群,系统根据物理机的配置,自动负载均衡 diff --git a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_apache.md b/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_apache.md deleted file mode 100644 index 47795fec8..000000000 --- a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_apache.md +++ /dev/null @@ -1,76 +0,0 @@ - - -# 产品介绍 - -Apache IoTDB 是一款低成本、高性能的物联网原生时序数据库。它可以解决企业组建物联网大数据平台管理时序数据时所遇到的应用场景复杂、数据体量大、采样频率高、数据乱序多、数据处理耗时长、分析需求多样、存储与运维成本高等多种问题。 - -- Github仓库链接:https://github.com/apache/iotdb - -- 开源安装包下载:https://iotdb.apache.org/zh/Download/ - -- 安装部署与使用文档:[快速上手](../QuickStart/QuickStart_apache.md) - - -## 产品体系 - -IoTDB 体系由若干个组件构成,帮助用户高效地管理和分析物联网产生的海量时序数据。 - -
- Introduction-zh-apache.png -
- -其中: - -1. **时序数据库(Apache IoTDB)**:时序数据存储的核心组件,其能够为用户提供高压缩存储能力、丰富时序查询能力、实时流处理能力,同时具备数据的高可用和集群的高扩展性,并在安全层面提供全方位保障。同时 IoTDB 还为用户提供多种应用工具,方便用户配置和管理系统;多语言API和外部系统应用集成能力,方便用户在 IoTDB 基础上构建业务应用。 -2. **时序数据标准文件格式(Apache TsFile)**:该文件格式是一种专为时序数据设计的存储格式,可以高效地存储和查询海量时序数据。目前 IoTDB、AINode 等模块的底层存储文件均由 Apache TsFile 进行支撑。通过 TsFile,用户可以在采集、管理、应用&分析阶段统一使用相同的文件格式进行数据管理,极大简化了数据采集到分析的整个流程,提高时序数据管理的效率和便捷度。 -3. **时序模型训推一体化引擎(IoTDB AINode)**:针对智能分析场景,IoTDB 提供 AINode 时序模型训推一体化引擎,它提供了一套完整的时序数据分析工具,底层为模型训练引擎,支持训练任务与数据管理,与包括机器学习、深度学习等。通过这些工具,用户可以对存储在 IoTDB 中的数据进行深入分析,挖掘出其中的价值。 - - -## 产品特性 - -Apache IoTDB 具备以下优势和特性: - -- 灵活的部署方式:支持云端一键部署、终端解压即用、终端-云端无缝连接(数据云端同步工具) - -- 低硬件成本的存储解决方案:支持高压缩比的磁盘存储,无需区分历史库与实时库,数据统一管理 - -- 层级化的测点组织管理方式:支持在系统中根据设备实际层级关系进行建模,以实现与工业测点管理结构的对齐,同时支持针对层级结构的目录查看、检索等能力 - -- 高通量的数据读写:支持百万级设备接入、数据高速读写、乱序/多频采集等复杂工业读写场景 - -- 丰富的时间序列查询语义:支持时序数据原生计算引擎,支持查询时时间戳对齐,提供近百种内置聚合与时序计算函数,支持面向时序特征分析和AI能力 - -- 高可用的分布式系统:支持HA分布式架构,系统提供7*24小时不间断的实时数据库服务,一个物理节点宕机或网络故障,不会影响系统的正常运行;支持物理节点的增加、删除或过热,系统会自动进行计算/存储资源的负载均衡处理;支持异构环境,不同类型、不同性能的服务器可以组建集群,系统根据物理机的配置,自动负载均衡 - -- 极低的使用&运维门槛:支持类 SQL 语言、提供多语言原生二次开发接口、具备控制台等完善的工具体系 - -- 丰富的生态环境对接:支持Hadoop、Spark等大数据生态系统组件对接,支持Grafana、Thingsboard、DataEase等设备管理和可视化工具 - -## 商业版本 - -天谋科技在 Apache IoTDB 开源版本的基础上提供了原厂商业化产品 TimechoDB,为企业、商业客户提供企业级产品和服务,它可以解决企业组建物联网大数据平台管理时序数据时所遇到的应用场景复杂、数据体量大、采样频率高、数据乱序多、数据处理耗时长、分析需求多样、存储与运维成本高等多种问题。 - -天谋科技基于 TimechoDB 提供更多样的产品功能、更强大的性能和稳定性、更丰富的效能工具,并为用户提供全方位的企业服务,从而为商业化客户提供更强大的产品能力,和更优质的开发、运维、使用体验。 - -- 天谋科技官网:https://www.timecho.com/ - -- TimechoDB 安装部署与使用文档:[快速上手](https://www.timecho.com/docs/zh/UserGuide/latest/QuickStart/QuickStart_timecho.html) \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_timecho.md b/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_timecho.md deleted file mode 100644 index a24e5f681..000000000 --- a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/IoTDB-Introduction_timecho.md +++ /dev/null @@ -1,266 +0,0 @@ - - -# 产品介绍 - -TimechoDB 是一款低成本、高性能的物联网原生时序数据库,是天谋科技基于 Apache IoTDB 社区版本提供的原厂商业化产品。它可以解决企业组建物联网大数据平台管理时序数据时所遇到的应用场景复杂、数据体量大、采样频率高、数据乱序多、数据处理耗时长、分析需求多样、存储与运维成本高等多种问题。 - -天谋科技基于 TimechoDB 提供更多样的产品功能、更强大的性能和稳定性、更丰富的效能工具,并为用户提供全方位的企业服务,从而为商业化客户提供更强大的产品能力,和更优质的开发、运维、使用体验。 - -- 下载、部署与使用:[快速上手](../QuickStart/QuickStart_timecho.md) - -## 产品体系 - -天谋产品体系由若干个组件构成,覆盖由【数据采集】到【数据管理】到【数据分析&应用】的全时序数据生命周期,做到“采-存-用”一体化时序数据解决方案,帮助用户高效地管理和分析物联网产生的海量时序数据。 - -
- Introduction-zh-timecho.png -
- - -其中: - -1. **时序数据库(TimechoDB,基于 Apache IoTDB 提供的原厂商业化产品)**:时序数据存储的核心组件,其能够为用户提供高压缩存储能力、丰富时序查询能力、实时流处理能力,同时具备数据的高可用和集群的高扩展性,并在安全层面提供全方位保障。同时 TimechoDB 还为用户提供多种应用工具,方便用户配置和管理系统;多语言API和外部系统应用集成能力,方便用户在 TimechoDB 基础上构建业务应用。 -2. **时序数据标准文件格式(Apache TsFile,多位天谋科技核心团队成员主导&贡献代码)**:该文件格式是一种专为时序数据设计的存储格式,可以高效地存储和查询海量时序数据。目前 Timecho 采集、存储、智能分析等模块的底层存储文件均由 Apache TsFile 进行支撑。TsFile 可以被高效地加载至 TimechoDB 中,也能够被迁移出来。通过 TsFile,用户可以在采集、管理、应用&分析阶段统一使用相同的文件格式进行数据管理,极大简化了数据采集到分析的整个流程,提高时序数据管理的效率和便捷度。 -3. **时序模型训推一体化引擎(AINode)**:针对智能分析场景,TimechoDB 提供 AINode 时序模型训推一体化引擎,它提供了一套完整的时序数据分析工具,底层为模型训练引擎,支持训练任务与数据管理,与包括机器学习、深度学习等。通过这些工具,用户可以对存储在 TimechoDB 中的数据进行深入分析,挖掘出其中的价值。 -4. **数据采集**:为了更加便捷的对接各类工业采集场景, 天谋科技提供数据采集接入服务,支持多种协议和格式,可以接入各种传感器、设备产生的数据,同时支持断点续传、网闸穿透等特性。更加适配工业领域采集过程中配置难、传输慢、网络弱的特点,让用户的数采变得更加简单、高效。 - - -## 产品特性 - -TimechoDB 具备以下优势和特性: - -- 灵活的部署方式:支持云端一键部署、终端解压即用、终端-云端无缝连接(数据云端同步工具) - -- 低硬件成本的存储解决方案:支持高压缩比的磁盘存储,无需区分历史库与实时库,数据统一管理 - -- 层级化的测点组织管理方式:支持在系统中根据设备实际层级关系进行建模,以实现与工业测点管理结构的对齐,同时支持针对层级结构的目录查看、检索等能力 - -- 高通量的数据读写:支持百万级设备接入、数据高速读写、乱序/多频采集等复杂工业读写场景 - -- 丰富的时间序列查询语义:支持时序数据原生计算引擎,支持查询时时间戳对齐,提供近百种内置聚合与时序计算函数,支持面向时序特征分析和AI能力 - -- 高可用的分布式系统:支持HA分布式架构,系统提供7*24小时不间断的实时数据库服务,一个物理节点宕机或网络故障,不会影响系统的正常运行;支持物理节点的增加、删除或过热,系统会自动进行计算/存储资源的负载均衡处理;支持异构环境,不同类型、不同性能的服务器可以组建集群,系统根据物理机的配置,自动负载均衡 - -- 极低的使用&运维门槛:支持类 SQL 语言、提供多语言原生二次开发接口、具备控制台等完善的工具体系 - -- 丰富的生态环境对接:支持Hadoop、Spark等大数据生态系统组件对接,支持Grafana、Thingsboard、DataEase等设备管理和可视化工具 - -## 企业特性 - -### 更高阶的产品功能 - -TimechoDB 在开源版基础上提供了更多高阶产品功能,在内核层面针对工业生产场景进行原生升级和优化,如多级存储、云边协同、可视化工具、安全增强等功能,能够让用户无需过多关注底层逻辑,将精力聚焦在业务开发中,让工业生产更简单更高效,为企业带来更多的经济效益。如: - -- 双活部署:双活通常是指两个独立的单机(或集群),实时进行镜像同步,它们的配置完全独立,可以同时接收外界的写入,每一个独立的单机(或集群)都可以将写入到自己的数据同步到另一个单机(或集群)中,两个单机(或集群)的数据可达到最终一致。 - -- 数据同步:通过数据库内置的同步模块,支持数据由场站向中心汇聚,支持全量汇聚、部分汇聚、级联汇聚等各类场景,可支持实时数据同步与批量数据同步两种模式。同时提供多种内置插件,支持企业数据同步应用中的网闸穿透、加密传输、压缩传输等相关要求。 - -- 多级存储:通过升级底层存储能力,支持根据访问频率和数据重要性等因素将数据划分为冷、温、热等不同层级的数据,并将其存储在不同介质中(如 SSD、机械硬盘、云存储等),同时在查询过程中也由系统进行数据调度。从而在保证数据访问速度的同时,降低客户数据存储成本。 - -- 安全增强:通过白名单、审计日志等功能加强企业内部管理,降低数据泄露风险。 - -详细功能对比如下: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
功能Apache IoTDBTimechoDB
部署模式单机部署
分布式部署
双活部署×
容器部署部分支持
数据库功能测点管理
数据写入
数据查询
连续查询
触发器
用户自定义函数
权限管理
数据同步仅文件同步,无内置插件实时同步+文件同步,丰富内置插件
流处理仅框架,无内置插件框架+丰富内置插件
多级存储×
视图×
白名单×
审计日志×
配套工具可视化控制台×
集群管理工具×
系统监控工具×
国产化国产化兼容性认证×
技术支持最佳实践×
使用培训×
- -### 更高效/稳定的产品性能 - -TimechoDB 在开源版的基础上优化了稳定性与性能,经过企业版技术支持,能够实现10倍以上性能提升,并具有故障及时恢复的性能优势。 - -### 更用户友好的工具体系 - -TimechoDB 将为用户提供更简单、易用的工具体系,通过集群监控面板(IoTDB Grafana)、数据库控制台(IoTDB Workbench)、集群管理工具(IoTDB Deploy Tool,简称 IoTD)等产品帮助用户快速部署、管理、监控数据库集群,降低运维人员工作/学习成本,简化数据库运维工作,使运维过程更加方便、快捷。 - -- 集群监控面板:旨在解决 IoTDB 及其所在操作系统的监控问题,主要包括:操作系统资源监控、IoTDB 性能监控,及上百项内核监控指标,从而帮助用户监控集群健康状态,并进行集群调优和运维。 - -
-

总体概览

-

操作系统资源监控

-

IoTDB 性能监控

-
-
- - - -
-

- -- 数据库控制台:旨在提供低门槛的数据库交互工具,通过提供界面化的控制台帮助用户简洁明了的进行元数据管理、数据增删改查、权限管理、系统管理等操作,简化数据库使用难度,提高数据库使用效率。 - - -
-

首页

-

元数据管理

-

SQL 查询

-
-
- - - -
-

- - -- 集群管理工具:旨在解决分布式系统多节点的运维难题,主要包括集群部署、集群启停、弹性扩容、配置更新、数据导出等功能,从而实现对复杂数据库集群的一键式指令下发,极大降低管理难度。 - - -
-  -
- -### 更专业的企业技术服务 - -TimechoDB 客户提供强大的原厂服务,包括但不限于现场安装及培训、专家顾问咨询、现场紧急救助、软件升级、在线自助服务、远程支持、最新开发版使用指导等服务。同时,为了使 IoTDB 更契合工业生产场景,我们会根据企业实际数据结构和读写负载,进行建模方案推荐、读写性能调优、压缩比调优、数据库配置推荐及其他的技术支持。如遇到部分产品未覆盖的工业化定制场景,TimechoDB 将根据用户特点提供定制化开发工具。 - -相较于开源版本,每 2-3 个月一个发版周期,TimechoDB 提供周期更快的发版频率,同时针对客户现场紧急问题,提供天级别的专属修复,确保生产环境稳定。 - - -### 更兼容的国产化适配 - -TimechoDB 代码自研可控,同时兼容大部分主流信创产品(CPU、操作系统等),并完成与多个厂家的兼容认证,确保产品的合规性和安全性。 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Performance.md b/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Performance.md deleted file mode 100644 index cfd3d5de5..000000000 --- a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Performance.md +++ /dev/null @@ -1,36 +0,0 @@ - - -# 性能特点 - -本章节从数据库连接、数据库读写性能及存储性能角度介绍IoTDB的性能特点,测试工具使用开源的时序数据库基准测试工具 [iot-benchmark](../Tools-System/Benchmark.md)。 - -## 数据库连接 - -- 支持高并发连接,单台服务器可支持数万次并发连接/秒。 - -## 数据库读写性能 - -- 具备高写入吞吐的特点,单核处理写入请求大于数万次/秒,单台服务器写入性能达到数千万点/秒;集群可线性扩展,集群的写入性能可达数亿点/秒。 -- 具备高查询吞吐、低查询延迟的特点,单台服务器支持数千万点/秒查询吞吐,可在毫秒级聚合百亿数据点。 - -## 存储性能 - -- 支持存储海量数据,具备PB级数据的存储和处理能力。 -- 支持高压缩比,无损压缩能够达到20倍压缩比,有损压缩能够达到100倍压缩比。 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Publication.md b/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Publication.md deleted file mode 100644 index 919e6b3cc..000000000 --- a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Publication.md +++ /dev/null @@ -1,42 +0,0 @@ - - -# 学术成果 - -Apache IoTDB 始于清华大学软件学院。IoTDB 是一个用于管理大量时间序列数据的数据库,它采用了列式存储、数据编码、预计算和索引技术,具有类 SQL 的接口,可支持每秒每节点写入数百万数据点,可以秒级获得超过数万亿个数据点的查询结果。它还可以很容易地与 Apache Hadoop、MapReduce 和 Apache Spark 集成以进行分析。 - -相关研究论文如下: -* [Apache IoTDB: A Time Series Database for IoT Applications](https://sxsong.github.io/doc/23sigmod-iotdb.pdf), Chen Wang, Jialin Qiao, Xiangdong Huang, Shaoxu Song, Haonan Hou, Tian Jiang, Lei Rui, Jianmin Wang, Jiaguang Sun. SIGMOD 2023. -* [Grouping Time Series for Efficient Columnar Storage](https://sxsong.github.io/doc/23sigmod-group.pdf), Chenguang Fang, Shaoxu Song, Haoquan Guan, Xiangdong Huang, Chen Wang, Jianmin Wang. SIGMOD 2023. -* [Learning Autoregressive Model in LSM-Tree based Store](https://sxsong.github.io/doc/23kdd.pdf), Yunxiang Su, Wenxuan Ma, Shaoxu Song. SIGMOD 2023. -* [TsQuality: Measuring Time Series Data Quality in Apache IoTDB](https://sxsong.github.io/doc/23vldb-qaulity.pdf), Yuanhui Qiu, Chenguang Fang, Shaoxu Song, Xiangdong Huang, Chen Wang, Jianmin Wang. VLDB 2023. -* [Frequency Domain Data Encoding in Apache IoTDB](https://sxsong.github.io/doc/22vldb-frequency.pdf), Haoyu Wang, Shaoxu Song. VLDB 2023. -* [Non-Blocking Raft for High Throughput IoT Data](https://sxsong.github.io/doc/23icde-raft.pdf), Tian Jiang, Xiangdong Huang, Shaoxu Song, Chen Wang, Jianmin Wang, Ruibo Li, Jincheng Sun. ICDE 2023. -* [Backward-Sort for Time Series in Apache IoTDB](https://sxsong.github.io/doc/23icde-sort.pdf), Xiaojian Zhang, Hongyin Zhang, Shaoxu Song, Xiangdong Huang, Chen Wang, Jianmin Wang. ICDE 2023. -* [Time Series Data Encoding for Efficient Storage: A Comparative Analysis in Apache IoTDB](https://sxsong.github.io/doc/22vldb-encoding.pdf), Jinzhao Xiao, Yuxiang Huang, Changyu Hu, Shaoxu Song, Xiangdong Huang, Jianmin Wang. VLDB 2022. -* [Separation or Not: On Handing Out-of-Order Time-Series Data in Leveled LSM-Tree](https://sxsong.github.io/doc/22icde-separation.pdf), Yuyuan Kang, Xiangdong Huang, Shaoxu Song, Lingzhe Zhang, Jialin Qiao, Chen Wang, Jianmin Wang, Julian Feinauer. ICDE 2022. -* [Dual-PISA: An index for aggregation operations on time series data](https://www.sciencedirect.com/science/article/pii/S0306437918305489), Jialin Qiao, Xiangdong Huang, Jianmin Wang, Raymond K Wong. IS 2020. -* [Apache IoTDB: time-series database for internet of things](http://www.vldb.org/pvldb/vol13/p2901-wang.pdf), Chen Wang, Xiangdong Huang, Jialin Qiao, Tian Jiang, Lei Rui, Jinrui Zhang, Rong Kang, Julian Feinauer, Kevin A. McGrail, Peng Wang, Jun Yuan, Jianmin Wang, Jiaguang Sun. VLDB 2020. -* [KV-match: A Subsequence Matching Approach Supporting Normalization and Time Warping](https://www.semanticscholar.org/paper/KV-match%3A-A-Subsequence-Matching-Approach-and-Time-Wu-Wang/9ed84cb15b7e5052028fc5b4d667248713ac8592), Jiaye Wu and Peng Wang and Chen Wang and Wei Wang and Jianmin Wang. ICDE 2019. -* [The Design of Apache IoTDB distributed framework](http://ndbc2019.sdu.edu.cn/info/1002/1044.htm), Tianan Li, Jianmin Wang, Xiangdong Huang, Yi Xu, Dongfang Mao, Jun Yuan. NDBC 2019. -* [Matching Consecutive Subpatterns over Streaming Time Series](https://link.springer.com/chapter/10.1007/978-3-319-96893-3_8), Rong Kang and Chen Wang and Peng Wang and Yuting Ding and Jianmin Wang. APWeb/WAIM 2018. -* [PISA: An Index for Aggregating Big Time Series Data](https://dl.acm.org/citation.cfm?id=2983775&dl=ACM&coll=DL), Xiangdong Huang and Jianmin Wang and Raymond K. Wong and Jinrui Zhang and Chen Wang. CIKM 2016. - diff --git a/src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache.md b/src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache.md deleted file mode 100644 index 79e33f672..000000000 --- a/src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_apache.md +++ /dev/null @@ -1,80 +0,0 @@ - - -# 快速上手 - -本篇文档将帮助您了解快速入门 IoTDB 的方法。 - -## 如何安装部署? - -本篇文档将帮助您快速安装部署 IoTDB,您可以通过以下文档的链接快速定位到所需要查看的内容: - -1. 准备所需机器资源:IoTDB 的部署和运行需要考虑多个方面的机器资源配置。具体资源配置可查看 [资源规划](../Deployment-and-Maintenance/Database-Resources.md) - -2. 完成系统配置准备:IoTDB 的系统配置涉及多个方面,关键的系统配置介绍可查看 [系统配置](../Deployment-and-Maintenance/Environment-Requirements.md) - -3. 获取安装包:您可以在[ Apache IoTDB 官网](https://iotdb.apache.org/zh/Download/)获取获取 IoTDB 安装包。具体安装包结构可查看:[安装包获取](../Deployment-and-Maintenance/IoTDB-Package_apache.md) - -4. 安装数据库:您可以根据实际部署架构选择以下教程进行安装部署: - - - 单机版:[单机版](../Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md) - - - 集群版:[集群版](../Deployment-and-Maintenance/Cluster-Deployment_apache.md) - -> ❗️注意:目前我们仍然推荐直接在物理机/虚拟机上安装部署,如需要 docker 部署,可参考:[Docker 部署](../Deployment-and-Maintenance/Docker-Deployment_apache.md) - -## 如何使用? - -1. 数据库建模设计:数据库建模是创建数据库系统的重要步骤,它涉及到设计数据的结构和关系,以确保数据的组织方式能够满足特定应用的需求,下面的文档将会帮助您快速了解 IoTDB 的建模设计: - - - 时序概念介绍:[走进时序数据](../Basic-Concept/Navigating_Time_Series_Data.md) - - - 建模设计介绍:[数据模型介绍](../Basic-Concept/Data-Model-and-Terminology.md) - - - SQL 语法介绍:[SQL 语法介绍](../User-Manual/Operate-Metadata_apache.md) - -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../User-Manual/Write-Delete-Data.md) - -3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../User-Manual/Query-Data.md) - -4. 其他进阶功能:除了数据库常见的写入、查询等功能外,IoTDB 还支持“数据同步、流处理框架、权限管理”等功能,具体使用方法可参见具体文档: - - - 数据同步:[数据同步](../User-Manual/Data-Sync_apache.md) - - - 流处理框架:[流处理框架](../User-Manual/Streaming_apache.md) - - - 权限管理:[权限管理](../User-Manual/Authority-Management.md) - -5. 应用编程接口: IoTDB 提供了多种应用编程接口(API),以便于开发者在应用程序中与 IoTDB 进行交互,目前支持 [Java](../API/Programming-Java-Native-API.md)、[Python](../API/Programming-Python-Native-API.md)、[C++](../API/Programming-Cpp-Native-API.md)等,更多编程接口可参见官网【应用编程接口】其他章节 - -## 还有哪些便捷的周边工具? - -IoTDB 除了自身拥有丰富的功能外,其周边的工具体系包含的种类十分齐全。本篇文档将帮助您快速使用周边工具体系: - - - 测试工具:IoT-benchmark 是一个基于 Java 和大数据环境开发的时序数据库基准测试工具,由清华大学软件学院研发并开源。它支持多种写入和查询方式,能够存储测试信息和结果供进一步查询或分析,并支持与 Tableau 集成以可视化测试结果。具体使用介绍请查看:[测试工具](../Tools-System/Benchmark.md) - - - 数据导入导出脚本:用于实现 IoTDB 内部数据与外部文件的交互,适用于单个文件或目录文件批量操作,具体使用介绍请查看:[数据导入导出脚本](../Tools-System/Data-Import-Export-Tool.md) - - - TsFile 导入导出脚本:针对于不同场景,IoTDB 为用户提供多种批量导入数据的操作方式,具体使用介绍请查看:[TsFile 导入导出脚本](../Tools-System/TsFile-Import-Export-Tool.md) - -## 使用过程中遇到问题? - -如果您在安装或使用过程中遇到困难,可以移步至 [常见问题](../FAQ/Frequently-asked-questions.md) 中进行查看 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_timecho.md b/src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_timecho.md deleted file mode 100644 index 2bfec8646..000000000 --- a/src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart_timecho.md +++ /dev/null @@ -1,92 +0,0 @@ - - -# 快速上手 - -本篇文档将帮助您了解快速入门 IoTDB 的方法。 - -## 如何安装部署? - -本篇文档将帮助您快速安装部署 IoTDB,您可以通过以下文档的链接快速定位到所需要查看的内容: - -1. 准备所需机器资源:IoTDB 的部署和运行需要考虑多个方面的机器资源配置。具体资源配置可查看 [资源规划](../Deployment-and-Maintenance/Database-Resources.md) - -2. 完成系统配置准备:IoTDB 的系统配置涉及多个方面,关键的系统配置介绍可查看 [系统配置](../Deployment-and-Maintenance/Environment-Requirements.md) - -3. 获取安装包:您可以联系天谋商务获取 IoTDB 安装包,以确保下载的是最新且稳定的版本。具体安装包结构可查看:[安装包获取](../Deployment-and-Maintenance/IoTDB-Package_timecho.md) - -4. 安装数据库并激活:您可以根据实际部署架构选择以下教程进行安装部署: - - - 单机版:[单机版](../Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md) - - - 集群版:[集群版](../Deployment-and-Maintenance//Cluster-Deployment_timecho.md) - - - 双活版:[双活版](../Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md) - -> ❗️注意:目前我们仍然推荐直接在物理机/虚拟机上安装部署,如需要 docker 部署,可参考:[Docker 部署](../Deployment-and-Maintenance/Docker-Deployment_timecho.md) - -5. 安装数据库配套工具:企业版数据库提供监控面板、可视化控制台等配套工具,建议在部署企业版时安装,可以帮助您更加便捷的使用 IoTDB: - - - 监控面板:提供了上百个数据库监控指标,用来对 IoTDB 及其所在操作系统进行细致监控,从而进行系统优化、性能优化、发现瓶颈等,安装步骤可查看 [监控面板部署](../Deployment-and-Maintenance/Monitoring-panel-deployment.md) - - - 可视化控制台:是 IoTDB 的可视化界面,支持通过界面交互的形式提供元数据管理、数据查询、数据可视化等功能的操作,帮助用户简单、高效的使用数据库,安装步骤可查看 [可视化控制台部署](../Deployment-and-Maintenance/workbench-deployment_timecho.md) - -## 如何使用? - -1. 数据库建模设计:数据库建模是创建数据库系统的重要步骤,它涉及到设计数据的结构和关系,以确保数据的组织方式能够满足特定应用的需求,下面的文档将会帮助您快速了解 IoTDB 的建模设计: - - - 时序概念介绍:[走进时序数据](../Basic-Concept/Navigating_Time_Series_Data.md) - - - 建模设计介绍:[数据模型介绍](../Basic-Concept/Data-Model-and-Terminology.md) - - - SQL 语法介绍:[SQL 语法介绍](../User-Manual/Operate-Metadata_timecho.md) - -2. 数据写入:在数据写入方面,IoTDB 提供了多种方式来插入实时数据,基本的数据写入操作请查看 [数据写入](../User-Manual/Write-Delete-Data.md) - -3. 数据查询:IoTDB 提供了丰富的数据查询功能,数据查询的基本介绍请查看 [数据查询](../User-Manual/Query-Data.md) - -4. 其他进阶功能:除了数据库常见的写入、查询等功能外,IoTDB 还支持“数据同步、流处理框架、安全控制、权限管理、AI 分析”等功能,具体使用方法可参见具体文档: - - - 数据同步:[数据同步](../User-Manual/Data-Sync_timecho.md) - - - 流处理框架:[流处理框架](../User-Manual/Streaming_timecho.md) - - - 安全控制:[安全控制](../User-Manual/Security-Management_timecho.md) - - - 权限管理:[权限管理](../User-Manual/Authority-Management.md) - - - AI 分析:[AI 能力](../User-Manual/AINode_timecho.md) - -5. 应用编程接口: IoTDB 提供了多种应用编程接口(API),以便于开发者在应用程序中与 IoTDB 进行交互,目前支持[ Java 原生接口](../API/Programming-Java-Native-API.md)、[Python 原生接口](../API/Programming-Python-Native-API.md)、[C++原生接口](../API/Programming-Cpp-Native-API.md)、[Go 原生接口](../API/Programming-Go-Native-API.md)等,更多编程接口可参见官网【应用编程接口】其他章节 - -## 还有哪些便捷的周边工具? - -IoTDB 除了自身拥有丰富的功能外,其周边的工具体系包含的种类十分齐全。本篇文档将帮助您快速使用周边工具体系: - - - 测试工具:IoT-benchmark 是一个基于 Java 和大数据环境开发的时序数据库基准测试工具,由清华大学软件学院研发并开源。它支持多种写入和查询方式,能够存储测试信息和结果供进一步查询或分析,并支持与 Tableau 集成以可视化测试结果。具体使用介绍请查看:[测试工具](../Tools-System/Benchmark.md) - - - 数据导入导出脚本:用于实现 IoTDB 内部数据与外部文件的交互,适用于单个文件或目录文件批量操作,具体使用介绍请查看:[数据导入导出脚本](../Tools-System/Data-Import-Export-Tool.md) - - - TsFile 导入导出脚本:针对于不同场景,IoTDB 为用户提供多种批量导入数据的操作方式,具体使用介绍请查看:[TsFile 导入导出脚本](../Tools-System/TsFile-Import-Export-Tool.md) - -## 使用过程中遇到问题? - -如果您在安装或使用过程中遇到困难,可以移步至 [常见问题](../FAQ/Frequently-asked-questions.md) 中进行查看 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/Function-and-Expression.md b/src/zh/UserGuide/V1.3.0-2/Reference/Function-and-Expression.md deleted file mode 100644 index 495043750..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Reference/Function-and-Expression.md +++ /dev/null @@ -1,3200 +0,0 @@ - - -# 内置函数与表达式 - -## 聚合函数 - -聚合函数是多对一函数。它们对一组值进行聚合计算,得到单个聚合结果。 - -除了 `COUNT()`, `COUNT_IF()`之外,其他所有聚合函数都忽略空值,并在没有输入行或所有值为空时返回空值。 例如,`SUM()` 返回 null 而不是零,而 `AVG()` 在计数中不包括 null 值。 - -IoTDB 支持的聚合函数如下: - -| 函数名 | 功能描述 | 允许的输入类型 | 必要的属性参数 | 输出类型 | -| ------------- | ------------------------------------------------------------ | ------------------------- | ------------------------------------------------------------ | -------------- | -| SUM | 求和。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| COUNT | 计算数据点数。 | 所有类型 | 无 | INT64 | -| AVG | 求平均值。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| STDDEV | STDDEV_SAMP 的别名,求样本标准差。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| STDDEV_POP | 求总体标准差。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| STDDEV_SAMP | 求样本标准差。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| VARIANCE | VAR_SAMP 的别名,求样本方差。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| VAR_POP | 求总体方差。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| VAR_SAMP | 求样本方差。 | INT32 INT64 FLOAT DOUBLE | 无 | DOUBLE | -| EXTREME | 求具有最大绝对值的值。如果正值和负值的最大绝对值相等,则返回正值。 | INT32 INT64 FLOAT DOUBLE | 无 | 与输入类型一致 | -| MAX_VALUE | 求最大值。 | INT32 INT64 FLOAT DOUBLE | 无 | 与输入类型一致 | -| MIN_VALUE | 求最小值。 | INT32 INT64 FLOAT DOUBLE | 无 | 与输入类型一致 | -| FIRST_VALUE | 求时间戳最小的值。 | 所有类型 | 无 | 与输入类型一致 | -| LAST_VALUE | 求时间戳最大的值。 | 所有类型 | 无 | 与输入类型一致 | -| MAX_TIME | 求最大时间戳。 | 所有类型 | 无 | Timestamp | -| MIN_TIME | 求最小时间戳。 | 所有类型 | 无 | Timestamp | -| COUNT_IF | 求数据点连续满足某一给定条件,且满足条件的数据点个数(用keep表示)满足指定阈值的次数。 | BOOLEAN | `[keep >=/>/=/!=/= threshold`,`threshold`类型为`INT64`
`ignoreNull`:可选,默认为`true`;为`true`表示忽略null值,即如果中间出现null值,直接忽略,不会打断连续性;为`false`表示不忽略null值,即如果中间出现null值,会打断连续性 | INT64 | -| TIME_DURATION | 求某一列最大一个不为NULL的值所在时间戳与最小一个不为NULL的值所在时间戳的时间戳差 | 所有类型 | 无 | INT64 | -| MODE | 求众数。注意:
1.输入序列的不同值个数过多时会有内存异常风险;
2.如果所有元素出现的频次相同,即没有众数,则返回对应时间戳最小的值;
3.如果有多个众数,则返回对应时间戳最小的众数。 | 所有类型 | 无 | 与输入类型一致 | -| COUNT_TIME | 查询结果集的时间戳的数量。与 align by device 搭配使用时,得到的结果是每个设备的结果集的时间戳的数量。 | 所有类型,输入参数只能为* | 无 | INT64 | -| MAX_BY | MAX_BY(x, y) 求二元输入 x 和 y 在 y 最大时对应的 x 的值。MAX_BY(time, x) 返回 x 取最大值时对应的时间戳。 | 第一个输入 x 可以是任意类型,第二个输入 y 只能是 INT32 INT64 FLOAT DOUBLE | 无 | 与第一个输入 x 的数据类型一致 | -| MIN_BY | MIN_BY(x, y) 求二元输入 x 和 y 在 y 最小时对应的 x 的值。MIN_BY(time, x) 返回 x 取最小值时对应的时间戳。 | 第一个输入 x 可以是任意类型,第二个输入 y 只能是 INT32 INT64 FLOAT DOUBLE | 无 | 与第一个输入 x 的数据类型一致 | - - -### COUNT_IF - -#### 语法 -```sql -count_if(predicate, [keep >=/>/=/!=/注意: count_if 当前暂不支持与 group by time 的 SlidingWindow 一起使用 - -#### 使用示例 - -##### 原始数据 - -``` -+-----------------------------+-------------+-------------+ -| Time|root.db.d1.s1|root.db.d1.s2| -+-----------------------------+-------------+-------------+ -|1970-01-01T08:00:00.001+08:00| 0| 0| -|1970-01-01T08:00:00.002+08:00| null| 0| -|1970-01-01T08:00:00.003+08:00| 0| 0| -|1970-01-01T08:00:00.004+08:00| 0| 0| -|1970-01-01T08:00:00.005+08:00| 1| 0| -|1970-01-01T08:00:00.006+08:00| 1| 0| -|1970-01-01T08:00:00.007+08:00| 1| 0| -|1970-01-01T08:00:00.008+08:00| 0| 0| -|1970-01-01T08:00:00.009+08:00| 0| 0| -|1970-01-01T08:00:00.010+08:00| 0| 0| -+-----------------------------+-------------+-------------+ -``` - -##### 不使用ignoreNull参数(忽略null) - -SQL: -```sql -select count_if(s1=0 & s2=0, 3), count_if(s1=1 & s2=0, 3) from root.db.d1 -``` - -输出: -``` -+--------------------------------------------------+--------------------------------------------------+ -|count_if(root.db.d1.s1 = 0 & root.db.d1.s2 = 0, 3)|count_if(root.db.d1.s1 = 1 & root.db.d1.s2 = 0, 3)| -+--------------------------------------------------+--------------------------------------------------+ -| 2| 1| -+--------------------------------------------------+-------------------------------------------------- -``` - -##### 使用ignoreNull参数 - -SQL: -```sql -select count_if(s1=0 & s2=0, 3, 'ignoreNull'='false'), count_if(s1=1 & s2=0, 3, 'ignoreNull'='false') from root.db.d1 -``` - -输出: -``` -+------------------------------------------------------------------------+------------------------------------------------------------------------+ -|count_if(root.db.d1.s1 = 0 & root.db.d1.s2 = 0, 3, "ignoreNull"="false")|count_if(root.db.d1.s1 = 1 & root.db.d1.s2 = 0, 3, "ignoreNull"="false")| -+------------------------------------------------------------------------+------------------------------------------------------------------------+ -| 1| 1| -+------------------------------------------------------------------------+------------------------------------------------------------------------+ -``` - -### TIME_DURATION -#### 语法 -```sql - time_duration(Path) -``` -#### 使用示例 -##### 准备数据 -``` -+----------+-------------+ -| Time|root.db.d1.s1| -+----------+-------------+ -| 1| 70| -| 3| 10| -| 4| 303| -| 6| 110| -| 7| 302| -| 8| 110| -| 9| 60| -| 10| 70| -|1677570934| 30| -+----------+-------------+ -``` -##### 写入语句 -```sql -"CREATE DATABASE root.db", -"CREATE TIMESERIES root.db.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN tags(city=Beijing)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(1, 2, 10, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(2, null, 20, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(3, 10, 0, null)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(4, 303, 30, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(5, null, 20, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(6, 110, 20, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(7, 302, 20, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(8, 110, null, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(9, 60, 20, true)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(10,70, 20, null)", -"INSERT INTO root.db.d1(timestamp,s1,s2,s3) values(1677570934, 30, 0, true)", -``` - -查询: -```sql -select time_duration(s1) from root.db.d1 -``` - -输出 -``` -+----------------------------+ -|time_duration(root.db.d1.s1)| -+----------------------------+ -| 1677570933| -+----------------------------+ -``` -> 注:若数据点只有一个,则返回0,若数据点为null,则返回null。 - -### COUNT_TIME -#### 语法 -```sql - count_time(*) -``` -#### 使用示例 -##### 准备数据 -``` -+----------+-------------+-------------+-------------+-------------+ -| Time|root.db.d1.s1|root.db.d1.s2|root.db.d2.s1|root.db.d2.s2| -+----------+-------------+-------------+-------------+-------------+ -| 0| 0| null| null| 0| -| 1| null| 1| 1| null| -| 2| null| 2| 2| null| -| 4| 4| null| null| 4| -| 5| 5| 5| 5| 5| -| 7| null| 7| 7| null| -| 8| 8| 8| 8| 8| -| 9| null| 9| null| null| -+----------+-------------+-------------+-------------+-------------+ -``` -##### 写入语句 -```sql -CREATE DATABASE root.db; -CREATE TIMESERIES root.db.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN; -CREATE TIMESERIES root.db.d1.s2 WITH DATATYPE=INT32, ENCODING=PLAIN; -CREATE TIMESERIES root.db.d2.s1 WITH DATATYPE=INT32, ENCODING=PLAIN; -CREATE TIMESERIES root.db.d2.s2 WITH DATATYPE=INT32, ENCODING=PLAIN; -INSERT INTO root.db.d1(time, s1) VALUES(0, 0), (4,4), (5,5), (8,8); -INSERT INTO root.db.d1(time, s2) VALUES(1, 1), (2,2), (5,5), (7,7), (8,8), (9,9); -INSERT INTO root.db.d2(time, s1) VALUES(1, 1), (2,2), (5,5), (7,7), (8,8); -INSERT INTO root.db.d2(time, s2) VALUES(0, 0), (4,4), (5,5), (8,8); -``` - -查询示例1: -```sql -select count_time(*) from root.db.** -``` - -输出 -``` -+-------------+ -|count_time(*)| -+-------------+ -| 8| -+-------------+ -``` - -查询示例2: -```sql -select count_time(*) from root.db.d1, root.db.d2 -``` - -输出 -``` -+-------------+ -|count_time(*)| -+-------------+ -| 8| -+-------------+ -``` - -查询示例3: -```sql -select count_time(*) from root.db.** group by([0, 10), 2ms) -``` - -输出 -``` -+-----------------------------+-------------+ -| Time|count_time(*)| -+-----------------------------+-------------+ -|1970-01-01T08:00:00.000+08:00| 2| -|1970-01-01T08:00:00.002+08:00| 1| -|1970-01-01T08:00:00.004+08:00| 2| -|1970-01-01T08:00:00.006+08:00| 1| -|1970-01-01T08:00:00.008+08:00| 2| -+-----------------------------+-------------+ -``` - -查询示例4: -```sql -select count_time(*) from root.db.** group by([0, 10), 2ms) align by device -``` - -输出 -``` -+-----------------------------+----------+-------------+ -| Time| Device|count_time(*)| -+-----------------------------+----------+-------------+ -|1970-01-01T08:00:00.000+08:00|root.db.d1| 2| -|1970-01-01T08:00:00.002+08:00|root.db.d1| 1| -|1970-01-01T08:00:00.004+08:00|root.db.d1| 2| -|1970-01-01T08:00:00.006+08:00|root.db.d1| 1| -|1970-01-01T08:00:00.008+08:00|root.db.d1| 2| -|1970-01-01T08:00:00.000+08:00|root.db.d2| 2| -|1970-01-01T08:00:00.002+08:00|root.db.d2| 1| -|1970-01-01T08:00:00.004+08:00|root.db.d2| 2| -|1970-01-01T08:00:00.006+08:00|root.db.d2| 1| -|1970-01-01T08:00:00.008+08:00|root.db.d2| 1| -+-----------------------------+----------+-------------+ - -``` - -> 注: -> 1. count_time里的表达式只能为*。 -> 2. count_time不能和其他的聚合函数一起使用。 -> 3. having语句里不支持使用count_time, 使用count_time聚合函数时不支持使用having语句。 -> 4. count_time不支持与group by level, group by tag一起使用。 - -### MAX_BY - -#### 功能定义 -max_by(x, y): 返回 y 最大时对应时间戳下的 x 值。 -- max_by 必须有两个输入参数 x 和 y。 -- 第一个输入可以为 time 关键字, max_by(time, x) 返回 x 取最大值时对应的时间戳。 -- 如果 y 最大时对应的时间戳下 x 为 null,则返回 null。 -- 如果 y 可以在多个时间戳下取得最大值,取最大值中最小时间戳对应的 x 值。 -- 与 IoTDB max_value 保持一致,仅支持 INT32、INT64、FLOAT、DOUBLE 作为 y 的输入,支持所有六种类型作为 x 的输入。 -- x, y 的输入均不允许为具体数值。 - - -#### 语法 -```sql -select max_by(x, y) from root.sg -select max_by(time, x) from root.sg -``` - -#### 使用示例 - -##### 原始数据 -```sql -IoTDB> select * from root.test -+-----------------------------+-----------+-----------+ -| Time|root.test.a|root.test.b| -+-----------------------------+-----------+-----------+ -|1970-01-01T08:00:00.001+08:00| 1.0| 10.0| -|1970-01-01T08:00:00.002+08:00| 2.0| 10.0| -|1970-01-01T08:00:00.003+08:00| 3.0| 3.0| -|1970-01-01T08:00:00.004+08:00| 10.0| 10.0| -|1970-01-01T08:00:00.005+08:00| 10.0| 12.0| -|1970-01-01T08:00:00.006+08:00| 6.0| 6.0| -+-----------------------------+-----------+-----------+ -``` -##### 查询示例 -查询最大值对应的时间戳: -```sql -IoTDB> select max_by(time, a), max_value(a) from root.test -+-------------------------+------------------------+ -|max_by(Time, root.test.a)| max_value(root.test.a)| -+-------------------------+------------------------+ -| 4| 10.0| -+-------------------------+------------------------+ -``` - -求 a 最大时对应的 b 值: -```sql -IoTDB> select max_by(b, a) from root.test -+--------------------------------+ -|max_by(root.test.b, root.test.a)| -+--------------------------------+ -| 10.0| -+--------------------------------+ -``` - -结合表达式使用: -```sql -IoTDB> select max_by(b + 1, a * 2) from root.test -+----------------------------------------+ -|max_by(root.test.b + 1, root.test.a * 2)| -+----------------------------------------+ -| 11.0| -+----------------------------------------+ -``` - -结合 group by time 子句使用: -```sql -IoTDB> select max_by(b, a) from root.test group by ([0,7),4ms) -+-----------------------------+--------------------------------+ -| Time|max_by(root.test.b, root.test.a)| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.000+08:00| 3.0| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.004+08:00| 10.0| -+-----------------------------+--------------------------------+ -``` - -结合 having 子句使用: -```sql -IoTDB> select max_by(b, a) from root.test group by ([0,7),4ms) having max_by(b, a) > 4.0 -+-----------------------------+--------------------------------+ -| Time|max_by(root.test.b, root.test.a)| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.004+08:00| 10.0| -+-----------------------------+--------------------------------+ -``` -结合 order by 子句使用: -```sql -IoTDB> select max_by(b, a) from root.test group by ([0,7),4ms) order by time desc -+-----------------------------+--------------------------------+ -| Time|max_by(root.test.b, root.test.a)| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.004+08:00| 10.0| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.000+08:00| 3.0| -+-----------------------------+--------------------------------+ -``` - -#### 功能定义 -min_by(x, y): 返回 y 最小时对应时间戳下的 x 值。 -- min_by 必须有两个输入参数 x 和 y。 -- 第一个输入可以为 time 关键字, min_by(time, x) 返回 x 取最小值时对应的时间戳。 -- 如果 y 最大时对应的时间戳下 x 为 null,则返回 null。 -- 如果 y 可以在多个时间戳下取得最小值,取最小值中最小时间戳对应的 x 值。 -- 与 IoTDB min_value 保持一致,仅支持 INT32、INT64、FLOAT、DOUBLE 作为 y 的输入,支持所有六种类型作为 x 的输入。 -- x, y 的输入均不允许为具体数值。 - -#### 语法 -```sql -select min_by(x, y) from root.sg -select min_by(time, x) from root.sg -``` - -#### 使用示例 - -##### 原始数据 -```sql -IoTDB> select * from root.test -+-----------------------------+-----------+-----------+ -| Time|root.test.a|root.test.b| -+-----------------------------+-----------+-----------+ -|1970-01-01T08:00:00.001+08:00| 4.0| 10.0| -|1970-01-01T08:00:00.002+08:00| 3.0| 10.0| -|1970-01-01T08:00:00.003+08:00| 2.0| 3.0| -|1970-01-01T08:00:00.004+08:00| 1.0| 10.0| -|1970-01-01T08:00:00.005+08:00| 1.0| 12.0| -|1970-01-01T08:00:00.006+08:00| 6.0| 6.0| -+-----------------------------+-----------+-----------+ -``` -##### 查询示例 -查询最小值对应的时间戳: -```sql -IoTDB> select min_by(time, a), min_value(a) from root.test -+-------------------------+------------------------+ -|min_by(Time, root.test.a)| min_value(root.test.a)| -+-------------------------+------------------------+ -| 4| 1.0| -+-------------------------+------------------------+ -``` - -求 a 最小时对应的 b 值: -```sql -IoTDB> select min_by(b, a) from root.test -+--------------------------------+ -|min_by(root.test.b, root.test.a)| -+--------------------------------+ -| 10.0| -+--------------------------------+ -``` - -结合表达式使用: -```sql -IoTDB> select min_by(b + 1, a * 2) from root.test -+----------------------------------------+ -|min_by(root.test.b + 1, root.test.a * 2)| -+----------------------------------------+ -| 11.0| -+----------------------------------------+ -``` - -结合 group by time 子句使用: -```sql -IoTDB> select min_by(b, a) from root.test group by ([0,7),4ms) -+-----------------------------+--------------------------------+ -| Time|min_by(root.test.b, root.test.a)| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.000+08:00| 3.0| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.004+08:00| 10.0| -+-----------------------------+--------------------------------+ -``` - -结合 having 子句使用: -```sql -IoTDB> select min_by(b, a) from root.test group by ([0,7),4ms) having max_by(b, a) > 4.0 -+-----------------------------+--------------------------------+ -| Time|min_by(root.test.b, root.test.a)| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.004+08:00| 10.0| -+-----------------------------+--------------------------------+ -``` - -结合 order by 子句使用: -```sql -IoTDB> select min_by(b, a) from root.test group by ([0,7),4ms) order by time desc -+-----------------------------+--------------------------------+ -| Time|min_by(root.test.b, root.test.a)| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.004+08:00| 10.0| -+-----------------------------+--------------------------------+ -|1970-01-01T08:00:00.000+08:00| 3.0| -+-----------------------------+--------------------------------+ -``` - - - -## 算数运算符和函数 - -### 算数运算符 - -#### 一元算数运算符 - -支持的运算符:`+`, `-` - -输入数据类型要求:`INT32`, `INT64`, `FLOAT`, `DOUBLE` - -输出数据类型:与输入数据类型一致 - -#### 二元算数运算符 - -支持的运算符:`+`, `-`, `*`, `/`, `%` - -输入数据类型要求:`INT32`, `INT64`, `FLOAT`和`DOUBLE` - -输出数据类型:`DOUBLE` - -注意:当某个时间戳下左操作数和右操作数都不为空(`null`)时,二元运算操作才会有输出结果 - -#### 使用示例 - -例如: - -```sql -select s1, - s1, s2, + s2, s1 + s2, s1 - s2, s1 * s2, s1 / s2, s1 % s2 from root.sg.d1 -``` - -结果: - -``` -+-----------------------------+-------------+--------------+-------------+-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ -| Time|root.sg.d1.s1|-root.sg.d1.s1|root.sg.d1.s2|root.sg.d1.s2|root.sg.d1.s1 + root.sg.d1.s2|root.sg.d1.s1 - root.sg.d1.s2|root.sg.d1.s1 * root.sg.d1.s2|root.sg.d1.s1 / root.sg.d1.s2|root.sg.d1.s1 % root.sg.d1.s2| -+-----------------------------+-------------+--------------+-------------+-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| -1.0| 1.0| 1.0| 2.0| 0.0| 1.0| 1.0| 0.0| -|1970-01-01T08:00:00.002+08:00| 2.0| -2.0| 2.0| 2.0| 4.0| 0.0| 4.0| 1.0| 0.0| -|1970-01-01T08:00:00.003+08:00| 3.0| -3.0| 3.0| 3.0| 6.0| 0.0| 9.0| 1.0| 0.0| -|1970-01-01T08:00:00.004+08:00| 4.0| -4.0| 4.0| 4.0| 8.0| 0.0| 16.0| 1.0| 0.0| -|1970-01-01T08:00:00.005+08:00| 5.0| -5.0| 5.0| 5.0| 10.0| 0.0| 25.0| 1.0| 0.0| -+-----------------------------+-------------+--------------+-------------+-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ -Total line number = 5 -It costs 0.014s -``` - -### 数学函数 - -目前 IoTDB 支持下列数学函数,这些数学函数的行为与这些函数在 Java Math 标准库中对应实现的行为一致。 - -| 函数名 | 输入序列类型 | 输出序列类型 | 必要属性参数 | Java 标准库中的对应实现 | -| ------- | ------------------------------ | ------------------------ |-----------| ------------------------------------------------------------ | -| SIN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#sin(double) | -| COS | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#cos(double) | -| TAN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#tan(double) | -| ASIN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#asin(double) | -| ACOS | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#acos(double) | -| ATAN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#atan(double) | -| SINH | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#sinh(double) | -| COSH | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#cosh(double) | -| TANH | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#tanh(double) | -| DEGREES | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#toDegrees(double) | -| RADIANS | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#toRadians(double) | -| ABS | INT32 / INT64 / FLOAT / DOUBLE | 与输入序列的实际类型一致 | | Math#abs(int) / Math#abs(long) /Math#abs(float) /Math#abs(double) | -| SIGN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#signum(double) | -| CEIL | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#ceil(double) | -| FLOOR | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#floor(double) | -| ROUND | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE |`places`:四舍五入有效位数,正数为小数点后面的有效位数,负数为整数位的有效位数 | Math#rint(Math#pow(10,places))/Math#pow(10,places)| -| EXP | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#exp(double) | -| LN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#log(double) | -| LOG10 | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#log10(double) | -| SQRT | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#sqrt(double) | - -例如: - -``` sql -select s1, sin(s1), cos(s1), tan(s1) from root.sg1.d1 limit 5 offset 1000; -``` - -结果: - -``` -+-----------------------------+-------------------+-------------------+--------------------+-------------------+ -| Time| root.sg1.d1.s1|sin(root.sg1.d1.s1)| cos(root.sg1.d1.s1)|tan(root.sg1.d1.s1)| -+-----------------------------+-------------------+-------------------+--------------------+-------------------+ -|2020-12-10T17:11:49.037+08:00|7360723084922759782| 0.8133527237573284| 0.5817708713544664| 1.3980636773094157| -|2020-12-10T17:11:49.038+08:00|4377791063319964531|-0.8938962705202537| 0.4482738644511651| -1.994085181866842| -|2020-12-10T17:11:49.039+08:00|7972485567734642915| 0.9627757585308978|-0.27030138509681073|-3.5618602479083545| -|2020-12-10T17:11:49.040+08:00|2508858212791964081|-0.6073417341629443| -0.7944406950452296| 0.7644897069734913| -|2020-12-10T17:11:49.041+08:00|2817297431185141819|-0.8419358900502509| -0.5395775727782725| 1.5603611649667768| -+-----------------------------+-------------------+-------------------+--------------------+-------------------+ -Total line number = 5 -It costs 0.008s -``` -#### ROUND - -例如: -```sql -select s4,round(s4),round(s4,2),round(s4,-1) from root.sg1.d1 -``` - -```sql -+-----------------------------+-------------+--------------------+----------------------+-----------------------+ -| Time|root.db.d1.s4|ROUND(root.db.d1.s4)|ROUND(root.db.d1.s4,2)|ROUND(root.db.d1.s4,-1)| -+-----------------------------+-------------+--------------------+----------------------+-----------------------+ -|1970-01-01T08:00:00.001+08:00| 101.14345| 101.0| 101.14| 100.0| -|1970-01-01T08:00:00.002+08:00| 20.144346| 20.0| 20.14| 20.0| -|1970-01-01T08:00:00.003+08:00| 20.614372| 21.0| 20.61| 20.0| -|1970-01-01T08:00:00.005+08:00| 20.814346| 21.0| 20.81| 20.0| -|1970-01-01T08:00:00.006+08:00| 60.71443| 61.0| 60.71| 60.0| -|2023-03-13T16:16:19.764+08:00| 10.143425| 10.0| 10.14| 10.0| -+-----------------------------+-------------+--------------------+----------------------+-----------------------+ -Total line number = 6 -It costs 0.059s -``` - - - -## 比较运算符和函数 - -### 基本比较运算符 - -- 输入数据类型: `INT32`, `INT64`, `FLOAT`, `DOUBLE`。 -- 注意:会将所有数据转换为`DOUBLE`类型后进行比较。`==`和`!=`可以直接比较两个`BOOLEAN`。 -- 返回类型:`BOOLEAN`。 - -|运算符 |含义| -|----------------------------|-----------| -|`>` |大于| -|`>=` |大于等于| -|`<` |小于| -|`<=` |小于等于| -|`==` |等于| -|`!=` / `<>` |不等于| - -**示例:** - -```sql -select a, b, a > 10, a <= b, !(a <= b), a > 10 && a > b from root.test; -``` - -运行结果 -``` -IoTDB> select a, b, a > 10, a <= b, !(a <= b), a > 10 && a > b from root.test; -+-----------------------------+-----------+-----------+----------------+--------------------------+---------------------------+------------------------------------------------+ -| Time|root.test.a|root.test.b|root.test.a > 10|root.test.a <= root.test.b|!root.test.a <= root.test.b|(root.test.a > 10) & (root.test.a > root.test.b)| -+-----------------------------+-----------+-----------+----------------+--------------------------+---------------------------+------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 23| 10.0| true| false| true| true| -|1970-01-01T08:00:00.002+08:00| 33| 21.0| true| false| true| true| -|1970-01-01T08:00:00.004+08:00| 13| 15.0| true| true| false| false| -|1970-01-01T08:00:00.005+08:00| 26| 0.0| true| false| true| true| -|1970-01-01T08:00:00.008+08:00| 1| 22.0| false| true| false| false| -|1970-01-01T08:00:00.010+08:00| 23| 12.0| true| false| true| true| -+-----------------------------+-----------+-----------+----------------+--------------------------+---------------------------+------------------------------------------------+ -``` - -### `BETWEEN ... AND ...` 运算符 - -|运算符 |含义| -|----------------------------|-----------| -|`BETWEEN ... AND ...` |在指定范围内| -|`NOT BETWEEN ... AND ...` |不在指定范围内| - -**示例:** 选择区间 [36.5,40] 内或之外的数据: - -```sql -select temperature from root.sg1.d1 where temperature between 36.5 and 40; -``` - -```sql -select temperature from root.sg1.d1 where temperature not between 36.5 and 40; -``` - -### 模糊匹配运算符 - -对于 TEXT 类型的数据,支持使用 `Like` 和 `Regexp` 运算符对数据进行模糊匹配 - -|运算符 |含义| -|----------------------------|-----------| -|`LIKE` |匹配简单模式| -|`NOT LIKE` |无法匹配简单模式| -|`REGEXP` |匹配正则表达式| -|`NOT REGEXP` |无法匹配正则表达式| - -输入数据类型:`TEXT` - -返回类型:`BOOLEAN` - -#### 使用 `Like` 进行模糊匹配 - -**匹配规则:** - -- `%` 表示任意0个或多个字符。 -- `_` 表示任意单个字符。 - -**示例 1:** 查询 `root.sg.d1` 下 `value` 含有`'cc'`的数据。 - -```shell -IoTDB> select * from root.sg.d1 where value like '%cc%' -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:00.000+08:00| aabbccdd| -|2017-11-01T00:00:01.000+08:00| cc| -+-----------------------------+----------------+ -Total line number = 2 -It costs 0.002s -``` - -**示例 2:** 查询 `root.sg.d1` 下 `value` 中间为 `'b'`、前后为任意单个字符的数据。 - -```shell -IoTDB> select * from root.sg.device where value like '_b_' -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:02.000+08:00| abc| -+-----------------------------+----------------+ -Total line number = 1 -It costs 0.002s -``` - -#### 使用 `Regexp` 进行模糊匹配 - -需要传入的过滤条件为 **Java 标准库风格的正则表达式**。 - -**常见的正则匹配举例:** - -``` -长度为3-20的所有字符:^.{3,20}$ -大写英文字符:^[A-Z]+$ -数字和英文字符:^[A-Za-z0-9]+$ -以a开头的:^a.* -``` - -**示例 1:** 查询 root.sg.d1 下 value 值为26个英文字符组成的字符串。 - -```shell -IoTDB> select * from root.sg.d1 where value regexp '^[A-Za-z]+$' -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:00.000+08:00| aabbccdd| -|2017-11-01T00:00:01.000+08:00| cc| -+-----------------------------+----------------+ -Total line number = 2 -It costs 0.002s -``` - -**示例 2:** 查询 root.sg.d1 下 value 值为26个小写英文字符组成的字符串且时间大于100的。 - -```shell -IoTDB> select * from root.sg.d1 where value regexp '^[a-z]+$' and time > 100 -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:00.000+08:00| aabbccdd| -|2017-11-01T00:00:01.000+08:00| cc| -+-----------------------------+----------------+ -Total line number = 2 -It costs 0.002s -``` - -**示例 3:** - -```sql -select b, b like '1%', b regexp '[0-2]' from root.test; -``` - -运行结果 -``` -+-----------------------------+-----------+-------------------------+--------------------------+ -| Time|root.test.b|root.test.b LIKE '^1.*?$'|root.test.b REGEXP '[0-2]'| -+-----------------------------+-----------+-------------------------+--------------------------+ -|1970-01-01T08:00:00.001+08:00| 111test111| true| true| -|1970-01-01T08:00:00.003+08:00| 333test333| false| false| -+-----------------------------+-----------+-------------------------+--------------------------+ -``` - -### `IS NULL` 运算符 - -|运算符 |含义| -|----------------------------|-----------| -|`IS NULL` |是空值| -|`IS NOT NULL` |不是空值| - -**示例 1:** 选择值为空的数据: - -```sql -select code from root.sg1.d1 where temperature is null; -``` - -**示例 2:** 选择值为非空的数据: - -```sql -select code from root.sg1.d1 where temperature is not null; -``` - -### `IN` 运算符 - -|运算符 |含义| -|----------------------------|-----------| -|`IN` / `CONTAINS` |是指定列表中的值| -|`NOT IN` / `NOT CONTAINS` |不是指定列表中的值| - -输入数据类型:`All Types` - -返回类型 `BOOLEAN` - -**注意:请确保集合中的值可以被转为输入数据的类型。** -> 例如: -> ->`s1 in (1, 2, 3, 'test')`,`s1`的数据类型是`INT32` -> -> 我们将会抛出异常,因为`'test'`不能被转为`INT32`类型 - -**示例 1:** 选择值在特定范围内的数据: - -```sql -select code from root.sg1.d1 where code in ('200', '300', '400', '500'); -``` - -**示例 2:** 选择值在特定范围外的数据: - -```sql -select code from root.sg1.d1 where code not in ('200', '300', '400', '500'); -``` - -**示例 3:** - -```sql -select a, a in (1, 2) from root.test; -``` - -输出2: -``` -+-----------------------------+-----------+--------------------+ -| Time|root.test.a|root.test.a IN (1,2)| -+-----------------------------+-----------+--------------------+ -|1970-01-01T08:00:00.001+08:00| 1| true| -|1970-01-01T08:00:00.003+08:00| 3| false| -+-----------------------------+-----------+--------------------+ -``` - -### 条件函数 - -条件函数针对每个数据点进行条件判断,返回布尔值。 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| ON_OFF | INT32 / INT64 / FLOAT / DOUBLE | `threshold`:DOUBLE类型 | BOOLEAN 类型 | 返回`ts_value >= threshold`的bool值 | -| IN_RANGE | INT32 / INT64 / FLOAT / DOUBLE | `lower`:DOUBLE类型
`upper`:DOUBLE类型 | BOOLEAN类型 | 返回`ts_value >= lower && ts_value <= upper`的bool值 | | - -测试数据: - -``` -IoTDB> select ts from root.test; -+-----------------------------+------------+ -| Time|root.test.ts| -+-----------------------------+------------+ -|1970-01-01T08:00:00.001+08:00| 1| -|1970-01-01T08:00:00.002+08:00| 2| -|1970-01-01T08:00:00.003+08:00| 3| -|1970-01-01T08:00:00.004+08:00| 4| -+-----------------------------+------------+ -``` - -**示例 1:** - -SQL语句: -```sql -select ts, on_off(ts, 'threshold'='2') from root.test; -``` - -输出: -``` -IoTDB> select ts, on_off(ts, 'threshold'='2') from root.test; -+-----------------------------+------------+-------------------------------------+ -| Time|root.test.ts|on_off(root.test.ts, "threshold"="2")| -+-----------------------------+------------+-------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1| false| -|1970-01-01T08:00:00.002+08:00| 2| true| -|1970-01-01T08:00:00.003+08:00| 3| true| -|1970-01-01T08:00:00.004+08:00| 4| true| -+-----------------------------+------------+-------------------------------------+ -``` - -**示例 2:** - -Sql语句: -```sql -select ts, in_range(ts, 'lower'='2', 'upper'='3.1') from root.test; -``` - -输出: -``` -IoTDB> select ts, in_range(ts, 'lower'='2', 'upper'='3.1') from root.test; -+-----------------------------+------------+--------------------------------------------------+ -| Time|root.test.ts|in_range(root.test.ts, "lower"="2", "upper"="3.1")| -+-----------------------------+------------+--------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1| false| -|1970-01-01T08:00:00.002+08:00| 2| true| -|1970-01-01T08:00:00.003+08:00| 3| true| -|1970-01-01T08:00:00.004+08:00| 4| false| -+-----------------------------+------------+--------------------------------------------------+ -``` - - - -## 逻辑运算符 - -### 一元逻辑运算符 - -- 支持运算符:`!` -- 输入数据类型:`BOOLEAN`。 -- 输出数据类型:`BOOLEAN`。 -- 注意:`!`的优先级很高,记得使用括号调整优先级。 - -### 二元逻辑运算符 - -- 支持运算符 - - AND:`and`,`&`, `&&` - - OR:`or`,`|`,`||` - -- 输入数据类型:`BOOLEAN`。 - -- 返回类型 `BOOLEAN`。 - -- 注意:当某个时间戳下左操作数和右操作数都为`BOOLEAN`类型时,二元逻辑操作才会有输出结果。 - -**示例:** - -```sql -select a, b, a > 10, a <= b, !(a <= b), a > 10 && a > b from root.test; -``` - -运行结果 -``` -IoTDB> select a, b, a > 10, a <= b, !(a <= b), a > 10 && a > b from root.test; -+-----------------------------+-----------+-----------+----------------+--------------------------+---------------------------+------------------------------------------------+ -| Time|root.test.a|root.test.b|root.test.a > 10|root.test.a <= root.test.b|!root.test.a <= root.test.b|(root.test.a > 10) & (root.test.a > root.test.b)| -+-----------------------------+-----------+-----------+----------------+--------------------------+---------------------------+------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 23| 10.0| true| false| true| true| -|1970-01-01T08:00:00.002+08:00| 33| 21.0| true| false| true| true| -|1970-01-01T08:00:00.004+08:00| 13| 15.0| true| true| false| false| -|1970-01-01T08:00:00.005+08:00| 26| 0.0| true| false| true| true| -|1970-01-01T08:00:00.008+08:00| 1| 22.0| false| true| false| false| -|1970-01-01T08:00:00.010+08:00| 23| 12.0| true| false| true| true| -+-----------------------------+-----------+-----------+----------------+--------------------------+---------------------------+------------------------------------------------+ -``` - - - -## 字符串处理 - -### STRING_CONTAINS - -#### 函数简介 - -本函数判断字符串中是否存在子串 `s` - -**函数名:** STRING_CONTAINS - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** -+ `s`: 待搜寻的字符串。 - -**输出序列:** 输出单个序列,类型为 BOOLEAN。 - -#### 使用示例 - -``` sql -select s1, string_contains(s1, 's'='warn') from root.sg1.d4; -``` - -结果: - -``` -+-----------------------------+--------------+-------------------------------------------+ -| Time|root.sg1.d4.s1|string_contains(root.sg1.d4.s1, "s"="warn")| -+-----------------------------+--------------+-------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| warn:-8721| true| -|1970-01-01T08:00:00.002+08:00| error:-37229| false| -|1970-01-01T08:00:00.003+08:00| warn:1731| true| -+-----------------------------+--------------+-------------------------------------------+ -Total line number = 3 -It costs 0.007s -``` - -### STRING_MATCHES - -#### 函数简介 - -本函数判断字符串是否能够被正则表达式`regex`匹配。 - -**函数名:** STRING_MATCHES - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** -+ `regex`: Java 标准库风格的正则表达式。 - -**输出序列:** 输出单个序列,类型为 BOOLEAN。 - -#### 使用示例 - -``` sql -select s1, string_matches(s1, 'regex'='[^\\s]+37229') from root.sg1.d4; -``` - -结果: - -``` -+-----------------------------+--------------+------------------------------------------------------+ -| Time|root.sg1.d4.s1|string_matches(root.sg1.d4.s1, "regex"="[^\\s]+37229")| -+-----------------------------+--------------+------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| warn:-8721| false| -|1970-01-01T08:00:00.002+08:00| error:-37229| true| -|1970-01-01T08:00:00.003+08:00| warn:1731| false| -+-----------------------------+--------------+------------------------------------------------------+ -Total line number = 3 -It costs 0.007s -``` - -### Length - -#### 函数简介 - -本函数用于获取输入序列的长度。 - -**函数名:** LENGTH - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**输出序列:** 输出单个序列,类型为 INT32。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, length(s1) from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+----------------------+ -| Time|root.sg1.d1.s1|length(root.sg1.d1.s1)| -+-----------------------------+--------------+----------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| 6| -|1970-01-01T08:00:00.002+08:00| 22test22| 8| -+-----------------------------+--------------+----------------------+ -``` - -### Locate - -#### 函数简介 - -本函数用于获取`target`子串第一次出现在输入序列的位置,如果输入序列中不包含`target`则返回 -1 。 - -**函数名:** LOCATE - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** - -+ `target`: 需要被定位的子串。 -+ `reverse`: 指定是否需要倒序定位,默认值为`false`, 即从左至右定位。 - -**输出序列:** 输出单个序列,类型为INT32。 - -**提示:** 下标从 0 开始。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, locate(s1, "target"="1") from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+------------------------------------+ -| Time|root.sg1.d1.s1|locate(root.sg1.d1.s1, "target"="1")| -+-----------------------------+--------------+------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| 0| -|1970-01-01T08:00:00.002+08:00| 22test22| -1| -+-----------------------------+--------------+------------------------------------+ -``` - -另一个用于查询的 SQL 语句: - -```sql -select s1, locate(s1, "target"="1", "reverse"="true") from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+------------------------------------------------------+ -| Time|root.sg1.d1.s1|locate(root.sg1.d1.s1, "target"="1", "reverse"="true")| -+-----------------------------+--------------+------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| 5| -|1970-01-01T08:00:00.002+08:00| 22test22| -1| -+-----------------------------+--------------+------------------------------------------------------+ -``` - -### StartsWith - -#### 函数简介 - -本函数用于判断输入序列是否有指定前缀。 - -**函数名:** STARTSWITH - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** -+ `target`: 需要匹配的前缀。 - -**输出序列:** 输出单个序列,类型为 BOOLEAN。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, startswith(s1, "target"="1") from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+----------------------------------------+ -| Time|root.sg1.d1.s1|startswith(root.sg1.d1.s1, "target"="1")| -+-----------------------------+--------------+----------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| true| -|1970-01-01T08:00:00.002+08:00| 22test22| false| -+-----------------------------+--------------+----------------------------------------+ -``` - -### EndsWith - -#### 函数简介 - -本函数用于判断输入序列是否有指定后缀。 - -**函数名:** ENDSWITH - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** -+ `target`: 需要匹配的后缀。 - -**输出序列:** 输出单个序列,类型为 BOOLEAN。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, endswith(s1, "target"="1") from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+--------------------------------------+ -| Time|root.sg1.d1.s1|endswith(root.sg1.d1.s1, "target"="1")| -+-----------------------------+--------------+--------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| true| -|1970-01-01T08:00:00.002+08:00| 22test22| false| -+-----------------------------+--------------+--------------------------------------+ -``` - -### Concat - -#### 函数简介 - -本函数用于拼接输入序列和`target`字串。 - -**函数名:** CONCAT - -**输入序列:** 至少一个输入序列,类型为 TEXT。 - -**参数:** -+ `targets`: 一系列 K-V, key需要以`target`为前缀且不重复, value是待拼接的字符串。 -+ `series_behind`: 指定拼接时时间序列是否在后面,默认为`false`。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** -+ 如果输入序列是NULL, 跳过该序列的拼接。 -+ 函数只能将输入序列和`targets`区分开各自拼接。`concat(s1, "target1"="IoT", s2, "target2"="DB")`和 - `concat(s1, s2, "target1"="IoT", "target2"="DB")`得到的结果是一样的。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+--------------+ -| Time|root.sg1.d1.s1|root.sg1.d1.s2| -+-----------------------------+--------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| null| -|1970-01-01T08:00:00.002+08:00| 22test22| 2222test| -+-----------------------------+--------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, s2, concat(s1, s2, "target1"="IoT", "target2"="DB") from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+--------------+-----------------------------------------------------------------------+ -| Time|root.sg1.d1.s1|root.sg1.d1.s2|concat(root.sg1.d1.s1, root.sg1.d1.s2, "target1"="IoT", "target2"="DB")| -+-----------------------------+--------------+--------------+-----------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| null| 1test1IoTDB| -|1970-01-01T08:00:00.002+08:00| 22test22| 2222test| 22test222222testIoTDB| -+-----------------------------+--------------+--------------+-----------------------------------------------------------------------+ -``` - -另一个用于查询的 SQL 语句: - -```sql -select s1, s2, concat(s1, s2, "target1"="IoT", "target2"="DB", "series_behind"="true") from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+--------------+-----------------------------------------------------------------------------------------------+ -| Time|root.sg1.d1.s1|root.sg1.d1.s2|concat(root.sg1.d1.s1, root.sg1.d1.s2, "target1"="IoT", "target2"="DB", "series_behind"="true")| -+-----------------------------+--------------+--------------+-----------------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| null| IoTDB1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| 2222test| IoTDB22test222222test| -+-----------------------------+--------------+--------------+-----------------------------------------------------------------------------------------------+ -``` - -### Substring - -#### 函数简介 -提取字符串的子字符串,从指定的第一个字符开始,并在指定的字符数之后停止。下标从1开始。from 和 for的范围是 INT32 类型取值范围。 - -**函数名:** SUBSTRING - - -**输入序列:** 仅支持单个输入序列,类型为TEXT。 - -**参数:** -+ `from`: 指定子串开始下标。 -+ `for`: 指定多少个字符数后停止。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, substring(s1 from 1 for 2) from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+--------------------------------------+ -| Time|root.sg1.d1.s1|SUBSTRING(root.sg1.d1.s1 FROM 1 FOR 2)| -+-----------------------------+--------------+--------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| 1t| -|1970-01-01T08:00:00.002+08:00| 22test22| 22| -+-----------------------------+--------------+--------------------------------------+ -``` - -### Replace - -#### 函数简介 -将输入序列中的子串替换成目标子串。 - -**函数名:** REPLACE - - -**输入序列:** 仅支持单个输入序列,类型为TEXT。 - -**参数:** -+ 第一个参数: 需要替换的目标子串。 -+ 第二个参数: 要替换成的子串。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, replace(s1, 'es', 'tt') from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+-----------------------------------+ -| Time|root.sg1.d1.s1|REPLACE(root.sg1.d1.s1, 'es', 'tt')| -+-----------------------------+--------------+-----------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| 1tttt1| -|1970-01-01T08:00:00.002+08:00| 22test22| 22tttt22| -+-----------------------------+--------------+-----------------------------------+ -``` - -### Upper - -#### 函数简介 - -本函数用于将输入序列转化为大写。 - -**函数名:** UPPER - -**输入序列:** 仅支持单个输入序列,类型为TEXT。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| -|1970-01-01T08:00:00.002+08:00| 22test22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, upper(s1) from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+---------------------+ -| Time|root.sg1.d1.s1|upper(root.sg1.d1.s1)| -+-----------------------------+--------------+---------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| 1TEST1| -|1970-01-01T08:00:00.002+08:00| 22test22| 22TEST22| -+-----------------------------+--------------+---------------------+ -``` - -### Lower - -#### 函数简介 - -本函数用于将输入序列转换为小写。 - -**函数名:** LOWER - -**输入序列:** 仅支持单个输入序列,类型为TEXT。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s1| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1TEST1| -|1970-01-01T08:00:00.002+08:00| 22TEST22| -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, lower(s1) from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+---------------------+ -| Time|root.sg1.d1.s1|lower(root.sg1.d1.s1)| -+-----------------------------+--------------+---------------------+ -|1970-01-01T08:00:00.001+08:00| 1TEST1| 1test1| -|1970-01-01T08:00:00.002+08:00| 22TEST22| 22test22| -+-----------------------------+--------------+---------------------+ -``` - -### Trim - -#### 函数简介 - -本函数用于移除输入序列前后的空格。 - -**函数名:** TRIM - -**输入序列:** 仅支持单个输入序列,类型为TEXT。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** 如果输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+ -| Time|root.sg1.d1.s3| -+-----------------------------+--------------+ -|1970-01-01T08:00:00.002+08:00| 3querytest3| -|1970-01-01T08:00:00.003+08:00| 3querytest3 | -+-----------------------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s3, trim(s3) from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+--------------------+ -| Time|root.sg1.d1.s3|trim(root.sg1.d1.s3)| -+-----------------------------+--------------+--------------------+ -|1970-01-01T08:00:00.002+08:00| 3querytest3| 3querytest3| -|1970-01-01T08:00:00.003+08:00| 3querytest3 | 3querytest3| -+-----------------------------+--------------+--------------------+ -``` - -### StrCmp - -#### 函数简介 - -本函数用于比较两个输入序列。 如果值相同返回 `0` , 序列1的值小于序列2的值返回一个`负数`,序列1的值大于序列2的值返回一个`正数`。 - -**函数名:** StrCmp - -**输入序列:** 输入两个序列,类型均为 TEXT。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** 如果任何一个输入是NULL,返回NULL。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+--------------+--------------+ -| Time|root.sg1.d1.s1|root.sg1.d1.s2| -+-----------------------------+--------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| null| -|1970-01-01T08:00:00.002+08:00| 22test22| 2222test| -+-----------------------------+--------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select s1, s2, strcmp(s1, s2) from root.sg1.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------+--------------+--------------------------------------+ -| Time|root.sg1.d1.s1|root.sg1.d1.s2|strcmp(root.sg1.d1.s1, root.sg1.d1.s2)| -+-----------------------------+--------------+--------------+--------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1test1| null| null| -|1970-01-01T08:00:00.002+08:00| 22test22| 2222test| 66| -+-----------------------------+--------------+--------------+--------------------------------------+ -``` - -### StrReplace - -#### 函数简介 - -**非内置函数,需要注册数据质量函数库后才能使用**。本函数用于将文本中的子串替换为指定的字符串。 - -**函数名:** STRREPLACE - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** - -+ `target`: 需要替换的字符子串 -+ `replace`: 替换后的字符串。 -+ `limit`: 替换次数,大于等于 -1 的整数,默认为 -1 表示所有匹配的子串都会被替换。 -+ `offset`: 需要跳过的匹配次数,即前`offset`次匹配到的字符子串并不会被替换,默认为 0。 -+ `reverse`: 是否需要反向计数,默认为 false 即按照从左向右的次序。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2021-01-01T00:00:01.000+08:00| A,B,A+,B-| -|2021-01-01T00:00:02.000+08:00| A,A+,A,B+| -|2021-01-01T00:00:03.000+08:00| B+,B,B| -|2021-01-01T00:00:04.000+08:00| A+,A,A+,A| -|2021-01-01T00:00:05.000+08:00| A,B-,B,B| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select strreplace(s1, "target"=",", "replace"="/", "limit"="2") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------+ -| Time|strreplace(root.test.d1.s1, "target"=",",| -| | "replace"="/", "limit"="2")| -+-----------------------------+-----------------------------------------+ -|2021-01-01T00:00:01.000+08:00| A/B/A+,B-| -|2021-01-01T00:00:02.000+08:00| A/A+/A,B+| -|2021-01-01T00:00:03.000+08:00| B+/B/B| -|2021-01-01T00:00:04.000+08:00| A+/A/A+,A| -|2021-01-01T00:00:05.000+08:00| A/B-/B,B| -+-----------------------------+-----------------------------------------+ -``` - -另一个用于查询的 SQL 语句: - -```sql -select strreplace(s1, "target"=",", "replace"="/", "limit"="1", "offset"="1", "reverse"="true") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------------------+ -| Time|strreplace(root.test.d1.s1, "target"=",", "replace"= | -| | "|", "limit"="1", "offset"="1", "reverse"="true")| -+-----------------------------+-----------------------------------------------------+ -|2021-01-01T00:00:01.000+08:00| A,B/A+,B-| -|2021-01-01T00:00:02.000+08:00| A,A+/A,B+| -|2021-01-01T00:00:03.000+08:00| B+/B,B| -|2021-01-01T00:00:04.000+08:00| A+,A/A+,A| -|2021-01-01T00:00:05.000+08:00| A,B-/B,B| -+-----------------------------+-----------------------------------------------------+ -``` - -### RegexMatch - -#### 函数简介 - -**非内置函数,需要注册数据质量函数库后才能使用**。本函数用于正则表达式匹配文本中的具体内容并返回。 - -**函数名:** REGEXMATCH - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** - -+ `regex`: 匹配的正则表达式,支持所有 Java 正则表达式语法,比如`\d+\.\d+\.\d+\.\d+`将会匹配任意 IPv4 地址. -+ `group`: 输出的匹配组序号,根据 java.util.regex 规定,第 0 组为整个正则表达式,此后的组按照左括号出现的顺序依次编号。 - 如`A(B(CD))`中共有三个组,第 0 组`A(B(CD))`,第 1 组`B(CD)`和第 2 组`CD`。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -**提示:** 空值或无法匹配给定的正则表达式的数据点没有输出结果。 - -#### 使用示例 - - -输入序列: - -``` -+-----------------------------+-------------------------------+ -| Time| root.test.d1.s1| -+-----------------------------+-------------------------------+ -|2021-01-01T00:00:01.000+08:00| [192.168.0.1] [SUCCESS]| -|2021-01-01T00:00:02.000+08:00| [192.168.0.24] [SUCCESS]| -|2021-01-01T00:00:03.000+08:00| [192.168.0.2] [FAIL]| -|2021-01-01T00:00:04.000+08:00| [192.168.0.5] [SUCCESS]| -|2021-01-01T00:00:05.000+08:00| [192.168.0.124] [SUCCESS]| -+-----------------------------+-------------------------------+ -``` - -用于查询的 SQL 语句: - -```sql -select regexmatch(s1, "regex"="\d+\.\d+\.\d+\.\d+", "group"="0") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------------------------------------+ -| Time|regexmatch(root.test.d1.s1, "regex"="\d+\.\d+\.\d+\.\d+", "group"="0")| -+-----------------------------+----------------------------------------------------------------------+ -|2021-01-01T00:00:01.000+08:00| 192.168.0.1| -|2021-01-01T00:00:02.000+08:00| 192.168.0.24| -|2021-01-01T00:00:03.000+08:00| 192.168.0.2| -|2021-01-01T00:00:04.000+08:00| 192.168.0.5| -|2021-01-01T00:00:05.000+08:00| 192.168.0.124| -+-----------------------------+----------------------------------------------------------------------+ -``` - -### RegexReplace - -##### 函数简介 - -**非内置函数,需要注册数据质量函数库后才能使用**。本函数用于将文本中符合正则表达式的匹配结果替换为指定的字符串。 - -**函数名:** REGEXREPLACE - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** - -+ `regex`: 需要替换的正则表达式,支持所有 Java 正则表达式语法。 -+ `replace`: 替换后的字符串,支持 Java 正则表达式中的后向引用, - 形如'$1'指代了正则表达式`regex`中的第一个分组,并会在替换时自动填充匹配到的子串。 -+ `limit`: 替换次数,大于等于 -1 的整数,默认为 -1 表示所有匹配的子串都会被替换。 -+ `offset`: 需要跳过的匹配次数,即前`offset`次匹配到的字符子串并不会被替换,默认为 0。 -+ `reverse`: 是否需要反向计数,默认为 false 即按照从左向右的次序。 - -**输出序列:** 输出单个序列,类型为 TEXT。 - -##### 使用示例 - -输入序列: - -``` -+-----------------------------+-------------------------------+ -| Time| root.test.d1.s1| -+-----------------------------+-------------------------------+ -|2021-01-01T00:00:01.000+08:00| [192.168.0.1] [SUCCESS]| -|2021-01-01T00:00:02.000+08:00| [192.168.0.24] [SUCCESS]| -|2021-01-01T00:00:03.000+08:00| [192.168.0.2] [FAIL]| -|2021-01-01T00:00:04.000+08:00| [192.168.0.5] [SUCCESS]| -|2021-01-01T00:00:05.000+08:00| [192.168.0.124] [SUCCESS]| -+-----------------------------+-------------------------------+ -``` - -用于查询的 SQL 语句: - -```sql -select regexreplace(s1, "regex"="192\.168\.0\.(\d+)", "replace"="cluster-$1", "limit"="1") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------------------------+ -| Time|regexreplace(root.test.d1.s1, "regex"="192\.168\.0\.(\d+)",| -| | "replace"="cluster-$1", "limit"="1")| -+-----------------------------+-----------------------------------------------------------+ -|2021-01-01T00:00:01.000+08:00| [cluster-1] [SUCCESS]| -|2021-01-01T00:00:02.000+08:00| [cluster-24] [SUCCESS]| -|2021-01-01T00:00:03.000+08:00| [cluster-2] [FAIL]| -|2021-01-01T00:00:04.000+08:00| [cluster-5] [SUCCESS]| -|2021-01-01T00:00:05.000+08:00| [cluster-124] [SUCCESS]| -+-----------------------------+-----------------------------------------------------------+ -``` - -#### RegexSplit - -##### 函数简介 - -**非内置函数,需要注册数据质量函数库后才能使用**。本函数用于使用给定的正则表达式切分文本,并返回指定的项。 - -**函数名:** REGEXSPLIT - -**输入序列:** 仅支持单个输入序列,类型为 TEXT。 - -**参数:** - -+ `regex`: 用于分割文本的正则表达式,支持所有 Java 正则表达式语法,比如`['"]`将会匹配任意的英文引号`'`和`"`。 -+ `index`: 输出结果在切分后数组中的序号,需要是大于等于 -1 的整数,默认值为 -1 表示返回切分后数组的长度,其它非负整数即表示返回数组中对应位置的切分结果(数组的秩从 0 开始计数)。 - -**输出序列:** 输出单个序列,在`index`为 -1 时输出数据类型为 INT32,否则为 TEXT。 - -**提示:** 如果`index`超出了切分后结果数组的秩范围,例如使用`,`切分`0,1,2`时输入`index`为 3,则该数据点没有输出结果。 - -##### 使用示例 - - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2021-01-01T00:00:01.000+08:00| A,B,A+,B-| -|2021-01-01T00:00:02.000+08:00| A,A+,A,B+| -|2021-01-01T00:00:03.000+08:00| B+,B,B| -|2021-01-01T00:00:04.000+08:00| A+,A,A+,A| -|2021-01-01T00:00:05.000+08:00| A,B-,B,B| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select regexsplit(s1, "regex"=",", "index"="-1") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|regexsplit(root.test.d1.s1, "regex"=",", "index"="-1")| -+-----------------------------+------------------------------------------------------+ -|2021-01-01T00:00:01.000+08:00| 4| -|2021-01-01T00:00:02.000+08:00| 4| -|2021-01-01T00:00:03.000+08:00| 3| -|2021-01-01T00:00:04.000+08:00| 4| -|2021-01-01T00:00:05.000+08:00| 4| -+-----------------------------+------------------------------------------------------+ -``` - -另一个查询的 SQL 语句: - -```sql -select regexsplit(s1, "regex"=",", "index"="3") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------------------+ -| Time|regexsplit(root.test.d1.s1, "regex"=",", "index"="3")| -+-----------------------------+-----------------------------------------------------+ -|2021-01-01T00:00:01.000+08:00| B-| -|2021-01-01T00:00:02.000+08:00| B+| -|2021-01-01T00:00:04.000+08:00| A| -|2021-01-01T00:00:05.000+08:00| B| -+-----------------------------+-----------------------------------------------------+ -``` - - - -## 数据类型转换 - -### CAST - -#### 函数简介 - -当前 IoTDB 支持6种数据类型,其中包括 INT32、INT64、FLOAT、DOUBLE、BOOLEAN 以及 TEXT。当我们对数据进行查询或者计算时可能需要进行数据类型的转换, 比如说将 TEXT 转换为 INT32,或者提高数据精度,比如说将 FLOAT 转换为 DOUBLE。IoTDB 支持使用cast 函数对数据类型进行转换。 - -语法示例如下: - -```sql -SELECT cast(s1 as INT32) from root.sg -``` - -cast 函数语法形式上与 PostgreSQL 一致,AS 后指定的数据类型表明要转换成的目标类型,目前 IoTDB 支持的六种数据类型均可以在 cast 函数中使用,遵循的转换规则如下表所示,其中行表示原始数据类型,列表示要转化成的目标数据类型: - -| | **INT32** | **INT64** | **FLOAT** | **DOUBLE** | **BOOLEAN** | **TEXT** | -| ----------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------------------- | ----------------------- | ------------------------------------------------------------ | -------------------------------- | -| **INT32** | 不转化 | 直接转化 | 直接转化 | 直接转化 | !=0 : true
==0: false | String.valueOf() | -| **INT64** | 超出 INT32 范围:执行抛异常
否则:直接转化 | 不转化 | 直接转化 | 直接转化 | !=0L : true
==0: false | String.valueOf() | -| **FLOAT** | 超出 INT32 范围:执行抛异常
否则:四舍五入(Math.round()) | 超出 INT64 范围:执行抛异常
否则:四舍五入(Math.round()) | 不转化 | 直接转化 | !=0.0f : true
==0: false | String.valueOf() | -| **DOUBLE** | 超出 INT32 范围:执行抛异常
否则:四舍五入(Math.round()) | 超出 INT64 范围:执行抛异常
否则:四舍五入(Math.round()) | 超出 FLOAT 范围:执行抛异常
否则:直接转化 | 不转化 | !=0.0 : true
==0: false | String.valueOf() | -| **BOOLEAN** | true: 1
false: 0 | true: 1L
false: 0 | true: 1.0f
false: 0 | true: 1.0
false: 0 | 不转化 | true: "true"
false: "false" | -| **TEXT** | Integer.parseInt() | Long.parseLong() | Float.parseFloat() | Double.parseDouble() | text.toLowerCase =="true" : true
text.toLowerCase =="false" : false
其它情况:执行抛异常 | 不转化 | - -#### 使用示例 - -``` -// timeseries -IoTDB> show timeseries root.sg.d1.** -+-------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+ -| Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters| -+-------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+ -|root.sg.d1.s3| null| root.sg| FLOAT| PLAIN| SNAPPY|null| null| null| null| -|root.sg.d1.s4| null| root.sg| DOUBLE| PLAIN| SNAPPY|null| null| null| null| -|root.sg.d1.s5| null| root.sg| BOOLEAN| PLAIN| SNAPPY|null| null| null| null| -|root.sg.d1.s6| null| root.sg| TEXT| PLAIN| SNAPPY|null| null| null| null| -|root.sg.d1.s1| null| root.sg| INT32| PLAIN| SNAPPY|null| null| null| null| -|root.sg.d1.s2| null| root.sg| INT64| PLAIN| SNAPPY|null| null| null| null| -+-------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+ - -// data of timeseries -IoTDB> select * from root.sg.d1; -+-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+ -| Time|root.sg.d1.s3|root.sg.d1.s4|root.sg.d1.s5|root.sg.d1.s6|root.sg.d1.s1|root.sg.d1.s2| -+-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| 0.0| false| 10000| 0| 0| -|1970-01-01T08:00:00.001+08:00| 1.0| 1.0| false| 3| 1| 1| -|1970-01-01T08:00:00.002+08:00| 2.7| 2.7| true| TRue| 2| 2| -|1970-01-01T08:00:00.003+08:00| 3.33| 3.33| true| faLse| 3| 3| -+-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+ - -// cast BOOLEAN to other types -IoTDB> select cast(s5 as INT32), cast(s5 as INT64),cast(s5 as FLOAT),cast(s5 as DOUBLE), cast(s5 as TEXT) from root.sg.d1 -+-----------------------------+----------------------------+----------------------------+----------------------------+-----------------------------+---------------------------+ -| Time|CAST(root.sg.d1.s5 AS INT32)|CAST(root.sg.d1.s5 AS INT64)|CAST(root.sg.d1.s5 AS FLOAT)|CAST(root.sg.d1.s5 AS DOUBLE)|CAST(root.sg.d1.s5 AS TEXT)| -+-----------------------------+----------------------------+----------------------------+----------------------------+-----------------------------+---------------------------+ -|1970-01-01T08:00:00.000+08:00| 0| 0| 0.0| 0.0| false| -|1970-01-01T08:00:00.001+08:00| 0| 0| 0.0| 0.0| false| -|1970-01-01T08:00:00.002+08:00| 1| 1| 1.0| 1.0| true| -|1970-01-01T08:00:00.003+08:00| 1| 1| 1.0| 1.0| true| -+-----------------------------+----------------------------+----------------------------+----------------------------+-----------------------------+---------------------------+ - -// cast TEXT to numeric types -IoTDB> select cast(s6 as INT32), cast(s6 as INT64), cast(s6 as FLOAT), cast(s6 as DOUBLE) from root.sg.d1 where time < 2 -+-----------------------------+----------------------------+----------------------------+----------------------------+-----------------------------+ -| Time|CAST(root.sg.d1.s6 AS INT32)|CAST(root.sg.d1.s6 AS INT64)|CAST(root.sg.d1.s6 AS FLOAT)|CAST(root.sg.d1.s6 AS DOUBLE)| -+-----------------------------+----------------------------+----------------------------+----------------------------+-----------------------------+ -|1970-01-01T08:00:00.000+08:00| 10000| 10000| 10000.0| 10000.0| -|1970-01-01T08:00:00.001+08:00| 3| 3| 3.0| 3.0| -+-----------------------------+----------------------------+----------------------------+----------------------------+-----------------------------+ - -// cast TEXT to BOOLEAN -IoTDB> select cast(s6 as BOOLEAN) from root.sg.d1 where time >= 2 -+-----------------------------+------------------------------+ -| Time|CAST(root.sg.d1.s6 AS BOOLEAN)| -+-----------------------------+------------------------------+ -|1970-01-01T08:00:00.002+08:00| true| -|1970-01-01T08:00:00.003+08:00| false| -+-----------------------------+------------------------------+ -``` - - - -## 常序列生成函数 - -常序列生成函数用于生成所有数据点的值都相同的时间序列。 - -常序列生成函数接受一个或者多个时间序列输入,其输出的数据点的时间戳集合是这些输入序列时间戳集合的并集。 - -目前 IoTDB 支持如下常序列生成函数: - -| 函数名 | 必要的属性参数 | 输出序列类型 | 功能描述 | -| ------ | ------------------------------------------------------------ | -------------------------- | ------------------------------------------------------------ | -| CONST | `value`: 输出的数据点的值
`type`: 输出的数据点的类型,只能是 INT32 / INT64 / FLOAT / DOUBLE / BOOLEAN / TEXT | 由输入属性参数 `type` 决定 | 根据输入属性 `value` 和 `type` 输出用户指定的常序列。 | -| PI | 无 | DOUBLE | 常序列的值:`π` 的 `double` 值,圆的周长与其直径的比值,即圆周率,等于 *Java标准库* 中的`Math.PI`。 | -| E | 无 | DOUBLE | 常序列的值:`e` 的 `double` 值,自然对数的底,它等于 *Java 标准库* 中的 `Math.E`。 | - -例如: - -``` sql -select s1, s2, const(s1, 'value'='1024', 'type'='INT64'), pi(s2), e(s1, s2) from root.sg1.d1; -``` - -结果: - -``` -select s1, s2, const(s1, 'value'='1024', 'type'='INT64'), pi(s2), e(s1, s2) from root.sg1.d1; -+-----------------------------+--------------+--------------+-----------------------------------------------------+------------------+---------------------------------+ -| Time|root.sg1.d1.s1|root.sg1.d1.s2|const(root.sg1.d1.s1, "value"="1024", "type"="INT64")|pi(root.sg1.d1.s2)|e(root.sg1.d1.s1, root.sg1.d1.s2)| -+-----------------------------+--------------+--------------+-----------------------------------------------------+------------------+---------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| 0.0| 1024| 3.141592653589793| 2.718281828459045| -|1970-01-01T08:00:00.001+08:00| 1.0| null| 1024| null| 2.718281828459045| -|1970-01-01T08:00:00.002+08:00| 2.0| null| 1024| null| 2.718281828459045| -|1970-01-01T08:00:00.003+08:00| null| 3.0| null| 3.141592653589793| 2.718281828459045| -|1970-01-01T08:00:00.004+08:00| null| 4.0| null| 3.141592653589793| 2.718281828459045| -+-----------------------------+--------------+--------------+-----------------------------------------------------+------------------+---------------------------------+ -Total line number = 5 -It costs 0.005s -``` - - - -## 选择函数 - -目前 IoTDB 支持如下选择函数: - -| 函数名 | 输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能描述 | -| -------- | ------------------------------------- | ------------------------------------------------- | ------------------------ | ------------------------------------------------------------ | -| TOP_K | INT32 / INT64 / FLOAT / DOUBLE / TEXT | `k`: 最多选择的数据点数,必须大于 0 小于等于 1000 | 与输入序列的实际类型一致 | 返回某时间序列中值最大的`k`个数据点。若多于`k`个数据点的值并列最大,则返回时间戳最小的数据点。 | -| BOTTOM_K | INT32 / INT64 / FLOAT / DOUBLE / TEXT | `k`: 最多选择的数据点数,必须大于 0 小于等于 1000 | 与输入序列的实际类型一致 | 返回某时间序列中值最小的`k`个数据点。若多于`k`个数据点的值并列最小,则返回时间戳最小的数据点。 | - -例如: - -``` sql -select s1, top_k(s1, 'k'='2'), bottom_k(s1, 'k'='2') from root.sg1.d2 where time > 2020-12-10T20:36:15.530+08:00; -``` - -结果: - -``` -+-----------------------------+--------------------+------------------------------+---------------------------------+ -| Time| root.sg1.d2.s1|top_k(root.sg1.d2.s1, "k"="2")|bottom_k(root.sg1.d2.s1, "k"="2")| -+-----------------------------+--------------------+------------------------------+---------------------------------+ -|2020-12-10T20:36:15.531+08:00| 1531604122307244742| 1531604122307244742| null| -|2020-12-10T20:36:15.532+08:00|-7426070874923281101| null| null| -|2020-12-10T20:36:15.533+08:00|-7162825364312197604| -7162825364312197604| null| -|2020-12-10T20:36:15.534+08:00|-8581625725655917595| null| -8581625725655917595| -|2020-12-10T20:36:15.535+08:00|-7667364751255535391| null| -7667364751255535391| -+-----------------------------+--------------------+------------------------------+---------------------------------+ -Total line number = 5 -It costs 0.006s -``` - - - -## 区间查询函数 - -### 连续满足区间函数 - -连续满足条件区间函数用来查询所有满足指定条件的连续区间。 - -按返回值可分为两类: -1. 返回满足条件连续区间的起始时间戳和时间跨度(时间跨度为0表示此处只有起始时间这一个数据点满足条件) -2. 返回满足条件连续区间的起始时间戳和后面连续满足条件的点的个数(个数为1表示此处只有起始时间这一个数据点满足条件) - -| 函数名 | 输入序列类型 | 属性参数 | 输出序列类型 | 功能描述 | -|-------------------|--------------------------------------|------------------------------------------------|-------|------------------------------------------------------------------| -| ZERO_DURATION | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值0
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续为0(false)的开始时间与持续时间,持续时间t(单位ms)满足`t >= min && t <= max` | -| NON_ZERO_DURATION | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值0
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续不为0(false)的开始时间与持续时间,持续时间t(单位ms)满足`t >= min && t <= max` | | -| ZERO_COUNT | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值1
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续为0(false)的开始时间与其后数据点的个数,数据点个数n满足`n >= min && n <= max` | | -| NON_ZERO_COUNT | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值1
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续不为0(false)的开始时间与其后数据点的个数,数据点个数n满足`n >= min && n <= max` | | - -测试数据: -``` -IoTDB> select s1,s2,s3,s4,s5 from root.sg.d2; -+-----------------------------+-------------+-------------+-------------+-------------+-------------+ -| Time|root.sg.d2.s1|root.sg.d2.s2|root.sg.d2.s3|root.sg.d2.s4|root.sg.d2.s5| -+-----------------------------+-------------+-------------+-------------+-------------+-------------+ -|1970-01-01T08:00:00.000+08:00| 0| 0| 0.0| 0.0| false| -|1970-01-01T08:00:00.001+08:00| 1| 1| 1.0| 1.0| true| -|1970-01-01T08:00:00.002+08:00| 1| 1| 1.0| 1.0| true| -|1970-01-01T08:00:00.003+08:00| 0| 0| 0.0| 0.0| false| -|1970-01-01T08:00:00.004+08:00| 1| 1| 1.0| 1.0| true| -|1970-01-01T08:00:00.005+08:00| 0| 0| 0.0| 0.0| false| -|1970-01-01T08:00:00.006+08:00| 0| 0| 0.0| 0.0| false| -|1970-01-01T08:00:00.007+08:00| 1| 1| 1.0| 1.0| true| -+-----------------------------+-------------+-------------+-------------+-------------+-------------+ -``` - -sql: -```sql -select s1, zero_count(s1), non_zero_count(s2), zero_duration(s3), non_zero_duration(s4) from root.sg.d2; -``` - -结果: -``` -+-----------------------------+-------------+-------------------------+-----------------------------+----------------------------+--------------------------------+ -| Time|root.sg.d2.s1|zero_count(root.sg.d2.s1)|non_zero_count(root.sg.d2.s2)|zero_duration(root.sg.d2.s3)|non_zero_duration(root.sg.d2.s4)| -+-----------------------------+-------------+-------------------------+-----------------------------+----------------------------+--------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0| 1| null| 0| null| -|1970-01-01T08:00:00.001+08:00| 1| null| 2| null| 1| -|1970-01-01T08:00:00.002+08:00| 1| null| null| null| null| -|1970-01-01T08:00:00.003+08:00| 0| 1| null| 0| null| -|1970-01-01T08:00:00.004+08:00| 1| null| 1| null| 0| -|1970-01-01T08:00:00.005+08:00| 0| 2| null| 1| null| -|1970-01-01T08:00:00.006+08:00| 0| null| null| null| null| -|1970-01-01T08:00:00.007+08:00| 1| null| 1| null| 0| -+-----------------------------+-------------+-------------------------+-----------------------------+----------------------------+--------------------------------+ -``` - - - -## 趋势计算函数 - -目前 IoTDB 支持如下趋势计算函数: - -| 函数名 | 输入序列类型 | 属性参数 | 输出序列类型 | 功能描述 | -| ----------------------- | ----------------------------------------------- | ------------------------------------------------------------ | ------------------------ | ------------------------------------------------------------ | -| TIME_DIFFERENCE | INT32 / INT64 / FLOAT / DOUBLE / BOOLEAN / TEXT | 无 | INT64 | 统计序列中某数据点的时间戳与前一数据点时间戳的差。范围内第一个数据点没有对应的结果输出。 | -| DIFFERENCE | INT32 / INT64 / FLOAT / DOUBLE | 无 | 与输入序列的实际类型一致 | 统计序列中某数据点的值与前一数据点的值的差。范围内第一个数据点没有对应的结果输出。 | -| NON_NEGATIVE_DIFFERENCE | INT32 / INT64 / FLOAT / DOUBLE | 无 | 与输入序列的实际类型一致 | 统计序列中某数据点的值与前一数据点的值的差的绝对值。范围内第一个数据点没有对应的结果输出。 | -| DERIVATIVE | INT32 / INT64 / FLOAT / DOUBLE | 无 | DOUBLE | 统计序列中某数据点相对于前一数据点的变化率,数量上等同于 DIFFERENCE / TIME_DIFFERENCE。范围内第一个数据点没有对应的结果输出。 | -| NON_NEGATIVE_DERIVATIVE | INT32 / INT64 / FLOAT / DOUBLE | 无 | DOUBLE | 统计序列中某数据点相对于前一数据点的变化率的绝对值,数量上等同于 NON_NEGATIVE_DIFFERENCE / TIME_DIFFERENCE。范围内第一个数据点没有对应的结果输出。 | -| DIFF | INT32 / INT64 / FLOAT / DOUBLE | `ignoreNull`:可选,默认为true;为true时,前一个数据点值为null时,忽略该数据点继续向前找到第一个出现的不为null的值;为false时,如果前一个数据点为null,则不忽略,使用null进行相减,结果也为null | DOUBLE | 统计序列中某数据点的值与前一数据点的值的差。第一个数据点没有对应的结果输出,输出值为null | - -例如: - -``` sql -select s1, time_difference(s1), difference(s1), non_negative_difference(s1), derivative(s1), non_negative_derivative(s1) from root.sg1.d1 limit 5 offset 1000; -``` - -结果: - -``` -+-----------------------------+-------------------+-------------------------------+--------------------------+---------------------------------------+--------------------------+---------------------------------------+ -| Time| root.sg1.d1.s1|time_difference(root.sg1.d1.s1)|difference(root.sg1.d1.s1)|non_negative_difference(root.sg1.d1.s1)|derivative(root.sg1.d1.s1)|non_negative_derivative(root.sg1.d1.s1)| -+-----------------------------+-------------------+-------------------------------+--------------------------+---------------------------------------+--------------------------+---------------------------------------+ -|2020-12-10T17:11:49.037+08:00|7360723084922759782| 1| -8431715764844238876| 8431715764844238876| -8.4317157648442388E18| 8.4317157648442388E18| -|2020-12-10T17:11:49.038+08:00|4377791063319964531| 1| -2982932021602795251| 2982932021602795251| -2.982932021602795E18| 2.982932021602795E18| -|2020-12-10T17:11:49.039+08:00|7972485567734642915| 1| 3594694504414678384| 3594694504414678384| 3.5946945044146785E18| 3.5946945044146785E18| -|2020-12-10T17:11:49.040+08:00|2508858212791964081| 1| -5463627354942678834| 5463627354942678834| -5.463627354942679E18| 5.463627354942679E18| -|2020-12-10T17:11:49.041+08:00|2817297431185141819| 1| 308439218393177738| 308439218393177738| 3.0843921839317773E17| 3.0843921839317773E17| -+-----------------------------+-------------------+-------------------------------+--------------------------+---------------------------------------+--------------------------+---------------------------------------+ -Total line number = 5 -It costs 0.014s -``` - -### 使用示例 - -#### 原始数据 - -``` -+-----------------------------+------------+------------+ -| Time|root.test.s1|root.test.s2| -+-----------------------------+------------+------------+ -|1970-01-01T08:00:00.001+08:00| 1| 1.0| -|1970-01-01T08:00:00.002+08:00| 2| null| -|1970-01-01T08:00:00.003+08:00| null| 3.0| -|1970-01-01T08:00:00.004+08:00| 4| null| -|1970-01-01T08:00:00.005+08:00| 5| 5.0| -|1970-01-01T08:00:00.006+08:00| null| 6.0| -+-----------------------------+------------+------------+ -``` - -#### 不使用ignoreNull参数(忽略null) - -SQL: -```sql -SELECT DIFF(s1), DIFF(s2) from root.test; -``` - -输出: -``` -+-----------------------------+------------------+------------------+ -| Time|DIFF(root.test.s1)|DIFF(root.test.s2)| -+-----------------------------+------------------+------------------+ -|1970-01-01T08:00:00.001+08:00| null| null| -|1970-01-01T08:00:00.002+08:00| 1.0| null| -|1970-01-01T08:00:00.003+08:00| null| 2.0| -|1970-01-01T08:00:00.004+08:00| 2.0| null| -|1970-01-01T08:00:00.005+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.006+08:00| null| 1.0| -+-----------------------------+------------------+------------------+ -``` - -#### 使用ignoreNull参数 - -SQL: -```sql -SELECT DIFF(s1, 'ignoreNull'='false'), DIFF(s2, 'ignoreNull'='false') from root.test; -``` - -输出: -``` -+-----------------------------+----------------------------------------+----------------------------------------+ -| Time|DIFF(root.test.s1, "ignoreNull"="false")|DIFF(root.test.s2, "ignoreNull"="false")| -+-----------------------------+----------------------------------------+----------------------------------------+ -|1970-01-01T08:00:00.001+08:00| null| null| -|1970-01-01T08:00:00.002+08:00| 1.0| null| -|1970-01-01T08:00:00.003+08:00| null| null| -|1970-01-01T08:00:00.004+08:00| null| null| -|1970-01-01T08:00:00.005+08:00| 1.0| null| -|1970-01-01T08:00:00.006+08:00| null| 1.0| -+-----------------------------+----------------------------------------+----------------------------------------+ -``` - - - -## 采样函数 - -### 等数量分桶降采样函数 - -本函数对输入序列进行等数量分桶采样,即根据用户给定的降采样比例和降采样方法将输入序列按固定点数等分为若干桶。在每个桶内通过给定的采样方法进行采样。 - -#### 等数量分桶随机采样 - -对等数量分桶后,桶内进行随机采样。 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| EQUAL_SIZE_BUCKET_RANDOM_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | 降采样比例 `proportion`,取值范围为`(0, 1]`,默认为`0.1` | INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例的等分桶随机采样 | - -##### 示例 - -输入序列:`root.ln.wf01.wt01.temperature`从`0.0-99.0`共`100`条数据。 - -``` -IoTDB> select temperature from root.ln.wf01.wt01; -+-----------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.temperature| -+-----------------------------+-----------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.002+08:00| 2.0| -|1970-01-01T08:00:00.003+08:00| 3.0| -|1970-01-01T08:00:00.004+08:00| 4.0| -|1970-01-01T08:00:00.005+08:00| 5.0| -|1970-01-01T08:00:00.006+08:00| 6.0| -|1970-01-01T08:00:00.007+08:00| 7.0| -|1970-01-01T08:00:00.008+08:00| 8.0| -|1970-01-01T08:00:00.009+08:00| 9.0| -|1970-01-01T08:00:00.010+08:00| 10.0| -|1970-01-01T08:00:00.011+08:00| 11.0| -|1970-01-01T08:00:00.012+08:00| 12.0| -|.............................|.............................| -|1970-01-01T08:00:00.089+08:00| 89.0| -|1970-01-01T08:00:00.090+08:00| 90.0| -|1970-01-01T08:00:00.091+08:00| 91.0| -|1970-01-01T08:00:00.092+08:00| 92.0| -|1970-01-01T08:00:00.093+08:00| 93.0| -|1970-01-01T08:00:00.094+08:00| 94.0| -|1970-01-01T08:00:00.095+08:00| 95.0| -|1970-01-01T08:00:00.096+08:00| 96.0| -|1970-01-01T08:00:00.097+08:00| 97.0| -|1970-01-01T08:00:00.098+08:00| 98.0| -|1970-01-01T08:00:00.099+08:00| 99.0| -+-----------------------------+-----------------------------+ -``` -sql: -```sql -select equal_size_bucket_random_sample(temperature,'proportion'='0.1') as random_sample from root.ln.wf01.wt01; -``` -结果: -``` -+-----------------------------+-------------+ -| Time|random_sample| -+-----------------------------+-------------+ -|1970-01-01T08:00:00.007+08:00| 7.0| -|1970-01-01T08:00:00.014+08:00| 14.0| -|1970-01-01T08:00:00.020+08:00| 20.0| -|1970-01-01T08:00:00.035+08:00| 35.0| -|1970-01-01T08:00:00.047+08:00| 47.0| -|1970-01-01T08:00:00.059+08:00| 59.0| -|1970-01-01T08:00:00.063+08:00| 63.0| -|1970-01-01T08:00:00.079+08:00| 79.0| -|1970-01-01T08:00:00.086+08:00| 86.0| -|1970-01-01T08:00:00.096+08:00| 96.0| -+-----------------------------+-------------+ -Total line number = 10 -It costs 0.024s -``` - -#### 等数量分桶聚合采样 - -采用聚合采样法对输入序列进行采样,用户需要另外提供一个聚合函数参数即 -- `type`:聚合类型,取值为`avg`或`max`或`min`或`sum`或`extreme`或`variance`。在缺省情况下,采用`avg`。其中`extreme`表示等分桶中,绝对值最大的值。`variance`表示采样等分桶中的方差。 - -每个桶采样输出的时间戳为这个桶第一个点的时间戳 - - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| EQUAL_SIZE_BUCKET_AGG_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | `proportion`取值范围为`(0, 1]`,默认为`0.1`
`type`:取值类型有`avg`, `max`, `min`, `sum`, `extreme`, `variance`, 默认为`avg` | INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例的等分桶聚合采样 | - -##### 示例 - -输入序列:`root.ln.wf01.wt01.temperature`从`0.0-99.0`共`100`条有序数据,同等分桶随机采样的测试数据。 - -sql: -```sql -select equal_size_bucket_agg_sample(temperature, 'type'='avg','proportion'='0.1') as agg_avg, equal_size_bucket_agg_sample(temperature, 'type'='max','proportion'='0.1') as agg_max, equal_size_bucket_agg_sample(temperature,'type'='min','proportion'='0.1') as agg_min, equal_size_bucket_agg_sample(temperature, 'type'='sum','proportion'='0.1') as agg_sum, equal_size_bucket_agg_sample(temperature, 'type'='extreme','proportion'='0.1') as agg_extreme, equal_size_bucket_agg_sample(temperature, 'type'='variance','proportion'='0.1') as agg_variance from root.ln.wf01.wt01; -``` -结果: -``` -+-----------------------------+-----------------+-------+-------+-------+-----------+------------+ -| Time| agg_avg|agg_max|agg_min|agg_sum|agg_extreme|agg_variance| -+-----------------------------+-----------------+-------+-------+-------+-----------+------------+ -|1970-01-01T08:00:00.000+08:00| 4.5| 9.0| 0.0| 45.0| 9.0| 8.25| -|1970-01-01T08:00:00.010+08:00| 14.5| 19.0| 10.0| 145.0| 19.0| 8.25| -|1970-01-01T08:00:00.020+08:00| 24.5| 29.0| 20.0| 245.0| 29.0| 8.25| -|1970-01-01T08:00:00.030+08:00| 34.5| 39.0| 30.0| 345.0| 39.0| 8.25| -|1970-01-01T08:00:00.040+08:00| 44.5| 49.0| 40.0| 445.0| 49.0| 8.25| -|1970-01-01T08:00:00.050+08:00| 54.5| 59.0| 50.0| 545.0| 59.0| 8.25| -|1970-01-01T08:00:00.060+08:00| 64.5| 69.0| 60.0| 645.0| 69.0| 8.25| -|1970-01-01T08:00:00.070+08:00|74.50000000000001| 79.0| 70.0| 745.0| 79.0| 8.25| -|1970-01-01T08:00:00.080+08:00| 84.5| 89.0| 80.0| 845.0| 89.0| 8.25| -|1970-01-01T08:00:00.090+08:00| 94.5| 99.0| 90.0| 945.0| 99.0| 8.25| -+-----------------------------+-----------------+-------+-------+-------+-----------+------------+ -Total line number = 10 -It costs 0.044s -``` - -#### 等数量分桶 M4 采样 - -采用M4采样法对输入序列进行采样。即对于每个桶采样首、尾、最小和最大值。 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| EQUAL_SIZE_BUCKET_M4_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | `proportion`取值范围为`(0, 1]`,默认为`0.1`| INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例的等分桶M4采样 | - -##### 示例 - -输入序列:`root.ln.wf01.wt01.temperature`从`0.0-99.0`共`100`条有序数据,同等分桶随机采样的测试数据。 - -sql: -```sql -select equal_size_bucket_m4_sample(temperature, 'proportion'='0.1') as M4_sample from root.ln.wf01.wt01; -``` -结果: -``` -+-----------------------------+---------+ -| Time|M4_sample| -+-----------------------------+---------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.038+08:00| 38.0| -|1970-01-01T08:00:00.039+08:00| 39.0| -|1970-01-01T08:00:00.040+08:00| 40.0| -|1970-01-01T08:00:00.041+08:00| 41.0| -|1970-01-01T08:00:00.078+08:00| 78.0| -|1970-01-01T08:00:00.079+08:00| 79.0| -|1970-01-01T08:00:00.080+08:00| 80.0| -|1970-01-01T08:00:00.081+08:00| 81.0| -|1970-01-01T08:00:00.098+08:00| 98.0| -|1970-01-01T08:00:00.099+08:00| 99.0| -+-----------------------------+---------+ -Total line number = 12 -It costs 0.065s -``` - -#### 等数量分桶离群值采样 - -本函数对输入序列进行等数量分桶离群值采样,即根据用户给定的降采样比例和桶内采样个数将输入序列按固定点数等分为若干桶,在每个桶内通过给定的离群值采样方法进行采样。 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| EQUAL_SIZE_BUCKET_OUTLIER_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | `proportion`取值范围为`(0, 1]`,默认为`0.1`
`type`取值为`avg`或`stendis`或`cos`或`prenextdis`,默认为`avg`
`number`取值应大于0,默认`3`| INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例和桶内采样个数的等分桶离群值采样 | - -参数说明 -- `proportion`: 采样比例 - - `number`: 每个桶内的采样个数,默认`3` -- `type`: 离群值采样方法,取值为 - - `avg`: 取桶内数据点的平均值,并根据采样比例,找到距离均值最远的`top number`个 - - `stendis`: 取桶内每一个数据点距离桶的首末数据点连成直线的垂直距离,并根据采样比例,找到距离最大的`top number`个 - - `cos`: 设桶内一个数据点为b,b左边的数据点为a,b右边的数据点为c,则取ab与bc向量的夹角的余弦值,值越小,说明形成的角度越大,越可能是异常值。找到cos值最小的`top number`个 - - `prenextdis`: 设桶内一个数据点为b,b左边的数据点为a,b右边的数据点为c,则取ab与bc的长度之和作为衡量标准,和越大越可能是异常值,找到最大的`top number`个 - -##### 示例 - -测试数据:`root.ln.wf01.wt01.temperature`从`0.0-99.0`共`100`条数据,其中为了加入离群值,我们使得个位数为5的值自增100。 -``` -IoTDB> select temperature from root.ln.wf01.wt01; -+-----------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.temperature| -+-----------------------------+-----------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.002+08:00| 2.0| -|1970-01-01T08:00:00.003+08:00| 3.0| -|1970-01-01T08:00:00.004+08:00| 4.0| -|1970-01-01T08:00:00.005+08:00| 105.0| -|1970-01-01T08:00:00.006+08:00| 6.0| -|1970-01-01T08:00:00.007+08:00| 7.0| -|1970-01-01T08:00:00.008+08:00| 8.0| -|1970-01-01T08:00:00.009+08:00| 9.0| -|1970-01-01T08:00:00.010+08:00| 10.0| -|1970-01-01T08:00:00.011+08:00| 11.0| -|1970-01-01T08:00:00.012+08:00| 12.0| -|1970-01-01T08:00:00.013+08:00| 13.0| -|1970-01-01T08:00:00.014+08:00| 14.0| -|1970-01-01T08:00:00.015+08:00| 115.0| -|1970-01-01T08:00:00.016+08:00| 16.0| -|.............................|.............................| -|1970-01-01T08:00:00.092+08:00| 92.0| -|1970-01-01T08:00:00.093+08:00| 93.0| -|1970-01-01T08:00:00.094+08:00| 94.0| -|1970-01-01T08:00:00.095+08:00| 195.0| -|1970-01-01T08:00:00.096+08:00| 96.0| -|1970-01-01T08:00:00.097+08:00| 97.0| -|1970-01-01T08:00:00.098+08:00| 98.0| -|1970-01-01T08:00:00.099+08:00| 99.0| -+-----------------------------+-----------------------------+ -``` -sql: -```sql -select equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='avg', 'number'='2') as outlier_avg_sample, equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='stendis', 'number'='2') as outlier_stendis_sample, equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='cos', 'number'='2') as outlier_cos_sample, equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='prenextdis', 'number'='2') as outlier_prenextdis_sample from root.ln.wf01.wt01; -``` -结果: -``` -+-----------------------------+------------------+----------------------+------------------+-------------------------+ -| Time|outlier_avg_sample|outlier_stendis_sample|outlier_cos_sample|outlier_prenextdis_sample| -+-----------------------------+------------------+----------------------+------------------+-------------------------+ -|1970-01-01T08:00:00.005+08:00| 105.0| 105.0| 105.0| 105.0| -|1970-01-01T08:00:00.015+08:00| 115.0| 115.0| 115.0| 115.0| -|1970-01-01T08:00:00.025+08:00| 125.0| 125.0| 125.0| 125.0| -|1970-01-01T08:00:00.035+08:00| 135.0| 135.0| 135.0| 135.0| -|1970-01-01T08:00:00.045+08:00| 145.0| 145.0| 145.0| 145.0| -|1970-01-01T08:00:00.055+08:00| 155.0| 155.0| 155.0| 155.0| -|1970-01-01T08:00:00.065+08:00| 165.0| 165.0| 165.0| 165.0| -|1970-01-01T08:00:00.075+08:00| 175.0| 175.0| 175.0| 175.0| -|1970-01-01T08:00:00.085+08:00| 185.0| 185.0| 185.0| 185.0| -|1970-01-01T08:00:00.095+08:00| 195.0| 195.0| 195.0| 195.0| -+-----------------------------+------------------+----------------------+------------------+-------------------------+ -Total line number = 10 -It costs 0.041s -``` - -### M4函数 - -#### 函数简介 - -M4用于在窗口内采样第一个点(`first`)、最后一个点(`last`)、最小值点(`bottom`)、最大值点(`top`): - -- 第一个点是拥有这个窗口内最小时间戳的点; -- 最后一个点是拥有这个窗口内最大时间戳的点; -- 最小值点是拥有这个窗口内最小值的点(如果有多个这样的点,M4只返回其中一个); -- 最大值点是拥有这个窗口内最大值的点(如果有多个这样的点,M4只返回其中一个)。 - -image - -| 函数名 | 可接收的输入序列类型 | 属性参数 | 输出序列类型 | 功能类型 | -| ------ | ------------------------------ | ------------------------------------------------------------ | ------------------------------ | ------------------------------------------------------------ | -| M4 | INT32 / INT64 / FLOAT / DOUBLE | 包含固定点数的窗口和滑动时间窗口使用不同的属性参数。包含固定点数的窗口使用属性`windowSize`和`slidingStep`。滑动时间窗口使用属性`timeInterval`、`slidingStep`、`displayWindowBegin`和`displayWindowEnd`。更多细节见下文。 | INT32 / INT64 / FLOAT / DOUBLE | 返回每个窗口内的第一个点(`first`)、最后一个点(`last`)、最小值点(`bottom`)、最大值点(`top`)。在一个窗口内的聚合点输出之前,M4会将它们按照时间戳递增排序并且去重。 | - -#### 属性参数 - -**(1) 包含固定点数的窗口(SlidingSizeWindowAccessStrategy)使用的属性参数:** - -+ `windowSize`: 一个窗口内的点数。Int数据类型。必需的属性参数。 -+ `slidingStep`: 按照设定的点数来滑动窗口。Int数据类型。可选的属性参数;如果没有设置,默认取值和`windowSize`一样。 - -image - -**(2) 滑动时间窗口(SlidingTimeWindowAccessStrategy)使用的属性参数:** - -+ `timeInterval`: 一个窗口的时间长度。Long数据类型。必需的属性参数。 -+ `slidingStep`: 按照设定的时长来滑动窗口。Long数据类型。可选的属性参数;如果没有设置,默认取值和`timeInterval`一样。 -+ `displayWindowBegin`: 窗口滑动的起始时间戳位置(包含在内)。Long数据类型。可选的属性参数;如果没有设置,默认取值为Long.MIN_VALUE,意为使用输入的时间序列的第一个点的时间戳作为窗口滑动的起始时间戳位置。 -+ `displayWindowEnd`: 结束时间限制(不包含在内;本质上和`WHERE time < displayWindowEnd`起的效果是一样的)。Long数据类型。可选的属性参数;如果没有设置,默认取值为Long.MAX_VALUE,意为除了输入的时间序列自身数据读取完毕之外没有增加额外的结束时间过滤条件限制。 - -groupBy window - -#### 示例 - -输入的时间序列: - -```sql -+-----------------------------+------------------+ -| Time|root.vehicle.d1.s1| -+-----------------------------+------------------+ -|1970-01-01T08:00:00.001+08:00| 5.0| -|1970-01-01T08:00:00.002+08:00| 15.0| -|1970-01-01T08:00:00.005+08:00| 10.0| -|1970-01-01T08:00:00.008+08:00| 8.0| -|1970-01-01T08:00:00.010+08:00| 30.0| -|1970-01-01T08:00:00.020+08:00| 20.0| -|1970-01-01T08:00:00.025+08:00| 8.0| -|1970-01-01T08:00:00.027+08:00| 20.0| -|1970-01-01T08:00:00.030+08:00| 40.0| -|1970-01-01T08:00:00.033+08:00| 9.0| -|1970-01-01T08:00:00.035+08:00| 10.0| -|1970-01-01T08:00:00.040+08:00| 20.0| -|1970-01-01T08:00:00.045+08:00| 30.0| -|1970-01-01T08:00:00.052+08:00| 8.0| -|1970-01-01T08:00:00.054+08:00| 18.0| -+-----------------------------+------------------+ -``` - -查询语句1: - -```sql -select M4(s1,'timeInterval'='25','displayWindowBegin'='0','displayWindowEnd'='100') from root.vehicle.d1 -``` - -输出结果1: - -```sql -+-----------------------------+-----------------------------------------------------------------------------------------------+ -| Time|M4(root.vehicle.d1.s1, "timeInterval"="25", "displayWindowBegin"="0", "displayWindowEnd"="100")| -+-----------------------------+-----------------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 5.0| -|1970-01-01T08:00:00.010+08:00| 30.0| -|1970-01-01T08:00:00.020+08:00| 20.0| -|1970-01-01T08:00:00.025+08:00| 8.0| -|1970-01-01T08:00:00.030+08:00| 40.0| -|1970-01-01T08:00:00.045+08:00| 30.0| -|1970-01-01T08:00:00.052+08:00| 8.0| -|1970-01-01T08:00:00.054+08:00| 18.0| -+-----------------------------+-----------------------------------------------------------------------------------------------+ -Total line number = 8 -``` - -查询语句2: - -```sql -select M4(s1,'windowSize'='10') from root.vehicle.d1 -``` - -输出结果2: - -```sql -+-----------------------------+-----------------------------------------+ -| Time|M4(root.vehicle.d1.s1, "windowSize"="10")| -+-----------------------------+-----------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 5.0| -|1970-01-01T08:00:00.030+08:00| 40.0| -|1970-01-01T08:00:00.033+08:00| 9.0| -|1970-01-01T08:00:00.035+08:00| 10.0| -|1970-01-01T08:00:00.045+08:00| 30.0| -|1970-01-01T08:00:00.052+08:00| 8.0| -|1970-01-01T08:00:00.054+08:00| 18.0| -+-----------------------------+-----------------------------------------+ -Total line number = 7 -``` - -#### 推荐的使用场景 - -**(1) 使用场景:保留极端点的降采样** - -由于M4为每个窗口聚合其第一个点(`first`)、最后一个点(`last`)、最小值点(`bottom`)、最大值点(`top`),因此M4通常保留了极值点,因此比其他下采样方法(如分段聚合近似 (PAA))能更好地保留模式。如果你想对时间序列进行下采样并且希望保留极值点,你可以试试 M4。 - -**(2) 使用场景:基于M4降采样的大规模时间序列的零误差双色折线图可视化** - -参考论文["M4: A Visualization-Oriented Time Series Data Aggregation"](http://www.vldb.org/pvldb/vol7/p797-jugel.pdf),作为大规模时间序列可视化的降采样方法,M4可以做到双色折线图的零变形。 - -假设屏幕画布的像素宽乘高是`w*h`,假设时间序列要可视化的时间范围是`[tqs,tqe)`,并且(tqe-tqs)是w的整数倍,那么落在第i个时间跨度`Ii=[tqs+(tqe-tqs)/w*(i-1),tqs+(tqe-tqs)/w*i)` 内的点将会被画在第i个像素列中,i=1,2,...,w。于是从可视化驱动的角度出发,使用查询语句:`"select M4(s1,'timeInterval'='(tqe-tqs)/w','displayWindowBegin'='tqs','displayWindowEnd'='tqe') from root.vehicle.d1"`,来采集每个时间跨度内的第一个点(`first`)、最后一个点(`last`)、最小值点(`bottom`)、最大值点(`top`)。降采样时间序列的结果点数不会超过`4*w`个,与此同时,使用这些聚合点画出来的二色折线图与使用原始数据画出来的在像素级别上是完全一致的。 - -为了免除参数值硬编码的麻烦,当Grafana用于可视化时,我们推荐使用Grafana的[模板变量](https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables)`$ __interval_ms`,如下所示: - -```sql -select M4(s1,'timeInterval'='$__interval_ms') from root.sg1.d1 -``` - -其中`timeInterval`自动设置为`(tqe-tqs)/w`。请注意,这里的时间精度假定为毫秒。 - -#### 和其它函数的功能比较 - -| SQL | 是否支持M4聚合 | 滑动窗口类型 | 示例 | 相关文档 | -| ------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| 1. 带有Group By子句的内置聚合函数 | 不支持,缺少`BOTTOM_TIME`和`TOP_TIME`,即缺少最小值点和最大值点的时间戳。 | Time Window | `select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d)` | https://iotdb.apache.org/UserGuide/Master/Query-Data/Aggregate-Query.html#built-in-aggregate-functions
https://iotdb.apache.org/UserGuide/Master/Query-Data/Aggregate-Query.html#downsampling-aggregate-query | -| 2. EQUAL_SIZE_BUCKET_M4_SAMPLE (内置UDF) | 支持* | Size Window. `windowSize = 4*(int)(1/proportion)` | `select equal_size_bucket_m4_sample(temperature, 'proportion'='0.1') as M4_sample from root.ln.wf01.wt01` | https://iotdb.apache.org/UserGuide/Master/Query-Data/Select-Expression.html#time-series-generating-functions | -| **3. M4 (内置UDF)** | 支持* | Size Window, Time Window | (1) Size Window: `select M4(s1,'windowSize'='10') from root.vehicle.d1`
(2) Time Window: `select M4(s1,'timeInterval'='25','displayWindowBegin'='0','displayWindowEnd'='100') from root.vehicle.d1` | 本文档 | -| 4. 扩展带有Group By子句的内置聚合函数来支持M4聚合 | 未实施 | 未实施 | 未实施 | 未实施 | - -进一步比较`EQUAL_SIZE_BUCKET_M4_SAMPLE`和`M4`: - -**(1) 不同的M4聚合函数定义:** - -在每个窗口内,`EQUAL_SIZE_BUCKET_M4_SAMPLE`从排除了第一个点和最后一个点之后剩余的点中提取最小值点和最大值点。 - -而`M4`则是从窗口内所有点中(包括第一个点和最后一个点)提取最小值点和最大值点,这个定义与元数据中保存的`max_value`和`min_value`的语义更加一致。 - -值得注意的是,在一个窗口内的聚合点输出之前,`EQUAL_SIZE_BUCKET_M4_SAMPLE`和`M4`都会将它们按照时间戳递增排序并且去重。 - -**(2) 不同的滑动窗口:** - -`EQUAL_SIZE_BUCKET_M4_SAMPLE`使用SlidingSizeWindowAccessStrategy,并且通过采样比例(`proportion`)来间接控制窗口点数(`windowSize`),转换公式是`windowSize = 4*(int)(1/proportion)`。 - -`M4`支持两种滑动窗口:SlidingSizeWindowAccessStrategy和SlidingTimeWindowAccessStrategy,并且`M4`通过相应的参数直接控制窗口的点数或者时长。 - - - -## 时间序列处理 - -### CHANGE_POINTS - -#### 函数简介 - -本函数用于去除输入序列中的连续相同值。如输入序列`1,1,2,2,3`输出序列为`1,2,3`。 - -**函数名:** CHANGE_POINTS - -**输入序列:** 仅支持输入1个序列。 - -**参数:** 无 - -#### 使用示例 - -原始数据: - -``` -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -| Time|root.testChangePoints.d1.s1|root.testChangePoints.d1.s2|root.testChangePoints.d1.s3|root.testChangePoints.d1.s4|root.testChangePoints.d1.s5|root.testChangePoints.d1.s6| -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -|1970-01-01T08:00:00.001+08:00| true| 1| 1| 1.0| 1.0| 1test1| -|1970-01-01T08:00:00.002+08:00| true| 2| 2| 2.0| 1.0| 2test2| -|1970-01-01T08:00:00.003+08:00| false| 1| 2| 1.0| 1.0| 2test2| -|1970-01-01T08:00:00.004+08:00| true| 1| 3| 1.0| 1.0| 1test1| -|1970-01-01T08:00:00.005+08:00| true| 1| 3| 1.0| 1.0| 1test1| -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -``` - -用于查询的SQL语句: - -```sql -select change_points(s1), change_points(s2), change_points(s3), change_points(s4), change_points(s5), change_points(s6) from root.testChangePoints.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+ -| Time|change_points(root.testChangePoints.d1.s1)|change_points(root.testChangePoints.d1.s2)|change_points(root.testChangePoints.d1.s3)|change_points(root.testChangePoints.d1.s4)|change_points(root.testChangePoints.d1.s5)|change_points(root.testChangePoints.d1.s6)| -+-----------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| true| 1| 1| 1.0| 1.0| 1test1| -|1970-01-01T08:00:00.002+08:00| null| 2| 2| 2.0| null| 2test2| -|1970-01-01T08:00:00.003+08:00| false| 1| null| 1.0| null| null| -|1970-01-01T08:00:00.004+08:00| true| null| 3| null| null| 1test1| -+-----------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+------------------------------------------+ -``` - - - -## Lambda 表达式 - -### JEXL 自定义函数 - -#### 函数简介 - -Java Expression Language (JEXL) 是一个表达式语言引擎。我们使用 JEXL 来扩展 UDF,在命令行中,通过简易的 lambda 表达式来实现 UDF。 - -lambda 表达式中支持的运算符详见链接 [JEXL 中 lambda 表达式支持的运算符](https://commons.apache.org/proper/commons-jexl/apidocs/org/apache/commons/jexl3/package-summary.html#customization) 。 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| JEXL | INT32 / INT64 / FLOAT / DOUBLE / TEXT / BOOLEAN | `expr`是一个支持标准的一元或多元参数的lambda表达式,符合`x -> {...}`或`(x, y, z) -> {...}`的格式,例如`x -> {x * 2}`, `(x, y, z) -> {x + y * z}`| INT32 / INT64 / FLOAT / DOUBLE / TEXT / BOOLEAN | 返回将输入的时间序列通过lambda表达式变换的序列 | - -#### 使用示例 - -输入序列: -``` -IoTDB> select * from root.ln.wf01.wt01; -+-----------------------------+---------------------+--------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.str|root.ln.wf01.wt01.st|root.ln.wf01.wt01.temperature| -+-----------------------------+---------------------+--------------------+-----------------------------+ -|1970-01-01T08:00:00.000+08:00| str| 10.0| 0.0| -|1970-01-01T08:00:00.001+08:00| str| 20.0| 1.0| -|1970-01-01T08:00:00.002+08:00| str| 30.0| 2.0| -|1970-01-01T08:00:00.003+08:00| str| 40.0| 3.0| -|1970-01-01T08:00:00.004+08:00| str| 50.0| 4.0| -|1970-01-01T08:00:00.005+08:00| str| 60.0| 5.0| -|1970-01-01T08:00:00.006+08:00| str| 70.0| 6.0| -|1970-01-01T08:00:00.007+08:00| str| 80.0| 7.0| -|1970-01-01T08:00:00.008+08:00| str| 90.0| 8.0| -|1970-01-01T08:00:00.009+08:00| str| 100.0| 9.0| -|1970-01-01T08:00:00.010+08:00| str| 110.0| 10.0| -+-----------------------------+---------------------+--------------------+-----------------------------+ -``` - -用于查询的SQL语句: -```sql -select jexl(temperature, 'expr'='x -> {x + x}') as jexl1, jexl(temperature, 'expr'='x -> {x * 3}') as jexl2, jexl(temperature, 'expr'='x -> {x * x}') as jexl3, jexl(temperature, 'expr'='x -> {multiply(x, 100)}') as jexl4, jexl(temperature, st, 'expr'='(x, y) -> {x + y}') as jexl5, jexl(temperature, st, str, 'expr'='(x, y, z) -> {x + y + z}') as jexl6 from root.ln.wf01.wt01; -``` - -输出序列: -``` -+-----------------------------+-----+-----+-----+------+-----+--------+ -| Time|jexl1|jexl2|jexl3| jexl4|jexl5| jexl6| -+-----------------------------+-----+-----+-----+------+-----+--------+ -|1970-01-01T08:00:00.000+08:00| 0.0| 0.0| 0.0| 0.0| 10.0| 10.0str| -|1970-01-01T08:00:00.001+08:00| 2.0| 3.0| 1.0| 100.0| 21.0| 21.0str| -|1970-01-01T08:00:00.002+08:00| 4.0| 6.0| 4.0| 200.0| 32.0| 32.0str| -|1970-01-01T08:00:00.003+08:00| 6.0| 9.0| 9.0| 300.0| 43.0| 43.0str| -|1970-01-01T08:00:00.004+08:00| 8.0| 12.0| 16.0| 400.0| 54.0| 54.0str| -|1970-01-01T08:00:00.005+08:00| 10.0| 15.0| 25.0| 500.0| 65.0| 65.0str| -|1970-01-01T08:00:00.006+08:00| 12.0| 18.0| 36.0| 600.0| 76.0| 76.0str| -|1970-01-01T08:00:00.007+08:00| 14.0| 21.0| 49.0| 700.0| 87.0| 87.0str| -|1970-01-01T08:00:00.008+08:00| 16.0| 24.0| 64.0| 800.0| 98.0| 98.0str| -|1970-01-01T08:00:00.009+08:00| 18.0| 27.0| 81.0| 900.0|109.0|109.0str| -|1970-01-01T08:00:00.010+08:00| 20.0| 30.0|100.0|1000.0|120.0|120.0str| -+-----------------------------+-----+-----+-----+------+-----+--------+ -Total line number = 11 -It costs 0.118s -``` - - - -## 条件表达式 - -### CASE - -CASE表达式是一种条件表达式,可用于根据特定条件返回不同的值,功能类似于其它语言中的if-else。 -CASE表达式由以下部分组成: -- CASE关键字:表示开始CASE表达式。 -- WHEN-THEN子句:可能存在多个,用于定义条件与给出结果。此子句又分为WHEN和THEN两个部分,WHEN部分表示条件,THEN部分表示结果表达式。如果WHEN条件为真,则返回对应的THEN结果。 -- ELSE子句:如果没有任何WHEN-THEN子句的条件为真,则返回ELSE子句中的结果。可以不存在ELSE子句。 -- END关键字:表示结束CASE表达式。 - -CASE表达式是一种标量运算,可以配合任何其它的标量运算或聚合函数使用。 - -下文把所有THEN部分和ELSE子句并称为结果子句。 - -#### 语法示例 - -CASE表达式支持两种格式。 - -语法示例如下: -- 格式1: -```sql - CASE - WHEN condition1 THEN expression1 - [WHEN condition2 THEN expression2] ... - [ELSE expression_end] - END -``` - 从上至下检查WHEN子句中的condition。 - - condition为真时返回对应THEN子句中的expression,condition为假时继续检查下一个WHEN子句中的condition。 -- 格式2: -```sql - CASE caseValue - WHEN whenValue1 THEN expression1 - [WHEN whenValue2 THEN expression2] ... - [ELSE expression_end] - END -``` - - 从上至下检查WHEN子句中的whenValue是否与caseValue相等。 - - 满足caseValue=whenValue时返回对应THEN子句中的expression,不满足时继续检查下一个WHEN子句中的whenValue。 - - 格式2会被iotdb转换成等效的格式1,例如以上sql语句会转换成: -```sql - CASE - WHEN caseValue=whenValue1 THEN expression1 - [WHEN caseValue=whenValue1 THEN expression1] ... - [ELSE expression_end] - END -``` - -如果格式1中的condition均不为真,或格式2中均不满足caseVaule=whenValue,则返回ELSE子句中的expression_end;不存在ELSE子句则返回null。 - -#### 注意事项 - -- 格式1中,所有WHEN子句必须返回BOOLEAN类型。 -- 格式2中,所有WHEN子句必须能够与CASE子句进行判等。 -- 一个CASE表达式中所有结果子句的返回值类型需要满足一定的条件: - - BOOLEAN类型不能与其它类型共存,存在其它类型会报错。 - - TEXT类型不能与其它类型共存,存在其它类型会报错。 - - 其它四种数值类型可以共存,最终结果会为DOUBLE类型,转换过程可能会存在精度损失。 -- CASE表达式没有实现惰性计算,即所有子句都会被计算。 -- CASE表达式不支持与UDF混用。 -- CASE表达式内部不能存在聚合函数,但CASE表达式的结果可以提供给聚合函数。 -- 使用CLI时,由于CASE表达式字符串较长,推荐用as为表达式提供别名。 - -#### 使用示例 - -##### 示例1 - -CASE表达式可对数据进行直观地分析,例如: - -- 某种化学产品的制备需要温度和压力都处于特定范围之内 -- 在制备过程中传感器会侦测温度和压力,在iotdb中形成T(temperature)和P(pressure)两个时间序列 - -这种应用场景下,CASE表达式可以指出哪些时间的参数是合适的,哪些时间的参数不合适,以及为什么不合适。 - -数据: -```sql -IoTDB> select * from root.test1 -+-----------------------------+------------+------------+ -| Time|root.test1.P|root.test1.T| -+-----------------------------+------------+------------+ -|2023-03-29T11:25:54.724+08:00| 1000000.0| 1025.0| -|2023-03-29T11:26:13.445+08:00| 1000094.0| 1040.0| -|2023-03-29T11:27:36.988+08:00| 1000095.0| 1041.0| -|2023-03-29T11:27:56.446+08:00| 1000095.0| 1059.0| -|2023-03-29T11:28:20.838+08:00| 1200000.0| 1040.0| -+-----------------------------+------------+------------+ -``` - -SQL语句: -```sql -select T, P, case -when 1000=1050 then "bad temperature" -when P<=1000000 or P>=1100000 then "bad pressure" -end as `result` -from root.test1 -``` - - -输出: -``` -+-----------------------------+------------+------------+---------------+ -| Time|root.test1.T|root.test1.P| result| -+-----------------------------+------------+------------+---------------+ -|2023-03-29T11:25:54.724+08:00| 1025.0| 1000000.0| bad pressure| -|2023-03-29T11:26:13.445+08:00| 1040.0| 1000094.0| good!| -|2023-03-29T11:27:36.988+08:00| 1041.0| 1000095.0| good!| -|2023-03-29T11:27:56.446+08:00| 1059.0| 1000095.0|bad temperature| -|2023-03-29T11:28:20.838+08:00| 1040.0| 1200000.0| bad pressure| -+-----------------------------+------------+------------+---------------+ -``` - - -##### 示例2 - -CASE表达式可实现结果的自由转换,例如将具有某种模式的字符串转换成另一种字符串。 - -数据: -```sql -IoTDB> select * from root.test2 -+-----------------------------+--------------+ -| Time|root.test2.str| -+-----------------------------+--------------+ -|2023-03-27T18:23:33.427+08:00| abccd| -|2023-03-27T18:23:39.389+08:00| abcdd| -|2023-03-27T18:23:43.463+08:00| abcdefg| -+-----------------------------+--------------+ -``` - -SQL语句: -```sql -select str, case -when str like "%cc%" then "has cc" -when str like "%dd%" then "has dd" -else "no cc and dd" end as `result` -from root.test2 -``` - -输出: -``` -+-----------------------------+--------------+------------+ -| Time|root.test2.str| result| -+-----------------------------+--------------+------------+ -|2023-03-27T18:23:33.427+08:00| abccd| has cc| -|2023-03-27T18:23:39.389+08:00| abcdd| has dd| -|2023-03-27T18:23:43.463+08:00| abcdefg|no cc and dd| -+-----------------------------+--------------+------------+ -``` - -##### 示例3:搭配聚合函数 - -###### 合法:聚合函数←CASE表达式 - -CASE表达式可作为聚合函数的参数。例如,与聚合函数COUNT搭配,可实现同时按多个条件进行数据统计。 - -数据: -```sql -IoTDB> select * from root.test3 -+-----------------------------+------------+ -| Time|root.test3.x| -+-----------------------------+------------+ -|2023-03-27T18:11:11.300+08:00| 0.0| -|2023-03-27T18:11:14.658+08:00| 1.0| -|2023-03-27T18:11:15.981+08:00| 2.0| -|2023-03-27T18:11:17.668+08:00| 3.0| -|2023-03-27T18:11:19.112+08:00| 4.0| -|2023-03-27T18:11:20.822+08:00| 5.0| -|2023-03-27T18:11:22.462+08:00| 6.0| -|2023-03-27T18:11:24.174+08:00| 7.0| -|2023-03-27T18:11:25.858+08:00| 8.0| -|2023-03-27T18:11:27.979+08:00| 9.0| -+-----------------------------+------------+ -``` - -SQL语句: - -```sql -select -count(case when x<=1 then 1 end) as `(-∞,1]`, -count(case when 1 select * from root.test4 -+-----------------------------+------------+ -| Time|root.test4.x| -+-----------------------------+------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.002+08:00| 2.0| -|1970-01-01T08:00:00.003+08:00| 3.0| -|1970-01-01T08:00:00.004+08:00| 4.0| -+-----------------------------+------------+ -``` - -SQL语句: -```sql -select x, case x when 1 then "one" when 2 then "two" else "other" end from root.test4 -``` - -输出: -``` -+-----------------------------+------------+-----------------------------------------------------------------------------------+ -| Time|root.test4.x|CASE WHEN root.test4.x = 1 THEN "one" WHEN root.test4.x = 2 THEN "two" ELSE "other"| -+-----------------------------+------------+-----------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| one| -|1970-01-01T08:00:00.002+08:00| 2.0| two| -|1970-01-01T08:00:00.003+08:00| 3.0| other| -|1970-01-01T08:00:00.004+08:00| 4.0| other| -+-----------------------------+------------+-----------------------------------------------------------------------------------+ -``` - -##### 示例5:结果子句类型 - -CASE表达式的结果子句的返回值需要满足一定的类型限制。 - -此示例中,继续使用示例4中的数据。 - -###### 非法:BOOLEAN与其它类型共存 - -SQL语句: -```sql -select x, case x when 1 then true when 2 then 2 end from root.test4 -``` - -输出: -``` -Msg: 701: CASE expression: BOOLEAN and other types cannot exist at same time -``` - -###### 合法:只存在BOOLEAN类型 - -SQL语句: -```sql -select x, case x when 1 then true when 2 then false end as `result` from root.test4 -``` - -输出: -``` -+-----------------------------+------------+------+ -| Time|root.test4.x|result| -+-----------------------------+------------+------+ -|1970-01-01T08:00:00.001+08:00| 1.0| true| -|1970-01-01T08:00:00.002+08:00| 2.0| false| -|1970-01-01T08:00:00.003+08:00| 3.0| null| -|1970-01-01T08:00:00.004+08:00| 4.0| null| -+-----------------------------+------------+------+ -``` - -###### 非法:TEXT与其它类型共存 - -SQL语句: -```sql -select x, case x when 1 then 1 when 2 then "str" end from root.test4 -``` - -输出: -``` -Msg: 701: CASE expression: TEXT and other types cannot exist at same time -``` - -###### 合法:只存在TEXT类型 - -见示例1。 - -###### 合法:数值类型共存 - -SQL语句: -```sql -select x, case x -when 1 then 1 -when 2 then 222222222222222 -when 3 then 3.3 -when 4 then 4.4444444444444 -end as `result` -from root.test4 -``` - -输出: -``` -+-----------------------------+------------+-------------------+ -| Time|root.test4.x| result| -+-----------------------------+------------+-------------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| 1.0| -|1970-01-01T08:00:00.002+08:00| 2.0|2.22222222222222E14| -|1970-01-01T08:00:00.003+08:00| 3.0| 3.299999952316284| -|1970-01-01T08:00:00.004+08:00| 4.0| 4.44444465637207| -+-----------------------------+------------+-------------------+ -``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/Modify-Config-Manual.md b/src/zh/UserGuide/V1.3.0-2/Reference/Modify-Config-Manual.md deleted file mode 100644 index 307b92f7e..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Reference/Modify-Config-Manual.md +++ /dev/null @@ -1,72 +0,0 @@ - - -# 配置项修改介绍 -## 设置方式 -* 使用sql语句修改【推荐】 -* 直接修改配置文件【不推荐】 -## 生效方式 -* 第一次启动后不可修改 (first_start) -* 重启后生效 (restart) -* 热加载 (hot_reload) -# 直接修改配置文件 -可以通过重启或以下命令生效 -## 热加载配置命令 -使支持热加载的配置项改动立即生效。 -对于已经写在配置文件中修改过的配置项,从配置文件中删除或注释后再进行 load configuration 将恢复默认值。 -``` -load configuration -``` -# 配置项操作语句 -设置配置项 -``` -set configuration "key1"="value1" "key2"="value2"... (on nodeId) -``` -### 示例1 -``` -set configuration "enable_cross_space_compaction"="false" -``` -对集群所有节点永久生效,设置 enable_cross_space_compaction 为 false,并写入到 iotdb-common.properties 中。 -### 示例2 -``` -set configuration "enable_cross_space_compaction"="false" "enable_seq_space_compaction"="false" on 1 -``` -对 nodeId 为 1 的节点永久生效,设置 enable_cross_space_compaction 为 false,设置 enable_seq_space_compaction 为 false,并写入到 iotdb-common.properties 中。 -### 示例3 -``` -set configuration "enable_cross_space_compaction"="false" "timestamp_precision"="ns" -``` -对集群所有节点永久生效,设置 enable_cross_space_compaction 为 false,timestamp_precision 为 ns,并写入到 iotdb-common.properties 中。但是,timestamp_precision 是第一次启动后就无法修改的配置项,因此会忽略这个配置项的更新,返回如下。 -``` -Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 301: ignored config items: [timestamp_precision] -``` -# 生效配置项 -支持热加载立即生效的配置项在 iotdb-common.properties.template 文件中标记 effectiveMode 为 hot_reload - -示例 -``` -# Used for indicate cluster name and distinguish different cluster. -# If you need to modify the cluster name, it's recommended to use 'set configuration "cluster_name=xxx"' sql. -# Manually modifying configuration file is not recommended, which may cause node restart fail. -# effectiveMode: hot_reload -# Datatype: string -cluster_name=defaultCluster -``` diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/UDF-Libraries_timecho.md b/src/zh/UserGuide/V1.3.0-2/Reference/UDF-Libraries_timecho.md deleted file mode 100644 index 9b27a58c1..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Reference/UDF-Libraries_timecho.md +++ /dev/null @@ -1,5281 +0,0 @@ - -# UDF函数库 - -基于用户自定义函数能力,IoTDB 提供了一系列关于时序数据处理的函数,包括数据质量、数据画像、异常检测、 频域分析、数据匹配、数据修复、序列发现、机器学习等,能够满足工业领域对时序数据处理的需求。 - -> 注意:当前UDF函数库中的函数仅支持毫秒级的时间戳精度。 - -## 安装步骤 -1. 请获取与 IoTDB 版本兼容的 UDF 函数库 JAR 包的压缩包。 - - | UDF 安装包 | 支持的 IoTDB 版本 | 下载链接 | - | --------------- | ----------------- | ------------------------------------------------------------ | - | TimechoDB-UDF-1.3.3.zip | V1.3.3及以上 | 请联系天谋商务获取 | - | TimechoDB-UDF-1.3.2.zip | V1.0.0~V1.3.2 | 请联系天谋商务获取 | - -2. 将获取的压缩包中的 `library-udf.jar` 文件放置在 IoTDB 集群所有节点的 `/ext/udf` 的目录下 -3. 在 IoTDB 的 SQL 命令行终端(CLI)或可视化控制台(Workbench)的 SQL 操作界面中,执行下述相应的函数注册语句。 -4. 批量注册:两种注册方式:注册脚本 或 SQL汇总语句 -- 注册脚本 - - 将压缩包中的注册脚本(`register-UDF.sh` 或 `register-UDF.bat`)按需复制到 IoTDB 的 tools 目录下,修改脚本中的参数(默认为host=127.0.0.1,rpcPort=6667,user=root,pass=root); - - 启动 IoTDB 服务,运行注册脚本批量注册 UDF - -- SQL汇总语句 - - 打开压缩包中的SQl文件,复制全部 SQL 语句,在 IoTDB 的 SQL 命令行终端(CLI)或可视化控制台(Workbench)的 SQL 操作界面中,执行全部 SQl 语句批量注册 UDF - -## 数据质量 - -### Completeness - -#### 注册语句 - -```sql -create function completeness as 'org.apache.iotdb.library.dquality.UDTFCompleteness' -``` - -#### 函数简介 - -本函数用于计算时间序列的完整性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的完整性,并输出窗口第一个数据点的时间戳和窗口的完整性。 - -**函数名:** COMPLETENESS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 -+ `downtime`:完整性计算是否考虑停机异常。它的取值为 'true' 或 'false',默认值为 'true'. 在考虑停机异常时,长时间的数据缺失将被视作停机,不对完整性产生影响。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行完整性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算完整性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select completeness(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------+ -| Time|completeness(root.test.d1.s1)| -+-----------------------------+-----------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.875| -+-----------------------------+-----------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算完整性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select completeness(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------+ -| Time|completeness(root.test.d1.s1, "window"="15")| -+-----------------------------+--------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.875| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+--------------------------------------------+ -``` - -### Consistency - -#### 注册语句 - -```sql -create function consistency as 'org.apache.iotdb.library.dquality.UDTFConsistency' -``` - -#### 函数简介 - -本函数用于计算时间序列的一致性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的一致性,并输出窗口第一个数据点的时间戳和窗口的时效性。 - -**函数名:** CONSISTENCY - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行一致性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算一致性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consistency(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+----------------------------+ -| Time|consistency(root.test.d1.s1)| -+-----------------------------+----------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -+-----------------------------+----------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算一致性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consistency(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------+ -| Time|consistency(root.test.d1.s1, "window"="15")| -+-----------------------------+-------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+-------------------------------------------+ -``` - -### Timeliness - -#### 注册语句 - -```sql -create function timeliness as 'org.apache.iotdb.library.dquality.UDTFTimeliness' -``` - -#### 函数简介 - -本函数用于计算时间序列的时效性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的时效性,并输出窗口第一个数据点的时间戳和窗口的时效性。 - -**函数名:** TIMELINESS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行时效性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算时效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select timeliness(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+---------------------------+ -| Time|timeliness(root.test.d1.s1)| -+-----------------------------+---------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -+-----------------------------+---------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算时效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select timeliness(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------+ -| Time|timeliness(root.test.d1.s1, "window"="15")| -+-----------------------------+------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+------------------------------------------+ -``` - -### Validity - -#### 注册语句 - -```sql -create function validity as 'org.apache.iotdb.library.dquality.UDTFValidity' -``` - -#### 函数简介 - -本函数用于计算时间序列的有效性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的有效性,并输出窗口第一个数据点的时间戳和窗口的有效性。 - - -**函数名:** VALIDITY - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行有效性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算有效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select validity(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|validity(root.test.d1.s1)| -+-----------------------------+-------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.8833333333333333| -+-----------------------------+-------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算有效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select validity(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------+ -| Time|validity(root.test.d1.s1, "window"="15")| -+-----------------------------+----------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.8833333333333333| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+----------------------------------------+ -``` - - - - -## 数据画像 - -### ACF - -#### 注册语句 - -```sql -create function acf as 'org.apache.iotdb.library.dprofile.UDTFACF' -``` - -#### 函数简介 - -本函数用于计算时间序列的自相关函数值,即序列与自身之间的互相关函数。 - -**函数名:** ACF - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列中共包含$2N-1$个数据点。 - -**提示:** - -+ 序列中的`NaN`值会被忽略,在计算中表现为0。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 3| -|2020-01-01T00:00:04.000+08:00| NaN| -|2020-01-01T00:00:05.000+08:00| 5| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select acf(s1) from root.test.d1 where time <= 2020-01-01 00:00:05 -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|acf(root.test.d1.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.002+08:00| 0.0| -|1970-01-01T08:00:00.003+08:00| 3.6| -|1970-01-01T08:00:00.004+08:00| 0.0| -|1970-01-01T08:00:00.005+08:00| 7.0| -|1970-01-01T08:00:00.006+08:00| 0.0| -|1970-01-01T08:00:00.007+08:00| 3.6| -|1970-01-01T08:00:00.008+08:00| 0.0| -|1970-01-01T08:00:00.009+08:00| 1.0| -+-----------------------------+--------------------+ -``` - -### Distinct - -#### 注册语句 - -```sql -create function distinct as 'org.apache.iotdb.library.dprofile.UDTFDistinct' -``` - -#### 函数简介 - -本函数可以返回输入序列中出现的所有不同的元素。 - -**函数名:** DISTINCT - -**输入序列:** 仅支持单个输入序列,类型可以是任意的 - -**输出序列:** 输出单个序列,类型与输入相同。 - -**提示:** - -+ 输出序列的时间戳是无意义的。输出顺序是任意的。 -+ 缺失值和空值将被忽略,但`NaN`不会被忽略。 -+ 字符串区分大小写 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s2| -+-----------------------------+---------------+ -|2020-01-01T08:00:00.001+08:00| Hello| -|2020-01-01T08:00:00.002+08:00| hello| -|2020-01-01T08:00:00.003+08:00| Hello| -|2020-01-01T08:00:00.004+08:00| World| -|2020-01-01T08:00:00.005+08:00| World| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select distinct(s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|distinct(root.test.d2.s2)| -+-----------------------------+-------------------------+ -|1970-01-01T08:00:00.001+08:00| Hello| -|1970-01-01T08:00:00.002+08:00| hello| -|1970-01-01T08:00:00.003+08:00| World| -+-----------------------------+-------------------------+ -``` - -### Histogram - -#### 注册语句 - -```sql -create function histogram as 'org.apache.iotdb.library.dprofile.UDTFHistogram' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的分布直方图。 - -**函数名:** HISTOGRAM - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `min`:表示所求数据范围的下限,默认值为 -Double.MAX_VALUE。 -+ `max`:表示所求数据范围的上限,默认值为 Double.MAX_VALUE,`start`的值必须小于或等于`end`。 -+ `count`: 表示直方图分桶的数量,默认值为 1,其值必须为正整数。 - -**输出序列:** 直方图分桶的值,其中第 i 个桶(从 1 开始计数)表示的数据范围下界为$min+ (i-1)\cdot\frac{max-min}{count}$,数据范围上界为$min+ i \cdot \frac{max-min}{count}$。 - - -**提示:** - -+ 如果某个数据点的数值小于`min`,它会被放入第 1 个桶;如果某个数据点的数值大于`max`,它会被放入最后 1 个桶。 -+ 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| -|2020-01-01T00:00:01.000+08:00| 2.0| -|2020-01-01T00:00:02.000+08:00| 3.0| -|2020-01-01T00:00:03.000+08:00| 4.0| -|2020-01-01T00:00:04.000+08:00| 5.0| -|2020-01-01T00:00:05.000+08:00| 6.0| -|2020-01-01T00:00:06.000+08:00| 7.0| -|2020-01-01T00:00:07.000+08:00| 8.0| -|2020-01-01T00:00:08.000+08:00| 9.0| -|2020-01-01T00:00:09.000+08:00| 10.0| -|2020-01-01T00:00:10.000+08:00| 11.0| -|2020-01-01T00:00:11.000+08:00| 12.0| -|2020-01-01T00:00:12.000+08:00| 13.0| -|2020-01-01T00:00:13.000+08:00| 14.0| -|2020-01-01T00:00:14.000+08:00| 15.0| -|2020-01-01T00:00:15.000+08:00| 16.0| -|2020-01-01T00:00:16.000+08:00| 17.0| -|2020-01-01T00:00:17.000+08:00| 18.0| -|2020-01-01T00:00:18.000+08:00| 19.0| -|2020-01-01T00:00:19.000+08:00| 20.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select histogram(s1,"min"="1","max"="20","count"="10") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------------------------------+ -| Time|histogram(root.test.d1.s1, "min"="1", "max"="20", "count"="10")| -+-----------------------------+---------------------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 2| -|1970-01-01T08:00:00.001+08:00| 2| -|1970-01-01T08:00:00.002+08:00| 2| -|1970-01-01T08:00:00.003+08:00| 2| -|1970-01-01T08:00:00.004+08:00| 2| -|1970-01-01T08:00:00.005+08:00| 2| -|1970-01-01T08:00:00.006+08:00| 2| -|1970-01-01T08:00:00.007+08:00| 2| -|1970-01-01T08:00:00.008+08:00| 2| -|1970-01-01T08:00:00.009+08:00| 2| -+-----------------------------+---------------------------------------------------------------+ -``` - -### Integral - -#### 注册语句 - -```sql -create function integral as 'org.apache.iotdb.library.dprofile.UDAFIntegral' -``` - -#### 函数简介 - -本函数用于计算时间序列的数值积分,即以时间为横坐标、数值为纵坐标绘制的折线图中折线以下的面积。 - -**函数名:** INTEGRAL - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `unit`:积分求解所用的时间轴单位,取值为 "1S", "1s", "1m", "1H", "1d"(区分大小写),分别表示以毫秒、秒、分钟、小时、天为单位计算积分。 - 缺省情况下取 "1s",以秒为单位。 - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为积分结果的数据点。 - -**提示:** - -+ 积分值等于折线图中每相邻两个数据点和时间轴形成的直角梯形的面积之和,不同时间单位下相当于横轴进行不同倍数放缩,得到的积分值可直接按放缩倍数转换。 - -+ 数据中`NaN`将会被忽略。折线将以临近两个有值数据点为准。 - -#### 使用示例 - -##### 参数缺省 - -缺省情况下积分以1s为时间单位。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| 2| -|2020-01-01T00:00:03.000+08:00| 5| -|2020-01-01T00:00:04.000+08:00| 6| -|2020-01-01T00:00:05.000+08:00| 7| -|2020-01-01T00:00:08.000+08:00| 8| -|2020-01-01T00:00:09.000+08:00| NaN| -|2020-01-01T00:00:10.000+08:00| 10| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select integral(s1) from root.test.d1 where time <= 2020-01-01 00:00:10 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|integral(root.test.d1.s1)| -+-----------------------------+-------------------------+ -|1970-01-01T08:00:00.000+08:00| 57.5| -+-----------------------------+-------------------------+ -``` - -其计算公式为: -$$\frac{1}{2}[(1+2)\times 1 + (2+5) \times 1 + (5+6) \times 1 + (6+7) \times 1 + (7+8) \times 3 + (8+10) \times 2] = 57.5$$ - - -##### 指定时间单位 - -指定以分钟为时间单位。 - - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select integral(s1, "unit"="1m") from root.test.d1 where time <= 2020-01-01 00:00:10 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|integral(root.test.d1.s1)| -+-----------------------------+-------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.958| -+-----------------------------+-------------------------+ -``` - -其计算公式为: -$$\frac{1}{2\times 60}[(1+2) \times 1 + (2+3) \times 1 + (5+6) \times 1 + (6+7) \times 1 + (7+8) \times 3 + (8+10) \times 2] = 0.958$$ - -### IntegralAvg - -#### 注册语句 - -```sql -create function integralavg as 'org.apache.iotdb.library.dprofile.UDAFIntegralAvg' -``` - -#### 函数简介 - -本函数用于计算时间序列的函数均值,即在相同时间单位下的数值积分除以序列总的时间跨度。更多关于数值积分计算的信息请参考`Integral`函数。 - -**函数名:** INTEGRALAVG - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为时间加权平均结果的数据点。 - -**提示:** - -+ 时间加权的平均值等于在任意时间单位`unit`下计算的数值积分(即折线图中每相邻两个数据点和时间轴形成的直角梯形的面积之和), - 除以相同时间单位下输入序列的时间跨度,其值与具体采用的时间单位无关,默认与 IoTDB 时间单位一致。 - -+ 数据中的`NaN`将会被忽略。折线将以临近两个有值数据点为准。 - -+ 输入序列为空时,函数输出结果为 0;仅有一个数据点时,输出结果为该点数值。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| 2| -|2020-01-01T00:00:03.000+08:00| 5| -|2020-01-01T00:00:04.000+08:00| 6| -|2020-01-01T00:00:05.000+08:00| 7| -|2020-01-01T00:00:08.000+08:00| 8| -|2020-01-01T00:00:09.000+08:00| NaN| -|2020-01-01T00:00:10.000+08:00| 10| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select integralavg(s1) from root.test.d1 where time <= 2020-01-01 00:00:10 -``` - -输出序列: - -``` -+-----------------------------+----------------------------+ -| Time|integralavg(root.test.d1.s1)| -+-----------------------------+----------------------------+ -|1970-01-01T08:00:00.000+08:00| 5.75| -+-----------------------------+----------------------------+ -``` - -其计算公式为: -$$\frac{1}{2}[(1+2)\times 1 + (2+5) \times 1 + (5+6) \times 1 + (6+7) \times 1 + (7+8) \times 3 + (8+10) \times 2] / 10 = 5.75$$ - -### Mad - -#### 注册语句 - -```sql -create function mad as 'org.apache.iotdb.library.dprofile.UDAFMad' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的精确或近似绝对中位差,绝对中位差为所有数值与其中位数绝对偏移量的中位数。 - -如有数据集$\{1,3,3,5,5,6,7,8,9\}$,其中位数为5,所有数值与中位数的偏移量的绝对值为$\{0,0,1,2,2,2,3,4,4\}$,其中位数为2,故而原数据集的绝对中位差为2。 - -**函数名:** MAD - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `error`:近似绝对中位差的基于数值的误差百分比,取值范围为 [0,1),默认值为 0。如当`error`=0.01 时,记精确绝对中位差为a,近似绝对中位差为b,不等式 $0.99a \le b \le 1.01a$ 成立。当`error`=0 时,计算结果为精确绝对中位差。 - - -**输出序列:** 输出单个序列,类型为DOUBLE,序列仅包含一个时间戳为 0、值为绝对中位差的数据点。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -##### 精确查询 - -当`error`参数缺省或为0时,本函数计算精确绝对中位差。 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -............ -Total line number = 20 -``` - -用于查询的 SQL 语句: - -```sql -select mad(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -| Time|median(root.test.s1, "error"="0")| -+-----------------------------+---------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -+-----------------------------+---------------------------------+ -``` - -##### 近似查询 - -当`error`参数取值不为 0 时,本函数计算近似绝对中位差。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select mad(s1, "error"="0.01") from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -| Time|mad(root.test.s1, "error"="0.01")| -+-----------------------------+---------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.9900000000000001| -+-----------------------------+---------------------------------+ -``` - -### Median - -#### 注册语句 - -```sql -create function median as 'org.apache.iotdb.library.dprofile.UDAFMedian' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的精确或近似中位数。中位数是顺序排列的一组数据中居于中间位置的数;当序列有偶数个时,中位数为中间二者的平均数。 - -**函数名:** MEDIAN - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `error`:近似中位数的基于排名的误差百分比,取值范围 [0,1),默认值为 0。如当`error`=0.01 时,计算出的中位数的真实排名百分比在 0.49~0.51 之间。当`error`=0 时,计算结果为精确中位数。 - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为中位数的数据点。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -Total line number = 20 -``` - -用于查询的 SQL 语句: - -```sql -select median(s1, "error"="0.01") from root.test -``` - -输出序列: - -``` -+-----------------------------+------------------------------------+ -| Time|median(root.test.s1, "error"="0.01")| -+-----------------------------+------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -+-----------------------------+------------------------------------+ -``` - -### MinMax - -#### 注册语句 - -```sql -create function minmax as 'org.apache.iotdb.library.dprofile.UDTFMinMax' -``` - -#### 函数简介 - -本函数将输入序列使用 min-max 方法进行标准化。最小值归一至 0,最大值归一至 1. - -**函数名:** MINMAX - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `compute`:若设置为"batch",则将数据全部读入后转换;若设置为 "stream",则需用户提供最大值及最小值进行流式计算转换。默认为 "batch"。 -+ `min`:使用流式计算时的最小值。 -+ `max`:使用流式计算时的最大值。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 全数据计算 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select minmax(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|minmax(root.test.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.100+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.200+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.300+08:00| 0.25| -|1970-01-01T08:00:00.400+08:00| 0.08333333333333333| -|1970-01-01T08:00:00.500+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.600+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.700+08:00| 0.0| -|1970-01-01T08:00:00.800+08:00| 0.3333333333333333| -|1970-01-01T08:00:00.900+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.000+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.100+08:00| 0.25| -|1970-01-01T08:00:01.200+08:00| 0.08333333333333333| -|1970-01-01T08:00:01.300+08:00| 0.08333333333333333| -|1970-01-01T08:00:01.400+08:00| 0.25| -|1970-01-01T08:00:01.500+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.600+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.700+08:00| 1.0| -|1970-01-01T08:00:01.800+08:00| 0.3333333333333333| -|1970-01-01T08:00:01.900+08:00| 0.0| -|1970-01-01T08:00:02.000+08:00| 0.16666666666666666| -+-----------------------------+--------------------+ -``` - - -### MvAvg - -#### 注册语句 - -```sql -create function mvavg as 'org.apache.iotdb.library.dprofile.UDTFMvAvg' -``` - -#### 函数简介 - -本函数计算序列的移动平均。 - -**函数名:** MVAVG - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `window`:移动窗口的长度。默认值为 10. - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 指定窗口长度 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select mvavg(s1, "window"="3") from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -| Time|mvavg(root.test.s1, "window"="3")| -+-----------------------------+---------------------------------+ -|1970-01-01T08:00:00.300+08:00| 0.3333333333333333| -|1970-01-01T08:00:00.400+08:00| 0.0| -|1970-01-01T08:00:00.500+08:00| -0.3333333333333333| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -0.6666666666666666| -|1970-01-01T08:00:00.800+08:00| 0.0| -|1970-01-01T08:00:00.900+08:00| 0.6666666666666666| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 0.3333333333333333| -|1970-01-01T08:00:01.200+08:00| 0.0| -|1970-01-01T08:00:01.300+08:00| -0.6666666666666666| -|1970-01-01T08:00:01.400+08:00| 0.0| -|1970-01-01T08:00:01.500+08:00| 0.3333333333333333| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 3.3333333333333335| -|1970-01-01T08:00:01.800+08:00| 4.0| -|1970-01-01T08:00:01.900+08:00| 0.0| -|1970-01-01T08:00:02.000+08:00| -0.6666666666666666| -+-----------------------------+---------------------------------+ -``` - -### PACF - -#### 注册语句 - -```sql -create function pacf as 'org.apache.iotdb.library.dprofile.UDTFPACF' -``` - -#### 函数简介 - -本函数通过求解 Yule-Walker 方程,计算序列的偏自相关系数。对于特殊的输入序列,方程可能没有解,此时输出`NaN`。 - -**函数名:** PACF - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `lag`:最大滞后阶数。默认值为$\min(10\log_{10}n,n-1)$,$n$表示数据点个数。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 指定滞后阶数 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 3| -|2020-01-01T00:00:04.000+08:00| NaN| -|2020-01-01T00:00:05.000+08:00| 5| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select pacf(s1, "lag"="5") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------+ -| Time|pacf(root.test.d1.s1, "lag"="5")| -+-----------------------------+--------------------------------+ -|2020-01-01T00:00:01.000+08:00| 1.0| -|2020-01-01T00:00:02.000+08:00| -0.5744680851063829| -|2020-01-01T00:00:03.000+08:00| 0.3172297297297296| -|2020-01-01T00:00:04.000+08:00| -0.2977686586304181| -|2020-01-01T00:00:05.000+08:00| -2.0609033521065867| -+-----------------------------+--------------------------------+ -``` - - -### Percentile - -#### 注册语句 - -```sql -create function percentile as 'org.apache.iotdb.library.dprofile.UDAFPercentile' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的精确或近似分位数。 - -**函数名:** PERCENTILE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `rank`:所求分位数在所有数据中的排名百分比,取值范围为 (0,1],默认值为 0.5。如当设为 0.5时则计算中位数。 -+ `error`:近似分位数的基于排名的误差百分比,取值范围为 [0,1),默认值为0。如`rank`=0.5 且`error`=0.01,则计算出的分位数的真实排名百分比在 0.49~0.51之间。当`error`=0 时,计算结果为精确分位数。 - -**输出序列:** 输出单个序列,类型与输入序列相同。当`error`=0时,序列仅包含一个时间戳为分位数第一次出现的时间戳、值为分位数的数据点;否则,输出值的时间戳为0。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+-------------+ -| Time|root.test2.s1| -+-----------------------------+-------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+-------------+ -............ -Total line number = 20 -``` - -用于查询的 SQL 语句: - -```sql -select percentile(s1, "rank"="0.2", "error"="0.01") from root.test -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------------+ -| Time|percentile(root.test2.s1, "rank"="0.2", "error"="0.01")| -+-----------------------------+-------------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| -1.0| -+-----------------------------+-------------------------------------------------------+ -``` - -### Quantile - -#### 注册语句 - -```sql -create function quantile as 'org.apache.iotdb.library.dprofile.UDAFQuantile' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的近似分位数。本函数基于KLL sketch算法实现。 - -**函数名:** QUANTILE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `rank`:所求分位数在所有数据中的排名比,取值范围为 (0,1],默认值为 0.5。如当设为 0.5时则计算近似中位数。 -+ `K`:允许维护的KLL sketch大小,最小值为100,默认值为800。如`rank`=0.5 且`K`=800,则计算出的分位数的真实排名比有至少99%的可能性在 0.49~0.51之间。 - -**输出序列:** 输出单个序列,类型与输入序列相同。输出值的时间戳为0。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - - -输入序列: - -``` -+-----------------------------+-------------+ -| Time|root.test1.s1| -+-----------------------------+-------------+ -|2021-03-17T10:32:17.054+08:00| 7| -|2021-03-17T10:32:18.054+08:00| 15| -|2021-03-17T10:32:19.054+08:00| 36| -|2021-03-17T10:32:20.054+08:00| 39| -|2021-03-17T10:32:21.054+08:00| 40| -|2021-03-17T10:32:22.054+08:00| 41| -|2021-03-17T10:32:23.054+08:00| 20| -|2021-03-17T10:32:24.054+08:00| 18| -+-----------------------------+-------------+ -............ -Total line number = 8 -``` - -用于查询的 SQL 语句: - -```sql -select quantile(s1, "rank"="0.2", "K"="800") from root.test1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------+ -| Time|quantile(root.test1.s1, "rank"="0.2", "K"="800")| -+-----------------------------+------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 7.000000000000001| -+-----------------------------+------------------------------------------------+ -``` - -### Period - -#### 注册语句 - -```sql -create function period as 'org.apache.iotdb.library.dprofile.UDAFPeriod' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的周期。 - -**函数名:** PERIOD - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型为 INT32,序列仅包含一个时间戳为 0、值为周期的数据点。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d3.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.002+08:00| 2.0| -|1970-01-01T08:00:00.003+08:00| 3.0| -|1970-01-01T08:00:00.004+08:00| 1.0| -|1970-01-01T08:00:00.005+08:00| 2.0| -|1970-01-01T08:00:00.006+08:00| 3.0| -|1970-01-01T08:00:00.007+08:00| 1.0| -|1970-01-01T08:00:00.008+08:00| 2.0| -|1970-01-01T08:00:00.009+08:00| 3.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select period(s1) from root.test.d3 -``` - -输出序列: - -``` -+-----------------------------+-----------------------+ -| Time|period(root.test.d3.s1)| -+-----------------------------+-----------------------+ -|1970-01-01T08:00:00.000+08:00| 3| -+-----------------------------+-----------------------+ -``` - -### QLB - -#### 注册语句 - -```sql -create function qlb as 'org.apache.iotdb.library.dprofile.UDTFQLB' -``` - -#### 函数简介 - -本函数对输入序列计算$Q_{LB} $统计量,并计算对应的p值。p值越小表明序列越有可能为非平稳序列。 - -**函数名:** QLB - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `lag`:计算时用到的最大延迟阶数,取值应为 1 至 n-2 之间的整数,n 为序列采样总数。默认取 n-2。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。该序列是$Q_{LB} $统计量对应的 p 值,时间标签代表偏移阶数。 - -**提示:** $Q_{LB} $统计量由自相关系数求得,如需得到统计量而非 p 值,可以使用 ACF 函数。 - -#### 使用示例 - -##### 使用默认参数 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T00:00:00.100+08:00| 1.22| -|1970-01-01T00:00:00.200+08:00| -2.78| -|1970-01-01T00:00:00.300+08:00| 1.53| -|1970-01-01T00:00:00.400+08:00| 0.70| -|1970-01-01T00:00:00.500+08:00| 0.75| -|1970-01-01T00:00:00.600+08:00| -0.72| -|1970-01-01T00:00:00.700+08:00| -0.22| -|1970-01-01T00:00:00.800+08:00| 0.28| -|1970-01-01T00:00:00.900+08:00| 0.57| -|1970-01-01T00:00:01.000+08:00| -0.22| -|1970-01-01T00:00:01.100+08:00| -0.72| -|1970-01-01T00:00:01.200+08:00| 1.34| -|1970-01-01T00:00:01.300+08:00| -0.25| -|1970-01-01T00:00:01.400+08:00| 0.17| -|1970-01-01T00:00:01.500+08:00| 2.51| -|1970-01-01T00:00:01.600+08:00| 1.42| -|1970-01-01T00:00:01.700+08:00| -1.34| -|1970-01-01T00:00:01.800+08:00| -0.01| -|1970-01-01T00:00:01.900+08:00| -0.49| -|1970-01-01T00:00:02.000+08:00| 1.63| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select QLB(s1) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|QLB(root.test.d1.s1)| -+-----------------------------+--------------------+ -|1970-01-01T00:00:00.001+08:00| 0.2168702295315677| -|1970-01-01T00:00:00.002+08:00| 0.3068948509261751| -|1970-01-01T00:00:00.003+08:00| 0.4217859150918444| -|1970-01-01T00:00:00.004+08:00| 0.5114539874276656| -|1970-01-01T00:00:00.005+08:00| 0.6560619525616759| -|1970-01-01T00:00:00.006+08:00| 0.7722398654053280| -|1970-01-01T00:00:00.007+08:00| 0.8532491661465290| -|1970-01-01T00:00:00.008+08:00| 0.9028575017542528| -|1970-01-01T00:00:00.009+08:00| 0.9434989988192729| -|1970-01-01T00:00:00.010+08:00| 0.8950280161464689| -|1970-01-01T00:00:00.011+08:00| 0.7701048398839656| -|1970-01-01T00:00:00.012+08:00| 0.7845536060001281| -|1970-01-01T00:00:00.013+08:00| 0.5943030981705825| -|1970-01-01T00:00:00.014+08:00| 0.4618413512531093| -|1970-01-01T00:00:00.015+08:00| 0.2645948244673964| -|1970-01-01T00:00:00.016+08:00| 0.3167530476666645| -|1970-01-01T00:00:00.017+08:00| 0.2330010780351453| -|1970-01-01T00:00:00.018+08:00| 0.0666611237622325| -+-----------------------------+--------------------+ -``` - -### Resample - -#### 注册语句 - -```sql -create function re_sample as 'org.apache.iotdb.library.dprofile.UDTFResample' -``` - -#### 函数简介 - -本函数对输入序列按照指定的频率进行重采样,包括上采样和下采样。目前,本函数支持的上采样方法包括`NaN`填充法 (NaN)、前值填充法 (FFill)、后值填充法 (BFill) 以及线性插值法 (Linear);本函数支持的下采样方法为分组聚合,聚合方法包括最大值 (Max)、最小值 (Min)、首值 (First)、末值 (Last)、平均值 (Mean)和中位数 (Median)。 - -**函数名:** RESAMPLE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `every`:重采样频率,是一个有单位的正数。目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。该参数不允许缺省。 -+ `interp`:上采样的插值方法,取值为 'NaN'、'FFill'、'BFill' 或 'Linear'。在缺省情况下,使用`NaN`填充法。 -+ `aggr`:下采样的聚合方法,取值为 'Max'、'Min'、'First'、'Last'、'Mean' 或 'Median'。在缺省情况下,使用平均数聚合。 -+ `start`:重采样的起始时间(包含),是一个格式为 'yyyy-MM-dd HH:mm:ss' 的时间字符串。在缺省情况下,使用第一个有效数据点的时间戳。 -+ `end`:重采样的结束时间(不包含),是一个格式为 'yyyy-MM-dd HH:mm:ss' 的时间字符串。在缺省情况下,使用最后一个有效数据点的时间戳。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。该序列按照重采样频率严格等间隔分布。 - -**提示:** 数据中的`NaN`将会被忽略。 - -#### 使用示例 - -##### 上采样 - -当重采样频率高于数据原始频率时,将会进行上采样。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2021-03-06T16:00:00.000+08:00| 3.09| -|2021-03-06T16:15:00.000+08:00| 3.53| -|2021-03-06T16:30:00.000+08:00| 3.5| -|2021-03-06T16:45:00.000+08:00| 3.51| -|2021-03-06T17:00:00.000+08:00| 3.41| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select resample(s1,'every'='5m','interp'='linear') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------------------------+ -| Time|resample(root.test.d1.s1, "every"="5m", "interp"="linear")| -+-----------------------------+----------------------------------------------------------+ -|2021-03-06T16:00:00.000+08:00| 3.0899999141693115| -|2021-03-06T16:05:00.000+08:00| 3.2366665999094644| -|2021-03-06T16:10:00.000+08:00| 3.3833332856496177| -|2021-03-06T16:15:00.000+08:00| 3.5299999713897705| -|2021-03-06T16:20:00.000+08:00| 3.5199999809265137| -|2021-03-06T16:25:00.000+08:00| 3.509999990463257| -|2021-03-06T16:30:00.000+08:00| 3.5| -|2021-03-06T16:35:00.000+08:00| 3.503333330154419| -|2021-03-06T16:40:00.000+08:00| 3.506666660308838| -|2021-03-06T16:45:00.000+08:00| 3.509999990463257| -|2021-03-06T16:50:00.000+08:00| 3.4766666889190674| -|2021-03-06T16:55:00.000+08:00| 3.443333387374878| -|2021-03-06T17:00:00.000+08:00| 3.4100000858306885| -+-----------------------------+----------------------------------------------------------+ -``` - -##### 下采样 - -当重采样频率低于数据原始频率时,将会进行下采样。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select resample(s1,'every'='30m','aggr'='first') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------+ -| Time|resample(root.test.d1.s1, "every"="30m", "aggr"="first")| -+-----------------------------+--------------------------------------------------------+ -|2021-03-06T16:00:00.000+08:00| 3.0899999141693115| -|2021-03-06T16:30:00.000+08:00| 3.5| -|2021-03-06T17:00:00.000+08:00| 3.4100000858306885| -+-----------------------------+--------------------------------------------------------+ -``` - - -###### 指定重采样时间段 - -可以使用`start`和`end`两个参数指定重采样的时间段,超出实际时间范围的部分会被插值填补。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select resample(s1,'every'='30m','start'='2021-03-06 15:00:00') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------------------------------------+ -| Time|resample(root.test.d1.s1, "every"="30m", "start"="2021-03-06 15:00:00")| -+-----------------------------+-----------------------------------------------------------------------+ -|2021-03-06T15:00:00.000+08:00| NaN| -|2021-03-06T15:30:00.000+08:00| NaN| -|2021-03-06T16:00:00.000+08:00| 3.309999942779541| -|2021-03-06T16:30:00.000+08:00| 3.5049999952316284| -|2021-03-06T17:00:00.000+08:00| 3.4100000858306885| -+-----------------------------+-----------------------------------------------------------------------+ -``` - -### Sample - -#### 注册语句 - -```sql -create function sample as 'org.apache.iotdb.library.dprofile.UDTFSample' -``` - -#### 函数简介 - -本函数对输入序列进行采样,即从输入序列中选取指定数量的数据点并输出。目前,本函数支持三种采样方法:**蓄水池采样法 (reservoir sampling)** 对数据进行随机采样,所有数据点被采样的概率相同;**等距采样法 (isometric sampling)** 按照相等的索引间隔对数据进行采样,**最大三角采样法 (triangle sampling)** 对所有数据会按采样率分桶,每个桶内会计算数据点间三角形面积,并保留面积最大的点,该算法通常用于数据的可视化展示中,采用过程可以保证一些关键的突变点在采用中得到保留,更多抽样算法细节可以阅读论文 [here](http://skemman.is/stream/get/1946/15343/37285/3/SS_MSthesis.pdf)。 - -**函数名:** SAMPLE - -**输入序列:** 仅支持单个输入序列,类型可以是任意的。 - -**参数:** - -+ `method`:采样方法,取值为 'reservoir','isometric' 或 'triangle' 。在缺省情况下,采用蓄水池采样法。 -+ `k`:采样数,它是一个正整数,在缺省情况下为 1。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列的长度为采样数,序列中的每一个数据点都来自于输入序列。 - -**提示:** 如果采样数大于序列长度,那么输入序列中所有的数据点都会被输出。 - -#### 使用示例 - - -##### 蓄水池采样 - -当`method`参数为 'reservoir' 或缺省时,采用蓄水池采样法对输入序列进行采样。由于该采样方法具有随机性,下面展示的输出序列只是一种可能的结果。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1.0| -|2020-01-01T00:00:02.000+08:00| 2.0| -|2020-01-01T00:00:03.000+08:00| 3.0| -|2020-01-01T00:00:04.000+08:00| 4.0| -|2020-01-01T00:00:05.000+08:00| 5.0| -|2020-01-01T00:00:06.000+08:00| 6.0| -|2020-01-01T00:00:07.000+08:00| 7.0| -|2020-01-01T00:00:08.000+08:00| 8.0| -|2020-01-01T00:00:09.000+08:00| 9.0| -|2020-01-01T00:00:10.000+08:00| 10.0| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select sample(s1,'method'='reservoir','k'='5') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|sample(root.test.d1.s1, "method"="reservoir", "k"="5")| -+-----------------------------+------------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 2.0| -|2020-01-01T00:00:03.000+08:00| 3.0| -|2020-01-01T00:00:05.000+08:00| 5.0| -|2020-01-01T00:00:08.000+08:00| 8.0| -|2020-01-01T00:00:10.000+08:00| 10.0| -+-----------------------------+------------------------------------------------------+ -``` - - -##### 等距采样 - -当`method`参数为 'isometric' 时,采用等距采样法对输入序列进行采样。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select sample(s1,'method'='isometric','k'='5') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|sample(root.test.d1.s1, "method"="isometric", "k"="5")| -+-----------------------------+------------------------------------------------------+ -|2020-01-01T00:00:01.000+08:00| 1.0| -|2020-01-01T00:00:03.000+08:00| 3.0| -|2020-01-01T00:00:05.000+08:00| 5.0| -|2020-01-01T00:00:07.000+08:00| 7.0| -|2020-01-01T00:00:09.000+08:00| 9.0| -+-----------------------------+------------------------------------------------------+ -``` - -### Segment - -#### 注册语句 - -```sql -create function segment as 'org.apache.iotdb.library.dprofile.UDTFSegment' -``` - -#### 函数简介 - -本函数按照数据的线性变化趋势将数据划分为多个子序列,返回分段直线拟合后的子序列首值或所有拟合值。 - -**函数名:** SEGMENT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `output`:"all" 输出所有拟合值;"first" 输出子序列起点拟合值。默认为 "first"。 - -+ `error`:判定存在线性趋势的误差允许阈值。误差的定义为子序列进行线性拟合的误差的绝对值的均值。默认为 0.1. - -**输出序列:** 输出单个序列,类型为 DOUBLE。 - -**提示:** 函数默认所有数据等时间间隔分布。函数读取所有数据,若原始数据过多,请先进行降采样处理。拟合采用自底向上方法,子序列的尾值可能会被认作子序列首值输出。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 5.0| -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 1.0| -|1970-01-01T08:00:00.300+08:00| 2.0| -|1970-01-01T08:00:00.400+08:00| 3.0| -|1970-01-01T08:00:00.500+08:00| 4.0| -|1970-01-01T08:00:00.600+08:00| 5.0| -|1970-01-01T08:00:00.700+08:00| 6.0| -|1970-01-01T08:00:00.800+08:00| 7.0| -|1970-01-01T08:00:00.900+08:00| 8.0| -|1970-01-01T08:00:01.000+08:00| 9.0| -|1970-01-01T08:00:01.100+08:00| 9.1| -|1970-01-01T08:00:01.200+08:00| 9.2| -|1970-01-01T08:00:01.300+08:00| 9.3| -|1970-01-01T08:00:01.400+08:00| 9.4| -|1970-01-01T08:00:01.500+08:00| 9.5| -|1970-01-01T08:00:01.600+08:00| 9.6| -|1970-01-01T08:00:01.700+08:00| 9.7| -|1970-01-01T08:00:01.800+08:00| 9.8| -|1970-01-01T08:00:01.900+08:00| 9.9| -|1970-01-01T08:00:02.000+08:00| 10.0| -|1970-01-01T08:00:02.100+08:00| 8.0| -|1970-01-01T08:00:02.200+08:00| 6.0| -|1970-01-01T08:00:02.300+08:00| 4.0| -|1970-01-01T08:00:02.400+08:00| 2.0| -|1970-01-01T08:00:02.500+08:00| 0.0| -|1970-01-01T08:00:02.600+08:00| -2.0| -|1970-01-01T08:00:02.700+08:00| -4.0| -|1970-01-01T08:00:02.800+08:00| -6.0| -|1970-01-01T08:00:02.900+08:00| -8.0| -|1970-01-01T08:00:03.000+08:00| -10.0| -|1970-01-01T08:00:03.100+08:00| 10.0| -|1970-01-01T08:00:03.200+08:00| 10.0| -|1970-01-01T08:00:03.300+08:00| 10.0| -|1970-01-01T08:00:03.400+08:00| 10.0| -|1970-01-01T08:00:03.500+08:00| 10.0| -|1970-01-01T08:00:03.600+08:00| 10.0| -|1970-01-01T08:00:03.700+08:00| 10.0| -|1970-01-01T08:00:03.800+08:00| 10.0| -|1970-01-01T08:00:03.900+08:00| 10.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select segment(s1,"error"="0.1") from root.test -``` - -输出序列: - -``` -+-----------------------------+------------------------------------+ -| Time|segment(root.test.s1, "error"="0.1")| -+-----------------------------+------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 5.0| -|1970-01-01T08:00:00.200+08:00| 1.0| -|1970-01-01T08:00:01.000+08:00| 9.0| -|1970-01-01T08:00:02.000+08:00| 10.0| -|1970-01-01T08:00:03.000+08:00| -10.0| -|1970-01-01T08:00:03.200+08:00| 10.0| -+-----------------------------+------------------------------------+ -``` - -### Skew - -#### 注册语句 - -```sql -create function skew as 'org.apache.iotdb.library.dprofile.UDAFSkew' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的总体偏度 - -**函数名:** SKEW - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为总体偏度的数据点。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| -|2020-01-01T00:00:01.000+08:00| 2.0| -|2020-01-01T00:00:02.000+08:00| 3.0| -|2020-01-01T00:00:03.000+08:00| 4.0| -|2020-01-01T00:00:04.000+08:00| 5.0| -|2020-01-01T00:00:05.000+08:00| 6.0| -|2020-01-01T00:00:06.000+08:00| 7.0| -|2020-01-01T00:00:07.000+08:00| 8.0| -|2020-01-01T00:00:08.000+08:00| 9.0| -|2020-01-01T00:00:09.000+08:00| 10.0| -|2020-01-01T00:00:10.000+08:00| 10.0| -|2020-01-01T00:00:11.000+08:00| 10.0| -|2020-01-01T00:00:12.000+08:00| 10.0| -|2020-01-01T00:00:13.000+08:00| 10.0| -|2020-01-01T00:00:14.000+08:00| 10.0| -|2020-01-01T00:00:15.000+08:00| 10.0| -|2020-01-01T00:00:16.000+08:00| 10.0| -|2020-01-01T00:00:17.000+08:00| 10.0| -|2020-01-01T00:00:18.000+08:00| 10.0| -|2020-01-01T00:00:19.000+08:00| 10.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select skew(s1) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------+ -| Time| skew(root.test.d1.s1)| -+-----------------------------+-----------------------+ -|1970-01-01T08:00:00.000+08:00| -0.9998427402292644| -+-----------------------------+-----------------------+ -``` - -### Spline - -#### 注册语句 - -```sql -create function spline as 'org.apache.iotdb.library.dprofile.UDTFSpline' -``` - -#### 函数简介 - -本函数提供对原始序列进行三次样条曲线拟合后的插值重采样。 - -**函数名:** SPLINE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `points`:重采样个数。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -**提示**:输出序列保留输入序列的首尾值,等时间间隔采样。仅当输入点个数不少于 4 个时才计算插值。 - -#### 使用示例 - -##### 指定插值个数 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.2| -|1970-01-01T08:00:00.500+08:00| 1.7| -|1970-01-01T08:00:00.700+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 2.1| -|1970-01-01T08:00:01.100+08:00| 2.0| -|1970-01-01T08:00:01.200+08:00| 1.8| -|1970-01-01T08:00:01.300+08:00| 1.2| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 1.6| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select spline(s1, "points"="151") from root.test -``` - -输出序列: - -``` -+-----------------------------+------------------------------------+ -| Time|spline(root.test.s1, "points"="151")| -+-----------------------------+------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.010+08:00| 0.04870000251134237| -|1970-01-01T08:00:00.020+08:00| 0.09680000495910646| -|1970-01-01T08:00:00.030+08:00| 0.14430000734329226| -|1970-01-01T08:00:00.040+08:00| 0.19120000966389972| -|1970-01-01T08:00:00.050+08:00| 0.23750001192092896| -|1970-01-01T08:00:00.060+08:00| 0.2832000141143799| -|1970-01-01T08:00:00.070+08:00| 0.32830001624425253| -|1970-01-01T08:00:00.080+08:00| 0.3728000183105469| -|1970-01-01T08:00:00.090+08:00| 0.416700020313263| -|1970-01-01T08:00:00.100+08:00| 0.4600000222524008| -|1970-01-01T08:00:00.110+08:00| 0.5027000241279602| -|1970-01-01T08:00:00.120+08:00| 0.5448000259399414| -|1970-01-01T08:00:00.130+08:00| 0.5863000276883443| -|1970-01-01T08:00:00.140+08:00| 0.627200029373169| -|1970-01-01T08:00:00.150+08:00| 0.6675000309944153| -|1970-01-01T08:00:00.160+08:00| 0.7072000325520833| -|1970-01-01T08:00:00.170+08:00| 0.7463000340461731| -|1970-01-01T08:00:00.180+08:00| 0.7848000354766846| -|1970-01-01T08:00:00.190+08:00| 0.8227000368436178| -|1970-01-01T08:00:00.200+08:00| 0.8600000381469728| -|1970-01-01T08:00:00.210+08:00| 0.8967000393867494| -|1970-01-01T08:00:00.220+08:00| 0.9328000405629477| -|1970-01-01T08:00:00.230+08:00| 0.9683000416755676| -|1970-01-01T08:00:00.240+08:00| 1.0032000427246095| -|1970-01-01T08:00:00.250+08:00| 1.037500043710073| -|1970-01-01T08:00:00.260+08:00| 1.071200044631958| -|1970-01-01T08:00:00.270+08:00| 1.1043000454902647| -|1970-01-01T08:00:00.280+08:00| 1.1368000462849934| -|1970-01-01T08:00:00.290+08:00| 1.1687000470161437| -|1970-01-01T08:00:00.300+08:00| 1.2000000476837158| -|1970-01-01T08:00:00.310+08:00| 1.2307000483103594| -|1970-01-01T08:00:00.320+08:00| 1.2608000489139557| -|1970-01-01T08:00:00.330+08:00| 1.2903000494873524| -|1970-01-01T08:00:00.340+08:00| 1.3192000500233967| -|1970-01-01T08:00:00.350+08:00| 1.3475000505149364| -|1970-01-01T08:00:00.360+08:00| 1.3752000509548186| -|1970-01-01T08:00:00.370+08:00| 1.402300051335891| -|1970-01-01T08:00:00.380+08:00| 1.4288000516510009| -|1970-01-01T08:00:00.390+08:00| 1.4547000518929958| -|1970-01-01T08:00:00.400+08:00| 1.480000052054723| -|1970-01-01T08:00:00.410+08:00| 1.5047000521290301| -|1970-01-01T08:00:00.420+08:00| 1.5288000521087646| -|1970-01-01T08:00:00.430+08:00| 1.5523000519867738| -|1970-01-01T08:00:00.440+08:00| 1.575200051755905| -|1970-01-01T08:00:00.450+08:00| 1.597500051409006| -|1970-01-01T08:00:00.460+08:00| 1.619200050938924| -|1970-01-01T08:00:00.470+08:00| 1.6403000503385066| -|1970-01-01T08:00:00.480+08:00| 1.660800049600601| -|1970-01-01T08:00:00.490+08:00| 1.680700048718055| -|1970-01-01T08:00:00.500+08:00| 1.7000000476837158| -|1970-01-01T08:00:00.510+08:00| 1.7188475466453037| -|1970-01-01T08:00:00.520+08:00| 1.7373800457262996| -|1970-01-01T08:00:00.530+08:00| 1.7555825448831923| -|1970-01-01T08:00:00.540+08:00| 1.7734400440724702| -|1970-01-01T08:00:00.550+08:00| 1.790937543250622| -|1970-01-01T08:00:00.560+08:00| 1.8080600423741364| -|1970-01-01T08:00:00.570+08:00| 1.8247925413995016| -|1970-01-01T08:00:00.580+08:00| 1.8411200402832066| -|1970-01-01T08:00:00.590+08:00| 1.8570275389817397| -|1970-01-01T08:00:00.600+08:00| 1.8725000374515897| -|1970-01-01T08:00:00.610+08:00| 1.8875225356492449| -|1970-01-01T08:00:00.620+08:00| 1.902080033531194| -|1970-01-01T08:00:00.630+08:00| 1.9161575310539258| -|1970-01-01T08:00:00.640+08:00| 1.9297400281739288| -|1970-01-01T08:00:00.650+08:00| 1.9428125248476913| -|1970-01-01T08:00:00.660+08:00| 1.9553600210317021| -|1970-01-01T08:00:00.670+08:00| 1.96736751668245| -|1970-01-01T08:00:00.680+08:00| 1.9788200117564232| -|1970-01-01T08:00:00.690+08:00| 1.9897025062101101| -|1970-01-01T08:00:00.700+08:00| 2.0| -|1970-01-01T08:00:00.710+08:00| 2.0097024933913334| -|1970-01-01T08:00:00.720+08:00| 2.0188199867081615| -|1970-01-01T08:00:00.730+08:00| 2.027367479995188| -|1970-01-01T08:00:00.740+08:00| 2.0353599732971155| -|1970-01-01T08:00:00.750+08:00| 2.0428124666586482| -|1970-01-01T08:00:00.760+08:00| 2.049739960124489| -|1970-01-01T08:00:00.770+08:00| 2.056157453739342| -|1970-01-01T08:00:00.780+08:00| 2.06207994754791| -|1970-01-01T08:00:00.790+08:00| 2.067522441594897| -|1970-01-01T08:00:00.800+08:00| 2.072499935925006| -|1970-01-01T08:00:00.810+08:00| 2.07702743058294| -|1970-01-01T08:00:00.820+08:00| 2.081119925613404| -|1970-01-01T08:00:00.830+08:00| 2.0847924210611| -|1970-01-01T08:00:00.840+08:00| 2.0880599169707317| -|1970-01-01T08:00:00.850+08:00| 2.0909374133870027| -|1970-01-01T08:00:00.860+08:00| 2.0934399103546166| -|1970-01-01T08:00:00.870+08:00| 2.0955824079182768| -|1970-01-01T08:00:00.880+08:00| 2.0973799061226863| -|1970-01-01T08:00:00.890+08:00| 2.098847405012549| -|1970-01-01T08:00:00.900+08:00| 2.0999999046325684| -|1970-01-01T08:00:00.910+08:00| 2.1005574051201332| -|1970-01-01T08:00:00.920+08:00| 2.1002599065303778| -|1970-01-01T08:00:00.930+08:00| 2.0991524087846245| -|1970-01-01T08:00:00.940+08:00| 2.0972799118041947| -|1970-01-01T08:00:00.950+08:00| 2.0946874155104105| -|1970-01-01T08:00:00.960+08:00| 2.0914199198245944| -|1970-01-01T08:00:00.970+08:00| 2.0875224246680673| -|1970-01-01T08:00:00.980+08:00| 2.083039929962151| -|1970-01-01T08:00:00.990+08:00| 2.0780174356281687| -|1970-01-01T08:00:01.000+08:00| 2.0724999415874406| -|1970-01-01T08:00:01.010+08:00| 2.06653244776129| -|1970-01-01T08:00:01.020+08:00| 2.060159954071038| -|1970-01-01T08:00:01.030+08:00| 2.053427460438006| -|1970-01-01T08:00:01.040+08:00| 2.046379966783517| -|1970-01-01T08:00:01.050+08:00| 2.0390624730288924| -|1970-01-01T08:00:01.060+08:00| 2.031519979095454| -|1970-01-01T08:00:01.070+08:00| 2.0237974849045237| -|1970-01-01T08:00:01.080+08:00| 2.015939990377423| -|1970-01-01T08:00:01.090+08:00| 2.0079924954354746| -|1970-01-01T08:00:01.100+08:00| 2.0| -|1970-01-01T08:00:01.110+08:00| 1.9907018211101906| -|1970-01-01T08:00:01.120+08:00| 1.9788509124245144| -|1970-01-01T08:00:01.130+08:00| 1.9645127287932083| -|1970-01-01T08:00:01.140+08:00| 1.9477527250665083| -|1970-01-01T08:00:01.150+08:00| 1.9286363560946513| -|1970-01-01T08:00:01.160+08:00| 1.9072290767278735| -|1970-01-01T08:00:01.170+08:00| 1.8835963418164114| -|1970-01-01T08:00:01.180+08:00| 1.8578036062105014| -|1970-01-01T08:00:01.190+08:00| 1.8299163247603802| -|1970-01-01T08:00:01.200+08:00| 1.7999999523162842| -|1970-01-01T08:00:01.210+08:00| 1.7623635841923329| -|1970-01-01T08:00:01.220+08:00| 1.7129696477516976| -|1970-01-01T08:00:01.230+08:00| 1.6543635959181928| -|1970-01-01T08:00:01.240+08:00| 1.5890908816156328| -|1970-01-01T08:00:01.250+08:00| 1.5196969577678319| -|1970-01-01T08:00:01.260+08:00| 1.4487272772986044| -|1970-01-01T08:00:01.270+08:00| 1.3787272931317647| -|1970-01-01T08:00:01.280+08:00| 1.3122424581911272| -|1970-01-01T08:00:01.290+08:00| 1.251818225400506| -|1970-01-01T08:00:01.300+08:00| 1.2000000476837158| -|1970-01-01T08:00:01.310+08:00| 1.1548000470995912| -|1970-01-01T08:00:01.320+08:00| 1.1130667107899999| -|1970-01-01T08:00:01.330+08:00| 1.0756000393033045| -|1970-01-01T08:00:01.340+08:00| 1.043200033187868| -|1970-01-01T08:00:01.350+08:00| 1.016666692992053| -|1970-01-01T08:00:01.360+08:00| 0.9968000192642223| -|1970-01-01T08:00:01.370+08:00| 0.9844000125527389| -|1970-01-01T08:00:01.380+08:00| 0.9802666734059655| -|1970-01-01T08:00:01.390+08:00| 0.9852000023722649| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.410+08:00| 1.023999999165535| -|1970-01-01T08:00:01.420+08:00| 1.0559999990463256| -|1970-01-01T08:00:01.430+08:00| 1.0959999996423722| -|1970-01-01T08:00:01.440+08:00| 1.1440000009536744| -|1970-01-01T08:00:01.450+08:00| 1.2000000029802322| -|1970-01-01T08:00:01.460+08:00| 1.264000005722046| -|1970-01-01T08:00:01.470+08:00| 1.3360000091791153| -|1970-01-01T08:00:01.480+08:00| 1.4160000133514405| -|1970-01-01T08:00:01.490+08:00| 1.5040000182390214| -|1970-01-01T08:00:01.500+08:00| 1.600000023841858| -+-----------------------------+------------------------------------+ -``` - -### Spread - -#### 注册语句 - -```sql -create function spread as 'org.apache.iotdb.library.dprofile.UDAFSpread' -``` - -#### 函数简介 - -本函数用于计算时间序列的极差,即最大值减去最小值的结果。 - -**函数名:** SPREAD - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型与输入相同,序列仅包含一个时间戳为 0 、值为极差的数据点。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select spread(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+-----------------------+ -| Time|spread(root.test.d1.s1)| -+-----------------------------+-----------------------+ -|1970-01-01T08:00:00.000+08:00| 26.0| -+-----------------------------+-----------------------+ -``` - - -### ZScore - -#### 注册语句 - -```sql -create function zscore as 'org.apache.iotdb.library.dprofile.UDTFZScore' -``` - -#### 函数简介 - -本函数将输入序列使用z-score方法进行归一化。 - -**函数名:** ZSCORE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `compute`:若设置为 "batch",则将数据全部读入后转换;若设置为 "stream",则需用户提供均值及方差进行流式计算转换。默认为 "batch"。 -+ `avg`:使用流式计算时的均值。 -+ `sd`:使用流式计算时的标准差。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 全数据计算 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select zscore(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|zscore(root.test.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.100+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.200+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.300+08:00| 0.20672455764868078| -|1970-01-01T08:00:00.400+08:00| -0.6201736729460423| -|1970-01-01T08:00:00.500+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.600+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.700+08:00| -1.033622788243404| -|1970-01-01T08:00:00.800+08:00| 0.6201736729460423| -|1970-01-01T08:00:00.900+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.000+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.100+08:00| 0.20672455764868078| -|1970-01-01T08:00:01.200+08:00| -0.6201736729460423| -|1970-01-01T08:00:01.300+08:00| -0.6201736729460423| -|1970-01-01T08:00:01.400+08:00| 0.20672455764868078| -|1970-01-01T08:00:01.500+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.600+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.700+08:00| 3.9277665953249348| -|1970-01-01T08:00:01.800+08:00| 0.6201736729460423| -|1970-01-01T08:00:01.900+08:00| -1.033622788243404| -|1970-01-01T08:00:02.000+08:00|-0.20672455764868078| -+-----------------------------+--------------------+ -``` - - - -## 异常检测 - -### IQR - -#### 注册语句 - -```sql -create function iqr as 'org.apache.iotdb.library.anomaly.UDTFIQR' -``` - -#### 函数简介 - -本函数用于检验超出上下四分位数1.5倍IQR的数据分布异常。 - -**函数名:** IQR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `method`:若设置为 "batch",则将数据全部读入后检测;若设置为 "stream",则需用户提供上下四分位数进行流式检测。默认为 "batch"。 -+ `q1`:使用流式计算时的下四分位数。 -+ `q3`:使用流式计算时的上四分位数。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -**说明**:$IQR=Q_3-Q_1$ - -#### 使用示例 - -##### 全数据计算 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select iqr(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+-----------------+ -| Time|iqr(root.test.s1)| -+-----------------------------+-----------------+ -|1970-01-01T08:00:01.700+08:00| 10.0| -+-----------------------------+-----------------+ -``` - -### KSigma - -#### 注册语句 - -```sql -create function ksigma as 'org.apache.iotdb.library.anomaly.UDTFKSigma' -``` - -#### 函数简介 - -本函数利用动态 K-Sigma 算法进行异常检测。在一个窗口内,与平均值的差距超过k倍标准差的数据将被视作异常并输出。 - -**函数名:** KSIGMA - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `k`:在动态 K-Sigma 算法中,分布异常的标准差倍数阈值,默认值为 3。 -+ `window`:动态 K-Sigma 算法的滑动窗口大小,默认值为 10000。 - - -**输出序列:** 输出单个序列,类型与输入序列相同。 - -**提示:** k 应大于 0,否则将不做输出。 - -#### 使用示例 - -##### 指定k - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 0.0| -|2020-01-01T00:00:03.000+08:00| 50.0| -|2020-01-01T00:00:04.000+08:00| 100.0| -|2020-01-01T00:00:06.000+08:00| 150.0| -|2020-01-01T00:00:08.000+08:00| 200.0| -|2020-01-01T00:00:10.000+08:00| 200.0| -|2020-01-01T00:00:14.000+08:00| 200.0| -|2020-01-01T00:00:15.000+08:00| 200.0| -|2020-01-01T00:00:16.000+08:00| 200.0| -|2020-01-01T00:00:18.000+08:00| 200.0| -|2020-01-01T00:00:20.000+08:00| 150.0| -|2020-01-01T00:00:22.000+08:00| 100.0| -|2020-01-01T00:00:26.000+08:00| 50.0| -|2020-01-01T00:00:28.000+08:00| 0.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select ksigma(s1,"k"="1.0") from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -|Time |ksigma(root.test.d1.s1,"k"="3.0")| -+-----------------------------+---------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.0| -|2020-01-01T00:00:03.000+08:00| 50.0| -|2020-01-01T00:00:26.000+08:00| 50.0| -|2020-01-01T00:00:28.000+08:00| 0.0| -+-----------------------------+---------------------------------+ -``` - -### LOF - -#### 注册语句 - -```sql -create function LOF as 'org.apache.iotdb.library.anomaly.UDTFLOF' -``` - -#### 函数简介 - -本函数使用局部离群点检测方法用于查找序列的密度异常。将根据提供的第k距离数及局部离群点因子(lof)阈值,判断输入数据是否为离群点,即异常,并输出各点的 LOF 值。 - -**函数名:** LOF - -**输入序列:** 多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`:使用的检测方法。默认为 default,以高维数据计算。设置为 series,将一维时间序列转换为高维数据计算。 -+ `k`:使用第k距离计算局部离群点因子.默认为 3。 -+ `window`:每次读取数据的窗口长度。默认为 10000. -+ `windowsize`:使用series方法时,转化高维数据的维数,即单个窗口的大小。默认为 5。 - -**输出序列:** 输出单时间序列,类型为DOUBLE。 - -**提示:** 不完整的数据行会被忽略,不参与计算,也不标记为离群点。 - - -#### 使用示例 - -##### 默认参数 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| 1.0| -|1970-01-01T08:00:00.300+08:00| 1.0| 1.0| -|1970-01-01T08:00:00.400+08:00| 1.0| 0.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -1.0| -|1970-01-01T08:00:00.600+08:00| -1.0| -1.0| -|1970-01-01T08:00:00.700+08:00| -1.0| 0.0| -|1970-01-01T08:00:00.800+08:00| 2.0| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| null| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select lof(s1,s2) from root.test.d1 where time<1000 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|lof(root.test.d1.s1, root.test.d1.s2)| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.100+08:00| 3.8274824267668244| -|1970-01-01T08:00:00.200+08:00| 3.0117631741126156| -|1970-01-01T08:00:00.300+08:00| 2.838155437762879| -|1970-01-01T08:00:00.400+08:00| 3.0117631741126156| -|1970-01-01T08:00:00.500+08:00| 2.73518261244453| -|1970-01-01T08:00:00.600+08:00| 2.371440975708148| -|1970-01-01T08:00:00.700+08:00| 2.73518261244453| -|1970-01-01T08:00:00.800+08:00| 1.7561416374270742| -+-----------------------------+-------------------------------------+ -``` - -##### 诊断一维时间序列 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.100+08:00| 1.0| -|1970-01-01T08:00:00.200+08:00| 2.0| -|1970-01-01T08:00:00.300+08:00| 3.0| -|1970-01-01T08:00:00.400+08:00| 4.0| -|1970-01-01T08:00:00.500+08:00| 5.0| -|1970-01-01T08:00:00.600+08:00| 6.0| -|1970-01-01T08:00:00.700+08:00| 7.0| -|1970-01-01T08:00:00.800+08:00| 8.0| -|1970-01-01T08:00:00.900+08:00| 9.0| -|1970-01-01T08:00:01.000+08:00| 10.0| -|1970-01-01T08:00:01.100+08:00| 11.0| -|1970-01-01T08:00:01.200+08:00| 12.0| -|1970-01-01T08:00:01.300+08:00| 13.0| -|1970-01-01T08:00:01.400+08:00| 14.0| -|1970-01-01T08:00:01.500+08:00| 15.0| -|1970-01-01T08:00:01.600+08:00| 16.0| -|1970-01-01T08:00:01.700+08:00| 17.0| -|1970-01-01T08:00:01.800+08:00| 18.0| -|1970-01-01T08:00:01.900+08:00| 19.0| -|1970-01-01T08:00:02.000+08:00| 20.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select lof(s1, "method"="series") from root.test.d1 where time<1000 -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|lof(root.test.d1.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.100+08:00| 3.77777777777778| -|1970-01-01T08:00:00.200+08:00| 4.32727272727273| -|1970-01-01T08:00:00.300+08:00| 4.85714285714286| -|1970-01-01T08:00:00.400+08:00| 5.40909090909091| -|1970-01-01T08:00:00.500+08:00| 5.94999999999999| -|1970-01-01T08:00:00.600+08:00| 6.43243243243243| -|1970-01-01T08:00:00.700+08:00| 6.79999999999999| -|1970-01-01T08:00:00.800+08:00| 7.0| -|1970-01-01T08:00:00.900+08:00| 7.0| -|1970-01-01T08:00:01.000+08:00| 6.79999999999999| -|1970-01-01T08:00:01.100+08:00| 6.43243243243243| -|1970-01-01T08:00:01.200+08:00| 5.94999999999999| -|1970-01-01T08:00:01.300+08:00| 5.40909090909091| -|1970-01-01T08:00:01.400+08:00| 4.85714285714286| -|1970-01-01T08:00:01.500+08:00| 4.32727272727273| -|1970-01-01T08:00:01.600+08:00| 3.77777777777778| -+-----------------------------+--------------------+ -``` - -### MissDetect - -#### 注册语句 - -```sql -create function missdetect as 'org.apache.iotdb.library.anomaly.UDTFMissDetect' -``` - -#### 函数简介 - -本函数用于检测数据中的缺失异常。在一些数据中,缺失数据会被线性插值填补,在数据中出现完美的线性片段,且这些片段往往长度较大。本函数通过在数据中发现这些完美线性片段来检测缺失异常。 - -**函数名:** MISSDETECT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `minlen`:被标记为异常的完美线性片段的最小长度,是一个大于等于 10 的整数,默认值为 10。 - -**输出序列:** 输出单个序列,类型为 BOOLEAN,即该数据点是否为缺失异常。 - -**提示:** 数据中的`NaN`将会被忽略。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s2| -+-----------------------------+---------------+ -|2021-07-01T12:00:00.000+08:00| 0.0| -|2021-07-01T12:00:01.000+08:00| 1.0| -|2021-07-01T12:00:02.000+08:00| 0.0| -|2021-07-01T12:00:03.000+08:00| 1.0| -|2021-07-01T12:00:04.000+08:00| 0.0| -|2021-07-01T12:00:05.000+08:00| 0.0| -|2021-07-01T12:00:06.000+08:00| 0.0| -|2021-07-01T12:00:07.000+08:00| 0.0| -|2021-07-01T12:00:08.000+08:00| 0.0| -|2021-07-01T12:00:09.000+08:00| 0.0| -|2021-07-01T12:00:10.000+08:00| 0.0| -|2021-07-01T12:00:11.000+08:00| 0.0| -|2021-07-01T12:00:12.000+08:00| 0.0| -|2021-07-01T12:00:13.000+08:00| 0.0| -|2021-07-01T12:00:14.000+08:00| 0.0| -|2021-07-01T12:00:15.000+08:00| 0.0| -|2021-07-01T12:00:16.000+08:00| 1.0| -|2021-07-01T12:00:17.000+08:00| 0.0| -|2021-07-01T12:00:18.000+08:00| 1.0| -|2021-07-01T12:00:19.000+08:00| 0.0| -|2021-07-01T12:00:20.000+08:00| 1.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select missdetect(s2,'minlen'='10') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------+ -| Time|missdetect(root.test.d2.s2, "minlen"="10")| -+-----------------------------+------------------------------------------+ -|2021-07-01T12:00:00.000+08:00| false| -|2021-07-01T12:00:01.000+08:00| false| -|2021-07-01T12:00:02.000+08:00| false| -|2021-07-01T12:00:03.000+08:00| false| -|2021-07-01T12:00:04.000+08:00| true| -|2021-07-01T12:00:05.000+08:00| true| -|2021-07-01T12:00:06.000+08:00| true| -|2021-07-01T12:00:07.000+08:00| true| -|2021-07-01T12:00:08.000+08:00| true| -|2021-07-01T12:00:09.000+08:00| true| -|2021-07-01T12:00:10.000+08:00| true| -|2021-07-01T12:00:11.000+08:00| true| -|2021-07-01T12:00:12.000+08:00| true| -|2021-07-01T12:00:13.000+08:00| true| -|2021-07-01T12:00:14.000+08:00| true| -|2021-07-01T12:00:15.000+08:00| true| -|2021-07-01T12:00:16.000+08:00| false| -|2021-07-01T12:00:17.000+08:00| false| -|2021-07-01T12:00:18.000+08:00| false| -|2021-07-01T12:00:19.000+08:00| false| -|2021-07-01T12:00:20.000+08:00| false| -+-----------------------------+------------------------------------------+ -``` - -### Range - -#### 注册语句 - -```sql -create function range as 'org.apache.iotdb.library.anomaly.UDTFRange' -``` - -#### 函数简介 - -本函数用于查找时间序列的范围异常。将根据提供的上界与下界,判断输入数据是否越界,即异常,并输出所有异常点为新的时间序列。 - -**函数名:** RANGE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `lower_bound`:范围异常检测的下界。 -+ `upper_bound`:范围异常检测的上界。 - -**输出序列:** 输出单个序列,类型与输入序列相同。 - -**提示:** 应满足`upper_bound`大于`lower_bound`,否则将不做输出。 - - -#### 使用示例 - -##### 指定上界与下界 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select range(s1,"lower_bound"="101.0","upper_bound"="125.0") from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------------------+ -|Time |range(root.test.d1.s1,"lower_bound"="101.0","upper_bound"="125.0")| -+-----------------------------+------------------------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -+-----------------------------+------------------------------------------------------------------+ -``` - -### TwoSidedFilter - -#### 注册语句 - -```sql -create function twosidedfilter as 'org.apache.iotdb.library.anomaly.UDTFTwoSidedFilter' -``` - -#### 函数简介 - -本函数基于双边窗口检测法对输入序列中的异常点进行过滤。 - -**函数名:** TWOSIDEDFILTER - -**输出序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型与输入相同,是输入序列去除异常点后的结果。 - -**参数:** - -- `len`:双边窗口检测法中的窗口大小,取值范围为正整数,默认值为 5.如当`len`=3 时,算法向前、向后各取长度为3的窗口,在窗口中计算异常度。 -- `threshold`:异常度的阈值,取值范围为(0,1),默认值为 0.3。阈值越高,函数对于异常度的判定标准越严格。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s0| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 2002.0| -|1970-01-01T08:00:01.000+08:00| 1946.0| -|1970-01-01T08:00:02.000+08:00| 1958.0| -|1970-01-01T08:00:03.000+08:00| 2012.0| -|1970-01-01T08:00:04.000+08:00| 2051.0| -|1970-01-01T08:00:05.000+08:00| 1898.0| -|1970-01-01T08:00:06.000+08:00| 2014.0| -|1970-01-01T08:00:07.000+08:00| 2052.0| -|1970-01-01T08:00:08.000+08:00| 1935.0| -|1970-01-01T08:00:09.000+08:00| 1901.0| -|1970-01-01T08:00:10.000+08:00| 1972.0| -|1970-01-01T08:00:11.000+08:00| 1969.0| -|1970-01-01T08:00:12.000+08:00| 1984.0| -|1970-01-01T08:00:13.000+08:00| 2018.0| -|1970-01-01T08:00:37.000+08:00| 1484.0| -|1970-01-01T08:00:38.000+08:00| 1055.0| -|1970-01-01T08:00:39.000+08:00| 1050.0| -|1970-01-01T08:01:05.000+08:00| 1023.0| -|1970-01-01T08:01:06.000+08:00| 1056.0| -|1970-01-01T08:01:07.000+08:00| 978.0| -|1970-01-01T08:01:08.000+08:00| 1050.0| -|1970-01-01T08:01:09.000+08:00| 1123.0| -|1970-01-01T08:01:10.000+08:00| 1150.0| -|1970-01-01T08:01:11.000+08:00| 1034.0| -|1970-01-01T08:01:12.000+08:00| 950.0| -|1970-01-01T08:01:13.000+08:00| 1059.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select TwoSidedFilter(s0, 'len'='5', 'threshold'='0.3') from root.test -``` - -输出序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s0| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 2002.0| -|1970-01-01T08:00:01.000+08:00| 1946.0| -|1970-01-01T08:00:02.000+08:00| 1958.0| -|1970-01-01T08:00:03.000+08:00| 2012.0| -|1970-01-01T08:00:04.000+08:00| 2051.0| -|1970-01-01T08:00:05.000+08:00| 1898.0| -|1970-01-01T08:00:06.000+08:00| 2014.0| -|1970-01-01T08:00:07.000+08:00| 2052.0| -|1970-01-01T08:00:08.000+08:00| 1935.0| -|1970-01-01T08:00:09.000+08:00| 1901.0| -|1970-01-01T08:00:10.000+08:00| 1972.0| -|1970-01-01T08:00:11.000+08:00| 1969.0| -|1970-01-01T08:00:12.000+08:00| 1984.0| -|1970-01-01T08:00:13.000+08:00| 2018.0| -|1970-01-01T08:01:05.000+08:00| 1023.0| -|1970-01-01T08:01:06.000+08:00| 1056.0| -|1970-01-01T08:01:07.000+08:00| 978.0| -|1970-01-01T08:01:08.000+08:00| 1050.0| -|1970-01-01T08:01:09.000+08:00| 1123.0| -|1970-01-01T08:01:10.000+08:00| 1150.0| -|1970-01-01T08:01:11.000+08:00| 1034.0| -|1970-01-01T08:01:12.000+08:00| 950.0| -|1970-01-01T08:01:13.000+08:00| 1059.0| -+-----------------------------+------------+ -``` - -### Outlier - -#### 注册语句 - -```sql -create function outlier as 'org.apache.iotdb.library.anomaly.UDTFOutlier' -``` - -#### 函数简介 - -本函数用于检测基于距离的异常点。在当前窗口中,如果一个点距离阈值范围内的邻居数量(包括它自己)少于密度阈值,则该点是异常点。 - -**函数名:** OUTLIER - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `r`:基于距离异常检测中的距离阈值。 -+ `k`:基于距离异常检测中的密度阈值。 -+ `w`:用于指定滑动窗口的大小。 -+ `s`:用于指定滑动窗口的步长。 - -**输出序列**:输出单个序列,类型与输入序列相同。 - -#### 使用示例 - -##### 指定查询参数 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|2020-01-04T23:59:55.000+08:00| 56.0| -|2020-01-04T23:59:56.000+08:00| 55.1| -|2020-01-04T23:59:57.000+08:00| 54.2| -|2020-01-04T23:59:58.000+08:00| 56.3| -|2020-01-04T23:59:59.000+08:00| 59.0| -|2020-01-05T00:00:00.000+08:00| 60.0| -|2020-01-05T00:00:01.000+08:00| 60.5| -|2020-01-05T00:00:02.000+08:00| 64.5| -|2020-01-05T00:00:03.000+08:00| 69.0| -|2020-01-05T00:00:04.000+08:00| 64.2| -|2020-01-05T00:00:05.000+08:00| 62.3| -|2020-01-05T00:00:06.000+08:00| 58.0| -|2020-01-05T00:00:07.000+08:00| 58.9| -|2020-01-05T00:00:08.000+08:00| 52.0| -|2020-01-05T00:00:09.000+08:00| 62.3| -|2020-01-05T00:00:10.000+08:00| 61.0| -|2020-01-05T00:00:11.000+08:00| 64.2| -|2020-01-05T00:00:12.000+08:00| 61.8| -|2020-01-05T00:00:13.000+08:00| 64.0| -|2020-01-05T00:00:14.000+08:00| 63.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select outlier(s1,"r"="5.0","k"="4","w"="10","s"="5") from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------+ -| Time|outlier(root.test.s1,"r"="5.0","k"="4","w"="10","s"="5")| -+-----------------------------+--------------------------------------------------------+ -|2020-01-05T00:00:03.000+08:00| 69.0| -+-----------------------------+--------------------------------------------------------+ -|2020-01-05T00:00:08.000+08:00| 52.0| -+-----------------------------+--------------------------------------------------------+ -``` - -### MasterTrain - -#### 函数简介 - -本函数基于主数据训练VAR预测模型。将根据提供的主数据判断时间序列中的数据点是否为错误值,并由连续p+1个非错误值作为训练样本训练VAR模型,输出训练后的模型参数。 - -**函数名:** MasterTrain - -**输入序列:** 支持多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `p`:模型阶数。 -+ `eta`:错误值判定阈值,在缺省情况下,算法根据3-sigma原则自动估计该参数。 - -**输出序列:** 输出单个序列,类型为DOUBLE。 - -**安装方式:** - -- 从IoTDB代码仓库下载`research/master-detector`分支代码到本地 -- 在根目录运行 `mvn spotless:apply` -- 在根目录运行 `mvn clean package -pl library-udf -DskipTests -am -P get-jar-with-dependencies` 编译项目 -- 将 `./library-UDF/target/library-udf-1.2.0-SNAPSHOT-jar-with-dependencies.jar`复制到IoTDB服务器的`./ext/udf/` 路径下。 -- 启动 IoTDB服务器,在客户端中执行 `create function MasterTrain as org.apache.iotdb.library.anomaly.UDTFMasterTrain'`。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+------------+--------------+--------------+ -| Time|root.test.lo|root.test.la|root.test.m_la|root.test.m_lo| -+-----------------------------+------------+------------+--------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 39.99982556| 116.327274| 116.3271939| 39.99984748| -|1970-01-01T08:00:00.002+08:00| 39.99983865| 116.327305| 116.3272269| 39.99984748| -|1970-01-01T08:00:00.003+08:00| 40.00019038| 116.3273291| 116.3272634| 39.99984769| -|1970-01-01T08:00:00.004+08:00| 39.99982556| 116.327342| 116.3273015| 39.9998483| -|1970-01-01T08:00:00.005+08:00| 39.99982991| 116.3273744| 116.327339| 39.99984892| -|1970-01-01T08:00:00.006+08:00| 39.99982716| 116.3274117| 116.3273759| 39.99984892| -|1970-01-01T08:00:00.007+08:00| 39.9998259| 116.3274396| 116.3274163| 39.99984953| -|1970-01-01T08:00:00.008+08:00| 39.99982597| 116.3274668| 116.3274525| 39.99985014| -|1970-01-01T08:00:00.009+08:00| 39.99982226| 116.3275026| 116.3274915| 39.99985076| -|1970-01-01T08:00:00.010+08:00| 39.99980988| 116.3274967| 116.3275235| 39.99985137| -|1970-01-01T08:00:00.011+08:00| 39.99984873| 116.3274929| 116.3275611| 39.99985199| -|1970-01-01T08:00:00.012+08:00| 39.99981589| 116.3274745| 116.3275974| 39.9998526| -|1970-01-01T08:00:00.013+08:00| 39.9998259| 116.3275095| 116.3276338| 39.99985384| -|1970-01-01T08:00:00.014+08:00| 39.99984873| 116.3274787| 116.3276695| 39.99985446| -|1970-01-01T08:00:00.015+08:00| 39.9998343| 116.3274693| 116.3277045| 39.99985569| -|1970-01-01T08:00:00.016+08:00| 39.99983316| 116.3274941| 116.3277389| 39.99985631| -|1970-01-01T08:00:00.017+08:00| 39.99983311| 116.3275401| 116.3277747| 39.99985693| -|1970-01-01T08:00:00.018+08:00| 39.99984113| 116.3275713| 116.3278041| 39.99985756| -|1970-01-01T08:00:00.019+08:00| 39.99983602| 116.3276003| 116.3278379| 39.99985818| -|1970-01-01T08:00:00.020+08:00| 39.9998355| 116.3276308| 116.3278723| 39.9998588| -|1970-01-01T08:00:00.021+08:00| 40.00012176| 116.3276107| 116.3279026| 39.99985942| -|1970-01-01T08:00:00.022+08:00| 39.9998404| 116.3276684| null| null| -|1970-01-01T08:00:00.023+08:00| 39.99983942| 116.3277016| null| null| -|1970-01-01T08:00:00.024+08:00| 39.99984113| 116.3277284| null| null| -|1970-01-01T08:00:00.025+08:00| 39.99984283| 116.3277562| null| null| -+-----------------------------+------------+------------+--------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select MasterTrain(lo,la,m_lo,m_la,'p'='3','eta'='1.0') from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------------------------------------------------------------+ -| Time|MasterTrain(root.test.lo, root.test.la, root.test.m_lo, root.test.m_la, "p"="3", "eta"="1.0")| -+-----------------------------+---------------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 0.13656607660463288| -|1970-01-01T08:00:00.002+08:00| 0.8291884323013894| -|1970-01-01T08:00:00.003+08:00| 0.05012816073171693| -|1970-01-01T08:00:00.004+08:00| -0.5495287787485761| -|1970-01-01T08:00:00.005+08:00| 0.03740486307345578| -|1970-01-01T08:00:00.006+08:00| 1.0500132150475212| -|1970-01-01T08:00:00.007+08:00| 0.04583944643116993| -|1970-01-01T08:00:00.008+08:00| -0.07863708480736269| -+-----------------------------+---------------------------------------------------------------------------------------------+ - -``` - -### MasterDetect - -#### 函数简介 - -本函数基于主数据检测并修复时间序列中的错误值。将根据提供的主数据判断时间序列中的数据点是否为错误值,并由MasterTrain训练的模型进行时间序列预测,错误值将由预测值及主数据共同修复。 - -**函数名:** MasterDetect - -**输入序列:** 支持多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `p`:模型阶数。 -+ `k`:主数据中的近邻数量,正整数, 在缺省情况下,算法根据主数据中的k个近邻的元组距离自动估计该参数。 -+ `eta`:错误值判定阈值,在缺省情况下,算法根据3-sigma原则自动估计该参数。 -+ `beta`:异常值判定阈值,在缺省情况下,算法根据3-sigma原则自动估计该参数。 -+ `output_type`:输出结果类型,可选'repair'或'anomaly',即输出修复结果或异常检测结果,在缺省情况下默认为'repair'。 -+ `output_column`:输出列的序号,默认为1,即输出第一列的修复结果。 - -**安装方式:** - -- 从IoTDB代码仓库下载`research/master-detector`分支代码到本地 -- 在根目录运行 `mvn spotless:apply` -- 在根目录运行 `mvn clean package -pl library-udf -DskipTests -am -P get-jar-with-dependencies` 编译项目 -- 将 `./library-UDF/target/library-udf-1.2.0-SNAPSHOT-jar-with-dependencies.jar`复制到IoTDB服务器的`./ext/udf/` 路径下。 -- 启动 IoTDB服务器,在客户端中执行 `create function MasterDetect as 'org.apache.iotdb.library.anomaly.UDTFMasterDetect'`。 - -**输出序列:** 输出单个序列,类型与输入数据中对应列的类型相同,序列为输入列修复后的结果。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+------------+--------------+--------------+--------------------+ -| Time|root.test.lo|root.test.la|root.test.m_la|root.test.m_lo| root.test.model| -+-----------------------------+------------+------------+--------------+--------------+--------------------+ -|1970-01-01T08:00:00.001+08:00| 39.99982556| 116.327274| 116.3271939| 39.99984748| 0.13656607660463288| -|1970-01-01T08:00:00.002+08:00| 39.99983865| 116.327305| 116.3272269| 39.99984748| 0.8291884323013894| -|1970-01-01T08:00:00.003+08:00| 40.00019038| 116.3273291| 116.3272634| 39.99984769| 0.05012816073171693| -|1970-01-01T08:00:00.004+08:00| 39.99982556| 116.327342| 116.3273015| 39.9998483| -0.5495287787485761| -|1970-01-01T08:00:00.005+08:00| 39.99982991| 116.3273744| 116.327339| 39.99984892| 0.03740486307345578| -|1970-01-01T08:00:00.006+08:00| 39.99982716| 116.3274117| 116.3273759| 39.99984892| 1.0500132150475212| -|1970-01-01T08:00:00.007+08:00| 39.9998259| 116.3274396| 116.3274163| 39.99984953| 0.04583944643116993| -|1970-01-01T08:00:00.008+08:00| 39.99982597| 116.3274668| 116.3274525| 39.99985014|-0.07863708480736269| -|1970-01-01T08:00:00.009+08:00| 39.99982226| 116.3275026| 116.3274915| 39.99985076| null| -|1970-01-01T08:00:00.010+08:00| 39.99980988| 116.3274967| 116.3275235| 39.99985137| null| -|1970-01-01T08:00:00.011+08:00| 39.99984873| 116.3274929| 116.3275611| 39.99985199| null| -|1970-01-01T08:00:00.012+08:00| 39.99981589| 116.3274745| 116.3275974| 39.9998526| null| -|1970-01-01T08:00:00.013+08:00| 39.9998259| 116.3275095| 116.3276338| 39.99985384| null| -|1970-01-01T08:00:00.014+08:00| 39.99984873| 116.3274787| 116.3276695| 39.99985446| null| -|1970-01-01T08:00:00.015+08:00| 39.9998343| 116.3274693| 116.3277045| 39.99985569| null| -|1970-01-01T08:00:00.016+08:00| 39.99983316| 116.3274941| 116.3277389| 39.99985631| null| -|1970-01-01T08:00:00.017+08:00| 39.99983311| 116.3275401| 116.3277747| 39.99985693| null| -|1970-01-01T08:00:00.018+08:00| 39.99984113| 116.3275713| 116.3278041| 39.99985756| null| -|1970-01-01T08:00:00.019+08:00| 39.99983602| 116.3276003| 116.3278379| 39.99985818| null| -|1970-01-01T08:00:00.020+08:00| 39.9998355| 116.3276308| 116.3278723| 39.9998588| null| -|1970-01-01T08:00:00.021+08:00| 40.00012176| 116.3276107| 116.3279026| 39.99985942| null| -|1970-01-01T08:00:00.022+08:00| 39.9998404| 116.3276684| null| null| null| -|1970-01-01T08:00:00.023+08:00| 39.99983942| 116.3277016| null| null| null| -|1970-01-01T08:00:00.024+08:00| 39.99984113| 116.3277284| null| null| null| -|1970-01-01T08:00:00.025+08:00| 39.99984283| 116.3277562| null| null| null| -+-----------------------------+------------+------------+--------------+--------------+--------------------+ -``` - -##### 修复 - -用于查询的 SQL 语句: - -```sql -select MasterDetect(lo,la,m_lo,m_la,model,'output_type'='repair','p'='3','k'='3','eta'='1.0') from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------------------------------------+ -| Time|MasterDetect(lo,la,m_lo,m_la,model,'output_type'='repair','p'='3','k'='3','eta'='1.0')| -+-----------------------------+--------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 116.327274| -|1970-01-01T08:00:00.002+08:00| 116.327305| -|1970-01-01T08:00:00.003+08:00| 116.3273291| -|1970-01-01T08:00:00.004+08:00| 116.327342| -|1970-01-01T08:00:00.005+08:00| 116.3273744| -|1970-01-01T08:00:00.006+08:00| 116.3274117| -|1970-01-01T08:00:00.007+08:00| 116.3274396| -|1970-01-01T08:00:00.008+08:00| 116.3274668| -|1970-01-01T08:00:00.009+08:00| 116.3275026| -|1970-01-01T08:00:00.010+08:00| 116.3274967| -|1970-01-01T08:00:00.011+08:00| 116.3274929| -|1970-01-01T08:00:00.012+08:00| 116.3274745| -|1970-01-01T08:00:00.013+08:00| 116.3275095| -|1970-01-01T08:00:00.014+08:00| 116.3274787| -|1970-01-01T08:00:00.015+08:00| 116.3274693| -|1970-01-01T08:00:00.016+08:00| 116.3274941| -|1970-01-01T08:00:00.017+08:00| 116.3275401| -|1970-01-01T08:00:00.018+08:00| 116.3275713| -|1970-01-01T08:00:00.019+08:00| 116.3276003| -|1970-01-01T08:00:00.020+08:00| 116.3276308| -|1970-01-01T08:00:00.021+08:00| 116.3276338| -|1970-01-01T08:00:00.022+08:00| 116.3276684| -|1970-01-01T08:00:00.023+08:00| 116.3277016| -|1970-01-01T08:00:00.024+08:00| 116.3277284| -|1970-01-01T08:00:00.025+08:00| 116.3277562| -+-----------------------------+--------------------------------------------------------------------------------------+ -``` - -##### 异常检测 - -用于查询的 SQL 语句: - -```sql -select MasterDetect(lo,la,m_lo,m_la,model,'output_type'='anomaly','p'='3','k'='3','eta'='1.0') from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------------------------------------------------------+ -| Time|MasterDetect(lo,la,m_lo,m_la,model,'output_type'='anomaly','p'='3','k'='3','eta'='1.0')| -+-----------------------------+---------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| false| -|1970-01-01T08:00:00.002+08:00| false| -|1970-01-01T08:00:00.003+08:00| false| -|1970-01-01T08:00:00.004+08:00| false| -|1970-01-01T08:00:00.005+08:00| true| -|1970-01-01T08:00:00.006+08:00| false| -|1970-01-01T08:00:00.007+08:00| false| -|1970-01-01T08:00:00.008+08:00| false| -|1970-01-01T08:00:00.009+08:00| false| -|1970-01-01T08:00:00.010+08:00| false| -|1970-01-01T08:00:00.011+08:00| false| -|1970-01-01T08:00:00.012+08:00| false| -|1970-01-01T08:00:00.013+08:00| false| -|1970-01-01T08:00:00.014+08:00| true| -|1970-01-01T08:00:00.015+08:00| false| -|1970-01-01T08:00:00.016+08:00| false| -|1970-01-01T08:00:00.017+08:00| false| -|1970-01-01T08:00:00.018+08:00| false| -|1970-01-01T08:00:00.019+08:00| false| -|1970-01-01T08:00:00.020+08:00| false| -|1970-01-01T08:00:00.021+08:00| false| -|1970-01-01T08:00:00.022+08:00| false| -|1970-01-01T08:00:00.023+08:00| false| -|1970-01-01T08:00:00.024+08:00| false| -|1970-01-01T08:00:00.025+08:00| false| -+-----------------------------+---------------------------------------------------------------------------------------+ -``` - - - -## 频域分析 - -### Conv - -#### 注册语句 - -```sql -create function conv as 'org.apache.iotdb.library.frequency.UDTFConv' -``` - -#### 函数简介 - -本函数对两个输入序列进行卷积,即多项式乘法。 - - -**函数名:** CONV - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型为DOUBLE,它是两个序列卷积的结果。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 1.0| 7.0| -|1970-01-01T08:00:00.001+08:00| 0.0| 2.0| -|1970-01-01T08:00:00.002+08:00| 1.0| null| -+-----------------------------+---------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select conv(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------+ -| Time|conv(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+--------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 7.0| -|1970-01-01T08:00:00.001+08:00| 2.0| -|1970-01-01T08:00:00.002+08:00| 7.0| -|1970-01-01T08:00:00.003+08:00| 2.0| -+-----------------------------+--------------------------------------+ -``` - -### Deconv - -#### 注册语句 - -```sql -create function deconv as 'org.apache.iotdb.library.frequency.UDTFDeconv' -``` - -#### 函数简介 - -本函数对两个输入序列进行去卷积,即多项式除法运算。 - -**函数名:** DECONV - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `result`:去卷积的结果,取值为'quotient'或'remainder',分别对应于去卷积的商和余数。在缺省情况下,输出去卷积的商。 - -**输出序列:** 输出单个序列,类型为DOUBLE。它是将第二个序列从第一个序列中去卷积(第一个序列除以第二个序列)的结果。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -##### 计算去卷积的商 - -当`result`参数缺省或为'quotient'时,本函数计算去卷积的商。 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s3|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 8.0| 7.0| -|1970-01-01T08:00:00.001+08:00| 2.0| 2.0| -|1970-01-01T08:00:00.002+08:00| 7.0| null| -|1970-01-01T08:00:00.003+08:00| 2.0| null| -+-----------------------------+---------------+---------------+ -``` - - -用于查询的SQL语句: - -```sql -select deconv(s3,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------+ -| Time|deconv(root.test.d2.s3, root.test.d2.s2)| -+-----------------------------+----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 1.0| -|1970-01-01T08:00:00.001+08:00| 0.0| -|1970-01-01T08:00:00.002+08:00| 1.0| -+-----------------------------+----------------------------------------+ -``` - -##### 计算去卷积的余数 - -当`result`参数为'remainder'时,本函数计算去卷积的余数。输入序列同上,用于查询的SQL语句如下: - -```sql -select deconv(s3,s2,'result'='remainder') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------------+ -| Time|deconv(root.test.d2.s3, root.test.d2.s2, "result"="remainder")| -+-----------------------------+--------------------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 1.0| -|1970-01-01T08:00:00.001+08:00| 0.0| -|1970-01-01T08:00:00.002+08:00| 0.0| -|1970-01-01T08:00:00.003+08:00| 0.0| -+-----------------------------+--------------------------------------------------------------+ -``` - -### DWT - -#### 注册语句 - -```sql -create function dwt as 'org.apache.iotdb.library.frequency.UDTFDWT' -``` - -#### 函数简介 - -本函数对输入序列进行一维离散小波变换。 - -**函数名:** DWT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`:小波滤波的类型,提供'Haar', 'DB4', 'DB6', 'DB8',其中DB指代Daubechies。若不设置该参数,则用户需提供小波滤波的系数。不区分大小写。 -+ `coef`:小波滤波的系数。若提供该参数,请使用英文逗号','分割各项,不添加空格或其它符号。 -+ `layer`:进行变换的次数,最终输出的向量个数等同于$layer+1$.默认取1。 - -**输出序列:** 输出单个序列,类型为DOUBLE,长度与输入相等。 - -**提示:** 输入序列长度必须为2的整数次幂。 - -#### 使用示例 - -##### Haar变换 - - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.100+08:00| 0.2| -|1970-01-01T08:00:00.200+08:00| 1.5| -|1970-01-01T08:00:00.300+08:00| 1.2| -|1970-01-01T08:00:00.400+08:00| 0.6| -|1970-01-01T08:00:00.500+08:00| 1.7| -|1970-01-01T08:00:00.600+08:00| 0.8| -|1970-01-01T08:00:00.700+08:00| 2.0| -|1970-01-01T08:00:00.800+08:00| 2.5| -|1970-01-01T08:00:00.900+08:00| 2.1| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 2.0| -|1970-01-01T08:00:01.200+08:00| 1.8| -|1970-01-01T08:00:01.300+08:00| 1.2| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 1.6| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select dwt(s1,"method"="haar") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|dwt(root.test.d1.s1, "method"="haar")| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.14142135834465192| -|1970-01-01T08:00:00.100+08:00| 1.909188342921157| -|1970-01-01T08:00:00.200+08:00| 1.6263456473052773| -|1970-01-01T08:00:00.300+08:00| 1.9798989957517026| -|1970-01-01T08:00:00.400+08:00| 3.252691126023161| -|1970-01-01T08:00:00.500+08:00| 1.414213562373095| -|1970-01-01T08:00:00.600+08:00| 2.1213203435596424| -|1970-01-01T08:00:00.700+08:00| 1.8384776479437628| -|1970-01-01T08:00:00.800+08:00| -0.14142135834465192| -|1970-01-01T08:00:00.900+08:00| 0.21213200063848547| -|1970-01-01T08:00:01.000+08:00| -0.7778174761639416| -|1970-01-01T08:00:01.100+08:00| -0.8485281289944873| -|1970-01-01T08:00:01.200+08:00| 0.2828427799095765| -|1970-01-01T08:00:01.300+08:00| -1.414213562373095| -|1970-01-01T08:00:01.400+08:00| 0.42426400127697095| -|1970-01-01T08:00:01.500+08:00| -0.42426408557066786| -+-----------------------------+-------------------------------------+ -``` - -### FFT - -#### 注册语句 - -```sql -create function fft as 'org.apache.iotdb.library.frequency.UDTFFFT' -``` - -#### 函数简介 - -本函数对输入序列进行快速傅里叶变换。 - -**函数名:** FFT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`:傅里叶变换的类型,取值为'uniform'或'nonuniform',缺省情况下为'uniform'。当取值为'uniform'时,时间戳将被忽略,所有数据点都将被视作等距的,并应用等距快速傅里叶算法;当取值为'nonuniform'时,将根据时间戳应用非等距快速傅里叶算法(未实现)。 -+ `result`:傅里叶变换的结果,取值为'real'、'imag'、'abs'或'angle',分别对应于变换结果的实部、虚部、模和幅角。在缺省情况下,输出变换的模。 -+ `compress`:压缩参数,取值范围(0,1],是有损压缩时保留的能量比例。在缺省情况下,不进行压缩。 - -**输出序列:** 输出单个序列,类型为DOUBLE,长度与输入相等。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -##### 等距傅里叶变换 - -当`type`参数缺省或为'uniform'时,本函数进行等距傅里叶变换。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 2.902113| -|1970-01-01T08:00:01.000+08:00| 1.1755705| -|1970-01-01T08:00:02.000+08:00| -2.1755705| -|1970-01-01T08:00:03.000+08:00| -1.9021131| -|1970-01-01T08:00:04.000+08:00| 1.0| -|1970-01-01T08:00:05.000+08:00| 1.9021131| -|1970-01-01T08:00:06.000+08:00| 0.1755705| -|1970-01-01T08:00:07.000+08:00| -1.1755705| -|1970-01-01T08:00:08.000+08:00| -0.902113| -|1970-01-01T08:00:09.000+08:00| 0.0| -|1970-01-01T08:00:10.000+08:00| 0.902113| -|1970-01-01T08:00:11.000+08:00| 1.1755705| -|1970-01-01T08:00:12.000+08:00| -0.1755705| -|1970-01-01T08:00:13.000+08:00| -1.9021131| -|1970-01-01T08:00:14.000+08:00| -1.0| -|1970-01-01T08:00:15.000+08:00| 1.9021131| -|1970-01-01T08:00:16.000+08:00| 2.1755705| -|1970-01-01T08:00:17.000+08:00| -1.1755705| -|1970-01-01T08:00:18.000+08:00| -2.902113| -|1970-01-01T08:00:19.000+08:00| 0.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select fft(s1) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------+ -| Time| fft(root.test.d1.s1)| -+-----------------------------+----------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.001+08:00| 1.2727111142703152E-8| -|1970-01-01T08:00:00.002+08:00| 2.385520799101839E-7| -|1970-01-01T08:00:00.003+08:00| 8.723291723972645E-8| -|1970-01-01T08:00:00.004+08:00| 19.999999960195904| -|1970-01-01T08:00:00.005+08:00| 9.999999850988388| -|1970-01-01T08:00:00.006+08:00| 3.2260694930700566E-7| -|1970-01-01T08:00:00.007+08:00| 8.723291605373329E-8| -|1970-01-01T08:00:00.008+08:00| 1.108657103979944E-7| -|1970-01-01T08:00:00.009+08:00| 1.2727110997246171E-8| -|1970-01-01T08:00:00.010+08:00|1.9852334701272664E-23| -|1970-01-01T08:00:00.011+08:00| 1.2727111194499847E-8| -|1970-01-01T08:00:00.012+08:00| 1.108657103979944E-7| -|1970-01-01T08:00:00.013+08:00| 8.723291785769131E-8| -|1970-01-01T08:00:00.014+08:00| 3.226069493070057E-7| -|1970-01-01T08:00:00.015+08:00| 9.999999850988388| -|1970-01-01T08:00:00.016+08:00| 19.999999960195904| -|1970-01-01T08:00:00.017+08:00| 8.723291747109068E-8| -|1970-01-01T08:00:00.018+08:00| 2.3855207991018386E-7| -|1970-01-01T08:00:00.019+08:00| 1.2727112069910878E-8| -+-----------------------------+----------------------+ -``` - -注:输入序列服从$y=sin(2\pi t/4)+2sin(2\pi t/5)$,长度为20,因此在输出序列中$k=4$和$k=5$处有尖峰。 - -##### 等距傅里叶变换并压缩 - -输入序列同上,用于查询的SQL语句如下: - -```sql -select fft(s1, 'result'='real', 'compress'='0.99'), fft(s1, 'result'='imag','compress'='0.99') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------+----------------------+ -| Time| fft(root.test.d1.s1,| fft(root.test.d1.s1,| -| | "result"="real",| "result"="imag",| -| | "compress"="0.99")| "compress"="0.99")| -+-----------------------------+----------------------+----------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| 0.0| -|1970-01-01T08:00:00.001+08:00| -3.932894010461041E-9| 1.2104201863039066E-8| -|1970-01-01T08:00:00.002+08:00|-1.4021739447490164E-7| 1.9299268669082926E-7| -|1970-01-01T08:00:00.003+08:00| -7.057291240286645E-8| 5.127422242345858E-8| -|1970-01-01T08:00:00.004+08:00| 19.021130288047125| -6.180339875198807| -|1970-01-01T08:00:00.005+08:00| 9.999999850988388| 3.501852745067114E-16| -|1970-01-01T08:00:00.019+08:00| -3.932894898639461E-9|-1.2104202549376264E-8| -+-----------------------------+----------------------+----------------------+ -``` - -注:基于傅里叶变换结果的共轭性质,压缩结果只保留前一半;根据给定的压缩参数,从低频到高频保留数据点,直到保留的能量比例超过该值;保留最后一个数据点以表示序列长度。 - -### HighPass - -#### 注册语句 - -```sql -create function highpass as 'org.apache.iotdb.library.frequency.UDTFHighPass' -``` - -#### 函数简介 - -本函数对输入序列进行高通滤波,提取高于截止频率的分量。输入序列的时间戳将被忽略,所有数据点都将被视作等距的。 - -**函数名:** HIGHPASS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `wpass`:归一化后的截止频率,取值为(0,1),不可缺省。 - -**输出序列:** 输出单个序列,类型为DOUBLE,它是滤波后的序列,长度与时间戳均与输入一致。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 2.902113| -|1970-01-01T08:00:01.000+08:00| 1.1755705| -|1970-01-01T08:00:02.000+08:00| -2.1755705| -|1970-01-01T08:00:03.000+08:00| -1.9021131| -|1970-01-01T08:00:04.000+08:00| 1.0| -|1970-01-01T08:00:05.000+08:00| 1.9021131| -|1970-01-01T08:00:06.000+08:00| 0.1755705| -|1970-01-01T08:00:07.000+08:00| -1.1755705| -|1970-01-01T08:00:08.000+08:00| -0.902113| -|1970-01-01T08:00:09.000+08:00| 0.0| -|1970-01-01T08:00:10.000+08:00| 0.902113| -|1970-01-01T08:00:11.000+08:00| 1.1755705| -|1970-01-01T08:00:12.000+08:00| -0.1755705| -|1970-01-01T08:00:13.000+08:00| -1.9021131| -|1970-01-01T08:00:14.000+08:00| -1.0| -|1970-01-01T08:00:15.000+08:00| 1.9021131| -|1970-01-01T08:00:16.000+08:00| 2.1755705| -|1970-01-01T08:00:17.000+08:00| -1.1755705| -|1970-01-01T08:00:18.000+08:00| -2.902113| -|1970-01-01T08:00:19.000+08:00| 0.0| -+-----------------------------+---------------+ -``` - - -用于查询的SQL语句: - -```sql -select highpass(s1,'wpass'='0.45') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------+ -| Time|highpass(root.test.d1.s1, "wpass"="0.45")| -+-----------------------------+-----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.9999999534830373| -|1970-01-01T08:00:01.000+08:00| 1.7462829277628608E-8| -|1970-01-01T08:00:02.000+08:00| -0.9999999593178128| -|1970-01-01T08:00:03.000+08:00| -4.1115269056426626E-8| -|1970-01-01T08:00:04.000+08:00| 0.9999999925494194| -|1970-01-01T08:00:05.000+08:00| 3.328126513330016E-8| -|1970-01-01T08:00:06.000+08:00| -1.0000000183304454| -|1970-01-01T08:00:07.000+08:00| 6.260191433311374E-10| -|1970-01-01T08:00:08.000+08:00| 1.0000000018134796| -|1970-01-01T08:00:09.000+08:00| -3.097210911744423E-17| -|1970-01-01T08:00:10.000+08:00| -1.0000000018134794| -|1970-01-01T08:00:11.000+08:00| -6.260191627862097E-10| -|1970-01-01T08:00:12.000+08:00| 1.0000000183304454| -|1970-01-01T08:00:13.000+08:00| -3.328126501424346E-8| -|1970-01-01T08:00:14.000+08:00| -0.9999999925494196| -|1970-01-01T08:00:15.000+08:00| 4.111526915498874E-8| -|1970-01-01T08:00:16.000+08:00| 0.9999999593178128| -|1970-01-01T08:00:17.000+08:00| -1.7462829341296528E-8| -|1970-01-01T08:00:18.000+08:00| -0.9999999534830369| -|1970-01-01T08:00:19.000+08:00| -1.035237222742873E-16| -+-----------------------------+-----------------------------------------+ -``` - -注:输入序列服从$y=sin(2\pi t/4)+2sin(2\pi t/5)$,长度为20,因此高通滤波之后的输出序列服从$y=sin(2\pi t/4)$。 - -### IFFT - -#### 注册语句 - -```sql -create function ifft as 'org.apache.iotdb.library.frequency.UDTFIFFT' -``` - -#### 函数简介 - -本函数将输入的两个序列作为实部和虚部视作一个复数,进行逆快速傅里叶变换,并输出结果的实部。输入数据的格式参见`FFT`函数的输出,并支持以`FFT`函数压缩后的输出作为本函数的输入。 - -**函数名:** IFFT - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `start`:输出序列的起始时刻,是一个格式为'yyyy-MM-dd HH:mm:ss'的时间字符串。在缺省情况下,为'1970-01-01 08:00:00'。 -+ `interval`:输出序列的时间间隔,是一个有单位的正数。目前支持五种单位,分别是'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。在缺省情况下,为1s。 - - -**输出序列:** 输出单个序列,类型为DOUBLE。该序列是一个等距时间序列,它的值是将两个输入序列依次作为实部和虚部进行逆快速傅里叶变换的结果。 - -**提示:** 如果某行数据中包含空值或`NaN`,该行数据将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+----------------------+----------------------+ -| Time| root.test.d1.re| root.test.d1.im| -+-----------------------------+----------------------+----------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| 0.0| -|1970-01-01T08:00:00.001+08:00| -3.932894010461041E-9| 1.2104201863039066E-8| -|1970-01-01T08:00:00.002+08:00|-1.4021739447490164E-7| 1.9299268669082926E-7| -|1970-01-01T08:00:00.003+08:00| -7.057291240286645E-8| 5.127422242345858E-8| -|1970-01-01T08:00:00.004+08:00| 19.021130288047125| -6.180339875198807| -|1970-01-01T08:00:00.005+08:00| 9.999999850988388| 3.501852745067114E-16| -|1970-01-01T08:00:00.019+08:00| -3.932894898639461E-9|-1.2104202549376264E-8| -+-----------------------------+----------------------+----------------------+ -``` - - -用于查询的SQL语句: - -```sql -select ifft(re, im, 'interval'='1m', 'start'='2021-01-01 00:00:00') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------------+ -| Time|ifft(root.test.d1.re, root.test.d1.im, "interval"="1m",| -| | "start"="2021-01-01 00:00:00")| -+-----------------------------+-------------------------------------------------------+ -|2021-01-01T00:00:00.000+08:00| 2.902112992431231| -|2021-01-01T00:01:00.000+08:00| 1.1755704705132448| -|2021-01-01T00:02:00.000+08:00| -2.175570513757101| -|2021-01-01T00:03:00.000+08:00| -1.9021130389094498| -|2021-01-01T00:04:00.000+08:00| 0.9999999925494194| -|2021-01-01T00:05:00.000+08:00| 1.902113046743454| -|2021-01-01T00:06:00.000+08:00| 0.17557053610884188| -|2021-01-01T00:07:00.000+08:00| -1.1755704886020932| -|2021-01-01T00:08:00.000+08:00| -0.9021130371347148| -|2021-01-01T00:09:00.000+08:00| 3.552713678800501E-16| -|2021-01-01T00:10:00.000+08:00| 0.9021130371347154| -|2021-01-01T00:11:00.000+08:00| 1.1755704886020932| -|2021-01-01T00:12:00.000+08:00| -0.17557053610884144| -|2021-01-01T00:13:00.000+08:00| -1.902113046743454| -|2021-01-01T00:14:00.000+08:00| -0.9999999925494196| -|2021-01-01T00:15:00.000+08:00| 1.9021130389094498| -|2021-01-01T00:16:00.000+08:00| 2.1755705137571004| -|2021-01-01T00:17:00.000+08:00| -1.1755704705132448| -|2021-01-01T00:18:00.000+08:00| -2.902112992431231| -|2021-01-01T00:19:00.000+08:00| -3.552713678800501E-16| -+-----------------------------+-------------------------------------------------------+ -``` - -### LowPass - -#### 注册语句 - -```sql -create function lowpass as 'org.apache.iotdb.library.frequency.UDTFLowPass' -``` - -#### 函数简介 - -本函数对输入序列进行低通滤波,提取低于截止频率的分量。输入序列的时间戳将被忽略,所有数据点都将被视作等距的。 - -**函数名:** LOWPASS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `wpass`:归一化后的截止频率,取值为(0,1),不可缺省。 - -**输出序列:** 输出单个序列,类型为DOUBLE,它是滤波后的序列,长度与时间戳均与输入一致。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 2.902113| -|1970-01-01T08:00:01.000+08:00| 1.1755705| -|1970-01-01T08:00:02.000+08:00| -2.1755705| -|1970-01-01T08:00:03.000+08:00| -1.9021131| -|1970-01-01T08:00:04.000+08:00| 1.0| -|1970-01-01T08:00:05.000+08:00| 1.9021131| -|1970-01-01T08:00:06.000+08:00| 0.1755705| -|1970-01-01T08:00:07.000+08:00| -1.1755705| -|1970-01-01T08:00:08.000+08:00| -0.902113| -|1970-01-01T08:00:09.000+08:00| 0.0| -|1970-01-01T08:00:10.000+08:00| 0.902113| -|1970-01-01T08:00:11.000+08:00| 1.1755705| -|1970-01-01T08:00:12.000+08:00| -0.1755705| -|1970-01-01T08:00:13.000+08:00| -1.9021131| -|1970-01-01T08:00:14.000+08:00| -1.0| -|1970-01-01T08:00:15.000+08:00| 1.9021131| -|1970-01-01T08:00:16.000+08:00| 2.1755705| -|1970-01-01T08:00:17.000+08:00| -1.1755705| -|1970-01-01T08:00:18.000+08:00| -2.902113| -|1970-01-01T08:00:19.000+08:00| 0.0| -+-----------------------------+---------------+ -``` - - -用于查询的SQL语句: - -```sql -select lowpass(s1,'wpass'='0.45') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------+ -| Time|lowpass(root.test.d1.s1, "wpass"="0.45")| -+-----------------------------+----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 1.9021130073323922| -|1970-01-01T08:00:01.000+08:00| 1.1755704705132448| -|1970-01-01T08:00:02.000+08:00| -1.1755705286582614| -|1970-01-01T08:00:03.000+08:00| -1.9021130389094498| -|1970-01-01T08:00:04.000+08:00| 7.450580419288145E-9| -|1970-01-01T08:00:05.000+08:00| 1.902113046743454| -|1970-01-01T08:00:06.000+08:00| 1.1755705212076808| -|1970-01-01T08:00:07.000+08:00| -1.1755704886020932| -|1970-01-01T08:00:08.000+08:00| -1.9021130222335536| -|1970-01-01T08:00:09.000+08:00| 3.552713678800501E-16| -|1970-01-01T08:00:10.000+08:00| 1.9021130222335536| -|1970-01-01T08:00:11.000+08:00| 1.1755704886020932| -|1970-01-01T08:00:12.000+08:00| -1.1755705212076801| -|1970-01-01T08:00:13.000+08:00| -1.902113046743454| -|1970-01-01T08:00:14.000+08:00| -7.45058112983088E-9| -|1970-01-01T08:00:15.000+08:00| 1.9021130389094498| -|1970-01-01T08:00:16.000+08:00| 1.1755705286582616| -|1970-01-01T08:00:17.000+08:00| -1.1755704705132448| -|1970-01-01T08:00:18.000+08:00| -1.9021130073323924| -|1970-01-01T08:00:19.000+08:00| -2.664535259100376E-16| -+-----------------------------+----------------------------------------+ -``` - -注:输入序列服从$y=sin(2\pi t/4)+2sin(2\pi t/5)$,长度为20,因此低通滤波之后的输出序列服从$y=2sin(2\pi t/5)$。 - - -### Envelope - -#### 注册语句 - -```sql -create function envelope as 'org.apache.iotdb.library.frequency.UDFEnvelopeAnalysis' -``` - -#### 函数简介 - -本函数通过输入一维浮点数数组和用户指定的调制频率,实现对信号的解调和包络提取。解调的目标是从复杂的信号中提取感兴趣的部分,使其更易理解。比如通过解调可以找到信号的包络,即振幅的变化趋势。 - -**函数名:** Envelope - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `frequency`:频率(选填,正数。不填此参数,系统会基于序列对应时间的时间间隔来推断频率)。 -+ `amplification`: 扩增倍数(选填,正整数。输出Time列的结果为正整数的集合,不会输出小数。当频率小1时,可通过此参数对频率进行扩增以展示正常的结果)。 - -**输出序列:** -+ `Time`: 该列返回的值的含义是频率而并非时间,如果输出的格式为时间格式(如:1970-01-01T08:00:19.000+08:00),请将其转为时间戳值。 - -+ `Envelope(Path, 'frequency'='{frequency}')`:输出单个序列,类型为DOUBLE,它是包络分析之后的结果。 - -**提示:** 当解调的原始序列的值不连续时,本函数会视为连续处理,建议被分析的时间序列是一段值完整的时间序列。同时建议指定开始时间与结束时间。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:01.000+08:00| 1.0 | -|1970-01-01T08:00:02.000+08:00| 2.0 | -|1970-01-01T08:00:03.000+08:00| 3.0 | -|1970-01-01T08:00:04.000+08:00| 4.0 | -|1970-01-01T08:00:05.000+08:00| 5.0 | -|1970-01-01T08:00:06.000+08:00| 6.0 | -|1970-01-01T08:00:07.000+08:00| 7.0 | -|1970-01-01T08:00:08.000+08:00| 8.0 | -|1970-01-01T08:00:09.000+08:00| 9.0 | -|1970-01-01T08:00:10.000+08:00| 10.0 | -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: -```sql -set time_display_type=long; -select envelope(s1),envelope(s1,'frequency'='1000'),envelope(s1,'amplification'='10') from root.test.d1; -``` -输出序列: - -``` -+----+-------------------------+---------------------------------------------+-----------------------------------------------+ -|Time|envelope(root.test.d1.s1)|envelope(root.test.d1.s1, "frequency"="1000")|envelope(root.test.d1.s1, "amplification"="10")| -+----+-------------------------+---------------------------------------------+-----------------------------------------------+ -| 0| 6.284350808484124| 6.284350808484124| 6.284350808484124| -| 100| 1.5581923657404393| 1.5581923657404393| null| -| 200| 0.8503211038340728| 0.8503211038340728| null| -| 300| 0.512808785945551| 0.512808785945551| null| -| 400| 0.26361156774506744| 0.26361156774506744| null| -|1000| null| null| 1.5581923657404393| -|2000| null| null| 0.8503211038340728| -|3000| null| null| 0.512808785945551| -|4000| null| null| 0.26361156774506744| -+----+-------------------------+---------------------------------------------+-----------------------------------------------+ - -``` - -## 数据匹配 - -### Cov - -#### 注册语句 - -```sql -create function cov as 'org.apache.iotdb.library.dmatch.UDAFCov' -``` - -#### 函数简介 - -本函数用于计算两列数值型数据的总体协方差。 - -**函数名:** COV - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列仅包含一个时间戳为 0、值为总体协方差的数据点。 - -**提示:** - -+ 如果某行数据中包含空值、缺失值或`NaN`,该行数据将会被忽略; -+ 如果数据中所有的行都被忽略,函数将会输出`NaN`。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| 101.0| -|2020-01-01T00:00:03.000+08:00| 101.0| null| -|2020-01-01T00:00:04.000+08:00| 102.0| 101.0| -|2020-01-01T00:00:06.000+08:00| 104.0| 102.0| -|2020-01-01T00:00:08.000+08:00| 126.0| 102.0| -|2020-01-01T00:00:10.000+08:00| 108.0| 103.0| -|2020-01-01T00:00:12.000+08:00| null| 103.0| -|2020-01-01T00:00:14.000+08:00| 112.0| 104.0| -|2020-01-01T00:00:15.000+08:00| 113.0| null| -|2020-01-01T00:00:16.000+08:00| 114.0| 104.0| -|2020-01-01T00:00:18.000+08:00| 116.0| 105.0| -|2020-01-01T00:00:20.000+08:00| 118.0| 105.0| -|2020-01-01T00:00:22.000+08:00| 100.0| 106.0| -|2020-01-01T00:00:26.000+08:00| 124.0| 108.0| -|2020-01-01T00:00:28.000+08:00| 126.0| 108.0| -|2020-01-01T00:00:30.000+08:00| NaN| 108.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select cov(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|cov(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 12.291666666666666| -+-----------------------------+-------------------------------------+ -``` - -### Dtw - -#### 注册语句 - -```sql -create function dtw as 'org.apache.iotdb.library.dmatch.UDAFDtw' -``` - -#### 函数简介 - -本函数用于计算两列数值型数据的 DTW 距离。 - -**函数名:** DTW - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列仅包含一个时间戳为 0、值为两个时间序列的 DTW 距离值。 - -**提示:** - -+ 如果某行数据中包含空值、缺失值或`NaN`,该行数据将会被忽略; -+ 如果数据中所有的行都被忽略,函数将会输出 0。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.002+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.003+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.004+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.005+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.006+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.007+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.008+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.009+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.010+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.011+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.012+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.013+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.014+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.015+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.016+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.017+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.018+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.019+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.020+08:00| 1.0| 2.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select dtw(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|dtw(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 20.0| -+-----------------------------+-------------------------------------+ -``` - -### Pearson - -#### 注册语句 - -```sql -create function pearson as 'org.apache.iotdb.library.dmatch.UDAFPearson' -``` - -#### 函数简介 - -本函数用于计算两列数值型数据的皮尔森相关系数。 - -**函数名:** PEARSON - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列仅包含一个时间戳为 0、值为皮尔森相关系数的数据点。 - -**提示:** - -+ 如果某行数据中包含空值、缺失值或`NaN`,该行数据将会被忽略; -+ 如果数据中所有的行都被忽略,函数将会输出`NaN`。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| 101.0| -|2020-01-01T00:00:03.000+08:00| 101.0| null| -|2020-01-01T00:00:04.000+08:00| 102.0| 101.0| -|2020-01-01T00:00:06.000+08:00| 104.0| 102.0| -|2020-01-01T00:00:08.000+08:00| 126.0| 102.0| -|2020-01-01T00:00:10.000+08:00| 108.0| 103.0| -|2020-01-01T00:00:12.000+08:00| null| 103.0| -|2020-01-01T00:00:14.000+08:00| 112.0| 104.0| -|2020-01-01T00:00:15.000+08:00| 113.0| null| -|2020-01-01T00:00:16.000+08:00| 114.0| 104.0| -|2020-01-01T00:00:18.000+08:00| 116.0| 105.0| -|2020-01-01T00:00:20.000+08:00| 118.0| 105.0| -|2020-01-01T00:00:22.000+08:00| 100.0| 106.0| -|2020-01-01T00:00:26.000+08:00| 124.0| 108.0| -|2020-01-01T00:00:28.000+08:00| 126.0| 108.0| -|2020-01-01T00:00:30.000+08:00| NaN| 108.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select pearson(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------+ -| Time|pearson(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+-----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.5630881927754872| -+-----------------------------+-----------------------------------------+ -``` - -### PtnSym - -#### 注册语句 - -```sql -create function ptnsym as 'org.apache.iotdb.library.dmatch.UDTFPtnSym' -``` - -#### 函数简介 - -本函数用于寻找序列中所有对称度小于阈值的对称子序列。对称度通过 DTW 计算,值越小代表序列对称性越高。 - -**函数名:** PTNSYM - -**输入序列:** 仅支持一个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `window`:对称子序列的长度,是一个正整数,默认值为 10。 -+ `threshold`:对称度阈值,是一个非负数,只有对称度小于等于该值的对称子序列才会被输出。在缺省情况下,所有的子序列都会被输出。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列中的每一个数据点对应于一个对称子序列,时间戳为子序列的起始时刻,值为对称度。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s4| -+-----------------------------+---------------+ -|2021-01-01T12:00:00.000+08:00| 1.0| -|2021-01-01T12:00:01.000+08:00| 2.0| -|2021-01-01T12:00:02.000+08:00| 3.0| -|2021-01-01T12:00:03.000+08:00| 2.0| -|2021-01-01T12:00:04.000+08:00| 1.0| -|2021-01-01T12:00:05.000+08:00| 1.0| -|2021-01-01T12:00:06.000+08:00| 1.0| -|2021-01-01T12:00:07.000+08:00| 1.0| -|2021-01-01T12:00:08.000+08:00| 2.0| -|2021-01-01T12:00:09.000+08:00| 3.0| -|2021-01-01T12:00:10.000+08:00| 2.0| -|2021-01-01T12:00:11.000+08:00| 1.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select ptnsym(s4, 'window'='5', 'threshold'='0') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|ptnsym(root.test.d1.s4, "window"="5", "threshold"="0")| -+-----------------------------+------------------------------------------------------+ -|2021-01-01T12:00:00.000+08:00| 0.0| -|2021-01-01T12:00:07.000+08:00| 0.0| -+-----------------------------+------------------------------------------------------+ -``` - -### XCorr - -#### 注册语句 - -```sql -create function xcorr as 'org.apache.iotdb.library.dmatch.UDTFXCorr' -``` - -#### 函数简介 - -本函数用于计算两条时间序列的互相关函数值, -对离散序列而言,互相关函数可以表示为 -$$CR(n) = \frac{1}{N} \sum_{m=1}^N S_1[m]S_2[m+n]$$ -常用于表征两条序列在不同对齐条件下的相似度。 - -**函数名:** XCORR - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列中共包含$2N-1$个数据点, -其中正中心的值为两条序列按照预先对齐的结果计算的互相关系数(即等于以上公式的$CR(0)$), -前半部分的值表示将后一条输入序列向前平移时计算的互相关系数, -直至两条序列没有重合的数据点(不包含完全分离时的结果$CR(-N)=0.0$), -后半部分类似。 -用公式可表示为(所有序列的索引从1开始计数): -$$OS[i] = CR(-N+i) = \frac{1}{N} \sum_{m=1}^{i} S_1[m]S_2[N-i+m],\ if\ i <= N$$ -$$OS[i] = CR(i-N) = \frac{1}{N} \sum_{m=1}^{2N-i} S_1[i-N+m]S_2[m],\ if\ i > N$$ - -**提示:** - -+ 两条序列中的`null` 和`NaN` 值会被忽略,在计算中表现为 0。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:01.000+08:00| null| 6| -|2020-01-01T00:00:02.000+08:00| 2| 7| -|2020-01-01T00:00:03.000+08:00| 3| NaN| -|2020-01-01T00:00:04.000+08:00| 4| 9| -|2020-01-01T00:00:05.000+08:00| 5| 10| -+-----------------------------+---------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select xcorr(s1, s2) from root.test.d1 where time <= 2020-01-01 00:00:05 -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------+ -| Time|xcorr(root.test.d1.s1, root.test.d1.s2)| -+-----------------------------+---------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 0.0| -|1970-01-01T08:00:00.002+08:00| 4.0| -|1970-01-01T08:00:00.003+08:00| 9.6| -|1970-01-01T08:00:00.004+08:00| 13.4| -|1970-01-01T08:00:00.005+08:00| 20.0| -|1970-01-01T08:00:00.006+08:00| 15.6| -|1970-01-01T08:00:00.007+08:00| 9.2| -|1970-01-01T08:00:00.008+08:00| 11.8| -|1970-01-01T08:00:00.009+08:00| 6.0| -+-----------------------------+---------------------------------------+ -``` - - - -## 数据修复 - -### TimestampRepair - -#### 注册语句 - -```sql -create function timestamprepair as 'org.apache.iotdb.library.drepair.UDTFTimestampRepair' -``` - -### 函数简介 - -本函数用于时间戳修复。根据给定的标准时间间隔,采用最小化修复代价的方法,通过对数据时间戳的微调,将原本时间戳间隔不稳定的数据修复为严格等间隔的数据。在未给定标准时间间隔的情况下,本函数将使用时间间隔的中位数 (median)、众数 (mode) 或聚类中心 (cluster) 来推算标准时间间隔。 - - -**函数名:** TIMESTAMPREPAIR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `interval`: 标准时间间隔(单位是毫秒),是一个正整数。在缺省情况下,将根据指定的方法推算。 -+ `method`:推算标准时间间隔的方法,取值为 'median', 'mode' 或 'cluster',仅在`interval`缺省时有效。在缺省情况下,将使用中位数方法进行推算。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列是修复后的输入序列。 - -### 使用示例 - -#### 指定标准时间间隔 - -在给定`interval`参数的情况下,本函数将按照指定的标准时间间隔进行修复。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2021-07-01T12:00:00.000+08:00| 1.0| -|2021-07-01T12:00:10.000+08:00| 2.0| -|2021-07-01T12:00:19.000+08:00| 3.0| -|2021-07-01T12:00:30.000+08:00| 4.0| -|2021-07-01T12:00:40.000+08:00| 5.0| -|2021-07-01T12:00:50.000+08:00| 6.0| -|2021-07-01T12:01:01.000+08:00| 7.0| -|2021-07-01T12:01:11.000+08:00| 8.0| -|2021-07-01T12:01:21.000+08:00| 9.0| -|2021-07-01T12:01:31.000+08:00| 10.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select timestamprepair(s1,'interval'='10000') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------------------+ -| Time|timestamprepair(root.test.d2.s1, "interval"="10000")| -+-----------------------------+----------------------------------------------------+ -|2021-07-01T12:00:00.000+08:00| 1.0| -|2021-07-01T12:00:10.000+08:00| 2.0| -|2021-07-01T12:00:20.000+08:00| 3.0| -|2021-07-01T12:00:30.000+08:00| 4.0| -|2021-07-01T12:00:40.000+08:00| 5.0| -|2021-07-01T12:00:50.000+08:00| 6.0| -|2021-07-01T12:01:00.000+08:00| 7.0| -|2021-07-01T12:01:10.000+08:00| 8.0| -|2021-07-01T12:01:20.000+08:00| 9.0| -|2021-07-01T12:01:30.000+08:00| 10.0| -+-----------------------------+----------------------------------------------------+ -``` - -#### 自动推算标准时间间隔 - -如果`interval`参数没有给定,本函数将按照推算的标准时间间隔进行修复。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select timestamprepair(s1) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------+ -| Time|timestamprepair(root.test.d2.s1)| -+-----------------------------+--------------------------------+ -|2021-07-01T12:00:00.000+08:00| 1.0| -|2021-07-01T12:00:10.000+08:00| 2.0| -|2021-07-01T12:00:20.000+08:00| 3.0| -|2021-07-01T12:00:30.000+08:00| 4.0| -|2021-07-01T12:00:40.000+08:00| 5.0| -|2021-07-01T12:00:50.000+08:00| 6.0| -|2021-07-01T12:01:00.000+08:00| 7.0| -|2021-07-01T12:01:10.000+08:00| 8.0| -|2021-07-01T12:01:20.000+08:00| 9.0| -|2021-07-01T12:01:30.000+08:00| 10.0| -+-----------------------------+--------------------------------+ -``` - -### ValueFill - -#### 注册语句 - -```sql -create function valuefill as 'org.apache.iotdb.library.drepair.UDTFValueFill' -``` - -#### 函数简介 - -**函数名:** ValueFill - -**输入序列:** 单列时序数据,类型为INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`: {"mean", "previous", "linear", "likelihood", "AR", "MA", "SCREEN"}, 默认为 "linear"。其中,“mean” 指使用均值填补的方法; “previous" 指使用前值填补方法;“linear" 指使用线性插值填补方法;“likelihood” 为基于速度的正态分布的极大似然估计方法;“AR” 指自回归的填补方法;“MA” 指滑动平均的填补方法;"SCREEN" 指约束填补方法;缺省情况下使用 “linear”。 - -**输出序列:** 填补后的单维序列。 - -**备注:** AR 模型采用 AR(1),时序列需满足自相关条件,否则将输出单个数据点 (0, 0.0). - -#### 使用示例 -##### 使用 linear 方法进行填补 - -当`method`缺省或取值为 'linear' 时,本函数将使用线性插值方法进行填补。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| NaN| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| NaN| -|2020-01-01T00:00:22.000+08:00| NaN| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select valuefill(s1) from root.test.d2 -``` - -输出序列: - - - -``` -+-----------------------------+-----------------------+ -| Time|valuefill(root.test.d2)| -+-----------------------------+-----------------------+ -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 108.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.7| -|2020-01-01T00:00:22.000+08:00| 121.3| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+-----------------------+ -``` - -##### 使用 previous 方法进行填补 - -当`method`取值为 'previous' 时,本函数将使前值填补方法进行数值填补。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select valuefill(s1,"method"="previous") from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------+ -| Time|valuefill(root.test.d2,"method"="previous")| -+-----------------------------+-------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 110.5| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 116.0| -|2020-01-01T00:00:22.000+08:00| 116.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+-------------------------------------------+ -``` - -### ValueRepair - -#### 注册语句 - -```sql -create function valuerepair as 'org.apache.iotdb.library.drepair.UDTFValueRepair' -``` - -#### 函数简介 - -本函数用于对时间序列的数值进行修复。目前,本函数支持两种修复方法:**Screen** 是一种基于速度阈值的方法,在最小改动的前提下使得所有的速度符合阈值要求;**LsGreedy** 是一种基于速度变化似然的方法,将速度变化建模为高斯分布,并采用贪心算法极大化似然函数。 - -**函数名:** VALUEREPAIR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `method`:修复时采用的方法,取值为 'Screen' 或 'LsGreedy'. 在缺省情况下,使用 Screen 方法进行修复。 -+ `minSpeed`:该参数仅在使用 Screen 方法时有效。当速度小于该值时会被视作数值异常点加以修复。在缺省情况下为中位数减去三倍绝对中位差。 -+ `maxSpeed`:该参数仅在使用 Screen 方法时有效。当速度大于该值时会被视作数值异常点加以修复。在缺省情况下为中位数加上三倍绝对中位差。 -+ `center`:该参数仅在使用 LsGreedy 方法时有效。对速度变化分布建立的高斯模型的中心。在缺省情况下为 0。 -+ `sigma` :该参数仅在使用 LsGreedy 方法时有效。对速度变化分布建立的高斯模型的标准差。在缺省情况下为绝对中位差。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列是修复后的输入序列。 - -**提示:** 输入序列中的`NaN`在修复之前会先进行线性插值填补。 - -#### 使用示例 - -##### 使用 Screen 方法进行修复 - -当`method`缺省或取值为 'Screen' 时,本函数将使用 Screen 方法进行数值修复。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 100.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select valuerepair(s1) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+----------------------------+ -| Time|valuerepair(root.test.d2.s1)| -+-----------------------------+----------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 106.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+----------------------------+ -``` - -##### 使用 LsGreedy 方法进行修复 - -当`method`取值为 'LsGreedy' 时,本函数将使用 LsGreedy 方法进行数值修复。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select valuerepair(s1,'method'='LsGreedy') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------+ -| Time|valuerepair(root.test.d2.s1, "method"="LsGreedy")| -+-----------------------------+-------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 106.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+-------------------------------------------------+ -``` - -### MasterRepair - -#### 函数简介 - -本函数实现基于主数据的时间序列数据修复。 - -**函数名:**MasterRepair - -**输入序列:** 支持多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `omega`:算法窗口大小,非负整数(单位为毫秒), 在缺省情况下,算法根据不同时间差下的两个元组距离自动估计该参数。 -- `eta`:算法距离阈值,正数, 在缺省情况下,算法根据窗口中元组的距离分布自动估计该参数。 -- `k`:主数据中的近邻数量,正整数, 在缺省情况下,算法根据主数据中的k个近邻的元组距离自动估计该参数。 -- `output_column`:输出列的序号,默认输出第一列的修复结果。 - -**输出序列:**输出单个序列,类型与输入数据中对应列的类型相同,序列为输入列修复后的结果。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+------------+------------+------------+------------+------------+ -| Time|root.test.t1|root.test.t2|root.test.t3|root.test.m1|root.test.m2|root.test.m3| -+-----------------------------+------------+------------+------------+------------+------------+------------+ -|2021-07-01T12:00:01.000+08:00| 1704| 1154.55| 0.195| 1704| 1154.55| 0.195| -|2021-07-01T12:00:02.000+08:00| 1702| 1152.30| 0.193| 1702| 1152.30| 0.193| -|2021-07-01T12:00:03.000+08:00| 1702| 1148.65| 0.192| 1702| 1148.65| 0.192| -|2021-07-01T12:00:04.000+08:00| 1701| 1145.20| 0.194| 1701| 1145.20| 0.194| -|2021-07-01T12:00:07.000+08:00| 1703| 1150.55| 0.195| 1703| 1150.55| 0.195| -|2021-07-01T12:00:08.000+08:00| 1694| 1151.55| 0.193| 1704| 1151.55| 0.193| -|2021-07-01T12:01:09.000+08:00| 1705| 1153.55| 0.194| 1705| 1153.55| 0.194| -|2021-07-01T12:01:10.000+08:00| 1706| 1152.30| 0.190| 1706| 1152.30| 0.190| -+-----------------------------+------------+------------+------------+------------+------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select MasterRepair(t1,t2,t3,m1,m2,m3) from root.test -``` - -输出序列: - - -``` -+-----------------------------+-------------------------------------------------------------------------------------------+ -| Time|MasterRepair(root.test.t1,root.test.t2,root.test.t3,root.test.m1,root.test.m2,root.test.m3)| -+-----------------------------+-------------------------------------------------------------------------------------------+ -|2021-07-01T12:00:01.000+08:00| 1704| -|2021-07-01T12:00:02.000+08:00| 1702| -|2021-07-01T12:00:03.000+08:00| 1702| -|2021-07-01T12:00:04.000+08:00| 1701| -|2021-07-01T12:00:07.000+08:00| 1703| -|2021-07-01T12:00:08.000+08:00| 1704| -|2021-07-01T12:01:09.000+08:00| 1705| -|2021-07-01T12:01:10.000+08:00| 1706| -+-----------------------------+-------------------------------------------------------------------------------------------+ -``` - -### SeasonalRepair - -#### 函数简介 -本函数用于对周期性时间序列的数值进行基于分解的修复。目前,本函数支持两种方法:**Classical**使用经典分解方法得到的残差项检测数值的异常波动,并使用滑动平均修复序列;**Improved**使用改进的分解方法得到的残差项检测数值的异常波动,并使用滑动中值修复序列。 - -**函数名:** SEASONALREPAIR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `method`:修复时采用的分解方法,取值为'Classical'或'Improved'。在缺省情况下,使用经典分解方法进行修复。 -+ `period`:序列的周期。 -+ `k`:残差项的范围阈值,用来限制残差项偏离中心的程度。在缺省情况下为9。 -+ `max_iter`:算法的最大迭代次数。在缺省情况下为10。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列是修复后的输入序列。 - -**提示:** 输入序列中的`NaN`在修复之前会先进行线性插值填补。 - -#### 使用示例 -##### 使用经典分解方法进行修复 -当`method`缺省或取值为'Classical'时,本函数将使用经典分解方法进行数值修复。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:04.000+08:00| 120.0| -|2020-01-01T00:00:06.000+08:00| 80.0| -|2020-01-01T00:00:08.000+08:00| 100.5| -|2020-01-01T00:00:10.000+08:00| 119.5| -|2020-01-01T00:00:12.000+08:00| 101.0| -|2020-01-01T00:00:14.000+08:00| 99.5| -|2020-01-01T00:00:16.000+08:00| 119.0| -|2020-01-01T00:00:18.000+08:00| 80.5| -|2020-01-01T00:00:20.000+08:00| 99.0| -|2020-01-01T00:00:22.000+08:00| 121.0| -|2020-01-01T00:00:24.000+08:00| 79.5| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select seasonalrepair(s1,'period'=3,'k'=2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------+ -| Time|seasonalrepair(root.test.d2.s1, 'period'=4, 'k'=2)| -+-----------------------------+--------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:04.000+08:00| 120.0| -|2020-01-01T00:00:06.000+08:00| 80.0| -|2020-01-01T00:00:08.000+08:00| 100.5| -|2020-01-01T00:00:10.000+08:00| 119.5| -|2020-01-01T00:00:12.000+08:00| 87.0| -|2020-01-01T00:00:14.000+08:00| 99.5| -|2020-01-01T00:00:16.000+08:00| 119.0| -|2020-01-01T00:00:18.000+08:00| 80.5| -|2020-01-01T00:00:20.000+08:00| 99.0| -|2020-01-01T00:00:22.000+08:00| 121.0| -|2020-01-01T00:00:24.000+08:00| 79.5| -+-----------------------------+--------------------------------------------------+ -``` - -##### 使用改进的分解方法进行修复 -当`method`取值为'Improved'时,本函数将使用改进的分解方法进行数值修复。 - -输入序列同上,用于查询的SQL语句如下: - -```sql -select seasonalrepair(s1,'method'='improved','period'=3) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------------------+ -| Time|valuerepair(root.test.d2.s1, 'method'='improved', 'period'=3)| -+-----------------------------+-------------------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:04.000+08:00| 120.0| -|2020-01-01T00:00:06.000+08:00| 80.0| -|2020-01-01T00:00:08.000+08:00| 100.5| -|2020-01-01T00:00:10.000+08:00| 119.5| -|2020-01-01T00:00:12.000+08:00| 81.5| -|2020-01-01T00:00:14.000+08:00| 99.5| -|2020-01-01T00:00:16.000+08:00| 119.0| -|2020-01-01T00:00:18.000+08:00| 80.5| -|2020-01-01T00:00:20.000+08:00| 99.0| -|2020-01-01T00:00:22.000+08:00| 121.0| -|2020-01-01T00:00:24.000+08:00| 79.5| -+-----------------------------+-------------------------------------------------------------+ -``` - - - -## 序列发现 - -### ConsecutiveSequences - -#### 注册语句 - -```sql -create function consecutivesequences as 'org.apache.iotdb.library.series.UDTFConsecutiveSequences' -``` - -#### 函数简介 - -本函数用于在多维严格等间隔数据中发现局部最长连续子序列。 - -严格等间隔数据是指数据的时间间隔是严格相等的,允许存在数据缺失(包括行缺失和值缺失),但不允许存在数据冗余和时间戳偏移。 - -连续子序列是指严格按照标准时间间隔等距排布,不存在任何数据缺失的子序列。如果某个连续子序列不是任何连续子序列的真子序列,那么它是局部最长的。 - - -**函数名:** CONSECUTIVESEQUENCES - -**输入序列:** 支持多个输入序列,类型可以是任意的,但要满足严格等间隔的要求。 - -**参数:** - -+ `gap`:标准时间间隔,是一个有单位的正数。目前支持五种单位,分别是'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。在缺省情况下,函数会利用众数估计标准时间间隔。 - -**输出序列:** 输出单个序列,类型为 INT32。输出序列中的每一个数据点对应一个局部最长连续子序列,时间戳为子序列的起始时刻,值为子序列包含的数据点个数。 - -**提示:** 对于不符合要求的输入,本函数不对输出做任何保证。 - -#### 使用示例 - -##### 手动指定标准时间间隔 - -本函数可以通过`gap`参数手动指定标准时间间隔。需要注意的是,错误的参数设置会导致输出产生严重错误。 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:05:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:10:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:20:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:25:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:30:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:35:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:40:00.000+08:00| 1.0| null| -|2020-01-01T00:45:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:50:00.000+08:00| 1.0| 1.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consecutivesequences(s1,s2,'gap'='5m') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------------------+ -| Time|consecutivesequences(root.test.d1.s1, root.test.d1.s2, "gap"="5m")| -+-----------------------------+------------------------------------------------------------------+ -|2020-01-01T00:00:00.000+08:00| 3| -|2020-01-01T00:20:00.000+08:00| 4| -|2020-01-01T00:45:00.000+08:00| 2| -+-----------------------------+------------------------------------------------------------------+ -``` - -##### 自动估计标准时间间隔 - -当`gap`参数缺省时,本函数可以利用众数估计标准时间间隔,得到同样的结果。因此,这种用法更受推荐。 - -输入序列同上,用于查询的SQL语句如下: - -```sql -select consecutivesequences(s1,s2) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|consecutivesequences(root.test.d1.s1, root.test.d1.s2)| -+-----------------------------+------------------------------------------------------+ -|2020-01-01T00:00:00.000+08:00| 3| -|2020-01-01T00:20:00.000+08:00| 4| -|2020-01-01T00:45:00.000+08:00| 2| -+-----------------------------+------------------------------------------------------+ -``` - -### ConsecutiveWindows - -#### 注册语句 - -```sql -create function consecutivewindows as 'org.apache.iotdb.library.series.UDTFConsecutiveWindows' -``` - -#### 函数简介 - -本函数用于在多维严格等间隔数据中发现指定长度的连续窗口。 - -严格等间隔数据是指数据的时间间隔是严格相等的,允许存在数据缺失(包括行缺失和值缺失),但不允许存在数据冗余和时间戳偏移。 - -连续窗口是指严格按照标准时间间隔等距排布,不存在任何数据缺失的子序列。 - - -**函数名:** CONSECUTIVEWINDOWS - -**输入序列:** 支持多个输入序列,类型可以是任意的,但要满足严格等间隔的要求。 - -**参数:** - -+ `gap`:标准时间间隔,是一个有单位的正数。目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。在缺省情况下,函数会利用众数估计标准时间间隔。 -+ `length`:序列长度,是一个有单位的正数。目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。该参数不允许缺省。 - -**输出序列:** 输出单个序列,类型为 INT32。输出序列中的每一个数据点对应一个指定长度连续子序列,时间戳为子序列的起始时刻,值为子序列包含的数据点个数。 - -**提示:** 对于不符合要求的输入,本函数不对输出做任何保证。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:05:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:10:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:20:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:25:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:30:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:35:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:40:00.000+08:00| 1.0| null| -|2020-01-01T00:45:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:50:00.000+08:00| 1.0| 1.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consecutivewindows(s1,s2,'length'='10m') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------------------+ -| Time|consecutivewindows(root.test.d1.s1, root.test.d1.s2, "length"="10m")| -+-----------------------------+--------------------------------------------------------------------+ -|2020-01-01T00:00:00.000+08:00| 3| -|2020-01-01T00:20:00.000+08:00| 3| -|2020-01-01T00:25:00.000+08:00| 3| -+-----------------------------+--------------------------------------------------------------------+ -``` - - - -## 机器学习 - -### AR - -#### 注册语句 - -```sql -create function ar as 'org.apache.iotdb.library.dlearn.UDTFAR' -``` -#### 函数简介 - -本函数用于学习数据的自回归模型系数。 - -**函数名:** AR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `p`:自回归模型的阶数。默认为1。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。第一行对应模型的一阶系数,以此类推。 - -**提示:** - -- `p`应为正整数。 - -- 序列中的大部分点为等间隔采样点。 -- 序列中的缺失点通过线性插值进行填补后用于学习过程。 - -#### 使用示例 - -##### 指定阶数 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d0.s0| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| -4.0| -|2020-01-01T00:00:02.000+08:00| -3.0| -|2020-01-01T00:00:03.000+08:00| -2.0| -|2020-01-01T00:00:04.000+08:00| -1.0| -|2020-01-01T00:00:05.000+08:00| 0.0| -|2020-01-01T00:00:06.000+08:00| 1.0| -|2020-01-01T00:00:07.000+08:00| 2.0| -|2020-01-01T00:00:08.000+08:00| 3.0| -|2020-01-01T00:00:09.000+08:00| 4.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select ar(s0,"p"="2") from root.test.d0 -``` - -输出序列: - -``` -+-----------------------------+---------------------------+ -| Time|ar(root.test.d0.s0,"p"="2")| -+-----------------------------+---------------------------+ -|1970-01-01T08:00:00.001+08:00| 0.9429| -|1970-01-01T08:00:00.002+08:00| -0.2571| -+-----------------------------+---------------------------+ -``` - -### Representation - -#### 函数简介 - -本函数用于时间序列的表示。 - -**函数名:** Representation - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `tb`:时间分块数量。默认为10。 -- `vb`:值分块数量。默认为10。 - -**输出序列:** 输出单个序列,类型为INT32,长度为`tb*vb`。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** - -- `tb `,`vb`应为正整数。 - -#### 使用示例 - -##### 指定时间分块数量、值分块数量 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d0.s0| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| -4.0| -|2020-01-01T00:00:02.000+08:00| -3.0| -|2020-01-01T00:00:03.000+08:00| -2.0| -|2020-01-01T00:00:04.000+08:00| -1.0| -|2020-01-01T00:00:05.000+08:00| 0.0| -|2020-01-01T00:00:06.000+08:00| 1.0| -|2020-01-01T00:00:07.000+08:00| 2.0| -|2020-01-01T00:00:08.000+08:00| 3.0| -|2020-01-01T00:00:09.000+08:00| 4.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select representation(s0,"tb"="3","vb"="2") from root.test.d0 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------+ -| Time|representation(root.test.d0.s0,"tb"="3","vb"="2")| -+-----------------------------+-------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1| -|1970-01-01T08:00:00.002+08:00| 1| -|1970-01-01T08:00:00.003+08:00| 0| -|1970-01-01T08:00:00.004+08:00| 0| -|1970-01-01T08:00:00.005+08:00| 1| -|1970-01-01T08:00:00.006+08:00| 1| -+-----------------------------+-------------------------------------------------+ -``` - -### RM - -#### 函数简介 - -本函数用于基于时间序列表示的匹配度。 - -**函数名:** RM - -**输入序列:** 仅支持两个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `tb`:时间分块数量。默认为10。 -- `vb`:值分块数量。默认为10。 - -**输出序列:** 输出单个序列,类型为DOUBLE,长度为`1`。序列的时间戳从0开始,序列仅有一个数据点,其时间戳为0,值为两个时间序列的匹配度。 - -**提示:** - -- `tb `,`vb`应为正整数。 - -#### 使用示例 - -##### 指定时间分块数量、值分块数量 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d0.s0|root.test.d0.s1 -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:01.000+08:00| -4.0| -4.0| -|2020-01-01T00:00:02.000+08:00| -3.0| -3.0| -|2020-01-01T00:00:03.000+08:00| -3.0| -3.0| -|2020-01-01T00:00:04.000+08:00| -1.0| -1.0| -|2020-01-01T00:00:05.000+08:00| 0.0| 0.0| -|2020-01-01T00:00:06.000+08:00| 1.0| 1.0| -|2020-01-01T00:00:07.000+08:00| 2.0| 2.0| -|2020-01-01T00:00:08.000+08:00| 3.0| 3.0| -|2020-01-01T00:00:09.000+08:00| 4.0| 4.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select rm(s0, s1,"tb"="3","vb"="2") from root.test.d0 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------------------+ -| Time|rm(root.test.d0.s0,root.test.d0.s1,"tb"="3","vb"="2")| -+-----------------------------+-----------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1.00| -+-----------------------------+-----------------------------------------------------+ -``` - diff --git a/src/zh/UserGuide/V1.3.0-2/SQL-Manual/SQL-Manual.md b/src/zh/UserGuide/V1.3.0-2/SQL-Manual/SQL-Manual.md deleted file mode 100644 index 0cf3d8ca3..000000000 --- a/src/zh/UserGuide/V1.3.0-2/SQL-Manual/SQL-Manual.md +++ /dev/null @@ -1,1970 +0,0 @@ -# SQL手册 - -## 元数据操作 - -### 数据库管理 - -#### 创建数据库 - -```sql -CREATE DATABASE root.ln -``` - -#### 查看数据库 - -```sql -show databases -show databases root.* -show databases root.** -``` - -#### 删除数据库 - -```sql -DELETE DATABASE root.ln -DELETE DATABASE root.sgcc -DELETE DATABASE root.** -``` - -#### 统计数据库数量 - -```sql -count databases -count databases root.* -count databases root.sgcc.* -count databases root.sgcc -``` - -### 时间序列管理 - -#### 创建时间序列 - -```sql -create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN -create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT,encoding=RLE -create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT,encoding=PLAIN -create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN,encoding=PLAIN -create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN,encoding=PLAIN -create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT,encoding=RLE -``` - -- 简化版 - -```sql -create timeseries root.ln.wf01.wt01.status BOOLEAN encoding=PLAIN -create timeseries root.ln.wf01.wt01.temperature FLOAT encoding=RLE -create timeseries root.ln.wf02.wt02.hardware TEXT encoding=PLAIN -create timeseries root.ln.wf02.wt02.status BOOLEAN encoding=PLAIN -create timeseries root.sgcc.wf03.wt01.status BOOLEAN encoding=PLAIN -create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=RLE -``` - -- 错误提示 - -```sql -create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF -> error: encoding TS_2DIFF does not support BOOLEAN -``` - -#### 创建对齐时间序列 - -```sql -CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY) -``` - -#### 删除时间序列 - -```sql -delete timeseries root.ln.wf01.wt01.status -delete timeseries root.ln.wf01.wt01.temperature, root.ln.wf02.wt02.hardware -delete timeseries root.ln.wf02.* -drop timeseries root.ln.wf02.* -``` - -#### 查看时间序列 - -```sql -SHOW TIMESERIES -SHOW TIMESERIES -SHOW TIMESERIES root.** -SHOW TIMESERIES root.ln.** -SHOW TIMESERIES root.ln.** limit 10 offset 10 -SHOW TIMESERIES root.ln.** where timeseries contains 'wf01.wt' -SHOW TIMESERIES root.ln.** where dataType=FLOAT -SHOW TIMESERIES root.ln.** where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -SHOW LATEST TIMESERIES -``` - -#### 统计时间序列数量 - -```sql -COUNT TIMESERIES root.** -COUNT TIMESERIES root.ln.** -COUNT TIMESERIES root.ln.*.*.status -COUNT TIMESERIES root.ln.wf01.wt01.status -COUNT TIMESERIES root.** WHERE TIMESERIES contains 'sgcc' -COUNT TIMESERIES root.** WHERE DATATYPE = INT64 -COUNT TIMESERIES root.** WHERE TAGS(unit) contains 'c' -COUNT TIMESERIES root.** WHERE TAGS(unit) = 'c' -COUNT TIMESERIES root.** WHERE TIMESERIES contains 'sgcc' group by level = 1 -COUNT TIMESERIES root.** WHERE time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -COUNT TIMESERIES root.** GROUP BY LEVEL=1 -COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2 -COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=2 -``` - -#### 标签点管理 - -```sql -create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2) -``` - -- 重命名标签或属性 - -```sql -ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1 -``` - -- 重新设置标签或属性的值 - -```sql -ALTER timeseries root.turbine.d1.s1 SET newTag1=newV1, attr1=newV1 -``` - -- 删除已经存在的标签或属性 - -```sql -ALTER timeseries root.turbine.d1.s1 DROP tag1, tag2 -``` - -- 添加新的标签 - -```sql -ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4 -``` - -- 添加新的属性 - -```sql -ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4 -``` - -- 更新插入别名,标签和属性 - -```sql -ALTER timeseries root.turbine.d1.s1 UPSERT ALIAS=newAlias TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4) -``` - -- 使用标签作为过滤条件查询时间序列 - -```sql -SHOW TIMESERIES (<`PathPattern`>)? timeseriesWhereClause -``` - -返回给定路径的下的所有满足条件的时间序列信息: - -```sql -ALTER timeseries root.ln.wf02.wt02.hardware ADD TAGS unit=c -ALTER timeseries root.ln.wf02.wt02.status ADD TAGS description=test1 -show timeseries root.ln.** where TAGS(unit)='c' -show timeseries root.ln.** where TAGS(description) contains 'test1' -``` - -- 使用标签作为过滤条件统计时间序列数量 - -```sql -COUNT TIMESERIES (<`PathPattern`>)? timeseriesWhereClause -COUNT TIMESERIES (<`PathPattern`>)? timeseriesWhereClause GROUP BY LEVEL= -``` - -返回给定路径的下的所有满足条件的时间序列的数量: - -```sql -count timeseries -count timeseries root.** where TAGS(unit)='c' -count timeseries root.** where TAGS(unit)='c' group by level = 2 -``` - -创建对齐时间序列: - -```sql -create aligned timeseries root.sg1.d1(s1 INT32 tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2), s2 DOUBLE tags(tag3=v3, tag4=v4) attributes(attr3=v3, attr4=v4)) -``` - -支持查询: - -```sql -show timeseries where TAGS(tag1)='v1' -``` - -### 时间序列路径管理 - -#### 查看路径的所有子路径 - -```sql -SHOW CHILD PATHS pathPattern -- 查询 root.ln 的下一层:show child paths root.ln -- 查询形如 root.xx.xx.xx 的路径:show child paths root.*.* -``` -#### 查看路径的所有子节点 - -```sql -SHOW CHILD NODES pathPattern - -- 查询 root 的下一层:show child nodes root -- 查询 root.ln 的下一层 :show child nodes root.ln -``` -#### 查看设备 - -```sql -IoTDB> show devices - -IoTDB> show devices root.ln.** - -IoTDB> show devices where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` -##### 查看设备及其 database 信息 - -```sql -IoTDB> show devices with database - -IoTDB> show devices root.ln.** with database -``` -#### 统计节点数 - -```sql -IoTDB > COUNT NODES root.** LEVEL=2 - -IoTDB > COUNT NODES root.ln.** LEVEL=2 - -IoTDB > COUNT NODES root.ln.wf01.* LEVEL=3 - -IoTDB > COUNT NODES root.**.temperature LEVEL=3 -``` -#### 统计设备数量 - -```sql - -IoTDB> count devices - -IoTDB> count devices root.ln.** - -IoTDB> count devices where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` -### 设备模板管理 - - -![img](/img/%E6%A8%A1%E6%9D%BF.png) -![img](/img/template.jpg) - - - -#### 创建设备模板 - -```Go -CREATE DEVICE TEMPLATE ALIGNED? '(' [',' ]+ ')' -``` - -创建包含两个非对齐序列的设备模板 -```sql -IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY) -``` -创建包含一组对齐序列的设备模板 -```sql -IoTDB> create device template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla) -``` -#### 挂载设备模板 -```sql -IoTDB> set DEVICE TEMPLATE t1 to root.sg1 -``` -#### 激活设备模板 -```sql -IoTDB> create timeseries using DEVICE TEMPLATE on root.sg1.d1 - -IoTDB> set DEVICE TEMPLATE t1 to root.sg1.d1 - -IoTDB> set DEVICE TEMPLATE t2 to root.sg1.d2 - -IoTDB> create timeseries using device template on root.sg1.d1 - -IoTDB> create timeseries using device template on root.sg1.d2 -``` -#### 查看设备模板 -```sql -IoTDB> show device templates -``` -- 查看某个设备模板下的物理量 -```sql -IoTDB> show nodes in device template t1 -``` -- 查看挂载了某个设备模板的路径 -```sql -IoTDB> show paths set device template t1 -``` -- 查看使用了某个设备模板的路径(即模板在该路径上已激活,序列已创建) -```sql -IoTDB> show paths using device template t1 -``` -#### 解除设备模板 -```sql -IoTDB> delete timeseries of device template t1 from root.sg1.d1 -``` -```sql -IoTDB> deactivate device template t1 from root.sg1.d1 -``` -批量处理 -```sql -IoTDB> delete timeseries of device template t1 from root.sg1.*, root.sg2.* -``` -```sql -IoTDB> deactivate device template t1 from root.sg1.*, root.sg2.* -``` -#### 卸载设备模板 -```sql -IoTDB> unset device template t1 from root.sg1.d1 -``` -#### 删除设备模板 -```sql -IoTDB> drop device template t1 -``` -### 数据存活时间管理 - -#### 设置 TTL -```sql -IoTDB> set ttl to root.ln 3600000 -``` -```sql -IoTDB> set ttl to root.sgcc.** 3600000 -``` -```sql -IoTDB> set ttl to root.** 3600000 -``` -#### 取消 TTL -```sql -IoTDB> unset ttl to root.ln -``` -```sql -IoTDB> unset ttl to root.sgcc.** -``` -```sql -IoTDB> unset ttl to root.** -``` - -#### 显示 TTL -```sql -IoTDB> SHOW ALL TTL -``` -```sql -IoTDB> SHOW TTL ON StorageGroupNames -``` -## 写入数据 - -### 写入单列数据 -```sql -IoTDB > insert into root.ln.wf02.wt02(timestamp,status) values(1,true) -``` -```sql -IoTDB > insert into root.ln.wf02.wt02(timestamp,hardware) values(1, 'v1'),(2, 'v1') -``` -### 写入多列数据 -```sql -IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) values (2, false, 'v2') -``` -```sql -IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (3, false, 'v3'),(4, true, 'v4') -``` -### 使用服务器时间戳 -```sql -IoTDB > insert into root.ln.wf02.wt02(status, hardware) values (false, 'v2') -``` -### 写入对齐时间序列数据 -```sql -IoTDB > create aligned timeseries root.sg1.d1(s1 INT32, s2 DOUBLE) -``` -```sql -IoTDB > insert into root.sg1.d1(timestamp, s1, s2) aligned values(1, 1, 1) -``` -```sql -IoTDB > insert into root.sg1.d1(timestamp, s1, s2) aligned values(2, 2, 2), (3, 3, 3) -``` -```sql -IoTDB > select * from root.sg1.d1 -``` -### 加载 TsFile 文件数据 - -load '' [sglevel=int][onSuccess=delete/none] - -#### 通过指定文件路径(绝对路径)加载单 tsfile 文件 - -- `load '/Users/Desktop/data/1575028885956-101-0.tsfile'` -- `load '/Users/Desktop/data/1575028885956-101-0.tsfile' sglevel=1` -- `load '/Users/Desktop/data/1575028885956-101-0.tsfile' onSuccess=delete` -- `load '/Users/Desktop/data/1575028885956-101-0.tsfile' sglevel=1 onSuccess=delete` - - -#### 通过指定文件夹路径(绝对路径)批量加载文件 - -- `load '/Users/Desktop/data'` -- `load '/Users/Desktop/data' sglevel=1` -- `load '/Users/Desktop/data' onSuccess=delete` -- `load '/Users/Desktop/data' sglevel=1 onSuccess=delete` - -## 删除数据 - -### 删除单列数据 -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` -```sql -delete from root.ln.wf02.wt02.status where time < 10 -``` -```sql -delete from root.ln.wf02.wt02.status where time <= 10 -``` -```sql -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -``` -```sql -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -``` -```sql -delete from root.ln.wf02.wt02.status where time > 20 -``` -```sql -delete from root.ln.wf02.wt02.status where time >= 20 -``` -```sql -delete from root.ln.wf02.wt02.status where time = 20 -``` -出错: -```sql -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 - -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic - -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` - -删除时间序列中的所有数据: -```sql -delete from root.ln.wf02.wt02.status -``` -### 删除多列数据 -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` -声明式的编程方式: -```sql -IoTDB> delete from root.ln.wf03.wt02.status where time < now() - -Msg: The statement is executed successfully. -``` -## 数据查询 - -### 基础查询 - -#### 时间过滤查询 -```sql -select temperature from root.ln.wf01.wt01 where time < 2017-11-01T00:08:00.000 -``` -#### 根据一个时间区间选择多列数据 -```sql -select status, temperature from root.ln.wf01.wt01 where time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000; -``` -#### 按照多个时间区间选择同一设备的多列数据 -```sql -select status, temperature from root.ln.wf01.wt01 where (time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000) or (time >= 2017-11-01T16:35:00.000 and time <= 2017-11-01T16:37:00.000); -``` -#### 按照多个时间区间选择不同设备的多列数据 -```sql -select wf01.wt01.status, wf02.wt02.hardware from root.ln where (time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000) or (time >= 2017-11-01T16:35:00.000 and time <= 2017-11-01T16:37:00.000); -``` -#### 根据时间降序返回结果集 -```sql -select * from root.ln.** where time > 1 order by time desc limit 10; -``` -### 选择表达式 - -#### 使用别名 -```sql -select s1 as temperature, s2 as speed from root.ln.wf01.wt01; -``` -#### 运算符 - -#### 函数 - -不支持: -```sql -select s1, count(s1) from root.sg.d1; - -select sin(s1), count(s1) from root.sg.d1; - -select s1, count(s1) from root.sg.d1 group by ([10,100),10ms); -``` -##### 时间序列查询嵌套表达式 - -示例 1: -```sql -select a, - -​ b, - -​ ((a + 1) * 2 - 1) % 2 + 1.5, - -​ sin(a + sin(a + sin(b))), - -​ -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b)) + 1 - -from root.sg1; -``` -示例 2: -```sql -select (a + b) * 2 + sin(a) from root.sg - -示例 3: - -select (a + *) / 2 from root.sg1 - -示例 4: - -select (a + b) * 3 from root.sg, root.ln -``` -##### 聚合查询嵌套表达式 - -示例 1: -```sql -select avg(temperature), - -​ sin(avg(temperature)), - -​ avg(temperature) + 1, - -​ -sum(hardware), - -​ avg(temperature) + sum(hardware) - -from root.ln.wf01.wt01; -``` -示例 2: -```sql -select avg(*), - -​ (avg(*) + 1) * 3 / 2 -1 - -from root.sg1 -``` -示例 3: -```sql -select avg(temperature), - -​ sin(avg(temperature)), - -​ avg(temperature) + 1, - -​ -sum(hardware), - -​ avg(temperature) + sum(hardware) as custom_sum - -from root.ln.wf01.wt01 - -GROUP BY([10, 90), 10ms); -``` -#### 最新点查询 - -SQL 语法: - -```Go -select last [COMMA ]* from < PrefixPath > [COMMA < PrefixPath >]* [ORDER BY TIMESERIES (DESC | ASC)?] -``` - -查询 root.ln.wf01.wt01.status 的最新数据点 -```sql -IoTDB> select last status from root.ln.wf01.wt01 -``` -查询 root.ln.wf01.wt01 下 status,temperature 时间戳大于等于 2017-11-07T23:50:00 的最新数据点 -```sql -IoTDB> select last status, temperature from root.ln.wf01.wt01 where time >= 2017-11-07T23:50:00 -``` - 查询 root.ln.wf01.wt01 下所有序列的最新数据点,并按照序列名降序排列 -```sql -IoTDB> select last * from root.ln.wf01.wt01 order by timeseries desc; -``` -### 查询过滤条件 - -#### 时间过滤条件 - -选择时间戳大于 2022-01-01T00:05:00.000 的数据: -```sql -select s1 from root.sg1.d1 where time > 2022-01-01T00:05:00.000; -``` -选择时间戳等于 2022-01-01T00:05:00.000 的数据: -```sql -select s1 from root.sg1.d1 where time = 2022-01-01T00:05:00.000; -``` -选择时间区间 [2017-11-01T00:05:00.000, 2017-11-01T00:12:00.000) 内的数据: -```sql -select s1 from root.sg1.d1 where time >= 2022-01-01T00:05:00.000 and time < 2017-11-01T00:12:00.000; -``` -#### 值过滤条件 - -选择值大于 36.5 的数据: -```sql -select temperature from root.sg1.d1 where temperature > 36.5; -``` -选择值等于 true 的数据: -```sql -select status from root.sg1.d1 where status = true; -``` -选择区间 [36.5,40] 内或之外的数据: -```sql -select temperature from root.sg1.d1 where temperature between 36.5 and 40; -``` -```sql -select temperature from root.sg1.d1 where temperature not between 36.5 and 40; -``` -选择值在特定范围内的数据: -```sql -select code from root.sg1.d1 where code in ('200', '300', '400', '500'); -``` -选择值在特定范围外的数据: -```sql -select code from root.sg1.d1 where code not in ('200', '300', '400', '500'); -``` -选择值为空的数据: -```sql -select code from root.sg1.d1 where temperature is null; -``` -选择值为非空的数据: -```sql -select code from root.sg1.d1 where temperature is not null; -``` -#### 模糊查询 - -查询 `root.sg.d1` 下 `value` 含有`'cc'`的数据 -```sql -IoTDB> select * from root.sg.d1 where value like '%cc%' -``` -查询 `root.sg.d1` 下 `value` 中间为 `'b'`、前后为任意单个字符的数据 -```sql -IoTDB> select * from root.sg.device where value like '_b_' -``` -查询 root.sg.d1 下 value 值为26个英文字符组成的字符串 -```sql -IoTDB> select * from root.sg.d1 where value regexp '^[A-Za-z]+$' -``` - -查询 root.sg.d1 下 value 值为26个小写英文字符组成的字符串且时间大于100的 -```sql -IoTDB> select * from root.sg.d1 where value regexp '^[a-z]+$' and time > 100 -``` - -### 分段分组聚合 - -#### 未指定滑动步长的时间区间分组聚合查询 -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d); -``` -#### 指定滑动步长的时间区间分组聚合查询 -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d); -``` -滑动步长可以小于聚合窗口 -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-01 10:00:00), 4h, 2h); -``` -#### 按照自然月份的时间区间分组聚合查询 -```sql -select count(status) from root.ln.wf01.wt01 where time > 2017-11-01T01:00:00 group by([2017-11-01T00:00:00, 2019-11-07T23:00:00), 1mo, 2mo); -``` -每个时间间隔窗口内都有数据 -```sql -select count(status) from root.ln.wf01.wt01 group by([2017-10-31T00:00:00, 2019-11-07T23:00:00), 1mo, 2mo); -``` -#### 左开右闭区间 -```sql -select count(status) from root.ln.wf01.wt01 group by ((2017-11-01T00:00:00, 2017-11-07T23:00:00],1d); -``` -#### 与分组聚合混合使用 - -统计降采样后的数据点个数 -```sql -select count(status) from root.ln.wf01.wt01 group by ((2017-11-01T00:00:00, 2017-11-07T23:00:00],1d), level=1; -``` -加上滑动 Step 的降采样后的结果也可以汇总 -```sql -select count(status) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d), level=1; -``` -#### 路径层级分组聚合 - -统计不同 database 下 status 序列的数据点个数 -```sql -select count(status) from root.** group by level = 1 -``` - 统计不同设备下 status 序列的数据点个数 -```sql -select count(status) from root.** group by level = 3 -``` -统计不同 database 下的不同设备中 status 序列的数据点个数 -```sql -select count(status) from root.** group by level = 1, 3 -``` -查询所有序列下温度传感器 temperature 的最大值 -```sql -select max_value(temperature) from root.** group by level = 0 -``` -查询某一层级下所有传感器拥有的总数据点数 -```sql -select count(*) from root.ln.** group by level = 2 -``` -#### 标签分组聚合 - -##### 单标签聚合查询 -```sql -SELECT AVG(temperature) FROM root.factory1.** GROUP BY TAGS(city); -``` -##### 多标签聚合查询 -```sql -SELECT avg(temperature) FROM root.factory1.** GROUP BY TAGS(city, workshop); -``` -##### 基于时间区间的标签聚合查询 -```sql -SELECT AVG(temperature) FROM root.factory1.** GROUP BY ([1000, 10000), 5s), TAGS(city, workshop); -``` -#### 差值分段聚合 -```sql -group by variation(controlExpression[,delta][,ignoreNull=true/false]) -``` -##### delta=0时的等值事件分段 -```sql -select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6) -``` -指定ignoreNull为false -```sql -select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6, ignoreNull=false) -``` -##### delta!=0时的差值事件分段 -```sql -select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6, 4) -``` -#### 条件分段聚合 -```sql -group by condition(predict,[keep>/>=/=/<=/<]threshold,[,ignoreNull=true/false]) -``` -查询至少连续两行以上的charging_status=1的数据 -```sql -select max_time(charging_status),count(vehicle_status),last_value(soc) from root.** group by condition(charging_status=1,KEEP>=2,ignoreNull=true) -``` -当设置`ignoreNull`为false时,遇到null值为将其视为一个不满足条件的行,得到结果原先的分组被含null的行拆分 -```sql -select max_time(charging_status),count(vehicle_status),last_value(soc) from root.** group by condition(charging_status=1,KEEP>=2,ignoreNull=false) -``` -#### 会话分段聚合 -```sql -group by session(timeInterval) -``` -按照不同的时间单位设定时间间隔 -```sql -select __endTime,count(*) from root.** group by session(1d) -``` -和`HAVING`、`ALIGN BY DEVICE`共同使用 -```sql -select __endTime,sum(hardware) from root.ln.wf02.wt01 group by session(50s) having sum(hardware)>0 align by device -``` -#### 点数分段聚合 -```sql -group by count(controlExpression, size[,ignoreNull=true/false]) -``` -select count(charging_stauts), first_value(soc) from root.sg group by count(charging_status,5) - -当使用ignoreNull将null值也考虑进来 -```sql -select count(charging_stauts), first_value(soc) from root.sg group by count(charging_status,5,ignoreNull=false) -``` -### 聚合结果过滤 - -不正确的: -```sql -select count(s1) from root.** group by ([1,3),1ms) having sum(s1) > s1 - -select count(s1) from root.** group by ([1,3),1ms) having s1 > 1 - -select count(s1) from root.** group by ([1,3),1ms), level=1 having sum(d1.s1) > 1 - -select count(d1.s1) from root.** group by ([1,3),1ms), level=1 having sum(s1) > 1 -``` -SQL 示例: -```sql - select count(s1) from root.** group by ([1,11),2ms), level=1 having count(s2) > 2; - - select count(s1), count(s2) from root.** group by ([1,11),2ms) having count(s2) > 1 align by device; -``` -### 结果集补空值 -```sql -FILL '(' PREVIOUS | LINEAR | constant (, interval=DURATION_LITERAL)? ')' -``` -#### `PREVIOUS` 填充 -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(previous); -``` -#### `PREVIOUS` 填充并指定填充超时阈值 -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(previous, 2m); -``` -#### `LINEAR` 填充 -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(linear); -``` -#### 常量填充 -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(2.0); -``` -使用 `BOOLEAN` 类型的常量填充 -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(true); -``` -### 查询结果分页 - -#### 按行分页 - - 基本的 `LIMIT` 子句 -```sql -select status, temperature from root.ln.wf01.wt01 limit 10 -``` -带 `OFFSET` 的 `LIMIT` 子句 -```sql -select status, temperature from root.ln.wf01.wt01 limit 5 offset 3 -``` -`LIMIT` 子句与 `WHERE` 子句结合 -```sql -select status,temperature from root.ln.wf01.wt01 where time > 2017-11-01T00:05:00.000 and time< 2017-11-01T00:12:00.000 limit 5 offset 3 -``` - `LIMIT` 子句与 `GROUP BY` 子句组合 -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d) limit 4 offset 3 -``` -#### 按列分页 - - 基本的 `SLIMIT` 子句 -```sql -select * from root.ln.wf01.wt01 where time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000 slimit 1 -``` -带 `SOFFSET` 的 `SLIMIT` 子句 -```sql -select * from root.ln.wf01.wt01 where time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000 slimit 1 soffset 1 -``` -`SLIMIT` 子句与 `GROUP BY` 子句结合 -```sql -select max_value(*) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d) slimit 1 soffset 1 -``` -`SLIMIT` 子句与 `LIMIT` 子句结合 -```sql -select * from root.ln.wf01.wt01 limit 10 offset 100 slimit 2 soffset 0 -``` -### 排序 - -时间对齐模式下的排序 -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 order by time desc; -``` -设备对齐模式下的排序 -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 order by device desc,time asc align by device; -``` -在时间戳相等时按照设备名排序 -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 order by time asc,device desc align by device; -``` -没有显式指定时 -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 align by device; -``` -对聚合后的结果进行排序 -```sql -select count(*) from root.ln.** group by ((2017-11-01T00:00:00.000+08:00,2017-11-01T00:03:00.000+08:00],1m) order by device asc,time asc align by device -``` -### 查询对齐模式 - -#### 按设备对齐 -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 align by device; -``` -### 查询写回(SELECT INTO) - -#### 整体描述 -```sql -selectIntoStatement - -​ : SELECT - -​ resultColumn [, resultColumn] ... - -​ INTO intoItem [, intoItem] ... - -​ FROM prefixPath [, prefixPath] ... - -​ [WHERE whereCondition] - -​ [GROUP BY groupByTimeClause, groupByLevelClause] - -​ [FILL ({PREVIOUS | LINEAR | constant} (, interval=DURATION_LITERAL)?)] - -​ [LIMIT rowLimit OFFSET rowOffset] - -​ [ALIGN BY DEVICE] - -​ ; - - - -intoItem - -​ : [ALIGNED] intoDevicePath '(' intoMeasurementName [',' intoMeasurementName]* ')' - -​ ; -``` -按时间对齐,将 `root.sg` database 下四条序列的查询结果写入到 `root.sg_copy` database 下指定的四条序列中 -```sql -IoTDB> select s1, s2 into root.sg_copy.d1(t1), root.sg_copy.d2(t1, t2), root.sg_copy.d1(t2) from root.sg.d1, root.sg.d2; -``` -按时间对齐,将聚合查询的结果存储到指定序列中 -```sql -IoTDB> select count(s1 + s2), last_value(s2) into root.agg.count(s1_add_s2), root.agg.last_value(s2) from root.sg.d1 group by ([0, 100), 10ms); -``` -按设备对齐 -```sql -IoTDB> select s1, s2 into root.sg_copy.d1(t1, t2), root.sg_copy.d2(t1, t2) from root.sg.d1, root.sg.d2 align by device; -``` -按设备对齐,将表达式计算的结果存储到指定序列中 -```sql -IoTDB> select s1 + s2 into root.expr.add(d1s1_d1s2), root.expr.add(d2s1_d2s2) from root.sg.d1, root.sg.d2 align by device; -``` -#### 使用变量占位符 - -##### 按时间对齐(默认) - -###### 目标设备不使用变量占位符 & 目标物理量列表使用变量占位符 -``` - -select s1, s2 - -into root.sg_copy.d1(::), root.sg_copy.d2(s1), root.sg_copy.d1(${3}), root.sg_copy.d2(::) - -from root.sg.d1, root.sg.d2; -``` - -该语句等价于: -``` - -select s1, s2 - -into root.sg_copy.d1(s1), root.sg_copy.d2(s1), root.sg_copy.d1(s2), root.sg_copy.d2(s2) - -from root.sg.d1, root.sg.d2; -``` - -###### 目标设备使用变量占位符 & 目标物理量列表不使用变量占位符 - -``` -select d1.s1, d1.s2, d2.s3, d3.s4 - -into ::(s1_1, s2_2), root.sg.d2_2(s3_3), root.${2}_copy.::(s4) - -from root.sg; -``` - -###### 目标设备使用变量占位符 & 目标物理量列表使用变量占位符 - -``` -select * into root.sg_bk.::(::) from root.sg.**; -``` - -##### 按设备对齐(使用 `ALIGN BY DEVICE`) - -###### 目标设备不使用变量占位符 & 目标物理量列表使用变量占位符 -``` - -select s1, s2, s3, s4 - -into root.backup_sg.d1(s1, s2, s3, s4), root.backup_sg.d2(::), root.sg.d3(backup_${4}) - -from root.sg.d1, root.sg.d2, root.sg.d3 - -align by device; -``` - -###### 目标设备使用变量占位符 & 目标物理量列表不使用变量占位符 -``` - -select avg(s1), sum(s2) + sum(s3), count(s4) - -into root.agg_${2}.::(avg_s1, sum_s2_add_s3, count_s4) - -from root.** - -align by device; -``` - -###### 目标设备使用变量占位符 & 目标物理量列表使用变量占位符 -``` - -select * into ::(backup_${4}) from root.sg.** align by device; -``` - -#### 指定目标序列为对齐序列 -``` - -select s1, s2 into root.sg_copy.d1(t1, t2), aligned root.sg_copy.d2(t1, t2) from root.sg.d1, root.sg.d2 align by device; -``` -## 运维语句 -生成对应的查询计划 -``` -explain select s1,s2 from root.sg.d1 -``` -执行对应的查询语句,并获取分析结果 -``` -explain analyze select s1,s2 from root.sg.d1 order by s1 -``` -## 运算符 - -更多见文档[Operator-and-Expression](../Reference/Function-and-Expression.md#算数运算符和函数) - -### 算数运算符 - -更多见文档 [Arithmetic Operators and Functions](../Reference/Function-and-Expression.md#算数运算符和函数) - -```sql -select s1, - s1, s2, + s2, s1 + s2, s1 - s2, s1 * s2, s1 / s2, s1 % s2 from root.sg.d1 -``` - -### 比较运算符 - -更多见文档[Comparison Operators and Functions](../Reference/Function-and-Expression.md#比较运算符和函数) - -```sql -# Basic comparison operators -select a, b, a > 10, a <= b, !(a <= b), a > 10 && a > b from root.test; - -# `BETWEEN ... AND ...` operator -select temperature from root.sg1.d1 where temperature between 36.5 and 40; -select temperature from root.sg1.d1 where temperature not between 36.5 and 40; - -# Fuzzy matching operator: Use `Like` for fuzzy matching -select * from root.sg.d1 where value like '%cc%' -select * from root.sg.device where value like '_b_' - -# Fuzzy matching operator: Use `Regexp` for fuzzy matching -select * from root.sg.d1 where value regexp '^[A-Za-z]+$' -select * from root.sg.d1 where value regexp '^[a-z]+$' and time > 100 -select b, b like '1%', b regexp '[0-2]' from root.test; - -# `IS NULL` operator -select code from root.sg1.d1 where temperature is null; -select code from root.sg1.d1 where temperature is not null; - -# `IN` operator -select code from root.sg1.d1 where code in ('200', '300', '400', '500'); -select code from root.sg1.d1 where code not in ('200', '300', '400', '500'); -select a, a in (1, 2) from root.test; -``` - -### 逻辑运算符 - -更多见文档[Logical Operators](../Reference/Function-and-Expression.md#逻辑运算符) - -```sql -select a, b, a > 10, a <= b, !(a <= b), a > 10 && a > b from root.test; -``` - -## 内置函数 - -更多见文档[Operator-and-Expression](../Reference/Function-and-Expression.md#聚合函数) - -### Aggregate Functions - -更多见文档[Aggregate Functions](../Reference/Function-and-Expression.md#聚合函数) - -```sql -select count(status) from root.ln.wf01.wt01; - -select count_if(s1=0 & s2=0, 3), count_if(s1=1 & s2=0, 3) from root.db.d1; -select count_if(s1=0 & s2=0, 3, 'ignoreNull'='false'), count_if(s1=1 & s2=0, 3, 'ignoreNull'='false') from root.db.d1; - -select time_duration(s1) from root.db.d1; -``` - -### 算数函数 - -更多见文档[Arithmetic Operators and Functions](../Reference/Function-and-Expression.md#数学函数) - -```sql -select s1, sin(s1), cos(s1), tan(s1) from root.sg1.d1 limit 5 offset 1000; -select s4,round(s4),round(s4,2),round(s4,-1) from root.sg1.d1; -``` - -### 比较函数 - -更多见文档[Comparison Operators and Functions](../Reference/Function-and-Expression.md#比较运算符和函数) - -```sql -select ts, on_off(ts, 'threshold'='2') from root.test; -select ts, in_range(ts, 'lower'='2', 'upper'='3.1') from root.test; -``` - -### 字符串处理函数 - -更多见文档[String Processing](../Reference/Function-and-Expression.md#字符串处理) - -```sql -select s1, string_contains(s1, 's'='warn') from root.sg1.d4; -select s1, string_matches(s1, 'regex'='[^\\s]+37229') from root.sg1.d4; -select s1, length(s1) from root.sg1.d1 -select s1, locate(s1, "target"="1") from root.sg1.d1 -select s1, locate(s1, "target"="1", "reverse"="true") from root.sg1.d1 -select s1, startswith(s1, "target"="1") from root.sg1.d1 -select s1, endswith(s1, "target"="1") from root.sg1.d1 -select s1, s2, concat(s1, s2, "target1"="IoT", "target2"="DB") from root.sg1.d1 -select s1, s2, concat(s1, s2, "target1"="IoT", "target2"="DB", "series_behind"="true") from root.sg1.d1 -select s1, substring(s1 from 1 for 2) from root.sg1.d1 -select s1, replace(s1, 'es', 'tt') from root.sg1.d1 -select s1, upper(s1) from root.sg1.d1 -select s1, lower(s1) from root.sg1.d1 -select s3, trim(s3) from root.sg1.d1 -select s1, s2, strcmp(s1, s2) from root.sg1.d1 -select strreplace(s1, "target"=",", "replace"="/", "limit"="2") from root.test.d1 -select strreplace(s1, "target"=",", "replace"="/", "limit"="1", "offset"="1", "reverse"="true") from root.test.d1 -select regexmatch(s1, "regex"="\d+\.\d+\.\d+\.\d+", "group"="0") from root.test.d1 -select regexreplace(s1, "regex"="192\.168\.0\.(\d+)", "replace"="cluster-$1", "limit"="1") from root.test.d1 -select regexsplit(s1, "regex"=",", "index"="-1") from root.test.d1 -select regexsplit(s1, "regex"=",", "index"="3") from root.test.d1 -``` - -### 数据类型转换函数 - -更多见文档[Data Type Conversion Function](../Reference/Function-and-Expression.md#数据类型转换) - -```sql -SELECT cast(s1 as INT32) from root.sg -``` - -### 常序列生成函数 - -更多见文档[Constant Timeseries Generating Functions](../Reference/Function-and-Expression.md#常序列生成函数) - -```sql -select s1, s2, const(s1, 'value'='1024', 'type'='INT64'), pi(s2), e(s1, s2) from root.sg1.d1; -``` - -### 选择函数 - -更多见文档[Selector Functions](../Reference/Function-and-Expression.md#选择函数) - -```sql -select s1, top_k(s1, 'k'='2'), bottom_k(s1, 'k'='2') from root.sg1.d2 where time > 2020-12-10T20:36:15.530+08:00; -``` - -### 区间查询函数 - -更多见文档[Continuous Interval Functions](../Reference/Function-and-Expression.md#区间查询函数) - -```sql -select s1, zero_count(s1), non_zero_count(s2), zero_duration(s3), non_zero_duration(s4) from root.sg.d2; -``` - -### 趋势计算函数 - -更多见文档[Variation Trend Calculation Functions](../Reference/Function-and-Expression.md#趋势计算函数) - -```sql -select s1, time_difference(s1), difference(s1), non_negative_difference(s1), derivative(s1), non_negative_derivative(s1) from root.sg1.d1 limit 5 offset 1000; - -SELECT DIFF(s1), DIFF(s2) from root.test; -SELECT DIFF(s1, 'ignoreNull'='false'), DIFF(s2, 'ignoreNull'='false') from root.test; -``` - -### 采样函数 - -更多见文档[Sample Functions](../Reference/Function-and-Expression.md#采样函数)。 -### 时间序列处理函数 - -更多见文档[Sample Functions](../Reference/Function-and-Expression.md#时间序列处理函数)。 - -```sql -select equal_size_bucket_random_sample(temperature,'proportion'='0.1') as random_sample from root.ln.wf01.wt01; -select equal_size_bucket_agg_sample(temperature, 'type'='avg','proportion'='0.1') as agg_avg, equal_size_bucket_agg_sample(temperature, 'type'='max','proportion'='0.1') as agg_max, equal_size_bucket_agg_sample(temperature,'type'='min','proportion'='0.1') as agg_min, equal_size_bucket_agg_sample(temperature, 'type'='sum','proportion'='0.1') as agg_sum, equal_size_bucket_agg_sample(temperature, 'type'='extreme','proportion'='0.1') as agg_extreme, equal_size_bucket_agg_sample(temperature, 'type'='variance','proportion'='0.1') as agg_variance from root.ln.wf01.wt01; -select equal_size_bucket_m4_sample(temperature, 'proportion'='0.1') as M4_sample from root.ln.wf01.wt01; -select equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='avg', 'number'='2') as outlier_avg_sample, equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='stendis', 'number'='2') as outlier_stendis_sample, equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='cos', 'number'='2') as outlier_cos_sample, equal_size_bucket_outlier_sample(temperature, 'proportion'='0.1', 'type'='prenextdis', 'number'='2') as outlier_prenextdis_sample from root.ln.wf01.wt01; - -select M4(s1,'timeInterval'='25','displayWindowBegin'='0','displayWindowEnd'='100') from root.vehicle.d1 -select M4(s1,'windowSize'='10') from root.vehicle.d1 -``` - -### 时间序列处理函数 - -更多见文档[Time-Series](../Reference/Function-and-Expression.md#时间序列处理) - -```sql -select change_points(s1), change_points(s2), change_points(s3), change_points(s4), change_points(s5), change_points(s6) from root.testChangePoints.d1 -``` - -## 数据质量函数库 - -更多见文档[Operator-and-Expression](../Reference/UDF-Libraries.md) - -### 数据质量 - -更多见文档[Data-Quality](../Reference/UDF-Libraries.md#数据质量) - -```sql -# Completeness -select completeness(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -select completeness(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 - -# Consistency -select consistency(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -select consistency(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 - -# Timeliness -select timeliness(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -select timeliness(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 - -# Validity -select Validity(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -select Validity(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 - -# Accuracy -select Accuracy(t1,t2,t3,m1,m2,m3) from root.test -``` - -### 数据画像 - -更多见文档[Data-Profiling](../Reference/UDF-Libraries.md#数据画像) - -```sql -# ACF -select acf(s1) from root.test.d1 where time <= 2020-01-01 00:00:05 - -# Distinct -select distinct(s2) from root.test.d2 - -# Histogram -select histogram(s1,"min"="1","max"="20","count"="10") from root.test.d1 - -# Integral -select integral(s1) from root.test.d1 where time <= 2020-01-01 00:00:10 -select integral(s1, "unit"="1m") from root.test.d1 where time <= 2020-01-01 00:00:10 - -# IntegralAvg -select integralavg(s1) from root.test.d1 where time <= 2020-01-01 00:00:10 - -# Mad -select mad(s0) from root.test -select mad(s0, "error"="0.01") from root.test - -# Median -select median(s0, "error"="0.01") from root.test - -# MinMax -select minmax(s1) from root.test - -# Mode -select mode(s2) from root.test.d2 - -# MvAvg -select mvavg(s1, "window"="3") from root.test - -# PACF -select pacf(s1, "lag"="5") from root.test - -# Percentile -select percentile(s0, "rank"="0.2", "error"="0.01") from root.test - -# Quantile -select quantile(s0, "rank"="0.2", "K"="800") from root.test - -# Period -select period(s1) from root.test.d3 - -# QLB -select QLB(s1) from root.test.d1 - -# Resample -select resample(s1,'every'='5m','interp'='linear') from root.test.d1 -select resample(s1,'every'='30m','aggr'='first') from root.test.d1 -select resample(s1,'every'='30m','start'='2021-03-06 15:00:00') from root.test.d1 - -# Sample -select sample(s1,'method'='reservoir','k'='5') from root.test.d1 -select sample(s1,'method'='isometric','k'='5') from root.test.d1 - -# Segment -select segment(s1, "error"="0.1") from root.test - -# Skew -select skew(s1) from root.test.d1 - -# Spline -select spline(s1, "points"="151") from root.test - -# Spread -select spread(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 - -# Stddev -select stddev(s1) from root.test.d1 - -# ZScore -select zscore(s1) from root.test -``` - -### 异常检测 - -更多见文档[Anomaly-Detection](../Reference/UDF-Libraries.md#异常检测) - -```sql -# IQR -select iqr(s1) from root.test - -# KSigma -select ksigma(s1,"k"="1.0") from root.test.d1 where time <= 2020-01-01 00:00:30 - -# LOF -select lof(s1,s2) from root.test.d1 where time<1000 -select lof(s1, "method"="series") from root.test.d1 where time<1000 - -# MissDetect -select missdetect(s2,'minlen'='10') from root.test.d2 - -# Range -select range(s1,"lower_bound"="101.0","upper_bound"="125.0") from root.test.d1 where time <= 2020-01-01 00:00:30 - -# TwoSidedFilter -select TwoSidedFilter(s0, 'len'='5', 'threshold'='0.3') from root.test - -# Outlier -select outlier(s1,"r"="5.0","k"="4","w"="10","s"="5") from root.test - -# MasterTrain -select MasterTrain(lo,la,m_lo,m_la,'p'='3','eta'='1.0') from root.test - -# MasterDetect -select MasterDetect(lo,la,m_lo,m_la,model,'output_type'='repair','p'='3','k'='3','eta'='1.0') from root.test -select MasterDetect(lo,la,m_lo,m_la,model,'output_type'='anomaly','p'='3','k'='3','eta'='1.0') from root.test -``` - -### 频域分析 - -更多见文档[Frequency-Domain](../Reference/UDF-Libraries.md#频域分析) - -```sql -# Conv -select conv(s1,s2) from root.test.d2 - -# Deconv -select deconv(s3,s2) from root.test.d2 -select deconv(s3,s2,'result'='remainder') from root.test.d2 - -# DWT -select dwt(s1,"method"="haar") from root.test.d1 - -# FFT -select fft(s1) from root.test.d1 -select fft(s1, 'result'='real', 'compress'='0.99'), fft(s1, 'result'='imag','compress'='0.99') from root.test.d1 - -# HighPass -select highpass(s1,'wpass'='0.45') from root.test.d1 - -# IFFT -select ifft(re, im, 'interval'='1m', 'start'='2021-01-01 00:00:00') from root.test.d1 - -# LowPass -select lowpass(s1,'wpass'='0.45') from root.test.d1 - -# Envelope -select envelope(s1) from root.test.d1 -``` - -### 数据匹配 - -更多见文档[Data-Matching](../Reference/UDF-Libraries.md#数据匹配) - -```sql -# Cov -select cov(s1,s2) from root.test.d2 - -# DTW -select dtw(s1,s2) from root.test.d2 - -# Pearson -select pearson(s1,s2) from root.test.d2 - -# PtnSym -select ptnsym(s4, 'window'='5', 'threshold'='0') from root.test.d1 - -# XCorr -select xcorr(s1, s2) from root.test.d1 where time <= 2020-01-01 00:00:05 -``` - -### 数据修复 - -更多见文档[Data-Repairing](../Reference/UDF-Libraries.md#数据修复) - -```sql -# TimestampRepair -select timestamprepair(s1,'interval'='10000') from root.test.d2 -select timestamprepair(s1) from root.test.d2 - -# ValueFill -select valuefill(s1) from root.test.d2 -select valuefill(s1,"method"="previous") from root.test.d2 - -# ValueRepair -select valuerepair(s1) from root.test.d2 -select valuerepair(s1,'method'='LsGreedy') from root.test.d2 - -# MasterRepair -select MasterRepair(t1,t2,t3,m1,m2,m3) from root.test - -# SeasonalRepair -select seasonalrepair(s1,'period'=3,'k'=2) from root.test.d2 -select seasonalrepair(s1,'method'='improved','period'=3) from root.test.d2 -``` - -### 序列发现 - -更多见文档[Series-Discovery](../Reference/UDF-Libraries.md#序列发现) - -```sql -# ConsecutiveSequences -select consecutivesequences(s1,s2,'gap'='5m') from root.test.d1 -select consecutivesequences(s1,s2) from root.test.d1 - -# ConsecutiveWindows -select consecutivewindows(s1,s2,'length'='10m') from root.test.d1 -``` - -### 机器学习 - -更多见文档[Machine-Learning](../Reference/UDF-Libraries.md#机器学习) - -```sql -# AR -select ar(s0,"p"="2") from root.test.d0 - -# Representation -select representation(s0,"tb"="3","vb"="2") from root.test.d0 - -# RM -select rm(s0, s1,"tb"="3","vb"="2") from root.test.d0 -``` - -## Lambda 表达式 - -更多见文档[Lambda](../Reference/Function-and-Expression.md#Lambda表达式) - -```sql -select jexl(temperature, 'expr'='x -> {x + x}') as jexl1, jexl(temperature, 'expr'='x -> {x * 3}') as jexl2, jexl(temperature, 'expr'='x -> {x * x}') as jexl3, jexl(temperature, 'expr'='x -> {multiply(x, 100)}') as jexl4, jexl(temperature, st, 'expr'='(x, y) -> {x + y}') as jexl5, jexl(temperature, st, str, 'expr'='(x, y, z) -> {x + y + z}') as jexl6 from root.ln.wf01.wt01;``` -``` - -## 条件表达式 - -更多见文档[Conditional Expressions](../Reference/Function-and-Expression.md#条件表达式) - -```sql -select T, P, case -when 1000=1050 then "bad temperature" -when P<=1000000 or P>=1100000 then "bad pressure" -end as `result` -from root.test1 - -select str, case -when str like "%cc%" then "has cc" -when str like "%dd%" then "has dd" -else "no cc and dd" end as `result` -from root.test2 - -select -count(case when x<=1 then 1 end) as `(-∞,1]`, -count(case when 1 -[RESAMPLE - [EVERY ] - [BOUNDARY ] - [RANGE [, end_time_offset]] -] -[TIMEOUT POLICY BLOCKED|DISCARD] -BEGIN - SELECT CLAUSE - INTO CLAUSE - FROM CLAUSE - [WHERE CLAUSE] - [GROUP BY([, ]) [, level = ]] - [HAVING CLAUSE] - [FILL ({PREVIOUS | LINEAR | constant} (, interval=DURATION_LITERAL)?)] - [LIMIT rowLimit OFFSET rowOffset] - [ALIGN BY DEVICE] -END -``` - -#### 配置连续查询执行的周期性间隔 -```sql -CREATE CONTINUOUS QUERY cq1 - -RESAMPLE EVERY 20s - -BEGIN - - SELECT max_value(temperature) - - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - - FROM root.ln.*.* - - GROUP BY(10s) - -END - - - -\> SELECT temperature_max from root.ln.*.*; -``` -#### 配置连续查询的时间窗口大小 -``` -CREATE CONTINUOUS QUERY cq2 - -RESAMPLE RANGE 40s - -BEGIN - - SELECT max_value(temperature) - - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - - FROM root.ln.*.* - - GROUP BY(10s) - -END - - -\> SELECT temperature_max from root.ln.*.*; -``` -#### 同时配置连续查询执行的周期性间隔和时间窗口大小 -```sql -CREATE CONTINUOUS QUERY cq3 - -RESAMPLE EVERY 20s RANGE 40s - -BEGIN - - SELECT max_value(temperature) - - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - - FROM root.ln.*.* - - GROUP BY(10s) - - FILL(100.0) - -END - - - -\> SELECT temperature_max from root.ln.*.*; -``` -#### 配置连续查询每次查询执行时间窗口的结束时间 -```sql -CREATE CONTINUOUS QUERY cq4 - -RESAMPLE EVERY 20s RANGE 40s, 20s - -BEGIN - - SELECT max_value(temperature) - - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - - FROM root.ln.*.* - - GROUP BY(10s) - - FILL(100.0) - -END - - - -\> SELECT temperature_max from root.ln.*.*; -``` -#### 没有GROUP BY TIME子句的连续查询 -```sql -CREATE CONTINUOUS QUERY cq5 - -RESAMPLE EVERY 20s - -BEGIN - - SELECT temperature + 1 - - INTO root.precalculated_sg.::(temperature) - - FROM root.ln.*.* - - align by device - -END - - - -\> SELECT temperature from root.precalculated_sg.*.* align by device; -``` -### 连续查询的管理 - -#### 查询系统已有的连续查询 - -展示集群中所有的已注册的连续查询 -```sql -SHOW (CONTINUOUS QUERIES | CQS) -``` -```sql -SHOW CONTINUOUS QUERIES; -``` -#### 删除已有的连续查询 - -删除指定的名为cq_id的连续查询: - -```sql -DROP (CONTINUOUS QUERY | CQ) -``` -```sql -DROP CONTINUOUS QUERY s1_count_cq; -``` -#### 作为子查询的替代品 - -1. 创建一个连续查询 -```sql -CREATE CQ s1_count_cq - -BEGIN - -​ SELECT count(s1) - -​ INTO root.sg_count.d.count_s1 - -​ FROM root.sg.d - -​ GROUP BY(30m) - -END -``` -1. 查询连续查询的结果 -```sql -SELECT avg(count_s1) from root.sg_count.d; -``` -## 用户自定义函数 - -### UDFParameters -```sql -SELECT UDF(s1, s2, 'key1'='iotdb', 'key2'='123.45') FROM root.sg.d; -``` -### UDF 注册 - -```sql -CREATE FUNCTION AS (USING URI URI-STRING)? -``` - -#### 不指定URI -```sql -CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample' -``` -#### 指定URI -```sql -CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample' USING URI 'http://jar/example.jar' -``` -### UDF 卸载 - -```sql -DROP FUNCTION -``` -```sql -DROP FUNCTION example -``` -### UDF 查询 - -#### 带自定义输入参数的查询 -```sql -SELECT example(s1, 'key1'='value1', 'key2'='value2'), example(*, 'key3'='value3') FROM root.sg.d1; -``` -```sql -SELECT example(s1, s2, 'key1'='value1', 'key2'='value2') FROM root.sg.d1; -``` -#### 与其他查询的嵌套查询 -```sql -SELECT s1, s2, example(s1, s2) FROM root.sg.d1; - -SELECT *, example(*) FROM root.sg.d1 DISABLE ALIGN; - -SELECT s1 * example(* / s1 + s2) FROM root.sg.d1; - -SELECT s1, s2, s1 + example(s1, s2), s1 - example(s1 + example(s1, s2) / s2) FROM root.sg.d1; -``` -### 查看所有注册的 UDF -```sql -SHOW FUNCTIONS -``` -## 权限管理 - -### 用户与角色相关 - -- 创建用户(需 MANAGE_USER 权限) - - -```SQL -CREATE USER -eg: CREATE USER user1 'passwd' -``` - -- 删除用户 (需 MANEGE_USER 权限) - - -```SQL -DROP USER -eg: DROP USER user1 -``` - -- 创建角色 (需 MANAGE_ROLE 权限) - -```SQL -CREATE ROLE -eg: CREATE ROLE role1 -``` - -- 删除角色 (需 MANAGE_ROLE 权限) - - -```SQL -DROP ROLE -eg: DROP ROLE role1 -``` - -- 赋予用户角色 (需 MANAGE_ROLE 权限) - - -```SQL -GRANT ROLE TO -eg: GRANT ROLE admin TO user1 -``` - -- 移除用户角色 (需 MANAGE_ROLE 权限) - - -```SQL -REVOKE ROLE FROM -eg: REVOKE ROLE admin FROM user1 -``` - -- 列出所有用户 (需 MANEGE_USER 权限) - -```SQL -LIST USER -``` - -- 列出所有角色 (需 MANAGE_ROLE 权限) - -```SQL -LIST ROLE -``` - -- 列出指定角色下所有用户 (需 MANEGE_USER 权限) - -```SQL -LIST USER OF ROLE -eg: LIST USER OF ROLE roleuser -``` - -- 列出指定用户下所有角色 - -用户可以列出自己的角色,但列出其他用户的角色需要拥有 MANAGE_ROLE 权限。 - -```SQL -LIST ROLE OF USER -eg: LIST ROLE OF USER tempuser -``` - -- 列出用户所有权限 - -用户可以列出自己的权限信息,但列出其他用户的权限需要拥有 MANAGE_USER 权限。 - -```SQL -LIST PRIVILEGES OF USER ; -eg: LIST PRIVILEGES OF USER tempuser; - -``` - -- 列出角色所有权限 - -用户可以列出自己具有的角色的权限信息,列出其他角色的权限需要有 MANAGE_ROLE 权限。 - -```SQL -LIST PRIVILEGES OF ROLE ; -eg: LIST PRIVILEGES OF ROLE actor; -``` - -- 更新密码 - -用户可以更新自己的密码,但更新其他用户密码需要具备MANAGE_USER 权限。 - -```SQL -ALTER USER SET PASSWORD ; -eg: ALTER USER tempuser SET PASSWORD 'newpwd'; -``` - -### 授权与取消授权 - -用户使用授权语句对赋予其他用户权限,语法如下: - -```SQL -GRANT ON TO ROLE/USER [WITH GRANT OPTION]; -eg: GRANT READ ON root.** TO ROLE role1; -eg: GRANT READ_DATA, WRITE_DATA ON root.t1.** TO USER user1; -eg: GRANT READ_DATA, WRITE_DATA ON root.t1.**,root.t2.** TO USER user1; -eg: GRANT MANAGE_ROLE ON root.** TO USER user1 WITH GRANT OPTION; -eg: GRANT ALL ON root.** TO USER user1 WITH GRANT OPTION; -``` - -用户使用取消授权语句可以将其他的权限取消,语法如下: - -```SQL -REVOKE ON FROM ROLE/USER ; -eg: REVOKE READ ON root.** FROM ROLE role1; -eg: REVOKE READ_DATA, WRITE_DATA ON root.t1.** FROM USER user1; -eg: REVOKE READ_DATA, WRITE_DATA ON root.t1.**, root.t2.** FROM USER user1; -eg: REVOKE MANAGE_ROLE ON root.** FROM USER user1; -eg: REVOKE ALL ON ROOT.** FROM USER user1; -``` - diff --git a/src/zh/UserGuide/V1.3.0-2/Tools-System/Benchmark.md b/src/zh/UserGuide/V1.3.0-2/Tools-System/Benchmark.md deleted file mode 100644 index 24605a56c..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Tools-System/Benchmark.md +++ /dev/null @@ -1,352 +0,0 @@ - - -# 测试工具 - -## 概述 - -IoT-benchmark 是基于 Java 和大数据环境开发的时序数据库基准测试工具,由清华大学软件学院研发并开源。它使用方便,支持多种写入以及查询方式,支持存储测试信息和结果以供进一步查询或分析,支持与 Tableau 集成以可视化测试结果。 - -下图1-1囊括了测试基准流程及其他扩展功能。这些流程可以由IoT-benchmark 统一来完成。IoT Benchmark 支持多种工作负载,包括**纯写入、纯查询、写入查询混合**等,支持**软硬件系统监控、测试指标度量**等监控功能,还实现了**初始化数据库自动化、测试数据分析及系统参数优化**等功能。 - -![](/img/bm1.png) - -图1-1 - -借鉴 YCSB 测试工具将工作负载生成、性能指标测量和数据库接口三个组件分离的设计思想,IoT-benchmark 的模块化设计如图1-2所示。与基于 YCSB 的测试工具系统不同的是,IoT-benchmark 增加了系统监控模块,支持测试数据和系统指标监控数据的持久化。此外也增加了一些特别针对时序数据场景的特殊负载测试功能,如支持物联网场景的批量写入和多种乱序数据写入模式。 - -![](/img/bm2.png) - -图1-2 - - - -目前 IoT-benchmark 支持如下时间序列数据库、版本和连接方式: - -| 数据库 | 版本 | 连接方式 | -| --------------- | ------- | -------------------------------------------------------- | -| InfluxDB | v1.x
v2.0 | SDK | | -| TimescaleDB | -- | jdbc | -| OpenTSDB | -- | Http Request | -| QuestDB | v6.0.7 | jdbc | -| TDengine | v2.2.0.2 | jdbc | -| VictoriaMetrics | v1.64.0 | Http Request | -| KairosDB | -- | Http Request | -| IoTDB | v1.x
v0.13 | jdbc、sessionByTablet、sessionByRecord、sessionByRecords | - -表1-1大数据测试基准对比 - -### 软件安装与环境搭建 - -#### IoT Benchmark 运行的前置条件 - -1. Java 8 -2. Maven 3.6+ -3. 对应的合适版本的数据库,如 Apache IoTDB 1.0 - - - -#### IoT Benchmark 的获取方式 - -- **获取二进制包**:进入https://github.com/thulab/iot-benchmark/releases 下载需要的安装包。下载下来为一个压缩文件,选择文件夹解压即可使用。 -- 源代码编译(可用户 Apache IoTDB 1.0 的测试): - - 第一步(编译 IoTDB Session 最新包):进入官网 https://github.com/apache/iotdb/tree/rel/1.0 下载 IoTDB 源码,在根目录下运行命令 mvn clean package install -pl session -am -DskipTests 编译 IoTDB Session 的最新包。 - - 第二步(编译 IoTDB Benchmark 测试包):进入官网 https://github.com/thulab/iot-benchmark 下载源码,在根目录下运行 mvn clean package install -pl iotdb-1.0 -am -DskipTests 编译测试 Apache IoTDB 1.0版本的测试包,测试包位置与根目录的相对路径为 ./iotdb-1.0/target/iotdb-1.0-0.0.1/iotdb-1.0-0.0.1 - - - -#### IoT Benchmark 的测试包结构 - -测试包的目录结构如下图1-3所示。其中测试配置文件为conf/config.properties,测试启动脚本为benchmark\.sh (Linux & MacOS) 和 benchmark.bat (Windows),详细文件用途见表1-2所示。 - -![](/img/bm3.png) - -图1-3文件和文件夹列表 - -| 名称 | 子文件 | 用途 | -| ---------------- | ----------------- | ------------------------- | -| benchmark.bat | - | Windows环境运行启动脚本 | -| benchmark\.sh | - | Linux/Mac环境运行启动脚本 | -| conf | config.properties | 测试场景配置文件 | -| logback.xml | 日志输出配置文件 | | -| lib | - | 依赖库文件 | -| LICENSE | - | 许可文件 | -| bin | startup\.sh | 初始化脚本文件夹 | -| ser-benchmark\.sh | - | 监控模式启动脚本 | - -表1-2文件和文件夹列表用途 - -#### IoT Benchmark 执行测试 - -1. 按照测试需求修改配置文件,主要参数介绍见 1.2 节,对应配置文件为conf/config.properties,**比如测试Apache** **IoTDB 1.0,则需要修改 DB_SWITCH=IoTDB-100-SESSION_BY_TABLET** -2. 启动被测时间序列数据库 -3. 通过运行 -4. 启动IoT-benchmark执行测试。执行中观测被测时间序列数据库和IoT-benchmark状态,执行完毕后查看结果和分析测试过程。 - -#### IoT Benchmark 结果说明 - -测试的所有日志文件被存放于 logs 文件夹下,测试的结果在测试完成后被存放到 data/csvOutput 文件夹下,例如测试后我们得到了如下的结果矩阵: - -![](/img/bm4.png) - -- Result Matrix - - OkOperation:成功的对应操作次数 - - OkPoint:对于写入操作,是成功写入的点数;对于查询操作,是成功查询到的点数。 - - FailOperation:失败的对应操作次数 - - FailPoint:对于写入操作是写入失败的点数 -- Latency(mx) Matrix - - AVG:操作平均耗时 - - MIN:操作最小耗时 - - Pn:操作整体分布的对应分位值,比如P25是下四分位数 - - - -### 主要参数介绍 - -本节重点解释说明了主要参数的用途和配置方法。 - -#### 工作模式和操作比例 - -- 工作模式参数“BENCHMARK_WORK_MODE”可选项为“默认模式”和“服务器监控”;其中“服务器监控”模式可直接通过执行ser-benchmark.sh脚本启动,脚本会自动修改该参数。“默认模式”为常用测试模式,结合配置OPERATION_PROPORTION参数达到“纯写入”、“纯查询”和“读写混合”的测试操作比例定义 - -- 当运行ServerMode来执行被测时序数据库运行环境监控时IoT-benchmark依赖sysstat软件相关命令;如果需要持久化测试过程数据时选择MySQL或IoTDB,则需要安装该类数据库;ServerMode和CSV的记录模式只能在Linux系统中使用,记录测试过程中的相关系统信息。因此我们建议使用MacOs或Linux系统,本文以Linux(Centos7)系统为例,如果使用Windows系统,可以使用conf文件夹下的benchmark.bat脚本启动IoT-benchmark。 - - 表1-3测试模式 - -| 模式名称 | BENCHMARK_WORK_MODE | 模式内容 | -| ---------------------- | ------------------- | ------------------------------------------------------------ | -| 常规测试模式 | testWithDefaultPath | 支持多种读和写操作的混合负载 | -| 服务器资源使用监控模式 | serverMODE | 服务器资源使用监控模式(该模式下运行通过ser-benchmark.sh脚本启动,无需手动配置该参数 | - -#### 服务器连接信息 - -工作模式指定后,被测时序数据库的信息要如何告知IoT-benchmark呢?当前通过“DB_SWITCH”告知被测时序数据库类型;通过“HOST”告知被测时序数据库网络地址;通过“PORT”告知被测时序数据库网络端口;通过“USERNAME”告知被测时序数据库登录用户名;通过“PASSWORD”告知被测时序数据库登录用户的密码;通过“DB_NAME”告知被测时序数据库名称;通过“TOKEN”告知被测时序数据库连接认证Token(InfluxDB 2.0使用); - -#### 写入场景构建参数 - -表1-4写入场景构建参数 - -| 参数名称 | 类型 | 示例 | 系统描述 | -| -------------------------- | ------ | ------------------------- | ------------------------------------------------------------ | -| CLIENT_NUMBER | 整数 | 100 | 客户端总数 | -| GROUP_NUMBER | 整数 | 20 | 数据库的数量;仅针对IoTDB。 | -| DEVICE_NUMBER | 整数 | 100 | 设备总数 | -| SENSOR_NUMBER | 整数 | 300 | 每个设备的传感器总数 | -| INSERT_DATATYPE_PROPORTION | 字符串 | 1:1:1:1:1:1 | 设备的数据类型比例,BOOLEAN:INT32:INT64:FLOAT:DOUBLE:TEXT | -| POINT_STEP | 整数 | 1000 | 数据间时间戳间隔,即生成的数据两个时间戳之间的固定长度。 | -| OP_MIN_INTERVAL | 整数 | 0 | 操作最小执行间隔:若操作耗时大于该值则立即执行下一个,否则等待 (OP_MIN_INTERVAL-实际执行时间) ms;如果为0,则参数不生效;如果为-1,则其值和POINT_STEP一致 | -| IS_OUT_OF_ORDER | 布尔 | false | 是否乱序写入 | -| OUT_OF_ORDER_RATIO | 浮点数 | 0.3 | 乱序写入的数据比例 | -| BATCH_SIZE_PER_WRITE | 整数 | 1 | 批写入数据行数(一次写入多少行数据) | -| START_TIME | 时间 | 2022-10-30T00:00:00+08:00 | 写入数据的开始时间戳;以该时间戳为起点开始模拟创建数据时间戳。 | -| LOOP | 整数 | 86400 | 总操作次数:具体每种类型操作会按OPERATION_PROPORTION定义的比例划分 | -| OPERATION_PROPORTION | 字符 | 1:0:0:0:0:0:0:0:0:0:0 | # 各操作的比例,按照顺序为 写入:Q1:Q2:Q3:Q4:Q5:Q6:Q7:Q8:Q9:Q10, 请注意使用英文冒号。比例中的每一项是整数。 | - -按照表1-4配置参数启动可描述测试场景为:向被测时序数据库压力写入30000个(100个设备,每个设备300个传感器)时间序列2022年10月30日一天的顺序数据,总计25.92亿个数据点。其中每个设备的300个传感器数据类型分别为50个布尔、50个整数、50个长整数、50个浮点、50个双精度、50个字符。如果我们将表格中IS_OUT_OF_ORDER的值改为true,那么他表示的场景为:向被测时序数据库压力写入30000个时间序列2022年10月30日一天的数据,其中存在30%的乱序数据(到达时序数据库时间晚于其他生成时间晚于自身的数据点)。 - -#### 查询场景构建参数 - -表1-5查询场景构建参数 - -| 参数名称 | 类型 | 示例 | 系统描述 | -| -------------------- | ---- | --------------------- | ------------------------------------------------------------ | -| QUERY_DEVICE_NUM | 整数 | 2 | 每条查询语句中查询涉及到的设备数量 | -| QUERY_SENSOR_NUM | 整数 | 2 | 每条查询语句中查询涉及到的传感器数量 | -| QUERY_AGGREGATE_FUN | 字符 | count | 在聚集查询中使用的聚集函数,比如count、avg、sum、max_time等 | -| STEP_SIZE | 整数 | 1 | 时间过滤条件的时间起点变化步长,若设为0则每个查询的时间过滤条件是一样的,单位:POINT_STEP | -| QUERY_INTERVAL | 整数 | 250000 | 起止时间的查询中开始时间与结束时间之间的时间间隔,和Group By中的时间间隔 | -| QUERY_LOWER_VALUE | 整数 | -5 | 条件查询子句时的参数,where xxx > QUERY_LOWER_VALUE | -| GROUP_BY_TIME_UNIT | 整数 | 20000 | Group by语句中的组的大小 | -| LOOP | 整数 | 10 | 总操作次数:具体每种类型操作会按OPERATION_PROPORTION定义的比例划分 | -| OPERATION_PROPORTION | 字符 | 0:0:0:0:0:0:0:0:0:0:1 | 写入:Q1:Q2:Q3:Q4:Q5:Q6:Q7:Q8:Q9:Q10 | - -表1-6查询类型及示例 SQL - -| 编号 | 查询类型 | IoTDB 示例 SQL | -| ---- | ---------------------------- | ------------------------------------------------------------ | -| Q1 | 精确点查询 | select v1 from root.db.d1 where time = ? | -| Q2 | 时间范围查询 | select v1 from root.db.d1 where time > ? and time < ? | -| Q3 | 带值过滤的时间范围查询 | select v1 from root.db.d1 where time > ? and time < ? and v1 > ? | -| Q4 | 时间范围聚合查询 | select count(v1) from root.db.d1 where and time > ? and time < ? | -| Q5 | 带值过滤的全时间范围聚合查询 | select count(v1) from root.db.d1 where v1 > ? | -| Q6 | 带值过滤的时间范围聚合查询 | select count(v1) from root.db.d1 where v1 > ? and time > ? and time < ? | -| Q7 | 时间分组聚合查询 | select count(v1) from root.db.d1 group by ([?, ?), ?, ?) | -| Q8 | 最新点查询 | select last v1 from root.db.d1 | -| Q9 | 倒序范围查询 | select v1 from root.sg.d1 where time > ? and time < ? order by time desc | -| Q10 | 倒序带值过滤的范围查询 | select v1 from root.sg.d1 where time > ? and time < ? and v1 > ? order by time desc | - - - - - -按照表1-5配置参数启动可描述测试场景为:从被测时序数据库执行10次2个设备2个传感器的倒序带值过滤的范围查询,SQL语句为:select s_0,s_31from data where time >2022-10-30T00:00:00+08:00 and time < 2022-10-30T00:04:10+08:00 and s_0 > -5 and device in d_21,d_46 order by time desc。 - -#### 测试过程和测试结果持久化 - -IoT-benchmark目前支持通过配置参数“TEST_DATA_PERSISTENCE”将测试过程和测试结果持久化到IoTDB、MySQL和CSV;其中写入到MySQL和CSV可以定义分库分表的行数上限,例如“RECORD_SPLIT=true、RECORD_SPLIT_MAX_LINE=10000000”表示每个数据库表或CSV文件按照总行数为1千万切分存放;如果记录到MySQL或IoTDB需要提供数据库链接信息,分别包括“TEST_DATA_STORE_IP”数据库的IP地址、“TEST_DATA_STORE_PORT”数据库的端口号、“TEST_DATA_STORE_DB”数据库的名称、“TEST_DATA_STORE_USER”数据库用户名、“TEST_DATA_STORE_PW”数据库用户密码。 - -如果我们设置“TEST_DATA_PERSISTENCE=CSV”,测试执行时和执行完毕后我们可以在IoT-benchmark根目录下看到新生成的data文件夹,其下包含csv文件夹记录测试过程;csvOutput文件夹记录测试结果。如果我们设置“TEST_DATA_PERSISTENCE=MySQL”,它会在测试开始前在指定的MySQL数据库中创建命名如“testWithDefaultPath_被测数据库名称_备注_测试启动时间”的数据表记录测试过程;会在名为“CONFIG”的数据表(如果不存在则创建该表),写入本次测试的配置信息;当测试完成时会在名为“FINAL_RESULT”的数据表(如果不存在则创建该表)中写入本次测试结果。 - -## 实际案例 - -我们以中车青岛四方车辆研究所有限公司应用为例,参考《ApacheIoTDB在智能运维平台存储中的应用》中描述的场景进行实际操作说明。 - -测试目标:模拟中车青岛四方所场景因切换时间序列数据库实际需求,对比预期使用的IoTDB和原有系统使用的KairosDB性能。 - -测试环境:为了保证在实验过程中消除其他无关服务与进程对数据库性能的影响,以及不同数据库之间的相互影响,本实验中的本地数据库均部署并运行在资源配置相同的多个独立的虚拟机上。因此,本实验搭建了 4 台 Linux( CentOS7 /x86) 虚拟机,并分别在上面部署了IoT-benchmark、 IoTDB数据库、KairosDB数据库、MySQL数据库。每一台虚拟机的具体资源配置如表2-1所示。每一台虚拟机的具体用途如表2-2所示。 - -表2-1虚拟机配置信息 - -| 硬件配置信息 | 系统描述 | -| ------------ | -------- | -| OS System | CentOS7 | -| CPU核数 | 16 | -| 内存 | 32G | -| 硬盘 | 200G | -| 网卡 | 千兆 | - - - -表2-2虚拟机用途 - -| IP | 用途 | -| ---------- | ------------- | -| 172.21.4.2 | IoT-benchmark | -| 172.21.4.3 | Apache-iotdb | -| 172.21.4.4 | KaiosDB | -| 172.21.4.5 | MySQL | - -### 写入测试 - -场景描述:创建100个客户端来模拟100列车、每列车3000个传感器、数据类型为DOUBLE类型、数据时间间隔为500ms(2Hz)、顺序发送。参考以上需求我们需要修改IoT-benchmark配置参数如表2-3中所列。 - -表2-3配置参数信息 - -| 参数名称 | IoTDB值 | KairosDB值 | -| -------------------------- | --------------------------- | ---------- | -| DB_SWITCH | IoTDB-013-SESSION_BY_TABLET | KairosDB | -| HOST | 172.21.4.3 | 172.21.4.4 | -| PORT | 6667 | 8080 | -| BENCHMARK_WORK_MODE | testWithDefaultPath | | -| OPERATION_PROPORTION | 1:0:0:0:0:0:0:0:0:0:0 | | -| CLIENT_NUMBER | 100 | | -| GROUP_NUMBER | 10 | | -| DEVICE_NUMBER | 100 | | -| SENSOR_NUMBER | 3000 | | -| INSERT_DATATYPE_PROPORTION | 0:0:0:0:1:0 | | -| POINT_STEP | 500 | | -| OP_MIN_INTERVAL | 0 | | -| IS_OUT_OF_ORDER | false | | -| BATCH_SIZE_PER_WRITE | 1 | | -| LOOP | 10000 | | -| TEST_DATA_PERSISTENCE | MySQL | | -| TEST_DATA_STORE_IP | 172.21.4.5 | | -| TEST_DATA_STORE_PORT | 3306 | | -| TEST_DATA_STORE_DB | demo | | -| TEST_DATA_STORE_USER | root | | -| TEST_DATA_STORE_PW | admin | | -| REMARK | demo | | - -首先在172.21.4.3和172.21.4.4上分别启动被测时间序列数据库Apache-IoTDB和KairosDB,之后在172.21.4.2、172.21.4.3和172.21.4.4上通过ser-benchamrk.sh脚本启动服务器资源监控(图2-1)。然后按照表2-3在172.21.4.2分别修改iotdb-0.13-0.0.1和kairosdb-0.0.1文件夹内的conf/config.properties文件满足测试需求。先后使用benchmark.sh启动对Apache-IoTDB和KairosDB的写入测试。 - -![](/img/bm5.png) - -图2-1服务器监控任务 - -​ 例如我们首先启动对KairosDB的测试,IoT-benchmark会在MySQL数据库中创建CONFIG数据表存放本次测试配置信息(图2-2),测试执行中会有日志输出当前测试进度(图2-3)。测试完成时会输出本次测试结果(图2-3),同时将结果写入FINAL_RESULT数据表中(图2-4)。 - -![](/img/bm6.png) - -图2-2测试配置信息表 - -![](/img/bm7.png) -![](/img/bm8.png) -![](/img/bm9.png) -![](/img/bm10.png) - -图2-3测试进度和结果 - -![](/img/bm11.png) - -图2-4测试结果表 - -之后我们再启动对Apache-IoTDB的测试,同样的IoT-benchmark会在MySQL数据库CONFIG数据表中写入本次测试配置信息,测试执行中会有日志输出当前测试进度。测试完成时会输出本次测试结果,同时将结果写入FINAL_RESULT数据表中。 - -依照测试结果信息我们知道同样的配置写入Apache-IoTDB和KairosDB写入延时时间分别为:55.98ms和1324.45ms;写入吞吐分别为:5,125,600.86点/秒和224,819.01点/秒;测试分别执行了585.30秒和11777.99秒。并且KairosDB有写入失败出现,排查后发现是数据磁盘使用率已达到100%,无磁盘空间继续接收数据。而Apache-IoTDB无写入失败现象,全部数据写入完毕后占用磁盘空间仅为4.7G(如图2-5所示);从写入吞吐和磁盘占用情况上看Apache-IoTDB均优于KairosDB。当然后续还有其他测试来从多方面观察和对比,比如查询性能、文件压缩比、数据安全性等。 - -![](/img/bm12.png) - -图2-5磁盘使用情况 - -那么测试过程中各个服务器资源使用情况如何呢?每个写操作具体的表现如何呢?这个时候我们就可以通过安装和使用Tableau来可视化服务器监控表和测试过程记录表内的数据了。Tableau的使用本文不展开介绍,通过它连接测试数据持久化的数据表后具体结果下如图(以Apache-IoTDB为例): - -![](/img/bm13.png) -![](/img/bm14.png) - -图2-6Tableau可视化测试过程 - - - -### 查询测试 - -场景描述:在写入测试场景下模拟10个客户端对时序数据库Apache-IoTDB内存放的数据进行全类型查询任务。配置如下: - -表2-4配置参数信息 - -| 参数名称 | 示例 | -| -------------------- | --------------------- | -| CLIENT_NUMBER | 10 | -| QUERY_DEVICE_NUM | 2 | -| QUERY_SENSOR_NUM | 2 | -| QUERY_AGGREGATE_FUN | count | -| STEP_SIZE | 1 | -| QUERY_INTERVAL | 250000 | -| QUERY_LOWER_VALUE | -5 | -| GROUP_BY_TIME_UNIT | 20000 | -| LOOP | 30 | -| OPERATION_PROPORTION | 0:1:1:1:1:1:1:1:1:1:1 | - -执行结果: - -![](/img/bm15.png) - -图2-7查询测试结果 - -### 其他参数说明 - -之前章节中针对Apache-IoTDB和KairosDB进行写入性能对比,但是用户如果要执行模拟真实写入速率测试该如何配置?测试时间过长该如何控制呢?生成的模拟数据有哪些规律吗?如果IoT-Benchmark服务器配置较低,可以使用多台机器模拟压力输出吗? - -表2-5配置参数信息 - -| 场景 | 参数 | 值 | 说明 | -| ------------------------------------------------------------ | -------------------------- | ------------------------------------------------------------ | --------------------------------- | -| 模拟真实写入速率 | OP_INTERVAL | -1 | 也可输入整数控制操作间隔 | -| 指定测试时长(1小时) | TEST_MAX_TIME | 3600000 | 单位 ms;需要LOOP执行时间大于该值 | -| 定义模拟数据规律:支持全部数据类型,数量平均分类;支持五种数据分布,数量平均分布;字符串长度为10;小数位数为2 | INSERT_DATATYPE_PROPORTION | 1:1:1:1:1:1 | 数据类型分布比率 | -| LINE_RATIO | 1 | 线性 | | -| SIN_RATIO | 1 | 傅里叶函数 | | -| SQUARE_RATIO | 1 | 方波 | | -| RANDOM_RATIO | 1 | 随机数 | | -| CONSTANT_RATIO | 1 | 常数 | | -| STRING_LENGTH | 10 | 字符串长度 | | -| DOUBLE_LENGTH | 2 | 小数位数 | | -| 三台机器模拟300台设备数据写入 | BENCHMARK_CLUSTER | true | 开启多benchmark模式 | -| BENCHMARK_INDEX | 0、1、3 | 以[写入测试](./Benchmark.md#写入测试)写入参数为例:0号负责设备编号0-99数据写入;1号负责设备编号100-199数据写入;2号负责设备编号200-299数据写入; | | \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/Tools-System/CLI.md b/src/zh/UserGuide/V1.3.0-2/Tools-System/CLI.md deleted file mode 100644 index 4e7b60744..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Tools-System/CLI.md +++ /dev/null @@ -1,276 +0,0 @@ - - -# SQL 命令行终端 (CLI) - -IOTDB 为用户提供 cli/Shell 工具用于启动客户端和服务端程序。下面介绍每个 cli/Shell 工具的运行方式和相关参数。 -> \$IOTDB\_HOME 表示 IoTDB 的安装目录所在路径。 - -## 安装 -如果使用源码版,可以在 iotdb 的根目录下执行 - -```shell -> mvn clean package -pl cli -am -DskipTests -``` - -在生成完毕之后,IoTDB 的 Cli 工具位于文件夹"cli/target/iotdb-cli-{project.version}"中。 - -如果你下载的是二进制版,那么 Cli 可以在 sbin 文件夹下直接找到。 - -## 运行 - -### Cli 运行方式 -安装后的 IoTDB 中有一个默认用户:`root`,默认密码为`root`。用户可以使用该用户尝试运行 IoTDB 客户端以测试服务器是否正常启动。客户端启动脚本为$IOTDB_HOME/sbin 文件夹下的`start-cli`脚本。启动脚本时需要指定运行 IP 和 RPC PORT。以下为服务器在本机启动,且用户未更改运行端口号的示例,默认端口为 6667。若用户尝试连接远程服务器或更改了服务器运行的端口号,请在-h 和-p 项处使用服务器的 IP 和 RPC PORT。
-用户也可以在启动脚本的最前方设置自己的环境变量,如 JAVA_HOME 等 (对于 linux 用户,脚本路径为:"/sbin/start-cli.sh"; 对于 windows 用户,脚本路径为:"/sbin/start-cli.bat") - -Linux 系统与 MacOS 系统启动命令如下: - -```shell -Shell > bash sbin/start-cli.sh -h 127.0.0.1 -p 6667 -u root -pw root -``` -Windows 系统启动命令如下: - -```shell -Shell > sbin\start-cli.bat -h 127.0.0.1 -p 6667 -u root -pw root -``` -回车后即可成功启动客户端。启动后出现如图提示即为启动成功。 - -``` - _____ _________ ______ ______ -|_ _| | _ _ ||_ _ `.|_ _ \ - | | .--.|_/ | | \_| | | `. \ | |_) | - | | / .'`\ \ | | | | | | | __'. - _| |_| \__. | _| |_ _| |_.' /_| |__) | -|_____|'.__.' |_____| |______.'|_______/ version - -Successfully login at 127.0.0.1:6667 -``` -输入`quit`或`exit`可退出 cli 结束本次会话,cli 输出`quit normally`表示退出成功。 - -### Cli 运行参数 - -|参数名|参数类型|是否为必需参数| 说明| 例子 | -|:---|:---|:---|:---|:---| -|-disableISO8601 |没有参数 | 否 |如果设置了这个参数,IoTDB 将以数字的形式打印时间戳 (timestamp)。|-disableISO8601| -|-h <`host`> |string 类型,不需要引号|是|IoTDB 客户端连接 IoTDB 服务器的 IP 地址。|-h 10.129.187.21| -|-help|没有参数|否|打印 IoTDB 的帮助信息|-help| -|-p <`rpcPort`>|int 类型|是|IoTDB 连接服务器的端口号,IoTDB 默认运行在 6667 端口。|-p 6667| -|-pw <`password`>|string 类型,不需要引号|否|IoTDB 连接服务器所使用的密码。如果没有输入密码 IoTDB 会在 Cli 端提示输入密码。|-pw root| -|-u <`username`>|string 类型,不需要引号|是|IoTDB 连接服务器锁使用的用户名。|-u root| -|-maxPRC <`maxPrintRowCount`>|int 类型|否|设置 IoTDB 返回客户端命令行中所显示的最大行数。|-maxPRC 10| -|-e <`execute`> |string 类型|否|在不进入客户端输入模式的情况下,批量操作 IoTDB|-e "show databases"| -|-c | 空 | 否 | 如果服务器设置了 `rpc_thrift_compression_enable=true`, 则 CLI 必须使用 `-c` | -c | - -下面展示一条客户端命令,功能是连接 IP 为 10.129.187.21 的主机,端口为 6667 ,用户名为 root,密码为 root,以数字的形式打印时间戳,IoTDB 命令行显示的最大行数为 10。 - -Linux 系统与 MacOS 系统启动命令如下: - -```shell -Shell > bash sbin/start-cli.sh -h 10.129.187.21 -p 6667 -u root -pw root -disableISO8601 -maxPRC 10 -``` -Windows 系统启动命令如下: - -```shell -Shell > sbin\start-cli.bat -h 10.129.187.21 -p 6667 -u root -pw root -disableISO8601 -maxPRC 10 -``` - -### CLI 特殊命令 -下面列举了一些CLI的特殊命令。 - -| 命令 | 描述 / 例子 | -|:---|:---| -| `set time_display_type=xxx` | 例如: long, default, ISO8601, yyyy-MM-dd HH:mm:ss | -| `show time_display_type` | 显示时间显示方式 | -| `set time_zone=xxx` | 例如: +08:00, Asia/Shanghai | -| `show time_zone` | 显示CLI的时区 | -| `set fetch_size=xxx` | 设置从服务器查询数据时的读取条数 | -| `show fetch_size` | 显示读取条数的大小 | -| `set max_display_num=xxx` | 设置 CLI 一次展示的最大数据条数, 设置为-1表示无限制 | -| `help` | 获取CLI特殊命令的提示 | -| `exit/quit` | 退出CLI | - -### 使用 OpenID 作为用户名认证登录 - -OpenID Connect (OIDC) 使用 keycloack 作为 OIDC 服务权限认证服务。 - -#### 配置 -配置位于 iotdb-common.properties,设定 authorizer_provider_class 为 org.apache.iotdb.commons.auth.authorizer.OpenIdAuthorizer 则开启了 openID 服务,默认情况下值为 org.apache.iotdb.commons.auth.authorizer.LocalFileAuthorizer 表示没有开启 openID 服务。 - -``` -authorizer_provider_class=org.apache.iotdb.commons.auth.authorizer.OpenIdAuthorizer -``` -如果开启了 openID 服务则 openID_url 为必填项,openID_url 值为 http://ip:port/realms/{realmsName} - -``` -openID_url=http://127.0.0.1:8080/realms/iotdb/ -``` -####keycloack 配置 - -1、下载 keycloack 程序(此教程为21.1.0版本),在 keycloack/bin 中启动 keycloack - -```shell -Shell > cd bin -Shell > ./kc.sh start-dev -``` -2、使用 https://ip:port 登陆 keycloack, 首次登陆需要创建用户 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/login_keycloak.png?raw=true) - -3、点击 Administration Console 进入管理端 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/AdministrationConsole.png?raw=true) - -4、在左侧的 Master 菜单点击 Create Realm, 输入 Realm Name 创建一个新的 Realm - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/add_Realm_1.jpg?raw=true) - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/add_Realm_2.jpg?raw=true) - -5、点击左侧菜单 Clients,创建 client - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/client.jpg?raw=true) - -6、点击左侧菜单 User,创建 user - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/user.jpg?raw=true) - -7、点击新创建的用户 id,点击 Credentials 导航输入密码和关闭 Temporary 选项,至此 keyclork 配置完成 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/pwd.jpg?raw=true) - -8、创建角色,点击左侧菜单的 Roles然后点击Create Role 按钮添加角色 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/add_role1.jpg?raw=true) - -9、在Role Name 中输入`iotdb_admin`,点击save 按钮。提示:这里的`iotdb_admin`不能为其他名称否则即使登陆成功后也将无权限使用iotdb的查询、插入、创建 database、添加用户、角色等功能 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/add_role2.jpg?raw=true) - -10、点击左侧的User 菜单然后点击用户列表中的用户为该用户添加我们刚创建的`iotdb_admin`角色 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/add_role3.jpg?raw=true) - -11、选择Role Mappings ,在Assign role选择`iotdb_admin`增加角色 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/add_role4.jpg?raw=true) - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/add_role5.jpg?raw=true) - -提示:如果用户角色有调整需要重新生成token并且重新登陆iotdb才会生效 - -以上步骤提供了一种 keycloak 登陆 iotdb 方式,更多方式请参考 keycloak 配置 - -若对应的 IoTDB 服务器开启了使用 OpenID Connect (OIDC) 作为权限认证服务,那么就不再需要使用用户名密码进行登录。 -替而代之的是使用 Token,以及空密码。 -此时,登录命令如下: - -```shell -Shell > bash sbin/start-cli.sh -h 10.129.187.21 -p 6667 -u {my-access-token} -pw "" -``` - -其中,需要将{my-access-token} (注意,包括{})替换成你的 token,即 access_token 对应的值。密码为空需要再次确认。 - -![avatar](/img/UserGuide/CLI/Command-Line-Interface/iotdbpw.jpeg?raw=true) - -如何获取 token 取决于你的 OIDC 设置。 最简单的一种情况是使用`password-grant`。例如,假设你在用 keycloack 作为你的 OIDC 服务, -并且你在 keycloack 中有一个被定义成 public 的`iotdb`客户的 realm,那么你可以使用如下`curl`命令获得 token。 -(注意例子中的{}和里面的内容需要替换成具体的服务器地址和 realm 名字): -```shell -curl -X POST "http://{your-keycloack-server}/realms/{your-realm}/protocol/openid-connect/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ - -d "username={username}" \ - -d "password={password}" \ - -d 'grant_type=password' \ - -d "client_id=iotdb-client" -``` - -示例结果如下: - -```json -{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJxMS1XbTBvelE1TzBtUUg4LVNKYXAyWmNONE1tdWNXd25RV0tZeFpKNG93In0.eyJleHAiOjE1OTAzOTgwNzEsImlhdCI6MTU5MDM5Nzc3MSwianRpIjoiNjA0ZmYxMDctN2NiNy00NTRmLWIwYmQtY2M2ZDQwMjFiNGU4IiwiaXNzIjoiaHR0cDovL2F1dGguZGVtby5wcmFnbWF0aWNpbmR1c3RyaWVzLmRlL2F1dGgvcmVhbG1zL0lvVERCIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6ImJhMzJlNDcxLWM3NzItNGIzMy04ZGE2LTZmZThhY2RhMDA3MyIsInR5cCI6IkJlYXJlciIsImF6cCI6ImlvdGRiIiwic2Vzc2lvbl9zdGF0ZSI6IjA2MGQyODYyLTE0ZWQtNDJmZS1iYWY3LThkMWY3ODQ2NTdmMSIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsibG9jYWxob3N0OjgwODAiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iLCJpb3RkYl9hZG1pbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ1c2VyIn0.nwbrJkWdCNjzFrTDwKNuV5h9dDMg5ytRKGOXmFIajpfsbOutJytjWTCB2WpA8E1YI3KM6gU6Jx7cd7u0oPo5syHhfCz119n_wBiDnyTZkFOAPsx0M2z20kvBLN9k36_VfuCMFUeddJjO31MeLTmxB0UKg2VkxdczmzMH3pnalhxqpnWWk3GnrRrhAf2sZog0foH4Ae3Ks0lYtYzaWK_Yo7E4Px42-gJpohy3JevOC44aJ4auzJR1RBj9LUbgcRinkBy0JLi6XXiYznSC2V485CSBHW3sseXn7pSXQADhnmGQrLfFGO5ZljmPO18eFJaimdjvgSChsrlSEmTDDsoo5Q","expires_in":300,"refresh_expires_in":1800,"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhMzZlMGU0NC02MWNmLTQ5NmMtOGRlZi03NTkwNjQ5MzQzMjEifQ.eyJleHAiOjE1OTAzOTk1NzEsImlhdCI6MTU5MDM5Nzc3MSwianRpIjoiNmMxNTBiY2EtYmE5NC00NTgxLWEwODEtYjI2YzhhMmI5YmZmIiwiaXNzIjoiaHR0cDovL2F1dGguZGVtby5wcmFnbWF0aWNpbmR1c3RyaWVzLmRlL2F1dGgvcmVhbG1zL0lvVERCIiwiYXVkIjoiaHR0cDovL2F1dGguZGVtby5wcmFnbWF0aWNpbmR1c3RyaWVzLmRlL2F1dGgvcmVhbG1zL0lvVERCIiwic3ViIjoiYmEzMmU0NzEtYzc3Mi00YjMzLThkYTYtNmZlOGFjZGEwMDczIiwidHlwIjoiUmVmcmVzaCIsImF6cCI6ImlvdGRiIiwic2Vzc2lvbl9zdGF0ZSI6IjA2MGQyODYyLTE0ZWQtNDJmZS1iYWY3LThkMWY3ODQ2NTdmMSIsInNjb3BlIjoiZW1haWwgcHJvZmlsZSJ9.ayNpXdNX28qahodX1zowrMGiUCw2AodlHBQFqr8Ui7c","token_type":"bearer","not-before-policy":0,"session_state":"060d2862-14ed-42fe-baf7-8d1f784657f1","scope":"email profile"} -``` - -### Cli 的批量操作 -当您想要通过脚本的方式通过 Cli / Shell 对 IoTDB 进行批量操作时,可以使用-e 参数。通过使用该参数,您可以在不进入客户端输入模式的情况下操作 IoTDB。 - -为了避免 SQL 语句和其他参数混淆,现在只支持-e 参数作为最后的参数使用。 - -针对 cli/Shell 工具的-e 参数用法如下: - -Linux 系统与 MacOS 指令: - -```shell -Shell > bash sbin/start-cli.sh -h {host} -p {rpcPort} -u {user} -pw {password} -e {sql for iotdb} -``` - -Windows 系统指令 -```shell -Shell > sbin\start-cli.bat -h {host} -p {rpcPort} -u {user} -pw {password} -e {sql for iotdb} -``` - -在 Windows 环境下,-e 参数的 SQL 语句需要使用` `` `对于`" "`进行替换 - -为了更好的解释-e 参数的使用,可以参考下面在 Linux 上执行的例子。 - -假设用户希望对一个新启动的 IoTDB 进行如下操作: - -1. 创建名为 root.demo 的 database - -2. 创建名为 root.demo.s1 的时间序列 - -3. 向创建的时间序列中插入三个数据点 - -4. 查询验证数据是否插入成功 - -那么通过使用 cli/Shell 工具的 -e 参数,可以采用如下的脚本: - -```shell -# !/bin/bash - -host=127.0.0.1 -rpcPort=6667 -user=root -pass=root - -bash ./sbin/start-cli.sh -h ${host} -p ${rpcPort} -u ${user} -pw ${pass} -e "CREATE DATABASE root.demo" -bash ./sbin/start-cli.sh -h ${host} -p ${rpcPort} -u ${user} -pw ${pass} -e "create timeseries root.demo.s1 WITH DATATYPE=INT32, ENCODING=RLE" -bash ./sbin/start-cli.sh -h ${host} -p ${rpcPort} -u ${user} -pw ${pass} -e "insert into root.demo(timestamp,s1) values(1,10)" -bash ./sbin/start-cli.sh -h ${host} -p ${rpcPort} -u ${user} -pw ${pass} -e "insert into root.demo(timestamp,s1) values(2,11)" -bash ./sbin/start-cli.sh -h ${host} -p ${rpcPort} -u ${user} -pw ${pass} -e "insert into root.demo(timestamp,s1) values(3,12)" -bash ./sbin/start-cli.sh -h ${host} -p ${rpcPort} -u ${user} -pw ${pass} -e "select s1 from root.demo" -``` - -打印出来的结果显示如下,通过这种方式进行的操作与客户端的输入模式以及通过 JDBC 进行操作结果是一致的。 - -```shell - Shell > bash ./shell.sh -+-----------------------------+------------+ -| Time|root.demo.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.001+08:00| 10| -|1970-01-01T08:00:00.002+08:00| 11| -|1970-01-01T08:00:00.003+08:00| 12| -+-----------------------------+------------+ -Total line number = 3 -It costs 0.267s -``` - -需要特别注意的是,在脚本中使用 -e 参数时要对特殊字符进行转义。 - diff --git a/src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_apache.md b/src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_apache.md deleted file mode 100644 index 70135b212..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_apache.md +++ /dev/null @@ -1,229 +0,0 @@ - - -# 运维工具 - -## 数据文件夹概览工具 - -IoTDB数据文件夹概览工具用于打印出数据文件夹的结构概览信息,工具位置为 tools/tsfile/print-iotdb-data-dir。 - -### 用法 - -- Windows: - -```bash -.\print-iotdb-data-dir.bat (<输出结果的存储路径>) -``` - -- Linux or MacOs: - -```shell -./print-iotdb-data-dir.sh (<输出结果的存储路径>) -``` - -注意:如果没有设置输出结果的存储路径, 将使用相对路径"IoTDB_data_dir_overview.txt"作为默认值。 - -### 示例 - -以Windows系统为例: - -`````````````````````````bash -.\print-iotdb-data-dir.bat D:\github\master\iotdb\data\datanode\data -```````````````````````` -Starting Printing the IoTDB Data Directory Overview -```````````````````````` -output save path:IoTDB_data_dir_overview.txt -data dir num:1 -143 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties,, use the default configs. -|============================================================== -|D:\github\master\iotdb\data\datanode\data -|--sequence -| |--root.redirect0 -| | |--1 -| | | |--0 -| |--root.redirect1 -| | |--2 -| | | |--0 -| |--root.redirect2 -| | |--3 -| | | |--0 -| |--root.redirect3 -| | |--4 -| | | |--0 -| |--root.redirect4 -| | |--5 -| | | |--0 -| |--root.redirect5 -| | |--6 -| | | |--0 -| |--root.sg1 -| | |--0 -| | | |--0 -| | | |--2760 -|--unsequence -|============================================================== -````````````````````````` - -## TsFile概览工具 - -TsFile概览工具用于以概要模式打印出一个TsFile的内容,工具位置为 tools/tsfile/print-tsfile。 - -### 用法 - -- Windows: - -```bash -.\print-tsfile-sketch.bat (<输出结果的存储路径>) -``` - -- Linux or MacOs: - -```shell -./print-tsfile-sketch.sh (<输出结果的存储路径>) -``` - -注意:如果没有设置输出结果的存储路径, 将使用相对路径"TsFile_sketch_view.txt"作为默认值。 - -### 示例 - -以Windows系统为例: - -`````````````````````````bash -.\print-tsfile.bat D:\github\master\1669359533965-1-0-0.tsfile D:\github\master\sketch.txt -```````````````````````` -Starting Printing the TsFile Sketch -```````````````````````` -TsFile path:D:\github\master\1669359533965-1-0-0.tsfile -Sketch save path:D:\github\master\sketch.txt -148 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties, use the default configs. --------------------------------- TsFile Sketch -------------------------------- -file path: D:\github\master\1669359533965-1-0-0.tsfile -file length: 2974 - - POSITION| CONTENT - -------- ------- - 0| [magic head] TsFile - 6| [version number] 3 -||||||||||||||||||||| [Chunk Group] of root.sg1.d1, num of Chunks:3 - 7| [Chunk Group Header] - | [marker] 0 - | [deviceID] root.sg1.d1 - 20| [Chunk] of root.sg1.d1.s1, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9032452783138882770,maxValue:9117677033041335123,firstValue:7068645577795875906,lastValue:-5833792328174747265,sumValue:5.795959009889246E19] - | [chunk header] marker=5, measurementID=s1, dataSize=864, dataType=INT64, compressionType=SNAPPY, encodingType=RLE - | [page] UncompressedSize:862, CompressedSize:860 - 893| [Chunk] of root.sg1.d1.s2, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-8806861312244965718,maxValue:9192550740609853234,firstValue:1150295375739457693,lastValue:-2839553973758938646,sumValue:8.2822564314572677E18] - | [chunk header] marker=5, measurementID=s2, dataSize=864, dataType=INT64, compressionType=SNAPPY, encodingType=RLE - | [page] UncompressedSize:862, CompressedSize:860 - 1766| [Chunk] of root.sg1.d1.s3, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9076669333460323191,maxValue:9175278522960949594,firstValue:2537897870994797700,lastValue:7194625271253769397,sumValue:-2.126008424849926E19] - | [chunk header] marker=5, measurementID=s3, dataSize=864, dataType=INT64, compressionType=SNAPPY, encodingType=RLE - | [page] UncompressedSize:862, CompressedSize:860 -||||||||||||||||||||| [Chunk Group] of root.sg1.d1 ends - 2656| [marker] 2 - 2657| [TimeseriesIndex] of root.sg1.d1.s1, tsDataType:INT64, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9032452783138882770,maxValue:9117677033041335123,firstValue:7068645577795875906,lastValue:-5833792328174747265,sumValue:5.795959009889246E19] - | [ChunkIndex] offset=20 - 2728| [TimeseriesIndex] of root.sg1.d1.s2, tsDataType:INT64, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-8806861312244965718,maxValue:9192550740609853234,firstValue:1150295375739457693,lastValue:-2839553973758938646,sumValue:8.2822564314572677E18] - | [ChunkIndex] offset=893 - 2799| [TimeseriesIndex] of root.sg1.d1.s3, tsDataType:INT64, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9076669333460323191,maxValue:9175278522960949594,firstValue:2537897870994797700,lastValue:7194625271253769397,sumValue:-2.126008424849926E19] - | [ChunkIndex] offset=1766 - 2870| [IndexOfTimerseriesIndex Node] type=LEAF_MEASUREMENT - | - | -||||||||||||||||||||| [TsFileMetadata] begins - 2891| [IndexOfTimerseriesIndex Node] type=LEAF_DEVICE - | - | - | [meta offset] 2656 - | [bloom filter] bit vector byte array length=31, filterSize=256, hashFunctionSize=5 -||||||||||||||||||||| [TsFileMetadata] ends - 2964| [TsFileMetadataSize] 73 - 2968| [magic tail] TsFile - 2974| END of TsFile ----------------------------- IndexOfTimerseriesIndex Tree ----------------------------- - [MetadataIndex:LEAF_DEVICE] - └──────[root.sg1.d1,2870] - [MetadataIndex:LEAF_MEASUREMENT] - └──────[s1,2657] ----------------------------------- TsFile Sketch End ---------------------------------- -````````````````````````` - -解释: - -- 以"|"为分隔,左边是在TsFile文件中的实际位置,右边是梗概内容。 -- "|||||||||||||||||||||"是为增强可读性而添加的导引信息,不是TsFile中实际存储的数据。 -- 最后打印的"IndexOfTimerseriesIndex Tree"是对TsFile文件末尾的元数据索引树的重新整理打印,便于直观理解,不是TsFile中存储的实际数据。 - -## TsFile Resource概览工具 - -TsFile resource概览工具用于打印出TsFile resource文件的内容,工具位置为 tools/tsfile/print-tsfile-resource-files。 - -### 用法 - -- Windows: - -```bash -.\print-tsfile-resource-files.bat -``` - -- Linux or MacOs: - -``` -./print-tsfile-resource-files.sh -``` - -### 示例 - -以Windows系统为例: - -`````````````````````````bash -.\print-tsfile-resource-files.bat D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0 -```````````````````````` -Starting Printing the TsFileResources -```````````````````````` -147 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties, use the default configs. -230 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-common.properties, use default configuration -231 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-common.properties from any of the known sources. -233 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-datanode.properties, use default configuration -237 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-datanode.properties from any of the known sources. -Analyzing D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile ... - -Resource plan index range [9223372036854775807, -9223372036854775808] -device root.sg1.d1, start time 0 (1970-01-01T08:00+08:00[GMT+08:00]), end time 99 (1970-01-01T08:00:00.099+08:00[GMT+08:00]) - -Analyzing the resource file folder D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0 finished. -````````````````````````` - -`````````````````````````bash -.\print-tsfile-resource-files.bat D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile.resource -```````````````````````` -Starting Printing the TsFileResources -```````````````````````` -178 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-common.properties, use default configuration -186 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties, use the default configs. -187 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-common.properties from any of the known sources. -188 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-datanode.properties, use default configuration -192 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-datanode.properties from any of the known sources. -Analyzing D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile ... - -Resource plan index range [9223372036854775807, -9223372036854775808] -device root.sg1.d1, start time 0 (1970-01-01T08:00+08:00[GMT+08:00]), end time 99 (1970-01-01T08:00:00.099+08:00[GMT+08:00]) - -Analyzing the resource file D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile.resource finished. -````````````````````````` diff --git a/src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_timecho.md b/src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_timecho.md deleted file mode 100644 index 3b4ba2f68..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Tools-System/Maintenance-Tool_timecho.md +++ /dev/null @@ -1,1001 +0,0 @@ - - -# 运维工具 - -## 集群管理工具 - -IoTDB 集群管理工具是一款易用的运维工具(企业版工具)。旨在解决 IoTDB 分布式系统多节点的运维难题,主要包括集群部署、集群启停、弹性扩容、配置更新、数据导出等功能,从而实现对复杂数据库集群的一键式指令下发,极大降低管理难度。本文档将说明如何用集群管理工具远程部署、配置、启动和停止 IoTDB 集群实例。 - -### 环境准备 - -本工具为 TimechoDB(基于IoTDB的企业版数据库)配套工具,您可以联系您的销售获取工具下载方式。 - -IoTDB 要部署的机器需要依赖jdk 8及以上版本、lsof、netstat、unzip功能如果没有请自行安装,可以参考文档最后的一节环境所需安装命令。 - -提示:IoTDB集群管理工具需要使用有root权限的账号 - -### 部署方法 - -#### 下载安装 - -本工具为TimechoDB(基于IoTDB的企业版数据库)配套工具,您可以联系您的销售获取工具下载方式。 - -注意:由于二进制包仅支持GLIBC2.17 及以上版本,因此最低适配Centos7版本 - -* 在iotd目录内输入以下指令后: - -```bash -bash install-iotdbctl.sh -``` - -即可在之后的 shell 内激活 iotdbctl 关键词,如检查部署前所需的环境指令如下所示: - -```bash -iotdbctl cluster check example -``` - -* 也可以不激活iotd直接使用 <iotdbctl absolute path>/sbin/iotdbctl 来执行命令,如检查部署前所需的环境: - -```bash -/sbin/iotdbctl cluster check example -``` - -### 系统结构 - -IoTDB集群管理工具主要由config、logs、doc、sbin目录组成。 - -* `config`存放要部署的集群配置文件如果要使用集群部署工具需要修改里面的yaml文件。 -* `logs` 存放部署工具日志,如果想要查看部署工具执行日志请查看`logs/iotd_yyyy_mm_dd.log`。 -* `sbin` 存放集群部署工具所需的二进制包。 -* `doc` 存放用户手册、开发手册和推荐部署手册。 - - -### 集群配置文件介绍 - -* 在`iotdbctl/config` 目录下有集群配置的yaml文件,yaml文件名字就是集群名字yaml 文件可以有多个,为了方便用户配置yaml文件在iotd/config目录下面提供了`default_cluster.yaml`示例。 -* yaml 文件配置由`global`、`confignode_servers`、`datanode_servers`、`grafana_server`、`prometheus_server`四大部分组成 -* global 是通用配置主要配置机器用户名密码、IoTDB本地安装文件、Jdk配置等。在`iotdbctl/config`目录中提供了一个`default_cluster.yaml`样例数据, - 用户可以复制修改成自己集群名字并参考里面的说明进行配置IoTDB集群,在`default_cluster.yaml`样例中没有注释的均为必填项,已经注释的为非必填项。 - -例如要执行`default_cluster.yaml`检查命令则需要执行命令`iotdbctl cluster check default_cluster`即可, -更多详细命令请参考下面命令列表。 - - -| 参数 | 说明 | 是否必填 | -|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------| -| iotdb\_zip\_dir | IoTDB 部署分发目录,如果值为空则从`iotdb_download_url`指定地址下载 | 非必填 | -| iotdb\_download\_url | IoTDB 下载地址,如果`iotdb_zip_dir` 没有值则从指定地址下载 | 非必填 | -| jdk\_tar\_dir | jdk 本地目录,可使用该 jdk 路径进行上传部署至目标节点。 | 非必填 | -| jdk\_deploy\_dir | jdk 远程机器部署目录,会将 jdk 部署到该目录下面,与下面的`jdk_dir_name`参数构成完整的jdk部署目录即 `/` | 非必填 | -| jdk\_dir\_name | jdk 解压后的目录名称默认是jdk_iotdb | 非必填 | -| iotdb\_lib\_dir | IoTDB lib 目录或者IoTDB 的lib 压缩包仅支持.zip格式 ,仅用于IoTDB升级,默认处于注释状态,如需升级请打开注释修改路径即可。如果使用zip文件请使用zip 命令压缩iotdb/lib目录例如 zip -r lib.zip apache\-iotdb\-1.2.0/lib/* | 非必填 | -| user | ssh登陆部署机器的用户名 | 必填 | -| password | ssh登录的密码, 如果password未指定使用pkey登陆, 请确保已配置节点之间ssh登录免密钥 | 非必填 | -| pkey | 密钥登陆如果password有值优先使用password否则使用pkey登陆 | 非必填 | -| ssh\_port | ssh登录端口 | 必填 | -| iotdb\_admin_user | iotdb服务用户名默认root | 非必填 | -| iotdb\_admin_password | iotdb服务密码默认root | 非必填 | -| deploy\_dir | IoTDB 部署目录,会把 IoTDB 部署到该目录下面与下面的`iotdb_dir_name`参数构成完整的IoTDB 部署目录即 `/` | 必填 | -| iotdb\_dir\_name | IoTDB 解压后的目录名称默认是iotdb | 非必填 | -| datanode-env.sh | 对应`iotdb/config/datanode-env.sh` ,在`global`与`confignode_servers`同时配置值时优先使用`confignode_servers`中的值 | 非必填 | -| confignode-env.sh | 对应`iotdb/config/confignode-env.sh`,在`global`与`datanode_servers`同时配置值时优先使用`datanode_servers`中的值 | 非必填 | -| iotdb-common.properties | 对应`iotdb/config/iotdb-common.properties` | 非必填 | -| cn\_seed\_config\_node | 集群配置地址指向存活的ConfigNode,默认指向confignode\_x,在`global`与`confignode_servers`同时配置值时优先使用`confignode_servers`中的值,对应`iotdb/config/iotdb-system.properties`中的`cn_seed_config_node` | 必填 | -| dn\_seed\_config\_node | 集群配置地址指向存活的ConfigNode,默认指向confignode\_x,在`global`与`datanode_servers`同时配置值时优先使用`datanode_servers`中的值,对应`iotdb/config/iotdb-system.properties`中的`dn_seed_config_node` | 必填 | - -其中datanode-env.sh 和confignode-env.sh 可以配置额外参数extra_opts,当该参数配置后会在datanode-env.sh 和confignode-env.sh 后面追加对应的值,可参考default\_cluster.yaml,配置示例如下: -datanode-env.sh: -extra_opts: | -IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -XX:+UseG1GC" -IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -XX:MaxGCPauseMillis=200" - -* confignode_servers 是部署IoTDB Confignodes配置,里面可以配置多个Confignode - 默认将第一个启动的ConfigNode节点node1当作Seed-ConfigNode - -| 参数 | 说明 | 是否必填 | -|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------| -| name | Confignode 名称 | 必填 | -| deploy\_dir | IoTDB config node 部署目录 | 必填| | -| cn\_internal\_address | 对应iotdb/内部通信地址,对应`iotdb/config/iotdb-system.properties`中的`cn_internal_address` | 必填 | -| cn\_seed\_config\_node | 集群配置地址指向存活的ConfigNode,默认指向confignode_x,在`global`与`confignode_servers`同时配置值时优先使用`confignode_servers`中的值,对应`iotdb/config/iotdb-confignode.properties`中的`cn_seed_config_node` | 必填 | -| cn\_internal\_port | 内部通信端口,对应`iotdb/config/iotdb-system.properties`中的`cn_internal_port` | 必填 | -| cn\_consensus\_port | 对应`iotdb/config/iotdb-system.properties`中的`cn_consensus_port` | 非必填 | -| cn\_data\_dir | 对应`iotdb/config/iotdb-system.properties`中的`cn_data_dir` | 必填 | -| iotdb-system.properties | 对应`iotdb/config/iotdb-system.properties`在`global`与`confignode_servers`同时配置值优先使用confignode\_servers中的值 | 非必填 | - -* datanode_servers 是部署IoTDB Datanodes配置,里面可以配置多个Datanode - - -| 参数 | 说明 |是否必填| -|---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|--- | -| name | Datanode 名称 |必填| -| deploy\_dir | IoTDB data node 部署目录 |必填| -| dn\_rpc\_address | datanode rpc 地址对应`iotdb/config/iotdb-system.properties`中的`dn_rpc_address` |必填| -| dn\_internal\_address | 内部通信地址,对应`iotdb/config/iotdb-system.properties`中的`dn_internal_address` |必填| -| dn\_seed\_config\_node | 集群配置地址指向存活的ConfigNode,默认指向confignode_x,在`global`与`datanode_servers`同时配置值时优先使用`datanode_servers`中的值,对应`iotdb/config/iotdb-system.properties`中的`dn_seed_config_node` |必填| -| dn\_rpc\_port | datanode rpc端口地址,对应`iotdb/config/iotdb-system.properties`中的`dn_rpc_port` |必填| -| dn\_internal\_port | 内部通信端口,对应`iotdb/config/iotdb-system.properties`中的`dn_internal_port` |必填| -| iotdb-system.properties | 对应`iotdb/config/iotdb-common.properties`在`global`与`datanode_servers`同时配置值优先使用`datanode_servers`中的值 |非必填| - -* grafana_server 是部署Grafana 相关配置 - -| 参数 | 说明 | 是否必填 | -|--------------------|------------------|-------------------| -| grafana\_dir\_name | grafana 解压目录名称 | 非必填默认grafana_iotdb | -| host | grafana 部署的服务器ip | 必填 | -| grafana\_port | grafana 部署机器的端口 | 非必填,默认3000 | -| deploy\_dir | grafana 部署服务器目录 | 必填 | -| grafana\_tar\_dir | grafana 压缩包位置 | 必填 | -| dashboards | dashboards 所在的位置 | 非必填,多个用逗号隔开 | - -* prometheus_server 是部署Prometheus 相关配置 - -| 参数 | 说明 | 是否必填 | -|--------------------------------|------------------|-----------------------| -| prometheus_dir\_name | prometheus 解压目录名称 | 非必填默认prometheus_iotdb | -| host | prometheus 部署的服务器ip | 必填 | -| prometheus\_port | prometheus 部署机器的端口 | 非必填,默认9090 | -| deploy\_dir | prometheus 部署服务器目录 | 必填 | -| prometheus\_tar\_dir | prometheus 压缩包位置 | 必填 | -| storage\_tsdb\_retention\_time | 默认保存数据天数 默认15天 | 非必填 | -| storage\_tsdb\_retention\_size | 指定block可以保存的数据大小默认512M ,注意单位KB, MB, GB, TB, PB, EB | 非必填 | - -如果在config/xxx.yaml的`iotdb-system.properties`和`iotdb-system.properties`中配置了metrics,则会自动把配置放入到promethues无需手动修改 - -注意:如何配置yaml key对应的值包含特殊字符如:等建议整个value使用双引号,对应的文件路径中不要使用包含空格的路径,防止出现识别出现异常问题。 - -### 使用场景 - -#### 清理数据场景 - -* 清理集群数据场景会删除IoTDB集群中的data目录以及yaml文件中配置的`cn_system_dir`、`cn_consensus_dir`、 - `dn_data_dirs`、`dn_consensus_dir`、`dn_system_dir`、`logs`和`ext`目录。 -* 首先执行停止集群命令、然后在执行集群清理命令。 -```bash -iotdbctl cluster stop default_cluster -iotdbctl cluster clean default_cluster -``` - -#### 集群销毁场景 - -* 集群销毁场景会删除IoTDB集群中的`data`、`cn_system_dir`、`cn_consensus_dir`、 - `dn_data_dirs`、`dn_consensus_dir`、`dn_system_dir`、`logs`、`ext`、`IoTDB`部署目录、 - grafana部署目录和prometheus部署目录。 -* 首先执行停止集群命令、然后在执行集群销毁命令。 - - -```bash -iotdbctl cluster stop default_cluster -iotdbctl cluster destroy default_cluster -``` - -#### 集群升级场景 - -* 集群升级首先需要在config/xxx.yaml中配置`iotdb_lib_dir`为要上传到服务器的jar所在目录路径(例如iotdb/lib)。 -* 如果使用zip文件上传请使用zip 命令压缩iotdb/lib目录例如 zip -r lib.zip apache-iotdb-1.2.0/lib/* -* 执行上传命令、然后执行重启IoTDB集群命令即可完成集群升级 - -```bash -iotdbctl cluster dist-lib default_cluster -iotdbctl cluster restart default_cluster -``` - -#### 集群配置文件的热部署场景 - -* 首先修改在config/xxx.yaml中配置。 -* 执行分发命令、然后执行热部署命令即可完成集群配置的热部署 - -```bash -iotdbctl cluster dist-conf default_cluster -iotdbctl cluster reload default_cluster -``` - -#### 集群扩容场景 - -* 首先修改在config/xxx.yaml中添加一个datanode 或者confignode 节点。 -* 执行集群扩容命令 -```bash -iotdbctl cluster scaleout default_cluster -``` - -#### 集群缩容场景 - -* 首先在config/xxx.yaml中找到要缩容的节点名字或者ip+port(其中confignode port 是cn_internal_port、datanode port 是rpc_port) -* 执行集群缩容命令 -```bash -iotdbctl cluster scalein default_cluster -``` - -#### 已有IoTDB集群,使用集群部署工具场景 - -* 配置服务器的`user`、`passwod`或`pkey`、`ssh_port` -* 修改config/xxx.yaml中IoTDB 部署路径,`deploy_dir`(IoTDB 部署目录)、`iotdb_dir_name`(IoTDB解压目录名称,默认是iotdb) - 例如IoTDB 部署完整路径是`/home/data/apache-iotdb-1.1.1`则需要修改yaml文件`deploy_dir:/home/data/`、`iotdb_dir_name:apache-iotdb-1.1.1` -* 如果服务器不是使用的java_home则修改`jdk_deploy_dir`(jdk 部署目录)、`jdk_dir_name`(jdk解压后的目录名称,默认是jdk_iotdb),如果使用的是java_home 则不需要修改配置 - 例如jdk部署完整路径是`/home/data/jdk_1.8.2`则需要修改yaml文件`jdk_deploy_dir:/home/data/`、`jdk_dir_name:jdk_1.8.2` -* 配置`cn_seed_config_node`、`dn_seed_config_node` -* 配置`confignode_servers`中`iotdb-system.properties`里面的`cn_internal_address`、`cn_internal_port`、`cn_consensus_port`、`cn_system_dir`、 - `cn_consensus_dir`里面的值不是IoTDB默认的则需要配置否则可不必配置 -* 配置`datanode_servers`中`iotdb-system.properties`里面的`dn_rpc_address`、`dn_internal_address`、`dn_data_dirs`、`dn_consensus_dir`、`dn_system_dir`等 -* 执行初始化命令 - -```bash -iotdbctl cluster init default_cluster -``` - -#### 一键部署IoTDB、Grafana和Prometheus 场景 - -* 配置`iotdb-system.properties` 打开metrics接口 -* 配置Grafana 配置,如果`dashboards` 有多个就用逗号隔开,名字不能重复否则会被覆盖。 -* 配置Prometheus配置,IoTDB 集群配置了metrics 则无需手动修改Prometheus 配置会根据哪个节点配置了metrics,自动修改Prometheus 配置。 -* 启动集群 - -```bash -iotdbctl cluster start default_cluster -``` - -更加详细参数请参考上方的 集群配置文件介绍 - - -### 命令格式 - -本工具的基本用法为: -```bash -iotdbctl cluster [params (Optional)] -``` -* key 表示了具体的命令。 - -* cluster name 表示集群名称(即`iotdbctl/config` 文件中yaml文件名字)。 - -* params 表示了命令的所需参数(选填)。 - -* 例如部署default_cluster集群的命令格式为: - -```bash -iotdbctl cluster deploy default_cluster -``` - -* 集群的功能及参数列表如下: - -| 命令 | 功能 | 参数 | -|-----------------|-------------------------------|-------------------------------------------------------------------------------------------------------------------------| -| check | 检测集群是否可以部署 | 集群名称列表 | -| clean | 清理集群 | 集群名称 | -| deploy/dist-all | 部署集群 | 集群名称 ,-N,模块名称(iotdb、grafana、prometheus可选),-op force(可选) | -| list | 打印集群及状态列表 | 无 | -| start | 启动集群 | 集群名称,-N,节点名称(nodename、grafana、prometheus可选) | -| stop | 关闭集群 | 集群名称,-N,节点名称(nodename、grafana、prometheus可选) ,-op force(nodename、grafana、prometheus可选) | -| restart | 重启集群 | 集群名称,-N,节点名称(nodename、grafana、prometheus可选),-op force(强制停止)/rolling(滚动重启) | -| show | 查看集群信息,details字段表示展示集群信息细节 | 集群名称, details(可选) | -| destroy | 销毁集群 | 集群名称,-N,模块名称(iotdb、grafana、prometheus可选) | -| scaleout | 集群扩容 | 集群名称 | -| scalein | 集群缩容 | 集群名称,-N,集群节点名字或集群节点ip+port | -| reload | 集群热加载 | 集群名称 | -| dist-conf | 集群配置文件分发 | 集群名称 | -| dumplog | 备份指定集群日志 | 集群名称,-N,集群节点名字 -h 备份至目标机器ip -pw 备份至目标机器密码 -p 备份至目标机器端口 -path 备份的目录 -startdate 起始时间 -enddate 结束时间 -loglevel 日志类型 -l 传输速度 | -| dumpdata | 备份指定集群数据 | 集群名称, -h 备份至目标机器ip -pw 备份至目标机器密码 -p 备份至目标机器端口 -path 备份的目录 -startdate 起始时间 -enddate 结束时间 -l 传输速度 | -| dist-lib | lib 包升级 | 集群名字(升级完后请重启) | -| init | 已有集群使用集群部署工具时,初始化集群配置 | 集群名字,初始化集群配置 | -| status | 查看进程状态 | 集群名字 | -| acitvate | 激活集群 | 集群名字 | -| dist-plugin | 上传plugin(udf,trigger,pipe)到集群 | 集群名字,-type 类型 U(udf)/T(trigger)/P(pipe) -file /xxxx/trigger.jar,上传完成后需手动执行创建udf、pipe、trigger命令 | -| upgrade | 滚动升级 | 集群名字 | -| health_check | 健康检查 | 集群名字,-N,节点名称(可选) | -| backup | 停机备份 | 集群名字,-N,节点名称(可选) | -| importschema | 元数据导入 | 集群名字,-N,节点名称(必填) -param 参数 | -| exportschema | 元数据导出 | 集群名字,-N,节点名称(必填) -param 参数 | - - -### 详细命令执行过程 - -下面的命令都是以default_cluster.yaml 为示例执行的,用户可以修改成自己的集群文件来执行 - -#### 检查集群部署环境命令 - -```bash -iotdbctl cluster check default_cluster -``` - -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 验证目标节点是否能够通过 SSH 登录 - -* 验证对应节点上的 JDK 版本是否满足IoTDB jdk1.8及以上版本、服务器是否按照unzip、是否安装lsof 或者netstat - -* 如果看到下面提示`Info:example check successfully!` 证明服务器已经具备安装的要求, - 如果输出`Error:example check fail!` 证明有部分条件没有满足需求可以查看上面的输出的Error日志(例如:`Error:Server (ip:172.20.31.76) iotdb port(10713) is listening`)进行修复, - 如果检查jdk没有满足要求,我们可以自己在yaml 文件中配置一个jdk1.8 及以上版本的进行部署不影响后面使用, - 如果检查lsof、netstat或者unzip 不满足要求需要在服务器上自行安装。 - -#### 部署集群命令 - -```bash -iotdbctl cluster deploy default_cluster -``` - -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 根据`confignode_servers` 和`datanode_servers`中的节点信息上传IoTDB压缩包和jdk压缩包(如果yaml中配置`jdk_tar_dir`和`jdk_deploy_dir`值) - -* 根据yaml文件节点配置信息生成并上传`iotdb-system.properties` - -```bash -iotdbctl cluster deploy default_cluster -op force -``` -注意:该命令会强制执行部署,具体过程会删除已存在的部署目录重新部署 - -*部署单个模块* -```bash -# 部署grafana模块 -iotdbctl cluster deploy default_cluster -N grafana -# 部署prometheus模块 -iotdbctl cluster deploy default_cluster -N prometheus -# 部署iotdb模块 -iotdbctl cluster deploy default_cluster -N iotdb -``` - -#### 启动集群命令 - -```bash -iotdbctl cluster start default_cluster -``` - -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 启动confignode,根据yaml配置文件中`confignode_servers`中的顺序依次启动同时根据进程id检查confignode是否正常,第一个confignode 为seek config - -* 启动datanode,根据yaml配置文件中`datanode_servers`中的顺序依次启动同时根据进程id检查datanode是否正常 - -* 如果根据进程id检查进程存在后,通过cli依次检查集群列表中每个服务是否正常,如果cli链接失败则每隔10s重试一次直到成功最多重试5次 - - -*启动单个节点命令* -```bash -#按照IoTDB 节点名称启动 -iotdbctl cluster start default_cluster -N datanode_1 -#按照IoTDB 集群ip+port启动,其中port对应confignode的cn_internal_port、datanode的rpc_port -iotdbctl cluster start default_cluster -N 192.168.1.5:6667 -#启动grafana -iotdbctl cluster start default_cluster -N grafana -#启动prometheus -iotdbctl cluster start default_cluster -N prometheus -``` - -* 根据 cluster-name 找到默认位置的 yaml 文件 - -* 根据提供的节点名称或者ip:port找到对于节点位置信息,如果启动的节点是`data_node`则ip使用yaml 文件中的`dn_rpc_address`、port 使用的是yaml文件中datanode_servers 中的`dn_rpc_port`。 - 如果启动的节点是`config_node`则ip使用的是yaml文件中confignode_servers 中的`cn_internal_address` 、port 使用的是`cn_internal_port` - -* 启动该节点 - -说明:由于集群部署工具仅是调用了IoTDB集群中的start-confignode.sh和start-datanode.sh 脚本, -在实际输出结果失败时有可能是集群还未正常启动,建议使用status命令进行查看当前集群状态(iotdbctl cluster status xxx) - - -#### 查看IoTDB集群状态命令 - -```bash -iotdbctl cluster show default_cluster -#查看IoTDB集群详细信息 -iotdbctl cluster show default_cluster details -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 依次在datanode通过cli执行`show cluster details` 如果有一个节点执行成功则不会在后续节点继续执行cli直接返回结果 - - -#### 停止集群命令 - - -```bash -iotdbctl cluster stop default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 根据`datanode_servers`中datanode节点信息,按照配置先后顺序依次停止datanode节点 - -* 根据`confignode_servers`中confignode节点信息,按照配置依次停止confignode节点 - -*强制停止集群命令* - -```bash -iotdbctl cluster stop default_cluster -op force -``` -会直接执行kill -9 pid 命令强制停止集群 - -*停止单个节点命令* - -```bash -#按照IoTDB 节点名称停止 -iotdbctl cluster stop default_cluster -N datanode_1 -#按照IoTDB 集群ip+port停止(ip+port是按照datanode中的ip+dn_rpc_port获取唯一节点或confignode中的ip+cn_internal_port获取唯一节点) -iotdbctl cluster stop default_cluster -N 192.168.1.5:6667 -#停止grafana -iotdbctl cluster stop default_cluster -N grafana -#停止prometheus -iotdbctl cluster stop default_cluster -N prometheus -``` - -* 根据 cluster-name 找到默认位置的 yaml 文件 - -* 根据提供的节点名称或者ip:port找到对应节点位置信息,如果停止的节点是`data_node`则ip使用yaml 文件中的`dn_rpc_address`、port 使用的是yaml文件中datanode_servers 中的`dn_rpc_port`。 - 如果停止的节点是`config_node`则ip使用的是yaml文件中confignode_servers 中的`cn_internal_address` 、port 使用的是`cn_internal_port` - -* 停止该节点 - -说明:由于集群部署工具仅是调用了IoTDB集群中的stop-confignode.sh和stop-datanode.sh 脚本,在某些情况下有可能iotdb集群并未停止。 - - -#### 清理集群数据命令 - -```bash -iotdbctl cluster clean default_cluster -``` - -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`、`datanode_servers`配置信息 - -* 根据`confignode_servers`、`datanode_servers`中的信息,检查是否还有服务正在运行, - 如果有任何一个服务正在运行则不会执行清理命令 - -* 删除IoTDB集群中的data目录以及yaml文件中配置的`cn_system_dir`、`cn_consensus_dir`、 - `dn_data_dirs`、`dn_consensus_dir`、`dn_system_dir`、`logs`和`ext`目录。 - - - -#### 重启集群命令 - -```bash -iotdbctl cluster restart default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`、`datanode_servers`、`grafana`、`prometheus`配置信息 - -* 执行上述的停止集群命令(stop),然后执行启动集群命令(start) 具体参考上面的start 和stop 命令 - -*强制重启集群命令* - -```bash -iotdbctl cluster restart default_cluster -op force -``` -会直接执行kill -9 pid 命令强制停止集群,然后启动集群 - -*重启单个节点命令* - -```bash -#按照IoTDB 节点名称重启datanode_1 -iotdbctl cluster restart default_cluster -N datanode_1 -#按照IoTDB 节点名称重启confignode_1 -iotdbctl cluster restart default_cluster -N confignode_1 -#重启grafana -iotdbctl cluster restart default_cluster -N grafana -#重启prometheus -iotdbctl cluster restart default_cluster -N prometheus -``` - -#### 集群缩容命令 - -```bash -#按照节点名称缩容 -iotdbctl cluster scalein default_cluster -N nodename -#按照ip+port缩容(ip+port按照datanode中的ip+dn_rpc_port获取唯一节点,confignode中的ip+cn_internal_port获取唯一节点) -iotdbctl cluster scalein default_cluster -N ip:port -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 判断要缩容的confignode节点和datanode是否只剩一个,如果只剩一个则不能执行缩容 - -* 然后根据ip:port或者nodename 获取要缩容的节点信息,执行缩容命令,然后销毁该节点目录,如果缩容的节点是`data_node`则ip使用yaml 文件中的`dn_rpc_address`、port 使用的是yaml文件中datanode_servers 中的`dn_rpc_port`。 - 如果缩容的节点是`config_node`则ip使用的是yaml文件中confignode_servers 中的`cn_internal_address` 、port 使用的是`cn_internal_port` - - -提示:目前一次仅支持一个节点缩容 - -#### 集群扩容命令 - -```bash -iotdbctl cluster scaleout default_cluster -``` -* 修改config/xxx.yaml 文件添加一个datanode 节点或者confignode节点 - -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 找到要扩容的节点,执行上传IoTDB压缩包和jdb包(如果yaml中配置`jdk_tar_dir`和`jdk_deploy_dir`值)并解压 - -* 根据yaml文件节点配置信息生成并上传`iotdb-system.properties` - -* 执行启动该节点命令并校验节点是否启动成功 - -提示:目前一次仅支持一个节点扩容 - -#### 销毁集群命令 -```bash -iotdbctl cluster destroy default_cluster -``` - -* cluster-name 找到默认位置的 yaml 文件 - -* 根据`confignode_servers`、`datanode_servers`、`grafana`、`prometheus`中node节点信息,检查是否节点还在运行, - 如果有任何一个节点正在运行则停止销毁命令 - -* 删除IoTDB集群中的`data`以及yaml文件配置的`cn_system_dir`、`cn_consensus_dir`、 - `dn_data_dirs`、`dn_consensus_dir`、`dn_system_dir`、`logs`、`ext`、`IoTDB`部署目录、 - grafana部署目录和prometheus部署目录 - -*销毁单个模块* -```bash -# 销毁grafana模块 -iotdbctl cluster destroy default_cluster -N grafana -# 销毁prometheus模块 -iotdbctl cluster destroy default_cluster -N prometheus -# 销毁iotdb模块 -iotdbctl cluster destroy default_cluster -N iotdb -``` - -#### 分发集群配置命令 -```bash -iotdbctl cluster dist-conf default_cluster -``` - -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`、`datanode_servers`、`grafana`、`prometheus`配置信息 - -* 根据yaml文件节点配置信息生成并依次上传`iotdb-system.properties`到指定节点 - -#### 热加载集群配置命令 -```bash -iotdbctl cluster reload default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 根据yaml文件节点配置信息依次在cli中执行`load configuration` - -#### 集群节点日志备份 -```bash -iotdbctl cluster dumplog default_cluster -N datanode_1,confignode_1 -startdate '2023-04-11' -enddate '2023-04-26' -h 192.168.9.48 -p 36000 -u root -pw root -path '/iotdb/logs' -logs '/root/data/db/iotdb/logs' -``` -* 根据 cluster-name 找到默认位置的 yaml 文件 - -* 该命令会根据yaml文件校验datanode_1,confignode_1 是否存在,然后根据配置的起止日期(startdate<=logtime<=enddate)备份指定节点datanode_1,confignode_1 的日志数据到指定服务`192.168.9.48` 端口`36000` 数据备份路径是 `/iotdb/logs` ,IoTDB日志存储路径在`/root/data/db/iotdb/logs`(非必填,如果不填写-logs xxx 默认从IoTDB安装路径/logs下面备份日志) - -| 命令 | 功能 | 是否必填 | -|------------|------------------------------------| ---| -| -h | 存放备份数据机器ip |否| -| -u | 存放备份数据机器用户名 |否| -| -pw | 存放备份数据机器密码 |否| -| -p | 存放备份数据机器端口(默认22) |否| -| -path | 存放备份数据的路径(默认当前路径) |否| -| -loglevel | 日志基本有all、info、error、warn(默认是全部) |否| -| -l | 限速(默认不限速范围0到104857601 单位Kbit/s) |否| -| -N | 配置文件集群名称多个用逗号隔开 |是| -| -startdate | 起始时间(包含默认1970-01-01) |否| -| -enddate | 截止时间(包含) |否| -| -logs | IoTDB 日志存放路径,默认是({iotdb}/logs) |否| - -#### 集群节点数据备份 -```bash -iotdbctl cluster dumpdata default_cluster -granularity partition -startdate '2023-04-11' -enddate '2023-04-26' -h 192.168.9.48 -p 36000 -u root -pw root -path '/iotdb/datas' -``` -* 该命令会根据yaml文件获取leader 节点,然后根据起止日期(startdate<=logtime<=enddate)备份数据到192.168.9.48 服务上的/iotdb/datas 目录下 - -| 命令 | 功能 | 是否必填 | -| ---|---------------------------------| ---| -|-h| 存放备份数据机器ip |否| -|-u| 存放备份数据机器用户名 |否| -|-pw| 存放备份数据机器密码 |否| -|-p| 存放备份数据机器端口(默认22) |否| -|-path| 存放备份数据的路径(默认当前路径) |否| -|-granularity| 类型partition |是| -|-l| 限速(默认不限速范围0到104857601 单位Kbit/s) |否| -|-startdate| 起始时间(包含) |是| -|-enddate| 截止时间(包含) |是| - -#### 集群lib包上传(升级) -```bash -iotdbctl cluster dist-lib default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 上传lib包 - -注意执行完升级后请重启IoTDB 才能生效 - -#### 集群初始化 -```bash -iotdbctl cluster init default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`、`datanode_servers`、`grafana`、`prometheus`配置信息 -* 初始化集群配置 - -#### 查看集群进程状态 -```bash -iotdbctl cluster status default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`、`datanode_servers`、`grafana`、`prometheus`配置信息 -* 展示集群的存活状态 - -#### 集群授权激活 - -集群激活默认是通过输入激活码激活,也可以通过-op license_path 通过license路径激活 - -* 默认激活方式 -```bash -iotdbctl cluster activate default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`配置信息 -* 读取里面的机器码 -* 等待输入激活码 - -```bash -Machine code: -Kt8NfGP73FbM8g4Vty+V9qU5lgLvwqHEF3KbLN/SGWYCJ61eFRKtqy7RS/jw03lHXt4MwdidrZJ== -JHQpXu97IKwv3rzbaDwoPLUuzNCm5aEeC9ZEBW8ndKgGXEGzMms25+u== -Please enter the activation code: -JHQpXu97IKwv3rzbaDwoPLUuzNCm5aEeC9ZEBW8ndKg=,lTF1Dur1AElXIi/5jPV9h0XCm8ziPd9/R+tMYLsze1oAPxE87+Nwws= -Activation successful -``` -* 激活单个节点 - -```bash -iotdbctl cluster activate default_cluster -N confignode1 -``` - -* 通过license路径方式激活 - -```bash -iotdbctl cluster activate default_cluster -op license_path -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`配置信息 -* 读取里面的机器码 -* 等待输入激活码 - -```bash -Machine code: -Kt8NfGP73FbM8g4Vty+V9qU5lgLvwqHEF3KbLN/SGWYCJ61eFRKtqy7RS/jw03lHXt4MwdidrZJ== -JHQpXu97IKwv3rzbaDwoPLUuzNCm5aEeC9ZEBW8ndKgGXEGzMms25+u== -Please enter the activation code: -JHQpXu97IKwv3rzbaDwoPLUuzNCm5aEeC9ZEBW8ndKg=,lTF1Dur1AElXIi/5jPV9h0XCm8ziPd9/R+tMYLsze1oAPxE87+Nwws= -Activation successful -``` -* 激活单个节点 - -```bash -iotdbctl cluster activate default_cluster -N confignode1 -op license_path -``` - -* 通过license路径方式激活 - -```bash -iotdbctl cluster activate default_cluster -op license_path -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`配置信息 -* 读取里面的机器码 -* 等待输入激活码 - -### 集群plugin分发 -```bash -#分发udf -iotdbctl cluster dist-plugin default_cluster -type U -file /xxxx/udf.jar -#分发trigger -iotdbctl cluster dist-plugin default_cluster -type T -file /xxxx/trigger.jar -#分发pipe -iotdbctl cluster dist-plugin default_cluster -type P -file /xxxx/pipe.jar -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取 `datanode_servers`配置信息 - -* 上传udf/trigger/pipe jar包 - -上传完成后需要手动执行创建udf/trigger/pipe命令 - -### 集群滚动升级 -```bash -iotdbctl cluster upgrade default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 - -* 上传lib包 -* confignode 执行停止、替换lib包、启动,然后datanode执行停止、替换lib包、启动 - - - -### 集群健康检查 -```bash -iotdbctl cluster health_check default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 -* 每个节点执行health_check.sh - -* 单个节点健康检查 -```bash -iotdbctl cluster health_check default_cluster -N datanode_1 -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`datanode_servers`配置信息 -* datanode1 执行health_check.sh - - -### 集群停机备份 -```bash -iotdbctl cluster backup default_cluster -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`confignode_servers`和`datanode_servers`配置信息 -* 每个节点执行backup.sh - -* 单个节点健康检查 -```bash -iotdbctl cluster backup default_cluster -N datanode_1 -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`datanode_servers`配置信息 -* datanode1 执行backup.sh - -说明:多个节点部署到单台机器,只支持 quick 模式 - -### 集群元数据导入 - -```bash -iotdbctl cluster importschema default_cluster -N datanode1 -param "-s ./dump0.csv -fd ./failed/ -lpf 10000" -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`datanode_servers`配置信息 -* datanode1 执行元数据导入import-schema.sh - -其中 -param的参数如下: - -| 命令 | 功能 | 是否必填 | -|-----|---------------------------------|------| -| -s |指定想要导入的数据文件,这里可以指定文件或者文件夹。如果指定的是文件夹,将会把文件夹中所有的后缀为csv的文件进行批量导入。 | 是 | -| -fd |指定一个目录来存放导入失败的文件,如果没有指定这个参数,失败的文件将会被保存到源数据的目录中,文件名为是源文件名加上.failed的后缀。 | 否 | -| -lpf |用于指定每个导入失败文件写入数据的行数,默认值为10000 | 否 | - - - -### 集群元数据导出 - -```bash -iotdbctl cluster exportschema default_cluster -N datanode1 -param "-t ./ -pf ./pattern.txt -lpf 10 -t 10000" -``` -* 根据 cluster-name 找到默认位置的 yaml 文件,获取`datanode_servers`配置信息 -* datanode1 执行元数据导入export-schema.sh - -其中 -param的参数如下: - -| 命令 | 功能 | 是否必填 | -|-----|------------------------------------------------------------|------| -| -t | 为导出的CSV文件指定输出路径 | 是 | -| -path |指定导出元数据的path pattern,指定该参数后会忽略-s参数例如:root.stock.** | 否 | -| -pf |如果未指定-path,则需指定该参数,指定查询元数据路径所在文件路径,支持 txt 文件格式,每个待导出的路径为一行。 | 否 | -| -lpf |指定导出的dump文件最大行数,默认值为10000。 | 否 | -| -timeout |指定session查询时的超时时间,单位为ms | 否 | - - - -### 集群部署工具样例介绍 -在集群部署工具安装目录中config/example 下面有3个yaml样例,如果需要可以复制到config 中进行修改即可 - -| 名称 | 说明 | -|-----------------------------|------------------------------------------------| -| default\_1c1d.yaml | 1个confignode和1个datanode 配置样例 | -| default\_3c3d.yaml | 3个confignode和3个datanode 配置样例 | -| default\_3c3d\_grafa\_prome | 3个confignode和3个datanode、Grafana、Prometheus配置样例 | - - -## 数据文件夹概览工具 - -IoTDB数据文件夹概览工具用于打印出数据文件夹的结构概览信息,工具位置为 tools/tsfile/print-iotdb-data-dir。 - -### 用法 - -- Windows: - -```bash -.\print-iotdb-data-dir.bat (<输出结果的存储路径>) -``` - -- Linux or MacOs: - -```shell -./print-iotdb-data-dir.sh (<输出结果的存储路径>) -``` - -注意:如果没有设置输出结果的存储路径, 将使用相对路径"IoTDB_data_dir_overview.txt"作为默认值。 - -### 示例 - -以Windows系统为例: - -`````````````````````````bash -.\print-iotdb-data-dir.bat D:\github\master\iotdb\data\datanode\data -```````````````````````` -Starting Printing the IoTDB Data Directory Overview -```````````````````````` -output save path:IoTDB_data_dir_overview.txt -data dir num:1 -143 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties, use the default configs. -|============================================================== -|D:\github\master\iotdb\data\datanode\data -|--sequence -| |--root.redirect0 -| | |--1 -| | | |--0 -| |--root.redirect1 -| | |--2 -| | | |--0 -| |--root.redirect2 -| | |--3 -| | | |--0 -| |--root.redirect3 -| | |--4 -| | | |--0 -| |--root.redirect4 -| | |--5 -| | | |--0 -| |--root.redirect5 -| | |--6 -| | | |--0 -| |--root.sg1 -| | |--0 -| | | |--0 -| | | |--2760 -|--unsequence -|============================================================== -````````````````````````` - -## TsFile概览工具 - -TsFile概览工具用于以概要模式打印出一个TsFile的内容,工具位置为 tools/tsfile/print-tsfile。 - -### 用法 - -- Windows: - -```bash -.\print-tsfile-sketch.bat (<输出结果的存储路径>) -``` - -- Linux or MacOs: - -```shell -./print-tsfile-sketch.sh (<输出结果的存储路径>) -``` - -注意:如果没有设置输出结果的存储路径, 将使用相对路径"TsFile_sketch_view.txt"作为默认值。 - -### 示例 - -以Windows系统为例: - -`````````````````````````bash -.\print-tsfile.bat D:\github\master\1669359533965-1-0-0.tsfile D:\github\master\sketch.txt -```````````````````````` -Starting Printing the TsFile Sketch -```````````````````````` -TsFile path:D:\github\master\1669359533965-1-0-0.tsfile -Sketch save path:D:\github\master\sketch.txt -148 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties, use the default configs. --------------------------------- TsFile Sketch -------------------------------- -file path: D:\github\master\1669359533965-1-0-0.tsfile -file length: 2974 - - POSITION| CONTENT - -------- ------- - 0| [magic head] TsFile - 6| [version number] 3 -||||||||||||||||||||| [Chunk Group] of root.sg1.d1, num of Chunks:3 - 7| [Chunk Group Header] - | [marker] 0 - | [deviceID] root.sg1.d1 - 20| [Chunk] of root.sg1.d1.s1, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9032452783138882770,maxValue:9117677033041335123,firstValue:7068645577795875906,lastValue:-5833792328174747265,sumValue:5.795959009889246E19] - | [chunk header] marker=5, measurementID=s1, dataSize=864, dataType=INT64, compressionType=SNAPPY, encodingType=RLE - | [page] UncompressedSize:862, CompressedSize:860 - 893| [Chunk] of root.sg1.d1.s2, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-8806861312244965718,maxValue:9192550740609853234,firstValue:1150295375739457693,lastValue:-2839553973758938646,sumValue:8.2822564314572677E18] - | [chunk header] marker=5, measurementID=s2, dataSize=864, dataType=INT64, compressionType=SNAPPY, encodingType=RLE - | [page] UncompressedSize:862, CompressedSize:860 - 1766| [Chunk] of root.sg1.d1.s3, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9076669333460323191,maxValue:9175278522960949594,firstValue:2537897870994797700,lastValue:7194625271253769397,sumValue:-2.126008424849926E19] - | [chunk header] marker=5, measurementID=s3, dataSize=864, dataType=INT64, compressionType=SNAPPY, encodingType=RLE - | [page] UncompressedSize:862, CompressedSize:860 -||||||||||||||||||||| [Chunk Group] of root.sg1.d1 ends - 2656| [marker] 2 - 2657| [TimeseriesIndex] of root.sg1.d1.s1, tsDataType:INT64, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9032452783138882770,maxValue:9117677033041335123,firstValue:7068645577795875906,lastValue:-5833792328174747265,sumValue:5.795959009889246E19] - | [ChunkIndex] offset=20 - 2728| [TimeseriesIndex] of root.sg1.d1.s2, tsDataType:INT64, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-8806861312244965718,maxValue:9192550740609853234,firstValue:1150295375739457693,lastValue:-2839553973758938646,sumValue:8.2822564314572677E18] - | [ChunkIndex] offset=893 - 2799| [TimeseriesIndex] of root.sg1.d1.s3, tsDataType:INT64, startTime: 1669359533948 endTime: 1669359534047 count: 100 [minValue:-9076669333460323191,maxValue:9175278522960949594,firstValue:2537897870994797700,lastValue:7194625271253769397,sumValue:-2.126008424849926E19] - | [ChunkIndex] offset=1766 - 2870| [IndexOfTimerseriesIndex Node] type=LEAF_MEASUREMENT - | - | -||||||||||||||||||||| [TsFileMetadata] begins - 2891| [IndexOfTimerseriesIndex Node] type=LEAF_DEVICE - | - | - | [meta offset] 2656 - | [bloom filter] bit vector byte array length=31, filterSize=256, hashFunctionSize=5 -||||||||||||||||||||| [TsFileMetadata] ends - 2964| [TsFileMetadataSize] 73 - 2968| [magic tail] TsFile - 2974| END of TsFile ----------------------------- IndexOfTimerseriesIndex Tree ----------------------------- - [MetadataIndex:LEAF_DEVICE] - └──────[root.sg1.d1,2870] - [MetadataIndex:LEAF_MEASUREMENT] - └──────[s1,2657] ----------------------------------- TsFile Sketch End ---------------------------------- -````````````````````````` - -解释: - -- 以"|"为分隔,左边是在TsFile文件中的实际位置,右边是梗概内容。 -- "|||||||||||||||||||||"是为增强可读性而添加的导引信息,不是TsFile中实际存储的数据。 -- 最后打印的"IndexOfTimerseriesIndex Tree"是对TsFile文件末尾的元数据索引树的重新整理打印,便于直观理解,不是TsFile中存储的实际数据。 - -## TsFile Resource概览工具 - -TsFile resource概览工具用于打印出TsFile resource文件的内容,工具位置为 tools/tsfile/print-tsfile-resource-files。 - -### 用法 - -- Windows: - -```bash -.\print-tsfile-resource-files.bat -``` - -- Linux or MacOs: - -``` -./print-tsfile-resource-files.sh -``` - -### 示例 - -以Windows系统为例: - -`````````````````````````bash -.\print-tsfile-resource-files.bat D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0 -```````````````````````` -Starting Printing the TsFileResources -```````````````````````` -147 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties, use the default configs. -230 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-common.properties, use default configuration -231 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-common.properties from any of the known sources. -233 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-datanode.properties, use default configuration -237 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-datanode.properties from any of the known sources. -Analyzing D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile ... - -Resource plan index range [9223372036854775807, -9223372036854775808] -device root.sg1.d1, start time 0 (1970-01-01T08:00+08:00[GMT+08:00]), end time 99 (1970-01-01T08:00:00.099+08:00[GMT+08:00]) - -Analyzing the resource file folder D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0 finished. -````````````````````````` - -`````````````````````````bash -.\print-tsfile-resource-files.bat D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile.resource -```````````````````````` -Starting Printing the TsFileResources -```````````````````````` -178 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-common.properties, use default configuration -186 [main] WARN o.a.i.t.c.conf.TSFileDescriptor - not found iotdb-common.properties, use the default configs. -187 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-common.properties from any of the known sources. -188 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Cannot find IOTDB_HOME or IOTDB_CONF environment variable when loading config file iotdb-datanode.properties, use default configuration -192 [main] WARN o.a.iotdb.db.conf.IoTDBDescriptor - Couldn't load the configuration iotdb-datanode.properties from any of the known sources. -Analyzing D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile ... - -Resource plan index range [9223372036854775807, -9223372036854775808] -device root.sg1.d1, start time 0 (1970-01-01T08:00+08:00[GMT+08:00]), end time 99 (1970-01-01T08:00:00.099+08:00[GMT+08:00]) - -Analyzing the resource file D:\github\master\iotdb\data\datanode\data\sequence\root.sg1\0\0\1669359533489-1-0-0.tsfile.resource finished. -````````````````````````` diff --git a/src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_apache.md b/src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_apache.md deleted file mode 100644 index f415ebea4..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_apache.md +++ /dev/null @@ -1,168 +0,0 @@ - - - -# 监控工具 - -## 监控指标的 Prometheus 映射关系 - -> 对于 Metric Name 为 name, Tags 为 K1=V1, ..., Kn=Vn 的监控指标有如下映射,其中 value 为具体值 - -| 监控指标类型 | 映射关系 | -| ---------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Counter | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value | -| AutoGauge、Gauge | name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value | -| Histogram | name_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.5"} value
name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.99"} value | -| Rate | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m1"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m5"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m15"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="mean"} value | -| Timer | name_seconds_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_seconds_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_seconds_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.5"} value value
name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.99"} value | - -## 修改配置文件 - -1) 以 DataNode 为例,修改 iotdb-datanode.properties 配置文件如下: - -```properties -dn_metric_reporter_list=PROMETHEUS -dn_metric_level=CORE -dn_metric_prometheus_reporter_port=9091 -``` - -2) 启动 IoTDB DataNode - -3) 打开浏览器或者用```curl``` 访问 ```http://servier_ip:9091/metrics```, 就能得到如下 metric 数据: - -``` -... -# HELP file_count -# TYPE file_count gauge -file_count{name="wal",} 0.0 -file_count{name="unseq",} 0.0 -file_count{name="seq",} 2.0 -... -``` - -## Prometheus + Grafana - -如上所示,IoTDB 对外暴露出标准的 Prometheus 格式的监控指标数据,可以使用 Prometheus 采集并存储监控指标,使用 Grafana -可视化监控指标。 - -IoTDB、Prometheus、Grafana三者的关系如下图所示: - -![iotdb_prometheus_grafana](/img/UserGuide/System-Tools/Metrics/iotdb_prometheus_grafana.png) - -1. IoTDB在运行过程中持续收集监控指标数据。 -2. Prometheus以固定的间隔(可配置)从IoTDB的HTTP接口拉取监控指标数据。 -3. Prometheus将拉取到的监控指标数据存储到自己的TSDB中。 -4. Grafana以固定的间隔(可配置)从Prometheus查询监控指标数据并绘图展示。 - -从交互流程可以看出,我们需要做一些额外的工作来部署和配置Prometheus和Grafana。 - -比如,你可以对Prometheus进行如下的配置(部分参数可以自行调整)来从IoTDB获取监控数据 - -```yaml -job_name: pull-metrics -honor_labels: true -honor_timestamps: true -scrape_interval: 15s -scrape_timeout: 10s -metrics_path: /metrics -scheme: http -follow_redirects: true -static_configs: - - targets: - - localhost:9091 -``` - -更多细节可以参考下面的文档: - -[Prometheus安装使用文档](https://prometheus.io/docs/prometheus/latest/getting_started/) - -[Prometheus从HTTP接口拉取metrics数据的配置说明](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) - -[Grafana安装使用文档](https://grafana.com/docs/grafana/latest/getting-started/getting-started/) - -[Grafana从Prometheus查询数据并绘图的文档](https://prometheus.io/docs/visualization/grafana/#grafana-support-for-prometheus) - -## Apache IoTDB Dashboard - -`Apache IoTDB Dashboard`是 IoTDB 企业版的配套产品,支持统一集中式运维管理,可通过一个监控面板监控多个集群。你可以联系商务获取到 Dashboard 的 Json文件。 - - -![Apache IoTDB Dashboard](/img/%E7%9B%91%E6%8E%A7%20default%20cluster.png) - -![Apache IoTDB Dashboard](/img/%E7%9B%91%E6%8E%A7%20cluster2.png) - - -### 集群概览 - -可以监控包括但不限于: -- 集群总CPU核数、总内存空间、总硬盘空间 -- 集群包含多少个ConfigNode与DataNode -- 集群启动时长 -- 集群写入速度 -- 集群各节点当前CPU、内存、磁盘使用率 -- 分节点的信息 - -![](/img/%E7%9B%91%E6%8E%A7%20%E6%A6%82%E8%A7%88.png) - -### 数据写入 - -可以监控包括但不限于: -- 写入平均耗时、耗时中位数、99%分位耗时 -- WAL文件数量与尺寸 -- 节点 WAL flush SyncBuffer 耗时 - -![](/img/%E7%9B%91%E6%8E%A7%20%E5%86%99%E5%85%A5.png) - -### 数据查询 - -可以监控包括但不限于: -- 节点查询加载时间序列元数据耗时 -- 节点查询读取时间序列耗时 -- 节点查询修改时间序列元数据耗时 -- 节点查询加载Chunk元数据列表耗时 -- 节点查询修改Chunk元数据耗时 -- 节点查询按照Chunk元数据过滤耗时 -- 节点查询构造Chunk Reader耗时的平均值 - -![](/img/%E7%9B%91%E6%8E%A7%20%E6%9F%A5%E8%AF%A2.png) - -### 存储引擎 - -可以监控包括但不限于: -- 分类型的文件数量、大小 -- 处于各阶段的TsFile数量、大小 -- 各类任务的数量与耗时 - -![](/img/%E7%9B%91%E6%8E%A7%20%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E.png) - -### 系统监控 - -可以监控包括但不限于: -- 系统内存、交换内存、进程内存 -- 磁盘空间、文件数、文件尺寸 -- JVM GC时间占比、分类型的GC次数、GC数据量、各年代的堆内存占用 -- 网络传输速率、包发送速率 - -![](/img/%E7%9B%91%E6%8E%A7%20%E7%B3%BB%E7%BB%9F%20%E5%86%85%E5%AD%98%E4%B8%8E%E7%A1%AC%E7%9B%98.png) - -![](/img/%E7%9B%91%E6%8E%A7%20%E7%B3%BB%E7%BB%9Fjvm.png) - -![](/img/%E7%9B%91%E6%8E%A7%20%E7%B3%BB%E7%BB%9F%20%E7%BD%91%E7%BB%9C.png) diff --git a/src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_timecho.md b/src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_timecho.md deleted file mode 100644 index 35bd0fac2..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Tools-System/Monitor-Tool_timecho.md +++ /dev/null @@ -1,168 +0,0 @@ - - - -# 监控工具 - -## 监控指标的 Prometheus 映射关系 - -> 对于 Metric Name 为 name, Tags 为 K1=V1, ..., Kn=Vn 的监控指标有如下映射,其中 value 为具体值 - -| 监控指标类型 | 映射关系 | -| ---------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Counter | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value | -| AutoGauge、Gauge | name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value | -| Histogram | name_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.5"} value
name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.99"} value | -| Rate | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m1"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m5"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m15"} value
name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="mean"} value | -| Timer | name_seconds_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_seconds_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_seconds_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value
name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.5"} value value
name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.99"} value | - -## 修改配置文件 - -1) 以 DataNode 为例,修改 iotdb-datanode.properties 配置文件如下: - -```properties -dn_metric_reporter_list=PROMETHEUS -dn_metric_level=CORE -dn_metric_prometheus_reporter_port=9091 -``` - -2) 启动 IoTDB DataNode - -3) 打开浏览器或者用```curl``` 访问 ```http://servier_ip:9091/metrics```, 就能得到如下 metric 数据: - -``` -... -# HELP file_count -# TYPE file_count gauge -file_count{name="wal",} 0.0 -file_count{name="unseq",} 0.0 -file_count{name="seq",} 2.0 -... -``` - -## Prometheus + Grafana - -如上所示,IoTDB 对外暴露出标准的 Prometheus 格式的监控指标数据,可以使用 Prometheus 采集并存储监控指标,使用 Grafana -可视化监控指标。 - -IoTDB、Prometheus、Grafana三者的关系如下图所示: - -![iotdb_prometheus_grafana](/img/UserGuide/System-Tools/Metrics/iotdb_prometheus_grafana.png) - -1. IoTDB在运行过程中持续收集监控指标数据。 -2. Prometheus以固定的间隔(可配置)从IoTDB的HTTP接口拉取监控指标数据。 -3. Prometheus将拉取到的监控指标数据存储到自己的TSDB中。 -4. Grafana以固定的间隔(可配置)从Prometheus查询监控指标数据并绘图展示。 - -从交互流程可以看出,我们需要做一些额外的工作来部署和配置Prometheus和Grafana。 - -比如,你可以对Prometheus进行如下的配置(部分参数可以自行调整)来从IoTDB获取监控数据 - -```yaml -job_name: pull-metrics -honor_labels: true -honor_timestamps: true -scrape_interval: 15s -scrape_timeout: 10s -metrics_path: /metrics -scheme: http -follow_redirects: true -static_configs: - - targets: - - localhost:9091 -``` - -更多细节可以参考下面的文档: - -[Prometheus安装使用文档](https://prometheus.io/docs/prometheus/latest/getting_started/) - -[Prometheus从HTTP接口拉取metrics数据的配置说明](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) - -[Grafana安装使用文档](https://grafana.com/docs/grafana/latest/getting-started/getting-started/) - -[Grafana从Prometheus查询数据并绘图的文档](https://prometheus.io/docs/visualization/grafana/#grafana-support-for-prometheus) - -## Apache IoTDB Dashboard - -我们提供了Apache IoTDB Dashboard,支持统一集中式运维管理,可通过一个监控面板监控多个集群。 - -![Apache IoTDB Dashboard](/img/%E7%9B%91%E6%8E%A7%20default%20cluster.png) - -![Apache IoTDB Dashboard](/img/%E7%9B%91%E6%8E%A7%20cluster2.png) - -你可以在企业版中获取到 Dashboard 的 Json文件。 - -### 集群概览 - -可以监控包括但不限于: -- 集群总CPU核数、总内存空间、总硬盘空间 -- 集群包含多少个ConfigNode与DataNode -- 集群启动时长 -- 集群写入速度 -- 集群各节点当前CPU、内存、磁盘使用率 -- 分节点的信息 - -![](/img/%E7%9B%91%E6%8E%A7%20%E6%A6%82%E8%A7%88.png) - -### 数据写入 - -可以监控包括但不限于: -- 写入平均耗时、耗时中位数、99%分位耗时 -- WAL文件数量与尺寸 -- 节点 WAL flush SyncBuffer 耗时 - -![](/img/%E7%9B%91%E6%8E%A7%20%E5%86%99%E5%85%A5.png) - -### 数据查询 - -可以监控包括但不限于: -- 节点查询加载时间序列元数据耗时 -- 节点查询读取时间序列耗时 -- 节点查询修改时间序列元数据耗时 -- 节点查询加载Chunk元数据列表耗时 -- 节点查询修改Chunk元数据耗时 -- 节点查询按照Chunk元数据过滤耗时 -- 节点查询构造Chunk Reader耗时的平均值 - -![](/img/%E7%9B%91%E6%8E%A7%20%E6%9F%A5%E8%AF%A2.png) - -### 存储引擎 - -可以监控包括但不限于: -- 分类型的文件数量、大小 -- 处于各阶段的TsFile数量、大小 -- 各类任务的数量与耗时 - -![](/img/%E7%9B%91%E6%8E%A7%20%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E.png) - -### 系统监控 - -可以监控包括但不限于: -- 系统内存、交换内存、进程内存 -- 磁盘空间、文件数、文件尺寸 -- JVM GC时间占比、分类型的GC次数、GC数据量、各年代的堆内存占用 -- 网络传输速率、包发送速率 - -![](/img/%E7%9B%91%E6%8E%A7%20%E7%B3%BB%E7%BB%9F%20%E5%86%85%E5%AD%98%E4%B8%8E%E7%A1%AC%E7%9B%98.png) - -![](/img/%E7%9B%91%E6%8E%A7%20%E7%B3%BB%E7%BB%9Fjvm.png) - -![](/img/%E7%9B%91%E6%8E%A7%20%E7%B3%BB%E7%BB%9F%20%E7%BD%91%E7%BB%9C.png) diff --git a/src/zh/UserGuide/V1.3.0-2/Tools-System/Workbench_timecho.md b/src/zh/UserGuide/V1.3.0-2/Tools-System/Workbench_timecho.md deleted file mode 100644 index 50b3a988d..000000000 --- a/src/zh/UserGuide/V1.3.0-2/Tools-System/Workbench_timecho.md +++ /dev/null @@ -1,31 +0,0 @@ -# 可视化控制台 -## 第1章 产品介绍 -IoTDB可视化控制台是在IoTDB企业版时序数据库基础上针对工业场景的实时数据收集、存储与分析一体化的数据管理场景开发的扩展组件,旨在为用户提供高效、可靠的实时数据存储和查询解决方案。它具有体量轻、性能高、易使用的特点,完美对接 Hadoop 与 Spark 生态,适用于工业物联网应用中海量时间序列数据高速写入和复杂分析查询的需求。 - -## 第2章 使用说明 -IoTDB的可视化控制台包含以下功能模块: -| **功能模块** | **功能说明** | -| ------------ | ------------------------------------------------------------ | -| 实例管理 | 支持对连接实例进行统一管理,支持创建、编辑和删除,同时可以可视化呈现多实例的关系,帮助客户更清晰的管理多数据库实例 | -| 首页 | 支持查看数据库实例中各节点的服务运行状态(如是否激活、是否运行、IP信息等),支持查看集群、ConfigNode、DataNode运行监控状态,对数据库运行健康度进行监控,判断实例是否有潜在运行问题 | -| 测点列表 | 支持直接查看实例中的测点信息,包括所在数据库信息(如数据库名称、数据保存时间、设备数量等),及测点信息(测点名称、数据类型、压缩编码等),同时支持单条或批量创建、导出、删除测点 | -| 数据模型 | 支持查看各层级从属关系,将层级模型直观展示 | -| 数据查询 | 支持对常用数据查询场景提供界面式查询交互,并对查询数据进行批量导入、导出 | -| 统计查询 | 支持对常用数据统计场景提供界面式查询交互,如最大值、最小值、平均值、总和的结果输出。 | -| SQL操作 | 支持对数据库SQL进行界面式交互,单条或多条语句执行,结果的展示和导出 | -| 趋势 | 支持一键可视化查看数据整体趋势,对选中测点进行实时&历史数据绘制,观察测点实时&历史运行状态 | -| 分析 | 支持将数据通过不同的分析方式(如傅里叶变换等)进行可视化展示 | -| 视图 | 支持通过界面来查看视图名称、视图描述、结果测点以及表达式等信息,同时还可以通过界面交互快速的创建、编辑、删除视图 | -| 数据同步 | 支持对数据库间的数据同步任务进行直观创建、查看、管理,支持直接查看任务运行状态、同步数据和目标地址,还可以通过界面实时观察到同步状态的监控指标变化 | -| 权限管理 | 支持对权限进行界面管控,用于管理和控制数据库用户访问和操作数据库的权限 | -| 审计日志 | 支持对用户在数据库上的操作进行详细记录,包括DDL、DML和查询操作。帮助用户追踪和识别潜在的安全威胁、数据库错误和滥用行为 | - -主要功能展示: -* 首页 -![首页.png](/img/%E9%A6%96%E9%A1%B5.png) -* 测点列表 -![测点列表.png](/img/workbench-1.png) -* 数据查询 -![数据查询.png](/img/%E6%95%B0%E6%8D%AE%E6%9F%A5%E8%AF%A2.png) -* 趋势 -![历史趋势.png](/img/%E5%8E%86%E5%8F%B2%E8%B6%8B%E5%8A%BF.png) \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Database-Programming.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Database-Programming.md deleted file mode 100644 index 1e61cce17..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Database-Programming.md +++ /dev/null @@ -1,1032 +0,0 @@ - - -# 数据库编程 -## 触发器 -### 使用说明 - -触发器提供了一种侦听序列数据变动的机制。配合用户自定义逻辑,可完成告警、数据转发等功能。 - -触发器基于 Java 反射机制实现。用户通过简单实现 Java 接口,即可实现数据侦听。IoTDB 允许用户动态注册、卸载触发器,在注册、卸载期间,无需启停服务器。 - -#### 侦听模式 - -IoTDB 的单个触发器可用于侦听符合特定模式的时间序列的数据变动,如时间序列 root.sg.a 上的数据变动,或者符合路径模式 root.**.a 的时间序列上的数据变动。您在注册触发器时可以通过 SQL 语句指定触发器侦听的路径模式。 - -#### 触发器类型 - -目前触发器分为两类,您在注册触发器时可以通过 SQL 语句指定类型: - -- 有状态的触发器。该类触发器的执行逻辑可能依赖前后的多条数据,框架会将不同节点写入的数据汇总到同一个触发器实例进行计算,来保留上下文信息,通常用于采样或者统计一段时间的数据聚合信息。集群中只有一个节点持有有状态触发器的实例。 -- 无状态的触发器。触发器的执行逻辑只和当前输入的数据有关,框架无需将不同节点的数据汇总到同一个触发器实例中,通常用于单行数据的计算和异常检测等。集群中每个节点均持有无状态触发器的实例。 - -#### 触发时机 - -触发器的触发时机目前有两种,后续会拓展其它触发时机。您在注册触发器时可以通过 SQL 语句指定触发时机: - -- BEFORE INSERT,即在数据持久化之前触发。请注意,目前触发器并不支持数据清洗,不会对要持久化的数据本身进行变动。 -- AFTER INSERT,即在数据持久化之后触发。 - -### 编写触发器 - -#### 触发器依赖 - -触发器的逻辑需要您编写 Java 类进行实现。 -在编写触发器逻辑时,需要使用到下面展示的依赖。如果您使用 [Maven](http://search.maven.org/),则可以直接从 [Maven 库](http://search.maven.org/)中搜索到它们。请注意选择和目标服务器版本相同的依赖版本。 - -``` xml - - org.apache.iotdb - iotdb-server - 1.0.0 - provided - -``` - -#### 接口说明 - -编写一个触发器需要实现 `org.apache.iotdb.trigger.api.Trigger` 类。 - -```java -import org.apache.iotdb.trigger.api.enums.FailureStrategy; -import org.apache.iotdb.tsfile.write.record.Tablet; - -public interface Trigger { - - /** - * This method is mainly used to validate {@link TriggerAttributes} before calling {@link - * Trigger#onCreate(TriggerAttributes)}. - * - * @param attributes TriggerAttributes - * @throws Exception e - */ - default void validate(TriggerAttributes attributes) throws Exception {} - - /** - * This method will be called when creating a trigger after validation. - * - * @param attributes TriggerAttributes - * @throws Exception e - */ - default void onCreate(TriggerAttributes attributes) throws Exception {} - - /** - * This method will be called when dropping a trigger. - * - * @throws Exception e - */ - default void onDrop() throws Exception {} - - /** - * When restarting a DataNode, Triggers that have been registered will be restored and this method - * will be called during the process of restoring. - * - * @throws Exception e - */ - default void restore() throws Exception {} - - /** - * Overrides this method to set the expected FailureStrategy, {@link FailureStrategy#OPTIMISTIC} - * is the default strategy. - * - * @return {@link FailureStrategy} - */ - default FailureStrategy getFailureStrategy() { - return FailureStrategy.OPTIMISTIC; - } - - /** - * @param tablet see {@link Tablet} for detailed information of data structure. Data that is - * inserted will be constructed as a Tablet and you can define process logic with {@link - * Tablet}. - * @return true if successfully fired - * @throws Exception e - */ - default boolean fire(Tablet tablet) throws Exception { - return true; - } -} -``` - -该类主要提供了两类编程接口:**生命周期相关接口**和**数据变动侦听相关接口**。该类中所有的接口都不是必须实现的,当您不实现它们时,它们不会对流经的数据操作产生任何响应。您可以根据实际需要,只实现其中若干接口。 - -下面是所有可供用户进行实现的接口的说明。 - -##### 生命周期相关接口 - -| 接口定义 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| *default void validate(TriggerAttributes attributes) throws Exception {}* | 用户在使用 `CREATE TRIGGER` 语句创建触发器时,可以指定触发器需要使用的参数,该接口会用于验证参数正确性。 | -| *default void onCreate(TriggerAttributes attributes) throws Exception {}* | 当您使用`CREATE TRIGGER`语句创建触发器后,该接口会被调用一次。在每一个触发器实例的生命周期内,该接口会且仅会被调用一次。该接口主要有如下作用:帮助用户解析 SQL 语句中的自定义属性(使用`TriggerAttributes`)。 可以创建或申请资源,如建立外部链接、打开文件等。 | -| *default void onDrop() throws Exception {}* | 当您使用`DROP TRIGGER`语句删除触发器后,该接口会被调用。在每一个触发器实例的生命周期内,该接口会且仅会被调用一次。该接口主要有如下作用:可以进行资源释放的操作。可以用于持久化触发器计算的结果。 | -| *default void restore() throws Exception {}* | 当重启 DataNode 时,集群会恢复 DataNode 上已经注册的触发器实例,在此过程中会为该 DataNode 上的有状态触发器调用一次该接口。有状态触发器实例所在的 DataNode 宕机后,集群会在另一个可用 DataNode 上恢复该触发器的实例,在此过程中会调用一次该接口。该接口可以用于自定义恢复逻辑。 | - -##### 数据变动侦听相关接口 - -###### 侦听接口 - -```java - /** - * @param tablet see {@link Tablet} for detailed information of data structure. Data that is - * inserted will be constructed as a Tablet and you can define process logic with {@link - * Tablet}. - * @return true if successfully fired - * @throws Exception e - */ - default boolean fire(Tablet tablet) throws Exception { - return true; - } -``` - -数据变动时,触发器以 Tablet 作为触发操作的单位。您可以通过 Tablet 获取相应序列的元数据和数据,然后进行相应的触发操作,触发成功则返回值应当为 true。该接口返回 false 或是抛出异常我们均认为触发失败。在触发失败时,我们会根据侦听策略接口进行相应的操作。 - -进行一次 INSERT 操作时,对于其中的每条时间序列,我们会检测是否有侦听该路径模式的触发器,然后将符合同一个触发器所侦听的路径模式的时间序列数据组装成一个新的 Tablet 用于触发器的 fire 接口。可以理解成: - -```java -Map> pathToTriggerListMap => Map -``` - -**请注意,目前我们不对触发器的触发顺序有任何保证。** - -下面是示例: - -假设有三个触发器,触发器的触发时机均为 BEFORE INSERT - -- 触发器 Trigger1 侦听路径模式:root\.sg.* -- 触发器 Trigger2 侦听路径模式:root.sg.a -- 触发器 Trigger3 侦听路径模式:root.sg.b - -写入语句: - -```sql -insert into root.sg(time, a, b) values (1, 1, 1); -``` - -序列 root.sg.a 匹配 Trigger1 和 Trigger2,序列 root.sg.b 匹配 Trigger1 和 Trigger3,那么: - -- root.sg.a 和 root.sg.b 的数据会被组装成一个新的 tablet1,在相应的触发时机进行 Trigger1.fire(tablet1) -- root.sg.a 的数据会被组装成一个新的 tablet2,在相应的触发时机进行 Trigger2.fire(tablet2) -- root.sg.b 的数据会被组装成一个新的 tablet3,在相应的触发时机进行 Trigger3.fire(tablet3) - -###### 侦听策略接口 - -在触发器触发失败时,我们会根据侦听策略接口设置的策略进行相应的操作,您可以通过下述接口设置 `org.apache.iotdb.trigger.api.enums.FailureStrategy`,目前有乐观和悲观两种策略: - -- 乐观策略:触发失败的触发器不影响后续触发器的触发,也不影响写入流程,即我们不对触发失败涉及的序列做额外处理,仅打日志记录失败,最后返回用户写入数据成功,但触发部分失败。 -- 悲观策略:失败触发器影响后续所有 Pipeline 的处理,即我们认为该 Trigger 触发失败会导致后续所有触发流程不再进行。如果该触发器的触发时机为 BEFORE INSERT,那么写入也不再进行,直接返回写入失败。 - -```java - /** - * Overrides this method to set the expected FailureStrategy, {@link FailureStrategy#OPTIMISTIC} - * is the default strategy. - * - * @return {@link FailureStrategy} - */ - default FailureStrategy getFailureStrategy() { - return FailureStrategy.OPTIMISTIC; - } -``` - -您可以参考下图辅助理解,其中 Trigger1 配置采用乐观策略,Trigger2 配置采用悲观策略。Trigger1 和 Trigger2 的触发时机是 BEFORE INSERT,Trigger3 和 Trigger4 的触发时机是 AFTER INSERT。 正常执行流程如下: - - - - - - -#### 示例 - -如果您使用 [Maven](http://search.maven.org/),可以参考我们编写的示例项目 trigger-example。您可以在 [这里](https://github.com/apache/iotdb/tree/master/example/trigger) 找到它。后续我们会加入更多的示例项目供您参考。 - -下面是其中一个示例项目的代码: - -```java -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.iotdb.trigger; - -import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerConfiguration; -import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerEvent; -import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerHandler; -import org.apache.iotdb.trigger.api.Trigger; -import org.apache.iotdb.trigger.api.TriggerAttributes; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.write.record.Tablet; -import org.apache.iotdb.tsfile.write.schema.MeasurementSchema; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; - -public class ClusterAlertingExample implements Trigger { - private static final Logger LOGGER = LoggerFactory.getLogger(ClusterAlertingExample.class); - - private final AlertManagerHandler alertManagerHandler = new AlertManagerHandler(); - - private final AlertManagerConfiguration alertManagerConfiguration = - new AlertManagerConfiguration("http://127.0.0.1:9093/api/v2/alerts"); - - private String alertname; - - private final HashMap labels = new HashMap<>(); - - private final HashMap annotations = new HashMap<>(); - - @Override - public void onCreate(TriggerAttributes attributes) throws Exception { - alertname = "alert_test"; - - labels.put("series", "root.ln.wf01.wt01.temperature"); - labels.put("value", ""); - labels.put("severity", ""); - - annotations.put("summary", "high temperature"); - annotations.put("description", "{{.alertname}}: {{.series}} is {{.value}}"); - - alertManagerHandler.open(alertManagerConfiguration); - } - - @Override - public void onDrop() throws IOException { - alertManagerHandler.close(); - } - - @Override - public boolean fire(Tablet tablet) throws Exception { - List measurementSchemaList = tablet.getSchemas(); - for (int i = 0, n = measurementSchemaList.size(); i < n; i++) { - if (measurementSchemaList.get(i).getType().equals(TSDataType.DOUBLE)) { - // for example, we only deal with the columns of Double type - double[] values = (double[]) tablet.values[i]; - for (double value : values) { - if (value > 100.0) { - LOGGER.info("trigger value > 100"); - labels.put("value", String.valueOf(value)); - labels.put("severity", "critical"); - AlertManagerEvent alertManagerEvent = - new AlertManagerEvent(alertname, labels, annotations); - alertManagerHandler.onEvent(alertManagerEvent); - } else if (value > 50.0) { - LOGGER.info("trigger value > 50"); - labels.put("value", String.valueOf(value)); - labels.put("severity", "warning"); - AlertManagerEvent alertManagerEvent = - new AlertManagerEvent(alertname, labels, annotations); - alertManagerHandler.onEvent(alertManagerEvent); - } - } - } - } - return true; - } -} -``` -### 管理触发器 - -您可以通过 SQL 语句注册和卸载一个触发器实例,您也可以通过 SQL 语句查询到所有已经注册的触发器。 - -**我们建议您在注册触发器时停止写入。** - -#### 注册触发器 - -触发器可以注册在任意路径模式上。被注册有触发器的序列将会被触发器侦听,当序列上有数据变动时,触发器中对应的触发方法将会被调用。 - -注册一个触发器可以按如下流程进行: - -1. 按照编写触发器章节的说明,实现一个完整的 Trigger 类,假定这个类的全类名为 `org.apache.iotdb.trigger.ClusterAlertingExample` -2. 将项目打成 JAR 包。 -3. 使用 SQL 语句注册该触发器。注册过程中会仅只会调用一次触发器的 `validate` 和 `onCreate` 接口,具体请参考编写触发器章节。 - -完整 SQL 语法如下: - -```sql -// Create Trigger -createTrigger - : CREATE triggerType TRIGGER triggerName=identifier triggerEventClause ON pathPattern AS className=STRING_LITERAL uriClause? triggerAttributeClause? - ; - -triggerType - : STATELESS | STATEFUL - ; - -triggerEventClause - : (BEFORE | AFTER) INSERT - ; - - : USING URI uri - ; - -uri - : STRING_LITERAL - ; - -triggerAttributeClause - : WITH LR_BRACKET triggerAttribute (COMMA triggerAttribute)* RR_BRACKET - ; - -triggerAttribute - : key=attributeKey operator_eq value=attributeValue - ; -``` - -下面对 SQL 语法进行说明,您可以结合使用说明章节进行理解: - -- triggerName:触发器 ID,该 ID 是全局唯一的,用于区分不同触发器,大小写敏感。 -- triggerType:触发器类型,分为无状态(STATELESS)和有状态(STATEFUL)两类。 -- triggerEventClause:触发时机,目前仅支持写入前(BEFORE INSERT)和写入后(AFTER INSERT)两种。 -- pathPattern:触发器侦听的路径模式,可以包含通配符 * 和 **。 -- className:触发器实现类的类名。 -- uriClause:可选项,当不指定该选项时,我们默认 DBA 已经在各个 DataNode 节点的 trigger_root_dir 目录(配置项,默认为 IOTDB_HOME/ext/trigger)下放置好创建该触发器需要的 JAR 包。当指定该选项时,我们会将该 URI 对应的文件资源下载并分发到各 DataNode 的 trigger_root_dir/install 目录下。 -- triggerAttributeClause:用于指定触发器实例创建时需要设置的参数,SQL 语法中该部分是可选项。 - -下面是一个帮助您理解的 SQL 语句示例: - -```sql -CREATE STATELESS TRIGGER triggerTest -BEFORE INSERT -ON root.sg.** -AS 'org.apache.iotdb.trigger.ClusterAlertingExample' -USING URI 'http://jar/ClusterAlertingExample.jar' -WITH ( - "name" = "trigger", - "limit" = "100" -) -``` - -上述 SQL 语句创建了一个名为 triggerTest 的触发器: - -- 该触发器是无状态的(STATELESS) -- 在写入前触发(BEFORE INSERT) -- 该触发器侦听路径模式为 root\.sg.** -- 所编写的触发器类名为 org.apache.iotdb.trigger.ClusterAlertingExample -- JAR 包的 URI 为 http://jar/ClusterAlertingExample.jar -- 创建该触发器实例时会传入 name 和 limit 两个参数。 - -#### 卸载触发器 - -可以通过指定触发器 ID 的方式卸载触发器,卸载触发器的过程中会且仅会调用一次触发器的 `onDrop` 接口。 - -卸载触发器的 SQL 语法如下: - -```sql -// Drop Trigger -dropTrigger - : DROP TRIGGER triggerName=identifier -; -``` - -下面是示例语句: - -```sql -DROP TRIGGER triggerTest1 -``` - -上述语句将会卸载 ID 为 triggerTest1 的触发器。 - -#### 查询触发器 - -可以通过 SQL 语句查询集群中存在的触发器的信息。SQL 语法如下: - -```sql -SHOW TRIGGERS -``` - -该语句的结果集格式如下: - -| TriggerName | Event | Type | State | PathPattern | ClassName | NodeId | -| ------------ | ---------------------------- | -------------------- | ------------------------------------------- | ----------- | --------------------------------------- | --------------------------------------- | -| triggerTest1 | BEFORE_INSERT / AFTER_INSERT | STATELESS / STATEFUL | INACTIVE / ACTIVE / DROPPING / TRANSFFERING | root.** | org.apache.iotdb.trigger.TriggerExample | ALL(STATELESS) / DATA_NODE_ID(STATEFUL) | - - -#### 触发器状态说明 - -在集群中注册以及卸载触发器的过程中,我们维护了触发器的状态,下面是对这些状态的说明: - -| 状态 | 描述 | 是否建议写入进行 | -| ------------ | ------------------------------------------------------------ | ---------------- | -| INACTIVE | 执行 `CREATE TRIGGER` 的中间状态,集群刚在 ConfigNode 上记录该触发器的信息,还未在任何 DataNode 上激活该触发器 | 否 | -| ACTIVE | 执行 `CREATE TRIGGE` 成功后的状态,集群所有 DataNode 上的该触发器都已经可用 | 是 | -| DROPPING | 执行 `DROP TRIGGER` 的中间状态,集群正处在卸载该触发器的过程中 | 否 | -| TRANSFERRING | 集群正在进行该触发器实例位置的迁移 | 否 | - -### 重要注意事项 - -- 触发器从注册时开始生效,不对已有的历史数据进行处理。**即只有成功注册触发器之后发生的写入请求才会被触发器侦听到。** -- 触发器目前采用**同步触发**,所以编写时需要保证触发器效率,否则可能会大幅影响写入性能。**您需要自己保证触发器内部的并发安全性**。 -- 集群中**不能注册过多触发器**。因为触发器信息全量保存在 ConfigNode 中,并且在所有 DataNode 都有一份该信息的副本。 -- **建议注册触发器时停止写入**。注册触发器并不是一个原子操作,注册触发器时,会出现集群内部分节点已经注册了该触发器,部分节点尚未注册成功的中间状态。为了避免部分节点上的写入请求被触发器侦听到,部分节点上没有被侦听到的情况,我们建议注册触发器时不要执行写入。 -- 触发器将作为进程内程序执行,如果您的触发器编写不慎,内存占用过多,由于 IoTDB 并没有办法监控触发器所使用的内存,所以有 OOM 的风险。 -- 持有有状态触发器实例的节点宕机时,我们会尝试在另外的节点上恢复相应实例,在恢复过程中我们会调用一次触发器类的 restore 接口,您可以在该接口中实现恢复触发器所维护的状态的逻辑。 -- 触发器 JAR 包有大小限制,必须小于 min(`config_node_ratis_log_appender_buffer_size_max`, 2G),其中 `config_node_ratis_log_appender_buffer_size_max` 是一个配置项,具体含义可以参考 IOTDB 配置项说明。 -- **不同的 JAR 包中最好不要有全类名相同但功能实现不一样的类**。例如:触发器 trigger1、trigger2 分别对应资源 trigger1.jar、trigger2.jar。如果两个 JAR 包里都包含一个 `org.apache.iotdb.trigger.example.AlertListener` 类,当 `CREATE TRIGGER` 使用到这个类时,系统会随机加载其中一个 JAR 包中的类,最终导致触发器执行行为不一致以及其他的问题。 - -### 配置参数 - -| 配置项 | 含义 | -| ------------------------------------------------- | ---------------------------------------------- | -| *trigger_lib_dir* | 保存触发器 jar 包的目录位置 | -| *stateful\_trigger\_retry\_num\_when\_not\_found* | 有状态触发器触发无法找到触发器实例时的重试次数 | - -## 连续查询(Continuous Query, CQ) - -### 简介 -连续查询(Continuous queries, aka CQ) 是对实时数据周期性地自动执行的查询,并将查询结果写入指定的时间序列中。 - -用户可以通过连续查询实现滑动窗口流式计算,如计算某个序列每小时平均温度,并写入一个新序列中。用户可以自定义 `RESAMPLE` 子句去创建不同的滑动窗口,可以实现对于乱序数据一定程度的容忍。 - -### 语法 - -```sql -CREATE (CONTINUOUS QUERY | CQ) -[RESAMPLE - [EVERY ] - [BOUNDARY ] - [RANGE [, end_time_offset]] -] -[TIMEOUT POLICY BLOCKED|DISCARD] -BEGIN - SELECT CLAUSE - INTO CLAUSE - FROM CLAUSE - [WHERE CLAUSE] - [GROUP BY([, ]) [, level = ]] - [HAVING CLAUSE] - [FILL {PREVIOUS | LINEAR | constant}] - [LIMIT rowLimit OFFSET rowOffset] - [ALIGN BY DEVICE] -END -``` - -> 注意: -> 1. 如果where子句中出现任何时间过滤条件,IoTDB将会抛出异常,因为IoTDB会自动为每次查询执行指定时间范围。 -> 2. GROUP BY TIME CLAUSE在连续查询中的语法稍有不同,它不能包含原来的第一个参数,即 [start_time, end_time),IoTDB会自动填充这个缺失的参数。如果指定,IoTDB将会抛出异常。 -> 3. 如果连续查询中既没有GROUP BY TIME子句,也没有指定EVERY子句,IoTDB将会抛出异常。 - -#### 连续查询语法中参数含义的描述 - -- `` 为连续查询指定一个全局唯一的标识。 -- `` 指定了连续查询周期性执行的间隔。现在支持的时间单位有:ns, us, ms, s, m, h, d, w, 并且它的值不能小于用户在`iotdb-common.properties`配置文件中指定的`continuous_query_min_every_interval`。这是一个可选参数,默认等于group by子句中的`group_by_interval`。 -- `` 指定了每次查询执行窗口的开始时间,即`now()-`。现在支持的时间单位有:ns, us, ms, s, m, h, d, w。这是一个可选参数,默认等于`EVERY`子句中的`every_interval`。 -- `` 指定了每次查询执行窗口的结束时间,即`now()-`。现在支持的时间单位有:ns, us, ms, s, m, h, d, w。这是一个可选参数,默认等于`0`. -- `` 表示用户期待的连续查询的首个周期任务的执行时间。(因为连续查询只会对当前实时的数据流做计算,所以该连续查询实际首个周期任务的执行时间并不一定等于用户指定的时间,具体计算逻辑如下所示) - - `` 可以早于、等于或者迟于当前时间。 - - 这个参数是可选的,默认等于`0`。 - - 首次查询执行窗口的开始时间为` - `. - - 首次查询执行窗口的结束时间为` - `. - - 第i个查询执行窗口的时间范围是`[ - + (i - 1) * , - + (i - 1) * )`。 - - 如果当前时间早于或等于, 那连续查询的首个周期任务的执行时间就是用户指定的`execution_boundary_time`. - - 如果当前时间迟于用户指定的`execution_boundary_time`,那么连续查询的首个周期任务的执行时间就是`execution_boundary_time + i * `中第一个大于或等于当前时间的值。 - -> - 都应该大于 0 -> - 应该小于等于 -> - 用户应该根据实际需求,为 指定合适的值 -> - 如果大于,在每一次查询执行的时间窗口上会有部分重叠 -> - 如果小于,在连续的两次查询执行的时间窗口中间将会有未覆盖的时间范围 -> - start_time_offset 应该大于end_time_offset - -##### ``等于`` - -![1](/img/UserGuide/Process-Data/Continuous-Query/pic1.png?raw=true) - -##### ``大于`` - -![2](/img/UserGuide/Process-Data/Continuous-Query/pic2.png?raw=true) - -##### ``小于`` - -![3](/img/UserGuide/Process-Data/Continuous-Query/pic3.png?raw=true) - -##### ``不为0 - -![4](/img/UserGuide/Process-Data/Continuous-Query/pic4.png?raw=true) - -- `TIMEOUT POLICY` 指定了我们如何处理“前一个时间窗口还未执行完时,下一个窗口的执行时间已经到达的场景,默认值是`BLOCKED`. - - `BLOCKED`意味着即使下一个窗口的执行时间已经到达,我们依旧需要阻塞等待前一个时间窗口的查询执行完再开始执行下一个窗口。如果使用`BLOCKED`策略,所有的时间窗口都将会被依此执行,但是如果遇到执行查询的时间长于周期性间隔时,连续查询的结果会迟于最新的时间窗口范围。 - - `DISCARD`意味着如果前一个时间窗口还未执行完,我们会直接丢弃下一个窗口的执行时间。如果使用`DISCARD`策略,可能会有部分时间窗口得不到执行。但是一旦前一个查询执行完后,它将会使用最新的时间窗口,所以它的执行结果总能赶上最新的时间窗口范围,当然是以部分时间窗口得不到执行为代价。 - - -### 连续查询的用例 - -下面是用例数据,这是一个实时的数据流,我们假设数据都按时到达。 - -```` -+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ -| Time|root.ln.wf02.wt02.temperature|root.ln.wf02.wt01.temperature|root.ln.wf01.wt02.temperature|root.ln.wf01.wt01.temperature| -+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ -|2021-05-11T22:18:14.598+08:00| 121.0| 72.0| 183.0| 115.0| -|2021-05-11T22:18:19.941+08:00| 0.0| 68.0| 68.0| 103.0| -|2021-05-11T22:18:24.949+08:00| 122.0| 45.0| 11.0| 14.0| -|2021-05-11T22:18:29.967+08:00| 47.0| 14.0| 59.0| 181.0| -|2021-05-11T22:18:34.979+08:00| 182.0| 113.0| 29.0| 180.0| -|2021-05-11T22:18:39.990+08:00| 42.0| 11.0| 52.0| 19.0| -|2021-05-11T22:18:44.995+08:00| 78.0| 38.0| 123.0| 52.0| -|2021-05-11T22:18:49.999+08:00| 137.0| 172.0| 135.0| 193.0| -|2021-05-11T22:18:55.003+08:00| 16.0| 124.0| 183.0| 18.0| -+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ -```` - -#### 配置连续查询执行的周期性间隔 - -在`RESAMPLE`子句中使用`EVERY`参数指定连续查询的执行间隔,如果没有指定,默认等于`group_by_interval`。 - -```sql -CREATE CONTINUOUS QUERY cq1 -RESAMPLE EVERY 20s -BEGIN - SELECT max_value(temperature) - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - FROM root.ln.*.* - GROUP BY(10s) -END -``` - -`cq1`计算出`temperature`传感器每10秒的平均值,并且将查询结果存储在`temperature_max`传感器下,传感器路径前缀使用跟原来一样的前缀。 - -`cq1`每20秒执行一次,每次执行的查询的时间窗口范围是从过去20秒到当前时间。 - -假设当前时间是`2021-05-11T22:18:40.000+08:00`,如果把日志等级设置为DEBUG,我们可以在`cq1`执行的DataNode上看到如下的输出: - -```` -At **2021-05-11T22:18:40.000+08:00**, `cq1` executes a query within the time range `[2021-05-11T22:18:20, 2021-05-11T22:18:40)`. -`cq1` generate 2 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -At **2021-05-11T22:19:00.000+08:00**, `cq1` executes a query within the time range `[2021-05-11T22:18:40, 2021-05-11T22:19:00)`. -`cq1` generate 2 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:40.000+08:00| 137.0| 172.0| 135.0| 193.0| -|2021-05-11T22:18:50.000+08:00| 16.0| 124.0| 183.0| 18.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -```` - -`cq1`并不会处理当前时间窗口以外的数据,即`2021-05-11T22:18:20.000+08:00`以前的数据,所以我们会得到如下结果: - -```` -> SELECT temperature_max from root.ln.*.*; -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -|2021-05-11T22:18:40.000+08:00| 137.0| 172.0| 135.0| 193.0| -|2021-05-11T22:18:50.000+08:00| 16.0| 124.0| 183.0| 18.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -```` - -#### 配置连续查询的时间窗口大小 - -使用`RANGE`子句中的`start_time_offset`参数指定连续查询每次执行的时间窗口的开始时间偏移,如果没有指定,默认值等于`EVERY`参数。 - -```sql -CREATE CONTINUOUS QUERY cq2 -RESAMPLE RANGE 40s -BEGIN - SELECT max_value(temperature) - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - FROM root.ln.*.* - GROUP BY(10s) -END -``` - -`cq2`计算出`temperature`传感器每10秒的平均值,并且将查询结果存储在`temperature_max`传感器下,传感器路径前缀使用跟原来一样的前缀。 - -`cq2`每10秒执行一次,每次执行的查询的时间窗口范围是从过去40秒到当前时间。 - -假设当前时间是`2021-05-11T22:18:40.000+08:00`,如果把日志等级设置为DEBUG,我们可以在`cq2`执行的DataNode上看到如下的输出: - -```` -At **2021-05-11T22:18:40.000+08:00**, `cq2` executes a query within the time range `[2021-05-11T22:18:00, 2021-05-11T22:18:40)`. -`cq2` generate 4 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:00.000+08:00| NULL| NULL| NULL| NULL| -|2021-05-11T22:18:10.000+08:00| 121.0| 72.0| 183.0| 115.0| -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -At **2021-05-11T22:18:50.000+08:00**, `cq2` executes a query within the time range `[2021-05-11T22:18:10, 2021-05-11T22:18:50)`. -`cq2` generate 4 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:10.000+08:00| 121.0| 72.0| 183.0| 115.0| -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -|2021-05-11T22:18:40.000+08:00| 137.0| 172.0| 135.0| 193.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -At **2021-05-11T22:19:00.000+08:00**, `cq2` executes a query within the time range `[2021-05-11T22:18:20, 2021-05-11T22:19:00)`. -`cq2` generate 4 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -|2021-05-11T22:18:40.000+08:00| 137.0| 172.0| 135.0| 193.0| -|2021-05-11T22:18:50.000+08:00| 16.0| 124.0| 183.0| 18.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -```` - -`cq2`并不会写入全是null值的行,值得注意的是`cq2`会多次计算某些区间的聚合值,下面是计算结果: - -```` -> SELECT temperature_max from root.ln.*.*; -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:10.000+08:00| 121.0| 72.0| 183.0| 115.0| -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -|2021-05-11T22:18:40.000+08:00| 137.0| 172.0| 135.0| 193.0| -|2021-05-11T22:18:50.000+08:00| 16.0| 124.0| 183.0| 18.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -```` - -#### 同时配置连续查询执行的周期性间隔和时间窗口大小 - -使用`RESAMPLE`子句中的`EVERY`参数和`RANGE`参数分别指定连续查询的执行间隔和窗口大小。并且使用`fill()`来填充没有值的时间区间。 - -```sql -CREATE CONTINUOUS QUERY cq3 -RESAMPLE EVERY 20s RANGE 40s -BEGIN - SELECT max_value(temperature) - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - FROM root.ln.*.* - GROUP BY(10s) - FILL(100.0) -END -``` - -`cq3`计算出`temperature`传感器每10秒的平均值,并且将查询结果存储在`temperature_max`传感器下,传感器路径前缀使用跟原来一样的前缀。如果某些区间没有值,用`100.0`填充。 - -`cq3`每20秒执行一次,每次执行的查询的时间窗口范围是从过去40秒到当前时间。 - -假设当前时间是`2021-05-11T22:18:40.000+08:00`,如果把日志等级设置为DEBUG,我们可以在`cq3`执行的DataNode上看到如下的输出: - -```` -At **2021-05-11T22:18:40.000+08:00**, `cq3` executes a query within the time range `[2021-05-11T22:18:00, 2021-05-11T22:18:40)`. -`cq3` generate 4 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:00.000+08:00| 100.0| 100.0| 100.0| 100.0| -|2021-05-11T22:18:10.000+08:00| 121.0| 72.0| 183.0| 115.0| -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -At **2021-05-11T22:19:00.000+08:00**, `cq3` executes a query within the time range `[2021-05-11T22:18:20, 2021-05-11T22:19:00)`. -`cq3` generate 4 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -|2021-05-11T22:18:40.000+08:00| 137.0| 172.0| 135.0| 193.0| -|2021-05-11T22:18:50.000+08:00| 16.0| 124.0| 183.0| 18.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -```` - -值得注意的是`cq3`会多次计算某些区间的聚合值,下面是计算结果: - -```` -> SELECT temperature_max from root.ln.*.*; -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:00.000+08:00| 100.0| 100.0| 100.0| 100.0| -|2021-05-11T22:18:10.000+08:00| 121.0| 72.0| 183.0| 115.0| -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -|2021-05-11T22:18:40.000+08:00| 137.0| 172.0| 135.0| 193.0| -|2021-05-11T22:18:50.000+08:00| 16.0| 124.0| 183.0| 18.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -```` - -#### 配置连续查询每次查询执行时间窗口的结束时间 - -使用`RESAMPLE`子句中的`EVERY`参数和`RANGE`参数分别指定连续查询的执行间隔和窗口大小。并且使用`fill()`来填充没有值的时间区间。 - -```sql -CREATE CONTINUOUS QUERY cq4 -RESAMPLE EVERY 20s RANGE 40s, 20s -BEGIN - SELECT max_value(temperature) - INTO root.ln.wf02.wt02(temperature_max), root.ln.wf02.wt01(temperature_max), root.ln.wf01.wt02(temperature_max), root.ln.wf01.wt01(temperature_max) - FROM root.ln.*.* - GROUP BY(10s) - FILL(100.0) -END -``` - -`cq4`计算出`temperature`传感器每10秒的平均值,并且将查询结果存储在`temperature_max`传感器下,传感器路径前缀使用跟原来一样的前缀。如果某些区间没有值,用`100.0`填充。 - -`cq4`每20秒执行一次,每次执行的查询的时间窗口范围是从过去40秒到过去20秒。 - -假设当前时间是`2021-05-11T22:18:40.000+08:00`,如果把日志等级设置为DEBUG,我们可以在`cq4`执行的DataNode上看到如下的输出: - -```` -At **2021-05-11T22:18:40.000+08:00**, `cq4` executes a query within the time range `[2021-05-11T22:18:00, 2021-05-11T22:18:20)`. -`cq4` generate 2 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:00.000+08:00| 100.0| 100.0| 100.0| 100.0| -|2021-05-11T22:18:10.000+08:00| 121.0| 72.0| 183.0| 115.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -At **2021-05-11T22:19:00.000+08:00**, `cq4` executes a query within the time range `[2021-05-11T22:18:20, 2021-05-11T22:18:40)`. -`cq4` generate 2 lines: -> -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -> -```` - -值得注意的是`cq4`只会计算每个聚合区间一次,并且每次开始执行计算的时间都会比当前的时间窗口结束时间迟20s, 下面是计算结果: - -```` -> SELECT temperature_max from root.ln.*.*; -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -| Time|root.ln.wf02.wt02.temperature_max|root.ln.wf02.wt01.temperature_max|root.ln.wf01.wt02.temperature_max|root.ln.wf01.wt01.temperature_max| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -|2021-05-11T22:18:00.000+08:00| 100.0| 100.0| 100.0| 100.0| -|2021-05-11T22:18:10.000+08:00| 121.0| 72.0| 183.0| 115.0| -|2021-05-11T22:18:20.000+08:00| 122.0| 45.0| 59.0| 181.0| -|2021-05-11T22:18:30.000+08:00| 182.0| 113.0| 52.0| 180.0| -+-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ -```` - -#### 没有GROUP BY TIME子句的连续查询 - -不使用`GROUP BY TIME`子句,并在`RESAMPLE`子句中显式使用`EVERY`参数指定连续查询的执行间隔。 - -```sql -CREATE CONTINUOUS QUERY cq5 -RESAMPLE EVERY 20s -BEGIN - SELECT temperature + 1 - INTO root.precalculated_sg.::(temperature) - FROM root.ln.*.* - align by device -END -``` - -`cq5`计算以`root.ln`为前缀的所有`temperature + 1`的值,并将结果储存在另一个 database `root.precalculated_sg`中。除 database 名称不同外,目标序列与源序列路径名均相同。 - -`cq5`每20秒执行一次,每次执行的查询的时间窗口范围是从过去20秒到当前时间。 - -假设当前时间是`2021-05-11T22:18:40.000+08:00`,如果把日志等级设置为DEBUG,我们可以在`cq5`执行的DataNode上看到如下的输出: - -```` -At **2021-05-11T22:18:40.000+08:00**, `cq5` executes a query within the time range `[2021-05-11T22:18:20, 2021-05-11T22:18:40)`. -`cq5` generate 16 lines: -> -+-----------------------------+-------------------------------+-----------+ -| Time| Device|temperature| -+-----------------------------+-------------------------------+-----------+ -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf02.wt02| 123.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf02.wt02| 48.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf02.wt02| 183.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf02.wt02| 45.0| -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf02.wt01| 46.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf02.wt01| 15.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf02.wt01| 114.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf02.wt01| 12.0| -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf01.wt02| 12.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf01.wt02| 60.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf01.wt02| 30.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf01.wt02| 53.0| -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf01.wt01| 15.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf01.wt01| 182.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf01.wt01| 181.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf01.wt01| 20.0| -+-----------------------------+-------------------------------+-----------+ -> -At **2021-05-11T22:19:00.000+08:00**, `cq5` executes a query within the time range `[2021-05-11T22:18:40, 2021-05-11T22:19:00)`. -`cq5` generate 12 lines: -> -+-----------------------------+-------------------------------+-----------+ -| Time| Device|temperature| -+-----------------------------+-------------------------------+-----------+ -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf02.wt02| 79.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf02.wt02| 138.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf02.wt02| 17.0| -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf02.wt01| 39.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf02.wt01| 173.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf02.wt01| 125.0| -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf01.wt02| 124.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf01.wt02| 136.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf01.wt02| 184.0| -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf01.wt01| 53.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf01.wt01| 194.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf01.wt01| 19.0| -+-----------------------------+-------------------------------+-----------+ -> -```` - -`cq5`并不会处理当前时间窗口以外的数据,即`2021-05-11T22:18:20.000+08:00`以前的数据,所以我们会得到如下结果: - -```` -> SELECT temperature from root.precalculated_sg.*.* align by device; -+-----------------------------+-------------------------------+-----------+ -| Time| Device|temperature| -+-----------------------------+-------------------------------+-----------+ -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf02.wt02| 123.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf02.wt02| 48.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf02.wt02| 183.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf02.wt02| 45.0| -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf02.wt02| 79.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf02.wt02| 138.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf02.wt02| 17.0| -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf02.wt01| 46.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf02.wt01| 15.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf02.wt01| 114.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf02.wt01| 12.0| -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf02.wt01| 39.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf02.wt01| 173.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf02.wt01| 125.0| -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf01.wt02| 12.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf01.wt02| 60.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf01.wt02| 30.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf01.wt02| 53.0| -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf01.wt02| 124.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf01.wt02| 136.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf01.wt02| 184.0| -|2021-05-11T22:18:24.949+08:00|root.precalculated_sg.wf01.wt01| 15.0| -|2021-05-11T22:18:29.967+08:00|root.precalculated_sg.wf01.wt01| 182.0| -|2021-05-11T22:18:34.979+08:00|root.precalculated_sg.wf01.wt01| 181.0| -|2021-05-11T22:18:39.990+08:00|root.precalculated_sg.wf01.wt01| 20.0| -|2021-05-11T22:18:44.995+08:00|root.precalculated_sg.wf01.wt01| 53.0| -|2021-05-11T22:18:49.999+08:00|root.precalculated_sg.wf01.wt01| 194.0| -|2021-05-11T22:18:55.003+08:00|root.precalculated_sg.wf01.wt01| 19.0| -+-----------------------------+-------------------------------+-----------+ -```` - -### 连续查询的管理 - -#### 查询系统已有的连续查询 - -展示集群中所有的已注册的连续查询 - -```sql -SHOW (CONTINUOUS QUERIES | CQS) -``` - -`SHOW (CONTINUOUS QUERIES | CQS)`会将结果集按照`cq_id`排序。 - -##### 例子 - -```sql -SHOW CONTINUOUS QUERIES; -``` - -执行以上sql,我们将会得到如下的查询结果: - -| cq_id | query | state | -|:-------------|---------------------------------------------------------------------------------------------------------------------------------------|-------| -| s1_count_cq | CREATE CQ s1_count_cq
BEGIN
SELECT count(s1)
INTO root.sg_count.d.count_s1
FROM root.sg.d
GROUP BY(30m)
END | active | - - -#### 删除已有的连续查询 - -删除指定的名为cq_id的连续查询: - -```sql -DROP (CONTINUOUS QUERY | CQ) -``` - -DROP CQ并不会返回任何结果集。 - -##### 例子 - -删除名为s1_count_cq的连续查询: - -```sql -DROP CONTINUOUS QUERY s1_count_cq; -``` - -#### 修改已有的连续查询 - -目前连续查询一旦被创建就不能再被修改。如果想要修改某个连续查询,只能先用`DROP`命令删除它,然后再用`CREATE`命令重新创建。 - - -### 连续查询的使用场景 - -#### 对数据进行降采样并对降采样后的数据使用不同的保留策略 - -可以使用连续查询,定期将高频率采样的原始数据(如每秒1000个点),降采样(如每秒仅保留一个点)后保存到另一个 database 的同名序列中。高精度的原始数据所在 database 的`TTL`可能设置的比较短,比如一天,而低精度的降采样后的数据所在的 database `TTL`可以设置的比较长,比如一个月,从而达到快速释放磁盘空间的目的。 - -#### 预计算代价昂贵的查询 - -我们可以通过连续查询对一些重复的查询进行预计算,并将查询结果保存在某些目标序列中,这样真实查询并不需要真的再次去做计算,而是直接查询目标序列的结果,从而缩短了查询的时间。 - -> 预计算查询结果尤其对一些可视化工具渲染时序图和工作台时有很大的加速作用。 - -#### 作为子查询的替代品 - -IoTDB现在不支持子查询,但是我们可以通过创建连续查询得到相似的功能。我们可以将子查询注册为一个连续查询,并将子查询的结果物化到目标序列中,外层查询再直接查询哪个目标序列。 - -##### 例子 - -IoTDB并不会接收如下的嵌套子查询。这个查询会计算s1序列每隔30分钟的非空值数量的平均值: - -```sql -SELECT avg(count_s1) from (select count(s1) as count_s1 from root.sg.d group by([0, now()), 30m)); -``` - -为了得到相同的结果,我们可以: - -**1. 创建一个连续查询** - -这一步执行内层子查询部分。下面创建的连续查询每隔30分钟计算一次`root.sg.d.s1`序列的非空值数量,并将结果写入目标序列`root.sg_count.d.count_s1`中。 - -```sql -CREATE CQ s1_count_cq -BEGIN - SELECT count(s1) - INTO root.sg_count.d.count_s1 - FROM root.sg.d - GROUP BY(30m) -END -``` - -**2. 查询连续查询的结果** - -这一步执行外层查询的avg([...])部分。 - -查询序列`root.sg_count.d.count_s1`的值,并计算平均值: - -```sql -SELECT avg(count_s1) from root.sg_count.d; -``` - - -### 连续查询相关的配置参数 -| 参数名 | 描述 | 类型 | 默认值 | -| :---------------------------------- |----------------------|----------|---------------| -| `continuous_query_submit_thread_count` | 用于周期性提交连续查询执行任务的线程数 | int32 | 2 | -| `continuous_query_min_every_interval_in_ms` | 系统允许的连续查询最小的周期性时间间隔 | duration | 1000 | diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/IoTDB-View_timecho.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/IoTDB-View_timecho.md deleted file mode 100644 index 17817fde5..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/IoTDB-View_timecho.md +++ /dev/null @@ -1,546 +0,0 @@ - - -# 视图 - -## 序列视图应用背景 - -### 应用场景1 时间序列重命名(PI资产管理) - -实际应用中,采集数据的设备可能使用人类难以理解的标识号来命名,这给业务层带来了查询上的困难。 - -而序列视图能够重新组织管理这些序列,在不改变原有序列内容、无需新建或拷贝序列的情况下,使用新的模型结构来访问他们。 - -**例如**:一台云端设备使用自己的网卡MAC地址组成实体编号,存储数据时写入如下时间序列:`root.db.0800200A8C6D.xvjeifg`. - -对于用户来说,它是难以理解的。但此时,用户能够使用序列视图功能对它重命名,将它映射到一个序列视图中去,使用`root.view.device001.temperature`来访问采集到的数据。 - -### 应用场景2 简化业务层查询逻辑 - -有时用户有大量设备,管理着大量时间序列。在进行某项业务时,用户希望仅处理其中的部分序列,此时就可以通过序列视图功能挑选出关注重点,方便反复查询、写入。 - -**例如**:用户管理一条产品流水线,各环节的设备有大量时间序列。温度检测员仅需要关注设备温度,就可以抽取温度相关的序列,组成序列视图。 - -### 应用场景3 辅助权限管理 - -生产过程中,不同业务负责的范围一般不同,出于安全考虑往往需要通过权限管理来限制业务员的访问范围。 - -**例如**:安全管理部门现在仅需要监控某生产线上各设备的温度,但这些数据与其他机密数据存放在同一数据库。此时,就可以创建若干新的视图,视图中仅含有生产线上与温度有关的时间序列,接着,向安全员只赋予这些序列视图的权限,从而达到权限限制的目的。 - -### 设计序列视图功能的动机 - -结合上述两类使用场景,设计序列视图功能的动机,主要有: - -1. 时间序列重命名。 -2. 简化业务层查询逻辑。 -3. 辅助权限管理,通过视图向特定用户开放数据。 - -## 序列视图概念 - -### 术语概念 - -约定:若无特殊说明,本文档所指定的视图均是**序列视图**,未来可能引入设备视图等新功能。 - -### 序列视图 - -序列视图是一种组织管理时间序列的方式。 - -在传统关系型数据库中,数据都必须存放在一个表中,而在IoTDB等时序数据库中,序列才是存储单元。因此,IoTDB中序列视图的概念也是建立在序列上的。 - -一个序列视图就是一条虚拟的时间序列,每条虚拟的时间序列都像是一条软链接或快捷方式,映射到某个视图外部的序列或者某种计算逻辑。换言之,一个虚拟序列要么映射到某个确定的外部序列,要么由多个外部序列运算得来。 - -用户可以使用复杂的SQL查询创建视图,此时序列视图就像一条被存储的查询语句,当从视图中读取数据时,就把被存储的查询语句作为数据来源,放在FROM子句中。 - -### 别名序列 - -在序列视图中,有一类特殊的存在,他们满足如下所有条件: - -1. 数据来源为单一的时间序列 -2. 没有任何计算逻辑 -3. 没有任何筛选条件(例如无WHERE子句的限制) - -这样的序列视图,被称为**别名序列**,或别名序列视图。不完全满足上述所有条件的序列视图,就称为非别名序列视图。他们之间的区别是:只有别名序列支持写入功能。 - -**所有序列视图包括别名序列目前均不支持触发器功能(Trigger)。** - -### 嵌套视图 - -用户可能想从一个现有的序列视图中选出若干序列,组成一个新的序列视图,就称之为嵌套视图。 - -**当前版本不支持嵌套视图功能**。 - -### IoTDB中对序列视图的一些约束 - -#### 限制1 序列视图必须依赖于一个或者若干个时间序列 - -一个序列视图有两种可能的存在形式: - -1. 它映射到一条时间序列 -2. 它由一条或若干条时间序列计算得来 - -前种存在形式已在前文举例,易于理解;而此处的后一种存在形式,则是因为序列视图允许计算逻辑的存在。 - -比如,用户在同一个锅炉安装了两个温度计,现在需要计算两个温度值的平均值作为测量结果。用户采集到的是如下两个序列:`root.db.d01.temperature01`、`root.db.d01.temperature02`。 - -此时,用户可以使用两个序列求平均值,作为视图中的一条序列:`root.db.d01.avg_temperature`。 - -该例子会3.1.2详细展开。 - -#### 限制2 非别名序列视图是只读的 - -不允许向非别名序列视图写入。 - -只有别名序列视图是支持写入的。 - -#### 限制3 不允许嵌套视图 - -不能选定现有序列视图中的某些列来创建序列视图,无论是直接的还是间接的。 - -本限制将在3.1.3给出示例。 - -#### 限制4 序列视图与时间序列不能重名 - -序列视图和时间序列都位于同一棵树下,所以他们不能重名。 - -任何一条序列的名称(路径)都应该是唯一确定的。 - -#### 限制5 序列视图与时间序列的时序数据共用,标签等元数据不共用 - -序列视图是指向时间序列的映射,所以它们完全共用时序数据,由时间序列负责持久化存储。 - -但是它们的tag、attributes等元数据不共用。 - -这是因为进行业务查询时,面向视图的用户关心的是当前视图的结构,而如果使用group by tag等方式做查询,显然希望是得到视图下含有对应tag的分组效果,而非时间序列的tag的分组效果(用户甚至对那些时间序列毫无感知)。 - -## 序列视图功能介绍 - -### 创建视图 - -创建一个序列视图与创建一条时间序列类似,区别在于需要通过AS关键字指定数据来源,即原始序列。 - -#### 创建视图的SQL - -用户可以选取一些序列创建一个视图: - -```SQL -CREATE VIEW root.view.device.status -AS - SELECT s01 - FROM root.db.device -``` - -它表示用户从现有设备`root.db.device`中选出了`s01`这条序列,创建了序列视图`root.view.device.status`。 - -序列视图可以与时间序列存在于同一实体下,例如: - -```SQL -CREATE VIEW root.db.device.status -AS - SELECT s01 - FROM root.db.device -``` - -这样,`root.db.device`下就有了`s01`的一份虚拟拷贝,但是使用不同的名字`status`。 - -可以发现,上述两个例子中的序列视图,都是别名序列,我们给用户提供一种针对该序列的更方便的创建方式: - -```SQL -CREATE VIEW root.view.device.status -AS - root.db.device.s01 -``` - -#### 创建含有计算逻辑的视图 - -沿用2.2章节限制1中的例子: - -> 用户在同一个锅炉安装了两个温度计,现在需要计算两个温度值的平均值作为测量结果。用户采集到的是如下两个序列:`root.db.d01.temperature01`、`root.db.d01.temperature02`。 -> -> 此时,用户可以使用两个序列求平均值,作为视图中的一条序列:`root.view.device01.avg_temperature`。 - -如果不使用视图,用户可以这样查询两个温度的平均值: - -```SQL -SELECT (temperature01 + temperature02) / 2 -FROM root.db.d01 -``` - -而如果使用序列视图,用户可以这样创建一个视图来简化将来的查询: - -```SQL -CREATE VIEW root.db.d01.avg_temperature -AS - SELECT (temperature01 + temperature02) / 2 - FROM root.db.d01 -``` - -然后用户可以这样查询: - -```SQL -SELECT avg_temperature FROM root.db.d01 -``` - -#### 不支持嵌套序列视图 - -继续沿用3.1.2中的例子,现在用户想使用序列视图`root.db.d01.avg_temperature`创建一个新的视图,这是不允许的。我们目前不支持嵌套视图,无论它是否是别名序列,都不支持。 - -比如下列SQL语句会报错: - -```SQL -CREATE VIEW root.view.device.avg_temp_copy -AS - root.db.d01.avg_temperature -- 不支持。不允许嵌套视图 -``` - -#### 一次创建多条序列视图 - -一次只能指定一个序列视图对用户来说使用不方便,则可以一次指定多条序列,比如: - -```SQL -CREATE VIEW root.db.device.status, root.db.device.sub.hardware -AS - SELECT s01, s02 - FROM root.db.device -``` - -此外,上述写法可以做简化: - -```SQL -CREATE VIEW root.db.device(status, sub.hardware) -AS - SELECT s01, s02 - FROM root.db.device -``` - -上述两条语句都等价于如下写法: - -```SQL -CREATE VIEW root.db.device.status -AS - SELECT s01 - FROM root.db.device; - -CREATE VIEW root.db.device.sub.hardware -AS - SELECT s02 - FROM root.db.device -``` - -也等价于如下写法 - -```SQL -CREATE VIEW root.db.device.status, root.db.device.sub.hardware -AS - root.db.device.s01, root.db.device.s02 - --- 或者 - -CREATE VIEW root.db.device(status, sub.hardware) -AS - root.db.device(s01, s02) -``` - -##### 所有序列间的映射关系为静态存储 - -有时,SELECT子句中可能包含运行时才能确定的语句个数,比如如下的语句: - -```SQL -SELECT s01, s02 -FROM root.db.d01, root.db.d02 -``` - -上述语句能匹配到的序列数量是并不确定的,和系统状态有关。即便如此,用户也可以使用它创建视图。 - -不过需要特别注意,所有序列间的映射关系为静态存储(创建时固定)!请看以下示例: - -当前数据库中仅含有`root.db.d01.s01`、`root.db.d02.s01`、`root.db.d02.s02`三条序列,接着创建视图: - -```SQL -CREATE VIEW root.view.d(alpha, beta, gamma) -AS - SELECT s01, s02 - FROM root.db.d01, root.db.d02 -``` - -时间序列之间映射关系如下: - -| 序号 | 时间序列 | 序列视图 | -| ---- | ----------------- | ----------------- | -| 1 | `root.db.d01.s01` | root.view.d.alpha | -| 2 | `root.db.d02.s01` | root.view.d.beta | -| 3 | `root.db.d02.s02` | root.view.d.gamma | - -此后,用户新增了序列`root.db.d01.s02`,则它不对应到任何视图;接着,用户删除`root.db.d01.s01`,则查询`root.view.d.alpha`会直接报错,它也不会对应到`root.db.d01.s02`。 - -请时刻注意,序列间映射关系是静态地、固化地存储的。 - -#### 批量创建序列视图 - -现有若干个设备,每个设备都有一个温度数值,例如: - -1. root.db.d1.temperature -2. root.db.d2.temperature -3. ... - -这些设备下可能存储了很多其他序列(例如`root.db.d1.speed`),但目前可以创建一个视图,只包含这些设备的温度值,而不关系其他序列: - -```SQL -CREATE VIEW root.db.view(${2}_temperature) -AS - SELECT temperature FROM root.db.* -``` - -这里仿照了查询写回(`SELECT INTO`)对命名规则的约定,使用变量占位符来指定命名规则。可以参考:[查询写回(SELECT INTO)](../User-Manual/Query-Data.md#查询写回(INTO-子句)) - -这里`root.db.*.temperature`指定了有哪些时间序列会被包含在视图中;`${2}`则指定了从时间序列中的哪个节点提取出名字来命名序列视图。 - -此处,`${2}`指代的是`root.db.*.temperature`的层级2(从 0 开始),也就是`*`的匹配结果;`${2}_temperature`则是将匹配结果与`temperature`通过下划线拼接了起来,构成视图下各序列的节点名称。 - -上述创建视图的语句,和下列写法是等价的: - -```SQL -CREATE VIEW root.db.view(${2}_${3}) -AS - SELECT temperature from root.db.* -``` - -最终视图中含有这些序列: - -1. root.db.view.d1_temperature -2. root.db.view.d2_temperature -3. ... - -使用通配符创建,只会存储创建时刻的静态映射关系。 - -#### 创建视图时SELECT子句受到一定限制 - -创建序列视图时,使用的SELECT子句受到一定限制。主要限制如下: - -1. 不能使用`WHERE`子句。 -2. 不能使用`GROUP BY`子句。 -3. 不能使用`MAX_VALUE`等聚合函数。 - -简单来说,`AS`后只能使用`SELECT ... FROM ... `的结构,且该查询语句的结果必须能构成一条时间序列。 - -### 视图数据查询 - -对于可以支持的数据查询功能,在执行时序数据查询时,序列视图与时间序列可以无差别使用,行为完全一致。 - -**目前序列视图不支持的查询类型如下:** - -1. **align by device 查询** -2. **group by tags 查询** - -用户也可以在同一个SELECT语句中混合查询时间序列与序列视图,比如: - -```SQL -SELECT temperature01, temperature02, avg_temperature -FROM root.db.d01 -WHERE temperature01 < temperature02 -``` - -但是,如果用户想要查询序列的元数据,例如tag、attributes等,则查询到的是序列视图的结果,而并非序列视图所引用的时间序列的结果。 - -此外,对于别名序列,如果用户想要得到时间序列的tag、attributes等信息,则需要先查询视图列的映射,找到对应的时间序列,再向时间序列查询tag、attributes等信息。查询视图列的映射的方法将会在3.5部分说明。 - -### 视图修改 - -视图支持的修改操作包括:修改计算逻辑,修改标签/属性/别名,以及删除。 - -#### 修改视图数据来源 - -```SQL -ALTER VIEW root.view.device.status -AS - SELECT s01 - FROM root.ln.wf.d01 -``` - -#### 修改视图的计算逻辑 - -```SQL -ALTER VIEW root.db.d01.avg_temperature -AS - SELECT (temperature01 + temperature02 + temperature03) / 3 - FROM root.db.d01 -``` - -#### 标签点管理 - -- 添加新的标签 - -```SQL -ALTER view root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4 -``` - -- 添加新的属性 - -```SQL -ALTER view root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4 -``` - -- 重命名标签或属性 - -```SQL -ALTER view root.turbine.d1.s1 RENAME tag1 TO newTag1 -``` - -- 重新设置标签或属性的值 - -```SQL -ALTER view root.turbine.d1.s1 SET newTag1=newV1, attr1=newV1 -``` - -- 删除已经存在的标签或属性 - -```SQL -ALTER view root.turbine.d1.s1 DROP tag1, tag2 -``` - -- 更新插入别名,标签和属性 - -> 如果该别名,标签或属性原来不存在,则插入,否则,用新值更新原来的旧值 - -```SQL -ALTER view root.turbine.d1.s1 UPSERT TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4) -``` - -#### 删除视图 - -因为一个视图就是一条序列,因此可以像删除时间序列一样删除一个视图。 - -```SQL -DELETE VIEW root.view.device.avg_temperatue -``` - -### 视图同步 - -#### 如果依赖的原序列被删除了 - -当序列视图查询时(序列解析时),如果依赖的时间序列不存在,则**返回空结果集**。 - -这和查询一个不存在的序列的反馈类似,但是有区别:如果依赖的时间序列无法解析,空结果集是包含表头的,以此来提醒用户该视图是存在问题的。 - -此外,被依赖的时间序列删除时,不会去查找是否有依赖于该列的视图,用户不会收到任何警告。 - -#### 不支持非别名序列的数据写入 - -不支持向非别名序列的写入。 - -详情请参考前文 2.1.6 限制2 - -#### 序列的元数据不共用 - -详情请参考前文2.1.6 限制5 - -### 视图元数据查询 - -视图元数据查询,特指查询视图本身的元数据(例如视图有多少列),以及数据库内视图的信息(例如有哪些视图)。 - -#### 查看当前的视图列 - -用户有两种查询方式: - -1. 使用`SHOW TIMESERIES`进行查询,该查询既包含时间序列,也包含序列视图。但是只能显示视图的部分属性 -2. 使用`SHOW VIEW`进行查询,该查询只包含序列视图。能完整显示序列视图的属性。 - -举例: - -```Shell -IoTDB> show timeseries; -+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType| -+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -|root.db.device.s01 | null| root.db| INT32| RLE| SNAPPY|null| null| null| null| BASE| -+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -|root.db.view.status | null| root.db| INT32| RLE| SNAPPY|null| null| null| null| VIEW| -+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -|root.db.d01.temp01 | null| root.db| FLOAT| RLE| SNAPPY|null| null| null| null| BASE| -+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -|root.db.d01.temp02 | null| root.db| FLOAT| RLE| SNAPPY|null| null| null| null| BASE| -+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -|root.db.d01.avg_temp| null| root.db| FLOAT| null| null|null| null| null| null| VIEW| -+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -Total line number = 5 -It costs 0.789s -IoTDB> -``` - -最后一列`ViewType`中显示了该序列的类型,时间序列为BASE,序列视图是VIEW。 - -此外,某些序列视图的属性会缺失,比如`root.db.d01.avg_temp`是由温度均值计算得来,所以`Encoding`和`Compression`属性都为空值。 - -此外,`SHOW TIMESERIES`语句的查询结果主要分为两部分: - -1. 时序数据的信息,例如数据类型,压缩方式,编码等 -2. 其他元数据信息,例如tag,attribute,所属database等 - -对于序列视图,展示的时序数据信息与其原始序列一致或者为空值(比如计算得到的平均温度有数据类型但是无压缩方式);展示的元数据信息则是视图的内容。 - -如果要得知视图的更多信息,需要使用`SHOW ``VIEW`。`SHOW ``VIEW`中展示视图的数据来源等。 - -```Shell -IoTDB> show VIEW root.**; -+--------------------+--------+--------+----+----------+--------+-----------------------------------------+ -| Timeseries|Database|DataType|Tags|Attributes|ViewType| SOURCE| -+--------------------+--------+--------+----+----------+--------+-----------------------------------------+ -|root.db.view.status | root.db| INT32|null| null| VIEW| root.db.device.s01| -+--------------------+--------+--------+----+----------+--------+-----------------------------------------+ -|root.db.d01.avg_temp| root.db| FLOAT|null| null| VIEW|(root.db.d01.temp01+root.db.d01.temp02)/2| -+--------------------+--------+--------+----+----------+--------+-----------------------------------------+ -Total line number = 2 -It costs 0.789s -IoTDB> -``` - -最后一列`SOURCE`显示了该序列视图的数据来源,列出了创建该序列的SQL语句。 - -##### 关于数据类型 - -上述两种查询都涉及视图的数据类型。视图的数据类型是根据定义视图的查询语句或别名序列的原始时间序列类型推断出来的。这个数据类型是根据当前系统的状态实时计算出来的,因此在不同时刻查询到的数据类型可能是改变的。 - -## FAQ - -#### Q1:我想让视图实现类型转换的功能。例如,原有一个int32类型的时间序列,和其他int64类型的序列被放在了同一个视图中。我现在希望通过视图查询到的数据,都能自动转换为int64类型。 - -> Ans:这不是序列视图的职能范围。但是可以使用`CAST`进行转换,比如: - -```SQL -CREATE VIEW root.db.device.int64_status -AS - SELECT CAST(s1, 'type'='INT64') from root.db.device -``` - -> 这样,查询`root.view.status`时,就会得到int64类型的结果。 -> -> 请特别注意,上述例子中,序列视图的数据是通过`CAST`转换得到的,因此`root.db.device.int64_status`并不是一条别名序列,也就**不支持写入**。 - -#### Q2:是否支持默认命名?选择若干时间序列,创建视图;但是我不指定每条序列的名字,由数据库自动命名? - -> Ans:不支持。用户必须明确指定命名。 - -#### Q3:在原有体系中,创建时间序列`root.db.device.s01`,可以发现自动创建了database`root.db`,自动创建了device`root.db.device`。接着删除时间序列`root.db.device.s01`,可以发现`root.db.device`被自动删除,`root.db`却还是保留的。对于创建视图,会沿用这一机制吗?出于什么考虑呢? - -> Ans:保持原有的行为不变,引入视图功能不会改变原有的这些逻辑。 - -#### Q4:是否支持序列视图重命名? - -> A:当前版本不支持重命名,可以自行创建新名称的视图投入使用。 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Maintennance.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Maintennance.md deleted file mode 100644 index 54e819a8e..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Maintennance.md +++ /dev/null @@ -1,351 +0,0 @@ - -# 运维语句 - -## Explain/Explain Analyze 语句 - -查询分析的意义在于帮助用户理解查询的执行机制和性能瓶颈,从而实现查询优化和性能提升。这不仅关乎到查询的执行效率,也直接影响到应用的用户体验和资源的有效利用。为了进行有效的查询分析,**IoTDB** **V1.3.2及以上版本**提供了查询分析语句:Explain 和 Explain Analyze。 - -- Explain 语句:允许用户预览查询 SQL 的执行计划,包括 IoTDB 如何组织数据检索和处理。 -- Explain Analyze 语句:在 Explain 语句基础上增加了性能分析,完整执行SQL并展示查询执行过程中的时间和资源消耗。为IoTDB用户深入理解查询详情以及进行查询优化提供了详细的相关信息。与其他常用的 IoTDB 排查手段相比,Explain Analyze 没有部署负担,同时能够针对单条 sql 进行分析,能够更好定位问题。各类方法对比如下: - -| 方法 | 安装难度 | 业务影响 | 功能范围 | -| :------------------ | :----------------------------------------------------------- | :--------------------------------------------------- | :----------------------------------------------------- | -| Explain Analyze语句 | 低。无需安装额外组件,为IoTDB内置SQL语句 | 低。只会影响当前分析的单条查询,对线上其他负载无影响 | 支持分布式,可支持对单条SQL进行追踪 | -| 监控面板 | 中。需要安装IoTDB监控面板工具(企业版工具),并开启IoTDB监控服务 | 中。IoTDB监控服务记录指标会带来额外耗时 | 支持分布式,仅支持对数据库整体查询负载和耗时进行分析 | -| Arthas抽样 | 中。需要安装Java Arthas工具(部分内网无法直接安装Arthas,且安装后,有时需要重启应用) | 高。CPU 抽样可能会影响线上业务的响应速度 | 不支持分布式,仅支持对数据库整体查询负载和耗时进行分析 | - -### Explain 语句 - -#### 语法 - -Explain命令允许用户查看SQL查询的执行计划。执行计划以算子的形式展示,描述了IoTDB会如何执行查询。其语法如下,其中SELECT_STATEMENT是查询相关的SQL语句: - -```SQL -EXPLAIN -``` - -Explain的返回结果包括了数据访问策略、过滤条件是否下推以及查询计划在不同节点的分配等信息,为用户提供了一种手段,以可视化查询的内部执行逻辑。 - -#### 示例 - -```SQL -# 插入数据 -insert into root.explain.data(timestamp, column1, column2) values(1710494762, "hello", "explain") - -# 执行explain语句 -explain select * from root.explain.data -``` - -执行上方SQL,会得到如下结果。不难看出,IoTDB分别通过两个SeriesScan节点去获取column1和column2的数据,最后通过fullOuterTimeJoin将其连接。 - -```Plain -+-----------------------------------------------------------------------+ -| distribution plan| -+-----------------------------------------------------------------------+ -| ┌───────────────────┐ | -| │FullOuterTimeJoin-3│ | -| │Order: ASC │ | -| └───────────────────┘ | -| ┌─────────────────┴─────────────────┐ | -| │ │ | -|┌─────────────────────────────────┐ ┌─────────────────────────────────┐| -|│SeriesScan-4 │ │SeriesScan-5 │| -|│Series: root.explain.data.column1│ │Series: root.explain.data.column2│| -|│Partition: 3 │ │Partition: 3 │| -|└─────────────────────────────────┘ └─────────────────────────────────┘| -+-----------------------------------------------------------------------+ -``` - -### Explain Analyze 语句 - -#### 语法 - -Explain Analyze 是 IOTDB 查询引擎自带的性能分析 SQL,与 Explain 不同,它会执行对应的查询计划并统计执行信息,可以用于追踪一条查询的具体性能分布,用于对资源进行观察,进行性能调优与异常分析。其语法如下: - -```SQL -EXPLAIN ANALYZE [VERBOSE] -``` - -其中SELECT_STATEMENT对应需要分析的查询语句;VERBOSE为打印详细分析结果,不填写VERBOSE时EXPLAIN ANALYZE将会省略部分信息。 - -在EXPLAIN ANALYZE的结果集中,会包含如下信息: - -![explain-analyze-1.png](/img/explain-analyze-1.png) - -其中: - -- QueryStatistics包含查询层面进的统计信息,主要包含规划解析阶段耗时,Fragment元数据等信息。 -- FragmentInstance是IoTDB在一个节点上查询计划的封装,每一个节点都会在结果集中输出一份Fragment信息,主要包含FragmentStatistics和算子信息。FragmentStastistics包含Fragment的统计信息,包括总实际耗时(墙上时间),所涉及到的TsFile,调度信息等情况。在一个Fragment的信息输出同时会以节点树层级的方式展示该Fragment下计划节点的统计信息,主要包括:CPU运行时间、输出的数据行数、指定接口被调用的次数、所占用的内存、节点专属的定制信息。 - -#### 特别说明 - -1. Explain Analyze 语句的结果简化 - -由于在 Fragment 中会输出当前节点中执行的所有节点信息,当一次查询涉及的序列过多时,每个节点都被输出,会导致 Explain Analyze 返回的结果集过大,因此当相同类型的节点超过 10 个时,系统会自动合并当前 Fragment 下所有相同类型的节点,合并后统计信息也被累积,对于一些无法合并的定制信息会直接丢弃(如下图)。 - -![explain-analyze-2.png](/img/explain-analyze-2.png) - -用户也可以自行修改 iotdb-common.properties 中的配置项`merge_threshold_of_explain_analyze`来设置触发合并的节点阈值,该参数支持热加载。 - -2. 查询超时场景使用 Explain Analyze 语句 - -Explain Analyze 本身是一种特殊的查询,当执行超时的时候,无法使用Explain Analyze语句进行分析。为了在查询超时的情况下也可以通过分析结果排查超时原因,Explain Analyze还提供了**定时日志**机制(无需用户配置),每经过一定的时间间隔会将 Explain Analyze 的当前结果以文本的形式输出到专门的日志中。当查询超时时,用户可以前往logs/log_explain_analyze.log中查看对应的日志进行排查。 - -日志的时间间隔基于查询的超时时间进行计算,可以保证在超时的情况下至少会有两次的结果记录。 - -#### 示例 - -下面是Explain Analyze的一个例子: - -```SQL -# 插入数据 -insert into root.explain.analyze.data(timestamp, column1, column2, column3) values(1710494762, "hello", "explain", "analyze") -insert into root.explain.analyze.data(timestamp, column1, column2, column3) values(1710494862, "hello2", "explain2", "analyze2") -insert into root.explain.analyze.data(timestamp, column1, column2, column3) values(1710494962, "hello3", "explain3", "analyze3") - -# 执行explain analyze语句 -explain analyze select column2 from root.explain.analyze.data order by column1 -``` - -得到输出如下: - -```Plain -+-------------------------------------------------------------------------------------------------+ -| Explain Analyze| -+-------------------------------------------------------------------------------------------------+ -|Analyze Cost: 1.739 ms | -|Fetch Partition Cost: 0.940 ms | -|Fetch Schema Cost: 0.066 ms | -|Logical Plan Cost: 0.000 ms | -|Logical Optimization Cost: 0.000 ms | -|Distribution Plan Cost: 0.000 ms | -|Fragment Instances Count: 1 | -| | -|FRAGMENT-INSTANCE[Id: 20240315_115800_00030_1.2.0][IP: 127.0.0.1][DataRegion: 4][State: FINISHED]| -| Total Wall Time: 25 ms | -| Cost of initDataQuerySource: 0.175 ms | -| Seq File(unclosed): 0, Seq File(closed): 1 | -| UnSeq File(unclosed): 0, UnSeq File(closed): 0 | -| ready queued time: 0.280 ms, blocked queued time: 2.456 ms | -| [PlanNodeId 10]: IdentitySinkNode(IdentitySinkOperator) | -| CPU Time: 0.780 ms | -| output: 1 rows | -| HasNext() Called Count: 3 | -| Next() Called Count: 2 | -| Estimated Memory Size: : 1245184 | -| [PlanNodeId 5]: TransformNode(TransformOperator) | -| CPU Time: 0.764 ms | -| output: 1 rows | -| HasNext() Called Count: 3 | -| Next() Called Count: 2 | -| Estimated Memory Size: : 1245184 | -| [PlanNodeId 4]: SortNode(SortOperator) | -| CPU Time: 0.721 ms | -| output: 1 rows | -| HasNext() Called Count: 3 | -| Next() Called Count: 2 | -| sortCost/ns: 1125 | -| sortedDataSize: 272 | -| prepareCost/ns: 610834 | -| [PlanNodeId 3]: FullOuterTimeJoinNode(FullOuterTimeJoinOperator) | -| CPU Time: 0.706 ms | -| output: 1 rows | -| HasNext() Called Count: 5 | -| Next() Called Count: 1 | -| [PlanNodeId 7]: SeriesScanNode(SeriesScanOperator) | -| CPU Time: 1.085 ms | -| output: 1 rows | -| HasNext() Called Count: 2 | -| Next() Called Count: 1 | -| SeriesPath: root.explain.analyze.data.column2 | -| [PlanNodeId 8]: SeriesScanNode(SeriesScanOperator) | -| CPU Time: 1.091 ms | -| output: 1 rows | -| HasNext() Called Count: 2 | -| Next() Called Count: 1 | -| SeriesPath: root.explain.analyze.data.column1 | -+-------------------------------------------------------------------------------------------------+ -``` - -触发合并后的部分结果示例如下: - -```Plain -Analyze Cost: 143.679 ms -Fetch Partition Cost: 22.023 ms -Fetch Schema Cost: 63.086 ms -Logical Plan Cost: 0.000 ms -Logical Optimization Cost: 0.000 ms -Distribution Plan Cost: 0.000 ms -Fragment Instances Count: 2 - -FRAGMENT-INSTANCE[Id: 20240311_041502_00001_1.2.0][IP: 192.168.130.9][DataRegion: 14] - Total Wall Time: 39964 ms - Cost of initDataQuerySource: 1.834 ms - Seq File(unclosed): 0, Seq File(closed): 3 - UnSeq File(unclosed): 0, UnSeq File(closed): 0 - ready queued time: 504.334 ms, blocked queued time: 25356.419 ms - [PlanNodeId 20793]: IdentitySinkNode(IdentitySinkOperator) Count: * 1 - CPU Time: 24440.724 ms - input: 71216 rows - HasNext() Called Count: 35963 - Next() Called Count: 35962 - Estimated Memory Size: : 33882112 - [PlanNodeId 10385]: FullOuterTimeJoinNode(FullOuterTimeJoinOperator) Count: * 8 - CPU Time: 41437.708 ms - input: 243011 rows - HasNext() Called Count: 41965 - Next() Called Count: 41958 - Estimated Memory Size: : 33882112 - [PlanNodeId 11569]: SeriesScanNode(SeriesScanOperator) Count: * 1340 - CPU Time: 1397.822 ms - input: 134000 rows - HasNext() Called Count: 2353 - Next() Called Count: 1340 - Estimated Memory Size: : 32833536 - [PlanNodeId 20778]: ExchangeNode(ExchangeOperator) Count: * 7 - CPU Time: 109.245 ms - input: 71891 rows - HasNext() Called Count: 1431 - Next() Called Count: 1431 - -FRAGMENT-INSTANCE[Id: 20240311_041502_00001_1.3.0][IP: 192.168.130.9][DataRegion: 11] - Total Wall Time: 39912 ms - Cost of initDataQuerySource: 15.439 ms - Seq File(unclosed): 0, Seq File(closed): 2 - UnSeq File(unclosed): 0, UnSeq File(closed): 0 - ready queued time: 152.988 ms, blocked queued time: 37775.356 ms - [PlanNodeId 20786]: IdentitySinkNode(IdentitySinkOperator) Count: * 1 - CPU Time: 2020.258 ms - input: 48800 rows - HasNext() Called Count: 978 - Next() Called Count: 978 - Estimated Memory Size: : 42336256 - [PlanNodeId 20771]: FullOuterTimeJoinNode(FullOuterTimeJoinOperator) Count: * 8 - CPU Time: 5255.307 ms - input: 195800 rows - HasNext() Called Count: 2455 - Next() Called Count: 2448 - Estimated Memory Size: : 42336256 - [PlanNodeId 11867]: SeriesScanNode(SeriesScanOperator) Count: * 1680 - CPU Time: 1248.080 ms - input: 168000 rows - HasNext() Called Count: 3198 - Next() Called Count: 1680 - Estimated Memory Size: : 41287680 - -...... -``` - -### 常见问题 - -#### WALL TIME(墙上时间)和 CPU TIME(CPU时间)的区别? - -CPU 时间也称为处理器时间或处理器使用时间,指的是程序在执行过程中实际占用 CPU 进行计算的时间,显示的是程序实际消耗的处理器资源。 - -墙上时间也称为实际时间或物理时间,指的是从程序开始执行到程序结束的总时间,包括了所有等待时间。 - -1. WALL TIME < CPU TIME 的场景:比如一个查询分片最后被调度器使用两个线程并行执行,真实物理世界上是 10s 过去了,但两个线程,可能一直占了两个 cpu 核跑了 10s,那 cpu time 就是 20s,wall time就是 10s -2. WALL TIME > CPU TIME 的场景:因为系统内可能会存在多个查询并行执行,但查询的执行线程数和内存是固定的, - 1. 所以当查询分片被某些资源阻塞住时(比如没有足够的内存进行数据传输、或等待上游数据)就会放入Blocked Queue,此时查询分片并不会占用 CPU TIME,但WALL TIME(真实物理时间的时间)是在向前流逝的 - 2. 或者当查询线程资源不足时,比如当前共有16个查询线程,但系统内并发有20个查询分片,即使所有查询都没有被阻塞,也只会同时并行运行16个查询分片,另外四个会被放入 READY QUEUE,等待被调度执行,此时查询分片并不会占用 CPU TIME,但WALL TIME(真实物理时间的时间)是在向前流逝的 - -#### Explain Analyze 是否有额外开销,测出的耗时是否与查询真实执行时有差别? - -几乎没有,因为 explain analyze operator 是单独的线程执行,收集原查询的统计信息,且这些统计信息,即使不explain analyze,原来的查询也会生成,只是没有人去取。并且 explain analyze 是纯 next 遍历结果集,不会打印,所以与原来查询真实执行时的耗时不会有显著差别。 - -#### IO 耗时主要关注几个指标? - -可能涉及 IO 耗时的主要有个指标,loadTimeSeriesMetadataDiskSeqTime, loadTimeSeriesMetadataDiskUnSeqTime 以及 construct[NonAligned/Aligned]ChunkReadersDiskTime - -TimeSeriesMetadata 的加载分别统计了顺序和乱序文件,但 Chunk 的读取暂时未分开统计,但顺乱序比例可以通过TimeseriesMetadata 顺乱序的比例计算出来。 - -#### 乱序数据对查询性能的影响能否有一些指标展示出来? - -乱序数据产生的影响主要有两个: - -1. 需要在内存中多做一个归并排序(一般认为这个耗时是比较短的,毕竟是纯内存的 cpu 操作) -2. 乱序数据会产生数据块间的时间范围重叠,导致统计信息无法使用 - 1. 无法利用统计信息直接 skip 掉整个不满足值过滤要求的 chunk - 1. 一般用户的查询都是只包含时间过滤条件,则不会有影响 - 2. 无法利用统计信息直接计算出聚合值,无需读取数据 - -单独对于乱序数据的性能影响,目前并没有有效的观测手段,除非就是在有乱序数据的时候,执行一遍查询耗时,然后等乱序合完了,再执行一遍,才能对比出来。 - -因为即使乱序这部分数据进了顺序,也是需要 IO、加压缩、decode,这个耗时少不了,不会因为乱序数据被合并进乱序了,就减少了。 - -#### 执行 explain analyze 时,查询超时后,为什么结果没有输出在 log_explain_analyze.log 中? - -升级时,只替换了 lib 包,没有替换 conf/logback-datanode.xml,需要替换一下 conf/logback-datanode.xml,然后不需要重启(该文件内容可以被热加载),大约等待 1 分钟后,重新执行 explain analyze verbose。 - -### 实战案例 - -#### 案例一:查询涉及文件数量过多,磁盘IO成为瓶颈,导致查询速度变慢 - -![explain-analyze-3.png](/img/explain-analyze-3.png) - -查询总耗时为 938 ms,其中从文件中读取索引区和数据区的耗时占据 918 ms,涉及了总共 289 个文件,假设查询涉及 N 个 TsFile,磁盘单次 seek 耗时为 t_seek,读取文件尾部索引的耗时为 t_index,读取文件的数据块的耗时为 t_chunk,则首次查询(未命中缓存)的理论耗时为 `cost = N * (t_seek + t_index + t_seek + t_chunk)`,按经验值,HDD 磁盘的一次 seek 耗时约为 5-10ms,所以查询涉及的文件数越多,查询延迟会越大。 - -最终优化方案为: - -1. 调整合并参数,降低文件数量 -2. 更换 HDD 为 SSD,降低磁盘单次 IO 的延迟 - -#### 案例二:like 谓词执行慢导致查询超时 - -执行如下 sql 时,查询超时(默认超时时间为 60s) - -```SQL -select count(s1) as total from root.db.d1 where s1 like '%XXXXXXXX%' -``` - -执行 explain analyze verbose 时,即使查询超时,也会每隔 15s,将阶段性的采集结果输出到 log_explain_analyze.log 中,从 log_explain_analyze.log 中得到最后两次的输出结果如下: - -![explain-analyze-4.png](/img/explain-analyze-4.png) - -![explain-analyze-5.png](/img/explain-analyze-5.png) - -观察结果,我们发现是因为查询未加时间条件,涉及的数据太多 constructAlignedChunkReadersDiskTime 和 pageReadersDecodeAlignedDiskTime的耗时一直在涨,意味着一直在读新的 chunk。但 AlignedSeriesScanNode 的输出信息一直是 0,这是因为算子只有在输出至少一行满足条件的数据时,才会让出时间片,并更新信息。从总的读取耗时(loadTimeSeriesMetadataAlignedDiskSeqTime + loadTimeSeriesMetadataAlignedDiskUnSeqTime + constructAlignedChunkReadersDiskTime + pageReadersDecodeAlignedDiskTime=约13.4秒)来看,其他耗时(60s - 13.4 = 46.6)应该都是在执行过滤条件上(like 谓词的执行很耗时)。 - -最终优化方案为:增加时间过滤条件,避免全表扫描 - -## Start/Stop Repair Data 语句 -用于修复由于系统 bug 导致的乱序(1.3.1 以上版本支持此命令) -### START REPAIR DATA - -启动一个数据修复任务,扫描创建修复任务的时间之前产生的 tsfile 文件并修复有乱序错误的文件。 - -```sql -IoTDB> START REPAIR DATA -IoTDB> START REPAIR DATA ON LOCAL -IoTDB> START REPAIR DATA ON CLUSTER -``` - -### STOP REPAIR DATA - -停止一个进行中的修复任务。如果需要再次恢复一个已停止的数据修复任务的进度,可以重新执行 `START REPAIR DATA`. - -```sql -IoTDB> STOP REPAIR DATA -IoTDB> STOP REPAIR DATA ON LOCAL -IoTDB> STOP REPAIR DATA ON CLUSTER -``` - diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_apache.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_apache.md deleted file mode 100644 index 0ee8684db..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_apache.md +++ /dev/null @@ -1,1283 +0,0 @@ - - -# 元数据管理 -## 数据库管理 - -数据库(Database)可以被视为关系数据库中的Database。 - -### 创建数据库 - -我们可以根据存储模型建立相应的数据库。如下所示: - -``` -IoTDB > CREATE DATABASE root.ln -``` - -需要注意的是,推荐创建一个 database. - -Database 的父子节点都不能再设置 database。例如在已经有`root.ln`和`root.sgcc`这两个 database 的情况下,创建`root.ln.wf01` database 是不可行的。系统将给出相应的错误提示,如下所示: - -``` -IoTDB> CREATE DATABASE root.ln.wf01 -Msg: 300: root.ln has already been created as database. -``` -Database 节点名只支持中英文字符、数字、下划线、英文句号和反引号的组合,如果想设置为纯数字或者包含下划线和英文句号,需要用反引号(` `` `)把 database 名称引起来。其中` `` `内,两个反引号表示一个反引号,例如 ` ```` ` 表示`` ` ``。 - -还需注意,如果在 Windows 系统上部署,database 名是大小写不敏感的。例如同时创建`root.ln` 和 `root.LN` 是不被允许的。 - -### 查看数据库 - -在 database 创建后,我们可以使用 [SHOW DATABASES](../SQL-Manual/SQL-Manual.md#查看数据库) 语句和 [SHOW DATABASES \](../SQL-Manual/SQL-Manual.md#查看数据库) 来查看 database,SQL 语句如下所示: - -``` -IoTDB> show databases -IoTDB> show databases root.* -IoTDB> show databases root.** -``` - -执行结果为: - -``` -+-------------+----+-------------------------+-----------------------+-----------------------+ -| database| ttl|schema_replication_factor|data_replication_factor|time_partition_interval| -+-------------+----+-------------------------+-----------------------+-----------------------+ -| root.sgcc|null| 2| 2| 604800| -| root.ln|null| 2| 2| 604800| -+-------------+----+-------------------------+-----------------------+-----------------------+ -Total line number = 2 -It costs 0.060s -``` - -### 删除数据库 - -用户可以使用`DELETE DATABASE `语句删除该路径模式匹配的所有的数据库。在删除的过程中,需要注意的是数据库的数据也会被删除。 - -``` -IoTDB > DELETE DATABASE root.ln -IoTDB > DELETE DATABASE root.sgcc -// 删除所有数据,时间序列以及数据库 -IoTDB > DELETE DATABASE root.** -``` - -### 统计数据库数量 - -用户可以使用`COUNT DATABASES `语句统计数据库的数量,允许指定`PathPattern` 用来统计匹配该`PathPattern` 的数据库的数量 - -SQL 语句如下所示: - -``` -IoTDB> show databases -IoTDB> count databases -IoTDB> count databases root.* -IoTDB> count databases root.sgcc.* -IoTDB> count databases root.sgcc -``` - -执行结果为: - -``` -+-------------+ -| database| -+-------------+ -| root.sgcc| -| root.turbine| -| root.ln| -+-------------+ -Total line number = 3 -It costs 0.003s - -+-------------+ -| Database| -+-------------+ -| 3| -+-------------+ -Total line number = 1 -It costs 0.003s - -+-------------+ -| Database| -+-------------+ -| 3| -+-------------+ -Total line number = 1 -It costs 0.002s - -+-------------+ -| Database| -+-------------+ -| 0| -+-------------+ -Total line number = 1 -It costs 0.002s - -+-------------+ -| database| -+-------------+ -| 1| -+-------------+ -Total line number = 1 -It costs 0.002s -``` - -### TTL - -IoTDB 支持对 database 级别设置数据存活时间(TTL),这使得 IoTDB 可以定期、自动地删除一定时间之前的数据。合理使用 TTL -可以帮助您控制 IoTDB 占用的总磁盘空间以避免出现磁盘写满等异常。并且,随着文件数量的增多,查询性能往往随之下降, -内存占用也会有所提高。及时地删除一些较老的文件有助于使查询性能维持在一个较高的水平和减少内存资源的占用。 - -TTL的默认单位为毫秒,如果配置文件中的时间精度修改为其他单位,设置ttl时仍然使用毫秒单位。 - -#### 设置 TTL - -设置 TTL 的 SQL 语句如下所示: -``` -IoTDB> set ttl to root.ln 3600000 -``` -这个例子表示在`root.ln`数据库中,只有3600000毫秒,即最近一个小时的数据将会保存,旧数据会被移除或不可见。 -``` -IoTDB> set ttl to root.sgcc.** 3600000 -``` -支持给某一路径下的 database 设置TTL,这个例子表示`root.sgcc`路径下的所有 database 设置TTL。 -``` -IoTDB> set ttl to root.** 3600000 -``` -表示给所有 database 设置TTL。 - -#### 取消 TTL - -取消 TTL 的 SQL 语句如下所示: - -``` -IoTDB> unset ttl to root.ln -``` - -取消设置 TTL 后, database `root.ln`中所有的数据都会被保存。 -``` -IoTDB> unset ttl to root.sgcc.** -``` - -取消设置`root.sgcc`路径下的所有 database 的 TTL 。 -``` -IoTDB> unset ttl to root.** -``` - -取消设置所有 database 的 TTL 。 - -#### 显示 TTL - -显示 TTL 的 SQL 语句如下所示: - -``` -IoTDB> SHOW ALL TTL -IoTDB> SHOW TTL ON DataBaseNames -``` - -SHOW ALL TTL 这个例子会给出所有 database 的 TTL。 -SHOW TTL ON root.ln,root.sgcc,root.DB 这个例子会显示指定的三个 database 的 TTL。 -注意:没有设置 TTL 的 database 的 TTL 将显示为 null。 - -``` -IoTDB> show all ttl -+-------------+-------+ -| database|ttl(ms)| -+-------------+-------+ -| root.ln|3600000| -| root.sgcc| null| -| root.DB|3600000| -+-------------+-------+ -``` - - - -### 设置异构数据库(进阶操作) - -在熟悉 IoTDB 元数据建模的前提下,用户可以在 IoTDB 中设置异构的数据库,以便应对不同的生产需求。 - -目前支持的数据库异构参数有: - -| 参数名 | 参数类型 | 参数描述 | -|---------------------------|---------|---------------------------| -| TTL | Long | 数据库的 TTL | -| SCHEMA_REPLICATION_FACTOR | Integer | 数据库的元数据副本数 | -| DATA_REPLICATION_FACTOR | Integer | 数据库的数据副本数 | -| SCHEMA_REGION_GROUP_NUM | Integer | 数据库的 SchemaRegionGroup 数量 | -| DATA_REGION_GROUP_NUM | Integer | 数据库的 DataRegionGroup 数量 | - -用户在配置异构参数时需要注意以下三点: -+ TTL 和 TIME_PARTITION_INTERVAL 必须为正整数。 -+ SCHEMA_REPLICATION_FACTOR 和 DATA_REPLICATION_FACTOR 必须小于等于已部署的 DataNode 数量。 -+ SCHEMA_REGION_GROUP_NUM 和 DATA_REGION_GROUP_NUM 的功能与 iotdb-common.properties 配置文件中的 -`schema_region_group_extension_policy` 和 `data_region_group_extension_policy` 参数相关,以 DATA_REGION_GROUP_NUM 为例: -若设置 `data_region_group_extension_policy=CUSTOM`,则 DATA_REGION_GROUP_NUM 将作为 Database 拥有的 DataRegionGroup 的数量; -若设置 `data_region_group_extension_policy=AUTO`,则 DATA_REGION_GROUP_NUM 将作为 Database 拥有的 DataRegionGroup 的配额下界,即当该 Database 开始写入数据时,将至少拥有此数量的 DataRegionGroup。 - -用户可以在创建 Database 时设置任意异构参数,或在单机/分布式 IoTDB 运行时调整部分异构参数。 - -#### 创建 Database 时设置异构参数 - -用户可以在创建 Database 时设置上述任意异构参数,SQL 语句如下所示: - -``` -CREATE DATABASE prefixPath (WITH databaseAttributeClause (COMMA? databaseAttributeClause)*)? -``` - -例如: -``` -CREATE DATABASE root.db WITH SCHEMA_REPLICATION_FACTOR=1, DATA_REPLICATION_FACTOR=3, SCHEMA_REGION_GROUP_NUM=1, DATA_REGION_GROUP_NUM=2; -``` - -#### 运行时调整异构参数 - -用户可以在 IoTDB 运行时调整部分异构参数,SQL 语句如下所示: - -``` -ALTER DATABASE prefixPath WITH databaseAttributeClause (COMMA? databaseAttributeClause)* -``` - -例如: -``` -ALTER DATABASE root.db WITH SCHEMA_REGION_GROUP_NUM=1, DATA_REGION_GROUP_NUM=2; -``` - -注意,运行时只能调整下列异构参数: -+ SCHEMA_REGION_GROUP_NUM -+ DATA_REGION_GROUP_NUM - -#### 查看异构数据库 - -用户可以查询每个 Database 的具体异构配置,SQL 语句如下所示: - -``` -SHOW DATABASES DETAILS prefixPath? -``` - -例如: - -``` -IoTDB> SHOW DATABASES DETAILS -+--------+--------+-----------------------+---------------------+---------------------+--------------------+-----------------------+-----------------------+------------------+---------------------+---------------------+ -|Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|MinSchemaRegionGroupNum|MaxSchemaRegionGroupNum|DataRegionGroupNum|MinDataRegionGroupNum|MaxDataRegionGroupNum| -+--------+--------+-----------------------+---------------------+---------------------+--------------------+-----------------------+-----------------------+------------------+---------------------+---------------------+ -|root.db1| null| 1| 3| 604800000| 0| 1| 1| 0| 2| 2| -|root.db2|86400000| 1| 1| 604800000| 0| 1| 1| 0| 2| 2| -|root.db3| null| 1| 1| 604800000| 0| 1| 1| 0| 2| 2| -+--------+--------+-----------------------+---------------------+---------------------+--------------------+-----------------------+-----------------------+------------------+---------------------+---------------------+ -Total line number = 3 -It costs 0.058s -``` - -各列查询结果依次为: -+ 数据库名称 -+ 数据库的 TTL -+ 数据库的元数据副本数 -+ 数据库的数据副本数 -+ 数据库的时间分区间隔 -+ 数据库当前拥有的 SchemaRegionGroup 数量 -+ 数据库需要拥有的最小 SchemaRegionGroup 数量 -+ 数据库允许拥有的最大 SchemaRegionGroup 数量 -+ 数据库当前拥有的 DataRegionGroup 数量 -+ 数据库需要拥有的最小 DataRegionGroup 数量 -+ 数据库允许拥有的最大 DataRegionGroup 数量 - - -## 设备模板管理 - -IoTDB 支持设备模板功能,实现同类型不同实体的物理量元数据共享,减少元数据内存占用,同时简化同类型实体的管理。 - - -![img](/img/%E6%A8%A1%E6%9D%BF.png) - -![img](/img/template.jpg) - -### 创建设备模板 - -创建设备模板的 SQL 语法如下: - -```sql -CREATE DEVICE TEMPLATE ALIGNED? '(' [',' ]+ ')' -``` - -**示例1:** 创建包含两个非对齐序列的元数据模板 - -```shell -IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY) -``` - -**示例2:** 创建包含一组对齐序列的元数据模板 - -```shell -IoTDB> create device template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla) -``` - -其中,物理量 `lat` 和 `lon` 是对齐的。 - -### 挂载设备模板 - -元数据模板在创建后,需执行挂载操作,方可用于相应路径下的序列创建与数据写入。 - -**挂载模板前,需确保相关数据库已经创建。** - -**推荐将模板挂载在 database 节点上,不建议将模板挂载到 database 上层的节点上。** - -**模板挂载路径下禁止创建普通序列,已创建了普通序列的前缀路径上不允许挂载模板。** - -挂载元数据模板的 SQL 语句如下所示: - -```shell -IoTDB> set device template t1 to root.sg1.d1 -``` - -### 激活设备模板 - -挂载好设备模板后,且系统开启自动注册序列功能的情况下,即可直接进行数据的写入。例如 database 为 root.sg1,模板 t1 被挂载到了节点 root.sg1.d1,那么可直接向时间序列(如 root.sg1.d1.temperature 和 root.sg1.d1.status)写入时间序列数据,该时间序列已可被当作正常创建的序列使用。 - -**注意**:在插入数据之前或系统未开启自动注册序列功能,模板定义的时间序列不会被创建。可以使用如下SQL语句在插入数据前创建时间序列即激活模板: - -```shell -IoTDB> create timeseries using device template on root.sg1.d1 -``` - -**示例:** 执行以下语句 -```shell -IoTDB> set device template t1 to root.sg1.d1 -IoTDB> set device template t2 to root.sg1.d2 -IoTDB> create timeseries using device template on root.sg1.d1 -IoTDB> create timeseries using device template on root.sg1.d2 -``` - -查看此时的时间序列: -```sql -show timeseries root.sg1.** -``` - -```shell -+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression|tags|attributes|deadband|deadband parameters| -+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -|root.sg1.d1.temperature| null| root.sg1| FLOAT| RLE| SNAPPY|null| null| null| null| -| root.sg1.d1.status| null| root.sg1| BOOLEAN| PLAIN| SNAPPY|null| null| null| null| -| root.sg1.d2.lon| null| root.sg1| FLOAT| GORILLA| SNAPPY|null| null| null| null| -| root.sg1.d2.lat| null| root.sg1| FLOAT| GORILLA| SNAPPY|null| null| null| null| -+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -``` - -查看此时的设备: -```sql -show devices root.sg1.** -``` - -```shell -+---------------+---------+---------+ -| devices|isAligned| Template| -+---------------+---------+---------+ -| root.sg1.d1| false| null| -| root.sg1.d2| true| null| -+---------------+---------+---------+ -``` - -### 查看设备模板 - -- 查看所有设备模板 - -SQL 语句如下所示: - -```shell -IoTDB> show device templates -``` - -执行结果如下: -```shell -+-------------+ -|template name| -+-------------+ -| t2| -| t1| -+-------------+ -``` - -- 查看某个设备模板下的物理量 - -SQL 语句如下所示: - -```shell -IoTDB> show nodes in device template t1 -``` - -执行结果如下: -```shell -+-----------+--------+--------+-----------+ -|child nodes|dataType|encoding|compression| -+-----------+--------+--------+-----------+ -|temperature| FLOAT| RLE| SNAPPY| -| status| BOOLEAN| PLAIN| SNAPPY| -+-----------+--------+--------+-----------+ -``` - -- 查看挂载了某个设备模板的路径 - -```shell -IoTDB> show paths set device template t1 -``` - -执行结果如下: -```shell -+-----------+ -|child paths| -+-----------+ -|root.sg1.d1| -+-----------+ -``` - -- 查看使用了某个设备模板的路径(即模板在该路径上已激活,序列已创建) - -```shell -IoTDB> show paths using device template t1 -``` - -执行结果如下: -```shell -+-----------+ -|child paths| -+-----------+ -|root.sg1.d1| -+-----------+ -``` - -### 解除设备模板 - -若需删除模板表示的某一组时间序列,可采用解除模板操作,SQL语句如下所示: - -```shell -IoTDB> delete timeseries of device template t1 from root.sg1.d1 -``` - -或 - -```shell -IoTDB> deactivate device template t1 from root.sg1.d1 -``` - -解除操作支持批量处理,SQL语句如下所示: - -```shell -IoTDB> delete timeseries of device template t1 from root.sg1.*, root.sg2.* -``` - -或 - -```shell -IoTDB> deactivate device template t1 from root.sg1.*, root.sg2.* -``` - -若解除命令不指定模板名称,则会将给定路径涉及的所有模板使用情况均解除。 - -### 卸载设备模板 - -卸载设备模板的 SQL 语句如下所示: - -```shell -IoTDB> unset device template t1 from root.sg1.d1 -``` - -**注意**:不支持卸载仍处于激活状态的模板,需保证执行卸载操作前解除对该模板的所有使用,即删除所有该模板表示的序列。 - -### 删除设备模板 - -删除设备模板的 SQL 语句如下所示: - -```shell -IoTDB> drop device template t1 -``` - -**注意**:不支持删除已经挂载的模板,需在删除操作前保证该模板卸载成功。 - -### 修改设备模板 - -在需要新增物理量的场景中,可以通过修改设备模板来给所有已激活该模板的设备新增物理量。 - -修改设备模板的 SQL 语句如下所示: - -```shell -IoTDB> alter device template t1 add (speed FLOAT encoding=RLE, FLOAT TEXT encoding=PLAIN compression=SNAPPY) -``` - -**向已挂载模板的路径下的设备中写入数据,若写入请求中的物理量不在模板中,将自动扩展模板。** - - -## 时间序列管理 - -### 创建时间序列 - -根据建立的数据模型,我们可以分别在两个数据库中创建相应的时间序列。创建时间序列的 SQL 语句如下所示: - -``` -IoTDB > create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN -IoTDB > create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT,encoding=RLE -IoTDB > create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT,encoding=PLAIN -IoTDB > create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN,encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN,encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT,encoding=RLE -``` - -从 v0.13 起,可以使用简化版的 SQL 语句创建时间序列: - -``` -IoTDB > create timeseries root.ln.wf01.wt01.status BOOLEAN encoding=PLAIN -IoTDB > create timeseries root.ln.wf01.wt01.temperature FLOAT encoding=RLE -IoTDB > create timeseries root.ln.wf02.wt02.hardware TEXT encoding=PLAIN -IoTDB > create timeseries root.ln.wf02.wt02.status BOOLEAN encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.status BOOLEAN encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=RLE -``` - -需要注意的是,当创建时间序列时指定的编码方式与数据类型不对应时,系统会给出相应的错误提示,如下所示: -``` -IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF -error: encoding TS_2DIFF does not support BOOLEAN -``` - -详细的数据类型与编码方式的对应列表请参见 [编码方式](../Basic-Concept/Encoding-and-Compression.md)。 - -### 创建对齐时间序列 - -创建一组对齐时间序列的SQL语句如下所示: - -``` -IoTDB> CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY) -``` - -一组对齐序列中的序列可以有不同的数据类型、编码方式以及压缩方式。 - -对齐的时间序列也支持设置别名、标签、属性。 - -### 删除时间序列 - -我们可以使用`(DELETE | DROP) TimeSeries `语句来删除我们之前创建的时间序列。SQL 语句如下所示: - -``` -IoTDB> delete timeseries root.ln.wf01.wt01.status -IoTDB> delete timeseries root.ln.wf01.wt01.temperature, root.ln.wf02.wt02.hardware -IoTDB> delete timeseries root.ln.wf02.* -IoTDB> drop timeseries root.ln.wf02.* -``` - -### 查看时间序列 - -* SHOW LATEST? TIMESERIES pathPattern? timeseriesWhereClause? limitClause? - - SHOW TIMESERIES 中可以有四种可选的子句,查询结果为这些时间序列的所有信息 - -时间序列信息具体包括:时间序列路径名,database,Measurement 别名,数据类型,编码方式,压缩方式,属性和标签。 - -示例: - -* SHOW TIMESERIES - - 展示系统中所有的时间序列信息 - -* SHOW TIMESERIES <`Path`> - - 返回给定路径的下的所有时间序列信息。其中 `Path` 需要为一个时间序列路径或路径模式。例如,分别查看`root`路径和`root.ln`路径下的时间序列,SQL 语句如下所示: - -``` -IoTDB> show timeseries root.** -IoTDB> show timeseries root.ln.** -``` - -执行结果分别为: - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -|root.sgcc.wf03.wt01.temperature| null| root.sgcc| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.sgcc.wf03.wt01.status| null| root.sgcc| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -| root.turbine.d1.s1|newAlias| root.turbine| FLOAT| RLE| SNAPPY|{"newTag1":"newV1","tag4":"v4","tag3":"v3"}|{"attr2":"v2","attr1":"newV1","attr4":"v4","attr3":"v3"}| null| null| -| root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY| null| null| null| null| -| root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 7 -It costs 0.016s - -+-----------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression|tags|attributes|deadband|deadband parameters| -+-----------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -| root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY|null| null| null| null| -| root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY|null| null| null| null| -|root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY|null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY|null| null| null| null| -+-----------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -Total line number = 4 -It costs 0.004s -``` - -* SHOW TIMESERIES LIMIT INT OFFSET INT - - 只返回从指定下标开始的结果,最大返回条数被 LIMIT 限制,用于分页查询。例如: - -``` -show timeseries root.ln.** limit 10 offset 10 -``` - -* SHOW TIMESERIES WHERE TIMESERIES contains 'containStr' - - 对查询结果集根据 timeseries 名称进行字符串模糊匹配过滤。例如: - -``` -show timeseries root.ln.** where timeseries contains 'wf01.wt' -``` - -执行结果为: - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 2 -It costs 0.016s -``` - -* SHOW TIMESERIES WHERE DataType=type - - 对查询结果集根据时间序列数据类型进行过滤。例如: - -``` -show timeseries root.ln.** where dataType=FLOAT -``` - -执行结果为: - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -|root.sgcc.wf03.wt01.temperature| null| root.sgcc| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.turbine.d1.s1|newAlias| root.turbine| FLOAT| RLE| SNAPPY|{"newTag1":"newV1","tag4":"v4","tag3":"v3"}|{"attr2":"v2","attr1":"newV1","attr4":"v4","attr3":"v3"}| null| null| -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 3 -It costs 0.016s - -``` - - -* SHOW LATEST TIMESERIES - - 表示查询出的时间序列需要按照最近插入时间戳降序排列 - - -需要注意的是,当查询路径不存在时,系统会返回 0 条时间序列。 - -### 统计时间序列总数 - -IoTDB 支持使用`COUNT TIMESERIES`来统计一条路径中的时间序列个数。SQL 语句如下所示: - -* 可以通过 `WHERE` 条件对时间序列名称进行字符串模糊匹配,语法为: `COUNT TIMESERIES WHERE TIMESERIES contains 'containStr'` 。 -* 可以通过 `WHERE` 条件对时间序列数据类型进行过滤,语法为: `COUNT TIMESERIES WHERE DataType='`。 -* 可以通过 `WHERE` 条件对标签点进行过滤,语法为: `COUNT TIMESERIES WHERE TAGS(key)='value'` 或 `COUNT TIMESERIES WHERE TAGS(key) contains 'value'`。 -* 可以通过定义`LEVEL`来统计指定层级下的时间序列个数。这条语句可以用来统计每一个设备下的传感器数量,语法为:`COUNT TIMESERIES GROUP BY LEVEL=`。 - -``` -IoTDB > COUNT TIMESERIES root.** -IoTDB > COUNT TIMESERIES root.ln.** -IoTDB > COUNT TIMESERIES root.ln.*.*.status -IoTDB > COUNT TIMESERIES root.ln.wf01.wt01.status -IoTDB > COUNT TIMESERIES root.** WHERE TIMESERIES contains 'sgcc' -IoTDB > COUNT TIMESERIES root.** WHERE DATATYPE = INT64 -IoTDB > COUNT TIMESERIES root.** WHERE TAGS(unit) contains 'c' -IoTDB > COUNT TIMESERIES root.** WHERE TAGS(unit) = 'c' -IoTDB > COUNT TIMESERIES root.** WHERE TIMESERIES contains 'sgcc' group by level = 1 -``` - -例如有如下时间序列(可以使用`show timeseries`展示所有时间序列): - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -|root.sgcc.wf03.wt01.temperature| null| root.sgcc| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.sgcc.wf03.wt01.status| null| root.sgcc| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -| root.turbine.d1.s1|newAlias| root.turbine| FLOAT| RLE| SNAPPY|{"newTag1":"newV1","tag4":"v4","tag3":"v3"}|{"attr2":"v2","attr1":"newV1","attr4":"v4","attr3":"v3"}| null| null| -| root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY| {"unit":"c"}| null| null| null| -| root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| {"description":"test1"}| null| null| null| -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 7 -It costs 0.004s -``` - -那么 Metadata Tree 如下所示: - - - -可以看到,`root`被定义为`LEVEL=0`。那么当你输入如下语句时: - -``` -IoTDB > COUNT TIMESERIES root.** GROUP BY LEVEL=1 -IoTDB > COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2 -IoTDB > COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=2 -``` - -你将得到以下结果: - -``` -IoTDB> COUNT TIMESERIES root.** GROUP BY LEVEL=1 -+------------+-----------------+ -| column|count(timeseries)| -+------------+-----------------+ -| root.sgcc| 2| -|root.turbine| 1| -| root.ln| 4| -+------------+-----------------+ -Total line number = 3 -It costs 0.002s - -IoTDB > COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2 -+------------+-----------------+ -| column|count(timeseries)| -+------------+-----------------+ -|root.ln.wf02| 2| -|root.ln.wf01| 2| -+------------+-----------------+ -Total line number = 2 -It costs 0.002s - -IoTDB > COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=2 -+------------+-----------------+ -| column|count(timeseries)| -+------------+-----------------+ -|root.ln.wf01| 2| -+------------+-----------------+ -Total line number = 1 -It costs 0.002s -``` - -> 注意:时间序列的路径只是过滤条件,与 level 的定义无关。 - -### 活跃时间序列查询 -我们在原有的时间序列查询和统计上添加新的WHERE时间过滤条件,可以得到在指定时间范围中存在数据的时间序列。 - -一个使用样例如下: -``` -IoTDB> insert into root.sg.data(timestamp, s1,s2) values(15000, 1, 2); -IoTDB> insert into root.sg.data2(timestamp, s1,s2) values(15002, 1, 2); -IoTDB> insert into root.sg.data3(timestamp, s1,s2) values(16000, 1, 2); -IoTDB> show timeseries; -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| root.sg.data.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -| root.sg.data.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data3.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data3.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ - -IoTDB> show timeseries where time >= 15000 and time < 16000; -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| root.sg.data.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -| root.sg.data.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ - -``` -关于活跃时间序列的定义,能通过正常查询查出来的数据就是活跃数据,也就是说插入但被删除的时间序列不在考虑范围内。 - -### 标签点管理 - -我们可以在创建时间序列的时候,为它添加别名和额外的标签和属性信息。 - -标签和属性的区别在于: - -* 标签可以用来查询时间序列路径,会在内存中维护标点到时间序列路径的倒排索引:标签 -> 时间序列路径 -* 属性只能用时间序列路径来查询:时间序列路径 -> 属性 - -所用到的扩展的创建时间序列的 SQL 语句如下所示: -``` -create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2) -``` - -括号里的`temprature`是`s1`这个传感器的别名。 -我们可以在任何用到`s1`的地方,将其用`temprature`代替,这两者是等价的。 - -> IoTDB 同时支持在查询语句中使用 AS 函数设置别名。二者的区别在于:AS 函数设置的别名用于替代整条时间序列名,且是临时的,不与时间序列绑定;而上文中的别名只作为传感器的别名,与其绑定且可与原传感器名等价使用。 - -> 注意:额外的标签和属性信息总的大小不能超过`tag_attribute_total_size`. - - * 标签点属性更新 -创建时间序列后,我们也可以对其原有的标签点属性进行更新,主要有以下六种更新方式: -* 重命名标签或属性 -``` -ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1 -``` -* 重新设置标签或属性的值 -``` -ALTER timeseries root.turbine.d1.s1 SET newTag1=newV1, attr1=newV1 -``` -* 删除已经存在的标签或属性 -``` -ALTER timeseries root.turbine.d1.s1 DROP tag1, tag2 -``` -* 添加新的标签 -``` -ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4 -``` -* 添加新的属性 -``` -ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4 -``` -* 更新插入别名,标签和属性 -> 如果该别名,标签或属性原来不存在,则插入,否则,用新值更新原来的旧值 -``` -ALTER timeseries root.turbine.d1.s1 UPSERT ALIAS=newAlias TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4) -``` - -* 使用标签作为过滤条件查询时间序列,使用 TAGS(tagKey) 来标识作为过滤条件的标签 -``` -SHOW TIMESERIES (<`PathPattern`>)? timeseriesWhereClause -``` - -返回给定路径的下的所有满足条件的时间序列信息,SQL 语句如下所示: - -``` -ALTER timeseries root.ln.wf02.wt02.hardware ADD TAGS unit=c -ALTER timeseries root.ln.wf02.wt02.status ADD TAGS description=test1 -show timeseries root.ln.** where TAGS(unit)='c' -show timeseries root.ln.** where TAGS(description) contains 'test1' -``` - -执行结果分别为: - -``` -+--------------------------+-----+-------------+--------+--------+-----------+------------+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags|attributes|deadband|deadband parameters| -+--------------------------+-----+-------------+--------+--------+-----------+------------+----------+--------+-------------------+ -|root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY|{"unit":"c"}| null| null| null| -+--------------------------+-----+-------------+--------+--------+-----------+------------+----------+--------+-------------------+ -Total line number = 1 -It costs 0.005s - -+------------------------+-----+-------------+--------+--------+-----------+-----------------------+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags|attributes|deadband|deadband parameters| -+------------------------+-----+-------------+--------+--------+-----------+-----------------------+----------+--------+-------------------+ -|root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY|{"description":"test1"}| null| null| null| -+------------------------+-----+-------------+--------+--------+-----------+-----------------------+----------+--------+-------------------+ -Total line number = 1 -It costs 0.004s -``` - -- 使用标签作为过滤条件统计时间序列数量 - -``` -COUNT TIMESERIES (<`PathPattern`>)? timeseriesWhereClause -COUNT TIMESERIES (<`PathPattern`>)? timeseriesWhereClause GROUP BY LEVEL= -``` - -返回给定路径的下的所有满足条件的时间序列的数量,SQL 语句如下所示: - -``` -count timeseries -count timeseries root.** where TAGS(unit)='c' -count timeseries root.** where TAGS(unit)='c' group by level = 2 -``` - -执行结果分别为: - -``` -IoTDB> count timeseries -+-----------------+ -|count(timeseries)| -+-----------------+ -| 6| -+-----------------+ -Total line number = 1 -It costs 0.019s -IoTDB> count timeseries root.** where TAGS(unit)='c' -+-----------------+ -|count(timeseries)| -+-----------------+ -| 2| -+-----------------+ -Total line number = 1 -It costs 0.020s -IoTDB> count timeseries root.** where TAGS(unit)='c' group by level = 2 -+--------------+-----------------+ -| column|count(timeseries)| -+--------------+-----------------+ -| root.ln.wf02| 2| -| root.ln.wf01| 0| -|root.sgcc.wf03| 0| -+--------------+-----------------+ -Total line number = 3 -It costs 0.011s -``` - -> 注意,现在我们只支持一个查询条件,要么是等值条件查询,要么是包含条件查询。当然 where 子句中涉及的必须是标签值,而不能是属性值。 - -创建对齐时间序列 - -``` -create aligned timeseries root.sg1.d1(s1 INT32 tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2), s2 DOUBLE tags(tag3=v3, tag4=v4) attributes(attr3=v3, attr4=v4)) -``` - -执行结果如下: - -``` -IoTDB> show timeseries -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -|root.sg1.d1.s1| null| root.sg1| INT32| RLE| SNAPPY|{"tag1":"v1","tag2":"v2"}|{"attr2":"v2","attr1":"v1"}| null| null| -|root.sg1.d1.s2| null| root.sg1| DOUBLE| GORILLA| SNAPPY|{"tag4":"v4","tag3":"v3"}|{"attr4":"v4","attr3":"v3"}| null| null| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -``` - -支持查询: - -``` -IoTDB> show timeseries where TAGS(tag1)='v1' -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -|root.sg1.d1.s1| null| root.sg1| INT32| RLE| SNAPPY|{"tag1":"v1","tag2":"v2"}|{"attr2":"v2","attr1":"v1"}| null| null| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -``` - -上述对时间序列标签、属性的更新等操作都支持。 - - -## 路径查询 - -### 查看路径的所有子路径 - -``` -SHOW CHILD PATHS pathPattern -``` - -可以查看此路径模式所匹配的所有路径的下一层的所有路径和它对应的节点类型,即pathPattern.*所匹配的路径及其节点类型。 - -节点类型:ROOT -> SG INTERNAL -> DATABASE -> INTERNAL -> DEVICE -> TIMESERIES - -示例: - -* 查询 root.ln 的下一层:show child paths root.ln - -``` -+------------+----------+ -| child paths|node types| -+------------+----------+ -|root.ln.wf01| INTERNAL| -|root.ln.wf02| INTERNAL| -+------------+----------+ -Total line number = 2 -It costs 0.002s -``` - -* 查询形如 root.xx.xx.xx 的路径:show child paths root.\*.\* - -``` -+---------------+ -| child paths| -+---------------+ -|root.ln.wf01.s1| -|root.ln.wf02.s2| -+---------------+ -``` - -### 查看路径的下一级节点 - -``` -SHOW CHILD NODES pathPattern -``` - -可以查看此路径模式所匹配的节点的下一层的所有节点。 - -示例: - -* 查询 root 的下一层:show child nodes root - -``` -+------------+ -| child nodes| -+------------+ -| ln| -+------------+ -``` - -* 查询 root.ln 的下一层 :show child nodes root.ln - -``` -+------------+ -| child nodes| -+------------+ -| wf01| -| wf02| -+------------+ -``` - -### 统计节点数 - -IoTDB 支持使用`COUNT NODES LEVEL=`来统计当前 Metadata - 树下满足某路径模式的路径中指定层级的节点个数。这条语句可以用来统计带有特定采样点的设备数。例如: - -``` -IoTDB > COUNT NODES root.** LEVEL=2 -IoTDB > COUNT NODES root.ln.** LEVEL=2 -IoTDB > COUNT NODES root.ln.wf01.* LEVEL=3 -IoTDB > COUNT NODES root.**.temperature LEVEL=3 -``` - -对于上面提到的例子和 Metadata Tree,你可以获得如下结果: - -``` -+------------+ -|count(nodes)| -+------------+ -| 4| -+------------+ -Total line number = 1 -It costs 0.003s - -+------------+ -|count(nodes)| -+------------+ -| 2| -+------------+ -Total line number = 1 -It costs 0.002s - -+------------+ -|count(nodes)| -+------------+ -| 1| -+------------+ -Total line number = 1 -It costs 0.002s - -+------------+ -|count(nodes)| -+------------+ -| 2| -+------------+ -Total line number = 1 -It costs 0.002s -``` - -> 注意:时间序列的路径只是过滤条件,与 level 的定义无关。 - -### 查看设备 - -* SHOW DEVICES pathPattern? (WITH DATABASE)? devicesWhereClause? limitClause? - -与 `Show Timeseries` 相似,IoTDB 目前也支持两种方式查看设备。 - -* `SHOW DEVICES` 语句显示当前所有的设备信息,等价于 `SHOW DEVICES root.**`。 -* `SHOW DEVICES ` 语句规定了 `PathPattern`,返回给定的路径模式所匹配的设备信息。 -* `WHERE` 条件中可以使用 `DEVICE contains 'xxx'`,根据 device 名称进行模糊查询。 -* `WHERE` 条件中可以使用 `TEMPLATE = 'xxx'`,`TEMPLATE != 'xxx'`,根据 template 名称进行过滤查询。 -* `WHERE` 条件中可以使用 `TEMPLATE is null`,`TEMPLATE is not null`,根据 template 是否为null(null 表示没激活)进行过滤查询。 - -SQL 语句如下所示: - -``` -IoTDB> show devices -IoTDB> show devices root.ln.** -IoTDB> show devices root.ln.** where device contains 't' -IoTDB> show devices root.ln.** where template = 't1' -IoTDB> show devices root.ln.** where template is null -IoTDB> show devices root.ln.** where template != 't1' -IoTDB> show devices root.ln.** where template is not null -``` - -你可以获得如下数据: - -``` -+-------------------+---------+---------+ -| devices|isAligned| Template| -+-------------------+---------+---------+ -| root.ln.wf01.wt01| false| t1| -| root.ln.wf02.wt02| false| null| -|root.sgcc.wf03.wt01| false| null| -| root.turbine.d1| false| null| -+-------------------+---------+---------+ -Total line number = 4 -It costs 0.002s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf01.wt01| false| t1| -|root.ln.wf02.wt02| false| null| -+-----------------+---------+---------+ -Total line number = 2 -It costs 0.001s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf01.wt01| false| t1| -|root.ln.wf02.wt02| false| null| -+-----------------+---------+---------+ -Total line number = 2 -It costs 0.001s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf01.wt01| false| t1| -+-----------------+---------+---------+ -Total line number = 1 -It costs 0.001s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf02.wt02| false| null| -+-----------------+---------+---------+ -Total line number = 1 -It costs 0.001s -``` - -其中,`isAligned`表示该设备下的时间序列是否对齐, -`Template`显示着该设备所激活的模板名,null 表示没有激活模板。 - -查看设备及其 database 信息,可以使用 `SHOW DEVICES WITH DATABASE` 语句。 - -* `SHOW DEVICES WITH DATABASE` 语句显示当前所有的设备信息和其所在的 database,等价于 `SHOW DEVICES root.**`。 -* `SHOW DEVICES WITH DATABASE` 语句规定了 `PathPattern`,返回给定的路径模式所匹配的设备信息和其所在的 database。 - -SQL 语句如下所示: - -``` -IoTDB> show devices with database -IoTDB> show devices root.ln.** with database -``` - -你可以获得如下数据: - -``` -+-------------------+-------------+---------+---------+ -| devices| database|isAligned| Template| -+-------------------+-------------+---------+---------+ -| root.ln.wf01.wt01| root.ln| false| t1| -| root.ln.wf02.wt02| root.ln| false| null| -|root.sgcc.wf03.wt01| root.sgcc| false| null| -| root.turbine.d1| root.turbine| false| null| -+-------------------+-------------+---------+---------+ -Total line number = 4 -It costs 0.003s - -+-----------------+-------------+---------+---------+ -| devices| database|isAligned| Template| -+-----------------+-------------+---------+---------+ -|root.ln.wf01.wt01| root.ln| false| t1| -|root.ln.wf02.wt02| root.ln| false| null| -+-----------------+-------------+---------+---------+ -Total line number = 2 -It costs 0.001s -``` - -### 统计设备数量 - -* COUNT DEVICES \ - -上述语句用于统计设备的数量,同时允许指定`PathPattern` 用于统计匹配该`PathPattern` 的设备数量 - -SQL 语句如下所示: - -``` -IoTDB> show devices -IoTDB> count devices -IoTDB> count devices root.ln.** -``` - -你可以获得如下数据: - -``` -+-------------------+---------+---------+ -| devices|isAligned| Template| -+-------------------+---------+---------+ -|root.sgcc.wf03.wt03| false| null| -| root.turbine.d1| false| null| -| root.ln.wf02.wt02| false| null| -| root.ln.wf01.wt01| false| t1| -+-------------------+---------+---------+ -Total line number = 4 -It costs 0.024s - -+--------------+ -|count(devices)| -+--------------+ -| 4| -+--------------+ -Total line number = 1 -It costs 0.004s - -+--------------+ -|count(devices)| -+--------------+ -| 2| -+--------------+ -Total line number = 1 -It costs 0.004s -``` - -### 活跃设备查询 -和活跃时间序列一样,我们可以在查看和统计设备的基础上添加时间过滤条件来查询在某段时间内存在数据的活跃设备。这里活跃的定义与活跃时间序列相同,使用样例如下: -``` -IoTDB> insert into root.sg.data(timestamp, s1,s2) values(15000, 1, 2); -IoTDB> insert into root.sg.data2(timestamp, s1,s2) values(15002, 1, 2); -IoTDB> insert into root.sg.data3(timestamp, s1,s2) values(16000, 1, 2); -IoTDB> show devices; -+-------------------+---------+ -| devices|isAligned| -+-------------------+---------+ -| root.sg.data| false| -| root.sg.data2| false| -| root.sg.data3| false| -+-------------------+---------+ - -IoTDB> show devices where time >= 15000 and time < 16000; -+-------------------+---------+ -| devices|isAligned| -+-------------------+---------+ -| root.sg.data| false| -| root.sg.data2| false| -+-------------------+---------+ - -IoTDB> count devices where time >= 15000 and time < 16000; -+--------------+ -|count(devices)| -+--------------+ -| 2| -+--------------+ -``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_timecho.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_timecho.md deleted file mode 100644 index 070fdd7b8..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata_timecho.md +++ /dev/null @@ -1,1285 +0,0 @@ - - -# 元数据管理 -## 数据库管理 - -数据库(Database)可以被视为关系数据库中的Database。 - -### 创建数据库 - -我们可以根据存储模型建立相应的数据库。如下所示: - -``` -IoTDB > CREATE DATABASE root.ln -``` - -需要注意的是,推荐创建一个 database. - -Database 的父子节点都不能再设置 database。例如在已经有`root.ln`和`root.sgcc`这两个 database 的情况下,创建`root.ln.wf01` database 是不可行的。系统将给出相应的错误提示,如下所示: - -``` -IoTDB> CREATE DATABASE root.ln.wf01 -Msg: 300: root.ln has already been created as database. -``` -Database 节点名只支持中英文字符、数字、下划线、英文句号和反引号的组合,如果想设置为纯数字或者包含下划线和英文句号,需要用反引号(` `` `)把 database 名称引起来。其中` `` `内,两个反引号表示一个反引号,例如 ` ```` ` 表示`` ` ``。 - -还需注意,如果在 Windows 系统上部署,database 名是大小写不敏感的。例如同时创建`root.ln` 和 `root.LN` 是不被允许的。 - -### 查看数据库 - -在 database 创建后,我们可以使用 [SHOW DATABASES](../SQL-Manual/SQL-Manual.md#查看数据库) 语句和 [SHOW DATABASES \](../SQL-Manual/SQL-Manual.md#查看数据库) 来查看 database,SQL 语句如下所示: - -``` -IoTDB> show databases -IoTDB> show databases root.* -IoTDB> show databases root.** -``` - -执行结果为: - -``` -+-------------+----+-------------------------+-----------------------+-----------------------+ -| database| ttl|schema_replication_factor|data_replication_factor|time_partition_interval| -+-------------+----+-------------------------+-----------------------+-----------------------+ -| root.sgcc|null| 2| 2| 604800| -| root.ln|null| 2| 2| 604800| -+-------------+----+-------------------------+-----------------------+-----------------------+ -Total line number = 2 -It costs 0.060s -``` - -### 删除数据库 - -用户可以使用`DELETE DATABASE `语句删除该路径模式匹配的所有的数据库。在删除的过程中,需要注意的是数据库的数据也会被删除。 - -``` -IoTDB > DELETE DATABASE root.ln -IoTDB > DELETE DATABASE root.sgcc -// 删除所有数据,时间序列以及数据库 -IoTDB > DELETE DATABASE root.** -``` - -### 统计数据库数量 - -用户可以使用`COUNT DATABASES `语句统计数据库的数量,允许指定`PathPattern` 用来统计匹配该`PathPattern` 的数据库的数量 - -SQL 语句如下所示: - -``` -IoTDB> show databases -IoTDB> count databases -IoTDB> count databases root.* -IoTDB> count databases root.sgcc.* -IoTDB> count databases root.sgcc -``` - -执行结果为: - -``` -+-------------+ -| database| -+-------------+ -| root.sgcc| -| root.turbine| -| root.ln| -+-------------+ -Total line number = 3 -It costs 0.003s - -+-------------+ -| Database| -+-------------+ -| 3| -+-------------+ -Total line number = 1 -It costs 0.003s - -+-------------+ -| Database| -+-------------+ -| 3| -+-------------+ -Total line number = 1 -It costs 0.002s - -+-------------+ -| Database| -+-------------+ -| 0| -+-------------+ -Total line number = 1 -It costs 0.002s - -+-------------+ -| database| -+-------------+ -| 1| -+-------------+ -Total line number = 1 -It costs 0.002s -``` - -### TTL - -IoTDB 支持对 database 级别设置数据存活时间(TTL),这使得 IoTDB 可以定期、自动地删除一定时间之前的数据。合理使用 TTL -可以帮助您控制 IoTDB 占用的总磁盘空间以避免出现磁盘写满等异常。并且,随着文件数量的增多,查询性能往往随之下降, -内存占用也会有所提高。及时地删除一些较老的文件有助于使查询性能维持在一个较高的水平和减少内存资源的占用。 - -TTL的默认单位为毫秒,如果配置文件中的时间精度修改为其他单位,设置ttl时仍然使用毫秒单位。 - -#### 设置 TTL - -设置 TTL 的 SQL 语句如下所示: -``` -IoTDB> set ttl to root.ln 3600000 -``` -这个例子表示在`root.ln`数据库中,只有3600000毫秒,即最近一个小时的数据将会保存,旧数据会被移除或不可见。 -``` -IoTDB> set ttl to root.sgcc.** 3600000 -``` -支持给某一路径下的 database 设置TTL,这个例子表示`root.sgcc`路径下的所有 database 设置TTL。 -``` -IoTDB> set ttl to root.** 3600000 -``` -表示给所有 database 设置TTL。 - -#### 取消 TTL - -取消 TTL 的 SQL 语句如下所示: - -``` -IoTDB> unset ttl to root.ln -``` - -取消设置 TTL 后, database `root.ln`中所有的数据都会被保存。 -``` -IoTDB> unset ttl to root.sgcc.** -``` - -取消设置`root.sgcc`路径下的所有 database 的 TTL 。 -``` -IoTDB> unset ttl to root.** -``` - -取消设置所有 database 的 TTL 。 - -#### 显示 TTL - -显示 TTL 的 SQL 语句如下所示: - -``` -IoTDB> SHOW ALL TTL -IoTDB> SHOW TTL ON DataBaseNames -``` - -SHOW ALL TTL 这个例子会给出所有 database 的 TTL。 -SHOW TTL ON root.ln,root.sgcc,root.DB 这个例子会显示指定的三个 database 的 TTL。 -注意:没有设置 TTL 的 database 的 TTL 将显示为 null。 - -``` -IoTDB> show all ttl -+-------------+-------+ -| database|ttl(ms)| -+-------------+-------+ -| root.ln|3600000| -| root.sgcc| null| -| root.DB|3600000| -+-------------+-------+ -``` - - - -### 设置异构数据库(进阶操作) - -在熟悉 IoTDB 元数据建模的前提下,用户可以在 IoTDB 中设置异构的数据库,以便应对不同的生产需求。 - -目前支持的数据库异构参数有: - -| 参数名 | 参数类型 | 参数描述 | -|---------------------------|---------|---------------------------| -| TTL | Long | 数据库的 TTL | -| SCHEMA_REPLICATION_FACTOR | Integer | 数据库的元数据副本数 | -| DATA_REPLICATION_FACTOR | Integer | 数据库的数据副本数 | -| SCHEMA_REGION_GROUP_NUM | Integer | 数据库的 SchemaRegionGroup 数量 | -| DATA_REGION_GROUP_NUM | Integer | 数据库的 DataRegionGroup 数量 | - -用户在配置异构参数时需要注意以下三点: -+ TTL 和 TIME_PARTITION_INTERVAL 必须为正整数。 -+ SCHEMA_REPLICATION_FACTOR 和 DATA_REPLICATION_FACTOR 必须小于等于已部署的 DataNode 数量。 -+ SCHEMA_REGION_GROUP_NUM 和 DATA_REGION_GROUP_NUM 的功能与 iotdb-common.properties 配置文件中的 -`schema_region_group_extension_policy` 和 `data_region_group_extension_policy` 参数相关,以 DATA_REGION_GROUP_NUM 为例: -若设置 `data_region_group_extension_policy=CUSTOM`,则 DATA_REGION_GROUP_NUM 将作为 Database 拥有的 DataRegionGroup 的数量; -若设置 `data_region_group_extension_policy=AUTO`,则 DATA_REGION_GROUP_NUM 将作为 Database 拥有的 DataRegionGroup 的配额下界,即当该 Database 开始写入数据时,将至少拥有此数量的 DataRegionGroup。 - -用户可以在创建 Database 时设置任意异构参数,或在单机/分布式 IoTDB 运行时调整部分异构参数。 - -#### 创建 Database 时设置异构参数 - -用户可以在创建 Database 时设置上述任意异构参数,SQL 语句如下所示: - -``` -CREATE DATABASE prefixPath (WITH databaseAttributeClause (COMMA? databaseAttributeClause)*)? -``` - -例如: -``` -CREATE DATABASE root.db WITH SCHEMA_REPLICATION_FACTOR=1, DATA_REPLICATION_FACTOR=3, SCHEMA_REGION_GROUP_NUM=1, DATA_REGION_GROUP_NUM=2; -``` - -#### 运行时调整异构参数 - -用户可以在 IoTDB 运行时调整部分异构参数,SQL 语句如下所示: - -``` -ALTER DATABASE prefixPath WITH databaseAttributeClause (COMMA? databaseAttributeClause)* -``` - -例如: -``` -ALTER DATABASE root.db WITH SCHEMA_REGION_GROUP_NUM=1, DATA_REGION_GROUP_NUM=2; -``` - -注意,运行时只能调整下列异构参数: -+ SCHEMA_REGION_GROUP_NUM -+ DATA_REGION_GROUP_NUM - -#### 查看异构数据库 - -用户可以查询每个 Database 的具体异构配置,SQL 语句如下所示: - -``` -SHOW DATABASES DETAILS prefixPath? -``` - -例如: - -``` -IoTDB> SHOW DATABASES DETAILS -+--------+--------+-----------------------+---------------------+---------------------+--------------------+-----------------------+-----------------------+------------------+---------------------+---------------------+ -|Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum|MinSchemaRegionGroupNum|MaxSchemaRegionGroupNum|DataRegionGroupNum|MinDataRegionGroupNum|MaxDataRegionGroupNum| -+--------+--------+-----------------------+---------------------+---------------------+--------------------+-----------------------+-----------------------+------------------+---------------------+---------------------+ -|root.db1| null| 1| 3| 604800000| 0| 1| 1| 0| 2| 2| -|root.db2|86400000| 1| 1| 604800000| 0| 1| 1| 0| 2| 2| -|root.db3| null| 1| 1| 604800000| 0| 1| 1| 0| 2| 2| -+--------+--------+-----------------------+---------------------+---------------------+--------------------+-----------------------+-----------------------+------------------+---------------------+---------------------+ -Total line number = 3 -It costs 0.058s -``` - -各列查询结果依次为: -+ 数据库名称 -+ 数据库的 TTL -+ 数据库的元数据副本数 -+ 数据库的数据副本数 -+ 数据库的时间分区间隔 -+ 数据库当前拥有的 SchemaRegionGroup 数量 -+ 数据库需要拥有的最小 SchemaRegionGroup 数量 -+ 数据库允许拥有的最大 SchemaRegionGroup 数量 -+ 数据库当前拥有的 DataRegionGroup 数量 -+ 数据库需要拥有的最小 DataRegionGroup 数量 -+ 数据库允许拥有的最大 DataRegionGroup 数量 - - -## 设备模板管理 - -IoTDB 支持设备模板功能,实现同类型不同实体的物理量元数据共享,减少元数据内存占用,同时简化同类型实体的管理。 - - -![img](/img/%E6%A8%A1%E6%9D%BF.png) - -![img](/img/template.jpg) - -### 创建设备模板 - -创建设备模板的 SQL 语法如下: - -```sql -CREATE DEVICE TEMPLATE ALIGNED? '(' [',' ]+ ')' -``` - -**示例1:** 创建包含两个非对齐序列的元数据模板 - -```shell -IoTDB> create device template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY) -``` - -**示例2:** 创建包含一组对齐序列的元数据模板 - -```shell -IoTDB> create device template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla) -``` - -其中,物理量 `lat` 和 `lon` 是对齐的。 - -### 挂载设备模板 - -元数据模板在创建后,需执行挂载操作,方可用于相应路径下的序列创建与数据写入。 - -**挂载模板前,需确保相关数据库已经创建。** - -**推荐将模板挂载在 database 节点上,不建议将模板挂载到 database 上层的节点上。** - -**模板挂载路径下禁止创建普通序列,已创建了普通序列的前缀路径上不允许挂载模板。** - -挂载元数据模板的 SQL 语句如下所示: - -```shell -IoTDB> set device template t1 to root.sg1.d1 -``` - -### 激活设备模板 - -挂载好设备模板后,且系统开启自动注册序列功能的情况下,即可直接进行数据的写入。例如 database 为 root.sg1,模板 t1 被挂载到了节点 root.sg1.d1,那么可直接向时间序列(如 root.sg1.d1.temperature 和 root.sg1.d1.status)写入时间序列数据,该时间序列已可被当作正常创建的序列使用。 - -**注意**:在插入数据之前或系统未开启自动注册序列功能,模板定义的时间序列不会被创建。可以使用如下SQL语句在插入数据前创建时间序列即激活模板: - -```shell -IoTDB> create timeseries using device template on root.sg1.d1 -``` - -**示例:** 执行以下语句 -```shell -IoTDB> set device template t1 to root.sg1.d1 -IoTDB> set device template t2 to root.sg1.d2 -IoTDB> create timeseries using device template on root.sg1.d1 -IoTDB> create timeseries using device template on root.sg1.d2 -``` - -查看此时的时间序列: -```sql -show timeseries root.sg1.** -``` - -```shell -+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression|tags|attributes|deadband|deadband parameters| -+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -|root.sg1.d1.temperature| null| root.sg1| FLOAT| RLE| SNAPPY|null| null| null| null| -| root.sg1.d1.status| null| root.sg1| BOOLEAN| PLAIN| SNAPPY|null| null| null| null| -| root.sg1.d2.lon| null| root.sg1| FLOAT| GORILLA| SNAPPY|null| null| null| null| -| root.sg1.d2.lat| null| root.sg1| FLOAT| GORILLA| SNAPPY|null| null| null| null| -+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -``` - -查看此时的设备: -```sql -show devices root.sg1.** -``` - -```shell -+---------------+---------+---------+ -| devices|isAligned| Template| -+---------------+---------+---------+ -| root.sg1.d1| false| null| -| root.sg1.d2| true| null| -+---------------+---------+---------+ -``` - -### 查看设备模板 - -- 查看所有设备模板 - -SQL 语句如下所示: - -```shell -IoTDB> show device templates -``` - -执行结果如下: -```shell -+-------------+ -|template name| -+-------------+ -| t2| -| t1| -+-------------+ -``` - -- 查看某个设备模板下的物理量 - -SQL 语句如下所示: - -```shell -IoTDB> show nodes in device template t1 -``` - -执行结果如下: -```shell -+-----------+--------+--------+-----------+ -|child nodes|dataType|encoding|compression| -+-----------+--------+--------+-----------+ -|temperature| FLOAT| RLE| SNAPPY| -| status| BOOLEAN| PLAIN| SNAPPY| -+-----------+--------+--------+-----------+ -``` - -- 查看挂载了某个设备模板的路径 - -```shell -IoTDB> show paths set device template t1 -``` - -执行结果如下: -```shell -+-----------+ -|child paths| -+-----------+ -|root.sg1.d1| -+-----------+ -``` - -- 查看使用了某个设备模板的路径(即模板在该路径上已激活,序列已创建) - -```shell -IoTDB> show paths using device template t1 -``` - -执行结果如下: -```shell -+-----------+ -|child paths| -+-----------+ -|root.sg1.d1| -+-----------+ -``` - -### 解除设备模板 - -若需删除模板表示的某一组时间序列,可采用解除模板操作,SQL语句如下所示: - -```shell -IoTDB> delete timeseries of device template t1 from root.sg1.d1 -``` - -或 - -```shell -IoTDB> deactivate device template t1 from root.sg1.d1 -``` - -解除操作支持批量处理,SQL语句如下所示: - -```shell -IoTDB> delete timeseries of device template t1 from root.sg1.*, root.sg2.* -``` - -或 - -```shell -IoTDB> deactivate device template t1 from root.sg1.*, root.sg2.* -``` - -若解除命令不指定模板名称,则会将给定路径涉及的所有模板使用情况均解除。 - -### 卸载设备模板 - -卸载设备模板的 SQL 语句如下所示: - -```shell -IoTDB> unset device template t1 from root.sg1.d1 -``` - -**注意**:不支持卸载仍处于激活状态的模板,需保证执行卸载操作前解除对该模板的所有使用,即删除所有该模板表示的序列。 - -### 删除设备模板 - -删除设备模板的 SQL 语句如下所示: - -```shell -IoTDB> drop device template t1 -``` - -**注意**:不支持删除已经挂载的模板,需在删除操作前保证该模板卸载成功。 - -### 修改设备模板 - -在需要新增物理量的场景中,可以通过修改设备模板来给所有已激活该模板的设备新增物理量。 - -修改设备模板的 SQL 语句如下所示: - -```shell -IoTDB> alter device template t1 add (speed FLOAT encoding=RLE, FLOAT TEXT encoding=PLAIN compression=SNAPPY) -``` - -**向已挂载模板的路径下的设备中写入数据,若写入请求中的物理量不在模板中,将自动扩展模板。** - - -## 时间序列管理 - -### 创建时间序列 - -根据建立的数据模型,我们可以分别在两个数据库中创建相应的时间序列。创建时间序列的 SQL 语句如下所示: - -``` -IoTDB > create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN -IoTDB > create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT,encoding=RLE -IoTDB > create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT,encoding=PLAIN -IoTDB > create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN,encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN,encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT,encoding=RLE -``` - -从 v0.13 起,可以使用简化版的 SQL 语句创建时间序列: - -``` -IoTDB > create timeseries root.ln.wf01.wt01.status BOOLEAN encoding=PLAIN -IoTDB > create timeseries root.ln.wf01.wt01.temperature FLOAT encoding=RLE -IoTDB > create timeseries root.ln.wf02.wt02.hardware TEXT encoding=PLAIN -IoTDB > create timeseries root.ln.wf02.wt02.status BOOLEAN encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.status BOOLEAN encoding=PLAIN -IoTDB > create timeseries root.sgcc.wf03.wt01.temperature FLOAT encoding=RLE -``` - -需要注意的是,当创建时间序列时指定的编码方式与数据类型不对应时,系统会给出相应的错误提示,如下所示: -``` -IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF -error: encoding TS_2DIFF does not support BOOLEAN -``` - -详细的数据类型与编码方式的对应列表请参见 [编码方式](../Basic-Concept/Encoding-and-Compression.md)。 - -### 创建对齐时间序列 - -创建一组对齐时间序列的SQL语句如下所示: - -``` -IoTDB> CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY) -``` - -一组对齐序列中的序列可以有不同的数据类型、编码方式以及压缩方式。 - -对齐的时间序列也支持设置别名、标签、属性。 - -### 删除时间序列 - -我们可以使用`(DELETE | DROP) TimeSeries `语句来删除我们之前创建的时间序列。SQL 语句如下所示: - -``` -IoTDB> delete timeseries root.ln.wf01.wt01.status -IoTDB> delete timeseries root.ln.wf01.wt01.temperature, root.ln.wf02.wt02.hardware -IoTDB> delete timeseries root.ln.wf02.* -IoTDB> drop timeseries root.ln.wf02.* -``` - -### 查看时间序列 - -* SHOW LATEST? TIMESERIES pathPattern? timeseriesWhereClause? limitClause? - - SHOW TIMESERIES 中可以有四种可选的子句,查询结果为这些时间序列的所有信息 - -时间序列信息具体包括:时间序列路径名,database,Measurement 别名,数据类型,编码方式,压缩方式,属性和标签。 - -示例: - -* SHOW TIMESERIES - - 展示系统中所有的时间序列信息 - -* SHOW TIMESERIES <`Path`> - - 返回给定路径的下的所有时间序列信息。其中 `Path` 需要为一个时间序列路径或路径模式。例如,分别查看`root`路径和`root.ln`路径下的时间序列,SQL 语句如下所示: - -``` -IoTDB> show timeseries root.** -IoTDB> show timeseries root.ln.** -``` - -执行结果分别为: - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -|root.sgcc.wf03.wt01.temperature| null| root.sgcc| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.sgcc.wf03.wt01.status| null| root.sgcc| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -| root.turbine.d1.s1|newAlias| root.turbine| FLOAT| RLE| SNAPPY|{"newTag1":"newV1","tag4":"v4","tag3":"v3"}|{"attr2":"v2","attr1":"newV1","attr4":"v4","attr3":"v3"}| null| null| -| root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY| null| null| null| null| -| root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 7 -It costs 0.016s - -+-----------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression|tags|attributes|deadband|deadband parameters| -+-----------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -| root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY|null| null| null| null| -| root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY|null| null| null| null| -|root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY|null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY|null| null| null| null| -+-----------------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+ -Total line number = 4 -It costs 0.004s -``` - -* SHOW TIMESERIES LIMIT INT OFFSET INT - - 只返回从指定下标开始的结果,最大返回条数被 LIMIT 限制,用于分页查询。例如: - -``` -show timeseries root.ln.** limit 10 offset 10 -``` - -* SHOW TIMESERIES WHERE TIMESERIES contains 'containStr' - - 对查询结果集根据 timeseries 名称进行字符串模糊匹配过滤。例如: - -``` -show timeseries root.ln.** where timeseries contains 'wf01.wt' -``` - -执行结果为: - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 2 -It costs 0.016s -``` - -* SHOW TIMESERIES WHERE DataType=type - - 对查询结果集根据时间序列数据类型进行过滤。例如: - -``` -show timeseries root.ln.** where dataType=FLOAT -``` - -执行结果为: - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -|root.sgcc.wf03.wt01.temperature| null| root.sgcc| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.turbine.d1.s1|newAlias| root.turbine| FLOAT| RLE| SNAPPY|{"newTag1":"newV1","tag4":"v4","tag3":"v3"}|{"attr2":"v2","attr1":"newV1","attr4":"v4","attr3":"v3"}| null| null| -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 3 -It costs 0.016s - -``` - - -* SHOW LATEST TIMESERIES - - 表示查询出的时间序列需要按照最近插入时间戳降序排列 - - -需要注意的是,当查询路径不存在时,系统会返回 0 条时间序列。 - -### 统计时间序列总数 - -IoTDB 支持使用`COUNT TIMESERIES`来统计一条路径中的时间序列个数。SQL 语句如下所示: - -* 可以通过 `WHERE` 条件对时间序列名称进行字符串模糊匹配,语法为: `COUNT TIMESERIES WHERE TIMESERIES contains 'containStr'` 。 -* 可以通过 `WHERE` 条件对时间序列数据类型进行过滤,语法为: `COUNT TIMESERIES WHERE DataType='`。 -* 可以通过 `WHERE` 条件对标签点进行过滤,语法为: `COUNT TIMESERIES WHERE TAGS(key)='value'` 或 `COUNT TIMESERIES WHERE TAGS(key) contains 'value'`。 -* 可以通过定义`LEVEL`来统计指定层级下的时间序列个数。这条语句可以用来统计每一个设备下的传感器数量,语法为:`COUNT TIMESERIES GROUP BY LEVEL=`。 - -``` -IoTDB > COUNT TIMESERIES root.** -IoTDB > COUNT TIMESERIES root.ln.** -IoTDB > COUNT TIMESERIES root.ln.*.*.status -IoTDB > COUNT TIMESERIES root.ln.wf01.wt01.status -IoTDB > COUNT TIMESERIES root.** WHERE TIMESERIES contains 'sgcc' -IoTDB > COUNT TIMESERIES root.** WHERE DATATYPE = INT64 -IoTDB > COUNT TIMESERIES root.** WHERE TAGS(unit) contains 'c' -IoTDB > COUNT TIMESERIES root.** WHERE TAGS(unit) = 'c' -IoTDB > COUNT TIMESERIES root.** WHERE TIMESERIES contains 'sgcc' group by level = 1 -``` - -例如有如下时间序列(可以使用`show timeseries`展示所有时间序列): - -``` -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -| timeseries| alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -|root.sgcc.wf03.wt01.temperature| null| root.sgcc| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.sgcc.wf03.wt01.status| null| root.sgcc| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -| root.turbine.d1.s1|newAlias| root.turbine| FLOAT| RLE| SNAPPY|{"newTag1":"newV1","tag4":"v4","tag3":"v3"}|{"attr2":"v2","attr1":"newV1","attr4":"v4","attr3":"v3"}| null| null| -| root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY| {"unit":"c"}| null| null| null| -| root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| {"description":"test1"}| null| null| null| -| root.ln.wf01.wt01.temperature| null| root.ln| FLOAT| RLE| SNAPPY| null| null| null| null| -| root.ln.wf01.wt01.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY| null| null| null| null| -+-------------------------------+--------+-------------+--------+--------+-----------+-------------------------------------------+--------------------------------------------------------+--------+-------------------+ -Total line number = 7 -It costs 0.004s -``` - -那么 Metadata Tree 如下所示: - - - -可以看到,`root`被定义为`LEVEL=0`。那么当你输入如下语句时: - -``` -IoTDB > COUNT TIMESERIES root.** GROUP BY LEVEL=1 -IoTDB > COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2 -IoTDB > COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=2 -``` - -你将得到以下结果: - -``` -IoTDB> COUNT TIMESERIES root.** GROUP BY LEVEL=1 -+------------+-----------------+ -| column|count(timeseries)| -+------------+-----------------+ -| root.sgcc| 2| -|root.turbine| 1| -| root.ln| 4| -+------------+-----------------+ -Total line number = 3 -It costs 0.002s - -IoTDB > COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2 -+------------+-----------------+ -| column|count(timeseries)| -+------------+-----------------+ -|root.ln.wf02| 2| -|root.ln.wf01| 2| -+------------+-----------------+ -Total line number = 2 -It costs 0.002s - -IoTDB > COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=2 -+------------+-----------------+ -| column|count(timeseries)| -+------------+-----------------+ -|root.ln.wf01| 2| -+------------+-----------------+ -Total line number = 1 -It costs 0.002s -``` - -> 注意:时间序列的路径只是过滤条件,与 level 的定义无关。 - -### 活跃时间序列查询 -我们在原有的时间序列查询和统计上添加新的WHERE时间过滤条件,可以得到在指定时间范围中存在数据的时间序列。 - -需要注意的是, 在带有时间过滤的元数据查询中并不考虑视图的存在,只考虑TsFile中实际存储的时间序列。 - -一个使用样例如下: -``` -IoTDB> insert into root.sg.data(timestamp, s1,s2) values(15000, 1, 2); -IoTDB> insert into root.sg.data2(timestamp, s1,s2) values(15002, 1, 2); -IoTDB> insert into root.sg.data3(timestamp, s1,s2) values(16000, 1, 2); -IoTDB> show timeseries; -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| root.sg.data.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -| root.sg.data.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data3.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data3.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ - -IoTDB> show timeseries where time >= 15000 and time < 16000; -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ -| root.sg.data.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -| root.sg.data.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s1| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -|root.sg.data2.s2| null| root.sg| FLOAT| GORILLA| LZ4|null| null| null| null| BASE| -+----------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+ - -``` -关于活跃时间序列的定义,能通过正常查询查出来的数据就是活跃数据,也就是说插入但被删除的时间序列不在考虑范围内。 - -### 标签点管理 - -我们可以在创建时间序列的时候,为它添加别名和额外的标签和属性信息。 - -标签和属性的区别在于: - -* 标签可以用来查询时间序列路径,会在内存中维护标点到时间序列路径的倒排索引:标签 -> 时间序列路径 -* 属性只能用时间序列路径来查询:时间序列路径 -> 属性 - -所用到的扩展的创建时间序列的 SQL 语句如下所示: -``` -create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2) -``` - -括号里的`temprature`是`s1`这个传感器的别名。 -我们可以在任何用到`s1`的地方,将其用`temprature`代替,这两者是等价的。 - -> IoTDB 同时支持在查询语句中使用 AS 函数设置别名。二者的区别在于:AS 函数设置的别名用于替代整条时间序列名,且是临时的,不与时间序列绑定;而上文中的别名只作为传感器的别名,与其绑定且可与原传感器名等价使用。 - -> 注意:额外的标签和属性信息总的大小不能超过`tag_attribute_total_size`. - - * 标签点属性更新 -创建时间序列后,我们也可以对其原有的标签点属性进行更新,主要有以下六种更新方式: -* 重命名标签或属性 -``` -ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1 -``` -* 重新设置标签或属性的值 -``` -ALTER timeseries root.turbine.d1.s1 SET newTag1=newV1, attr1=newV1 -``` -* 删除已经存在的标签或属性 -``` -ALTER timeseries root.turbine.d1.s1 DROP tag1, tag2 -``` -* 添加新的标签 -``` -ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4 -``` -* 添加新的属性 -``` -ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4 -``` -* 更新插入别名,标签和属性 -> 如果该别名,标签或属性原来不存在,则插入,否则,用新值更新原来的旧值 -``` -ALTER timeseries root.turbine.d1.s1 UPSERT ALIAS=newAlias TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4) -``` - -* 使用标签作为过滤条件查询时间序列,使用 TAGS(tagKey) 来标识作为过滤条件的标签 -``` -SHOW TIMESERIES (<`PathPattern`>)? timeseriesWhereClause -``` - -返回给定路径的下的所有满足条件的时间序列信息,SQL 语句如下所示: - -``` -ALTER timeseries root.ln.wf02.wt02.hardware ADD TAGS unit=c -ALTER timeseries root.ln.wf02.wt02.status ADD TAGS description=test1 -show timeseries root.ln.** where TAGS(unit)='c' -show timeseries root.ln.** where TAGS(description) contains 'test1' -``` - -执行结果分别为: - -``` -+--------------------------+-----+-------------+--------+--------+-----------+------------+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags|attributes|deadband|deadband parameters| -+--------------------------+-----+-------------+--------+--------+-----------+------------+----------+--------+-------------------+ -|root.ln.wf02.wt02.hardware| null| root.ln| TEXT| PLAIN| SNAPPY|{"unit":"c"}| null| null| null| -+--------------------------+-----+-------------+--------+--------+-----------+------------+----------+--------+-------------------+ -Total line number = 1 -It costs 0.005s - -+------------------------+-----+-------------+--------+--------+-----------+-----------------------+----------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags|attributes|deadband|deadband parameters| -+------------------------+-----+-------------+--------+--------+-----------+-----------------------+----------+--------+-------------------+ -|root.ln.wf02.wt02.status| null| root.ln| BOOLEAN| PLAIN| SNAPPY|{"description":"test1"}| null| null| null| -+------------------------+-----+-------------+--------+--------+-----------+-----------------------+----------+--------+-------------------+ -Total line number = 1 -It costs 0.004s -``` - -- 使用标签作为过滤条件统计时间序列数量 - -``` -COUNT TIMESERIES (<`PathPattern`>)? timeseriesWhereClause -COUNT TIMESERIES (<`PathPattern`>)? timeseriesWhereClause GROUP BY LEVEL= -``` - -返回给定路径的下的所有满足条件的时间序列的数量,SQL 语句如下所示: - -``` -count timeseries -count timeseries root.** where TAGS(unit)='c' -count timeseries root.** where TAGS(unit)='c' group by level = 2 -``` - -执行结果分别为: - -``` -IoTDB> count timeseries -+-----------------+ -|count(timeseries)| -+-----------------+ -| 6| -+-----------------+ -Total line number = 1 -It costs 0.019s -IoTDB> count timeseries root.** where TAGS(unit)='c' -+-----------------+ -|count(timeseries)| -+-----------------+ -| 2| -+-----------------+ -Total line number = 1 -It costs 0.020s -IoTDB> count timeseries root.** where TAGS(unit)='c' group by level = 2 -+--------------+-----------------+ -| column|count(timeseries)| -+--------------+-----------------+ -| root.ln.wf02| 2| -| root.ln.wf01| 0| -|root.sgcc.wf03| 0| -+--------------+-----------------+ -Total line number = 3 -It costs 0.011s -``` - -> 注意,现在我们只支持一个查询条件,要么是等值条件查询,要么是包含条件查询。当然 where 子句中涉及的必须是标签值,而不能是属性值。 - -创建对齐时间序列 - -``` -create aligned timeseries root.sg1.d1(s1 INT32 tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2), s2 DOUBLE tags(tag3=v3, tag4=v4) attributes(attr3=v3, attr4=v4)) -``` - -执行结果如下: - -``` -IoTDB> show timeseries -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -|root.sg1.d1.s1| null| root.sg1| INT32| RLE| SNAPPY|{"tag1":"v1","tag2":"v2"}|{"attr2":"v2","attr1":"v1"}| null| null| -|root.sg1.d1.s2| null| root.sg1| DOUBLE| GORILLA| SNAPPY|{"tag4":"v4","tag3":"v3"}|{"attr4":"v4","attr3":"v3"}| null| null| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -``` - -支持查询: - -``` -IoTDB> show timeseries where TAGS(tag1)='v1' -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -| timeseries|alias| database|dataType|encoding|compression| tags| attributes|deadband|deadband parameters| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -|root.sg1.d1.s1| null| root.sg1| INT32| RLE| SNAPPY|{"tag1":"v1","tag2":"v2"}|{"attr2":"v2","attr1":"v1"}| null| null| -+--------------+-----+-------------+--------+--------+-----------+-------------------------+---------------------------+--------+-------------------+ -``` - -上述对时间序列标签、属性的更新等操作都支持。 - - -## 路径查询 - -### 查看路径的所有子路径 - -``` -SHOW CHILD PATHS pathPattern -``` - -可以查看此路径模式所匹配的所有路径的下一层的所有路径和它对应的节点类型,即pathPattern.*所匹配的路径及其节点类型。 - -节点类型:ROOT -> SG INTERNAL -> DATABASE -> INTERNAL -> DEVICE -> TIMESERIES - -示例: - -* 查询 root.ln 的下一层:show child paths root.ln - -``` -+------------+----------+ -| child paths|node types| -+------------+----------+ -|root.ln.wf01| INTERNAL| -|root.ln.wf02| INTERNAL| -+------------+----------+ -Total line number = 2 -It costs 0.002s -``` - -* 查询形如 root.xx.xx.xx 的路径:show child paths root.\*.\* - -``` -+---------------+ -| child paths| -+---------------+ -|root.ln.wf01.s1| -|root.ln.wf02.s2| -+---------------+ -``` - -### 查看路径的下一级节点 - -``` -SHOW CHILD NODES pathPattern -``` - -可以查看此路径模式所匹配的节点的下一层的所有节点。 - -示例: - -* 查询 root 的下一层:show child nodes root - -``` -+------------+ -| child nodes| -+------------+ -| ln| -+------------+ -``` - -* 查询 root.ln 的下一层 :show child nodes root.ln - -``` -+------------+ -| child nodes| -+------------+ -| wf01| -| wf02| -+------------+ -``` - -### 统计节点数 - -IoTDB 支持使用`COUNT NODES LEVEL=`来统计当前 Metadata - 树下满足某路径模式的路径中指定层级的节点个数。这条语句可以用来统计带有特定采样点的设备数。例如: - -``` -IoTDB > COUNT NODES root.** LEVEL=2 -IoTDB > COUNT NODES root.ln.** LEVEL=2 -IoTDB > COUNT NODES root.ln.wf01.* LEVEL=3 -IoTDB > COUNT NODES root.**.temperature LEVEL=3 -``` - -对于上面提到的例子和 Metadata Tree,你可以获得如下结果: - -``` -+------------+ -|count(nodes)| -+------------+ -| 4| -+------------+ -Total line number = 1 -It costs 0.003s - -+------------+ -|count(nodes)| -+------------+ -| 2| -+------------+ -Total line number = 1 -It costs 0.002s - -+------------+ -|count(nodes)| -+------------+ -| 1| -+------------+ -Total line number = 1 -It costs 0.002s - -+------------+ -|count(nodes)| -+------------+ -| 2| -+------------+ -Total line number = 1 -It costs 0.002s -``` - -> 注意:时间序列的路径只是过滤条件,与 level 的定义无关。 - -### 查看设备 - -* SHOW DEVICES pathPattern? (WITH DATABASE)? devicesWhereClause? limitClause? - -与 `Show Timeseries` 相似,IoTDB 目前也支持两种方式查看设备。 - -* `SHOW DEVICES` 语句显示当前所有的设备信息,等价于 `SHOW DEVICES root.**`。 -* `SHOW DEVICES ` 语句规定了 `PathPattern`,返回给定的路径模式所匹配的设备信息。 -* `WHERE` 条件中可以使用 `DEVICE contains 'xxx'`,根据 device 名称进行模糊查询。 -* `WHERE` 条件中可以使用 `TEMPLATE = 'xxx'`,`TEMPLATE != 'xxx'`,根据 template 名称进行过滤查询。 -* `WHERE` 条件中可以使用 `TEMPLATE is null`,`TEMPLATE is not null`,根据 template 是否为null(null 表示没激活)进行过滤查询。 - -SQL 语句如下所示: - -``` -IoTDB> show devices -IoTDB> show devices root.ln.** -IoTDB> show devices root.ln.** where device contains 't' -IoTDB> show devices root.ln.** where template = 't1' -IoTDB> show devices root.ln.** where template is null -IoTDB> show devices root.ln.** where template != 't1' -IoTDB> show devices root.ln.** where template is not null -``` - -你可以获得如下数据: - -``` -+-------------------+---------+---------+ -| devices|isAligned| Template| -+-------------------+---------+---------+ -| root.ln.wf01.wt01| false| t1| -| root.ln.wf02.wt02| false| null| -|root.sgcc.wf03.wt01| false| null| -| root.turbine.d1| false| null| -+-------------------+---------+---------+ -Total line number = 4 -It costs 0.002s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf01.wt01| false| t1| -|root.ln.wf02.wt02| false| null| -+-----------------+---------+---------+ -Total line number = 2 -It costs 0.001s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf01.wt01| false| t1| -|root.ln.wf02.wt02| false| null| -+-----------------+---------+---------+ -Total line number = 2 -It costs 0.001s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf01.wt01| false| t1| -+-----------------+---------+---------+ -Total line number = 1 -It costs 0.001s - -+-----------------+---------+---------+ -| devices|isAligned| Template| -+-----------------+---------+---------+ -|root.ln.wf02.wt02| false| null| -+-----------------+---------+---------+ -Total line number = 1 -It costs 0.001s -``` - -其中,`isAligned`表示该设备下的时间序列是否对齐, -`Template`显示着该设备所激活的模板名,null 表示没有激活模板。 - -查看设备及其 database 信息,可以使用 `SHOW DEVICES WITH DATABASE` 语句。 - -* `SHOW DEVICES WITH DATABASE` 语句显示当前所有的设备信息和其所在的 database,等价于 `SHOW DEVICES root.**`。 -* `SHOW DEVICES WITH DATABASE` 语句规定了 `PathPattern`,返回给定的路径模式所匹配的设备信息和其所在的 database。 - -SQL 语句如下所示: - -``` -IoTDB> show devices with database -IoTDB> show devices root.ln.** with database -``` - -你可以获得如下数据: - -``` -+-------------------+-------------+---------+---------+ -| devices| database|isAligned| Template| -+-------------------+-------------+---------+---------+ -| root.ln.wf01.wt01| root.ln| false| t1| -| root.ln.wf02.wt02| root.ln| false| null| -|root.sgcc.wf03.wt01| root.sgcc| false| null| -| root.turbine.d1| root.turbine| false| null| -+-------------------+-------------+---------+---------+ -Total line number = 4 -It costs 0.003s - -+-----------------+-------------+---------+---------+ -| devices| database|isAligned| Template| -+-----------------+-------------+---------+---------+ -|root.ln.wf01.wt01| root.ln| false| t1| -|root.ln.wf02.wt02| root.ln| false| null| -+-----------------+-------------+---------+---------+ -Total line number = 2 -It costs 0.001s -``` - -### 统计设备数量 - -* COUNT DEVICES \ - -上述语句用于统计设备的数量,同时允许指定`PathPattern` 用于统计匹配该`PathPattern` 的设备数量 - -SQL 语句如下所示: - -``` -IoTDB> show devices -IoTDB> count devices -IoTDB> count devices root.ln.** -``` - -你可以获得如下数据: - -``` -+-------------------+---------+---------+ -| devices|isAligned| Template| -+-------------------+---------+---------+ -|root.sgcc.wf03.wt03| false| null| -| root.turbine.d1| false| null| -| root.ln.wf02.wt02| false| null| -| root.ln.wf01.wt01| false| t1| -+-------------------+---------+---------+ -Total line number = 4 -It costs 0.024s - -+--------------+ -|count(devices)| -+--------------+ -| 4| -+--------------+ -Total line number = 1 -It costs 0.004s - -+--------------+ -|count(devices)| -+--------------+ -| 2| -+--------------+ -Total line number = 1 -It costs 0.004s -``` - -### 活跃设备查询 -和活跃时间序列一样,我们可以在查看和统计设备的基础上添加时间过滤条件来查询在某段时间内存在数据的活跃设备。这里活跃的定义与活跃时间序列相同,使用样例如下: -``` -IoTDB> insert into root.sg.data(timestamp, s1,s2) values(15000, 1, 2); -IoTDB> insert into root.sg.data2(timestamp, s1,s2) values(15002, 1, 2); -IoTDB> insert into root.sg.data3(timestamp, s1,s2) values(16000, 1, 2); -IoTDB> show devices; -+-------------------+---------+ -| devices|isAligned| -+-------------------+---------+ -| root.sg.data| false| -| root.sg.data2| false| -| root.sg.data3| false| -+-------------------+---------+ - -IoTDB> show devices where time >= 15000 and time < 16000; -+-------------------+---------+ -| devices|isAligned| -+-------------------+---------+ -| root.sg.data| false| -| root.sg.data2| false| -+-------------------+---------+ - -IoTDB> count devices where time >= 15000 and time < 16000; -+--------------+ -|count(devices)| -+--------------+ -| 2| -+--------------+ -``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Operator-and-Expression.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Operator-and-Expression.md deleted file mode 100644 index 4c4be4392..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Operator-and-Expression.md +++ /dev/null @@ -1,552 +0,0 @@ - - -# 运算符、函数和表达式 - -## 运算符 -### 算数运算符 -|运算符 |含义| -|----------------------------|-----------| -|`+` |取正(单目)| -|`-` |取负(单目)| -|`*` |乘| -|`/` |除| -|`%` |取余| -|`+` |加| -|`-` |减| - -详细说明及示例见文档 [算数运算符和函数](../Reference/Function-and-Expression.md#算数运算符)。 - -### 比较运算符 -|运算符 |含义| -|----------------------------|-----------| -|`>` |大于| -|`>=` |大于等于| -|`<` |小于| -|`<=` |小于等于| -|`==` |等于| -|`!=` / `<>` |不等于| -|`BETWEEN ... AND ...` |在指定范围内| -|`NOT BETWEEN ... AND ...` |不在指定范围内| -|`LIKE` |匹配简单模式| -|`NOT LIKE` |无法匹配简单模式| -|`REGEXP` |匹配正则表达式| -|`NOT REGEXP` |无法匹配正则表达式| -|`IS NULL` |是空值| -|`IS NOT NULL` |不是空值| -|`IN` / `CONTAINS` |是指定列表中的值| -|`NOT IN` / `NOT CONTAINS` |不是指定列表中的值| - -详细说明及示例见文档 [比较运算符和函数](../Reference/Function-and-Expression.md#比较运算符和函数)。 - -### 逻辑运算符 -|运算符 |含义| -|----------------------------|-----------| -|`NOT` / `!` |取非(单目)| -|`AND` / `&` / `&&` |逻辑与| -|`OR`/ | / || |逻辑或| - -详细说明及示例见文档 [逻辑运算符](../Reference/Function-and-Expression.md#逻辑运算符)。 - -### 运算符优先级 - -运算符的优先级从高到低排列如下,同一行的运算符优先级相同。 - -```sql -!, - (unary operator), + (unary operator) -*, /, DIV, %, MOD --, + -=, ==, <=>, >=, >, <=, <, <>, != -LIKE, REGEXP, NOT LIKE, NOT REGEXP -BETWEEN ... AND ..., NOT BETWEEN ... AND ... -IS NULL, IS NOT NULL -IN, CONTAINS, NOT IN, NOT CONTAINS -AND, &, && -OR, |, || -``` - -## 内置函数 - -列表中的函数无须注册即可在 IoTDB 中使用,数据函数质量库中的函数需要参考注册步骤进行注册后才能使用。 - -### 聚合函数 - -| 函数名 | 功能描述 | 允许的输入类型 | 输出类型 | -|-------------|----------------------------------------------------------------------------| ------------------------ | -------------- | -| SUM | 求和。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| COUNT | 计算数据点数。 | 所有类型 | INT | -| AVG | 求平均值。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| STDDEV | STDDEV_SAMP 的别名,求样本标准差。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| STDDEV_POP | 求总体标准差。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| STDDEV_SAMP | 求样本标准差。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| VARIANCE | VAR_SAMP 的别名,求样本方差。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| VAR_POP | 求总体方差。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| VAR_SAMP | 求样本方差。 | INT32 INT64 FLOAT DOUBLE | DOUBLE | -| EXTREME | 求具有最大绝对值的值。如果正值和负值的最大绝对值相等,则返回正值。 | INT32 INT64 FLOAT DOUBLE | 与输入类型一致 | -| MAX_VALUE | 求最大值。 | INT32 INT64 FLOAT DOUBLE | 与输入类型一致 | -| MIN_VALUE | 求最小值。 | INT32 INT64 FLOAT DOUBLE | 与输入类型一致 | -| FIRST_VALUE | 求时间戳最小的值。 | 所有类型 | 与输入类型一致 | -| LAST_VALUE | 求时间戳最大的值。 | 所有类型 | 与输入类型一致 | -| MAX_TIME | 求最大时间戳。 | 所有类型 | Timestamp | -| MIN_TIME | 求最小时间戳。 | 所有类型 | Timestamp | -| MAX_BY | MAX_BY(x, y) 求二元输入 x 和 y 在 y 最大时对应的 x 的值。MAX_BY(time, x) 返回 x 取最大值时对应的时间戳。 | 第一个输入 x 可以是任意类型,第二个输入 y 只能是 INT32 INT64 FLOAT DOUBLE | 与第一个输入 x 的数据类型一致 | -| MIN_BY | MIN_BY(x, y) 求二元输入 x 和 y 在 y 最小时对应的 x 的值。MIN_BY(time, x) 返回 x 取最小值时对应的时间戳。 | 第一个输入 x 可以是任意类型,第二个输入 y 只能是 INT32 INT64 FLOAT DOUBLE | 与第一个输入 x 的数据类型一致 | - -详细说明及示例见文档 [聚合函数](../Reference/Function-and-Expression.md#聚合函数)。 - -### 数学函数 - -| 函数名 | 输入序列类型 | 输出序列类型 | 必要属性参数 | Java 标准库中的对应实现 | -| ------- | ------------------------------ | ------------------------ |----------------------------------------------|-------------------------------------------------------------------| -| SIN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#sin(double) | -| COS | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#cos(double) | -| TAN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#tan(double) | -| ASIN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#asin(double) | -| ACOS | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#acos(double) | -| ATAN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#atan(double) | -| SINH | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#sinh(double) | -| COSH | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#cosh(double) | -| TANH | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#tanh(double) | -| DEGREES | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#toDegrees(double) | -| RADIANS | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#toRadians(double) | -| ABS | INT32 / INT64 / FLOAT / DOUBLE | 与输入序列的实际类型一致 | | Math#abs(int) / Math#abs(long) /Math#abs(float) /Math#abs(double) | -| SIGN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#signum(double) | -| CEIL | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#ceil(double) | -| FLOOR | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#floor(double) | -| ROUND | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | `places`:四舍五入有效位数,正数为小数点后面的有效位数,负数为整数位的有效位数 | Math#rint(Math#pow(10,places))/Math#pow(10,places) | -| EXP | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#exp(double) | -| LN | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#log(double) | -| LOG10 | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#log10(double) | -| SQRT | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | | Math#sqrt(double) | - - -详细说明及示例见文档 [数学函数](../Reference/Function-and-Expression.md#数学函数)。 - -### 比较函数 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| ON_OFF | INT32 / INT64 / FLOAT / DOUBLE | `threshold`:DOUBLE | BOOLEAN | 返回`ts_value >= threshold`的bool值 | -| IN_RANGE | INT32 / INT64 / FLOAT / DOUBLE | `lower`:DOUBLE
`upper`:DOUBLE | BOOLEAN | 返回`ts_value >= lower && ts_value <= upper`的bool值 | | - -详细说明及示例见文档 [比较运算符和函数](../Reference/Function-and-Expression.md#比较运算符和函数)。 - -### 字符串函数 -| 函数名 | 输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能描述 | -|-----------------| ------------ |-----------------------------------------------------------------------------------------------------------| ------------ |-------------------------------------------------------------------------| -| STRING_CONTAINS | TEXT | `s`: 待搜寻的字符串 | BOOLEAN | 判断字符串中是否存在`s` | -| STRING_MATCHES | TEXT | `regex`: Java 标准库风格的正则表达式 | BOOLEAN | 判断字符串是否能够被正则表达式`regex`匹配 | -| LENGTH | TEXT | 无 | INT32 | 返回字符串的长度 | -| LOCATE | TEXT | `target`: 需要被定位的子串
`reverse`: 指定是否需要倒序定位,默认值为`false`, 即从左至右定位 | INT32 | 获取`target`子串第一次出现在输入序列的位置,如果输入序列中不包含`target`则返回 -1 | -| STARTSWITH | TEXT | `target`: 需要匹配的前缀 | BOOLEAN | 判断字符串是否有指定前缀 | -| ENDSWITH | TEXT | `target`: 需要匹配的后缀 | BOOLEAN | 判断字符串是否有指定后缀 | -| CONCAT | TEXT | `targets`: 一系列 K-V, key需要以`target`为前缀且不重复, value是待拼接的字符串。
`series_behind`: 指定拼接时时间序列是否在后面,默认为`false`。 | TEXT | 拼接字符串和`target`字串 | -| SUBSTRING | TEXT | `from`: 指定子串开始下标
`for`: 指定的字符个数之后停止 | TEXT | 提取字符串的子字符串,从指定的第一个字符开始,并在指定的字符数之后停止。下标从1开始。from 和 for的范围是 INT32 类型取值范围。 | -| REPLACE | TEXT | 第一个参数: 需要替换的目标子串
第二个参数:要替换成的子串 | TEXT | 将输入序列中的子串替换成目标子串 | -| UPPER | TEXT | 无 | TEXT | 将字符串转化为大写 | -| LOWER | TEXT | 无 | TEXT | 将字符串转化为小写 | -| TRIM | TEXT | 无 | TEXT | 移除字符串前后的空格 | -| STRCMP | TEXT | 无 | TEXT | 用于比较两个输入序列,如果值相同返回 `0` , 序列1的值小于序列2的值返回一个`负数`,序列1的值大于序列2的值返回一个`正数` | -详细说明及示例见文档 [字符串处理函数](../Reference/Function-and-Expression.md#字符串处理)。 - -### 数据类型转换函数 - -| 函数名 | 必要的属性参数 | 输出序列类型 | 功能类型 | -| ------ | ------------------------------------------------------------ | ------------------------ | ---------------------------------- | -| CAST | `type`:输出的数据点的类型,只能是 INT32 / INT64 / FLOAT / DOUBLE / BOOLEAN / TEXT | 由输入属性参数`type`决定 | 将数据转换为`type`参数指定的类型。 | - -详细说明及示例见文档 [数据类型转换](../Reference/Function-and-Expression.md#数据类型转换)。 - -### 常序列生成函数 - -| 函数名 | 必要的属性参数 | 输出序列类型 | 功能描述 | -| ------ | ------------------------------------------------------------ | -------------------------- | ------------------------------------------------------------ | -| CONST | `value`: 输出的数据点的值
`type`: 输出的数据点的类型,只能是 INT32 / INT64 / FLOAT / DOUBLE / BOOLEAN / TEXT | 由输入属性参数 `type` 决定 | 根据输入属性 `value` 和 `type` 输出用户指定的常序列。 | -| PI | 无 | DOUBLE | 常序列的值:`π` 的 `double` 值,圆的周长与其直径的比值,即圆周率,等于 *Java标准库* 中的`Math.PI`。 | -| E | 无 | DOUBLE | 常序列的值:`e` 的 `double` 值,自然对数的底,它等于 *Java 标准库* 中的 `Math.E`。 | - -详细说明及示例见文档 [常序列生成函数](../Reference/Function-and-Expression.md#常序列生成函数)。 - -### 选择函数 - -| 函数名 | 输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能描述 | -| -------- | ------------------------------------- | ------------------------------------------------- | ------------------------ | ------------------------------------------------------------ | -| TOP_K | INT32 / INT64 / FLOAT / DOUBLE / TEXT | `k`: 最多选择的数据点数,必须大于 0 小于等于 1000 | 与输入序列的实际类型一致 | 返回某时间序列中值最大的`k`个数据点。若多于`k`个数据点的值并列最大,则返回时间戳最小的数据点。 | -| BOTTOM_K | INT32 / INT64 / FLOAT / DOUBLE / TEXT | `k`: 最多选择的数据点数,必须大于 0 小于等于 1000 | 与输入序列的实际类型一致 | 返回某时间序列中值最小的`k`个数据点。若多于`k`个数据点的值并列最小,则返回时间戳最小的数据点。 | - -详细说明及示例见文档 [选择函数](../Reference/Function-and-Expression.md#选择函数)。 - -### 区间查询函数 - -| 函数名 | 输入序列类型 | 属性参数 | 输出序列类型 | 功能描述 | -|-------------------|--------------------------------------|------------------------------------------------|-------|------------------------------------------------------------------| -| ZERO_DURATION | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值0
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续为0(false)的开始时间与持续时间,持续时间t(单位ms)满足`t >= min && t <= max` | -| NON_ZERO_DURATION | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值0
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续不为0(false)的开始时间与持续时间,持续时间t(单位ms)满足`t >= min && t <= max` | | -| ZERO_COUNT | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值1
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续为0(false)的开始时间与其后数据点的个数,数据点个数n满足`n >= min && n <= max` | | -| NON_ZERO_COUNT | INT32/ INT64/ FLOAT/ DOUBLE/ BOOLEAN | `min`:可选,默认值1
`max`:可选,默认值`Long.MAX_VALUE` | Long | 返回时间序列连续不为0(false)的开始时间与其后数据点的个数,数据点个数n满足`n >= min && n <= max` | | - -详细说明及示例见文档 [区间查询函数](../Reference/Function-and-Expression.md#区间查询函数)。 - -### 趋势计算函数 - -| 函数名 | 输入序列类型 | 输出序列类型 | 功能描述 | -| ----------------------- | ----------------------------------------------- | ------------------------ | ------------------------------------------------------------ | -| TIME_DIFFERENCE | INT32 / INT64 / FLOAT / DOUBLE / BOOLEAN / TEXT | INT64 | 统计序列中某数据点的时间戳与前一数据点时间戳的差。范围内第一个数据点没有对应的结果输出。 | -| DIFFERENCE | INT32 / INT64 / FLOAT / DOUBLE | 与输入序列的实际类型一致 | 统计序列中某数据点的值与前一数据点的值的差。范围内第一个数据点没有对应的结果输出。 | -| NON_NEGATIVE_DIFFERENCE | INT32 / INT64 / FLOAT / DOUBLE | 与输入序列的实际类型一致 | 统计序列中某数据点的值与前一数据点的值的差的绝对值。范围内第一个数据点没有对应的结果输出。 | -| DERIVATIVE | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | 统计序列中某数据点相对于前一数据点的变化率,数量上等同于 DIFFERENCE / TIME_DIFFERENCE。范围内第一个数据点没有对应的结果输出。 | -| NON_NEGATIVE_DERIVATIVE | INT32 / INT64 / FLOAT / DOUBLE | DOUBLE | 统计序列中某数据点相对于前一数据点的变化率的绝对值,数量上等同于 NON_NEGATIVE_DIFFERENCE / TIME_DIFFERENCE。范围内第一个数据点没有对应的结果输出。 | - - -| 函数名 | 输入序列类型 | 参数 | 输出序列类型 | 功能描述 | -|------|--------------------------------|------------------------------------------------------------------------------------------------------------------------|--------|------------------------------------------------| -| DIFF | INT32 / INT64 / FLOAT / DOUBLE | `ignoreNull`:可选,默认为true;为true时,前一个数据点值为null时,忽略该数据点继续向前找到第一个出现的不为null的值;为false时,如果前一个数据点为null,则不忽略,使用null进行相减,结果也为null | DOUBLE | 统计序列中某数据点的值与前一数据点的值的差。第一个数据点没有对应的结果输出,输出值为null | - -详细说明及示例见文档 [趋势计算函数](../Reference/Function-and-Expression.md#趋势计算函数)。 - -### 采样函数 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -|----------|--------------------------------|---------------------------------------|------------|--------------------------------------------------| -| EQUAL_SIZE_BUCKET_RANDOM_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | 降采样比例 `proportion`,取值范围为`(0, 1]`,默认为`0.1` | INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例的等分桶随机采样 | -| EQUAL_SIZE_BUCKET_AGG_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | `proportion`取值范围为`(0, 1]`,默认为`0.1`
`type`:取值类型有`avg`, `max`, `min`, `sum`, `extreme`, `variance`, 默认为`avg` | INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例的等分桶聚合采样 | -| EQUAL_SIZE_BUCKET_M4_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | `proportion`取值范围为`(0, 1]`,默认为`0.1`| INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例的等分桶M4采样 | -| EQUAL_SIZE_BUCKET_OUTLIER_SAMPLE | INT32 / INT64 / FLOAT / DOUBLE | `proportion`取值范围为`(0, 1]`,默认为`0.1`
`type`取值为`avg`或`stendis`或`cos`或`prenextdis`,默认为`avg`
`number`取值应大于0,默认`3`| INT32 / INT64 / FLOAT / DOUBLE | 返回符合采样比例和桶内采样个数的等分桶离群值采样 | -| M4 | INT32 / INT64 / FLOAT / DOUBLE | 包含固定点数的窗口和滑动时间窗口使用不同的属性参数。包含固定点数的窗口使用属性`windowSize`和`slidingStep`。滑动时间窗口使用属性`timeInterval`、`slidingStep`、`displayWindowBegin`和`displayWindowEnd`。更多细节见下文。 | INT32 / INT64 / FLOAT / DOUBLE | 返回每个窗口内的第一个点(`first`)、最后一个点(`last`)、最小值点(`bottom`)、最大值点(`top`)。在一个窗口内的聚合点输出之前,M4会将它们按照时间戳递增排序并且去重。 | - -详细说明及示例见文档 [采样函数](../Reference/Function-and-Expression.md#采样函数)。 -### 时间序列处理函数 - -| 函数名 | 输入序列类型 | 参数 | 输出序列类型 | 功能描述 | -| ------------- | ------------------------------ | ---- | ------------------------ | -------------------------- | -| CHANGE_POINTS | INT32 / INT64 / FLOAT / DOUBLE | / | 与输入序列的实际类型一致 | 去除输入序列中的连续相同值 | - -详细说明及示例见文档 [时间序列处理](../Reference/Function-and-Expression.md#时间序列处理)。 - -## 数据质量函数库 - -### 关于 - -对基于时序数据的应用而言,数据质量至关重要。基于用户自定义函数能力,IoTDB 提供了一系列关于数据质量的函数,包括数据画像、数据质量评估与修复等,能够满足工业领域对数据质量的需求。 - -### 快速上手 - -**该函数库中的函数不是内置函数,使用前要先加载到系统中。** 操作流程如下: - -1. 下载包含全部依赖的 jar 包和注册脚本 [【点击下载】](https://archive.apache.org/dist/iotdb/1.0.1/apache-iotdb-1.0.1-library-udf-bin.zip) ; -2. 将 jar 包复制到 IoTDB 程序目录的 `ext\udf` 目录下 (若您使用的是集群,请将jar包复制到所有DataNode的该目录下); -3. 启动 IoTDB; -4. 将注册脚本复制到 IoTDB 的程序目录下(与`sbin`目录同级的根目录下),修改脚本中的参数(如果需要)并运行注册脚本以注册 UDF。 - -### 已经实现的函数 - -1. [Data-Quality](../Reference/UDF-Libraries.md#数据质量) 数据质量 -2. [Data-Profiling](../Reference/UDF-Libraries.md#数据画像) 数据画像 -3. [Anomaly-Detection](../Reference/UDF-Libraries.md#异常检测) 异常检测 -4. [Frequency-Domain](../Reference/UDF-Libraries.md#频域分析) 频域分析 -5. [Data-Matching](../Reference/UDF-Libraries.md#数据匹配) 数据匹配 -6. [Data-Repairing](../Reference/UDF-Libraries.md#数据修复) 数据修复 -7. [Series-Discovery](../Reference/UDF-Libraries.md#序列发现) 序列发现 -8. [Machine-Learning](../Reference/UDF-Libraries.md#机器学习) 机器学习 - -## Lambda 表达式 - -| 函数名 | 可接收的输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能类型 | -| ------ | ----------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------- | ---------------------------------------------- | -| JEXL | INT32 / INT64 / FLOAT / DOUBLE / TEXT / BOOLEAN | `expr`是一个支持标准的一元或多元参数的lambda表达式,符合`x -> {...}`或`(x, y, z) -> {...}`的格式,例如`x -> {x * 2}`, `(x, y, z) -> {x + y * z}` | INT32 / INT64 / FLOAT / DOUBLE / TEXT / BOOLEAN | 返回将输入的时间序列通过lambda表达式变换的序列 | - -详细说明及示例见文档 [Lambda 表达式](../Reference/Function-and-Expression.md#Lambda表达式) - -## 条件表达式 - -| 表达式名称 | 含义 | -|---------------------------|-----------| -| `CASE` | 类似if else | - -详细说明及示例见文档 [条件表达式](../Reference/Function-and-Expression.md#条件表达式) - -## SELECT 表达式 - -`SELECT` 子句指定查询的输出,由若干个 `selectExpr` 组成。 每个 `selectExpr` 定义了查询结果中的一列或多列。 - -**`selectExpr` 是一个由时间序列路径后缀、常量、函数和运算符组成的表达式。即 `selectExpr` 中可以包含:** - -- 时间序列路径后缀(支持使用通配符) -- 运算符 - - 算数运算符 - - 比较运算符 - - 逻辑运算符 -- 函数 - - 聚合函数 - - 时间序列生成函数(包括内置函数和用户自定义函数) -- 常量 - -#### 使用别名 - -由于 IoTDB 独特的数据模型,在每个传感器前都附带有设备等诸多额外信息。有时,我们只针对某个具体设备查询,而这些前缀信息频繁显示造成了冗余,影响了结果集的显示与分析。 - -IoTDB 支持使用`AS`为查询结果集中的列指定别名。 - -**示例:** - -```sql -select s1 as temperature, s2 as speed from root.ln.wf01.wt01; -``` - -结果集将显示为: - -| Time | temperature | speed | -| ---- | ----------- | ----- | -| ... | ... | ... | - -#### 运算符 - -IoTDB 中支持的运算符列表见文档 [运算符和函数](../Reference/Function-and-Expression.md#算数运算符和函数)。 - -#### 函数 - -##### 聚合函数 - -聚合函数是多对一函数。它们对一组值进行聚合计算,得到单个聚合结果。 - -**包含聚合函数的查询称为聚合查询**,否则称为时间序列查询。 - -**注意:聚合查询和时间序列查询不能混合使用。** 下列语句是不支持的: - -```sql -select s1, count(s1) from root.sg.d1; -select sin(s1), count(s1) from root.sg.d1; -select s1, count(s1) from root.sg.d1 group by ([10,100),10ms); -``` - -IoTDB 支持的聚合函数见文档 [聚合函数](../Reference/Function-and-Expression.md#聚合函数)。 - -##### 时间序列生成函数 - -时间序列生成函数接受若干原始时间序列作为输入,产生一列时间序列输出。与聚合函数不同的是,时间序列生成函数的结果集带有时间戳列。 - -所有的时间序列生成函数都可以接受 * 作为输入,都可以与原始时间序列查询混合进行。 - -###### 内置时间序列生成函数 - -IoTDB 中支持的内置函数列表见文档 [运算符和函数](../Reference/Function-and-Expression.md#算数运算符)。 - -###### 自定义时间序列生成函数 - -IoTDB 支持通过用户自定义函数(点击查看: [用户自定义函数](../Reference/UDF-Libraries.md) )能力进行函数功能扩展。 - -#### 嵌套表达式举例 - -IoTDB 支持嵌套表达式,由于聚合查询和时间序列查询不能在一条查询语句中同时出现,我们将支持的嵌套表达式分为时间序列查询嵌套表达式和聚合查询嵌套表达式两类。 - -##### 时间序列查询嵌套表达式 - -IoTDB 支持在 `SELECT` 子句中计算由**时间序列、常量、时间序列生成函数(包括用户自定义函数)和运算符**组成的任意嵌套表达式。 - -**说明:** - -- 当某个时间戳下左操作数和右操作数都不为空(`null`)时,表达式才会有结果,否则表达式值为`null`,且默认不出现在结果集中。 -- 如果表达式中某个操作数对应多条时间序列(如通配符 `*`),那么每条时间序列对应的结果都会出现在结果集中(按照笛卡尔积形式)。 - -**示例 1:** - -```sql -select a, - b, - ((a + 1) * 2 - 1) % 2 + 1.5, - sin(a + sin(a + sin(b))), - -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b)) + 1 -from root.sg1; -``` - -运行结果: - -``` -+-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| Time|root.sg1.a|root.sg1.b|((((root.sg1.a + 1) * 2) - 1) % 2) + 1.5|sin(root.sg1.a + sin(root.sg1.a + sin(root.sg1.b)))|(-root.sg1.a + root.sg1.b * ((sin(root.sg1.a + root.sg1.b) * sin(root.sg1.a + root.sg1.b)) + (cos(root.sg1.a + root.sg1.b) * cos(root.sg1.a + root.sg1.b)))) + 1| -+-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.010+08:00| 1| 1| 2.5| 0.9238430524420609| -1.0| -|1970-01-01T08:00:00.020+08:00| 2| 2| 2.5| 0.7903505371876317| -3.0| -|1970-01-01T08:00:00.030+08:00| 3| 3| 2.5| 0.14065207680386618| -5.0| -|1970-01-01T08:00:00.040+08:00| 4| null| 2.5| null| null| -|1970-01-01T08:00:00.050+08:00| null| 5| null| null| null| -|1970-01-01T08:00:00.060+08:00| 6| 6| 2.5| -0.7288037411970916| -11.0| -+-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 6 -It costs 0.048s -``` - -**示例 2:** - -```sql -select (a + b) * 2 + sin(a) from root.sg -``` - -运行结果: - -``` -+-----------------------------+----------------------------------------------+ -| Time|((root.sg.a + root.sg.b) * 2) + sin(root.sg.a)| -+-----------------------------+----------------------------------------------+ -|1970-01-01T08:00:00.010+08:00| 59.45597888911063| -|1970-01-01T08:00:00.020+08:00| 100.91294525072763| -|1970-01-01T08:00:00.030+08:00| 139.01196837590714| -|1970-01-01T08:00:00.040+08:00| 180.74511316047935| -|1970-01-01T08:00:00.050+08:00| 219.73762514629607| -|1970-01-01T08:00:00.060+08:00| 259.6951893788978| -|1970-01-01T08:00:00.070+08:00| 300.7738906815579| -|1970-01-01T08:00:00.090+08:00| 39.45597888911063| -|1970-01-01T08:00:00.100+08:00| 39.45597888911063| -+-----------------------------+----------------------------------------------+ -Total line number = 9 -It costs 0.011s -``` - -**示例 3:** - -```sql -select (a + *) / 2 from root.sg1 -``` - -运行结果: - -``` -+-----------------------------+-----------------------------+-----------------------------+ -| Time|(root.sg1.a + root.sg1.a) / 2|(root.sg1.a + root.sg1.b) / 2| -+-----------------------------+-----------------------------+-----------------------------+ -|1970-01-01T08:00:00.010+08:00| 1.0| 1.0| -|1970-01-01T08:00:00.020+08:00| 2.0| 2.0| -|1970-01-01T08:00:00.030+08:00| 3.0| 3.0| -|1970-01-01T08:00:00.040+08:00| 4.0| null| -|1970-01-01T08:00:00.060+08:00| 6.0| 6.0| -+-----------------------------+-----------------------------+-----------------------------+ -Total line number = 5 -It costs 0.011s -``` - -**示例 4:** - -```sql -select (a + b) * 3 from root.sg, root.ln -``` - -运行结果: - -``` -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -| Time|(root.sg.a + root.sg.b) * 3|(root.sg.a + root.ln.b) * 3|(root.ln.a + root.sg.b) * 3|(root.ln.a + root.ln.b) * 3| -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -|1970-01-01T08:00:00.010+08:00| 90.0| 270.0| 360.0| 540.0| -|1970-01-01T08:00:00.020+08:00| 150.0| 330.0| 690.0| 870.0| -|1970-01-01T08:00:00.030+08:00| 210.0| 450.0| 570.0| 810.0| -|1970-01-01T08:00:00.040+08:00| 270.0| 240.0| 690.0| 660.0| -|1970-01-01T08:00:00.050+08:00| 330.0| null| null| null| -|1970-01-01T08:00:00.060+08:00| 390.0| null| null| null| -|1970-01-01T08:00:00.070+08:00| 450.0| null| null| null| -|1970-01-01T08:00:00.090+08:00| 60.0| null| null| null| -|1970-01-01T08:00:00.100+08:00| 60.0| null| null| null| -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -Total line number = 9 -It costs 0.014s -``` - -##### 聚合查询嵌套表达式 - -IoTDB 支持在 `SELECT` 子句中计算由**聚合函数、常量、时间序列生成函数和表达式**组成的任意嵌套表达式。 - -**说明:** - -- 当某个时间戳下左操作数和右操作数都不为空(`null`)时,表达式才会有结果,否则表达式值为`null`,且默认不出现在结果集中。但在使用`GROUP BY`子句的聚合查询嵌套表达式中,我们希望保留每个时间窗口的值,所以表达式值为`null`的窗口也包含在结果集中。 -- 如果表达式中某个操作数对应多条时间序列(如通配符`*`),那么每条时间序列对应的结果都会出现在结果集中(按照笛卡尔积形式)。 - -**示例 1:** - -```sql -select avg(temperature), - sin(avg(temperature)), - avg(temperature) + 1, - -sum(hardware), - avg(temperature) + sum(hardware) -from root.ln.wf01.wt01; -``` - -运行结果: - -``` -+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+ -|avg(root.ln.wf01.wt01.temperature)|sin(avg(root.ln.wf01.wt01.temperature))|avg(root.ln.wf01.wt01.temperature) + 1|-sum(root.ln.wf01.wt01.hardware)|avg(root.ln.wf01.wt01.temperature) + sum(root.ln.wf01.wt01.hardware)| -+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+ -| 15.927999999999999| -0.21826546964855045| 16.927999999999997| -7426.0| 7441.928| -+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+ -Total line number = 1 -It costs 0.009s -``` - -**示例 2:** - -```sql -select avg(*), - (avg(*) + 1) * 3 / 2 -1 -from root.sg1 -``` - -运行结果: - -``` -+---------------+---------------+-------------------------------------+-------------------------------------+ -|avg(root.sg1.a)|avg(root.sg1.b)|(avg(root.sg1.a) + 1) * 3 / 2 - 1 |(avg(root.sg1.b) + 1) * 3 / 2 - 1 | -+---------------+---------------+-------------------------------------+-------------------------------------+ -| 3.2| 3.4| 5.300000000000001| 5.6000000000000005| -+---------------+---------------+-------------------------------------+-------------------------------------+ -Total line number = 1 -It costs 0.007s -``` - -**示例 3:** - -```sql -select avg(temperature), - sin(avg(temperature)), - avg(temperature) + 1, - -sum(hardware), - avg(temperature) + sum(hardware) as custom_sum -from root.ln.wf01.wt01 -GROUP BY([10, 90), 10ms); -``` - -运行结果: - -``` -+-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+ -| Time|avg(root.ln.wf01.wt01.temperature)|sin(avg(root.ln.wf01.wt01.temperature))|avg(root.ln.wf01.wt01.temperature) + 1|-sum(root.ln.wf01.wt01.hardware)|custom_sum| -+-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+ -|1970-01-01T08:00:00.010+08:00| 13.987499999999999| 0.9888207947857667| 14.987499999999999| -3211.0| 3224.9875| -|1970-01-01T08:00:00.020+08:00| 29.6| -0.9701057337071853| 30.6| -3720.0| 3749.6| -|1970-01-01T08:00:00.030+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.040+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.050+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.060+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.070+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.080+08:00| null| null| null| null| null| -+-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+ -Total line number = 8 -It costs 0.012s -``` diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Query-Data.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Query-Data.md deleted file mode 100644 index 32205b27c..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Query-Data.md +++ /dev/null @@ -1,3041 +0,0 @@ - - -# 数据查询 -## 概述 - -在 IoTDB 中,使用 `SELECT` 语句从一条或多条时间序列中查询数据,IoTDB 不区分历史数据和实时数据,用户可以用统一的sql语法进行查询,通过 `WHERE` 子句中的时间过滤谓词决定查询的时间范围。 - -### 语法定义 - -```sql -SELECT [LAST] selectExpr [, selectExpr] ... - [INTO intoItem [, intoItem] ...] - FROM prefixPath [, prefixPath] ... - [WHERE whereCondition] - [GROUP BY { - ([startTime, endTime), interval [, slidingStep]) | - LEVEL = levelNum [, levelNum] ... | - TAGS(tagKey [, tagKey] ... | - VARIATION(expression[,delta][,ignoreNull=true/false]) | - CONDITION(expression,[keep>/>=/=/ 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000; -``` - -其含义为: - -被选择的设备为 ln 集团 wf01 子站 wt01 设备;被选择的时间序列为供电状态(status)和温度传感器(temperature);该语句要求选择出 “2017-11-01T00:05:00.000” 至 “2017-11-01T00:12:00.000” 之间的所选时间序列的值。 - -该 SQL 语句的执行结果如下: - -``` -+-----------------------------+------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.status|root.ln.wf01.wt01.temperature| -+-----------------------------+------------------------+-----------------------------+ -|2017-11-01T00:06:00.000+08:00| false| 20.71| -|2017-11-01T00:07:00.000+08:00| false| 21.45| -|2017-11-01T00:08:00.000+08:00| false| 22.58| -|2017-11-01T00:09:00.000+08:00| false| 20.98| -|2017-11-01T00:10:00.000+08:00| true| 25.52| -|2017-11-01T00:11:00.000+08:00| false| 22.91| -+-----------------------------+------------------------+-----------------------------+ -Total line number = 6 -It costs 0.018s -``` - -#### 示例3:按照多个时间区间选择同一设备的多列数据 - -IoTDB 支持在一次查询中指定多个时间区间条件,用户可以根据需求随意组合时间区间条件。例如, - -SQL 语句为: - -```sql -select status, temperature from root.ln.wf01.wt01 where (time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000) or (time >= 2017-11-01T16:35:00.000 and time <= 2017-11-01T16:37:00.000); -``` - -其含义为: - -被选择的设备为 ln 集团 wf01 子站 wt01 设备;被选择的时间序列为“供电状态(status)”和“温度传感器(temperature)”;该语句指定了两个不同的时间区间,分别为“2017-11-01T00:05:00.000 至 2017-11-01T00:12:00.000”和“2017-11-01T16:35:00.000 至 2017-11-01T16:37:00.000”;该语句要求选择出满足任一时间区间的被选时间序列的值。 - -该 SQL 语句的执行结果如下: - -``` -+-----------------------------+------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.status|root.ln.wf01.wt01.temperature| -+-----------------------------+------------------------+-----------------------------+ -|2017-11-01T00:06:00.000+08:00| false| 20.71| -|2017-11-01T00:07:00.000+08:00| false| 21.45| -|2017-11-01T00:08:00.000+08:00| false| 22.58| -|2017-11-01T00:09:00.000+08:00| false| 20.98| -|2017-11-01T00:10:00.000+08:00| true| 25.52| -|2017-11-01T00:11:00.000+08:00| false| 22.91| -|2017-11-01T16:35:00.000+08:00| true| 23.44| -|2017-11-01T16:36:00.000+08:00| false| 21.98| -|2017-11-01T16:37:00.000+08:00| false| 21.93| -+-----------------------------+------------------------+-----------------------------+ -Total line number = 9 -It costs 0.018s -``` - -#### 示例4:按照多个时间区间选择不同设备的多列数据 - -该系统支持在一次查询中选择任意列的数据,也就是说,被选择的列可以来源于不同的设备。例如,SQL 语句为: - -```sql -select wf01.wt01.status, wf02.wt02.hardware from root.ln where (time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000) or (time >= 2017-11-01T16:35:00.000 and time <= 2017-11-01T16:37:00.000); -``` - -其含义为: - -被选择的时间序列为 “ln 集团 wf01 子站 wt01 设备的供电状态” 以及 “ln 集团 wf02 子站 wt02 设备的硬件版本”;该语句指定了两个时间区间,分别为 “2017-11-01T00:05:00.000 至 2017-11-01T00:12:00.000” 和 “2017-11-01T16:35:00.000 至 2017-11-01T16:37:00.000”;该语句要求选择出满足任意时间区间的被选时间序列的值。 - -该 SQL 语句的执行结果如下: - -``` -+-----------------------------+------------------------+--------------------------+ -| Time|root.ln.wf01.wt01.status|root.ln.wf02.wt02.hardware| -+-----------------------------+------------------------+--------------------------+ -|2017-11-01T00:06:00.000+08:00| false| v1| -|2017-11-01T00:07:00.000+08:00| false| v1| -|2017-11-01T00:08:00.000+08:00| false| v1| -|2017-11-01T00:09:00.000+08:00| false| v1| -|2017-11-01T00:10:00.000+08:00| true| v2| -|2017-11-01T00:11:00.000+08:00| false| v1| -|2017-11-01T16:35:00.000+08:00| true| v2| -|2017-11-01T16:36:00.000+08:00| false| v1| -|2017-11-01T16:37:00.000+08:00| false| v1| -+-----------------------------+------------------------+--------------------------+ -Total line number = 9 -It costs 0.014s -``` - -#### 示例5:根据时间降序返回结果集 - -IoTDB 支持 `order by time` 语句,用于对结果按照时间进行降序展示。例如,SQL 语句为: - -```sql -select * from root.ln.** where time > 1 order by time desc limit 10; -``` - -语句执行的结果为: - -``` -+-----------------------------+--------------------------+------------------------+-----------------------------+------------------------+ -| Time|root.ln.wf02.wt02.hardware|root.ln.wf02.wt02.status|root.ln.wf01.wt01.temperature|root.ln.wf01.wt01.status| -+-----------------------------+--------------------------+------------------------+-----------------------------+------------------------+ -|2017-11-07T23:59:00.000+08:00| v1| false| 21.07| false| -|2017-11-07T23:58:00.000+08:00| v1| false| 22.93| false| -|2017-11-07T23:57:00.000+08:00| v2| true| 24.39| true| -|2017-11-07T23:56:00.000+08:00| v2| true| 24.44| true| -|2017-11-07T23:55:00.000+08:00| v2| true| 25.9| true| -|2017-11-07T23:54:00.000+08:00| v1| false| 22.52| false| -|2017-11-07T23:53:00.000+08:00| v2| true| 24.58| true| -|2017-11-07T23:52:00.000+08:00| v1| false| 20.18| false| -|2017-11-07T23:51:00.000+08:00| v1| false| 22.24| false| -|2017-11-07T23:50:00.000+08:00| v2| true| 23.7| true| -+-----------------------------+--------------------------+------------------------+-----------------------------+------------------------+ -Total line number = 10 -It costs 0.016s -``` - -### 查询执行接口 - -在 IoTDB 中,提供两种方式执行数据查询操作: -- 使用 IoTDB-SQL 执行查询。 -- 常用查询的高效执行接口,包括时间序列原始数据范围查询、最新点查询、简单聚合查询。 - -#### 使用 IoTDB-SQL 执行查询 - -数据查询语句支持在 SQL 命令行终端、JDBC、JAVA / C++ / Python / Go 等编程语言 API、RESTful API 中使用。 - -- 在 SQL 命令行终端中执行查询语句:启动 SQL 命令行终端,直接输入查询语句执行即可,详见 [SQL 命令行终端](../Tools-System/CLI.md)。 - -- 在 JDBC 中执行查询语句,详见 [JDBC](../API/Programming-JDBC.md) 。 - -- 在 JAVA / C++ / Python / Go 等编程语言 API 中执行查询语句,详见应用编程接口一章相应文档。接口原型如下: - - ```java - SessionDataSet executeQueryStatement(String sql); - ``` - -- 在 RESTful API 中使用,详见 [HTTP API V1](../API/RestServiceV1.md) 或者 [HTTP API V2](../API/RestServiceV2.md)。 - -#### 常用查询的高效执行接口 - -各编程语言的 API 为常用的查询提供了高效执行接口,可以省去 SQL 解析等操作的耗时。包括: - -* 时间序列原始数据范围查询: - - 指定的查询时间范围为左闭右开区间,包含开始时间但不包含结束时间。 - -```java -SessionDataSet executeRawDataQuery(List paths, long startTime, long endTime); -``` - -* 最新点查询: - - 查询最后一条时间戳大于等于某个时间点的数据。 - -```java -SessionDataSet executeLastDataQuery(List paths, long lastTime); -``` - -* 聚合查询: - - 支持指定查询时间范围。指定的查询时间范围为左闭右开区间,包含开始时间但不包含结束时间。 - - 支持按照时间区间分段查询。 - -```java -SessionDataSet executeAggregationQuery(List paths, List aggregations); - -SessionDataSet executeAggregationQuery( - List paths, List aggregations, long startTime, long endTime); - -SessionDataSet executeAggregationQuery( - List paths, - List aggregations, - long startTime, - long endTime, - long interval); - -SessionDataSet executeAggregationQuery( - List paths, - List aggregations, - long startTime, - long endTime, - long interval, - long slidingStep); -``` - -## 选择表达式(SELECT FROM 子句) - -`SELECT` 子句指定查询的输出,由若干个 `selectExpr` 组成。 每个 `selectExpr` 定义了查询结果中的一列或多列。 - -**`selectExpr` 是一个由时间序列路径后缀、常量、函数和运算符组成的表达式。即 `selectExpr` 中可以包含:** -- 时间序列路径后缀(支持使用通配符) -- 运算符 - - 算数运算符 - - 比较运算符 - - 逻辑运算符 -- 函数 - - 聚合函数 - - 时间序列生成函数(包括内置函数和用户自定义函数) -- 常量 - -### 使用别名 - -由于 IoTDB 独特的数据模型,在每个传感器前都附带有设备等诸多额外信息。有时,我们只针对某个具体设备查询,而这些前缀信息频繁显示造成了冗余,影响了结果集的显示与分析。 - -IoTDB 支持使用`AS`为查询结果集中的列指定别名。 - -**示例:** - -```sql -select s1 as temperature, s2 as speed from root.ln.wf01.wt01; -``` - -结果集将显示为: - -| Time | temperature | speed | -| ---- | ----------- | ----- | -| ... | ... | ... | - -### 运算符 - -IoTDB 中支持的运算符列表见文档 [运算符和函数](../User-Manual/Operator-and-Expression.md)。 - -### 函数 - -#### 聚合函数 - -聚合函数是多对一函数。它们对一组值进行聚合计算,得到单个聚合结果。 - -**包含聚合函数的查询称为聚合查询**,否则称为时间序列查询。 - -**注意:聚合查询和时间序列查询不能混合使用。** 下列语句是不支持的: - -```sql -select s1, count(s1) from root.sg.d1; -select sin(s1), count(s1) from root.sg.d1; -select s1, count(s1) from root.sg.d1 group by ([10,100),10ms); -``` - -IoTDB 支持的聚合函数见文档 [聚合函数](../User-Manual/Operator-and-Expression.md#内置函数)。 - -#### 时间序列生成函数 - -时间序列生成函数接受若干原始时间序列作为输入,产生一列时间序列输出。与聚合函数不同的是,时间序列生成函数的结果集带有时间戳列。 - -所有的时间序列生成函数都可以接受 * 作为输入,都可以与原始时间序列查询混合进行。 - -##### 内置时间序列生成函数 - -IoTDB 中支持的内置函数列表见文档 [运算符和函数](../User-Manual/Operator-and-Expression.md)。 - -##### 自定义时间序列生成函数 - -IoTDB 支持通过用户自定义函数(点击查看: [用户自定义函数](../User-Manual/Database-Programming.md#用户自定义函数) )能力进行函数功能扩展。 - -### 嵌套表达式举例 - -IoTDB 支持嵌套表达式,由于聚合查询和时间序列查询不能在一条查询语句中同时出现,我们将支持的嵌套表达式分为时间序列查询嵌套表达式和聚合查询嵌套表达式两类。 - -#### 时间序列查询嵌套表达式 - -IoTDB 支持在 `SELECT` 子句中计算由**时间序列、常量、时间序列生成函数(包括用户自定义函数)和运算符**组成的任意嵌套表达式。 - -**说明:** - -- 当某个时间戳下左操作数和右操作数都不为空(`null`)时,表达式才会有结果,否则表达式值为`null`,且默认不出现在结果集中。 -- 如果表达式中某个操作数对应多条时间序列(如通配符 `*`),那么每条时间序列对应的结果都会出现在结果集中(按照笛卡尔积形式)。 - -**示例 1:** - -```sql -select a, - b, - ((a + 1) * 2 - 1) % 2 + 1.5, - sin(a + sin(a + sin(b))), - -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b)) + 1 -from root.sg1; -``` - -运行结果: - -``` -+-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| Time|root.sg1.a|root.sg1.b|((((root.sg1.a + 1) * 2) - 1) % 2) + 1.5|sin(root.sg1.a + sin(root.sg1.a + sin(root.sg1.b)))|(-root.sg1.a + root.sg1.b * ((sin(root.sg1.a + root.sg1.b) * sin(root.sg1.a + root.sg1.b)) + (cos(root.sg1.a + root.sg1.b) * cos(root.sg1.a + root.sg1.b)))) + 1| -+-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.010+08:00| 1| 1| 2.5| 0.9238430524420609| -1.0| -|1970-01-01T08:00:00.020+08:00| 2| 2| 2.5| 0.7903505371876317| -3.0| -|1970-01-01T08:00:00.030+08:00| 3| 3| 2.5| 0.14065207680386618| -5.0| -|1970-01-01T08:00:00.040+08:00| 4| null| 2.5| null| null| -|1970-01-01T08:00:00.050+08:00| null| 5| null| null| null| -|1970-01-01T08:00:00.060+08:00| 6| 6| 2.5| -0.7288037411970916| -11.0| -+-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ -Total line number = 6 -It costs 0.048s -``` - -**示例 2:** - -```sql -select (a + b) * 2 + sin(a) from root.sg -``` - -运行结果: - -``` -+-----------------------------+----------------------------------------------+ -| Time|((root.sg.a + root.sg.b) * 2) + sin(root.sg.a)| -+-----------------------------+----------------------------------------------+ -|1970-01-01T08:00:00.010+08:00| 59.45597888911063| -|1970-01-01T08:00:00.020+08:00| 100.91294525072763| -|1970-01-01T08:00:00.030+08:00| 139.01196837590714| -|1970-01-01T08:00:00.040+08:00| 180.74511316047935| -|1970-01-01T08:00:00.050+08:00| 219.73762514629607| -|1970-01-01T08:00:00.060+08:00| 259.6951893788978| -|1970-01-01T08:00:00.070+08:00| 300.7738906815579| -|1970-01-01T08:00:00.090+08:00| 39.45597888911063| -|1970-01-01T08:00:00.100+08:00| 39.45597888911063| -+-----------------------------+----------------------------------------------+ -Total line number = 9 -It costs 0.011s -``` - -**示例 3:** - -```sql -select (a + *) / 2 from root.sg1 -``` - -运行结果: - -``` -+-----------------------------+-----------------------------+-----------------------------+ -| Time|(root.sg1.a + root.sg1.a) / 2|(root.sg1.a + root.sg1.b) / 2| -+-----------------------------+-----------------------------+-----------------------------+ -|1970-01-01T08:00:00.010+08:00| 1.0| 1.0| -|1970-01-01T08:00:00.020+08:00| 2.0| 2.0| -|1970-01-01T08:00:00.030+08:00| 3.0| 3.0| -|1970-01-01T08:00:00.040+08:00| 4.0| null| -|1970-01-01T08:00:00.060+08:00| 6.0| 6.0| -+-----------------------------+-----------------------------+-----------------------------+ -Total line number = 5 -It costs 0.011s -``` - -**示例 4:** - -```sql -select (a + b) * 3 from root.sg, root.ln -``` - -运行结果: - -``` -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -| Time|(root.sg.a + root.sg.b) * 3|(root.sg.a + root.ln.b) * 3|(root.ln.a + root.sg.b) * 3|(root.ln.a + root.ln.b) * 3| -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -|1970-01-01T08:00:00.010+08:00| 90.0| 270.0| 360.0| 540.0| -|1970-01-01T08:00:00.020+08:00| 150.0| 330.0| 690.0| 870.0| -|1970-01-01T08:00:00.030+08:00| 210.0| 450.0| 570.0| 810.0| -|1970-01-01T08:00:00.040+08:00| 270.0| 240.0| 690.0| 660.0| -|1970-01-01T08:00:00.050+08:00| 330.0| null| null| null| -|1970-01-01T08:00:00.060+08:00| 390.0| null| null| null| -|1970-01-01T08:00:00.070+08:00| 450.0| null| null| null| -|1970-01-01T08:00:00.090+08:00| 60.0| null| null| null| -|1970-01-01T08:00:00.100+08:00| 60.0| null| null| null| -+-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+ -Total line number = 9 -It costs 0.014s -``` - -#### 聚合查询嵌套表达式 - -IoTDB 支持在 `SELECT` 子句中计算由**聚合函数、常量、时间序列生成函数和表达式**组成的任意嵌套表达式。 - -**说明:** -- 当某个时间戳下左操作数和右操作数都不为空(`null`)时,表达式才会有结果,否则表达式值为`null`,且默认不出现在结果集中。但在使用`GROUP BY`子句的聚合查询嵌套表达式中,我们希望保留每个时间窗口的值,所以表达式值为`null`的窗口也包含在结果集中。 -- 如果表达式中某个操作数对应多条时间序列(如通配符`*`),那么每条时间序列对应的结果都会出现在结果集中(按照笛卡尔积形式)。 - -**示例 1:** - -```sql -select avg(temperature), - sin(avg(temperature)), - avg(temperature) + 1, - -sum(hardware), - avg(temperature) + sum(hardware) -from root.ln.wf01.wt01; -``` - -运行结果: - -``` -+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+ -|avg(root.ln.wf01.wt01.temperature)|sin(avg(root.ln.wf01.wt01.temperature))|avg(root.ln.wf01.wt01.temperature) + 1|-sum(root.ln.wf01.wt01.hardware)|avg(root.ln.wf01.wt01.temperature) + sum(root.ln.wf01.wt01.hardware)| -+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+ -| 15.927999999999999| -0.21826546964855045| 16.927999999999997| -7426.0| 7441.928| -+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+ -Total line number = 1 -It costs 0.009s -``` - -**示例 2:** - -```sql -select avg(*), - (avg(*) + 1) * 3 / 2 -1 -from root.sg1 -``` - -运行结果: - -``` -+---------------+---------------+-------------------------------------+-------------------------------------+ -|avg(root.sg1.a)|avg(root.sg1.b)|(avg(root.sg1.a) + 1) * 3 / 2 - 1 |(avg(root.sg1.b) + 1) * 3 / 2 - 1 | -+---------------+---------------+-------------------------------------+-------------------------------------+ -| 3.2| 3.4| 5.300000000000001| 5.6000000000000005| -+---------------+---------------+-------------------------------------+-------------------------------------+ -Total line number = 1 -It costs 0.007s -``` - -**示例 3:** - -```sql -select avg(temperature), - sin(avg(temperature)), - avg(temperature) + 1, - -sum(hardware), - avg(temperature) + sum(hardware) as custom_sum -from root.ln.wf01.wt01 -GROUP BY([10, 90), 10ms); -``` - -运行结果: - -``` -+-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+ -| Time|avg(root.ln.wf01.wt01.temperature)|sin(avg(root.ln.wf01.wt01.temperature))|avg(root.ln.wf01.wt01.temperature) + 1|-sum(root.ln.wf01.wt01.hardware)|custom_sum| -+-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+ -|1970-01-01T08:00:00.010+08:00| 13.987499999999999| 0.9888207947857667| 14.987499999999999| -3211.0| 3224.9875| -|1970-01-01T08:00:00.020+08:00| 29.6| -0.9701057337071853| 30.6| -3720.0| 3749.6| -|1970-01-01T08:00:00.030+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.040+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.050+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.060+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.070+08:00| null| null| null| null| null| -|1970-01-01T08:00:00.080+08:00| null| null| null| null| null| -+-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+ -Total line number = 8 -It costs 0.012s -``` - -### 最新点查询 - -最新点查询是时序数据库 Apache IoTDB 中提供的一种特殊查询。它返回指定时间序列中时间戳最大的数据点,即一条序列的最新状态。 - -在物联网数据分析场景中,此功能尤为重要。为了满足了用户对设备实时监控的需求,Apache IoTDB 对最新点查询进行了**缓存优化**,能够提供毫秒级的返回速度。 - -SQL 语法: - -```sql -select last [COMMA ]* from < PrefixPath > [COMMA < PrefixPath >]* [ORDER BY TIMESERIES (DESC | ASC)?] -``` - -其含义是: 查询时间序列 prefixPath.path 中最近时间戳的数据。 - -- `whereClause` 中当前只支持时间过滤条件,任何其他过滤条件都将会返回异常。当缓存的最新点不满足过滤条件时,IoTDB 需要从存储中获取结果,此时性能将会有所下降。 - -- 结果集为四列的结构: - - ``` - +----+----------+-----+--------+ - |Time|timeseries|value|dataType| - +----+----------+-----+--------+ - ``` - -- 可以使用 `ORDER BY TIME/TIMESERIES/VALUE/DATATYPE (DESC | ASC)` 指定结果集按照某一列进行降序/升序排列。当值列包含多种类型的数据时,按照字符串类型来排序。 - -**示例 1:** 查询 root.ln.wf01.wt01.status 的最新数据点 - -``` -IoTDB> select last status from root.ln.wf01.wt01 -+-----------------------------+------------------------+-----+--------+ -| Time| timeseries|value|dataType| -+-----------------------------+------------------------+-----+--------+ -|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.status|false| BOOLEAN| -+-----------------------------+------------------------+-----+--------+ -Total line number = 1 -It costs 0.000s -``` - -**示例 2:** 查询 root.ln.wf01.wt01 下 status,temperature 时间戳大于等于 2017-11-07T23:50:00 的最新数据点。 - -``` -IoTDB> select last status, temperature from root.ln.wf01.wt01 where time >= 2017-11-07T23:50:00 -+-----------------------------+-----------------------------+---------+--------+ -| Time| timeseries| value|dataType| -+-----------------------------+-----------------------------+---------+--------+ -|2017-11-07T23:59:00.000+08:00| root.ln.wf01.wt01.status| false| BOOLEAN| -|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.temperature|21.067368| DOUBLE| -+-----------------------------+-----------------------------+---------+--------+ -Total line number = 2 -It costs 0.002s -``` - -**示例 3:** 查询 root.ln.wf01.wt01 下所有序列的最新数据点,并按照序列名降序排列。 - -``` -IoTDB> select last * from root.ln.wf01.wt01 order by timeseries desc; -+-----------------------------+-----------------------------+---------+--------+ -| Time| timeseries| value|dataType| -+-----------------------------+-----------------------------+---------+--------+ -|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.temperature|21.067368| DOUBLE| -|2017-11-07T23:59:00.000+08:00| root.ln.wf01.wt01.status| false| BOOLEAN| -+-----------------------------+-----------------------------+---------+--------+ -Total line number = 2 -It costs 0.002s -``` - -**示例 4:** 查询 root.ln.wf01.wt01 下所有序列的最新数据点,并按照dataType降序排列。 - -``` -IoTDB> select last * from root.ln.wf01.wt01 order by dataType desc; -+-----------------------------+-----------------------------+---------+--------+ -| Time| timeseries| value|dataType| -+-----------------------------+-----------------------------+---------+--------+ -|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.temperature|21.067368| DOUBLE| -|2017-11-07T23:59:00.000+08:00| root.ln.wf01.wt01.status| false| BOOLEAN| -+-----------------------------+-----------------------------+---------+--------+ -Total line number = 2 -It costs 0.002s -``` - -## 查询过滤条件(WHERE 子句) - -`WHERE` 子句指定了对数据行的筛选条件,由一个 `whereCondition` 组成。 - -`whereCondition` 是一个逻辑表达式,对于要选择的每一行,其计算结果为真。如果没有 `WHERE` 子句,将选择所有行。 -在 `whereCondition` 中,可以使用除聚合函数之外的任何 IOTDB 支持的函数和运算符。 - -根据过滤条件的不同,可以分为时间过滤条件和值过滤条件。时间过滤条件和值过滤条件可以混合使用。 - -### 时间过滤条件 - -使用时间过滤条件可以筛选特定时间范围的数据。对于时间戳支持的格式,请参考 [时间戳类型](../Basic-Concept/Data-Type.md) 。 - -示例如下: - -1. 选择时间戳大于 2022-01-01T00:05:00.000 的数据: - - ```sql - select s1 from root.sg1.d1 where time > 2022-01-01T00:05:00.000; - ``` - -2. 选择时间戳等于 2022-01-01T00:05:00.000 的数据: - - ```sql - select s1 from root.sg1.d1 where time = 2022-01-01T00:05:00.000; - ``` - -3. 选择时间区间 [2017-11-01T00:05:00.000, 2017-11-01T00:12:00.000) 内的数据: - - ```sql - select s1 from root.sg1.d1 where time >= 2022-01-01T00:05:00.000 and time < 2017-11-01T00:12:00.000; - ``` - -注:在上述示例中,`time` 也可写做 `timestamp`。 - -### 值过滤条件 - -使用值过滤条件可以筛选数据值满足特定条件的数据。 -**允许**使用 select 子句中未选择的时间序列作为值过滤条件。 - -示例如下: - -1. 选择值大于 36.5 的数据: - - ```sql - select temperature from root.sg1.d1 where temperature > 36.5; - ``` - -2. 选择值等于 true 的数据: - - ```sql - select status from root.sg1.d1 where status = true; - -3. 选择区间 [36.5,40] 内或之外的数据: - - ```sql - select temperature from root.sg1.d1 where temperature between 36.5 and 40; - ```` - ```sql - select temperature from root.sg1.d1 where temperature not between 36.5 and 40; - ```` - -4. 选择值在特定范围内的数据: - - ```sql - select code from root.sg1.d1 where code in ('200', '300', '400', '500'); - ``` - -5. 选择值在特定范围外的数据: - - ```sql - select code from root.sg1.d1 where code not in ('200', '300', '400', '500'); - ``` - -6. 选择值为空的数据: - - ```sql - select code from root.sg1.d1 where temperature is null; - ```` - -7. 选择值为非空的数据: - - ```sql - select code from root.sg1.d1 where temperature is not null; - ```` - -### 模糊查询 - -对于 TEXT 类型的数据,支持使用 `Like` 和 `Regexp` 运算符对数据进行模糊匹配 - -#### 使用 `Like` 进行模糊匹配 - -**匹配规则:** - -- `%` 表示任意0个或多个字符。 -- `_` 表示任意单个字符。 - -**示例 1:** 查询 `root.sg.d1` 下 `value` 含有`'cc'`的数据。 - -``` -IoTDB> select * from root.sg.d1 where value like '%cc%' -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:00.000+08:00| aabbccdd| -|2017-11-01T00:00:01.000+08:00| cc| -+-----------------------------+----------------+ -Total line number = 2 -It costs 0.002s -``` - -**示例 2:** 查询 `root.sg.d1` 下 `value` 中间为 `'b'`、前后为任意单个字符的数据。 - -``` -IoTDB> select * from root.sg.device where value like '_b_' -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:02.000+08:00| abc| -+-----------------------------+----------------+ -Total line number = 1 -It costs 0.002s -``` - -#### 使用 `Regexp` 进行模糊匹配 - -需要传入的过滤条件为 **Java 标准库风格的正则表达式**。 - -**常见的正则匹配举例:** - -``` -长度为3-20的所有字符:^.{3,20}$ -大写英文字符:^[A-Z]+$ -数字和英文字符:^[A-Za-z0-9]+$ -以a开头的:^a.* -``` - -**示例 1:** 查询 root.sg.d1 下 value 值为26个英文字符组成的字符串。 - -```shell -IoTDB> select * from root.sg.d1 where value regexp '^[A-Za-z]+$' -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:00.000+08:00| aabbccdd| -|2017-11-01T00:00:01.000+08:00| cc| -+-----------------------------+----------------+ -Total line number = 2 -It costs 0.002s -``` - -**示例 2:** 查询 root.sg.d1 下 value 值为26个小写英文字符组成的字符串且时间大于100的。 - -```shell -IoTDB> select * from root.sg.d1 where value regexp '^[a-z]+$' and time > 100 -+-----------------------------+----------------+ -| Time|root.sg.d1.value| -+-----------------------------+----------------+ -|2017-11-01T00:00:00.000+08:00| aabbccdd| -|2017-11-01T00:00:01.000+08:00| cc| -+-----------------------------+----------------+ -Total line number = 2 -It costs 0.002s -``` - -## 分段分组聚合(GROUP BY 子句) -IoTDB支持通过`GROUP BY`子句对序列进行分段或者分组聚合。 - -分段聚合是指按照时间维度,针对同时间序列中不同数据点之间的时间关系,对数据在行的方向进行分段,每个段得到一个聚合值。目前支持**时间区间分段**、**差值分段**、**条件分段**、**会话分段**和**点数分段**,未来将支持更多分段方式。 - -分组聚合是指针对不同时间序列,在时间序列的潜在业务属性上分组,每个组包含若干条时间序列,每个组得到一个聚合值。支持**按路径层级分组**和**按序列标签分组**两种分组方式。 - -### 分段聚合 - -#### 时间区间分段聚合 - -时间区间分段聚合是一种时序数据典型的查询方式,数据以高频进行采集,需要按照一定的时间间隔进行聚合计算,如计算每天的平均气温,需要将气温的序列按天进行分段,然后计算平均值。 - -在 IoTDB 中,聚合查询可以通过 `GROUP BY` 子句指定按照时间区间分段聚合。用户可以指定聚合的时间间隔和滑动步长,相关参数如下: - -* 参数 1:时间轴显示时间窗口大小 -* 参数 2:聚合窗口的大小(必须为正数) -* 参数 3:聚合窗口的滑动步长(可选,默认与聚合窗口大小相同) - -下图中指出了这三个参数的含义: - - - -接下来,我们给出几个典型例子: - -##### 未指定滑动步长的时间区间分段聚合查询 - -对应的 SQL 语句是: - -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d); -``` -这条查询的含义是: - -由于用户没有指定滑动步长,滑动步长将会被默认设置为跟时间间隔参数相同,也就是`1d`。 - -上面这个例子的第一个参数是显示窗口参数,决定了最终的显示范围是 [2017-11-01T00:00:00, 2017-11-07T23:00:00)。 - -上面这个例子的第二个参数是划分时间轴的时间间隔参数,将`1d`当作划分间隔,显示窗口参数的起始时间当作分割原点,时间轴即被划分为连续的时间间隔:[0,1d), [1d, 2d), [2d, 3d) 等等。 - -然后系统将会用 WHERE 子句中的时间和值过滤条件以及 GROUP BY 语句中的第一个参数作为数据的联合过滤条件,获得满足所有过滤条件的数据(在这个例子里是在 [2017-11-01T00:00:00, 2017-11-07 T23:00:00) 这个时间范围的数据),并把这些数据映射到之前分割好的时间轴中(这个例子里是从 2017-11-01T00:00:00 到 2017-11-07T23:00:00:00 的每一天) - -每个时间间隔窗口内都有数据,SQL 执行后的结果集如下所示: - -``` -+-----------------------------+-------------------------------+----------------------------------------+ -| Time|count(root.ln.wf01.wt01.status)|max_value(root.ln.wf01.wt01.temperature)| -+-----------------------------+-------------------------------+----------------------------------------+ -|2017-11-01T00:00:00.000+08:00| 1440| 26.0| -|2017-11-02T00:00:00.000+08:00| 1440| 26.0| -|2017-11-03T00:00:00.000+08:00| 1440| 25.99| -|2017-11-04T00:00:00.000+08:00| 1440| 26.0| -|2017-11-05T00:00:00.000+08:00| 1440| 26.0| -|2017-11-06T00:00:00.000+08:00| 1440| 25.99| -|2017-11-07T00:00:00.000+08:00| 1380| 26.0| -+-----------------------------+-------------------------------+----------------------------------------+ -Total line number = 7 -It costs 0.024s -``` - -##### 指定滑动步长的时间区间分段聚合查询 - -对应的 SQL 语句是: - -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d); -``` - -这条查询的含义是: - -由于用户指定了滑动步长为`1d`,GROUP BY 语句执行时将会每次把时间间隔往后移动一天的步长,而不是默认的 3 小时。 - -也就意味着,我们想要取从 2017-11-01 到 2017-11-07 每一天的凌晨 0 点到凌晨 3 点的数据。 - -上面这个例子的第一个参数是显示窗口参数,决定了最终的显示范围是 [2017-11-01T00:00:00, 2017-11-07T23:00:00)。 - -上面这个例子的第二个参数是划分时间轴的时间间隔参数,将`3h`当作划分间隔,显示窗口参数的起始时间当作分割原点,时间轴即被划分为连续的时间间隔:[2017-11-01T00:00:00, 2017-11-01T03:00:00), [2017-11-02T00:00:00, 2017-11-02T03:00:00), [2017-11-03T00:00:00, 2017-11-03T03:00:00) 等等。 - -上面这个例子的第三个参数是每次时间间隔的滑动步长。 - -然后系统将会用 WHERE 子句中的时间和值过滤条件以及 GROUP BY 语句中的第一个参数作为数据的联合过滤条件,获得满足所有过滤条件的数据(在这个例子里是在 [2017-11-01T00:00:00, 2017-11-07 T23:00:00) 这个时间范围的数据),并把这些数据映射到之前分割好的时间轴中(这个例子里是从 2017-11-01T00:00:00 到 2017-11-07T23:00:00:00 的每一天的凌晨 0 点到凌晨 3 点) - -每个时间间隔窗口内都有数据,SQL 执行后的结果集如下所示: - -``` -+-----------------------------+-------------------------------+----------------------------------------+ -| Time|count(root.ln.wf01.wt01.status)|max_value(root.ln.wf01.wt01.temperature)| -+-----------------------------+-------------------------------+----------------------------------------+ -|2017-11-01T00:00:00.000+08:00| 180| 25.98| -|2017-11-02T00:00:00.000+08:00| 180| 25.98| -|2017-11-03T00:00:00.000+08:00| 180| 25.96| -|2017-11-04T00:00:00.000+08:00| 180| 25.96| -|2017-11-05T00:00:00.000+08:00| 180| 26.0| -|2017-11-06T00:00:00.000+08:00| 180| 25.85| -|2017-11-07T00:00:00.000+08:00| 180| 25.99| -+-----------------------------+-------------------------------+----------------------------------------+ -Total line number = 7 -It costs 0.006s -``` - -滑动步长可以小于聚合窗口,此时聚合窗口之间有重叠时间(类似于一个滑动窗口)。 - -例如 SQL: -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-01 10:00:00), 4h, 2h); -``` - -SQL 执行后的结果集如下所示: - -``` -+-----------------------------+-------------------------------+----------------------------------------+ -| Time|count(root.ln.wf01.wt01.status)|max_value(root.ln.wf01.wt01.temperature)| -+-----------------------------+-------------------------------+----------------------------------------+ -|2017-11-01T00:00:00.000+08:00| 180| 25.98| -|2017-11-01T02:00:00.000+08:00| 180| 25.98| -|2017-11-01T04:00:00.000+08:00| 180| 25.96| -|2017-11-01T06:00:00.000+08:00| 180| 25.96| -|2017-11-01T08:00:00.000+08:00| 180| 26.0| -+-----------------------------+-------------------------------+----------------------------------------+ -Total line number = 5 -It costs 0.006s -``` - -##### 按照自然月份的时间区间分段聚合查询 - -对应的 SQL 语句是: - -```sql -select count(status) from root.ln.wf01.wt01 where time > 2017-11-01T01:00:00 group by([2017-11-01T00:00:00, 2019-11-07T23:00:00), 1mo, 2mo); -``` - -这条查询的含义是: - -由于用户指定了滑动步长为`2mo`,GROUP BY 语句执行时将会每次把时间间隔往后移动 2 个自然月的步长,而不是默认的 1 个自然月。 - -也就意味着,我们想要取从 2017-11-01 到 2019-11-07 每 2 个自然月的第一个月的数据。 - -上面这个例子的第一个参数是显示窗口参数,决定了最终的显示范围是 [2017-11-01T00:00:00, 2019-11-07T23:00:00)。 - -起始时间为 2017-11-01T00:00:00,滑动步长将会以起始时间作为标准按月递增,取当月的 1 号作为时间间隔的起始时间。 - -上面这个例子的第二个参数是划分时间轴的时间间隔参数,将`1mo`当作划分间隔,显示窗口参数的起始时间当作分割原点,时间轴即被划分为连续的时间间隔:[2017-11-01T00:00:00, 2017-12-01T00:00:00), [2018-02-01T00:00:00, 2018-03-01T00:00:00), [2018-05-03T00:00:00, 2018-06-01T00:00:00) 等等。 - -上面这个例子的第三个参数是每次时间间隔的滑动步长。 - -然后系统将会用 WHERE 子句中的时间和值过滤条件以及 GROUP BY 语句中的第一个参数作为数据的联合过滤条件,获得满足所有过滤条件的数据(在这个例子里是在 [2017-11-01T00:00:00, 2019-11-07T23:00:00) 这个时间范围的数据),并把这些数据映射到之前分割好的时间轴中(这个例子里是从 2017-11-01T00:00:00 到 2019-11-07T23:00:00:00 的每两个自然月的第一个月) - -每个时间间隔窗口内都有数据,SQL 执行后的结果集如下所示: - -``` -+-----------------------------+-------------------------------+ -| Time|count(root.ln.wf01.wt01.status)| -+-----------------------------+-------------------------------+ -|2017-11-01T00:00:00.000+08:00| 259| -|2018-01-01T00:00:00.000+08:00| 250| -|2018-03-01T00:00:00.000+08:00| 259| -|2018-05-01T00:00:00.000+08:00| 251| -|2018-07-01T00:00:00.000+08:00| 242| -|2018-09-01T00:00:00.000+08:00| 225| -|2018-11-01T00:00:00.000+08:00| 216| -|2019-01-01T00:00:00.000+08:00| 207| -|2019-03-01T00:00:00.000+08:00| 216| -|2019-05-01T00:00:00.000+08:00| 207| -|2019-07-01T00:00:00.000+08:00| 199| -|2019-09-01T00:00:00.000+08:00| 181| -|2019-11-01T00:00:00.000+08:00| 60| -+-----------------------------+-------------------------------+ -``` - -对应的 SQL 语句是: - -```sql -select count(status) from root.ln.wf01.wt01 group by([2017-10-31T00:00:00, 2019-11-07T23:00:00), 1mo, 2mo); -``` - -这条查询的含义是: - -由于用户指定了滑动步长为`2mo`,GROUP BY 语句执行时将会每次把时间间隔往后移动 2 个自然月的步长,而不是默认的 1 个自然月。 - -也就意味着,我们想要取从 2017-10-31 到 2019-11-07 每 2 个自然月的第一个月的数据。 - -与上述示例不同的是起始时间为 2017-10-31T00:00:00,滑动步长将会以起始时间作为标准按月递增,取当月的 31 号(即最后一天)作为时间间隔的起始时间。若起始时间设置为 30 号,滑动步长会将时间间隔的起始时间设置为当月 30 号,若不存在则为最后一天。 - -上面这个例子的第一个参数是显示窗口参数,决定了最终的显示范围是 [2017-10-31T00:00:00, 2019-11-07T23:00:00)。 - -上面这个例子的第二个参数是划分时间轴的时间间隔参数,将`1mo`当作划分间隔,显示窗口参数的起始时间当作分割原点,时间轴即被划分为连续的时间间隔:[2017-10-31T00:00:00, 2017-11-31T00:00:00), [2018-02-31T00:00:00, 2018-03-31T00:00:00), [2018-05-31T00:00:00, 2018-06-31T00:00:00) 等等。 - -上面这个例子的第三个参数是每次时间间隔的滑动步长。 - -然后系统将会用 WHERE 子句中的时间和值过滤条件以及 GROUP BY 语句中的第一个参数作为数据的联合过滤条件,获得满足所有过滤条件的数据(在这个例子里是在 [2017-10-31T00:00:00, 2019-11-07T23:00:00) 这个时间范围的数据),并把这些数据映射到之前分割好的时间轴中(这个例子里是从 2017-10-31T00:00:00 到 2019-11-07T23:00:00:00 的每两个自然月的第一个月) - -每个时间间隔窗口内都有数据,SQL 执行后的结果集如下所示: - -``` -+-----------------------------+-------------------------------+ -| Time|count(root.ln.wf01.wt01.status)| -+-----------------------------+-------------------------------+ -|2017-10-31T00:00:00.000+08:00| 251| -|2017-12-31T00:00:00.000+08:00| 250| -|2018-02-28T00:00:00.000+08:00| 259| -|2018-04-30T00:00:00.000+08:00| 250| -|2018-06-30T00:00:00.000+08:00| 242| -|2018-08-31T00:00:00.000+08:00| 225| -|2018-10-31T00:00:00.000+08:00| 216| -|2018-12-31T00:00:00.000+08:00| 208| -|2019-02-28T00:00:00.000+08:00| 216| -|2019-04-30T00:00:00.000+08:00| 208| -|2019-06-30T00:00:00.000+08:00| 199| -|2019-08-31T00:00:00.000+08:00| 181| -|2019-10-31T00:00:00.000+08:00| 69| -+-----------------------------+-------------------------------+ -``` - -##### 左开右闭区间 - -每个区间的结果时间戳为区间右端点,对应的 SQL 语句是: - -```sql -select count(status) from root.ln.wf01.wt01 group by ((2017-11-01T00:00:00, 2017-11-07T23:00:00],1d); -``` - -这条查询语句的时间区间是左开右闭的,结果中不会包含时间点 2017-11-01 的数据,但是会包含时间点 2017-11-07 的数据。 - -SQL 执行后的结果集如下所示: - -``` -+-----------------------------+-------------------------------+ -| Time|count(root.ln.wf01.wt01.status)| -+-----------------------------+-------------------------------+ -|2017-11-02T00:00:00.000+08:00| 1440| -|2017-11-03T00:00:00.000+08:00| 1440| -|2017-11-04T00:00:00.000+08:00| 1440| -|2017-11-05T00:00:00.000+08:00| 1440| -|2017-11-06T00:00:00.000+08:00| 1440| -|2017-11-07T00:00:00.000+08:00| 1440| -|2017-11-07T23:00:00.000+08:00| 1380| -+-----------------------------+-------------------------------+ -Total line number = 7 -It costs 0.004s -``` - -#### 差值分段聚合 -IoTDB支持通过`GROUP BY VARIATION`语句来根据差值进行分组。`GROUP BY VARIATION`会将第一个点作为一个组的**基准点**,每个新的数据在按照给定规则与基准点进行差值运算后, -如果差值小于给定的阈值则将该新点归于同一组,否则结束当前分组,以这个新的数据为新的基准点开启新的分组。 -该分组方式不会重叠,且没有固定的开始结束时间。其子句语法如下: -```sql -group by variation(controlExpression[,delta][,ignoreNull=true/false]) -``` -不同的参数含义如下 -* controlExpression - -分组所参照的值,**可以是查询数据中的某一列或是多列的表达式 -(多列表达式计算后仍为一个值,使用多列表达式时指定的列必须都为数值列)**, 差值便是根据数据的controlExpression的差值运算。 -* delta - -分组所使用的阈值,同一分组中**每个点的controlExpression对应的值与该组中基准点对应值的差值都小于`delta`**。当`delta=0`时,相当于一个等值分组,所有连续且expression值相同的数据将被分到一组。 - -* ignoreNull - -用于指定`controlExpression`的值为null时对数据的处理方式,当`ignoreNull`为false时,该null值会被视为新的值,`ignoreNull`为true时,则直接跳过对应的点。 - -在`delta`取不同值时,`controlExpression`支持的返回数据类型以及当`ignoreNull`为false时对于null值的处理方式可以见下表: - -| delta | controlExpression支持的返回类型 | ignoreNull=false时对于Null值的处理 | -|----------|--------------------------------------|-----------------------------------------------------------------| -| delta!=0 | INT32、INT64、FLOAT、DOUBLE | 若正在维护分组的值不为null,null视为无穷大/无穷小,结束当前分组。连续的null视为差值相等的值,会被分配在同一个分组 | -| delta=0 | TEXT、BINARY、INT32、INT64、FLOAT、DOUBLE | null被视为新分组中的新值,连续的null属于相同的分组 | - -下图为差值分段的一个分段方式示意图,与组中第一个数据的控制列值的差值在delta内的控制列对应的点属于相同的分组。 - -groupByVariation - -##### 使用注意事项 -1. `controlExpression`的结果应该为唯一值,如果使用通配符拼接后出现多列,则报错。 -2. 对于一个分组,默认Time列输出分组的开始时间,查询时可以使用select `__endTime`的方式来使得结果输出分组的结束时间。 -3. 与`ALIGN BY DEVICE`搭配使用时会对每个device进行单独的分组操作。 -4. 当没有指定`delta`和`ignoreNull`时,`delta`默认为0,`ignoreNull`默认为true。 -5. 当前暂不支持与`GROUP BY LEVEL`搭配使用。 - -使用如下的原始数据,接下来会给出几个事件分段查询的使用样例 -``` -+-----------------------------+-------+-------+-------+--------+-------+-------+ -| Time| s1| s2| s3| s4| s5| s6| -+-----------------------------+-------+-------+-------+--------+-------+-------+ -|1970-01-01T08:00:00.000+08:00| 4.5| 9.0| 0.0| 45.0| 9.0| 8.25| -|1970-01-01T08:00:00.010+08:00| null| 19.0| 10.0| 145.0| 19.0| 8.25| -|1970-01-01T08:00:00.020+08:00| 24.5| 29.0| null| 245.0| 29.0| null| -|1970-01-01T08:00:00.030+08:00| 34.5| null| 30.0| 345.0| null| null| -|1970-01-01T08:00:00.040+08:00| 44.5| 49.0| 40.0| 445.0| 49.0| 8.25| -|1970-01-01T08:00:00.050+08:00| null| 59.0| 50.0| 545.0| 59.0| 6.25| -|1970-01-01T08:00:00.060+08:00| 64.5| 69.0| 60.0| 645.0| 69.0| null| -|1970-01-01T08:00:00.070+08:00| 74.5| 79.0| null| null| 79.0| 3.25| -|1970-01-01T08:00:00.080+08:00| 84.5| 89.0| 80.0| 845.0| 89.0| 3.25| -|1970-01-01T08:00:00.090+08:00| 94.5| 99.0| 90.0| 945.0| 99.0| 3.25| -|1970-01-01T08:00:00.150+08:00| 66.5| 77.0| 90.0| 945.0| 99.0| 9.25| -+-----------------------------+-------+-------+-------+--------+-------+-------+ -``` -##### delta=0时的等值事件分段 -使用如下sql语句 -```sql -select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6) -``` -得到如下的查询结果,这里忽略了s6为null的行 -``` -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -| Time| __endTime|avg(root.sg.d.s1)|count(root.sg.d.s2)|sum(root.sg.d.s3)| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -|1970-01-01T08:00:00.000+08:00|1970-01-01T08:00:00.040+08:00| 24.5| 3| 50.0| -|1970-01-01T08:00:00.050+08:00|1970-01-01T08:00:00.050+08:00| null| 1| 50.0| -|1970-01-01T08:00:00.070+08:00|1970-01-01T08:00:00.090+08:00| 84.5| 3| 170.0| -|1970-01-01T08:00:00.150+08:00|1970-01-01T08:00:00.150+08:00| 66.5| 1| 90.0| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -``` -当指定ignoreNull为false时,会将s6为null的数据也考虑进来 -```sql -select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6, ignoreNull=false) -``` -得到如下的结果 -``` -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -| Time| __endTime|avg(root.sg.d.s1)|count(root.sg.d.s2)|sum(root.sg.d.s3)| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -|1970-01-01T08:00:00.000+08:00|1970-01-01T08:00:00.010+08:00| 4.5| 2| 10.0| -|1970-01-01T08:00:00.020+08:00|1970-01-01T08:00:00.030+08:00| 29.5| 1| 30.0| -|1970-01-01T08:00:00.040+08:00|1970-01-01T08:00:00.040+08:00| 44.5| 1| 40.0| -|1970-01-01T08:00:00.050+08:00|1970-01-01T08:00:00.050+08:00| null| 1| 50.0| -|1970-01-01T08:00:00.060+08:00|1970-01-01T08:00:00.060+08:00| 64.5| 1| 60.0| -|1970-01-01T08:00:00.070+08:00|1970-01-01T08:00:00.090+08:00| 84.5| 3| 170.0| -|1970-01-01T08:00:00.150+08:00|1970-01-01T08:00:00.150+08:00| 66.5| 1| 90.0| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -``` -##### delta!=0时的差值事件分段 -使用如下sql语句 -```sql -select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6, 4) -``` -得到如下的查询结果 -``` -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -| Time| __endTime|avg(root.sg.d.s1)|count(root.sg.d.s2)|sum(root.sg.d.s3)| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -|1970-01-01T08:00:00.000+08:00|1970-01-01T08:00:00.050+08:00| 24.5| 4| 100.0| -|1970-01-01T08:00:00.070+08:00|1970-01-01T08:00:00.090+08:00| 84.5| 3| 170.0| -|1970-01-01T08:00:00.150+08:00|1970-01-01T08:00:00.150+08:00| 66.5| 1| 90.0| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -``` -group by子句中的controlExpression同样支持列的表达式 - -```sql -select __endTime, avg(s1), count(s2), sum(s3) from root.sg.d group by variation(s6+s5, 10) -``` -得到如下的查询结果 -``` -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -| Time| __endTime|avg(root.sg.d.s1)|count(root.sg.d.s2)|sum(root.sg.d.s3)| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -|1970-01-01T08:00:00.000+08:00|1970-01-01T08:00:00.010+08:00| 4.5| 2| 10.0| -|1970-01-01T08:00:00.040+08:00|1970-01-01T08:00:00.050+08:00| 44.5| 2| 90.0| -|1970-01-01T08:00:00.070+08:00|1970-01-01T08:00:00.080+08:00| 79.5| 2| 80.0| -|1970-01-01T08:00:00.090+08:00|1970-01-01T08:00:00.150+08:00| 80.5| 2| 180.0| -+-----------------------------+-----------------------------+-----------------+-------------------+-----------------+ -``` -#### 条件分段聚合 -当需要根据指定条件对数据进行筛选,并将连续的符合条件的行分为一组进行聚合运算时,可以使用`GROUP BY CONDITION`的分段方式;不满足给定条件的行因为不属于任何分组会被直接简单忽略。 -其语法定义如下: -```sql -group by condition(predict,[keep>/>=/=/<=/<]threshold,[,ignoreNull=true/false]) -``` -* predict - -返回boolean数据类型的合法表达式,用于分组的筛选。 -* keep[>/>=/=/<=/<]threshold - -keep表达式用来指定形成分组所需要连续满足`predict`条件的数据行数,只有行数满足keep表达式的分组才会被输出。keep表达式由一个'keep'字符串和`long`类型的threshold组合或者是单独的`long`类型数据构成。 - -* ignoreNull=true/false - -用于指定遇到predict为null的数据行时的处理方式,为true则跳过该行,为false则结束当前分组。 - -##### 使用注意事项 -1. keep条件在查询中是必需的,但可以省略掉keep字符串给出一个`long`类型常数,默认为`keep=该long型常数`的等于条件。 -2. `ignoreNull`默认为true。 -3. 对于一个分组,默认Time列输出分组的开始时间,查询时可以使用select `__endTime`的方式来使得结果输出分组的结束时间。 -4. 与`ALIGN BY DEVICE`搭配使用时会对每个device进行单独的分组操作。 -5. 当前暂不支持与`GROUP BY LEVEL`搭配使用。 - - -对于如下原始数据,下面会给出几个查询样例: -``` -+-----------------------------+-------------------------+-------------------------------------+------------------------------------+ -| Time|root.sg.beijing.car01.soc|root.sg.beijing.car01.charging_status|root.sg.beijing.car01.vehicle_status| -+-----------------------------+-------------------------+-------------------------------------+------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 14.0| 1| 1| -|1970-01-01T08:00:00.002+08:00| 16.0| 1| 1| -|1970-01-01T08:00:00.003+08:00| 16.0| 0| 1| -|1970-01-01T08:00:00.004+08:00| 16.0| 0| 1| -|1970-01-01T08:00:00.005+08:00| 18.0| 1| 1| -|1970-01-01T08:00:00.006+08:00| 24.0| 1| 1| -|1970-01-01T08:00:00.007+08:00| 36.0| 1| 1| -|1970-01-01T08:00:00.008+08:00| 36.0| null| 1| -|1970-01-01T08:00:00.009+08:00| 45.0| 1| 1| -|1970-01-01T08:00:00.010+08:00| 60.0| 1| 1| -+-----------------------------+-------------------------+-------------------------------------+------------------------------------+ -``` -查询至少连续两行以上的charging_status=1的数据,sql语句如下: -```sql -select max_time(charging_status),count(vehicle_status),last_value(soc) from root.** group by condition(charging_status=1,KEEP>=2,ignoreNull=true) -``` -得到结果如下: -``` -+-----------------------------+-----------------------------------------------+-------------------------------------------+-------------------------------------+ -| Time|max_time(root.sg.beijing.car01.charging_status)|count(root.sg.beijing.car01.vehicle_status)|last_value(root.sg.beijing.car01.soc)| -+-----------------------------+-----------------------------------------------+-------------------------------------------+-------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 2| 2| 16.0| -|1970-01-01T08:00:00.005+08:00| 10| 5| 60.0| -+-----------------------------+-----------------------------------------------+-------------------------------------------+-------------------------------------+ -``` -当设置`ignoreNull`为false时,遇到null值为将其视为一个不满足条件的行,会结束正在计算的分组。 -```sql -select max_time(charging_status),count(vehicle_status),last_value(soc) from root.** group by condition(charging_status=1,KEEP>=2,ignoreNull=false) -``` -得到如下结果,原先的分组被含null的行拆分: -``` -+-----------------------------+-----------------------------------------------+-------------------------------------------+-------------------------------------+ -| Time|max_time(root.sg.beijing.car01.charging_status)|count(root.sg.beijing.car01.vehicle_status)|last_value(root.sg.beijing.car01.soc)| -+-----------------------------+-----------------------------------------------+-------------------------------------------+-------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 2| 2| 16.0| -|1970-01-01T08:00:00.005+08:00| 7| 3| 36.0| -|1970-01-01T08:00:00.009+08:00| 10| 2| 60.0| -+-----------------------------+-----------------------------------------------+-------------------------------------------+-------------------------------------+ -``` -#### 会话分段聚合 -`GROUP BY SESSION`可以根据时间列的间隔进行分组,在结果集的时间列中,时间间隔小于等于设定阈值的数据会被分为一组。例如在工业场景中,设备并不总是连续运行,`GROUP BY SESSION`会将设备每次接入会话所产生的数据分为一组。 -其语法定义如下: -```sql -group by session(timeInterval) -``` -* timeInterval - -设定的时间差阈值,当两条数据时间列的差值大于该阈值,则会给数据创建一个新的分组。 - -下图为`group by session`下的一个分组示意图 - - - -##### 使用注意事项 -1. 对于一个分组,默认Time列输出分组的开始时间,查询时可以使用select `__endTime`的方式来使得结果输出分组的结束时间。 -2. 与`ALIGN BY DEVICE`搭配使用时会对每个device进行单独的分组操作。 -3. 当前暂不支持与`GROUP BY LEVEL`搭配使用。 - -对于下面的原始数据,给出几个查询样例。 -``` -+-----------------------------+-----------------+-----------+--------+------+ -| Time| Device|temperature|hardware|status| -+-----------------------------+-----------------+-----------+--------+------+ -|1970-01-01T08:00:01.000+08:00|root.ln.wf02.wt01| 35.7| 11| false| -|1970-01-01T08:00:02.000+08:00|root.ln.wf02.wt01| 35.8| 22| true| -|1970-01-01T08:00:03.000+08:00|root.ln.wf02.wt01| 35.4| 33| false| -|1970-01-01T08:00:04.000+08:00|root.ln.wf02.wt01| 36.4| 44| false| -|1970-01-01T08:00:05.000+08:00|root.ln.wf02.wt01| 36.8| 55| false| -|1970-01-01T08:00:10.000+08:00|root.ln.wf02.wt01| 36.8| 110| false| -|1970-01-01T08:00:20.000+08:00|root.ln.wf02.wt01| 37.8| 220| true| -|1970-01-01T08:00:30.000+08:00|root.ln.wf02.wt01| 37.5| 330| false| -|1970-01-01T08:00:40.000+08:00|root.ln.wf02.wt01| 37.4| 440| false| -|1970-01-01T08:00:50.000+08:00|root.ln.wf02.wt01| 37.9| 550| false| -|1970-01-01T08:01:40.000+08:00|root.ln.wf02.wt01| 38.0| 110| false| -|1970-01-01T08:02:30.000+08:00|root.ln.wf02.wt01| 38.8| 220| true| -|1970-01-01T08:03:20.000+08:00|root.ln.wf02.wt01| 38.6| 330| false| -|1970-01-01T08:04:20.000+08:00|root.ln.wf02.wt01| 38.4| 440| false| -|1970-01-01T08:05:20.000+08:00|root.ln.wf02.wt01| 38.3| 550| false| -|1970-01-01T08:06:40.000+08:00|root.ln.wf02.wt01| null| 0| null| -|1970-01-01T08:07:50.000+08:00|root.ln.wf02.wt01| null| 0| null| -|1970-01-01T08:08:00.000+08:00|root.ln.wf02.wt01| null| 0| null| -|1970-01-02T08:08:01.000+08:00|root.ln.wf02.wt01| 38.2| 110| false| -|1970-01-02T08:08:02.000+08:00|root.ln.wf02.wt01| 37.5| 220| true| -|1970-01-02T08:08:03.000+08:00|root.ln.wf02.wt01| 37.4| 330| false| -|1970-01-02T08:08:04.000+08:00|root.ln.wf02.wt01| 36.8| 440| false| -|1970-01-02T08:08:05.000+08:00|root.ln.wf02.wt01| 37.4| 550| false| -+-----------------------------+-----------------+-----------+--------+------+ -``` -可以按照不同的时间单位设定时间间隔,sql语句如下: -```sql -select __endTime,count(*) from root.** group by session(1d) -``` -得到如下结果: -``` -+-----------------------------+-----------------------------+------------------------------------+---------------------------------+-------------------------------+ -| Time| __endTime|count(root.ln.wf02.wt01.temperature)|count(root.ln.wf02.wt01.hardware)|count(root.ln.wf02.wt01.status)| -+-----------------------------+-----------------------------+------------------------------------+---------------------------------+-------------------------------+ -|1970-01-01T08:00:01.000+08:00|1970-01-01T08:08:00.000+08:00| 15| 18| 15| -|1970-01-02T08:08:01.000+08:00|1970-01-02T08:08:05.000+08:00| 5| 5| 5| -+-----------------------------+-----------------------------+------------------------------------+---------------------------------+-------------------------------+ -``` -也可以和`HAVING`、`ALIGN BY DEVICE`共同使用 -```sql -select __endTime,sum(hardware) from root.ln.wf02.wt01 group by session(50s) having sum(hardware)>0 align by device -``` -得到如下结果,其中排除了`sum(hardware)`为0的部分 -``` -+-----------------------------+-----------------+-----------------------------+-------------+ -| Time| Device| __endTime|sum(hardware)| -+-----------------------------+-----------------+-----------------------------+-------------+ -|1970-01-01T08:00:01.000+08:00|root.ln.wf02.wt01|1970-01-01T08:03:20.000+08:00| 2475.0| -|1970-01-01T08:04:20.000+08:00|root.ln.wf02.wt01|1970-01-01T08:04:20.000+08:00| 440.0| -|1970-01-01T08:05:20.000+08:00|root.ln.wf02.wt01|1970-01-01T08:05:20.000+08:00| 550.0| -|1970-01-02T08:08:01.000+08:00|root.ln.wf02.wt01|1970-01-02T08:08:05.000+08:00| 1650.0| -+-----------------------------+-----------------+-----------------------------+-------------+ -``` -#### 点数分段聚合 -`GROUP BY COUNT`可以根据点数分组进行聚合运算,将连续的指定数量数据点分为一组,即按照固定的点数进行分组。 -其语法定义如下: -```sql -group by count(controlExpression, size[,ignoreNull=true/false]) -``` -* controlExpression - -计数参照的对象,可以是结果集的任意列或是列的表达式 - -* size - -一个组中数据点的数量,每`size`个数据点会被分到同一个组 - -* ignoreNull=true/false - -是否忽略`controlExpression`为null的数据点,当ignoreNull为true时,在计数时会跳过`controlExpression`结果为null的数据点 - -##### 使用注意事项 -1. 对于一个分组,默认Time列输出分组的开始时间,查询时可以使用select `__endTime`的方式来使得结果输出分组的结束时间。 -2. 与`ALIGN BY DEVICE`搭配使用时会对每个device进行单独的分组操作。 -3. 当前暂不支持与`GROUP BY LEVEL`搭配使用。 -4. 当一个分组内最终的点数不满足`size`的数量时,不会输出该分组的结果 - -对于下面的原始数据,给出几个查询样例。 -``` -+-----------------------------+-----------+-----------------------+ -| Time|root.sg.soc|root.sg.charging_status| -+-----------------------------+-----------+-----------------------+ -|1970-01-01T08:00:00.001+08:00| 14.0| 1| -|1970-01-01T08:00:00.002+08:00| 16.0| 1| -|1970-01-01T08:00:00.003+08:00| 16.0| 0| -|1970-01-01T08:00:00.004+08:00| 16.0| 0| -|1970-01-01T08:00:00.005+08:00| 18.0| 1| -|1970-01-01T08:00:00.006+08:00| 24.0| 1| -|1970-01-01T08:00:00.007+08:00| 36.0| 1| -|1970-01-01T08:00:00.008+08:00| 36.0| null| -|1970-01-01T08:00:00.009+08:00| 45.0| 1| -|1970-01-01T08:00:00.010+08:00| 60.0| 1| -+-----------------------------+-----------+-----------------------+ -``` -sql语句如下 -```sql -select count(charging_stauts), first_value(soc) from root.sg group by count(charging_status,5) -``` -得到如下结果,其中由于第二个1970-01-01T08:00:00.006+08:00到1970-01-01T08:00:00.010+08:00的窗口中包含四个点,不符合`size = 5`的条件,因此不被输出 -``` -+-----------------------------+-----------------------------+--------------------------------------+ -| Time| __endTime|first_value(root.sg.beijing.car01.soc)| -+-----------------------------+-----------------------------+--------------------------------------+ -|1970-01-01T08:00:00.001+08:00|1970-01-01T08:00:00.005+08:00| 14.0| -+-----------------------------+-----------------------------+--------------------------------------+ -``` -而当使用ignoreNull将null值也考虑进来时,可以得到两个点计数为5的窗口,sql如下 -```sql -select count(charging_stauts), first_value(soc) from root.sg group by count(charging_status,5,ignoreNull=false) -``` -得到如下结果 -``` -+-----------------------------+-----------------------------+--------------------------------------+ -| Time| __endTime|first_value(root.sg.beijing.car01.soc)| -+-----------------------------+-----------------------------+--------------------------------------+ -|1970-01-01T08:00:00.001+08:00|1970-01-01T08:00:00.005+08:00| 14.0| -|1970-01-01T08:00:00.006+08:00|1970-01-01T08:00:00.010+08:00| 24.0| -+-----------------------------+-----------------------------+--------------------------------------+ -``` -### 分组聚合 - -#### 路径层级分组聚合 - -在时间序列层级结构中,路径层级分组聚合查询用于**对某一层级下同名的序列进行聚合查询**。 - -- 使用 `GROUP BY LEVEL = INT` 来指定需要聚合的层级,并约定 `ROOT` 为第 0 层。若统计 "root.ln" 下所有序列则需指定 level 为 1。 -- 路径层次分组聚合查询支持使用所有内置聚合函数。对于 `sum`,`avg`,`min_value`, `max_value`, `extreme` 五种聚合函数,需保证所有聚合的时间序列数据类型相同。其他聚合函数没有此限制。 - -**示例1:** 不同 database 下均存在名为 status 的序列, 如 "root.ln.wf01.wt01.status", "root.ln.wf02.wt02.status", 以及 "root.sgcc.wf03.wt01.status", 如果需要统计不同 database 下 status 序列的数据点个数,使用以下查询: - -```sql -select count(status) from root.** group by level = 1 -``` - -运行结果为: - -``` -+-------------------------+---------------------------+ -|count(root.ln.*.*.status)|count(root.sgcc.*.*.status)| -+-------------------------+---------------------------+ -| 20160| 10080| -+-------------------------+---------------------------+ -Total line number = 1 -It costs 0.003s -``` - -**示例2:** 统计不同设备下 status 序列的数据点个数,可以规定 level = 3, - -```sql -select count(status) from root.** group by level = 3 -``` - -运行结果为: - -``` -+---------------------------+---------------------------+ -|count(root.*.*.wt01.status)|count(root.*.*.wt02.status)| -+---------------------------+---------------------------+ -| 20160| 10080| -+---------------------------+---------------------------+ -Total line number = 1 -It costs 0.003s -``` - -注意,这时会将 database `ln` 和 `sgcc` 下名为 `wt01` 的设备视为同名设备聚合在一起。 - -**示例3:** 统计不同 database 下的不同设备中 status 序列的数据点个数,可以使用以下查询: - -```sql -select count(status) from root.** group by level = 1, 3 -``` - -运行结果为: - -``` -+----------------------------+----------------------------+------------------------------+ -|count(root.ln.*.wt01.status)|count(root.ln.*.wt02.status)|count(root.sgcc.*.wt01.status)| -+----------------------------+----------------------------+------------------------------+ -| 10080| 10080| 10080| -+----------------------------+----------------------------+------------------------------+ -Total line number = 1 -It costs 0.003s -``` - -**示例4:** 查询所有序列下温度传感器 temperature 的最大值,可以使用下列查询语句: - -```sql -select max_value(temperature) from root.** group by level = 0 -``` - -运行结果: - -``` -+---------------------------------+ -|max_value(root.*.*.*.temperature)| -+---------------------------------+ -| 26.0| -+---------------------------------+ -Total line number = 1 -It costs 0.013s -``` - -**示例5:** 上面的查询都是针对某一个传感器,特别地,**如果想要查询某一层级下所有传感器拥有的总数据点数,则需要显式规定测点为 `*`** - -```sql -select count(*) from root.ln.** group by level = 2 -``` - -运行结果: - -``` -+----------------------+----------------------+ -|count(root.*.wf01.*.*)|count(root.*.wf02.*.*)| -+----------------------+----------------------+ -| 20160| 20160| -+----------------------+----------------------+ -Total line number = 1 -It costs 0.013s -``` - -##### 与时间区间分段聚合混合使用 - -通过定义 LEVEL 来统计指定层级下的数据点个数。 - -例如: - -统计降采样后的数据点个数 - -```sql -select count(status) from root.ln.wf01.wt01 group by ((2017-11-01T00:00:00, 2017-11-07T23:00:00],1d), level=1; -``` - -结果: - -``` -+-----------------------------+-------------------------+ -| Time|COUNT(root.ln.*.*.status)| -+-----------------------------+-------------------------+ -|2017-11-02T00:00:00.000+08:00| 1440| -|2017-11-03T00:00:00.000+08:00| 1440| -|2017-11-04T00:00:00.000+08:00| 1440| -|2017-11-05T00:00:00.000+08:00| 1440| -|2017-11-06T00:00:00.000+08:00| 1440| -|2017-11-07T00:00:00.000+08:00| 1440| -|2017-11-07T23:00:00.000+08:00| 1380| -+-----------------------------+-------------------------+ -Total line number = 7 -It costs 0.006s -``` - -加上滑动 Step 的降采样后的结果也可以汇总 - -```sql -select count(status) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017-11-07 23:00:00), 3h, 1d), level=1; -``` - -``` -+-----------------------------+-------------------------+ -| Time|COUNT(root.ln.*.*.status)| -+-----------------------------+-------------------------+ -|2017-11-01T00:00:00.000+08:00| 180| -|2017-11-02T00:00:00.000+08:00| 180| -|2017-11-03T00:00:00.000+08:00| 180| -|2017-11-04T00:00:00.000+08:00| 180| -|2017-11-05T00:00:00.000+08:00| 180| -|2017-11-06T00:00:00.000+08:00| 180| -|2017-11-07T00:00:00.000+08:00| 180| -+-----------------------------+-------------------------+ -Total line number = 7 -It costs 0.004s -``` - -#### 标签分组聚合 - -IoTDB 支持通过 `GROUP BY TAGS` 语句根据时间序列中定义的标签的键值做分组聚合查询。 - -我们先在 IoTDB 中写入如下示例数据,稍后会以这些数据为例介绍标签聚合查询。 - -这些是某工厂 `factory1` 在多个城市的多个车间的设备温度数据, 时间范围为 [1000, 10000)。 - -时间序列路径中的设备一级是设备唯一标识。城市信息 `city` 和车间信息 `workshop` 则被建模在该设备时间序列的标签中。 -其中,设备 `d1`、`d2` 在 `Beijing` 的 `w1` 车间, `d3`、`d4` 在 `Beijing` 的 `w2` 车间,`d5`、`d6` 在 `Shanghai` 的 `w1` 车间,`d7` 在 `Shanghai` 的 `w2` 车间。 -`d8` 和 `d9` 设备目前处于调试阶段,还未被分配到具体的城市和车间,所以其相应的标签值为空值。 - -```SQL -create database root.factory1; -create timeseries root.factory1.d1.temperature with datatype=FLOAT tags(city=Beijing, workshop=w1); -create timeseries root.factory1.d2.temperature with datatype=FLOAT tags(city=Beijing, workshop=w1); -create timeseries root.factory1.d3.temperature with datatype=FLOAT tags(city=Beijing, workshop=w2); -create timeseries root.factory1.d4.temperature with datatype=FLOAT tags(city=Beijing, workshop=w2); -create timeseries root.factory1.d5.temperature with datatype=FLOAT tags(city=Shanghai, workshop=w1); -create timeseries root.factory1.d6.temperature with datatype=FLOAT tags(city=Shanghai, workshop=w1); -create timeseries root.factory1.d7.temperature with datatype=FLOAT tags(city=Shanghai, workshop=w2); -create timeseries root.factory1.d8.temperature with datatype=FLOAT; -create timeseries root.factory1.d9.temperature with datatype=FLOAT; - -insert into root.factory1.d1(time, temperature) values(1000, 104.0); -insert into root.factory1.d1(time, temperature) values(3000, 104.2); -insert into root.factory1.d1(time, temperature) values(5000, 103.3); -insert into root.factory1.d1(time, temperature) values(7000, 104.1); - -insert into root.factory1.d2(time, temperature) values(1000, 104.4); -insert into root.factory1.d2(time, temperature) values(3000, 103.7); -insert into root.factory1.d2(time, temperature) values(5000, 103.3); -insert into root.factory1.d2(time, temperature) values(7000, 102.9); - -insert into root.factory1.d3(time, temperature) values(1000, 103.9); -insert into root.factory1.d3(time, temperature) values(3000, 103.8); -insert into root.factory1.d3(time, temperature) values(5000, 102.7); -insert into root.factory1.d3(time, temperature) values(7000, 106.9); - -insert into root.factory1.d4(time, temperature) values(1000, 103.9); -insert into root.factory1.d4(time, temperature) values(5000, 102.7); -insert into root.factory1.d4(time, temperature) values(7000, 106.9); - -insert into root.factory1.d5(time, temperature) values(1000, 112.9); -insert into root.factory1.d5(time, temperature) values(7000, 113.0); - -insert into root.factory1.d6(time, temperature) values(1000, 113.9); -insert into root.factory1.d6(time, temperature) values(3000, 113.3); -insert into root.factory1.d6(time, temperature) values(5000, 112.7); -insert into root.factory1.d6(time, temperature) values(7000, 112.3); - -insert into root.factory1.d7(time, temperature) values(1000, 101.2); -insert into root.factory1.d7(time, temperature) values(3000, 99.3); -insert into root.factory1.d7(time, temperature) values(5000, 100.1); -insert into root.factory1.d7(time, temperature) values(7000, 99.8); - -insert into root.factory1.d8(time, temperature) values(1000, 50.0); -insert into root.factory1.d8(time, temperature) values(3000, 52.1); -insert into root.factory1.d8(time, temperature) values(5000, 50.1); -insert into root.factory1.d8(time, temperature) values(7000, 50.5); - -insert into root.factory1.d9(time, temperature) values(1000, 50.3); -insert into root.factory1.d9(time, temperature) values(3000, 52.1); -``` - -##### 单标签聚合查询 - -用户想统计该工厂每个地区的设备的温度的平均值,可以使用如下查询语句 - -```SQL -SELECT AVG(temperature) FROM root.factory1.** GROUP BY TAGS(city); -``` - -该查询会将具有同一个 `city` 标签值的时间序列的所有满足查询条件的点做平均值计算,计算结果如下 - -``` -+--------+------------------+ -| city| avg(temperature)| -+--------+------------------+ -| Beijing|104.04666697184244| -|Shanghai|107.85000076293946| -| NULL| 50.84999910990397| -+--------+------------------+ -Total line number = 3 -It costs 0.231s -``` - -从结果集中可以看到,和分段聚合、按层次分组聚合相比,标签聚合的查询结果的不同点是: -1. 标签聚合查询的聚合结果不会再做去星号展开,而是将多个时间序列的数据作为一个整体进行聚合计算。 -2. 标签聚合查询除了输出聚合结果列,还会输出聚合标签的键值列。该列的列名为聚合指定的标签键,列的值则为所有查询的时间序列中出现的该标签的值。 -如果某些时间序列未设置该标签,则在键值列中有一行单独的 `NULL` ,代表未设置标签的所有时间序列数据的聚合结果。 - -##### 多标签分组聚合查询 - -除了基本的单标签聚合查询外,还可以按顺序指定多个标签进行聚合计算。 - -例如,用户想统计每个城市的每个车间内设备的平均温度。但因为各个城市的车间名称有可能相同,所以不能直接按照 `workshop` 做标签聚合。必须要先按照城市,再按照车间处理。 - -SQL 语句如下 - -```SQL -SELECT avg(temperature) FROM root.factory1.** GROUP BY TAGS(city, workshop); -``` - -查询结果如下 - -``` -+--------+--------+------------------+ -| city|workshop| avg(temperature)| -+--------+--------+------------------+ -| NULL| NULL| 50.84999910990397| -|Shanghai| w1|113.01666768391927| -| Beijing| w2| 104.4000004359654| -|Shanghai| w2|100.10000038146973| -| Beijing| w1|103.73750019073486| -+--------+--------+------------------+ -Total line number = 5 -It costs 0.027s -``` - -从结果集中可以看到,和单标签聚合相比,多标签聚合的查询结果会根据指定的标签顺序,输出相应标签的键值列。 - -##### 基于时间区间的标签聚合查询 - -按照时间区间聚合是时序数据库中最常用的查询需求之一。IoTDB 在基于时间区间的聚合基础上,支持进一步按照标签进行聚合查询。 - -例如,用户想统计时间 `[1000, 10000)` 范围内,每个城市每个车间中的设备每 5 秒内的平均温度。 - -SQL 语句如下 - -```SQL -SELECT AVG(temperature) FROM root.factory1.** GROUP BY ([1000, 10000), 5s), TAGS(city, workshop); -``` - -查询结果如下 - -``` -+-----------------------------+--------+--------+------------------+ -| Time| city|workshop| avg(temperature)| -+-----------------------------+--------+--------+------------------+ -|1970-01-01T08:00:01.000+08:00| NULL| NULL| 50.91999893188476| -|1970-01-01T08:00:01.000+08:00|Shanghai| w1|113.20000076293945| -|1970-01-01T08:00:01.000+08:00| Beijing| w2| 103.4| -|1970-01-01T08:00:01.000+08:00|Shanghai| w2| 100.1999994913737| -|1970-01-01T08:00:01.000+08:00| Beijing| w1|103.81666692097981| -|1970-01-01T08:00:06.000+08:00| NULL| NULL| 50.5| -|1970-01-01T08:00:06.000+08:00|Shanghai| w1| 112.6500015258789| -|1970-01-01T08:00:06.000+08:00| Beijing| w2| 106.9000015258789| -|1970-01-01T08:00:06.000+08:00|Shanghai| w2| 99.80000305175781| -|1970-01-01T08:00:06.000+08:00| Beijing| w1| 103.5| -+-----------------------------+--------+--------+------------------+ -``` - -和标签聚合相比,基于时间区间的标签聚合的查询会首先按照时间区间划定聚合范围,在时间区间内部再根据指定的标签顺序,进行相应数据的聚合计算。在输出的结果集中,会包含一列时间列,该时间列值的含义和时间区间聚合查询的相同。 - -##### 标签分组聚合的限制 - -由于标签聚合功能仍然处于开发阶段,目前有如下未实现功能。 - -> 1. 暂不支持 `HAVING` 子句过滤查询结果。 -> 2. 暂不支持结果按照标签值排序。 -> 3. 暂不支持 `LIMIT`,`OFFSET`,`SLIMIT`,`SOFFSET`。 -> 4. 暂不支持 `ALIGN BY DEVICE`。 -> 5. 暂不支持聚合函数内部包含表达式,例如 `count(s+1)`。 -> 6. 不支持值过滤条件聚合,和分层聚合查询行为保持一致。 - -## 聚合结果过滤(HAVING 子句) - -如果想对聚合查询的结果进行过滤,可以在 `GROUP BY` 子句之后使用 `HAVING` 子句。 - -**注意:** - -1. `HAVING`子句中的过滤条件必须由聚合值构成,原始序列不能单独出现。 - - 下列使用方式是不正确的: - ```sql - select count(s1) from root.** group by ([1,3),1ms) having sum(s1) > s1 - select count(s1) from root.** group by ([1,3),1ms) having s1 > 1 - ``` - -2. 对`GROUP BY LEVEL`结果进行过滤时,`SELECT`和`HAVING`中出现的PATH只能有一级。 - - 下列使用方式是不正确的: - ```sql - select count(s1) from root.** group by ([1,3),1ms), level=1 having sum(d1.s1) > 1 - select count(d1.s1) from root.** group by ([1,3),1ms), level=1 having sum(s1) > 1 - ``` - -**SQL 示例:** - -- **示例 1:** - - 对于以下聚合结果进行过滤: - - ``` - +-----------------------------+---------------------+---------------------+ - | Time|count(root.test.*.s1)|count(root.test.*.s2)| - +-----------------------------+---------------------+---------------------+ - |1970-01-01T08:00:00.001+08:00| 4| 4| - |1970-01-01T08:00:00.003+08:00| 1| 0| - |1970-01-01T08:00:00.005+08:00| 2| 4| - |1970-01-01T08:00:00.007+08:00| 3| 2| - |1970-01-01T08:00:00.009+08:00| 4| 4| - +-----------------------------+---------------------+---------------------+ - ``` - - ```sql - select count(s1) from root.** group by ([1,11),2ms), level=1 having count(s2) > 2; - ``` - - 执行结果如下: - - ``` - +-----------------------------+---------------------+ - | Time|count(root.test.*.s1)| - +-----------------------------+---------------------+ - |1970-01-01T08:00:00.001+08:00| 4| - |1970-01-01T08:00:00.005+08:00| 2| - |1970-01-01T08:00:00.009+08:00| 4| - +-----------------------------+---------------------+ - ``` - -- **示例 2:** - - 对于以下聚合结果进行过滤: - ``` - +-----------------------------+-------------+---------+---------+ - | Time| Device|count(s1)|count(s2)| - +-----------------------------+-------------+---------+---------+ - |1970-01-01T08:00:00.001+08:00|root.test.sg1| 1| 2| - |1970-01-01T08:00:00.003+08:00|root.test.sg1| 1| 0| - |1970-01-01T08:00:00.005+08:00|root.test.sg1| 1| 2| - |1970-01-01T08:00:00.007+08:00|root.test.sg1| 2| 1| - |1970-01-01T08:00:00.009+08:00|root.test.sg1| 2| 2| - |1970-01-01T08:00:00.001+08:00|root.test.sg2| 2| 2| - |1970-01-01T08:00:00.003+08:00|root.test.sg2| 0| 0| - |1970-01-01T08:00:00.005+08:00|root.test.sg2| 1| 2| - |1970-01-01T08:00:00.007+08:00|root.test.sg2| 1| 1| - |1970-01-01T08:00:00.009+08:00|root.test.sg2| 2| 2| - +-----------------------------+-------------+---------+---------+ - ``` - - ```sql - select count(s1), count(s2) from root.** group by ([1,11),2ms) having count(s2) > 1 align by device; - ``` - - 执行结果如下: - - ``` - +-----------------------------+-------------+---------+---------+ - | Time| Device|count(s1)|count(s2)| - +-----------------------------+-------------+---------+---------+ - |1970-01-01T08:00:00.001+08:00|root.test.sg1| 1| 2| - |1970-01-01T08:00:00.005+08:00|root.test.sg1| 1| 2| - |1970-01-01T08:00:00.009+08:00|root.test.sg1| 2| 2| - |1970-01-01T08:00:00.001+08:00|root.test.sg2| 2| 2| - |1970-01-01T08:00:00.005+08:00|root.test.sg2| 1| 2| - |1970-01-01T08:00:00.009+08:00|root.test.sg2| 2| 2| - +-----------------------------+-------------+---------+---------+ - ``` - - -## 结果集补空值(FILL 子句) - -### 功能介绍 - -当执行一些数据查询时,结果集的某行某列可能没有数据,则此位置结果为空,但这种空值不利于进行数据可视化展示和分析,需要对空值进行填充。 - -在 IoTDB 中,用户可以使用 `FILL` 子句指定数据缺失情况下的填充模式,允许用户按照特定的方法对任何查询的结果集填充空值,如取前一个不为空的值、线性插值等。 - -### 语法定义 - -**`FILL` 子句的语法定义如下:** - -```sql -FILL '(' PREVIOUS | LINEAR | constant ')' -``` - -**注意:** -- 在 `Fill` 语句中只能指定一种填充方法,该方法作用于结果集的全部列。 -- 空值填充不兼容 0.13 版本及以前的语法(即不支持 `FILL(([(, , )?])+)`) - -### 填充方式 - -**IoTDB 目前支持以下三种空值填充方式:** - -- `PREVIOUS` 填充:使用该列前一个非空值进行填充。 -- `LINEAR` 填充:使用该列前一个非空值和下一个非空值的线性插值进行填充。 -- 常量填充:使用指定常量填充。 - -**各数据类型支持的填充方法如下表所示:** - -| 数据类型 | 支持的填充方法 | -| :------- |:------------------------| -| BOOLEAN | `PREVIOUS`、常量 | -| INT32 | `PREVIOUS`、`LINEAR`、常量 | -| INT64 | `PREVIOUS`、`LINEAR`、常量 | -| FLOAT | `PREVIOUS`、`LINEAR`、常量 | -| DOUBLE | `PREVIOUS`、`LINEAR`、常量 | -| TEXT | `PREVIOUS`、常量 | - -**注意:** 对于数据类型不支持指定填充方法的列,既不会填充它,也不会报错,只是让那一列保持原样。 - -**下面通过举例进一步说明。** - -如果我们不使用任何填充方式: - -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000; -``` - -查询结果如下: - -``` -+-----------------------------+-------------------------------+--------------------------+ -| Time|root.sgcc.wf03.wt01.temperature|root.sgcc.wf03.wt01.status| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:37:00.000+08:00| 21.93| true| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:38:00.000+08:00| null| false| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:39:00.000+08:00| 22.23| null| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:40:00.000+08:00| 23.43| null| -+-----------------------------+-------------------------------+--------------------------+ -Total line number = 4 -``` - -#### `PREVIOUS` 填充 - -**对于查询结果集中的空值,使用该列前一个非空值进行填充。** - -**注意:** 如果结果集的某一列第一个值就为空,则不会填充该值,直到遇到该列第一个非空值为止。 - -例如,使用 `PREVIOUS` 填充,SQL 语句如下: - -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(previous); -``` - -`PREVIOUS` 填充后的结果如下: - -``` -+-----------------------------+-------------------------------+--------------------------+ -| Time|root.sgcc.wf03.wt01.temperature|root.sgcc.wf03.wt01.status| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:37:00.000+08:00| 21.93| true| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:38:00.000+08:00| 21.93| false| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:39:00.000+08:00| 22.23| false| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:40:00.000+08:00| 23.43| false| -+-----------------------------+-------------------------------+--------------------------+ -Total line number = 4 -``` - -**在前值填充时,能够支持指定一个时间间隔,如果当前null值的时间戳与前一个非null值的时间戳的间隔,超过指定的时间间隔,则不进行填充。** - -> 1. 在线性填充和常量填充的情况下,如果指定了第二个参数,会抛出异常 -> 2. 时间超时参数仅支持整数 - 例如,原始数据如下所示: - -```sql -select s1 from root.db.d1 -``` -``` -+-----------------------------+-------------+ -| Time|root.db.d1.s1| -+-----------------------------+-------------+ -|2023-11-08T16:41:50.008+08:00| 1.0| -+-----------------------------+-------------+ -|2023-11-08T16:46:50.011+08:00| 2.0| -+-----------------------------+-------------+ -|2023-11-08T16:48:50.011+08:00| 3.0| -+-----------------------------+-------------+ -``` - -根据时间分组,每1分钟求一个平均值 - -```sql -select avg(s1) - from root.db.d1 - group by([2023-11-08T16:40:00.008+08:00, 2023-11-08T16:50:00.008+08:00), 1m) -``` -``` -+-----------------------------+------------------+ -| Time|avg(root.db.d1.s1)| -+-----------------------------+------------------+ -|2023-11-08T16:40:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:41:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:42:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:43:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:44:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:45:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:46:00.008+08:00| 2.0| -+-----------------------------+------------------+ -|2023-11-08T16:47:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:48:00.008+08:00| 3.0| -+-----------------------------+------------------+ -|2023-11-08T16:49:00.008+08:00| null| -+-----------------------------+------------------+ -``` - -根据时间分组并用前值填充 - -```sql -select avg(s1) - from root.db.d1 - group by([2023-11-08T16:40:00.008+08:00, 2023-11-08T16:50:00.008+08:00), 1m) - FILL(PREVIOUS); -``` -``` -+-----------------------------+------------------+ -| Time|avg(root.db.d1.s1)| -+-----------------------------+------------------+ -|2023-11-08T16:40:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:41:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:42:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:43:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:44:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:45:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:46:00.008+08:00| 2.0| -+-----------------------------+------------------+ -|2023-11-08T16:47:00.008+08:00| 2.0| -+-----------------------------+------------------+ -|2023-11-08T16:48:00.008+08:00| 3.0| -+-----------------------------+------------------+ -|2023-11-08T16:49:00.008+08:00| 3.0| -+-----------------------------+------------------+ -``` - -根据时间分组并用前值填充,并指定超过2分钟的就不填充 - -```sql -select avg(s1) -from root.db.d1 -group by([2023-11-08T16:40:00.008+08:00, 2023-11-08T16:50:00.008+08:00), 1m) - FILL(PREVIOUS, 2m); -``` -``` -+-----------------------------+------------------+ -| Time|avg(root.db.d1.s1)| -+-----------------------------+------------------+ -|2023-11-08T16:40:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:41:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:42:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:43:00.008+08:00| 1.0| -+-----------------------------+------------------+ -|2023-11-08T16:44:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:45:00.008+08:00| null| -+-----------------------------+------------------+ -|2023-11-08T16:46:00.008+08:00| 2.0| -+-----------------------------+------------------+ -|2023-11-08T16:47:00.008+08:00| 2.0| -+-----------------------------+------------------+ -|2023-11-08T16:48:00.008+08:00| 3.0| -+-----------------------------+------------------+ -|2023-11-08T16:49:00.008+08:00| 3.0| -+-----------------------------+------------------+ -``` - - -#### `LINEAR` 填充 - -**对于查询结果集中的空值,使用该列前一个非空值和下一个非空值的线性插值进行填充。** - -**注意:** -- 如果某个值之前的所有值都为空,或者某个值之后的所有值都为空,则不会填充该值。 -- 如果某列的数据类型为boolean/text,我们既不会填充它,也不会报错,只是让那一列保持原样。 - -例如,使用 `LINEAR` 填充,SQL 语句如下: - -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(linear); -``` - -`LINEAR` 填充后的结果如下: - -``` -+-----------------------------+-------------------------------+--------------------------+ -| Time|root.sgcc.wf03.wt01.temperature|root.sgcc.wf03.wt01.status| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:37:00.000+08:00| 21.93| true| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:38:00.000+08:00| 22.08| false| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:39:00.000+08:00| 22.23| null| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:40:00.000+08:00| 23.43| null| -+-----------------------------+-------------------------------+--------------------------+ -Total line number = 4 -``` - -#### 常量填充 - -**对于查询结果集中的空值,使用指定常量填充。** - -**注意:** -- 如果某列数据类型与常量类型不兼容,既不填充该列,也不报错,将该列保持原样。对于常量兼容的数据类型,如下表所示: - - | 常量类型 | 能够填充的序列数据类型 | - |:------ |:------------------ | - | `BOOLEAN` | `BOOLEAN` `TEXT` | - | `INT64` | `INT32` `INT64` `FLOAT` `DOUBLE` `TEXT` | - | `DOUBLE` | `FLOAT` `DOUBLE` `TEXT` | - | `TEXT` | `TEXT` | -- 当常量值大于 `INT32` 所能表示的最大值时,对于 `INT32` 类型的列,既不填充该列,也不报错,将该列保持原样。 - -例如,使用 `FLOAT` 类型的常量填充,SQL 语句如下: - -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(2.0); -``` - -`FLOAT` 类型的常量填充后的结果如下: - -``` -+-----------------------------+-------------------------------+--------------------------+ -| Time|root.sgcc.wf03.wt01.temperature|root.sgcc.wf03.wt01.status| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:37:00.000+08:00| 21.93| true| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:38:00.000+08:00| 2.0| false| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:39:00.000+08:00| 22.23| null| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:40:00.000+08:00| 23.43| null| -+-----------------------------+-------------------------------+--------------------------+ -Total line number = 4 -``` - -再比如,使用 `BOOLEAN` 类型的常量填充,SQL 语句如下: - -```sql -select temperature, status from root.sgcc.wf03.wt01 where time >= 2017-11-01T16:37:00.000 and time <= 2017-11-01T16:40:00.000 fill(true); -``` - -`BOOLEAN` 类型的常量填充后的结果如下: - -``` -+-----------------------------+-------------------------------+--------------------------+ -| Time|root.sgcc.wf03.wt01.temperature|root.sgcc.wf03.wt01.status| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:37:00.000+08:00| 21.93| true| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:38:00.000+08:00| null| false| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:39:00.000+08:00| 22.23| true| -+-----------------------------+-------------------------------+--------------------------+ -|2017-11-01T16:40:00.000+08:00| 23.43| true| -+-----------------------------+-------------------------------+--------------------------+ -Total line number = 4 -``` - - -## 查询结果分页(LIMIT/SLIMIT 子句) - -当查询结果集数据量很大,放在一个页面不利于显示,可以使用 `LIMIT/SLIMIT` 子句和 `OFFSET/SOFFSET `子句进行分页控制。 - -- `LIMIT` 和 `SLIMIT` 子句用于控制查询结果的行数和列数。 -- `OFFSET` 和 `SOFFSET` 子句用于控制结果显示的起始位置。 - -### 按行分页 - -用户可以通过 `LIMIT` 和 `OFFSET` 子句控制查询结果的行数,`LIMIT rowLimit` 指定查询结果的行数,`OFFSET rowOffset` 指定查询结果显示的起始行位置。 - -注意: -- 当 `rowOffset` 超过结果集的大小时,返回空结果集。 -- 当 `rowLimit` 超过结果集的大小时,返回所有查询结果。 -- 当 `rowLimit` 和 `rowOffset` 不是正整数,或超过 `INT64` 允许的最大值时,系统将提示错误。 - -我们将通过以下示例演示如何使用 `LIMIT` 和 `OFFSET` 子句。 - -- **示例 1:** 基本的 `LIMIT` 子句 - -SQL 语句: - -```sql -select status, temperature from root.ln.wf01.wt01 limit 10 -``` - -含义: - -所选设备为 ln 组 wf01 工厂 wt01 设备; 选择的时间序列是“状态”和“温度”。 SQL 语句要求返回查询结果的前 10 行。 - -结果如下所示: - -``` -+-----------------------------+------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.status|root.ln.wf01.wt01.temperature| -+-----------------------------+------------------------+-----------------------------+ -|2017-11-01T00:00:00.000+08:00| true| 25.96| -|2017-11-01T00:01:00.000+08:00| true| 24.36| -|2017-11-01T00:02:00.000+08:00| false| 20.09| -|2017-11-01T00:03:00.000+08:00| false| 20.18| -|2017-11-01T00:04:00.000+08:00| false| 21.13| -|2017-11-01T00:05:00.000+08:00| false| 22.72| -|2017-11-01T00:06:00.000+08:00| false| 20.71| -|2017-11-01T00:07:00.000+08:00| false| 21.45| -|2017-11-01T00:08:00.000+08:00| false| 22.58| -|2017-11-01T00:09:00.000+08:00| false| 20.98| -+-----------------------------+------------------------+-----------------------------+ -Total line number = 10 -It costs 0.000s -``` - -- **示例 2:** 带 `OFFSET` 的 `LIMIT` 子句 - -SQL 语句: - -```sql -select status, temperature from root.ln.wf01.wt01 limit 5 offset 3 -``` - -含义: - -所选设备为 ln 组 wf01 工厂 wt01 设备; 选择的时间序列是“状态”和“温度”。 SQL 语句要求返回查询结果的第 3 至 7 行(第一行编号为 0 行)。 - -结果如下所示: - -``` -+-----------------------------+------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.status|root.ln.wf01.wt01.temperature| -+-----------------------------+------------------------+-----------------------------+ -|2017-11-01T00:03:00.000+08:00| false| 20.18| -|2017-11-01T00:04:00.000+08:00| false| 21.13| -|2017-11-01T00:05:00.000+08:00| false| 22.72| -|2017-11-01T00:06:00.000+08:00| false| 20.71| -|2017-11-01T00:07:00.000+08:00| false| 21.45| -+-----------------------------+------------------------+-----------------------------+ -Total line number = 5 -It costs 0.342s -``` - -- **示例 3:** `LIMIT` 子句与 `WHERE` 子句结合 - -SQL 语句: - -```sql -select status,temperature from root.ln.wf01.wt01 where time > 2024-07-07T00:05:00.000 and time< 2024-07-12T00:12:00.000 limit 5 offset 3 -``` - -含义: - -所选设备为 ln 组 wf01 工厂 wt01 设备;选择的时间序列为“状态”和“温度”。 SQL 要求返回时间“ 2024-07-07T00:05:00.000”和“ 2024-07-12T00:12: 00.000 ”之间的状态和温度传感器值的第3至7行(第一行编号为第0行)。 - -结果如下所示: - -``` -+-----------------------------+------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.status|root.ln.wf01.wt01.temperature| -+-----------------------------+------------------------+-----------------------------+ -|2024-07-09T17:32:11.943+08:00| true| 24.941973| -|2024-07-09T17:32:12.944+08:00| true| 20.05108| -|2024-07-09T17:32:13.945+08:00| true| 20.541632| -|2024-07-09T17:32:14.945+08:00| null| 23.09016| -|2024-07-09T17:32:14.946+08:00| true| null| -+-----------------------------+------------------------+-----------------------------+ -Total line number = 5 -It costs 0.070s -``` - -- **示例 4:** `LIMIT` 子句与 `GROUP BY` 子句组合 - -SQL 语句: - -```sql -select count(status), max_value(temperature) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d) limit 4 offset 3 -``` - -含义: - -SQL 语句子句要求返回查询结果的第 3 至 6 行(第一行编号为 0 行)。 - -结果如下所示: - -``` -+-----------------------------+-------------------------------+----------------------------------------+ -| Time|count(root.ln.wf01.wt01.status)|max_value(root.ln.wf01.wt01.temperature)| -+-----------------------------+-------------------------------+----------------------------------------+ -|2017-11-04T00:00:00.000+08:00| 1440| 26.0| -|2017-11-05T00:00:00.000+08:00| 1440| 26.0| -|2017-11-06T00:00:00.000+08:00| 1440| 25.99| -|2017-11-07T00:00:00.000+08:00| 1380| 26.0| -+-----------------------------+-------------------------------+----------------------------------------+ -Total line number = 4 -It costs 0.016s -``` - -### 按列分页 - -用户可以通过 `SLIMIT` 和 `SOFFSET` 子句控制查询结果的列数,`SLIMIT seriesLimit` 指定查询结果的列数,`SOFFSET seriesOffset` 指定查询结果显示的起始列位置。 - -注意: -- 仅用于控制值列,对时间列和设备列无效。 -- 当 `seriesOffset` 超过结果集的大小时,返回空结果集。 -- 当 `seriesLimit` 超过结果集的大小时,返回所有查询结果。 -- 当 `seriesLimit` 和 `seriesOffset` 不是正整数,或超过 `INT64` 允许的最大值时,系统将提示错误。 - -我们将通过以下示例演示如何使用 `SLIMIT` 和 `SOFFSET` 子句。 - -- **示例 1:** 基本的 `SLIMIT` 子句 - -SQL 语句: - -```sql -select * from root.ln.wf01.wt01 where time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000 slimit 1 -``` - -含义: - -所选设备为 ln 组 wf01 工厂 wt01 设备; 所选时间序列是该设备下的第二列,即温度。 SQL 语句要求在"2017-11-01T00:05:00.000"和"2017-11-01T00:12:00.000"的时间点之间选择温度传感器值。 - -结果如下所示: - -``` -+-----------------------------+-----------------------------+ -| Time|root.ln.wf01.wt01.temperature| -+-----------------------------+-----------------------------+ -|2017-11-01T00:06:00.000+08:00| 20.71| -|2017-11-01T00:07:00.000+08:00| 21.45| -|2017-11-01T00:08:00.000+08:00| 22.58| -|2017-11-01T00:09:00.000+08:00| 20.98| -|2017-11-01T00:10:00.000+08:00| 25.52| -|2017-11-01T00:11:00.000+08:00| 22.91| -+-----------------------------+-----------------------------+ -Total line number = 6 -It costs 0.000s -``` - -- **示例 2:** 带 `SOFFSET` 的 `SLIMIT` 子句 - -SQL 语句: - -```sql -select * from root.ln.wf01.wt01 where time > 2017-11-01T00:05:00.000 and time < 2017-11-01T00:12:00.000 slimit 1 soffset 1 -``` - -含义: - -所选设备为 ln 组 wf01 工厂 wt01 设备; 所选时间序列是该设备下的第一列,即电源状态。 SQL 语句要求在" 2017-11-01T00:05:00.000"和"2017-11-01T00:12:00.000"的时间点之间选择状态传感器值。 - -结果如下所示: - -``` -+-----------------------------+------------------------+ -| Time|root.ln.wf01.wt01.status| -+-----------------------------+------------------------+ -|2017-11-01T00:06:00.000+08:00| false| -|2017-11-01T00:07:00.000+08:00| false| -|2017-11-01T00:08:00.000+08:00| false| -|2017-11-01T00:09:00.000+08:00| false| -|2017-11-01T00:10:00.000+08:00| true| -|2017-11-01T00:11:00.000+08:00| false| -+-----------------------------+------------------------+ -Total line number = 6 -It costs 0.003s -``` - -- **示例 3:** `SLIMIT` 子句与 `GROUP BY` 子句结合 - -SQL 语句: - -```sql -select max_value(*) from root.ln.wf01.wt01 group by ([2017-11-01T00:00:00, 2017-11-07T23:00:00),1d) slimit 1 soffset 1 -``` - -含义: - -``` -+-----------------------------+-----------------------------------+ -| Time|max_value(root.ln.wf01.wt01.status)| -+-----------------------------+-----------------------------------+ -|2017-11-01T00:00:00.000+08:00| true| -|2017-11-02T00:00:00.000+08:00| true| -|2017-11-03T00:00:00.000+08:00| true| -|2017-11-04T00:00:00.000+08:00| true| -|2017-11-05T00:00:00.000+08:00| true| -|2017-11-06T00:00:00.000+08:00| true| -|2017-11-07T00:00:00.000+08:00| true| -+-----------------------------+-----------------------------------+ -Total line number = 7 -It costs 0.000s -``` - -- **示例 4:** `SLIMIT` 子句与 `LIMIT` 子句结合 - -SQL 语句: - -```sql -select * from root.ln.wf01.wt01 limit 10 offset 100 slimit 2 soffset 0 -``` - -含义: - -所选设备为 ln 组 wf01 工厂 wt01 设备; 所选时间序列是此设备下的第 0 列至第 1 列(第一列编号为第 0 列)。 SQL 语句子句要求返回查询结果的第 100 至 109 行(第一行编号为 0 行)。 - -结果如下所示: - -``` -+-----------------------------+-----------------------------+------------------------+ -| Time|root.ln.wf01.wt01.temperature|root.ln.wf01.wt01.status| -+-----------------------------+-----------------------------+------------------------+ -|2017-11-01T01:40:00.000+08:00| 21.19| false| -|2017-11-01T01:41:00.000+08:00| 22.79| false| -|2017-11-01T01:42:00.000+08:00| 22.98| false| -|2017-11-01T01:43:00.000+08:00| 21.52| false| -|2017-11-01T01:44:00.000+08:00| 23.45| true| -|2017-11-01T01:45:00.000+08:00| 24.06| true| -|2017-11-01T01:46:00.000+08:00| 22.6| false| -|2017-11-01T01:47:00.000+08:00| 23.78| true| -|2017-11-01T01:48:00.000+08:00| 24.72| true| -|2017-11-01T01:49:00.000+08:00| 24.68| true| -+-----------------------------+-----------------------------+------------------------+ -Total line number = 10 -It costs 0.009s -``` - -## 结果集排序(ORDER BY 子句) - -### 时间对齐模式下的排序 -IoTDB的查询结果集默认按照时间对齐,可以使用`ORDER BY TIME`的子句指定时间戳的排列顺序。示例代码如下: -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 order by time desc; -``` -执行结果: - -``` -+-----------------------------+--------------------------+------------------------+-----------------------------+------------------------+ -| Time|root.ln.wf02.wt02.hardware|root.ln.wf02.wt02.status|root.ln.wf01.wt01.temperature|root.ln.wf01.wt01.status| -+-----------------------------+--------------------------+------------------------+-----------------------------+------------------------+ -|2017-11-01T00:01:00.000+08:00| v2| true| 24.36| true| -|2017-11-01T00:00:00.000+08:00| v2| true| 25.96| true| -|1970-01-01T08:00:00.002+08:00| v2| false| null| null| -|1970-01-01T08:00:00.001+08:00| v1| true| null| null| -+-----------------------------+--------------------------+------------------------+-----------------------------+------------------------+ -``` -### 设备对齐模式下的排序 -当使用`ALIGN BY DEVICE`查询对齐模式下的结果集时,可以使用`ORDER BY`子句对返回的结果集顺序进行规定。 - -在设备对齐模式下支持4种排序模式的子句,其中包括两种排序键,`DEVICE`和`TIME`,靠前的排序键为主排序键,每种排序键都支持`ASC`和`DESC`两种排列顺序。 -1. ``ORDER BY DEVICE``: 按照设备名的字典序进行排序,排序方式为字典序排序,在这种情况下,相同名的设备会以组的形式进行展示。 - -2. ``ORDER BY TIME``: 按照时间戳进行排序,此时不同的设备对应的数据点会按照时间戳的优先级被打乱排序。 - -3. ``ORDER BY DEVICE,TIME``: 按照设备名的字典序进行排序,设备名相同的数据点会通过时间戳进行排序。 - -4. ``ORDER BY TIME,DEVICE``: 按照时间戳进行排序,时间戳相同的数据点会通过设备名的字典序进行排序。 - -> 为了保证结果的可观性,当不使用`ORDER BY`子句,仅使用`ALIGN BY DEVICE`时,会为设备视图提供默认的排序方式。其中默认的排序视图为``ORDER BY DEVCE,TIME``,默认的排序顺序为`ASC`, -> 即结果集默认先按照设备名升序排列,在相同设备名内再按照时间戳升序排序。 - - -当主排序键为`DEVICE`时,结果集的格式与默认情况类似:先按照设备名对结果进行排列,在相同的设备名下内按照时间戳进行排序。示例代码如下: -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 order by device desc,time asc align by device; -``` -执行结果: - -``` -+-----------------------------+-----------------+--------+------+-----------+ -| Time| Device|hardware|status|temperature| -+-----------------------------+-----------------+--------+------+-----------+ -|1970-01-01T08:00:00.001+08:00|root.ln.wf02.wt02| v1| true| null| -|1970-01-01T08:00:00.002+08:00|root.ln.wf02.wt02| v2| false| null| -|2017-11-01T00:00:00.000+08:00|root.ln.wf02.wt02| v2| true| null| -|2017-11-01T00:01:00.000+08:00|root.ln.wf02.wt02| v2| true| null| -|2017-11-01T00:00:00.000+08:00|root.ln.wf01.wt01| null| true| 25.96| -|2017-11-01T00:01:00.000+08:00|root.ln.wf01.wt01| null| true| 24.36| -+-----------------------------+-----------------+--------+------+-----------+ -``` -主排序键为`Time`时,结果集会先按照时间戳进行排序,在时间戳相等时按照设备名排序。 -示例代码如下: -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 order by time asc,device desc align by device; -``` -执行结果: -``` -+-----------------------------+-----------------+--------+------+-----------+ -| Time| Device|hardware|status|temperature| -+-----------------------------+-----------------+--------+------+-----------+ -|1970-01-01T08:00:00.001+08:00|root.ln.wf02.wt02| v1| true| null| -|1970-01-01T08:00:00.002+08:00|root.ln.wf02.wt02| v2| false| null| -|2017-11-01T00:00:00.000+08:00|root.ln.wf02.wt02| v2| true| null| -|2017-11-01T00:00:00.000+08:00|root.ln.wf01.wt01| null| true| 25.96| -|2017-11-01T00:01:00.000+08:00|root.ln.wf02.wt02| v2| true| null| -|2017-11-01T00:01:00.000+08:00|root.ln.wf01.wt01| null| true| 24.36| -+-----------------------------+-----------------+--------+------+-----------+ -``` -当没有显式指定时,主排序键默认为`Device`,排序顺序默认为`ASC`,示例代码如下: -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 align by device; -``` -结果如图所示,可以看出,`ORDER BY DEVICE ASC,TIME ASC`就是默认情况下的排序方式,由于`ASC`是默认排序顺序,此处可以省略。 -``` -+-----------------------------+-----------------+--------+------+-----------+ -| Time| Device|hardware|status|temperature| -+-----------------------------+-----------------+--------+------+-----------+ -|2017-11-01T00:00:00.000+08:00|root.ln.wf01.wt01| null| true| 25.96| -|2017-11-01T00:01:00.000+08:00|root.ln.wf01.wt01| null| true| 24.36| -|1970-01-01T08:00:00.001+08:00|root.ln.wf02.wt02| v1| true| null| -|1970-01-01T08:00:00.002+08:00|root.ln.wf02.wt02| v2| false| null| -|2017-11-01T00:00:00.000+08:00|root.ln.wf02.wt02| v2| true| null| -|2017-11-01T00:01:00.000+08:00|root.ln.wf02.wt02| v2| true| null| -+-----------------------------+-----------------+--------+------+-----------+ -``` -同样,可以在聚合查询中使用`ALIGN BY DEVICE`和`ORDER BY`子句,对聚合后的结果进行排序,示例代码如下所示: -```sql -select count(*) from root.ln.** group by ((2017-11-01T00:00:00.000+08:00,2017-11-01T00:03:00.000+08:00],1m) order by device asc,time asc align by device -``` -执行结果: -``` -+-----------------------------+-----------------+---------------+-------------+------------------+ -| Time| Device|count(hardware)|count(status)|count(temperature)| -+-----------------------------+-----------------+---------------+-------------+------------------+ -|2017-11-01T00:01:00.000+08:00|root.ln.wf01.wt01| null| 1| 1| -|2017-11-01T00:02:00.000+08:00|root.ln.wf01.wt01| null| 0| 0| -|2017-11-01T00:03:00.000+08:00|root.ln.wf01.wt01| null| 0| 0| -|2017-11-01T00:01:00.000+08:00|root.ln.wf02.wt02| 1| 1| null| -|2017-11-01T00:02:00.000+08:00|root.ln.wf02.wt02| 0| 0| null| -|2017-11-01T00:03:00.000+08:00|root.ln.wf02.wt02| 0| 0| null| -+-----------------------------+-----------------+---------------+-------------+------------------+ -``` - -### 任意表达式排序 -除了IoTDB中规定的Time,Device关键字外,还可以通过`ORDER BY`子句对指定时间序列中任意列的表达式进行排序。 - -排序在通过`ASC`,`DESC`指定排序顺序的同时,可以通过`NULLS`语法来指定NULL值在排序中的优先级,`NULLS FIRST`默认NULL值在结果集的最上方,`NULLS LAST`则保证NULL值在结果集的最后。如果没有在子句中指定,则默认顺序为`ASC`,`NULLS LAST`。 - -对于如下的数据,将给出几个任意表达式的查询示例供参考: -``` -+-----------------------------+-------------+-------+-------+--------+-------+ -| Time| Device| base| score| bonus| total| -+-----------------------------+-------------+-------+-------+--------+-------+ -|1970-01-01T08:00:00.000+08:00| root.one| 12| 50.0| 45.0| 107.0| -|1970-01-02T08:00:00.000+08:00| root.one| 10| 50.0| 45.0| 105.0| -|1970-01-03T08:00:00.000+08:00| root.one| 8| 50.0| 45.0| 103.0| -|1970-01-01T08:00:00.010+08:00| root.two| 9| 50.0| 15.0| 74.0| -|1970-01-01T08:00:00.020+08:00| root.two| 8| 10.0| 15.0| 33.0| -|1970-01-01T08:00:00.010+08:00| root.three| 9| null| 24.0| 33.0| -|1970-01-01T08:00:00.020+08:00| root.three| 8| null| 22.5| 30.5| -|1970-01-01T08:00:00.030+08:00| root.three| 7| null| 23.5| 30.5| -|1970-01-01T08:00:00.010+08:00| root.four| 9| 32.0| 45.0| 86.0| -|1970-01-01T08:00:00.020+08:00| root.four| 8| 32.0| 45.0| 85.0| -|1970-01-01T08:00:00.030+08:00| root.five| 7| 53.0| 44.0| 104.0| -|1970-01-01T08:00:00.040+08:00| root.five| 6| 54.0| 42.0| 102.0| -+-----------------------------+-------------+-------+-------+--------+-------+ -``` - -当需要根据基础分数score对结果进行排序时,可以直接使用 -```Sql -select score from root.** order by score desc align by device -``` -会得到如下结果 - -``` -+-----------------------------+---------+-----+ -| Time| Device|score| -+-----------------------------+---------+-----+ -|1970-01-01T08:00:00.040+08:00|root.five| 54.0| -|1970-01-01T08:00:00.030+08:00|root.five| 53.0| -|1970-01-01T08:00:00.000+08:00| root.one| 50.0| -|1970-01-02T08:00:00.000+08:00| root.one| 50.0| -|1970-01-03T08:00:00.000+08:00| root.one| 50.0| -|1970-01-01T08:00:00.000+08:00| root.two| 50.0| -|1970-01-01T08:00:00.010+08:00| root.two| 50.0| -|1970-01-01T08:00:00.010+08:00|root.four| 32.0| -|1970-01-01T08:00:00.020+08:00|root.four| 32.0| -|1970-01-01T08:00:00.020+08:00| root.two| 10.0| -+-----------------------------+---------+-----+ -``` - -当想要根据总分对结果进行排序,可以在order by子句中使用表达式进行计算 -```Sql -select score,total from root.one order by base+score+bonus desc -``` -该sql等价于 -```Sql -select score,total from root.one order by total desc -``` -得到如下结果 - -``` -+-----------------------------+--------------+--------------+ -| Time|root.one.score|root.one.total| -+-----------------------------+--------------+--------------+ -|1970-01-01T08:00:00.000+08:00| 50.0| 107.0| -|1970-01-02T08:00:00.000+08:00| 50.0| 105.0| -|1970-01-03T08:00:00.000+08:00| 50.0| 103.0| -+-----------------------------+--------------+--------------+ -``` -而如果要对总分进行排序,且分数相同时依次根据score, base, bonus和提交时间进行排序时,可以通过多个表达式来指定多层排序 - -```Sql -select base, score, bonus, total from root.** order by total desc NULLS Last, - score desc NULLS Last, - bonus desc NULLS Last, - time desc align by device -``` -得到如下结果 -``` -+-----------------------------+----------+----+-----+-----+-----+ -| Time| Device|base|score|bonus|total| -+-----------------------------+----------+----+-----+-----+-----+ -|1970-01-01T08:00:00.000+08:00| root.one| 12| 50.0| 45.0|107.0| -|1970-01-02T08:00:00.000+08:00| root.one| 10| 50.0| 45.0|105.0| -|1970-01-01T08:00:00.030+08:00| root.five| 7| 53.0| 44.0|104.0| -|1970-01-03T08:00:00.000+08:00| root.one| 8| 50.0| 45.0|103.0| -|1970-01-01T08:00:00.040+08:00| root.five| 6| 54.0| 42.0|102.0| -|1970-01-01T08:00:00.010+08:00| root.four| 9| 32.0| 45.0| 86.0| -|1970-01-01T08:00:00.020+08:00| root.four| 8| 32.0| 45.0| 85.0| -|1970-01-01T08:00:00.010+08:00| root.two| 9| 50.0| 15.0| 74.0| -|1970-01-01T08:00:00.000+08:00| root.two| 9| 50.0| 15.0| 74.0| -|1970-01-01T08:00:00.020+08:00| root.two| 8| 10.0| 15.0| 33.0| -|1970-01-01T08:00:00.010+08:00|root.three| 9| null| 24.0| 33.0| -|1970-01-01T08:00:00.030+08:00|root.three| 7| null| 23.5| 30.5| -|1970-01-01T08:00:00.020+08:00|root.three| 8| null| 22.5| 30.5| -+-----------------------------+----------+----+-----+-----+-----+ -``` -在order by中同样可以使用聚合查询表达式 -```Sql -select min_value(total) from root.** order by min_value(total) asc align by device -``` -得到如下结果 -``` -+----------+----------------+ -| Device|min_value(total)| -+----------+----------------+ -|root.three| 30.5| -| root.two| 33.0| -| root.four| 85.0| -| root.five| 102.0| -| root.one| 103.0| -+----------+----------------+ -``` -当在查询中指定多列,未被排序的列会随着行和排序列一起改变顺序,当排序列相同时行的顺序和具体实现有关(没有固定顺序) -```Sql -select min_value(total),max_value(base) from root.** order by max_value(total) desc align by device -``` -得到结果如下 -· -``` -+----------+----------------+---------------+ -| Device|min_value(total)|max_value(base)| -+----------+----------------+---------------+ -| root.one| 103.0| 12| -| root.five| 102.0| 7| -| root.four| 85.0| 9| -| root.two| 33.0| 9| -|root.three| 30.5| 9| -+----------+----------------+---------------+ -``` - -Order by device, time可以和order by expression共同使用 -```Sql -select score from root.** order by device asc, score desc, time asc align by device -``` -会得到如下结果 -``` -+-----------------------------+---------+-----+ -| Time| Device|score| -+-----------------------------+---------+-----+ -|1970-01-01T08:00:00.040+08:00|root.five| 54.0| -|1970-01-01T08:00:00.030+08:00|root.five| 53.0| -|1970-01-01T08:00:00.010+08:00|root.four| 32.0| -|1970-01-01T08:00:00.020+08:00|root.four| 32.0| -|1970-01-01T08:00:00.000+08:00| root.one| 50.0| -|1970-01-02T08:00:00.000+08:00| root.one| 50.0| -|1970-01-03T08:00:00.000+08:00| root.one| 50.0| -|1970-01-01T08:00:00.000+08:00| root.two| 50.0| -|1970-01-01T08:00:00.010+08:00| root.two| 50.0| -|1970-01-01T08:00:00.020+08:00| root.two| 10.0| -+-----------------------------+---------+-----+ -``` - -## 查询对齐模式(ALIGN BY DEVICE 子句) - -在 IoTDB 中,查询结果集**默认按照时间对齐**,包含一列时间列和若干个值列,每一行数据各列的时间戳相同。 - -除按照时间对齐外,还支持以下对齐模式: - -- 按设备对齐 `ALIGN BY DEVICE` - -### 按设备对齐 - -在按设备对齐模式下,设备名会单独作为一列出现,查询结果集包含一列时间列、一列设备列和若干个值列。如果 `SELECT` 子句中选择了 `N` 列,则结果集包含 `N + 2` 列(时间列和设备名字列)。 - -在默认情况下,结果集按照 `Device` 进行排列,在每个 `Device` 内按照 `Time` 列升序排序。 - -当查询多个设备时,要求设备之间同名的列数据类型相同。 - -为便于理解,可以按照关系模型进行对应。设备可以视为关系模型中的表,选择的列可以视为表中的列,`Time + Device` 看做其主键。 - -**示例:** - -```sql -select * from root.ln.** where time <= 2017-11-01T00:01:00 align by device; -``` - -执行如下: - -``` -+-----------------------------+-----------------+-----------+------+--------+ -| Time| Device|temperature|status|hardware| -+-----------------------------+-----------------+-----------+------+--------+ -|2017-11-01T00:00:00.000+08:00|root.ln.wf01.wt01| 25.96| true| null| -|2017-11-01T00:01:00.000+08:00|root.ln.wf01.wt01| 24.36| true| null| -|1970-01-01T08:00:00.001+08:00|root.ln.wf02.wt02| null| true| v1| -|1970-01-01T08:00:00.002+08:00|root.ln.wf02.wt02| null| false| v2| -|2017-11-01T00:00:00.000+08:00|root.ln.wf02.wt02| null| true| v2| -|2017-11-01T00:01:00.000+08:00|root.ln.wf02.wt02| null| true| v2| -+-----------------------------+-----------------+-----------+------+--------+ -Total line number = 6 -It costs 0.012s -``` -### 设备对齐模式下的排序 -在设备对齐模式下,默认按照设备名的字典序升序排列,每个设备内部按照时间戳大小升序排列,可以通过 `ORDER BY` 子句调整设备列和时间列的排序优先级。 - -详细说明及示例见文档 [结果集排序](./Operator-and-Expression.md)。 - -## 查询写回(INTO 子句) - -`SELECT INTO` 语句用于将查询结果写入一系列指定的时间序列中。 - -应用场景如下: -- **实现 IoTDB 内部 ETL**:对原始数据进行 ETL 处理后写入新序列。 -- **查询结果存储**:将查询结果进行持久化存储,起到类似物化视图的作用。 -- **非对齐序列转对齐序列**:对齐序列从0.13版本开始支持,可以通过该功能将非对齐序列的数据写入新的对齐序列中。 - -### 语法定义 - -#### 整体描述 - -```sql -selectIntoStatement - : SELECT - resultColumn [, resultColumn] ... - INTO intoItem [, intoItem] ... - FROM prefixPath [, prefixPath] ... - [WHERE whereCondition] - [GROUP BY groupByTimeClause, groupByLevelClause] - [FILL {PREVIOUS | LINEAR | constant}] - [LIMIT rowLimit OFFSET rowOffset] - [ALIGN BY DEVICE] - ; - -intoItem - : [ALIGNED] intoDevicePath '(' intoMeasurementName [',' intoMeasurementName]* ')' - ; -``` - -#### `INTO` 子句 - -`INTO` 子句由若干个 `intoItem` 构成。 - -每个 `intoItem` 由一个目标设备路径和一个包含若干目标物理量名的列表组成(与 `INSERT` 语句中的 `INTO` 子句写法类似)。 - -其中每个目标物理量名与目标设备路径组成一个目标序列,一个 `intoItem` 包含若干目标序列。例如:`root.sg_copy.d1(s1, s2)` 指定了两条目标序列 `root.sg_copy.d1.s1` 和 `root.sg_copy.d1.s2`。 - -`INTO` 子句指定的目标序列要能够与查询结果集的列一一对应。具体规则如下: - -- **按时间对齐**(默认):全部 `intoItem` 包含的目标序列数量要与查询结果集的列数(除时间列外)一致,且按照表头从左到右的顺序一一对应。 -- **按设备对齐**(使用 `ALIGN BY DEVICE`):全部 `intoItem` 中指定的目标设备数和查询的设备数(即 `FROM` 子句中路径模式匹配的设备数)一致,且按照结果集设备的输出顺序一一对应。 - 为每个目标设备指定的目标物理量数量要与查询结果集的列数(除时间和设备列外)一致,且按照表头从左到右的顺序一一对应。 - -下面通过示例进一步说明: - -- **示例 1**(按时间对齐) -```shell -IoTDB> select s1, s2 into root.sg_copy.d1(t1), root.sg_copy.d2(t1, t2), root.sg_copy.d1(t2) from root.sg.d1, root.sg.d2; -+--------------+-------------------+--------+ -| source column| target timeseries| written| -+--------------+-------------------+--------+ -| root.sg.d1.s1| root.sg_copy.d1.t1| 8000| -+--------------+-------------------+--------+ -| root.sg.d2.s1| root.sg_copy.d2.t1| 10000| -+--------------+-------------------+--------+ -| root.sg.d1.s2| root.sg_copy.d2.t2| 12000| -+--------------+-------------------+--------+ -| root.sg.d2.s2| root.sg_copy.d1.t2| 10000| -+--------------+-------------------+--------+ -Total line number = 4 -It costs 0.725s -``` - -该语句将 `root.sg` database 下四条序列的查询结果写入到 `root.sg_copy` database 下指定的四条序列中。注意,`root.sg_copy.d2(t1, t2)` 也可以写做 `root.sg_copy.d2(t1), root.sg_copy.d2(t2)`。 - -可以看到,`INTO` 子句的写法非常灵活,只要满足组合出的目标序列没有重复,且与查询结果列一一对应即可。 - -> `CLI` 展示的结果集中,各列的含义如下: -> - `source column` 列表示查询结果的列名。 -> - `target timeseries` 表示对应列写入的目标序列。 -> - `written` 表示预期写入的数据量。 - -- **示例 2**(按时间对齐) -```shell -IoTDB> select count(s1 + s2), last_value(s2) into root.agg.count(s1_add_s2), root.agg.last_value(s2) from root.sg.d1 group by ([0, 100), 10ms); -+--------------------------------------+-------------------------+--------+ -| source column| target timeseries| written| -+--------------------------------------+-------------------------+--------+ -| count(root.sg.d1.s1 + root.sg.d1.s2)| root.agg.count.s1_add_s2| 10| -+--------------------------------------+-------------------------+--------+ -| last_value(root.sg.d1.s2)| root.agg.last_value.s2| 10| -+--------------------------------------+-------------------------+--------+ -Total line number = 2 -It costs 0.375s -``` - -该语句将聚合查询的结果存储到指定序列中。 - -- **示例 3**(按设备对齐) -```shell -IoTDB> select s1, s2 into root.sg_copy.d1(t1, t2), root.sg_copy.d2(t1, t2) from root.sg.d1, root.sg.d2 align by device; -+--------------+--------------+-------------------+--------+ -| source device| source column| target timeseries| written| -+--------------+--------------+-------------------+--------+ -| root.sg.d1| s1| root.sg_copy.d1.t1| 8000| -+--------------+--------------+-------------------+--------+ -| root.sg.d1| s2| root.sg_copy.d1.t2| 11000| -+--------------+--------------+-------------------+--------+ -| root.sg.d2| s1| root.sg_copy.d2.t1| 12000| -+--------------+--------------+-------------------+--------+ -| root.sg.d2| s2| root.sg_copy.d2.t2| 9000| -+--------------+--------------+-------------------+--------+ -Total line number = 4 -It costs 0.625s -``` - -该语句同样是将 `root.sg` database 下四条序列的查询结果写入到 `root.sg_copy` database 下指定的四条序列中。但在按设备对齐中,`intoItem` 的数量必须和查询的设备数量一致,每个查询设备对应一个 `intoItem`。 - -> 按设备对齐查询时,`CLI` 展示的结果集多出一列 `source device` 列表示查询的设备。 - -- **示例 4**(按设备对齐) -```shell -IoTDB> select s1 + s2 into root.expr.add(d1s1_d1s2), root.expr.add(d2s1_d2s2) from root.sg.d1, root.sg.d2 align by device; -+--------------+--------------+------------------------+--------+ -| source device| source column| target timeseries| written| -+--------------+--------------+------------------------+--------+ -| root.sg.d1| s1 + s2| root.expr.add.d1s1_d1s2| 10000| -+--------------+--------------+------------------------+--------+ -| root.sg.d2| s1 + s2| root.expr.add.d2s1_d2s2| 10000| -+--------------+--------------+------------------------+--------+ -Total line number = 2 -It costs 0.532s -``` - -该语句将表达式计算的结果存储到指定序列中。 - -#### 使用变量占位符 - -特别地,可以使用变量占位符描述目标序列与查询序列之间的对应规律,简化语句书写。目前支持以下两种变量占位符: - -- 后缀复制符 `::`:复制查询设备后缀(或物理量),表示从该层开始一直到设备的最后一层(或物理量),目标设备的节点名(或物理量名)与查询的设备对应的节点名(或物理量名)相同。 -- 单层节点匹配符 `${i}`:表示目标序列当前层节点名与查询序列的第`i`层节点名相同。比如,对于路径`root.sg1.d1.s1`而言,`${1}`表示`sg1`,`${2}`表示`d1`,`${3}`表示`s1`。 - -在使用变量占位符时,`intoItem`与查询结果集列的对应关系不能存在歧义,具体情况分类讨论如下: - -##### 按时间对齐(默认) - -> 注:变量占位符**只能描述序列与序列之间的对应关系**,如果查询中包含聚合、表达式计算,此时查询结果中的列无法与某个序列对应,因此目标设备和目标物理量都不能使用变量占位符。 - -###### (1)目标设备不使用变量占位符 & 目标物理量列表使用变量占位符 - -**限制:** - 1. 每个 `intoItem` 中,物理量列表的长度必须为 1。
(如果长度可以大于1,例如 `root.sg1.d1(::, s1)`,无法确定具体哪些列与`::`匹配) - 2. `intoItem` 数量为 1,或与查询结果集列数一致。
(在每个目标物理量列表长度均为 1 的情况下,若 `intoItem` 只有 1 个,此时表示全部查询序列写入相同设备;若 `intoItem` 数量与查询序列一致,则表示为每个查询序列指定一个目标设备;若 `intoItem` 大于 1 小于查询序列数,此时无法与查询序列一一对应) - -**匹配方法:** 每个查询序列指定目标设备,而目标物理量根据变量占位符生成。 - -**示例:** - -```sql -select s1, s2 -into root.sg_copy.d1(::), root.sg_copy.d2(s1), root.sg_copy.d1(${3}), root.sg_copy.d2(::) -from root.sg.d1, root.sg.d2; -``` -该语句等价于: -```sql -select s1, s2 -into root.sg_copy.d1(s1), root.sg_copy.d2(s1), root.sg_copy.d1(s2), root.sg_copy.d2(s2) -from root.sg.d1, root.sg.d2; -``` -可以看到,在这种情况下,语句并不能得到很好地简化。 - -###### (2)目标设备使用变量占位符 & 目标物理量列表不使用变量占位符 - -**限制:** 全部 `intoItem` 中目标物理量的数量与查询结果集列数一致。 - -**匹配方式:** 为每个查询序列指定了目标物理量,目标设备根据对应目标物理量所在 `intoItem` 的目标设备占位符生成。 - -**示例:** -```sql -select d1.s1, d1.s2, d2.s3, d3.s4 -into ::(s1_1, s2_2), root.sg.d2_2(s3_3), root.${2}_copy.::(s4) -from root.sg; -``` - -###### (3)目标设备使用变量占位符 & 目标物理量列表使用变量占位符 - -**限制:** `intoItem` 只有一个且物理量列表的长度为 1。 - -**匹配方式:** 每个查询序列根据变量占位符可以得到一个目标序列。 - -**示例:** -```sql -select * into root.sg_bk.::(::) from root.sg.**; -``` -将 `root.sg` 下全部序列的查询结果写到 `root.sg_bk`,设备名后缀和物理量名保持不变。 - -##### 按设备对齐(使用 `ALIGN BY DEVICE`) - -> 注:变量占位符**只能描述序列与序列之间的对应关系**,如果查询中包含聚合、表达式计算,此时查询结果中的列无法与某个物理量对应,因此目标物理量不能使用变量占位符。 - -###### (1)目标设备不使用变量占位符 & 目标物理量列表使用变量占位符 - -**限制:** 每个 `intoItem` 中,如果物理量列表使用了变量占位符,则列表的长度必须为 1。 - -**匹配方法:** 每个查询序列指定目标设备,而目标物理量根据变量占位符生成。 - -**示例:** -```sql -select s1, s2, s3, s4 -into root.backup_sg.d1(s1, s2, s3, s4), root.backup_sg.d2(::), root.sg.d3(backup_${4}) -from root.sg.d1, root.sg.d2, root.sg.d3 -align by device; -``` - -###### (2)目标设备使用变量占位符 & 目标物理量列表不使用变量占位符 - -**限制:** `intoItem` 只有一个。(如果出现多个带占位符的 `intoItem`,我们将无法得知每个 `intoItem` 需要匹配哪几个源设备) - -**匹配方式:** 每个查询设备根据变量占位符得到一个目标设备,每个设备下结果集各列写入的目标物理量由目标物理量列表指定。 - -**示例:** -```sql -select avg(s1), sum(s2) + sum(s3), count(s4) -into root.agg_${2}.::(avg_s1, sum_s2_add_s3, count_s4) -from root.** -align by device; -``` - -###### (3)目标设备使用变量占位符 & 目标物理量列表使用变量占位符 - -**限制:** `intoItem` 只有一个且物理量列表的长度为 1。 - -**匹配方式:** 每个查询序列根据变量占位符可以得到一个目标序列。 - -**示例:** -```sql -select * into ::(backup_${4}) from root.sg.** align by device; -``` -将 `root.sg` 下每条序列的查询结果写到相同设备下,物理量名前加`backup_`。 - -#### 指定目标序列为对齐序列 - -通过 `ALIGNED` 关键词可以指定写入的目标设备为对齐写入,每个 `intoItem` 可以独立设置。 - -**示例:** -```sql -select s1, s2 into root.sg_copy.d1(t1, t2), aligned root.sg_copy.d2(t1, t2) from root.sg.d1, root.sg.d2 align by device; -``` -该语句指定了 `root.sg_copy.d1` 是非对齐设备,`root.sg_copy.d2`是对齐设备。 - -#### 不支持使用的查询子句 - -- `SLIMIT`、`SOFFSET`:查询出来的列不确定,功能不清晰,因此不支持。 -- `LAST`查询、`GROUP BY TAGS`、`DISABLE ALIGN`:表结构和写入结构不一致,因此不支持。 - -#### 其他要注意的点 - -- 对于一般的聚合查询,时间戳是无意义的,约定使用 0 来存储。 -- 当目标序列存在时,需要保证源序列和目标时间序列的数据类型兼容。关于数据类型的兼容性,查看文档 [数据类型](../Basic-Concept/Data-Type.md#数据类型兼容性)。 -- 当目标序列不存在时,系统将自动创建目标序列(包括 database)。 -- 当查询的序列不存在或查询的序列不存在数据,则不会自动创建目标序列。 - -### 应用举例 - -#### 实现 IoTDB 内部 ETL -对原始数据进行 ETL 处理后写入新序列。 -```shell -IOTDB > SELECT preprocess_udf(s1, s2) INTO ::(preprocessed_s1, preprocessed_s2) FROM root.sg.* ALIGN BY DEIVCE; -+--------------+-------------------+---------------------------+--------+ -| source device| source column| target timeseries| written| -+--------------+-------------------+---------------------------+--------+ -| root.sg.d1| preprocess_udf(s1)| root.sg.d1.preprocessed_s1| 8000| -+--------------+-------------------+---------------------------+--------+ -| root.sg.d1| preprocess_udf(s2)| root.sg.d1.preprocessed_s2| 10000| -+--------------+-------------------+---------------------------+--------+ -| root.sg.d2| preprocess_udf(s1)| root.sg.d2.preprocessed_s1| 11000| -+--------------+-------------------+---------------------------+--------+ -| root.sg.d2| preprocess_udf(s2)| root.sg.d2.preprocessed_s2| 9000| -+--------------+-------------------+---------------------------+--------+ -``` -以上语句使用自定义函数对数据进行预处理,将预处理后的结果持久化存储到新序列中。 - -#### 查询结果存储 -将查询结果进行持久化存储,起到类似物化视图的作用。 -```shell -IOTDB > SELECT count(s1), last_value(s1) INTO root.sg.agg_${2}(count_s1, last_value_s1) FROM root.sg1.d1 GROUP BY ([0, 10000), 10ms); -+--------------------------+-----------------------------+--------+ -| source column| target timeseries| written| -+--------------------------+-----------------------------+--------+ -| count(root.sg.d1.s1)| root.sg.agg_d1.count_s1| 1000| -+--------------------------+-----------------------------+--------+ -| last_value(root.sg.d1.s2)| root.sg.agg_d1.last_value_s2| 1000| -+--------------------------+-----------------------------+--------+ -Total line number = 2 -It costs 0.115s -``` -以上语句将降采样查询的结果持久化存储到新序列中。 - -#### 非对齐序列转对齐序列 -对齐序列从 0.13 版本开始支持,可以通过该功能将非对齐序列的数据写入新的对齐序列中。 - -**注意:** 建议配合使用 `LIMIT & OFFSET` 子句或 `WHERE` 子句(时间过滤条件)对数据进行分批,防止单次操作的数据量过大。 - -```shell -IOTDB > SELECT s1, s2 INTO ALIGNED root.sg1.aligned_d(s1, s2) FROM root.sg1.non_aligned_d WHERE time >= 0 and time < 10000; -+--------------------------+----------------------+--------+ -| source column| target timeseries| written| -+--------------------------+----------------------+--------+ -| root.sg1.non_aligned_d.s1| root.sg1.aligned_d.s1| 10000| -+--------------------------+----------------------+--------+ -| root.sg1.non_aligned_d.s2| root.sg1.aligned_d.s2| 10000| -+--------------------------+----------------------+--------+ -Total line number = 2 -It costs 0.375s -``` -以上语句将一组非对齐的序列的数据迁移到一组对齐序列。 - -### 相关用户权限 - -用户必须有下列权限才能正常执行查询写回语句: - -* 所有 `SELECT` 子句中源序列的 `WRITE_SCHEMA` 权限。 -* 所有 `INTO` 子句中目标序列 `WRITE_DATA` 权限。 - -更多用户权限相关的内容,请参考[权限管理语句](./Authority-Management.md)。 - -### 相关配置参数 - -* `select_into_insert_tablet_plan_row_limit` - - | 参数名 | select_into_insert_tablet_plan_row_limit | - | ---- | ---- | - | 描述 | 写入过程中每一批 `Tablet` 的最大行数 | - | 类型 | int32 | - | 默认值 | 10000 | - | 改后生效方式 | 重启后生效 | diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Security-Management_timecho.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Security-Management_timecho.md deleted file mode 100644 index bc4cff150..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Security-Management_timecho.md +++ /dev/null @@ -1,158 +0,0 @@ - - -# 安全控制 - -## 白名单 - -**功能描述** - -允许哪些客户端地址能连接 IoTDB - -**配置文件** - -conf/iotdb-common.properties - -conf/white.list - -**配置项** - -iotdb-common.properties: - -决定是否开启白名单功能 - -```YAML -# 是否开启白名单功能 -enable_white_list=true -``` - -white.list: - -决定哪些IP地址能够连接IoTDB - -```YAML -# 支持注释 -# 支持精确匹配,每行一个ip -10.2.3.4 - -# 支持*通配符,每行一个ip -10.*.1.3 -10.100.0.* -``` - -**注意事项** - -1. 如果通过session客户端取消本身的白名单,当前连接并不会立即断开。在下次创建连接的时候拒绝。 -2. 如果直接修改white.list,一分钟内生效。如果通过session客户端修改,立即生效,更新内存中的值和white.list磁盘文件 -3. 开启白名单功能,没有white.list 文件,启动DB服务成功,但是,拒绝所有连接。 -4. DB服务运行中,删除 white.list 文件,至多一分钟后,拒绝所有连接。 -5. 是否开启白名单功能的配置,可以热加载。 -6. 使用Java 原生接口修改白名单,必须是root用户才能修改,拒绝非root用户修改;修改内容必须合法,否则会抛出StatementExecutionException异常。 - -![白名单](/img/%E7%99%BD%E5%90%8D%E5%8D%95.png) - -## 审计日志 - -### 功能背景 - - 审计日志是数据库的记录凭证,通过审计日志功能可以查询到用户在数据库中增删改查等各项操作,以保证信息安全。关于IoTDB的审计日志功能可以实现以下场景的需求: - -- 可以按链接来源(是否人为操作)决定是否记录审计日志,如:非人为操作如硬件采集器写入的数据不需要记录审计日志,人为操作如普通用户通过cli、workbench等工具操作的数据需要记录审计日志。 -- 过滤掉系统级别的写入操作,如IoTDB监控体系本身记录的写入操作等。 - - - -#### 场景说明 - - - -##### 对所有用户的所有操作(增、删、改、查)进行记录 - -通过审计日志功能追踪到所有用户在数据中的各项操作。其中所记录的信息要包含数据操作(新增、删除、查询)及元数据操作(新增、修改、删除、查询)、客户端登录信息(用户名、ip地址)。 - - - -客户端的来源 - -- Cli、workbench、Zeppelin、Grafana、通过 Session/JDBC/MQTT 等协议传入的请求 - -![审计日志](/img/%E5%AE%A1%E8%AE%A1%E6%97%A5%E5%BF%97.png) - - - -##### 可关闭部分用户连接的审计日志 - - - -如非人为操作,硬件采集器通过 Session/JDBC/MQTT 写入的数据不需要记录审计日志 - - - -### 功能定义 - - - -通过配置可以实现: - -- 决定是否开启审计功能 -- 决定审计日志的输出位置,支持输出至一项或多项 - 1. 日志文件 - 2. IoTDB存储 -- 决定是否屏蔽原生接口的写入,防止记录审计日志过多影响性能 -- 决定审计日志内容类别,支持记录一项或多项 - 1. 数据的新增、删除操作 - 2. 数据和元数据的查询操作 - 3. 元数据类的新增、修改、删除操作 - -#### 配置项 - - 在 iotdb-common.properties中修改以下几项配置 - -```YAML -#################### -### Audit log Configuration -#################### - -# whether to enable the audit log. -# Datatype: Boolean -# enable_audit_log=false - -# Output location of audit logs -# Datatype: String -# IOTDB: the stored time series is: root.__system.audit._{user} -# LOGGER: log_audit.log in the log directory -# audit_log_storage=IOTDB,LOGGER - -# whether enable audit log for DML operation of data -# whether enable audit log for DDL operation of schema -# whether enable audit log for QUERY operation of data and schema -# Datatype: String -# audit_log_operation=DML,DDL,QUERY - -# whether the local write api records audit logs -# Datatype: Boolean -# This contains Session insert api: insertRecord(s), insertTablet(s),insertRecordsOfOneDevice -# MQTT insert api -# RestAPI insert api -# This parameter will cover the DML in audit_log_operation -# enable_audit_log_for_native_insert_api=true -``` - diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_apache.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_apache.md deleted file mode 100644 index 3aff9500b..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_apache.md +++ /dev/null @@ -1,813 +0,0 @@ - - -# 流处理框架 - -IoTDB 流处理框架允许用户实现自定义的流处理逻辑,可以实现对存储引擎变更的监听和捕获、实现对变更数据的变形、实现对变形后数据的向外推送等逻辑。 - -我们将一个数据流处理任务称为 Pipe。一个流处理任务(Pipe)包含三个子任务: - -- 抽取(Source) -- 处理(Process) -- 发送(Sink) - -流处理框架允许用户使用 Java 语言自定义编写三个子任务的处理逻辑,通过类似 UDF 的方式处理数据。 -在一个 Pipe 中,上述的三个子任务分别由三种插件执行实现,数据会依次经过这三个插件进行处理: -Pipe Source 用于抽取数据,Pipe Processor 用于处理数据,Pipe Sink 用于发送数据,最终数据将被发至外部系统。 - -**Pipe 任务的模型如下:** - -![任务模型图](/img/1706697228308.jpg) - -描述一个数据流处理任务,本质就是描述 Pipe Source、Pipe Processor 和 Pipe Sink 插件的属性。 -用户可以通过 SQL 语句声明式地配置三个子任务的具体属性,通过组合不同的属性,实现灵活的数据 ETL 能力。 - -利用流处理框架,可以搭建完整的数据链路来满足端*边云同步、异地灾备、读写负载分库*等需求。 - -## 自定义流处理插件开发 - -### 编程开发依赖 - -推荐采用 maven 构建项目,在`pom.xml`中添加以下依赖。请注意选择和 IoTDB 服务器版本相同的依赖版本。 - -```xml - - org.apache.iotdb - pipe-api - 1.3.1 - provided - -``` - -### 事件驱动编程模型 - -流处理插件的用户编程接口设计,参考了事件驱动编程模型的通用设计理念。事件(Event)是用户编程接口中的数据抽象,而编程接口与具体的执行方式解耦,只需要专注于描述事件(数据)到达系统后,系统期望的处理方式即可。 - -在流处理插件的用户编程接口中,事件是数据库数据写入操作的抽象。事件由单机流处理引擎捕获,按照流处理三个阶段的流程,依次传递至 PipeSource 插件,PipeProcessor 插件和 PipeSink 插件,并依次在三个插件中触发用户逻辑的执行。 - -为了兼顾端侧低负载场景下的流处理低延迟和端侧高负载场景下的流处理高吞吐,流处理引擎会动态地在操作日志和数据文件中选择处理对象,因此,流处理的用户编程接口要求用户提供下列两类事件的处理逻辑:操作日志写入事件 TabletInsertionEvent 和数据文件写入事件 TsFileInsertionEvent。 - -#### **操作日志写入事件(TabletInsertionEvent)** - -操作日志写入事件(TabletInsertionEvent)是对用户写入请求的高层数据抽象,它通过提供统一的操作接口,为用户提供了操纵写入请求底层数据的能力。 - -对于不同的数据库部署方式,操作日志写入事件对应的底层存储结构是不一样的。对于单机部署的场景,操作日志写入事件是对写前日志(WAL)条目的封装;对于分布式部署的场景,操作日志写入事件是对单个节点共识协议操作日志条目的封装。 - -对于数据库不同写入请求接口生成的写入操作,操作日志写入事件对应的请求结构体的数据结构也是不一样的。IoTDB 提供了 InsertRecord、InsertRecords、InsertTablet、InsertTablets 等众多的写入接口,每一种写入请求都使用了完全不同的序列化方式,生成的二进制条目也不尽相同。 - -操作日志写入事件的存在,为用户提供了一种统一的数据操作视图,它屏蔽了底层数据结构的实现差异,极大地降低了用户的编程门槛,提升了功能的易用性。 - -```java -/** TabletInsertionEvent is used to define the event of data insertion. */ -public interface TabletInsertionEvent extends Event { - - /** - * The consumer processes the data row by row and collects the results by RowCollector. - * - * @return {@code Iterable} a list of new TabletInsertionEvent contains the - * results collected by the RowCollector - */ - Iterable processRowByRow(BiConsumer consumer); - - /** - * The consumer processes the Tablet directly and collects the results by RowCollector. - * - * @return {@code Iterable} a list of new TabletInsertionEvent contains the - * results collected by the RowCollector - */ - Iterable processTablet(BiConsumer consumer); -} -``` - -#### **数据文件写入事件(TsFileInsertionEvent)** - -数据文件写入事件(TsFileInsertionEvent) 是对数据库文件落盘操作的高层抽象,它是若干操作日志写入事件(TabletInsertionEvent)的数据集合。 - -IoTDB 的存储引擎是 LSM 结构的。数据写入时会先将写入操作落盘到日志结构的文件里,同时将写入数据保存在内存里。当内存达到控制上限,则会触发刷盘行为,即将内存中的数据转换为数据库文件,同时删除之前预写的操作日志。当内存中的数据转换为数据库文件中的数据时,会经过编码压缩和通用压缩两次压缩处理,因此数据库文件的数据相比内存中的原始数据占用的空间更少。 - -在极端的网络情况下,直接传输数据文件相比传输数据写入的操作要更加经济,它会占用更低的网络带宽,能实现更快的传输速度。当然,天下没有免费的午餐,对文件中的数据进行计算处理,相比直接对内存中的数据进行计算处理时,需要额外付出文件 I/O 的代价。但是,正是磁盘数据文件和内存写入操作两种结构各有优劣的存在,给了系统做动态权衡调整的机会,也正是基于这样的观察,插件的事件模型中才引入了数据文件写入事件。 - -综上,数据文件写入事件出现在流处理插件的事件流中,存在下面两种情况: - -(1)历史数据抽取:一个流处理任务开始前,所有已经落盘的写入数据都会以 TsFile 的形式存在。一个流处理任务开始后,采集历史数据时,历史数据将以 TsFileInsertionEvent 作为抽象; - -(2)实时数据抽取:一个流处理任务进行时,当数据流中实时处理操作日志写入事件的速度慢于写入请求速度一定进度之后,未来得及处理的操作日志写入事件会被被持久化至磁盘,以 TsFile 的形式存在,这一些数据被流处理引擎抽取到后,会以 TsFileInsertionEvent 作为抽象。 - -```java -/** - * TsFileInsertionEvent is used to define the event of writing TsFile. Event data stores in disks, - * which is compressed and encoded, and requires IO cost for computational processing. - */ -public interface TsFileInsertionEvent extends Event { - - /** - * The method is used to convert the TsFileInsertionEvent into several TabletInsertionEvents. - * - * @return {@code Iterable} the list of TabletInsertionEvent - */ - Iterable toTabletInsertionEvents(); -} -``` - -### 自定义流处理插件编程接口定义 - -基于自定义流处理插件编程接口,用户可以轻松编写数据抽取插件、数据处理插件和数据发送插件,从而使得流处理功能灵活适配各种工业场景。 - -#### 数据抽取插件接口 - -数据抽取是流处理数据从数据抽取到数据发送三阶段的第一阶段。数据抽取插件(PipeSource)是流处理引擎和存储引擎的桥梁,它通过监听存储引擎的行为, -捕获各种数据写入事件。 - -```java -/** - * PipeSource - * - *

PipeSource is responsible for capturing events from sources. - * - *

Various data sources can be supported by implementing different PipeSource classes. - * - *

The lifecycle of a PipeSource is as follows: - * - *

    - *
  • When a collaboration task is created, the KV pairs of `WITH SOURCE` clause in SQL are - * parsed and the validation method {@link PipeSource#validate(PipeParameterValidator)} will - * be called to validate the parameters. - *
  • Before the collaboration task starts, the method {@link - * PipeSource#customize(PipeParameters, PipeSourceRuntimeConfiguration)} will be called to - * config the runtime behavior of the PipeSource. - *
  • Then the method {@link PipeSource#start()} will be called to start the PipeSource. - *
  • While the collaboration task is in progress, the method {@link PipeSource#supply()} will be - * called to capture events from sources and then the events will be passed to the - * PipeProcessor. - *
  • The method {@link PipeSource#close()} will be called when the collaboration task is - * cancelled (the `DROP PIPE` command is executed). - *
- */ -public interface PipeSource extends PipePlugin { - - /** - * This method is mainly used to validate {@link PipeParameters} and it is executed before {@link - * PipeSource#customize(PipeParameters, PipeSourceRuntimeConfiguration)} is called. - * - * @param validator the validator used to validate {@link PipeParameters} - * @throws Exception if any parameter is not valid - */ - void validate(PipeParameterValidator validator) throws Exception; - - /** - * This method is mainly used to customize PipeSource. In this method, the user can do the - * following things: - * - *
    - *
  • Use PipeParameters to parse key-value pair attributes entered by the user. - *
  • Set the running configurations in PipeSourceRuntimeConfiguration. - *
- * - *

This method is called after the method {@link PipeSource#validate(PipeParameterValidator)} - * is called. - * - * @param parameters used to parse the input parameters entered by the user - * @param configuration used to set the required properties of the running PipeSource - * @throws Exception the user can throw errors if necessary - */ - void customize(PipeParameters parameters, PipeSourceRuntimeConfiguration configuration) - throws Exception; - - /** - * Start the Source. After this method is called, events should be ready to be supplied by - * {@link PipeSource#supply()}. This method is called after {@link - * PipeSource#customize(PipeParameters, PipeSourceRuntimeConfiguration)} is called. - * - * @throws Exception the user can throw errors if necessary - */ - void start() throws Exception; - - /** - * Supply single event from the Source and the caller will send the event to the processor. - * This method is called after {@link PipeSource#start()} is called. - * - * @return the event to be supplied. the event may be null if the Source has no more events at - * the moment, but the Source is still running for more events. - * @throws Exception the user can throw errors if necessary - */ - Event supply() throws Exception; -} -``` - -#### 数据处理插件接口 - -数据处理是流处理数据从数据抽取到数据发送三阶段的第二阶段。数据处理插件(PipeProcessor)主要用于过滤和转换由数据抽取插件(PipeSource)捕获的 -各种事件。 - -```java -/** - * PipeProcessor - * - *

PipeProcessor is used to filter and transform the Event formed by the PipeSource. - * - *

The lifecycle of a PipeProcessor is as follows: - * - *

    - *
  • When a collaboration task is created, the KV pairs of `WITH PROCESSOR` clause in SQL are - * parsed and the validation method {@link PipeProcessor#validate(PipeParameterValidator)} - * will be called to validate the parameters. - *
  • Before the collaboration task starts, the method {@link - * PipeProcessor#customize(PipeParameters, PipeProcessorRuntimeConfiguration)} will be called - * to config the runtime behavior of the PipeProcessor. - *
  • While the collaboration task is in progress: - *
      - *
    • PipeSource captures the events and wraps them into three types of Event instances. - *
    • PipeProcessor processes the event and then passes them to the PipeSink. The - * following 3 methods will be called: {@link - * PipeProcessor#process(TabletInsertionEvent, EventCollector)}, {@link - * PipeProcessor#process(TsFileInsertionEvent, EventCollector)} and {@link - * PipeProcessor#process(Event, EventCollector)}. - *
    • PipeSink serializes the events into binaries and send them to sinks. - *
    - *
  • When the collaboration task is cancelled (the `DROP PIPE` command is executed), the {@link - * PipeProcessor#close() } method will be called. - *
- */ -public interface PipeProcessor extends PipePlugin { - - /** - * This method is mainly used to validate {@link PipeParameters} and it is executed before {@link - * PipeProcessor#customize(PipeParameters, PipeProcessorRuntimeConfiguration)} is called. - * - * @param validator the validator used to validate {@link PipeParameters} - * @throws Exception if any parameter is not valid - */ - void validate(PipeParameterValidator validator) throws Exception; - - /** - * This method is mainly used to customize PipeProcessor. In this method, the user can do the - * following things: - * - *
    - *
  • Use PipeParameters to parse key-value pair attributes entered by the user. - *
  • Set the running configurations in PipeProcessorRuntimeConfiguration. - *
- * - *

This method is called after the method {@link - * PipeProcessor#validate(PipeParameterValidator)} is called and before the beginning of the - * events processing. - * - * @param parameters used to parse the input parameters entered by the user - * @param configuration used to set the required properties of the running PipeProcessor - * @throws Exception the user can throw errors if necessary - */ - void customize(PipeParameters parameters, PipeProcessorRuntimeConfiguration configuration) - throws Exception; - - /** - * This method is called to process the TabletInsertionEvent. - * - * @param tabletInsertionEvent TabletInsertionEvent to be processed - * @param eventCollector used to collect result events after processing - * @throws Exception the user can throw errors if necessary - */ - void process(TabletInsertionEvent tabletInsertionEvent, EventCollector eventCollector) - throws Exception; - - /** - * This method is called to process the TsFileInsertionEvent. - * - * @param tsFileInsertionEvent TsFileInsertionEvent to be processed - * @param eventCollector used to collect result events after processing - * @throws Exception the user can throw errors if necessary - */ - default void process(TsFileInsertionEvent tsFileInsertionEvent, EventCollector eventCollector) - throws Exception { - for (final TabletInsertionEvent tabletInsertionEvent : - tsFileInsertionEvent.toTabletInsertionEvents()) { - process(tabletInsertionEvent, eventCollector); - } - } - - /** - * This method is called to process the Event. - * - * @param event Event to be processed - * @param eventCollector used to collect result events after processing - * @throws Exception the user can throw errors if necessary - */ - void process(Event event, EventCollector eventCollector) throws Exception; -} -``` - -#### 数据发送插件接口 - -数据发送是流处理数据从数据抽取到数据发送三阶段的第三阶段。数据发送插件(PipeSink)主要用于发送经由数据处理插件(PipeProcessor)处理过后的 -各种事件,它作为流处理框架的网络实现层,接口上应允许接入多种实时通信协议和多种连接器。 - -```java -/** - * PipeSink - * - *

PipeSink is responsible for sending events to sinks. - * - *

Various network protocols can be supported by implementing different PipeSink classes. - * - *

The lifecycle of a PipeSink is as follows: - * - *

    - *
  • When a collaboration task is created, the KV pairs of `WITH SINK` clause in SQL are - * parsed and the validation method {@link PipeSink#validate(PipeParameterValidator)} will be - * called to validate the parameters. - *
  • Before the collaboration task starts, the method {@link PipeSink#customize(PipeParameters, - * PipeSinkRuntimeConfiguration)} will be called to config the runtime behavior of the - * PipeSink and the method {@link PipeSink#handshake()} will be called to create a connection - * with sink. - *
  • While the collaboration task is in progress: - *
      - *
    • PipeSource captures the events and wraps them into three types of Event instances. - *
    • PipeProcessor processes the event and then passes them to the PipeSink. - *
    • PipeSink serializes the events into binaries and send them to sinks. The following 3 - * methods will be called: {@link PipeSink#transfer(TabletInsertionEvent)}, {@link - * PipeSink#transfer(TsFileInsertionEvent)} and {@link PipeSink#transfer(Event)}. - *
    - *
  • When the collaboration task is cancelled (the `DROP PIPE` command is executed), the {@link - * PipeSink#close() } method will be called. - *
- * - *

In addition, the method {@link PipeSink#heartbeat()} will be called periodically to check - * whether the connection with sink is still alive. The method {@link PipeSink#handshake()} will be - * called to create a new connection with the sink when the method {@link PipeSink#heartbeat()} - * throws exceptions. - */ -public interface PipeSink extends PipePlugin { - - /** - * This method is mainly used to validate {@link PipeParameters} and it is executed before {@link - * PipeSink#customize(PipeParameters, PipeSinkRuntimeConfiguration)} is called. - * - * @param validator the validator used to validate {@link PipeParameters} - * @throws Exception if any parameter is not valid - */ - void validate(PipeParameterValidator validator) throws Exception; - - /** - * This method is mainly used to customize PipeSink. In this method, the user can do the following - * things: - * - *

    - *
  • Use PipeParameters to parse key-value pair attributes entered by the user. - *
  • Set the running configurations in PipeSinkRuntimeConfiguration. - *
- * - *

This method is called after the method {@link PipeSink#validate(PipeParameterValidator)} is - * called and before the method {@link PipeSink#handshake()} is called. - * - * @param parameters used to parse the input parameters entered by the user - * @param configuration used to set the required properties of the running PipeSink - * @throws Exception the user can throw errors if necessary - */ - void customize(PipeParameters parameters, PipeSinkRuntimeConfiguration configuration) - throws Exception; - - /** - * This method is used to create a connection with sink. This method will be called after the - * method {@link PipeSink#customize(PipeParameters, PipeSinkRuntimeConfiguration)} is called or - * will be called when the method {@link PipeSink#heartbeat()} throws exceptions. - * - * @throws Exception if the connection is failed to be created - */ - void handshake() throws Exception; - - /** - * This method will be called periodically to check whether the connection with sink is still - * alive. - * - * @throws Exception if the connection dies - */ - void heartbeat() throws Exception; - - /** - * This method is used to transfer the TabletInsertionEvent. - * - * @param tabletInsertionEvent TabletInsertionEvent to be transferred - * @throws PipeConnectionException if the connection is broken - * @throws Exception the user can throw errors if necessary - */ - void transfer(TabletInsertionEvent tabletInsertionEvent) throws Exception; - - /** - * This method is used to transfer the TsFileInsertionEvent. - * - * @param tsFileInsertionEvent TsFileInsertionEvent to be transferred - * @throws PipeConnectionException if the connection is broken - * @throws Exception the user can throw errors if necessary - */ - default void transfer(TsFileInsertionEvent tsFileInsertionEvent) throws Exception { - try { - for (final TabletInsertionEvent tabletInsertionEvent : - tsFileInsertionEvent.toTabletInsertionEvents()) { - transfer(tabletInsertionEvent); - } - } finally { - tsFileInsertionEvent.close(); - } - } - - /** - * This method is used to transfer the generic events, including HeartbeatEvent. - * - * @param event Event to be transferred - * @throws PipeConnectionException if the connection is broken - * @throws Exception the user can throw errors if necessary - */ - void transfer(Event event) throws Exception; -} -``` - -## 自定义流处理插件管理 - -为了保证用户自定义插件在实际生产中的灵活性和易用性,系统还需要提供对插件进行动态统一管理的能力。 -本章节介绍的流处理插件管理语句提供了对插件进行动态统一管理的入口。 - -### 加载插件语句 - -在 IoTDB 中,若要在系统中动态载入一个用户自定义插件,则首先需要基于 PipeSource、 PipeProcessor 或者 PipeSink 实现一个具体的插件类, -然后需要将插件类编译打包成 jar 可执行文件,最后使用加载插件的管理语句将插件载入 IoTDB。 - -加载插件的管理语句的语法如图所示。 - -```sql -CREATE PIPEPLUGIN <别名> -AS <全类名> -USING -``` - -例如,用户实现了一个全类名为 edu.tsinghua.iotdb.pipe.ExampleProcessor 的数据处理插件, -打包后的 jar 资源包存放到了 https://example.com:8080/iotdb/pipe-plugin.jar 上,用户希望在流处理引擎中使用这个插件, -将插件标记为 example。那么,这个数据处理插件的创建语句如图所示。 - -```sql -CREATE PIPEPLUGIN example -AS 'edu.tsinghua.iotdb.pipe.ExampleProcessor' -USING URI -``` - -### 删除插件语句 - -当用户不再想使用一个插件,需要将插件从系统中卸载时,可以使用如图所示的删除插件语句。 - -```sql -DROP PIPEPLUGIN <别名> -``` - -### 查看插件语句 - -用户也可以按需查看系统中的插件。查看插件的语句如图所示。 - -```sql -SHOW PIPEPLUGINS -``` - -## 系统预置的流处理插件 - -### 预置 source 插件 - -#### iotdb-source - -作用:抽取 IoTDB 内部的历史或实时数据进入 pipe。 - - -| key | value | value 取值范围 | required or optional with default | -|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------|-----------------------------------| -| source | iotdb-source | String: iotdb-source | required | -| source.pattern | 用于筛选时间序列的路径前缀 | String: 任意的时间序列前缀 | optional: root | -| source.history.start-time | 抽取的历史数据的开始 event time,包含 start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MIN_VALUE | -| source.history.end-time | 抽取的历史数据的结束 event time,包含 end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MAX_VALUE | -| start-time(V1.3.1+) | start of synchronizing all data event time,including start-time. Will disable "history.start-time" "history.end-time" if configured | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MIN_VALUE | -| end-time(V1.3.1+) | end of synchronizing all data event time,including end-time. Will disable "history.start-time" "history.end-time" if configured | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MAX_VALUE | - -> 🚫 **source.pattern 参数说明** -> -> * Pattern 需用反引号修饰不合法字符或者是不合法路径节点,例如如果希望筛选 root.\`a@b\` 或者 root.\`123\`,应设置 pattern 为 root.\`a@b\` 或者 root.\`123\`(具体参考 [单双引号和反引号的使用时机](https://iotdb.apache.org/zh/Download/#_1-0-版本不兼容的语法详细说明)) -> * 在底层实现中,当检测到 pattern 为 root(默认值)时,抽取效率较高,其他任意格式都将降低性能 -> * 路径前缀不需要能够构成完整的路径。例如,当创建一个包含参数为 'source.pattern'='root.aligned.1' 的 pipe 时: -> -> * root.aligned.1TS -> * root.aligned.1TS.\`1\` -> * root.aligned.100T -> -> 的数据会被抽取; -> -> * root.aligned.\`1\` -> * root.aligned.\`123\` -> -> 的数据不会被抽取。 - -> ❗️**source.history 的 start-time,end-time 参数说明** -> -> * start-time,end-time 应为 ISO 格式,例如 2011-12-03T10:15:30 或 2011-12-03T10:15:30+01:00 - -> ✅ **一条数据从生产到落库 IoTDB,包含两个关键的时间概念** -> -> * **event time:** 数据实际生产时的时间(或者数据生产系统给数据赋予的生成时间,是数据点中的时间项),也称为事件时间。 -> * **arrival time:** 数据到达 IoTDB 系统内的时间。 -> -> 我们常说的乱序数据,指的是数据到达时,其 **event time** 远落后于当前系统时间(或者已经落库的最大 **event time**)的数据。另一方面,不论是乱序数据还是顺序数据,只要它们是新到达系统的,那它们的 **arrival time** 都是会随着数据到达 IoTDB 的顺序递增的。 - -> 💎 **iotdb-source 的工作可以拆分成两个阶段** -> -> 1. 历史数据抽取:所有 **arrival time** < 创建 pipe 时**当前系统时间**的数据称为历史数据 -> 2. 实时数据抽取:所有 **arrival time** >= 创建 pipe 时**当前系统时间**的数据称为实时数据 -> -> 历史数据传输阶段和实时数据传输阶段,**两阶段串行执行,只有当历史数据传输阶段完成后,才执行实时数据传输阶段。** - -### 预置 processor 插件 - -#### do-nothing-processor - -作用:不对 source 传入的事件做任何的处理。 - - -| key | value | value 取值范围 | required or optional with default | -|-----------|----------------------|------------------------------|-----------------------------------| -| processor | do-nothing-processor | String: do-nothing-processor | required | - -### 预置 sink 插件 - -#### do-nothing-sink - -作用:不对 processor 传入的事件做任何的处理。 - - -| key | value | value 取值范围 | required or optional with default | -|------|-----------------|-------------------------|-----------------------------------| -| sink | do-nothing-sink | String: do-nothing-sink | required | - -## 流处理任务管理 - -### 创建流处理任务 - -使用 `CREATE PIPE` 语句来创建流处理任务。以数据同步流处理任务的创建为例,示例 SQL 语句如下: - -```sql -CREATE PIPE -- PipeId 是能够唯一标定流处理任务的名字 -WITH SOURCE ( - -- 默认的 IoTDB 数据抽取插件 - 'source' = 'iotdb-source', - -- 路径前缀,只有能够匹配该路径前缀的数据才会被抽取,用作后续的处理和发送 - 'source.pattern' = 'root.timecho', - -- 描述被抽取的历史数据的时间范围,表示最早时间 - 'source.history.start-time' = '2011.12.03T10:15:30+01:00', - -- 描述被抽取的历史数据的时间范围,表示最晚时间 - 'source.history.end-time' = '2022.12.03T10:15:30+01:00', -) -WITH PROCESSOR ( - -- 默认的数据处理插件,即不做任何处理 - 'processor' = 'do-nothing-processor', -) -WITH SINK ( - -- IoTDB 数据发送插件,目标端为 IoTDB - 'sink' = 'iotdb-thrift-sink', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 ip - 'sink.ip' = '127.0.0.1', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 port - 'sink.port' = '6667', -) -``` - -**创建流处理任务时需要配置 PipeId 以及三个插件部分的参数:** - - -| 配置项 | 说明 | 是否必填 | 默认实现 | 默认实现说明 | 是否允许自定义实现 | -|-----------|--------------------------------|---------------------------|----------------------|------------------------------|--------------------------| -| PipeId | 全局唯一标定一个流处理任务的名称 | 必填 | - | - | - | -| source | Pipe Source 插件,负责在数据库底层抽取流处理数据 | 选填 | iotdb-source | 将数据库的全量历史数据和后续到达的实时数据接入流处理任务 | 否 | -| processor | Pipe Processor 插件,负责处理数据 | 选填 | do-nothing-processor | 对传入的数据不做任何处理 | | -| sink | Pipe Sink 插件,负责发送数据 | 必填 | - | - | | - -示例中,使用了 iotdb-source、do-nothing-processor 和 iotdb-thrift-sink 插件构建数据流处理任务。IoTDB 还内置了其他的流处理插件,**请查看“系统预置流处理插件”一节**。 - -**一个最简的 CREATE PIPE 语句示例如下:** - -```sql -CREATE PIPE -- PipeId 是能够唯一标定流处理任务的名字 -WITH SINK ( - -- IoTDB 数据发送插件,目标端为 IoTDB - 'sink' = 'iotdb-thrift-sink', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 ip - 'sink.ip' = '127.0.0.1', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 port - 'sink.port' = '6667', -) -``` - -其表达的语义是:将本数据库实例中的全量历史数据和后续到达的实时数据,同步到目标为 127.0.0.1:6667 的 IoTDB 实例上。 - -**注意:** - -- SOURCE 和 PROCESSOR 为选填配置,若不填写配置参数,系统则会采用相应的默认实现 -- SINK 为必填配置,需要在 CREATE PIPE 语句中声明式配置 -- SINK 具备自复用能力。对于不同的流处理任务,如果他们的 SINK 具备完全相同 KV 属性的(所有属性的 key 对应的 value 都相同),**那么系统最终只会创建一个 SINK 实例**,以实现对连接资源的复用。 - - - 例如,有下面 pipe1, pipe2 两个流处理任务的声明: - - ```sql - CREATE PIPE pipe1 - WITH SINK ( - 'sink' = 'iotdb-thrift-sink', - 'sink.ip' = 'localhost', - 'sink.port' = '9999', - ) - - CREATE PIPE pipe2 - WITH SINK ( - 'sink' = 'iotdb-thrift-sink', - 'sink.port' = '9999', - 'sink.ip' = 'localhost', - ) - ``` - - - 因为它们对 SINK 的声明完全相同(**即使某些属性声明时的顺序不同**),所以框架会自动对它们声明的 SINK 进行复用,最终 pipe1, pipe2 的 SINK 将会是同一个实例。 -- 请不要构建出包含数据循环同步的应用场景(会导致无限循环): - - - IoTDB A -> IoTDB B -> IoTDB A - - IoTDB A -> IoTDB A - -### 启动流处理任务 - -CREATE PIPE 语句成功执行后,流处理任务相关实例会被创建,但整个流处理任务的运行状态会被置为 STOPPED(V1.3.0),即流处理任务不会立刻处理数据。在 1.3.1 及以上的版本,流处理任务的运行状态在创建后将被立即置为 RUNNING。 - -可以使用 START PIPE 语句使流处理任务开始处理数据: - -```sql -START PIPE -``` - -### 停止流处理任务 - -使用 STOP PIPE 语句使流处理任务停止处理数据: - -```sql -STOP PIPE -``` - -### 删除流处理任务 - -使用 DROP PIPE 语句使流处理任务停止处理数据(当流处理任务状态为 RUNNING 时),然后删除整个流处理任务流处理任务: - -```sql -DROP PIPE -``` - -用户在删除流处理任务前,不需要执行 STOP 操作。 - -### 展示流处理任务 - -使用 SHOW PIPES 语句查看所有流处理任务: - -```sql -SHOW PIPES -``` - -查询结果如下: - -```sql -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -| ID| CreationTime| State|PipeSource|PipeProcessor|PipeSink|ExceptionMessage| -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -|iotdb-kafka|2022-03-30T20:58:30.689|RUNNING| ...| ...| ...| {}| -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -|iotdb-iotdb|2022-03-31T12:55:28.129|STOPPED| ...| ...| ...| TException: ...| -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -``` - -可以使用 `` 指定想看的某个流处理任务状态: - -```sql -SHOW PIPE -``` - -您也可以通过 where 子句,判断某个 \ 使用的 Pipe Sink 被复用的情况。 - -```sql -SHOW PIPES -WHERE SINK USED BY -``` - -### 流处理任务运行状态迁移 - -一个流处理 pipe 在其生命周期中会经过多种状态: - -- **RUNNING:** pipe 正在正常工作 - - 当一个 pipe 被成功创建之后,其初始状态为工作状态(V1.3.1+) -- **STOPPED:** pipe 处于停止运行状态。当管道处于该状态时,有如下几种可能: - - 当一个 pipe 被成功创建之后,其初始状态为暂停状态(V1.3.0) - - 用户手动将一个处于正常运行状态的 pipe 暂停,其状态会被动从 RUNNING 变为 STOPPED - - 当一个 pipe 运行过程中出现无法恢复的错误时,其状态会自动从 RUNNING 变为 STOPPED -- **DROPPED:** pipe 任务被永久删除 - -下图表明了所有状态以及状态的迁移: - -![状态迁移图](/img/%E7%8A%B6%E6%80%81%E8%BF%81%E7%A7%BB%E5%9B%BE.png) - -## 权限管理 - -### 流处理任务 - - -| 权限名称 | 描述 | -|----------|---------------| -| USE_PIPE | 注册流处理任务。路径无关。 | -| USE_PIPE | 开启流处理任务。路径无关。 | -| USE_PIPE | 停止流处理任务。路径无关。 | -| USE_PIPE | 卸载流处理任务。路径无关。 | -| USE_PIPE | 查询流处理任务。路径无关。 | - -### 流处理任务插件 - - -| 权限名称 | 描述 | -|:---------|-----------------| -| USE_PIPE | 注册流处理任务插件。路径无关。 | -| USE_PIPE | 卸载流处理任务插件。路径无关。 | -| USE_PIPE | 查询流处理任务插件。路径无关。 | - -## 配置参数 - -在 iotdb-common.properties 中: - -V1.3.0: -```Properties -#################### -### Pipe Configuration -#################### - -# Uncomment the following field to configure the pipe lib directory. -# For Windows platform -# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is -# absolute. Otherwise, it is relative. -# pipe_lib_dir=ext\\pipe -# For Linux platform -# If its prefix is "/", then the path is absolute. Otherwise, it is relative. -# pipe_lib_dir=ext/pipe - -# The maximum number of threads that can be used to execute the pipe subtasks in PipeSubtaskExecutor. -# The actual value will be min(pipe_subtask_executor_max_thread_num, max(1, CPU core number / 2)). -# pipe_subtask_executor_max_thread_num=5 - -# The connection timeout (in milliseconds) for the thrift client. -# pipe_connector_timeout_ms=900000 - -# The maximum number of selectors that can be used in the async connector. -# pipe_async_connector_selector_number=1 - -# The core number of clients that can be used in the async connector. -# pipe_async_connector_core_client_number=8 - -# The maximum number of clients that can be used in the async connector. -# pipe_async_connector_max_client_number=16 -``` - -V1.3.1+: -```Properties -#################### -### Pipe Configuration -#################### - -# Uncomment the following field to configure the pipe lib directory. -# For Windows platform -# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is -# absolute. Otherwise, it is relative. -# pipe_lib_dir=ext\\pipe -# For Linux platform -# If its prefix is "/", then the path is absolute. Otherwise, it is relative. -# pipe_lib_dir=ext/pipe - -# The maximum number of threads that can be used to execute the pipe subtasks in PipeSubtaskExecutor. -# The actual value will be min(pipe_subtask_executor_max_thread_num, max(1, CPU core number / 2)). -# pipe_subtask_executor_max_thread_num=5 - -# The connection timeout (in milliseconds) for the thrift client. -# pipe_sink_timeout_ms=900000 - -# The maximum number of selectors that can be used in the sink. -# Recommend to set this value to less than or equal to pipe_sink_max_client_number. -# pipe_sink_selector_number=4 - -# The maximum number of clients that can be used in the sink. -# pipe_sink_max_client_number=16 -``` diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_timecho.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_timecho.md deleted file mode 100644 index 2c18c96e7..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Streaming_timecho.md +++ /dev/null @@ -1,858 +0,0 @@ - - -# 流处理框架 - -IoTDB 流处理框架允许用户实现自定义的流处理逻辑,可以实现对存储引擎变更的监听和捕获、实现对变更数据的变形、实现对变形后数据的向外推送等逻辑。 - -我们将一个数据流处理任务称为 Pipe。一个流处理任务(Pipe)包含三个子任务: - -- 抽取(Source) -- 处理(Process) -- 发送(Sink) - -流处理框架允许用户使用 Java 语言自定义编写三个子任务的处理逻辑,通过类似 UDF 的方式处理数据。 -在一个 Pipe 中,上述的三个子任务分别由三种插件执行实现,数据会依次经过这三个插件进行处理: -Pipe Source 用于抽取数据,Pipe Processor 用于处理数据,Pipe Sink 用于发送数据,最终数据将被发至外部系统。 - -**Pipe 任务的模型如下:** - -![任务模型图](/img/1706697228308.jpg) - -描述一个数据流处理任务,本质就是描述 Pipe Source、Pipe Processor 和 Pipe Sink 插件的属性。 -用户可以通过 SQL 语句声明式地配置三个子任务的具体属性,通过组合不同的属性,实现灵活的数据 ETL 能力。 - -利用流处理框架,可以搭建完整的数据链路来满足端*边云同步、异地灾备、读写负载分库*等需求。 - -## 自定义流处理插件开发 - -### 编程开发依赖 - -推荐采用 maven 构建项目,在`pom.xml`中添加以下依赖。请注意选择和 IoTDB 服务器版本相同的依赖版本。 - -```xml - - org.apache.iotdb - pipe-api - 1.3.1 - provided - -``` - -### 事件驱动编程模型 - -流处理插件的用户编程接口设计,参考了事件驱动编程模型的通用设计理念。事件(Event)是用户编程接口中的数据抽象,而编程接口与具体的执行方式解耦,只需要专注于描述事件(数据)到达系统后,系统期望的处理方式即可。 - -在流处理插件的用户编程接口中,事件是数据库数据写入操作的抽象。事件由单机流处理引擎捕获,按照流处理三个阶段的流程,依次传递至 PipeSource 插件,PipeProcessor 插件和 PipeSink 插件,并依次在三个插件中触发用户逻辑的执行。 - -为了兼顾端侧低负载场景下的流处理低延迟和端侧高负载场景下的流处理高吞吐,流处理引擎会动态地在操作日志和数据文件中选择处理对象,因此,流处理的用户编程接口要求用户提供下列两类事件的处理逻辑:操作日志写入事件 TabletInsertionEvent 和数据文件写入事件 TsFileInsertionEvent。 - -#### **操作日志写入事件(TabletInsertionEvent)** - -操作日志写入事件(TabletInsertionEvent)是对用户写入请求的高层数据抽象,它通过提供统一的操作接口,为用户提供了操纵写入请求底层数据的能力。 - -对于不同的数据库部署方式,操作日志写入事件对应的底层存储结构是不一样的。对于单机部署的场景,操作日志写入事件是对写前日志(WAL)条目的封装;对于分布式部署的场景,操作日志写入事件是对单个节点共识协议操作日志条目的封装。 - -对于数据库不同写入请求接口生成的写入操作,操作日志写入事件对应的请求结构体的数据结构也是不一样的。IoTDB 提供了 InsertRecord、InsertRecords、InsertTablet、InsertTablets 等众多的写入接口,每一种写入请求都使用了完全不同的序列化方式,生成的二进制条目也不尽相同。 - -操作日志写入事件的存在,为用户提供了一种统一的数据操作视图,它屏蔽了底层数据结构的实现差异,极大地降低了用户的编程门槛,提升了功能的易用性。 - -```java -/** TabletInsertionEvent is used to define the event of data insertion. */ -public interface TabletInsertionEvent extends Event { - - /** - * The consumer processes the data row by row and collects the results by RowCollector. - * - * @return {@code Iterable} a list of new TabletInsertionEvent contains the - * results collected by the RowCollector - */ - Iterable processRowByRow(BiConsumer consumer); - - /** - * The consumer processes the Tablet directly and collects the results by RowCollector. - * - * @return {@code Iterable} a list of new TabletInsertionEvent contains the - * results collected by the RowCollector - */ - Iterable processTablet(BiConsumer consumer); -} -``` - -#### **数据文件写入事件(TsFileInsertionEvent)** - -数据文件写入事件(TsFileInsertionEvent) 是对数据库文件落盘操作的高层抽象,它是若干操作日志写入事件(TabletInsertionEvent)的数据集合。 - -IoTDB 的存储引擎是 LSM 结构的。数据写入时会先将写入操作落盘到日志结构的文件里,同时将写入数据保存在内存里。当内存达到控制上限,则会触发刷盘行为,即将内存中的数据转换为数据库文件,同时删除之前预写的操作日志。当内存中的数据转换为数据库文件中的数据时,会经过编码压缩和通用压缩两次压缩处理,因此数据库文件的数据相比内存中的原始数据占用的空间更少。 - -在极端的网络情况下,直接传输数据文件相比传输数据写入的操作要更加经济,它会占用更低的网络带宽,能实现更快的传输速度。当然,天下没有免费的午餐,对文件中的数据进行计算处理,相比直接对内存中的数据进行计算处理时,需要额外付出文件 I/O 的代价。但是,正是磁盘数据文件和内存写入操作两种结构各有优劣的存在,给了系统做动态权衡调整的机会,也正是基于这样的观察,插件的事件模型中才引入了数据文件写入事件。 - -综上,数据文件写入事件出现在流处理插件的事件流中,存在下面两种情况: - -(1)历史数据抽取:一个流处理任务开始前,所有已经落盘的写入数据都会以 TsFile 的形式存在。一个流处理任务开始后,采集历史数据时,历史数据将以 TsFileInsertionEvent 作为抽象; - -(2)实时数据抽取:一个流处理任务进行时,当数据流中实时处理操作日志写入事件的速度慢于写入请求速度一定进度之后,未来得及处理的操作日志写入事件会被被持久化至磁盘,以 TsFile 的形式存在,这一些数据被流处理引擎抽取到后,会以 TsFileInsertionEvent 作为抽象。 - -```java -/** - * TsFileInsertionEvent is used to define the event of writing TsFile. Event data stores in disks, - * which is compressed and encoded, and requires IO cost for computational processing. - */ -public interface TsFileInsertionEvent extends Event { - - /** - * The method is used to convert the TsFileInsertionEvent into several TabletInsertionEvents. - * - * @return {@code Iterable} the list of TabletInsertionEvent - */ - Iterable toTabletInsertionEvents(); -} -``` - -### 自定义流处理插件编程接口定义 - -基于自定义流处理插件编程接口,用户可以轻松编写数据抽取插件、数据处理插件和数据发送插件,从而使得流处理功能灵活适配各种工业场景。 - -#### 数据抽取插件接口 - -数据抽取是流处理数据从数据抽取到数据发送三阶段的第一阶段。数据抽取插件(PipeSource)是流处理引擎和存储引擎的桥梁,它通过监听存储引擎的行为, -捕获各种数据写入事件。 - -```java -/** - * PipeSource - * - *

PipeSource is responsible for capturing events from sources. - * - *

Various data sources can be supported by implementing different PipeSource classes. - * - *

The lifecycle of a PipeSource is as follows: - * - *

    - *
  • When a collaboration task is created, the KV pairs of `WITH SOURCE` clause in SQL are - * parsed and the validation method {@link PipeSource#validate(PipeParameterValidator)} will - * be called to validate the parameters. - *
  • Before the collaboration task starts, the method {@link - * PipeSource#customize(PipeParameters, PipeSourceRuntimeConfiguration)} will be called to - * config the runtime behavior of the PipeSource. - *
  • Then the method {@link PipeSource#start()} will be called to start the PipeSource. - *
  • While the collaboration task is in progress, the method {@link PipeSource#supply()} will be - * called to capture events from sources and then the events will be passed to the - * PipeProcessor. - *
  • The method {@link PipeSource#close()} will be called when the collaboration task is - * cancelled (the `DROP PIPE` command is executed). - *
- */ -public interface PipeSource extends PipePlugin { - - /** - * This method is mainly used to validate {@link PipeParameters} and it is executed before {@link - * PipeSource#customize(PipeParameters, PipeSourceRuntimeConfiguration)} is called. - * - * @param validator the validator used to validate {@link PipeParameters} - * @throws Exception if any parameter is not valid - */ - void validate(PipeParameterValidator validator) throws Exception; - - /** - * This method is mainly used to customize PipeSource. In this method, the user can do the - * following things: - * - *
    - *
  • Use PipeParameters to parse key-value pair attributes entered by the user. - *
  • Set the running configurations in PipeSourceRuntimeConfiguration. - *
- * - *

This method is called after the method {@link PipeSource#validate(PipeParameterValidator)} - * is called. - * - * @param parameters used to parse the input parameters entered by the user - * @param configuration used to set the required properties of the running PipeSource - * @throws Exception the user can throw errors if necessary - */ - void customize(PipeParameters parameters, PipeSourceRuntimeConfiguration configuration) - throws Exception; - - /** - * Start the Source. After this method is called, events should be ready to be supplied by - * {@link PipeSource#supply()}. This method is called after {@link - * PipeSource#customize(PipeParameters, PipeSourceRuntimeConfiguration)} is called. - * - * @throws Exception the user can throw errors if necessary - */ - void start() throws Exception; - - /** - * Supply single event from the Source and the caller will send the event to the processor. - * This method is called after {@link PipeSource#start()} is called. - * - * @return the event to be supplied. the event may be null if the Source has no more events at - * the moment, but the Source is still running for more events. - * @throws Exception the user can throw errors if necessary - */ - Event supply() throws Exception; -} -``` - -#### 数据处理插件接口 - -数据处理是流处理数据从数据抽取到数据发送三阶段的第二阶段。数据处理插件(PipeProcessor)主要用于过滤和转换由数据抽取插件(PipeSource)捕获的 -各种事件。 - -```java -/** - * PipeProcessor - * - *

PipeProcessor is used to filter and transform the Event formed by the PipeSource. - * - *

The lifecycle of a PipeProcessor is as follows: - * - *

    - *
  • When a collaboration task is created, the KV pairs of `WITH PROCESSOR` clause in SQL are - * parsed and the validation method {@link PipeProcessor#validate(PipeParameterValidator)} - * will be called to validate the parameters. - *
  • Before the collaboration task starts, the method {@link - * PipeProcessor#customize(PipeParameters, PipeProcessorRuntimeConfiguration)} will be called - * to config the runtime behavior of the PipeProcessor. - *
  • While the collaboration task is in progress: - *
      - *
    • PipeSource captures the events and wraps them into three types of Event instances. - *
    • PipeProcessor processes the event and then passes them to the PipeSink. The - * following 3 methods will be called: {@link - * PipeProcessor#process(TabletInsertionEvent, EventCollector)}, {@link - * PipeProcessor#process(TsFileInsertionEvent, EventCollector)} and {@link - * PipeProcessor#process(Event, EventCollector)}. - *
    • PipeSink serializes the events into binaries and send them to sinks. - *
    - *
  • When the collaboration task is cancelled (the `DROP PIPE` command is executed), the {@link - * PipeProcessor#close() } method will be called. - *
- */ -public interface PipeProcessor extends PipePlugin { - - /** - * This method is mainly used to validate {@link PipeParameters} and it is executed before {@link - * PipeProcessor#customize(PipeParameters, PipeProcessorRuntimeConfiguration)} is called. - * - * @param validator the validator used to validate {@link PipeParameters} - * @throws Exception if any parameter is not valid - */ - void validate(PipeParameterValidator validator) throws Exception; - - /** - * This method is mainly used to customize PipeProcessor. In this method, the user can do the - * following things: - * - *
    - *
  • Use PipeParameters to parse key-value pair attributes entered by the user. - *
  • Set the running configurations in PipeProcessorRuntimeConfiguration. - *
- * - *

This method is called after the method {@link - * PipeProcessor#validate(PipeParameterValidator)} is called and before the beginning of the - * events processing. - * - * @param parameters used to parse the input parameters entered by the user - * @param configuration used to set the required properties of the running PipeProcessor - * @throws Exception the user can throw errors if necessary - */ - void customize(PipeParameters parameters, PipeProcessorRuntimeConfiguration configuration) - throws Exception; - - /** - * This method is called to process the TabletInsertionEvent. - * - * @param tabletInsertionEvent TabletInsertionEvent to be processed - * @param eventCollector used to collect result events after processing - * @throws Exception the user can throw errors if necessary - */ - void process(TabletInsertionEvent tabletInsertionEvent, EventCollector eventCollector) - throws Exception; - - /** - * This method is called to process the TsFileInsertionEvent. - * - * @param tsFileInsertionEvent TsFileInsertionEvent to be processed - * @param eventCollector used to collect result events after processing - * @throws Exception the user can throw errors if necessary - */ - default void process(TsFileInsertionEvent tsFileInsertionEvent, EventCollector eventCollector) - throws Exception { - for (final TabletInsertionEvent tabletInsertionEvent : - tsFileInsertionEvent.toTabletInsertionEvents()) { - process(tabletInsertionEvent, eventCollector); - } - } - - /** - * This method is called to process the Event. - * - * @param event Event to be processed - * @param eventCollector used to collect result events after processing - * @throws Exception the user can throw errors if necessary - */ - void process(Event event, EventCollector eventCollector) throws Exception; -} -``` - -#### 数据发送插件接口 - -数据发送是流处理数据从数据抽取到数据发送三阶段的第三阶段。数据发送插件(PipeSink)主要用于发送经由数据处理插件(PipeProcessor)处理过后的 -各种事件,它作为流处理框架的网络实现层,接口上应允许接入多种实时通信协议和多种连接器。 - -```java -/** - * PipeSink - * - *

PipeSink is responsible for sending events to sinks. - * - *

Various network protocols can be supported by implementing different PipeSink classes. - * - *

The lifecycle of a PipeSink is as follows: - * - *

    - *
  • When a collaboration task is created, the KV pairs of `WITH SINK` clause in SQL are - * parsed and the validation method {@link PipeSink#validate(PipeParameterValidator)} will be - * called to validate the parameters. - *
  • Before the collaboration task starts, the method {@link PipeSink#customize(PipeParameters, - * PipeSinkRuntimeConfiguration)} will be called to config the runtime behavior of the - * PipeSink and the method {@link PipeSink#handshake()} will be called to create a connection - * with sink. - *
  • While the collaboration task is in progress: - *
      - *
    • PipeSource captures the events and wraps them into three types of Event instances. - *
    • PipeProcessor processes the event and then passes them to the PipeSink. - *
    • PipeSink serializes the events into binaries and send them to sinks. The following 3 - * methods will be called: {@link PipeSink#transfer(TabletInsertionEvent)}, {@link - * PipeSink#transfer(TsFileInsertionEvent)} and {@link PipeSink#transfer(Event)}. - *
    - *
  • When the collaboration task is cancelled (the `DROP PIPE` command is executed), the {@link - * PipeSink#close() } method will be called. - *
- * - *

In addition, the method {@link PipeSink#heartbeat()} will be called periodically to check - * whether the connection with sink is still alive. The method {@link PipeSink#handshake()} will be - * called to create a new connection with the sink when the method {@link PipeSink#heartbeat()} - * throws exceptions. - */ -public interface PipeSink extends PipePlugin { - - /** - * This method is mainly used to validate {@link PipeParameters} and it is executed before {@link - * PipeSink#customize(PipeParameters, PipeSinkRuntimeConfiguration)} is called. - * - * @param validator the validator used to validate {@link PipeParameters} - * @throws Exception if any parameter is not valid - */ - void validate(PipeParameterValidator validator) throws Exception; - - /** - * This method is mainly used to customize PipeSink. In this method, the user can do the following - * things: - * - *

    - *
  • Use PipeParameters to parse key-value pair attributes entered by the user. - *
  • Set the running configurations in PipeSinkRuntimeConfiguration. - *
- * - *

This method is called after the method {@link PipeSink#validate(PipeParameterValidator)} is - * called and before the method {@link PipeSink#handshake()} is called. - * - * @param parameters used to parse the input parameters entered by the user - * @param configuration used to set the required properties of the running PipeSink - * @throws Exception the user can throw errors if necessary - */ - void customize(PipeParameters parameters, PipeSinkRuntimeConfiguration configuration) - throws Exception; - - /** - * This method is used to create a connection with sink. This method will be called after the - * method {@link PipeSink#customize(PipeParameters, PipeSinkRuntimeConfiguration)} is called or - * will be called when the method {@link PipeSink#heartbeat()} throws exceptions. - * - * @throws Exception if the connection is failed to be created - */ - void handshake() throws Exception; - - /** - * This method will be called periodically to check whether the connection with sink is still - * alive. - * - * @throws Exception if the connection dies - */ - void heartbeat() throws Exception; - - /** - * This method is used to transfer the TabletInsertionEvent. - * - * @param tabletInsertionEvent TabletInsertionEvent to be transferred - * @throws PipeConnectionException if the connection is broken - * @throws Exception the user can throw errors if necessary - */ - void transfer(TabletInsertionEvent tabletInsertionEvent) throws Exception; - - /** - * This method is used to transfer the TsFileInsertionEvent. - * - * @param tsFileInsertionEvent TsFileInsertionEvent to be transferred - * @throws PipeConnectionException if the connection is broken - * @throws Exception the user can throw errors if necessary - */ - default void transfer(TsFileInsertionEvent tsFileInsertionEvent) throws Exception { - try { - for (final TabletInsertionEvent tabletInsertionEvent : - tsFileInsertionEvent.toTabletInsertionEvents()) { - transfer(tabletInsertionEvent); - } - } finally { - tsFileInsertionEvent.close(); - } - } - - /** - * This method is used to transfer the generic events, including HeartbeatEvent. - * - * @param event Event to be transferred - * @throws PipeConnectionException if the connection is broken - * @throws Exception the user can throw errors if necessary - */ - void transfer(Event event) throws Exception; -} -``` - -## 自定义流处理插件管理 - -为了保证用户自定义插件在实际生产中的灵活性和易用性,系统还需要提供对插件进行动态统一管理的能力。 -本章节介绍的流处理插件管理语句提供了对插件进行动态统一管理的入口。 - -### 加载插件语句 - -在 IoTDB 中,若要在系统中动态载入一个用户自定义插件,则首先需要基于 PipeSource、 PipeProcessor 或者 PipeSink 实现一个具体的插件类, -然后需要将插件类编译打包成 jar 可执行文件,最后使用加载插件的管理语句将插件载入 IoTDB。 - -加载插件的管理语句的语法如图所示。 - -```sql -CREATE PIPEPLUGIN <别名> -AS <全类名> -USING -``` - -示例:假如用户实现了一个全类名为edu.tsinghua.iotdb.pipe.ExampleProcessor 的数据处理插件,打包后的jar包为 pipe-plugin.jar ,用户希望在流处理引擎中使用这个插件,将插件标记为 example。插件包有两种使用方式,一种为上传到URI服务器,一种为上传到集群本地目录,两种方法任选一种即可。 - -【方式一】上传到URI服务器 - -准备工作:使用该种方式注册,您需要提前将 JAR 包上传到 URI 服务器上并确保执行注册语句的IoTDB实例能够访问该 URI 服务器。例如 https://example.com:8080/iotdb/pipe-plugin.jar 。 - -创建语句: - -```sql -CREATE PIPEPLUGIN example -AS 'edu.tsinghua.iotdb.pipe.ExampleProcessor' -USING URI -``` - -【方式二】上传到集群本地目录 - -准备工作:使用该种方式注册,您需要提前将 JAR 包放置到DataNode节点所在机器的任意路径下,推荐您将JAR包放在IoTDB安装路径的/ext/pipe目录下(安装包中已有,无需新建)。例如:iotdb-1.x.x-bin/ext/pipe/pipe-plugin.jar。(**注意:如果您使用的是集群,那么需要将 JAR 包放置到每个 DataNode 节点所在机器的该路径下)** - -创建语句: - -```sql -CREATE PIPEPLUGIN example -AS 'edu.tsinghua.iotdb.pipe.ExampleProcessor' -USING URI -``` - -### 删除插件语句 - -当用户不再想使用一个插件,需要将插件从系统中卸载时,可以使用如图所示的删除插件语句。 - -```sql -DROP PIPEPLUGIN <别名> -``` - -### 查看插件语句 - -用户也可以按需查看系统中的插件。查看插件的语句如图所示。 - -```sql -SHOW PIPEPLUGINS -``` - -## 系统预置的流处理插件 - -### 预置 source 插件 - -#### iotdb-source - -作用:抽取 IoTDB 内部的历史或实时数据进入 pipe。 - - -| key | value | value 取值范围 | required or optional with default | -|---------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------|-----------------------------------| -| source | iotdb-source | String: iotdb-source | required | -| source.pattern | 用于筛选时间序列的路径前缀 | String: 任意的时间序列前缀 | optional: root | -| source.history.start-time | 抽取的历史数据的开始 event time,包含 start-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MIN_VALUE | -| source.history.end-time | 抽取的历史数据的结束 event time,包含 end-time | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MAX_VALUE | -| start-time(V1.3.1+) | start of synchronizing all data event time,including start-time. Will disable "history.start-time" "history.end-time" if configured | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MIN_VALUE | -| end-time(V1.3.1+) | end of synchronizing all data event time,including end-time. Will disable "history.start-time" "history.end-time" if configured | Long: [Long.MIN_VALUE, Long.MAX_VALUE] | optional: Long.MAX_VALUE | -| source.realtime.mode | 实时数据的抽取模式 | String: hybrid, log, file | optional: hybrid | -| source.forwarding-pipe-requests | 是否抽取由其他 Pipe (通常是数据同步)写入的数据 | Boolean: true, false | optional: true | - -> 🚫 **source.pattern 参数说明** -> -> * Pattern 需用反引号修饰不合法字符或者是不合法路径节点,例如如果希望筛选 root.\`a@b\` 或者 root.\`123\`,应设置 pattern 为 root.\`a@b\` 或者 root.\`123\`(具体参考 [单双引号和反引号的使用时机](https://iotdb.apache.org/zh/Download/#_1-0-版本不兼容的语法详细说明)) -> * 在底层实现中,当检测到 pattern 为 root(默认值)时,抽取效率较高,其他任意格式都将降低性能 -> * 路径前缀不需要能够构成完整的路径。例如,当创建一个包含参数为 'source.pattern'='root.aligned.1' 的 pipe 时: - > - > * root.aligned.1TS -> * root.aligned.1TS.\`1\` -> * root.aligned.100T - > - > 的数据会被抽取; - > - > * root.aligned.\`1\` -> * root.aligned.\`123\` - > - > 的数据不会被抽取。 - -> ❗️**source.history 的 start-time,end-time 参数说明** -> -> * start-time,end-time 应为 ISO 格式,例如 2011-12-03T10:15:30 或 2011-12-03T10:15:30+01:00 - -> ✅ **一条数据从生产到落库 IoTDB,包含两个关键的时间概念** -> -> * **event time:** 数据实际生产时的时间(或者数据生产系统给数据赋予的生成时间,是数据点中的时间项),也称为事件时间。 -> * **arrival time:** 数据到达 IoTDB 系统内的时间。 -> -> 我们常说的乱序数据,指的是数据到达时,其 **event time** 远落后于当前系统时间(或者已经落库的最大 **event time**)的数据。另一方面,不论是乱序数据还是顺序数据,只要它们是新到达系统的,那它们的 **arrival time** 都是会随着数据到达 IoTDB 的顺序递增的。 - -> 💎 **iotdb-source 的工作可以拆分成两个阶段** -> -> 1. 历史数据抽取:所有 **arrival time** < 创建 pipe 时**当前系统时间**的数据称为历史数据 -> 2. 实时数据抽取:所有 **arrival time** >= 创建 pipe 时**当前系统时间**的数据称为实时数据 -> -> 历史数据传输阶段和实时数据传输阶段,**两阶段串行执行,只有当历史数据传输阶段完成后,才执行实时数据传输阶段。** - -> 📌 **source.realtime.mode:数据抽取的模式** -> -> * log:该模式下,任务仅使用操作日志进行数据处理、发送 -> * file:该模式下,任务仅使用数据文件进行数据处理、发送 -> * hybrid:该模式,考虑了按操作日志逐条目发送数据时延迟低但吞吐低的特点,以及按数据文件批量发送时发送吞吐高但延迟高的特点,能够在不同的写入负载下自动切换适合的数据抽取方式,首先采取基于操作日志的数据抽取方式以保证低发送延迟,当产生数据积压时自动切换成基于数据文件的数据抽取方式以保证高发送吞吐,积压消除时自动切换回基于操作日志的数据抽取方式,避免了采用单一数据抽取算法难以平衡数据发送延迟或吞吐的问题。 - -> 🍕 **source.forwarding-pipe-requests:是否允许转发从另一 pipe 传输而来的数据** -> -> * 如果要使用 pipe 构建 A -> B -> C 的数据同步,那么 B -> C 的 pipe 需要将该参数为 true 后,A -> B 中 A 通过 pipe 写入 B 的数据才能被正确转发到 C -> * 如果要使用 pipe 构建 A \<-> B 的双向数据同步(双活),那么 A -> B 和 B -> A 的 pipe 都需要将该参数设置为 false,否则将会造成数据无休止的集群间循环转发 - -### 预置 processor 插件 - -#### do-nothing-processor - -作用:不对 source 传入的事件做任何的处理。 - - -| key | value | value 取值范围 | required or optional with default | -|-----------|----------------------|------------------------------|-----------------------------------| -| processor | do-nothing-processor | String: do-nothing-processor | required | - -### 预置 sink 插件 - -#### do-nothing-sink - -作用:不对 processor 传入的事件做任何的处理。 - - -| key | value | value 取值范围 | required or optional with default | -|------|-----------------|-------------------------|-----------------------------------| -| sink | do-nothing-sink | String: do-nothing-sink | required | - -## 流处理任务管理 - -### 创建流处理任务 - -使用 `CREATE PIPE` 语句来创建流处理任务。以数据同步流处理任务的创建为例,示例 SQL 语句如下: - -```sql -CREATE PIPE -- PipeId 是能够唯一标定流处理任务的名字 -WITH SOURCE ( - -- 默认的 IoTDB 数据抽取插件 - 'source' = 'iotdb-source', - -- 路径前缀,只有能够匹配该路径前缀的数据才会被抽取,用作后续的处理和发送 - 'source.pattern' = 'root.timecho', - -- 是否抽取历史数据 - 'source.history.enable' = 'true', - -- 描述被抽取的历史数据的时间范围,表示最早时间 - 'source.history.start-time' = '2011.12.03T10:15:30+01:00', - -- 描述被抽取的历史数据的时间范围,表示最晚时间 - 'source.history.end-time' = '2022.12.03T10:15:30+01:00', - -- 是否抽取实时数据 - 'source.realtime.enable' = 'true', - -- 描述实时数据的抽取方式 - 'source.realtime.mode' = 'hybrid', -) -WITH PROCESSOR ( - -- 默认的数据处理插件,即不做任何处理 - 'processor' = 'do-nothing-processor', -) -WITH SINK ( - -- IoTDB 数据发送插件,目标端为 IoTDB - 'sink' = 'iotdb-thrift-sink', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 ip - 'sink.ip' = '127.0.0.1', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 port - 'sink.port' = '6667', -) -``` - -**创建流处理任务时需要配置 PipeId 以及三个插件部分的参数:** - - -| 配置项 | 说明 | 是否必填 | 默认实现 | 默认实现说明 | 是否允许自定义实现 | -|-----------|--------------------------------|---------------------------|----------------------|------------------------------|--------------------------| -| PipeId | 全局唯一标定一个流处理任务的名称 | 必填 | - | - | - | -| source | Pipe Source 插件,负责在数据库底层抽取流处理数据 | 选填 | iotdb-source | 将数据库的全量历史数据和后续到达的实时数据接入流处理任务 | 否 | -| processor | Pipe Processor 插件,负责处理数据 | 选填 | do-nothing-processor | 对传入的数据不做任何处理 | | -| sink | Pipe Sink 插件,负责发送数据 | 必填 | - | - | | - -示例中,使用了 iotdb-source、do-nothing-processor 和 iotdb-thrift-sink 插件构建数据流处理任务。IoTDB 还内置了其他的流处理插件,**请查看“系统预置流处理插件”一节**。 - -**一个最简的 CREATE PIPE 语句示例如下:** - -```sql -CREATE PIPE -- PipeId 是能够唯一标定流处理任务的名字 -WITH SINK ( - -- IoTDB 数据发送插件,目标端为 IoTDB - 'sink' = 'iotdb-thrift-sink', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 ip - 'sink.ip' = '127.0.0.1', - -- 目标端 IoTDB 其中一个 DataNode 节点的数据服务 port - 'sink.port' = '6667', -) -``` - -其表达的语义是:将本数据库实例中的全量历史数据和后续到达的实时数据,同步到目标为 127.0.0.1:6667 的 IoTDB 实例上。 - -**注意:** - -- SOURCE 和 PROCESSOR 为选填配置,若不填写配置参数,系统则会采用相应的默认实现 -- SINK 为必填配置,需要在 CREATE PIPE 语句中声明式配置 -- SINK 具备自复用能力。对于不同的流处理任务,如果他们的 SINK 具备完全相同 KV 属性的(所有属性的 key 对应的 value 都相同),**那么系统最终只会创建一个 SINK 实例**,以实现对连接资源的复用。 - - - 例如,有下面 pipe1, pipe2 两个流处理任务的声明: - - ```sql - CREATE PIPE pipe1 - WITH SINK ( - 'sink' = 'iotdb-thrift-sink', - 'sink.ip' = 'localhost', - 'sink.port' = '9999', - ) - - CREATE PIPE pipe2 - WITH SINK ( - 'sink' = 'iotdb-thrift-sink', - 'sink.port' = '9999', - 'sink.ip' = 'localhost', - ) - ``` - - - 因为它们对 SINK 的声明完全相同(**即使某些属性声明时的顺序不同**),所以框架会自动对它们声明的 SINK 进行复用,最终 pipe1, pipe2 的 SINK 将会是同一个实例。 -- 在 source 为默认的 iotdb-source,且 source.forwarding-pipe-requests 为默认值 true 时,请不要构建出包含数据循环同步的应用场景(会导致无限循环): - - - IoTDB A -> IoTDB B -> IoTDB A - - IoTDB A -> IoTDB A - -### 启动流处理任务 - -CREATE PIPE 语句成功执行后,流处理任务相关实例会被创建,但整个流处理任务的运行状态会被置为 STOPPED,即流处理任务不会立刻处理数据(V1.3.0)。在 1.3.1 及以上的版本,流处理任务的运行状态在创建后将被立即置为 RUNNING。 - -可以使用 START PIPE 语句使流处理任务开始处理数据: - -```sql -START PIPE -``` - -### 停止流处理任务 - -使用 STOP PIPE 语句使流处理任务停止处理数据: - -```sql -STOP PIPE -``` - -### 删除流处理任务 - -使用 DROP PIPE 语句使流处理任务停止处理数据(当流处理任务状态为 RUNNING 时),然后删除整个流处理任务流处理任务: - -```sql -DROP PIPE -``` - -用户在删除流处理任务前,不需要执行 STOP 操作。 - -### 展示流处理任务 - -使用 SHOW PIPES 语句查看所有流处理任务: - -```sql -SHOW PIPES -``` - -查询结果如下: - -```sql -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -| ID| CreationTime | State|PipeSource|PipeProcessor|PipeSink|ExceptionMessage| -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -|iotdb-kafka|2022-03-30T20:58:30.689|RUNNING| ...| ...| ...| {}| -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -|iotdb-iotdb|2022-03-31T12:55:28.129|STOPPED| ...| ...| ...| TException: ...| -+-----------+-----------------------+-------+----------+-------------+--------+----------------+ -``` - -可以使用 `` 指定想看的某个流处理任务状态: - -```sql -SHOW PIPE -``` - -您也可以通过 where 子句,判断某个 \ 使用的 Pipe Sink 被复用的情况。 - -```sql -SHOW PIPES -WHERE SINK USED BY -``` - -### 流处理任务运行状态迁移 - -一个流处理 pipe 在其的生命周期中会经过多种状态: - -- **RUNNING:** pipe 正在正常工作 - - 当一个 pipe 被成功创建之后,其初始状态为工作状态(V1.3.1+) -- **STOPPED:** pipe 处于停止运行状态。当管道处于该状态时,有如下几种可能: - - 当一个 pipe 被成功创建之后,其初始状态为暂停状态(V1.3.0) - - 用户手动将一个处于正常运行状态的 pipe 暂停,其状态会被动从 RUNNING 变为 STOPPED - - 当一个 pipe 运行过程中出现无法恢复的错误时,其状态会自动从 RUNNING 变为 STOPPED -- **DROPPED:** pipe 任务被永久删除 - -下图表明了所有状态以及状态的迁移: - -![状态迁移图](/img/%E7%8A%B6%E6%80%81%E8%BF%81%E7%A7%BB%E5%9B%BE.png) - -## 权限管理 - -### 流处理任务 - - -| 权限名称 | 描述 | -|----------|---------------| -| USE_PIPE | 注册流处理任务。路径无关。 | -| USE_PIPE | 开启流处理任务。路径无关。 | -| USE_PIPE | 停止流处理任务。路径无关。 | -| USE_PIPE | 卸载流处理任务。路径无关。 | -| USE_PIPE | 查询流处理任务。路径无关。 | - -### 流处理任务插件 - - -| 权限名称 | 描述 | -|----------|-----------------| -| USE_PIPE | 注册流处理任务插件。路径无关。 | -| USE_PIPE | 卸载流处理任务插件。路径无关。 | -| USE_PIPE | 查询流处理任务插件。路径无关。 | - -## 配置参数 - -在 iotdb-common.properties 中: - -V1.3.0+: -```Properties -#################### -### Pipe Configuration -#################### - -# Uncomment the following field to configure the pipe lib directory. -# For Windows platform -# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is -# absolute. Otherwise, it is relative. -# pipe_lib_dir=ext\\pipe -# For Linux platform -# If its prefix is "/", then the path is absolute. Otherwise, it is relative. -# pipe_lib_dir=ext/pipe - -# The maximum number of threads that can be used to execute the pipe subtasks in PipeSubtaskExecutor. -# The actual value will be min(pipe_subtask_executor_max_thread_num, max(1, CPU core number / 2)). -# pipe_subtask_executor_max_thread_num=5 - -# The connection timeout (in milliseconds) for the thrift client. -# pipe_connector_timeout_ms=900000 - -# The maximum number of selectors that can be used in the async connector. -# pipe_async_connector_selector_number=1 - -# The core number of clients that can be used in the async connector. -# pipe_async_connector_core_client_number=8 - -# The maximum number of clients that can be used in the async connector. -# pipe_async_connector_max_client_number=16 - -# Whether to enable receiving pipe data through air gap. -# The receiver can only return 0 or 1 in tcp mode to indicate whether the data is received successfully. -# pipe_air_gap_receiver_enabled=false - -# The port for the server to receive pipe data through air gap. -# pipe_air_gap_receiver_port=9780 -``` - -V1.3.1+: -```Properties -# Uncomment the following field to configure the pipe lib directory. -# For Windows platform -# If its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\", then the path is -# absolute. Otherwise, it is relative. -# pipe_lib_dir=ext\\pipe -# For Linux platform -# If its prefix is "/", then the path is absolute. Otherwise, it is relative. -# pipe_lib_dir=ext/pipe - -# The maximum number of threads that can be used to execute the pipe subtasks in PipeSubtaskExecutor. -# The actual value will be min(pipe_subtask_executor_max_thread_num, max(1, CPU core number / 2)). -# pipe_subtask_executor_max_thread_num=5 - -# The connection timeout (in milliseconds) for the thrift client. -# pipe_sink_timeout_ms=900000 - -# The maximum number of selectors that can be used in the sink. -# Recommend to set this value to less than or equal to pipe_sink_max_client_number. -# pipe_sink_selector_number=4 - -# The maximum number of clients that can be used in the sink. -# pipe_sink_max_client_number=16 - -# Whether to enable receiving pipe data through air gap. -# The receiver can only return 0 or 1 in tcp mode to indicate whether the data is received successfully. -# pipe_air_gap_receiver_enabled=false - -# The port for the server to receive pipe data through air gap. -# pipe_air_gap_receiver_port=9780 -``` diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Syntax-Rule.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Syntax-Rule.md deleted file mode 100644 index e05c1c776..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Syntax-Rule.md +++ /dev/null @@ -1,289 +0,0 @@ - - -# 语法约定 -## 字面值常量 - -该部分对 IoTDB 中支持的字面值常量进行说明,包括字符串常量、数值型常量、时间戳常量、布尔型常量和空值。 - -### 字符串常量 - -在 IoTDB 中,字符串是由**单引号(`'`)或双引号(`"`)字符括起来的字符序列**。示例如下: - -``` -'a string' -"another string" -``` - -#### 使用场景 - -- `INSERT` 或者 `SELECT` 中用于表达 `TEXT` 类型数据的场景。 - - ```SQL - # insert 示例 - insert into root.ln.wf02.wt02(timestamp,hardware) values(1, 'v1') - insert into root.ln.wf02.wt02(timestamp,hardware) values(2, '\\') - - +-----------------------------+--------------------------+ - | Time|root.ln.wf02.wt02.hardware| - +-----------------------------+--------------------------+ - |1970-01-01T08:00:00.001+08:00| v1| - +-----------------------------+--------------------------+ - |1970-01-01T08:00:00.002+08:00| \\| - +-----------------------------+--------------------------+ - - # select 示例 - select code from root.sg1.d1 where code in ('string1', 'string2'); - ``` - -- `LOAD` / `REMOVE` / `SETTLE` 指令中的文件路径。 - - ```SQL - # load 示例 - LOAD 'examplePath' - - # remove 示例 - REMOVE 'examplePath' - - # SETTLE 示例 - SETTLE 'examplePath' - ``` - -- 用户密码。 - - ```SQL - # 示例,write_pwd 即为用户密码 - CREATE USER ln_write_user 'write_pwd' - ``` - -- 触发器和 UDF 中的类全类名,示例如下: - - ```SQL - # 触发器示例,AS 后使用字符串表示类全类名 - CREATE TRIGGER `alert-listener-sg1d1s1` - AFTER INSERT - ON root.sg1.d1.s1 - AS 'org.apache.iotdb.db.engine.trigger.example.AlertListener' - WITH ( - 'lo' = '0', - 'hi' = '100.0' - ) - - # UDF 示例,AS 后使用字符串表示类全类名 - CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample' - ``` - -- Select 子句中可以为结果集中的值指定别名,别名可以被定义为字符串或者标识符,示例如下: - - ```SQL - select s1 as 'temperature', s2 as 'speed' from root.ln.wf01.wt01; - - # 表头如下所示 - +-----------------------------+-----------|-----+ - | Time|temperature|speed| - +-----------------------------+-----------|-----+ - ``` - -- 用于表示键值对,键值对的键和值可以被定义成常量(包括字符串)或者标识符,具体请参考键值对章节。 - -#### 如何在字符串内使用引号 - -- 在单引号引起的字符串内,双引号无需特殊处理。同理,在双引号引起的字符串内,单引号无需特殊处理。 -- 在单引号引起的字符串里,可以通过双写单引号来表示一个单引号,即单引号 ' 可以表示为 ''。 -- 在双引号引起的字符串里,可以通过双写双引号来表示一个双引号,即双引号 " 可以表示为 ""。 - -字符串内使用引号的示例如下: - -``` -'string' // string -'"string"' // "string" -'""string""' // ""string"" -'''string' // 'string - -"string" // string -"'string'" // 'string' -"''string''" // ''string'' -"""string" // "string -``` - -### 数值型常量 - -数值型常量包括整型和浮点型。 - -整型常量是一个数字序列。可以以 `+` 或 `-` 开头表示正负。例如:`1`, `-1`。 - -带有小数部分或由科学计数法表示的为浮点型常量,例如:`.1`, `3.14`, `-2.23`, `+1.70`, `1.2E3`, `1.2E-3`, `-1.2E3`, `-1.2E-3`。 - -在 IoTDB 中,`INT32` 和 `INT64` 表示整数类型(计算是准确的),`FLOAT` 和 `DOUBLE` 表示浮点数类型(计算是近似的)。 - -在浮点上下文中可以使用整数,它会被解释为等效的浮点数。 - -### 时间戳常量 - -时间戳是一个数据到来的时间点,在 IoTDB 中分为绝对时间戳和相对时间戳。详细信息可参考 [数据类型文档](../Basic-Concept/Data-Type.md)。 - -特别地,`NOW()`表示语句开始执行时的服务端系统时间戳。 - -### 布尔型常量 - -布尔值常量 `TRUE` 和 `FALSE` 分别等价于 `1` 和 `0`,它们对大小写不敏感。 - -### 空值 - -`NULL`值表示没有数据。`NULL`对大小写不敏感。 - -## 标识符 - -### 使用场景 - -在 IoTDB 中,触发器名称、UDF函数名、元数据模板名称、用户与角色名、连续查询标识、Pipe、PipeSink、键值对中的键和值、别名等可以作为标识符。 - -### 约束 - -请注意,此处约束是标识符的通用约束,具体标识符可能还附带其它约束条件,如用户名限制字符数大于等于4,更严格的约束请参考具体标识符相关的说明文档。 - -**标识符命名有以下约束:** - -- 不使用反引号括起的标识符中,允许出现以下字符: - - [ 0-9 a-z A-Z _ ] (字母,数字,下划线) - - ['\u2E80'..'\u9FFF'] (UNICODE 中文字符) - -- 标识符允许使用数字开头、不使用反引号括起的标识符不能全部为数字。 - -- 标识符是大小写敏感的。 - -- 标识符允许为关键字。 - -**如果出现如下情况,标识符需要使用反引号进行引用:** - -- 标识符包含不允许的特殊字符。 -- 标识符为实数。 - -### 如何在反引号引起的标识符中使用引号 - -**在反引号引起的标识符中可以直接使用单引号和双引号。** - -**在用反引号引用的标识符中,可以通过双写反引号的方式使用反引号,即 ` 可以表示为 ``**,示例如下: - -```SQL -# 创建模板 t1`t -create device template `t1``t` -(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY) - -# 创建模板 t1't"t -create device template `t1't"t` -(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY) -``` - -### 特殊情况示例 - -需要使用反引号进行引用的部分情况示例: - -- 触发器名称出现上述特殊情况时需使用反引号引用: - - ```sql - # 创建触发器 alert.`listener-sg1d1s1 - CREATE TRIGGER `alert.``listener-sg1d1s1` - AFTER INSERT - ON root.sg1.d1.s1 - AS 'org.apache.iotdb.db.engine.trigger.example.AlertListener' - WITH ( - 'lo' = '0', - 'hi' = '100.0' - ) - ``` - -- UDF 名称出现上述特殊情况时需使用反引号引用: - - ```sql - # 创建名为 111 的 UDF,111 为实数,所以需要用反引号引用。 - CREATE FUNCTION `111` AS 'org.apache.iotdb.udf.UDTFExample' - ``` - -- 元数据模板名称出现上述特殊情况时需使用反引号引用: - - ```sql - # 创建名为 111 的元数据模板,111 为实数,需要用反引号引用。 - create device template `111` - (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY) - ``` - -- 用户名、角色名出现上述特殊情况时需使用反引号引用,同时无论是否使用反引号引用,用户名、角色名中均不允许出现空格,具体请参考权限管理章节中的说明。 - - ```sql - # 创建用户 special`user. - CREATE USER `special``user.` 'write_pwd' - - # 创建角色 111 - CREATE ROLE `111` - ``` - -- 连续查询标识出现上述特殊情况时需使用反引号引用: - - ```sql - # 创建连续查询 test.cq - CREATE CONTINUOUS QUERY `test.cq` - BEGIN - SELECT max_value(temperature) - INTO temperature_max - FROM root.ln.*.* - GROUP BY time(10s) - END - ``` - -- Pipe、PipeSink 名称出现上述特殊情况时需使用反引号引用: - - ```sql - # 创建 PipeSink test.*1 - CREATE PIPESINK `test.*1` AS IoTDB ('ip' = '输入你的IP') - - # 创建 Pipe test.*2 - CREATE PIPE `test.*2` TO `test.*1` FROM - (select ** from root WHERE time>=yyyy-mm-dd HH:MM:SS) WITH 'SyncDelOp' = 'true' - ``` - -- Select 子句中可以结果集中的值指定别名,别名可以被定义为字符串或者标识符,示例如下: - - ```sql - select s1 as temperature, s2 as speed from root.ln.wf01.wt01; - # 表头如下所示 - +-----------------------------+-----------+-----+ - | Time|temperature|speed| - +-----------------------------+-----------+-----+ - ``` - -- 用于表示键值对,键值对的键和值可以被定义成常量(包括字符串)或者标识符,具体请参考键值对章节。 - -- 路径中非database的节点允许含有“*”符号,在使用时需要把该节点用反引号括起来,如root.db.`*`,但是此种用法只建议在路径中不可避免含有“*”时使用。 - -## 关键字 - -关键字是在 SQL 具有特定含义的词,可以作为标识符。保留字是关键字的一个子集,保留字不能用于标识符。 - -关于 IoTDB 的关键字列表,可以查看 [关键字](../Reference/Keywords.md) 。 - -## 词法与文法详细定义 - -请阅读代码仓库中的词法和语法描述文件: - -词法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlLexer.g4` - -语法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4` diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Tiered-Storage_timecho.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Tiered-Storage_timecho.md deleted file mode 100644 index eafaee494..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Tiered-Storage_timecho.md +++ /dev/null @@ -1,97 +0,0 @@ - - -# 多级存储 -## 概述 - -多级存储功能向用户提供多种存储介质管理的能力,用户可以使用多级存储功能为 IoTDB 配置不同类型的存储介质,并为存储介质进行分级。具体的,在 IoTDB 中,多级存储的配置体现为多目录的管理。用户可以将多个存储目录归为同一类,作为一个“层级”向 IoTDB 中配置,这种“层级”我们称之为 storage tier;同时,用户可以根据数据的冷热进行分类,并将不同类别的数据存储到指定的“层级”中。当前 IoTDB 支持通过数据的 TTL 进行冷热数据的分类,当一个层级中的数据不满足当前层级定义的 TTL 规则时,该数据会被自动迁移至下一层级中。 - -## 参数定义 - -在 IoTDB 中开启多级存储,需要进行以下几个方面的配置: - -1. 配置数据目录,并将数据目录分为不同的层级 -2. 配置每个层级所管理的数据的 TTL,以区分不同层级管理的冷热数据类别。 -3. 配置每个层级的最小剩余存储空间比例,当该层级的存储空间触发该阈值时,该层级的数据会被自动迁移至下一层级(可选)。 - -具体的参数定义及其描述如下。 - -| 配置项 | 默认值 | 说明 | 约束 | -| ---------------------------------------- | ------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -| dn_data_dirs | data/datanode/data | 用来指定不同的存储目录,并将存储目录进行层级划分 | 每级存储使用分号分隔,单级内使用逗号分隔;云端配置只能作为最后一级存储且第一级不能作为云端存储;最多配置一个云端对象;远端存储目录使用 OBJECT_STORAGE 来表示 | -| default_ttl_in_ms | -1 | 定义每个层级负责的数据范围,通过 TTL 表示 | 每级存储使用分号分隔;层级数量需与 dn_data_dirs 定义的层级数一致;"-1" 表示"无限制" | -| dn_default_space_move_thresholds(V1.3.0/1) | 0.15 | 定义每个层级数据目录的最小剩余空间比例;当剩余空间少于该比例时,数据会被自动迁移至下一个层级;当最后一个层级的剩余存储空间到低于此阈值时,会将系统置为 READ_ONLY | 每级存储使用分号分隔;层级数量需与 dn_data_dirs 定义的层级数一致 | -| dn_default_space_usage_thresholds(V1.3.2) | 0.85 | 定义每个层级数据目录的最小剩余空间比例;当剩余空间少于该比例时,数据会被自动迁移至下一个层级;当最后一个层级的剩余存储空间到低于此阈值时,会将系统置为 READ_ONLY | 每级存储使用分号分隔;层级数量需与 dn_data_dirs 定义的层级数一致 | -| object_storage_type | AWS_S3 | 云端存储类型 | IoTDB 当前只支持 AWS S3 作为远端存储类型,此参数不支持修改 | -| object_storage_bucket | iotdb_data | 云端存储 bucket 的名称 | AWS S3 中的 bucket 定义;如果未使用远端存储,无需配置 | -| object_storage_endpoiont | | 云端存储的 endpoint | AWS S3 的 endpoint;如果未使用远端存储,无需配置 | -| object_storage_access_key | | 云端存储的验证信息 key | AWS S3 的 credential key;如果未使用远端存储,无需配置 | -| object_storage_access_secret | | 云端存储的验证信息 secret | AWS S3 的 credential secret;如果未使用远端存储,无需配置 | -| remote_tsfile_cache_dirs | data/datanode/data/cache | 云端存储在本地的缓存目录 | 如果未使用远端存储,无需配置 | -| remote_tsfile_cache_page_size_in_kb | 20480 | 云端存储在本地缓存文件的块大小 | 如果未使用远端存储,无需配置 | -| remote_tsfile_cache_max_disk_usage_in_mb | 51200 | 云端存储本地缓存的最大磁盘占用大小 | 如果未使用远端存储,无需配置 | - -## 本地多级存储配置示例 - -以下以本地两级存储的配置示例。 - -```JavaScript -// 必须配置项 -dn_data_dirs=/data1/data;/data2/data,/data3/data; -default_ttl_in_ms=86400000;-1 -dn_default_space_move_thresholds=0.2;0.1 -``` - -在该示例中,共配置了两个层级的存储,具体为: - -| **层级** | **数据目录** | **数据范围** | **磁盘最小剩余空间阈值** | -| -------- | -------------------------------------- | --------------- | ------------------------ | -| 层级一 | 目录一:/data1/data | 最近 1 天的数据 | 20% | -| 层级二 | 目录一:/data2/data目录二:/data3/data | 1 天以前的数据 | 10% | - -## 远端多级存储配置示例 - -以下以三级存储为例: - -```JavaScript -// 必须配置项 -dn_data_dirs=/data1/data;/data2/data,/data3/data;OBJECT_STORAGE -default_ttl_in_ms=86400000;864000000;-1 -dn_default_space_move_thresholds=0.2;0.15;0.1 -object_storage_name=AWS_S3 -object_storage_bucket=iotdb -object_storage_endpoiont= -object_storage_access_key= -object_storage_access_secret= - -// 可选配置项 -remote_tsfile_cache_dirs=data/datanode/data/cache -remote_tsfile_cache_page_size_in_kb=20971520 -remote_tsfile_cache_max_disk_usage_in_mb=53687091200 -``` - -在该示例中,共配置了三个层级的存储,具体为: - -| **层级** | **数据目录** | **数据范围** | **磁盘最小剩余空间阈值** | -| -------- | -------------------------------------- | ---------------------------- | ------------------------ | -| 层级一 | 目录一:/data1/data | 最近 1 天的数据 | 20% | -| 层级二 | 目录一:/data2/data目录二:/data3/data | 过去1 天至过去 10 天内的数据 | 15% | -| 层级三 | 远端 AWS S3 存储 | 过去 10 天以前的数据 | 10% | \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/User-defined-function.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/User-defined-function.md deleted file mode 100644 index c74a5f86f..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/User-defined-function.md +++ /dev/null @@ -1,210 +0,0 @@ -# 用户自定义函数 - -## 1. UDF 介绍 - -UDF(User Defined Function)即用户自定义函数,IoTDB 提供多种内建的面向时序处理的函数,也支持扩展自定义函数来满足更多的计算需求。 - -IoTDB 支持两种类型的 UDF 函数,如下表所示。 - - - - - - - - - - - - - - - - - - - - - - -
UDF 分类数据访问策略描述
UDTFMAPPABLE_ROW_BY_ROW自定义标量函数,输入 k 列时间序列 1 行数据,输出 1 列时间序列 1 行数据,可用于标量函数出现的任何子句和表达式中,如select子句、where子句等。
ROW_BY_ROW
SLIDING_TIME_WINDOW
SLIDING_SIZE_WINDOW
SESSION_TIME_WINDOW
STATE_WINDOW
自定义时间序列生成函数,输入 k 列时间序列 m 行数据,输出 1 列时间序列 n 行数据,输入行数 m 可以与输出行数 n 不相同,只能用于SELECT子句中。
UDAF-自定义聚合函数,输入 k 列时间序列 m 行数据,输出 1 列时间序列 1 行数据,可用于聚合函数出现的任何子句和表达式中,如select子句、having子句等。
- -### 1.1 UDF 使用 - -UDF 的使用方法与普通内建函数类似,可以直接在 SELECT 语句中像调用普通函数一样使用UDF。 - -#### 1.支持的基础 SQL 语法 - -* `SLIMIT` / `SOFFSET` -* `LIMIT` / `OFFSET` -* 支持值过滤 -* 支持时间过滤 - - -#### 2. 带 * 查询 - -假定现在有时间序列 `root.sg.d1.s1`和 `root.sg.d1.s2`。 - -* **执行`SELECT example(*) from root.sg.d1`** - -那么结果集中将包括`example(root.sg.d1.s1)`和`example(root.sg.d1.s2)`的结果。 - -* **执行`SELECT example(s1, *) from root.sg.d1`** - -那么结果集中将包括`example(root.sg.d1.s1, root.sg.d1.s1)`和`example(root.sg.d1.s1, root.sg.d1.s2)`的结果。 - -* **执行`SELECT example(*, *) from root.sg.d1`** - -那么结果集中将包括`example(root.sg.d1.s1, root.sg.d1.s1)`,`example(root.sg.d1.s2, root.sg.d1.s1)`,`example(root.sg.d1.s1, root.sg.d1.s2)` 和 `example(root.sg.d1.s2, root.sg.d1.s2)`的结果。 - -#### 3. 带自定义输入参数的查询 - -可以在进行 UDF 查询的时候,向 UDF 传入任意数量的键值对参数。键值对中的键和值都需要被单引号或者双引号引起来。注意,键值对参数只能在所有时间序列后传入。下面是一组例子: - - 示例: -``` sql -SELECT example(s1, 'key1'='value1', 'key2'='value2'), example(*, 'key3'='value3') FROM root.sg.d1; -SELECT example(s1, s2, 'key1'='value1', 'key2'='value2') FROM root.sg.d1; -``` - -#### 4. 与其他查询的嵌套查询 - - 示例: -``` sql -SELECT s1, s2, example(s1, s2) FROM root.sg.d1; -SELECT *, example(*) FROM root.sg.d1 DISABLE ALIGN; -SELECT s1 * example(* / s1 + s2) FROM root.sg.d1; -SELECT s1, s2, s1 + example(s1, s2), s1 - example(s1 + example(s1, s2) / s2) FROM root.sg.d1; -``` - - -## 2. UDF 开发 - -可以参考 UDF函数开发:[开发指导](../Reference/UDF-development.md) - -## 3. UDF 管理 - -### 3.1 UDF 注册 - -注册一个 UDF 可以按如下流程进行: - -1. 实现一个完整的 UDF 类,假定这个类的全类名为`org.apache.iotdb.udf.UDTFExample` -2. 将项目打成 JAR 包,如果使用 Maven 管理项目,可以参考 [Maven 项目示例](https://github.com/apache/iotdb/tree/master/example/udf)的写法 -3. 进行注册前的准备工作,根据注册方式的不同需要做不同的准备,具体可参考以下例子 -4. 使用以下 SQL 语句注册 UDF - -```sql -CREATE FUNCTION AS (USING URI URI-STRING) -``` - -#### 示例:注册名为`example`的 UDF,以下两种注册方式任选其一即可 - -#### 方式一:手动放置jar包 - -准备工作: -使用该种方式注册时,需要提前将 JAR 包放置到集群所有节点的 `ext/udf`目录下(该目录可配置)。 - -注册语句: - -```sql -CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample' -``` - -#### 方式二:集群通过URI自动安装jar包 - -准备工作: -使用该种方式注册时,需要提前将 JAR 包上传到 URI 服务器上并确保执行注册语句的 IoTDB 实例能够访问该 URI 服务器。 - -注册语句: - -```sql -CREATE FUNCTION example AS 'org.apache.iotdb.udf.UDTFExample' USING URI 'http://jar/example.jar' -``` - -IoTDB 会下载 JAR 包并同步到整个集群。 - -#### 注意 - -1. 由于 IoTDB 的 UDF 是通过反射技术动态装载的,因此在装载过程中无需启停服务器。 - -2. UDF 函数名称是大小写不敏感的。 - -3. 请不要给 UDF 函数注册一个内置函数的名字。使用内置函数的名字给 UDF 注册会失败。 - -4. 不同的 JAR 包中最好不要有全类名相同但实现功能逻辑不一样的类。例如 UDF(UDAF/UDTF):`udf1`、`udf2`分别对应资源`udf1.jar`、`udf2.jar`。如果两个 JAR 包里都包含一个`org.apache.iotdb.udf.UDTFExample`类,当同一个 SQL 中同时使用到这两个 UDF 时,系统会随机加载其中一个类,导致 UDF 执行行为不一致。 - -### 3.2 UDF 卸载 - -SQL 语法如下: - -```sql -DROP FUNCTION -``` - -示例:卸载上述例子的 UDF: - -```sql -DROP FUNCTION example -``` - - -### 3.3 查看所有注册的 UDF - -``` sql -SHOW FUNCTIONS -``` - -### 3.4 UDF 配置 - -- 允许在 `iotdb-common.properties` 中配置 udf 的存储目录.: - ``` Properties -# UDF lib dir - -udf_lib_dir=ext/udf -``` - -- 使用自定义函数时,提示内存不足,更改 `iotdb-common.properties` 中下述配置参数并重启服务。 - ``` Properties - -# Used to estimate the memory usage of text fields in a UDF query. -# It is recommended to set this value to be slightly larger than the average length of all text -# effectiveMode: restart -# Datatype: int -udf_initial_byte_array_length_for_memory_control=48 - -# How much memory may be used in ONE UDF query (in MB). -# The upper limit is 20% of allocated memory for read. -# effectiveMode: restart -# Datatype: float -udf_memory_budget_in_mb=30.0 - -# UDF memory allocation ratio. -# The parameter form is a:b:c, where a, b, and c are integers. -# effectiveMode: restart -udf_reader_transformer_collector_memory_proportion=1:1:1 -``` - -### 3.5 UDF 用户权限 - -用户在使用 UDF 时会涉及到 `USE_UDF` 权限,具备该权限的用户才被允许执行 UDF 注册、卸载和查询操作。 - -更多用户权限相关的内容,请参考 [权限管理语句](./Authority-Management.md##权限管理)。 - - -## 4. UDF 函数库 - -基于用户自定义函数能力,IoTDB 提供了一系列关于时序数据处理的函数,包括数据质量、数据画像、异常检测、 频域分析、数据匹配、数据修复、序列发现、机器学习等,能够满足工业领域对时序数据处理的需求。 - -可以参考 [UDF 函数库](../Reference/UDF-Libraries.md)文档,查找安装步骤及每个函数对应的注册语句,以确保正确注册所有需要的函数。 - -## 5. 常见问题: - -1. 如何修改已经注册的 UDF? - -答:假设 UDF 的名称为`example`,全类名为`org.apache.iotdb.udf.UDTFExample`,由`example.jar`引入 - -1. 首先卸载已经注册的`example`函数,执行`DROP FUNCTION example` -2. 删除 `iotdb-server-1.0.0-all-bin/ext/udf` 目录下的`example.jar` -3. 修改`org.apache.iotdb.udf.UDTFExample`中的逻辑,重新打包,JAR 包的名字可以仍然为`example.jar` -4. 将新的 JAR 包上传至 `iotdb-server-1.0.0-all-bin/ext/udf` 目录下 -5. 装载新的 UDF,执行`CREATE FUNCTION example AS "org.apache.iotdb.udf.UDTFExample"` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Write-Delete-Data.md b/src/zh/UserGuide/V1.3.0-2/User-Manual/Write-Delete-Data.md deleted file mode 100644 index 8689c95f3..000000000 --- a/src/zh/UserGuide/V1.3.0-2/User-Manual/Write-Delete-Data.md +++ /dev/null @@ -1,258 +0,0 @@ - - - -# 数据写入与删除 -## CLI写入数据 - -IoTDB 为用户提供多种插入实时数据的方式,例如在 [Cli/Shell 工具](../Tools-System/CLI.md) 中直接输入插入数据的 INSERT 语句,或使用 Java API(标准 [Java JDBC](../API/Programming-JDBC.md) 接口)单条或批量执行插入数据的 INSERT 语句。 - -本节主要为您介绍实时数据接入的 INSERT 语句在场景中的实际使用示例,有关 INSERT SQL 语句的详细语法请参见本文 [INSERT 语句](../SQL-Manual/SQL-Manual.md#写入数据) 节。 - -注:写入重复时间戳的数据则原时间戳数据被覆盖,可视为更新数据。 - -### 使用 INSERT 语句 - -使用 INSERT 语句可以向指定的已经创建的一条或多条时间序列中插入数据。对于每一条数据,均由一个时间戳类型的时间戳和一个数值或布尔值、字符串类型的传感器采集值组成。 - -**无模式写入**:可以在未定义元数据时, 通过 insert 语句直接写入数据,数据库中将自动识别并注册所需的元数据,实现自动建模。 - -在本节的场景实例下,以其中的两个时间序列`root.ln.wf02.wt02.status`和`root.ln.wf02.wt02.hardware`为例 ,它们的数据类型分别为 BOOLEAN 和 TEXT。 - -单列数据插入示例代码如下: - -```sql -IoTDB > insert into root.ln.wf02.wt02(timestamp,status) values(1,true) -IoTDB > insert into root.ln.wf02.wt02(timestamp,hardware) values(1, 'v1') -``` - -以上示例代码将长整型的 timestamp 以及值为 true 的数据插入到时间序列`root.ln.wf02.wt02.status`中和将长整型的 timestamp 以及值为”v1”的数据插入到时间序列`root.ln.wf02.wt02.hardware`中。执行成功后会返回执行时间,代表数据插入已完成。 - -> 注意:在 IoTDB 中,TEXT 类型的数据单双引号都可以来表示,上面的插入语句是用的是双引号表示 TEXT 类型数据,下面的示例将使用单引号表示 TEXT 类型数据。 - -INSERT 语句还可以支持在同一个时间点下多列数据的插入,同时向 2 时间点插入上述两个时间序列的值,多列数据插入示例代码如下: - -```sql -IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) values (2, false, 'v2') -``` - -此外,INSERT 语句支持一次性插入多行数据,同时向 2 个不同时间点插入上述时间序列的值,示例代码如下: - -```sql -IoTDB > insert into root.ln.wf02.wt02(timestamp, status, hardware) VALUES (3, false, 'v3'),(4, true, 'v4') -``` - -插入数据后我们可以使用 SELECT 语句简单查询已插入的数据。 - -```sql -IoTDB > select * from root.ln.wf02.wt02 where time < 5 -``` - -结果如图所示。由查询结果可以看出,单列、多列数据的插入操作正确执行。 - -``` -+-----------------------------+--------------------------+------------------------+ -| Time|root.ln.wf02.wt02.hardware|root.ln.wf02.wt02.status| -+-----------------------------+--------------------------+------------------------+ -|1970-01-01T08:00:00.001+08:00| v1| true| -|1970-01-01T08:00:00.002+08:00| v2| false| -|1970-01-01T08:00:00.003+08:00| v3| false| -|1970-01-01T08:00:00.004+08:00| v4| true| -+-----------------------------+--------------------------+------------------------+ -Total line number = 4 -It costs 0.004s -``` - -此外,我们可以省略 timestamp 列,此时系统将使用当前的系统时间作为该数据点的时间戳,示例代码如下: -```sql -IoTDB > insert into root.ln.wf02.wt02(status, hardware) values (false, 'v2') -``` -**注意:** 当一次插入多行数据时必须指定时间戳。 - -### 向对齐时间序列插入数据 - -向对齐时间序列插入数据只需在SQL中增加`ALIGNED`关键词,其他类似。 - -示例代码如下: - -```sql -IoTDB > create aligned timeseries root.sg1.d1(s1 INT32, s2 DOUBLE) -IoTDB > insert into root.sg1.d1(time, s1, s2) aligned values(1, 1, 1) -IoTDB > insert into root.sg1.d1(time, s1, s2) aligned values(2, 2, 2), (3, 3, 3) -IoTDB > select * from root.sg1.d1 -``` - -结果如图所示。由查询结果可以看出,数据的插入操作正确执行。 - -``` -+-----------------------------+--------------+--------------+ -| Time|root.sg1.d1.s1|root.sg1.d1.s2| -+-----------------------------+--------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 1| 1.0| -|1970-01-01T08:00:00.002+08:00| 2| 2.0| -|1970-01-01T08:00:00.003+08:00| 3| 3.0| -+-----------------------------+--------------+--------------+ -Total line number = 3 -It costs 0.004s -``` - -## 原生接口写入 -原生接口 (Session) 是目前IoTDB使用最广泛的系列接口,包含多种写入接口,适配不同的数据采集场景,性能高效且支持多语言。 - -### 多语言接口写入 -* ### Java - 使用Java接口写入之前,你需要先建立连接,参考 [Java原生接口](../API/Programming-Java-Native-API.md)。 - 之后通过 [ JAVA 数据操作接口(DML)](../API/Programming-Java-Native-API.md#数据写入)写入。 - -* ### Python - 参考 [ Python 数据操作接口(DML)](../API/Programming-Python-Native-API.md#数据写入) - -* ### C++ - 参考 [ C++ 数据操作接口(DML)](../API/Programming-Cpp-Native-API.md) - -* ### Go - 参考 [Go 原生接口](../API/Programming-Go-Native-API.md) - -## REST API写入 - -参考 [insertTablet (v1)](../API/RestServiceV1.md#inserttablet) or [insertTablet (v2)](../API/RestServiceV2.md#inserttablet) - -示例如下: -```JSON -{ -      "timestamps": [ -            1, -            2, -            3 -      ], -      "measurements": [ -            "temperature", -            "status" -      ], -      "data_types": [ -            "FLOAT", -            "BOOLEAN" -      ], -      "values": [ -            [ -                  1.1, -                  2.2, -                  3.3 -            ], -            [ -                  false, -                  true, -                  true -            ] -      ], -      "is_aligned": false, -      "device": "root.ln.wf01.wt01" -} -``` - -## MQTT写入 - -参考 [内置 MQTT 服务](../API/Programming-MQTT.md#内置-mqtt-服务) - -## 批量数据导入 - -针对于不同场景,IoTDB 为用户提供多种批量导入数据的操作方式,本章节向大家介绍最为常用的两种方式为 CSV文本形式的导入 和 TsFile文件形式的导入。 - -### TsFile批量导入 - -TsFile 是在 IoTDB 中使用的时间序列的文件格式,您可以通过CLI等工具直接将存有时间序列的一个或多个 TsFile 文件导入到另外一个正在运行的IoTDB实例中。具体操作方式请参考[导入导出工具](../Tools-System/TsFile-Import-Export-Tool.md)。 - -### CSV批量导入 - -CSV 是以纯文本形式存储表格数据,您可以在CSV文件中写入多条格式化的数据,并批量的将这些数据导入到 IoTDB 中,在导入数据之前,建议在IoTDB中创建好对应的元数据信息。如果忘记创建元数据也不要担心,IoTDB 可以自动将CSV中数据推断为其对应的数据类型,前提是你每一列的数据类型必须唯一。除单个文件外,此工具还支持以文件夹的形式导入多个 CSV 文件,并且支持设置如时间精度等优化参数。具体操作方式请参考[导入导出工具](../Tools-System/Data-Import-Export-Tool.md)。 - -## 删除数据 - -用户使用 [DELETE 语句](../SQL-Manual/SQL-Manual.md#删除数据) 可以删除指定的时间序列中符合时间删除条件的数据。在删除数据时,用户可以选择需要删除的一个或多个时间序列、时间序列的前缀、时间序列带、*路径对某一个时间区间内的数据进行删除。 - -在 JAVA 编程环境中,您可以使用 JDBC API 单条或批量执行 DELETE 语句。 - -### 单传感器时间序列值删除 - -以测控 ln 集团为例,存在这样的使用场景: - -wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态出现多段错误,且无法分析其正确数据,错误数据影响了与其他设备的关联分析。此时,需要将此时间段前的数据删除。进行此操作的 SQL 语句为: - -```sql -delete from root.ln.wf02.wt02.status where time<=2017-11-01T16:26:00; -``` - -如果我们仅仅想要删除 2017 年内的在 2017-11-01 16:26:00 之前的数据,可以使用以下 SQL: -```sql -delete from root.ln.wf02.wt02.status where time>=2017-01-01T00:00:00 and time<=2017-11-01T16:26:00; -``` - -IoTDB 支持删除一个时间序列任何一个时间范围内的所有时序点,用户可以使用以下 SQL 语句指定需要删除的时间范围: -```sql -delete from root.ln.wf02.wt02.status where time < 10 -delete from root.ln.wf02.wt02.status where time <= 10 -delete from root.ln.wf02.wt02.status where time < 20 and time > 10 -delete from root.ln.wf02.wt02.status where time <= 20 and time >= 10 -delete from root.ln.wf02.wt02.status where time > 20 -delete from root.ln.wf02.wt02.status where time >= 20 -delete from root.ln.wf02.wt02.status where time = 20 -``` - -需要注意,当前的删除语句不支持 where 子句后的时间范围为多个由 OR 连接成的时间区间。如下删除语句将会解析出错: -``` -delete from root.ln.wf02.wt02.status where time > 4 or time < 0 -Msg: 303: Check metadata error: For delete statement, where clause can only contain atomic -expressions like : time > XXX, time <= XXX, or two atomic expressions connected by 'AND' -``` - -如果 delete 语句中未指定 where 子句,则会删除时间序列中的所有数据。 -```sql -delete from root.ln.wf02.wt02.status -``` - -### 多传感器时间序列值删除 - -当 ln 集团 wf02 子站的 wt02 设备在 2017-11-01 16:26:00 之前的供电状态和设备硬件版本都需要删除,此时可以使用含义更广的 [路径模式(Path Pattern)](../Basic-Concept/Data-Model-and-Terminology.md) 进行删除操作,进行此操作的 SQL 语句为: - - -```sql -delete from root.ln.wf02.wt02.* where time <= 2017-11-01T16:26:00; -``` - -需要注意的是,当删除的路径不存在时,IoTDB 不会提示路径不存在,而是显示执行成功,因为 SQL 是一种声明式的编程方式,除非是语法错误、权限不足等,否则都不认为是错误,如下所示。 - -```sql -IoTDB> delete from root.ln.wf03.wt02.status where time < now() -Msg: The statement is executed successfully. -``` - -### 删除时间分区 (实验性功能) -您可以通过如下语句来删除某一个 database 下的指定时间分区: - -```sql -DELETE PARTITION root.ln 0,1,2 -``` - -上例中的 0,1,2 为待删除时间分区的 id,您可以通过查看 IoTDB 的数据文件夹找到它,或者可以通过计算`timestamp / partitionInterval`(向下取整), -手动地将一个时间戳转换为对应的 id,其中的`partitionInterval`可以在 IoTDB 的配置文件中找到(如果您使用的版本支持时间分区)。 - -请注意该功能目前只是实验性的,如果您不是开发者,使用时请务必谨慎。 - diff --git a/src/zh/UserGuide/V1.3.0-2/UserGuideReadme.md b/src/zh/UserGuide/V1.3.0-2/UserGuideReadme.md deleted file mode 100644 index 739e32ae4..000000000 --- a/src/zh/UserGuide/V1.3.0-2/UserGuideReadme.md +++ /dev/null @@ -1,30 +0,0 @@ - -# IoTDB 用户手册 Toc - -我们一直都在致力于不断向 IOTDB 中引入更多功能,因此不同的发行版本的用户手册文档也不尽相同。 - -"In Progress Version" 用于匹配 IOTDB 源代码存储库的 master 分支。 -其他文档用于匹配 IoTDB 发布的版本。 - -- [In progress version](https://iotdb.apache.org/UserGuide/Master/QuickStart/QuickStart.html) -- [Version 1.0.x](https://iotdb.apache.org/UserGuide/V1.0.x/QuickStart/QuickStart.html) -- [Version 0.13.x](https://iotdb.apache.org/UserGuide/V0.13.x/QuickStart/QuickStart.html) diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-CSharp-Native-API.md b/src/zh/UserGuide/V1.3.3/API/Programming-CSharp-Native-API.md deleted file mode 100644 index addbce6c7..000000000 --- a/src/zh/UserGuide/V1.3.3/API/Programming-CSharp-Native-API.md +++ /dev/null @@ -1,274 +0,0 @@ - - -# C# 原生接口 - -## 依赖 - -- .NET SDK >= 5.0 或 .NET Framework 4.x -- Thrift >= 0.14.1 -- NLog >= 4.7.9 - -## 安装 - -您可以使用 NuGet Package Manager, .NET CLI等工具来安装,以 .NET CLI为例 - -如果您使用的是\.NET 5.0 或者更高版本的SDK,输入如下命令即可安装最新的NuGet包 - -``` -dotnet add package Apache.IoTDB -``` - -为了适配 .NET Framework 4.x,我们单独构建了一个NuGet包,如果您使用的是\.NET Framework 4.x,输入如下命令即可安装最新的包 - -```bash -dotnet add package Apache.IoTDB.framework -``` - -如果您想安装更早版本的客户端,只需要指定版本即可 - -```bash -# 安装0.12.1.2版本的客户端 -dotnet add package Apache.IoTDB --version 0.12.1.2 -``` - -## 基本接口说明 - -Session接口在语义上和其他语言客户端相同 - -```csharp -// 参数定义 -string host = "localhost"; -int port = 6667; -int pool_size = 2; - -// 初始化session -var session_pool = new SessionPool(host, port, pool_size); - -// 开启session -await session_pool.Open(false); - -// 创建时间序列 -await session_pool.CreateTimeSeries("root.test_group.test_device.ts1", TSDataType.TEXT, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); -await session_pool.CreateTimeSeries("root.test_group.test_device.ts2", TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); -await session_pool.CreateTimeSeries("root.test_group.test_device.ts3", TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - -// 插入record -var measures = new List{"ts1", "ts2", "ts3"}; -var values = new List { "test_text", true, (int)123 }; -var timestamp = 1; -var rowRecord = new RowRecord(timestamp, values, measures); -await session_pool.InsertRecordAsync("root.test_group.test_device", rowRecord); - -// 插入Tablet -var timestamp_lst = new List{ timestamp + 1 }; -var value_lst = new List {"iotdb", true, (int) 12}; -var tablet = new Tablet("root.test_group.test_device", measures, value_lst, timestamp_ls); -await session_pool.InsertTabletAsync(tablet); - -// 关闭Session -await session_pool.Close(); -``` - -## **Row Record** - -- 对**IoTDB**中的`record`数据进行封装和抽象。 -- 示例: - - | timestamp | status | temperature | - | --------- | ------ | ----------- | - | 1 | 0 | 20 | - -- 构造方法: - -```csharp -var rowRecord = - new RowRecord(long timestamps, List values, List measurements); -``` - -### **Tablet** - -- 一种类似于表格的数据结构,包含一个设备的若干行非空数据块。 -- 示例: - - | time | status | temperature | - | ---- | ------ | ----------- | - | 1 | 0 | 20 | - | 2 | 0 | 20 | - | 3 | 3 | 21 | - -- 构造方法: - -```csharp -var tablet = - Tablet(string deviceId, List measurements, List> values, List timestamps); -``` - - - -## **API** - -### **基础接口** - -| api name | parameters | notes | use example | -| -------------- | ------------------------- | ------------------------ | ----------------------------- | -| Open | bool | open session | session_pool.Open(false) | -| Close | null | close session | session_pool.Close() | -| IsOpen | null | check if session is open | session_pool.IsOpen() | -| OpenDebugMode | LoggingConfiguration=null | open debug mode | session_pool.OpenDebugMode() | -| CloseDebugMode | null | close debug mode | session_pool.CloseDebugMode() | -| SetTimeZone | string | set time zone | session_pool.GetTimeZone() | -| GetTimeZone | null | get time zone | session_pool.GetTimeZone() | - -### **Record相关接口** - -| api name | parameters | notes | use example | -| ----------------------------------- | ----------------------------- | ----------------------------------- | ------------------------------------------------------------ | -| InsertRecordAsync | string, RowRecord | insert single record | session_pool.InsertRecordAsync("root.97209_TEST_CSHARP_CLIENT_GROUP.TEST_CSHARP_CLIENT_DEVICE", new RowRecord(1, values, measures)); | -| InsertRecordsAsync | List\, List\ | insert records | session_pool.InsertRecordsAsync(device_id, rowRecords) | -| InsertRecordsOfOneDeviceAsync | string, List\ | insert records of one device | session_pool.InsertRecordsOfOneDeviceAsync(device_id, rowRecords) | -| InsertRecordsOfOneDeviceSortedAsync | string, List\ | insert sorted records of one device | InsertRecordsOfOneDeviceSortedAsync(deviceId, sortedRowRecords); | -| TestInsertRecordAsync | string, RowRecord | test insert record | session_pool.TestInsertRecordAsync("root.97209_TEST_CSHARP_CLIENT_GROUP.TEST_CSHARP_CLIENT_DEVICE", rowRecord) | -| TestInsertRecordsAsync | List\, List\ | test insert record | session_pool.TestInsertRecordsAsync(device_id, rowRecords) | - -### **Tablet相关接口** - -| api name | parameters | notes | use example | -| ---------------------- | ------------ | -------------------- | -------------------------------------------- | -| InsertTabletAsync | Tablet | insert single tablet | session_pool.InsertTabletAsync(tablet) | -| InsertTabletsAsync | List\ | insert tablets | session_pool.InsertTabletsAsync(tablets) | -| TestInsertTabletAsync | Tablet | test insert tablet | session_pool.TestInsertTabletAsync(tablet) | -| TestInsertTabletsAsync | List\ | test insert tablets | session_pool.TestInsertTabletsAsync(tablets) | - -### **SQL语句接口** - -| api name | parameters | notes | use example | -| ----------------------------- | ---------- | ------------------------------ | ------------------------------------------------------------ | -| ExecuteQueryStatementAsync | string | execute sql query statement | session_pool.ExecuteQueryStatementAsync("select * from root.97209_TEST_CSHARP_CLIENT_GROUP.TEST_CSHARP_CLIENT_DEVICE where time<15"); | -| ExecuteNonQueryStatementAsync | string | execute sql nonquery statement | session_pool.ExecuteNonQueryStatementAsync( "create timeseries root.97209_TEST_CSHARP_CLIENT_GROUP.TEST_CSHARP_CLIENT_DEVICE.status with datatype=BOOLEAN,encoding=PLAIN") | - -### 数据表接口 - -| api name | parameters | notes | use example | -| -------------------------- | ------------------------------------------------------------ | --------------------------- | ------------------------------------------------------------ | -| SetStorageGroup | string | set storage group | session_pool.SetStorageGroup("root.97209_TEST_CSHARP_CLIENT_GROUP_01") | -| CreateTimeSeries | string, TSDataType, TSEncoding, Compressor | create time series | session_pool.InsertTabletsAsync(tablets) | -| DeleteStorageGroupAsync | string | delete single storage group | session_pool.DeleteStorageGroupAsync("root.97209_TEST_CSHARP_CLIENT_GROUP_01") | -| DeleteStorageGroupsAsync | List\ | delete storage group | session_pool.DeleteStorageGroupAsync("root.97209_TEST_CSHARP_CLIENT_GROUP") | -| CreateMultiTimeSeriesAsync | List\, List\ , List\ , List\ | create multi time series | session_pool.CreateMultiTimeSeriesAsync(ts_path_lst, data_type_lst, encoding_lst, compressor_lst); | -| DeleteTimeSeriesAsync | List\ | delete time series | | -| DeleteTimeSeriesAsync | string | delete time series | | -| DeleteDataAsync | List\, long, long | delete data | session_pool.DeleteDataAsync(ts_path_lst, 2, 3) | - -### **辅助接口** - -| api name | parameters | notes | use example | -| -------------------------- | ---------- | --------------------------- | ---------------------------------------------------- | -| CheckTimeSeriesExistsAsync | string | check if time series exists | session_pool.CheckTimeSeriesExistsAsync(time series) | - - - -用法可以参考[用户示例](https://github.com/apache/iotdb-client-csharp/tree/main/samples/Apache.IoTDB.Samples) - -## 连接池 - -为了实现并发客户端请求,我们提供了针对原生接口的连接池(`SessionPool`),由于`SessionPool`本身为`Session`的超集,当`SessionPool`的`pool_size`参数设置为1时,退化为原来的`Session` - -我们使用`ConcurrentQueue`数据结构封装了一个客户端队列,以维护与服务端的多个连接,当调用`Open()`接口时,会在该队列中创建指定个数的客户端,同时通过`System.Threading.Monitor`类实现对队列的同步访问。 - -当请求发生时,会尝试从连接池中寻找一个空闲的客户端连接,如果没有空闲连接,那么程序将需要等待直到有空闲连接 - -当一个连接被用完后,他会自动返回池中等待下次被使用 - -## ByteBuffer - -在传入RPC接口参数时,需要对Record和Tablet两种数据结构进行序列化,我们主要通过封装的ByteBuffer类实现 - -在封装字节序列的基础上,我们进行了内存预申请与内存倍增的优化,减少了序列化过程中内存的申请和释放,在一个拥有20000行的Tablet上进行序列化测试时,速度比起原生的数组动态增长具有**35倍的性能加速** - -### 实现介绍 -在进行`RowRecords`以及`Tablet`的插入时,我们需要对多行RowRecord和Tablet进行序列化以进行发送。客户端中的序列化实现主要依赖于ByteBuffer完成。接下来我们介绍ByteBuffer的实现细节。本文包含如下几点内容: - - 序列化的协议 - - C#与Java的大小端的差异 - - ByteBuffer内存倍增算法 - -### 序列化协议 -客户端向IoTDB服务器发送的序列化数据总体应该包含两个信息。 - - 数据类型 - - 数据本身 - -其中对于`字符串`的序列化时,我们需要再加入字符串的长度信息。即一个字符串的序列化完整结果为: - - [类型][长度][数据内容] -接下来我们分别介绍`RowRecord`、`Tablet`的序列化方式 - -#### RowRecord -我们对RowRecord进行序列化时,`伪代码`如下: -```csharp -public byte[] value_to_bytes(List data_types, List values){ - ByteBuffer buffer = new ByteBuffer(values.Count); - for(int i = 0;i < data_types.Count(); i++){ - buffer.add_type((data_types[i]); - buffer.add_val(values[i]); - } -} -``` - -对于其序列化的结果格式如下: - - [数据类型1][数据1][数据类型2][数据2]...[数据类型N][数据N] - 其中数据类型为自定义的`Enum`变量,分别如下: -```csharp -public enum TSDataType{BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT, NONE}; -``` - -#### Tablet序列化 -使用`Tabelt`进行数据插入时有如下限制: - - 限制:Tablet中数据不能有空值 -由于向 `IoTDB`服务器发送`Tablet`数据插入请求时会携带`行数`, `列数`, `列数据类型`,所以`Tabelt`序列化时我们不需要加入数据类型信息。`Tablet`是`按照列进行序列化`,这是因为后端可以通过行数得知出当前列的元素个数,同时根据列类型来对数据进行解析。 - -### CSharp与Java序列化数据时的大小端差异 -由于Java序列化默认大端协议,而CSharp序列化默认得到小端序列。所以我们在CSharp中序列化数据之后,需要对数据进行反转这样后端才可以正常解析。同时当我们从后端获取到序列化的结果时(如`SessionDataset`),我们也需要对获得的数据进行反转以解析内容。这其中特例便是字符串的序列化,CSharp中对字符串的序列化结果为大端序,所以序列化字符串或者接收到字符串序列化结果时,不需要反转序列结果。 - -### ByteBuffer内存倍增法 -拥有数万行的Tablet的序列化结果可能有上百兆,为了能够高效的实现大`Tablet`的序列化,我们对ByteBuffer使用`内存倍增法`的策略来减少序列化过程中对于内存的申请和释放。即当当前的buffer的长度不足以放下序列化结果时,我们将当前buffer的内存`至少`扩增2倍。这极大的减少了内存的申请释放次数,加速了大Tablet的序列化速度。 -```csharp -private void extend_buffer(int space_need){ - if(write_pos + space_need >= total_length){ - total_length = max(space_need, total_length); - byte[] new_buffer = new byte[total_length * 2]; - buffer.CopyTo(new_buffer, 0); - buffer = new_buffer; - total_length = 2 * total_length; - } -} -``` -同时在序列化`Tablet`时,我们首先根据Tablet的`行数`,`列数`以及每一列的数据类型估计当前`Tablet`序列化结果所需要的内存大小,并在初始化时进行内存的申请。这进一步的减少了内存的申请释放频率。 - -通过上述的策略,我们在一个有`20000`行的Tablet上进行测试时,序列化速度相比Naive数组长度动态生长实现算法具有约35倍的性能加速。 - -## 异常重连 - -当服务端发生异常或者宕机重启时,客户端中原来通过`Open()`产生的的session会失效,抛出`TException`异常 - -为了避免这一情况的发生,我们对大部分的接口进行了增强,一旦出现连接问题,就会尝试重新调用`Open()`接口并创建新的Session,并尝试重新发送对应的请求 - diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-Go-Native-API.md b/src/zh/UserGuide/V1.3.3/API/Programming-Go-Native-API.md deleted file mode 100644 index 303e791e2..000000000 --- a/src/zh/UserGuide/V1.3.3/API/Programming-Go-Native-API.md +++ /dev/null @@ -1,84 +0,0 @@ - - -# Go 原生接口 - -## 依赖 - - * golang >= 1.13 - * make >= 3.0 - * curl >= 7.1.1 - * thrift 0.15.0 - * Linux、Macos 或其他类 unix 系统 - * Windows+bash (下载 IoTDB Go client 需要 git ,通过 WSL、cygwin、Git Bash 任意一种方式均可) - -## 安装方法 - - * 通过 go mod - -```sh -# 切换到 GOPATH 的 HOME 路径,启用 Go Modules 功能 -export GO111MODULE=on - -# 配置 GOPROXY 环境变量 -export GOPROXY=https://goproxy.io - -# 创建命名的文件夹或目录,并切换当前目录 -mkdir session_example && cd session_example - -# 保存文件,自动跳转到新的地址 -curl -o session_example.go -L https://github.com/apache/iotdb-client-go/raw/main/example/session_example.go - -# 初始化 go module 环境 -go mod init session_example - -# 下载依赖包 -go mod tidy - -# 编译并运行程序 -go run session_example.go -``` - -* 通过 GOPATH - -```sh -# get thrift 0.13.0 -go get github.com/apache/thrift@0.13.0 - -# 递归创建目录 -mkdir -p $GOPATH/src/iotdb-client-go-example/session_example - -# 切换到当前目录 -cd $GOPATH/src/iotdb-client-go-example/session_example - -# 保存文件,自动跳转到新的地址 -curl -o session_example.go -L https://github.com/apache/iotdb-client-go/raw/main/example/session_example.go - -# 初始化 go module 环境 -go mod init - -# 下载依赖包 -go mod tidy - -# 编译并运行程序 -go run session_example.go -``` -**注意:GO原生客户端Session不是线程安全的,强烈不建议在多线程场景下应用。如有多线程应用场景,请使用Session Pool.** diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-Kafka.md b/src/zh/UserGuide/V1.3.3/API/Programming-Kafka.md deleted file mode 100644 index 61bfaab06..000000000 --- a/src/zh/UserGuide/V1.3.3/API/Programming-Kafka.md +++ /dev/null @@ -1,118 +0,0 @@ - - -# Kafka - -[Apache Kafka](https://kafka.apache.org/) 是一个开源的分布式事件流平台,被数千家公司用于高性能数据管道、流分析、数据集成和关键任务应用。 - -## 示例代码 - -### kafka 生产者生产数据 Java 代码示例 - -```java - Properties props = new Properties(); - props.put("bootstrap.servers", "127.0.0.1:9092"); - props.put("key.serializer", StringSerializer.class); - props.put("value.serializer", StringSerializer.class); - KafkaProducer producer = new KafkaProducer<>(props); - producer.send( - new ProducerRecord<>( - "Kafka-Test", "key", "root.kafka," + System.currentTimeMillis() + ",value,INT32,100")); - producer.close(); -``` - -### kafka 消费者接收数据 Java 代码示例 - -```java - Properties props = new Properties(); - props.put("bootstrap.servers", "127.0.0.1:9092"); - props.put("key.deserializer", StringDeserializer.class); - props.put("value.deserializer", StringDeserializer.class); - props.put("auto.offset.reset", "earliest"); - props.put("group.id", "Kafka-Test"); - KafkaConsumer kafkaConsumer = new KafkaConsumer<>(props); - kafkaConsumer.subscribe(Collections.singleton("Kafka-Test")); - ConsumerRecords records = kafkaConsumer.poll(Duration.ofSeconds(1)); - ``` - -### 存入 IoTDB 服务器的 Java 代码示例 - -```java - SessionPool pool = - new SessionPool.Builder() - .host("127.0.0.1") - .port(6667) - .user("root") - .password("root") - .maxSize(3) - .build(); - List datas = new ArrayList<>(records.count()); - for (ConsumerRecord record : records) { - datas.add(record.value()); - } - int size = datas.size(); - List deviceIds = new ArrayList<>(size); - List times = new ArrayList<>(size); - List> measurementsList = new ArrayList<>(size); - List> typesList = new ArrayList<>(size); - List> valuesList = new ArrayList<>(size); - for (String data : datas) { - String[] dataArray = data.split(","); - String device = dataArray[0]; - long time = Long.parseLong(dataArray[1]); - List measurements = Arrays.asList(dataArray[2].split(":")); - List types = new ArrayList<>(); - for (String type : dataArray[3].split(":")) { - types.add(TSDataType.valueOf(type)); - } - List values = new ArrayList<>(); - String[] valuesStr = dataArray[4].split(":"); - for (int i = 0; i < valuesStr.length; i++) { - switch (types.get(i)) { - case INT64: - values.add(Long.parseLong(valuesStr[i])); - break; - case DOUBLE: - values.add(Double.parseDouble(valuesStr[i])); - break; - case INT32: - values.add(Integer.parseInt(valuesStr[i])); - break; - case TEXT: - values.add(valuesStr[i]); - break; - case FLOAT: - values.add(Float.parseFloat(valuesStr[i])); - break; - case BOOLEAN: - values.add(Boolean.parseBoolean(valuesStr[i])); - break; - } - } - deviceIds.add(device); - times.add(time); - measurementsList.add(measurements); - typesList.add(types); - valuesList.add(values); - } - pool.insertRecords(deviceIds, times, measurementsList, typesList, valuesList); - ``` - diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-NodeJS-Native-API.md b/src/zh/UserGuide/V1.3.3/API/Programming-NodeJS-Native-API.md deleted file mode 100644 index 3bd4e132e..000000000 --- a/src/zh/UserGuide/V1.3.3/API/Programming-NodeJS-Native-API.md +++ /dev/null @@ -1,201 +0,0 @@ - - - -# Node.js 原生接口 - -IoTDB 使用 Thrift 作为跨语言的 RPC 框架,因此可以通过 Thrift 提供的接口来实现对 IoTDB 的访问。本文档将介绍如何生成可访问 IoTDB 的原生 Node.js 接口。 - - -## 依赖 - - * JDK >= 1.8 - * Node.js >= 16.0.0 - * thrift 0.14.1 - * Linux、Macos 或其他类 unix 系统 - * Windows+bash (下载 IoTDB Go client 需要 git ,通过 WSL、cygwin、Git Bash 任意一种方式均可) - -必须安装 thrift(0.14.1 或更高版本)才能将 thrift 文件编译为 Node.js 代码。下面是官方的安装教程,最终,您应该得到一个 thrift 可执行文件。 - -``` -http://thrift.apache.org/docs/install/ -``` - - -## 编译 thrift 库,生成 Node.js 原生接口 - -1. 在 IoTDB 源代码文件夹的根目录中找到 pom.xml 文件。 -2. 打开 pom.xml 文件,找到以下内容: - -```xml - - generate-thrift-sources-java - generate-sources - - compile - - - java - ${thrift.exec.absolute.path} - ${basedir}/src/main/thrift - - -``` -3. 参考该设置,在 pom.xml 文件中添加以下内容,用来生成 Node.js 的原生接口: - -```xml - - generate-thrift-sources-nodejs - generate-sources - - compile - - - js:node - ${thrift.exec.absolute.path} - ${basedir}/src/main/thrift - **/common.thrift,**/client.thrift - ${project.build.directory}/generated-sources-nodejs - - -``` - -4. 在 IoTDB 源代码文件夹的根目录下,运行`mvn clean generate-sources`, - -这个指令将自动删除`iotdb/iotdb-protocol/thrift/target` 和 `iotdb/iotdb-protocol/thrift-commons/target`中的文件,并使用新生成的 thrift 文件重新填充该文件夹。 - -这个文件夹在 git 中会被忽略,并且**永远不应该被推到 git 中!** - -**注意**不要将`iotdb/iotdb-protocol/thrift/target` 和 `iotdb/iotdb-protocol/thrift-commons/target`上传到 git 仓库中 ! - -## 使用 Node.js 原生接口 - -将 `iotdb/iotdb-protocol/thrift/target/generated-sources-nodejs/` 和 `iotdb/iotdb-protocol/thrift-commons/target/generated-sources-nodejs/` 中的文件复制到您的项目中,即可使用。 - - -## 支持的 rpc 接口 - -``` -// 打开一个 session -TSOpenSessionResp openSession(1:TSOpenSessionReq req); - -// 关闭一个 session -TSStatus closeSession(1:TSCloseSessionReq req); - -// 执行一条 SQL 语句 -TSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req); - -// 批量执行 SQL 语句 -TSStatus executeBatchStatement(1:TSExecuteBatchStatementReq req); - -// 执行查询 SQL 语句 -TSExecuteStatementResp executeQueryStatement(1:TSExecuteStatementReq req); - -// 执行插入、删除 SQL 语句 -TSExecuteStatementResp executeUpdateStatement(1:TSExecuteStatementReq req); - -// 向服务器取下一批查询结果 -TSFetchResultsResp fetchResults(1:TSFetchResultsReq req) - -// 获取元数据 -TSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req) - -// 取消某次查询操作 -TSStatus cancelOperation(1:TSCancelOperationReq req); - -// 关闭查询操作数据集,释放资源 -TSStatus closeOperation(1:TSCloseOperationReq req); - -// 获取时区信息 -TSGetTimeZoneResp getTimeZone(1:i64 sessionId); - -// 设置时区 -TSStatus setTimeZone(1:TSSetTimeZoneReq req); - -// 获取服务端配置 -ServerProperties getProperties(); - -// 设置 database -TSStatus setStorageGroup(1:i64 sessionId, 2:string storageGroup); - -// 创建时间序列 -TSStatus createTimeseries(1:TSCreateTimeseriesReq req); - -// 创建多条时间序列 -TSStatus createMultiTimeseries(1:TSCreateMultiTimeseriesReq req); - -// 删除时间序列 -TSStatus deleteTimeseries(1:i64 sessionId, 2:list path) - -// 删除 database -TSStatus deleteStorageGroups(1:i64 sessionId, 2:list storageGroup); - -// 按行插入数据 -TSStatus insertRecord(1:TSInsertRecordReq req); - -// 按 String 格式插入一条数据 -TSStatus insertStringRecord(1:TSInsertStringRecordReq req); - -// 按列插入数据 -TSStatus insertTablet(1:TSInsertTabletReq req); - -// 按列批量插入数据 -TSStatus insertTablets(1:TSInsertTabletsReq req); - -// 按行批量插入数据 -TSStatus insertRecords(1:TSInsertRecordsReq req); - -// 按行批量插入同属于某个设备的数据 -TSStatus insertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req); - -// 按 String 格式批量按行插入数据 -TSStatus insertStringRecords(1:TSInsertStringRecordsReq req); - -// 测试按列插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertTablet(1:TSInsertTabletReq req); - -// 测试批量按列插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertTablets(1:TSInsertTabletsReq req); - -// 测试按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertRecord(1:TSInsertRecordReq req); - -// 测试按 String 格式按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertStringRecord(1:TSInsertStringRecordReq req); - -// 测试按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertRecords(1:TSInsertRecordsReq req); - -// 测试按行批量插入同属于某个设备的数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req); - -// 测试按 String 格式批量按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertStringRecords(1:TSInsertStringRecordsReq req); - -// 删除数据 -TSStatus deleteData(1:TSDeleteDataReq req); - -// 执行原始数据查询 -TSExecuteStatementResp executeRawDataQuery(1:TSRawDataQueryReq req); - -// 向服务器申请一个查询语句 ID -i64 requestStatementId(1:i64 sessionId); -``` diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-ODBC.md b/src/zh/UserGuide/V1.3.3/API/Programming-ODBC.md deleted file mode 100644 index 08a7fc6b8..000000000 --- a/src/zh/UserGuide/V1.3.3/API/Programming-ODBC.md +++ /dev/null @@ -1,146 +0,0 @@ - - -# ODBC -在 JDBC 插件的基础上,IoTDB 可以通过 ODBC-JDBC 桥来支持通过 ODBC 对数据库的操作。 - -## 依赖 -* 带依赖打包的 IoTDB JDBC 插件包 -* ODBC-JDBC 桥(如 Zappy-Sys) - -## 部署方法 -### 准备 JDBC 插件包 -下载 IoTDB 源码,在根目录下执行下面的命令: -```shell -mvn clean package -pl iotdb-client/jdbc -am -DskipTests -P get-jar-with-dependencies -``` -之后,就可以在`iotdb-client/jdbc/target`目录下看到`iotdb-jdbc-1.3.2-SNAPSHOT-jar-with-dependencies.jar`文件。 - -### 准备 ODBC-JDBC 桥 -*注意: 这里给出的仅仅是一种 ODBC-JDBC 桥,仅作示例。读者可以自行寻找其他的 ODBC-JDBC 桥来对接 IoTDB 的 JDBC 插件。* -1. **下载 Zappy-Sys ODBC-JDBC 桥插件**: - 进入 https://zappysys.com/products/odbc-powerpack/odbc-jdbc-bridge-driver/ 网站,点击下载按钮并直接安装。 - - ![ZappySys_website.jpg](/img/ZappySys_website.jpg) - -2. **准备 IoTDB**:打开 IoTDB 集群,并任意写入一条数据。 - ```sql - IoTDB > insert into root.ln.wf02.wt02(timestamp,status) values(1,true) - ``` - -3. **部署及调试插件**: - 1. 打开 ODBC 数据源 32/64 位,取决于 Windows 的位数,一个示例的位置是 `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools`。 - - ![ODBC_ADD_CN.jpg](/img/ODBC_ADD_CN.jpg) - - 2. 点击添加,选择 ZappySys JDBC Bridge。 - - ![ODBC_CREATE_CN.jpg](/img/ODBC_CREATE_CN.jpg) - - 3. 填写如下配置: - - | 配置项 | 填写内容 | 示例 | - |---------------------|-----------------------------------------------|--------------------------------------------------------------------------------------------------------------------| - | Connection String | jdbc:iotdb://:/ | jdbc:iotdb://127.0.0.1:6667/ | - | Driver Class | org.apache.iotdb.jdbc.IoTDBDriver | org.apache.iotdb.jdbc.IoTDBDriver | - | JDBC driver file(s) | IoTDB JDBC jar-with-dependencies 插件路径 | C:\Users\13361\Documents\GitHub\iotdb\iotdb-client\jdbc\target\iotdb-jdbc-1.3.2-SNAPSHOT-jar-with-dependencies.jar | - | User name | IoTDB 的用户名 | root | - | User password | IoTDB 的密码 | root | - - ![ODBC_CONNECTION.png](/img/ODBC_CONNECTION.png) - - 4. 点击 Test Connection 按钮,应该显示连接成功。 - - ![ODBC_CONFIG_CN.jpg](/img/ODBC_CONFIG_CN.jpg) - - 5. 点击上方的 Preview, 将查询文本换为 `select * from root.**`,点击 Preview Data,应该正确显示查询结果。 - - ![ODBC_TEST.jpg](/img/ODBC_TEST.jpg) - -4. **使用 ODBC 操作数据**:正确部署后,就可以使用 Windows 的 ODBC 库,对 IoTDB 的数据进行操作。 这里给出 C# 语言的代码示例: - ```C# - using System.Data.Odbc; - - // Get a connection - var dbConnection = new OdbcConnection("DSN=ZappySys JDBC Bridge"); - dbConnection.Open(); - - // Execute the write commands to prepare data - var dbCommand = dbConnection.CreateCommand(); - dbCommand.CommandText = "insert into root.Keller.Flur.Energieversorgung(time, s1) values(1715670861634, 1)"; - dbCommand.ExecuteNonQuery(); - dbCommand.CommandText = "insert into root.Keller.Flur.Energieversorgung(time, s2) values(1715670861634, true)"; - dbCommand.ExecuteNonQuery(); - dbCommand.CommandText = "insert into root.Keller.Flur.Energieversorgung(time, s3) values(1715670861634, 3.1)"; - dbCommand.ExecuteNonQuery(); - - // Execute the read command - dbCommand.CommandText = "SELECT * FROM root.Keller.Flur.Energieversorgung"; - var dbReader = dbCommand.ExecuteReader(); - - // Write the output header - var fCount = dbReader.FieldCount; - Console.Write(":"); - for(var i = 0; i < fCount; i++) - { - var fName = dbReader.GetName(i); - Console.Write(fName + ":"); - } - Console.WriteLine(); - - // Output the content - while (dbReader.Read()) - { - Console.Write(":"); - for(var i = 0; i < fCount; i++) - { - var fieldType = dbReader.GetFieldType(i); - switch (fieldType.Name) - { - case "DateTime": - var dateTime = dbReader.GetInt64(i); - Console.Write(dateTime + ":"); - break; - case "Double": - if (dbReader.IsDBNull(i)) - { - Console.Write("null:"); - } - else - { - var fValue = dbReader.GetDouble(i); - Console.Write(fValue + ":"); - } - break; - default: - Console.Write(fieldType.Name + ":"); - break; - } - } - Console.WriteLine(); - } - - // Shut down gracefully - dbReader.Close(); - dbCommand.Dispose(); - dbConnection.Close(); - ``` - 运行该程序可以向 IoTDB 内写入数据,并且查询并打印写入的数据。 diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-Rust-Native-API.md b/src/zh/UserGuide/V1.3.3/API/Programming-Rust-Native-API.md deleted file mode 100644 index d75710501..000000000 --- a/src/zh/UserGuide/V1.3.3/API/Programming-Rust-Native-API.md +++ /dev/null @@ -1,200 +0,0 @@ - - - -# Rust 原生接口 - -IoTDB 使用 Thrift 作为跨语言的 RPC 框架,因此可以通过 Thrift 提供的接口来实现对 IoTDB 的访问。本文档将介绍如何生成可访问 IoTDB 的原生 Rust 接口。 - - -## 依赖 - - * JDK >= 1.8 - * Rust >= 1.0.0 - * thrift 0.14.1 - * Linux、Macos 或其他类 unix 系统 - * Windows+bash (下载 IoTDB Go client 需要 git ,通过 WSL、cygwin、Git Bash 任意一种方式均可) - -必须安装 thrift(0.14.1 或更高版本)才能将 thrift 文件编译为 Rust 代码。下面是官方的安装教程,最终,您应该得到一个 thrift 可执行文件。 - -``` -http://thrift.apache.org/docs/install/ -``` - - -## 编译 thrift 库,生成 Rust 原生接口 - -1. 在 IoTDB 源代码文件夹的根目录中找到 pom.xml 文件。 -2. 打开 pom.xml 文件,找到以下内容: - -```xml - - generate-thrift-sources-java - generate-sources - - compile - - - java - ${thrift.exec.absolute.path} - ${basedir}/src/main/thrift - - -``` -3. 参考该设置,在 pom.xml 文件中添加以下内容,用来生成 Rust 的原生接口: - -```xml - - generate-thrift-sources-rust - generate-sources - - compile - - - rs - ${thrift.exec.absolute.path} - ${basedir}/src/main/thrift - **/common.thrift,**/client.thrift - ${project.build.directory}/generated-sources-rust - - -``` - -4. 在 IoTDB 源代码文件夹的根目录下,运行`mvn clean generate-sources`, - -这个指令将自动删除`iotdb/iotdb-protocol/thrift/target` 和 `iotdb/iotdb-protocol/thrift-commons/target`中的文件,并使用新生成的 thrift 文件重新填充该文件夹。 - -这个文件夹在 git 中会被忽略,并且**永远不应该被推到 git 中!** - -**注意**不要将`iotdb/iotdb-protocol/thrift/target` 和 `iotdb/iotdb-protocol/thrift-commons/target`上传到 git 仓库中 ! - -## 使用 Rust 原生接口 - -将 `iotdb/iotdb-protocol/thrift/target/generated-sources-rust/` 和 `iotdb/iotdb-protocol/thrift-commons/target/generated-sources-rust/` 中的文件复制到您的项目中,即可使用。 - -## 支持的 rpc 接口 - -``` -// 打开一个 session -TSOpenSessionResp openSession(1:TSOpenSessionReq req); - -// 关闭一个 session -TSStatus closeSession(1:TSCloseSessionReq req); - -// 执行一条 SQL 语句 -TSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req); - -// 批量执行 SQL 语句 -TSStatus executeBatchStatement(1:TSExecuteBatchStatementReq req); - -// 执行查询 SQL 语句 -TSExecuteStatementResp executeQueryStatement(1:TSExecuteStatementReq req); - -// 执行插入、删除 SQL 语句 -TSExecuteStatementResp executeUpdateStatement(1:TSExecuteStatementReq req); - -// 向服务器取下一批查询结果 -TSFetchResultsResp fetchResults(1:TSFetchResultsReq req) - -// 获取元数据 -TSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req) - -// 取消某次查询操作 -TSStatus cancelOperation(1:TSCancelOperationReq req); - -// 关闭查询操作数据集,释放资源 -TSStatus closeOperation(1:TSCloseOperationReq req); - -// 获取时区信息 -TSGetTimeZoneResp getTimeZone(1:i64 sessionId); - -// 设置时区 -TSStatus setTimeZone(1:TSSetTimeZoneReq req); - -// 获取服务端配置 -ServerProperties getProperties(); - -// 设置 database -TSStatus setStorageGroup(1:i64 sessionId, 2:string storageGroup); - -// 创建时间序列 -TSStatus createTimeseries(1:TSCreateTimeseriesReq req); - -// 创建多条时间序列 -TSStatus createMultiTimeseries(1:TSCreateMultiTimeseriesReq req); - -// 删除时间序列 -TSStatus deleteTimeseries(1:i64 sessionId, 2:list path) - -// 删除 database -TSStatus deleteStorageGroups(1:i64 sessionId, 2:list storageGroup); - -// 按行插入数据 -TSStatus insertRecord(1:TSInsertRecordReq req); - -// 按 String 格式插入一条数据 -TSStatus insertStringRecord(1:TSInsertStringRecordReq req); - -// 按列插入数据 -TSStatus insertTablet(1:TSInsertTabletReq req); - -// 按列批量插入数据 -TSStatus insertTablets(1:TSInsertTabletsReq req); - -// 按行批量插入数据 -TSStatus insertRecords(1:TSInsertRecordsReq req); - -// 按行批量插入同属于某个设备的数据 -TSStatus insertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req); - -// 按 String 格式批量按行插入数据 -TSStatus insertStringRecords(1:TSInsertStringRecordsReq req); - -// 测试按列插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertTablet(1:TSInsertTabletReq req); - -// 测试批量按列插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertTablets(1:TSInsertTabletsReq req); - -// 测试按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertRecord(1:TSInsertRecordReq req); - -// 测试按 String 格式按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertStringRecord(1:TSInsertStringRecordReq req); - -// 测试按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertRecords(1:TSInsertRecordsReq req); - -// 测试按行批量插入同属于某个设备的数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req); - -// 测试按 String 格式批量按行插入数据的延迟,注意:该接口不真实插入数据,只用来测试网络延迟 -TSStatus testInsertStringRecords(1:TSInsertStringRecordsReq req); - -// 删除数据 -TSStatus deleteData(1:TSDeleteDataReq req); - -// 执行原始数据查询 -TSExecuteStatementResp executeRawDataQuery(1:TSRawDataQueryReq req); - -// 向服务器申请一个查询语句 ID -i64 requestStatementId(1:i64 sessionId); -``` diff --git a/src/zh/UserGuide/V1.3.3/Basic-Concept/Navigating_Time_Series_Data.md b/src/zh/UserGuide/V1.3.3/Basic-Concept/Navigating_Time_Series_Data.md deleted file mode 100644 index 35f789271..000000000 --- a/src/zh/UserGuide/V1.3.3/Basic-Concept/Navigating_Time_Series_Data.md +++ /dev/null @@ -1,67 +0,0 @@ - -# 走进时序数据 - -## 什么叫时序数据? - -万物互联的今天,物联网场景、工业场景等各类场景都在进行数字化转型,人们通过在各类设备上安装传感器对设备的各类状态进行采集。如电机采集电压、电流,风机的叶片转速、角速度、发电功率;车辆采集经纬度、速度、油耗;桥梁的振动频率、挠度、位移量等。传感器的数据采集,已经渗透在各个行业中。 - -![](/img/%E6%97%B6%E5%BA%8F%E6%95%B0%E6%8D%AE%E4%BB%8B%E7%BB%8D.png) - - - -通常来说,我们把每个采集点位叫做一个**测点( 也叫物理量、时间序列、时间线、信号量、指标、测量值等)**,每个测点都在随时间的推移不断收集到新的数据信息,从而构成了一条**时间序列**。用表格的方式,每个时间序列就是一个由时间、值两列形成的表格;用图形化的方式,每个时间序列就是一个随时间推移形成的走势图,也可以形象的称之为设备的“心电图”。 - -![](/img/%E5%BF%83%E7%94%B5%E5%9B%BE1.png) - -传感器产生的海量时序数据是各行各业数字化转型的基础,因此我们对时序数据的模型梳理主要围绕设备、传感器展开。 - -## 时序数据中的关键概念有哪些? - -时序数据中主要涉及的概念由下至上可分为:数据点、测点、设备。 - -![](/img/%E7%99%BD%E6%9D%BF.png) - -### 数据点 - -- 定义:由一个时间戳和一个数值组成,其中时间戳为 long 类型,数值可以为 BOOLEAN、FLOAT、INT32 等各种类型。 -- 示例:如上图中表格形式的时间序列的一行,或图形形式的时间序列的一个点,就是一个数据点。 - -![](/img/%E6%95%B0%E6%8D%AE%E7%82%B9.png) - -### 测点 - -- 定义:是多个数据点按时间戳递增排列形成的一个时间序列。通常一个测点代表一个采集点位,能够定期采集所在环境的物理量。 -- 又名:物理量、时间序列、时间线、信号量、指标、测量值等 -- 示例: - - 电力场景:电流、电压 - - 能源场景:风速、转速 - - 车联网场景:油量、车速、经度、维度 - - 工厂场景:温度、湿度 - -### 设备 - -- 定义:对应一个实际场景中的物理设备,通常是一组测点的集合,由一到多个标签定位标识 -- 示例 - - 车联网场景:车辆,由车辆识别代码 VIN 标识 - - 工厂场景:机械臂,由物联网平台生成的唯一 ID 标识 - - 能源场景:风机,由区域、场站、线路、机型、实例等标识 - - 监控场景:CPU,由机房、机架、Hostname、设备类型等标识 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata.md b/src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata.md deleted file mode 100644 index e0ddf712e..000000000 --- a/src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -redirectTo: Operate-Metadata_apache.html ---- - \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_apache.md b/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_apache.md deleted file mode 100644 index 12d14db9b..000000000 --- a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_apache.md +++ /dev/null @@ -1,412 +0,0 @@ - -# Docker部署 - -## 环境准备 - -### Docker安装 - -```SQL -#以ubuntu为例,其他操作系统可以自行搜索安装方法 -#step1: 安装一些必要的系统工具 -sudo apt-get update -sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common -#step2: 安装GPG证书 -curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - -#step3: 写入软件源信息 -sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" -#step4: 更新并安装Docker-CE -sudo apt-get -y update -sudo apt-get -y install docker-ce -#step5: 设置docker开机自启动 -sudo systemctl enable docker -#step6: 验证docker是否安装成功 -docker --version #显示版本信息,即安装成功 -``` - -### docker-compose安装 - -```SQL -#安装命令 -curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose -chmod +x /usr/local/bin/docker-compose -ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose -#验证是否安装成功 -docker-compose --version #显示版本信息即安装成功 -``` - -## 单机版 - -本节演示如何部署1C1D的docker单机版。 - -### 拉取镜像文件 - -Apache IoTDB的Docker镜像已经上传至https://hub.docker.com/r/apache/iotdb。 - -以获取1.3.2版本为例,拉取镜像命令: - -```bash -docker pull apache/iotdb:1.3.2-standalone -``` - -查看镜像: - -```bash -docker images -``` - -![](/img/%E5%BC%80%E6%BA%90-%E6%8B%89%E5%8F%96%E9%95%9C%E5%83%8F.png) - -### 创建docker bridge网络 - -```Bash -docker network create --driver=bridge --subnet=172.18.0.0/16 --gateway=172.18.0.1 iotdb -``` - -### 编写docker-compose的yml文件 - -这里我们以把IoTDB安装目录和yml文件统一放在`/docker-iotdb`文件夹下为例: - -文件目录结构为:`/docker-iotdb/iotdb`, `/docker-iotdb/docker-compose-standalone.yml ` - -```bash -docker-iotdb: -├── iotdb #iotdb安装目录 -│── docker-compose-standalone.yml #单机版docker-compose的yml文件 -``` - -完整的docker-compose-standalone.yml 内容如下: - -```bash -version: "3" -services: - iotdb-service: - image: apache/iotdb:1.3.2-standalone #使用的镜像 - hostname: iotdb - container_name: iotdb - restart: always - ports: - - "6667:6667" - environment: - - cn_internal_address=iotdb - - cn_internal_port=10710 - - cn_consensus_port=10720 - - cn_seed_config_node=iotdb:10710 - - dn_rpc_address=iotdb - - dn_internal_address=iotdb - - dn_rpc_port=6667 - - dn_internal_port=10730 - - dn_mpp_data_exchange_port=10740 - - dn_schema_region_consensus_port=10750 - - dn_data_region_consensus_port=10760 - - dn_seed_config_node=iotdb:10710 - privileged: true - volumes: - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - networks: - iotdb: - ipv4_address: 172.18.0.6 -networks: - iotdb: - external: true -``` - -### 启动IoTDB - -使用下面的命令启动: - -```bash -cd /docker-iotdb -docker-compose -f docker-compose-standalone.yml up -d #后台启动 -``` - -### 验证部署 - -- 查看日志,有如下字样,表示启动成功 - - ```SQL - docker logs -f iotdb-datanode #查看日志命令 - 2024-07-21 08:22:38,457 [main] INFO o.a.i.db.service.DataNode:227 - Congratulations, IoTDB DataNode is set up successfully. Now, enjoy yourself! - ``` - - ![](/img/%E5%BC%80%E6%BA%90-%E9%AA%8C%E8%AF%81%E9%83%A8%E7%BD%B2.png) - -- 进入容器,查看服务运行状态 - - 查看启动的容器 - - ```SQL - docker ps - ``` - - ![](/img/%E5%BC%80%E6%BA%90-%E9%AA%8C%E8%AF%81%E9%83%A8%E7%BD%B22.png) - - 进入容器, 通过cli登录数据库, 使用show cluster命令查看服务状态 - - ```SQL - docker exec -it iotdb /bin/bash #进入容器 - ./start-cli.sh -h iotdb #登录数据库 - IoTDB> show cluster #查看服务状态 - ``` - - 可以看到服务状态都是running, 说明IoTDB部署成功。 - - ![](/img/%E5%BC%80%E6%BA%90-%E9%AA%8C%E8%AF%81%E9%83%A8%E7%BD%B23.png) - -### 映射/conf目录(可选) - -后续如果想在物理机中直接修改配置文件,可以把容器中的/conf文件夹映射出来,分三步: - -步骤一:拷贝容器中的/conf目录到`/docker-iotdb/iotdb/conf` - -```bash -docker cp iotdb:/iotdb/conf /docker-iotdb/iotdb/conf -``` - -步骤二:在`docker-compose-standalone.yml`中添加映射 - -```bash - volumes: - - ./iotdb/conf:/iotdb/conf #增加这个/conf文件夹的映射 - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs -``` - -步骤三:重新启动IoTDB - -```bash -docker-compose -f docker-compose-standalone.yml up -d -``` - -## 集群版 - -本小节描述如何手动部署包括3个ConfigNode和3个DataNode的实例,即通常所说的3C3D集群。 - -
- -
- -**注意:集群版目前只支持host网络和overlay 网络,不支持bridge网络。** - -下面以host网络为例演示如何部署3C3D集群。 - -### 设置主机名 - -假设现在有3台linux服务器,IP地址和服务角色分配如下: - -| 节点ip | 主机名 | 服务 | -| ----------- | ------- | -------------------- | -| 192.168.1.3 | iotdb-1 | ConfigNode、DataNode | -| 192.168.1.4 | iotdb-2 | ConfigNode、DataNode | -| 192.168.1.5 | iotdb-3 | ConfigNode、DataNode | - -在3台机器上分别配置主机名,设置主机名需要在目标服务器上配置`/etc/hosts`,使用如下命令: - -```Bash -echo "192.168.1.3 iotdb-1" >> /etc/hosts -echo "192.168.1.4 iotdb-2" >> /etc/hosts -echo "192.168.1.5 iotdb-3" >> /etc/hosts -``` - -### 拉取镜像文件 - -Apache IoTDB的Docker镜像已经上传至https://hub.docker.com/r/apache/iotdb。 - -在3台服务器上分别拉取IoTDB镜像,以获取1.3.2版本为例,拉取镜像命令: - -```SQL -docker pull apache/iotdb:1.3.2-standalone -``` - -查看镜像: - -```SQL -docker images -``` - -![](/img/%E5%BC%80%E6%BA%90-%E9%9B%86%E7%BE%A4%E7%89%881.png) - -### 编写docker-compose的yml文件 - -这里我们以把IoTDB安装目录和yml文件统一放在`/docker-iotdb`文件夹下为例: - -文件目录结构为:`/docker-iotdb/iotdb`, `/docker-iotdb/confignode.yml`,`/docker-iotdb/datanode.yml` - -```SQL -docker-iotdb: -├── confignode.yml #confignode的yml文件 -├── datanode.yml #datanode的yml文件 -└── iotdb #IoTDB安装目录 -``` - -在每台服务器上都要编写2个yml文件,即confignode.yml和datanode.yml,yml示例如下: - -**confignode.yml:** - -```bash -#confignode.yml -version: "3" -services: - iotdb-confignode: - image: apache/iotdb:1.3.2-standalone #使用的镜像 - hostname: iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - container_name: iotdb-confignode - command: ["bash", "-c", "entrypoint.sh confignode"] - restart: always - environment: - - cn_internal_address=iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - - cn_internal_port=10710 - - cn_consensus_port=10720 - - cn_seed_config_node=iotdb-1:10710 #默认第一台为seed节点 - - schema_replication_factor=3 #元数据副本数 - - data_replication_factor=2 #数据副本数 - privileged: true - volumes: - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /dev/mem:/dev/mem:ro - network_mode: "host" #使用host网络 -``` - -**datanode.yml:** - -```bash -#datanode.yml -version: "3" -services: - iotdb-datanode: - image: iotdb-enterprise:1.3.2.3-standalone #使用的镜像 - hostname: iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - container_name: iotdb-datanode - command: ["bash", "-c", "entrypoint.sh datanode"] - restart: always - ports: - - "6667:6667" - privileged: true - environment: - - dn_rpc_address=iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - - dn_internal_address=iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - - dn_seed_config_node=iotdb-1:10710 #默认第1台为seed节点 - - dn_rpc_port=6667 - - dn_internal_port=10730 - - dn_mpp_data_exchange_port=10740 - - dn_schema_region_consensus_port=10750 - - dn_data_region_consensus_port=10760 - - schema_replication_factor=3 #元数据副本数 - - data_replication_factor=2 #数据副本数 - volumes: - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /dev/mem:/dev/mem:ro - network_mode: "host" #使用host网络 -``` - -### 首次启动confignode - -先在3台服务器上分别启动confignode, 注意启动顺序,先启动第1台iotdb-1,再启动iotdb-2和iotdb-3。 - -```bash -cd /docker-iotdb -docker-compose -f confignode.yml up -d #后台启动 -``` - -### 启动datanode - -在3台服务器上分别启动datanode - -```SQL -cd /docker-iotdb -docker-compose -f datanode.yml up -d #后台启动 -``` - -![](/img/%E5%BC%80%E6%BA%90-%E9%9B%86%E7%BE%A4%E7%89%882.png) - -### 验证部署 - -- 查看日志,有如下字样,表示datanode启动成功 - - ```SQL - docker logs -f iotdb-datanode #查看日志命令 - 2024-07-21 09:40:58,120 [main] INFO o.a.i.db.service.DataNode:227 - Congratulations, IoTDB DataNode is set up successfully. Now, enjoy yourself! - ``` - - ![](/img/%E5%BC%80%E6%BA%90-%E9%9B%86%E7%BE%A4%E7%89%883.png) - -- 进入容器,查看服务运行状态 - - 查看启动的容器 - - ```SQL - docker ps - ``` - - ![](/img/%E5%BC%80%E6%BA%90-%E9%9B%86%E7%BE%A4%E7%89%884.png) - - 进入任意一个容器, 通过cli登录数据库, 使用show cluster命令查看服务状态 - - ```SQL - docker exec -it iotdb-datanode /bin/bash #进入容器 - ./start-cli.sh -h iotdb-1 #登录数据库 - IoTDB> show cluster #查看服务状态 - ``` - - 可以看到服务状态都是running, 说明IoTDB部署成功。 - - ![](/img/%E5%BC%80%E6%BA%90-%E9%9B%86%E7%BE%A4%E7%89%885.png) - -### 映射/conf目录(可选) - -后续如果想在物理机中直接修改配置文件,可以把容器中的/conf文件夹映射出来,分三步: - -步骤一:在3台服务器中分别拷贝容器中的/conf目录到/docker-iotdb/iotdb/conf - -```bash -docker cp iotdb-confignode:/iotdb/conf /docker-iotdb/iotdb/conf -或者 -docker cp iotdb-datanode:/iotdb/conf /docker-iotdb/iotdb/conf -``` - -步骤二:在3台服务器的confignode.yml和datanode.yml中添加/conf目录映射 - -```bash -#confignode.yml - volumes: - - ./iotdb/conf:/iotdb/conf #增加这个/conf文件夹的映射 - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /dev/mem:/dev/mem:ro - -#datanode.yml - volumes: - - ./iotdb/conf:/iotdb/conf #增加这个/conf文件夹的映射 - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /dev/mem:/dev/mem:ro -``` - -步骤三:在3台服务器上重新启动IoTDB - -```bash -cd /docker-iotdb -docker-compose -f confignode.yml up -d -docker-compose -f datanode.yml up -d -``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_timecho.md b/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_timecho.md deleted file mode 100644 index 8d98b0f45..000000000 --- a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Docker-Deployment_timecho.md +++ /dev/null @@ -1,474 +0,0 @@ - -# Docker部署 - -## 环境准备 - -### Docker安装 - -```Bash -#以ubuntu为例,其他操作系统可以自行搜索安装方法 -#step1: 安装一些必要的系统工具 -sudo apt-get update -sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common -#step2: 安装GPG证书 -curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - -#step3: 写入软件源信息 -sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" -#step4: 更新并安装Docker-CE -sudo apt-get -y update -sudo apt-get -y install docker-ce -#step5: 设置docker开机自启动 -sudo systemctl enable docker -#step6: 验证docker是否安装成功 -docker --version #显示版本信息,即安装成功 -``` - -### docker-compose安装 - -```Bash -#安装命令 -curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose -chmod +x /usr/local/bin/docker-compose -ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose -#验证是否安装成功 -docker-compose --version #显示版本信息即安装成功 -``` - -### 安装dmidecode插件 - -默认情况下,linux服务器应该都已安装,如果没有安装的话,可以使用下面的命令安装。 - -```Bash -sudo apt-get install dmidecode -``` - -dmidecode 安装后,查找安装路径:`whereis dmidecode`,这里假设结果为`/usr/sbin/dmidecode`,记住该路径,后面的docker-compose的yml文件会用到。 - -### 获取IoTDB的容器镜像 - -关于IoTDB企业版的容器镜像您可联系商务或技术支持获取。 - -## 单机版部署 - -本节演示如何部署1C1D的docker单机版。 - -### load 镜像文件 - -比如这里获取的IoTDB的容器镜像文件名是:`iotdb-enterprise-1.3.2.3-standalone-docker.tar.gz` - -load镜像: - -```Bash -docker load -i iotdb-enterprise-1.3.2.3-standalone-docker.tar.gz -``` - -查看镜像: - -```Bash -docker images -``` - -![](/img/%E5%8D%95%E6%9C%BA-%E6%9F%A5%E7%9C%8B%E9%95%9C%E5%83%8F.png) - -### 创建docker bridge网络 - -```Bash -docker network create --driver=bridge --subnet=172.18.0.0/16 --gateway=172.18.0.1 iotdb -``` - -### 编写docker-compose的yml文件 - -这里我们以把IoTDB安装目录和yml文件统一放在`/docker-iotdb` 文件夹下为例: - -文件目录结构为:`/docker-iotdb/iotdb`, `/docker-iotdb/docker-compose-standalone.yml ` - -```Bash -docker-iotdb: -├── iotdb #iotdb安装目录 -│── docker-compose-standalone.yml #单机版docker-compose的yml文件 -``` - -完整的`docker-compose-standalone.yml`内容如下: - -```Bash -version: "3" -services: - iotdb-service: - image: iotdb-enterprise:1.3.2.3-standalone #使用的镜像 - hostname: iotdb - container_name: iotdb - restart: always - ports: - - "6667:6667" - environment: - - cn_internal_address=iotdb - - cn_internal_port=10710 - - cn_consensus_port=10720 - - cn_seed_config_node=iotdb:10710 - - dn_rpc_address=iotdb - - dn_internal_address=iotdb - - dn_rpc_port=6667 - - dn_internal_port=10730 - - dn_mpp_data_exchange_port=10740 - - dn_schema_region_consensus_port=10750 - - dn_data_region_consensus_port=10760 - - dn_seed_config_node=iotdb:10710 - privileged: true - volumes: - - ./iotdb/activation:/iotdb/activation - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /usr/sbin/dmidecode:/usr/sbin/dmidecode:ro - - /dev/mem:/dev/mem:ro - networks: - iotdb: - ipv4_address: 172.18.0.6 -networks: - iotdb: - external: true -``` - -### 首次启动 - -使用下面的命令启动: - -```Bash -cd /docker-iotdb -docker-compose -f docker-compose-standalone.yml up -``` - -由于没有激活,首次启动时会直接退出,属于正常现象,首次启动是为了获取机器码文件,用于后面的激活流程。 - -![](/img/%E5%8D%95%E6%9C%BA-%E6%BF%80%E6%B4%BB.png) - -### 申请激活 - -- 首次启动后,在物理机目录`/docker-iotdb/iotdb/activation`下会生成一个 `system_info`文件,将这个文件拷贝给天谋工作人员。 - - ![](/img/%E5%8D%95%E6%9C%BA-%E7%94%B3%E8%AF%B7%E6%BF%80%E6%B4%BB1.png) - -- 收到工作人员返回的license文件,将license文件拷贝到`/docker-iotdb/iotdb/activation`文件夹下。 - - ![](/img/%E5%8D%95%E6%9C%BA-%E7%94%B3%E8%AF%B7%E6%BF%80%E6%B4%BB2.png) - -### 再次启动IoTDB - -```Bash -docker-compose -f docker-compose-standalone.yml up -d -``` - -![](/img/%E5%90%AF%E5%8A%A8iotdb.png) - -### 验证部署 - -- 查看日志,有如下字样,表示启动成功 - -```Bash -docker logs -f iotdb-datanode #查看日志命令 -2024-07-19 12:02:32,608 [main] INFO o.a.i.db.service.DataNode:231 - Congratulations, IoTDB DataNode is set up successfully. Now, enjoy yourself! -``` - -![](/img/%E5%8D%95%E6%9C%BA-%E9%AA%8C%E8%AF%81%E9%83%A8%E7%BD%B21.png) - -- 进入容器,查看服务运行状态及激活信息 - - 查看启动的容器 - - ```Bash - docker ps - ``` - - ![](/img/%E5%8D%95%E6%9C%BA-%E9%AA%8C%E8%AF%81%E9%83%A8%E7%BD%B22.png) - - 进入容器, 通过cli登录数据库, 使用show cluster命令查看服务状态及激活状态 - - ```Bash - docker exec -it iotdb /bin/bash #进入容器 - ./start-cli.sh -h iotdb #登录数据库 - IoTDB> show cluster #查看状态 - ``` - - 可以看到服务都是running,激活状态显示已激活。 - - ![](/img/%E5%8D%95%E6%9C%BA-%E9%AA%8C%E8%AF%81%E9%83%A8%E7%BD%B23.png) - -### 映射/conf目录(可选) - -后续如果想在物理机中直接修改配置文件,可以把容器中的/conf文件夹映射出来,分三步: - -步骤一:拷贝容器中的/conf目录到`/docker-iotdb/iotdb/conf` - -```Bash -docker cp iotdb:/iotdb/conf /docker-iotdb/iotdb/conf -``` - -步骤二:在docker-compose-standalone.yml中添加映射 - -```Bash - volumes: - - ./iotdb/conf:/iotdb/conf #增加这个/conf文件夹的映射 - - ./iotdb/activation:/iotdb/activation - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /usr/sbin/dmidecode:/usr/sbin/dmidecode:ro - - /dev/mem:/dev/mem:ro -``` - -步骤三:重新启动IoTDB - -```Bash -docker-compose -f docker-compose-standalone.yml up -d -``` - -## 集群版部署 - -本小节描述如何手动部署包括3个ConfigNode和3个DataNode的实例,即通常所说的3C3D集群。 - -
- -
- -**注意:集群版目前只支持host网络和overlay 网络,不支持bridge网络。** - -下面以host网络为例演示如何部署3C3D集群。 - -### 设置主机名 - -假设现在有3台linux服务器,IP地址和服务角色分配如下: - -| 节点ip | 主机名 | 服务 | -| ----------- | ------- | -------------------- | -| 192.168.1.3 | iotdb-1 | ConfigNode、DataNode | -| 192.168.1.4 | iotdb-2 | ConfigNode、DataNode | -| 192.168.1.5 | iotdb-3 | ConfigNode、DataNode | - -在3台机器上分别配置主机名,设置主机名需要在目标服务器上配置/etc/hosts,使用如下命令: - -```Bash -echo "192.168.1.3 iotdb-1" >> /etc/hosts -echo "192.168.1.4 iotdb-2" >> /etc/hosts -echo "192.168.1.5 iotdb-3" >> /etc/hosts -``` - -### load镜像文件 - -比如获取的IoTDB的容器镜像文件名是:`iotdb-enterprise-1.3.2.3-standalone-docker.tar.gz` - -在3台服务器上分别执行load镜像命令: - -```Bash -docker load -i iotdb-enterprise-1.3.2.3-standalone-docker.tar.gz -``` - -查看镜像: - -```Bash -docker images -``` - -![](/img/%E9%95%9C%E5%83%8F%E5%8A%A0%E8%BD%BD.png) - -### 编写docker-compose的yml文件 - -这里我们以把IoTDB安装目录和yml文件统一放在/docker-iotdb文件夹下为例: - -文件目录结构为:`/docker-iotdb/iotdb`,`/docker-iotdb/confignode.yml`,`/docker-iotdb/datanode.yml` - -```Bash -docker-iotdb: -├── confignode.yml #confignode的yml文件 -├── datanode.yml #datanode的yml文件 -└── iotdb #IoTDB安装目录 -``` - -在每台服务器上都要编写2个yml文件,即`confignode.yml`和`datanode.yml`,yml示例如下: - -**confignode.yml:** - -```Bash -#confignode.yml -version: "3" -services: - iotdb-confignode: - image: iotdb-enterprise:1.3.2.3-standalone #使用的镜像 - hostname: iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - container_name: iotdb-confignode - command: ["bash", "-c", "entrypoint.sh confignode"] - restart: always - environment: - - cn_internal_address=iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - - cn_internal_port=10710 - - cn_consensus_port=10720 - - cn_seed_config_node=iotdb-1:10710 #默认第一台为seed节点 - - schema_replication_factor=3 #元数据副本数 - - data_replication_factor=2 #数据副本数 - privileged: true - volumes: - - ./iotdb/activation:/iotdb/activation - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /usr/sbin/dmidecode:/usr/sbin/dmidecode:ro - - /dev/mem:/dev/mem:ro - network_mode: "host" #使用host网络 -``` - -**datanode.yml:** - -```Bash -#datanode.yml -version: "3" -services: - iotdb-datanode: - image: iotdb-enterprise:1.3.2.3-standalone #使用的镜像 - hostname: iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - container_name: iotdb-datanode - command: ["bash", "-c", "entrypoint.sh datanode"] - restart: always - ports: - - "6667:6667" - privileged: true - environment: - - dn_rpc_address=iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - - dn_internal_address=iotdb-1|iotdb-2|iotdb-3 #根据实际情况选择,三选一 - - dn_seed_config_node=iotdb-1:10710 #默认第1台为seed节点 - - dn_rpc_port=6667 - - dn_internal_port=10730 - - dn_mpp_data_exchange_port=10740 - - dn_schema_region_consensus_port=10750 - - dn_data_region_consensus_port=10760 - - schema_replication_factor=3 #元数据副本数 - - data_replication_factor=2 #数据副本数 - volumes: - - ./iotdb/activation:/iotdb/activation - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /usr/sbin/dmidecode:/usr/sbin/dmidecode:ro - - /dev/mem:/dev/mem:ro - network_mode: "host" #使用host网络 -``` - -### 首次启动confignode - -先在3台服务器上分别启动confignode, 用来获取机器码,注意启动顺序,先启动第1台iotdb-1,再启动iotdb-2和iotdb-3。 - -```Bash -cd /docker-iotdb -docker-compose -f confignode.yml up -d #后台启动 -``` - -### 申请激活 - -- 首次启动3个confignode后,在每个物理机目录`/docker-iotdb/iotdb/activation`下都会生成一个`system_info`文件,将3个服务器的`system_info`文件拷贝给天谋工作人员; - - ![](/img/%E5%8D%95%E6%9C%BA-%E7%94%B3%E8%AF%B7%E6%BF%80%E6%B4%BB1.png) - -- 将3个license文件分别放入对应的ConfigNode节点的`/docker-iotdb/iotdb/activation`文件夹下; - - ![](/img/%E5%8D%95%E6%9C%BA-%E7%94%B3%E8%AF%B7%E6%BF%80%E6%B4%BB2.png) - -- license放入对应的activation文件夹后,confignode会自动激活,不用重启confignode - -### 启动datanode - -在3台服务器上分别启动datanode - -```Bash -cd /docker-iotdb -docker-compose -f datanode.yml up -d #后台启动 -``` - -![](/img/%E9%9B%86%E7%BE%A4%E7%89%88-dn%E5%90%AF%E5%8A%A8.png) - -### 验证部署 - -- 查看日志,有如下字样,表示datanode启动成功 - - ```Bash - docker logs -f iotdb-datanode #查看日志命令 - 2024-07-20 16:50:48,937 [main] INFO o.a.i.db.service.DataNode:231 - Congratulations, IoTDB DataNode is set up successfully. Now, enjoy yourself! - ``` - - ![](/img/dn%E5%90%AF%E5%8A%A8.png) - -- 进入任意一个容器,查看服务运行状态及激活信息 - - 查看启动的容器 - - ```Bash - docker ps - ``` - - ![](/img/%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8.png) - - 进入容器,通过cli登录数据库,使用`show cluster`命令查看服务状态及激活状态 - - ```Bash - docker exec -it iotdb-datanode /bin/bash #进入容器 - ./start-cli.sh -h iotdb-1 #登录数据库 - IoTDB> show cluster #查看状态 - ``` - - 可以看到服务都是running,激活状态显示已激活。 - - ![](/img/%E9%9B%86%E7%BE%A4-%E6%BF%80%E6%B4%BB.png) - -### 映射/conf目录(可选) - -后续如果想在物理机中直接修改配置文件,可以把容器中的/conf文件夹映射出来,分三步: - -步骤一:在3台服务器中分别拷贝容器中的/conf目录到`/docker-iotdb/iotdb/conf` - -```Bash -docker cp iotdb-confignode:/iotdb/conf /docker-iotdb/iotdb/conf -或者 -docker cp iotdb-datanode:/iotdb/conf /docker-iotdb/iotdb/conf -``` - -步骤二:在3台服务器的`confignode.yml`和`datanode.yml`中添加/conf目录映射 - -```Bash -#confignode.yml - volumes: - - ./iotdb/conf:/iotdb/conf #增加这个/conf文件夹的映射 - - ./iotdb/activation:/iotdb/activation - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /usr/sbin/dmidecode:/usr/sbin/dmidecode:ro - - /dev/mem:/dev/mem:ro - -#datanode.yml - volumes: - - ./iotdb/conf:/iotdb/conf #增加这个/conf文件夹的映射 - - ./iotdb/activation:/iotdb/activation - - ./iotdb/data:/iotdb/data - - ./iotdb/logs:/iotdb/logs - - /usr/sbin/dmidecode:/usr/sbin/dmidecode:ro - - /dev/mem:/dev/mem:ro -``` - -步骤三:在3台服务器上重新启动IoTDB - -```Bash -cd /docker-iotdb -docker-compose -f confignode.yml up -d -docker-compose -f datanode.yml up -d -``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md b/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md deleted file mode 100644 index 545e0ca75..000000000 --- a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md +++ /dev/null @@ -1,163 +0,0 @@ - -# 双活版部署 - -## 什么是双活版? - -双活通常是指两个独立的单机(或集群),实时进行镜像同步,它们的配置完全独立,可以同时接收外界的写入,每一个独立的单机(或集群)都可以将写入到自己的数据同步到另一个单机(或集群)中,两个单机(或集群)的数据可达到最终一致。 - -- 两个单机(或集群)可构成一个高可用组:当其中一个单机(或集群)停止服务时,另一个单机(或集群)不会受到影响。当停止服务的单机(或集群)再次启动时,另一个单机(或集群)会将新写入的数据同步过来。业务可以绑定两个单机(或集群)进行读写,从而达到高可用的目的。 -- 双活部署方案允许在物理节点少于 3 的情况下实现高可用,在部署成本上具备一定优势。同时可以通过电力、网络的双环网,实现两套单机(或集群)的物理供应隔离,保障运行的稳定性。 -- 目前双活能力为企业版功能。 - -![](/img/%E5%8F%8C%E6%B4%BB%E5%90%8C%E6%AD%A5.png) - -## 注意事项 - -1. 部署时推荐优先使用`hostname`进行IP配置,可避免后期修改主机ip导致数据库无法启动的问题。设置hostname需要在目标服务器上配置`/etc/hosts`,如本机ip是192.168.1.3,hostname是iotdb-1,则可以使用以下命令设置服务器的 hostname,并使用hostname配置IoTDB的`cn_internal_address`、`dn_internal_address`。 - - ```Bash - echo "192.168.1.3 iotdb-1" >> /etc/hosts - ``` - -2. 有些参数首次启动后不能修改,请参考下方的"安装步骤"章节来进行设置。 - -3. 推荐部署监控面板,可以对重要运行指标进行监控,随时掌握数据库运行状态,监控面板可以联系商务获取,部署监控面板步骤可以参考[文档](https://www.timecho.com/docs/zh/UserGuide/latest/Deployment-and-Maintenance/Monitoring-panel-deployment.html) - -## 安装步骤 - -我们以两台单机A和B构建的双活版IoTDB为例,A和B的ip分别是192.168.1.3 和 192.168.1.4 ,这里用hostname来表示不同的主机,规划如下: - -| 机器 | 机器ip | 主机名 | -| ---- | ----------- | ------- | -| A | 192.168.1.3 | iotdb-1 | -| B | 192.168.1.4 | iotdb-2 | - -### Step1:分别安装两套独立的 IoTDB - -在2个机器上分别安装 IoTDB,单机版部署文档可参考[文档](../Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md),集群版部署文档可参考[文档](../Deployment-and-Maintenance/Cluster-Deployment_timecho.md)。**推荐 A、B 集群的各项配置保持一致,以实现最佳的双活效果。** - -### Step2:在机器A上创建数据同步任务至机器B - -- 在机器A上创建数据同步流程,即机器A上的数据自动同步到机器B,使用sbin目录下的cli工具连接A上的IoTDB数据库: - - ```Bash - ./sbin/start-cli.sh -h iotdb-1 - ``` - -- 创建并启动数据同步命令,SQL 如下: - - ```Bash - create pipe AB - with source ( - 'source.forwarding-pipe-requests' = 'false' - ) - with sink ( - 'sink'='iotdb-thrift-sink', - 'sink.ip'='iotdb-2', - 'sink.port'='6667' - ) - ``` - -- 注意:为了避免数据无限循环,需要将A和B上的参数`source.forwarding-pipe-requests` 均设置为 `false`,表示不转发从另一pipe传输而来的数据。 - -### Step3:在机器B上创建数据同步任务至机器A - - - 在机器B上创建数据同步流程,即机器B上的数据自动同步到机器A,使用sbin目录下的cli工具连接B上的IoTDB数据库: - - ```Bash - ./sbin/start-cli.sh -h iotdb-2 - ``` - - 创建并启动pipe,SQL 如下: - - ```Bash - create pipe BA - with source ( - 'source.forwarding-pipe-requests' = 'false' - ) - with sink ( - 'sink'='iotdb-thrift-sink', - 'sink.ip'='iotdb-1', - 'sink.port'='6667' - ) - ``` - -- 注意:为了避免数据无限循环,需要将A和B上的参数`source.forwarding-pipe-requests` 均设置为 `false`,表示不转发从另一pipe传输而来的数据。 - -### Step4:验证部署 - -上述数据同步流程创建完成后,即可启动双活集群。 - -#### 检查集群运行状态 - -```Bash -#在2个节点分别执行show cluster命令检查IoTDB服务状态 -show cluster -``` - -**机器A**: - -![](/img/%E5%8F%8C%E6%B4%BB-A.png) - -**机器B**: - -![](/img/%E5%8F%8C%E6%B4%BB-B.png) - -确保每一个 ConfigNode 和 DataNode 都处于 Running 状态。 - -#### 检查同步状态 - -- 机器A上检查同步状态 - -```Bash -show pipes -``` - -![](/img/show%20pipes-A.png) - -- 机器B上检查同步状态 - -```Bash -show pipes -``` - -![](/img/show%20pipes-B.png) - -确保每一个 pipe 都处于 RUNNING 状态。 - -### Step5:停止双活版 IoTDB - -- 在机器A的执行下列命令: - - ```SQL - ./sbin/start-cli.sh -h iotdb-1 #登录cli - IoTDB> stop pipe AB #停止数据同步流程 - ./sbin/stop-standalone.sh #停止数据库服务 - ``` - -- 在机器B的执行下列命令: - - ```SQL - ./sbin/start-cli.sh -h iotdb-2 #登录cli - IoTDB> stop pipe BA #停止数据同步流程 - ./sbin/stop-standalone.sh #停止数据库服务 - ``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Environment-Requirements.md b/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Environment-Requirements.md deleted file mode 100644 index 9b91e2952..000000000 --- a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Environment-Requirements.md +++ /dev/null @@ -1,208 +0,0 @@ - -# 系统配置 - -## 磁盘阵列 - -### 配置建议 - -IoTDB对磁盘阵列配置没有严格运行要求,推荐使用多个磁盘阵列存储IoTDB的数据,以达到多个磁盘阵列并发写入的目标,配置可参考以下建议: - -1. 物理环境 - 系统盘:建议使用2块磁盘做Raid1,仅考虑操作系统自身所占空间即可,可以不为IoTDB预留系统盘空间 - 数据盘 - 建议做Raid,在磁盘维度进行数据保护 - 建议为IoTDB提供多块磁盘(1-6块左右)或磁盘组(不建议将所有磁盘做成一个磁盘阵列,会影响 IoTDB的性能上限) -2. 虚拟环境 - 建议挂载多块硬盘(1-6块左右) -3. 在部署 IoTDB 时,建议避免使用 NAS 等网络存储设备。 - -### 配置示例 - -- 示例1,4块3.5英寸硬盘 - -因服务器安装的硬盘较少,直接做Raid5即可,无需其他配置。 - -推荐配置如下: - -| **使用分类** | **Raid类型** | **硬盘数量** | **冗余** | **可用容量** | -| ----------- | -------- | -------- | --------- | -------- | -| 系统/数据盘 | RAID5 | 4 | 允许坏1块 | 3 | - -- 示例2,12块3.5英寸硬盘 - -服务器配置12块3.5英寸盘。 - -前2块盘推荐Raid1作系统盘,2组数据盘可分为2组Raid5,每组5块盘实际可用4块。 - -推荐配置如下: - -| **使用分类** | **Raid类型** | **硬盘数量** | **冗余** | **可用容量** | -| -------- | -------- | -------- | --------- | -------- | -| 系统盘 | RAID1 | 2 | 允许坏1块 | 1 | -| 数据盘 | RAID5 | 5 | 允许坏1块 | 4 | -| 数据盘 | RAID5 | 5 | 允许坏1块 | 4 | - -- 示例3,24块2.5英寸盘 - -服务器配置24块2.5英寸盘。 - -前2块盘推荐Raid1作系统盘,后面可分为3组Raid5,每组7块盘实际可用6块。剩余一块可闲置或存储写前日志使用。 - -推荐配置如下: - -| **使用分类** | **Raid类型** | **硬盘数量** | **冗余** | **可用容量** | -| -------- | -------- | -------- | --------- | -------- | -| 系统盘 | RAID1 | 2 | 允许坏1块 | 1 | -| 数据盘 | RAID5 | 7 | 允许坏1块 | 6 | -| 数据盘 | RAID5 | 7 | 允许坏1块 | 6 | -| 数据盘 | RAID5 | 7 | 允许坏1块 | 6 | -| 数据盘 | NoRaid | 1 | 损坏丢失 | 1 | - -## 操作系统 - -### 版本要求 - -IoTDB支持Linux、Windows、MacOS等操作系统,同时企业版支持龙芯、飞腾、鲲鹏等国产 CPU,支持中标麒麟、银河麒麟、统信、凝思等国产服务器操作系统。 - -### 硬盘分区 - -- 建议使用默认的标准分区方式,不推荐LVM扩展和硬盘加密。 -- 系统盘只需满足操作系统的使用空间即可,不需要为IoTDB预留空间。 -- 每个硬盘组只对应一个分区即可,数据盘(里面有多个磁盘组,对应raid)不用再额外分区,所有空间给IoTDB使用。 - -建议的磁盘分区方式如下表所示。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
硬盘分类磁盘组对应盘符大小文件系统类型
系统盘磁盘组0/boot1GB默认
/磁盘组剩余全部空间默认
数据盘磁盘组1/data1磁盘组1全部空间默认
磁盘组2/data2磁盘组2全部空间默认
......
- -### 网络配置 - -1. 关闭防火墙 - -```Bash -# 查看防火墙 -systemctl status firewalld -# 关闭防火墙 -systemctl stop firewalld -# 永久关闭防火墙 -systemctl disable firewalld -``` - -2. 保证所需端口不被占用 - -(1)集群占用端口的检查:在集群默认配置中,ConfigNode 会占用端口 10710 和 10720,DataNode 会占用端口 6667、10730、10740、10750 、10760、9090、9190、3000请确保这些端口未被占用。检查方式如下: - -```Bash -lsof -i:6667 或 netstat -tunp | grep 6667 -lsof -i:10710 或 netstat -tunp | grep 10710 -lsof -i:10720 或 netstat -tunp | grep 10720 -#如果命令有输出,则表示该端口已被占用。 -``` - -(2)集群部署工具占用端口的检查:使用集群管理工具opskit安装部署集群时,需打开SSH远程连接服务配置,并开放22号端口。 - -```Bash -yum install openssh-server #安装ssh服务 -systemctl start sshd #启用22号端口 -``` - -3. 保证服务器之间的网络相互连通 - -### 其他配置 - -1. 将系统 swap 优先级降至最低 - -```Bash -echo "vm.swappiness = 0">> /etc/sysctl.conf -# 一起执行 swapoff -a 和 swapon -a 命令是为了将 swap 里的数据转储回内存,并清空 swap 里的数据。 -# 不可省略 swappiness 设置而只执行 swapoff -a;否则,重启后 swap 会再次自动打开,使得操作失效。 -swapoff -a && swapon -a -# 在不重启的情况下使配置生效。 -sysctl -p -# swap的已使用内存变为0 -free -m -``` - -2. 设置系统最大打开文件数为 65535,以避免出现 "太多的打开文件 "的错误。 - -```Bash -#查看当前限制 -ulimit -n -# 临时修改 -ulimit -n 65535 -# 永久修改 -echo "* soft nofile 65535" >> /etc/security/limits.conf -echo "* hard nofile 65535" >> /etc/security/limits.conf -#退出当前终端会话后查看,预期显示65535 -ulimit -n -``` - -## 软件依赖 - -安装 Java 运行环境 ,Java 版本 >= 1.8,请确保已设置 jdk 环境变量。(V1.3.2.2 及之上版本推荐直接部署JDK17,老版本JDK部分场景下性能有问题,且datanode会出现stop不掉的问题) - -```Bash - #下面以在centos7,使用JDK-17安装为例: - tar -zxvf jdk-17_linux-x64_bin.tar #解压JDK文件 - Vim ~/.bashrc #配置JDK环境 - { export JAVA_HOME=/usr/lib/jvm/jdk-17.0.9 - export PATH=$JAVA_HOME/bin:$PATH - } #添加JDK环境变量 - source ~/.bashrc #配置环境生效 - java -version #检查JDK环境 -``` \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_timecho.md b/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_timecho.md deleted file mode 100644 index f824da365..000000000 --- a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_timecho.md +++ /dev/null @@ -1,46 +0,0 @@ - -# 安装包获取 - -## 企业版获取方式 - -企业版安装包可通过产品试用申请,或直接联系与您对接的商务人员获取。 - -## 安装包结构 - -解压后安装包(iotdb-enterprise-{version}-bin.zip),安装包解压后目录结构如下: - -| **目录** | **类型** | **说明** | -| ---------------- | -------- | ------------------------------------------------------------ | -| activation | 文件夹 | 激活文件所在目录,包括生成的机器码以及从商务侧获取的企业版激活码(启动ConfigNode后才会生成该目录,即可获取激活码) | -| conf | 文件夹 | 配置文件目录,包含 ConfigNode、DataNode、JMX 和 logback 等配置文件 | -| data | 文件夹 | 默认的数据文件目录,包含 ConfigNode 和 DataNode 的数据文件。(启动程序后才会生成该目录) | -| lib | 文件夹 | IoTDB可执行库文件目录 | -| licenses | 文件夹 | 开源社区证书文件目录 | -| logs | 文件夹 | 默认的日志文件目录,包含 ConfigNode 和 DataNode 的日志文件(启动程序后才会生成该目录) | -| sbin | 文件夹 | 主要脚本目录,包含启、停等脚本等 | -| tools | 文件夹 | 系统周边工具目录 | -| ext | 文件夹 | pipe,trigger,udf插件的相关文件(需要使用时用户自行创建) | -| LICENSE | 文件 | 证书 | -| NOTICE | 文件 | 提示 | -| README_ZH\.md | 文件 | markdown格式的中文版说明 | -| README\.md | 文件 | 使用说明 | -| RELEASE_NOTES\.md | 文件 | 版本说明 | diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/DBeaver.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/DBeaver.md deleted file mode 100644 index 4b0dfcfc2..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/DBeaver.md +++ /dev/null @@ -1,83 +0,0 @@ - - -# DBeaver - -DBeaver 是一个 SQL 客户端和数据库管理工具。DBeaver 可以使用 IoTDB 的 JDBC 驱动与 IoTDB 进行交互。 - -## DBeaver 安装 - -* DBeaver 下载地址:https://dbeaver.io/download/ - -## IoTDB 安装 - -* 下载 IoTDB 二进制版本 - * IoTDB 下载地址:https://iotdb.apache.org/Download/ - * 版本 >= 0.13.0 -* 或者从源代码中编译 - * 参考 https://github.com/apache/iotdb - -## 连接 IoTDB 与 DBeaver - -1. 启动 IoTDB 服务 - - ```shell - ./sbin/start-server.sh - ``` -2. 启动 DBeaver - -3. 打开 Driver Manager - - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/01.png?raw=true) -4. 为 IoTDB 新建一个驱动类型 - - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/02.png) - -5. 下载 jdbc 驱动, 点击下列网址 [地址1](https://maven.proxy.ustclug.org/maven2/org/apache/iotdb/iotdb-jdbc/) 或 [地址2](https://repo1.maven.org/maven2/org/apache/iotdb/iotdb-jdbc/),选择对应版本的 jar 包,下载后缀 jar-with-dependencies.jar 的包 - ![](/img/20230920-192746.jpg) -6. 添加刚刚下载的驱动包,点击 Find Class - - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/03.png) - -7. 编辑驱动设置 - - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/05.png) - -8. 新建 DataBase Connection, 选择 iotdb - - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/06.png) - -9. 编辑 JDBC 连接设置 - - ``` - JDBC URL: jdbc:iotdb://127.0.0.1:6667/ - Username: root - Password: root - ``` - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/07.png) - -10. 测试连接 - - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/08.png) - -11. 可以开始通过 DBeaver 使用 IoTDB - - ![](/img/UserGuide/Ecosystem-Integration/DBeaver/09.png) diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-IoTDB.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-IoTDB.md deleted file mode 100644 index 6d2e61dec..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-IoTDB.md +++ /dev/null @@ -1,121 +0,0 @@ - - -# Apache Flink(IoTDB) - -IoTDB 与 [Apache Flink](https://flink.apache.org/) 的集成。此模块包含了 iotdb sink,允许 flink job 将时序数据写入 IoTDB。 - -## IoTDBSink - -使用 `IoTDBSink` ,您需要定义一个 `IoTDBOptions` 和一个 `IoTSerializationSchema` 实例。 `IoTDBSink` 默认每次发送一个数据,可以通过调用 `withBatchSize(int)` 进行调整。 - -## 示例 - -该示例演示了如下从一个 Flink job 中发送数据到 IoTDB server 的场景: - -- 一个模拟的 Source `SensorSource` 每秒钟产生一个数据点。 - -- Flink 使用 `IoTDBSink` 消费产生的数据并写入 IoTDB 。 - - ```java - import org.apache.iotdb.flink.options.IoTDBSinkOptions; - import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; - import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; - import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; - - import com.google.common.collect.Lists; - import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; - import org.apache.flink.streaming.api.functions.source.SourceFunction; - - import java.security.SecureRandom; - import java.util.HashMap; - import java.util.Map; - import java.util.Random; - - public class FlinkIoTDBSink { - public static void main(String[] args) throws Exception { - // run the flink job on local mini cluster - StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); - - IoTDBSinkOptions options = new IoTDBSinkOptions(); - options.setHost("127.0.0.1"); - options.setPort(6667); - options.setUser("root"); - options.setPassword("root"); - - // If the server enables auto_create_schema, then we do not need to register all timeseries - // here. - options.setTimeseriesOptionList( - Lists.newArrayList( - new IoTDBSinkOptions.TimeseriesOption( - "root.sg.d1.s1", TSDataType.DOUBLE, TSEncoding.GORILLA, CompressionType.SNAPPY))); - - IoTSerializationSchema serializationSchema = new DefaultIoTSerializationSchema(); - IoTDBSink ioTDBSink = - new IoTDBSink(options, serializationSchema) - // enable batching - .withBatchSize(10) - // how many connections to the server will be created for each parallelism - .withSessionPoolSize(3); - - env.addSource(new SensorSource()) - .name("sensor-source") - .setParallelism(1) - .addSink(ioTDBSink) - .name("iotdb-sink"); - - env.execute("iotdb-flink-example"); - } - - private static class SensorSource implements SourceFunction> { - boolean running = true; - Random random = new SecureRandom(); - - @Override - public void run(SourceContext context) throws Exception { - while (running) { - Map tuple = new HashMap(); - tuple.put("device", "root.sg.d1"); - tuple.put("timestamp", String.valueOf(System.currentTimeMillis())); - tuple.put("measurements", "s1"); - tuple.put("types", "DOUBLE"); - tuple.put("values", String.valueOf(random.nextDouble())); - - context.collect(tuple); - Thread.sleep(1000); - } - } - - @Override - public void cancel() { - running = false; - } - } - } - - ``` - - - -## 运行方法 - -* 启动 IoTDB server -* 运行 `org.apache.iotdb.flink.FlinkIoTDBSink.java` 将 Flink job 运行在本地的集群上。 diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-TsFile.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-TsFile.md deleted file mode 100644 index 17a3975e6..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Flink-TsFile.md +++ /dev/null @@ -1,178 +0,0 @@ - - -# Apache Flink(TsFile) - -## 关于 TsFile-Flink 连接器 - -TsFile-Flink-Connector 对 Tsfile 类型的外部数据源实现 Flink 的支持。 这使用户可以通过 Flink DataStream/DataSet 进行读取,写入和查询。 - -使用此连接器,您可以 - -* 从本地文件系统或 hdfs 加载单个或多个 TsFile (只支持以 DataSet 的形式)到 Flink 。 -* 将本地文件系统或 hdfs 中特定目录中的所有文件加载到 Flink 中。 - -## 快速开始 - -### TsFileInputFormat 示例 - -1. 使用默认的 RowRowRecordParser 创建 TsFileInputFormat 。 - -```java -String[] filedNames = { - QueryConstant.RESERVED_TIME, - "device_1.sensor_1", - "device_1.sensor_2", - "device_1.sensor_3", - "device_2.sensor_1", - "device_2.sensor_2", - "device_2.sensor_3" -}; -TypeInformation[] typeInformations = new TypeInformation[] { - Types.LONG, - Types.FLOAT, - Types.INT, - Types.INT, - Types.FLOAT, - Types.INT, - Types.INT -}; -List paths = Arrays.stream(filedNames) - .filter(s -> !s.equals(QueryConstant.RESERVED_TIME)) - .map(Path::new) - .collect(Collectors.toList()); -RowTypeInfo rowTypeInfo = new RowTypeInfo(typeInformations, filedNames); -QueryExpression queryExpression = QueryExpression.create(paths, null); -RowRowRecordParser parser = RowRowRecordParser.create(rowTypeInfo, queryExpression.getSelectedSeries()); -TsFileInputFormat inputFormat = new TsFileInputFormat<>(queryExpression, parser); -``` - -2. 从输入格式读取数据并打印到标准输出 stdout: - -DataStream: - -```java -StreamExecutionEnvironment senv = StreamExecutionEnvironment.getExecutionEnvironment(); -inputFormat.setFilePath("source.tsfile"); -DataStream source = senv.createInput(inputFormat); -DataStream rowString = source.map(Row::toString); -Iterator result = DataStreamUtils.collect(rowString); -while (result.hasNext()) { - System.out.println(result.next()); -} -``` - -DataSet: - -```java -ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); -inputFormat.setFilePath("source.tsfile"); -DataSet source = env.createInput(inputFormat); -List result = source.map(Row::toString).collect(); -for (String s : result) { - System.out.println(s); -} -``` - -### TSRecordOutputFormat 示例 - -1. 使用默认的 RowTSRecordConverter 创建 TSRecordOutputFormat 。 - -```java -String[] filedNames = { - QueryConstant.RESERVED_TIME, - "device_1.sensor_1", - "device_1.sensor_2", - "device_1.sensor_3", - "device_2.sensor_1", - "device_2.sensor_2", - "device_2.sensor_3" -}; -TypeInformation[] typeInformations = new TypeInformation[] { - Types.LONG, - Types.LONG, - Types.LONG, - Types.LONG, - Types.LONG, - Types.LONG, - Types.LONG -}; -RowTypeInfo rowTypeInfo = new RowTypeInfo(typeInformations, filedNames); -Schema schema = new Schema(); -schema.extendTemplate("template", new MeasurementSchema("sensor_1", TSDataType.INT64, TSEncoding.TS_2DIFF)); -schema.extendTemplate("template", new MeasurementSchema("sensor_2", TSDataType.INT64, TSEncoding.TS_2DIFF)); -schema.extendTemplate("template", new MeasurementSchema("sensor_3", TSDataType.INT64, TSEncoding.TS_2DIFF)); -RowTSRecordConverter converter = new RowTSRecordConverter(rowTypeInfo); -TSRecordOutputFormat outputFormat = new TSRecordOutputFormat<>(schema, converter); -``` - -2. 通过输出格式写数据: - -DataStream: - -```java -StreamExecutionEnvironment senv = StreamExecutionEnvironment.getExecutionEnvironment(); -senv.setParallelism(1); -List data = new ArrayList<>(7); -data.add(new Tuple7(1L, 2L, 3L, 4L, 5L, 6L, 7L)); -data.add(new Tuple7(2L, 3L, 4L, 5L, 6L, 7L, 8L)); -data.add(new Tuple7(3L, 4L, 5L, 6L, 7L, 8L, 9L)); -data.add(new Tuple7(4L, 5L, 6L, 7L, 8L, 9L, 10L)); -data.add(new Tuple7(6L, 6L, 7L, 8L, 9L, 10L, 11L)); -data.add(new Tuple7(7L, 7L, 8L, 9L, 10L, 11L, 12L)); -data.add(new Tuple7(8L, 8L, 9L, 10L, 11L, 12L, 13L)); -outputFormat.setOutputFilePath(new org.apache.flink.core.fs.Path(path)); -DataStream source = senv.fromCollection( - data, Types.TUPLE(Types.LONG, Types.LONG, Types.LONG, Types.LONG, Types.LONG, Types.LONG, Types.LONG)); -source.map(t -> { - Row row = new Row(7); - for (int i = 0; i < 7; i++) { - row.setField(i, t.getField(i)); - } - return row; -}).returns(rowTypeInfo).writeUsingOutputFormat(outputFormat); -senv.execute(); -``` - -DataSet: - -```java -ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); -env.setParallelism(1); -List data = new ArrayList<>(7); -data.add(new Tuple7(1L, 2L, 3L, 4L, 5L, 6L, 7L)); -data.add(new Tuple7(2L, 3L, 4L, 5L, 6L, 7L, 8L)); -data.add(new Tuple7(3L, 4L, 5L, 6L, 7L, 8L, 9L)); -data.add(new Tuple7(4L, 5L, 6L, 7L, 8L, 9L, 10L)); -data.add(new Tuple7(6L, 6L, 7L, 8L, 9L, 10L, 11L)); -data.add(new Tuple7(7L, 7L, 8L, 9L, 10L, 11L, 12L)); -data.add(new Tuple7(8L, 8L, 9L, 10L, 11L, 12L, 13L)); -DataSet source = env.fromCollection( - data, Types.TUPLE(Types.LONG, Types.LONG, Types.LONG, Types.LONG, Types.LONG, Types.LONG, Types.LONG)); -source.map(t -> { - Row row = new Row(7); - for (int i = 0; i < 7; i++) { - row.setField(i, t.getField(i)); - } - return row; -}).returns(rowTypeInfo).write(outputFormat, path); -env.execute(); -``` diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Connector.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Connector.md deleted file mode 100644 index 3e44550ad..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Connector.md +++ /dev/null @@ -1,184 +0,0 @@ - - -# Grafana(IoTDB) - -Grafana 是开源的指标量监测和可视化工具,可用于展示时序数据和应用程序运行分析。Grafana 支持 Graphite,InfluxDB 等国际主流时序数据库作为数据源。在 IoTDB 项目中,我们开发了 Grafana 展现 IoTDB 中时序数据的连接器 IoTDB-Grafana-Connector,为您提供使用 Grafana 展示 IoTDB 数据库中的时序数据的可视化方法。 - -## Grafana 的安装与部署 - -### 安装 - -* Grafana 组件下载地址:https://grafana.com/grafana/download -* 版本 >= 4.4.1 - -### simple-json-datasource 数据源插件安装 - - -* 插件名称: simple-json-datasource -* 下载地址: https://github.com/grafana/simple-json-datasource - -#### windows系统 -具体下载方法是:到Grafana的插件目录中:`{Grafana文件目录}\data\plugins\`(Windows系统,启动Grafana后会自动创建`data\plugins`目录)或`/var/lib/grafana/plugins` (Linux系统,plugins目录需要手动创建)或`/usr/local/var/lib/grafana/plugins`(MacOS系统,具体位置参看使用`brew install`安装Grafana后命令行给出的位置提示。 - -执行下面的命令: - -``` -Shell > git clone https://github.com/grafana/simple-json-datasource.git -``` - -#### linux系统 -建议使用grafana-cli安装该插件,具体安装命令如下 - -``` -sudo grafana-cli plugins install grafana-simple-json-datasource -sudo service grafana-server restart -``` - -#### 后续操作 -然后重启Grafana服务器,在浏览器中登录Grafana,在“Add data source”页面中“Type”选项出现“SimpleJson”即为安装成功。 - -如果出现如下报错 -``` -Unsigned plugins were found during plugin initialization. Grafana Labs cannot guarantee the integrity of these plugins. We recommend only using signed plugins. -The following plugins are disabled and not shown in the list below: -``` - -请找到相关的grafana的配置文件(例如windows下的customer.ini,linux下rpm安装后为/etc/grafana/grafana.ini),并进行如下的配置 - -``` -allow_loading_unsigned_plugins = "grafana-simple-json-datasource" -``` - -### 启动 Grafana - -进入 Grafana 的安装目录,使用以下命令启动 Grafana: -* Windows 系统: -``` -Shell > bin\grafana-server.exe -``` -* Linux 系统: -``` -Shell > sudo service grafana-server start -``` -* MacOS 系统: -``` -Shell > grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins -``` -更多安装详情,请点 [这里](https://grafana.com/docs/grafana/latest/installation/) - -## IoTDB 安装 - -参见 [https://github.com/apache/iotdb](https://github.com/apache/iotdb) - -## Grafana-IoTDB-Connector 连接器安装 - -```shell -git clone https://github.com/apache/iotdb.git -``` - -## 启动 Grafana-IoTDB-Connector - - * 方案一(适合开发者) - -导入整个项目,maven 依赖安装完后,直接运行`iotdb/grafana-connector/rc/main/java/org/apache/iotdb/web/grafana`目录下`TsfileWebDemoApplication.java`,这个 grafana 连接器采用 springboot 开发 - - * 方案二(适合使用者) - -```shell -cd iotdb -mvn clean package -pl iotdb-connector/grafana-connector -am -Dmaven.test.skip=true -cd iotdb-connector/grafana-connector/target -java -jar iotdb-grafana-connector-{version}.war - . ____ _ __ _ _ - /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ -( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ - \\/ ___)| |_)| | | | | || (_| | ) ) ) ) - ' |____| .__|_| |_|_| |_\__, | / / / / - =========|_|==============|___/=/_/_/_/ - :: Spring Boot :: (v1.5.4.RELEASE) -... -``` - -如果您需要配置属性,将`grafana/src/main/resources/application.properties`移动到 war 包同级目录下(`grafana/target`) - -## 使用 Grafana - -Grafana 以网页的 dashboard 形式为您展示数据,在使用时请您打开浏览器,访问 http://\:\ - -默认地址为 http://localhost:3000/ - -注:IP 为您的 Grafana 所在的服务器 IP,Port 为 Grafana 的运行端口(默认 3000)。默认登录的用户名和密码都是“admin”。 - -### 添加 IoTDB 数据源 - -点击左上角的“Grafana”图标,选择`Data Source`选项,然后再点击`Add data source`。 - - -在编辑数据源的时候,`Type`一栏选择`Simplejson`,`URL`一栏填写 http://\:\,IP 为您的 IoTDB-Grafana-Connector 连接器所在的服务器 IP,Port 为运行端口(默认 8888)。之后确保 IoTDB 已经启动,点击“Save & Test”,出现“Data Source is working”提示表示配置成功。 - - -### 操作 Grafana - -进入 Grafana 可视化页面后,可以选择添加时间序列,如下图。您也可以按照 Grafana 官方文档进行相应的操作,详情可参看 Grafana 官方文档:http://docs.grafana.org/guides/getting_started/。 - - - -## 配置 grafana - -``` -# IoTDB 的 IP 和端口 -spring.datasource.url=jdbc:iotdb://127.0.0.1:6667/ -spring.datasource.username=root -spring.datasource.password=root -spring.datasource.driver-class-name=org.apache.iotdb.jdbc.IoTDBDriver -server.port=8888 -# Use this value to set timestamp precision as "ms", "us" or "ns", which must to be same with the timestamp -# precision of Apache IoTDB engine. -timestamp_precision=ms - -# 是否开启降采样 -isDownSampling=true -# 默认采样 interval -interval=1m -# 用于对连续数据 (int, long, float, double) 进行降采样的聚合函数 -# COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, MIN_VALUE, NOW, SUM -continuous_data_function=AVG -# 用于对离散数据 (boolean, string) 进行降采样的聚合函数 -# COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MIN_TIME, NOW -discrete_data_function=LAST_VALUE -``` - -其中 interval 具体配置信息如下 - -<1h: no sampling - -1h~1d : intervals = 1m - -1d~30d:intervals = 1h - -\>30d:intervals = 1d - -配置完后,请重新运行 war 包 - -``` -java -jar iotdb-grafana-connector-{version}.war -``` diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Hive-TsFile.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Hive-TsFile.md deleted file mode 100644 index 126a023f6..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Hive-TsFile.md +++ /dev/null @@ -1,167 +0,0 @@ - - -# Apache Hive(TsFile) - -## 什么是 TsFile 的 Hive 连接器 - -TsFile 的 Hive 连接器实现了对 Hive 读取外部 Tsfile 类型的文件格式的支持, -使用户能够通过 Hive 操作 Tsfile。 - -有了这个连接器,用户可以 -* 将单个 Tsfile 文件加载进 Hive,不论文件是存储在本地文件系统或者是 HDFS 中 -* 将某个特定目录下的所有文件加载进 Hive,不论文件是存储在本地文件系统或者是 HDFS 中 -* 使用 HQL 查询 tsfile -* 到现在为止,写操作在 hive-connector 中还没有被支持。所以,HQL 中的 insert 操作是不被允许的 - -## 系统环境要求 - -|Hadoop Version |Hive Version | Java Version | TsFile | -|------------- |------------ | ------------ |------------ | -| `2.7.3` or `3.2.1` | `2.3.6` or `3.1.2` | `1.8` | `1.0.0+`| - -## 数据类型对应关系 - -| TsFile 数据类型 | Hive 数据类型 | -| ---------------- | --------------- | -| BOOLEAN | Boolean | -| INT32 | INT | -| INT64 | BIGINT | -| FLOAT | Float | -| DOUBLE | Double | -| TEXT | STRING | - -## 为 Hive 添加依赖 jar 包 - -为了在 Hive 中使用 Tsfile 的 hive 连接器,我们需要把 hive 连接器的 jar 导入进 hive。 - -从 下载完 iotdb 后,你可以使用 `mvn clean package -pl iotdb-connector/hive-connector -am -Dmaven.test.skip=true -P get-jar-with-dependencies`命令得到一个 `hive-connector-X.X.X-SNAPSHOT-jar-with-dependencies.jar`。 - -然后在 hive 的命令行中,使用`add jar XXX`命令添加依赖。例如: - -```shell -hive> add jar /Users/hive/iotdb/hive-connector/target/hive-connector-1.0.0-jar-with-dependencies.jar; - -Added [/Users/hive/iotdb/hive-connector/target/hive-connector-1.0.0-jar-with-dependencies.jar] to class path -Added resources: [/Users/hive/iotdb/hive-connector/target/hive-connector-1.0.0-jar-with-dependencies.jar] -``` - -## 创建 Tsfile-backed 的 Hive 表 - -为了创建一个 Tsfile-backed 的表,需要将`serde`指定为`org.apache.iotdb.hive.TsFileSerDe`, -将`inputformat`指定为`org.apache.iotdb.hive.TSFHiveInputFormat`, -将`outputformat`指定为`org.apache.iotdb.hive.TSFHiveOutputFormat`。 - -同时要提供一个只包含两个字段的 Schema,这两个字段分别是`time_stamp`和`sensor_id`。 -`time_stamp`代表的是时间序列的时间值,`sensor_id`是你想要从 tsfile 文件中提取出来分析的传感器名称,比如说`sensor_1`。 -表的名字可以是 hive 所支持的任何表名。 - -需要提供一个路径供 hive-connector 从其中拉取最新的数据。 - -这个路径必须是一个指定的文件夹,这个文件夹可以在你的本地文件系统上,也可以在 HDFS 上,如果你启动了 Hadoop 的话。 -如果是本地文件系统,要以这样的形式`file:///data/data/sequence/root.baic2.WWS.leftfrontdoor/` - -最后需要在`TBLPROPERTIES`里指明`device_id` - -例如: - -``` -CREATE EXTERNAL TABLE IF NOT EXISTS only_sensor_1( - time_stamp TIMESTAMP, - sensor_1 BIGINT) -ROW FORMAT SERDE 'org.apache.iotdb.hive.TsFileSerDe' -STORED AS - INPUTFORMAT 'org.apache.iotdb.hive.TSFHiveInputFormat' - OUTPUTFORMAT 'org.apache.iotdb.hive.TSFHiveOutputFormat' -LOCATION '/data/data/sequence/root.baic2.WWS.leftfrontdoor/' -TBLPROPERTIES ('device_id'='root.baic2.WWS.leftfrontdoor.plc1'); -``` - -在这个例子里,我们从`/data/data/sequence/root.baic2.WWS.leftfrontdoor/`中拉取`root.baic2.WWS.leftfrontdoor.plc1.sensor_1`的数据。 -这个表可能产生如下描述: - -``` -hive> describe only_sensor_1; -OK -time_stamp timestamp from deserializer -sensor_1 bigint from deserializer -Time taken: 0.053 seconds, Fetched: 2 row(s) -``` - -到目前为止,Tsfile-backed 的表已经可以像 hive 中其他表一样被操作了。 - -## 从 Tsfile-backed 的 Hive 表中查询 - -在做任何查询之前,我们需要通过如下命令,在 hive 中设置`hive.input.format`: - -``` -hive> set hive.input.format=org.apache.hadoop.hive.ql.io.HiveInputFormat; -``` - -现在,我们已经在 hive 中有了一个名为`only_sensor_1`的外部表。 -我们可以使用 HQL 做任何查询来分析其中的数据。 - -例如: - -### 选择查询语句示例 - -``` -hive> select * from only_sensor_1 limit 10; -OK -1 1000000 -2 1000001 -3 1000002 -4 1000003 -5 1000004 -6 1000005 -7 1000006 -8 1000007 -9 1000008 -10 1000009 -Time taken: 1.464 seconds, Fetched: 10 row(s) -``` - -### 聚合查询语句示例 - -``` -hive> select count(*) from only_sensor_1; -WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases. -Query ID = jackietien_20191016202416_d1e3e233-d367-4453-b39a-2aac9327a3b6 -Total jobs = 1 -Launching Job 1 out of 1 -Number of reduce tasks determined at compile time: 1 -In order to change the average load for a reducer (in bytes): - set hive.exec.reducers.bytes.per.reducer= -In order to limit the maximum number of reducers: - set hive.exec.reducers.max= -In order to set a constant number of reducers: - set mapreduce.job.reduces= -Job running in-process (local Hadoop) -2019-10-16 20:24:18,305 Stage-1 map = 0%, reduce = 0% -2019-10-16 20:24:27,443 Stage-1 map = 100%, reduce = 100% -Ended Job = job_local867757288_0002 -MapReduce Jobs Launched: -Stage-Stage-1: HDFS Read: 0 HDFS Write: 0 SUCCESS -Total MapReduce CPU Time Spent: 0 msec -OK -1000000 -Time taken: 11.334 seconds, Fetched: 1 row(s) -``` diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/NiFi-IoTDB.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/NiFi-IoTDB.md deleted file mode 100644 index 62aec3970..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/NiFi-IoTDB.md +++ /dev/null @@ -1,140 +0,0 @@ - -# Apache NiFi - -## Apache NiFi简介 - -Apache NiFi 是一个易用的、功能强大的、可靠的数据处理和分发系统。 - -Apache NiFi 支持强大的、可伸缩的数据路由、转换和系统中介逻辑的有向图。 - -Apache NiFi 包含以下功能: - -* 基于浏览器的用户接口: - * 设计、控制、反馈和监控的无缝体验 -* 数据起源跟踪 - * 从头到尾完整的信息族谱 -* 丰富的配置 - * 丢失容忍和保证交付 - * 低延迟和高吞吐 - * 动态优先级策略 - * 运行时可以修改流配置 - * 反向压力控制 -* 扩展设计 - * 用于定制 processors 和 services 的组件体系结构 - * 快速开发和迭代测试 -* 安全会话 - * 带有可配置认证策略的 HTTPS 协议 - * 多租户授权和策略管理 - * 包括TLS和SSH的加密通信的标准协议 - -## PutIoTDBRecord - -这是一个用于数据写入的处理器。它使用配置的 Record Reader 将传入 FlowFile 的内容读取为单独的记录,并使用本机接口将它们写入 Apache IoTDB。 - -### PutIoTDBRecord的配置项 - -| 配置项 | 描述 | 默认值 | 是否必填 | -| ------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------| ------ | -------- | -| Host | IoTDB 的主机名 | null | true | -| Port | IoTDB 的端口 | 6667 | true | -| Username | IoTDB 的用户名 | null | true | -| Password | IoTDB 的密码 | null | true | -| Prefix | 将被写入IoTDB的数据的tsName前缀 以root. 开头
可以使用Nifi expression language做动态替换. | null | true | -| Time | 时间字段名 | null | true | -| Record Reader | 指定一个 Record Reader controller service 来解析数据,并且推断数据格式。 | null | true | -| Schema | IoTDB 需要的 schema 不能很好的被 NiFi 支持,因此你可以在这里自定义 schema。
除此之外,你可以通过这个方式设置编码和压缩类型。如果你没有设置这个配置,就会使用 Record Reader 推断的 schema。
这个配置可以通过 Attributes 的表达式来更新。 | null | false | -| Aligned | 是否使用 aligned 接口?
这个配置可以通过 Attributes 的表达式来更新。 | false | false | -| MaxRowNumber | 指定 tablet 的最大行数。
这个配置可以通过 Attributes 的表达式来更新。 | 1024 | false | - -### Flowfile 的推断数据类型 - -如果要使用推断类型,需要注意以下几点: - -1. 输入的 flowfile 需要能被 `Record Reader` 读取。 -2. flowfile的 schema 中必须包含以时间字段名属性命名的字段 -3. `Time`的数据类型只能是 `STRING` 或者 `LONG `。 -4. 除`Time` 以外的列必须以 `root.` 开头。 -5. 支持的数据类型有: `INT`,`LONG`, `FLOAT`, `DOUBLE`, `BOOLEAN`, `TEXT`。 - -### 通过配置项自定义 schema - -如上所述,通过配置项来自定义 schema 比起推断的 schema来说,是一种更加灵活和强大的方式。 - - `Schema` 配置项的解构如下: - -```json -{ - "fields": [{ - "tsName": "s1", - "dataType": "INT32", - "encoding": "RLE", - "compressionType": "GZIP" - }, { - "tsName": "s2", - "dataType": "INT64", - "encoding": "RLE", - "compressionType": "GZIP" - }] -} -``` - -**注意** - -1. flowfile 的第一列数据必须为 `Time`。剩下的必须与 `fields` 配置中保持一样的顺序。 -1. 定义 shema 的 JSON 中必须包含 `timeType` and `fields` 这两项。 -2. `timeType` 只支持 `LONG` 和 `STRING` 这两个选项。 -3. `tsName` 和 `dataType` 这两项必须被设置。 -4. 当数据插入IoTDB时,Prefix属性会被添加到 tsName以作为插入的字段名。 -5. 支持的 `dataTypes` 有:`INT32`, `INT64`, `FLOAT`, `DOUBLE`, `BOOLEAN`, `TEXT`。 -6. 支持的 `encoding` 有: `PLAIN`, `DICTIONARY`, `RLE`, `DIFF`, `TS_2DIFF`, `BITMAP`, `GORILLA_V1`, `REGULAR`, `GORILLA`,`ZIGZAG`,`CHIMP`, `SPRINTZ`, `RLBE`。 -7. 支持的 `compressionType` 有: `UNCOMPRESSED`, `SNAPPY`, `GZIP`, `LZO`, `SDT`, `PAA`, `PLA`, `LZ4`, `ZSTD`, `LZMA2`。 - -## Relationships - -| relationship | 描述 | -| ------------ | ----------------------- | -| success | 数据能被正确的写入。 | -| failure | schema 或者数据有异常。 | - -## QueryIoTDBRecord - -这是一个用于数据读取的处理器。它通过读取 FlowFile 的内容中的SQL 查询来对IoTDB的原生接口进行访问,并将查询结果用Record Writer写入 flowfile。 - -### QueryIoTDBRecord的配置项 - -| 配置项 | 描述 | 默认值 | 是否必填 | -| ------------- |--------------------------------------------------------------------------------| ------ | -------- | -| Host | IoTDB 的主机名 | null | true | -| Port | IoTDB 的端口 | 6667 | true | -| Username | IoTDB 的用户名 | null | true | -| Password | IoTDB 的密码 | null | true | -| Record Writer | 指定一个 Record Writer controller service 来写入数据。 | null | true | -| iotdb-query | 需要执行的IoTDB query
。 Note: 如果有连入侧的连接那么查询会从FlowFile的内容中提取,否则使用当前配置的属性 | null | false | -| iotdb-query-chunk-size | 返回的结果可以进行分块,数据流中会返回一批按设置大小切分的数据,而不是一个单一的响应. 分块查询可以返回无限量的行。 注意: 数据分块只有在设置不为0时启用 | 0 | false | - - -## Relationships - -| relationship | 描述 | -| ------------ | ----------------------- | -| success | 数据能被正确的写入。 | -| failure | schema 或者数据有异常。 | diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Spark-TsFile.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Spark-TsFile.md deleted file mode 100644 index 0bcc8ce91..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Spark-TsFile.md +++ /dev/null @@ -1,320 +0,0 @@ - - -# Apache Spark(TsFile) - -## About TsFile-Spark-Connector - -TsFile-Spark-Connector 对 Tsfile 类型的外部数据源实现 Spark 的支持。 这使用户可以通过 Spark 读取,写入和查询 Tsfile。 - -使用此连接器,您可以 - -- 从本地文件系统或 hdfs 加载单个 TsFile 到 Spark -- 将本地文件系统或 hdfs 中特定目录中的所有文件加载到 Spark 中 -- 将数据从 Spark 写入 TsFile - -## System Requirements - -| Spark Version | Scala Version | Java Version | TsFile | -| ------------- | ------------- | ------------ | -------- | -| `2.4.3` | `2.11.8` | `1.8` | `1.0.0` | - -> 注意:有关如何下载和使用 TsFile 的更多信息,请参见以下链接:https://github.com/apache/iotdb/tree/master/tsfile -> 注意:spark 版本目前仅支持 2.4.3, 其他版本可能存在不适配的问题,目前已知 2.4.7 的版本存在不适配的问题 - -## 快速开始 - -### 本地模式 - -在本地模式下使用 TsFile-Spark-Connector 启动 Spark: - -``` -./ --jars tsfile-spark-connector.jar,tsfile-{version}-jar-with-dependencies.jar,hadoop-tsfile-{version}-jar-with-dependencies.jar -``` - -- \是您的 spark-shell 的真实路径。 -- 多个 jar 包用逗号分隔,没有任何空格。 -- 有关如何获取 TsFile 的信息,请参见 https://github.com/apache/iotdb/tree/master/tsfile。 -- 获取到 dependency 包:```mvn clean package -DskipTests -P get-jar-with-dependencies``` - -### 分布式模式 - -在分布式模式下使用 TsFile-Spark-Connector 启动 Spark(即,Spark 集群通过 spark-shell 连接): - -``` -. / --jars tsfile-spark-connector.jar,tsfile-{version}-jar-with-dependencies.jar,hadoop-tsfile-{version}-jar-with-dependencies.jar --master spark://ip:7077 -``` - -注意: - -- \是您的 spark-shell 的真实路径。 -- 多个 jar 包用逗号分隔,没有任何空格。 -- 有关如何获取 TsFile 的信息,请参见 https://github.com/apache/iotdb/tree/master/tsfile。 - -## 数据类型对应 - -| TsFile 数据类型 | SparkSQL 数据类型 | -| -------------- | ---------------- | -| BOOLEAN | BooleanType | -| INT32 | IntegerType | -| INT64 | LongType | -| FLOAT | FloatType | -| DOUBLE | DoubleType | -| TEXT | StringType | - -## 模式推断 - -显示 TsFile 的方式取决于架构。 以以下 TsFile 结构为例:TsFile 模式中有三个度量:状态,温度和硬件。 这三种测量的基本信息如下: - -|名称 | 类型 | 编码 | -| ---- | ---- | ---- | -|状态 | Boolean|PLAIN| -|温度 | Float|RLE| -|硬件 |Text|PLAIN| - -TsFile 中的现有数据如下: - - * d1:root.ln.wf01.wt01 - * d2:root.ln.wf02.wt02 - -| time | d1.status | time | d1.temperature | time | d2.hardware | time | d2.status | -| :---- | :---- | :---- | :---- | :---- | :---- | :---- | :---- | -| 1 | True | 1 | 2.2 | 2 | "aaa" | 1 | True | -| 3 | True | 2 | 2.2 | 4 | "bbb" | 2 | False | -| 5 | False | 3 | 2.1 | 6 | "ccc" | 4 | True | - -相应的 SparkSQL 表如下: - -| time | root.ln.wf02.wt02.temperature | root.ln.wf02.wt02.status | root.ln.wf02.wt02.hardware | root.ln.wf01.wt01.temperature | root.ln.wf01.wt01.status | root.ln.wf01.wt01.hardware | -| ---- | ----------------------------- | ------------------------ | -------------------------- | ----------------------------- | ------------------------ | -------------------------- | -| 1 | null | true | null | 2.2 | true | null | -| 2 | null | false | aaa | 2.2 | null | null | -| 3 | null | null | null | 2.1 | true | null | -| 4 | null | true | bbb | null | null | null | -| 5 | null | null | null | null | false | null | -| 6 | null | null | ccc | null | null | null | - -您还可以使用如下所示的窄表形式:(您可以参阅第 6 部分,了解如何使用窄表形式) - -| time | device_name | status | hardware | temperature | -| ---- | ----------------- | ------ | -------- | ----------- | -| 1 | root.ln.wf02.wt01 | true | null | 2.2 | -| 1 | root.ln.wf02.wt02 | true | null | null | -| 2 | root.ln.wf02.wt01 | null | null | 2.2 | -| 2 | root.ln.wf02.wt02 | false | aaa | null | -| 3 | root.ln.wf02.wt01 | true | null | 2.1 | -| 4 | root.ln.wf02.wt02 | true | bbb | null | -| 5 | root.ln.wf02.wt01 | false | null | null | -| 6 | root.ln.wf02.wt02 | null | ccc | null | - -## Scala API - -注意:请记住预先分配必要的读写权限。 - - * 示例 1:从本地文件系统读取 - -```scala -import org.apache.iotdb.spark.tsfile._ -val wide_df = spark.read.tsfile("test.tsfile") -wide_df.show - -val narrow_df = spark.read.tsfile("test.tsfile", true) -narrow_df.show -``` - - * 示例 2:从 hadoop 文件系统读取 - -```scala -import org.apache.iotdb.spark.tsfile._ -val wide_df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile") -wide_df.show - -val narrow_df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile", true) -narrow_df.show -``` - - * 示例 3:从特定目录读取 - -```scala -import org.apache.iotdb.spark.tsfile._ -val df = spark.read.tsfile("hdfs://localhost:9000/usr/hadoop") -df.show -``` - -注 1:现在不支持目录中所有 TsFile 的全局时间排序。 - -注 2:具有相同名称的度量应具有相同的架构。 - - * 示例 4:广泛形式的查询 - -```scala -import org.apache.iotdb.spark.tsfile._ -val df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile") -df.createOrReplaceTempView("tsfile_table") -val newDf = spark.sql("select * from tsfile_table where `device_1.sensor_1`>0 and `device_1.sensor_2` < 22") -newDf.show -``` - -```scala -import org.apache.iotdb.spark.tsfile._ -val df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile") -df.createOrReplaceTempView("tsfile_table") -val newDf = spark.sql("select count(*) from tsfile_table") -newDf.show -``` - - * 示例 5:缩小形式的查询 - -```scala -import org.apache.iotdb.spark.tsfile._ -val df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile", true) -df.createOrReplaceTempView("tsfile_table") -val newDf = spark.sql("select * from tsfile_table where device_name = 'root.ln.wf02.wt02' and temperature > 5") -newDf.show -``` - -```scala -import org.apache.iotdb.spark.tsfile._ -val df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile", true) -df.createOrReplaceTempView("tsfile_table") -val newDf = spark.sql("select count(*) from tsfile_table") -newDf.show -``` - - * 例 6:写宽格式 - -```scala -// we only support wide_form table to write -import org.apache.iotdb.spark.tsfile._ - -val df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile") -df.show -df.write.tsfile("hdfs://localhost:9000/output") - -val newDf = spark.read.tsfile("hdfs://localhost:9000/output") -newDf.show -``` - - * 例 7:写窄格式 - -```scala -// we only support wide_form table to write -import org.apache.iotdb.spark.tsfile._ - -val df = spark.read.tsfile("hdfs://localhost:9000/test.tsfile", true) -df.show -df.write.tsfile("hdfs://localhost:9000/output", true) - -val newDf = spark.read.tsfile("hdfs://localhost:9000/output", true) -newDf.show -``` - -附录 A:模式推断的旧设计 - -显示 TsFile 的方式与 TsFile Schema 有关。 以以下 TsFile 结构为例:TsFile 架构中有三个度量:状态,温度和硬件。 这三个度量的基本信息如下: - -|名称 | 类型 | 编码 | -| ---- | ---- | ---- | -|状态 | Boolean|PLAIN| -|温度 | Float|RLE| -|硬件|Text|PLAIN| - -文件中的现有数据如下: - - * delta_object1: root.ln.wf01.wt01 - * delta_object2: root.ln.wf02.wt02 - * delta_object3: :root.sgcc.wf03.wt01 - -| time | delta_object1.status | time | delta_object1.temperature | time | delta_object2.hardware | time | delta_object2.status | time | delta_object3.status | time | delta_object3.temperature | -| :---- | :---- | :---- | :---- | :---- | :---- | :---- | :---- | :---- | :---- | :---- | :---- | -| 1 | True | 1 | 2.2 | 2 | "aaa" | 1 | True | 2 | True | 3 | 3.3 | -| 3 | True | 2 | 2.2 | 4 | "bbb" | 2 | False | 3 | True | 6 | 6.6 | -| 5 | False| 3 | 2.1 | 6 | "ccc" | 4 | True | 4 | True | 8 | 8.8 | -| 7 | True | 4 | 2.0 | 8 | "ddd" | 5 | False | 6 | True | 9 | 9.9 | - -有两种显示方法: - - * 默认方式 - -将创建两列来存储设备的完整路径:time(LongType)和 delta_object(StringType)。 - -- `time`:时间戳记,LongType -- `delta_object`:Delta_object ID,StringType - -接下来,为每个度量创建一列以存储特定数据。 SparkSQL 表结构如下: - -|time(LongType)|delta\_object(StringType)|status(BooleanType)|temperature(FloatType)|hardware(StringType)| -|--- |--- |--- |--- |--- | -|1|root.ln.wf01.wt01|True|2.2|null| -|1|root.ln.wf02.wt02|True|null|null| -|2|root.ln.wf01.wt01|null|2.2|null| -|2|root.ln.wf02.wt02|False|null|"aaa"| -|2|root.sgcc.wf03.wt01|True|null|null| -|3|root.ln.wf01.wt01|True|2.1|null| -|3|root.sgcc.wf03.wt01|True|3.3|null| -|4|root.ln.wf01.wt01|null|2.0|null| -|4|root.ln.wf02.wt02|True|null|"bbb"| -|4|root.sgcc.wf03.wt01|True|null|null| -|5|root.ln.wf01.wt01|False|null|null| -|5|root.ln.wf02.wt02|False|null|null| -|5|root.sgcc.wf03.wt01|True|null|null| -|6|root.ln.wf02.wt02|null|null|"ccc"| -|6|root.sgcc.wf03.wt01|null|6.6|null| -|7|root.ln.wf01.wt01|True|null|null| -|8|root.ln.wf02.wt02|null|null|"ddd"| -|8|root.sgcc.wf03.wt01|null|8.8|null| -|9|root.sgcc.wf03.wt01|null|9.9|null| - - * 展开 delta_object 列 - -通过“。”将设备列展开为多个列,忽略根目录“root”。方便进行更丰富的聚合操作。如果用户想使用这种显示方式,需要在表创建语句中设置参数“delta\_object\_name”(参考本手册 5.1 节中的示例 5),在本例中,将参数“delta\_object\_name”设置为“root.device.turbine”。路径层的数量必须是一对一的。此时,除了“根”层之外,为设备路径的每一层创建一列。列名是参数中的名称,值是设备相应层的名称。接下来,将为每个度量创建一个列来存储特定的数据。 - -那么 SparkSQL 表结构如下: - -|time(LongType)|group(StringType)|field(StringType)|device(StringType)|status(BooleanType)|temperature(FloatType)|hardware(StringType)| -|--- |--- |--- |--- |--- |--- |--- | -|1|ln|wf01|wt01|True|2.2|null| -|1|ln|wf02|wt02|True|null|null| -|2|ln|wf01|wt01|null|2.2|null| -|2|ln|wf02|wt02|False|null|"aaa"| -|2|sgcc|wf03|wt01|True|null|null| -|3|ln|wf01|wt01|True|2.1|null| -|3|sgcc|wf03|wt01|True|3.3|null| -|4|ln|wf01|wt01|null|2.0|null| -|4|ln|wf02|wt02|True|null|"bbb"| -|4|sgcc|wf03|wt01|True|null|null| -|5|ln|wf01|wt01|False|null|null| -|5|ln|wf02|wt02|False|null|null| -|5|sgcc|wf03|wt01|True|null|null| -|6|ln|wf02|wt02|null|null|"ccc"| -|6|sgcc|wf03|wt01|null|6.6|null| -|7|ln|wf01|wt01|True|null|null| -|8|ln|wf02|wt02|null|null|"ddd"| -|8|sgcc|wf03|wt01|null|8.8|null| -|9|sgcc|wf03|wt01|null|9.9|null| - -TsFile-Spark-Connector 可以通过 SparkSQL 在 SparkSQL 中以表的形式显示一个或多个 tsfile。它还允许用户指定一个目录或使用通配符来匹配多个目录。如果有多个 tsfile,那么所有 tsfile 中的度量值的并集将保留在表中,并且具有相同名称的度量值在默认情况下具有相同的数据类型。注意,如果存在名称相同但数据类型不同的情况,TsFile-Spark-Connector 将不能保证结果的正确性。 - -写入过程是将数据 aframe 写入一个或多个 tsfile。默认情况下,需要包含两个列:time 和 delta_object。其余的列用作测量。如果用户希望将第二个表结构写回 TsFile,可以设置“delta\_object\_name”参数(请参阅本手册 5.1 节的 5.1 节)。 - -附录 B:旧注 - -注意:检查 Spark 根目录中的 jar 软件包,并将 libthrift-0.9.2.jar 和 libfb303-0.9.2.jar 分别替换为 libthrift-0.9.1.jar 和 libfb303-0.9.1.jar。 diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_apache.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_apache.md deleted file mode 100644 index b02f8c91d..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_apache.md +++ /dev/null @@ -1,174 +0,0 @@ - - -# Apache Zeppelin - -## Zeppelin 简介 - -Apache Zeppelin 是一个基于网页的交互式数据分析系统。用户可以通过 Zeppelin 连接数据源并使用 SQL、Scala 等进行交互式操作。操作可以保存为文档(类似于 Jupyter)。Zeppelin 支持多种数据源,包括 Spark、ElasticSearch、Cassandra 和 InfluxDB 等等。现在,IoTDB 已经支持使用 Zeppelin 进行操作。样例如下: - -![iotdb-note-snapshot](/img/github/102752947-520a3e80-43a5-11eb-8fb1-8fac471c8c7e.png) - -## Zeppelin-IoTDB 解释器 - -### 系统环境需求 - -| IoTDB 版本 | Java 版本 | Zeppelin 版本 | -| :--------: | :-----------: | :-----------: | -| >=`0.12.0` | >=`1.8.0_271` | `>=0.9.0` | - -安装 IoTDB:参考 [快速上手](../Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md). 假设 IoTDB 安装在 `$IoTDB_HOME`. - -安装 Zeppelin: -> 方法 1 直接下载:下载 [Zeppelin](https://zeppelin.apache.org/download.html#) 并解压二进制文件。推荐下载 [netinst](http://www.apache.org/dyn/closer.cgi/zeppelin/zeppelin-0.9.0/zeppelin-0.9.0-bin-netinst.tgz) 二进制包,此包由于未编译不相关的 interpreter,因此大小相对较小。 -> -> 方法 2 源码编译:参考 [从源码构建 Zeppelin](https://zeppelin.apache.org/docs/latest/setup/basics/how_to_build.html) ,使用命令为 `mvn clean package -pl zeppelin-web,zeppelin-server -am -DskipTests`。 - -假设 Zeppelin 安装在 `$Zeppelin_HOME`. - -### 编译解释器 - -运行如下命令编译 IoTDB Zeppelin 解释器。 - -```shell -cd $IoTDB_HOME - mvn clean package -pl iotdb-connector/zeppelin-interpreter -am -DskipTests -P get-jar-with-dependencies -``` - -编译后的解释器位于如下目录: - -```shell -$IoTDB_HOME/zeppelin-interpreter/target/zeppelin-{version}-SNAPSHOT-jar-with-dependencies.jar -``` - -### 安装解释器 - -当你编译好了解释器,在 Zeppelin 的解释器目录下创建一个新的文件夹`iotdb`,并将 IoTDB 解释器放入其中。 - -```shell -cd $IoTDB_HOME -mkdir -p $Zeppelin_HOME/interpreter/iotdb -cp $IoTDB_HOME/zeppelin-interpreter/target/zeppelin-{version}-SNAPSHOT-jar-with-dependencies.jar $Zeppelin_HOME/interpreter/iotdb -``` - -### 修改 Zeppelin 配置 - -进入 `$Zeppelin_HOME/conf`,使用 template 创建 Zeppelin 配置文件: - -```shell -cp zeppelin-site.xml.template zeppelin-site.xml -``` - -打开 zeppelin-site.xml 文件,将 `zeppelin.server.addr` 项修改为 `0.0.0.0` - -### 启动 Zeppelin 和 IoTDB - -进入 `$Zeppelin_HOME` 并运行 Zeppelin: - -```shell -# Unix/OS X -> ./bin/zeppelin-daemon.sh start - -# Windows -> .\bin\zeppelin.cmd -``` - -进入 `$IoTDB_HOME` 并运行 IoTDB: - -```shell -# Unix/OS X -> nohup sbin/start-server.sh >/dev/null 2>&1 & -or -> nohup sbin/start-server.sh -c -rpc_port >/dev/null 2>&1 & - -# Windows -> sbin\start-server.bat -c -rpc_port -``` - -## 使用 Zeppelin-IoTDB 解释器 - -当 Zeppelin 启动后,访问 [http://127.0.0.1:8080/](http://127.0.0.1:8080/) - -通过如下步骤创建一个新的笔记本页面: - -1. 点击 `Create new node` 按钮 -2. 设置笔记本名 -3. 选择解释器为 iotdb - -现在可以开始使用 Zeppelin 操作 IoTDB 了。 - -![iotdb-create-note](/img/github/102752945-5171a800-43a5-11eb-8614-53b3276a3ce2.png) - -我们提供了一些简单的 SQL 来展示 Zeppelin-IoTDB 解释器的使用: - -```sql -CREATE DATABASE root.ln.wf01.wt01; -CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN; -CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=PLAIN; -CREATE TIMESERIES root.ln.wf01.wt01.hardware WITH DATATYPE=INT32, ENCODING=PLAIN; - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (1, 1.1, false, 11); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (2, 2.2, true, 22); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (3, 3.3, false, 33); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (4, 4.4, false, 44); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (5, 5.5, false, 55); - -SELECT * -FROM root.ln.wf01.wt01 -WHERE time >= 1 - AND time <= 6; -``` - -样例如下: - -![iotdb-note-snapshot2](/img/github/102752948-52a2d500-43a5-11eb-9156-0c55667eb4cd.png) - -用户也可以参考 [[1]](https://zeppelin.apache.org/docs/0.9.0/usage/display_system/basic.html) 编写更丰富多彩的文档。 - -以上样例放置于 `$IoTDB_HOME/zeppelin-interpreter/Zeppelin-IoTDB-Demo.zpln` - -## 解释器配置项 - -进入页面 [http://127.0.0.1:8080/#/interpreter](http://127.0.0.1:8080/#/interpreter) 并配置 IoTDB 的连接参数: - -![iotdb-configuration](/img/github/102752940-50407b00-43a5-11eb-94fb-3e3be222183c.png) - -可配置参数默认值和解释如下: - -| 属性 | 默认值 | 描述 | -| ---------------------------- | --------- | -------------------------------- | -| iotdb.host | 127.0.0.1 | IoTDB 主机名 | -| iotdb.port | 6667 | IoTDB 端口 | -| iotdb.username | root | 用户名 | -| iotdb.password | root | 密码 | -| iotdb.fetchSize | 10000 | 查询结果分批次返回时,每一批数量 | -| iotdb.zoneId | | 时区 ID | -| iotdb.enable.rpc.compression | FALSE | 是否允许 rpc 压缩 | -| iotdb.time.display.type | default | 时间戳的展示格式 | diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md b/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md deleted file mode 100644 index 39ea4384b..000000000 --- a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md +++ /dev/null @@ -1,174 +0,0 @@ - - -# Apache Zeppelin - -## Zeppelin 简介 - -Apache Zeppelin 是一个基于网页的交互式数据分析系统。用户可以通过 Zeppelin 连接数据源并使用 SQL、Scala 等进行交互式操作。操作可以保存为文档(类似于 Jupyter)。Zeppelin 支持多种数据源,包括 Spark、ElasticSearch、Cassandra 和 InfluxDB 等等。现在,IoTDB 已经支持使用 Zeppelin 进行操作。样例如下: - -![iotdb-note-snapshot](/img/github/102752947-520a3e80-43a5-11eb-8fb1-8fac471c8c7e.png) - -## Zeppelin-IoTDB 解释器 - -### 系统环境需求 - -| IoTDB 版本 | Java 版本 | Zeppelin 版本 | -| :--------: | :-----------: | :-----------: | -| >=`0.12.0` | >=`1.8.0_271` | `>=0.9.0` | - -安装 IoTDB:参考 [快速上手](../Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md). 假设 IoTDB 安装在 `$IoTDB_HOME`. - -安装 Zeppelin: -> 方法 1 直接下载:下载 [Zeppelin](https://zeppelin.apache.org/download.html#) 并解压二进制文件。推荐下载 [netinst](http://www.apache.org/dyn/closer.cgi/zeppelin/zeppelin-0.9.0/zeppelin-0.9.0-bin-netinst.tgz) 二进制包,此包由于未编译不相关的 interpreter,因此大小相对较小。 -> -> 方法 2 源码编译:参考 [从源码构建 Zeppelin](https://zeppelin.apache.org/docs/latest/setup/basics/how_to_build.html) ,使用命令为 `mvn clean package -pl zeppelin-web,zeppelin-server -am -DskipTests`。 - -假设 Zeppelin 安装在 `$Zeppelin_HOME`. - -### 编译解释器 - -运行如下命令编译 IoTDB Zeppelin 解释器。 - -```shell -cd $IoTDB_HOME - mvn clean package -pl iotdb-connector/zeppelin-interpreter -am -DskipTests -P get-jar-with-dependencies -``` - -编译后的解释器位于如下目录: - -```shell -$IoTDB_HOME/zeppelin-interpreter/target/zeppelin-{version}-SNAPSHOT-jar-with-dependencies.jar -``` - -### 安装解释器 - -当你编译好了解释器,在 Zeppelin 的解释器目录下创建一个新的文件夹`iotdb`,并将 IoTDB 解释器放入其中。 - -```shell -cd $IoTDB_HOME -mkdir -p $Zeppelin_HOME/interpreter/iotdb -cp $IoTDB_HOME/zeppelin-interpreter/target/zeppelin-{version}-SNAPSHOT-jar-with-dependencies.jar $Zeppelin_HOME/interpreter/iotdb -``` - -### 修改 Zeppelin 配置 - -进入 `$Zeppelin_HOME/conf`,使用 template 创建 Zeppelin 配置文件: - -```shell -cp zeppelin-site.xml.template zeppelin-site.xml -``` - -打开 zeppelin-site.xml 文件,将 `zeppelin.server.addr` 项修改为 `0.0.0.0` - -### 启动 Zeppelin 和 IoTDB - -进入 `$Zeppelin_HOME` 并运行 Zeppelin: - -```shell -# Unix/OS X -> ./bin/zeppelin-daemon.sh start - -# Windows -> .\bin\zeppelin.cmd -``` - -进入 `$IoTDB_HOME` 并运行 IoTDB: - -```shell -# Unix/OS X -> nohup sbin/start-server.sh >/dev/null 2>&1 & -or -> nohup sbin/start-server.sh -c -rpc_port >/dev/null 2>&1 & - -# Windows -> sbin\start-server.bat -c -rpc_port -``` - -## 使用 Zeppelin-IoTDB 解释器 - -当 Zeppelin 启动后,访问 [http://127.0.0.1:8080/](http://127.0.0.1:8080/) - -通过如下步骤创建一个新的笔记本页面: - -1. 点击 `Create new node` 按钮 -2. 设置笔记本名 -3. 选择解释器为 iotdb - -现在可以开始使用 Zeppelin 操作 IoTDB 了。 - -![iotdb-create-note](/img/github/102752945-5171a800-43a5-11eb-8614-53b3276a3ce2.png) - -我们提供了一些简单的 SQL 来展示 Zeppelin-IoTDB 解释器的使用: - -```sql -CREATE DATABASE root.ln.wf01.wt01; -CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN; -CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=PLAIN; -CREATE TIMESERIES root.ln.wf01.wt01.hardware WITH DATATYPE=INT32, ENCODING=PLAIN; - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (1, 1.1, false, 11); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (2, 2.2, true, 22); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (3, 3.3, false, 33); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (4, 4.4, false, 44); - -INSERT INTO root.ln.wf01.wt01 (timestamp, temperature, status, hardware) -VALUES (5, 5.5, false, 55); - -SELECT * -FROM root.ln.wf01.wt01 -WHERE time >= 1 - AND time <= 6; -``` - -样例如下: - -![iotdb-note-snapshot2](/img/github/102752948-52a2d500-43a5-11eb-9156-0c55667eb4cd.png) - -用户也可以参考 [[1]](https://zeppelin.apache.org/docs/0.9.0/usage/display_system/basic.html) 编写更丰富多彩的文档。 - -以上样例放置于 `$IoTDB_HOME/zeppelin-interpreter/Zeppelin-IoTDB-Demo.zpln` - -## 解释器配置项 - -进入页面 [http://127.0.0.1:8080/#/interpreter](http://127.0.0.1:8080/#/interpreter) 并配置 IoTDB 的连接参数: - -![iotdb-configuration](/img/github/102752940-50407b00-43a5-11eb-94fb-3e3be222183c.png) - -可配置参数默认值和解释如下: - -| 属性 | 默认值 | 描述 | -| ---------------------------- | --------- | -------------------------------- | -| iotdb.host | 127.0.0.1 | IoTDB 主机名 | -| iotdb.port | 6667 | IoTDB 端口 | -| iotdb.username | root | 用户名 | -| iotdb.password | root | 密码 | -| iotdb.fetchSize | 10000 | 查询结果分批次返回时,每一批数量 | -| iotdb.zoneId | | 时区 ID | -| iotdb.enable.rpc.compression | FALSE | 是否允许 rpc 压缩 | -| iotdb.time.display.type | default | 时间戳的展示格式 | diff --git a/src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Scenario.md b/src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Scenario.md deleted file mode 100644 index 6a9e186c8..000000000 --- a/src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Scenario.md +++ /dev/null @@ -1,95 +0,0 @@ - - -# 应用场景 - -## 应用1——车联网 - -### 背景 - -> - 难点:设备多,序列多 - -某车企业务体量庞大,需处理车辆多、数据量大,亿级数据测点,每秒超千万条新增数据点,毫秒级采集频率,对数据库的实时写入、存储与处理能力均要求较高。 - -原始架构中使用Hbase集群作为存储数据库,查询延迟高,系统维护难度和成本高。难以满足需求。而IoTDB支持百万级测点数高频数据写入和查询毫秒级响应,高效的数据处理方式可以让用户快速、准确地获取到所需数据,大幅提升了数据处理的效率。 - -因此选择以IoTDB为数据存储层,架构轻量,减轻运维成本,且支持弹性扩缩容和高可用,确保系统的稳定性和可用性。 - -### 架构 - -该车企以IoTDB为时序数据存储引擎的数据管理架构如下图所示。 - - -![img](/img/1280X1280.png) - -车辆数据基于TCP和工业协议编码后发送至边缘网关,网关将数据发往消息队列Kafka集群,解耦生产和消费两端。Kafka将数据发送至Flink进行实时处理,处理后的数据写入IoTDB中,历史数据和最新数据均在IoTDB中进行查询,最后数据通过API流入可视化平台等进行应用。 - -## 应用2——智能运维 - -### 背景 - -某钢厂旨在搭建低成本、大规模接入能力的远程智能运维软硬件平台,接入数百条产线,百万以上设备,千万级时间序列,实现智能运维远程覆盖。 - -此过程中面临诸多痛点: - -> - 设备种类繁多、协议众多、数据类型众多 -> - 时序数据特别是高频数据,数据量巨大 -> - 海量时序数据下的读写速度无法满足业务需求 -> - 现有时序数据管理组件无法满足各类高级应用需求 - -而选取IoTDB作为智能运维平台的存储数据库后,能稳定写入多频及高频采集数据,覆盖钢铁全工序,并采用复合压缩算法使数据大小缩减10倍以上,节省成本。IoTDB 还有效支持超过10年的历史数据降采样查询,帮助企业挖掘数据趋势,助力企业长远战略分析。 - -### 架构 - -下图为该钢厂的智能运维平台架构设计。 - -![img](/img/1280X1280%20(1).png) - -## 应用3——智能工厂 - -### 背景 - -> - 难点/亮点:云边协同 - -某卷烟厂希望从“传统工厂”向“高端工厂”完成转型升级,利用物联网和设备监控技术,加强信息管理和服务实现数据在企业内部自由流动,数据和决策的上通下达,帮助企业提高生产力,降低运营成本。 - -### 架构 - -下图为该工厂的物联网系统架构,IoTDB贯穿公司、工厂、车间三级物联网平台,实现设备统一联调联控。车间层面的数据通过边缘层的IoTDB进行实时采集、处理和存储,并实现了一系列的分析任务。经过预处理的数据被发送至平台层的IoTDB,进行业务层面的数据治理,如设备管理、连接管理、服务支持等。最终,数据会被集成到集团层面的IoTDB中,供整个组织进行综合分析和决策。 - -![img](/img/1280X1280%20(2).png) - - -## 应用4——工况监控 - -### 背景 - -> - 难点/亮点:智慧供热,降本增效 - -某电厂需要对风机锅炉设备、发电机、变电设备等主辅机数万测点进行监控。在以往的供暖供热过程中缺少对于下一阶段的供热量的预判,导致无效供热、过度供热、供热不足等情况。 - -使用IoTDB作为存储与分析引擎后,结合气象数据、楼控数据、户控数据、换热站数据、官网数据、热源侧数据等总和评判供热量,所有数据在IoTDB中进行时间对齐,为智慧供热提供可靠的数据依据,实现智慧供热。同时也解决了按需计费、管网、热站等相关供热过程中各重要组成部分的工况监控,减少了人力投入。 - -### 架构 - -下图为该电厂的供热场景数据管理架构。 - -![img](/img/7b7a22ae-6367-4084-a526-53c88190bc50.png) diff --git a/src/zh/UserGuide/V1.3.3/Reference/Keywords.md b/src/zh/UserGuide/V1.3.3/Reference/Keywords.md deleted file mode 100644 index 0d681ffbb..000000000 --- a/src/zh/UserGuide/V1.3.3/Reference/Keywords.md +++ /dev/null @@ -1,227 +0,0 @@ - - -# 关键字 - -保留字(不能用于作为标识符): - -- ROOT -- TIME -- TIMESTAMP - -一般关键字: - -- ADD -- AFTER -- ALIAS -- ALIGN -- ALIGNED -- ALL -- ALTER -- ALTER_TIMESERIES -- ANY -- APPEND -- APPLY_TEMPLATE -- AS -- ASC -- ATTRIBUTES -- BEFORE -- BEGIN -- BLOCKED -- BOUNDARY -- BY -- CACHE -- CHILD -- CLEAR -- CLUSTER -- CONCAT -- CONFIGNODES -- CONFIGURATION -- CONTINUOUS -- COUNT -- CONTAIN -- CQ -- CQS -- CREATE -- CREATE_CONTINUOUS_QUERY -- CREATE_FUNCTION -- CREATE_ROLE -- CREATE_TIMESERIES -- CREATE_TRIGGER -- CREATE_USER -- DATA -- DATABASE -- DATABASES -- DATANODES -- DEACTIVATE -- DEBUG -- DELETE -- DELETE_ROLE -- DELETE_STORAGE_GROUP -- DELETE_TIMESERIES -- DELETE_USER -- DESC -- DESCRIBE -- DEVICE -- DEVICEID -- DEVICES -- DISABLE -- DISCARD -- DROP -- DROP_CONTINUOUS_QUERY -- DROP_FUNCTION -- DROP_TRIGGER -- END -- ENDTIME -- EVERY -- EXPLAIN -- FILL -- FILE -- FLUSH -- FOR -- FROM -- FULL -- FUNCTION -- FUNCTIONS -- GLOBAL -- GRANT -- GRANT_ROLE_PRIVILEGE -- GRANT_USER_PRIVILEGE -- GRANT_USER_ROLE -- GROUP -- HAVING -- HEAD -- INDEX -- INFO -- INSERT -- INSERT_TIMESERIES -- INTO -- KILL -- LABEL -- LAST -- LATEST -- LEVEL -- LIKE -- LIMIT -- LINEAR -- LINK -- LIST -- LIST_ROLE -- LIST_USER -- LOAD -- LOCAL -- LOCK -- MERGE -- METADATA -- MODIFY_PASSWORD -- NODES -- NONE -- NOW -- OF -- OFF -- OFFSET -- ON -- ORDER -- ONSUCCESS -- PARTITION -- PASSWORD -- PATHS -- PIPE -- PIPES -- PIPESINK -- PIPESINKS -- PIPESINKTYPE -- POLICY -- PREVIOUS -- PREVIOUSUNTILLAST -- PRIVILEGES -- PROCESSLIST -- PROPERTY -- PRUNE -- QUERIES -- QUERY -- RANGE -- READONLY -- READ_TEMPLATE -- READ_TEMPLATE_APPLICATION -- READ_TIMESERIES -- REGEXP -- REGIONID -- REGIONS -- REMOVE -- RENAME -- RESAMPLE -- RESOURCE -- REVOKE -- REVOKE_ROLE_PRIVILEGE -- REVOKE_USER_PRIVILEGE -- REVOKE_USER_ROLE -- ROLE -- RUNNING -- SCHEMA -- SELECT -- SERIESSLOTID -- SET -- SET_STORAGE_GROUP -- SETTLE -- SGLEVEL -- SHOW -- SLIMIT -- SOFFSET -- STORAGE -- START -- STARTTIME -- STATELESS -- STATEFUL -- STOP -- SYSTEM -- TAIL -- TAGS -- TASK -- TEMPLATE -- TIMEOUT -- TIMESERIES -- TIMESLOTID -- TO -- TOLERANCE -- TOP -- TRACING -- TRIGGER -- TRIGGERS -- TTL -- UNLINK -- UNLOAD -- UNSET -- UPDATE -- UPDATE_TEMPLATE -- UPSERT -- URI -- USER -- USING -- VALUES -- VERIFY -- VERSION -- VIEW -- WATERMARK_EMBEDDING -- WHERE -- WITH -- WITHOUT -- WRITABLE \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/Reference/Status-Codes.md b/src/zh/UserGuide/V1.3.3/Reference/Status-Codes.md deleted file mode 100644 index d941f7862..000000000 --- a/src/zh/UserGuide/V1.3.3/Reference/Status-Codes.md +++ /dev/null @@ -1,178 +0,0 @@ - - -# 状态码 - -IoTDB 引入了**状态码**这一概念。例如,因为 IoTDB 需要在写入数据之前首先注册时间序列,一种可能的解决方案是: - -``` -try { - writeData(); -} catch (SQLException e) { - // the most case is that the time series does not exist - if (e.getMessage().contains("exist")) { - //However, using the content of the error message is not so efficient - registerTimeSeries(); - //write data once again - writeData(); - } -} - -``` - -利用状态码,我们就可以不必写诸如`if (e.getErrorMessage().contains("exist"))`的代码, -只需要使用`e.getStatusType().getCode() == TSStatusCode.TIME_SERIES_NOT_EXIST_ERROR.getStatusCode()`。 - -这里是状态码和相对应信息的列表: - -| 状态码 | 状态类型 | 状态信息 | -|:-----|:---------------------------------------|:--------------------------| -| 200 | SUCCESS_STATUS | 成功状态 | -| 201 | INCOMPATIBLE_VERSION | 版本不兼容 | -| 202 | CONFIGURATION_ERROR | 配置文件有错误项 | -| 203 | START_UP_ERROR | 启动错误 | -| 204 | SHUT_DOWN_ERROR | 关机错误 | -| 300 | UNSUPPORTED_OPERATION | 不支持的操作 | -| 301 | EXECUTE_STATEMENT_ERROR | 执行语句错误 | -| 302 | MULTIPLE_ERROR | 多行语句执行错误 | -| 303 | ILLEGAL_PARAMETER | 参数错误 | -| 304 | OVERLAP_WITH_EXISTING_TASK | 与正在执行的其他操作冲突 | -| 305 | INTERNAL_SERVER_ERROR | 服务器内部错误 | -| 306 | DISPATCH_ERROR | 分发错误 | -| 400 | REDIRECTION_RECOMMEND | 推荐客户端重定向 | -| 500 | DATABASE_NOT_EXIST | 数据库不存在 | -| 501 | DATABASE_ALREADY_EXISTS | 数据库已存在 | -| 502 | SERIES_OVERFLOW | 序列数量超过阈值 | -| 503 | TIMESERIES_ALREADY_EXIST | 时间序列已存在 | -| 504 | TIMESERIES_IN_BLACK_LIST | 时间序列正在删除 | -| 505 | ALIAS_ALREADY_EXIST | 路径别名已经存在 | -| 506 | PATH_ALREADY_EXIST | 路径已经存在 | -| 507 | METADATA_ERROR | 处理元数据错误 | -| 508 | PATH_NOT_EXIST | 路径不存在 | -| 509 | ILLEGAL_PATH | 路径不合法 | -| 510 | CREATE_TEMPLATE_ERROR | 创建物理量模板失败 | -| 511 | DUPLICATED_TEMPLATE | 元数据模板重复 | -| 512 | UNDEFINED_TEMPLATE | 元数据模板未定义 | -| 513 | TEMPLATE_NOT_SET | 元数据模板未设置 | -| 514 | DIFFERENT_TEMPLATE | 元数据模板不一致 | -| 515 | TEMPLATE_IS_IN_USE | 元数据模板正在使用 | -| 516 | TEMPLATE_INCOMPATIBLE | 元数据模板不兼容 | -| 517 | SEGMENT_NOT_FOUND | 未找到 Segment | -| 518 | PAGE_OUT_OF_SPACE | PBTreeFile 中 Page 空间不够 | -| 519 | RECORD_DUPLICATED | 记录重复 | -| 520 | SEGMENT_OUT_OF_SPACE | PBTreeFile 中 segment 空间不够 | -| 521 | PBTREE_FILE_NOT_EXISTS | PBTreeFile 不存在 | -| 522 | OVERSIZE_RECORD | 记录大小超过元数据文件页面大小 | -| 523 | PBTREE_FILE_REDO_LOG_BROKEN | PBTreeFile 的 redo 日志损坏 | -| 524 | TEMPLATE_NOT_ACTIVATED | 元数据模板未激活 | -| 526 | SCHEMA_QUOTA_EXCEEDED | 集群元数据超过配额上限 | -| 527 | MEASUREMENT_ALREADY_EXISTS_IN_TEMPLATE | 元数据模板中已存在物理量 | -| 600 | SYSTEM_READ_ONLY | IoTDB 系统只读 | -| 601 | STORAGE_ENGINE_ERROR | 存储引擎相关错误 | -| 602 | STORAGE_ENGINE_NOT_READY | 存储引擎还在恢复中,还不能接受读写操作 | -| 603 | DATAREGION_PROCESS_ERROR | DataRegion 相关错误 | -| 604 | TSFILE_PROCESSOR_ERROR | TsFile 处理器相关错误 | -| 605 | WRITE_PROCESS_ERROR | 写入相关错误 | -| 606 | WRITE_PROCESS_REJECT | 写入拒绝错误 | -| 607 | OUT_OF_TTL | 插入时间少于 TTL 时间边界 | -| 608 | COMPACTION_ERROR | 合并错误 | -| 609 | ALIGNED_TIMESERIES_ERROR | 对齐时间序列错误 | -| 610 | WAL_ERROR | WAL 异常 | -| 611 | DISK_SPACE_INSUFFICIENT | 磁盘空间不足 | -| 700 | SQL_PARSE_ERROR | SQL 语句分析错误 | -| 701 | SEMANTIC_ERROR | SQL 语义错误 | -| 702 | GENERATE_TIME_ZONE_ERROR | 生成时区错误 | -| 703 | SET_TIME_ZONE_ERROR | 设置时区错误 | -| 704 | QUERY_NOT_ALLOWED | 查询语句不允许 | -| 705 | LOGICAL_OPERATOR_ERROR | 逻辑符相关错误 | -| 706 | LOGICAL_OPTIMIZE_ERROR | 逻辑优化相关错误 | -| 707 | UNSUPPORTED_FILL_TYPE | 不支持的填充类型 | -| 708 | QUERY_PROCESS_ERROR | 查询处理相关错误 | -| 709 | MPP_MEMORY_NOT_ENOUGH | MPP 框架中任务执行内存不足 | -| 710 | CLOSE_OPERATION_ERROR | 关闭操作错误 | -| 711 | TSBLOCK_SERIALIZE_ERROR | TsBlock 序列化错误 | -| 712 | INTERNAL_REQUEST_TIME_OUT | MPP 操作超时 | -| 713 | INTERNAL_REQUEST_RETRY_ERROR | 内部操作重试失败 | -| 714 | NO_SUCH_QUERY | 查询不存在 | -| 715 | QUERY_WAS_KILLED | 查询执行时被终止 | -| 800 | UNINITIALIZED_AUTH_ERROR | 授权模块未初始化 | -| 801 | WRONG_LOGIN_PASSWORD | 用户名或密码错误 | -| 802 | NOT_LOGIN | 没有登录 | -| 803 | NO_PERMISSION | 没有操作权限 | -| 804 | USER_NOT_EXIST | 用户不存在 | -| 805 | USER_ALREADY_EXIST | 用户已存在 | -| 806 | USER_ALREADY_HAS_ROLE | 用户拥有对应角色 | -| 807 | USER_NOT_HAS_ROLE | 用户未拥有对应角色 | -| 808 | ROLE_NOT_EXIST | 角色不存在 | -| 809 | ROLE_ALREADY_EXIST | 角色已存在 | -| 810 | ALREADY_HAS_PRIVILEGE | 已拥有对应权限 | -| 811 | NOT_HAS_PRIVILEGE | 未拥有对应权限 | -| 812 | CLEAR_PERMISSION_CACHE_ERROR | 清空权限缓存失败 | -| 813 | UNKNOWN_AUTH_PRIVILEGE | 未知权限 | -| 814 | UNSUPPORTED_AUTH_OPERATION | 不支持的权限操作 | -| 815 | AUTH_IO_EXCEPTION | 权限模块IO异常 | -| 900 | MIGRATE_REGION_ERROR | Region 迁移失败 | -| 901 | CREATE_REGION_ERROR | 创建 region 失败 | -| 902 | DELETE_REGION_ERROR | 删除 region 失败 | -| 903 | PARTITION_CACHE_UPDATE_ERROR | 更新分区缓存失败 | -| 904 | CONSENSUS_NOT_INITIALIZED | 共识层未初始化,不能提供服务 | -| 905 | REGION_LEADER_CHANGE_ERROR | Region leader 迁移失败 | -| 906 | NO_AVAILABLE_REGION_GROUP | 无法找到可用的 Region 副本组 | -| 907 | LACK_DATA_PARTITION_ALLOCATION | 调用创建数据分区方法的返回结果里缺少信息 | -| 1000 | DATANODE_ALREADY_REGISTERED | DataNode 在集群中已经注册 | -| 1001 | NO_ENOUGH_DATANODE | DataNode 数量不足,无法移除节点或创建副本 | -| 1002 | ADD_CONFIGNODE_ERROR | 新增 ConfigNode 失败 | -| 1003 | REMOVE_CONFIGNODE_ERROR | 移除 ConfigNode 失败 | -| 1004 | DATANODE_NOT_EXIST | 此 DataNode 不存在 | -| 1005 | DATANODE_STOP_ERROR | DataNode 关闭失败 | -| 1006 | REMOVE_DATANODE_ERROR | 移除 datanode 失败 | -| 1007 | REGISTER_DATANODE_WITH_WRONG_ID | 注册的 DataNode 中有错误的注册id | -| 1008 | CAN_NOT_CONNECT_DATANODE | 连接 DataNode 失败 | -| 1100 | LOAD_FILE_ERROR | 加载文件错误 | -| 1101 | LOAD_PIECE_OF_TSFILE_ERROR | 加载 TsFile 片段异常 | -| 1102 | DESERIALIZE_PIECE_OF_TSFILE_ERROR | 反序列化 TsFile 片段异常 | -| 1103 | SYNC_CONNECTION_ERROR | 同步连接错误 | -| 1104 | SYNC_FILE_REDIRECTION_ERROR | 同步文件时重定向异常 | -| 1105 | SYNC_FILE_ERROR | 同步文件异常 | -| 1106 | CREATE_PIPE_SINK_ERROR | 创建 PIPE Sink 失败 | -| 1107 | PIPE_ERROR | PIPE 异常 | -| 1108 | PIPESERVER_ERROR | PIPE server 异常 | -| 1109 | VERIFY_METADATA_ERROR | 校验元数据失败 | -| 1200 | UDF_LOAD_CLASS_ERROR | UDF 加载类异常 | -| 1201 | UDF_DOWNLOAD_ERROR | 无法从 ConfigNode 下载 UDF | -| 1202 | CREATE_UDF_ON_DATANODE_ERROR | 在 DataNode 创建 UDF 失败 | -| 1203 | DROP_UDF_ON_DATANODE_ERROR | 在 DataNode 卸载 UDF 失败 | -| 1300 | CREATE_TRIGGER_ERROR | ConfigNode 创建 Trigger 失败 | -| 1301 | DROP_TRIGGER_ERROR | ConfigNode 删除 Trigger 失败 | -| 1302 | TRIGGER_FIRE_ERROR | 触发器执行错误 | -| 1303 | TRIGGER_LOAD_CLASS_ERROR | 触发器加载类异常 | -| 1304 | TRIGGER_DOWNLOAD_ERROR | 从 ConfigNode 下载触发器异常 | -| 1305 | CREATE_TRIGGER_INSTANCE_ERROR | 创建触发器实例异常 | -| 1306 | ACTIVE_TRIGGER_INSTANCE_ERROR | 激活触发器实例异常 | -| 1307 | DROP_TRIGGER_INSTANCE_ERROR | 删除触发器实例异常 | -| 1308 | UPDATE_TRIGGER_LOCATION_ERROR | 更新有状态的触发器所在 DataNode 异常 | -| 1400 | NO_SUCH_CQ | CQ 任务不存在 | -| 1401 | CQ_ALREADY_ACTIVE | CQ 任务已激活 | -| 1402 | CQ_AlREADY_EXIST | CQ 任务已存在 | -| 1403 | CQ_UPDATE_LAST_EXEC_TIME_ERROR | CQ 更新上一次执行时间失败 | - -> 在最新版本中,我们重构了 IoTDB 的异常类。通过将错误信息统一提取到异常类中,并为所有异常添加不同的错误代码,从而当捕获到异常并引发更高级别的异常时,错误代码将保留并传递,以便用户了解详细的错误原因。 -除此之外,我们添加了一个基础异常类“ProcessException”,由所有异常扩展。 diff --git a/src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries.md b/src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries.md deleted file mode 100644 index 2867a78eb..000000000 --- a/src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -redirectTo: UDF-Libraries_apache.html ---- - \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_apache.md b/src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_apache.md deleted file mode 100644 index b35e35e1a..000000000 --- a/src/zh/UserGuide/V1.3.3/SQL-Manual/UDF-Libraries_apache.md +++ /dev/null @@ -1,5346 +0,0 @@ - -# UDF函数库 - -基于用户自定义函数能力,IoTDB 提供了一系列关于时序数据处理的函数,包括数据质量、数据画像、异常检测、 频域分析、数据匹配、数据修复、序列发现、机器学习等,能够满足工业领域对时序数据处理的需求。 - -> 注意:当前UDF函数库中的函数仅支持毫秒级的时间戳精度。 - -## 安装步骤 -1. 请获取与 IoTDB 版本兼容的 UDF 函数库 JAR 包的压缩包。 - - | UDF 安装包 | 支持的 IoTDB 版本 | 下载链接 | - | --------------- | ----------------- | ------------------------------------------------------------ | - | apache-UDF-1.3.3.zip | V1.3.3及以上 | 请联系天谋商务获取 | - | apache-UDF-1.3.2.zip | V1.0.0~V1.3.2 | 请联系天谋商务获取| - -2. 将获取的压缩包中的 library-udf.jar 文件放置在 IoTDB 集群所有节点的 `/ext/udf` 的目录下 -3. 在 IoTDB 的 SQL 命令行终端(CLI)的 SQL 操作界面中,执行下述相应的函数注册语句。 -4. 批量注册:两种注册方式:注册脚本 或 SQL汇总语句 -- 注册脚本 - - 将压缩包中的注册脚本(register-UDF.sh 或 register-UDF.bat)按需复制到 IoTDB 的 tools 目录下,修改脚本中的参数(默认为host=127.0.0.1,rpcPort=6667,user=root,pass=root); - - 启动 IoTDB 服务,运行注册脚本批量注册 UDF - -- SQL汇总语句 - - 打开压缩包中的SQl文件,复制全部 SQL 语句,在 IoTDB 的 SQL 命令行终端(CLI)的 SQL 操作界面中,执行全部 SQl 语句批量注册 UDF - -## 数据质量 - -### Completeness - -#### 注册语句 - -```sql -create function completeness as 'org.apache.iotdb.library.dquality.UDTFCompleteness' -``` - -#### 函数简介 - -本函数用于计算时间序列的完整性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的完整性,并输出窗口第一个数据点的时间戳和窗口的完整性。 - -**函数名:** COMPLETENESS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 -+ `downtime`:完整性计算是否考虑停机异常。它的取值为 'true' 或 'false',默认值为 'true'. 在考虑停机异常时,长时间的数据缺失将被视作停机,不对完整性产生影响。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行完整性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算完整性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select completeness(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------+ -| Time|completeness(root.test.d1.s1)| -+-----------------------------+-----------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.875| -+-----------------------------+-----------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算完整性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select completeness(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------+ -| Time|completeness(root.test.d1.s1, "window"="15")| -+-----------------------------+--------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.875| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+--------------------------------------------+ -``` - -### Consistency - -#### 注册语句 - -```sql -create function consistency as 'org.apache.iotdb.library.dquality.UDTFConsistency' -``` - -#### 函数简介 - -本函数用于计算时间序列的一致性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的一致性,并输出窗口第一个数据点的时间戳和窗口的时效性。 - -**函数名:** CONSISTENCY - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行一致性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算一致性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consistency(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+----------------------------+ -| Time|consistency(root.test.d1.s1)| -+-----------------------------+----------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -+-----------------------------+----------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算一致性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consistency(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------+ -| Time|consistency(root.test.d1.s1, "window"="15")| -+-----------------------------+-------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+-------------------------------------------+ -``` - -### Timeliness - -#### 注册语句 - -```sql -create function timeliness as 'org.apache.iotdb.library.dquality.UDTFTimeliness' -``` - -#### 函数简介 - -本函数用于计算时间序列的时效性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的时效性,并输出窗口第一个数据点的时间戳和窗口的时效性。 - -**函数名:** TIMELINESS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行时效性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算时效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select timeliness(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+---------------------------+ -| Time|timeliness(root.test.d1.s1)| -+-----------------------------+---------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -+-----------------------------+---------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算时效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select timeliness(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------+ -| Time|timeliness(root.test.d1.s1, "window"="15")| -+-----------------------------+------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.9333333333333333| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+------------------------------------------+ -``` - -### Validity - -#### 注册语句 - -```sql -create function validity as 'org.apache.iotdb.library.dquality.UDTFValidity' -``` - -#### 函数简介 - -本函数用于计算时间序列的有效性。将输入序列划分为若干个连续且不重叠的窗口,分别计算每一个窗口的有效性,并输出窗口第一个数据点的时间戳和窗口的有效性。 - - -**函数名:** VALIDITY - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `window`:窗口大小,它是一个大于0的整数或者一个有单位的正数。前者代表每一个窗口包含的数据点数目,最后一个窗口的数据点数目可能会不足;后者代表窗口的时间跨度,目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。缺省情况下,全部输入数据都属于同一个窗口。 - -**输出序列:** 输出单个序列,类型为DOUBLE,其中每一个数据点的值的范围都是 [0,1]. - -**提示:** 只有当窗口内的数据点数目超过10时,才会进行有效性计算。否则,该窗口将被忽略,不做任何输出。 - - -#### 使用示例 - -##### 参数缺省 - -在参数缺省的情况下,本函数将会把全部输入数据都作为同一个窗口计算有效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select validity(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|validity(root.test.d1.s1)| -+-----------------------------+-------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.8833333333333333| -+-----------------------------+-------------------------+ -``` - -##### 指定窗口大小 - -在指定窗口大小的情况下,本函数会把输入数据划分为若干个窗口计算有效性。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -|2020-01-01T00:00:32.000+08:00| 130.0| -|2020-01-01T00:00:34.000+08:00| 132.0| -|2020-01-01T00:00:36.000+08:00| 134.0| -|2020-01-01T00:00:38.000+08:00| 136.0| -|2020-01-01T00:00:40.000+08:00| 138.0| -|2020-01-01T00:00:42.000+08:00| 140.0| -|2020-01-01T00:00:44.000+08:00| 142.0| -|2020-01-01T00:00:46.000+08:00| 144.0| -|2020-01-01T00:00:48.000+08:00| 146.0| -|2020-01-01T00:00:50.000+08:00| 148.0| -|2020-01-01T00:00:52.000+08:00| 150.0| -|2020-01-01T00:00:54.000+08:00| 152.0| -|2020-01-01T00:00:56.000+08:00| 154.0| -|2020-01-01T00:00:58.000+08:00| 156.0| -|2020-01-01T00:01:00.000+08:00| 158.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select validity(s1,"window"="15") from root.test.d1 where time <= 2020-01-01 00:01:00 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------+ -| Time|validity(root.test.d1.s1, "window"="15")| -+-----------------------------+----------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.8833333333333333| -|2020-01-01T00:00:32.000+08:00| 1.0| -+-----------------------------+----------------------------------------+ -``` - - - - -## 数据画像 - -### ACF - -#### 注册语句 - -```sql -create function acf as 'org.apache.iotdb.library.dprofile.UDTFACF' -``` - -#### 函数简介 - -本函数用于计算时间序列的自相关函数值,即序列与自身之间的互相关函数。 - -**函数名:** ACF - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列中共包含$2N-1$个数据点。 - -**提示:** - -+ 序列中的`NaN`值会被忽略,在计算中表现为0。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 3| -|2020-01-01T00:00:04.000+08:00| NaN| -|2020-01-01T00:00:05.000+08:00| 5| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select acf(s1) from root.test.d1 where time <= 2020-01-01 00:00:05 -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|acf(root.test.d1.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.002+08:00| 0.0| -|1970-01-01T08:00:00.003+08:00| 3.6| -|1970-01-01T08:00:00.004+08:00| 0.0| -|1970-01-01T08:00:00.005+08:00| 7.0| -|1970-01-01T08:00:00.006+08:00| 0.0| -|1970-01-01T08:00:00.007+08:00| 3.6| -|1970-01-01T08:00:00.008+08:00| 0.0| -|1970-01-01T08:00:00.009+08:00| 1.0| -+-----------------------------+--------------------+ -``` - -### Distinct - -#### 注册语句 - -```sql -create function distinct as 'org.apache.iotdb.library.dprofile.UDTFDistinct' -``` - -#### 函数简介 - -本函数可以返回输入序列中出现的所有不同的元素。 - -**函数名:** DISTINCT - -**输入序列:** 仅支持单个输入序列,类型可以是任意的 - -**输出序列:** 输出单个序列,类型与输入相同。 - -**提示:** - -+ 输出序列的时间戳是无意义的。输出顺序是任意的。 -+ 缺失值和空值将被忽略,但`NaN`不会被忽略。 -+ 字符串区分大小写 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s2| -+-----------------------------+---------------+ -|2020-01-01T08:00:00.001+08:00| Hello| -|2020-01-01T08:00:00.002+08:00| hello| -|2020-01-01T08:00:00.003+08:00| Hello| -|2020-01-01T08:00:00.004+08:00| World| -|2020-01-01T08:00:00.005+08:00| World| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select distinct(s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|distinct(root.test.d2.s2)| -+-----------------------------+-------------------------+ -|1970-01-01T08:00:00.001+08:00| Hello| -|1970-01-01T08:00:00.002+08:00| hello| -|1970-01-01T08:00:00.003+08:00| World| -+-----------------------------+-------------------------+ -``` - -### Histogram - -#### 注册语句 - -```sql -create function histogram as 'org.apache.iotdb.library.dprofile.UDTFHistogram' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的分布直方图。 - -**函数名:** HISTOGRAM - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `min`:表示所求数据范围的下限,默认值为 -Double.MAX_VALUE。 -+ `max`:表示所求数据范围的上限,默认值为 Double.MAX_VALUE,`start`的值必须小于或等于`end`。 -+ `count`: 表示直方图分桶的数量,默认值为 1,其值必须为正整数。 - -**输出序列:** 直方图分桶的值,其中第 i 个桶(从 1 开始计数)表示的数据范围下界为$min+ (i-1)\cdot\frac{max-min}{count}$,数据范围上界为$min+ i \cdot \frac{max-min}{count}$。 - - -**提示:** - -+ 如果某个数据点的数值小于`min`,它会被放入第 1 个桶;如果某个数据点的数值大于`max`,它会被放入最后 1 个桶。 -+ 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| -|2020-01-01T00:00:01.000+08:00| 2.0| -|2020-01-01T00:00:02.000+08:00| 3.0| -|2020-01-01T00:00:03.000+08:00| 4.0| -|2020-01-01T00:00:04.000+08:00| 5.0| -|2020-01-01T00:00:05.000+08:00| 6.0| -|2020-01-01T00:00:06.000+08:00| 7.0| -|2020-01-01T00:00:07.000+08:00| 8.0| -|2020-01-01T00:00:08.000+08:00| 9.0| -|2020-01-01T00:00:09.000+08:00| 10.0| -|2020-01-01T00:00:10.000+08:00| 11.0| -|2020-01-01T00:00:11.000+08:00| 12.0| -|2020-01-01T00:00:12.000+08:00| 13.0| -|2020-01-01T00:00:13.000+08:00| 14.0| -|2020-01-01T00:00:14.000+08:00| 15.0| -|2020-01-01T00:00:15.000+08:00| 16.0| -|2020-01-01T00:00:16.000+08:00| 17.0| -|2020-01-01T00:00:17.000+08:00| 18.0| -|2020-01-01T00:00:18.000+08:00| 19.0| -|2020-01-01T00:00:19.000+08:00| 20.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select histogram(s1,"min"="1","max"="20","count"="10") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------------------------------+ -| Time|histogram(root.test.d1.s1, "min"="1", "max"="20", "count"="10")| -+-----------------------------+---------------------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 2| -|1970-01-01T08:00:00.001+08:00| 2| -|1970-01-01T08:00:00.002+08:00| 2| -|1970-01-01T08:00:00.003+08:00| 2| -|1970-01-01T08:00:00.004+08:00| 2| -|1970-01-01T08:00:00.005+08:00| 2| -|1970-01-01T08:00:00.006+08:00| 2| -|1970-01-01T08:00:00.007+08:00| 2| -|1970-01-01T08:00:00.008+08:00| 2| -|1970-01-01T08:00:00.009+08:00| 2| -+-----------------------------+---------------------------------------------------------------+ -``` - -### Integral - -#### 注册语句 - -```sql -create function integral as 'org.apache.iotdb.library.dprofile.UDAFIntegral' -``` - -#### 函数简介 - -本函数用于计算时间序列的数值积分,即以时间为横坐标、数值为纵坐标绘制的折线图中折线以下的面积。 - -**函数名:** INTEGRAL - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `unit`:积分求解所用的时间轴单位,取值为 "1S", "1s", "1m", "1H", "1d"(区分大小写),分别表示以毫秒、秒、分钟、小时、天为单位计算积分。 - 缺省情况下取 "1s",以秒为单位。 - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为积分结果的数据点。 - -**提示:** - -+ 积分值等于折线图中每相邻两个数据点和时间轴形成的直角梯形的面积之和,不同时间单位下相当于横轴进行不同倍数放缩,得到的积分值可直接按放缩倍数转换。 - -+ 数据中`NaN`将会被忽略。折线将以临近两个有值数据点为准。 - -#### 使用示例 - -##### 参数缺省 - -缺省情况下积分以1s为时间单位。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| 2| -|2020-01-01T00:00:03.000+08:00| 5| -|2020-01-01T00:00:04.000+08:00| 6| -|2020-01-01T00:00:05.000+08:00| 7| -|2020-01-01T00:00:08.000+08:00| 8| -|2020-01-01T00:00:09.000+08:00| NaN| -|2020-01-01T00:00:10.000+08:00| 10| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select integral(s1) from root.test.d1 where time <= 2020-01-01 00:00:10 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|integral(root.test.d1.s1)| -+-----------------------------+-------------------------+ -|1970-01-01T08:00:00.000+08:00| 57.5| -+-----------------------------+-------------------------+ -``` - -其计算公式为: -$$\frac{1}{2}[(1+2)\times 1 + (2+5) \times 1 + (5+6) \times 1 + (6+7) \times 1 + (7+8) \times 3 + (8+10) \times 2] = 57.5$$ - - -##### 指定时间单位 - -指定以分钟为时间单位。 - - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select integral(s1, "unit"="1m") from root.test.d1 where time <= 2020-01-01 00:00:10 -``` - -输出序列: - -``` -+-----------------------------+-------------------------+ -| Time|integral(root.test.d1.s1)| -+-----------------------------+-------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.958| -+-----------------------------+-------------------------+ -``` - -其计算公式为: -$$\frac{1}{2\times 60}[(1+2) \times 1 + (2+3) \times 1 + (5+6) \times 1 + (6+7) \times 1 + (7+8) \times 3 + (8+10) \times 2] = 0.958$$ - -### IntegralAvg - -#### 注册语句 - -```sql -create function integralavg as 'org.apache.iotdb.library.dprofile.UDAFIntegralAvg' -``` - -#### 函数简介 - -本函数用于计算时间序列的函数均值,即在相同时间单位下的数值积分除以序列总的时间跨度。更多关于数值积分计算的信息请参考`Integral`函数。 - -**函数名:** INTEGRALAVG - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为时间加权平均结果的数据点。 - -**提示:** - -+ 时间加权的平均值等于在任意时间单位`unit`下计算的数值积分(即折线图中每相邻两个数据点和时间轴形成的直角梯形的面积之和), - 除以相同时间单位下输入序列的时间跨度,其值与具体采用的时间单位无关,默认与 IoTDB 时间单位一致。 - -+ 数据中的`NaN`将会被忽略。折线将以临近两个有值数据点为准。 - -+ 输入序列为空时,函数输出结果为 0;仅有一个数据点时,输出结果为该点数值。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| 2| -|2020-01-01T00:00:03.000+08:00| 5| -|2020-01-01T00:00:04.000+08:00| 6| -|2020-01-01T00:00:05.000+08:00| 7| -|2020-01-01T00:00:08.000+08:00| 8| -|2020-01-01T00:00:09.000+08:00| NaN| -|2020-01-01T00:00:10.000+08:00| 10| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select integralavg(s1) from root.test.d1 where time <= 2020-01-01 00:00:10 -``` - -输出序列: - -``` -+-----------------------------+----------------------------+ -| Time|integralavg(root.test.d1.s1)| -+-----------------------------+----------------------------+ -|1970-01-01T08:00:00.000+08:00| 5.75| -+-----------------------------+----------------------------+ -``` - -其计算公式为: -$$\frac{1}{2}[(1+2)\times 1 + (2+5) \times 1 + (5+6) \times 1 + (6+7) \times 1 + (7+8) \times 3 + (8+10) \times 2] / 10 = 5.75$$ - -### Mad - -#### 注册语句 - -```sql -create function mad as 'org.apache.iotdb.library.dprofile.UDAFMad' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的精确或近似绝对中位差,绝对中位差为所有数值与其中位数绝对偏移量的中位数。 - -如有数据集$\{1,3,3,5,5,6,7,8,9\}$,其中位数为5,所有数值与中位数的偏移量的绝对值为$\{0,0,1,2,2,2,3,4,4\}$,其中位数为2,故而原数据集的绝对中位差为2。 - -**函数名:** MAD - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `error`:近似绝对中位差的基于数值的误差百分比,取值范围为 [0,1),默认值为 0。如当`error`=0.01 时,记精确绝对中位差为a,近似绝对中位差为b,不等式 $0.99a \le b \le 1.01a$ 成立。当`error`=0 时,计算结果为精确绝对中位差。 - - -**输出序列:** 输出单个序列,类型为DOUBLE,序列仅包含一个时间戳为 0、值为绝对中位差的数据点。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -##### 精确查询 - -当`error`参数缺省或为0时,本函数计算精确绝对中位差。 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -............ -Total line number = 20 -``` - -用于查询的 SQL 语句: - -```sql -select mad(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -| Time|median(root.test.s1, "error"="0")| -+-----------------------------+---------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -+-----------------------------+---------------------------------+ -``` - -##### 近似查询 - -当`error`参数取值不为 0 时,本函数计算近似绝对中位差。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select mad(s1, "error"="0.01") from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -| Time|mad(root.test.s1, "error"="0.01")| -+-----------------------------+---------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.9900000000000001| -+-----------------------------+---------------------------------+ -``` - -### Median - -#### 注册语句 - -```sql -create function median as 'org.apache.iotdb.library.dprofile.UDAFMedian' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的精确或近似中位数。中位数是顺序排列的一组数据中居于中间位置的数;当序列有偶数个时,中位数为中间二者的平均数。 - -**函数名:** MEDIAN - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `error`:近似中位数的基于排名的误差百分比,取值范围 [0,1),默认值为 0。如当`error`=0.01 时,计算出的中位数的真实排名百分比在 0.49~0.51 之间。当`error`=0 时,计算结果为精确中位数。 - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为中位数的数据点。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -Total line number = 20 -``` - -用于查询的 SQL 语句: - -```sql -select median(s1, "error"="0.01") from root.test -``` - -输出序列: - -``` -+-----------------------------+------------------------------------+ -| Time|median(root.test.s1, "error"="0.01")| -+-----------------------------+------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -+-----------------------------+------------------------------------+ -``` - -### MinMax - -#### 注册语句 - -```sql -create function minmax as 'org.apache.iotdb.library.dprofile.UDTFMinMax' -``` - -#### 函数简介 - -本函数将输入序列使用 min-max 方法进行标准化。最小值归一至 0,最大值归一至 1. - -**函数名:** MINMAX - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `compute`:若设置为"batch",则将数据全部读入后转换;若设置为 "stream",则需用户提供最大值及最小值进行流式计算转换。默认为 "batch"。 -+ `min`:使用流式计算时的最小值。 -+ `max`:使用流式计算时的最大值。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 全数据计算 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select minmax(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|minmax(root.test.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.100+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.200+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.300+08:00| 0.25| -|1970-01-01T08:00:00.400+08:00| 0.08333333333333333| -|1970-01-01T08:00:00.500+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.600+08:00| 0.16666666666666666| -|1970-01-01T08:00:00.700+08:00| 0.0| -|1970-01-01T08:00:00.800+08:00| 0.3333333333333333| -|1970-01-01T08:00:00.900+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.000+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.100+08:00| 0.25| -|1970-01-01T08:00:01.200+08:00| 0.08333333333333333| -|1970-01-01T08:00:01.300+08:00| 0.08333333333333333| -|1970-01-01T08:00:01.400+08:00| 0.25| -|1970-01-01T08:00:01.500+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.600+08:00| 0.16666666666666666| -|1970-01-01T08:00:01.700+08:00| 1.0| -|1970-01-01T08:00:01.800+08:00| 0.3333333333333333| -|1970-01-01T08:00:01.900+08:00| 0.0| -|1970-01-01T08:00:02.000+08:00| 0.16666666666666666| -+-----------------------------+--------------------+ -``` - - - -### MvAvg - -#### 注册语句 - -```sql -create function mvavg as 'org.apache.iotdb.library.dprofile.UDTFMvAvg' -``` - -#### 函数简介 - -本函数计算序列的移动平均。 - -**函数名:** MVAVG - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `window`:移动窗口的长度。默认值为 10. - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 指定窗口长度 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select mvavg(s1, "window"="3") from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -| Time|mvavg(root.test.s1, "window"="3")| -+-----------------------------+---------------------------------+ -|1970-01-01T08:00:00.300+08:00| 0.3333333333333333| -|1970-01-01T08:00:00.400+08:00| 0.0| -|1970-01-01T08:00:00.500+08:00| -0.3333333333333333| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -0.6666666666666666| -|1970-01-01T08:00:00.800+08:00| 0.0| -|1970-01-01T08:00:00.900+08:00| 0.6666666666666666| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 0.3333333333333333| -|1970-01-01T08:00:01.200+08:00| 0.0| -|1970-01-01T08:00:01.300+08:00| -0.6666666666666666| -|1970-01-01T08:00:01.400+08:00| 0.0| -|1970-01-01T08:00:01.500+08:00| 0.3333333333333333| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 3.3333333333333335| -|1970-01-01T08:00:01.800+08:00| 4.0| -|1970-01-01T08:00:01.900+08:00| 0.0| -|1970-01-01T08:00:02.000+08:00| -0.6666666666666666| -+-----------------------------+---------------------------------+ -``` - -### PACF - -#### 注册语句 - -```sql -create function pacf as 'org.apache.iotdb.library.dprofile.UDTFPACF' -``` - -#### 函数简介 - -本函数通过求解 Yule-Walker 方程,计算序列的偏自相关系数。对于特殊的输入序列,方程可能没有解,此时输出`NaN`。 - -**函数名:** PACF - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `lag`:最大滞后阶数。默认值为$\min(10\log_{10}n,n-1)$,$n$表示数据点个数。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 指定滞后阶数 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1| -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 3| -|2020-01-01T00:00:04.000+08:00| NaN| -|2020-01-01T00:00:05.000+08:00| 5| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select pacf(s1, "lag"="5") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------+ -| Time|pacf(root.test.d1.s1, "lag"="5")| -+-----------------------------+--------------------------------+ -|2020-01-01T00:00:01.000+08:00| 1.0| -|2020-01-01T00:00:02.000+08:00| -0.5744680851063829| -|2020-01-01T00:00:03.000+08:00| 0.3172297297297296| -|2020-01-01T00:00:04.000+08:00| -0.2977686586304181| -|2020-01-01T00:00:05.000+08:00| -2.0609033521065867| -+-----------------------------+--------------------------------+ -``` - -### Percentile - -#### 注册语句 - -```sql -create function percentile as 'org.apache.iotdb.library.dprofile.UDAFPercentile' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的精确或近似分位数。 - -**函数名:** PERCENTILE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `rank`:所求分位数在所有数据中的排名百分比,取值范围为 (0,1],默认值为 0.5。如当设为 0.5时则计算中位数。 -+ `error`:近似分位数的基于排名的误差百分比,取值范围为 [0,1),默认值为0。如`rank`=0.5 且`error`=0.01,则计算出的分位数的真实排名百分比在 0.49~0.51之间。当`error`=0 时,计算结果为精确分位数。 - -**输出序列:** 输出单个序列,类型与输入序列相同。当`error`=0时,序列仅包含一个时间戳为分位数第一次出现的时间戳、值为分位数的数据点;否则,输出值的时间戳为0。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s0| -+-----------------------------+------------+ -|2021-03-17T10:32:17.054+08:00| 0.5319929| -|2021-03-17T10:32:18.054+08:00| 0.9304316| -|2021-03-17T10:32:19.054+08:00| -1.4800133| -|2021-03-17T10:32:20.054+08:00| 0.6114087| -|2021-03-17T10:32:21.054+08:00| 2.5163336| -|2021-03-17T10:32:22.054+08:00| -1.0845392| -|2021-03-17T10:32:23.054+08:00| 1.0562582| -|2021-03-17T10:32:24.054+08:00| 1.3867859| -|2021-03-17T10:32:25.054+08:00| -0.45429882| -|2021-03-17T10:32:26.054+08:00| 1.0353678| -|2021-03-17T10:32:27.054+08:00| 0.7307929| -|2021-03-17T10:32:28.054+08:00| 2.3167255| -|2021-03-17T10:32:29.054+08:00| 2.342443| -|2021-03-17T10:32:30.054+08:00| 1.5809103| -|2021-03-17T10:32:31.054+08:00| 1.4829416| -|2021-03-17T10:32:32.054+08:00| 1.5800357| -|2021-03-17T10:32:33.054+08:00| 0.7124368| -|2021-03-17T10:32:34.054+08:00| -0.78597564| -|2021-03-17T10:32:35.054+08:00| 1.2058644| -|2021-03-17T10:32:36.054+08:00| 1.4215064| -|2021-03-17T10:32:37.054+08:00| 1.2808295| -|2021-03-17T10:32:38.054+08:00| -0.6173715| -|2021-03-17T10:32:39.054+08:00| 0.06644377| -|2021-03-17T10:32:40.054+08:00| 2.349338| -|2021-03-17T10:32:41.054+08:00| 1.7335888| -|2021-03-17T10:32:42.054+08:00| 1.5872132| -............ -Total line number = 10000 -``` - -用于查询的 SQL 语句: - -```sql -select percentile(s0, "rank"="0.2", "error"="0.01") from root.test -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|percentile(root.test.s0, "rank"="0.2", "error"="0.01")| -+-----------------------------+------------------------------------------------------+ -|2021-03-17T10:35:02.054+08:00| 0.1801469624042511| -+-----------------------------+------------------------------------------------------+ -```输入序列: - -``` -+-----------------------------+-------------+ -| Time|root.test2.s1| -+-----------------------------+-------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+-------------+ -............ -Total line number = 20 -``` - -用于查询的 SQL 语句: - -```sql -select percentile(s1, "rank"="0.2", "error"="0.01") from root.test -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------------+ -| Time|percentile(root.test2.s1, "rank"="0.2", "error"="0.01")| -+-----------------------------+-------------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| -1.0| -+-----------------------------+-------------------------------------------------------+ -``` - - -### Quantile - -#### 注册语句 - -```sql -create function quantile as 'org.apache.iotdb.library.dprofile.UDAFQuantile' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的近似分位数。本函数基于KLL sketch算法实现。 - -**函数名:** QUANTILE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `rank`:所求分位数在所有数据中的排名比,取值范围为 (0,1],默认值为 0.5。如当设为 0.5时则计算近似中位数。 -+ `K`:允许维护的KLL sketch大小,最小值为100,默认值为800。如`rank`=0.5 且`K`=800,则计算出的分位数的真实排名比有至少99%的可能性在 0.49~0.51之间。 - -**输出序列:** 输出单个序列,类型与输入序列相同。输出值的时间戳为0。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - - -输入序列: - -``` -+-----------------------------+-------------+ -| Time|root.test1.s1| -+-----------------------------+-------------+ -|2021-03-17T10:32:17.054+08:00| 7| -|2021-03-17T10:32:18.054+08:00| 15| -|2021-03-17T10:32:19.054+08:00| 36| -|2021-03-17T10:32:20.054+08:00| 39| -|2021-03-17T10:32:21.054+08:00| 40| -|2021-03-17T10:32:22.054+08:00| 41| -|2021-03-17T10:32:23.054+08:00| 20| -|2021-03-17T10:32:24.054+08:00| 18| -+-----------------------------+-------------+ -............ -Total line number = 8 -``` - -用于查询的 SQL 语句: - -```sql -select quantile(s1, "rank"="0.2", "K"="800") from root.test1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------+ -| Time|quantile(root.test1.s1, "rank"="0.2", "K"="800")| -+-----------------------------+------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 7.000000000000001| -+-----------------------------+------------------------------------------------+ -``` - -### Period - -#### 注册语句 - -```sql -create function period as 'org.apache.iotdb.library.dprofile.UDAFPeriod' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的周期。 - -**函数名:** PERIOD - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型为 INT32,序列仅包含一个时间戳为 0、值为周期的数据点。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d3.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| -|1970-01-01T08:00:00.002+08:00| 2.0| -|1970-01-01T08:00:00.003+08:00| 3.0| -|1970-01-01T08:00:00.004+08:00| 1.0| -|1970-01-01T08:00:00.005+08:00| 2.0| -|1970-01-01T08:00:00.006+08:00| 3.0| -|1970-01-01T08:00:00.007+08:00| 1.0| -|1970-01-01T08:00:00.008+08:00| 2.0| -|1970-01-01T08:00:00.009+08:00| 3.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select period(s1) from root.test.d3 -``` - -输出序列: - -``` -+-----------------------------+-----------------------+ -| Time|period(root.test.d3.s1)| -+-----------------------------+-----------------------+ -|1970-01-01T08:00:00.000+08:00| 3| -+-----------------------------+-----------------------+ -``` - -### QLB - -#### 注册语句 - -```sql -create function qlb as 'org.apache.iotdb.library.dprofile.UDTFQLB' -``` - -#### 函数简介 - -本函数对输入序列计算$Q_{LB} $统计量,并计算对应的p值。p值越小表明序列越有可能为非平稳序列。 - -**函数名:** QLB - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `lag`:计算时用到的最大延迟阶数,取值应为 1 至 n-2 之间的整数,n 为序列采样总数。默认取 n-2。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。该序列是$Q_{LB} $统计量对应的 p 值,时间标签代表偏移阶数。 - -**提示:** $Q_{LB} $统计量由自相关系数求得,如需得到统计量而非 p 值,可以使用 ACF 函数。 - -#### 使用示例 - -##### 使用默认参数 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T00:00:00.100+08:00| 1.22| -|1970-01-01T00:00:00.200+08:00| -2.78| -|1970-01-01T00:00:00.300+08:00| 1.53| -|1970-01-01T00:00:00.400+08:00| 0.70| -|1970-01-01T00:00:00.500+08:00| 0.75| -|1970-01-01T00:00:00.600+08:00| -0.72| -|1970-01-01T00:00:00.700+08:00| -0.22| -|1970-01-01T00:00:00.800+08:00| 0.28| -|1970-01-01T00:00:00.900+08:00| 0.57| -|1970-01-01T00:00:01.000+08:00| -0.22| -|1970-01-01T00:00:01.100+08:00| -0.72| -|1970-01-01T00:00:01.200+08:00| 1.34| -|1970-01-01T00:00:01.300+08:00| -0.25| -|1970-01-01T00:00:01.400+08:00| 0.17| -|1970-01-01T00:00:01.500+08:00| 2.51| -|1970-01-01T00:00:01.600+08:00| 1.42| -|1970-01-01T00:00:01.700+08:00| -1.34| -|1970-01-01T00:00:01.800+08:00| -0.01| -|1970-01-01T00:00:01.900+08:00| -0.49| -|1970-01-01T00:00:02.000+08:00| 1.63| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select QLB(s1) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|QLB(root.test.d1.s1)| -+-----------------------------+--------------------+ -|1970-01-01T00:00:00.001+08:00| 0.2168702295315677| -|1970-01-01T00:00:00.002+08:00| 0.3068948509261751| -|1970-01-01T00:00:00.003+08:00| 0.4217859150918444| -|1970-01-01T00:00:00.004+08:00| 0.5114539874276656| -|1970-01-01T00:00:00.005+08:00| 0.6560619525616759| -|1970-01-01T00:00:00.006+08:00| 0.7722398654053280| -|1970-01-01T00:00:00.007+08:00| 0.8532491661465290| -|1970-01-01T00:00:00.008+08:00| 0.9028575017542528| -|1970-01-01T00:00:00.009+08:00| 0.9434989988192729| -|1970-01-01T00:00:00.010+08:00| 0.8950280161464689| -|1970-01-01T00:00:00.011+08:00| 0.7701048398839656| -|1970-01-01T00:00:00.012+08:00| 0.7845536060001281| -|1970-01-01T00:00:00.013+08:00| 0.5943030981705825| -|1970-01-01T00:00:00.014+08:00| 0.4618413512531093| -|1970-01-01T00:00:00.015+08:00| 0.2645948244673964| -|1970-01-01T00:00:00.016+08:00| 0.3167530476666645| -|1970-01-01T00:00:00.017+08:00| 0.2330010780351453| -|1970-01-01T00:00:00.018+08:00| 0.0666611237622325| -+-----------------------------+--------------------+ -``` - -### Resample - -#### 注册语句 - -```sql -create function re_sample as 'org.apache.iotdb.library.dprofile.UDTFResample' -``` - -#### 函数简介 - -本函数对输入序列按照指定的频率进行重采样,包括上采样和下采样。目前,本函数支持的上采样方法包括`NaN`填充法 (NaN)、前值填充法 (FFill)、后值填充法 (BFill) 以及线性插值法 (Linear);本函数支持的下采样方法为分组聚合,聚合方法包括最大值 (Max)、最小值 (Min)、首值 (First)、末值 (Last)、平均值 (Mean)和中位数 (Median)。 - -**函数名:** RESAMPLE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `every`:重采样频率,是一个有单位的正数。目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。该参数不允许缺省。 -+ `interp`:上采样的插值方法,取值为 'NaN'、'FFill'、'BFill' 或 'Linear'。在缺省情况下,使用`NaN`填充法。 -+ `aggr`:下采样的聚合方法,取值为 'Max'、'Min'、'First'、'Last'、'Mean' 或 'Median'。在缺省情况下,使用平均数聚合。 -+ `start`:重采样的起始时间(包含),是一个格式为 'yyyy-MM-dd HH:mm:ss' 的时间字符串。在缺省情况下,使用第一个有效数据点的时间戳。 -+ `end`:重采样的结束时间(不包含),是一个格式为 'yyyy-MM-dd HH:mm:ss' 的时间字符串。在缺省情况下,使用最后一个有效数据点的时间戳。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。该序列按照重采样频率严格等间隔分布。 - -**提示:** 数据中的`NaN`将会被忽略。 - -#### 使用示例 - -##### 上采样 - -当重采样频率高于数据原始频率时,将会进行上采样。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2021-03-06T16:00:00.000+08:00| 3.09| -|2021-03-06T16:15:00.000+08:00| 3.53| -|2021-03-06T16:30:00.000+08:00| 3.5| -|2021-03-06T16:45:00.000+08:00| 3.51| -|2021-03-06T17:00:00.000+08:00| 3.41| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select resample(s1,'every'='5m','interp'='linear') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------------------------+ -| Time|resample(root.test.d1.s1, "every"="5m", "interp"="linear")| -+-----------------------------+----------------------------------------------------------+ -|2021-03-06T16:00:00.000+08:00| 3.0899999141693115| -|2021-03-06T16:05:00.000+08:00| 3.2366665999094644| -|2021-03-06T16:10:00.000+08:00| 3.3833332856496177| -|2021-03-06T16:15:00.000+08:00| 3.5299999713897705| -|2021-03-06T16:20:00.000+08:00| 3.5199999809265137| -|2021-03-06T16:25:00.000+08:00| 3.509999990463257| -|2021-03-06T16:30:00.000+08:00| 3.5| -|2021-03-06T16:35:00.000+08:00| 3.503333330154419| -|2021-03-06T16:40:00.000+08:00| 3.506666660308838| -|2021-03-06T16:45:00.000+08:00| 3.509999990463257| -|2021-03-06T16:50:00.000+08:00| 3.4766666889190674| -|2021-03-06T16:55:00.000+08:00| 3.443333387374878| -|2021-03-06T17:00:00.000+08:00| 3.4100000858306885| -+-----------------------------+----------------------------------------------------------+ -``` - -##### 下采样 - -当重采样频率低于数据原始频率时,将会进行下采样。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select resample(s1,'every'='30m','aggr'='first') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------+ -| Time|resample(root.test.d1.s1, "every"="30m", "aggr"="first")| -+-----------------------------+--------------------------------------------------------+ -|2021-03-06T16:00:00.000+08:00| 3.0899999141693115| -|2021-03-06T16:30:00.000+08:00| 3.5| -|2021-03-06T17:00:00.000+08:00| 3.4100000858306885| -+-----------------------------+--------------------------------------------------------+ -``` - - -###### 指定重采样时间段 - -可以使用`start`和`end`两个参数指定重采样的时间段,超出实际时间范围的部分会被插值填补。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select resample(s1,'every'='30m','start'='2021-03-06 15:00:00') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------------------------------------+ -| Time|resample(root.test.d1.s1, "every"="30m", "start"="2021-03-06 15:00:00")| -+-----------------------------+-----------------------------------------------------------------------+ -|2021-03-06T15:00:00.000+08:00| NaN| -|2021-03-06T15:30:00.000+08:00| NaN| -|2021-03-06T16:00:00.000+08:00| 3.309999942779541| -|2021-03-06T16:30:00.000+08:00| 3.5049999952316284| -|2021-03-06T17:00:00.000+08:00| 3.4100000858306885| -+-----------------------------+-----------------------------------------------------------------------+ -``` - -### Sample - -#### 注册语句 - -```sql -create function sample as 'org.apache.iotdb.library.dprofile.UDTFSample' -``` - -#### 函数简介 - -本函数对输入序列进行采样,即从输入序列中选取指定数量的数据点并输出。目前,本函数支持三种采样方法:**蓄水池采样法 (reservoir sampling)** 对数据进行随机采样,所有数据点被采样的概率相同;**等距采样法 (isometric sampling)** 按照相等的索引间隔对数据进行采样,**最大三角采样法 (triangle sampling)** 对所有数据会按采样率分桶,每个桶内会计算数据点间三角形面积,并保留面积最大的点,该算法通常用于数据的可视化展示中,采用过程可以保证一些关键的突变点在采用中得到保留,更多抽样算法细节可以阅读论文 [here](http://skemman.is/stream/get/1946/15343/37285/3/SS_MSthesis.pdf)。 - -**函数名:** SAMPLE - -**输入序列:** 仅支持单个输入序列,类型可以是任意的。 - -**参数:** - -+ `method`:采样方法,取值为 'reservoir','isometric' 或 'triangle' 。在缺省情况下,采用蓄水池采样法。 -+ `k`:采样数,它是一个正整数,在缺省情况下为 1。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列的长度为采样数,序列中的每一个数据点都来自于输入序列。 - -**提示:** 如果采样数大于序列长度,那么输入序列中所有的数据点都会被输出。 - -#### 使用示例 - - -##### 蓄水池采样 - -当`method`参数为 'reservoir' 或缺省时,采用蓄水池采样法对输入序列进行采样。由于该采样方法具有随机性,下面展示的输出序列只是一种可能的结果。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| 1.0| -|2020-01-01T00:00:02.000+08:00| 2.0| -|2020-01-01T00:00:03.000+08:00| 3.0| -|2020-01-01T00:00:04.000+08:00| 4.0| -|2020-01-01T00:00:05.000+08:00| 5.0| -|2020-01-01T00:00:06.000+08:00| 6.0| -|2020-01-01T00:00:07.000+08:00| 7.0| -|2020-01-01T00:00:08.000+08:00| 8.0| -|2020-01-01T00:00:09.000+08:00| 9.0| -|2020-01-01T00:00:10.000+08:00| 10.0| -+-----------------------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select sample(s1,'method'='reservoir','k'='5') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|sample(root.test.d1.s1, "method"="reservoir", "k"="5")| -+-----------------------------+------------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 2.0| -|2020-01-01T00:00:03.000+08:00| 3.0| -|2020-01-01T00:00:05.000+08:00| 5.0| -|2020-01-01T00:00:08.000+08:00| 8.0| -|2020-01-01T00:00:10.000+08:00| 10.0| -+-----------------------------+------------------------------------------------------+ -``` - - -##### 等距采样 - -当`method`参数为 'isometric' 时,采用等距采样法对输入序列进行采样。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select sample(s1,'method'='isometric','k'='5') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|sample(root.test.d1.s1, "method"="isometric", "k"="5")| -+-----------------------------+------------------------------------------------------+ -|2020-01-01T00:00:01.000+08:00| 1.0| -|2020-01-01T00:00:03.000+08:00| 3.0| -|2020-01-01T00:00:05.000+08:00| 5.0| -|2020-01-01T00:00:07.000+08:00| 7.0| -|2020-01-01T00:00:09.000+08:00| 9.0| -+-----------------------------+------------------------------------------------------+ -``` - -### Segment - -#### 注册语句 - -```sql -create function segment as 'org.apache.iotdb.library.dprofile.UDTFSegment' -``` - -#### 函数简介 - -本函数按照数据的线性变化趋势将数据划分为多个子序列,返回分段直线拟合后的子序列首值或所有拟合值。 - -**函数名:** SEGMENT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `output`:"all" 输出所有拟合值;"first" 输出子序列起点拟合值。默认为 "first"。 - -+ `error`:判定存在线性趋势的误差允许阈值。误差的定义为子序列进行线性拟合的误差的绝对值的均值。默认为 0.1. - -**输出序列:** 输出单个序列,类型为 DOUBLE。 - -**提示:** 函数默认所有数据等时间间隔分布。函数读取所有数据,若原始数据过多,请先进行降采样处理。拟合采用自底向上方法,子序列的尾值可能会被认作子序列首值输出。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 5.0| -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 1.0| -|1970-01-01T08:00:00.300+08:00| 2.0| -|1970-01-01T08:00:00.400+08:00| 3.0| -|1970-01-01T08:00:00.500+08:00| 4.0| -|1970-01-01T08:00:00.600+08:00| 5.0| -|1970-01-01T08:00:00.700+08:00| 6.0| -|1970-01-01T08:00:00.800+08:00| 7.0| -|1970-01-01T08:00:00.900+08:00| 8.0| -|1970-01-01T08:00:01.000+08:00| 9.0| -|1970-01-01T08:00:01.100+08:00| 9.1| -|1970-01-01T08:00:01.200+08:00| 9.2| -|1970-01-01T08:00:01.300+08:00| 9.3| -|1970-01-01T08:00:01.400+08:00| 9.4| -|1970-01-01T08:00:01.500+08:00| 9.5| -|1970-01-01T08:00:01.600+08:00| 9.6| -|1970-01-01T08:00:01.700+08:00| 9.7| -|1970-01-01T08:00:01.800+08:00| 9.8| -|1970-01-01T08:00:01.900+08:00| 9.9| -|1970-01-01T08:00:02.000+08:00| 10.0| -|1970-01-01T08:00:02.100+08:00| 8.0| -|1970-01-01T08:00:02.200+08:00| 6.0| -|1970-01-01T08:00:02.300+08:00| 4.0| -|1970-01-01T08:00:02.400+08:00| 2.0| -|1970-01-01T08:00:02.500+08:00| 0.0| -|1970-01-01T08:00:02.600+08:00| -2.0| -|1970-01-01T08:00:02.700+08:00| -4.0| -|1970-01-01T08:00:02.800+08:00| -6.0| -|1970-01-01T08:00:02.900+08:00| -8.0| -|1970-01-01T08:00:03.000+08:00| -10.0| -|1970-01-01T08:00:03.100+08:00| 10.0| -|1970-01-01T08:00:03.200+08:00| 10.0| -|1970-01-01T08:00:03.300+08:00| 10.0| -|1970-01-01T08:00:03.400+08:00| 10.0| -|1970-01-01T08:00:03.500+08:00| 10.0| -|1970-01-01T08:00:03.600+08:00| 10.0| -|1970-01-01T08:00:03.700+08:00| 10.0| -|1970-01-01T08:00:03.800+08:00| 10.0| -|1970-01-01T08:00:03.900+08:00| 10.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select segment(s1,"error"="0.1") from root.test -``` - -输出序列: - -``` -+-----------------------------+------------------------------------+ -| Time|segment(root.test.s1, "error"="0.1")| -+-----------------------------+------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 5.0| -|1970-01-01T08:00:00.200+08:00| 1.0| -|1970-01-01T08:00:01.000+08:00| 9.0| -|1970-01-01T08:00:02.000+08:00| 10.0| -|1970-01-01T08:00:03.000+08:00| -10.0| -|1970-01-01T08:00:03.200+08:00| 10.0| -+-----------------------------+------------------------------------+ -``` - -### Skew - -#### 注册语句 - -```sql -create function skew as 'org.apache.iotdb.library.dprofile.UDAFSkew' -``` - -#### 函数简介 - -本函数用于计算单列数值型数据的总体偏度 - -**函数名:** SKEW - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型为 DOUBLE,序列仅包含一个时间戳为 0、值为总体偏度的数据点。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| -|2020-01-01T00:00:01.000+08:00| 2.0| -|2020-01-01T00:00:02.000+08:00| 3.0| -|2020-01-01T00:00:03.000+08:00| 4.0| -|2020-01-01T00:00:04.000+08:00| 5.0| -|2020-01-01T00:00:05.000+08:00| 6.0| -|2020-01-01T00:00:06.000+08:00| 7.0| -|2020-01-01T00:00:07.000+08:00| 8.0| -|2020-01-01T00:00:08.000+08:00| 9.0| -|2020-01-01T00:00:09.000+08:00| 10.0| -|2020-01-01T00:00:10.000+08:00| 10.0| -|2020-01-01T00:00:11.000+08:00| 10.0| -|2020-01-01T00:00:12.000+08:00| 10.0| -|2020-01-01T00:00:13.000+08:00| 10.0| -|2020-01-01T00:00:14.000+08:00| 10.0| -|2020-01-01T00:00:15.000+08:00| 10.0| -|2020-01-01T00:00:16.000+08:00| 10.0| -|2020-01-01T00:00:17.000+08:00| 10.0| -|2020-01-01T00:00:18.000+08:00| 10.0| -|2020-01-01T00:00:19.000+08:00| 10.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select skew(s1) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------+ -| Time| skew(root.test.d1.s1)| -+-----------------------------+-----------------------+ -|1970-01-01T08:00:00.000+08:00| -0.9998427402292644| -+-----------------------------+-----------------------+ -``` - -### Spline - -#### 注册语句 - -```sql -create function spline as 'org.apache.iotdb.library.dprofile.UDTFSpline' -``` - -#### 函数简介 - -本函数提供对原始序列进行三次样条曲线拟合后的插值重采样。 - -**函数名:** SPLINE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `points`:重采样个数。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -**提示**:输出序列保留输入序列的首尾值,等时间间隔采样。仅当输入点个数不少于 4 个时才计算插值。 - -#### 使用示例 - -##### 指定插值个数 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.2| -|1970-01-01T08:00:00.500+08:00| 1.7| -|1970-01-01T08:00:00.700+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 2.1| -|1970-01-01T08:00:01.100+08:00| 2.0| -|1970-01-01T08:00:01.200+08:00| 1.8| -|1970-01-01T08:00:01.300+08:00| 1.2| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 1.6| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select spline(s1, "points"="151") from root.test -``` - -输出序列: - -``` -+-----------------------------+------------------------------------+ -| Time|spline(root.test.s1, "points"="151")| -+-----------------------------+------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.010+08:00| 0.04870000251134237| -|1970-01-01T08:00:00.020+08:00| 0.09680000495910646| -|1970-01-01T08:00:00.030+08:00| 0.14430000734329226| -|1970-01-01T08:00:00.040+08:00| 0.19120000966389972| -|1970-01-01T08:00:00.050+08:00| 0.23750001192092896| -|1970-01-01T08:00:00.060+08:00| 0.2832000141143799| -|1970-01-01T08:00:00.070+08:00| 0.32830001624425253| -|1970-01-01T08:00:00.080+08:00| 0.3728000183105469| -|1970-01-01T08:00:00.090+08:00| 0.416700020313263| -|1970-01-01T08:00:00.100+08:00| 0.4600000222524008| -|1970-01-01T08:00:00.110+08:00| 0.5027000241279602| -|1970-01-01T08:00:00.120+08:00| 0.5448000259399414| -|1970-01-01T08:00:00.130+08:00| 0.5863000276883443| -|1970-01-01T08:00:00.140+08:00| 0.627200029373169| -|1970-01-01T08:00:00.150+08:00| 0.6675000309944153| -|1970-01-01T08:00:00.160+08:00| 0.7072000325520833| -|1970-01-01T08:00:00.170+08:00| 0.7463000340461731| -|1970-01-01T08:00:00.180+08:00| 0.7848000354766846| -|1970-01-01T08:00:00.190+08:00| 0.8227000368436178| -|1970-01-01T08:00:00.200+08:00| 0.8600000381469728| -|1970-01-01T08:00:00.210+08:00| 0.8967000393867494| -|1970-01-01T08:00:00.220+08:00| 0.9328000405629477| -|1970-01-01T08:00:00.230+08:00| 0.9683000416755676| -|1970-01-01T08:00:00.240+08:00| 1.0032000427246095| -|1970-01-01T08:00:00.250+08:00| 1.037500043710073| -|1970-01-01T08:00:00.260+08:00| 1.071200044631958| -|1970-01-01T08:00:00.270+08:00| 1.1043000454902647| -|1970-01-01T08:00:00.280+08:00| 1.1368000462849934| -|1970-01-01T08:00:00.290+08:00| 1.1687000470161437| -|1970-01-01T08:00:00.300+08:00| 1.2000000476837158| -|1970-01-01T08:00:00.310+08:00| 1.2307000483103594| -|1970-01-01T08:00:00.320+08:00| 1.2608000489139557| -|1970-01-01T08:00:00.330+08:00| 1.2903000494873524| -|1970-01-01T08:00:00.340+08:00| 1.3192000500233967| -|1970-01-01T08:00:00.350+08:00| 1.3475000505149364| -|1970-01-01T08:00:00.360+08:00| 1.3752000509548186| -|1970-01-01T08:00:00.370+08:00| 1.402300051335891| -|1970-01-01T08:00:00.380+08:00| 1.4288000516510009| -|1970-01-01T08:00:00.390+08:00| 1.4547000518929958| -|1970-01-01T08:00:00.400+08:00| 1.480000052054723| -|1970-01-01T08:00:00.410+08:00| 1.5047000521290301| -|1970-01-01T08:00:00.420+08:00| 1.5288000521087646| -|1970-01-01T08:00:00.430+08:00| 1.5523000519867738| -|1970-01-01T08:00:00.440+08:00| 1.575200051755905| -|1970-01-01T08:00:00.450+08:00| 1.597500051409006| -|1970-01-01T08:00:00.460+08:00| 1.619200050938924| -|1970-01-01T08:00:00.470+08:00| 1.6403000503385066| -|1970-01-01T08:00:00.480+08:00| 1.660800049600601| -|1970-01-01T08:00:00.490+08:00| 1.680700048718055| -|1970-01-01T08:00:00.500+08:00| 1.7000000476837158| -|1970-01-01T08:00:00.510+08:00| 1.7188475466453037| -|1970-01-01T08:00:00.520+08:00| 1.7373800457262996| -|1970-01-01T08:00:00.530+08:00| 1.7555825448831923| -|1970-01-01T08:00:00.540+08:00| 1.7734400440724702| -|1970-01-01T08:00:00.550+08:00| 1.790937543250622| -|1970-01-01T08:00:00.560+08:00| 1.8080600423741364| -|1970-01-01T08:00:00.570+08:00| 1.8247925413995016| -|1970-01-01T08:00:00.580+08:00| 1.8411200402832066| -|1970-01-01T08:00:00.590+08:00| 1.8570275389817397| -|1970-01-01T08:00:00.600+08:00| 1.8725000374515897| -|1970-01-01T08:00:00.610+08:00| 1.8875225356492449| -|1970-01-01T08:00:00.620+08:00| 1.902080033531194| -|1970-01-01T08:00:00.630+08:00| 1.9161575310539258| -|1970-01-01T08:00:00.640+08:00| 1.9297400281739288| -|1970-01-01T08:00:00.650+08:00| 1.9428125248476913| -|1970-01-01T08:00:00.660+08:00| 1.9553600210317021| -|1970-01-01T08:00:00.670+08:00| 1.96736751668245| -|1970-01-01T08:00:00.680+08:00| 1.9788200117564232| -|1970-01-01T08:00:00.690+08:00| 1.9897025062101101| -|1970-01-01T08:00:00.700+08:00| 2.0| -|1970-01-01T08:00:00.710+08:00| 2.0097024933913334| -|1970-01-01T08:00:00.720+08:00| 2.0188199867081615| -|1970-01-01T08:00:00.730+08:00| 2.027367479995188| -|1970-01-01T08:00:00.740+08:00| 2.0353599732971155| -|1970-01-01T08:00:00.750+08:00| 2.0428124666586482| -|1970-01-01T08:00:00.760+08:00| 2.049739960124489| -|1970-01-01T08:00:00.770+08:00| 2.056157453739342| -|1970-01-01T08:00:00.780+08:00| 2.06207994754791| -|1970-01-01T08:00:00.790+08:00| 2.067522441594897| -|1970-01-01T08:00:00.800+08:00| 2.072499935925006| -|1970-01-01T08:00:00.810+08:00| 2.07702743058294| -|1970-01-01T08:00:00.820+08:00| 2.081119925613404| -|1970-01-01T08:00:00.830+08:00| 2.0847924210611| -|1970-01-01T08:00:00.840+08:00| 2.0880599169707317| -|1970-01-01T08:00:00.850+08:00| 2.0909374133870027| -|1970-01-01T08:00:00.860+08:00| 2.0934399103546166| -|1970-01-01T08:00:00.870+08:00| 2.0955824079182768| -|1970-01-01T08:00:00.880+08:00| 2.0973799061226863| -|1970-01-01T08:00:00.890+08:00| 2.098847405012549| -|1970-01-01T08:00:00.900+08:00| 2.0999999046325684| -|1970-01-01T08:00:00.910+08:00| 2.1005574051201332| -|1970-01-01T08:00:00.920+08:00| 2.1002599065303778| -|1970-01-01T08:00:00.930+08:00| 2.0991524087846245| -|1970-01-01T08:00:00.940+08:00| 2.0972799118041947| -|1970-01-01T08:00:00.950+08:00| 2.0946874155104105| -|1970-01-01T08:00:00.960+08:00| 2.0914199198245944| -|1970-01-01T08:00:00.970+08:00| 2.0875224246680673| -|1970-01-01T08:00:00.980+08:00| 2.083039929962151| -|1970-01-01T08:00:00.990+08:00| 2.0780174356281687| -|1970-01-01T08:00:01.000+08:00| 2.0724999415874406| -|1970-01-01T08:00:01.010+08:00| 2.06653244776129| -|1970-01-01T08:00:01.020+08:00| 2.060159954071038| -|1970-01-01T08:00:01.030+08:00| 2.053427460438006| -|1970-01-01T08:00:01.040+08:00| 2.046379966783517| -|1970-01-01T08:00:01.050+08:00| 2.0390624730288924| -|1970-01-01T08:00:01.060+08:00| 2.031519979095454| -|1970-01-01T08:00:01.070+08:00| 2.0237974849045237| -|1970-01-01T08:00:01.080+08:00| 2.015939990377423| -|1970-01-01T08:00:01.090+08:00| 2.0079924954354746| -|1970-01-01T08:00:01.100+08:00| 2.0| -|1970-01-01T08:00:01.110+08:00| 1.9907018211101906| -|1970-01-01T08:00:01.120+08:00| 1.9788509124245144| -|1970-01-01T08:00:01.130+08:00| 1.9645127287932083| -|1970-01-01T08:00:01.140+08:00| 1.9477527250665083| -|1970-01-01T08:00:01.150+08:00| 1.9286363560946513| -|1970-01-01T08:00:01.160+08:00| 1.9072290767278735| -|1970-01-01T08:00:01.170+08:00| 1.8835963418164114| -|1970-01-01T08:00:01.180+08:00| 1.8578036062105014| -|1970-01-01T08:00:01.190+08:00| 1.8299163247603802| -|1970-01-01T08:00:01.200+08:00| 1.7999999523162842| -|1970-01-01T08:00:01.210+08:00| 1.7623635841923329| -|1970-01-01T08:00:01.220+08:00| 1.7129696477516976| -|1970-01-01T08:00:01.230+08:00| 1.6543635959181928| -|1970-01-01T08:00:01.240+08:00| 1.5890908816156328| -|1970-01-01T08:00:01.250+08:00| 1.5196969577678319| -|1970-01-01T08:00:01.260+08:00| 1.4487272772986044| -|1970-01-01T08:00:01.270+08:00| 1.3787272931317647| -|1970-01-01T08:00:01.280+08:00| 1.3122424581911272| -|1970-01-01T08:00:01.290+08:00| 1.251818225400506| -|1970-01-01T08:00:01.300+08:00| 1.2000000476837158| -|1970-01-01T08:00:01.310+08:00| 1.1548000470995912| -|1970-01-01T08:00:01.320+08:00| 1.1130667107899999| -|1970-01-01T08:00:01.330+08:00| 1.0756000393033045| -|1970-01-01T08:00:01.340+08:00| 1.043200033187868| -|1970-01-01T08:00:01.350+08:00| 1.016666692992053| -|1970-01-01T08:00:01.360+08:00| 0.9968000192642223| -|1970-01-01T08:00:01.370+08:00| 0.9844000125527389| -|1970-01-01T08:00:01.380+08:00| 0.9802666734059655| -|1970-01-01T08:00:01.390+08:00| 0.9852000023722649| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.410+08:00| 1.023999999165535| -|1970-01-01T08:00:01.420+08:00| 1.0559999990463256| -|1970-01-01T08:00:01.430+08:00| 1.0959999996423722| -|1970-01-01T08:00:01.440+08:00| 1.1440000009536744| -|1970-01-01T08:00:01.450+08:00| 1.2000000029802322| -|1970-01-01T08:00:01.460+08:00| 1.264000005722046| -|1970-01-01T08:00:01.470+08:00| 1.3360000091791153| -|1970-01-01T08:00:01.480+08:00| 1.4160000133514405| -|1970-01-01T08:00:01.490+08:00| 1.5040000182390214| -|1970-01-01T08:00:01.500+08:00| 1.600000023841858| -+-----------------------------+------------------------------------+ -``` - -### Spread - -#### 注册语句 - -```sql -create function spread as 'org.apache.iotdb.library.dprofile.UDAFSpread' -``` - -#### 函数简介 - -本函数用于计算时间序列的极差,即最大值减去最小值的结果。 - -**函数名:** SPREAD - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型与输入相同,序列仅包含一个时间戳为 0 、值为极差的数据点。 - -**提示:** 数据中的空值、缺失值和`NaN`将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select spread(s1) from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+-----------------------+ -| Time|spread(root.test.d1.s1)| -+-----------------------------+-----------------------+ -|1970-01-01T08:00:00.000+08:00| 26.0| -+-----------------------------+-----------------------+ -``` - - - -### ZScore - -#### 注册语句 - -```sql -create function zscore as 'org.apache.iotdb.library.dprofile.UDTFZScore' -``` - -#### 函数简介 - -本函数将输入序列使用z-score方法进行归一化。 - -**函数名:** ZSCORE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `compute`:若设置为 "batch",则将数据全部读入后转换;若设置为 "stream",则需用户提供均值及方差进行流式计算转换。默认为 "batch"。 -+ `avg`:使用流式计算时的均值。 -+ `sd`:使用流式计算时的标准差。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -#### 使用示例 - -##### 全数据计算 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select zscore(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|zscore(root.test.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.100+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.200+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.300+08:00| 0.20672455764868078| -|1970-01-01T08:00:00.400+08:00| -0.6201736729460423| -|1970-01-01T08:00:00.500+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.600+08:00|-0.20672455764868078| -|1970-01-01T08:00:00.700+08:00| -1.033622788243404| -|1970-01-01T08:00:00.800+08:00| 0.6201736729460423| -|1970-01-01T08:00:00.900+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.000+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.100+08:00| 0.20672455764868078| -|1970-01-01T08:00:01.200+08:00| -0.6201736729460423| -|1970-01-01T08:00:01.300+08:00| -0.6201736729460423| -|1970-01-01T08:00:01.400+08:00| 0.20672455764868078| -|1970-01-01T08:00:01.500+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.600+08:00|-0.20672455764868078| -|1970-01-01T08:00:01.700+08:00| 3.9277665953249348| -|1970-01-01T08:00:01.800+08:00| 0.6201736729460423| -|1970-01-01T08:00:01.900+08:00| -1.033622788243404| -|1970-01-01T08:00:02.000+08:00|-0.20672455764868078| -+-----------------------------+--------------------+ -``` - - - -## 异常检测 - -### IQR - -#### 注册语句 - -```sql -create function iqr as 'org.apache.iotdb.library.anomaly.UDTFIQR' -``` - -#### 函数简介 - -本函数用于检验超出上下四分位数1.5倍IQR的数据分布异常。 - -**函数名:** IQR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `method`:若设置为 "batch",则将数据全部读入后检测;若设置为 "stream",则需用户提供上下四分位数进行流式检测。默认为 "batch"。 -+ `q1`:使用流式计算时的下四分位数。 -+ `q3`:使用流式计算时的上四分位数。 - -**输出序列**:输出单个序列,类型为 DOUBLE。 - -**说明**:$IQR=Q_3-Q_1$ - -#### 使用示例 - -##### 全数据计算 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| -|1970-01-01T08:00:00.300+08:00| 1.0| -|1970-01-01T08:00:00.400+08:00| -1.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -|1970-01-01T08:00:00.600+08:00| 0.0| -|1970-01-01T08:00:00.700+08:00| -2.0| -|1970-01-01T08:00:00.800+08:00| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 1.0| -|1970-01-01T08:00:01.200+08:00| -1.0| -|1970-01-01T08:00:01.300+08:00| -1.0| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 0.0| -|1970-01-01T08:00:01.600+08:00| 0.0| -|1970-01-01T08:00:01.700+08:00| 10.0| -|1970-01-01T08:00:01.800+08:00| 2.0| -|1970-01-01T08:00:01.900+08:00| -2.0| -|1970-01-01T08:00:02.000+08:00| 0.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select iqr(s1) from root.test -``` - -输出序列: - -``` -+-----------------------------+-----------------+ -| Time|iqr(root.test.s1)| -+-----------------------------+-----------------+ -|1970-01-01T08:00:01.700+08:00| 10.0| -+-----------------------------+-----------------+ -``` - -### KSigma - -#### 注册语句 - -```sql -create function ksigma as 'org.apache.iotdb.library.anomaly.UDTFKSigma' -``` - -#### 函数简介 - -本函数利用动态 K-Sigma 算法进行异常检测。在一个窗口内,与平均值的差距超过k倍标准差的数据将被视作异常并输出。 - -**函数名:** KSIGMA - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `k`:在动态 K-Sigma 算法中,分布异常的标准差倍数阈值,默认值为 3。 -+ `window`:动态 K-Sigma 算法的滑动窗口大小,默认值为 10000。 - - -**输出序列:** 输出单个序列,类型与输入序列相同。 - -**提示:** k 应大于 0,否则将不做输出。 - -#### 使用示例 - -##### 指定k - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 0.0| -|2020-01-01T00:00:03.000+08:00| 50.0| -|2020-01-01T00:00:04.000+08:00| 100.0| -|2020-01-01T00:00:06.000+08:00| 150.0| -|2020-01-01T00:00:08.000+08:00| 200.0| -|2020-01-01T00:00:10.000+08:00| 200.0| -|2020-01-01T00:00:14.000+08:00| 200.0| -|2020-01-01T00:00:15.000+08:00| 200.0| -|2020-01-01T00:00:16.000+08:00| 200.0| -|2020-01-01T00:00:18.000+08:00| 200.0| -|2020-01-01T00:00:20.000+08:00| 150.0| -|2020-01-01T00:00:22.000+08:00| 100.0| -|2020-01-01T00:00:26.000+08:00| 50.0| -|2020-01-01T00:00:28.000+08:00| 0.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select ksigma(s1,"k"="1.0") from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+---------------------------------+ -|Time |ksigma(root.test.d1.s1,"k"="3.0")| -+-----------------------------+---------------------------------+ -|2020-01-01T00:00:02.000+08:00| 0.0| -|2020-01-01T00:00:03.000+08:00| 50.0| -|2020-01-01T00:00:26.000+08:00| 50.0| -|2020-01-01T00:00:28.000+08:00| 0.0| -+-----------------------------+---------------------------------+ -``` - -### LOF - -#### 注册语句 - -```sql -create function LOF as 'org.apache.iotdb.library.anomaly.UDTFLOF' -``` - -#### 函数简介 - -本函数使用局部离群点检测方法用于查找序列的密度异常。将根据提供的第k距离数及局部离群点因子(lof)阈值,判断输入数据是否为离群点,即异常,并输出各点的 LOF 值。 - -**函数名:** LOF - -**输入序列:** 多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`:使用的检测方法。默认为 default,以高维数据计算。设置为 series,将一维时间序列转换为高维数据计算。 -+ `k`:使用第k距离计算局部离群点因子.默认为 3。 -+ `window`:每次读取数据的窗口长度。默认为 10000. -+ `windowsize`:使用series方法时,转化高维数据的维数,即单个窗口的大小。默认为 5。 - -**输出序列:** 输出单时间序列,类型为DOUBLE。 - -**提示:** 不完整的数据行会被忽略,不参与计算,也不标记为离群点。 - - -#### 使用示例 - -##### 默认参数 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.100+08:00| 0.0| 0.0| -|1970-01-01T08:00:00.200+08:00| 0.0| 1.0| -|1970-01-01T08:00:00.300+08:00| 1.0| 1.0| -|1970-01-01T08:00:00.400+08:00| 1.0| 0.0| -|1970-01-01T08:00:00.500+08:00| 0.0| -1.0| -|1970-01-01T08:00:00.600+08:00| -1.0| -1.0| -|1970-01-01T08:00:00.700+08:00| -1.0| 0.0| -|1970-01-01T08:00:00.800+08:00| 2.0| 2.0| -|1970-01-01T08:00:00.900+08:00| 0.0| null| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select lof(s1,s2) from root.test.d1 where time<1000 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|lof(root.test.d1.s1, root.test.d1.s2)| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.100+08:00| 3.8274824267668244| -|1970-01-01T08:00:00.200+08:00| 3.0117631741126156| -|1970-01-01T08:00:00.300+08:00| 2.838155437762879| -|1970-01-01T08:00:00.400+08:00| 3.0117631741126156| -|1970-01-01T08:00:00.500+08:00| 2.73518261244453| -|1970-01-01T08:00:00.600+08:00| 2.371440975708148| -|1970-01-01T08:00:00.700+08:00| 2.73518261244453| -|1970-01-01T08:00:00.800+08:00| 1.7561416374270742| -+-----------------------------+-------------------------------------+ -``` - -##### 诊断一维时间序列 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.100+08:00| 1.0| -|1970-01-01T08:00:00.200+08:00| 2.0| -|1970-01-01T08:00:00.300+08:00| 3.0| -|1970-01-01T08:00:00.400+08:00| 4.0| -|1970-01-01T08:00:00.500+08:00| 5.0| -|1970-01-01T08:00:00.600+08:00| 6.0| -|1970-01-01T08:00:00.700+08:00| 7.0| -|1970-01-01T08:00:00.800+08:00| 8.0| -|1970-01-01T08:00:00.900+08:00| 9.0| -|1970-01-01T08:00:01.000+08:00| 10.0| -|1970-01-01T08:00:01.100+08:00| 11.0| -|1970-01-01T08:00:01.200+08:00| 12.0| -|1970-01-01T08:00:01.300+08:00| 13.0| -|1970-01-01T08:00:01.400+08:00| 14.0| -|1970-01-01T08:00:01.500+08:00| 15.0| -|1970-01-01T08:00:01.600+08:00| 16.0| -|1970-01-01T08:00:01.700+08:00| 17.0| -|1970-01-01T08:00:01.800+08:00| 18.0| -|1970-01-01T08:00:01.900+08:00| 19.0| -|1970-01-01T08:00:02.000+08:00| 20.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select lof(s1, "method"="series") from root.test.d1 where time<1000 -``` - -输出序列: - -``` -+-----------------------------+--------------------+ -| Time|lof(root.test.d1.s1)| -+-----------------------------+--------------------+ -|1970-01-01T08:00:00.100+08:00| 3.77777777777778| -|1970-01-01T08:00:00.200+08:00| 4.32727272727273| -|1970-01-01T08:00:00.300+08:00| 4.85714285714286| -|1970-01-01T08:00:00.400+08:00| 5.40909090909091| -|1970-01-01T08:00:00.500+08:00| 5.94999999999999| -|1970-01-01T08:00:00.600+08:00| 6.43243243243243| -|1970-01-01T08:00:00.700+08:00| 6.79999999999999| -|1970-01-01T08:00:00.800+08:00| 7.0| -|1970-01-01T08:00:00.900+08:00| 7.0| -|1970-01-01T08:00:01.000+08:00| 6.79999999999999| -|1970-01-01T08:00:01.100+08:00| 6.43243243243243| -|1970-01-01T08:00:01.200+08:00| 5.94999999999999| -|1970-01-01T08:00:01.300+08:00| 5.40909090909091| -|1970-01-01T08:00:01.400+08:00| 4.85714285714286| -|1970-01-01T08:00:01.500+08:00| 4.32727272727273| -|1970-01-01T08:00:01.600+08:00| 3.77777777777778| -+-----------------------------+--------------------+ -``` - -### MissDetect - -#### 注册语句 - -```sql -create function missdetect as 'org.apache.iotdb.library.anomaly.UDTFMissDetect' -``` - -#### 函数简介 - -本函数用于检测数据中的缺失异常。在一些数据中,缺失数据会被线性插值填补,在数据中出现完美的线性片段,且这些片段往往长度较大。本函数通过在数据中发现这些完美线性片段来检测缺失异常。 - -**函数名:** MISSDETECT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `minlen`:被标记为异常的完美线性片段的最小长度,是一个大于等于 10 的整数,默认值为 10。 - -**输出序列:** 输出单个序列,类型为 BOOLEAN,即该数据点是否为缺失异常。 - -**提示:** 数据中的`NaN`将会被忽略。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s2| -+-----------------------------+---------------+ -|2021-07-01T12:00:00.000+08:00| 0.0| -|2021-07-01T12:00:01.000+08:00| 1.0| -|2021-07-01T12:00:02.000+08:00| 0.0| -|2021-07-01T12:00:03.000+08:00| 1.0| -|2021-07-01T12:00:04.000+08:00| 0.0| -|2021-07-01T12:00:05.000+08:00| 0.0| -|2021-07-01T12:00:06.000+08:00| 0.0| -|2021-07-01T12:00:07.000+08:00| 0.0| -|2021-07-01T12:00:08.000+08:00| 0.0| -|2021-07-01T12:00:09.000+08:00| 0.0| -|2021-07-01T12:00:10.000+08:00| 0.0| -|2021-07-01T12:00:11.000+08:00| 0.0| -|2021-07-01T12:00:12.000+08:00| 0.0| -|2021-07-01T12:00:13.000+08:00| 0.0| -|2021-07-01T12:00:14.000+08:00| 0.0| -|2021-07-01T12:00:15.000+08:00| 0.0| -|2021-07-01T12:00:16.000+08:00| 1.0| -|2021-07-01T12:00:17.000+08:00| 0.0| -|2021-07-01T12:00:18.000+08:00| 1.0| -|2021-07-01T12:00:19.000+08:00| 0.0| -|2021-07-01T12:00:20.000+08:00| 1.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select missdetect(s2,'minlen'='10') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------+ -| Time|missdetect(root.test.d2.s2, "minlen"="10")| -+-----------------------------+------------------------------------------+ -|2021-07-01T12:00:00.000+08:00| false| -|2021-07-01T12:00:01.000+08:00| false| -|2021-07-01T12:00:02.000+08:00| false| -|2021-07-01T12:00:03.000+08:00| false| -|2021-07-01T12:00:04.000+08:00| true| -|2021-07-01T12:00:05.000+08:00| true| -|2021-07-01T12:00:06.000+08:00| true| -|2021-07-01T12:00:07.000+08:00| true| -|2021-07-01T12:00:08.000+08:00| true| -|2021-07-01T12:00:09.000+08:00| true| -|2021-07-01T12:00:10.000+08:00| true| -|2021-07-01T12:00:11.000+08:00| true| -|2021-07-01T12:00:12.000+08:00| true| -|2021-07-01T12:00:13.000+08:00| true| -|2021-07-01T12:00:14.000+08:00| true| -|2021-07-01T12:00:15.000+08:00| true| -|2021-07-01T12:00:16.000+08:00| false| -|2021-07-01T12:00:17.000+08:00| false| -|2021-07-01T12:00:18.000+08:00| false| -|2021-07-01T12:00:19.000+08:00| false| -|2021-07-01T12:00:20.000+08:00| false| -+-----------------------------+------------------------------------------+ -``` - -### Range - -#### 注册语句 - -```sql -create function range as 'org.apache.iotdb.library.anomaly.UDTFRange' -``` - -#### 函数简介 - -本函数用于查找时间序列的范围异常。将根据提供的上界与下界,判断输入数据是否越界,即异常,并输出所有异常点为新的时间序列。 - -**函数名:** RANGE - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `lower_bound`:范围异常检测的下界。 -+ `upper_bound`:范围异常检测的上界。 - -**输出序列:** 输出单个序列,类型与输入序列相同。 - -**提示:** 应满足`upper_bound`大于`lower_bound`,否则将不做输出。 - - -#### 使用示例 - -##### 指定上界与下界 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select range(s1,"lower_bound"="101.0","upper_bound"="125.0") from root.test.d1 where time <= 2020-01-01 00:00:30 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------------------+ -|Time |range(root.test.d1.s1,"lower_bound"="101.0","upper_bound"="125.0")| -+-----------------------------+------------------------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -+-----------------------------+------------------------------------------------------------------+ -``` - -### TwoSidedFilter - -#### 注册语句 - -```sql -create function twosidedfilter as 'org.apache.iotdb.library.anomaly.UDTFTwoSidedFilter' -``` - -#### 函数简介 - -本函数基于双边窗口检测法对输入序列中的异常点进行过滤。 - -**函数名:** TWOSIDEDFILTER - -**输出序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型与输入相同,是输入序列去除异常点后的结果。 - -**参数:** - -- `len`:双边窗口检测法中的窗口大小,取值范围为正整数,默认值为 5.如当`len`=3 时,算法向前、向后各取长度为3的窗口,在窗口中计算异常度。 -- `threshold`:异常度的阈值,取值范围为(0,1),默认值为 0.3。阈值越高,函数对于异常度的判定标准越严格。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s0| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 2002.0| -|1970-01-01T08:00:01.000+08:00| 1946.0| -|1970-01-01T08:00:02.000+08:00| 1958.0| -|1970-01-01T08:00:03.000+08:00| 2012.0| -|1970-01-01T08:00:04.000+08:00| 2051.0| -|1970-01-01T08:00:05.000+08:00| 1898.0| -|1970-01-01T08:00:06.000+08:00| 2014.0| -|1970-01-01T08:00:07.000+08:00| 2052.0| -|1970-01-01T08:00:08.000+08:00| 1935.0| -|1970-01-01T08:00:09.000+08:00| 1901.0| -|1970-01-01T08:00:10.000+08:00| 1972.0| -|1970-01-01T08:00:11.000+08:00| 1969.0| -|1970-01-01T08:00:12.000+08:00| 1984.0| -|1970-01-01T08:00:13.000+08:00| 2018.0| -|1970-01-01T08:00:37.000+08:00| 1484.0| -|1970-01-01T08:00:38.000+08:00| 1055.0| -|1970-01-01T08:00:39.000+08:00| 1050.0| -|1970-01-01T08:01:05.000+08:00| 1023.0| -|1970-01-01T08:01:06.000+08:00| 1056.0| -|1970-01-01T08:01:07.000+08:00| 978.0| -|1970-01-01T08:01:08.000+08:00| 1050.0| -|1970-01-01T08:01:09.000+08:00| 1123.0| -|1970-01-01T08:01:10.000+08:00| 1150.0| -|1970-01-01T08:01:11.000+08:00| 1034.0| -|1970-01-01T08:01:12.000+08:00| 950.0| -|1970-01-01T08:01:13.000+08:00| 1059.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select TwoSidedFilter(s0, 'len'='5', 'threshold'='0.3') from root.test -``` - -输出序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s0| -+-----------------------------+------------+ -|1970-01-01T08:00:00.000+08:00| 2002.0| -|1970-01-01T08:00:01.000+08:00| 1946.0| -|1970-01-01T08:00:02.000+08:00| 1958.0| -|1970-01-01T08:00:03.000+08:00| 2012.0| -|1970-01-01T08:00:04.000+08:00| 2051.0| -|1970-01-01T08:00:05.000+08:00| 1898.0| -|1970-01-01T08:00:06.000+08:00| 2014.0| -|1970-01-01T08:00:07.000+08:00| 2052.0| -|1970-01-01T08:00:08.000+08:00| 1935.0| -|1970-01-01T08:00:09.000+08:00| 1901.0| -|1970-01-01T08:00:10.000+08:00| 1972.0| -|1970-01-01T08:00:11.000+08:00| 1969.0| -|1970-01-01T08:00:12.000+08:00| 1984.0| -|1970-01-01T08:00:13.000+08:00| 2018.0| -|1970-01-01T08:01:05.000+08:00| 1023.0| -|1970-01-01T08:01:06.000+08:00| 1056.0| -|1970-01-01T08:01:07.000+08:00| 978.0| -|1970-01-01T08:01:08.000+08:00| 1050.0| -|1970-01-01T08:01:09.000+08:00| 1123.0| -|1970-01-01T08:01:10.000+08:00| 1150.0| -|1970-01-01T08:01:11.000+08:00| 1034.0| -|1970-01-01T08:01:12.000+08:00| 950.0| -|1970-01-01T08:01:13.000+08:00| 1059.0| -+-----------------------------+------------+ -``` - -### Outlier - -#### 注册语句 - -```sql -create function outlier as 'org.apache.iotdb.library.anomaly.UDTFOutlier' -``` - -#### 函数简介 - -本函数用于检测基于距离的异常点。在当前窗口中,如果一个点距离阈值范围内的邻居数量(包括它自己)少于密度阈值,则该点是异常点。 - -**函数名:** OUTLIER - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `r`:基于距离异常检测中的距离阈值。 -+ `k`:基于距离异常检测中的密度阈值。 -+ `w`:用于指定滑动窗口的大小。 -+ `s`:用于指定滑动窗口的步长。 - -**输出序列**:输出单个序列,类型与输入序列相同。 - -#### 使用示例 - -##### 指定查询参数 - -输入序列: - -``` -+-----------------------------+------------+ -| Time|root.test.s1| -+-----------------------------+------------+ -|2020-01-04T23:59:55.000+08:00| 56.0| -|2020-01-04T23:59:56.000+08:00| 55.1| -|2020-01-04T23:59:57.000+08:00| 54.2| -|2020-01-04T23:59:58.000+08:00| 56.3| -|2020-01-04T23:59:59.000+08:00| 59.0| -|2020-01-05T00:00:00.000+08:00| 60.0| -|2020-01-05T00:00:01.000+08:00| 60.5| -|2020-01-05T00:00:02.000+08:00| 64.5| -|2020-01-05T00:00:03.000+08:00| 69.0| -|2020-01-05T00:00:04.000+08:00| 64.2| -|2020-01-05T00:00:05.000+08:00| 62.3| -|2020-01-05T00:00:06.000+08:00| 58.0| -|2020-01-05T00:00:07.000+08:00| 58.9| -|2020-01-05T00:00:08.000+08:00| 52.0| -|2020-01-05T00:00:09.000+08:00| 62.3| -|2020-01-05T00:00:10.000+08:00| 61.0| -|2020-01-05T00:00:11.000+08:00| 64.2| -|2020-01-05T00:00:12.000+08:00| 61.8| -|2020-01-05T00:00:13.000+08:00| 64.0| -|2020-01-05T00:00:14.000+08:00| 63.0| -+-----------------------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select outlier(s1,"r"="5.0","k"="4","w"="10","s"="5") from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------+ -| Time|outlier(root.test.s1,"r"="5.0","k"="4","w"="10","s"="5")| -+-----------------------------+--------------------------------------------------------+ -|2020-01-05T00:00:03.000+08:00| 69.0| -+-----------------------------+--------------------------------------------------------+ -|2020-01-05T00:00:08.000+08:00| 52.0| -+-----------------------------+--------------------------------------------------------+ -``` - -### MasterTrain - -#### 函数简介 - -本函数基于主数据训练VAR预测模型。将根据提供的主数据判断时间序列中的数据点是否为错误值,并由连续p+1个非错误值作为训练样本训练VAR模型,输出训练后的模型参数。 - -**函数名:** MasterTrain - -**输入序列:** 支持多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `p`:模型阶数。 -+ `eta`:错误值判定阈值,在缺省情况下,算法根据3-sigma原则自动估计该参数。 - -**输出序列:** 输出单个序列,类型为DOUBLE。 - -**安装方式:** - -- 从IoTDB代码仓库下载`research/master-detector`分支代码到本地 -- 在根目录运行 `mvn spotless:apply` -- 在根目录运行 `mvn clean package -pl library-udf -DskipTests -am -P get-jar-with-dependencies` 编译项目 -- 将 `./library-UDF/target/library-udf-1.2.0-SNAPSHOT-jar-with-dependencies.jar`复制到IoTDB服务器的`./ext/udf/` 路径下。 -- 启动 IoTDB服务器,在客户端中执行 `create function MasterTrain as org.apache.iotdb.library.anomaly.UDTFMasterTrain'`。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+------------+--------------+--------------+ -| Time|root.test.lo|root.test.la|root.test.m_la|root.test.m_lo| -+-----------------------------+------------+------------+--------------+--------------+ -|1970-01-01T08:00:00.001+08:00| 39.99982556| 116.327274| 116.3271939| 39.99984748| -|1970-01-01T08:00:00.002+08:00| 39.99983865| 116.327305| 116.3272269| 39.99984748| -|1970-01-01T08:00:00.003+08:00| 40.00019038| 116.3273291| 116.3272634| 39.99984769| -|1970-01-01T08:00:00.004+08:00| 39.99982556| 116.327342| 116.3273015| 39.9998483| -|1970-01-01T08:00:00.005+08:00| 39.99982991| 116.3273744| 116.327339| 39.99984892| -|1970-01-01T08:00:00.006+08:00| 39.99982716| 116.3274117| 116.3273759| 39.99984892| -|1970-01-01T08:00:00.007+08:00| 39.9998259| 116.3274396| 116.3274163| 39.99984953| -|1970-01-01T08:00:00.008+08:00| 39.99982597| 116.3274668| 116.3274525| 39.99985014| -|1970-01-01T08:00:00.009+08:00| 39.99982226| 116.3275026| 116.3274915| 39.99985076| -|1970-01-01T08:00:00.010+08:00| 39.99980988| 116.3274967| 116.3275235| 39.99985137| -|1970-01-01T08:00:00.011+08:00| 39.99984873| 116.3274929| 116.3275611| 39.99985199| -|1970-01-01T08:00:00.012+08:00| 39.99981589| 116.3274745| 116.3275974| 39.9998526| -|1970-01-01T08:00:00.013+08:00| 39.9998259| 116.3275095| 116.3276338| 39.99985384| -|1970-01-01T08:00:00.014+08:00| 39.99984873| 116.3274787| 116.3276695| 39.99985446| -|1970-01-01T08:00:00.015+08:00| 39.9998343| 116.3274693| 116.3277045| 39.99985569| -|1970-01-01T08:00:00.016+08:00| 39.99983316| 116.3274941| 116.3277389| 39.99985631| -|1970-01-01T08:00:00.017+08:00| 39.99983311| 116.3275401| 116.3277747| 39.99985693| -|1970-01-01T08:00:00.018+08:00| 39.99984113| 116.3275713| 116.3278041| 39.99985756| -|1970-01-01T08:00:00.019+08:00| 39.99983602| 116.3276003| 116.3278379| 39.99985818| -|1970-01-01T08:00:00.020+08:00| 39.9998355| 116.3276308| 116.3278723| 39.9998588| -|1970-01-01T08:00:00.021+08:00| 40.00012176| 116.3276107| 116.3279026| 39.99985942| -|1970-01-01T08:00:00.022+08:00| 39.9998404| 116.3276684| null| null| -|1970-01-01T08:00:00.023+08:00| 39.99983942| 116.3277016| null| null| -|1970-01-01T08:00:00.024+08:00| 39.99984113| 116.3277284| null| null| -|1970-01-01T08:00:00.025+08:00| 39.99984283| 116.3277562| null| null| -+-----------------------------+------------+------------+--------------+--------------+ -``` - -用于查询的 SQL 语句: - -```sql -select MasterTrain(lo,la,m_lo,m_la,'p'='3','eta'='1.0') from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------------------------------------------------------------+ -| Time|MasterTrain(root.test.lo, root.test.la, root.test.m_lo, root.test.m_la, "p"="3", "eta"="1.0")| -+-----------------------------+---------------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 0.13656607660463288| -|1970-01-01T08:00:00.002+08:00| 0.8291884323013894| -|1970-01-01T08:00:00.003+08:00| 0.05012816073171693| -|1970-01-01T08:00:00.004+08:00| -0.5495287787485761| -|1970-01-01T08:00:00.005+08:00| 0.03740486307345578| -|1970-01-01T08:00:00.006+08:00| 1.0500132150475212| -|1970-01-01T08:00:00.007+08:00| 0.04583944643116993| -|1970-01-01T08:00:00.008+08:00| -0.07863708480736269| -+-----------------------------+---------------------------------------------------------------------------------------------+ - -``` - -### MasterDetect - -#### 函数简介 - -本函数基于主数据检测并修复时间序列中的错误值。将根据提供的主数据判断时间序列中的数据点是否为错误值,并由MasterTrain训练的模型进行时间序列预测,错误值将由预测值及主数据共同修复。 - -**函数名:** MasterDetect - -**输入序列:** 支持多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `p`:模型阶数。 -+ `k`:主数据中的近邻数量,正整数, 在缺省情况下,算法根据主数据中的k个近邻的元组距离自动估计该参数。 -+ `eta`:错误值判定阈值,在缺省情况下,算法根据3-sigma原则自动估计该参数。 -+ `beta`:异常值判定阈值,在缺省情况下,算法根据3-sigma原则自动估计该参数。 -+ `output_type`:输出结果类型,可选'repair'或'anomaly',即输出修复结果或异常检测结果,在缺省情况下默认为'repair'。 -+ `output_column`:输出列的序号,默认为1,即输出第一列的修复结果。 - -**安装方式:** - -- 从IoTDB代码仓库下载`research/master-detector`分支代码到本地 -- 在根目录运行 `mvn spotless:apply` -- 在根目录运行 `mvn clean package -pl library-udf -DskipTests -am -P get-jar-with-dependencies` 编译项目 -- 将 `./library-UDF/target/library-udf-1.2.0-SNAPSHOT-jar-with-dependencies.jar`复制到IoTDB服务器的`./ext/udf/` 路径下。 -- 启动 IoTDB服务器,在客户端中执行 `create function MasterDetect as 'org.apache.iotdb.library.anomaly.UDTFMasterDetect'`。 - -**输出序列:** 输出单个序列,类型与输入数据中对应列的类型相同,序列为输入列修复后的结果。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+------------+--------------+--------------+--------------------+ -| Time|root.test.lo|root.test.la|root.test.m_la|root.test.m_lo| root.test.model| -+-----------------------------+------------+------------+--------------+--------------+--------------------+ -|1970-01-01T08:00:00.001+08:00| 39.99982556| 116.327274| 116.3271939| 39.99984748| 0.13656607660463288| -|1970-01-01T08:00:00.002+08:00| 39.99983865| 116.327305| 116.3272269| 39.99984748| 0.8291884323013894| -|1970-01-01T08:00:00.003+08:00| 40.00019038| 116.3273291| 116.3272634| 39.99984769| 0.05012816073171693| -|1970-01-01T08:00:00.004+08:00| 39.99982556| 116.327342| 116.3273015| 39.9998483| -0.5495287787485761| -|1970-01-01T08:00:00.005+08:00| 39.99982991| 116.3273744| 116.327339| 39.99984892| 0.03740486307345578| -|1970-01-01T08:00:00.006+08:00| 39.99982716| 116.3274117| 116.3273759| 39.99984892| 1.0500132150475212| -|1970-01-01T08:00:00.007+08:00| 39.9998259| 116.3274396| 116.3274163| 39.99984953| 0.04583944643116993| -|1970-01-01T08:00:00.008+08:00| 39.99982597| 116.3274668| 116.3274525| 39.99985014|-0.07863708480736269| -|1970-01-01T08:00:00.009+08:00| 39.99982226| 116.3275026| 116.3274915| 39.99985076| null| -|1970-01-01T08:00:00.010+08:00| 39.99980988| 116.3274967| 116.3275235| 39.99985137| null| -|1970-01-01T08:00:00.011+08:00| 39.99984873| 116.3274929| 116.3275611| 39.99985199| null| -|1970-01-01T08:00:00.012+08:00| 39.99981589| 116.3274745| 116.3275974| 39.9998526| null| -|1970-01-01T08:00:00.013+08:00| 39.9998259| 116.3275095| 116.3276338| 39.99985384| null| -|1970-01-01T08:00:00.014+08:00| 39.99984873| 116.3274787| 116.3276695| 39.99985446| null| -|1970-01-01T08:00:00.015+08:00| 39.9998343| 116.3274693| 116.3277045| 39.99985569| null| -|1970-01-01T08:00:00.016+08:00| 39.99983316| 116.3274941| 116.3277389| 39.99985631| null| -|1970-01-01T08:00:00.017+08:00| 39.99983311| 116.3275401| 116.3277747| 39.99985693| null| -|1970-01-01T08:00:00.018+08:00| 39.99984113| 116.3275713| 116.3278041| 39.99985756| null| -|1970-01-01T08:00:00.019+08:00| 39.99983602| 116.3276003| 116.3278379| 39.99985818| null| -|1970-01-01T08:00:00.020+08:00| 39.9998355| 116.3276308| 116.3278723| 39.9998588| null| -|1970-01-01T08:00:00.021+08:00| 40.00012176| 116.3276107| 116.3279026| 39.99985942| null| -|1970-01-01T08:00:00.022+08:00| 39.9998404| 116.3276684| null| null| null| -|1970-01-01T08:00:00.023+08:00| 39.99983942| 116.3277016| null| null| null| -|1970-01-01T08:00:00.024+08:00| 39.99984113| 116.3277284| null| null| null| -|1970-01-01T08:00:00.025+08:00| 39.99984283| 116.3277562| null| null| null| -+-----------------------------+------------+------------+--------------+--------------+--------------------+ -``` - -##### 修复 - -用于查询的 SQL 语句: - -```sql -select MasterDetect(lo,la,m_lo,m_la,model,'output_type'='repair','p'='3','k'='3','eta'='1.0') from root.test -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------------------------------------+ -| Time|MasterDetect(lo,la,m_lo,m_la,model,'output_type'='repair','p'='3','k'='3','eta'='1.0')| -+-----------------------------+--------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 116.327274| -|1970-01-01T08:00:00.002+08:00| 116.327305| -|1970-01-01T08:00:00.003+08:00| 116.3273291| -|1970-01-01T08:00:00.004+08:00| 116.327342| -|1970-01-01T08:00:00.005+08:00| 116.3273744| -|1970-01-01T08:00:00.006+08:00| 116.3274117| -|1970-01-01T08:00:00.007+08:00| 116.3274396| -|1970-01-01T08:00:00.008+08:00| 116.3274668| -|1970-01-01T08:00:00.009+08:00| 116.3275026| -|1970-01-01T08:00:00.010+08:00| 116.3274967| -|1970-01-01T08:00:00.011+08:00| 116.3274929| -|1970-01-01T08:00:00.012+08:00| 116.3274745| -|1970-01-01T08:00:00.013+08:00| 116.3275095| -|1970-01-01T08:00:00.014+08:00| 116.3274787| -|1970-01-01T08:00:00.015+08:00| 116.3274693| -|1970-01-01T08:00:00.016+08:00| 116.3274941| -|1970-01-01T08:00:00.017+08:00| 116.3275401| -|1970-01-01T08:00:00.018+08:00| 116.3275713| -|1970-01-01T08:00:00.019+08:00| 116.3276003| -|1970-01-01T08:00:00.020+08:00| 116.3276308| -|1970-01-01T08:00:00.021+08:00| 116.3276338| -|1970-01-01T08:00:00.022+08:00| 116.3276684| -|1970-01-01T08:00:00.023+08:00| 116.3277016| -|1970-01-01T08:00:00.024+08:00| 116.3277284| -|1970-01-01T08:00:00.025+08:00| 116.3277562| -+-----------------------------+--------------------------------------------------------------------------------------+ -``` - -##### 异常检测 - -用于查询的 SQL 语句: - -```sql -select MasterDetect(lo,la,m_lo,m_la,model,'output_type'='anomaly','p'='3','k'='3','eta'='1.0') from root.test -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------------------------------------------------------+ -| Time|MasterDetect(lo,la,m_lo,m_la,model,'output_type'='anomaly','p'='3','k'='3','eta'='1.0')| -+-----------------------------+---------------------------------------------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| false| -|1970-01-01T08:00:00.002+08:00| false| -|1970-01-01T08:00:00.003+08:00| false| -|1970-01-01T08:00:00.004+08:00| false| -|1970-01-01T08:00:00.005+08:00| true| -|1970-01-01T08:00:00.006+08:00| false| -|1970-01-01T08:00:00.007+08:00| false| -|1970-01-01T08:00:00.008+08:00| false| -|1970-01-01T08:00:00.009+08:00| false| -|1970-01-01T08:00:00.010+08:00| false| -|1970-01-01T08:00:00.011+08:00| false| -|1970-01-01T08:00:00.012+08:00| false| -|1970-01-01T08:00:00.013+08:00| false| -|1970-01-01T08:00:00.014+08:00| true| -|1970-01-01T08:00:00.015+08:00| false| -|1970-01-01T08:00:00.016+08:00| false| -|1970-01-01T08:00:00.017+08:00| false| -|1970-01-01T08:00:00.018+08:00| false| -|1970-01-01T08:00:00.019+08:00| false| -|1970-01-01T08:00:00.020+08:00| false| -|1970-01-01T08:00:00.021+08:00| false| -|1970-01-01T08:00:00.022+08:00| false| -|1970-01-01T08:00:00.023+08:00| false| -|1970-01-01T08:00:00.024+08:00| false| -|1970-01-01T08:00:00.025+08:00| false| -+-----------------------------+---------------------------------------------------------------------------------------+ -``` - - - -## 频域分析 - -### Conv - -#### 注册语句 - -```sql -create function conv as 'org.apache.iotdb.library.frequency.UDTFConv' -``` - -#### 函数简介 - -本函数对两个输入序列进行卷积,即多项式乘法。 - - -**函数名:** CONV - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE - -**输出序列:** 输出单个序列,类型为DOUBLE,它是两个序列卷积的结果。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 1.0| 7.0| -|1970-01-01T08:00:00.001+08:00| 0.0| 2.0| -|1970-01-01T08:00:00.002+08:00| 1.0| null| -+-----------------------------+---------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select conv(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------+ -| Time|conv(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+--------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 7.0| -|1970-01-01T08:00:00.001+08:00| 2.0| -|1970-01-01T08:00:00.002+08:00| 7.0| -|1970-01-01T08:00:00.003+08:00| 2.0| -+-----------------------------+--------------------------------------+ -``` - -### Deconv - -#### 注册语句 - -```sql -create function deconv as 'org.apache.iotdb.library.frequency.UDTFDeconv' -``` - -#### 函数简介 - -本函数对两个输入序列进行去卷积,即多项式除法运算。 - -**函数名:** DECONV - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `result`:去卷积的结果,取值为'quotient'或'remainder',分别对应于去卷积的商和余数。在缺省情况下,输出去卷积的商。 - -**输出序列:** 输出单个序列,类型为DOUBLE。它是将第二个序列从第一个序列中去卷积(第一个序列除以第二个序列)的结果。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -##### 计算去卷积的商 - -当`result`参数缺省或为'quotient'时,本函数计算去卷积的商。 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s3|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 8.0| 7.0| -|1970-01-01T08:00:00.001+08:00| 2.0| 2.0| -|1970-01-01T08:00:00.002+08:00| 7.0| null| -|1970-01-01T08:00:00.003+08:00| 2.0| null| -+-----------------------------+---------------+---------------+ -``` - - -用于查询的SQL语句: - -```sql -select deconv(s3,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------+ -| Time|deconv(root.test.d2.s3, root.test.d2.s2)| -+-----------------------------+----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 1.0| -|1970-01-01T08:00:00.001+08:00| 0.0| -|1970-01-01T08:00:00.002+08:00| 1.0| -+-----------------------------+----------------------------------------+ -``` - -##### 计算去卷积的余数 - -当`result`参数为'remainder'时,本函数计算去卷积的余数。输入序列同上,用于查询的SQL语句如下: - -```sql -select deconv(s3,s2,'result'='remainder') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------------+ -| Time|deconv(root.test.d2.s3, root.test.d2.s2, "result"="remainder")| -+-----------------------------+--------------------------------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 1.0| -|1970-01-01T08:00:00.001+08:00| 0.0| -|1970-01-01T08:00:00.002+08:00| 0.0| -|1970-01-01T08:00:00.003+08:00| 0.0| -+-----------------------------+--------------------------------------------------------------+ -``` - -### DWT - -#### 注册语句 - -```sql -create function dwt as 'org.apache.iotdb.library.frequency.UDTFDWT' -``` - -#### 函数简介 - -本函数对输入序列进行一维离散小波变换。 - -**函数名:** DWT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`:小波滤波的类型,提供'Haar', 'DB4', 'DB6', 'DB8',其中DB指代Daubechies。若不设置该参数,则用户需提供小波滤波的系数。不区分大小写。 -+ `coef`:小波滤波的系数。若提供该参数,请使用英文逗号','分割各项,不添加空格或其它符号。 -+ `layer`:进行变换的次数,最终输出的向量个数等同于$layer+1$.默认取1。 - -**输出序列:** 输出单个序列,类型为DOUBLE,长度与输入相等。 - -**提示:** 输入序列长度必须为2的整数次幂。 - -#### 使用示例 - -##### Haar变换 - - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.100+08:00| 0.2| -|1970-01-01T08:00:00.200+08:00| 1.5| -|1970-01-01T08:00:00.300+08:00| 1.2| -|1970-01-01T08:00:00.400+08:00| 0.6| -|1970-01-01T08:00:00.500+08:00| 1.7| -|1970-01-01T08:00:00.600+08:00| 0.8| -|1970-01-01T08:00:00.700+08:00| 2.0| -|1970-01-01T08:00:00.800+08:00| 2.5| -|1970-01-01T08:00:00.900+08:00| 2.1| -|1970-01-01T08:00:01.000+08:00| 0.0| -|1970-01-01T08:00:01.100+08:00| 2.0| -|1970-01-01T08:00:01.200+08:00| 1.8| -|1970-01-01T08:00:01.300+08:00| 1.2| -|1970-01-01T08:00:01.400+08:00| 1.0| -|1970-01-01T08:00:01.500+08:00| 1.6| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select dwt(s1,"method"="haar") from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|dwt(root.test.d1.s1, "method"="haar")| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.14142135834465192| -|1970-01-01T08:00:00.100+08:00| 1.909188342921157| -|1970-01-01T08:00:00.200+08:00| 1.6263456473052773| -|1970-01-01T08:00:00.300+08:00| 1.9798989957517026| -|1970-01-01T08:00:00.400+08:00| 3.252691126023161| -|1970-01-01T08:00:00.500+08:00| 1.414213562373095| -|1970-01-01T08:00:00.600+08:00| 2.1213203435596424| -|1970-01-01T08:00:00.700+08:00| 1.8384776479437628| -|1970-01-01T08:00:00.800+08:00| -0.14142135834465192| -|1970-01-01T08:00:00.900+08:00| 0.21213200063848547| -|1970-01-01T08:00:01.000+08:00| -0.7778174761639416| -|1970-01-01T08:00:01.100+08:00| -0.8485281289944873| -|1970-01-01T08:00:01.200+08:00| 0.2828427799095765| -|1970-01-01T08:00:01.300+08:00| -1.414213562373095| -|1970-01-01T08:00:01.400+08:00| 0.42426400127697095| -|1970-01-01T08:00:01.500+08:00| -0.42426408557066786| -+-----------------------------+-------------------------------------+ -``` - -### FFT - -#### 注册语句 - -```sql -create function fft as 'org.apache.iotdb.library.frequency.UDTFFFT' -``` - -#### 函数简介 - -本函数对输入序列进行快速傅里叶变换。 - -**函数名:** FFT - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`:傅里叶变换的类型,取值为'uniform'或'nonuniform',缺省情况下为'uniform'。当取值为'uniform'时,时间戳将被忽略,所有数据点都将被视作等距的,并应用等距快速傅里叶算法;当取值为'nonuniform'时,将根据时间戳应用非等距快速傅里叶算法(未实现)。 -+ `result`:傅里叶变换的结果,取值为'real'、'imag'、'abs'或'angle',分别对应于变换结果的实部、虚部、模和幅角。在缺省情况下,输出变换的模。 -+ `compress`:压缩参数,取值范围(0,1],是有损压缩时保留的能量比例。在缺省情况下,不进行压缩。 - -**输出序列:** 输出单个序列,类型为DOUBLE,长度与输入相等。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -##### 等距傅里叶变换 - -当`type`参数缺省或为'uniform'时,本函数进行等距傅里叶变换。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 2.902113| -|1970-01-01T08:00:01.000+08:00| 1.1755705| -|1970-01-01T08:00:02.000+08:00| -2.1755705| -|1970-01-01T08:00:03.000+08:00| -1.9021131| -|1970-01-01T08:00:04.000+08:00| 1.0| -|1970-01-01T08:00:05.000+08:00| 1.9021131| -|1970-01-01T08:00:06.000+08:00| 0.1755705| -|1970-01-01T08:00:07.000+08:00| -1.1755705| -|1970-01-01T08:00:08.000+08:00| -0.902113| -|1970-01-01T08:00:09.000+08:00| 0.0| -|1970-01-01T08:00:10.000+08:00| 0.902113| -|1970-01-01T08:00:11.000+08:00| 1.1755705| -|1970-01-01T08:00:12.000+08:00| -0.1755705| -|1970-01-01T08:00:13.000+08:00| -1.9021131| -|1970-01-01T08:00:14.000+08:00| -1.0| -|1970-01-01T08:00:15.000+08:00| 1.9021131| -|1970-01-01T08:00:16.000+08:00| 2.1755705| -|1970-01-01T08:00:17.000+08:00| -1.1755705| -|1970-01-01T08:00:18.000+08:00| -2.902113| -|1970-01-01T08:00:19.000+08:00| 0.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select fft(s1) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------+ -| Time| fft(root.test.d1.s1)| -+-----------------------------+----------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| -|1970-01-01T08:00:00.001+08:00| 1.2727111142703152E-8| -|1970-01-01T08:00:00.002+08:00| 2.385520799101839E-7| -|1970-01-01T08:00:00.003+08:00| 8.723291723972645E-8| -|1970-01-01T08:00:00.004+08:00| 19.999999960195904| -|1970-01-01T08:00:00.005+08:00| 9.999999850988388| -|1970-01-01T08:00:00.006+08:00| 3.2260694930700566E-7| -|1970-01-01T08:00:00.007+08:00| 8.723291605373329E-8| -|1970-01-01T08:00:00.008+08:00| 1.108657103979944E-7| -|1970-01-01T08:00:00.009+08:00| 1.2727110997246171E-8| -|1970-01-01T08:00:00.010+08:00|1.9852334701272664E-23| -|1970-01-01T08:00:00.011+08:00| 1.2727111194499847E-8| -|1970-01-01T08:00:00.012+08:00| 1.108657103979944E-7| -|1970-01-01T08:00:00.013+08:00| 8.723291785769131E-8| -|1970-01-01T08:00:00.014+08:00| 3.226069493070057E-7| -|1970-01-01T08:00:00.015+08:00| 9.999999850988388| -|1970-01-01T08:00:00.016+08:00| 19.999999960195904| -|1970-01-01T08:00:00.017+08:00| 8.723291747109068E-8| -|1970-01-01T08:00:00.018+08:00| 2.3855207991018386E-7| -|1970-01-01T08:00:00.019+08:00| 1.2727112069910878E-8| -+-----------------------------+----------------------+ -``` - -注:输入序列服从$y=sin(2\pi t/4)+2sin(2\pi t/5)$,长度为20,因此在输出序列中$k=4$和$k=5$处有尖峰。 - -##### 等距傅里叶变换并压缩 - -输入序列同上,用于查询的SQL语句如下: - -```sql -select fft(s1, 'result'='real', 'compress'='0.99'), fft(s1, 'result'='imag','compress'='0.99') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------+----------------------+ -| Time| fft(root.test.d1.s1,| fft(root.test.d1.s1,| -| | "result"="real",| "result"="imag",| -| | "compress"="0.99")| "compress"="0.99")| -+-----------------------------+----------------------+----------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| 0.0| -|1970-01-01T08:00:00.001+08:00| -3.932894010461041E-9| 1.2104201863039066E-8| -|1970-01-01T08:00:00.002+08:00|-1.4021739447490164E-7| 1.9299268669082926E-7| -|1970-01-01T08:00:00.003+08:00| -7.057291240286645E-8| 5.127422242345858E-8| -|1970-01-01T08:00:00.004+08:00| 19.021130288047125| -6.180339875198807| -|1970-01-01T08:00:00.005+08:00| 9.999999850988388| 3.501852745067114E-16| -|1970-01-01T08:00:00.019+08:00| -3.932894898639461E-9|-1.2104202549376264E-8| -+-----------------------------+----------------------+----------------------+ -``` - -注:基于傅里叶变换结果的共轭性质,压缩结果只保留前一半;根据给定的压缩参数,从低频到高频保留数据点,直到保留的能量比例超过该值;保留最后一个数据点以表示序列长度。 - -### HighPass - -#### 注册语句 - -```sql -create function highpass as 'org.apache.iotdb.library.frequency.UDTFHighPass' -``` - -#### 函数简介 - -本函数对输入序列进行高通滤波,提取高于截止频率的分量。输入序列的时间戳将被忽略,所有数据点都将被视作等距的。 - -**函数名:** HIGHPASS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `wpass`:归一化后的截止频率,取值为(0,1),不可缺省。 - -**输出序列:** 输出单个序列,类型为DOUBLE,它是滤波后的序列,长度与时间戳均与输入一致。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 2.902113| -|1970-01-01T08:00:01.000+08:00| 1.1755705| -|1970-01-01T08:00:02.000+08:00| -2.1755705| -|1970-01-01T08:00:03.000+08:00| -1.9021131| -|1970-01-01T08:00:04.000+08:00| 1.0| -|1970-01-01T08:00:05.000+08:00| 1.9021131| -|1970-01-01T08:00:06.000+08:00| 0.1755705| -|1970-01-01T08:00:07.000+08:00| -1.1755705| -|1970-01-01T08:00:08.000+08:00| -0.902113| -|1970-01-01T08:00:09.000+08:00| 0.0| -|1970-01-01T08:00:10.000+08:00| 0.902113| -|1970-01-01T08:00:11.000+08:00| 1.1755705| -|1970-01-01T08:00:12.000+08:00| -0.1755705| -|1970-01-01T08:00:13.000+08:00| -1.9021131| -|1970-01-01T08:00:14.000+08:00| -1.0| -|1970-01-01T08:00:15.000+08:00| 1.9021131| -|1970-01-01T08:00:16.000+08:00| 2.1755705| -|1970-01-01T08:00:17.000+08:00| -1.1755705| -|1970-01-01T08:00:18.000+08:00| -2.902113| -|1970-01-01T08:00:19.000+08:00| 0.0| -+-----------------------------+---------------+ -``` - - -用于查询的SQL语句: - -```sql -select highpass(s1,'wpass'='0.45') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------+ -| Time|highpass(root.test.d1.s1, "wpass"="0.45")| -+-----------------------------+-----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.9999999534830373| -|1970-01-01T08:00:01.000+08:00| 1.7462829277628608E-8| -|1970-01-01T08:00:02.000+08:00| -0.9999999593178128| -|1970-01-01T08:00:03.000+08:00| -4.1115269056426626E-8| -|1970-01-01T08:00:04.000+08:00| 0.9999999925494194| -|1970-01-01T08:00:05.000+08:00| 3.328126513330016E-8| -|1970-01-01T08:00:06.000+08:00| -1.0000000183304454| -|1970-01-01T08:00:07.000+08:00| 6.260191433311374E-10| -|1970-01-01T08:00:08.000+08:00| 1.0000000018134796| -|1970-01-01T08:00:09.000+08:00| -3.097210911744423E-17| -|1970-01-01T08:00:10.000+08:00| -1.0000000018134794| -|1970-01-01T08:00:11.000+08:00| -6.260191627862097E-10| -|1970-01-01T08:00:12.000+08:00| 1.0000000183304454| -|1970-01-01T08:00:13.000+08:00| -3.328126501424346E-8| -|1970-01-01T08:00:14.000+08:00| -0.9999999925494196| -|1970-01-01T08:00:15.000+08:00| 4.111526915498874E-8| -|1970-01-01T08:00:16.000+08:00| 0.9999999593178128| -|1970-01-01T08:00:17.000+08:00| -1.7462829341296528E-8| -|1970-01-01T08:00:18.000+08:00| -0.9999999534830369| -|1970-01-01T08:00:19.000+08:00| -1.035237222742873E-16| -+-----------------------------+-----------------------------------------+ -``` - -注:输入序列服从$y=sin(2\pi t/4)+2sin(2\pi t/5)$,长度为20,因此高通滤波之后的输出序列服从$y=sin(2\pi t/4)$。 - -### IFFT - -#### 注册语句 - -```sql -create function ifft as 'org.apache.iotdb.library.frequency.UDTFIFFT' -``` - -#### 函数简介 - -本函数将输入的两个序列作为实部和虚部视作一个复数,进行逆快速傅里叶变换,并输出结果的实部。输入数据的格式参见`FFT`函数的输出,并支持以`FFT`函数压缩后的输出作为本函数的输入。 - -**函数名:** IFFT - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `start`:输出序列的起始时刻,是一个格式为'yyyy-MM-dd HH:mm:ss'的时间字符串。在缺省情况下,为'1970-01-01 08:00:00'。 -+ `interval`:输出序列的时间间隔,是一个有单位的正数。目前支持五种单位,分别是'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。在缺省情况下,为1s。 - - -**输出序列:** 输出单个序列,类型为DOUBLE。该序列是一个等距时间序列,它的值是将两个输入序列依次作为实部和虚部进行逆快速傅里叶变换的结果。 - -**提示:** 如果某行数据中包含空值或`NaN`,该行数据将会被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+----------------------+----------------------+ -| Time| root.test.d1.re| root.test.d1.im| -+-----------------------------+----------------------+----------------------+ -|1970-01-01T08:00:00.000+08:00| 0.0| 0.0| -|1970-01-01T08:00:00.001+08:00| -3.932894010461041E-9| 1.2104201863039066E-8| -|1970-01-01T08:00:00.002+08:00|-1.4021739447490164E-7| 1.9299268669082926E-7| -|1970-01-01T08:00:00.003+08:00| -7.057291240286645E-8| 5.127422242345858E-8| -|1970-01-01T08:00:00.004+08:00| 19.021130288047125| -6.180339875198807| -|1970-01-01T08:00:00.005+08:00| 9.999999850988388| 3.501852745067114E-16| -|1970-01-01T08:00:00.019+08:00| -3.932894898639461E-9|-1.2104202549376264E-8| -+-----------------------------+----------------------+----------------------+ -``` - - -用于查询的SQL语句: - -```sql -select ifft(re, im, 'interval'='1m', 'start'='2021-01-01 00:00:00') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------------+ -| Time|ifft(root.test.d1.re, root.test.d1.im, "interval"="1m",| -| | "start"="2021-01-01 00:00:00")| -+-----------------------------+-------------------------------------------------------+ -|2021-01-01T00:00:00.000+08:00| 2.902112992431231| -|2021-01-01T00:01:00.000+08:00| 1.1755704705132448| -|2021-01-01T00:02:00.000+08:00| -2.175570513757101| -|2021-01-01T00:03:00.000+08:00| -1.9021130389094498| -|2021-01-01T00:04:00.000+08:00| 0.9999999925494194| -|2021-01-01T00:05:00.000+08:00| 1.902113046743454| -|2021-01-01T00:06:00.000+08:00| 0.17557053610884188| -|2021-01-01T00:07:00.000+08:00| -1.1755704886020932| -|2021-01-01T00:08:00.000+08:00| -0.9021130371347148| -|2021-01-01T00:09:00.000+08:00| 3.552713678800501E-16| -|2021-01-01T00:10:00.000+08:00| 0.9021130371347154| -|2021-01-01T00:11:00.000+08:00| 1.1755704886020932| -|2021-01-01T00:12:00.000+08:00| -0.17557053610884144| -|2021-01-01T00:13:00.000+08:00| -1.902113046743454| -|2021-01-01T00:14:00.000+08:00| -0.9999999925494196| -|2021-01-01T00:15:00.000+08:00| 1.9021130389094498| -|2021-01-01T00:16:00.000+08:00| 2.1755705137571004| -|2021-01-01T00:17:00.000+08:00| -1.1755704705132448| -|2021-01-01T00:18:00.000+08:00| -2.902112992431231| -|2021-01-01T00:19:00.000+08:00| -3.552713678800501E-16| -+-----------------------------+-------------------------------------------------------+ -``` - -### LowPass - -#### 注册语句 - -```sql -create function lowpass as 'org.apache.iotdb.library.frequency.UDTFLowPass' -``` - -#### 函数简介 - -本函数对输入序列进行低通滤波,提取低于截止频率的分量。输入序列的时间戳将被忽略,所有数据点都将被视作等距的。 - -**函数名:** LOWPASS - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `wpass`:归一化后的截止频率,取值为(0,1),不可缺省。 - -**输出序列:** 输出单个序列,类型为DOUBLE,它是滤波后的序列,长度与时间戳均与输入一致。 - -**提示:** 输入序列中的`NaN`将被忽略。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:00.000+08:00| 2.902113| -|1970-01-01T08:00:01.000+08:00| 1.1755705| -|1970-01-01T08:00:02.000+08:00| -2.1755705| -|1970-01-01T08:00:03.000+08:00| -1.9021131| -|1970-01-01T08:00:04.000+08:00| 1.0| -|1970-01-01T08:00:05.000+08:00| 1.9021131| -|1970-01-01T08:00:06.000+08:00| 0.1755705| -|1970-01-01T08:00:07.000+08:00| -1.1755705| -|1970-01-01T08:00:08.000+08:00| -0.902113| -|1970-01-01T08:00:09.000+08:00| 0.0| -|1970-01-01T08:00:10.000+08:00| 0.902113| -|1970-01-01T08:00:11.000+08:00| 1.1755705| -|1970-01-01T08:00:12.000+08:00| -0.1755705| -|1970-01-01T08:00:13.000+08:00| -1.9021131| -|1970-01-01T08:00:14.000+08:00| -1.0| -|1970-01-01T08:00:15.000+08:00| 1.9021131| -|1970-01-01T08:00:16.000+08:00| 2.1755705| -|1970-01-01T08:00:17.000+08:00| -1.1755705| -|1970-01-01T08:00:18.000+08:00| -2.902113| -|1970-01-01T08:00:19.000+08:00| 0.0| -+-----------------------------+---------------+ -``` - - -用于查询的SQL语句: - -```sql -select lowpass(s1,'wpass'='0.45') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------+ -| Time|lowpass(root.test.d1.s1, "wpass"="0.45")| -+-----------------------------+----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 1.9021130073323922| -|1970-01-01T08:00:01.000+08:00| 1.1755704705132448| -|1970-01-01T08:00:02.000+08:00| -1.1755705286582614| -|1970-01-01T08:00:03.000+08:00| -1.9021130389094498| -|1970-01-01T08:00:04.000+08:00| 7.450580419288145E-9| -|1970-01-01T08:00:05.000+08:00| 1.902113046743454| -|1970-01-01T08:00:06.000+08:00| 1.1755705212076808| -|1970-01-01T08:00:07.000+08:00| -1.1755704886020932| -|1970-01-01T08:00:08.000+08:00| -1.9021130222335536| -|1970-01-01T08:00:09.000+08:00| 3.552713678800501E-16| -|1970-01-01T08:00:10.000+08:00| 1.9021130222335536| -|1970-01-01T08:00:11.000+08:00| 1.1755704886020932| -|1970-01-01T08:00:12.000+08:00| -1.1755705212076801| -|1970-01-01T08:00:13.000+08:00| -1.902113046743454| -|1970-01-01T08:00:14.000+08:00| -7.45058112983088E-9| -|1970-01-01T08:00:15.000+08:00| 1.9021130389094498| -|1970-01-01T08:00:16.000+08:00| 1.1755705286582616| -|1970-01-01T08:00:17.000+08:00| -1.1755704705132448| -|1970-01-01T08:00:18.000+08:00| -1.9021130073323924| -|1970-01-01T08:00:19.000+08:00| -2.664535259100376E-16| -+-----------------------------+----------------------------------------+ -``` -## Envelope - -### 函数简介 - -本函数通过输入一维浮点数数组和用户指定的调制频率,实现对信号的解调和包络提取。解调的目标是从复杂的信号中提取感兴趣的部分,使其更易理解。比如通过解调可以找到信号的包络,即振幅的变化趋势。 - -**函数名:** Envelope - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `frequency`:频率(选填,正数。不填此参数,系统会基于序列对应时间的时间间隔来推断频率)。 -+ `amplification`: 扩增倍数(选填,正整数。输出Time列的结果为正整数的集合,不会输出小数。当频率小1时,可通过此参数对频率进行扩增以展示正常的结果)。 - -**输出序列:** -+ `Time`: 该列返回的值的含义是频率而并非时间,如果输出的格式为时间格式(如:1970-01-01T08:00:19.000+08:00),请将其转为时间戳值。 - -+ `Envelope(Path, 'frequency'='{frequency}')`:输出单个序列,类型为DOUBLE,它是包络分析之后的结果。 - -**提示:** 当解调的原始序列的值不连续时,本函数会视为连续处理,建议被分析的时间序列是一段值完整的时间序列。同时建议指定开始时间与结束时间。 - -### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s1| -+-----------------------------+---------------+ -|1970-01-01T08:00:01.000+08:00| 1.0 | -|1970-01-01T08:00:02.000+08:00| 2.0 | -|1970-01-01T08:00:03.000+08:00| 3.0 | -|1970-01-01T08:00:04.000+08:00| 4.0 | -|1970-01-01T08:00:05.000+08:00| 5.0 | -|1970-01-01T08:00:06.000+08:00| 6.0 | -|1970-01-01T08:00:07.000+08:00| 7.0 | -|1970-01-01T08:00:08.000+08:00| 8.0 | -|1970-01-01T08:00:09.000+08:00| 9.0 | -|1970-01-01T08:00:10.000+08:00| 10.0 | -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: -```sql -set time_display_type=long; -select envelope(s1),envelope(s1,'frequency'='1000'),envelope(s1,'amplification'='10') from root.test.d1; -``` -输出序列: - -``` -+----+-------------------------+---------------------------------------------+-----------------------------------------------+ -|Time|envelope(root.test.d1.s1)|envelope(root.test.d1.s1, "frequency"="1000")|envelope(root.test.d1.s1, "amplification"="10")| -+----+-------------------------+---------------------------------------------+-----------------------------------------------+ -| 0| 6.284350808484124| 6.284350808484124| 6.284350808484124| -| 100| 1.5581923657404393| 1.5581923657404393| null| -| 200| 0.8503211038340728| 0.8503211038340728| null| -| 300| 0.512808785945551| 0.512808785945551| null| -| 400| 0.26361156774506744| 0.26361156774506744| null| -|1000| null| null| 1.5581923657404393| -|2000| null| null| 0.8503211038340728| -|3000| null| null| 0.512808785945551| -|4000| null| null| 0.26361156774506744| -+----+-------------------------+---------------------------------------------+-----------------------------------------------+ - -``` - -注:输入序列服从$y=sin(2\pi t/4)+2sin(2\pi t/5)$,长度为20,因此低通滤波之后的输出序列服从$y=2sin(2\pi t/5)$。 - - - -## 数据匹配 - -### Cov - -#### 注册语句 - -```sql -create function cov as 'org.apache.iotdb.library.dmatch.UDAFCov' -``` - -#### 函数简介 - -本函数用于计算两列数值型数据的总体协方差。 - -**函数名:** COV - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列仅包含一个时间戳为 0、值为总体协方差的数据点。 - -**提示:** - -+ 如果某行数据中包含空值、缺失值或`NaN`,该行数据将会被忽略; -+ 如果数据中所有的行都被忽略,函数将会输出`NaN`。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| 101.0| -|2020-01-01T00:00:03.000+08:00| 101.0| null| -|2020-01-01T00:00:04.000+08:00| 102.0| 101.0| -|2020-01-01T00:00:06.000+08:00| 104.0| 102.0| -|2020-01-01T00:00:08.000+08:00| 126.0| 102.0| -|2020-01-01T00:00:10.000+08:00| 108.0| 103.0| -|2020-01-01T00:00:12.000+08:00| null| 103.0| -|2020-01-01T00:00:14.000+08:00| 112.0| 104.0| -|2020-01-01T00:00:15.000+08:00| 113.0| null| -|2020-01-01T00:00:16.000+08:00| 114.0| 104.0| -|2020-01-01T00:00:18.000+08:00| 116.0| 105.0| -|2020-01-01T00:00:20.000+08:00| 118.0| 105.0| -|2020-01-01T00:00:22.000+08:00| 100.0| 106.0| -|2020-01-01T00:00:26.000+08:00| 124.0| 108.0| -|2020-01-01T00:00:28.000+08:00| 126.0| 108.0| -|2020-01-01T00:00:30.000+08:00| NaN| 108.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select cov(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|cov(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 12.291666666666666| -+-----------------------------+-------------------------------------+ -``` - -### Dtw - -#### 注册语句 - -```sql -create function dtw as 'org.apache.iotdb.library.dmatch.UDAFDtw' -``` - -#### 函数简介 - -本函数用于计算两列数值型数据的 DTW 距离。 - -**函数名:** DTW - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列仅包含一个时间戳为 0、值为两个时间序列的 DTW 距离值。 - -**提示:** - -+ 如果某行数据中包含空值、缺失值或`NaN`,该行数据将会被忽略; -+ 如果数据中所有的行都被忽略,函数将会输出 0。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|1970-01-01T08:00:00.001+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.002+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.003+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.004+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.005+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.006+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.007+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.008+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.009+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.010+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.011+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.012+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.013+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.014+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.015+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.016+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.017+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.018+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.019+08:00| 1.0| 2.0| -|1970-01-01T08:00:00.020+08:00| 1.0| 2.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select dtw(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------+ -| Time|dtw(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+-------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 20.0| -+-----------------------------+-------------------------------------+ -``` - -### Pearson - -#### 注册语句 - -```sql -create function pearson as 'org.apache.iotdb.library.dmatch.UDAFPearson' -``` - -#### 函数简介 - -本函数用于计算两列数值型数据的皮尔森相关系数。 - -**函数名:** PEARSON - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列仅包含一个时间戳为 0、值为皮尔森相关系数的数据点。 - -**提示:** - -+ 如果某行数据中包含空值、缺失值或`NaN`,该行数据将会被忽略; -+ 如果数据中所有的行都被忽略,函数将会输出`NaN`。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d2.s1|root.test.d2.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| 101.0| -|2020-01-01T00:00:03.000+08:00| 101.0| null| -|2020-01-01T00:00:04.000+08:00| 102.0| 101.0| -|2020-01-01T00:00:06.000+08:00| 104.0| 102.0| -|2020-01-01T00:00:08.000+08:00| 126.0| 102.0| -|2020-01-01T00:00:10.000+08:00| 108.0| 103.0| -|2020-01-01T00:00:12.000+08:00| null| 103.0| -|2020-01-01T00:00:14.000+08:00| 112.0| 104.0| -|2020-01-01T00:00:15.000+08:00| 113.0| null| -|2020-01-01T00:00:16.000+08:00| 114.0| 104.0| -|2020-01-01T00:00:18.000+08:00| 116.0| 105.0| -|2020-01-01T00:00:20.000+08:00| 118.0| 105.0| -|2020-01-01T00:00:22.000+08:00| 100.0| 106.0| -|2020-01-01T00:00:26.000+08:00| 124.0| 108.0| -|2020-01-01T00:00:28.000+08:00| 126.0| 108.0| -|2020-01-01T00:00:30.000+08:00| NaN| 108.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select pearson(s1,s2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------+ -| Time|pearson(root.test.d2.s1, root.test.d2.s2)| -+-----------------------------+-----------------------------------------+ -|1970-01-01T08:00:00.000+08:00| 0.5630881927754872| -+-----------------------------+-----------------------------------------+ -``` - -### PtnSym - -#### 注册语句 - -```sql -create function ptnsym as 'org.apache.iotdb.library.dmatch.UDTFPtnSym' -``` - -#### 函数简介 - -本函数用于寻找序列中所有对称度小于阈值的对称子序列。对称度通过 DTW 计算,值越小代表序列对称性越高。 - -**函数名:** PTNSYM - -**输入序列:** 仅支持一个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `window`:对称子序列的长度,是一个正整数,默认值为 10。 -+ `threshold`:对称度阈值,是一个非负数,只有对称度小于等于该值的对称子序列才会被输出。在缺省情况下,所有的子序列都会被输出。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列中的每一个数据点对应于一个对称子序列,时间戳为子序列的起始时刻,值为对称度。 - - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d1.s4| -+-----------------------------+---------------+ -|2021-01-01T12:00:00.000+08:00| 1.0| -|2021-01-01T12:00:01.000+08:00| 2.0| -|2021-01-01T12:00:02.000+08:00| 3.0| -|2021-01-01T12:00:03.000+08:00| 2.0| -|2021-01-01T12:00:04.000+08:00| 1.0| -|2021-01-01T12:00:05.000+08:00| 1.0| -|2021-01-01T12:00:06.000+08:00| 1.0| -|2021-01-01T12:00:07.000+08:00| 1.0| -|2021-01-01T12:00:08.000+08:00| 2.0| -|2021-01-01T12:00:09.000+08:00| 3.0| -|2021-01-01T12:00:10.000+08:00| 2.0| -|2021-01-01T12:00:11.000+08:00| 1.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select ptnsym(s4, 'window'='5', 'threshold'='0') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|ptnsym(root.test.d1.s4, "window"="5", "threshold"="0")| -+-----------------------------+------------------------------------------------------+ -|2021-01-01T12:00:00.000+08:00| 0.0| -|2021-01-01T12:00:07.000+08:00| 0.0| -+-----------------------------+------------------------------------------------------+ -``` - -### XCorr - -#### 注册语句 - -```sql -create function xcorr as 'org.apache.iotdb.library.dmatch.UDTFXCorr' -``` - -#### 函数简介 - -本函数用于计算两条时间序列的互相关函数值, -对离散序列而言,互相关函数可以表示为 -$$CR(n) = \frac{1}{N} \sum_{m=1}^N S_1[m]S_2[m+n]$$ -常用于表征两条序列在不同对齐条件下的相似度。 - -**函数名:** XCORR - -**输入序列:** 仅支持两个输入序列,类型均为 INT32 / INT64 / FLOAT / DOUBLE。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。序列中共包含$2N-1$个数据点, -其中正中心的值为两条序列按照预先对齐的结果计算的互相关系数(即等于以上公式的$CR(0)$), -前半部分的值表示将后一条输入序列向前平移时计算的互相关系数, -直至两条序列没有重合的数据点(不包含完全分离时的结果$CR(-N)=0.0$), -后半部分类似。 -用公式可表示为(所有序列的索引从1开始计数): -$$OS[i] = CR(-N+i) = \frac{1}{N} \sum_{m=1}^{i} S_1[m]S_2[N-i+m],\ if\ i <= N$$ -$$OS[i] = CR(i-N) = \frac{1}{N} \sum_{m=1}^{2N-i} S_1[i-N+m]S_2[m],\ if\ i > N$$ - -**提示:** - -+ 两条序列中的`null` 和`NaN` 值会被忽略,在计算中表现为 0。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:01.000+08:00| null| 6| -|2020-01-01T00:00:02.000+08:00| 2| 7| -|2020-01-01T00:00:03.000+08:00| 3| NaN| -|2020-01-01T00:00:04.000+08:00| 4| 9| -|2020-01-01T00:00:05.000+08:00| 5| 10| -+-----------------------------+---------------+---------------+ -``` - - -用于查询的 SQL 语句: - -```sql -select xcorr(s1, s2) from root.test.d1 where time <= 2020-01-01 00:00:05 -``` - -输出序列: - -``` -+-----------------------------+---------------------------------------+ -| Time|xcorr(root.test.d1.s1, root.test.d1.s2)| -+-----------------------------+---------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 0.0| -|1970-01-01T08:00:00.002+08:00| 4.0| -|1970-01-01T08:00:00.003+08:00| 9.6| -|1970-01-01T08:00:00.004+08:00| 13.4| -|1970-01-01T08:00:00.005+08:00| 20.0| -|1970-01-01T08:00:00.006+08:00| 15.6| -|1970-01-01T08:00:00.007+08:00| 9.2| -|1970-01-01T08:00:00.008+08:00| 11.8| -|1970-01-01T08:00:00.009+08:00| 6.0| -+-----------------------------+---------------------------------------+ -``` - - - -## 数据修复 - -### TimestampRepair - -#### 注册语句 - -```sql -create function timestamprepair as 'org.apache.iotdb.library.drepair.UDTFTimestampRepair' -``` - -### 函数简介 - -本函数用于时间戳修复。根据给定的标准时间间隔,采用最小化修复代价的方法,通过对数据时间戳的微调,将原本时间戳间隔不稳定的数据修复为严格等间隔的数据。在未给定标准时间间隔的情况下,本函数将使用时间间隔的中位数 (median)、众数 (mode) 或聚类中心 (cluster) 来推算标准时间间隔。 - - -**函数名:** TIMESTAMPREPAIR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `interval`: 标准时间间隔(单位是毫秒),是一个正整数。在缺省情况下,将根据指定的方法推算。 -+ `method`:推算标准时间间隔的方法,取值为 'median', 'mode' 或 'cluster',仅在`interval`缺省时有效。在缺省情况下,将使用中位数方法进行推算。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列是修复后的输入序列。 - -### 使用示例 - -#### 指定标准时间间隔 - -在给定`interval`参数的情况下,本函数将按照指定的标准时间间隔进行修复。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2021-07-01T12:00:00.000+08:00| 1.0| -|2021-07-01T12:00:10.000+08:00| 2.0| -|2021-07-01T12:00:19.000+08:00| 3.0| -|2021-07-01T12:00:30.000+08:00| 4.0| -|2021-07-01T12:00:40.000+08:00| 5.0| -|2021-07-01T12:00:50.000+08:00| 6.0| -|2021-07-01T12:01:01.000+08:00| 7.0| -|2021-07-01T12:01:11.000+08:00| 8.0| -|2021-07-01T12:01:21.000+08:00| 9.0| -|2021-07-01T12:01:31.000+08:00| 10.0| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select timestamprepair(s1,'interval'='10000') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+----------------------------------------------------+ -| Time|timestamprepair(root.test.d2.s1, "interval"="10000")| -+-----------------------------+----------------------------------------------------+ -|2021-07-01T12:00:00.000+08:00| 1.0| -|2021-07-01T12:00:10.000+08:00| 2.0| -|2021-07-01T12:00:20.000+08:00| 3.0| -|2021-07-01T12:00:30.000+08:00| 4.0| -|2021-07-01T12:00:40.000+08:00| 5.0| -|2021-07-01T12:00:50.000+08:00| 6.0| -|2021-07-01T12:01:00.000+08:00| 7.0| -|2021-07-01T12:01:10.000+08:00| 8.0| -|2021-07-01T12:01:20.000+08:00| 9.0| -|2021-07-01T12:01:30.000+08:00| 10.0| -+-----------------------------+----------------------------------------------------+ -``` - -#### 自动推算标准时间间隔 - -如果`interval`参数没有给定,本函数将按照推算的标准时间间隔进行修复。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select timestamprepair(s1) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------+ -| Time|timestamprepair(root.test.d2.s1)| -+-----------------------------+--------------------------------+ -|2021-07-01T12:00:00.000+08:00| 1.0| -|2021-07-01T12:00:10.000+08:00| 2.0| -|2021-07-01T12:00:20.000+08:00| 3.0| -|2021-07-01T12:00:30.000+08:00| 4.0| -|2021-07-01T12:00:40.000+08:00| 5.0| -|2021-07-01T12:00:50.000+08:00| 6.0| -|2021-07-01T12:01:00.000+08:00| 7.0| -|2021-07-01T12:01:10.000+08:00| 8.0| -|2021-07-01T12:01:20.000+08:00| 9.0| -|2021-07-01T12:01:30.000+08:00| 10.0| -+-----------------------------+--------------------------------+ -``` - -### ValueFill - -#### 注册语句 - -```sql -create function valuefill as 'org.apache.iotdb.library.drepair.UDTFValueFill' -``` - -#### 函数简介 - -**函数名:** ValueFill - -**输入序列:** 单列时序数据,类型为INT32 / INT64 / FLOAT / DOUBLE - -**参数:** - -+ `method`: {"mean", "previous", "linear", "likelihood", "AR", "MA", "SCREEN"}, 默认为 "linear"。其中,“mean” 指使用均值填补的方法; “previous" 指使用前值填补方法;“linear" 指使用线性插值填补方法;“likelihood” 为基于速度的正态分布的极大似然估计方法;“AR” 指自回归的填补方法;“MA” 指滑动平均的填补方法;"SCREEN" 指约束填补方法;缺省情况下使用 “linear”。 - -**输出序列:** 填补后的单维序列。 - -**备注:** AR 模型采用 AR(1),时序列需满足自相关条件,否则将输出单个数据点 (0, 0.0). - -#### 使用示例 -##### 使用 linear 方法进行填补 - -当`method`缺省或取值为 'linear' 时,本函数将使用线性插值方法进行填补。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| NaN| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| NaN| -|2020-01-01T00:00:22.000+08:00| NaN| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select valuefill(s1) from root.test.d2 -``` - -输出序列: - - - -``` -+-----------------------------+-----------------------+ -| Time|valuefill(root.test.d2)| -+-----------------------------+-----------------------+ -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 108.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.7| -|2020-01-01T00:00:22.000+08:00| 121.3| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+-----------------------+ -``` - -##### 使用 previous 方法进行填补 - -当`method`取值为 'previous' 时,本函数将使前值填补方法进行数值填补。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select valuefill(s1,"method"="previous") from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------+ -| Time|valuefill(root.test.d2,"method"="previous")| -+-----------------------------+-------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| NaN| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 110.5| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 116.0| -|2020-01-01T00:00:22.000+08:00| 116.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+-------------------------------------------+ -``` - -### ValueRepair - -#### 注册语句 - -```sql -create function valuerepair as 'org.apache.iotdb.library.drepair.UDTFValueRepair' -``` - -#### 函数简介 - -本函数用于对时间序列的数值进行修复。目前,本函数支持两种修复方法:**Screen** 是一种基于速度阈值的方法,在最小改动的前提下使得所有的速度符合阈值要求;**LsGreedy** 是一种基于速度变化似然的方法,将速度变化建模为高斯分布,并采用贪心算法极大化似然函数。 - -**函数名:** VALUEREPAIR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `method`:修复时采用的方法,取值为 'Screen' 或 'LsGreedy'. 在缺省情况下,使用 Screen 方法进行修复。 -+ `minSpeed`:该参数仅在使用 Screen 方法时有效。当速度小于该值时会被视作数值异常点加以修复。在缺省情况下为中位数减去三倍绝对中位差。 -+ `maxSpeed`:该参数仅在使用 Screen 方法时有效。当速度大于该值时会被视作数值异常点加以修复。在缺省情况下为中位数加上三倍绝对中位差。 -+ `center`:该参数仅在使用 LsGreedy 方法时有效。对速度变化分布建立的高斯模型的中心。在缺省情况下为 0。 -+ `sigma` :该参数仅在使用 LsGreedy 方法时有效。对速度变化分布建立的高斯模型的标准差。在缺省情况下为绝对中位差。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列是修复后的输入序列。 - -**提示:** 输入序列中的`NaN`在修复之前会先进行线性插值填补。 - -#### 使用示例 - -##### 使用 Screen 方法进行修复 - -当`method`缺省或取值为 'Screen' 时,本函数将使用 Screen 方法进行数值修复。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 126.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 100.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| NaN| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select valuerepair(s1) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+----------------------------+ -| Time|valuerepair(root.test.d2.s1)| -+-----------------------------+----------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 106.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+----------------------------+ -``` - -##### 使用 LsGreedy 方法进行修复 - -当`method`取值为 'LsGreedy' 时,本函数将使用 LsGreedy 方法进行数值修复。 - -输入序列同上,用于查询的 SQL 语句如下: - -```sql -select valuerepair(s1,'method'='LsGreedy') from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------+ -| Time|valuerepair(root.test.d2.s1, "method"="LsGreedy")| -+-----------------------------+-------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:03.000+08:00| 101.0| -|2020-01-01T00:00:04.000+08:00| 102.0| -|2020-01-01T00:00:06.000+08:00| 104.0| -|2020-01-01T00:00:08.000+08:00| 106.0| -|2020-01-01T00:00:10.000+08:00| 108.0| -|2020-01-01T00:00:14.000+08:00| 112.0| -|2020-01-01T00:00:15.000+08:00| 113.0| -|2020-01-01T00:00:16.000+08:00| 114.0| -|2020-01-01T00:00:18.000+08:00| 116.0| -|2020-01-01T00:00:20.000+08:00| 118.0| -|2020-01-01T00:00:22.000+08:00| 120.0| -|2020-01-01T00:00:26.000+08:00| 124.0| -|2020-01-01T00:00:28.000+08:00| 126.0| -|2020-01-01T00:00:30.000+08:00| 128.0| -+-----------------------------+-------------------------------------------------+ -``` - -### MasterRepair - -#### 函数简介 - -本函数实现基于主数据的时间序列数据修复。 - -**函数名:**MasterRepair - -**输入序列:** 支持多个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `omega`:算法窗口大小,非负整数(单位为毫秒), 在缺省情况下,算法根据不同时间差下的两个元组距离自动估计该参数。 -- `eta`:算法距离阈值,正数, 在缺省情况下,算法根据窗口中元组的距离分布自动估计该参数。 -- `k`:主数据中的近邻数量,正整数, 在缺省情况下,算法根据主数据中的k个近邻的元组距离自动估计该参数。 -- `output_column`:输出列的序号,默认输出第一列的修复结果。 - -**输出序列:**输出单个序列,类型与输入数据中对应列的类型相同,序列为输入列修复后的结果。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+------------+------------+------------+------------+------------+------------+ -| Time|root.test.t1|root.test.t2|root.test.t3|root.test.m1|root.test.m2|root.test.m3| -+-----------------------------+------------+------------+------------+------------+------------+------------+ -|2021-07-01T12:00:01.000+08:00| 1704| 1154.55| 0.195| 1704| 1154.55| 0.195| -|2021-07-01T12:00:02.000+08:00| 1702| 1152.30| 0.193| 1702| 1152.30| 0.193| -|2021-07-01T12:00:03.000+08:00| 1702| 1148.65| 0.192| 1702| 1148.65| 0.192| -|2021-07-01T12:00:04.000+08:00| 1701| 1145.20| 0.194| 1701| 1145.20| 0.194| -|2021-07-01T12:00:07.000+08:00| 1703| 1150.55| 0.195| 1703| 1150.55| 0.195| -|2021-07-01T12:00:08.000+08:00| 1694| 1151.55| 0.193| 1704| 1151.55| 0.193| -|2021-07-01T12:01:09.000+08:00| 1705| 1153.55| 0.194| 1705| 1153.55| 0.194| -|2021-07-01T12:01:10.000+08:00| 1706| 1152.30| 0.190| 1706| 1152.30| 0.190| -+-----------------------------+------------+------------+------------+------------+------------+------------+ -``` - -用于查询的 SQL 语句: - -```sql -select MasterRepair(t1,t2,t3,m1,m2,m3) from root.test -``` - -输出序列: - - -``` -+-----------------------------+-------------------------------------------------------------------------------------------+ -| Time|MasterRepair(root.test.t1,root.test.t2,root.test.t3,root.test.m1,root.test.m2,root.test.m3)| -+-----------------------------+-------------------------------------------------------------------------------------------+ -|2021-07-01T12:00:01.000+08:00| 1704| -|2021-07-01T12:00:02.000+08:00| 1702| -|2021-07-01T12:00:03.000+08:00| 1702| -|2021-07-01T12:00:04.000+08:00| 1701| -|2021-07-01T12:00:07.000+08:00| 1703| -|2021-07-01T12:00:08.000+08:00| 1704| -|2021-07-01T12:01:09.000+08:00| 1705| -|2021-07-01T12:01:10.000+08:00| 1706| -+-----------------------------+-------------------------------------------------------------------------------------------+ -``` - -### SeasonalRepair - -#### 函数简介 -本函数用于对周期性时间序列的数值进行基于分解的修复。目前,本函数支持两种方法:**Classical**使用经典分解方法得到的残差项检测数值的异常波动,并使用滑动平均修复序列;**Improved**使用改进的分解方法得到的残差项检测数值的异常波动,并使用滑动中值修复序列。 - -**函数名:** SEASONALREPAIR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -+ `method`:修复时采用的分解方法,取值为'Classical'或'Improved'。在缺省情况下,使用经典分解方法进行修复。 -+ `period`:序列的周期。 -+ `k`:残差项的范围阈值,用来限制残差项偏离中心的程度。在缺省情况下为9。 -+ `max_iter`:算法的最大迭代次数。在缺省情况下为10。 - -**输出序列:** 输出单个序列,类型与输入序列相同。该序列是修复后的输入序列。 - -**提示:** 输入序列中的`NaN`在修复之前会先进行线性插值填补。 - -#### 使用示例 -##### 使用经典分解方法进行修复 -当`method`缺省或取值为'Classical'时,本函数将使用经典分解方法进行数值修复。 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d2.s1| -+-----------------------------+---------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:04.000+08:00| 120.0| -|2020-01-01T00:00:06.000+08:00| 80.0| -|2020-01-01T00:00:08.000+08:00| 100.5| -|2020-01-01T00:00:10.000+08:00| 119.5| -|2020-01-01T00:00:12.000+08:00| 101.0| -|2020-01-01T00:00:14.000+08:00| 99.5| -|2020-01-01T00:00:16.000+08:00| 119.0| -|2020-01-01T00:00:18.000+08:00| 80.5| -|2020-01-01T00:00:20.000+08:00| 99.0| -|2020-01-01T00:00:22.000+08:00| 121.0| -|2020-01-01T00:00:24.000+08:00| 79.5| -+-----------------------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select seasonalrepair(s1,'period'=3,'k'=2) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------+ -| Time|seasonalrepair(root.test.d2.s1, 'period'=4, 'k'=2)| -+-----------------------------+--------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:04.000+08:00| 120.0| -|2020-01-01T00:00:06.000+08:00| 80.0| -|2020-01-01T00:00:08.000+08:00| 100.5| -|2020-01-01T00:00:10.000+08:00| 119.5| -|2020-01-01T00:00:12.000+08:00| 87.0| -|2020-01-01T00:00:14.000+08:00| 99.5| -|2020-01-01T00:00:16.000+08:00| 119.0| -|2020-01-01T00:00:18.000+08:00| 80.5| -|2020-01-01T00:00:20.000+08:00| 99.0| -|2020-01-01T00:00:22.000+08:00| 121.0| -|2020-01-01T00:00:24.000+08:00| 79.5| -+-----------------------------+--------------------------------------------------+ -``` - -##### 使用改进的分解方法进行修复 -当`method`取值为'Improved'时,本函数将使用改进的分解方法进行数值修复。 - -输入序列同上,用于查询的SQL语句如下: - -```sql -select seasonalrepair(s1,'method'='improved','period'=3) from root.test.d2 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------------------+ -| Time|valuerepair(root.test.d2.s1, 'method'='improved', 'period'=3)| -+-----------------------------+-------------------------------------------------------------+ -|2020-01-01T00:00:02.000+08:00| 100.0| -|2020-01-01T00:00:04.000+08:00| 120.0| -|2020-01-01T00:00:06.000+08:00| 80.0| -|2020-01-01T00:00:08.000+08:00| 100.5| -|2020-01-01T00:00:10.000+08:00| 119.5| -|2020-01-01T00:00:12.000+08:00| 81.5| -|2020-01-01T00:00:14.000+08:00| 99.5| -|2020-01-01T00:00:16.000+08:00| 119.0| -|2020-01-01T00:00:18.000+08:00| 80.5| -|2020-01-01T00:00:20.000+08:00| 99.0| -|2020-01-01T00:00:22.000+08:00| 121.0| -|2020-01-01T00:00:24.000+08:00| 79.5| -+-----------------------------+-------------------------------------------------------------+ -``` - - - -## 序列发现 - -### ConsecutiveSequences - -#### 注册语句 - -```sql -create function consecutivesequences as 'org.apache.iotdb.library.series.UDTFConsecutiveSequences' -``` - -#### 函数简介 - -本函数用于在多维严格等间隔数据中发现局部最长连续子序列。 - -严格等间隔数据是指数据的时间间隔是严格相等的,允许存在数据缺失(包括行缺失和值缺失),但不允许存在数据冗余和时间戳偏移。 - -连续子序列是指严格按照标准时间间隔等距排布,不存在任何数据缺失的子序列。如果某个连续子序列不是任何连续子序列的真子序列,那么它是局部最长的。 - - -**函数名:** CONSECUTIVESEQUENCES - -**输入序列:** 支持多个输入序列,类型可以是任意的,但要满足严格等间隔的要求。 - -**参数:** - -+ `gap`:标准时间间隔,是一个有单位的正数。目前支持五种单位,分别是'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。在缺省情况下,函数会利用众数估计标准时间间隔。 - -**输出序列:** 输出单个序列,类型为 INT32。输出序列中的每一个数据点对应一个局部最长连续子序列,时间戳为子序列的起始时刻,值为子序列包含的数据点个数。 - -**提示:** 对于不符合要求的输入,本函数不对输出做任何保证。 - -#### 使用示例 - -##### 手动指定标准时间间隔 - -本函数可以通过`gap`参数手动指定标准时间间隔。需要注意的是,错误的参数设置会导致输出产生严重错误。 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:05:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:10:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:20:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:25:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:30:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:35:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:40:00.000+08:00| 1.0| null| -|2020-01-01T00:45:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:50:00.000+08:00| 1.0| 1.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consecutivesequences(s1,s2,'gap'='5m') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------------------+ -| Time|consecutivesequences(root.test.d1.s1, root.test.d1.s2, "gap"="5m")| -+-----------------------------+------------------------------------------------------------------+ -|2020-01-01T00:00:00.000+08:00| 3| -|2020-01-01T00:20:00.000+08:00| 4| -|2020-01-01T00:45:00.000+08:00| 2| -+-----------------------------+------------------------------------------------------------------+ -``` - -##### 自动估计标准时间间隔 - -当`gap`参数缺省时,本函数可以利用众数估计标准时间间隔,得到同样的结果。因此,这种用法更受推荐。 - -输入序列同上,用于查询的SQL语句如下: - -```sql -select consecutivesequences(s1,s2) from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+------------------------------------------------------+ -| Time|consecutivesequences(root.test.d1.s1, root.test.d1.s2)| -+-----------------------------+------------------------------------------------------+ -|2020-01-01T00:00:00.000+08:00| 3| -|2020-01-01T00:20:00.000+08:00| 4| -|2020-01-01T00:45:00.000+08:00| 2| -+-----------------------------+------------------------------------------------------+ -``` - -### ConsecutiveWindows - -#### 注册语句 - -```sql -create function consecutivewindows as 'org.apache.iotdb.library.series.UDTFConsecutiveWindows' -``` - -#### 函数简介 - -本函数用于在多维严格等间隔数据中发现指定长度的连续窗口。 - -严格等间隔数据是指数据的时间间隔是严格相等的,允许存在数据缺失(包括行缺失和值缺失),但不允许存在数据冗余和时间戳偏移。 - -连续窗口是指严格按照标准时间间隔等距排布,不存在任何数据缺失的子序列。 - - -**函数名:** CONSECUTIVEWINDOWS - -**输入序列:** 支持多个输入序列,类型可以是任意的,但要满足严格等间隔的要求。 - -**参数:** - -+ `gap`:标准时间间隔,是一个有单位的正数。目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。在缺省情况下,函数会利用众数估计标准时间间隔。 -+ `length`:序列长度,是一个有单位的正数。目前支持五种单位,分别是 'ms'(毫秒)、's'(秒)、'm'(分钟)、'h'(小时)和'd'(天)。该参数不允许缺省。 - -**输出序列:** 输出单个序列,类型为 INT32。输出序列中的每一个数据点对应一个指定长度连续子序列,时间戳为子序列的起始时刻,值为子序列包含的数据点个数。 - -**提示:** 对于不符合要求的输入,本函数不对输出做任何保证。 - -#### 使用示例 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d1.s1|root.test.d1.s2| -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:05:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:10:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:20:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:25:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:30:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:35:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:40:00.000+08:00| 1.0| null| -|2020-01-01T00:45:00.000+08:00| 1.0| 1.0| -|2020-01-01T00:50:00.000+08:00| 1.0| 1.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的SQL语句: - -```sql -select consecutivewindows(s1,s2,'length'='10m') from root.test.d1 -``` - -输出序列: - -``` -+-----------------------------+--------------------------------------------------------------------+ -| Time|consecutivewindows(root.test.d1.s1, root.test.d1.s2, "length"="10m")| -+-----------------------------+--------------------------------------------------------------------+ -|2020-01-01T00:00:00.000+08:00| 3| -|2020-01-01T00:20:00.000+08:00| 3| -|2020-01-01T00:25:00.000+08:00| 3| -+-----------------------------+--------------------------------------------------------------------+ -``` - - - -## 机器学习 - -### AR - -#### 注册语句 - -```sql -create function ar as 'org.apache.iotdb.library.dlearn.UDTFAR' -``` -#### 函数简介 - -本函数用于学习数据的自回归模型系数。 - -**函数名:** AR - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `p`:自回归模型的阶数。默认为1。 - -**输出序列:** 输出单个序列,类型为 DOUBLE。第一行对应模型的一阶系数,以此类推。 - -**提示:** - -- `p`应为正整数。 - -- 序列中的大部分点为等间隔采样点。 -- 序列中的缺失点通过线性插值进行填补后用于学习过程。 - -#### 使用示例 - -##### 指定阶数 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d0.s0| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| -4.0| -|2020-01-01T00:00:02.000+08:00| -3.0| -|2020-01-01T00:00:03.000+08:00| -2.0| -|2020-01-01T00:00:04.000+08:00| -1.0| -|2020-01-01T00:00:05.000+08:00| 0.0| -|2020-01-01T00:00:06.000+08:00| 1.0| -|2020-01-01T00:00:07.000+08:00| 2.0| -|2020-01-01T00:00:08.000+08:00| 3.0| -|2020-01-01T00:00:09.000+08:00| 4.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select ar(s0,"p"="2") from root.test.d0 -``` - -输出序列: - -``` -+-----------------------------+---------------------------+ -| Time|ar(root.test.d0.s0,"p"="2")| -+-----------------------------+---------------------------+ -|1970-01-01T08:00:00.001+08:00| 0.9429| -|1970-01-01T08:00:00.002+08:00| -0.2571| -+-----------------------------+---------------------------+ -``` - -### Representation - -#### 函数简介 - -本函数用于时间序列的表示。 - -**函数名:** Representation - -**输入序列:** 仅支持单个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `tb`:时间分块数量。默认为10。 -- `vb`:值分块数量。默认为10。 - -**输出序列:** 输出单个序列,类型为INT32,长度为`tb*vb`。序列的时间戳从0开始,仅用于表示顺序。 - -**提示:** - -- `tb `,`vb`应为正整数。 - -#### 使用示例 - -##### 指定时间分块数量、值分块数量 - -输入序列: - -``` -+-----------------------------+---------------+ -| Time|root.test.d0.s0| -+-----------------------------+---------------+ -|2020-01-01T00:00:01.000+08:00| -4.0| -|2020-01-01T00:00:02.000+08:00| -3.0| -|2020-01-01T00:00:03.000+08:00| -2.0| -|2020-01-01T00:00:04.000+08:00| -1.0| -|2020-01-01T00:00:05.000+08:00| 0.0| -|2020-01-01T00:00:06.000+08:00| 1.0| -|2020-01-01T00:00:07.000+08:00| 2.0| -|2020-01-01T00:00:08.000+08:00| 3.0| -|2020-01-01T00:00:09.000+08:00| 4.0| -+-----------------------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select representation(s0,"tb"="3","vb"="2") from root.test.d0 -``` - -输出序列: - -``` -+-----------------------------+-------------------------------------------------+ -| Time|representation(root.test.d0.s0,"tb"="3","vb"="2")| -+-----------------------------+-------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1| -|1970-01-01T08:00:00.002+08:00| 1| -|1970-01-01T08:00:00.003+08:00| 0| -|1970-01-01T08:00:00.004+08:00| 0| -|1970-01-01T08:00:00.005+08:00| 1| -|1970-01-01T08:00:00.006+08:00| 1| -+-----------------------------+-------------------------------------------------+ -``` - -### RM - -#### 函数简介 - -本函数用于基于时间序列表示的匹配度。 - -**函数名:** RM - -**输入序列:** 仅支持两个输入序列,类型为 INT32 / INT64 / FLOAT / DOUBLE。 - -**参数:** - -- `tb`:时间分块数量。默认为10。 -- `vb`:值分块数量。默认为10。 - -**输出序列:** 输出单个序列,类型为DOUBLE,长度为`1`。序列的时间戳从0开始,序列仅有一个数据点,其时间戳为0,值为两个时间序列的匹配度。 - -**提示:** - -- `tb `,`vb`应为正整数。 - -#### 使用示例 - -##### 指定时间分块数量、值分块数量 - -输入序列: - -``` -+-----------------------------+---------------+---------------+ -| Time|root.test.d0.s0|root.test.d0.s1 -+-----------------------------+---------------+---------------+ -|2020-01-01T00:00:01.000+08:00| -4.0| -4.0| -|2020-01-01T00:00:02.000+08:00| -3.0| -3.0| -|2020-01-01T00:00:03.000+08:00| -3.0| -3.0| -|2020-01-01T00:00:04.000+08:00| -1.0| -1.0| -|2020-01-01T00:00:05.000+08:00| 0.0| 0.0| -|2020-01-01T00:00:06.000+08:00| 1.0| 1.0| -|2020-01-01T00:00:07.000+08:00| 2.0| 2.0| -|2020-01-01T00:00:08.000+08:00| 3.0| 3.0| -|2020-01-01T00:00:09.000+08:00| 4.0| 4.0| -+-----------------------------+---------------+---------------+ -``` - -用于查询的 SQL 语句: - -```sql -select rm(s0, s1,"tb"="3","vb"="2") from root.test.d0 -``` - -输出序列: - -``` -+-----------------------------+-----------------------------------------------------+ -| Time|rm(root.test.d0.s0,root.test.d0.s1,"tb"="3","vb"="2")| -+-----------------------------+-----------------------------------------------------+ -|1970-01-01T08:00:00.001+08:00| 1.00| -+-----------------------------+-----------------------------------------------------+ -``` - diff --git a/src/zh/UserGuide/V1.3.3/Technical-Insider/Cluster-data-partitioning.md b/src/zh/UserGuide/V1.3.3/Technical-Insider/Cluster-data-partitioning.md deleted file mode 100644 index 119e003a0..000000000 --- a/src/zh/UserGuide/V1.3.3/Technical-Insider/Cluster-data-partitioning.md +++ /dev/null @@ -1,110 +0,0 @@ - - -# 负载均衡 -本文档介绍 IoTDB 中的分区策略和负载均衡策略。根据时序数据的特性,IoTDB 按序列和时间维度对其进行分区。结合序列分区与时间分区创建一个分区,作为划分的基本单元。为了提高吞吐量并降低管理成本,这些分区被均匀分配到分片(Region)中,分片是复制的基本单元。分片的副本决定了数据的存储位置,主副本负责主要负载的管理。在此过程中,副本放置算法决定哪些节点将持有分片副本,而主副本选择算法则指定哪个副本将成为主副本。 - -## 分区策略和分区分配 -IoTDB 为时间序列数据实现了量身定制的分区算法。在此基础上,缓存于配置节点和数据节点上的分区信息不仅易于管理,而且能够清晰区分冷热数据。随后,平衡的分区被均匀分配到集群的分片中,以实现存储均衡。 - -### 分区策略 -IoTDB 将生产环境中的每个传感器映射为一个时间序列。然后,使用序列分区算法对时间序列进行分区以管理其元数据,再结合时间分区算法来管理其数据。下图展示了 IoTDB 如何对时序数据进行分区。 - - - -#### 分区算法 -由于生产环境中通常部署大量设备和传感器,IoTDB 使用序列分区算法以确保分区信息的大小可控。由于生成的时间序列与时间戳相关联,IoTDB 使用时间分区算法来清晰区分冷热分区。 - -##### 序列分区算法 -默认情况下,IoTDB 将序列分区的数量限制为 1000,并将序列分区算法配置为哈希分区算法。这带来以下收益: -+ 由于序列分区的数量是固定常量,序列与序列分区之间的映射保持稳定。因此,IoTDB 不需要频繁进行数据迁移。 -+ 序列分区的负载相对均衡,因为序列分区的数量远小于生产环境中部署的传感器数量。 - -更进一步,如果能够更准确地估计生产环境中的实际负载情况,序列分区算法可以配置为自定义的哈希分区或列表分区,以在所有序列分区中实现更均匀的负载分布。 - -##### 时间分区算法 -时间分区算法通过下式将给定的时间戳转换为相应的时间分区 - -$$\left\lfloor\frac{\text{Timestamp}-\text{StartTimestamp}}{\text{TimePartitionInterval}}\right\rfloor\text{。}$$ - -在此式中,$\text{StartTimestamp}$ 和 $\text{TimePartitionInterval}$ 都是可配置参数,以适应不同的生产环境。$\text{StartTimestamp}$ 表示第一个时间分区的起始时间,而 $\text{TimePartitionInterval}$ 定义了每个时间分区的持续时间。默认情况下,$\text{TimePartitionInterval}$ 设置为七天。 - -#### 元数据分区 -由于序列分区算法对时间序列进行了均匀分区,每个序列分区对应一个元数据分区。这些元数据分区随后被均匀分配到 元数据分片 中,以实现元数据的均衡分布。 - -#### 数据分区 -结合序列分区与时间分区创建数据分区。由于序列分区算法对时间序列进行了均匀分区,特定时间分区内的数据分区负载保持均衡。这些数据分区随后被均匀分配到数据分片中,以实现数据的均衡分布。 - -### 分区分配 -IoTDB 使用分片来实现时间序列的弹性存储,集群中分片的数量由所有数据节点的总资源决定。由于分片的数量是动态的,IoTDB 可以轻松扩展。元数据分片和数据分片都遵循相同的分区分配算法,即均匀划分所有序列分区。下图展示了分区分配过程,其中动态扩展的分片匹配不断扩展的时间序列和集群。 - - - -#### 分片扩容 -分片的数量由下式给出 - -$$\text{RegionGroupNumber}=\left\lfloor\frac{\sum_{i=1}^{DataNodeNumber}\text{RegionNumber}_i}{\text{ReplicationFactor}}\right\rfloor\text{。}$$ - -在此式中,$\text{RegionNumber}_i$ 表示期望在第 $i$ 个数据节点上放置的副本数量,而 $\text{ReplicationFactor}$ 表示每个分片中的副本数量。$\text{RegionNumber}_i$ 和 $\text{ReplicationFactor}$ 都是可配置的参数。$\text{RegionNumber}_i$ 可以根据第 $i$ 个数据节点上的可用硬件资源(如 CPU 核心数量、内存大小等)确定,以适应不同的物理服务器。$\text{ReplicationFactor}$ 可以调整以确保不同级别的容错能力。 - -#### 分配策略 -元数据分片和数据分片都遵循相同的分配策略,即均匀划分所有序列分区。因此,每个元数据分片持有相同数量的元数据分区,以确保元数据存储均衡。同样,对于每个时间分区,每个数据分片 获取与其持有的序列分区对应的数据分区。因此,时间分区内的数据分区均匀分布在所有数据分片中,确保每个时间分区内的数据存储均衡。 - -值得注意的是,IoTDB 有效利用了时序数据的特性。当配置了 TTL(生存时间)时,IoTDB 可实现无需迁移的时序数据弹性存储,该功能在集群扩展时最小化了对在线操作的影响。上图展示了该功能的一个实例:新生成的数据分区被均匀分配到每个数据分片,过期数据会自动归档。因此,集群的存储最终将保持平衡。 - -## 均衡策略 -为了提高集群的可用性和性能,IoTDB 采用了精心设计的存储均衡和计算均衡算法。 - -### 存储均衡 -数据节点持有的副本数量反映了它的存储负载。如果数据节点之间的副本数量差异较大,拥有更多副本的数据节点可能成为存储瓶颈。尽管简单的轮询(Round Robin)放置算法可以通过确保每个数据节点持有等量副本来实现存储均衡,但它会降低集群的容错能力,如下所示: - - - -+ 假设集群有 4 个数据节点,4 个分片,并且副本因子为 2。 -+ 将分片 $r_1$ 的 2 个副本放置在数据节点 $n_1$ 和 $n_2$ 上。 -+ 将分片 $r_2$ 的 2 个副本放置在数据节点 $n_3$ 和 $n_4$ 上。 -+ 将分片 $r_3$ 的 2 个副本放置在数据节点 $n_1$ 和 $n_3$ 上。 -+ 将分片 $r_4$ 的 2 个副本放置在数据节点 $n_2$ 和 $n_4$ 上。 - -在这种情况下,如果数据节点 $n_2$ 发生故障,由它先前负责的负载将只能全部转移到数据节点 $n_1$,可能导致其过载。 - -为了解决这个问题,IoTDB 采用了一种副本放置算法,该算法不仅将副本均匀放置到所有数据节点上,还确保每个 数据节点在发生故障时,能够将其负载转移到足够多的其他数据节点。因此,集群实现了存储分布的均衡,并具备较高的容错能力,从而确保其可用性。 - -### 计算均衡 -数据节点持有的主副本数量反映了它的计算负载。如果数据节点之间持有主副本数量差异较大,拥有更多主副本的数据节点可能成为计算瓶颈。如果主副本选择过程使用直观的贪心算法,当副本以容错算法放置时,可能会导致主副本分布不均,如下所示: - - - -+ 假设集群有 4 个数据节点,4 个分片,并且副本因子为 2。 -+ 选择分片 $r_5$ 在数据节点 $n_5$ 上的副本作为主副本。 -+ 选择分片 $r_6$ 在数据节点 $n_7$ 上的副本作为主副本。 -+ 选择分片 $r_7$ 在数据节点 $n_7$ 上的副本作为主副本。 -+ 选择分片 $r_8$ 在数据节点 $n_8$ 上的副本作为主副本。 - -请注意,以上步骤严格遵循贪心算法。然而,到第 3 步时,无论在数据节点 $n_5$ 或 $n_7$ 上选择分片 $r_7$ 的主副本,都会导致主副本分布不均衡。根本原因在于每一步贪心选择都缺乏全局视角,最终导致局部最优解。 - -为了解决这个问题,IoTDB 采用了一种主副本选择算法,能够持续平衡集群中的主副本分布。因此,集群实现了计算负载的均衡分布,确保了其性能。 - -## Source Code -+ [数据分区](https://github.com/apache/iotdb/tree/master/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition) -+ [分区分配](https://github.com/apache/iotdb/tree/master/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/partition) -+ [副本放置](https://github.com/apache/iotdb/tree/master/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/副本) -+ [主副本选择](https://github.com/apache/iotdb/tree/master/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/router/主副本) \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/User-Manual/AINode_timecho.md b/src/zh/UserGuide/V1.3.3/User-Manual/AINode_timecho.md deleted file mode 100644 index 594236294..000000000 --- a/src/zh/UserGuide/V1.3.3/User-Manual/AINode_timecho.md +++ /dev/null @@ -1,650 +0,0 @@ - - -# AI能力(AINode) - -AINode 是 IoTDB 在ConfigNode、DataNode后提供的第三种内生节点,该节点通过与 IoTDB 集群的 DataNode、ConfigNode 的交互,扩展了对时间序列进行机器学习分析的能力,支持从外部引入已有机器学习模型进行注册,并使用注册的模型在指定时序数据上通过简单 SQL 语句完成时序分析任务的过程,将模型的创建、管理及推理融合在数据库引擎中。目前已提供常见时序分析场景(例如预测与异常检测)的机器学习算法或自研模型。 - -系统架构如下图所示: -::: center - -::: -三种节点的职责如下: - -- **ConfigNode**:负责保存和管理模型的元信息;负责分布式节点管理。 -- **DataNode**:负责接收并解析用户的 SQL请求;负责存储时间序列数据;负责数据的预处理计算。 -- **AINode**:负责模型文件的导入创建以及模型推理。 - -## 优势特点 - -与单独构建机器学习服务相比,具有以下优势: - -- **简单易用**:无需使用 Python 或 Java 编程,使用 SQL 语句即可完成机器学习模型管理与推理的完整流程。如创建模型可使用CREATE MODEL语句、使用模型进行推理可使用CALL INFERENCE(...)语句等,使用更加简单便捷。 - -- **避免数据迁移**:使用 IoTDB 原生机器学习可以将存储在 IoTDB 中的数据直接应用于机器学习模型的推理,无需将数据移动到单独的机器学习服务平台,从而加速数据处理、提高安全性并降低成本。 - -![](/img/h1.png) - -- **内置先进算法**:支持业内领先机器学习分析算法,覆盖典型时序分析任务,为时序数据库赋能原生数据分析能力。如: - - **时间序列预测(Time Series Forecasting)**:从过去时间序列中学习变化模式;从而根据给定过去时间的观测值,输出未来序列最可能的预测。 - - **时序异常检测(Anomaly Detection for Time Series)**:在给定的时间序列数据中检测和识别异常值,帮助发现时间序列中的异常行为。 - - **时间序列标注(Time Series Annotation)**:为每个数据点或特定时间段添加额外的信息或标记,例如事件发生、异常点、趋势变化等,以便更好地理解和分析数据。 - - -## 基本概念 - -- **模型(Model)**:机器学习模型,以时序数据作为输入,输出分析任务的结果或决策。模型是AINode 的基本管理单元,支持模型的增(注册)、删、查、用(推理)。 -- **创建(Create)**: 将外部设计或训练好的模型文件或算法加载到MLNode中,由IoTDB统一管理与使用。 -- **推理(Inference)**:使用创建的模型在指定时序数据上完成该模型适用的时序分析任务的过程。 -- **内置能力(Built-in)**:AINode 自带常见时序分析场景(例如预测与异常检测)的机器学习算法或自研模型。 - -::: center - -::: - -## 安装部署 - -AINode 的部署可参考文档 [部署指导](../Deployment-and-Maintenance/AINode_Deployment_timecho.md#AINode-部署) 章节。 - -## 使用指导 - -AINode 对时序数据相关的深度学习模型提供了模型创建及删除的流程,内置模型无需创建及删除,可直接使用,并且在完成推理后创建的内置模型实例将自动销毁。 - -### 注册模型 - -通过指定模型输入输出的向量维度,可以注册训练好的深度学习模型,从而用于模型推理。 - -符合以下内容的模型可以注册到AINode中: - 1. AINode 支持的PyTorch 2.1.0、 2.2.0版本训练的模型,需避免使用2.2.0版本以上的特性。 - 2. AINode支持使用PyTorch JIT存储的模型,模型文件需要包含模型的参数和结构。 - 3. 模型输入序列可以包含一列或多列,若有多列,需要和模型能力、模型配置文件对应。 - 4. 模型的输入输出维度必须在`config.yaml`配置文件中明确定义。使用模型时,必须严格按照`config.yaml`配置文件中定义的输入输出维度。如果输入输出列数不匹配配置文件,将会导致错误。 - -下方为模型注册的SQL语法定义。 - -```SQL -create model using uri -``` - -SQL中参数的具体含义如下: - -- model_name:模型的全局唯一标识,不可重复。模型名称具备以下约束: - - - 允许出现标识符 [ 0-9 a-z A-Z _ ] (字母,数字,下划线) - - 长度限制为2-64字符 - - 大小写敏感 - -- uri:模型注册文件的资源路径,路径下应包含**模型权重model.pt文件和模型的元数据描述文件config.yaml** - - - 模型权重文件:深度学习模型训练完成后得到的权重文件,目前支持pytorch训练得到的.pt文件 - - - yaml元数据描述文件:模型注册时需要提供的与模型结构有关的参数,其中必须包含模型的输入输出维度用于模型推理: - - - | **参数名** | **参数描述** | **示例** | - | ------------ | ---------------------------- | -------- | - | input_shape | 模型输入的行列,用于模型推理 | [96,2] | - | output_shape | 模型输出的行列,用于模型推理 | [48,2] | - - - ​ 除了模型推理外,还可以指定模型输入输出的数据类型: - - - | **参数名** | **参数描述** | **示例** | - | ----------- | ------------------ | --------------------- | - | input_type | 模型输入的数据类型 | ['float32','float32'] | - | output_type | 模型输出的数据类型 | ['float32','float32'] | - - - ​ 除此之外,可以额外指定备注信息用于在模型管理时进行展示 - - - | **参数名** | **参数描述** | **示例** | - | ---------- | ---------------------------------------------- | ------------------------------------------- | - | attributes | 可选,用户自行设定的模型备注信息,用于模型展示 | 'model_type': 'dlinear','kernel_size': '25' | - - -除了本地模型文件的注册,还可以通过URI来指定远程资源路径来进行注册,使用开源的模型仓库(例如HuggingFace)。 - -#### 示例 - -在当前的example文件夹下,包含model.pt和config.yaml文件,model.pt为训练得到,config.yaml的内容如下: - -```YAML -configs: - # 必选项 - input_shape: [96, 2] # 表示模型接收的数据为96行x2列 - output_shape: [48, 2] # 表示模型输出的数据为48行x2列 - - # 可选项 默认为全部float32,列数为shape对应的列数 - input_type: ["int64","int64"] #输入对应的数据类型,需要与输入列数匹配 - output_type: ["text","int64"] #输出对应的数据类型,需要与输出列数匹配 - -attributes: # 可选项 为用户自定义的备注信息 - 'model_type': 'dlinear' - 'kernel_size': '25' -``` - -指定该文件夹作为加载路径就可以注册该模型 - -```SQL -IoTDB> create model dlinear_example using uri "file://./example" -``` - -也可以从huggingFace上下载对应的模型文件进行注册 - -```SQL -IoTDB> create model dlinear_example using uri "https://huggingface.com/IoTDBML/dlinear/" -``` - -SQL执行后会异步进行注册的流程,可以通过模型展示查看模型的注册状态(见模型展示章节),注册成功的耗时主要受到模型文件大小的影响。 - -模型注册完成后,就可以通过使用正常查询的方式调用具体函数,进行模型推理。 - -### 查看模型 - -注册成功的模型可以通过show models指令查询模型的具体信息。其SQL定义如下: - -```SQL -show models - -show models -``` - -除了直接展示所有模型的信息外,可以指定model id来查看某一具体模型的信息。模型展示的结果中包含如下信息: - -| **ModelId** | **State** | **Configs** | **Attributes** | -| ------------ | ------------------------------------- | ---------------------------------------------- | -------------- | -| 模型唯一标识 | 模型注册状态(LOADING,ACTIVE,DROPPING) | InputShape, outputShapeInputTypes, outputTypes | 模型备注信息 | - -其中,State用于展示当前模型注册的状态,包含以下三个阶段 - -- **LOADING**:已经在configNode中添加对应的模型元信息,正将模型文件传输到AINode节点上 -- **ACTIVE:** 模型已经设置完成,模型处于可用状态 -- **DROPPING**:模型删除中,正在从configNode以及AINode处删除模型相关信息 -- **UNAVAILABLE**: 模型创建失败,可以通过drop model删除创建失败的model_name。 - -#### 示例 - -```SQL -IoTDB> show models - - -+---------------------+--------------------------+-----------+----------------------------+-----------------------+ -| ModelId| ModelType| State| Configs| Notes| -+---------------------+--------------------------+-----------+----------------------------+-----------------------+ -| dlinear_example| USER_DEFINED| ACTIVE| inputShape:[96,2]| | -| | | | outputShape:[48,2]| | -| | | | inputDataType:[float,float]| | -| | | |outputDataType:[float,float]| | -| _STLForecaster| BUILT_IN_FORECAST| ACTIVE| |Built-in model in IoTDB| -| _NaiveForecaster| BUILT_IN_FORECAST| ACTIVE| |Built-in model in IoTDB| -| _ARIMA| BUILT_IN_FORECAST| ACTIVE| |Built-in model in IoTDB| -|_ExponentialSmoothing| BUILT_IN_FORECAST| ACTIVE| |Built-in model in IoTDB| -| _GaussianHMM|BUILT_IN_ANOMALY_DETECTION| ACTIVE| |Built-in model in IoTDB| -| _GMMHMM|BUILT_IN_ANOMALY_DETECTION| ACTIVE| |Built-in model in IoTDB| -| _Stray|BUILT_IN_ANOMALY_DETECTION| ACTIVE| |Built-in model in IoTDB| -+---------------------+--------------------------+-----------+------------------------------------------------------------+-----------------------+ -``` - -我们前面已经注册了对应的模型,可以通过对应的指定查看模型状态,active表明模型注册成功,可用于推理。 - -### 删除模型 - -对于注册成功的模型,用户可以通过SQL进行删除。该操作除了删除configNode上的元信息外,还会删除所有AINode下的相关模型文件。其SQL如下: - -```SQL -drop model -``` - -需要指定已经成功注册的模型model_name来删除对应的模型。由于模型删除涉及多个节点上的数据删除,操作不会立即完成,此时模型的状态为DROPPING,该状态的模型不能用于模型推理。 - -### 使用内置模型推理 - -SQL语法如下: - - -```SQL -call inference(,sql[,=]) -``` - -内置模型推理无需注册流程,通过call关键字,调用inference函数就可以使用模型的推理功能,其对应的参数介绍如下: - -- **built_in_model_name:** 内置模型名称 -- **parameterName**:参数名 -- **parameterValue**:参数值 - -#### 内置模型及参数说明 - -目前已内置如下机器学习模型,具体参数说明请参考以下链接。 - -| 模型 | built_in_model_name | 任务类型 | 参数说明 | -| -------------------- | --------------------- | -------- | ------------------------------------------------------------ | -| Arima | _Arima | 预测 | [Arima参数说明](https://www.sktime.net/en/latest/api_reference/auto_generated/sktime.forecasting.arima.ARIMA.html?highlight=Arima) | -| STLForecaster | _STLForecaster | 预测 | [STLForecaster参数说明](https://www.sktime.net/en/latest/api_reference/auto_generated/sktime.forecasting.trend.STLForecaster.html#sktime.forecasting.trend.STLForecaster) | -| NaiveForecaster | _NaiveForecaster | 预测 | [NaiveForecaster参数说明](https://www.sktime.net/en/latest/api_reference/auto_generated/sktime.forecasting.naive.NaiveForecaster.html#naiveforecaster) | -| ExponentialSmoothing | _ExponentialSmoothing | 预测 | [ExponentialSmoothing参数说明](https://www.sktime.net/en/latest/api_reference/auto_generated/sktime.forecasting.exp_smoothing.ExponentialSmoothing.html) | -| GaussianHMM | _GaussianHMM | 标注 | [GaussianHMM参数说明](https://www.sktime.net/en/latest/api_reference/auto_generated/sktime.annotation.hmm_learn.gaussian.GaussianHMM.html) | -| GMMHMM | _GMMHMM | 标注 | [GMMHMM参数说明](https://www.sktime.net/en/latest/api_reference/auto_generated/sktime.annotation.hmm_learn.gmm.GMMHMM.html) | -| Stray | _Stray | 异常检测 | [Stray参数说明](https://www.sktime.net/en/latest/api_reference/auto_generated/sktime.annotation.stray.STRAY.html) | - -#### 示例 - -下面是使用内置模型推理的一个操作示例,使用内置的Stray模型进行异常检测算法,输入为`[144,1]`,输出为`[144,1]`,我们通过SQL使用其进行推理。 - -```SQL -IoTDB> select * from root.eg.airline -+-----------------------------+------------------+ -| Time|root.eg.airline.s0| -+-----------------------------+------------------+ -|1949-01-31T00:00:00.000+08:00| 224.0| -|1949-02-28T00:00:00.000+08:00| 118.0| -|1949-03-31T00:00:00.000+08:00| 132.0| -|1949-04-30T00:00:00.000+08:00| 129.0| -...... -|1960-09-30T00:00:00.000+08:00| 508.0| -|1960-10-31T00:00:00.000+08:00| 461.0| -|1960-11-30T00:00:00.000+08:00| 390.0| -|1960-12-31T00:00:00.000+08:00| 432.0| -+-----------------------------+------------------+ -Total line number = 144 - -IoTDB> call inference(_Stray, "select s0 from root.eg.airline", k=2) -+-------+ -|output0| -+-------+ -| 0| -| 0| -| 0| -| 0| -...... -| 1| -| 1| -| 0| -| 0| -| 0| -| 0| -+-------+ -Total line number = 144 -``` - -### 使用深度学习模型推理 - -SQL语法如下: - -```SQL -call inference(,sql[,window=]) - - -window_function: - head(window_size) - tail(window_size) - count(window_size,sliding_step) -``` - -在完成模型的注册后,通过call关键字,调用inference函数就可以使用模型的推理功能,其对应的参数介绍如下: - -- **model_name**: 对应一个已经注册的模型 -- **sql**:sql查询语句,查询的结果作为模型的输入进行模型推理。查询的结果中行列的维度需要与具体模型config中指定的大小相匹配。(这里的sql不建议使用`SELECT *`子句,因为在IoTDB中,`*`并不会对列进行排序,因此列的顺序是未定义的,可以使用`SELECT s0,s1`的方式确保列的顺序符合模型输入的预期) -- **window_function**: 推理过程中可以使用的窗口函数,目前提供三种类型的窗口函数用于辅助模型推理: - - **head(window_size)**: 获取数据中最前的window_size个点用于模型推理,该窗口可用于数据裁剪 - ![](/img/AINode-call1.png) - - - **tail(window_size)**:获取数据中最后的window_size个点用于模型推,该窗口可用于数据裁剪 - ![](/img/AINode-call2.png) - - - **count(window_size, sliding_step)**:基于点数的滑动窗口,每个窗口的数据会分别通过模型进行推理,如下图示例所示,window_size为2的窗口函数将输入数据集分为三个窗口,每个窗口分别进行推理运算生成结果。该窗口可用于连续推理 - ![](/img/AINode-call3.png) - -**说明1: window可以用来解决sql查询结果和模型的输入行数要求不一致时的问题,对行进行裁剪。需要注意的是,当列数不匹配或是行数直接少于模型需求时,推理无法进行,会返回错误信息。** - -**说明2: 在深度学习应用中,经常将时间戳衍生特征(数据中的时间列)作为生成式任务的协变量,一同输入到模型中以提升模型的效果,但是在模型的输出结果中一般不包含时间列。为了保证实现的通用性,模型推理结果只对应模型的真实输出,如果模型不输出时间列,则结果中不会包含。** - - -#### 示例 - -下面是使用深度学习模型推理的一个操作示例,针对上面提到的输入为`[96,2]`,输出为`[48,2]`的`dlinear`预测模型,我们通过SQL使用其进行推理。 - -```Shell -IoTDB> select s1,s2 from root.** -+-----------------------------+-------------------+-------------------+ -| Time| root.eg.etth.s0| root.eg.etth.s1| -+-----------------------------+-------------------+-------------------+ -|1990-01-01T00:00:00.000+08:00| 0.7855| 1.611| -|1990-01-02T00:00:00.000+08:00| 0.7818| 1.61| -|1990-01-03T00:00:00.000+08:00| 0.7867| 1.6293| -|1990-01-04T00:00:00.000+08:00| 0.786| 1.637| -|1990-01-05T00:00:00.000+08:00| 0.7849| 1.653| -|1990-01-06T00:00:00.000+08:00| 0.7866| 1.6537| -|1990-01-07T00:00:00.000+08:00| 0.7886| 1.662| -...... -|1990-03-31T00:00:00.000+08:00| 0.7585| 1.678| -|1990-04-01T00:00:00.000+08:00| 0.7587| 1.6763| -|1990-04-02T00:00:00.000+08:00| 0.76| 1.6813| -|1990-04-03T00:00:00.000+08:00| 0.7669| 1.684| -|1990-04-04T00:00:00.000+08:00| 0.7645| 1.677| -|1990-04-05T00:00:00.000+08:00| 0.7625| 1.68| -|1990-04-06T00:00:00.000+08:00| 0.7617| 1.6917| -+-----------------------------+-------------------+-------------------+ -Total line number = 96 - -IoTDB> call inference(dlinear_example,"select s0,s1 from root.**") -+--------------------------------------------+-----------------------------+ -| _result_0| _result_1| -+--------------------------------------------+-----------------------------+ -| 0.726302981376648| 1.6549958229064941| -| 0.7354921698570251| 1.6482787370681763| -| 0.7238251566886902| 1.6278168201446533| -...... -| 0.7692174911499023| 1.654654049873352| -| 0.7685555815696716| 1.6625318765640259| -| 0.7856493592262268| 1.6508299350738525| -+--------------------------------------------+-----------------------------+ -Total line number = 48 -``` - -#### 使用tail/head窗口函数的示例 - -当数据量不定且想要取96行最新数据用于推理时,可以使用对应的窗口函数tail。head函数的用法与其类似,不同点在于其取的是最早的96个点。 - -```Shell -IoTDB> select s1,s2 from root.** -+-----------------------------+-------------------+-------------------+ -| Time| root.eg.etth.s0| root.eg.etth.s1| -+-----------------------------+-------------------+-------------------+ -|1988-01-01T00:00:00.000+08:00| 0.7355| 1.211| -...... -|1990-01-01T00:00:00.000+08:00| 0.7855| 1.611| -|1990-01-02T00:00:00.000+08:00| 0.7818| 1.61| -|1990-01-03T00:00:00.000+08:00| 0.7867| 1.6293| -|1990-01-04T00:00:00.000+08:00| 0.786| 1.637| -|1990-01-05T00:00:00.000+08:00| 0.7849| 1.653| -|1990-01-06T00:00:00.000+08:00| 0.7866| 1.6537| -|1990-01-07T00:00:00.000+08:00| 0.7886| 1.662| -...... -|1990-03-31T00:00:00.000+08:00| 0.7585| 1.678| -|1990-04-01T00:00:00.000+08:00| 0.7587| 1.6763| -|1990-04-02T00:00:00.000+08:00| 0.76| 1.6813| -|1990-04-03T00:00:00.000+08:00| 0.7669| 1.684| -|1990-04-04T00:00:00.000+08:00| 0.7645| 1.677| -|1990-04-05T00:00:00.000+08:00| 0.7625| 1.68| -|1990-04-06T00:00:00.000+08:00| 0.7617| 1.6917| -+-----------------------------+-------------------+-------------------+ -Total line number = 996 - -IoTDB> call inference(dlinear_example,"select s0,s1 from root.**",window=tail(96)) -+--------------------------------------------+-----------------------------+ -| _result_0| _result_1| -+--------------------------------------------+-----------------------------+ -| 0.726302981376648| 1.6549958229064941| -| 0.7354921698570251| 1.6482787370681763| -| 0.7238251566886902| 1.6278168201446533| -...... -| 0.7692174911499023| 1.654654049873352| -| 0.7685555815696716| 1.6625318765640259| -| 0.7856493592262268| 1.6508299350738525| -+--------------------------------------------+-----------------------------+ -Total line number = 48 -``` - -#### 使用count窗口函数的示例 - -该窗口主要用于计算式任务,当任务对应的模型一次只能处理固定行数据而最终想要的确实多组预测结果时,使用该窗口函数可以使用点数滑动窗口进行连续推理。假设我们现在有一个异常检测模型anomaly_example(input: [24,2], output[1,1]),对每24行数据会生成一个0/1的标签,其使用示例如下: - -```Shell -IoTDB> select s1,s2 from root.** -+-----------------------------+-------------------+-------------------+ -| Time| root.eg.etth.s0| root.eg.etth.s1| -+-----------------------------+-------------------+-------------------+ -|1990-01-01T00:00:00.000+08:00| 0.7855| 1.611| -|1990-01-02T00:00:00.000+08:00| 0.7818| 1.61| -|1990-01-03T00:00:00.000+08:00| 0.7867| 1.6293| -|1990-01-04T00:00:00.000+08:00| 0.786| 1.637| -|1990-01-05T00:00:00.000+08:00| 0.7849| 1.653| -|1990-01-06T00:00:00.000+08:00| 0.7866| 1.6537| -|1990-01-07T00:00:00.000+08:00| 0.7886| 1.662| -...... -|1990-03-31T00:00:00.000+08:00| 0.7585| 1.678| -|1990-04-01T00:00:00.000+08:00| 0.7587| 1.6763| -|1990-04-02T00:00:00.000+08:00| 0.76| 1.6813| -|1990-04-03T00:00:00.000+08:00| 0.7669| 1.684| -|1990-04-04T00:00:00.000+08:00| 0.7645| 1.677| -|1990-04-05T00:00:00.000+08:00| 0.7625| 1.68| -|1990-04-06T00:00:00.000+08:00| 0.7617| 1.6917| -+-----------------------------+-------------------+-------------------+ -Total line number = 96 - -IoTDB> call inference(anomaly_example,"select s0,s1 from root.**",window=count(24,24)) -+-------------------------+ -| _result_0| -+-------------------------+ -| 0| -| 1| -| 1| -| 0| -+-------------------------+ -Total line number = 4 -``` - -其中结果集中每行的标签对应每24行数据为一组,输入该异常检测模型后的输出。 - -## 权限管理 - -使用AINode相关的功能时,可以使用IoTDB本身的鉴权去做一个权限管理,用户只有在具备 USE_MODEL 权限时,才可以使用模型管理的相关功能。当使用推理功能时,用户需要有访问输入模型的SQL对应的源序列的权限。 - -| 权限名称 | 权限范围 | 管理员用户(默认ROOT) | 普通用户 | 路径相关 | -| --------- | --------------------------------- | ---------------------- | -------- | -------- | -| USE_MODEL | create model / show models / drop model | √ | √ | x | -| READ_DATA | call inference | √ | √ | √ | - -## 实际案例 - -### 电力负载预测 - -在部分工业场景下,会存在预测电力负载的需求,预测结果可用于优化电力供应、节约能源和资源、支持规划和扩展以及增强电力系统的可靠性。 - -我们所使用的 ETTh1 的测试集的数据为[ETTh1](/img/ETTh1.csv)。 - - -包含间隔1h采集一次的电力数据,每条数据由负载和油温构成,分别为:High UseFul Load, High UseLess Load, Middle UseLess Load, Low UseFul Load, Low UseLess Load, Oil Temperature。 - -在该数据集上,IoTDB-ML的模型推理功能可以通过以往高中低三种负载的数值和对应时间戳油温的关系,预测未来一段时间内的油温,赋能电网变压器的自动调控和监视。 - -#### 步骤一:数据导入 - -用户可以使用tools文件夹中的`import-csv.sh` 向 IoTDB 中导入 ETT 数据集 - -```Bash -bash ./import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f ../../ETTh1.csv -``` - -#### 步骤二:模型导入 - -我们可以在iotdb-cli 中输入以下SQL从 huggingface 上拉取一个已经训练好的模型进行注册,用于后续的推理。 - -```SQL -create model dlinear using uri 'https://huggingface.co/hvlgo/dlinear/tree/main' -``` - -该模型基于较为轻量化的深度模型DLinear训练而得,能够以相对快的推理速度尽可能多地捕捉到序列内部的变化趋势和变量间的数据变化关系,相较于其他更深的模型更适用于快速实时预测。 - -#### 步骤三:模型推理 - -```Shell -IoTDB> select s0,s1,s2,s3,s4,s5,s6 from root.eg.etth LIMIT 96 -+-----------------------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+ -| Time|root.eg.etth.s0|root.eg.etth.s1|root.eg.etth.s2|root.eg.etth.s3|root.eg.etth.s4|root.eg.etth.s5|root.eg.etth.s6| -+-----------------------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+ -|2017-10-20T00:00:00.000+08:00| 10.449| 3.885| 8.706| 2.025| 2.041| 0.944| 8.864| -|2017-10-20T01:00:00.000+08:00| 11.119| 3.952| 8.813| 2.31| 2.071| 1.005| 8.442| -|2017-10-20T02:00:00.000+08:00| 9.511| 2.88| 7.533| 1.564| 1.949| 0.883| 8.16| -|2017-10-20T03:00:00.000+08:00| 9.645| 2.21| 7.249| 1.066| 1.828| 0.914| 7.949| -...... -|2017-10-23T20:00:00.000+08:00| 8.105| 0.938| 4.371| -0.569| 3.533| 1.279| 9.708| -|2017-10-23T21:00:00.000+08:00| 7.167| 1.206| 4.087| -0.462| 3.107| 1.432| 8.723| -|2017-10-23T22:00:00.000+08:00| 7.1| 1.34| 4.015| -0.32| 2.772| 1.31| 8.864| -|2017-10-23T23:00:00.000+08:00| 9.176| 2.746| 7.107| 1.635| 2.65| 1.097| 9.004| -+-----------------------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+ -Total line number = 96 - -IoTDB> call inference(dlinear_example, "select s0,s1,s2,s3,s4,s5,s6 from root.eg.etth", window=head(96)) -+-----------+----------+----------+------------+---------+----------+----------+ -| output0| output1| output2| output3| output4| output5| output6| -+-----------+----------+----------+------------+---------+----------+----------+ -| 10.319546| 3.1450553| 7.877341| 1.5723765|2.7303758| 1.1362307| 8.867775| -| 10.443649| 3.3286757| 7.8593454| 1.7675098| 2.560634| 1.1177158| 8.920919| -| 10.883752| 3.2341104| 8.47036| 1.6116762|2.4874182| 1.1760603| 8.798939| -...... -| 8.0115595| 1.2995274| 6.9900327|-0.098746896| 3.04923| 1.176214| 9.548782| -| 8.612427| 2.5036244| 5.6790237| 0.66474205|2.8870275| 1.2051733| 9.330128| -| 10.096699| 3.399722| 6.9909| 1.7478468|2.7642853| 1.1119363| 9.541455| -+-----------+----------+----------+------------+---------+----------+----------+ -Total line number = 48 -``` - -我们将对油温的预测的结果和真实结果进行对比,可以得到以下的图像。 - -图中10/24 00:00之前的数据为输入模型的过去数据,10/24 00:00后的蓝色线条为模型给出的油温预测结果,而红色为数据集中实际的油温数据(用于进行对比)。 - -![](/img/AINode-analysis1.png) - -可以看到,我们使用了过去96个小时(4天)的六个负载信息和对应时间油温的关系,基于之前学习到的序列间相互关系对未来48个小时(2天)的油温这一数据的可能变化进行了建模,可以看到可视化后预测曲线与实际结果在趋势上保持了较高程度的一致性。 - -### 功率预测 - -变电站需要对电流、电压、功率等数据进行电力监控,用于检测潜在的电网问题、识别电力系统中的故障、有效管理电网负载以及分析电力系统的性能和趋势等。 - -我们利用某变电站中的电流、电压和功率等数据构成了真实场景下的数据集。该数据集包括变电站近四个月时间跨度,每5 - 6s 采集一次的 A相电压、B相电压、C相电压等数据。 - -测试集数据内容为[data](/img/data.csv)。 - -在该数据集上,IoTDB-ML的模型推理功能可以通过以往A相电压,B相电压和C相电压的数值和对应时间戳,预测未来一段时间内的C相电压,赋能变电站的监视管理。 - -#### 步骤一:数据导入 - -用户可以使用tools文件夹中的`import-csv.sh` 导入数据集 - -```Bash -bash ./import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f ../../data.csv -``` - -#### 步骤二:模型导入 - -我们可以在iotdb-cli 中选择内置模型或已经注册好的模型用于后续的推理。 - -我们采用内置模型STLForecaster进行预测,STLForecaster 是一个基于 statsmodels 库中 STL 实现的时间序列预测方法。 - -#### 步骤三:模型推理 - -```Shell -IoTDB> select * from root.eg.voltage limit 96 -+-----------------------------+------------------+------------------+------------------+ -| Time|root.eg.voltage.s0|root.eg.voltage.s1|root.eg.voltage.s2| -+-----------------------------+------------------+------------------+------------------+ -|2023-02-14T20:38:32.000+08:00| 2038.0| 2028.0| 2041.0| -|2023-02-14T20:38:38.000+08:00| 2014.0| 2005.0| 2018.0| -|2023-02-14T20:38:44.000+08:00| 2014.0| 2005.0| 2018.0| -...... -|2023-02-14T20:47:52.000+08:00| 2024.0| 2016.0| 2027.0| -|2023-02-14T20:47:57.000+08:00| 2024.0| 2016.0| 2027.0| -|2023-02-14T20:48:03.000+08:00| 2024.0| 2016.0| 2027.0| -+-----------------------------+------------------+------------------+------------------+ -Total line number = 96 - -IoTDB> call inference(_STLForecaster, "select s0,s1,s2 from root.eg.voltage", window=head(96),predict_length=48) -+---------+---------+---------+ -| output0| output1| output2| -+---------+---------+---------+ -|2026.3601|2018.2953|2029.4257| -|2019.1538|2011.4361|2022.0888| -|2025.5074|2017.4522|2028.5199| -...... - -|2022.2336|2015.0290|2025.1023| -|2015.7241|2008.8975|2018.5085| -|2022.0777|2014.9136|2024.9396| -|2015.5682|2008.7821|2018.3458| -+---------+---------+---------+ -Total line number = 48 -``` -我们将对C相电压的预测的结果和真实结果进行对比,可以得到以下的图像。 - -图中 02/14 20:48 之前的数据为输入模型的过去数据, 02/14 20:48 后的蓝色线条为模型给出的C相电压预测结果,而红色为数据集中实际的C相电压数据(用于进行对比)。 - -![](/img/AINode-analysis2.png) - -可以看到,我们使用了过去10分钟的电压的数据,基于之前学习到的序列间相互关系对未来5分钟的C相电压这一数据的可能变化进行了建模,可以看到可视化后预测曲线与实际结果在趋势上保持了一定的同步性。 - -### 异常检测 - -在民航交通运输业,存在着对乘机旅客数量进行异常检测的需求。异常检测的结果可用于指导调整航班的调度,以使得企业获得更大效益。 - -Airline Passengers一个时间序列数据集,该数据集记录了1949年至1960年期间国际航空乘客数量,间隔一个月进行一次采样。该数据集共含一条时间序列。数据集为[airline](/img/airline.csv)。 -在该数据集上,IoTDB-ML的模型推理功能可以通过捕捉序列的变化规律以对序列时间点进行异常检测,赋能交通运输业。 - -#### 步骤一:数据导入 - -用户可以使用tools文件夹中的`import-csv.sh` 导入数据集 - -```Bash -bash ./import-csv.sh -h 127.0.0.1 -p 6667 -u root -pw root -f ../../data.csv -``` - -#### 步骤二:模型推理 - -IoTDB内置有部分可以直接使用的机器学习算法,使用其中的异常检测算法进行预测的样例如下: - -```Shell -IoTDB> select * from root.eg.airline -+-----------------------------+------------------+ -| Time|root.eg.airline.s0| -+-----------------------------+------------------+ -|1949-01-31T00:00:00.000+08:00| 224.0| -|1949-02-28T00:00:00.000+08:00| 118.0| -|1949-03-31T00:00:00.000+08:00| 132.0| -|1949-04-30T00:00:00.000+08:00| 129.0| -...... -|1960-09-30T00:00:00.000+08:00| 508.0| -|1960-10-31T00:00:00.000+08:00| 461.0| -|1960-11-30T00:00:00.000+08:00| 390.0| -|1960-12-31T00:00:00.000+08:00| 432.0| -+-----------------------------+------------------+ -Total line number = 144 - -IoTDB> call inference(_Stray, "select s0 from root.eg.airline", k=2) -+-------+ -|output0| -+-------+ -| 0| -| 0| -| 0| -| 0| -...... -| 1| -| 1| -| 0| -| 0| -| 0| -| 0| -+-------+ -Total line number = 144 -``` - -我们将检测为异常的结果进行绘制,可以得到以下图像。其中蓝色曲线为原时间序列,用红色点特殊标注的时间点为算法检测为异常的时间点。 - -![](/img/s6.png) - -可以看到,Stray模型对输入序列变化进行了建模,成功检测出出现异常的时间点。 \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/User-Manual/Authority-Management.md b/src/zh/UserGuide/V1.3.3/User-Manual/Authority-Management.md deleted file mode 100644 index 814762e8b..000000000 --- a/src/zh/UserGuide/V1.3.3/User-Manual/Authority-Management.md +++ /dev/null @@ -1,510 +0,0 @@ - - -# 权限管理 - -IoTDB 为用户提供了权限管理操作,为用户提供对数据与集群系统的权限管理功能,保障数据与系统安全。 -本篇介绍IoTDB 中权限模块的基本概念、用户定义、权限管理、鉴权逻辑与功能用例。在 JAVA 编程环境中,您可以使用 [JDBC API](../API/Programming-JDBC.md) 单条或批量执行权限管理类语句。 - -## 基本概念 - -### 用户 - -用户即数据库的合法使用者。一个用户与一个唯一的用户名相对应,并且拥有密码作为身份验证的手段。一个人在使用数据库之前,必须先提供合法的(即存于数据库中的)用户名与密码,作为用户成功登录。 - -### 权限 - -数据库提供多种操作,但并非所有的用户都能执行所有操作。如果一个用户可以执行某项操作,则称该用户有执行该操作的权限。权限通常需要一个路径来限定其生效范围,可以使用[路径模式](../Basic-Concept/Data-Model-and-Terminology.md)灵活管理权限。 - -### 角色 - -角色是若干权限的集合,并且有一个唯一的角色名作为标识符。角色通常和一个现实身份相对应(例如交通调度员),而一个现实身份可能对应着多个用户。这些具有相同现实身份的用户往往具有相同的一些权限,角色就是为了能对这样的权限进行统一的管理的抽象。 - -### 默认用户与角色 - -安装初始化后的 IoTDB 中有一个默认用户:root,默认密码为 root。该用户为管理员用户,固定拥有所有权限,无法被赋予、撤销权限,也无法被删除,数据库内仅有一个管理员用户。 - -一个新创建的用户或角色不具备任何权限。 - -## 用户定义 - -拥有 MANAGE_USER、MANAGE_ROLE 的用户或者管理员可以创建用户或者角色,需要满足以下约束: - -### 用户名限制 - -4~32个字符,支持使用英文大小写字母、数字、特殊字符(`!@#$%^&*()_+-=`) - -用户无法创建和管理员用户同名的用户。 - -### 密码限制 - -4~32个字符,可使用大写小写字母、数字、特殊字符(`!@#$%^&*()_+-=`),密码默认采用 MD5 进行加密。 - -### 角色名限制 - -4~32个字符,支持使用英文大小写字母、数字、特殊字符(`!@#$%^&*()_+-=`) - -用户无法创建和管理员用户同名的角色。 - -## 权限管理 - -IoTDB 主要有两类权限:序列权限、全局权限。 - -### 序列权限 - -序列权限约束了用户访问数据的范围与方式,支持对绝对路径与前缀匹配路径授权,可对timeseries 粒度生效。 - -下表描述了这类权限的种类与范围: - -| 权限名称 | 描述 | -|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| READ_DATA | 允许读取授权路径下的序列数据。 | -| WRITE_DATA | 允许读取授权路径下的序列数据。
允许插入、删除授权路径下的的序列数据。
允许在授权路径下导入、加载数据,在导入数据时,需要拥有对应路径的 WRITE_DATA 权限,在自动创建数据库与序列时,需要有 MANAGE_DATABASE 与 WRITE_SCHEMA 权限。 | -| READ_SCHEMA | 允许获取授权路径下元数据树的详细信息:
包括:路径下的数据库、子路径、子节点、设备、序列、模版、视图等。 | -| WRITE_SCHEMA | 允许获取授权路径下元数据树的详细信息。
允许在授权路径下对序列、模版、视图等进行创建、删除、修改操作。
在创建或修改 view 的时候,会检查 view 路径的 WRITE_SCHEMA 权限、数据源的 READ_SCHEMA 权限。
在对 view 进行查询、插入时,会检查 view 路径的 READ_DATA 权限、WRITE_DATA 权限。
允许在授权路径下设置、取消、查看TTL。
允许在授权路径下挂载或者接触挂载模板。 | - -### 全局权限 - -全局权限约束了用户使用的数据库功能、限制了用户执行改变系统状态与任务状态的命令,用户获得全局授权后,可对数据库进行管理。 - -下表描述了系统权限的种类: - -| 权限名称 | 描述 | -|:---------------:|:------------------------------------------------------------------| -| MANAGE_DATABASE | - 允许用户创建、删除数据库. | -| MANAGE_USER | - 允许用户创建、删除、修改、查看用户。 | -| MANAGE_ROLE | - 允许用户创建、删除、查看角色。
允许用户将角色授予给其他用户,或取消其他用户的角色。 | -| USE_TRIGGER | - 允许用户创建、删除、查看触发器。
与触发器的数据源权限检查相独立。 | -| USE_UDF | - 允许用户创建、删除、查看用户自定义函数。
与自定义函数的数据源权限检查相独立。 | -| USE_CQ | - 允许用户创建、开始、停止、删除、查看管道。
允许用户创建、删除、查看管道插件。
与管道的数据源权限检查相独立。 | -| USE_PIPE | - 允许用户注册、开始、停止、卸载、查询流处理任务。
- 允许用户注册、卸载、查询注册流处理任务插件。 | -| EXTEND_TEMPLATE | - 允许自动扩展模板。 | -| MAINTAIN | - 允许用户查询、取消查询。
允许用户查看变量。
允许用户查看集群状态。 | -| USE_MODEL | - 允许用户创建、删除、查询深度学习模型 | - -关于模板权限: - -1. 模板的创建、删除、修改、查询、挂载、卸载仅允许管理员操作。 -2. 激活模板需要拥有激活路径的 WRITE_SCHEMA 权限 -3. 若开启了自动创建,在向挂载了模板的不存在路径写入时,数据库会自动扩展模板并写入数据,因此需要有 EXTEND_TEMPLATE 权限与写入序列的 WRITE_DATA 权限。 -4. 解除模板,需要拥有挂载模板路径的 WRITE_SCHEMA 权限。 -5. 查询使用了某个元数据模板的路径,需要有路径的 READ_SCHEMA 权限,否则将返回为空。 - -### 权限授予与取消 - -在 IoTDB 中,用户可以由三种途径获得权限: - -1. 由超级管理员授予,超级管理员可以控制其他用户的权限。 -2. 由允许权限授权的用户授予,该用户获得权限时被指定了 grant option 关键字。 -3. 由超级管理员或者有 MANAGE_ROLE 的用户授予某个角色进而获取权限。 - -取消用户的权限,可以由以下几种途径: - -1. 由超级管理员取消用户的权限。 -2. 由允许权限授权的用户取消权限,该用户获得权限时被指定了 grant option 关键字。 -3. 由超级管理员或者MANAGE_ROLE 的用户取消用户的某个角色进而取消权限。 - -- 在授权时,必须指定路径。全局权限需要指定为 root.**, 而序列相关权限必须为绝对路径或者以双通配符结尾的前缀路径。 -- 当授予角色权限时,可以为该权限指定 with grant option 关键字,意味着用户可以转授其授权路径上的权限,也可以取消其他用户的授权路径上的权限。例如用户 A 在被授予`集团1.公司1.**`的读权限时制定了 grant option 关键字,那么 A 可以将`集团1.公司1`以下的任意节点、序列的读权限转授给他人, 同样也可以取消其他用户 `集团1.公司1` 下任意节点的读权限。 -- 在取消授权时,取消授权语句会与用户所有的权限路径进行匹配,将匹配到的权限路径进行清理,例如用户A 具有 `集团1.公司1.工厂1 `的读权限, 在取消 `集团1.公司1.** `的读权限时,会清除用户A 的 `集团1.公司1.工厂1` 的读权限。 - - - -## 鉴权 - -用户权限主要由三部分组成:权限生效范围(路径), 权限类型, with grant option 标记: - -``` -userTest1 : - root.t1.** - read_schema, read_data - with grant option - root.** - write_schema, write_data - with grant option -``` - -每个用户都有一个这样的权限访问列表,标识他们获得的所有权限,可以通过 `LIST PRIVILEGES OF USER ` 查看他们的权限。 - -在对一个路径进行鉴权时,数据库会进行路径与权限的匹配。例如检查 `root.t1.t2` 的 read_schema 权限时,首先会与权限访问列表的 `root.t1.**`进行匹配,匹配成功,则检查该路径是否包含待鉴权的权限,否则继续下一条路径-权限的匹配,直到匹配成功或者匹配结束。 - -在进行多路径鉴权时,对于多路径查询任务,数据库只会将有权限的数据呈现出来,无权限的数据不会包含在结果中;对于多路径写入任务,数据库要求必须所有的目标序列都获得了对应的权限,才能进行写入。 - -请注意,下面的操作需要检查多重权限 -1. 开启了自动创建序列功能,在用户将数据插入到不存在的序列中时,不仅需要对应序列的写入权限,还需要序列的元数据修改权限。 -2. 执行 select into 语句时,需要检查源序列的读权限与目标序列的写权限。需要注意的是源序列数据可能因为权限不足而仅能获取部分数据,目标序列写入权限不足时会报错终止任务。 -3. View 权限与数据源的权限是独立的,向 view 执行读写操作仅会检查 view 的权限,而不再对源路径进行权限校验。 - - - -## 功能语法与示例 - -IoTDB 提供了组合权限,方便用户授权: - -| 权限名称 | 权限范围 | -|-------|-------------------------| -| ALL | 所有权限 | -| READ | READ_SCHEMA、READ_DATA | -| WRITE | WRITE_SCHEMA、WRITE_DATA | - -组合权限并不是一种具体的权限,而是一种简写方式,与直接书写对应的权限名称没有差异。 - -下面将通过一系列具体的用例展示权限语句的用法,非管理员执行下列语句需要提前获取权限,所需的权限标记在操作描述后。 - -### 用户与角色相关 - -- 创建用户(需 MANAGE_USER 权限) - - -```SQL -CREATE USER -eg: CREATE USER user1 'passwd' -``` - -- 删除用户 (需 MANEGE_USER 权限) - - -```SQL -DROP USER -eg: DROP USER user1 -``` - -- 创建角色 (需 MANAGE_ROLE 权限) - -```SQL -CREATE ROLE -eg: CREATE ROLE role1 -``` - -- 删除角色 (需 MANAGE_ROLE 权限) - - -```SQL -DROP ROLE -eg: DROP ROLE role1 -``` - -- 赋予用户角色 (需 MANAGE_ROLE 权限) - - -```SQL -GRANT ROLE TO -eg: GRANT ROLE admin TO user1 -``` - -- 移除用户角色 (需 MANAGE_ROLE 权限) - - -```SQL -REVOKE ROLE FROM -eg: REVOKE ROLE admin FROM user1 -``` - -- 列出所有用户 (需 MANEGE_USER 权限) - -```SQL -LIST USER -``` - -- 列出所有角色 (需 MANAGE_ROLE 权限) - -```SQL -LIST ROLE -``` - -- 列出指定角色下所有用户 (需 MANEGE_USER 权限) - -```SQL -LIST USER OF ROLE -eg: LIST USER OF ROLE roleuser -``` - -- 列出指定用户下所有角色 - -用户可以列出自己的角色,但列出其他用户的角色需要拥有 MANAGE_ROLE 权限。 - -```SQL -LIST ROLE OF USER -eg: LIST ROLE OF USER tempuser -``` - -- 列出用户所有权限 - -用户可以列出自己的权限信息,但列出其他用户的权限需要拥有 MANAGE_USER 权限。 - -```SQL -LIST PRIVILEGES OF USER ; -eg: LIST PRIVILEGES OF USER tempuser; - -``` - -- 列出角色所有权限 - -用户可以列出自己具有的角色的权限信息,列出其他角色的权限需要有 MANAGE_ROLE 权限。 - -```SQL -LIST PRIVILEGES OF ROLE ; -eg: LIST PRIVILEGES OF ROLE actor; -``` - -- 更新密码 - -用户可以更新自己的密码,但更新其他用户密码需要具备MANAGE_USER 权限。 - -```SQL -ALTER USER SET PASSWORD ; -eg: ALTER USER tempuser SET PASSWORD 'newpwd'; -``` - -### 授权与取消授权 - -用户使用授权语句对赋予其他用户权限,语法如下: - -```SQL -GRANT ON TO ROLE/USER [WITH GRANT OPTION]; -eg: GRANT READ ON root.** TO ROLE role1; -eg: GRANT READ_DATA, WRITE_DATA ON root.t1.** TO USER user1; -eg: GRANT READ_DATA, WRITE_DATA ON root.t1.**,root.t2.** TO USER user1; -eg: GRANT MANAGE_ROLE ON root.** TO USER user1 WITH GRANT OPTION; -eg: GRANT ALL ON root.** TO USER user1 WITH GRANT OPTION; -``` - -用户使用取消授权语句可以将其他的权限取消,语法如下: - -```SQL -REVOKE ON FROM ROLE/USER ; -eg: REVOKE READ ON root.** FROM ROLE role1; -eg: REVOKE READ_DATA, WRITE_DATA ON root.t1.** FROM USER user1; -eg: REVOKE READ_DATA, WRITE_DATA ON root.t1.**, root.t2.** FROM USER user1; -eg: REVOKE MANAGE_ROLE ON root.** FROM USER user1; -eg: REVOKE ALL ON ROOT.** FROM USER user1; -``` - -- **非管理员用户执行授权/取消授权语句时,需要对\ 有\ 权限,并且该权限是被标记带有 WITH GRANT OPTION 的。** - -- 在授予取消全局权限时,或者语句中包含全局权限时(ALL 展开会包含全局权限),须指定 path 为 root.**。 例如,以下授权/取消授权语句是合法的: - - ```SQL - GRANT MANAGE_USER ON root.** TO USER user1; - GRANT MANAGE_ROLE ON root.** TO ROLE role1 WITH GRANT OPTION; - GRANT ALL ON root.** TO role role1 WITH GRANT OPTION; - REVOKE MANAGE_USER ON root.** FROM USER user1; - REVOKE MANAGE_ROLE ON root.** FROM ROLE role1; - REVOKE ALL ON root.** FROM ROLE role1; - ``` - 下面的语句是非法的: - - ```SQL - GRANT READ, MANAGE_ROLE ON root.t1.** TO USER user1; - GRANT ALL ON root.t1.t2 TO USER user1 WITH GRANT OPTION; - REVOKE ALL ON root.t1.t2 FROM USER user1; - REVOKE READ, MANAGE_ROLE ON root.t1.t2 FROM ROLE ROLE1; - ``` - -- \ 必须为全路径或者以双通配符结尾的匹配路径,以下路径是合法的: - - ```SQL - root.** - root.t1.t2.** - root.t1.t2.t3 - ``` - - 以下的路径是非法的: - - ```SQL - root.t1.* - root.t1.**.t2 - root.t1*.t2.t3 - ``` - -## 示例 - -根据本文中描述的 [样例数据](https://github.com/thulab/iotdb/files/4438687/OtherMaterial-Sample.Data.txt) 内容,IoTDB 的样例数据可能同时属于 ln, sgcc 等不同发电集团,不同的发电集团不希望其他发电集团获取自己的数据库数据,因此我们需要将不同的数据在集团层进行权限隔离。 - -### 创建用户 - -使用 `CREATE USER ` 创建用户。例如,我们可以使用具有所有权限的root用户为 ln 和 sgcc 集团创建两个用户角色,名为 ln_write_user, sgcc_write_user,密码均为 write_pwd。建议使用反引号(`)包裹用户名。SQL 语句为: - -```SQL -CREATE USER `ln_write_user` 'write_pwd' -CREATE USER `sgcc_write_user` 'write_pwd' -``` -此时使用展示用户的 SQL 语句: - -```SQL -LIST USER -``` - -我们可以看到这两个已经被创建的用户,结果如下: - -```SQL -IoTDB> CREATE USER `ln_write_user` 'write_pwd' -Msg: The statement is executed successfully. -IoTDB> CREATE USER `sgcc_write_user` 'write_pwd' -Msg: The statement is executed successfully. -IoTDB> LIST USER; -+---------------+ -| user| -+---------------+ -| ln_write_user| -| root| -|sgcc_write_user| -+---------------+ -Total line number = 3 -It costs 0.012s -``` - -### 赋予用户权限 - -此时,虽然两个用户已经创建,但是他们不具有任何权限,因此他们并不能对数据库进行操作,例如我们使用 ln_write_user 用户对数据库中的数据进行写入,SQL 语句为: - -```SQL -INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true) -``` - -此时,系统不允许用户进行此操作,会提示错误: - -```SQL -IoTDB> INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true) -Msg: 803: No permissions for this operation, please add privilege WRITE_DATA on [root.ln.wf01.wt01.status] -``` - -现在,我们用 root 用户分别赋予他们向对应路径的写入权限. - -我们使用 `GRANT ON TO USER ` 语句赋予用户权限,例如: -```SQL -GRANT WRITE_DATA ON root.ln.** TO USER `ln_write_user` -GRANT WRITE_DATA ON root.sgcc1.**, root.sgcc2.** TO USER `sgcc_write_user` -``` - -执行状态如下所示: - -```SQL -IoTDB> GRANT WRITE_DATA ON root.ln.** TO USER `ln_write_user` -Msg: The statement is executed successfully. -IoTDB> GRANT WRITE_DATA ON root.sgcc1.**, root.sgcc2.** TO USER `sgcc_write_user` -Msg: The statement is executed successfully. -``` - -接着使用ln_write_user再尝试写入数据 - -```SQL -IoTDB> INSERT INTO root.ln.wf01.wt01(timestamp, status) values(1509465600000, true) -Msg: The statement is executed successfully. -``` - -### 撤销用户权限 -授予用户权限后,我们可以使用 `REVOKE ON FROM USER `来撤销已经授予用户的权限。例如,用root用户撤销ln_write_user和sgcc_write_user的权限: - -``` SQL -REVOKE WRITE_DATA ON root.ln.** FROM USER `ln_write_user` -REVOKE WRITE_DATA ON root.sgcc1.**, root.sgcc2.** FROM USER `sgcc_write_user` -``` - -执行状态如下所示: -``` SQL -IoTDB> REVOKE WRITE_DATA ON root.ln.** FROM USER `ln_write_user` -Msg: The statement is executed successfully. -IoTDB> REVOKE WRITE_DATA ON root.sgcc1.**, root.sgcc2.** FROM USER `sgcc_write_user` -Msg: The statement is executed successfully. -``` - -撤销权限后,ln_write_user就没有向root.ln.**写入数据的权限了。 - -``` SQL -IoTDB> INSERT INTO root.ln.wf01.wt01(timestamp, status) values(1509465600000, true) -Msg: 803: No permissions for this operation, please add privilege WRITE_DATA on [root.ln.wf01.wt01.status] -``` - -## 其他说明 - -角色是权限的集合,而权限和角色都是用户的一种属性。即一个角色可以拥有若干权限。一个用户可以拥有若干角色与权限(称为用户自身权限)。 - -目前在 IoTDB 中并不存在相互冲突的权限,因此一个用户真正具有的权限是用户自身权限与其所有的角色的权限的并集。即要判定用户是否能执行某一项操作,就要看用户自身权限或用户的角色的所有权限中是否有一条允许了该操作。用户自身权限与其角色权限,他的多个角色的权限之间可能存在相同的权限,但这并不会产生影响。 - -需要注意的是:如果一个用户自身有某种权限(对应操作 A),而他的某个角色有相同的权限。那么如果仅从该用户撤销该权限无法达到禁止该用户执行操作 A 的目的,还需要从这个角色中也撤销对应的权限,或者从这个用户将该角色撤销。同样,如果仅从上述角色将权限撤销,也不能禁止该用户执行操作 A。 - -同时,对角色的修改会立即反映到所有拥有该角色的用户上,例如对角色增加某种权限将立即使所有拥有该角色的用户都拥有对应权限,删除某种权限也将使对应用户失去该权限(除非用户本身有该权限)。 - -## 升级说明 - -在 1.3 版本前,权限类型较多,在这一版实现中,权限类型做了精简,并且添加了对权限路径的约束。 - -数据库 1.3 版本的权限路径必须为全路径或者以双通配符结尾的匹配路径,在系统升级时,会自动转换不合法的权限路径和权限类型。 -路径上首个非法节点会被替换为`**`, 不在支持的权限类型也会映射到当前系统支持的权限上。 - -例如: - -| 权限类型 | 权限路径 | 映射之后的权限类型 | 权限路径 | -| ----------------- | --------------- |-----------------| ------------- | -| CREATE_DATBASE | root.db.t1.* | MANAGE_DATABASE | root.** | -| INSERT_TIMESERIES | root.db.t2.*.t3 | WRITE_DATA | root.db.t2.** | -| CREATE_TIMESERIES | root.db.t2*c.t3 | WRITE_SCHEMA | root.db.** | -| LIST_ROLE | root.** | (忽略) | | - - -新旧版本的权限类型对照可以参照下面的表格(--IGNORE 表示新版本忽略该权限): - -| 权限名称 | 是否路径相关 | 新权限名称 | 是否路径相关 | -|---------------------------|--------|-----------------|--------| -| CREATE_DATABASE | 是 | MANAGE_DATABASE | 否 | -| INSERT_TIMESERIES | 是 | WRITE_DATA | 是 | -| UPDATE_TIMESERIES | 是 | WRITE_DATA | 是 | -| READ_TIMESERIES | 是 | READ_DATA | 是 | -| CREATE_TIMESERIES | 是 | WRITE_SCHEMA | 是 | -| DELETE_TIMESERIES | 是 | WRITE_SCHEMA | 是 | -| CREATE_USER | 否 | MANAGE_USER | 否 | -| DELETE_USER | 否 | MANAGE_USER | 否 | -| MODIFY_PASSWORD | 否 | -- IGNORE | | -| LIST_USER | 否 | -- IGNORE | | -| GRANT_USER_PRIVILEGE | 否 | -- IGNORE | | -| REVOKE_USER_PRIVILEGE | 否 | -- IGNORE | | -| GRANT_USER_ROLE | 否 | MANAGE_ROLE | 否 | -| REVOKE_USER_ROLE | 否 | MANAGE_ROLE | 否 | -| CREATE_ROLE | 否 | MANAGE_ROLE | 否 | -| DELETE_ROLE | 否 | MANAGE_ROLE | 否 | -| LIST_ROLE | 否 | -- IGNORE | | -| GRANT_ROLE_PRIVILEGE | 否 | -- IGNORE | | -| REVOKE_ROLE_PRIVILEGE | 否 | -- IGNORE | | -| CREATE_FUNCTION | 否 | USE_UDF | 否 | -| DROP_FUNCTION | 否 | USE_UDF | 否 | -| CREATE_TRIGGER | 是 | USE_TRIGGER | 否 | -| DROP_TRIGGER | 是 | USE_TRIGGER | 否 | -| START_TRIGGER | 是 | USE_TRIGGER | 否 | -| STOP_TRIGGER | 是 | USE_TRIGGER | 否 | -| CREATE_CONTINUOUS_QUERY | 否 | USE_CQ | 否 | -| DROP_CONTINUOUS_QUERY | 否 | USE_CQ | 否 | -| ALL | 否 | All privilegs | | -| DELETE_DATABASE | 是 | MANAGE_DATABASE | 否 | -| ALTER_TIMESERIES | 是 | WRITE_SCHEMA | 是 | -| UPDATE_TEMPLATE | 否 | -- IGNORE | | -| READ_TEMPLATE | 否 | -- IGNORE | | -| APPLY_TEMPLATE | 是 | WRITE_SCHEMA | 是 | -| READ_TEMPLATE_APPLICATION | 否 | -- IGNORE | | -| SHOW_CONTINUOUS_QUERIES | 否 | -- IGNORE | | -| CREATE_PIPEPLUGIN | 否 | USE_PIPE | 否 | -| DROP_PIPEPLUGINS | 否 | USE_PIPE | 否 | -| SHOW_PIPEPLUGINS | 否 | -- IGNORE | | -| CREATE_PIPE | 否 | USE_PIPE | 否 | -| START_PIPE | 否 | USE_PIPE | 否 | -| STOP_PIPE | 否 | USE_PIPE | 否 | -| DROP_PIPE | 否 | USE_PIPE | 否 | -| SHOW_PIPES | 否 | -- IGNORE | | -| CREATE_VIEW | 是 | WRITE_SCHEMA | 是 | -| ALTER_VIEW | 是 | WRITE_SCHEMA | 是 | -| RENAME_VIEW | 是 | WRITE_SCHEMA | 是 | -| DELETE_VIEW | 是 | WRITE_SCHEMA | 是 | diff --git a/src/zh/UserGuide/V1.3.3/User-Manual/Trigger.md b/src/zh/UserGuide/V1.3.3/User-Manual/Trigger.md deleted file mode 100644 index 0e5f54d20..000000000 --- a/src/zh/UserGuide/V1.3.3/User-Manual/Trigger.md +++ /dev/null @@ -1,467 +0,0 @@ - - -# 触发器 - -## 使用说明 - -触发器提供了一种侦听序列数据变动的机制。配合用户自定义逻辑,可完成告警、数据转发等功能。 - -触发器基于 Java 反射机制实现。用户通过简单实现 Java 接口,即可实现数据侦听。IoTDB 允许用户动态注册、卸载触发器,在注册、卸载期间,无需启停服务器。 - -### 侦听模式 - -IoTDB 的单个触发器可用于侦听符合特定模式的时间序列的数据变动,如时间序列 root.sg.a 上的数据变动,或者符合路径模式 root.**.a 的时间序列上的数据变动。您在注册触发器时可以通过 SQL 语句指定触发器侦听的路径模式。 - -### 触发器类型 - -目前触发器分为两类,您在注册触发器时可以通过 SQL 语句指定类型: - -- 有状态的触发器。该类触发器的执行逻辑可能依赖前后的多条数据,框架会将不同节点写入的数据汇总到同一个触发器实例进行计算,来保留上下文信息,通常用于采样或者统计一段时间的数据聚合信息。集群中只有一个节点持有有状态触发器的实例。 -- 无状态的触发器。触发器的执行逻辑只和当前输入的数据有关,框架无需将不同节点的数据汇总到同一个触发器实例中,通常用于单行数据的计算和异常检测等。集群中每个节点均持有无状态触发器的实例。 - -### 触发时机 - -触发器的触发时机目前有两种,后续会拓展其它触发时机。您在注册触发器时可以通过 SQL 语句指定触发时机: - -- BEFORE INSERT,即在数据持久化之前触发。请注意,目前触发器并不支持数据清洗,不会对要持久化的数据本身进行变动。 -- AFTER INSERT,即在数据持久化之后触发。 - -## 编写触发器 - -### 触发器依赖 - -触发器的逻辑需要您编写 Java 类进行实现。 -在编写触发器逻辑时,需要使用到下面展示的依赖。如果您使用 [Maven](http://search.maven.org/),则可以直接从 [Maven 库](http://search.maven.org/)中搜索到它们。请注意选择和目标服务器版本相同的依赖版本。 - -``` xml - - org.apache.iotdb - iotdb-server - 1.0.0 - provided - -``` - -### 接口说明 - -编写一个触发器需要实现 `org.apache.iotdb.trigger.api.Trigger` 类。 - -```java -import org.apache.iotdb.trigger.api.enums.FailureStrategy; -import org.apache.iotdb.tsfile.write.record.Tablet; - -public interface Trigger { - - /** - * This method is mainly used to validate {@link TriggerAttributes} before calling {@link - * Trigger#onCreate(TriggerAttributes)}. - * - * @param attributes TriggerAttributes - * @throws Exception e - */ - default void validate(TriggerAttributes attributes) throws Exception {} - - /** - * This method will be called when creating a trigger after validation. - * - * @param attributes TriggerAttributes - * @throws Exception e - */ - default void onCreate(TriggerAttributes attributes) throws Exception {} - - /** - * This method will be called when dropping a trigger. - * - * @throws Exception e - */ - default void onDrop() throws Exception {} - - /** - * When restarting a DataNode, Triggers that have been registered will be restored and this method - * will be called during the process of restoring. - * - * @throws Exception e - */ - default void restore() throws Exception {} - - /** - * Overrides this method to set the expected FailureStrategy, {@link FailureStrategy#OPTIMISTIC} - * is the default strategy. - * - * @return {@link FailureStrategy} - */ - default FailureStrategy getFailureStrategy() { - return FailureStrategy.OPTIMISTIC; - } - - /** - * @param tablet see {@link Tablet} for detailed information of data structure. Data that is - * inserted will be constructed as a Tablet and you can define process logic with {@link - * Tablet}. - * @return true if successfully fired - * @throws Exception e - */ - default boolean fire(Tablet tablet) throws Exception { - return true; - } -} -``` - -该类主要提供了两类编程接口:**生命周期相关接口**和**数据变动侦听相关接口**。该类中所有的接口都不是必须实现的,当您不实现它们时,它们不会对流经的数据操作产生任何响应。您可以根据实际需要,只实现其中若干接口。 - -下面是所有可供用户进行实现的接口的说明。 - -#### 生命周期相关接口 - -| 接口定义 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| *default void validate(TriggerAttributes attributes) throws Exception {}* | 用户在使用 `CREATE TRIGGER` 语句创建触发器时,可以指定触发器需要使用的参数,该接口会用于验证参数正确性。 | -| *default void onCreate(TriggerAttributes attributes) throws Exception {}* | 当您使用`CREATE TRIGGER`语句创建触发器后,该接口会被调用一次。在每一个触发器实例的生命周期内,该接口会且仅会被调用一次。该接口主要有如下作用:帮助用户解析 SQL 语句中的自定义属性(使用`TriggerAttributes`)。 可以创建或申请资源,如建立外部链接、打开文件等。 | -| *default void onDrop() throws Exception {}* | 当您使用`DROP TRIGGER`语句删除触发器后,该接口会被调用。在每一个触发器实例的生命周期内,该接口会且仅会被调用一次。该接口主要有如下作用:可以进行资源释放的操作。可以用于持久化触发器计算的结果。 | -| *default void restore() throws Exception {}* | 当重启 DataNode 时,集群会恢复 DataNode 上已经注册的触发器实例,在此过程中会为该 DataNode 上的有状态触发器调用一次该接口。有状态触发器实例所在的 DataNode 宕机后,集群会在另一个可用 DataNode 上恢复该触发器的实例,在此过程中会调用一次该接口。该接口可以用于自定义恢复逻辑。 | - -#### 数据变动侦听相关接口 - -##### 侦听接口 - -```java - /** - * @param tablet see {@link Tablet} for detailed information of data structure. Data that is - * inserted will be constructed as a Tablet and you can define process logic with {@link - * Tablet}. - * @return true if successfully fired - * @throws Exception e - */ - default boolean fire(Tablet tablet) throws Exception { - return true; - } -``` - -数据变动时,触发器以 Tablet 作为触发操作的单位。您可以通过 Tablet 获取相应序列的元数据和数据,然后进行相应的触发操作,触发成功则返回值应当为 true。该接口返回 false 或是抛出异常我们均认为触发失败。在触发失败时,我们会根据侦听策略接口进行相应的操作。 - -进行一次 INSERT 操作时,对于其中的每条时间序列,我们会检测是否有侦听该路径模式的触发器,然后将符合同一个触发器所侦听的路径模式的时间序列数据组装成一个新的 Tablet 用于触发器的 fire 接口。可以理解成: - -```java -Map> pathToTriggerListMap => Map -``` - -**请注意,目前我们不对触发器的触发顺序有任何保证。** - -下面是示例: - -假设有三个触发器,触发器的触发时机均为 BEFORE INSERT - -- 触发器 Trigger1 侦听路径模式:root.sg.* -- 触发器 Trigger2 侦听路径模式:root.sg.a -- 触发器 Trigger3 侦听路径模式:root.sg.b - -写入语句: - -```sql -insert into root.sg(time, a, b) values (1, 1, 1); -``` - -序列 root.sg.a 匹配 Trigger1 和 Trigger2,序列 root.sg.b 匹配 Trigger1 和 Trigger3,那么: - -- root.sg.a 和 root.sg.b 的数据会被组装成一个新的 tablet1,在相应的触发时机进行 Trigger1.fire(tablet1) -- root.sg.a 的数据会被组装成一个新的 tablet2,在相应的触发时机进行 Trigger2.fire(tablet2) -- root.sg.b 的数据会被组装成一个新的 tablet3,在相应的触发时机进行 Trigger3.fire(tablet3) - -##### 侦听策略接口 - -在触发器触发失败时,我们会根据侦听策略接口设置的策略进行相应的操作,您可以通过下述接口设置 `org.apache.iotdb.trigger.api.enums.FailureStrategy`,目前有乐观和悲观两种策略: - -- 乐观策略:触发失败的触发器不影响后续触发器的触发,也不影响写入流程,即我们不对触发失败涉及的序列做额外处理,仅打日志记录失败,最后返回用户写入数据成功,但触发部分失败。 -- 悲观策略:失败触发器影响后续所有 Pipeline 的处理,即我们认为该 Trigger 触发失败会导致后续所有触发流程不再进行。如果该触发器的触发时机为 BEFORE INSERT,那么写入也不再进行,直接返回写入失败。 - -```java - /** - * Overrides this method to set the expected FailureStrategy, {@link FailureStrategy#OPTIMISTIC} - * is the default strategy. - * - * @return {@link FailureStrategy} - */ - default FailureStrategy getFailureStrategy() { - return FailureStrategy.OPTIMISTIC; - } -``` - -您可以参考下图辅助理解,其中 Trigger1 配置采用乐观策略,Trigger2 配置采用悲观策略。Trigger1 和 Trigger2 的触发时机是 BEFORE INSERT,Trigger3 和 Trigger4 的触发时机是 AFTER INSERT。 正常执行流程如下: - - - - - - -### 示例 - -如果您使用 [Maven](http://search.maven.org/),可以参考我们编写的示例项目 trigger-example。您可以在 [这里](https://github.com/apache/iotdb/tree/master/example/trigger) 找到它。后续我们会加入更多的示例项目供您参考。 - -下面是其中一个示例项目的代码: - -```java -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.iotdb.trigger; - -import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerConfiguration; -import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerEvent; -import org.apache.iotdb.db.engine.trigger.sink.alertmanager.AlertManagerHandler; -import org.apache.iotdb.trigger.api.Trigger; -import org.apache.iotdb.trigger.api.TriggerAttributes; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.write.record.Tablet; -import org.apache.iotdb.tsfile.write.schema.MeasurementSchema; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; - -public class ClusterAlertingExample implements Trigger { - private static final Logger LOGGER = LoggerFactory.getLogger(ClusterAlertingExample.class); - - private final AlertManagerHandler alertManagerHandler = new AlertManagerHandler(); - - private final AlertManagerConfiguration alertManagerConfiguration = - new AlertManagerConfiguration("http://127.0.0.1:9093/api/v2/alerts"); - - private String alertname; - - private final HashMap labels = new HashMap<>(); - - private final HashMap annotations = new HashMap<>(); - - @Override - public void onCreate(TriggerAttributes attributes) throws Exception { - alertname = "alert_test"; - - labels.put("series", "root.ln.wf01.wt01.temperature"); - labels.put("value", ""); - labels.put("severity", ""); - - annotations.put("summary", "high temperature"); - annotations.put("description", "{{.alertname}}: {{.series}} is {{.value}}"); - - alertManagerHandler.open(alertManagerConfiguration); - } - - @Override - public void onDrop() throws IOException { - alertManagerHandler.close(); - } - - @Override - public boolean fire(Tablet tablet) throws Exception { - List measurementSchemaList = tablet.getSchemas(); - for (int i = 0, n = measurementSchemaList.size(); i < n; i++) { - if (measurementSchemaList.get(i).getType().equals(TSDataType.DOUBLE)) { - // for example, we only deal with the columns of Double type - double[] values = (double[]) tablet.values[i]; - for (double value : values) { - if (value > 100.0) { - LOGGER.info("trigger value > 100"); - labels.put("value", String.valueOf(value)); - labels.put("severity", "critical"); - AlertManagerEvent alertManagerEvent = - new AlertManagerEvent(alertname, labels, annotations); - alertManagerHandler.onEvent(alertManagerEvent); - } else if (value > 50.0) { - LOGGER.info("trigger value > 50"); - labels.put("value", String.valueOf(value)); - labels.put("severity", "warning"); - AlertManagerEvent alertManagerEvent = - new AlertManagerEvent(alertname, labels, annotations); - alertManagerHandler.onEvent(alertManagerEvent); - } - } - } - } - return true; - } -} -``` -## 管理触发器 - -您可以通过 SQL 语句注册和卸载一个触发器实例,您也可以通过 SQL 语句查询到所有已经注册的触发器。 - -**我们建议您在注册触发器时停止写入。** - -### 注册触发器 - -触发器可以注册在任意路径模式上。被注册有触发器的序列将会被触发器侦听,当序列上有数据变动时,触发器中对应的触发方法将会被调用。 - -注册一个触发器可以按如下流程进行: - -1. 按照编写触发器章节的说明,实现一个完整的 Trigger 类,假定这个类的全类名为 `org.apache.iotdb.trigger.ClusterAlertingExample` -2. 将项目打成 JAR 包。 -3. 使用 SQL 语句注册该触发器。注册过程中会仅只会调用一次触发器的 `validate` 和 `onCreate` 接口,具体请参考编写触发器章节。 - -完整 SQL 语法如下: - -```sql -// Create Trigger -createTrigger - : CREATE triggerType TRIGGER triggerName=identifier triggerEventClause ON pathPattern AS className=STRING_LITERAL uriClause? triggerAttributeClause? - ; - -triggerType - : STATELESS | STATEFUL - ; - -triggerEventClause - : (BEFORE | AFTER) INSERT - ; - -uriClause - : USING URI uri - ; - -uri - : STRING_LITERAL - ; - -triggerAttributeClause - : WITH LR_BRACKET triggerAttribute (COMMA triggerAttribute)* RR_BRACKET - ; - -triggerAttribute - : key=attributeKey operator_eq value=attributeValue - ; -``` - -下面对 SQL 语法进行说明,您可以结合使用说明章节进行理解: - -- triggerName:触发器 ID,该 ID 是全局唯一的,用于区分不同触发器,大小写敏感。 -- triggerType:触发器类型,分为无状态(STATELESS)和有状态(STATEFUL)两类。 -- triggerEventClause:触发时机,目前仅支持写入前(BEFORE INSERT)和写入后(AFTER INSERT)两种。 -- pathPattern:触发器侦听的路径模式,可以包含通配符 * 和 **。 -- className:触发器实现类的类名。 -- uriClause:可选项,当不指定该选项时,我们默认 DBA 已经在各个 DataNode 节点的 trigger_root_dir 目录(配置项,默认为 IOTDB_HOME/ext/trigger)下放置好创建该触发器需要的 JAR 包。当指定该选项时,我们会将该 URI 对应的文件资源下载并分发到各 DataNode 的 trigger_root_dir/install 目录下。 -- triggerAttributeClause:用于指定触发器实例创建时需要设置的参数,SQL 语法中该部分是可选项。 - -下面是一个帮助您理解的 SQL 语句示例: - -```sql -CREATE STATELESS TRIGGER triggerTest -BEFORE INSERT -ON root.sg.** -AS 'org.apache.iotdb.trigger.ClusterAlertingExample' -USING URI 'http://jar/ClusterAlertingExample.jar' -WITH ( - "name" = "trigger", - "limit" = "100" -) -``` - -上述 SQL 语句创建了一个名为 triggerTest 的触发器: - -- 该触发器是无状态的(STATELESS) -- 在写入前触发(BEFORE INSERT) -- 该触发器侦听路径模式为 root.sg.** -- 所编写的触发器类名为 org.apache.iotdb.trigger.ClusterAlertingExample -- JAR 包的 URI 为 http://jar/ClusterAlertingExample.jar -- 创建该触发器实例时会传入 name 和 limit 两个参数。 - -### 卸载触发器 - -可以通过指定触发器 ID 的方式卸载触发器,卸载触发器的过程中会且仅会调用一次触发器的 `onDrop` 接口。 - -卸载触发器的 SQL 语法如下: - -```sql -// Drop Trigger -dropTrigger - : DROP TRIGGER triggerName=identifier -; -``` - -下面是示例语句: - -```sql -DROP TRIGGER triggerTest1 -``` - -上述语句将会卸载 ID 为 triggerTest1 的触发器。 - -### 查询触发器 - -可以通过 SQL 语句查询集群中存在的触发器的信息。SQL 语法如下: - -```sql -SHOW TRIGGERS -``` - -该语句的结果集格式如下: - -| TriggerName | Event | Type | State | PathPattern | ClassName | NodeId | -| ------------ | ---------------------------- | -------------------- | ------------------------------------------- | ----------- | --------------------------------------- | --------------------------------------- | -| triggerTest1 | BEFORE_INSERT / AFTER_INSERT | STATELESS / STATEFUL | INACTIVE / ACTIVE / DROPPING / TRANSFFERING | root.** | org.apache.iotdb.trigger.TriggerExample | ALL(STATELESS) / DATA_NODE_ID(STATEFUL) | - - -### 触发器状态说明 - -在集群中注册以及卸载触发器的过程中,我们维护了触发器的状态,下面是对这些状态的说明: - -| 状态 | 描述 | 是否建议写入进行 | -| ------------ | ------------------------------------------------------------ | ---------------- | -| INACTIVE | 执行 `CREATE TRIGGER` 的中间状态,集群刚在 ConfigNode 上记录该触发器的信息,还未在任何 DataNode 上激活该触发器 | 否 | -| ACTIVE | 执行 `CREATE TRIGGE` 成功后的状态,集群所有 DataNode 上的该触发器都已经可用 | 是 | -| DROPPING | 执行 `DROP TRIGGER` 的中间状态,集群正处在卸载该触发器的过程中 | 否 | -| TRANSFERRING | 集群正在进行该触发器实例位置的迁移 | 否 | - -## 重要注意事项 - -- 触发器从注册时开始生效,不对已有的历史数据进行处理。**即只有成功注册触发器之后发生的写入请求才会被触发器侦听到。** -- 触发器目前采用**同步触发**,所以编写时需要保证触发器效率,否则可能会大幅影响写入性能。**您需要自己保证触发器内部的并发安全性**。 -- 集群中**不能注册过多触发器**。因为触发器信息全量保存在 ConfigNode 中,并且在所有 DataNode 都有一份该信息的副本。 -- **建议注册触发器时停止写入**。注册触发器并不是一个原子操作,注册触发器时,会出现集群内部分节点已经注册了该触发器,部分节点尚未注册成功的中间状态。为了避免部分节点上的写入请求被触发器侦听到,部分节点上没有被侦听到的情况,我们建议注册触发器时不要执行写入。 -- 触发器将作为进程内程序执行,如果您的触发器编写不慎,内存占用过多,由于 IoTDB 并没有办法监控触发器所使用的内存,所以有 OOM 的风险。 -- 持有有状态触发器实例的节点宕机时,我们会尝试在另外的节点上恢复相应实例,在恢复过程中我们会调用一次触发器类的 restore 接口,您可以在该接口中实现恢复触发器所维护的状态的逻辑。 -- 触发器 JAR 包有大小限制,必须小于 min(`config_node_ratis_log_appender_buffer_size_max`, 2G),其中 `config_node_ratis_log_appender_buffer_size_max` 是一个配置项,具体含义可以参考 IOTDB 配置项说明。 -- **不同的 JAR 包中最好不要有全类名相同但功能实现不一样的类**。例如:触发器 trigger1、trigger2 分别对应资源 trigger1.jar、trigger2.jar。如果两个 JAR 包里都包含一个 `org.apache.iotdb.trigger.example.AlertListener` 类,当 `CREATE TRIGGER` 使用到这个类时,系统会随机加载其中一个 JAR 包中的类,最终导致触发器执行行为不一致以及其他的问题。 - -## 配置参数 - -| 配置项 | 含义 | -| ------------------------------------------------- | ---------------------------------------------- | -| *trigger_lib_dir* | 保存触发器 jar 包的目录位置 | -| *stateful\_trigger\_retry\_num\_when\_not\_found* | 有状态触发器触发无法找到触发器实例时的重试次数 | \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.3/User-Manual/UDF-development.md b/src/zh/UserGuide/V1.3.3/User-Manual/UDF-development.md deleted file mode 100644 index 24e0366ad..000000000 --- a/src/zh/UserGuide/V1.3.3/User-Manual/UDF-development.md +++ /dev/null @@ -1,721 +0,0 @@ -# UDF 开发 - -## 1. UDF 开发 - -### 1.1 UDF 依赖 - -如果您使用 [Maven](http://search.maven.org/) ,可以从 [Maven 库](http://search.maven.org/) 中搜索下面示例中的依赖。请注意选择和目标 IoTDB 服务器版本相同的依赖版本。 - -``` xml - - org.apache.iotdb - udf-api - 1.0.0 - provided - -``` - -### 1.2 UDTF(User Defined Timeseries Generating Function) - -编写一个 UDTF 需要继承`org.apache.iotdb.udf.api.UDTF`类,并至少实现`beforeStart`方法和一种`transform`方法。 - -#### 接口说明: - -| 接口定义 | 描述 | 是否必须 | -| :----------------------------------------------------------- | :----------------------------------------------------------- | ------------------------- | -| void validate(UDFParameterValidator validator) throws Exception | 在初始化方法`beforeStart`调用前执行,用于检测`UDFParameters`中用户输入的参数是否合法。 | 否 | -| void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) throws Exception | 初始化方法,在 UDTF 处理输入数据前,调用用户自定义的初始化行为。用户每执行一次 UDTF 查询,框架就会构造一个新的 UDF 类实例,该方法在每个 UDF 类实例被初始化时调用一次。在每一个 UDF 类实例的生命周期内,该方法只会被调用一次。 | 是 | -| Object transform(Row row) throws Exception` | 这个方法由框架调用。当您在`beforeStart`中选择以`MappableRowByRowAccessStrategy`的策略消费原始数据时,可以选用该方法进行数据处理。输入参数以`Row`的形式传入,输出结果通过返回值`Object`输出。 | 所有`transform`方法四选一 | -| void transform(Column[] columns, ColumnBuilder builder) throws Exception | 这个方法由框架调用。当您在`beforeStart`中选择以`MappableRowByRowAccessStrategy`的策略消费原始数据时,可以选用该方法进行数据处理。输入参数以`Column[]`的形式传入,输出结果通过`ColumnBuilder`输出。您需要在该方法内自行调用`builder`提供的数据收集方法,以决定最终的输出数据。 | 所有`transform`方法四选一 | -| void transform(Row row, PointCollector collector) throws Exception | 这个方法由框架调用。当您在`beforeStart`中选择以`RowByRowAccessStrategy`的策略消费原始数据时,这个数据处理方法就会被调用。输入参数以`Row`的形式传入,输出结果通过`PointCollector`输出。您需要在该方法内自行调用`collector`提供的数据收集方法,以决定最终的输出数据。 | 所有`transform`方法四选一 | -| void transform(RowWindow rowWindow, PointCollector collector) throws Exception | 这个方法由框架调用。当您在`beforeStart`中选择以`SlidingSizeWindowAccessStrategy`或者`SlidingTimeWindowAccessStrategy`的策略消费原始数据时,这个数据处理方法就会被调用。输入参数以`RowWindow`的形式传入,输出结果通过`PointCollector`输出。您需要在该方法内自行调用`collector`提供的数据收集方法,以决定最终的输出数据。 | 所有`transform`方法四选一 | -| void terminate(PointCollector collector) throws Exception | 这个方法由框架调用。该方法会在所有的`transform`调用执行完成后,在`beforeDestory`方法执行前被调用。在一个 UDF 查询过程中,该方法会且只会调用一次。您需要在该方法内自行调用`collector`提供的数据收集方法,以决定最终的输出数据。 | 否 | -| void beforeDestroy() | UDTF 的结束方法。此方法由框架调用,并且只会被调用一次,即在处理完最后一条记录之后被调用。 | 否 | - -在一个完整的 UDTF 实例生命周期中,各个方法的调用顺序如下: - -1. void validate(UDFParameterValidator validator) throws Exception -2. void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) throws Exception -3. Object transform(Row row) throws Exception 或着 void transform(Column[] columns, ColumnBuilder builder) throws Exception 或者 void transform(Row row, PointCollector collector) throws Exception 或者 void transform(RowWindow rowWindow, PointCollector collector) throws Exception -4. void terminate(PointCollector collector) throws Exception -5. void beforeDestroy() - -> 注意,框架每执行一次 UDTF 查询,都会构造一个全新的 UDF 类实例,查询结束时,对应的 UDF 类实例即被销毁,因此不同 UDTF 查询(即使是在同一个 SQL 语句中)UDF 类实例内部的数据都是隔离的。您可以放心地在 UDTF 中维护一些状态数据,无需考虑并发对 UDF 类实例内部状态数据的影响。 - -#### 接口详细介绍: - -1. **void validate(UDFParameterValidator validator) throws Exception** - - `validate`方法能够对用户输入的参数进行验证。 - - 您可以在该方法中限制输入序列的数量和类型,检查用户输入的属性或者进行自定义逻辑的验证。 - - `UDFParameterValidator`的使用方法请见 Javadoc。 - -2. **void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) throws Exception** - - `beforeStart`方法有两个作用: - 1. 帮助用户解析 SQL 语句中的 UDF 参数 - 2. 配置 UDF 运行时必要的信息,即指定 UDF 访问原始数据时采取的策略和输出结果序列的类型 - 3. 创建资源,比如建立外部链接,打开文件等 - -2.1 **UDFParameters** - -`UDFParameters`的作用是解析 SQL 语句中的 UDF 参数(SQL 中 UDF 函数名称后括号中的部分)。参数包括序列类型参数和字符串 key-value 对形式输入的属性参数。 - -示例: - -``` sql -SELECT UDF(s1, s2, 'key1'='iotdb', 'key2'='123.45') FROM root.sg.d; -``` - -用法: - -``` java -void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) throws Exception { - String stringValue = parameters.getString("key1"); // iotdb - Float floatValue = parameters.getFloat("key2"); // 123.45 - Double doubleValue = parameters.getDouble("key3"); // null - int intValue = parameters.getIntOrDefault("key4", 678); // 678 - // do something - - // configurations - // ... -} -``` - -2.2 **UDTFConfigurations** - -您必须使用 `UDTFConfigurations` 指定 UDF 访问原始数据时采取的策略和输出结果序列的类型。 - -用法: - -``` java -void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) throws Exception { - // parameters - // ... - - // configurations - configurations - .setAccessStrategy(new RowByRowAccessStrategy()) - .setOutputDataType(Type.INT32); -} -``` - -其中`setAccessStrategy`方法用于设定 UDF 访问原始数据时采取的策略,`setOutputDataType`用于设定输出结果序列的类型。 - - 2.2.1 **setAccessStrategy** - -注意,您在此处设定的原始数据访问策略决定了框架会调用哪一种`transform`方法 ,请实现与原始数据访问策略对应的`transform`方法。当然,您也可以根据`UDFParameters`解析出来的属性参数,动态决定设定哪一种策略,因此,实现两种`transform`方法也是被允许的。 - -下面是您可以设定的访问原始数据的策略: - -| 接口定义 | 描述 | 调用的`transform`方法 | -| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| MappableRowByRowStrategy | 自定义标量函数
框架会为每一行原始数据输入调用一次`transform`方法,输入 k 列时间序列 1 行数据,输出 1 列时间序列 1 行数据,可用于标量函数出现的任何子句和表达式中,如select子句、where子句等。 | void transform(Column[] columns, ColumnBuilder builder) throws ExceptionObject transform(Row row) throws Exception | -| RowByRowAccessStrategy | 自定义时间序列生成函数,逐行地处理原始数据。
框架会为每一行原始数据输入调用一次`transform`方法,输入 k 列时间序列 1 行数据,输出 1 列时间序列 n 行数据。
当输入一个序列时,该行就作为输入序列的一个数据点。
当输入多个序列时,输入序列按时间对齐后,每一行作为的输入序列的一个数据点。
(一行数据中,可能存在某一列为`null`值,但不会全部都是`null`) | void transform(Row row, PointCollector collector) throws Exception | -| SlidingTimeWindowAccessStrategy | 自定义时间序列生成函数,以滑动时间窗口的方式处理原始数据。
框架会为每一个原始数据输入窗口调用一次`transform`方法,输入 k 列时间序列 m 行数据,输出 1 列时间序列 n 行数据。
一个窗口可能存在多行数据,输入序列按时间对齐后,每个窗口作为的输入序列的一个数据点。
(每个窗口可能存在 i 行,每行数据可能存在某一列为`null`值,但不会全部都是`null`) | void transform(RowWindow rowWindow, PointCollector collector) throws Exception | -| SlidingSizeWindowAccessStrategy | 自定义时间序列生成函数,以固定行数的方式处理原始数据,即每个数据处理窗口都会包含固定行数的数据(最后一个窗口除外)。
框架会为每一个原始数据输入窗口调用一次`transform`方法,输入 k 列时间序列 m 行数据,输出 1 列时间序列 n 行数据。
一个窗口可能存在多行数据,输入序列按时间对齐后,每个窗口作为的输入序列的一个数据点。
(每个窗口可能存在 i 行,每行数据可能存在某一列为`null`值,但不会全部都是`null`) | void transform(RowWindow rowWindow, PointCollector collector) throws Exception | -| SessionTimeWindowAccessStrategy | 自定义时间序列生成函数,以会话窗口的方式处理原始数据。
框架会为每一个原始数据输入窗口调用一次`transform`方法,输入 k 列时间序列 m 行数据,输出 1 列时间序列 n 行数据。
一个窗口可能存在多行数据,输入序列按时间对齐后,每个窗口作为的输入序列的一个数据点。
(每个窗口可能存在 i 行,每行数据可能存在某一列为`null`值,但不会全部都是`null`) | void transform(RowWindow rowWindow, PointCollector collector) throws Exception | -| StateWindowAccessStrategy | 自定义时间序列生成函数,以状态窗口的方式处理原始数据。
框架会为每一个原始数据输入窗口调用一次`transform`方法,输入 1 列时间序列 m 行数据,输出 1 列时间序列 n 行数据。
一个窗口可能存在多行数据,目前仅支持对一个物理量也就是一列数据进行开窗。 | void transform(RowWindow rowWindow, PointCollector collector) throws Exception | - -#### 接口详情: - -- `MappableRowByRowStrategy` 和 `RowByRowAccessStrategy`的构造不需要任何参数。 - -- `SlidingTimeWindowAccessStrategy` - -开窗示意图: - - - -`SlidingTimeWindowAccessStrategy`有多种构造方法,您可以向构造方法提供 3 类参数: - -1. 时间轴显示时间窗开始和结束时间 - -时间轴显示时间窗开始和结束时间不是必须要提供的。当您不提供这类参数时,时间轴显示时间窗开始时间会被定义为整个查询结果集中最小的时间戳,时间轴显示时间窗结束时间会被定义为整个查询结果集中最大的时间戳。 - -2. 划分时间轴的时间间隔参数(必须为正数) -3. 滑动步长(不要求大于等于时间间隔,但是必须为正数) - -滑动步长参数也不是必须的。当您不提供滑动步长参数时,滑动步长会被设定为划分时间轴的时间间隔。 - -3 类参数的关系可见下图。策略的构造方法详见 Javadoc。 - - - -> 注意,最后的一些时间窗口的实际时间间隔可能小于规定的时间间隔参数。另外,可能存在某些时间窗口内数据行数量为 0 的情况,这种情况框架也会为该窗口调用一次`transform`方法。 - -- `SlidingSizeWindowAccessStrategy` - -开窗示意图: - - - -`SlidingSizeWindowAccessStrategy`有多种构造方法,您可以向构造方法提供 2 个参数: - -1. 窗口大小,即一个数据处理窗口包含的数据行数。注意,最后一些窗口的数据行数可能少于规定的数据行数。 -2. 滑动步长,即下一窗口第一个数据行与当前窗口第一个数据行间的数据行数(不要求大于等于窗口大小,但是必须为正数) - -滑动步长参数不是必须的。当您不提供滑动步长参数时,滑动步长会被设定为窗口大小。 - -- `SessionTimeWindowAccessStrategy` - -开窗示意图:**时间间隔小于等于给定的最小时间间隔 sessionGap 则分为一组。** - - - - -`SessionTimeWindowAccessStrategy`有多种构造方法,您可以向构造方法提供 2 类参数: - -1. 时间轴显示时间窗开始和结束时间。 -2. 会话窗口之间的最小时间间隔。 - -- `StateWindowAccessStrategy` - -开窗示意图:**对于数值型数据,状态差值小于等于给定的阈值 delta 则分为一组。** - - - -`StateWindowAccessStrategy`有四种构造方法: - -1. 针对数值型数据,可以提供时间轴显示时间窗开始和结束时间以及对于单个窗口内部允许变化的阈值delta。 -2. 针对文本数据以及布尔数据,可以提供时间轴显示时间窗开始和结束时间。对于这两种数据类型,单个窗口内的数据是相同的,不需要提供变化阈值。 -3. 针对数值型数据,可以只提供单个窗口内部允许变化的阈值delta,时间轴显示时间窗开始时间会被定义为整个查询结果集中最小的时间戳,时间轴显示时间窗结束时间会被定义为整个查询结果集中最大的时间戳。 -4. 针对文本数据以及布尔数据,可以不提供任何参数,开始与结束时间戳见3中解释。 - -StateWindowAccessStrategy 目前只能接收一列输入。策略的构造方法详见 Javadoc。 - - 2.2.2 **setOutputDataType** - -注意,您在此处设定的输出结果序列的类型,决定了`transform`方法中`PointCollector`实际能够接收的数据类型。`setOutputDataType`中设定的输出类型和`PointCollector`实际能够接收的数据输出类型关系如下: - -| `setOutputDataType`中设定的输出类型 | `PointCollector`实际能够接收的输出类型 | -| :---------------------------------- | :----------------------------------------------------------- | -| INT32 | int | -| INT64 | long | -| FLOAT | float | -| DOUBLE | double | -| BOOLEAN | boolean | -| TEXT | java.lang.String 和 org.apache.iotdb.udf.api.type.Binary | - -UDTF 输出序列的类型是运行时决定的。您可以根据输入序列类型动态决定输出序列类型。 - -示例: - -```java -void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) throws Exception { - // do something - // ... - - configurations - .setAccessStrategy(new RowByRowAccessStrategy()) - .setOutputDataType(parameters.getDataType(0)); -} -``` - -3. **Object transform(Row row) throws Exception** - -当您在`beforeStart`方法中指定 UDF 读取原始数据的策略为 `MappableRowByRowAccessStrategy`,您就需要该方法和下面的`void transform(Column[] columns, ColumnBuilder builder) throws Exception` 二选一来实现,在该方法中增加对原始数据处理的逻辑。 - -该方法每次处理原始数据的一行。原始数据由`Row`读入,由返回值输出。您必须在一次`transform`方法调用中,根据每个输入的数据点输出一个对应的数据点,即输入和输出依然是一对一的。需要注意的是,输出数据点的类型必须与您在`beforeStart`方法中设置的一致,而输出数据点的时间戳必须是严格单调递增的。 - -下面是一个实现了`Object transform(Row row) throws Exception`方法的完整 UDF 示例。它是一个加法器,接收两列时间序列输入,输出这两个数据点的代数和。 - -```java -import org.apache.iotdb.udf.api.UDTF; -import org.apache.iotdb.udf.api.access.Row; -import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations; -import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator; -import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters; -import org.apache.iotdb.udf.api.customizer.strategy.MappableRowByRowAccessStrategy; -import org.apache.iotdb.udf.api.type.Type; - -public class Adder implements UDTF { - private Type dataType; - - @Override - public void validate(UDFParameterValidator validator) throws Exception { - validator - .validateInputSeriesNumber(2) - .validateInputSeriesDataType(0, Type.INT64) - .validateInputSeriesDataType(1, Type.INT64); - } - - @Override - public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) { - dataType = parameters.getDataType(0); - configurations - .setAccessStrategy(new MappableRowByRowAccessStrategy()) - .setOutputDataType(dataType); - } - - @Override - public Object transform(Row row) throws Exception { - return row.getLong(0) + row.getLong(1); - } -} -``` - -4. **void transform(Column[] columns, ColumnBuilder builder) throws Exception** - -当您在`beforeStart`方法中指定 UDF 读取原始数据的策略为 `MappableRowByRowAccessStrategy`,您就需要实现该方法,在该方法中增加对原始数据处理的逻辑。 - -该方法每次处理原始数据的多行,经过性能测试,我们发现一次性处理多行的 UDTF 比一次处理一行的 UDTF 性能更好。原始数据由`Column[]`读入,由`ColumnBuilder`输出。您必须在一次`transform`方法调用中,根据每个输入的数据点输出一个对应的数据点,即输入和输出依然是一对一的。需要注意的是,输出数据点的类型必须与您在`beforeStart`方法中设置的一致,而输出数据点的时间戳必须是严格单调递增的。 - -下面是一个实现了`void transform(Column[] columns, ColumnBuilder builder) throws Exceptionn`方法的完整 UDF 示例。它是一个加法器,接收两列时间序列输入,输出这两个数据点的代数和。 - -``` java -import org.apache.iotdb.tsfile.read.common.block.column.Column; -import org.apache.iotdb.tsfile.read.common.block.column.ColumnBuilder; -import org.apache.iotdb.udf.api.UDTF; -import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations; -import org.apache.iotdb.udf.api.customizer.parameter.UDFParameterValidator; -import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters; -import org.apache.iotdb.udf.api.customizer.strategy.MappableRowByRowAccessStrategy; -import org.apache.iotdb.udf.api.type.Type; - -public class Adder implements UDTF { - private Type type; - - @Override - public void validate(UDFParameterValidator validator) throws Exception { - validator - .validateInputSeriesNumber(2) - .validateInputSeriesDataType(0, Type.INT64) - .validateInputSeriesDataType(1, Type.INT64); - } - - @Override - public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) { - type = parameters.getDataType(0); - configurations.setAccessStrategy(new MappableRowByRowAccessStrategy()).setOutputDataType(type); - } - - @Override - public void transform(Column[] columns, ColumnBuilder builder) throws Exception { - long[] inputs1 = columns[0].getLongs(); - long[] inputs2 = columns[1].getLongs(); - - int count = columns[0].getPositionCount(); - for (int i = 0; i < count; i++) { - builder.writeLong(inputs1[i] + inputs2[i]); - } - } -} -``` - -5. **void transform(Row row, PointCollector collector) throws Exception** - -当您在`beforeStart`方法中指定 UDF 读取原始数据的策略为 `RowByRowAccessStrategy`,您就需要实现该方法,在该方法中增加对原始数据处理的逻辑。 - -该方法每次处理原始数据的一行。原始数据由`Row`读入,由`PointCollector`输出。您可以选择在一次`transform`方法调用中输出任意数量的数据点。需要注意的是,输出数据点的类型必须与您在`beforeStart`方法中设置的一致,而输出数据点的时间戳必须是严格单调递增的。 - -下面是一个实现了`void transform(Row row, PointCollector collector) throws Exception`方法的完整 UDF 示例。它是一个加法器,接收两列时间序列输入,当这两个数据点都不为`null`时,输出这两个数据点的代数和。 - -``` java -import org.apache.iotdb.udf.api.UDTF; -import org.apache.iotdb.udf.api.access.Row; -import org.apache.iotdb.udf.api.collector.PointCollector; -import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations; -import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters; -import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy; -import org.apache.iotdb.udf.api.type.Type; - -public class Adder implements UDTF { - - @Override - public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) { - configurations - .setOutputDataType(Type.INT64) - .setAccessStrategy(new RowByRowAccessStrategy()); - } - - @Override - public void transform(Row row, PointCollector collector) throws Exception { - if (row.isNull(0) || row.isNull(1)) { - return; - } - collector.putLong(row.getTime(), row.getLong(0) + row.getLong(1)); - } -} -``` - -6. **void transform(RowWindow rowWindow, PointCollector collector) throws Exception** - -当您在`beforeStart`方法中指定 UDF 读取原始数据的策略为 `SlidingTimeWindowAccessStrategy`或者`SlidingSizeWindowAccessStrategy`时,您就需要实现该方法,在该方法中增加对原始数据处理的逻辑。 - -该方法每次处理固定行数或者固定时间间隔内的一批数据,我们称包含这一批数据的容器为窗口。原始数据由`RowWindow`读入,由`PointCollector`输出。`RowWindow`能够帮助您访问某一批次的`Row`,它提供了对这一批次的`Row`进行随机访问和迭代访问的接口。您可以选择在一次`transform`方法调用中输出任意数量的数据点,需要注意的是,输出数据点的类型必须与您在`beforeStart`方法中设置的一致,而输出数据点的时间戳必须是严格单调递增的。 - -下面是一个实现了`void transform(RowWindow rowWindow, PointCollector collector) throws Exception`方法的完整 UDF 示例。它是一个计数器,接收任意列数的时间序列输入,作用是统计并输出指定时间范围内每一个时间窗口中的数据行数。 - -```java -import java.io.IOException; -import org.apache.iotdb.udf.api.UDTF; -import org.apache.iotdb.udf.api.access.RowWindow; -import org.apache.iotdb.udf.api.collector.PointCollector; -import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations; -import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters; -import org.apache.iotdb.udf.api.customizer.strategy.SlidingTimeWindowAccessStrategy; -import org.apache.iotdb.udf.api.type.Type; - -public class Counter implements UDTF { - - @Override - public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) { - configurations - .setOutputDataType(Type.INT32) - .setAccessStrategy(new SlidingTimeWindowAccessStrategy( - parameters.getLong("time_interval"), - parameters.getLong("sliding_step"), - parameters.getLong("display_window_begin"), - parameters.getLong("display_window_end"))); - } - - @Override - public void transform(RowWindow rowWindow, PointCollector collector) throws Exception { - if (rowWindow.windowSize() != 0) { - collector.putInt(rowWindow.windowStartTime(), rowWindow.windowSize()); - } - } -} -``` - -7. **void terminate(PointCollector collector) throws Exception** - -在一些场景下,UDF 需要遍历完所有的原始数据后才能得到最后的输出结果。`terminate`接口为这类 UDF 提供了支持。 - -该方法会在所有的`transform`调用执行完成后,在`beforeDestory`方法执行前被调用。您可以选择使用`transform`方法进行单纯的数据处理,最后使用`terminate`将处理结果输出。 - -结果需要由`PointCollector`输出。您可以选择在一次`terminate`方法调用中输出任意数量的数据点。需要注意的是,输出数据点的类型必须与您在`beforeStart`方法中设置的一致,而输出数据点的时间戳必须是严格单调递增的。 - -下面是一个实现了`void terminate(PointCollector collector) throws Exception`方法的完整 UDF 示例。它接收一个`INT32`类型的时间序列输入,作用是输出该序列的最大值点。 - -```java -import java.io.IOException; -import org.apache.iotdb.udf.api.UDTF; -import org.apache.iotdb.udf.api.access.Row; -import org.apache.iotdb.udf.api.collector.PointCollector; -import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations; -import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters; -import org.apache.iotdb.udf.api.customizer.strategy.RowByRowAccessStrategy; -import org.apache.iotdb.udf.api.type.Type; - -public class Max implements UDTF { - - private Long time; - private int value; - - @Override - public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) { - configurations - .setOutputDataType(TSDataType.INT32) - .setAccessStrategy(new RowByRowAccessStrategy()); - } - - @Override - public void transform(Row row, PointCollector collector) { - if (row.isNull(0)) { - return; - } - int candidateValue = row.getInt(0); - if (time == null || value < candidateValue) { - time = row.getTime(); - value = candidateValue; - } - } - - @Override - public void terminate(PointCollector collector) throws IOException { - if (time != null) { - collector.putInt(time, value); - } - } -} -``` - -8. **void beforeDestroy()** - -UDTF 的结束方法,您可以在此方法中进行一些资源释放等的操作。 - -此方法由框架调用。对于一个 UDF 类实例而言,生命周期中会且只会被调用一次,即在处理完最后一条记录之后被调用。 - -### 1.3 UDAF(User Defined Aggregation Function) - -一个完整的 UDAF 定义涉及到 State 和 UDAF 两个类。 - -#### State 类 - -编写一个 State 类需要实现`org.apache.iotdb.udf.api.State`接口,下表是需要实现的方法说明。 - -#### 接口说明: - -| 接口定义 | 描述 | 是否必须 | -| -------------------------------- | ------------------------------------------------------------ | -------- | -| void reset() | 将 `State` 对象重置为初始的状态,您需要像编写构造函数一样,在该方法内填入 `State` 类中各个字段的初始值。 | 是 | -| byte[] serialize() | 将 `State` 序列化为二进制数据。该方法用于 IoTDB 内部的 `State` 对象传递,注意序列化的顺序必须和下面的反序列化方法一致。 | 是 | -| void deserialize(byte[] bytes) | 将二进制数据反序列化为 `State`。该方法用于 IoTDB 内部的 `State` 对象传递,注意反序列化的顺序必须和上面的序列化方法一致。 | 是 | - -#### 接口详细介绍: - -1. **void reset()** - -该方法的作用是将 `State` 重置为初始的状态,您需要在该方法内填写 `State` 对象中各个字段的初始值。出于优化上的考量,IoTDB 在内部会尽可能地复用 `State`,而不是为每一个组创建一个新的 `State`,这样会引入不必要的开销。当 `State` 更新完一个组中的数据之后,就会调用这个方法重置为初始状态,以此来处理下一个组。 - -以求平均数(也就是 `avg`)的 `State` 为例,您需要数据的总和 `sum` 与数据的条数 `count`,并在 `reset()` 方法中将二者初始化为 0。 - -```java -class AvgState implements State { - double sum; - - long count; - - @Override - public void reset() { - sum = 0; - count = 0; - } - - // other methods -} -``` - -2. **byte[] serialize()/void deserialize(byte[] bytes)** - -该方法的作用是将 State 序列化为二进制数据,和从二进制数据中反序列化出 State。IoTDB 作为分布式数据库,涉及到在不同节点中传递数据,因此您需要编写这两个方法,来实现 State 在不同节点中的传递。注意序列化和反序列的顺序必须一致。 - -还是以求平均数(也就是求 avg)的 State 为例,您可以通过任意途径将 State 的内容转化为 `byte[]` 数组,以及从 `byte[]` 数组中读取出 State 的内容,下面展示的是用 Java8 引入的 `ByteBuffer` 进行序列化/反序列的代码: - -```java -@Override -public byte[] serialize() { - ByteBuffer buffer = ByteBuffer.allocate(Double.BYTES + Long.BYTES); - buffer.putDouble(sum); - buffer.putLong(count); - - return buffer.array(); -} - -@Override -public void deserialize(byte[] bytes) { - ByteBuffer buffer = ByteBuffer.wrap(bytes); - sum = buffer.getDouble(); - count = buffer.getLong(); -} -``` - -#### UDAF 类 - -编写一个 UDAF 类需要实现`org.apache.iotdb.udf.api.UDAF`接口,下表是需要实现的方法说明。 - -#### 接口说明: - -| 接口定义 | 描述 | 是否必须 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -| void validate(UDFParameterValidator validator) throws Exception | 在初始化方法`beforeStart`调用前执行,用于检测`UDFParameters`中用户输入的参数是否合法。该方法与 UDTF 的`validate`相同。 | 否 | -| void beforeStart(UDFParameters parameters, UDAFConfigurations configurations) throws Exception | 初始化方法,在 UDAF 处理输入数据前,调用用户自定义的初始化行为。与 UDTF 不同的是,这里的 configuration 是 `UDAFConfiguration` 类型。 | 是 | -| State createState() | 创建`State`对象,一般只需要调用默认构造函数,然后按需修改默认的初始值即可。 | 是 | -| void addInput(State state, Column[] columns, BitMap bitMap) | 根据传入的数据`Column[]`批量地更新`State`对象,注意最后一列,也就是 `columns[columns.length - 1]` 总是代表时间列。另外`BitMap`表示之前已经被过滤掉的数据,您在编写该方法时需要手动判断对应的数据是否被过滤掉。 | 是 | -| void combineState(State state, State rhs) | 将`rhs`状态合并至`state`状态中。在分布式场景下,同一组的数据可能分布在不同节点上,IoTDB 会为每个节点上的部分数据生成一个`State`对象,然后调用该方法合并成完整的`State`。 | 是 | -| void outputFinal(State state, ResultValue resultValue) | 根据`State`中的数据,计算出最终的聚合结果。注意根据聚合的语义,每一组只能输出一个值。 | 是 | -| void beforeDestroy() | UDAF 的结束方法。此方法由框架调用,并且只会被调用一次,即在处理完最后一条记录之后被调用。 | 否 | - -在一个完整的 UDAF 实例生命周期中,各个方法的调用顺序如下: - -1. State createState() -2. void validate(UDFParameterValidator validator) throws Exception -3. void beforeStart(UDFParameters parameters, UDAFConfigurations configurations) throws Exception -4. void addInput(State state, Column[] columns, BitMap bitMap) -5. void combineState(State state, State rhs) -6. void outputFinal(State state, ResultValue resultValue) -7. void beforeDestroy() - -和 UDTF 类似,框架每执行一次 UDAF 查询,都会构造一个全新的 UDF 类实例,查询结束时,对应的 UDF 类实例即被销毁,因此不同 UDAF 查询(即使是在同一个 SQL 语句中)UDF 类实例内部的数据都是隔离的。您可以放心地在 UDAF 中维护一些状态数据,无需考虑并发对 UDF 类实例内部状态数据的影响。 - -#### 接口详细介绍: - -1. **void validate(UDFParameterValidator validator) throws Exception** - -同 UDTF, `validate`方法能够对用户输入的参数进行验证。 - -您可以在该方法中限制输入序列的数量和类型,检查用户输入的属性或者进行自定义逻辑的验证。 - -2. **void beforeStart(UDFParameters parameters, UDAFConfigurations configurations) throws Exception** - - `beforeStart`方法的作用 UDAF 相同: - - 1. 帮助用户解析 SQL 语句中的 UDF 参数 - 2. 配置 UDF 运行时必要的信息,即指定 UDF 访问原始数据时采取的策略和输出结果序列的类型 - 3. 创建资源,比如建立外部链接,打开文件等。 - -其中,`UDFParameters` 类型的作用可以参照上文。 - -2.2 **UDTFConfigurations** - -和 UDTF 的区别在于,UDAF 使用了 `UDAFConfigurations` 作为 `configuration` 对象的类型。 - -目前,该类仅支持设置输出数据的类型。 - -```java -void beforeStart(UDFParameters parameters, UDAFConfigurations configurations) throws Exception { - // parameters - // ... - - // configurations - configurations - .setOutputDataType(Type.INT32); -} -``` - -`setOutputDataType` 中设定的输出类型和 `ResultValue` 实际能够接收的数据输出类型关系如下: - -| `setOutputDataType`中设定的输出类型 | `ResultValue`实际能够接收的输出类型 | -| :---------------------------------- | :------------------------------------- | -| INT32 | int | -| INT64 | long | -| FLOAT | float | -| DOUBLE | double | -| BOOLEAN | boolean | -| TEXT | org.apache.iotdb.udf.api.type.Binary | - -UDAF 输出序列的类型也是运行时决定的。您可以根据输入序列类型动态决定输出序列类型。 - -示例: - -```java -void beforeStart(UDFParameters parameters, UDAFConfigurations configurations) throws Exception { - // do something - // ... - - configurations - .setOutputDataType(parameters.getDataType(0)); -} -``` - -3. **State createState()** - -为 UDAF 创建并初始化 `State`。由于 Java 语言本身的限制,您只能调用 `State` 类的默认构造函数。默认构造函数会为类中所有的字段赋一个默认的初始值,如果该初始值并不符合您的要求,您需要在这个方法内进行手动的初始化。 - -下面是一个包含手动初始化的例子。假设您要实现一个累乘的聚合函数,`State` 的初始值应该设置为 1,但是默认构造函数会初始化为 0,因此您需要在调用默认构造函数之后,手动对 `State` 进行初始化: - -```java -public State createState() { - MultiplyState state = new MultiplyState(); - state.result = 1; - return state; -} -``` - -4. **void addInput(State state, Column[] columns, BitMap bitMap)** - -该方法的作用是,通过原始的输入数据来更新 `State` 对象。出于性能上的考量,也是为了和 IoTDB 向量化的查询引擎相对齐,原始的输入数据不再是一个数据点,而是列的数组 `Column[]`。注意最后一列(也就是 `columns[columns.length - 1]` )总是时间列,因此您也可以在 UDAF 中根据时间进行不同的操作。 - -由于输入参数的类型不是一个数据点,而是多个列,您需要手动对列中的部分数据进行过滤处理,这就是第三个参数 `BitMap` 存在的意义。它用来标识这些列中哪些数据被过滤掉了,您在任何情况下都无需考虑被过滤掉的数据。 - -下面是一个用于统计数据条数(也就是 count)的 `addInput()` 示例。它展示了您应该如何使用 `BitMap` 来忽视那些已经被过滤掉的数据。注意还是由于 Java 语言本身的限制,您需要在方法的开头将接口中定义的 `State` 类型强制转化为自定义的 `State` 类型,不然后续无法正常使用该 `State` 对象。 - -```java -public void addInput(State state, Column[] columns, BitMap bitMap) { - CountState countState = (CountState) state; - - int count = columns[0].getPositionCount(); - for (int i = 0; i < count; i++) { - if (bitMap != null && !bitMap.isMarked(i)) { - continue; - } - if (!columns[0].isNull(i)) { - countState.count++; - } - } -} -``` - -5. **void combineState(State state, State rhs)** - -该方法的作用是合并两个 `State`,更加准确的说,是用第二个 `State` 对象来更新第一个 `State` 对象。IoTDB 是分布式数据库,同一组的数据可能分布在多个不同的节点上。出于性能考虑,IoTDB 会为每个节点上的部分数据先进行聚合成 `State`,然后再将不同节点上的、属于同一个组的 `State` 进行合并,这就是 `combineState` 的作用。 - -下面是一个用于求平均数(也就是 avg)的 `combineState()` 示例。和 `addInput` 类似,您都需要在开头对两个 `State` 进行强制类型转换。另外需要注意是用第二个 `State` 的内容来更新第一个 `State` 的值。 - -```java -public void combineState(State state, State rhs) { - AvgState avgState = (AvgState) state; - AvgState avgRhs = (AvgState) rhs; - - avgState.count += avgRhs.count; - avgState.sum += avgRhs.sum; -} -``` - -6. **void outputFinal(State state, ResultValue resultValue)** - -该方法的作用是从 `State` 中计算出最终的结果。您需要访问 `State` 中的各个字段,求出最终的结果,并将最终的结果设置到 `ResultValue` 对象中。IoTDB 内部会为每个组在最后调用一次这个方法。注意根据聚合的语义,最终的结果只能是一个值。 - -下面还是一个用于求平均数(也就是 avg)的 `outputFinal` 示例。除了开头的强制类型转换之外,您还将看到 `ResultValue` 对象的具体用法,即通过 `setXXX`(其中 `XXX` 是类型名)来设置最后的结果。 - -```java -public void outputFinal(State state, ResultValue resultValue) { - AvgState avgState = (AvgState) state; - - if (avgState.count != 0) { - resultValue.setDouble(avgState.sum / avgState.count); - } else { - resultValue.setNull(); - } -} -``` - -7. **void beforeDestroy()** - -UDAF 的结束方法,您可以在此方法中进行一些资源释放等的操作。 - -此方法由框架调用。对于一个 UDF 类实例而言,生命周期中会且只会被调用一次,即在处理完最后一条记录之后被调用。 - -### 1.4 完整 Maven 项目示例 - -如果您使用 [Maven](http://search.maven.org/),可以参考我们编写的示例项目**udf-example**。您可以在 [这里](https://github.com/apache/iotdb/tree/master/example/udf) 找到它。 - - -## 2. 为iotdb贡献通用的内置UDF函数 - -该部分主要讲述了外部用户如何将自己编写的 UDF 贡献给 IoTDB 社区。 - -## 2.1 前提条件 - -1. UDF 具有通用性。 - - 通用性主要指的是:UDF 在某些业务场景下,可以被广泛使用。换言之,就是 UDF 具有复用价值,可被社区内其他用户直接使用。 - - 如果不确定自己写的 UDF 是否具有通用性,可以发邮件到 `dev@iotdb.apache.org` 或直接创建 ISSUE 发起讨论。 - -2. UDF 已经完成测试,且能够正常运行在用户的生产环境中。 - -### 2.2 贡献清单 - -1. UDF 的源代码 -2. UDF 的测试用例 -3. UDF 的使用说明 - -### 2.3 贡献内容 - -#### 2.3.1 源代码 - -1. 在`iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin`中创建 UDF 主类和相关的辅助类。 -2. 在`iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/BuiltinTimeSeriesGeneratingFunction.java`中注册编写的 UDF。 - -#### 2.3.2 测试用例 - -至少需要为贡献的 UDF 编写集成测试。 - -可以在`integration-test/src/test/java/org/apache/iotdb/db/it/udf`中为贡献的 UDF 新增一个测试类进行测试。 - -#### 2.3.3 使用说明 - -使用说明需要包含:UDF 的名称、UDF 的作用、执行函数必须的属性参数、函数的适用的场景以及使用示例等。 - -使用说明需包含中英文两个版本。应分别在 `docs/zh/UserGuide/Operation Manual/DML Data Manipulation Language.md` 和 `docs/UserGuide/Operation Manual/DML Data Manipulation Language.md` 中新增使用说明。 - -#### 2.3.4 提交 PR - -当准备好源代码、测试用例和使用说明后,就可以将 UDF 贡献到 IoTDB 社区了。在 [Github](https://github.com/apache/iotdb) 上面提交 Pull Request (PR) 即可。具体提交方式见:[贡献指南](https://iotdb.apache.org/zh/Community/Development-Guide.html)。 - -当 PR 评审通过并被合并后, UDF 就已经贡献给 IoTDB 社区了! \ No newline at end of file diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-CSharp-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-CSharp-Native-API.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/API/Programming-CSharp-Native-API.md rename to src/zh/UserGuide/V1.3.x/API/Programming-CSharp-Native-API.md diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-Cpp-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-Cpp-Native-API.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/Programming-Cpp-Native-API.md rename to src/zh/UserGuide/V1.3.x/API/Programming-Cpp-Native-API.md diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-Data-Subscription.md b/src/zh/UserGuide/V1.3.x/API/Programming-Data-Subscription.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/Programming-Data-Subscription.md rename to src/zh/UserGuide/V1.3.x/API/Programming-Data-Subscription.md diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-Go-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-Go-Native-API.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/API/Programming-Go-Native-API.md rename to src/zh/UserGuide/V1.3.x/API/Programming-Go-Native-API.md diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-JDBC.md b/src/zh/UserGuide/V1.3.x/API/Programming-JDBC.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/Programming-JDBC.md rename to src/zh/UserGuide/V1.3.x/API/Programming-JDBC.md diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-Java-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-Java-Native-API.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/Programming-Java-Native-API.md rename to src/zh/UserGuide/V1.3.x/API/Programming-Java-Native-API.md diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-Kafka.md b/src/zh/UserGuide/V1.3.x/API/Programming-Kafka.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/API/Programming-Kafka.md rename to src/zh/UserGuide/V1.3.x/API/Programming-Kafka.md diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-MQTT.md b/src/zh/UserGuide/V1.3.x/API/Programming-MQTT.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/Programming-MQTT.md rename to src/zh/UserGuide/V1.3.x/API/Programming-MQTT.md diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-NodeJS-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-NodeJS-Native-API.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/API/Programming-NodeJS-Native-API.md rename to src/zh/UserGuide/V1.3.x/API/Programming-NodeJS-Native-API.md diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-ODBC.md b/src/zh/UserGuide/V1.3.x/API/Programming-ODBC.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/API/Programming-ODBC.md rename to src/zh/UserGuide/V1.3.x/API/Programming-ODBC.md diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-OPC-UA_timecho.md b/src/zh/UserGuide/V1.3.x/API/Programming-OPC-UA_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/Programming-OPC-UA_timecho.md rename to src/zh/UserGuide/V1.3.x/API/Programming-OPC-UA_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/API/Programming-Python-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-Python-Native-API.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/Programming-Python-Native-API.md rename to src/zh/UserGuide/V1.3.x/API/Programming-Python-Native-API.md diff --git a/src/zh/UserGuide/V1.3.0-2/API/Programming-Rust-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-Rust-Native-API.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/API/Programming-Rust-Native-API.md rename to src/zh/UserGuide/V1.3.x/API/Programming-Rust-Native-API.md diff --git a/src/zh/UserGuide/V1.3.3/API/RestServiceV1.md b/src/zh/UserGuide/V1.3.x/API/RestServiceV1.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/RestServiceV1.md rename to src/zh/UserGuide/V1.3.x/API/RestServiceV1.md diff --git a/src/zh/UserGuide/V1.3.3/API/RestServiceV2.md b/src/zh/UserGuide/V1.3.x/API/RestServiceV2.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/API/RestServiceV2.md rename to src/zh/UserGuide/V1.3.x/API/RestServiceV2.md diff --git a/src/zh/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept.md b/src/zh/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept.md rename to src/zh/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept.md diff --git a/src/zh/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_apache.md b/src/zh/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_apache.md rename to src/zh/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_apache.md diff --git a/src/zh/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_timecho.md b/src/zh/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Background-knowledge/Cluster-Concept_timecho.md rename to src/zh/UserGuide/V1.3.x/Background-knowledge/Cluster-Concept_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/Background-knowledge/Data-Type.md b/src/zh/UserGuide/V1.3.x/Background-knowledge/Data-Type.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Background-knowledge/Data-Type.md rename to src/zh/UserGuide/V1.3.x/Background-knowledge/Data-Type.md diff --git a/src/zh/UserGuide/V1.3.3/Basic-Concept/Data-Model-and-Terminology.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Data-Model-and-Terminology.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Basic-Concept/Data-Model-and-Terminology.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Data-Model-and-Terminology.md diff --git a/src/zh/UserGuide/V1.3.0-2/Basic-Concept/Navigating_Time_Series_Data.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Navigating_Time_Series_Data.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Basic-Concept/Navigating_Time_Series_Data.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Navigating_Time_Series_Data.md diff --git a/src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/User-Manual/Operate-Metadata.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata.md diff --git a/src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_apache.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_apache.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_apache.md diff --git a/src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_timecho.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Basic-Concept/Operate-Metadata_timecho.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Operate-Metadata_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/Basic-Concept/Query-Data.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Query-Data.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Basic-Concept/Query-Data.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Query-Data.md diff --git a/src/zh/UserGuide/V1.3.3/Basic-Concept/Write-Delete-Data.md b/src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Basic-Concept/Write-Delete-Data.md rename to src/zh/UserGuide/V1.3.x/Basic-Concept/Write-Delete-Data.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_apache.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_apache.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_apache.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_timecho.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/AINode_Deployment_timecho.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/AINode_Deployment_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_apache.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_apache.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_apache.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_timecho.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Cluster-Deployment_timecho.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Cluster-Deployment_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Database-Resources.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Database-Resources.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Database-Resources.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Database-Resources.md diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Docker-Deployment_apache.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Docker-Deployment_apache.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_apache.md diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Docker-Deployment_timecho.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Docker-Deployment_timecho.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Docker-Deployment_timecho.md diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Dual-Active-Deployment_timecho.md diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Environment-Requirements.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Environment-Requirements.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/Environment-Requirements.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Environment-Requirements.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_apache.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/IoTDB-Package_apache.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_apache.md diff --git a/src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/IoTDB-Package_timecho.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Deployment-and-Maintenance/IoTDB-Package_timecho.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/IoTDB-Package_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Monitoring-panel-deployment.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Monitoring-panel-deployment.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Monitoring-panel-deployment.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Monitoring-panel-deployment.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Slow-Query-Management.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Slow-Query-Management.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Slow-Query-Management.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Slow-Query-Management.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_apache.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/Stand-Alone-Deployment_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/workbench-deployment_timecho.md b/src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/workbench-deployment_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Deployment-and-Maintenance/workbench-deployment_timecho.md rename to src/zh/UserGuide/V1.3.x/Deployment-and-Maintenance/workbench-deployment_timecho.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/DBeaver.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/DBeaver.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/DBeaver.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/DBeaver.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/DataEase.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/DataEase.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/DataEase.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/DataEase.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Flink-IoTDB.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Flink-IoTDB.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Flink-IoTDB.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Flink-IoTDB.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Flink-TsFile.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Flink-TsFile.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Flink-TsFile.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Flink-TsFile.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Grafana-Connector.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Connector.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Grafana-Connector.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Connector.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Plugin.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Plugin.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Grafana-Plugin.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Grafana-Plugin.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Hive-TsFile.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Hive-TsFile.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Hive-TsFile.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Hive-TsFile.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Ignition-IoTDB-plugin_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_apache.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_apache.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_apache.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_timecho.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Kubernetes_timecho.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Kubernetes_timecho.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/NiFi-IoTDB.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/NiFi-IoTDB.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/NiFi-IoTDB.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/NiFi-IoTDB.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Spark-IoTDB.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Spark-IoTDB.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Spark-IoTDB.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Spark-IoTDB.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Spark-TsFile.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Spark-TsFile.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Spark-TsFile.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Spark-TsFile.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Telegraf.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Telegraf.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Telegraf.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Telegraf.md diff --git a/src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Thingsboard.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Thingsboard.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Ecosystem-Integration/Thingsboard.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Thingsboard.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Zeppelin-IoTDB_apache.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Zeppelin-IoTDB_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Zeppelin-IoTDB_apache.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Zeppelin-IoTDB_apache.md diff --git a/src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md b/src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md rename to src/zh/UserGuide/V1.3.x/Ecosystem-Integration/Zeppelin-IoTDB_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/FAQ/Frequently-asked-questions.md b/src/zh/UserGuide/V1.3.x/FAQ/Frequently-asked-questions.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/FAQ/Frequently-asked-questions.md rename to src/zh/UserGuide/V1.3.x/FAQ/Frequently-asked-questions.md diff --git a/src/zh/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_apache.md b/src/zh/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_apache.md rename to src/zh/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_apache.md diff --git a/src/zh/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_timecho.md b/src/zh/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/IoTDB-Introduction/IoTDB-Introduction_timecho.md rename to src/zh/UserGuide/V1.3.x/IoTDB-Introduction/IoTDB-Introduction_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Release-history_apache.md b/src/zh/UserGuide/V1.3.x/IoTDB-Introduction/Release-history_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Release-history_apache.md rename to src/zh/UserGuide/V1.3.x/IoTDB-Introduction/Release-history_apache.md diff --git a/src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Release-history_timecho.md b/src/zh/UserGuide/V1.3.x/IoTDB-Introduction/Release-history_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/IoTDB-Introduction/Release-history_timecho.md rename to src/zh/UserGuide/V1.3.x/IoTDB-Introduction/Release-history_timecho.md diff --git a/src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Scenario.md b/src/zh/UserGuide/V1.3.x/IoTDB-Introduction/Scenario.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/IoTDB-Introduction/Scenario.md rename to src/zh/UserGuide/V1.3.x/IoTDB-Introduction/Scenario.md diff --git a/src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart.md b/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/QuickStart/QuickStart.md rename to src/zh/UserGuide/V1.3.x/QuickStart/QuickStart.md diff --git a/src/zh/UserGuide/V1.3.3/QuickStart/QuickStart_apache.md b/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/QuickStart/QuickStart_apache.md rename to src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_apache.md diff --git a/src/zh/UserGuide/V1.3.3/QuickStart/QuickStart_timecho.md b/src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/QuickStart/QuickStart_timecho.md rename to src/zh/UserGuide/V1.3.x/QuickStart/QuickStart_timecho.md diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/Common-Config-Manual.md b/src/zh/UserGuide/V1.3.x/Reference/Common-Config-Manual-old.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Reference/Common-Config-Manual.md rename to src/zh/UserGuide/V1.3.x/Reference/Common-Config-Manual-old.md diff --git a/src/zh/UserGuide/V1.3.3/Reference/Common-Config-Manual.md b/src/zh/UserGuide/V1.3.x/Reference/Common-Config-Manual.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Reference/Common-Config-Manual.md rename to src/zh/UserGuide/V1.3.x/Reference/Common-Config-Manual.md diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/ConfigNode-Config-Manual.md b/src/zh/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual-old.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Reference/ConfigNode-Config-Manual.md rename to src/zh/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual-old.md diff --git a/src/zh/UserGuide/V1.3.3/Reference/ConfigNode-Config-Manual.md b/src/zh/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Reference/ConfigNode-Config-Manual.md rename to src/zh/UserGuide/V1.3.x/Reference/ConfigNode-Config-Manual.md diff --git a/src/zh/UserGuide/V1.3.3/Reference/DataNode-Config-Manual.md b/src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old.md similarity index 100% rename from src/zh/UserGuide/V1.3.3/Reference/DataNode-Config-Manual.md rename to src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old.md diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/DataNode-Config-Manual_apache.md b/src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_apache.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Reference/DataNode-Config-Manual_apache.md rename to src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_apache.md diff --git a/src/zh/UserGuide/V1.3.0-2/Reference/DataNode-Config-Manual_timecho.md b/src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_timecho.md similarity index 100% rename from src/zh/UserGuide/V1.3.0-2/Reference/DataNode-Config-Manual_timecho.md rename to src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual-old_timecho.md diff --git a/src/zh/UserGuide/V1.3.3/QuickStart/QuickStart.md b/src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual.md similarity index 94% rename from src/zh/UserGuide/V1.3.3/QuickStart/QuickStart.md rename to src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual.md index d94d5e0c9..172882761 100644 --- a/src/zh/UserGuide/V1.3.3/QuickStart/QuickStart.md +++ b/src/zh/UserGuide/V1.3.x/Reference/DataNode-Config-Manual.md @@ -1,5 +1,5 @@ --- -redirectTo: QuickStart_apache.html +redirectTo: DataNode-Config-Manual_apache.html ---