Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ 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.

**Table Mode**: It is recommended to create a table for each type of device. The collection of physical quantities from devices of the same type shares certain commonalities (such as the collection of temperature and humidity physical quantities), allowing for flexible and rich data analysis.

### 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.

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ 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.

**Table Mode**: It is recommended to create a table for each type of device. The collection of physical quantities from devices of the same type shares certain commonalities (such as the collection of temperature and humidity physical quantities), allowing for flexible and rich data analysis.

### 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.

Expand Down Expand Up @@ -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
Expand Down
Loading