diff --git a/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md index f044ecd7f..cfa0674d6 100644 --- a/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -37,7 +37,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -77,7 +77,167 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). + +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_apache.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_apache.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_apache.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_apache.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API_apache.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API_apache.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API_apache.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../User-Manual/Tree-to-Table_apache.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md index 9b0cfd84e..0afd66d24 100644 --- a/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -37,7 +37,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -77,7 +77,166 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_timecho.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_timecho.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_timecho.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_timecho.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API_timecho.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API_timecho.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API_timecho.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../User-Manual/Tree-to-Table_timecho.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md index bc1db965d..b97da4240 100644 --- a/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -41,7 +41,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -81,7 +81,167 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). + +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_apache.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_apache.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_apache.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_apache.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../../latest-Table/User-Manual/Tree-to-Table_apache.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md index 9f930f86d..51421369b 100644 --- a/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers Tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -41,7 +41,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -81,7 +81,167 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). + +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_timecho.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_timecho.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_timecho.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_timecho.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../../latest-Table/User-Manual/Tree-to-Table_timecho.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md index f044ecd7f..cfa0674d6 100644 --- a/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -37,7 +37,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -77,7 +77,167 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). + +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_apache.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_apache.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_apache.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_apache.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API_apache.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API_apache.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API_apache.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../User-Manual/Tree-to-Table_apache.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md index 9b0cfd84e..0afd66d24 100644 --- a/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -37,7 +37,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -77,7 +77,166 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_timecho.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_timecho.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_timecho.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_timecho.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API_timecho.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API_timecho.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API_timecho.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../User-Manual/Tree-to-Table_timecho.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md index bc1db965d..b97da4240 100644 --- a/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -41,7 +41,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -81,7 +81,167 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). + +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_apache.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_apache.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_apache.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_apache.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../../latest-Table/User-Manual/Tree-to-Table_apache.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md index 9f930f86d..51421369b 100644 --- a/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,9 +27,9 @@ This section introduces how to transform time series data application scenarios Before designing an IoTDB data mode, it's essential to understand time series data and its underlying structure. For more details, refer to: [Time Series Data Mode](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. Two Time Series Mode in IoTDB +## 2. Tree-Table Twin Mode in IoTDB -IoTDB offers two data mode syntaxes—tree mode and table mode, each with its distinct characteristics as follows: +IoTDB offers Tree-table twin mode, each with its distinct characteristics as follows: **Tree Mode**: It manages data points as objects, with each data point corresponding to a time series. The data point names, segmented by dots, form a tree-like directory structure that corresponds one-to-one with the physical world, making the read and write operations on data points straightforward and intuitive. @@ -41,7 +41,7 @@ IoTDB offers two data mode syntaxes—tree mode and table mode, each with its di ### 2.1 Mode Characteristics -Both mode syntaxes have their own applicable scenarios. +Tree-table twin mode syntaxes have their own applicable scenarios. The following table compares the tree mode and the table mode from various dimensions, including applicable scenarios and typical operations. Users can choose the appropriate mode based on their specific usage requirements to achieve efficient data storage and management. @@ -81,7 +81,167 @@ The following table compares the tree mode and the table mode from various dimen - Both mode spaces can coexist within the same cluster instance. Each mode follows distinct syntax and database naming conventions, and they remain isolated by default. -- When establishing a database connection via client tools (Cli) or SDKs, specify the mode syntax using the `sql_dialect` parameter (Tree syntax is used by default). + +## 2.2 Model Selection + +IoTDB supports model selection through various client tools. The configuration methods for different clients are as follows: + +1. [Command-Line Interface (CLI)](../Tools-System/CLI_timecho.md) + +When connecting via CLI, specify the model using the `sql_dialect` parameter (default: tree model). + +```bash +# Tree model +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# Table model +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-commands_timecho.md#_2-1-setting-the-connected-model) + +Use the `SET` statement to switch models in SQL: + +```sql +-- Tree model +IoTDB> SET SQL_DIALECT=TREE + +-- Table model +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. Application Programming Interfaces (APIs) + +For multi-language APIs, create connections via model-specific session/session pool classes. Examples: + +* [Java Native API](../API/Programming-Java-Native-API_timecho.md) + +```java +// Tree model +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +// Table model +ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python Native API](../API/Programming-Python-Native-API_timecho.md) + +```python +# Tree model +session = Session( + ip=ip, + port=port, + user=username, + password=password, + fetch_size=1024, + zone_id="UTC+8", + enable_redirection=True +) + +# Table model +config = TableSessionPoolConfig( + node_urls=node_urls, + username=username, + password=password, + database=database, + max_pool_size=max_pool_size, + fetch_size=fetch_size, + wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ Native API](../API/Programming-Cpp-Native-API.md) + +```cpp +// Tree model +session = new Session(hostip, port, username, password); + +// Table model +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [Go Native API](../API/Programming-Go-Native-API.md) + +```go +// Tree model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +// Table model +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# Native API](../API/Programming-CSharp-Native-API.md) + +```csharp +// Tree model +var session_pool = new SessionPool(host, port, pool_size); + +// Table model +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +For the table model, include `sql_dialect=table` in the JDBC URL: + +```java +// Tree model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// Table model +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +## 2.3 Tree-to-Table Conversion + +IoTDB supports **tree-to-table conversion**, as shown in the figure below: + +![](/img/tree-to-table-en-1.png) + +This feature allows existing tree-model data to be transformed into table views. Users can then query the same dataset using either model. Detailed instructions are available in [Tree-to-Table View](../../latest-Table/User-Manual/Tree-to-Table_timecho.md). **Note**: SQL statements for creating tree-to-table views **must be executed in table mode**. ## 3. Application Scenarios diff --git a/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md index a5c12864d..cbd5260cf 100644 --- a/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 @@ -37,7 +37,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -77,7 +77,169 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 + +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_apache.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_apache.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_apache.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_apache.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API_apache.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API_apache.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API_apache.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../User-Manual/Tree-to-Table_apache.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 + + ## 3. 应用场景 @@ -166,7 +328,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 - 即使设备之间有联系,或有层级关系,也推荐为每一类设备建一张表。
- +
##### 3.2.3.2 如果没有设备标识列和属性列,如何建模? diff --git a/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md index fc796b78d..97e1ec59f 100644 --- a/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/zh/UserGuide/Master/Table/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,9 +27,9 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 @@ -37,7 +37,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -77,7 +77,167 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 + +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_timecho.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_timecho.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_timecho.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_timecho.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API_timecho.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API_timecho.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API_timecho.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../User-Manual/Tree-to-Table_timecho.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 ## 3. 应用场景 diff --git a/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md index a9bd51a40..92f3abacc 100644 --- a/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 @@ -41,7 +41,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -81,7 +81,166 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_apache.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_apache.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_apache.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_apache.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../../latest-Table/User-Manual/Tree-to-Table_apache.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 ## 3. 应用场景 @@ -111,6 +270,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 | **时间序列(测点)** | 定义:
1. 一个以数据库路径为前缀的、由 . 分割的路径,可包含任意多个层级,如 root.db.turbine.device1.metric1
2. 每个时间序列可以有不同的数据类型。
命名推荐:
1. 仅将唯一定位时间序列的标签(类似联合主键)放入路径中,一般不超过10层
2. 通常将基数(不同的取值数量)少的标签放在前面,便于系统将公共前缀进行压缩
数量推荐:
1. 集群可管理的时间序列总量和总内存相关,可参考资源推荐章节
2. 任一层级的子节点数量没有限制
创建方式:可手动创建或在数据写入时自动创建。 | | **设备** | 定义:倒数第二级为设备,如 root.db.turbine.**device1**.metric1中的“device1”这一层级即为设备
创建方式:无法仅创建设备,随时间序列创建而存在 | + #### 3.1.3 建模示例 ##### 3.1.3.1 有多种类型的设备需要管理,如何建模? diff --git a/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md index 985e1d100..541f0d39b 100644 --- a/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/zh/UserGuide/Master/Tree/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,21 +27,21 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 > 1. 数据建模时,为了足够的性能要求,建议数据路径(Path)的倒数第二层节点(对应设备数量)不少于 1000 个,且设备数量与并发处理能力挂钩,设备数量充足时,并发读写效率更优。 - 若遇到“设备数量较少但单设备测点数量较多”的场景(如仅 3 台设备,每台设备含 10000 个测点),推荐在最后层级新增 `.value` ,以此提升倒数第二层节点总数,示例:`root.db.device01.metric.value`。 +若遇到“设备数量较少但单设备测点数量较多”的场景(如仅 3 台设备,每台设备含 10000 个测点),推荐在最后层级新增 `.value` ,以此提升倒数第二层节点总数,示例:`root.db.device01.metric.value`。 > 2. 在构建树模型[路径](../Basic-Concept/Operate-Metadata_timecho.md#4-路径查询)时,节点命名若存在包含非标准字符或特殊符号的可能性,则建议对所有层级节点实施反引号封装策略。这样可以有效规避因字符解析异常导致的测点注册失败及数据写入中断问题,确保路径标识符在语法解析层面的准确性。 **表模型**:推荐为每类设备创建一张表,同类设备的物理量采集都具备一定共性(如都采集温度和湿度物理量),数据分析灵活丰富。 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -81,7 +81,166 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_timecho.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_timecho.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_timecho.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_timecho.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../../latest-Table/User-Manual/Tree-to-Table_timecho.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 ## 3. 应用场景 diff --git a/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md index 7c6f00aef..c2e14d462 100644 --- a/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 @@ -37,7 +37,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -77,7 +77,167 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 + +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_apache.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_apache.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_apache.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_apache.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API_apache.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API_apache.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API_apache.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../User-Manual/Tree-to-Table_apache.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 ## 3. 应用场景 diff --git a/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md index fc796b78d..97e1ec59f 100644 --- a/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/zh/UserGuide/latest-Table/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,9 +27,9 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 @@ -37,7 +37,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -77,7 +77,167 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 + +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_timecho.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_timecho.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_timecho.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_timecho.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API_timecho.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API_timecho.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API_timecho.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../User-Manual/Tree-to-Table_timecho.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 ## 3. 应用场景 diff --git a/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md b/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md index eb47ab5ad..92f3abacc 100644 --- a/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md +++ b/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_apache.md @@ -27,9 +27,9 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 @@ -41,7 +41,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -81,7 +81,166 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_apache.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_apache.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_apache.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_apache.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_apache.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../../latest-Table/User-Manual/Tree-to-Table_apache.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 ## 3. 应用场景 diff --git a/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md b/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md index ab6232902..541f0d39b 100644 --- a/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md +++ b/src/zh/UserGuide/latest/Background-knowledge/Data-Model-and-Terminology_timecho.md @@ -27,9 +27,9 @@ 在构建IoTDB建模方案前,需要先了解时序数据和时序数据模型,详细内容见此页面:[时序数据模型](../Background-knowledge/Navigating_Time_Series_Data.md) -## 2. IoTDB 的两种时序模型 +## 2. IoTDB 的树表孪生模型 -IoTDB 提供了两种数据建模方式——树模型和表模型,其特点分别如下: +IoTDB 提供了树表孪生模型的方式,其特点分别如下: **树模型**:以测点为对象进行管理,每个测点对应一条时间序列,测点名按`.`分割可形成一个树形目录结构,与物理世界一一对应,对测点的读写操作简单直观。 @@ -41,7 +41,7 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 ### 2.1 模型特点 -两种模型有各自的适用场景。 +树表孪生模型有各自的适用场景。 以下表格从适用场景、典型操作等多个维度对树模型和表模型进行了对比。用户可以根据具体的使用需求,选择适合的模型,从而实现数据的高效存储和管理。 @@ -81,7 +81,166 @@ IoTDB 提供了两种数据建模方式——树模型和表模型,其特点 **注意:** - 同一个集群实例中可以存在两种模型空间,不同模型的语法、数据库命名方式不同,默认不互相可见。 -- 在通过客户端工具 Cli 或 SDK 建立数据库连接时,需要通过 sql_dialect 参数指定使用的模型语法(默认使用树语法进行操作)。 +### 2.2 模型选择 + +IoTDB 支持通过多种客户端工具与数据库建立连接,不同客户端下进行模型选择的方式说明如下: + +1. [命令行工具 CLI](../Tools-System/CLI_timecho.md) + +通过 CLI 建立连接时,需要通过 `sql_dialect` 参数指定使用的模型(默认使用树模型)。 + +```Bash +# 树模型 +start-cli.sh(bat) +start-cli.sh(bat) -sql_dialect tree + +# 表模型 +start-cli.sh(bat) -sql_dialect table +``` + +2. [SQL](../User-Manual/Maintenance-statement_timecho.md#_2-1-设置连接的模型) + +在使用 SQL 语言进行数据操作时,可通过 set 语句切换使用的模型。 + +```SQL +-- 指定为树模型 +IoTDB> SET SQL_DIALECT=TREE + +-- 指定为表模型 +IoTDB> SET SQL_DIALECT=TABLE +``` + +3. 应用编程接口 + +通过多语言应用编程接口建立连接时,可通过模型对应的 session/sessionpool 创建连接池实例,简单示例如下: + +* [Java 原生接口](../API/Programming-Java-Native-API_timecho.md) + +```Java +// 树模型 +SessionPool sessionPool = + new SessionPool.Builder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(3) + .build(); + +//表模型 + ITableSessionPool tableSessionPool = + new TableSessionPoolBuilder() + .nodeUrls(nodeUrls) + .user(username) + .password(password) + .maxSize(1) + .build(); +``` + +* [Python 原生接口](../API/Programming-Python-Native-API_timecho.md) + +```Python +# 树模型 +session = Session( +​ ip=ip, +​ port=port, +​ user=username, +​ password=password, +​ fetch_size=1024, +​ zone_id="UTC+8", +​ enable_redirection=True +) + +# 表模型 +config = TableSessionPoolConfig( +​ node_urls=node_urls, +​ username=username, +​ password=password, +​ database=database, +​ max_pool_size=max_pool_size, +​ fetch_size=fetch_size, +​ wait_timeout_in_ms=wait_timeout_in_ms, +) +session_pool = TableSessionPool(config) +``` + +* [C++ 原生接口](../API/Programming-Cpp-Native-API.md) + +```C++ +// 树模型 +session = new Session(hostip, port, username, password); + +// 表模型 +session = (new TableSessionBuilder()) + ->host(ip) + ->rpcPort(port) + ->username(username) + ->password(password) + ->build(); +``` + +* [GO 原生接口](../API/Programming-Go-Native-API.md) + +```Go +//树模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, +} +sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false) +defer sessionPool.Close() + +//表模型 +config := &client.PoolConfig{ + Host: host, + Port: port, + UserName: user, + Password: password, + Database: dbname, +} +sessionPool := client.NewTableSessionPool(config, 3, 60000, 4000, false) +defer sessionPool.Close() +``` + +* [C# 原生接口](../API/Programming-CSharp-Native-API.md) + +```C# +//树模型 +var session_pool = new SessionPool(host, port, pool_size); + +//表模型 +var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(nodeUrls) + .SetUsername(username) + .SetPassword(password) + .SetFetchSize(1024) + .Build(); +``` + +* [JDBC](../API/Programming-JDBC_timecho.md) + +使用表模型,必须在 url 中指定 sql\_dialect 参数为 table。 + +```Java +// 树模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667/", username, password); + +// 表模型 +Class.forName("org.apache.iotdb.jdbc.IoTDBDriver"); +Connection connection = DriverManager.getConnection( + "jdbc:iotdb://127.0.0.1:6667?sql_dialect=table", username, password); +``` + +### 2.3 树转表 + +IoTDB 提供了树转表功能,如下图所示: + +![](/img/tree-to-table-1.png) + +该功能支持通过创建表视图的方式,将已存在的树模型数据转化为表视图,进而通过表视图进行查询,实现了对同一份数据的树模型和表模型协同处理。更详细的功能介绍可参考[树转表视图](../../latest-Table/User-Manual/Tree-to-Table_timecho.md),需要注意的是:​**创建树转表视图的 SQL 语句只允许在表模型下执行**​。 ## 3. 应用场景