Merge branch '3.0' into feat/TD-17777-V30
This commit is contained in:
commit
49b49eb0eb
|
@ -79,7 +79,7 @@ def pre_test(){
|
|||
rm -rf debug
|
||||
mkdir debug
|
||||
cd debug
|
||||
cmake .. > /dev/null
|
||||
cmake .. -DBUILD_TEST=true > /dev/null
|
||||
make -j4> /dev/null
|
||||
|
||||
'''
|
||||
|
|
10
Jenkinsfile2
10
Jenkinsfile2
|
@ -173,7 +173,7 @@ def pre_test_build_mac() {
|
|||
'''
|
||||
sh '''
|
||||
cd ${WK}/debug
|
||||
cmake ..
|
||||
cmake .. -DBUILD_TEST=true
|
||||
make -j8
|
||||
'''
|
||||
sh '''
|
||||
|
@ -218,12 +218,12 @@ def pre_test_win(){
|
|||
if (env.CHANGE_URL =~ /\/TDengine\//) {
|
||||
bat '''
|
||||
cd %WIN_INTERNAL_ROOT%
|
||||
git pull
|
||||
git pull origin ''' + env.CHANGE_TARGET + '''
|
||||
'''
|
||||
bat '''
|
||||
cd %WIN_COMMUNITY_ROOT%
|
||||
git remote prune origin
|
||||
git pull
|
||||
git pull origin ''' + env.CHANGE_TARGET + '''
|
||||
'''
|
||||
bat '''
|
||||
cd %WIN_COMMUNITY_ROOT%
|
||||
|
@ -236,7 +236,7 @@ def pre_test_win(){
|
|||
} else if (env.CHANGE_URL =~ /\/TDinternal\//) {
|
||||
bat '''
|
||||
cd %WIN_INTERNAL_ROOT%
|
||||
git pull
|
||||
git pull origin ''' + env.CHANGE_TARGET + '''
|
||||
'''
|
||||
bat '''
|
||||
cd %WIN_INTERNAL_ROOT%
|
||||
|
@ -302,7 +302,7 @@ def pre_test_build_win() {
|
|||
set CL=/MP8
|
||||
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> cmake"
|
||||
time /t
|
||||
cmake .. -G "NMake Makefiles JOM" || exit 7
|
||||
cmake .. -G "NMake Makefiles JOM" -DBUILD_TEST=true || exit 7
|
||||
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> jom -j 6"
|
||||
time /t
|
||||
jom -j 6 || exit 8
|
||||
|
|
20
README.md
20
README.md
|
@ -15,19 +15,19 @@
|
|||
[](https://coveralls.io/github/taosdata/TDengine?branch=develop)
|
||||
[](https://bestpractices.coreinfrastructure.org/projects/4201)
|
||||
|
||||
English | [简体中文](README-CN.md) | [Lean more about TSDB](https://tdengine.com/tsdb)
|
||||
English | [简体中文](README-CN.md) | [Learn more about TSDB](https://tdengine.com/tsdb/)
|
||||
|
||||
# What is TDengine?
|
||||
|
||||
TDengine is an open source, high-performance, cloud native [time-series database](https://tdengine.com/tsdb/) optimized for Internet of Things (IoT), Connected Cars, and Industrial IoT. It enables efficient, real-time data ingestion, processing, and monitoring of TB and even PB scale data per day, generated by billions of sensors and data collectors. TDengine differentiates itself from other time-seires databases with the following advantages:
|
||||
|
||||
- **[High-Performance](https://tdengine.com/tdengine/high-performance-time-series-database/)**: TDengine is the only time-series database to solve the high cardinality issue to support billions of data collection points while out performing other time-series databases for data ingestion, querying and data compression.
|
||||
- **[High Performance](https://tdengine.com/tdengine/high-performance-time-series-database/)**: TDengine is the only time-series database to solve the high cardinality issue to support billions of data collection points while out performing other time-series databases for data ingestion, querying and data compression.
|
||||
|
||||
- **[Simplified Solution](https://tdengine.com/tdengine/simplified-time-series-data-solution/)**: Through built-in caching, stream processing and data subscription features, TDengine provides a simplified solution for time-series data processing. It reduces system design complexity and operation costs significantly.
|
||||
|
||||
- **[Cloud Native](https://tdengine.com/tdengine/cloud-native-time-series-database/)**: Through native distributed design, sharding and partitioning, separation of compute and storage, RAFT, support for kubernetes deployment and full observability, TDengine is a cloud native Time-Series Database and can be deployed on public, private or hybrid clouds.
|
||||
|
||||
- **[Ease of Use](https://docs.tdengine.com/get-started/docker/)**: For administrators, TDengine significantly reduces the effort to deploy and maintain. For developers, it provides a simple interface, simplified solution and seamless integrations for third party tools. For data users, it gives easy data access.
|
||||
- **[Ease of Use](https://tdengine.com/tdengine/easy-time-series-data-platform/)**: For administrators, TDengine significantly reduces the effort to deploy and maintain. For developers, it provides a simple interface, simplified solution and seamless integrations for third party tools. For data users, it gives easy data access.
|
||||
|
||||
- **[Easy Data Analytics](https://tdengine.com/tdengine/time-series-data-analytics-made-easy/)**: Through super tables, storage and compute separation, data partitioning by time interval, pre-computation and other means, TDengine makes it easy to explore, format, and get access to data in a highly efficient way.
|
||||
|
||||
|
@ -232,9 +232,9 @@ After building successfully, TDengine can be installed by
|
|||
sudo make install
|
||||
```
|
||||
|
||||
Users can find more information about directories installed on the system in the [directory and files](https://docs.taosdata.com/reference/directory/) section.
|
||||
Users can find more information about directories installed on the system in the [directory and files](https://docs.tdengine.com/reference/directory/) section.
|
||||
|
||||
Installing from source code will also configure service management for TDengine.Users can also choose to [install from packages](https://docs.taosdata.com/get-started/package/) for it.
|
||||
Installing from source code will also configure service management for TDengine.Users can also choose to [install from packages](https://docs.tdengine.com/get-started/package/) for it.
|
||||
|
||||
To start the service after installation, in a terminal, use:
|
||||
|
||||
|
@ -321,7 +321,11 @@ TDengine provides abundant developing tools for users to develop on TDengine. Fo
|
|||
|
||||
Please follow the [contribution guidelines](CONTRIBUTING.md) to contribute to the project.
|
||||
|
||||
# Join TDengine User Community
|
||||
# Join the TDengine Community
|
||||
|
||||
- Join [TDengine Discord Channel](https://discord.com/invite/VZdSuUg4pS?utm_id=discord)
|
||||
- Join wechat group by adding WeChat “tdengine”
|
||||
For more information about TDengine, you can follow us on social media and join our Discord server:
|
||||
|
||||
- [Discord](https://discord.com/invite/VZdSuUg4pS)
|
||||
- [Twitter](https://twitter.com/TaosData)
|
||||
- [LinkedIn](https://www.linkedin.com/company/tdengine/)
|
||||
- [YouTube](https://www.youtube.com/channel/UCmp-1U6GS_3V3hjir6Uq5DQ)
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
# Deps options
|
||||
# =========================================================
|
||||
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
OFF
|
||||
)
|
||||
|
||||
IF(${TD_WINDOWS})
|
||||
|
||||
MESSAGE("build pthread Win32")
|
||||
|
@ -45,12 +51,6 @@ IF(${TD_WINDOWS})
|
|||
"If build wingetopt on Windows"
|
||||
ON
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
ON
|
||||
)
|
||||
|
||||
option(
|
||||
TDENGINE_3
|
||||
|
@ -65,28 +65,8 @@ IF(${TD_WINDOWS})
|
|||
)
|
||||
|
||||
ELSEIF (TD_DARWIN_64)
|
||||
add_definitions(-DCOMPILER_SUPPORTS_CXX13)
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
ON
|
||||
)
|
||||
ELSE ()
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++13" COMPILER_SUPPORTS_CXX13)
|
||||
IF(${COMPILER_SUPPORTS_CXX13})
|
||||
IF(${BUILD_TEST})
|
||||
add_definitions(-DCOMPILER_SUPPORTS_CXX13)
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
ON
|
||||
)
|
||||
ELSE ()
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
OFF
|
||||
)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
IF (DEFINED VERNUMBER)
|
||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||
ELSE ()
|
||||
SET(TD_VER_NUMBER "3.0.1.1")
|
||||
SET(TD_VER_NUMBER "3.0.1.3")
|
||||
ENDIF ()
|
||||
|
||||
IF (DEFINED VERCOMPATIBLE)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taosadapter
|
||||
ExternalProject_Add(taosadapter
|
||||
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
||||
GIT_TAG 05fb2ff
|
||||
GIT_TAG be729ab
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taos-tools
|
||||
ExternalProject_Add(taos-tools
|
||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||
GIT_TAG 125c77a
|
||||
GIT_TAG 70f5a1c
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taosws-rs
|
||||
ExternalProject_Add(taosws-rs
|
||||
GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git
|
||||
GIT_TAG e771403
|
||||
GIT_TAG 1bdfca3
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -3,7 +3,11 @@ sidebar_label: Docker
|
|||
title: Quick Install on Docker
|
||||
---
|
||||
|
||||
This document describes how to install TDengine in a Docker container and perform queries and inserts. To get started with TDengine in a non-containerized environment, see [Quick Install](../../get-started/package). If you want to view the source code, build TDengine yourself, or contribute to the project, see the [TDengine GitHub repository](https://github.com/taosdata/TDengine).
|
||||
This document describes how to install TDengine in a Docker container and perform queries and inserts.
|
||||
|
||||
- The easiest way to explore TDengine is through [TDengine Cloud](http://cloud.tdengine.com).
|
||||
- To get started with TDengine in a non-containerized environment, see [Quick Install from Package](../../get-started/package).
|
||||
- If you want to view the source code, build TDengine yourself, or contribute to the project, see the [TDengine GitHub repository](https://github.com/taosdata/TDengine).
|
||||
|
||||
## Run TDengine
|
||||
|
||||
|
|
|
@ -7,7 +7,11 @@ import Tabs from "@theme/Tabs";
|
|||
import TabItem from "@theme/TabItem";
|
||||
import PkgListV3 from "/components/PkgListV3";
|
||||
|
||||
For information about installing TDengine on Docker, see [Quick Install on Docker](../../get-started/docker). If you want to view the source code, build TDengine yourself, or contribute to the project, see the [TDengine GitHub repository](https://github.com/taosdata/TDengine).
|
||||
This document describes how to install TDengine on Linux and Windows and perform queries and inserts.
|
||||
|
||||
- The easiest way to explore TDengine is through [TDengine Cloud](http://cloud.tdengine.com).
|
||||
- To get started with TDengine on Docker, see [Quick Install on Docker](../../get-started/docker).
|
||||
- If you want to view the source code, build TDengine yourself, or contribute to the project, see the [TDengine GitHub repository](https://github.com/taosdata/TDengine).
|
||||
|
||||
The full package of TDengine includes the TDengine Server (`taosd`), TDengine Client (`taosc`), taosAdapter for connecting with third-party systems and providing a RESTful interface, a command-line interface (CLI, taos), and some tools. Note that taosAdapter supports Linux only. In addition to connectors for multiple languages, TDengine also provides a [REST API](../../reference/rest-api) through [taosAdapter](../../reference/taosadapter).
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ title: Get Started
|
|||
description: This article describes how to install TDengine and test its performance.
|
||||
---
|
||||
|
||||
The full package of TDengine includes the TDengine Server (`taosd`), TDengine Client (`taosc`), taosAdapter for connecting with third-party systems and providing a RESTful interface, a command-line interface, and some tools. In addition to connectors for multiple languages, TDengine also provides a [RESTful interface](/reference/rest-api) through [taosAdapter](/reference/taosadapter).
|
||||
You can install and run TDengine on Linux and Windows machines as well as Docker containers. You can also deploy TDengine as a managed service with TDengine Cloud.
|
||||
|
||||
You can install and run TDengine on Linux and Windows machines as well as Docker containers.
|
||||
The full package of TDengine includes the TDengine Server (`taosd`), TDengine Client (`taosc`), taosAdapter for connecting with third-party systems and providing a RESTful interface, a command-line interface, and some tools. In addition to connectors for multiple languages, TDengine also provides a [RESTful interface](/reference/rest-api) through [taosAdapter](/reference/taosadapter).
|
||||
|
||||
```mdx-code-block
|
||||
import DocCardList from '@theme/DocCardList';
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
```csharp title="Native Connection"
|
||||
{{#include docs/examples/csharp/ConnectExample.cs}}
|
||||
{{#include docs/examples/csharp/connect/Program.cs}}
|
||||
```
|
||||
|
||||
:::info
|
||||
C# connector supports only native connection for now.
|
||||
|
||||
:::
|
||||
```csharp title="WebSocket Connection"
|
||||
{{#include docs/examples/csharp/wsConnect/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -37,7 +37,8 @@ meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0
|
|||
- All the data in `tag_set` will be converted to nchar type automatically .
|
||||
- Each data in `field_set` must be self-descriptive for its data type. For example 1.2f32 means a value 1.2 of float type. Without the "f" type suffix, it will be treated as type double.
|
||||
- Multiple kinds of precision can be used for the `timestamp` field. Time precision can be from nanosecond (ns) to hour (h).
|
||||
|
||||
- You can configure smlChildTableName in taos.cfg to specify table names, for example, `smlChildTableName=tname`. You can insert `st,tname=cpul,t1=4 c1=3 1626006833639000000` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored.
|
||||
- It is assumed that the order of field_set in a supertable is consistent, meaning that the first record contains all fields and subsequent records store fields in the same order. If the order is not consistent, set smlDataFormat in taos.cfg to false. Otherwise, data will be written out of order and a database error will occur.(smlDataFormat in taos.cfg default to false after version of 3.0.1.3)
|
||||
:::
|
||||
|
||||
For more details please refer to [InfluxDB Line Protocol](https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/) and [TDengine Schemaless](/reference/schemaless/#Schemaless-Line-Protocol)
|
||||
|
@ -64,3 +65,7 @@ For more details please refer to [InfluxDB Line Protocol](https://docs.influxdat
|
|||
<CLine />
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Query Examples
|
||||
If you want query the data of `location=California.LosAngeles,groupid=2`,here is the query sql:
|
||||
select * from `meters.voltage` where location="California.LosAngeles" and groupid=2
|
||||
|
|
|
@ -31,7 +31,7 @@ For example:
|
|||
```txt
|
||||
meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3
|
||||
```
|
||||
|
||||
- The defult child table name is generated by rules.You can configure smlChildTableName in taos.cfg to specify chile table names, for example, `smlChildTableName=tname`. You can insert `meters.current 1648432611250 11.3 tname=cpu1 location=California.LosAngeles groupid=3` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored.
|
||||
Please refer to [OpenTSDB Telnet API](http://opentsdb.net/docs/build/html/api_telnet/put.html) for more details.
|
||||
|
||||
## Examples
|
||||
|
@ -79,3 +79,6 @@ taos> select tbname, * from `meters.current`;
|
|||
t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.250 | 12.600000000 | 2 | California.SanFrancisco |
|
||||
Query OK, 4 row(s) in set (0.005399s)
|
||||
```
|
||||
## Query Examples
|
||||
If you want query the data of `location=California.LosAngeles groupid=3`,here is the query sql:
|
||||
select * from `meters.voltage` where location="California.LosAngeles" and groupid=3
|
||||
|
|
|
@ -48,7 +48,7 @@ Please refer to [OpenTSDB HTTP API](http://opentsdb.net/docs/build/html/api_http
|
|||
|
||||
- In JSON protocol, strings will be converted to nchar type and numeric values will be converted to double type.
|
||||
- Only data in array format is accepted and so an array must be used even if there is only one row.
|
||||
|
||||
- The defult child table name is generated by rules.You can configure smlChildTableName in taos.cfg to specify chile table names, for example, `smlChildTableName=tname`. You can insert `"tags": { "host": "web02","dc": "lga","tname":"cpu1"}` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored.
|
||||
:::
|
||||
|
||||
## Examples
|
||||
|
@ -94,3 +94,6 @@ taos> select * from `meters.current`;
|
|||
2022-03-28 09:56:51.250 | 12.600000000 | 2.000000000 | California.SanFrancisco |
|
||||
Query OK, 2 row(s) in set (0.004076s)
|
||||
```
|
||||
## Query Examples
|
||||
If you want query the data of "tags": {"location": "California.LosAngeles", "groupid": 1},here is the query sql:
|
||||
select * from `meters.voltage` where location="California.LosAngeles" and groupid=1
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/InfluxDBLineExample.cs}}
|
||||
{{#include docs/examples/csharp/influxdbLine/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/OptsJsonExample.cs}}
|
||||
{{#include docs/examples/csharp/optsJSON/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/OptsTelnetExample.cs}}
|
||||
{{#include docs/examples/csharp/optsTelnet/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/SQLInsertExample.cs}}
|
||||
{{#include docs/examples/csharp/sqlInsert/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/StmtInsertExample.cs}}
|
||||
{{#include docs/examples/csharp/stmtInsert/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/QueryExample.cs}}
|
||||
{{#include docs/examples/csharp/query/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/AsyncQueryExample.cs}}
|
||||
{{#include docs/examples/csharp/asyncQuery/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/SubscribeDemo.cs}}
|
||||
{{#include docs/examples/csharp/subscribe/Program.cs}}
|
||||
```
|
|
@ -1,70 +1,70 @@
|
|||
---
|
||||
sidebar_label: Data Types
|
||||
title: Data Types
|
||||
description: "TDengine supports a variety of data types including timestamp, float, JSON and many others."
|
||||
description: 'TDengine supports a variety of data types including timestamp, float, JSON and many others.'
|
||||
---
|
||||
|
||||
## Timestamp
|
||||
|
||||
When using TDengine to store and query data, the most important part of the data is timestamp. Timestamp must be specified when creating and inserting data rows. Timestamp must follow the rules below:
|
||||
|
||||
- The format must be `YYYY-MM-DD HH:mm:ss.MS`, the default time precision is millisecond (ms), for example `2017-08-12 18:25:58.128`
|
||||
- Internal function `now` can be used to get the current timestamp on the client side
|
||||
- The current timestamp of the client side is applied when `now` is used to insert data
|
||||
- The format must be `YYYY-MM-DD HH:mm:ss.MS`, the default time precision is millisecond (ms), for example `2017-08-12 18:25:58.128`.
|
||||
- Internal function `NOW` can be used to get the current timestamp on the client side.
|
||||
- The current timestamp of the client side is applied when `NOW` is used to insert data.
|
||||
- Epoch Time:timestamp can also be a long integer number, which means the number of seconds, milliseconds or nanoseconds, depending on the time precision, from UTC 1970-01-01 00:00:00.
|
||||
- Add/subtract operations can be carried out on timestamps. For example `now-2h` means 2 hours prior to the time at which query is executed. The units of time in operations can be b(nanosecond), u(microsecond), a(millisecond), s(second), m(minute), h(hour), d(day), or w(week). So `select * from t1 where ts > now-2w and ts <= now-1w` means the data between two weeks ago and one week ago. The time unit can also be n (calendar month) or y (calendar year) when specifying the time window for down sampling operations.
|
||||
- Add/subtract operations can be carried out on timestamps. For example `NOW-2h` means 2 hours prior to the time at which query is executed. The units of time in operations can be b(nanosecond), u(microsecond), a(millisecond), s(second), m(minute), h(hour), d(day), or w(week). So `SELECT * FROM t1 WHERE ts > NOW-2w AND ts <= NOW-1w` means the data between two weeks ago and one week ago. The time unit can also be n (calendar month) or y (calendar year) when specifying the time window for down sampling operations.
|
||||
|
||||
Time precision in TDengine can be set by the `PRECISION` parameter when executing `CREATE DATABASE`. The default time precision is millisecond. In the statement below, the precision is set to nanonseconds.
|
||||
|
||||
```sql
|
||||
CREATE DATABASE db_name PRECISION 'ns';
|
||||
```
|
||||
|
||||
## Data Types
|
||||
|
||||
In TDengine, the data types below can be used when specifying a column or tag.
|
||||
|
||||
| # | **type** | **Bytes** | **Description** |
|
||||
| --- | :-------: | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1 | TIMESTAMP | 8 | Default precision is millisecond, microsecond and nanosecond are also supported |
|
||||
| 2 | INT | 4 | Integer, the value range is [-2^31, 2^31-1] |
|
||||
| 3 | INT UNSIGNED| 4| unsigned integer, the value range is [0, 2^32-1]
|
||||
| 4 | BIGINT | 8 | Long integer, the value range is [-2^63, 2^63-1] |
|
||||
| 5 | BIGINT UNSIGNED | 8 | unsigned long integer, the value range is [0, 2^64-1] |
|
||||
| 6 | FLOAT | 4 | Floating point number, the effective number of digits is 6-7, the value range is [-3.4E38, 3.4E38] |
|
||||
| 7 | DOUBLE | 8 | Double precision floating point number, the effective number of digits is 15-16, the value range is [-1.7E308, 1.7E308] |
|
||||
| 8 | BINARY | User Defined | Single-byte string for ASCII visible characters. Length must be specified when defining a column or tag of binary type. |
|
||||
| 9 | SMALLINT | 2 | Short integer, the value range is [-32768, 32767] |
|
||||
| 10 | INT UNSIGNED| 2| unsigned integer, the value range is [0, 65535]|
|
||||
| 11 | TINYINT | 1 | Single-byte integer, the value range is [-128, 127] |
|
||||
| 12 | TINYINT UNSIGNED | 1 | unsigned single-byte integer, the value range is [0, 255] |
|
||||
| 13 | BOOL | 1 | Bool, the value range is {true, false} |
|
||||
| 14 | NCHAR | User Defined| Multi-Byte string that can include multi byte characters like Chinese characters. Each character of NCHAR type consumes 4 bytes storage. The string value should be quoted with single quotes. Literal single quote inside the string must be preceded with backslash, like `\’`. The length must be specified when defining a column or tag of NCHAR type, for example nchar(10) means it can store at most 10 characters of nchar type and will consume fixed storage of 40 bytes. An error will be reported if the string value exceeds the length defined. |
|
||||
| 15 | JSON | | JSON type can only be used on tags. A tag of json type is excluded with any other tags of any other type |
|
||||
| 16 | VARCHAR | User-defined | Alias of BINARY |
|
||||
|
||||
| # | **type** | **Bytes** | **Description** |
|
||||
| --- | :--------------: | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1 | TIMESTAMP | 8 | Default precision is millisecond, microsecond and nanosecond are also supported. |
|
||||
| 2 | INT | 4 | Integer, the value range is [-2^31, 2^31-1]. |
|
||||
| 3 | INT UNSIGNED | 4 | Unsigned integer, the value range is [0, 2^32-1]. |
|
||||
| 4 | BIGINT | 8 | Long integer, the value range is [-2^63, 2^63-1]. |
|
||||
| 5 | BIGINT UNSIGNED | 8 | unsigned long integer, the value range is [0, 2^64-1]. |
|
||||
| 6 | FLOAT | 4 | Floating point number, the effective number of digits is 6-7, the value range is [-3.4E38, 3.4E38]. |
|
||||
| 7 | DOUBLE | 8 | Double precision floating point number, the effective number of digits is 15-16, the value range is [-1.7E308, 1.7E308]. |
|
||||
| 8 | BINARY | User Defined | Single-byte string for ASCII visible characters. Length must be specified when defining a column or tag of binary type. |
|
||||
| 9 | SMALLINT | 2 | Short integer, the value range is [-32768, 32767]. |
|
||||
| 10 | INT UNSIGNED | 2 | unsigned integer, the value range is [0, 65535]. |
|
||||
| 11 | TINYINT | 1 | Single-byte integer, the value range is [-128, 127]. |
|
||||
| 12 | TINYINT UNSIGNED | 1 | unsigned single-byte integer, the value range is [0, 255]. |
|
||||
| 13 | BOOL | 1 | Bool, the value range is {true, false}. |
|
||||
| 14 | NCHAR | User Defined | Multi-byte string that can include multi byte characters like Chinese characters. Each character of NCHAR type consumes 4 bytes storage. The string value should be quoted with single quotes. Literal single quote inside the string must be preceded with backslash, like `\'`. The length must be specified when defining a column or tag of NCHAR type, for example nchar(10) means it can store at most 10 characters of nchar type and will consume fixed storage of 40 bytes. An error will be reported if the string value exceeds the length defined. |
|
||||
| 15 | JSON | | JSON type can only be used on tags. A tag of json type is excluded with any other tags of any other type. |
|
||||
| 16 | VARCHAR | User-defined | Alias of BINARY |
|
||||
|
||||
:::note
|
||||
- TDengine is case insensitive and treats any characters in the sql command as lower case by default, case sensitive strings must be quoted with single quotes.
|
||||
- Only ASCII visible characters are suggested to be used in a column or tag of BINARY type. Multi-byte characters must be stored in NCHAR type.
|
||||
- The length of BINARY can be up to 16374 bytes. The string value must be quoted with single quotes. You must specify a length in bytes for a BINARY value, for example binary(20) for up to twenty single-byte characters. If the data exceeds the specified length, an error will occur. The literal single quote inside the string must be preceded with back slash like `\'`
|
||||
|
||||
- Only ASCII visible characters are suggested to be used in a column or tag of BINARY type. Multi-byte characters must be stored in NCHAR type.
|
||||
- The length of BINARY can be up to 16,374 bytes. The string value must be quoted with single quotes. You must specify a length in bytes for a BINARY value, for example binary(20) for up to twenty single-byte characters. If the data exceeds the specified length, an error will occur. The literal single quote inside the string must be preceded with back slash like `\'`
|
||||
- Numeric values in SQL statements will be determined as integer or float type according to whether there is decimal point or whether scientific notation is used, so attention must be paid to avoid overflow. For example, 9999999999999999999 will be considered as overflow because it exceeds the upper limit of long integer, but 9999999999999999999.0 will be considered as a legal float number.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## Constants
|
||||
|
||||
TDengine supports a variety of constants:
|
||||
|
||||
| # | **Syntax** | **Type** | **Description** |
|
||||
| --- | :-------: | --------- | -------------------------------------- |
|
||||
| 1 | [{+ \| -}]123 | BIGINT | Integer literals are of type BIGINT. Data that exceeds the length of the BIGINT type is truncated. |
|
||||
| 2 | 123.45 | DOUBLE | Floating-point literals are of type DOUBLE. Numeric values will be determined as integer or float type according to whether there is decimal point or whether scientific notation is used. |
|
||||
| 3 | 1.2E3 | DOUBLE | Literals in scientific notation are of type DOUBLE. |
|
||||
| 4 | 'abc' | BINARY | Content enclosed in single quotation marks is of type BINARY. The size of a BINARY is the size of the string in bytes. A literal single quote inside the string must be escaped with a backslash (\'). |
|
||||
| 5 | 'abc' | BINARY | Content enclosed in double quotation marks is of type BINARY. The size of a BINARY is the size of the string in bytes. A literal double quote inside the string must be escaped with a backslash (\"). |
|
||||
| 6 | TIMESTAMP {'literal' \| "literal"} | TIMESTAMP | The TIMESTAMP keyword indicates that the following string literal is interpreted as a timestamp. The string must be in YYYY-MM-DD HH:mm:ss.MS format. The precision is inherited from the database configuration. |
|
||||
| 7 | {TRUE \| FALSE} | BOOL | Boolean literals are of type BOOL. |
|
||||
| 8 | {'' \| "" \| '\t' \| "\t" \| ' ' \| " " \| NULL } | -- | The preceding characters indicate null literals. These can be used with any data type. |
|
||||
| # | **Syntax** | **Type** | **Description** |
|
||||
| --- | :-----------------------------------------------: | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1 | [{+ \| -}]123 | BIGINT | Integer literals are of type BIGINT. Data that exceeds the length of the BIGINT type is truncated. |
|
||||
| 2 | 123.45 | DOUBLE | Floating-point literals are of type DOUBLE. Numeric values will be determined as integer or float type according to whether there is decimal point or whether scientific notation is used. |
|
||||
| 3 | 1.2E3 | DOUBLE | Literals in scientific notation are of type DOUBLE. |
|
||||
| 4 | 'abc' | BINARY | Content enclosed in single quotation marks is of type BINARY. The size of a BINARY is the size of the string in bytes. A literal single quote inside the string must be escaped with a backslash `\'`. |
|
||||
| 5 | 'abc' | BINARY | Content enclosed in double quotation marks is of type BINARY. The size of a BINARY is the size of the string in bytes. A literal double quote inside the string must be escaped with a backslash `\"`. |
|
||||
| 6 | TIMESTAMP {'literal' \| "literal"} | TIMESTAMP | The TIMESTAMP keyword indicates that the following string literal is interpreted as a timestamp. The string must be in YYYY-MM-DD HH:mm:ss.MS format. The precision is inherited from the database configuration. |
|
||||
| 7 | {TRUE \| FALSE} | BOOL | Boolean literals are of type BOOL. |
|
||||
| 8 | {'' \| "" \| '\t' \| "\t" \| ' ' \| " " \| NULL } | -- | The preceding characters indicate null literals. These can be used with any data type. |
|
||||
|
||||
:::note
|
||||
Numeric values will be determined as integer or float type according to whether there is decimal point or whether scientific notation is used, so attention must be paid to avoid overflow. For example, 9999999999999999999 will be considered as overflow because it exceeds the upper limit of long integer, but 9999999999999999999.0 will be considered as a legal float number.
|
||||
|
|
|
@ -16,6 +16,8 @@ INSERT INTO
|
|||
[(field1_name, ...)]
|
||||
VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
|
||||
...];
|
||||
|
||||
INSERT INTO tb_name [(field1_name, ...)] subquery
|
||||
```
|
||||
|
||||
**Timestamps**
|
||||
|
@ -37,7 +39,7 @@ INSERT INTO
|
|||
|
||||
4. The FILE clause inserts tags or data from a comma-separates values (CSV) file. Do not include headers in your CSV files.
|
||||
|
||||
5. A single INSERT statement can write data to multiple tables.
|
||||
5. A single `INSERT ... VALUES` statement and `INSERT ... FILE` statement can write data to multiple tables.
|
||||
|
||||
6. The INSERT statement is fully parsed before being executed, so that if any element of the statement fails, the entire statement will fail. For example, the following statement will not create a table because the latter part of the statement is invalid:
|
||||
|
||||
|
@ -47,6 +49,8 @@ INSERT INTO
|
|||
|
||||
7. However, an INSERT statement that writes data to multiple subtables can succeed for some tables and fail for others. This situation is caused because vnodes perform write operations independently of each other. One vnode failing to write data does not affect the ability of other vnodes to write successfully.
|
||||
|
||||
8. Data from TDengine can be inserted into a specified table using the `INSERT ... subquery` statement. Arbitrary query statements are supported. This syntax can only be used for subtables and normal tables, and does not support automatic table creation.
|
||||
|
||||
## Insert a Record
|
||||
|
||||
Single row or multiple rows specified with VALUES can be inserted into a specific table. A single row is inserted using the below statement.
|
||||
|
|
|
@ -66,9 +66,9 @@ order_expr:
|
|||
|
||||
A query can be performed on some or all columns. Data and tag columns can all be included in the SELECT list.
|
||||
|
||||
## Wildcards
|
||||
### Wildcards
|
||||
|
||||
You can use an asterisk (\*) as a wildcard character to indicate all columns. For standard tables, the asterisk indicates only data columns. For supertables and subtables, tag columns are also included.
|
||||
You can use an asterisk (\*) as a wildcard character to indicate all columns. For normal tables or sub-tables, the asterisk indicates only data columns. For supertables, tag columns are also included when using asterisk (\*).
|
||||
|
||||
```sql
|
||||
SELECT * FROM d1001;
|
||||
|
@ -136,6 +136,8 @@ taos> SELECT ts, ts AS primary_key_ts FROM d1001;
|
|||
|
||||
### Pseudocolumns
|
||||
|
||||
**Pseudocolumn:** A pseudo-column behaves like a table column but is not actually stored in the table. You can select from pseudo-columns, but you cannot insert, update, or delete their values. A pseudo-column is also similar to a function without arguments. This section describes these pseudo-columns:
|
||||
|
||||
**TBNAME**
|
||||
The TBNAME pseudocolumn in a supertable contains the names of subtables within the supertable.
|
||||
|
||||
|
@ -179,6 +181,14 @@ In TDengine, the first column of all tables must be a timestamp. This column is
|
|||
select _rowts, max(current) from meters;
|
||||
```
|
||||
|
||||
**\_IROWTS**
|
||||
|
||||
The \_IROWTS pseudocolumn can only be used with INTERP function. This pseudocolumn can be used to retrieve the corresponding timestamp column associated with the interpolation results.
|
||||
|
||||
```sql
|
||||
select _irowts, interp(current) from meters range('2020-01-01 10:00:00', '2020-01-01 10:30:00') every(1s) fill(linear);
|
||||
```
|
||||
|
||||
## Query Objects
|
||||
|
||||
`FROM` can be followed by a number of tables or super tables, or can be followed by a sub-query.
|
||||
|
|
|
@ -13,7 +13,7 @@ Single row functions return a result for each row.
|
|||
#### ABS
|
||||
|
||||
```sql
|
||||
SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ABS(expr)
|
||||
```
|
||||
|
||||
**Description**: The absolute value of a specific field.
|
||||
|
@ -31,7 +31,7 @@ SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ACOS
|
||||
|
||||
```sql
|
||||
SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ACOS(expr)
|
||||
```
|
||||
|
||||
**Description**: The arc cosine of a specific field.
|
||||
|
@ -49,7 +49,7 @@ SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ASIN
|
||||
|
||||
```sql
|
||||
SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ASIN(expr)
|
||||
```
|
||||
|
||||
**Description**: The arc sine of a specific field.
|
||||
|
@ -68,7 +68,7 @@ SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ATAN
|
||||
|
||||
```sql
|
||||
SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ATAN(expr)
|
||||
```
|
||||
|
||||
**Description**: The arc tangent of a specific field.
|
||||
|
@ -87,7 +87,7 @@ SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### CEIL
|
||||
|
||||
```sql
|
||||
SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
CEIL(expr)
|
||||
```
|
||||
|
||||
**Description**: The rounded up value of a specific field
|
||||
|
@ -105,7 +105,7 @@ SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### COS
|
||||
|
||||
```sql
|
||||
SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
COS(expr)
|
||||
```
|
||||
|
||||
**Description**: The cosine of a specific field.
|
||||
|
@ -123,7 +123,7 @@ SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### FLOOR
|
||||
|
||||
```sql
|
||||
SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
FLOOR(expr)
|
||||
```
|
||||
|
||||
**Description**: The rounded down value of a specific field
|
||||
|
@ -132,7 +132,7 @@ SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### LOG
|
||||
|
||||
```sql
|
||||
SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LOG(expr [, base])
|
||||
```
|
||||
|
||||
**Description**: The logarithm of a specific field with `base` as the radix. If you do not enter a base, the natural logarithm of the field is returned.
|
||||
|
@ -151,7 +151,7 @@ SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### POW
|
||||
|
||||
```sql
|
||||
SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
|
||||
POW(expr, power)
|
||||
```
|
||||
|
||||
**Description**: The power of a specific field with `power` as the exponent.
|
||||
|
@ -170,7 +170,7 @@ SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ROUND
|
||||
|
||||
```sql
|
||||
SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
ROUND(expr)
|
||||
```
|
||||
|
||||
**Description**: The rounded value of a specific field.
|
||||
|
@ -180,7 +180,7 @@ SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### SIN
|
||||
|
||||
```sql
|
||||
SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SIN(expr)
|
||||
```
|
||||
|
||||
**Description**: The sine of a specific field.
|
||||
|
@ -198,7 +198,7 @@ SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### SQRT
|
||||
|
||||
```sql
|
||||
SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SQRT(expr)
|
||||
```
|
||||
|
||||
**Description**: The square root of a specific field.
|
||||
|
@ -216,7 +216,7 @@ SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### TAN
|
||||
|
||||
```sql
|
||||
SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
TAN(expr)
|
||||
```
|
||||
|
||||
**Description**: The tangent of a specific field.
|
||||
|
@ -238,7 +238,7 @@ Concatenation functions take strings as input and produce string or numeric valu
|
|||
#### CHAR_LENGTH
|
||||
|
||||
```sql
|
||||
SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CHAR_LENGTH(expr)
|
||||
```
|
||||
|
||||
**Description**: The length in number of characters of a string
|
||||
|
@ -254,7 +254,7 @@ SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### CONCAT
|
||||
|
||||
```sql
|
||||
SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CONCAT(expr1, expr2 [, expr] ...)
|
||||
```
|
||||
|
||||
**Description**: The concatenation result of two or more strings
|
||||
|
@ -271,7 +271,7 @@ SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHER
|
|||
#### CONCAT_WS
|
||||
|
||||
```sql
|
||||
SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CONCAT_WS(separator_expr, expr1, expr2 [, expr] ...)
|
||||
```
|
||||
|
||||
**Description**: The concatenation result of two or more strings with separator
|
||||
|
@ -288,7 +288,7 @@ SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | st
|
|||
#### LENGTH
|
||||
|
||||
```sql
|
||||
SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LENGTH(expr)
|
||||
```
|
||||
|
||||
**Description**: The length in bytes of a string
|
||||
|
@ -305,7 +305,7 @@ SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### LOWER
|
||||
|
||||
```sql
|
||||
SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LOWER(expr)
|
||||
```
|
||||
|
||||
**Description**: Convert the input string to lower case
|
||||
|
@ -322,7 +322,7 @@ SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### LTRIM
|
||||
|
||||
```sql
|
||||
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LTRIM(expr)
|
||||
```
|
||||
|
||||
**Description**: Remove the left leading blanks of a string
|
||||
|
@ -339,7 +339,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### RTRIM
|
||||
|
||||
```sql
|
||||
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LTRIM(expr)
|
||||
```
|
||||
|
||||
**Description**: Remove the right tailing blanks of a string
|
||||
|
@ -356,7 +356,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### SUBSTR
|
||||
|
||||
```sql
|
||||
SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SUBSTR(expr, pos [, len])
|
||||
```
|
||||
|
||||
**Description**: The sub-string starting from `pos` with length of `len` from the original string `str` - If `len` is not specified, it means from `pos` to the end.
|
||||
|
@ -373,7 +373,7 @@ SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### UPPER
|
||||
|
||||
```sql
|
||||
SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
UPPER(expr)
|
||||
```
|
||||
|
||||
**Description**: Convert the input string to upper case
|
||||
|
@ -394,10 +394,10 @@ Conversion functions change the data type of a value.
|
|||
#### CAST
|
||||
|
||||
```sql
|
||||
SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CAST(expr AS type_name)
|
||||
```
|
||||
|
||||
**Description**: Convert the input data `expression` into the type specified by `type_name`. This function can be used only in SELECT statements.
|
||||
**Description**: Convert the input data `expr` into the type specified by `type_name`. This function can be used only in SELECT statements.
|
||||
|
||||
**Return value type**: The type specified by parameter `type_name`
|
||||
|
||||
|
@ -418,7 +418,7 @@ SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### TO_ISO8601
|
||||
|
||||
```sql
|
||||
SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TO_ISO8601(expr [, timezone])
|
||||
```
|
||||
|
||||
**Description**: The ISO8601 date/time format converted from a UNIX timestamp, plus the timezone. You can specify any time zone with the timezone parameter. If you do not enter this parameter, the time zone on the client is used.
|
||||
|
@ -441,7 +441,7 @@ SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### TO_JSON
|
||||
|
||||
```sql
|
||||
SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TO_JSON(str_literal)
|
||||
```
|
||||
|
||||
**Description**: Converts a string into JSON.
|
||||
|
@ -458,7 +458,7 @@ SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### TO_UNIXTIMESTAMP
|
||||
|
||||
```sql
|
||||
SELECT TO_UNIXTIMESTAMP(datetime_string) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TO_UNIXTIMESTAMP(expr)
|
||||
```
|
||||
|
||||
**Description**: UNIX timestamp converted from a string of date/time format
|
||||
|
@ -486,9 +486,7 @@ All functions that return the current time, such as `NOW`, `TODAY`, and `TIMEZON
|
|||
#### NOW
|
||||
|
||||
```sql
|
||||
SELECT NOW() FROM { tb_name | stb_name } [WHERE clause];
|
||||
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior NOW();
|
||||
INSERT INTO tb_name VALUES (NOW(), ...);
|
||||
NOW()
|
||||
```
|
||||
|
||||
**Description**: The current time of the client side system
|
||||
|
@ -511,7 +509,7 @@ INSERT INTO tb_name VALUES (NOW(), ...);
|
|||
#### TIMEDIFF
|
||||
|
||||
```sql
|
||||
SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TIMEDIFF(expr1, expr2 [, time_unit])
|
||||
```
|
||||
|
||||
**Description**: The difference between two timestamps, and rounded to the time unit specified by `time_unit`
|
||||
|
@ -534,7 +532,7 @@ SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM
|
|||
#### TIMETRUNCATE
|
||||
|
||||
```sql
|
||||
SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TIMETRUNCATE(expr, time_unit)
|
||||
```
|
||||
|
||||
**Description**: Truncate the input timestamp with unit specified by `time_unit`
|
||||
|
@ -555,7 +553,7 @@ SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name
|
|||
#### TIMEZONE
|
||||
|
||||
```sql
|
||||
SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
|
||||
TIMEZONE()
|
||||
```
|
||||
|
||||
**Description**: The timezone of the client side system
|
||||
|
@ -570,9 +568,7 @@ SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### TODAY
|
||||
|
||||
```sql
|
||||
SELECT TODAY() FROM { tb_name | stb_name } [WHERE clause];
|
||||
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior TODAY()];
|
||||
INSERT INTO tb_name VALUES (TODAY(), ...);
|
||||
TODAY()
|
||||
```
|
||||
|
||||
**Description**: The timestamp of 00:00:00 of the client side system
|
||||
|
@ -599,7 +595,12 @@ TDengine supports the following aggregate functions:
|
|||
### APERCENTILE
|
||||
|
||||
```sql
|
||||
SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHERE clause]
|
||||
APERCENTILE(expr, p [, algo_type])
|
||||
|
||||
algo_type: {
|
||||
"default"
|
||||
| "t-digest"
|
||||
}
|
||||
```
|
||||
|
||||
**Description**: Similar to `PERCENTILE`, but a simulated result is returned
|
||||
|
@ -611,14 +612,14 @@ SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHER
|
|||
**Applicable table types**: standard tables and supertables
|
||||
|
||||
**Explanations**:
|
||||
- _P_ is in range [0,100], when _P_ is 0, the result is same as using function MIN; when _P_ is 100, the result is same as function MAX.
|
||||
- _p_ is in range [0,100], when _p_ is 0, the result is same as using function MIN; when _p_ is 100, the result is same as function MAX.
|
||||
- `algo_type` can only be input as `default` or `t-digest` Enter `default` to use a histogram-based algorithm. Enter `t-digest` to use the t-digest algorithm to calculate the approximation of the quantile. `default` is used by default.
|
||||
- The approximation result of `t-digest` algorithm is sensitive to input data order. For example, when querying STable with different input data order there might be minor differences in calculated results.
|
||||
|
||||
### AVG
|
||||
|
||||
```sql
|
||||
SELECT AVG(field_name) FROM tb_name [WHERE clause];
|
||||
AVG(expr)
|
||||
```
|
||||
|
||||
**Description**: The average value of the specified fields.
|
||||
|
@ -633,7 +634,7 @@ SELECT AVG(field_name) FROM tb_name [WHERE clause];
|
|||
### COUNT
|
||||
|
||||
```sql
|
||||
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
|
||||
COUNT({* | expr})
|
||||
```
|
||||
|
||||
**Description**: The number of records in the specified fields.
|
||||
|
@ -653,7 +654,7 @@ If you input a specific column, the number of non-null values in the column is r
|
|||
### ELAPSED
|
||||
|
||||
```sql
|
||||
SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE clause] [INTERVAL(interval [, offset]) [SLIDING sliding]];
|
||||
ELAPSED(ts_primary_key [, time_unit])
|
||||
```
|
||||
|
||||
**Description**:`elapsed` function can be used to calculate the continuous time length in which there is valid data. If it's used with `INTERVAL` clause, the returned result is the calcualted time length within each time window. If it's used without `INTERVAL` caluse, the returned result is the calculated time length within the specified time range. Please be noted that the return value of `elapsed` is the number of `time_unit` in the calculated time length.
|
||||
|
@ -665,7 +666,7 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
|
|||
**Applicable tables**: table, STable, outter in nested query
|
||||
|
||||
**Explanations**:
|
||||
- `field_name` parameter can only be the first column of a table, i.e. timestamp primary key.
|
||||
- `ts_primary_key` parameter can only be the first column of a table, i.e. timestamp primary key.
|
||||
- The minimum value of `time_unit` is the time precision of the database. If `time_unit` is not specified, the time precision of the database is used as the default time unit. Time unit specified by `time_unit` can be:
|
||||
1b (nanoseconds), 1u (microseconds), 1a (milliseconds), 1s (seconds), 1m (minutes), 1h (hours), 1d (days), or 1w (weeks)
|
||||
- It can be used with `INTERVAL` to get the time valid time length of each time window. Please be noted that the return value is same as the time window for all time windows except for the first and the last time window.
|
||||
|
@ -679,7 +680,7 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
|
|||
### LEASTSQUARES
|
||||
|
||||
```sql
|
||||
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause];
|
||||
LEASTSQUARES(expr, start_val, step_val)
|
||||
```
|
||||
|
||||
**Description**: The linear regression function of the specified column and the timestamp column (primary key), `start_val` is the initial value and `step_val` is the step value.
|
||||
|
@ -694,7 +695,7 @@ SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause]
|
|||
### SPREAD
|
||||
|
||||
```sql
|
||||
SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
SPREAD(expr)
|
||||
```
|
||||
|
||||
**Description**: The difference between the max and the min of a specific column
|
||||
|
@ -709,7 +710,7 @@ SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### STDDEV
|
||||
|
||||
```sql
|
||||
SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
|
||||
STDDEV(expr)
|
||||
```
|
||||
|
||||
**Description**: Standard deviation of a specific column in a table or STable
|
||||
|
@ -724,7 +725,7 @@ SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
|
|||
### SUM
|
||||
|
||||
```sql
|
||||
SELECT SUM(field_name) FROM tb_name [WHERE clause];
|
||||
SUM(expr)
|
||||
```
|
||||
|
||||
**Description**: The sum of a specific column in a table or STable
|
||||
|
@ -739,7 +740,7 @@ SELECT SUM(field_name) FROM tb_name [WHERE clause];
|
|||
### HYPERLOGLOG
|
||||
|
||||
```sql
|
||||
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
HYPERLOGLOG(expr)
|
||||
```
|
||||
|
||||
**Description**:
|
||||
|
@ -756,7 +757,7 @@ SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### HISTOGRAM
|
||||
|
||||
```sql
|
||||
SELECT HISTOGRAM(field_name,bin_type, bin_description, normalized) FROM tb_name [WHERE clause];
|
||||
HISTOGRAM(expr,bin_type, bin_description, normalized)
|
||||
```
|
||||
|
||||
**Description**:Returns count of data points in user-specified ranges.
|
||||
|
@ -786,7 +787,7 @@ SELECT HISTOGRAM(field_name,bin_type, bin_description, normalized) FROM tb_nam
|
|||
### PERCENTILE
|
||||
|
||||
```sql
|
||||
SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
|
||||
PERCENTILE(expr, p)
|
||||
```
|
||||
|
||||
**Description**: The value whose rank in a specific column matches the specified percentage. If such a value matching the specified percentage doesn't exist in the column, an interpolation value will be returned.
|
||||
|
@ -797,7 +798,7 @@ SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
|
|||
|
||||
**Applicable table types**: table only
|
||||
|
||||
**More explanations**: _P_ is in range [0,100], when _P_ is 0, the result is same as using function MIN; when _P_ is 100, the result is same as function MAX.
|
||||
**More explanations**: _p_ is in range [0,100], when _p_ is 0, the result is same as using function MIN; when _p_ is 100, the result is same as function MAX.
|
||||
|
||||
|
||||
## Selection Functions
|
||||
|
@ -807,7 +808,7 @@ Selection functions return one or more results depending. You can specify the ti
|
|||
### BOTTOM
|
||||
|
||||
```sql
|
||||
SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
BOTTOM(expr, k)
|
||||
```
|
||||
|
||||
**Description**: The least _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
|
||||
|
@ -827,7 +828,7 @@ SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### FIRST
|
||||
|
||||
```sql
|
||||
SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
FIRST(expr)
|
||||
```
|
||||
|
||||
**Description**: The first non-null value of a specific column in a table or STable
|
||||
|
@ -847,7 +848,7 @@ SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### INTERP
|
||||
|
||||
```sql
|
||||
SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RANGE(timestamp1,timestamp2) EVERY(interval) FILL({ VALUE | PREV | NULL | LINEAR | NEXT});
|
||||
INTERP(expr)
|
||||
```
|
||||
|
||||
**Description**: The value that matches the specified timestamp range is returned, if existing; or an interpolation value is returned.
|
||||
|
@ -866,11 +867,12 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RA
|
|||
- The number of rows in the result set of `INTERP` is determined by the parameter `EVERY`. Starting from timestamp1, one interpolation is performed for every time interval specified `EVERY` parameter.
|
||||
- Interpolation is performed based on `FILL` parameter.
|
||||
- `INTERP` can only be used to interpolate in single timeline. So it must be used with `partition by tbname` when it's used on a STable.
|
||||
- Pseudo column `_irowts` can be used along with `INTERP` to return the timestamps associated with interpolation points(support after version 3.0.1.4).
|
||||
|
||||
### LAST
|
||||
|
||||
```sql
|
||||
SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
LAST(expr)
|
||||
```
|
||||
|
||||
**Description**: The last non-NULL value of a specific column in a table or STable
|
||||
|
@ -891,7 +893,7 @@ SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### LAST_ROW
|
||||
|
||||
```sql
|
||||
SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
|
||||
LAST_ROW(expr)
|
||||
```
|
||||
|
||||
**Description**: The last row of a table or STable
|
||||
|
@ -910,7 +912,7 @@ SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
|
|||
### MAX
|
||||
|
||||
```sql
|
||||
SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
MAX(expr)
|
||||
```
|
||||
|
||||
**Description**: The maximum value of a specific column of a table or STable
|
||||
|
@ -925,7 +927,7 @@ SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### MIN
|
||||
|
||||
```sql
|
||||
SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
||||
MIN(expr)
|
||||
```
|
||||
|
||||
**Description**: The minimum value of a specific column in a table or STable
|
||||
|
@ -940,7 +942,7 @@ SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
|||
### MODE
|
||||
|
||||
```sql
|
||||
SELECT MODE(field_name) FROM tb_name [WHERE clause];
|
||||
MODE(expr)
|
||||
```
|
||||
|
||||
**Description**:The value which has the highest frequency of occurrence. NULL is returned if there are multiple values which have highest frequency of occurrence.
|
||||
|
@ -955,7 +957,7 @@ SELECT MODE(field_name) FROM tb_name [WHERE clause];
|
|||
### SAMPLE
|
||||
|
||||
```sql
|
||||
SELECT SAMPLE(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SAMPLE(expr, k)
|
||||
```
|
||||
|
||||
**Description**: _k_ sampling values of a specific column. The applicable range of _k_ is [1,1000].
|
||||
|
@ -977,7 +979,7 @@ This function cannot be used in expression calculation.
|
|||
### TAIL
|
||||
|
||||
```sql
|
||||
SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
|
||||
TAIL(expr, k, offset_val)
|
||||
```
|
||||
|
||||
**Description**: The next _k_ rows are returned after skipping the last `offset_val` rows, NULL values are not ignored. `offset_val` is optional parameter. When it's not specified, the last _k_ rows are returned. When `offset_val` is used, the effect is same as `order by ts desc LIMIT k OFFSET offset_val`.
|
||||
|
@ -994,7 +996,7 @@ SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
|
|||
### TOP
|
||||
|
||||
```sql
|
||||
SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TOP(expr, k)
|
||||
```
|
||||
|
||||
**Description**: The greatest _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
|
||||
|
@ -1014,7 +1016,7 @@ SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### UNIQUE
|
||||
|
||||
```sql
|
||||
SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
||||
UNIQUE(expr)
|
||||
```
|
||||
|
||||
**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword, but it can also be used to match tags or timestamp. The first occurrence of a timestamp or tag is used.
|
||||
|
@ -1033,7 +1035,7 @@ TDengine includes extensions to standard SQL that are intended specifically for
|
|||
### CSUM
|
||||
|
||||
```sql
|
||||
SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CSUM(expr)
|
||||
```
|
||||
|
||||
**Description**: The cumulative sum of each row for a specific column. The number of output rows is same as that of the input rows.
|
||||
|
@ -1056,7 +1058,12 @@ SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
### DERIVATIVE
|
||||
|
||||
```sql
|
||||
SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHERE clause];
|
||||
DERIVATIVE(expr, time_inerval, ignore_negative)
|
||||
|
||||
ignore_negative: {
|
||||
0
|
||||
| 1
|
||||
}
|
||||
```
|
||||
|
||||
**Description**: The derivative of a specific column. The time rage can be specified by parameter `time_interval`, the minimum allowed time range is 1 second (1s); the value of `ignore_negative` can be 0 or 1, 1 means negative values are ignored.
|
||||
|
@ -1075,7 +1082,12 @@ SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHER
|
|||
### DIFF
|
||||
|
||||
```sql
|
||||
SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHERE clause];
|
||||
DIFF(expr [, ignore_negative])
|
||||
|
||||
ignore_negative: {
|
||||
0
|
||||
| 1
|
||||
}
|
||||
```
|
||||
|
||||
**Description**: The different of each row with its previous row for a specific column. `ignore_negative` can be specified as 0 or 1, the default value is 1 if it's not specified. `1` means negative values are ignored.
|
||||
|
@ -1095,7 +1107,7 @@ SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHER
|
|||
### IRATE
|
||||
|
||||
```sql
|
||||
SELECT IRATE(field_name) FROM tb_name WHERE clause;
|
||||
IRATE(expr)
|
||||
```
|
||||
|
||||
**Description**: instantaneous rate on a specific column. The last two samples in the specified time range are used to calculate instantaneous rate. If the last sample value is smaller, then only the last sample value is used instead of the difference between the last two sample values.
|
||||
|
@ -1110,7 +1122,7 @@ SELECT IRATE(field_name) FROM tb_name WHERE clause;
|
|||
### MAVG
|
||||
|
||||
```sql
|
||||
SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
|
||||
MAVG(expr, k)
|
||||
```
|
||||
|
||||
**Description**: The moving average of continuous _k_ values of a specific column. If the number of input rows is less than _k_, nothing is returned. The applicable range of _k_ is [1,1000].
|
||||
|
@ -1133,7 +1145,7 @@ SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
|
|||
### STATECOUNT
|
||||
|
||||
```sql
|
||||
SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clause];
|
||||
STATECOUNT(expr, oper, val)
|
||||
```
|
||||
|
||||
**Description**: The number of continuous rows satisfying the specified conditions for a specific column. The result is shown as an extra column for each row. If the specified condition is evaluated as true, the number is increased by 1; otherwise the number is reset to -1. If the input value is NULL, then the corresponding row is skipped.
|
||||
|
@ -1160,7 +1172,7 @@ SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clau
|
|||
### STATEDURATION
|
||||
|
||||
```sql
|
||||
SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [WHERE clause];
|
||||
STATEDURATION(expr, oper, val, unit)
|
||||
```
|
||||
|
||||
**Description**: The length of time range in which all rows satisfy the specified condition for a specific column. The result is shown as an extra column for each row. The length for the first row that satisfies the condition is 0. Next, if the condition is evaluated as true for a row, the time interval between current row and its previous row is added up to the time range; otherwise the time range length is reset to -1. If the value of the column is NULL, the corresponding row is skipped.
|
||||
|
@ -1188,7 +1200,7 @@ SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [W
|
|||
### TWA
|
||||
|
||||
```sql
|
||||
SELECT TWA(field_name) FROM tb_name WHERE clause;
|
||||
TWA(expr)
|
||||
```
|
||||
|
||||
**Description**: Time weighted average on a specific column within a time range
|
||||
|
|
|
@ -343,6 +343,7 @@ The following list shows all reserved keywords:
|
|||
### \_
|
||||
|
||||
- \_C0
|
||||
- \_IROWTS
|
||||
- \_QDURATION
|
||||
- \_QEND
|
||||
- \_QSTART
|
||||
|
|
|
@ -11,7 +11,15 @@ TDengine includes a built-in database named `INFORMATION_SCHEMA` to provide acce
|
|||
4. Future versions of TDengine can add new columns to INFORMATION_SCHEMA tables without affecting existing business systems.
|
||||
5. It is easier for users coming from other database management systems. For example, Oracle users can query data dictionary tables.
|
||||
|
||||
Note: SHOW statements are still supported for the convenience of existing users.
|
||||
:::info
|
||||
|
||||
- SHOW statements are still supported for the convenience of existing users.
|
||||
- Some columns in the system table may be keywords, and you need to use the escape character '\`' when querying, for example, to query the VGROUPS in the database `test`:
|
||||
```sql
|
||||
select `vgroups` from ins_databases where name = 'test';
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
This document introduces the tables of INFORMATION_SCHEMA and their structure.
|
||||
|
||||
|
@ -102,7 +110,11 @@ Provides information about user-created databases. Similar to SHOW DATABASES.
|
|||
| 24 | wal_retention_period | INT | WAL retention period |
|
||||
| 25 | wal_retention_size | INT | Maximum WAL size |
|
||||
| 26 | wal_roll_period | INT | WAL rotation period |
|
||||
| 27 | wal_segment_size | WAL file size |
|
||||
| 27 | wal_segment_size | BIGINT | WAL file size |
|
||||
| 28 | stt_trigger | SMALLINT | The threshold for number of files to trigger file merging |
|
||||
| 29 | table_prefix | SMALLINT | The prefix length in the table name that is ignored when distributing table to vnode based on table name |
|
||||
| 30 | table_suffix | SMALLINT | The suffix length in the table name that is ignored when distributing table to vnode based on table name |
|
||||
| 31 | tsdb_pagesize | INT | The page size for internal storage engine, its unit is KB |
|
||||
|
||||
## INS_FUNCTIONS
|
||||
|
||||
|
|
|
@ -11,12 +11,13 @@ description: "This document explains how TDengine SQL has changed in version 3.0
|
|||
| 1 | VARCHAR | Added | Alias of BINARY.
|
||||
| 2 | TIMESTAMP literal | Added | TIMESTAMP 'timestamp format' syntax now supported.
|
||||
| 3 | _ROWTS pseudocolumn | Added | Indicates the primary key. Alias of _C0.
|
||||
| 4 | INFORMATION_SCHEMA | Added | Database for system metadata containing all schema definitions
|
||||
| 5 | PERFORMANCE_SCHEMA | Added | Database for system performance information.
|
||||
| 6 | Connection queries | Deprecated | Connection queries are no longer supported. The syntax and interfaces are deprecated.
|
||||
| 7 | Mixed operations | Enhanced | Mixing scalar and vector operations in queries has been enhanced and is supported in all SELECT clauses.
|
||||
| 8 | Tag operations | Added | Tag columns can be used in queries and clauses like data columns.
|
||||
| 9 | Timeline clauses and time functions in supertables | Enhanced | When PARTITION BY is not used, data in supertables is merged into a single timeline.
|
||||
| 4 | _IROWTS pseudocolumn | Added | Used to retrieve timestamps with INTERP function.
|
||||
| 5 | INFORMATION_SCHEMA | Added | Database for system metadata containing all schema definitions
|
||||
| 6 | PERFORMANCE_SCHEMA | Added | Database for system performance information.
|
||||
| 7 | Connection queries | Deprecated | Connection queries are no longer supported. The syntax and interfaces are deprecated.
|
||||
| 8 | Mixed operations | Enhanced | Mixing scalar and vector operations in queries has been enhanced and is supported in all SELECT clauses.
|
||||
| 9 | Tag operations | Added | Tag columns can be used in queries and clauses like data columns.
|
||||
| 10 | Timeline clauses and time functions in supertables | Enhanced | When PARTITION BY is not used, data in supertables is merged into a single timeline.
|
||||
|
||||
## SQL Syntax
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ where `TOKEN` is the string after Base64 encoding of `{username}:{password}`, e.
|
|||
|
||||
### HTTP body structure
|
||||
|
||||
#### Successful Operation
|
||||
#### Successful Insert Operation
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -143,7 +143,7 @@ Description:
|
|||
- rows: (`int`) Only returns `1`.
|
||||
- data: (`[][]any`) Returns the number of rows affected.
|
||||
|
||||
#### Successful Query
|
||||
#### Successful Query Operation
|
||||
|
||||
Example:
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ The parameters are described as follows:
|
|||
- **protocol**: Specify which connection method to use. For example, `taos+ws://localhost:6041` uses Websocket to establish connections.
|
||||
- **username/password**: Username and password used to create connections.
|
||||
- **host/port**: Specifies the server and port to establish a connection. If you do not specify a hostname or port, native connections default to `localhost:6030` and Websocket connections default to `localhost:6041`.
|
||||
- **database**: Specify the default database to connect to.
|
||||
- **database**: Specify the default database to connect to. It's optional.
|
||||
- **params**:Optional parameters.
|
||||
|
||||
A sample DSN description string is as follows:
|
||||
|
|
|
@ -17,7 +17,7 @@ import CSAsyncQuery from "../../07-develop/04-query-data/_cs_async.mdx"
|
|||
|
||||
`TDengine.Connector` is a C# language connector provided by TDengine that allows C# developers to develop C# applications that access TDengine cluster data.
|
||||
|
||||
The `TDengine.Connector` connector supports connect to TDengine instances via the TDengine client driver (taosc), providing data writing, querying, subscription, schemaless writing, bind interface, etc. The `TDengine.Connector` currently does not provide a REST connection interface. Developers can write their RESTful application by referring to the [REST API](/reference/rest-api/) documentation.
|
||||
The `TDengine.Connector` connector supports connect to TDengine instances via the TDengine client driver (taosc), providing data writing, querying, subscription, schemaless writing, bind interface, etc.The `TDengine.Connector` also supports WebSocket and developers can build connection through DSN, which supports data writing, querying, and parameter binding, etc.
|
||||
|
||||
This article describes how to install `TDengine.Connector` in a Linux or Windows environment and connect to TDengine clusters via `TDengine.Connector` to perform basic operations such as data writing and querying.
|
||||
|
||||
|
@ -35,6 +35,10 @@ Please refer to [version support list](/reference/connector#version-support)
|
|||
|
||||
## Supported features
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="Native Connection">
|
||||
|
||||
1. Connection Management
|
||||
2. General Query
|
||||
3. Continuous Query
|
||||
|
@ -42,6 +46,18 @@ Please refer to [version support list](/reference/connector#version-support)
|
|||
5. Subscription
|
||||
6. Schemaless
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket Connection">
|
||||
|
||||
1. Connection Management
|
||||
2. General Query
|
||||
3. Continuous Query
|
||||
4. Parameter Binding
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Installation Steps
|
||||
|
||||
### Pre-installation preparation
|
||||
|
@ -74,12 +90,18 @@ cp -r src/ myProject
|
|||
cd myProject
|
||||
dotnet add exmaple.csproj reference src/TDengine.csproj
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Establish a Connection
|
||||
|
||||
``` C#
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="Native Connection">
|
||||
|
||||
``` csharp
|
||||
using TDengineDriver;
|
||||
|
||||
namespace TDengineExample
|
||||
|
@ -112,14 +134,62 @@ namespace TDengineExample
|
|||
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket Connection">
|
||||
|
||||
The structure of the DSN description string is as follows:
|
||||
|
||||
```text
|
||||
[<protocol>]://[[<username>:<password>@]<host>:<port>][/<database>][?<p1>=<v1>[&<p2>=<v2>]]
|
||||
|------------|---|-----------|-----------|------|------|------------|-----------------------|
|
||||
| protocol | | username | password | host | port | database | params |
|
||||
```
|
||||
|
||||
The parameters are described as follows:
|
||||
|
||||
* **protocol**: Specify which connection method to use (support http/ws). For example, `ws://localhost:6041` uses Websocket to establish connections.
|
||||
* **username/password**: Username and password used to create connections.
|
||||
* **host/port**: Specifies the server and port to establish a connection. Websocket connections default to `localhost:6041`.
|
||||
* **database**: Specify the default database to connect to. It's optional.
|
||||
* **params**:Optional parameters.
|
||||
|
||||
A sample DSN description string is as follows:
|
||||
|
||||
```text
|
||||
ws://localhost:6041/test
|
||||
```
|
||||
|
||||
``` csharp
|
||||
{{#include docs/examples/csharp/wsConnect/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Usage examples
|
||||
|
||||
### Write data
|
||||
|
||||
#### SQL Write
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="Native Connection">
|
||||
|
||||
<CSInsert />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket Connection">
|
||||
|
||||
```csharp
|
||||
{{#include docs/examples/csharp/wsInsert/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
#### InfluxDB line protocol write
|
||||
|
||||
<CSInfluxLine />
|
||||
|
@ -132,12 +202,48 @@ namespace TDengineExample
|
|||
|
||||
<CSOpenTSDBJson />
|
||||
|
||||
#### Parameter Binding
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="Native Connection">
|
||||
|
||||
``` csharp
|
||||
{{#include docs/examples/csharp/stmtInsert/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket Connection">
|
||||
|
||||
```csharp
|
||||
{{#include docs/examples/csharp/wsStmt/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### Query data
|
||||
|
||||
#### Synchronous Query
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="Native Connection">
|
||||
|
||||
<CSQuery />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket Connection">
|
||||
|
||||
```csharp
|
||||
{{#include docs/examples/csharp/wsQuery/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
#### Asynchronous query
|
||||
|
||||
<CSAsyncQuery />
|
||||
|
@ -145,18 +251,21 @@ namespace TDengineExample
|
|||
### More sample programs
|
||||
|
||||
|Sample program |Sample program description |
|
||||
|--------------------------------------------------------------------------------------------------------------------|------------ --------------------------------|
|
||||
|--------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
|
||||
| [CURD](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/Query/Query.cs) | Table creation, data insertion, and query examples with TDengine.Connector |
|
||||
| [JSON Tag](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/JSONTag) | Writing and querying JSON tag data with TDengine Connector |
|
||||
| [stmt](https://github.com/taosdata/taos-connector-dotnet/tree/3.0/examples/Stmt) | Parameter binding with TDengine Connector |
|
||||
| [schemaless](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/schemaless) | Schemaless writes with TDengine Connector |
|
||||
| [async query](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/AsyncQuery/QueryAsync.cs) | Asynchronous queries with TDengine Connector |
|
||||
| [TMQ](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/TMQ/TMQ.cs) | Data subscription with TDengine Connector |
|
||||
| [Subscription](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/TMQ/TMQ.cs) | Subscription example with TDengine Connector |
|
||||
| [Basic WebSocket Usage](https://github.com/taosdata/taos-connector-dotnet/blob/5a4a7cd0dbcda114447cdc6d0c6dedd8e84a52da/examples/WS/WebSocketSample.cs) | WebSocket basic data in and out with TDengine connector |
|
||||
| [WebSocket Parameter Binding](https://github.com/taosdata/taos-connector-dotnet/blob/5a4a7cd0dbcda114447cdc6d0c6dedd8e84a52da/examples/WS/WebSocketSTMT.cs) | WebSocket parameter binding example |
|
||||
|
||||
## Important update records
|
||||
|
||||
| TDengine.Connector | Description |
|
||||
|--------------------|--------------------------------|
|
||||
| 3.0.1 | Support WebSocket and Cloud,With function query, insert, and parameter binding|
|
||||
| 3.0.0 | Supports TDengine 3.0.0.0. TDengine 2.x is not supported. Added `TDengine.Impl.GetData()` interface to deserialize query results. |
|
||||
| 1.0.7 | Fixed TDengine.Query() memory leak. |
|
||||
| 1.0.6 | Fix schemaless bug in 1.0.4 and 1.0.5. |
|
||||
|
|
|
@ -164,7 +164,7 @@ The parameters described in this document by the effect that they have on the sy
|
|||
| Attribute | Description |
|
||||
| -------- | -------------------- |
|
||||
| Applicable | Client only |
|
||||
| 含义 | SMA index optimization policy |
|
||||
| Meaning | SMA index optimization policy |
|
||||
| Unit | None |
|
||||
| Default Value | 0 |
|
||||
| Notes |
|
||||
|
@ -177,12 +177,21 @@ The parameters described in this document by the effect that they have on the sy
|
|||
### maxNumOfDistinctRes
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- | --- |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | The maximum number of distinct rows returned |
|
||||
| Value Range | [100,000 - 100,000,000] |
|
||||
| Default Value | 100,000 |
|
||||
|
||||
### keepColumnName
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Client only |
|
||||
| Meaning | When the Last, First, LastRow function is queried, whether the returned column name contains the function name. |
|
||||
| Value Range | 0 means including the function name, 1 means not including the function name. |
|
||||
| Default Value | 0 |
|
||||
|
||||
## Locale Parameters
|
||||
|
||||
### timezone
|
||||
|
@ -325,7 +334,7 @@ The charset that takes effect is UTF-8.
|
|||
| Applicable | Server Only |
|
||||
| Meaning | Maximum number of vnodes per dnode |
|
||||
| Value Range | 0-4096 |
|
||||
| Default Value | 256 |
|
||||
| Default Value | 2x the CPU cores |
|
||||
|
||||
## Time Parameters
|
||||
|
||||
|
@ -697,152 +706,154 @@ To prevent system resource from being exhausted by multiple concurrent streams,
|
|||
| 15 | telemetryPort | No | Yes |
|
||||
| 16 | queryPolicy | No | Yes |
|
||||
| 17 | querySmaOptimize | No | Yes |
|
||||
| 18 | queryBufferSize | Yes | Yes |
|
||||
| 19 | maxNumOfDistinctRes | Yes | Yes |
|
||||
| 20 | minSlidingTime | Yes | Yes |
|
||||
| 21 | minIntervalTime | Yes | Yes |
|
||||
| 22 | countAlwaysReturnValue | Yes | Yes |
|
||||
| 23 | dataDir | Yes | Yes |
|
||||
| 24 | minimalDataDirGB | Yes | Yes |
|
||||
| 25 | supportVnodes | No | Yes |
|
||||
| 26 | tempDir | Yes | Yes |
|
||||
| 27 | minimalTmpDirGB | Yes | Yes |
|
||||
| 28 | compressMsgSize | Yes | Yes |
|
||||
| 29 | compressColData | Yes | Yes |
|
||||
| 30 | smlChildTableName | Yes | Yes |
|
||||
| 31 | smlTagName | Yes | Yes |
|
||||
| 32 | smlDataFormat | No | Yes |
|
||||
| 33 | statusInterval | Yes | Yes |
|
||||
| 34 | shellActivityTimer | Yes | Yes |
|
||||
| 35 | transPullupInterval | No | Yes |
|
||||
| 36 | mqRebalanceInterval | No | Yes |
|
||||
| 37 | ttlUnit | No | Yes |
|
||||
| 38 | ttlPushInterval | No | Yes |
|
||||
| 39 | numOfTaskQueueThreads | No | Yes |
|
||||
| 40 | numOfRpcThreads | No | Yes |
|
||||
| 41 | numOfCommitThreads | Yes | Yes |
|
||||
| 42 | numOfMnodeReadThreads | No | Yes |
|
||||
| 43 | numOfVnodeQueryThreads | No | Yes |
|
||||
| 44 | numOfVnodeStreamThreads | No | Yes |
|
||||
| 45 | numOfVnodeFetchThreads | No | Yes |
|
||||
| 46 | numOfVnodeWriteThreads | No | Yes |
|
||||
| 47 | numOfVnodeSyncThreads | No | Yes |
|
||||
| 48 | numOfQnodeQueryThreads | No | Yes |
|
||||
| 49 | numOfQnodeFetchThreads | No | Yes |
|
||||
| 50 | numOfSnodeSharedThreads | No | Yes |
|
||||
| 51 | numOfSnodeUniqueThreads | No | Yes |
|
||||
| 52 | rpcQueueMemoryAllowed | No | Yes |
|
||||
| 53 | logDir | Yes | Yes |
|
||||
| 54 | minimalLogDirGB | Yes | Yes |
|
||||
| 55 | numOfLogLines | Yes | Yes |
|
||||
| 56 | asyncLog | Yes | Yes |
|
||||
| 57 | logKeepDays | Yes | Yes |
|
||||
| 58 | debugFlag | Yes | Yes |
|
||||
| 59 | tmrDebugFlag | Yes | Yes |
|
||||
| 60 | uDebugFlag | Yes | Yes |
|
||||
| 61 | rpcDebugFlag | Yes | Yes |
|
||||
| 62 | jniDebugFlag | Yes | Yes |
|
||||
| 63 | qDebugFlag | Yes | Yes |
|
||||
| 64 | cDebugFlag | Yes | Yes |
|
||||
| 65 | dDebugFlag | Yes | Yes |
|
||||
| 66 | vDebugFlag | Yes | Yes |
|
||||
| 67 | mDebugFlag | Yes | Yes |
|
||||
| 68 | wDebugFlag | Yes | Yes |
|
||||
| 69 | sDebugFlag | Yes | Yes |
|
||||
| 70 | tsdbDebugFlag | Yes | Yes |
|
||||
| 71 | tqDebugFlag | No | Yes |
|
||||
| 72 | fsDebugFlag | Yes | Yes |
|
||||
| 73 | udfDebugFlag | No | Yes |
|
||||
| 74 | smaDebugFlag | No | Yes |
|
||||
| 75 | idxDebugFlag | No | Yes |
|
||||
| 76 | tdbDebugFlag | No | Yes |
|
||||
| 77 | metaDebugFlag | No | Yes |
|
||||
| 78 | timezone | Yes | Yes |
|
||||
| 79 | locale | Yes | Yes |
|
||||
| 80 | charset | Yes | Yes |
|
||||
| 81 | udf | Yes | Yes |
|
||||
| 82 | enableCoreFile | Yes | Yes |
|
||||
| 83 | arbitrator | Yes | No |
|
||||
| 84 | numOfThreadsPerCore | Yes | No |
|
||||
| 85 | numOfMnodes | Yes | No |
|
||||
| 86 | vnodeBak | Yes | No |
|
||||
| 87 | balance | Yes | No |
|
||||
| 88 | balanceInterval | Yes | No |
|
||||
| 89 | offlineThreshold | Yes | No |
|
||||
| 90 | role | Yes | No |
|
||||
| 91 | dnodeNopLoop | Yes | No |
|
||||
| 92 | keepTimeOffset | Yes | No |
|
||||
| 93 | rpcTimer | Yes | No |
|
||||
| 94 | rpcMaxTime | Yes | No |
|
||||
| 95 | rpcForceTcp | Yes | No |
|
||||
| 96 | tcpConnTimeout | Yes | No |
|
||||
| 97 | syncCheckInterval | Yes | No |
|
||||
| 98 | maxTmrCtrl | Yes | No |
|
||||
| 99 | monitorReplica | Yes | No |
|
||||
| 100 | smlTagNullName | Yes | No |
|
||||
| 101 | keepColumnName | Yes | No |
|
||||
| 102 | ratioOfQueryCores | Yes | No |
|
||||
| 103 | maxStreamCompDelay | Yes | No |
|
||||
| 104 | maxFirstStreamCompDelay | Yes | No |
|
||||
| 105 | retryStreamCompDelay | Yes | No |
|
||||
| 106 | streamCompDelayRatio | Yes | No |
|
||||
| 107 | maxVgroupsPerDb | Yes | No |
|
||||
| 108 | maxTablesPerVnode | Yes | No |
|
||||
| 109 | minTablesPerVnode | Yes | No |
|
||||
| 110 | tableIncStepPerVnode | Yes | No |
|
||||
| 111 | cache | Yes | No |
|
||||
| 112 | blocks | Yes | No |
|
||||
| 113 | days | Yes | No |
|
||||
| 114 | keep | Yes | No |
|
||||
| 115 | minRows | Yes | No |
|
||||
| 116 | maxRows | Yes | No |
|
||||
| 117 | quorum | Yes | No |
|
||||
| 118 | comp | Yes | No |
|
||||
| 119 | walLevel | Yes | No |
|
||||
| 120 | fsync | Yes | No |
|
||||
| 121 | replica | Yes | No |
|
||||
| 122 | partitions | Yes | No |
|
||||
| 123 | quorum | Yes | No |
|
||||
| 124 | update | Yes | No |
|
||||
| 125 | cachelast | Yes | No |
|
||||
| 126 | maxSQLLength | Yes | No |
|
||||
| 127 | maxWildCardsLength | Yes | No |
|
||||
| 128 | maxRegexStringLen | Yes | No |
|
||||
| 129 | maxNumOfOrderedRes | Yes | No |
|
||||
| 130 | maxConnections | Yes | No |
|
||||
| 131 | mnodeEqualVnodeNum | Yes | No |
|
||||
| 132 | http | Yes | No |
|
||||
| 133 | httpEnableRecordSql | Yes | No |
|
||||
| 134 | httpMaxThreads | Yes | No |
|
||||
| 135 | restfulRowLimit | Yes | No |
|
||||
| 136 | httpDbNameMandatory | Yes | No |
|
||||
| 137 | httpKeepAlive | Yes | No |
|
||||
| 138 | enableRecordSql | Yes | No |
|
||||
| 139 | maxBinaryDisplayWidth | Yes | No |
|
||||
| 140 | stream | Yes | No |
|
||||
| 141 | retrieveBlockingModel | Yes | No |
|
||||
| 142 | tsdbMetaCompactRatio | Yes | No |
|
||||
| 143 | defaultJSONStrType | Yes | No |
|
||||
| 144 | walFlushSize | Yes | No |
|
||||
| 145 | keepTimeOffset | Yes | No |
|
||||
| 146 | flowctrl | Yes | No |
|
||||
| 147 | slaveQuery | Yes | No |
|
||||
| 148 | adjustMaster | Yes | No |
|
||||
| 149 | topicBinaryLen | Yes | No |
|
||||
| 150 | telegrafUseFieldNum | Yes | No |
|
||||
| 151 | deadLockKillQuery | Yes | No |
|
||||
| 152 | clientMerge | Yes | No |
|
||||
| 153 | sdbDebugFlag | Yes | No |
|
||||
| 154 | odbcDebugFlag | Yes | No |
|
||||
| 155 | httpDebugFlag | Yes | No |
|
||||
| 156 | monDebugFlag | Yes | No |
|
||||
| 157 | cqDebugFlag | Yes | No |
|
||||
| 158 | shortcutFlag | Yes | No |
|
||||
| 159 | probeSeconds | Yes | No |
|
||||
| 160 | probeKillSeconds | Yes | No |
|
||||
| 161 | probeInterval | Yes | No |
|
||||
| 162 | lossyColumns | Yes | No |
|
||||
| 163 | fPrecision | Yes | No |
|
||||
| 164 | dPrecision | Yes | No |
|
||||
| 165 | maxRange | Yes | No |
|
||||
| 166 | range | Yes | No |
|
||||
| 18 | queryRsmaTolerance | No | Yes |
|
||||
| 19 | queryBufferSize | Yes | Yes |
|
||||
| 20 | maxNumOfDistinctRes | Yes | Yes |
|
||||
| 21 | minSlidingTime | Yes | Yes |
|
||||
| 22 | minIntervalTime | Yes | Yes |
|
||||
| 23 | countAlwaysReturnValue | Yes | Yes |
|
||||
| 24 | dataDir | Yes | Yes |
|
||||
| 25 | minimalDataDirGB | Yes | Yes |
|
||||
| 26 | supportVnodes | No | Yes |
|
||||
| 27 | tempDir | Yes | Yes |
|
||||
| 28 | minimalTmpDirGB | Yes | Yes |
|
||||
| 29 | compressMsgSize | Yes | Yes |
|
||||
| 30 | compressColData | Yes | Yes |
|
||||
| 31 | smlChildTableName | Yes | Yes |
|
||||
| 32 | smlTagName | Yes | Yes |
|
||||
| 33 | smlDataFormat | No | Yes |
|
||||
| 34 | statusInterval | Yes | Yes |
|
||||
| 35 | shellActivityTimer | Yes | Yes |
|
||||
| 36 | transPullupInterval | No | Yes |
|
||||
| 37 | mqRebalanceInterval | No | Yes |
|
||||
| 38 | ttlUnit | No | Yes |
|
||||
| 39 | ttlPushInterval | No | Yes |
|
||||
| 40 | numOfTaskQueueThreads | No | Yes |
|
||||
| 41 | numOfRpcThreads | No | Yes |
|
||||
| 42 | numOfCommitThreads | Yes | Yes |
|
||||
| 43 | numOfMnodeReadThreads | No | Yes |
|
||||
| 44 | numOfVnodeQueryThreads | No | Yes |
|
||||
| 45 | numOfVnodeStreamThreads | No | Yes |
|
||||
| 46 | numOfVnodeFetchThreads | No | Yes |
|
||||
| 47 | numOfVnodeWriteThreads | No | Yes |
|
||||
| 48 | numOfVnodeSyncThreads | No | Yes |
|
||||
| 49 | numOfVnodeRsmaThreads | No | Yes |
|
||||
| 50 | numOfQnodeQueryThreads | No | Yes |
|
||||
| 51 | numOfQnodeFetchThreads | No | Yes |
|
||||
| 52 | numOfSnodeSharedThreads | No | Yes |
|
||||
| 53 | numOfSnodeUniqueThreads | No | Yes |
|
||||
| 54 | rpcQueueMemoryAllowed | No | Yes |
|
||||
| 55 | logDir | Yes | Yes |
|
||||
| 56 | minimalLogDirGB | Yes | Yes |
|
||||
| 57 | numOfLogLines | Yes | Yes |
|
||||
| 58 | asyncLog | Yes | Yes |
|
||||
| 59 | logKeepDays | Yes | Yes |
|
||||
| 60 | debugFlag | Yes | Yes |
|
||||
| 61 | tmrDebugFlag | Yes | Yes |
|
||||
| 62 | uDebugFlag | Yes | Yes |
|
||||
| 63 | rpcDebugFlag | Yes | Yes |
|
||||
| 64 | jniDebugFlag | Yes | Yes |
|
||||
| 65 | qDebugFlag | Yes | Yes |
|
||||
| 66 | cDebugFlag | Yes | Yes |
|
||||
| 67 | dDebugFlag | Yes | Yes |
|
||||
| 68 | vDebugFlag | Yes | Yes |
|
||||
| 69 | mDebugFlag | Yes | Yes |
|
||||
| 70 | wDebugFlag | Yes | Yes |
|
||||
| 71 | sDebugFlag | Yes | Yes |
|
||||
| 72 | tsdbDebugFlag | Yes | Yes |
|
||||
| 73 | tqDebugFlag | No | Yes |
|
||||
| 74 | fsDebugFlag | Yes | Yes |
|
||||
| 75 | udfDebugFlag | No | Yes |
|
||||
| 76 | smaDebugFlag | No | Yes |
|
||||
| 77 | idxDebugFlag | No | Yes |
|
||||
| 78 | tdbDebugFlag | No | Yes |
|
||||
| 79 | metaDebugFlag | No | Yes |
|
||||
| 80 | timezone | Yes | Yes |
|
||||
| 81 | locale | Yes | Yes |
|
||||
| 82 | charset | Yes | Yes |
|
||||
| 83 | udf | Yes | Yes |
|
||||
| 84 | enableCoreFile | Yes | Yes |
|
||||
| 85 | arbitrator | Yes | No |
|
||||
| 86 | numOfThreadsPerCore | Yes | No |
|
||||
| 87 | numOfMnodes | Yes | No |
|
||||
| 88 | vnodeBak | Yes | No |
|
||||
| 89 | balance | Yes | No |
|
||||
| 90 | balanceInterval | Yes | No |
|
||||
| 91 | offlineThreshold | Yes | No |
|
||||
| 92 | role | Yes | No |
|
||||
| 93 | dnodeNopLoop | Yes | No |
|
||||
| 94 | keepTimeOffset | Yes | No |
|
||||
| 95 | rpcTimer | Yes | No |
|
||||
| 96 | rpcMaxTime | Yes | No |
|
||||
| 97 | rpcForceTcp | Yes | No |
|
||||
| 98 | tcpConnTimeout | Yes | No |
|
||||
| 99 | syncCheckInterval | Yes | No |
|
||||
| 100 | maxTmrCtrl | Yes | No |
|
||||
| 101 | monitorReplica | Yes | No |
|
||||
| 102 | smlTagNullName | Yes | No |
|
||||
| 103 | keepColumnName | Yes | No |
|
||||
| 104 | ratioOfQueryCores | Yes | No |
|
||||
| 105 | maxStreamCompDelay | Yes | No |
|
||||
| 106 | maxFirstStreamCompDelay | Yes | No |
|
||||
| 107 | retryStreamCompDelay | Yes | No |
|
||||
| 108 | streamCompDelayRatio | Yes | No |
|
||||
| 109 | maxVgroupsPerDb | Yes | No |
|
||||
| 110 | maxTablesPerVnode | Yes | No |
|
||||
| 111 | minTablesPerVnode | Yes | No |
|
||||
| 112 | tableIncStepPerVnode | Yes | No |
|
||||
| 113 | cache | Yes | No |
|
||||
| 114 | blocks | Yes | No |
|
||||
| 115 | days | Yes | No |
|
||||
| 116 | keep | Yes | No |
|
||||
| 117 | minRows | Yes | No |
|
||||
| 118 | maxRows | Yes | No |
|
||||
| 119 | quorum | Yes | No |
|
||||
| 120 | comp | Yes | No |
|
||||
| 121 | walLevel | Yes | No |
|
||||
| 122 | fsync | Yes | No |
|
||||
| 123 | replica | Yes | No |
|
||||
| 124 | partitions | Yes | No |
|
||||
| 125 | quorum | Yes | No |
|
||||
| 126 | update | Yes | No |
|
||||
| 127 | cachelast | Yes | No |
|
||||
| 128 | maxSQLLength | Yes | No |
|
||||
| 129 | maxWildCardsLength | Yes | No |
|
||||
| 130 | maxRegexStringLen | Yes | No |
|
||||
| 131 | maxNumOfOrderedRes | Yes | No |
|
||||
| 132 | maxConnections | Yes | No |
|
||||
| 133 | mnodeEqualVnodeNum | Yes | No |
|
||||
| 134 | http | Yes | No |
|
||||
| 135 | httpEnableRecordSql | Yes | No |
|
||||
| 136 | httpMaxThreads | Yes | No |
|
||||
| 137 | restfulRowLimit | Yes | No |
|
||||
| 138 | httpDbNameMandatory | Yes | No |
|
||||
| 139 | httpKeepAlive | Yes | No |
|
||||
| 140 | enableRecordSql | Yes | No |
|
||||
| 141 | maxBinaryDisplayWidth | Yes | No |
|
||||
| 142 | stream | Yes | No |
|
||||
| 143 | retrieveBlockingModel | Yes | No |
|
||||
| 144 | tsdbMetaCompactRatio | Yes | No |
|
||||
| 145 | defaultJSONStrType | Yes | No |
|
||||
| 146 | walFlushSize | Yes | No |
|
||||
| 147 | keepTimeOffset | Yes | No |
|
||||
| 148 | flowctrl | Yes | No |
|
||||
| 149 | slaveQuery | Yes | No |
|
||||
| 150 | adjustMaster | Yes | No |
|
||||
| 151 | topicBinaryLen | Yes | No |
|
||||
| 152 | telegrafUseFieldNum | Yes | No |
|
||||
| 153 | deadLockKillQuery | Yes | No |
|
||||
| 154 | clientMerge | Yes | No |
|
||||
| 155 | sdbDebugFlag | Yes | No |
|
||||
| 156 | odbcDebugFlag | Yes | No |
|
||||
| 157 | httpDebugFlag | Yes | No |
|
||||
| 158 | monDebugFlag | Yes | No |
|
||||
| 159 | cqDebugFlag | Yes | No |
|
||||
| 160 | shortcutFlag | Yes | No |
|
||||
| 161 | probeSeconds | Yes | No |
|
||||
| 162 | probeKillSeconds | Yes | No |
|
||||
| 163 | probeInterval | Yes | No |
|
||||
| 164 | lossyColumns | Yes | No |
|
||||
| 165 | fPrecision | Yes | No |
|
||||
| 166 | dPrecision | Yes | No |
|
||||
| 167 | maxRange | Yes | No |
|
||||
| 168 | range | Yes | No |
|
||||
|
|
|
@ -47,9 +47,8 @@ In the schemaless writing data line protocol, each data item in the field_set ne
|
|||
|
||||
- `t`, `T`, `true`, `True`, `TRUE`, `f`, `F`, `false`, and `False` will be handled directly as BOOL types.
|
||||
|
||||
For example, the following data rows indicate that the t1 label is "3" (NCHAR), the t2 label is "4" (NCHAR), and the t3 label
|
||||
is "t3" to the super table named `st` labeled "t3" (NCHAR), write c1 column as 3 (BIGINT), c2 column as false (BOOL), c3 column
|
||||
is "passit" (BINARY), c4 column is 4 (DOUBLE), and the primary key timestamp is 1626006833639000000 in one row.
|
||||
For example, the following data rows write c1 column as 3 (BIGINT), c2 column as false (BOOL), c3 column
|
||||
as "passit" (BINARY), c4 column as 4 (DOUBLE), and the primary key timestamp as 1626006833639000000 to child table with the t1 label as "3" (NCHAR), the t2 label as "4" (NCHAR), and the t3 label as "t3" (NCHAR) and the super table named `st`.
|
||||
|
||||
```json
|
||||
st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
|
||||
|
@ -69,7 +68,7 @@ Schemaless writes process row data according to the following principles.
|
|||
|
||||
Note that tag_key1, tag_key2 are not the original order of the tags entered by the user but the result of using the tag names in ascending order of the strings. Therefore, tag_key1 is not the first tag entered in the line protocol.
|
||||
The string's MD5 hash value "md5_val" is calculated after the ranking is completed. The calculation result is then combined with the string to generate the table name: "t_md5_val". "t_" is a fixed prefix that every table generated by this mapping relationship has.
|
||||
You can configure smlChildTableName to specify table names, for example, `smlChildTableName=tname`. You can insert `st,tname=cpul,t1=4 c1=3 1626006833639000000` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored.
|
||||
You can configure smlChildTableName in taos.cfg to specify table names, for example, `smlChildTableName=tname`. You can insert `st,tname=cpul,t1=4 c1=3 1626006833639000000` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored.
|
||||
|
||||
2. If the super table obtained by parsing the line protocol does not exist, this super table is created.
|
||||
3. If the subtable obtained by the parse line protocol does not exist, Schemaless creates the sub-table according to the subtable name determined in steps 1 or 2.
|
||||
|
@ -78,7 +77,7 @@ You can configure smlChildTableName to specify table names, for example, `smlChi
|
|||
NULL.
|
||||
6. For BINARY or NCHAR columns, if the length of the value provided in a data row exceeds the column type limit, the maximum length of characters allowed to be stored in the column is automatically increased (only incremented and not decremented) to ensure complete preservation of the data.
|
||||
7. Errors encountered throughout the processing will interrupt the writing process and return an error code.
|
||||
8. It is assumed that the order of field_set in a supertable is consistent, meaning that the first record contains all fields and subsequent records store fields in the same order. If the order is not consistent, set smlDataFormat to false. Otherwise, data will be written out of order and a database error will occur.
|
||||
8. It is assumed that the order of field_set in a supertable is consistent, meaning that the first record contains all fields and subsequent records store fields in the same order. If the order is not consistent, set smlDataFormat in taos.cfg to false. Otherwise, data will be written out of order and a database error will occur.(smlDataFormat in taos.cfg default to false after version of 3.0.1.3)
|
||||
|
||||
:::tip
|
||||
All processing logic of schemaless will still follow TDengine's underlying restrictions on data structures, such as the total length of each row of data cannot exceed
|
||||
|
|
|
@ -6,6 +6,13 @@ description: TDengine release history, Release Notes and download links.
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.0.1.3
|
||||
|
||||
<Release type="tdengine" version="3.0.1.3" />
|
||||
|
||||
## 3.0.1.2
|
||||
|
||||
<Release type="tdengine" version="3.0.1.2" />
|
||||
|
||||
## 3.0.1.1
|
||||
|
||||
|
|
|
@ -6,6 +6,14 @@ description: taosTools release history, Release Notes, download links.
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 2.2.3
|
||||
|
||||
<Release type="tools" version="2.2.3" />
|
||||
|
||||
## 2.2.2
|
||||
|
||||
<Release type="tools" version="2.2.2" />
|
||||
|
||||
## 2.2.0
|
||||
|
||||
<Release type="tools" version="2.2.0" />
|
||||
|
|
|
@ -1,4 +1,27 @@
|
|||
bin
|
||||
obj
|
||||
.vs
|
||||
*.sln
|
||||
asyncQuery/bin
|
||||
connect/bin
|
||||
influxdbLine/bin
|
||||
optsJSON/bin
|
||||
optsTelnet/bin
|
||||
query/bin
|
||||
sqlInsert/bin
|
||||
stmtInsert/bin
|
||||
subscribe/bin
|
||||
wsConnect/bin
|
||||
wsInsert/bin
|
||||
wsQuery/bin
|
||||
wsStmt/bin
|
||||
asyncQuery/obj
|
||||
connect/obj
|
||||
influxdbLine/obj
|
||||
optsJSON/obj
|
||||
optsTelnet/obj
|
||||
query/obj
|
||||
sqlInsert/obj
|
||||
stmtInsert/obj
|
||||
subscribe/obj
|
||||
wsConnect/obj
|
||||
wsInsert/obj
|
||||
wsQuery/obj
|
||||
wsStmt/obj
|
|
@ -1,82 +0,0 @@
|
|||
using TDengineDriver;
|
||||
using TDengineDriver.Impl;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TDengineExample
|
||||
{
|
||||
internal class QueryExample
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
IntPtr conn = GetConnection();
|
||||
// run query
|
||||
IntPtr res = TDengine.Query(conn, "SELECT * FROM meters LIMIT 2");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("Failed to query since: " + TDengine.Error(res));
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// get filed count
|
||||
int fieldCount = TDengine.FieldCount(res);
|
||||
Console.WriteLine("fieldCount=" + fieldCount);
|
||||
|
||||
// print column names
|
||||
List<TDengineMeta> metas = LibTaos.GetMeta(res);
|
||||
for (int i = 0; i < metas.Count; i++)
|
||||
{
|
||||
Console.Write(metas[i].name + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
// print values
|
||||
List<Object> resData = LibTaos.GetData(res);
|
||||
for (int i = 0; i < resData.Count; i++)
|
||||
{
|
||||
Console.Write($"|{resData[i].ToString()} \t");
|
||||
if (((i + 1) % metas.Count == 0))
|
||||
{
|
||||
Console.WriteLine("");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine($"Query is not complete, Error {TDengine.ErrorNo(res)} {TDengine.Error(res)}");
|
||||
}
|
||||
// exit
|
||||
TDengine.FreeResult(res);
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
}
|
||||
static IntPtr GetConnection()
|
||||
{
|
||||
string host = "localhost";
|
||||
short port = 6030;
|
||||
string username = "root";
|
||||
string password = "taosdata";
|
||||
string dbname = "power";
|
||||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
System.Environment.Exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine success");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// output:
|
||||
// Connect to TDengine success
|
||||
// fieldCount=6
|
||||
// ts current voltage phase location groupid
|
||||
// 1648432611249 10.3 219 0.31 California.SanFrancisco 2
|
||||
// 1648432611749 12.6 218 0.33 California.SanFrancisco 2
|
|
@ -1,70 +0,0 @@
|
|||
using TDengineDriver;
|
||||
|
||||
|
||||
namespace TDengineExample
|
||||
{
|
||||
internal class SQLInsertExample
|
||||
{
|
||||
|
||||
static void Main()
|
||||
{
|
||||
IntPtr conn = GetConnection();
|
||||
IntPtr res = TDengine.Query(conn, "CREATE DATABASE power");
|
||||
CheckRes(conn, res, "failed to create database");
|
||||
res = TDengine.Query(conn, "USE power");
|
||||
CheckRes(conn, res, "failed to change database");
|
||||
res = TDengine.Query(conn, "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
|
||||
CheckRes(conn, res, "failed to create stable");
|
||||
var sql = "INSERT INTO d1001 USING meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000) " +
|
||||
"d1002 USING power.meters TAGS('California.SanFrancisco', 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000) " +
|
||||
"d1003 USING power.meters TAGS('California.LosAngeles', 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " +
|
||||
"d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
|
||||
res = TDengine.Query(conn, sql);
|
||||
CheckRes(conn, res, "failed to insert data");
|
||||
int affectedRows = TDengine.AffectRows(res);
|
||||
Console.WriteLine("affectedRows " + affectedRows);
|
||||
TDengine.FreeResult(res);
|
||||
ExitProgram(conn, 0);
|
||||
}
|
||||
|
||||
static IntPtr GetConnection()
|
||||
{
|
||||
string host = "localhost";
|
||||
short port = 6030;
|
||||
string username = "root";
|
||||
string password = "taosdata";
|
||||
string dbname = "";
|
||||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine success");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
static void CheckRes(IntPtr conn, IntPtr res, String errorMsg)
|
||||
{
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.Write(errorMsg + " since: " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void ExitProgram(IntPtr conn, int exitCode)
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// output:
|
||||
// Connect to TDengine success
|
||||
// affectedRows 8
|
|
@ -11,11 +11,17 @@ namespace TDengineExample
|
|||
static void Main()
|
||||
{
|
||||
IntPtr conn = GetConnection();
|
||||
QueryAsyncCallback queryAsyncCallback = new QueryAsyncCallback(QueryCallback);
|
||||
TDengine.QueryAsync(conn, "select * from meters", queryAsyncCallback, IntPtr.Zero);
|
||||
Thread.Sleep(2000);
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
try
|
||||
{
|
||||
QueryAsyncCallback queryAsyncCallback = new QueryAsyncCallback(QueryCallback);
|
||||
TDengine.QueryAsync(conn, "select * from meters", queryAsyncCallback, IntPtr.Zero);
|
||||
Thread.Sleep(2000);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void QueryCallback(IntPtr param, IntPtr taosRes, int code)
|
||||
|
@ -27,11 +33,11 @@ namespace TDengineExample
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"async query data failed, failed code {code}");
|
||||
throw new Exception($"async query data failed,code:{code},reason:{TDengine.Error(taosRes)}");
|
||||
}
|
||||
}
|
||||
|
||||
// Iteratively call this interface until "numOfRows" is no greater than 0.
|
||||
// Iteratively call this interface until "numOfRows" is no greater than 0.
|
||||
static void FetchRawBlockCallback(IntPtr param, IntPtr taosRes, int numOfRows)
|
||||
{
|
||||
if (numOfRows > 0)
|
||||
|
@ -43,7 +49,7 @@ namespace TDengineExample
|
|||
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
if (i != 0 && (i+1) % metaList.Count == 0)
|
||||
if (i != 0 && (i + 1) % metaList.Count == 0)
|
||||
{
|
||||
Console.WriteLine("{0}\t|", dataList[i]);
|
||||
}
|
||||
|
@ -63,7 +69,7 @@ namespace TDengineExample
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"FetchRawBlockCallback callback error, error code {numOfRows}");
|
||||
throw new Exception($"FetchRawBlockCallback callback error, error code {numOfRows}");
|
||||
}
|
||||
TDengine.FreeResult(taosRes);
|
||||
}
|
||||
|
@ -79,8 +85,7 @@ namespace TDengineExample
|
|||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
Environment.Exit(0);
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
|
@ -9,7 +9,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.0" />
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -16,7 +16,7 @@ namespace TDengineExample
|
|||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
|
@ -0,0 +1,94 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30114.105
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "asyncquery", "asyncQuery\asyncquery.csproj", "{E2A5F00C-14E7-40E1-A2DE-6AB2975616D3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "connect", "connect\connect.csproj", "{CCC5042D-93FC-4AE0-B2F6-7E692FD476B7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "influxdbline", "influxdbLine\influxdbline.csproj", "{6A24FB80-1E3C-4E2D-A5AB-914FA583874D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "optsJSON", "optsJSON\optsJSON.csproj", "{6725A961-0C66-4196-AC98-8D3F3D757D6C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "optstelnet", "optsTelnet\optstelnet.csproj", "{B3B50D25-688B-44D4-8683-482ABC52FFCA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "query", "query\query.csproj", "{F2B7D13B-FE04-4C5C-BB6D-C12E0A9D9970}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stmtinsert", "stmtInsert\stmtinsert.csproj", "{B40D6BED-BE3C-4B44-9B12-28BE441311BA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "subscribe", "subscribe\subscribe.csproj", "{C3D45A8E-AFC0-4547-9F3C-467B0B583DED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wsConnect", "wsConnect\wsConnect.csproj", "{51E19494-845E-49ED-97C7-749AE63111BD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wsInsert", "wsInsert\wsInsert.csproj", "{13E2233B-4AFF-40D9-AF42-AB3F01617540}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wsQuery", "wsQuery\wsQuery.csproj", "{0F394169-C456-442C-929D-C2D43A0EEC7B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wsStmt", "wsStmt\wsStmt.csproj", "{27B9C9AB-9055-4BF2-8A14-4E59F09D5985}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sqlinsert", "sqlInsert\sqlinsert.csproj", "{CD24BD12-8550-4627-A11D-707B446F48C3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E2A5F00C-14E7-40E1-A2DE-6AB2975616D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E2A5F00C-14E7-40E1-A2DE-6AB2975616D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E2A5F00C-14E7-40E1-A2DE-6AB2975616D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E2A5F00C-14E7-40E1-A2DE-6AB2975616D3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CCC5042D-93FC-4AE0-B2F6-7E692FD476B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CCC5042D-93FC-4AE0-B2F6-7E692FD476B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CCC5042D-93FC-4AE0-B2F6-7E692FD476B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CCC5042D-93FC-4AE0-B2F6-7E692FD476B7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6A24FB80-1E3C-4E2D-A5AB-914FA583874D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6A24FB80-1E3C-4E2D-A5AB-914FA583874D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6A24FB80-1E3C-4E2D-A5AB-914FA583874D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6A24FB80-1E3C-4E2D-A5AB-914FA583874D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6725A961-0C66-4196-AC98-8D3F3D757D6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6725A961-0C66-4196-AC98-8D3F3D757D6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6725A961-0C66-4196-AC98-8D3F3D757D6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6725A961-0C66-4196-AC98-8D3F3D757D6C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B3B50D25-688B-44D4-8683-482ABC52FFCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B3B50D25-688B-44D4-8683-482ABC52FFCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B3B50D25-688B-44D4-8683-482ABC52FFCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B3B50D25-688B-44D4-8683-482ABC52FFCA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F2B7D13B-FE04-4C5C-BB6D-C12E0A9D9970}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F2B7D13B-FE04-4C5C-BB6D-C12E0A9D9970}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F2B7D13B-FE04-4C5C-BB6D-C12E0A9D9970}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F2B7D13B-FE04-4C5C-BB6D-C12E0A9D9970}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B40D6BED-BE3C-4B44-9B12-28BE441311BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B40D6BED-BE3C-4B44-9B12-28BE441311BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B40D6BED-BE3C-4B44-9B12-28BE441311BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B40D6BED-BE3C-4B44-9B12-28BE441311BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C3D45A8E-AFC0-4547-9F3C-467B0B583DED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3D45A8E-AFC0-4547-9F3C-467B0B583DED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3D45A8E-AFC0-4547-9F3C-467B0B583DED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3D45A8E-AFC0-4547-9F3C-467B0B583DED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{51E19494-845E-49ED-97C7-749AE63111BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{51E19494-845E-49ED-97C7-749AE63111BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{51E19494-845E-49ED-97C7-749AE63111BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{51E19494-845E-49ED-97C7-749AE63111BD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{13E2233B-4AFF-40D9-AF42-AB3F01617540}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{13E2233B-4AFF-40D9-AF42-AB3F01617540}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{13E2233B-4AFF-40D9-AF42-AB3F01617540}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{13E2233B-4AFF-40D9-AF42-AB3F01617540}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0F394169-C456-442C-929D-C2D43A0EEC7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0F394169-C456-442C-929D-C2D43A0EEC7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0F394169-C456-442C-929D-C2D43A0EEC7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0F394169-C456-442C-929D-C2D43A0EEC7B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{27B9C9AB-9055-4BF2-8A14-4E59F09D5985}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{27B9C9AB-9055-4BF2-8A14-4E59F09D5985}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{27B9C9AB-9055-4BF2-8A14-4E59F09D5985}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{27B9C9AB-9055-4BF2-8A14-4E59F09D5985}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CD24BD12-8550-4627-A11D-707B446F48C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CD24BD12-8550-4627-A11D-707B446F48C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CD24BD12-8550-4627-A11D-707B446F48C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CD24BD12-8550-4627-A11D-707B446F48C3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -17,8 +17,7 @@ namespace TDengineExample
|
|||
IntPtr res = TDengine.SchemalessInsert(conn, lines, lines.Length, (int)TDengineSchemalessProtocol.TSDB_SML_LINE_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("SchemalessInsert failed since " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
throw new Exception("SchemalessInsert failed since " + TDengine.Error(res));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -26,7 +25,6 @@ namespace TDengineExample
|
|||
Console.WriteLine($"SchemalessInsert success, affected {affectedRows} rows");
|
||||
}
|
||||
TDengine.FreeResult(res);
|
||||
ExitProgram(conn, 0);
|
||||
|
||||
}
|
||||
static IntPtr GetConnection()
|
||||
|
@ -39,9 +37,7 @@ namespace TDengineExample
|
|||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(1);
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -55,23 +51,15 @@ namespace TDengineExample
|
|||
IntPtr res = TDengine.Query(conn, "CREATE DATABASE test");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("failed to create database, reason: " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
throw new Exception("failed to create database, reason: " + TDengine.Error(res));
|
||||
}
|
||||
res = TDengine.Query(conn, "USE test");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("failed to change database, reason: " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
throw new Exception("failed to change database, reason: " + TDengine.Error(res));
|
||||
}
|
||||
}
|
||||
|
||||
static void ExitProgram(IntPtr conn, int exitCode)
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,27 +7,31 @@ namespace TDengineExample
|
|||
static void Main()
|
||||
{
|
||||
IntPtr conn = GetConnection();
|
||||
PrepareDatabase(conn);
|
||||
string[] lines = { "[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": 2}}," +
|
||||
try
|
||||
{
|
||||
PrepareDatabase(conn);
|
||||
string[] lines = { "[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": 2}}," +
|
||||
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, \"value\": 219, \"tags\": {\"location\": \"California.LosAngeles\", \"groupid\": 1}}, " +
|
||||
"{\"metric\": \"meters.current\", \"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": 2}}," +
|
||||
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": \"California.LosAngeles\", \"groupid\": 1}}]"
|
||||
};
|
||||
|
||||
IntPtr res = TDengine.SchemalessInsert(conn, lines, 1, (int)TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("SchemalessInsert failed since " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
IntPtr res = TDengine.SchemalessInsert(conn, lines, 1, (int)TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
throw new Exception("SchemalessInsert failed since " + TDengine.Error(res));
|
||||
}
|
||||
else
|
||||
{
|
||||
int affectedRows = TDengine.AffectRows(res);
|
||||
Console.WriteLine($"SchemalessInsert success, affected {affectedRows} rows");
|
||||
}
|
||||
TDengine.FreeResult(res);
|
||||
}
|
||||
else
|
||||
finally
|
||||
{
|
||||
int affectedRows = TDengine.AffectRows(res);
|
||||
Console.WriteLine($"SchemalessInsert success, affected {affectedRows} rows");
|
||||
TDengine.Close(conn);
|
||||
}
|
||||
TDengine.FreeResult(res);
|
||||
ExitProgram(conn, 0);
|
||||
|
||||
}
|
||||
static IntPtr GetConnection()
|
||||
{
|
||||
|
@ -39,9 +43,7 @@ namespace TDengineExample
|
|||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(1);
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -55,22 +57,13 @@ namespace TDengineExample
|
|||
IntPtr res = TDengine.Query(conn, "CREATE DATABASE test");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("failed to create database, reason: " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
throw new Exception("failed to create database, reason: " + TDengine.Error(res));
|
||||
}
|
||||
res = TDengine.Query(conn, "USE test");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("failed to change database, reason: " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
throw new Exception("failed to change database, reason: " + TDengine.Error(res));
|
||||
}
|
||||
}
|
||||
|
||||
static void ExitProgram(IntPtr conn, int exitCode)
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,8 +7,10 @@ namespace TDengineExample
|
|||
static void Main()
|
||||
{
|
||||
IntPtr conn = GetConnection();
|
||||
PrepareDatabase(conn);
|
||||
string[] lines = {
|
||||
try
|
||||
{
|
||||
PrepareDatabase(conn);
|
||||
string[] lines = {
|
||||
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||
|
@ -18,20 +20,22 @@ namespace TDengineExample
|
|||
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||
};
|
||||
IntPtr res = TDengine.SchemalessInsert(conn, lines, lines.Length, (int)TDengineSchemalessProtocol.TSDB_SML_TELNET_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("SchemalessInsert failed since " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
IntPtr res = TDengine.SchemalessInsert(conn, lines, lines.Length, (int)TDengineSchemalessProtocol.TSDB_SML_TELNET_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
throw new Exception("SchemalessInsert failed since " + TDengine.Error(res));
|
||||
}
|
||||
else
|
||||
{
|
||||
int affectedRows = TDengine.AffectRows(res);
|
||||
Console.WriteLine($"SchemalessInsert success, affected {affectedRows} rows");
|
||||
}
|
||||
TDengine.FreeResult(res);
|
||||
}
|
||||
else
|
||||
catch
|
||||
{
|
||||
int affectedRows = TDengine.AffectRows(res);
|
||||
Console.WriteLine($"SchemalessInsert success, affected {affectedRows} rows");
|
||||
TDengine.Close(conn);
|
||||
}
|
||||
TDengine.FreeResult(res);
|
||||
ExitProgram(conn, 0);
|
||||
|
||||
}
|
||||
static IntPtr GetConnection()
|
||||
{
|
||||
|
@ -43,9 +47,7 @@ namespace TDengineExample
|
|||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(1);
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -59,22 +61,13 @@ namespace TDengineExample
|
|||
IntPtr res = TDengine.Query(conn, "CREATE DATABASE test");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("failed to create database, reason: " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
throw new Exception("failed to create database, reason: " + TDengine.Error(res));
|
||||
}
|
||||
res = TDengine.Query(conn, "USE test");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine("failed to change database, reason: " + TDengine.Error(res));
|
||||
ExitProgram(conn, 1);
|
||||
throw new Exception("failed to change database, reason: " + TDengine.Error(res));
|
||||
}
|
||||
}
|
||||
|
||||
static void ExitProgram(IntPtr conn, int exitCode)
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
using TDengineDriver;
|
||||
using TDengineDriver.Impl;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TDengineExample
|
||||
{
|
||||
internal class QueryExample
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
IntPtr conn = GetConnection();
|
||||
try
|
||||
{
|
||||
// run query
|
||||
IntPtr res = TDengine.Query(conn, "SELECT * FROM meters LIMIT 2");
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
throw new Exception("Failed to query since: " + TDengine.Error(res));
|
||||
}
|
||||
|
||||
// get filed count
|
||||
int fieldCount = TDengine.FieldCount(res);
|
||||
Console.WriteLine("fieldCount=" + fieldCount);
|
||||
|
||||
// print column names
|
||||
List<TDengineMeta> metas = LibTaos.GetMeta(res);
|
||||
for (int i = 0; i < metas.Count; i++)
|
||||
{
|
||||
Console.Write(metas[i].name + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
// print values
|
||||
List<Object> resData = LibTaos.GetData(res);
|
||||
for (int i = 0; i < resData.Count; i++)
|
||||
{
|
||||
Console.Write($"|{resData[i].ToString()} \t");
|
||||
if (((i + 1) % metas.Count == 0))
|
||||
{
|
||||
Console.WriteLine("");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
// Free result after use
|
||||
TDengine.FreeResult(res);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
}
|
||||
|
||||
}
|
||||
static IntPtr GetConnection()
|
||||
{
|
||||
string host = "localhost";
|
||||
short port = 6030;
|
||||
string username = "root";
|
||||
string password = "taosdata";
|
||||
string dbname = "power";
|
||||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine success");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// output:
|
||||
// Connect to TDengine success
|
||||
// fieldCount=6
|
||||
// ts current voltage phase location groupid
|
||||
// 1648432611249 10.3 219 0.31 California.SanFrancisco 2
|
||||
// 1648432611749 12.6 218 0.33 California.SanFrancisco 2
|
|
@ -9,7 +9,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.0" />
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,69 @@
|
|||
using TDengineDriver;
|
||||
|
||||
|
||||
namespace TDengineExample
|
||||
{
|
||||
internal class SQLInsertExample
|
||||
{
|
||||
|
||||
static void Main()
|
||||
{
|
||||
IntPtr conn = GetConnection();
|
||||
try
|
||||
{
|
||||
IntPtr res = TDengine.Query(conn, "CREATE DATABASE power");
|
||||
CheckRes(conn, res, "failed to create database");
|
||||
res = TDengine.Query(conn, "USE power");
|
||||
CheckRes(conn, res, "failed to change database");
|
||||
res = TDengine.Query(conn, "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
|
||||
CheckRes(conn, res, "failed to create stable");
|
||||
var sql = "INSERT INTO d1001 USING meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000) " +
|
||||
"d1002 USING power.meters TAGS('California.SanFrancisco', 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000) " +
|
||||
"d1003 USING power.meters TAGS('California.LosAngeles', 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " +
|
||||
"d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
|
||||
res = TDengine.Query(conn, sql);
|
||||
CheckRes(conn, res, "failed to insert data");
|
||||
int affectedRows = TDengine.AffectRows(res);
|
||||
Console.WriteLine("affectedRows " + affectedRows);
|
||||
TDengine.FreeResult(res);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static IntPtr GetConnection()
|
||||
{
|
||||
string host = "localhost";
|
||||
short port = 6030;
|
||||
string username = "root";
|
||||
string password = "taosdata";
|
||||
string dbname = "";
|
||||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine success");
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
static void CheckRes(IntPtr conn, IntPtr res, String errorMsg)
|
||||
{
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
throw new Exception($"{errorMsg} since: {TDengine.Error(res)}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// output:
|
||||
// Connect to TDengine success
|
||||
// affectedRows 8
|
|
@ -9,45 +9,50 @@ namespace TDengineExample
|
|||
static void Main()
|
||||
{
|
||||
conn = GetConnection();
|
||||
PrepareSTable();
|
||||
// 1. init and prepare
|
||||
stmt = TDengine.StmtInit(conn);
|
||||
if (stmt == IntPtr.Zero)
|
||||
try
|
||||
{
|
||||
Console.WriteLine("failed to init stmt, " + TDengine.Error(stmt));
|
||||
ExitProgram();
|
||||
}
|
||||
int res = TDengine.StmtPrepare(stmt, "INSERT INTO ? USING meters TAGS(?, ?) VALUES(?, ?, ?, ?)");
|
||||
CheckStmtRes(res, "failed to prepare stmt");
|
||||
PrepareSTable();
|
||||
// 1. init and prepare
|
||||
stmt = TDengine.StmtInit(conn);
|
||||
if (stmt == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception("failed to init stmt.");
|
||||
}
|
||||
int res = TDengine.StmtPrepare(stmt, "INSERT INTO ? USING meters TAGS(?, ?) VALUES(?, ?, ?, ?)");
|
||||
CheckStmtRes(res, "failed to prepare stmt");
|
||||
|
||||
// 2. bind table name and tags
|
||||
TAOS_MULTI_BIND[] tags = new TAOS_MULTI_BIND[2] { TaosMultiBind.MultiBindBinary(new string[]{"California.SanFrancisco"}), TaosMultiBind.MultiBindInt(new int?[] {2}) };
|
||||
res = TDengine.StmtSetTbnameTags(stmt, "d1001", tags);
|
||||
CheckStmtRes(res, "failed to bind table name and tags");
|
||||
// 2. bind table name and tags
|
||||
TAOS_MULTI_BIND[] tags = new TAOS_MULTI_BIND[2] { TaosMultiBind.MultiBindBinary(new string[] { "California.SanFrancisco" }), TaosMultiBind.MultiBindInt(new int?[] { 2 }) };
|
||||
res = TDengine.StmtSetTbnameTags(stmt, "d1001", tags);
|
||||
CheckStmtRes(res, "failed to bind table name and tags");
|
||||
|
||||
// 3. bind values
|
||||
TAOS_MULTI_BIND[] values = new TAOS_MULTI_BIND[4] {
|
||||
// 3. bind values
|
||||
TAOS_MULTI_BIND[] values = new TAOS_MULTI_BIND[4] {
|
||||
TaosMultiBind.MultiBindTimestamp(new long[2] { 1648432611249, 1648432611749}),
|
||||
TaosMultiBind.MultiBindFloat(new float?[2] { 10.3f, 12.6f}),
|
||||
TaosMultiBind.MultiBindInt(new int?[2] { 219, 218}),
|
||||
TaosMultiBind.MultiBindFloat(new float?[2]{ 0.31f, 0.33f})
|
||||
};
|
||||
res = TDengine.StmtBindParamBatch(stmt, values);
|
||||
CheckStmtRes(res, "failed to bind params");
|
||||
res = TDengine.StmtBindParamBatch(stmt, values);
|
||||
CheckStmtRes(res, "failed to bind params");
|
||||
|
||||
// 4. add batch
|
||||
res = TDengine.StmtAddBatch(stmt);
|
||||
CheckStmtRes(res, "failed to add batch");
|
||||
// 4. add batch
|
||||
res = TDengine.StmtAddBatch(stmt);
|
||||
CheckStmtRes(res, "failed to add batch");
|
||||
|
||||
// 5. execute
|
||||
res = TDengine.StmtExecute(stmt);
|
||||
CheckStmtRes(res, "faild to execute");
|
||||
// 5. execute
|
||||
res = TDengine.StmtExecute(stmt);
|
||||
CheckStmtRes(res, "faild to execute");
|
||||
|
||||
// 6. free
|
||||
TaosMultiBind.FreeTaosBind(tags);
|
||||
TaosMultiBind.FreeTaosBind(values);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
}
|
||||
|
||||
// 6. free
|
||||
TaosMultiBind.FreeTaosBind(tags);
|
||||
TaosMultiBind.FreeTaosBind(values);
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
}
|
||||
|
||||
static IntPtr GetConnection()
|
||||
|
@ -60,8 +65,7 @@ namespace TDengineExample
|
|||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
Environment.Exit(0);
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -70,8 +74,6 @@ namespace TDengineExample
|
|||
return conn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void PrepareSTable()
|
||||
{
|
||||
IntPtr res = TDengine.Query(conn, "CREATE DATABASE power");
|
||||
|
@ -90,9 +92,8 @@ namespace TDengineExample
|
|||
int code = TDengine.StmtClose(stmt);
|
||||
if (code != 0)
|
||||
{
|
||||
Console.WriteLine($"falied to close stmt, {code} reason: {TDengine.StmtErrorStr(stmt)} ");
|
||||
throw new Exception($"falied to close stmt, {code} reason: {TDengine.StmtErrorStr(stmt)} ");
|
||||
}
|
||||
ExitProgram();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,16 +101,9 @@ namespace TDengineExample
|
|||
{
|
||||
if (TDengine.ErrorNo(res) != 0)
|
||||
{
|
||||
Console.WriteLine(errorMsg + " since:" + TDengine.Error(res));
|
||||
ExitProgram();
|
||||
throw new Exception(errorMsg + " since:" + TDengine.Error(res));
|
||||
}
|
||||
}
|
||||
|
||||
static void ExitProgram()
|
||||
{
|
||||
TDengine.Close(conn);
|
||||
TDengine.Cleanup();
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,11 +11,10 @@ namespace TMQExample
|
|||
{
|
||||
IntPtr conn = GetConnection();
|
||||
string topic = "topic_example";
|
||||
Console.WriteLine($"create topic if not exist {topic} as select * from meters");
|
||||
//create topic
|
||||
IntPtr res = TDengine.Query(conn, $"create topic if not exists {topic} as select * from meters");
|
||||
|
||||
if (res == IntPtr.Zero)
|
||||
|
||||
if (TDengine.ErrorNo(res) != 0 )
|
||||
{
|
||||
throw new Exception($"create topic failed, reason:{TDengine.Error(res)}");
|
||||
}
|
||||
|
@ -26,7 +25,7 @@ namespace TMQExample
|
|||
TDConnectUser = "root",
|
||||
TDConnectPasswd = "taosdata",
|
||||
MsgWithTableName = "true",
|
||||
TDConnectIp = "127.0.0.1",
|
||||
TDConnectIp = "127.0.0.1",
|
||||
};
|
||||
|
||||
// create consumer
|
||||
|
@ -65,7 +64,6 @@ namespace TMQExample
|
|||
List<string> topics = consumer.Subscription();
|
||||
topics.ForEach(t => Console.WriteLine("topic name:{0}", t));
|
||||
|
||||
|
||||
// unsubscribe
|
||||
consumer.Unsubscribe();
|
||||
|
||||
|
@ -73,7 +71,6 @@ namespace TMQExample
|
|||
consumer.Close();
|
||||
TDengine.Close(conn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static IntPtr GetConnection()
|
||||
|
@ -86,8 +83,7 @@ namespace TMQExample
|
|||
var conn = TDengine.Connect(host, username, password, dbname, port);
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Connect to TDengine failed");
|
||||
System.Environment.Exit(0);
|
||||
throw new Exception("Connect to TDengine failed");
|
||||
}
|
||||
else
|
||||
{
|
|
@ -9,7 +9,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.0" />
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using TDengineWS.Impl;
|
||||
|
||||
namespace Examples
|
||||
{
|
||||
public class WSConnExample
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string DSN = "ws://root:taosdata@127.0.0.1:6041/test";
|
||||
IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN);
|
||||
if (wsConn == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Establish connect success.");
|
||||
}
|
||||
|
||||
// close connection.
|
||||
LibTaosWS.WSClose(wsConn);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using TDengineWS.Impl;
|
||||
|
||||
namespace Examples
|
||||
{
|
||||
public class WSInsertExample
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string DSN = "ws://root:taosdata@127.0.0.1:6041/test";
|
||||
IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN);
|
||||
|
||||
// Assert if connection is validate
|
||||
if (wsConn == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Establish connect success.");
|
||||
}
|
||||
|
||||
string createTable = "CREATE STABLE test.meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);";
|
||||
string insert = "INSERT INTO test.d1001 USING test.meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)" +
|
||||
"test.d1002 USING test.meters TAGS('California.SanFrancisco', 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)" +
|
||||
"test.d1003 USING test.meters TAGS('California.LosAngeles', 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " +
|
||||
"test.d1004 USING test.meters TAGS('California.LosAngeles', 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
|
||||
|
||||
IntPtr wsRes = LibTaosWS.WSQuery(wsConn, createTable);
|
||||
ValidInsert("create table", wsRes);
|
||||
LibTaosWS.WSFreeResult(wsRes);
|
||||
|
||||
wsRes = LibTaosWS.WSQuery(wsConn, insert);
|
||||
ValidInsert("insert data", wsRes);
|
||||
LibTaosWS.WSFreeResult(wsRes);
|
||||
|
||||
// close connection.
|
||||
LibTaosWS.WSClose(wsConn);
|
||||
}
|
||||
|
||||
static void ValidInsert(string desc, IntPtr wsRes)
|
||||
{
|
||||
int code = LibTaosWS.WSErrorNo(wsRes);
|
||||
if (code != 0)
|
||||
{
|
||||
throw new Exception($"execute SQL failed: reason: {LibTaosWS.WSErrorStr(wsRes)}, code:{code}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("{0} success affect {2} rows, cost {1} nanoseconds", desc, LibTaosWS.WSTakeTiming(wsRes), LibTaosWS.WSAffectRows(wsRes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Establish connect success.
|
||||
// create table success affect 0 rows, cost 3717542 nanoseconds
|
||||
// insert data success affect 8 rows, cost 2613637 nanoseconds
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using TDengineWS.Impl;
|
||||
using System.Collections.Generic;
|
||||
using TDengineDriver;
|
||||
|
||||
namespace Examples
|
||||
{
|
||||
public class WSQueryExample
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string DSN = "ws://root:taosdata@127.0.0.1:6041/test";
|
||||
IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN);
|
||||
if (wsConn == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Establish connect success.");
|
||||
}
|
||||
|
||||
string select = "select * from test.meters";
|
||||
|
||||
// optional:wsRes = LibTaosWS.WSQuery(wsConn, select);
|
||||
IntPtr wsRes = LibTaosWS.WSQueryTimeout(wsConn, select, 1);
|
||||
// Assert if query execute success.
|
||||
int code = LibTaosWS.WSErrorNo(wsRes);
|
||||
if (code != 0)
|
||||
{
|
||||
throw new Exception($"execute SQL failed: reason: {LibTaosWS.WSErrorStr(wsRes)}, code:{code}");
|
||||
}
|
||||
|
||||
// get meta data
|
||||
List<TDengineMeta> metas = LibTaosWS.WSGetFields(wsRes);
|
||||
// get retrieved data
|
||||
List<object> dataSet = LibTaosWS.WSGetData(wsRes);
|
||||
|
||||
// do something with result.
|
||||
foreach (var meta in metas)
|
||||
{
|
||||
Console.Write("{0} {1}({2}) \t|\t", meta.name, meta.TypeName(), meta.size);
|
||||
}
|
||||
Console.WriteLine("");
|
||||
|
||||
for (int i = 0; i < dataSet.Count;)
|
||||
{
|
||||
for (int j = 0; j < metas.Count; j++)
|
||||
{
|
||||
Console.Write("{0}\t|\t", dataSet[i]);
|
||||
i++;
|
||||
}
|
||||
Console.WriteLine("");
|
||||
}
|
||||
|
||||
// Free result after use.
|
||||
LibTaosWS.WSFreeResult(wsRes);
|
||||
|
||||
// close connection.
|
||||
LibTaosWS.WSClose(wsConn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establish connect success.
|
||||
// ts TIMESTAMP(8) | current FLOAT(4) | voltage INT(4) | phase FLOAT(4) | location BINARY(64) | groupid INT(4) |
|
||||
// 1538548685000 | 10.8 | 223 | 0.29 | California.LosAngeles | 3 |
|
||||
// 1538548686500 | 11.5 | 221 | 0.35 | California.LosAngeles | 3 |
|
||||
// 1538548685500 | 11.8 | 221 | 0.28 | California.LosAngeles | 2 |
|
||||
// 1538548696600 | 13.4 | 223 | 0.29 | California.LosAngeles | 2 |
|
||||
// 1538548685000 | 10.3 | 219 | 0.31 | California.SanFrancisco | 2 |
|
||||
// 1538548695000 | 12.6 | 218 | 0.33 | California.SanFrancisco | 2 |
|
||||
// 1538548696800 | 12.3 | 221 | 0.31 | California.SanFrancisco | 2 |
|
||||
// 1538548696650 | 10.3 | 218 | 0.25 | California.SanFrancisco | 3 |
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using TDengineWS.Impl;
|
||||
using TDengineDriver;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Examples
|
||||
{
|
||||
public class WSStmtExample
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
const string DSN = "ws://root:taosdata@127.0.0.1:6041/test";
|
||||
const string table = "meters";
|
||||
const string database = "test";
|
||||
const string childTable = "d1005";
|
||||
string insert = $"insert into ? using {database}.{table} tags(?,?) values(?,?,?,?)";
|
||||
const int numOfTags = 2;
|
||||
const int numOfColumns = 4;
|
||||
|
||||
// Establish connection
|
||||
IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN);
|
||||
if (wsConn == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Establish connect success...");
|
||||
}
|
||||
|
||||
// init stmt
|
||||
IntPtr wsStmt = LibTaosWS.WSStmtInit(wsConn);
|
||||
if (wsStmt != IntPtr.Zero)
|
||||
{
|
||||
int code = LibTaosWS.WSStmtPrepare(wsStmt, insert);
|
||||
ValidStmtStep(code, wsStmt, "WSStmtPrepare");
|
||||
|
||||
TAOS_MULTI_BIND[] wsTags = new TAOS_MULTI_BIND[] { WSMultiBind.WSBindNchar(new string[] { "California.SanDiego" }), WSMultiBind.WSBindInt(new int?[] { 4 }) };
|
||||
code = LibTaosWS.WSStmtSetTbnameTags(wsStmt, $"{database}.{childTable}", wsTags, numOfTags);
|
||||
ValidStmtStep(code, wsStmt, "WSStmtSetTbnameTags");
|
||||
|
||||
TAOS_MULTI_BIND[] data = new TAOS_MULTI_BIND[4];
|
||||
data[0] = WSMultiBind.WSBindTimestamp(new long[] { 1538548687000, 1538548688000, 1538548689000, 1538548690000, 1538548691000 });
|
||||
data[1] = WSMultiBind.WSBindFloat(new float?[] { 10.30F, 10.40F, 10.50F, 10.60F, 10.70F });
|
||||
data[2] = WSMultiBind.WSBindInt(new int?[] { 223, 221, 222, 220, 219 });
|
||||
data[3] = WSMultiBind.WSBindFloat(new float?[] { 0.31F, 0.32F, 0.33F, 0.35F, 0.28F });
|
||||
code = LibTaosWS.WSStmtBindParamBatch(wsStmt, data, numOfColumns);
|
||||
ValidStmtStep(code, wsStmt, "WSStmtBindParamBatch");
|
||||
|
||||
code = LibTaosWS.WSStmtAddBatch(wsStmt);
|
||||
ValidStmtStep(code, wsStmt, "WSStmtAddBatch");
|
||||
|
||||
IntPtr stmtAffectRowPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32)));
|
||||
code = LibTaosWS.WSStmtExecute(wsStmt, stmtAffectRowPtr);
|
||||
ValidStmtStep(code, wsStmt, "WSStmtExecute");
|
||||
Console.WriteLine("WS STMT insert {0} rows...", Marshal.ReadInt32(stmtAffectRowPtr));
|
||||
Marshal.FreeHGlobal(stmtAffectRowPtr);
|
||||
|
||||
LibTaosWS.WSStmtClose(wsStmt);
|
||||
|
||||
// Free unmanaged memory
|
||||
WSMultiBind.WSFreeTaosBind(wsTags);
|
||||
WSMultiBind.WSFreeTaosBind(data);
|
||||
|
||||
//check result with SQL "SELECT * FROM test.d1005;"
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Init STMT failed...");
|
||||
}
|
||||
|
||||
// close connection.
|
||||
LibTaosWS.WSClose(wsConn);
|
||||
}
|
||||
|
||||
static void ValidStmtStep(int code, IntPtr wsStmt, string desc)
|
||||
{
|
||||
if (code != 0)
|
||||
{
|
||||
throw new Exception($"{desc} failed,reason: {LibTaosWS.WSErrorStr(wsStmt)}, code: {code}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("{0} success...", desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WSStmtPrepare success...
|
||||
// WSStmtSetTbnameTags success...
|
||||
// WSStmtBindParamBatch success...
|
||||
// WSStmtAddBatch success...
|
||||
// WSStmtExecute success...
|
||||
// WS STMT insert 5 rows...
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TDengine.Connector" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -1,8 +1,8 @@
|
|||
```csharp title="原生连接"
|
||||
{{#include docs/examples/csharp/ConnectExample.cs}}
|
||||
{{#include docs/examples/csharp/connect/Program.cs}}
|
||||
```
|
||||
|
||||
:::info
|
||||
C# 连接器目前只支持原生连接。
|
||||
```csharp title="WebSocket 连接"
|
||||
{{#include docs/examples/csharp/wsConnect/Program.cs}}
|
||||
```
|
||||
|
||||
:::
|
||||
|
|
|
@ -37,7 +37,9 @@ meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0
|
|||
- tag_set 中的所有的数据自动转化为 nchar 数据类型;
|
||||
- field_set 中的每个数据项都需要对自身的数据类型进行描述, 比如 1.2f32 代表 float 类型的数值 1.2, 如果不带类型后缀会被当作 double 处理;
|
||||
- timestamp 支持多种时间精度。写入数据的时候需要用参数指定时间精度,支持从小时到纳秒的 6 种时间精度。
|
||||
|
||||
- 为了提高写入的效率,默认假设同一个超级表中 field_set 的顺序是一样的(第一条数据包含所有的 field,后面的数据按照这个顺序),如果顺序不一样,需要配置参数 smlDataFormat 为 false,否则,数据写入按照相同顺序写入,库中数据会异常。(3.0.1.3之后的版本 smlDataFormat 默认为 false) [TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议)
|
||||
- 默认生产的子表名是根据规则生成的唯一ID值。为了让用户可以指定生成的表名,可以通过在taos.cfg里配置 smlChildTableName 参数来指定。
|
||||
举例如下:配置 smlChildTableName=tname 插入数据为 st,tname=cpu1,t1=4 c1=3 1626006833639000000 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。[TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议)
|
||||
:::
|
||||
|
||||
要了解更多可参考:[InfluxDB Line 协议官方文档](https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/) 和 [TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议)
|
||||
|
@ -64,3 +66,7 @@ meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0
|
|||
<CLine />
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## 查询示例
|
||||
比如查询 location=California.LosAngeles,groupid=2 子表的数据可以通过如下sql:
|
||||
select * from meters where location=California.LosAngeles and groupid=2
|
||||
|
|
|
@ -32,6 +32,8 @@ OpenTSDB 行协议同样采用一行字符串来表示一行数据。OpenTSDB
|
|||
meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3
|
||||
```
|
||||
|
||||
- 默认生产的子表名是根据规则生成的唯一ID值。为了让用户可以指定生成的表名,可以通过在taos.cfg里配置 smlChildTableName 参数来指定。
|
||||
举例如下:配置 smlChildTableName=tname 插入数据为 meters.current 1648432611250 11.3 tname=cpu1 location=California.LosAngeles groupid=3 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。
|
||||
参考[OpenTSDB Telnet API 文档](http://opentsdb.net/docs/build/html/api_telnet/put.html)。
|
||||
|
||||
## 示例代码
|
||||
|
@ -79,3 +81,6 @@ taos> select tbname, * from `meters.current`;
|
|||
t_7e7b26dd860280242c6492a16... | 2022-03-28 09:56:51.250 | 12.600000000 | 2 | California.SanFrancisco |
|
||||
Query OK, 4 row(s) in set (0.005399s)
|
||||
```
|
||||
## 查询示例:
|
||||
想要查询 location=California.LosAngeles groupid=3 的数据,可以通过如下sql:
|
||||
select * from `meters.voltage` where location="California.LosAngeles" and groupid=3
|
||||
|
|
|
@ -48,7 +48,8 @@ OpenTSDB JSON 格式协议采用一个 JSON 字符串表示一行或多行数据
|
|||
|
||||
- 对于 JSON 格式协议,TDengine 并不会自动把所有标签转成 nchar 类型, 字符串将将转为 nchar 类型, 数值将同样转换为 double 类型。
|
||||
- TDengine 只接收 JSON **数组格式**的字符串,即使一行数据也需要转换成数组形式。
|
||||
|
||||
- 默认生产的子表名是根据规则生成的唯一ID值。为了让用户可以指定生成的表名,可以通过在taos.cfg里配置 smlChildTableName 参数来指定。
|
||||
举例如下:配置 smlChildTableName=tname 插入数据为 "tags": { "host": "web02","dc": "lga","tname":"cpu1"} 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。
|
||||
:::
|
||||
|
||||
## 示例代码
|
||||
|
@ -94,3 +95,7 @@ taos> select * from `meters.current`;
|
|||
2022-03-28 09:56:51.250 | 12.600000000 | 2.000000000 | California.SanFrancisco |
|
||||
Query OK, 2 row(s) in set (0.004076s)
|
||||
```
|
||||
|
||||
## 查询示例
|
||||
想要查询"tags": {"location": "California.LosAngeles", "groupid": 1} 的数据,可以通过如下sql:
|
||||
select * from `meters.voltage` where location="California.LosAngeles" and groupid=1
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/InfluxDBLineExample.cs}}
|
||||
{{#include docs/examples/csharp/influxdbLine/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/OptsJsonExample.cs}}
|
||||
{{#include docs/examples/csharp/optsJSON/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/OptsTelnetExample.cs}}
|
||||
{{#include docs/examples/csharp/optsTelnet/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/SQLInsertExample.cs}}
|
||||
{{#include docs/examples/csharp/sqlInsert/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/StmtInsertExample.cs}}
|
||||
{{#include docs/examples/csharp/stmtInsert/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/QueryExample.cs}}
|
||||
{{#include docs/examples/csharp/query/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/AsyncQueryExample.cs}}
|
||||
{{#include docs/examples/csharp/asyncQuery/Program.cs}}
|
||||
```
|
||||
|
|
|
@ -52,7 +52,7 @@ CREATE TABLE d1004 USING meters TAGS ("California.LosAngeles", 3);
|
|||
### 创建流
|
||||
|
||||
```sql
|
||||
create stream current_stream into current_stream_output_stb as select _wstart as start, _wend as end, max(current) as max_current from meters where voltage <= 220 interval (5s);
|
||||
create stream current_stream into current_stream_output_stb as select _wstart as start, _wend as wend, max(current) as max_current from meters where voltage <= 220 interval (5s);
|
||||
```
|
||||
|
||||
### 写入数据
|
||||
|
@ -71,7 +71,7 @@ insert into d1004 values("2018-10-03 14:38:06.500", 11.50000, 221, 0.35000);
|
|||
|
||||
```sql
|
||||
taos> select start, end, max_current from current_stream_output_stb;
|
||||
start | end | max_current |
|
||||
start | wend | max_current |
|
||||
===========================================================================
|
||||
2018-10-03 14:38:05.000 | 2018-10-03 14:38:10.000 | 10.30000 |
|
||||
2018-10-03 14:38:15.000 | 2018-10-03 14:38:20.000 | 12.60000 |
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
```csharp
|
||||
{{#include docs/examples/csharp/SubscribeDemo.cs}}
|
||||
{{#include docs/examples/csharp/subscribe/Program.cs}}
|
||||
```
|
|
@ -125,7 +125,7 @@ curl -L -u username:password -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name]
|
|||
|
||||
### HTTP body 结构
|
||||
|
||||
#### 正确执行
|
||||
#### 正确执行插入
|
||||
|
||||
样例:
|
||||
|
||||
|
@ -145,7 +145,7 @@ curl -L -u username:password -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name]
|
|||
- rows:(`int`)只返回 `1`。
|
||||
- data:(`[][]any`)返回受影响行数。
|
||||
|
||||
#### 正确查询
|
||||
#### 正确执行查询
|
||||
|
||||
样例:
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ DSN 描述字符串基本结构如下:
|
|||
- **protocol**: 显示指定以何种方式建立连接,例如:`taos+ws://localhost:6041` 指定以 Websocket 方式建立连接。
|
||||
- **username/password**: 用于创建连接的用户名及密码。
|
||||
- **host/port**: 指定创建连接的服务器及端口,当不指定服务器地址及端口时(`taos://`),原生连接默认为 `localhost:6030`,Websocket 连接默认为 `localhost:6041` 。
|
||||
- **database**: 指定默认连接的数据库名。
|
||||
- **database**: 指定默认连接的数据库名,可选参数。
|
||||
- **params**:其他可选参数。
|
||||
|
||||
一个完整的 DSN 描述字符串示例如下:
|
||||
|
|
|
@ -17,7 +17,7 @@ import CSAsyncQuery from "../07-develop/04-query-data/_cs_async.mdx"
|
|||
|
||||
`TDengine.Connector` 是 TDengine 提供的 C# 语言连接器。C# 开发人员可以通过它开发存取 TDengine 集群数据的 C# 应用软件。
|
||||
|
||||
`TDengine.Connector` 连接器支持通过 TDengine 客户端驱动(taosc)建立与 TDengine 运行实例的连接,提供数据写入、查询、订阅、schemaless 数据写入、参数绑定接口数据写入等功能 `TDengine.Connector` 目前暂未提供 REST 连接方式,用户可以参考 [REST API](../rest-api/) 文档自行编写。
|
||||
`TDengine.Connector` 连接器支持通过 TDengine 客户端驱动(taosc)建立与 TDengine 运行实例的连接,提供数据写入、查询、数据订阅、schemaless 数据写入、参数绑定接口数据写入等功能。 `TDengine.Connector` 还支持 WebSocket,通过 DSN 建立 WebSocket 连接,提供数据写入、查询、参数绑定接口数据写入等功能。
|
||||
|
||||
本文介绍如何在 Linux 或 Windows 环境中安装 `TDengine.Connector`,并通过 `TDengine.Connector` 连接 TDengine 集群,进行数据写入、查询等基本操作。
|
||||
|
||||
|
@ -35,12 +35,29 @@ import CSAsyncQuery from "../07-develop/04-query-data/_cs_async.mdx"
|
|||
|
||||
## 支持的功能特性
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="原生连接">
|
||||
|
||||
1. 连接管理
|
||||
2. 普通查询
|
||||
3. 连续查询
|
||||
4. 参数绑定
|
||||
5. 订阅功能
|
||||
5. 数据订阅(TMQ)
|
||||
6. Schemaless
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket 连接">
|
||||
|
||||
1. 连接管理
|
||||
2. 普通查询
|
||||
3. 连续查询
|
||||
4. 参数绑定
|
||||
|
||||
</TabItem>
|
||||
|
||||
</Tabs>
|
||||
|
||||
## 安装步骤
|
||||
|
||||
|
@ -79,7 +96,13 @@ dotnet add exmaple.csproj reference src/TDengine.csproj
|
|||
|
||||
## 建立连接
|
||||
|
||||
``` C#
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="原生连接">
|
||||
|
||||
使用 host、username、password、port 等信息建立连接。
|
||||
|
||||
``` csharp
|
||||
using TDengineDriver;
|
||||
|
||||
namespace TDengineExample
|
||||
|
@ -109,17 +132,63 @@ namespace TDengineExample
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket 连接">
|
||||
|
||||
使用 DSN 建立 WebSocket 连接 DSN 连接。 描述字符串基本结构如下:
|
||||
|
||||
```text
|
||||
[<protocol>]://[[<username>:<password>@]<host>:<port>][/<database>][?<p1>=<v1>[&<p2>=<v2>]]
|
||||
|------------|---|-----------|-----------|------|------|------------|-----------------------|
|
||||
| protocol | | username | password | host | port | database | params |
|
||||
```
|
||||
|
||||
各部分意义见下表:
|
||||
|
||||
* **protocol**: 显示指定以何种方式建立连接,例如:`ws://localhost:6041` 指定以 Websocket 方式建立连接(支持http/ws)。
|
||||
|
||||
* **username/password**: 用于创建连接的用户名及密码(默认`root/taosdata`)。
|
||||
|
||||
* **host/port**: 指定创建连接的服务器及端口,WebSocket 连接默认为 `localhost:6041` 。
|
||||
|
||||
* **database**: 指定默认连接的数据库名,可选参数。
|
||||
|
||||
* **params**:其他可选参数。
|
||||
|
||||
``` csharp
|
||||
{{#include docs/examples/csharp/wsConnect/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 写入数据
|
||||
|
||||
#### SQL 写入
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="原生连接">
|
||||
|
||||
<CSInsert />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket 连接">
|
||||
|
||||
```csharp
|
||||
{{#include docs/examples/csharp/wsInsert/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
</Tabs>
|
||||
|
||||
#### InfluxDB 行协议写入
|
||||
|
||||
<CSInfluxLine />
|
||||
|
@ -132,12 +201,50 @@ namespace TDengineExample
|
|||
|
||||
<CSOpenTSDBJson />
|
||||
|
||||
#### 参数绑定
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="原生连接">
|
||||
|
||||
``` csharp
|
||||
{{#include docs/examples/csharp/stmtInsert/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket 连接">
|
||||
|
||||
```csharp
|
||||
{{#include docs/examples/csharp/wsStmt/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
</Tabs>
|
||||
|
||||
### 查询数据
|
||||
|
||||
#### 同步查询
|
||||
|
||||
<Tabs defaultValue="native">
|
||||
|
||||
<TabItem value="native" label="原生连接">
|
||||
|
||||
<CSQuery />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="rest" label="WebSocket 连接">
|
||||
|
||||
```csharp
|
||||
{{#include docs/examples/csharp/wsQuery/Program.cs}}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
</Tabs>
|
||||
|
||||
#### 异步查询
|
||||
|
||||
<CSAsyncQuery />
|
||||
|
@ -151,12 +258,15 @@ namespace TDengineExample
|
|||
| [stmt](https://github.com/taosdata/taos-connector-dotnet/tree/3.0/examples/Stmt) | 使用 TDengine.Connector 实现的参数绑定插入和查询的示例 |
|
||||
| [schemaless](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/schemaless) | 使用 TDengine.Connector 实现的使用 schemaless 写入的示例 |
|
||||
| [async query](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/AsyncQuery/QueryAsync.cs) | 使用 TDengine.Connector 实现的异步查询的示例 |
|
||||
| [TMQ](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/TMQ/TMQ.cs) | 使用 TDengine.Connector 实现的订阅数据的示例 |
|
||||
| [数据订阅(TMQ)](https://github.com/taosdata/taos-connector-dotnet/blob/3.0/examples/TMQ/TMQ.cs) | 使用 TDengine.Connector 实现的订阅数据的示例 |
|
||||
| [Basic WebSocket Usage](https://github.com/taosdata/taos-connector-dotnet/blob/5a4a7cd0dbcda114447cdc6d0c6dedd8e84a52da/examples/WS/WebSocketSample.cs) | 使用 TDengine.Connector 的 WebSocket 基本的示例 |
|
||||
| [Basic WebSocket STMT](https://github.com/taosdata/taos-connector-dotnet/blob/5a4a7cd0dbcda114447cdc6d0c6dedd8e84a52da/examples/WS/WebSocketSTMT.cs) | 使用 TDengine.Connector 的 WebSocket STMT 基本的示例 |
|
||||
|
||||
## 重要更新记录
|
||||
|
||||
| TDengine.Connector | 说明 |
|
||||
|--------------------|--------------------------------|
|
||||
| 3.0.1 | 支持 WebSocket 和 Cloud,查询,插入,参数绑定。 |
|
||||
| 3.0.0 | 支持 TDengine 3.0.0.0,不兼容 2.x。新增接口TDengine.Impl.GetData(),解析查询结果。 |
|
||||
| 1.0.7 | 修复 TDengine.Query()内存泄露。 |
|
||||
| 1.0.6 | 修复 schemaless 在 1.0.4 和 1.0.5 中失效 bug。 |
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
sidebar_label: 数据类型
|
||||
title: 数据类型
|
||||
description: "TDengine 支持的数据类型: 时间戳、浮点型、JSON 类型等"
|
||||
description: 'TDengine 支持的数据类型: 时间戳、浮点型、JSON 类型等'
|
||||
---
|
||||
|
||||
## 时间戳
|
||||
|
@ -9,64 +9,65 @@ description: "TDengine 支持的数据类型: 时间戳、浮点型、JSON 类
|
|||
使用 TDengine,最重要的是时间戳。创建并插入记录、查询历史记录的时候,均需要指定时间戳。时间戳有如下规则:
|
||||
|
||||
- 时间格式为 `YYYY-MM-DD HH:mm:ss.MS`,默认时间分辨率为毫秒。比如:`2017-08-12 18:25:58.128`
|
||||
- 内部函数 now 是客户端的当前时间
|
||||
- 插入记录时,如果时间戳为 now,插入数据时使用提交这条记录的客户端的当前时间
|
||||
- Epoch Time:时间戳也可以是一个长整数,表示从 UTC 时间 1970-01-01 00:00:00 开始的毫秒数。相应地,如果所在 Database 的时间精度设置为“微秒”,则长整型格式的时间戳含义也就对应于从 UTC 时间 1970-01-01 00:00:00 开始的微秒数;纳秒精度逻辑类似。
|
||||
- 时间可以加减,比如 now-2h,表明查询时刻向前推 2 个小时(最近 2 小时)。数字后面的时间单位可以是 b(纳秒)、u(微秒)、a(毫秒)、s(秒)、m(分)、h(小时)、d(天)、w(周)。 比如 `select * from t1 where ts > now-2w and ts <= now-1w`,表示查询两周前整整一周的数据。在指定降采样操作(down sampling)的时间窗口(interval)时,时间单位还可以使用 n (自然月) 和 y (自然年)。
|
||||
- 内部函数 NOW 是客户端的当前时间
|
||||
- 插入记录时,如果时间戳为 NOW,插入数据时使用提交这条记录的客户端的当前时间
|
||||
- Epoch Time:时间戳也可以是一个长整数,表示从 UTC 时间 1970-01-01 00:00:00 开始的毫秒数。相应地,如果所在 Database 的时间精度设置为“微秒”,则长整型格式的时间戳含义也就对应于从 UTC 时间 1970-01-01 00:00:00 开始的微秒数;纳秒精度逻辑相同。
|
||||
- 时间可以加减,比如 NOW-2h,表明查询时刻向前推 2 个小时(最近 2 小时)。数字后面的时间单位可以是 b(纳秒)、u(微秒)、a(毫秒)、s(秒)、m(分)、h(小时)、d(天)、w(周)。 比如 `SELECT * FROM t1 WHERE ts > NOW-2w AND ts <= NOW-1w`,表示查询两周前整整一周的数据。在指定降采样操作(Down Sampling)的时间窗口(Interval)时,时间单位还可以使用 n(自然月)和 y(自然年)。
|
||||
|
||||
TDengine 缺省的时间戳精度是毫秒,但通过在 `CREATE DATABASE` 时传递的 PRECISION 参数也可以支持微秒和纳秒。
|
||||
TDengine 缺省的时间戳精度是毫秒,但通过在 `CREATE DATABASE` 时传递的 `PRECISION` 参数也可以支持微秒和纳秒。
|
||||
|
||||
```sql
|
||||
CREATE DATABASE db_name PRECISION 'ns';
|
||||
```
|
||||
|
||||
## 数据类型
|
||||
|
||||
在 TDengine 中,普通表的数据模型中可使用以下数据类型。
|
||||
|
||||
| # | **类型** | **Bytes** | **说明** |
|
||||
| --- | :-------: | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1 | TIMESTAMP | 8 | 时间戳。缺省精度毫秒,可支持微秒和纳秒,详细说明见上节。 |
|
||||
| 2 | INT | 4 | 整型,范围 [-2^31, 2^31-1] |
|
||||
| 3 | INT UNSIGNED| 4| 无符号整数,[0, 2^32-1]
|
||||
| 4 | BIGINT | 8 | 长整型,范围 [-2^63, 2^63-1] |
|
||||
| 5 | BIGINT UNSIGNED | 8 | 长整型,范围 [0, 2^64-1] |
|
||||
| 6 | FLOAT | 4 | 浮点型,有效位数 6-7,范围 [-3.4E38, 3.4E38] |
|
||||
| 7 | DOUBLE | 8 | 双精度浮点型,有效位数 15-16,范围 [-1.7E308, 1.7E308] |
|
||||
| 8 | BINARY | 自定义 | 记录单字节字符串,建议只用于处理 ASCII 可见字符,中文等多字节字符需使用 nchar。 |
|
||||
| 9 | SMALLINT | 2 | 短整型, 范围 [-32768, 32767] |
|
||||
| 10 | SMALLINT UNSIGNED | 2| 无符号短整型,范围 [0, 65535] |
|
||||
| 11 | TINYINT | 1 | 单字节整型,范围 [-128, 127] |
|
||||
| 12 | TINYINT UNSIGNED | 1 | 无符号单字节整型,范围 [0, 255] |
|
||||
| 13 | BOOL | 1 | 布尔型,{true, false} |
|
||||
| 14 | NCHAR | 自定义 | 记录包含多字节字符在内的字符串,如中文字符。每个 nchar 字符占用 4 bytes 的存储空间。字符串两端使用单引号引用,字符串内的单引号需用转义字符 `\’`。nchar 使用时须指定字符串大小,类型为 nchar(10) 的列表示此列的字符串最多存储 10 个 nchar 字符,会固定占用 40 bytes 的空间。如果用户字符串长度超出声明长度,将会报错。 |
|
||||
| 15 | JSON | | json 数据类型, 只有 tag 可以是 json 格式 |
|
||||
| 16 | VARCHAR | 自定义 | BINARY类型的别名 |
|
||||
|
||||
| # | **类型** | **Bytes** | **说明** |
|
||||
| --- | :---------------: | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1 | TIMESTAMP | 8 | 时间戳。缺省精度毫秒,可支持微秒和纳秒,详细说明见上节。 |
|
||||
| 2 | INT | 4 | 整型,范围 [-2^31, 2^31-1] |
|
||||
| 3 | INT UNSIGNED | 4 | 无符号整数,[0, 2^32-1] |
|
||||
| 4 | BIGINT | 8 | 长整型,范围 [-2^63, 2^63-1] |
|
||||
| 5 | BIGINT UNSIGNED | 8 | 长整型,范围 [0, 2^64-1] |
|
||||
| 6 | FLOAT | 4 | 浮点型,有效位数 6-7,范围 [-3.4E38, 3.4E38] |
|
||||
| 7 | DOUBLE | 8 | 双精度浮点型,有效位数 15-16,范围 [-1.7E308, 1.7E308] |
|
||||
| 8 | BINARY | 自定义 | 记录单字节字符串,建议只用于处理 ASCII 可见字符,中文等多字节字符需使用 NCHAR |
|
||||
| 9 | SMALLINT | 2 | 短整型, 范围 [-32768, 32767] |
|
||||
| 10 | SMALLINT UNSIGNED | 2 | 无符号短整型,范围 [0, 65535] |
|
||||
| 11 | TINYINT | 1 | 单字节整型,范围 [-128, 127] |
|
||||
| 12 | TINYINT UNSIGNED | 1 | 无符号单字节整型,范围 [0, 255] |
|
||||
| 13 | BOOL | 1 | 布尔型,{true, false} |
|
||||
| 14 | NCHAR | 自定义 | 记录包含多字节字符在内的字符串,如中文字符。每个 NCHAR 字符占用 4 字节的存储空间。字符串两端使用单引号引用,字符串内的单引号需用转义字符 `\'`。NCHAR 使用时须指定字符串大小,类型为 NCHAR(10) 的列表示此列的字符串最多存储 10 个 NCHAR 字符,会固定占用 40 字节的空间。如果用户字符串长度超出声明长度,将会报错。 |
|
||||
| 15 | JSON | | JSON 数据类型, 只有 Tag 可以是 JSON 格式 |
|
||||
| 16 | VARCHAR | 自定义 | BINARY 类型的别名 |
|
||||
|
||||
:::note
|
||||
- TDengine 对 SQL 语句中的英文字符不区分大小写,自动转化为小写执行。因此用户大小写敏感的字符串及密码,需要使用单引号将字符串引起来。
|
||||
|
||||
- 虽然 BINARY 类型在底层存储上支持字节型的二进制字符,但不同编程语言对二进制数据的处理方式并不保证一致,因此建议在 BINARY 类型中只存储 ASCII 可见字符,而避免存储不可见字符。多字节的数据,例如中文字符,则需要使用 NCHAR 类型进行保存。如果强行使用 BINARY 类型保存中文字符,虽然有时也能正常读写,但并不带有字符集信息,很容易出现数据乱码甚至数据损坏等情况。
|
||||
- BINARY 类型理论上最长可以有 16374 字节。binary 仅支持字符串输入,字符串两端需使用单引号引用。使用时须指定大小,如 binary(20) 定义了最长为 20 个单字节字符的字符串,每个字符占 1 byte 的存储空间,总共固定占用 20 bytes 的空间,此时如果用户字符串超出 20 字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 `\’`。
|
||||
- BINARY 类型理论上最长可以有 16,374 字节。BINARY 仅支持字符串输入,字符串两端需使用单引号引用。使用时须指定大小,如 BINARY(20) 定义了最长为 20 个单字节字符的字符串,每个字符占 1 字节的存储空间,总共固定占用 20 字节的空间,此时如果用户字符串超出 20 字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 `\'`。
|
||||
- SQL 语句中的数值类型将依据是否存在小数点,或使用科学计数法表示,来判断数值类型是否为整型或者浮点型,因此在使用时要注意相应类型越界的情况。例如,9999999999999999999 会认为超过长整型的上边界而溢出,而 9999999999999999999.0 会被认为是有效的浮点数。
|
||||
|
||||
:::
|
||||
|
||||
|
||||
## 常量
|
||||
TDengine支持多个类型的常量,细节如下表:
|
||||
|
||||
| # | **语法** | **类型** | **说明** |
|
||||
| --- | :-------: | --------- | -------------------------------------- |
|
||||
| 1 | [{+ \| -}]123 | BIGINT | 整型数值的字面量的类型均为BIGINT。如果用户输入超过了BIGINT的表示范围,TDengine 按BIGINT对数值进行截断。|
|
||||
| 2 | 123.45 | DOUBLE | 浮点数值的字面量的类型均为DOUBLE。TDengine依据是否存在小数点,或使用科学计数法表示,来判断数值类型是否为整型或者浮点型。|
|
||||
| 3 | 1.2E3 | DOUBLE | 科学计数法的字面量的类型为DOUBLE。|
|
||||
| 4 | 'abc' | BINARY | 单引号括住的内容为字符串字面值,其类型为BINARY,BINARY的size为实际的字符个数。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 \'。|
|
||||
| 5 | "abc" | BINARY | 双引号括住的内容为字符串字面值,其类型为BINARY,BINARY的size为实际的字符个数。对于字符串内的双引号,可以用转义字符反斜线加单引号来表示,即 \"。 |
|
||||
| 6 | TIMESTAMP {'literal' \| "literal"} | TIMESTAMP | TIMESTAMP关键字表示后面的字符串字面量需要被解释为TIMESTAMP类型。字符串需要满足YYYY-MM-DD HH:mm:ss.MS格式,其时间分辨率为当前数据库的时间分辨率。 |
|
||||
| 7 | {TRUE \| FALSE} | BOOL | 布尔类型字面量。 |
|
||||
| 8 | {'' \| "" \| '\t' \| "\t" \| ' ' \| " " \| NULL } | -- | 空值字面量。可以用于任意类型。|
|
||||
TDengine 支持多个类型的常量,细节如下表:
|
||||
|
||||
| # | **语法** | **类型** | **说明** |
|
||||
| --- | :-----------------------------------------------: | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 1 | [{+ \| -}]123 | BIGINT | 整型数值的字面量的类型均为 BIGINT。如果用户输入超过了 BIGINT 的表示范围,TDengine 按 BIGINT 对数值进行截断。 |
|
||||
| 2 | 123.45 | DOUBLE | 浮点数值的字面量的类型均为 DOUBLE。TDengine 依据是否存在小数点,或使用科学计数法表示,来判断数值类型是否为整型或者浮点型。 |
|
||||
| 3 | 1.2E3 | DOUBLE | 科学计数法的字面量的类型为 DOUBLE。 |
|
||||
| 4 | 'abc' | BINARY | 单引号括住的内容为字符串字面值,其类型为 BINARY,BINARY 的 Size 为实际的字符个数。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 `\'`。 |
|
||||
| 5 | "abc" | BINARY | 双引号括住的内容为字符串字面值,其类型为 BINARY,BINARY 的 Size 为实际的字符个数。对于字符串内的双引号,可以用转义字符反斜线加单引号来表示,即 `\"`。 |
|
||||
| 6 | TIMESTAMP {'literal' \| "literal"} | TIMESTAMP | TIMESTAMP 关键字表示后面的字符串字面量需要被解释为 TIMESTAMP 类型。字符串需要满足 YYYY-MM-DD HH:mm:ss.MS 格式,其时间分辨率为当前数据库的时间分辨率。 |
|
||||
| 7 | {TRUE \| FALSE} | BOOL | 布尔类型字面量。 |
|
||||
| 8 | {'' \| "" \| '\t' \| "\t" \| ' ' \| " " \| NULL } | -- | 空值字面量。可以用于任意类型。 |
|
||||
|
||||
:::note
|
||||
- TDengine依据是否存在小数点,或使用科学计数法表示,来判断数值类型是否为整型或者浮点型,因此在使用时要注意相应类型越界的情况。例如,9999999999999999999会认为超过长整型的上边界而溢出,而9999999999999999999.0会被认为是有效的浮点数。
|
||||
|
||||
- TDengine 依据是否存在小数点,或使用科学计数法表示,来判断数值类型是否为整型或者浮点型,因此在使用时要注意相应类型越界的情况。例如,9999999999999999999 会认为超过长整型的上边界而溢出,而 9999999999999999999.0 会被认为是有效的浮点数。
|
||||
|
||||
:::
|
||||
|
|
|
@ -17,6 +17,8 @@ INSERT INTO
|
|||
[(field1_name, ...)]
|
||||
VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
|
||||
...];
|
||||
|
||||
INSERT INTO tb_name [(field1_name, ...)] subquery
|
||||
```
|
||||
|
||||
**关于时间戳**
|
||||
|
@ -38,7 +40,7 @@ INSERT INTO
|
|||
|
||||
4. FILE 语法表示数据来自于 CSV 文件(英文逗号分隔、英文单引号括住每个值),CSV 文件无需表头。
|
||||
|
||||
5. 无论使用哪种语法,均可以在一条 INSERT 语句中同时向多个表插入数据。
|
||||
5. `INSERT ... VALUES` 语句和 `INSERT ... FILE` 语句均可以在一条 INSERT 语句中同时向多个表插入数据。
|
||||
|
||||
6. INSERT 语句是完整解析后再执行的,对如下语句,不会再出现数据错误但建表成功的情况:
|
||||
|
||||
|
@ -48,6 +50,8 @@ INSERT INTO
|
|||
|
||||
7. 对于向多个子表插入数据的情况,依然会有部分数据写入失败,部分数据写入成功的情况。这是因为多个子表可能分布在不同的 VNODE 上,客户端将 INSERT 语句完整解析后,将数据发往各个涉及的 VNODE 上,每个 VNODE 独立进行写入操作。如果某个 VNODE 因为某些原因(比如网络问题或磁盘故障)导致写入失败,并不会影响其他 VNODE 节点的写入。
|
||||
|
||||
8. 可以使用 `INSERT ... subquery` 语句将 TDengine 中的数据插入到指定表中。subquery 可以是任意的查询语句。此语法只能用于子表和普通表,且不支持自动建表。
|
||||
|
||||
## 插入一条记录
|
||||
|
||||
指定已经创建好的数据子表的表名,并通过 VALUES 关键字提供一行或多行数据,即可向数据库写入这些数据。例如,执行如下语句可以写入一行记录:
|
||||
|
|
|
@ -69,7 +69,7 @@ order_expr:
|
|||
|
||||
### 通配符
|
||||
|
||||
通配符 \* 可以用于代指全部列。对于普通表,结果中只有普通列。对于超级表和子表,还包含了 TAG 列。
|
||||
通配符 \* 可以用于代指全部列。对于普通表和子表,结果中只有普通列。对于超级表,还包含了 TAG 列。
|
||||
|
||||
```sql
|
||||
SELECT * FROM d1001;
|
||||
|
@ -137,6 +137,8 @@ taos> SELECT ts, ts AS primary_key_ts FROM d1001;
|
|||
|
||||
### 伪列
|
||||
|
||||
**伪列**: 伪列的行为表现与普通数据列相似但其并不实际存储在表中。可以查询伪列,但不能对其做插入、更新和删除的操作。伪列有点像没有参数的函数。下面介绍是可用的伪列:
|
||||
|
||||
**TBNAME**
|
||||
`TBNAME` 可以视为超级表中一个特殊的标签,代表子表的表名。
|
||||
|
||||
|
@ -180,6 +182,14 @@ TDengine 中,所有表的第一列都必须是时间戳类型,且为其主
|
|||
select _rowts, max(current) from meters;
|
||||
```
|
||||
|
||||
**\_IROWTS**
|
||||
|
||||
\_irowts 伪列只能与 interp 函数一起使用,用于返回 interp 函数插值结果对应的时间戳列。
|
||||
|
||||
```sql
|
||||
select _irowts, interp(current) from meters range('2020-01-01 10:00:00', '2020-01-01 10:30:00') every(1s) fill(linear);
|
||||
```
|
||||
|
||||
## 查询对象
|
||||
|
||||
FROM 关键字后面可以是若干个表(超级表)列表,也可以是子查询的结果。
|
||||
|
|
|
@ -14,7 +14,7 @@ toc_max_heading_level: 4
|
|||
#### ABS
|
||||
|
||||
```sql
|
||||
SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ABS(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的绝对值。
|
||||
|
@ -32,7 +32,7 @@ SELECT ABS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ACOS
|
||||
|
||||
```sql
|
||||
SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ACOS(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的反余弦结果。
|
||||
|
@ -50,7 +50,7 @@ SELECT ACOS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ASIN
|
||||
|
||||
```sql
|
||||
SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ASIN(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的反正弦结果。
|
||||
|
@ -69,7 +69,7 @@ SELECT ASIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ATAN
|
||||
|
||||
```sql
|
||||
SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
ATAN(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的反正切结果。
|
||||
|
@ -88,7 +88,7 @@ SELECT ATAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### CEIL
|
||||
|
||||
```sql
|
||||
SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
CEIL(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的向上取整数的结果。
|
||||
|
@ -106,7 +106,7 @@ SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### COS
|
||||
|
||||
```sql
|
||||
SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
COS(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的余弦结果。
|
||||
|
@ -124,7 +124,7 @@ SELECT COS(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### FLOOR
|
||||
|
||||
```sql
|
||||
SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
FLOOR(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的向下取整数的结果。
|
||||
|
@ -133,10 +133,10 @@ SELECT FLOOR(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### LOG
|
||||
|
||||
```sql
|
||||
SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LOG(expr1[, expr2])
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段对于底数 base 的对数。如果 base 参数省略,则返回指定字段的自然对数值。
|
||||
**功能说明**:获得 expr1 对于底数 expr2 的对数。如果 expr2 参数省略,则返回指定字段的自然对数值。
|
||||
|
||||
**返回结果类型**:DOUBLE。
|
||||
|
||||
|
@ -152,10 +152,10 @@ SELECT LOG(field_name[, base]) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### POW
|
||||
|
||||
```sql
|
||||
SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
|
||||
POW(expr1, expr2)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的指数为 power 的幂。
|
||||
**功能说明**:获得 expr1 的指数为 expr2 的幂。
|
||||
|
||||
**返回结果类型**:DOUBLE。
|
||||
|
||||
|
@ -171,7 +171,7 @@ SELECT POW(field_name, power) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### ROUND
|
||||
|
||||
```sql
|
||||
SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
ROUND(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的四舍五入的结果。
|
||||
|
@ -181,7 +181,7 @@ SELECT ROUND(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### SIN
|
||||
|
||||
```sql
|
||||
SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SIN(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的正弦结果。
|
||||
|
@ -199,7 +199,7 @@ SELECT SIN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### SQRT
|
||||
|
||||
```sql
|
||||
SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SQRT(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的平方根。
|
||||
|
@ -217,7 +217,7 @@ SELECT SQRT(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### TAN
|
||||
|
||||
```sql
|
||||
SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
TAN(expr)
|
||||
```
|
||||
|
||||
**功能说明**:获得指定字段的正切结果。
|
||||
|
@ -239,7 +239,7 @@ SELECT TAN(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### CHAR_LENGTH
|
||||
|
||||
```sql
|
||||
SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CHAR_LENGTH(expr)
|
||||
```
|
||||
|
||||
**功能说明**:以字符计数的字符串长度。
|
||||
|
@ -255,7 +255,7 @@ SELECT CHAR_LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### CONCAT
|
||||
|
||||
```sql
|
||||
SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CONCAT(expr1, expr2 [, expr] ... )
|
||||
```
|
||||
|
||||
**功能说明**:字符串连接函数。
|
||||
|
@ -272,7 +272,7 @@ SELECT CONCAT(str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHER
|
|||
#### CONCAT_WS
|
||||
|
||||
```sql
|
||||
SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CONCAT_WS(separator_expr, expr1, expr2 [, expr] ...)
|
||||
```
|
||||
|
||||
**功能说明**:带分隔符的字符串连接函数。
|
||||
|
@ -289,7 +289,7 @@ SELECT CONCAT_WS(separator, str1|column1, str2|column2, ...) FROM { tb_name | st
|
|||
#### LENGTH
|
||||
|
||||
```sql
|
||||
SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LENGTH(expr)
|
||||
```
|
||||
|
||||
**功能说明**:以字节计数的字符串长度。
|
||||
|
@ -306,7 +306,7 @@ SELECT LENGTH(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### LOWER
|
||||
|
||||
```sql
|
||||
SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LOWER(expr)
|
||||
```
|
||||
|
||||
**功能说明**:将字符串参数值转换为全小写字母。
|
||||
|
@ -323,7 +323,7 @@ SELECT LOWER(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### LTRIM
|
||||
|
||||
```sql
|
||||
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LTRIM(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回清除左边空格后的字符串。
|
||||
|
@ -340,7 +340,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### RTRIM
|
||||
|
||||
```sql
|
||||
SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
LTRIM(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回清除右边空格后的字符串。
|
||||
|
@ -357,7 +357,7 @@ SELECT LTRIM(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### SUBSTR
|
||||
|
||||
```sql
|
||||
SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SUBSTR(expr, pos [,len])
|
||||
```
|
||||
|
||||
**功能说明**:从源字符串 str 中的指定位置 pos 开始取一个长度为 len 的子串并返回。如果输入参数 len 被忽略,返回的子串包含从 pos 开始的整个字串。
|
||||
|
@ -374,7 +374,7 @@ SELECT SUBSTR(str,pos[,len]) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### UPPER
|
||||
|
||||
```sql
|
||||
SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
||||
UPPER(expr)
|
||||
```
|
||||
|
||||
**功能说明**:将字符串参数值转换为全大写字母。
|
||||
|
@ -395,10 +395,10 @@ SELECT UPPER(str|column) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### CAST
|
||||
|
||||
```sql
|
||||
SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CAST(expr AS type_name)
|
||||
```
|
||||
|
||||
**功能说明**:数据类型转换函数,返回 expression 转换为 type_name 指定的类型后的结果。只适用于 select 子句中。
|
||||
**功能说明**:数据类型转换函数,返回 expr 转换为 type_name 指定的类型后的结果。只适用于 select 子句中。
|
||||
|
||||
**返回结果类型**:CAST 中指定的类型(type_name)。
|
||||
|
||||
|
@ -419,7 +419,7 @@ SELECT CAST(expression AS type_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
#### TO_ISO8601
|
||||
|
||||
```sql
|
||||
SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TO_ISO8601(expr [, timezone])
|
||||
```
|
||||
|
||||
**功能说明**:将 UNIX 时间戳转换成为 ISO8601 标准的日期时间格式,并附加时区信息。timezone 参数允许用户为输出结果指定附带任意时区信息。如果 timezone 参数省略,输出结果则附带当前客户端的系统时区信息。
|
||||
|
@ -442,7 +442,7 @@ SELECT TO_ISO8601(ts[, timezone]) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### TO_JSON
|
||||
|
||||
```sql
|
||||
SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TO_JSON(str_literal)
|
||||
```
|
||||
|
||||
**功能说明**: 将字符串常量转换为 JSON 类型。
|
||||
|
@ -459,7 +459,7 @@ SELECT TO_JSON(str_literal) FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### TO_UNIXTIMESTAMP
|
||||
|
||||
```sql
|
||||
SELECT TO_UNIXTIMESTAMP(datetime_string) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TO_UNIXTIMESTAMP(expr)
|
||||
```
|
||||
|
||||
**功能说明**:将日期时间格式的字符串转换成为 UNIX 时间戳。
|
||||
|
@ -487,9 +487,7 @@ SELECT TO_UNIXTIMESTAMP(datetime_string) FROM { tb_name | stb_name } [WHERE clau
|
|||
#### NOW
|
||||
|
||||
```sql
|
||||
SELECT NOW() FROM { tb_name | stb_name } [WHERE clause];
|
||||
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior NOW();
|
||||
INSERT INTO tb_name VALUES (NOW(), ...);
|
||||
NOW()
|
||||
```
|
||||
|
||||
**功能说明**:返回客户端当前系统时间。
|
||||
|
@ -512,7 +510,7 @@ INSERT INTO tb_name VALUES (NOW(), ...);
|
|||
#### TIMEDIFF
|
||||
|
||||
```sql
|
||||
SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TIMEDIFF(expr1, expr2 [, time_unit])
|
||||
```
|
||||
|
||||
**功能说明**:计算两个时间戳之间的差值,并近似到时间单位 time_unit 指定的精度。
|
||||
|
@ -535,7 +533,7 @@ SELECT TIMEDIFF(ts | datetime_string1, ts | datetime_string2 [, time_unit]) FROM
|
|||
#### TIMETRUNCATE
|
||||
|
||||
```sql
|
||||
SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TIMETRUNCATE(expr, time_unit)
|
||||
```
|
||||
|
||||
**功能说明**:将时间戳按照指定时间单位 time_unit 进行截断。
|
||||
|
@ -556,7 +554,7 @@ SELECT TIMETRUNCATE(ts | datetime_string , time_unit) FROM { tb_name | stb_name
|
|||
#### TIMEZONE
|
||||
|
||||
```sql
|
||||
SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
|
||||
TIMEZONE()
|
||||
```
|
||||
|
||||
**功能说明**:返回客户端当前时区信息。
|
||||
|
@ -571,9 +569,7 @@ SELECT TIMEZONE() FROM { tb_name | stb_name } [WHERE clause];
|
|||
#### TODAY
|
||||
|
||||
```sql
|
||||
SELECT TODAY() FROM { tb_name | stb_name } [WHERE clause];
|
||||
SELECT select_expr FROM { tb_name | stb_name } WHERE ts_col cond_operatior TODAY()];
|
||||
INSERT INTO tb_name VALUES (TODAY(), ...);
|
||||
TODAY()
|
||||
```
|
||||
|
||||
**功能说明**:返回客户端当日零时的系统时间。
|
||||
|
@ -600,7 +596,12 @@ TDengine 支持针对数据的聚合查询。提供如下聚合函数。
|
|||
### APERCENTILE
|
||||
|
||||
```sql
|
||||
SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHERE clause]
|
||||
APERCENTILE(expr, p [, algo_type])
|
||||
|
||||
algo_type: {
|
||||
"default"
|
||||
| "t-digest"
|
||||
}
|
||||
```
|
||||
|
||||
**功能说明**:统计表/超级表中指定列的值的近似百分比分位数,与 PERCENTILE 函数相似,但是返回近似结果。
|
||||
|
@ -612,14 +613,14 @@ SELECT APERCENTILE(field_name, P[, algo_type]) FROM { tb_name | stb_name } [WHER
|
|||
**适用于**:表和超级表。
|
||||
|
||||
**说明**:
|
||||
- P值范围是[0,100],当为0时等同于MIN,为100时等同于MAX。
|
||||
- p值范围是[0,100],当为0时等同于MIN,为100时等同于MAX。
|
||||
- algo_type 取值为 "default" 或 "t-digest"。 输入为 "default" 时函数使用基于直方图算法进行计算。输入为 "t-digest" 时使用t-digest算法计算分位数的近似结果。如果不指定 algo_type 则使用 "default" 算法。
|
||||
- "t-digest"算法的近似结果对于输入数据顺序敏感,对超级表查询时不同的输入排序结果可能会有微小的误差。
|
||||
|
||||
### AVG
|
||||
|
||||
```sql
|
||||
SELECT AVG(field_name) FROM tb_name [WHERE clause];
|
||||
AVG(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计指定字段的平均值。
|
||||
|
@ -634,7 +635,7 @@ SELECT AVG(field_name) FROM tb_name [WHERE clause];
|
|||
### COUNT
|
||||
|
||||
```sql
|
||||
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
|
||||
COUNT({* | expr})
|
||||
```
|
||||
|
||||
**功能说明**:统计指定字段的记录行数。
|
||||
|
@ -654,7 +655,7 @@ SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
|
|||
### ELAPSED
|
||||
|
||||
```sql
|
||||
SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE clause] [INTERVAL(interval [, offset]) [SLIDING sliding]];
|
||||
ELAPSED(ts_primary_key [, time_unit])
|
||||
```
|
||||
|
||||
**功能说明**:elapsed函数表达了统计周期内连续的时间长度,和twa函数配合使用可以计算统计曲线下的面积。在通过INTERVAL子句指定窗口的情况下,统计在给定时间范围内的每个窗口内有数据覆盖的时间范围;如果没有INTERVAL子句,则返回整个给定时间范围内的有数据覆盖的时间范围。注意,ELAPSED返回的并不是时间范围的绝对值,而是绝对值除以time_unit所得到的单位个数。
|
||||
|
@ -666,7 +667,7 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
|
|||
**适用于**: 表,超级表,嵌套查询的外层查询
|
||||
|
||||
**说明**:
|
||||
- field_name参数只能是表的第一列,即 TIMESTAMP 类型的主键列。
|
||||
- ts_primary_key参数只能是表的第一列,即 TIMESTAMP 类型的主键列。
|
||||
- 按time_unit参数指定的时间单位返回,最小是数据库的时间分辨率。time_unit 参数未指定时,以数据库的时间分辨率为时间单位。支持的时间单位 time_unit 如下:
|
||||
1b(纳秒), 1u(微秒),1a(毫秒),1s(秒),1m(分),1h(小时),1d(天), 1w(周)。
|
||||
- 可以和interval组合使用,返回每个时间窗口的时间戳差值。需要特别注意的是,除第一个时间窗口和最后一个时间窗口外,中间窗口的时间戳差值均为窗口长度。
|
||||
|
@ -680,14 +681,14 @@ SELECT ELAPSED(ts_primary_key [, time_unit]) FROM { tb_name | stb_name } [WHERE
|
|||
### LEASTSQUARES
|
||||
|
||||
```sql
|
||||
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause];
|
||||
LEASTSQUARES(expr, start_val, step_val)
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列的值是主键(时间戳)的拟合直线方程。start_val 是自变量初始值,step_val 是自变量的步长值。
|
||||
|
||||
**返回数据类型**:字符串表达式(斜率, 截距)。
|
||||
|
||||
**适用数据类型**:field_name 必须是数值类型。
|
||||
**适用数据类型**:expr 必须是数值类型。
|
||||
|
||||
**适用于**:表。
|
||||
|
||||
|
@ -695,7 +696,7 @@ SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause]
|
|||
### SPREAD
|
||||
|
||||
```sql
|
||||
SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
SPREAD(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列的最大值和最小值之差。
|
||||
|
@ -710,7 +711,7 @@ SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### STDDEV
|
||||
|
||||
```sql
|
||||
SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
|
||||
STDDEV(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列的均方差。
|
||||
|
@ -725,7 +726,7 @@ SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
|
|||
### SUM
|
||||
|
||||
```sql
|
||||
SELECT SUM(field_name) FROM tb_name [WHERE clause];
|
||||
SUM(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计表/超级表中某列的和。
|
||||
|
@ -740,7 +741,7 @@ SELECT SUM(field_name) FROM tb_name [WHERE clause];
|
|||
### HYPERLOGLOG
|
||||
|
||||
```sql
|
||||
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
HYPERLOGLOG(expr)
|
||||
```
|
||||
|
||||
**功能说明**:
|
||||
|
@ -757,7 +758,7 @@ SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### HISTOGRAM
|
||||
|
||||
```sql
|
||||
SELECT HISTOGRAM(field_name,bin_type, bin_description, normalized) FROM tb_name [WHERE clause];
|
||||
HISTOGRAM(expr,bin_type, bin_description, normalized)
|
||||
```
|
||||
|
||||
**功能说明**:统计数据按照用户指定区间的分布。
|
||||
|
@ -787,7 +788,7 @@ SELECT HISTOGRAM(field_name,bin_type, bin_description, normalized) FROM tb_nam
|
|||
### PERCENTILE
|
||||
|
||||
```sql
|
||||
SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
|
||||
PERCENTILE(expr, p)
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列的值百分比分位数。
|
||||
|
@ -808,7 +809,7 @@ SELECT PERCENTILE(field_name, P) FROM { tb_name } [WHERE clause];
|
|||
### BOTTOM
|
||||
|
||||
```sql
|
||||
SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
BOTTOM(expr, k)
|
||||
```
|
||||
|
||||
**功能说明**:统计表/超级表中某列的值最小 _k_ 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
|
||||
|
@ -828,7 +829,7 @@ SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### FIRST
|
||||
|
||||
```sql
|
||||
SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
FIRST(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计表/超级表中某列的值最先写入的非 NULL 值。
|
||||
|
@ -848,7 +849,7 @@ SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### INTERP
|
||||
|
||||
```sql
|
||||
SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RANGE(timestamp1,timestamp2) EVERY(interval) FILL({ VALUE | PREV | NULL | LINEAR | NEXT});
|
||||
INTERP(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回指定时间截面指定列的记录值或插值。
|
||||
|
@ -867,11 +868,12 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] RA
|
|||
- INTERP 根据 EVERY 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(EVERY 值)进行插值。如果没有指定 EVERY,则默认窗口大小为无穷大,即从 timestamp1 开始只有一个窗口。
|
||||
- INTERP 根据 FILL 字段来决定在每个符合输出条件的时刻如何进行插值。
|
||||
- INTERP 只能在一个时间序列内进行插值,因此当作用于超级表时必须跟 partition by tbname 一起使用。
|
||||
- INTERP 可以与伪列 _irowts 一起使用,返回插值点所对应的时间戳(3.0.1.4版本以后支持)。
|
||||
|
||||
### LAST
|
||||
|
||||
```sql
|
||||
SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
LAST(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计表/超级表中某列的值最后写入的非 NULL 值。
|
||||
|
@ -892,7 +894,7 @@ SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### LAST_ROW
|
||||
|
||||
```sql
|
||||
SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
|
||||
LAST_ROW(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回表/超级表的最后一条记录。
|
||||
|
@ -911,7 +913,7 @@ SELECT LAST_ROW(field_name) FROM { tb_name | stb_name };
|
|||
### MAX
|
||||
|
||||
```sql
|
||||
SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
MAX(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计表/超级表中某列的值最大值。
|
||||
|
@ -926,7 +928,7 @@ SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### MIN
|
||||
|
||||
```sql
|
||||
SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
||||
MIN(expr)
|
||||
```
|
||||
|
||||
**功能说明**:统计表/超级表中某列的值最小值。
|
||||
|
@ -941,7 +943,7 @@ SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
|||
### MODE
|
||||
|
||||
```sql
|
||||
SELECT MODE(field_name) FROM tb_name [WHERE clause];
|
||||
MODE(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回出现频率最高的值,若存在多个频率相同的最高值,输出NULL。
|
||||
|
@ -956,7 +958,7 @@ SELECT MODE(field_name) FROM tb_name [WHERE clause];
|
|||
### SAMPLE
|
||||
|
||||
```sql
|
||||
SELECT SAMPLE(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
|
||||
SAMPLE(expr, k)
|
||||
```
|
||||
|
||||
**功能说明**: 获取数据的 k 个采样值。参数 k 的合法输入范围是 1≤ k ≤ 1000。
|
||||
|
@ -978,7 +980,7 @@ SELECT SAMPLE(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
|
|||
### TAIL
|
||||
|
||||
```sql
|
||||
SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
|
||||
TAIL(expr, k [, offset_rows])
|
||||
```
|
||||
|
||||
**功能说明**:返回跳过最后 offset_val 个,然后取连续 k 个记录,不忽略 NULL 值。offset_val 可以不输入。此时返回最后的 k 个记录。当有 offset_val 输入的情况下,该函数功能等效于 `order by ts desc LIMIT k OFFSET offset_val`。
|
||||
|
@ -995,7 +997,7 @@ SELECT TAIL(field_name, k, offset_val) FROM {tb_name | stb_name} [WHERE clause];
|
|||
### TOP
|
||||
|
||||
```sql
|
||||
SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
TOP(expr, k)
|
||||
```
|
||||
|
||||
**功能说明**: 统计表/超级表中某列的值最大 _k_ 个非 NULL 值。如果多条数据取值一样,全部取用又会超出 k 条限制时,系统会从相同值中随机选取符合要求的数量返回。
|
||||
|
@ -1015,7 +1017,7 @@ SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
|||
### UNIQUE
|
||||
|
||||
```sql
|
||||
SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
||||
UNIQUE(expr)
|
||||
```
|
||||
|
||||
**功能说明**:返回该列的数值首次出现的值。该函数功能与 distinct 相似,但是可以匹配标签和时间戳信息。可以针对除时间列以外的字段进行查询,可以匹配标签和时间戳,其中的标签和时间戳是第一次出现时刻的标签和时间戳。
|
||||
|
@ -1034,7 +1036,7 @@ SELECT UNIQUE(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
|||
### CSUM
|
||||
|
||||
```sql
|
||||
SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
||||
CSUM(expr)
|
||||
```
|
||||
|
||||
**功能说明**:累加和(Cumulative sum),输出行与输入行数相同。
|
||||
|
@ -1057,7 +1059,12 @@ SELECT CSUM(field_name) FROM { tb_name | stb_name } [WHERE clause]
|
|||
### DERIVATIVE
|
||||
|
||||
```sql
|
||||
SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHERE clause];
|
||||
DERIVATIVE(expr, time_interval, ignore_negative)
|
||||
|
||||
ignore_negative: {
|
||||
0
|
||||
| 1
|
||||
}
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列数值的单位变化率。其中单位时间区间的长度可以通过 time_interval 参数指定,最小可以是 1 秒(1s);ignore_negative 参数的值可以是 0 或 1,为 1 时表示忽略负值。
|
||||
|
@ -1076,7 +1083,12 @@ SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHER
|
|||
### DIFF
|
||||
|
||||
```sql
|
||||
SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHERE clause];
|
||||
DIFF(expr [, ignore_negative])
|
||||
|
||||
ignore_negative: {
|
||||
0
|
||||
| 1
|
||||
}
|
||||
```
|
||||
|
||||
**功能说明**:统计表中某列的值与前一行对应值的差。 ignore_negative 取值为 0|1 , 可以不填,默认值为 0. 不忽略负值。ignore_negative 为 1 时表示忽略负数。
|
||||
|
@ -1096,7 +1108,7 @@ SELECT {DIFF(field_name, ignore_negative) | DIFF(field_name)} FROM tb_name [WHER
|
|||
### IRATE
|
||||
|
||||
```sql
|
||||
SELECT IRATE(field_name) FROM tb_name WHERE clause;
|
||||
IRATE(expr)
|
||||
```
|
||||
|
||||
**功能说明**:计算瞬时增长率。使用时间区间中最后两个样本数据来计算瞬时增长速率;如果这两个值呈递减关系,那么只取最后一个数用于计算,而不是使用二者差值。
|
||||
|
@ -1111,7 +1123,7 @@ SELECT IRATE(field_name) FROM tb_name WHERE clause;
|
|||
### MAVG
|
||||
|
||||
```sql
|
||||
SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
|
||||
MAVG(expr, k)
|
||||
```
|
||||
|
||||
**功能说明**: 计算连续 k 个值的移动平均数(moving average)。如果输入行数小于 k,则无结果输出。参数 k 的合法输入范围是 1≤ k ≤ 1000。
|
||||
|
@ -1134,7 +1146,7 @@ SELECT MAVG(field_name, K) FROM { tb_name | stb_name } [WHERE clause]
|
|||
### STATECOUNT
|
||||
|
||||
```sql
|
||||
SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clause];
|
||||
STATECOUNT(expr, oper, val)
|
||||
```
|
||||
|
||||
**功能说明**:返回满足某个条件的连续记录的个数,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为 true 则加 1,条件为 false 则重置为-1,如果数据为 NULL,跳过该条数据。
|
||||
|
@ -1161,7 +1173,7 @@ SELECT STATECOUNT(field_name, oper, val) FROM { tb_name | stb_name } [WHERE clau
|
|||
### STATEDURATION
|
||||
|
||||
```sql
|
||||
SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [WHERE clause];
|
||||
STATEDURATION(expr, oper, val, unit)
|
||||
```
|
||||
|
||||
**功能说明**:返回满足某个条件的连续记录的时间长度,结果作为新的一列追加在每行后面。条件根据参数计算,如果条件为 true 则加上两个记录之间的时间长度(第一个满足条件的记录时间长度记为 0),条件为 false 则重置为-1,如果数据为 NULL,跳过该条数据。
|
||||
|
@ -1189,7 +1201,7 @@ SELECT stateDuration(field_name, oper, val, unit) FROM { tb_name | stb_name } [W
|
|||
### TWA
|
||||
|
||||
```sql
|
||||
SELECT TWA(field_name) FROM tb_name WHERE clause;
|
||||
TWA(expr)
|
||||
```
|
||||
|
||||
**功能说明**:时间加权平均函数。统计表中某列在一段时间内的时间加权平均。
|
||||
|
@ -1233,7 +1245,7 @@ SELECT SERVER_VERSION();
|
|||
### SERVER_STATUS
|
||||
|
||||
```sql
|
||||
SELECT SERVER_VERSION();
|
||||
SELECT SERVER_STATUS();
|
||||
```
|
||||
|
||||
**说明**:返回服务端当前的状态。
|
||||
|
|
|
@ -344,6 +344,7 @@ description: TDengine 保留关键字的详细列表
|
|||
### \_
|
||||
|
||||
- \_C0
|
||||
- \_IROWTS
|
||||
- \_QDURATION
|
||||
- \_QEND
|
||||
- \_QSTART
|
||||
|
|
|
@ -12,7 +12,15 @@ TDengine 内置了一个名为 `INFORMATION_SCHEMA` 的数据库,提供对数
|
|||
4. TDengine 在后续演进中可以灵活的添加已有 INFORMATION_SCHEMA 中表的列,而不用担心对既有业务系统造成影响
|
||||
5. 与其他数据库系统更具互操作性。例如,Oracle 数据库用户熟悉查询 Oracle 数据字典中的表
|
||||
|
||||
Note: 由于 SHOW 语句已经被开发者熟悉和广泛使用,所以它们仍然被保留。
|
||||
:::info
|
||||
|
||||
- 由于 SHOW 语句已经被开发者熟悉和广泛使用,所以它们仍然被保留。
|
||||
- 系统表中的一些列可能是关键字,在查询时需要使用转义符'\`',例如查询数据库 test 有几个 VGROUP:
|
||||
```sql
|
||||
select `vgroups` from ins_databases where name = 'test';
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
本章将详细介绍 `INFORMATION_SCHEMA` 这个内置元数据库中的表和表结构。
|
||||
|
||||
|
@ -103,7 +111,11 @@ Note: 由于 SHOW 语句已经被开发者熟悉和广泛使用,所以它们
|
|||
| 24 | wal_retention_period | INT | WAL 的保存时长 |
|
||||
| 25 | wal_retention_size | INT | WAL 的保存上限 |
|
||||
| 26 | wal_roll_period | INT | wal 文件切换时长 |
|
||||
| 27 | wal_segment_size | wal 单个文件大小 |
|
||||
| 27 | wal_segment_size | BIGINT | wal 单个文件大小 |
|
||||
| 28 | stt_trigger | SMALLINT | 触发文件合并的落盘文件的个数 |
|
||||
| 29 | table_prefix | SMALLINT | 内部存储引擎根据表名分配存储该表数据的 VNODE 时要忽略的前缀的长度 |
|
||||
| 30 | table_suffix | SMALLINT | 内部存储引擎根据表名分配存储该表数据的 VNODE 时要忽略的后缀的长度 |
|
||||
| 31 | tsdb_pagesize | INT | 时序数据存储引擎中的页大小 |
|
||||
|
||||
## INS_FUNCTIONS
|
||||
|
||||
|
|
|
@ -11,12 +11,13 @@ description: "TDengine 3.0 版本的语法变更说明"
|
|||
| 1 | VARCHAR | 新增 | BINARY类型的别名。
|
||||
| 2 | TIMESTAMP字面量 | 新增 | 新增支持 TIMESTAMP 'timestamp format' 语法。
|
||||
| 3 | _ROWTS伪列 | 新增 | 表示时间戳主键。是_C0伪列的别名。
|
||||
| 4 | INFORMATION_SCHEMA | 新增 | 包含各种SCHEMA定义的系统数据库。
|
||||
| 5 | PERFORMANCE_SCHEMA | 新增 | 包含运行信息的系统数据库。
|
||||
| 6 | 连续查询 | 废除 | 不再支持连续查询。相关的各种语法和接口废除。
|
||||
| 7 | 混合运算 | 增强 | 查询中的混合运算(标量运算和矢量运算混合)全面增强,SELECT的各个子句均全面支持符合语法语义的混合运算。
|
||||
| 8 | 标签运算 | 新增 |在查询中,标签列可以像普通列一样参与各种运算,用于各种子句。
|
||||
| 9 | 时间线子句和时间函数用于超级表查询 | 增强 |没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
| 4 | _IROWTS伪列 | 新增 | 用于返回 interp 函数插值结果对应的时间戳列。
|
||||
| 5 | INFORMATION_SCHEMA | 新增 | 包含各种SCHEMA定义的系统数据库。
|
||||
| 6 | PERFORMANCE_SCHEMA | 新增 | 包含运行信息的系统数据库。
|
||||
| 7 | 连续查询 | 废除 | 不再支持连续查询。相关的各种语法和接口废除。
|
||||
| 8 | 混合运算 | 增强 | 查询中的混合运算(标量运算和矢量运算混合)全面增强,SELECT的各个子句均全面支持符合语法语义的混合运算。
|
||||
| 9 | 标签运算 | 新增 |在查询中,标签列可以像普通列一样参与各种运算,用于各种子句。
|
||||
| 10 | 时间线子句和时间函数用于超级表查询 | 增强 |没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
|
||||
## SQL 语句变更
|
||||
|
||||
|
|
|
@ -177,12 +177,21 @@ taos --dump-config
|
|||
### maxNumOfDistinctRes
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- | --- |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 仅服务端适用 |
|
||||
| 含义 | 允许返回的 distinct 结果最大行数 |
|
||||
| 取值范围 | 默认值为 10 万,最大值 1 亿 |
|
||||
| 缺省值 | 10 万 |
|
||||
|
||||
### keepColumnName
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 仅客户端适用 |
|
||||
| 含义 | Last、First、LastRow 函数查询时,返回的列名是否包含函数名。 |
|
||||
| 取值范围 | 0 表示包含函数名,1 表示不包含函数名。 |
|
||||
| 缺省值 | 0 |
|
||||
|
||||
## 区域相关
|
||||
|
||||
### timezone
|
||||
|
@ -325,7 +334,7 @@ charset 的有效值是 UTF-8。
|
|||
| 适用范围 | 仅服务端适用 |
|
||||
| 含义 | dnode 支持的最大 vnode 数目 |
|
||||
| 取值范围 | 0-4096 |
|
||||
| 缺省值 | 256 |
|
||||
| 缺省值 | CPU 核数的 2 倍 |
|
||||
|
||||
## 时间相关
|
||||
|
||||
|
@ -668,153 +677,154 @@ charset 的有效值是 UTF-8。
|
|||
| 15 | telemetryPort | 否 | 是 |
|
||||
| 16 | queryPolicy | 否 | 是 |
|
||||
| 17 | querySmaOptimize | 否 | 是 |
|
||||
| 18 | queryBufferSize | 是 | 是 |
|
||||
| 19 | maxNumOfDistinctRes | 是 | 是 |
|
||||
| 20 | minSlidingTime | 是 | 是 |
|
||||
| 21 | minIntervalTime | 是 | 是 |
|
||||
| 22 | countAlwaysReturnValue | 是 | 是 |
|
||||
| 23 | dataDir | 是 | 是 |
|
||||
| 24 | minimalDataDirGB | 是 | 是 |
|
||||
| 25 | supportVnodes | 否 | 是 |
|
||||
| 26 | tempDir | 是 | 是 |
|
||||
| 27 | minimalTmpDirGB | 是 | 是 |
|
||||
| 28 | compressMsgSize | 是 | 是 |
|
||||
| 29 | compressColData | 是 | 是 |
|
||||
| 30 | smlChildTableName | 是 | 是 |
|
||||
| 31 | smlTagName | 是 | 是 |
|
||||
| 32 | smlDataFormat | 否 | 是 |
|
||||
| 33 | statusInterval | 是 | 是 |
|
||||
| 34 | shellActivityTimer | 是 | 是 |
|
||||
| 35 | transPullupInterval | 否 | 是 |
|
||||
| 36 | mqRebalanceInterval | 否 | 是 |
|
||||
| 37 | ttlUnit | 否 | 是 |
|
||||
| 38 | ttlPushInterval | 否 | 是 |
|
||||
| 39 | numOfTaskQueueThreads | 否 | 是 |
|
||||
| 40 | numOfRpcThreads | 否 | 是 |
|
||||
| 41 | numOfCommitThreads | 是 | 是 |
|
||||
| 42 | numOfMnodeReadThreads | 否 | 是 |
|
||||
| 43 | numOfVnodeQueryThreads | 否 | 是 |
|
||||
| 44 | numOfVnodeStreamThreads | 否 | 是 |
|
||||
| 45 | numOfVnodeFetchThreads | 否 | 是 |
|
||||
| 46 | numOfVnodeWriteThreads | 否 | 是 |
|
||||
| 47 | numOfVnodeSyncThreads | 否 | 是 |
|
||||
| 48 | numOfVnodeRsmaThreads | 否 | 是 |
|
||||
| 49 | numOfQnodeQueryThreads | 否 | 是 |
|
||||
| 50 | numOfQnodeFetchThreads | 否 | 是 |
|
||||
| 51 | numOfSnodeSharedThreads | 否 | 是 |
|
||||
| 52 | numOfSnodeUniqueThreads | 否 | 是 |
|
||||
| 53 | rpcQueueMemoryAllowed | 否 | 是 |
|
||||
| 54 | logDir | 是 | 是 |
|
||||
| 55 | minimalLogDirGB | 是 | 是 |
|
||||
| 56 | numOfLogLines | 是 | 是 |
|
||||
| 57 | asyncLog | 是 | 是 |
|
||||
| 58 | logKeepDays | 是 | 是 |
|
||||
| 59 | debugFlag | 是 | 是 |
|
||||
| 60 | tmrDebugFlag | 是 | 是 |
|
||||
| 61 | uDebugFlag | 是 | 是 |
|
||||
| 62 | rpcDebugFlag | 是 | 是 |
|
||||
| 63 | jniDebugFlag | 是 | 是 |
|
||||
| 64 | qDebugFlag | 是 | 是 |
|
||||
| 65 | cDebugFlag | 是 | 是 |
|
||||
| 66 | dDebugFlag | 是 | 是 |
|
||||
| 67 | vDebugFlag | 是 | 是 |
|
||||
| 68 | mDebugFlag | 是 | 是 |
|
||||
| 69 | wDebugFlag | 是 | 是 |
|
||||
| 70 | sDebugFlag | 是 | 是 |
|
||||
| 71 | tsdbDebugFlag | 是 | 是 |
|
||||
| 72 | tqDebugFlag | 否 | 是 |
|
||||
| 73 | fsDebugFlag | 是 | 是 |
|
||||
| 74 | udfDebugFlag | 否 | 是 |
|
||||
| 75 | smaDebugFlag | 否 | 是 |
|
||||
| 76 | idxDebugFlag | 否 | 是 |
|
||||
| 77 | tdbDebugFlag | 否 | 是 |
|
||||
| 78 | metaDebugFlag | 否 | 是 |
|
||||
| 79 | timezone | 是 | 是 |
|
||||
| 80 | locale | 是 | 是 |
|
||||
| 81 | charset | 是 | 是 |
|
||||
| 82 | udf | 是 | 是 |
|
||||
| 83 | enableCoreFile | 是 | 是 |
|
||||
| 84 | arbitrator | 是 | 否 |
|
||||
| 85 | numOfThreadsPerCore | 是 | 否 |
|
||||
| 86 | numOfMnodes | 是 | 否 |
|
||||
| 87 | vnodeBak | 是 | 否 |
|
||||
| 88 | balance | 是 | 否 |
|
||||
| 89 | balanceInterval | 是 | 否 |
|
||||
| 90 | offlineThreshold | 是 | 否 |
|
||||
| 91 | role | 是 | 否 |
|
||||
| 92 | dnodeNopLoop | 是 | 否 |
|
||||
| 93 | keepTimeOffset | 是 | 否 |
|
||||
| 94 | rpcTimer | 是 | 否 |
|
||||
| 95 | rpcMaxTime | 是 | 否 |
|
||||
| 96 | rpcForceTcp | 是 | 否 |
|
||||
| 97 | tcpConnTimeout | 是 | 否 |
|
||||
| 98 | syncCheckInterval | 是 | 否 |
|
||||
| 99 | maxTmrCtrl | 是 | 否 |
|
||||
| 100 | monitorReplica | 是 | 否 |
|
||||
| 101 | smlTagNullName | 是 | 否 |
|
||||
| 102 | keepColumnName | 是 | 否 |
|
||||
| 103 | ratioOfQueryCores | 是 | 否 |
|
||||
| 104 | maxStreamCompDelay | 是 | 否 |
|
||||
| 105 | maxFirstStreamCompDelay | 是 | 否 |
|
||||
| 106 | retryStreamCompDelay | 是 | 否 |
|
||||
| 107 | streamCompDelayRatio | 是 | 否 |
|
||||
| 108 | maxVgroupsPerDb | 是 | 否 |
|
||||
| 109 | maxTablesPerVnode | 是 | 否 |
|
||||
| 110 | minTablesPerVnode | 是 | 否 |
|
||||
| 111 | tableIncStepPerVnode | 是 | 否 |
|
||||
| 112 | cache | 是 | 否 |
|
||||
| 113 | blocks | 是 | 否 |
|
||||
| 114 | days | 是 | 否 |
|
||||
| 115 | keep | 是 | 否 |
|
||||
| 116 | minRows | 是 | 否 |
|
||||
| 117 | maxRows | 是 | 否 |
|
||||
| 118 | quorum | 是 | 否 |
|
||||
| 119 | comp | 是 | 否 |
|
||||
| 120 | walLevel | 是 | 否 |
|
||||
| 121 | fsync | 是 | 否 |
|
||||
| 122 | replica | 是 | 否 |
|
||||
| 123 | partitions | 是 | 否 |
|
||||
| 124 | quorum | 是 | 否 |
|
||||
| 125 | update | 是 | 否 |
|
||||
| 126 | cachelast | 是 | 否 |
|
||||
| 127 | maxSQLLength | 是 | 否 |
|
||||
| 128 | maxWildCardsLength | 是 | 否 |
|
||||
| 129 | maxRegexStringLen | 是 | 否 |
|
||||
| 130 | maxNumOfOrderedRes | 是 | 否 |
|
||||
| 131 | maxConnections | 是 | 否 |
|
||||
| 132 | mnodeEqualVnodeNum | 是 | 否 |
|
||||
| 133 | http | 是 | 否 |
|
||||
| 134 | httpEnableRecordSql | 是 | 否 |
|
||||
| 135 | httpMaxThreads | 是 | 否 |
|
||||
| 136 | restfulRowLimit | 是 | 否 |
|
||||
| 137 | httpDbNameMandatory | 是 | 否 |
|
||||
| 138 | httpKeepAlive | 是 | 否 |
|
||||
| 139 | enableRecordSql | 是 | 否 |
|
||||
| 140 | maxBinaryDisplayWidth | 是 | 否 |
|
||||
| 141 | stream | 是 | 否 |
|
||||
| 142 | retrieveBlockingModel | 是 | 否 |
|
||||
| 143 | tsdbMetaCompactRatio | 是 | 否 |
|
||||
| 144 | defaultJSONStrType | 是 | 否 |
|
||||
| 145 | walFlushSize | 是 | 否 |
|
||||
| 146 | keepTimeOffset | 是 | 否 |
|
||||
| 147 | flowctrl | 是 | 否 |
|
||||
| 148 | slaveQuery | 是 | 否 |
|
||||
| 149 | adjustMaster | 是 | 否 |
|
||||
| 150 | topicBinaryLen | 是 | 否 |
|
||||
| 151 | telegrafUseFieldNum | 是 | 否 |
|
||||
| 152 | deadLockKillQuery | 是 | 否 |
|
||||
| 153 | clientMerge | 是 | 否 |
|
||||
| 154 | sdbDebugFlag | 是 | 否 |
|
||||
| 155 | odbcDebugFlag | 是 | 否 |
|
||||
| 156 | httpDebugFlag | 是 | 否 |
|
||||
| 157 | monDebugFlag | 是 | 否 |
|
||||
| 158 | cqDebugFlag | 是 | 否 |
|
||||
| 159 | shortcutFlag | 是 | 否 |
|
||||
| 160 | probeSeconds | 是 | 否 |
|
||||
| 161 | probeKillSeconds | 是 | 否 |
|
||||
| 162 | probeInterval | 是 | 否 |
|
||||
| 163 | lossyColumns | 是 | 否 |
|
||||
| 164 | fPrecision | 是 | 否 |
|
||||
| 165 | dPrecision | 是 | 否 |
|
||||
| 166 | maxRange | 是 | 否 |
|
||||
| 167 | range | 是 | 否 |
|
||||
| 18 | queryRsmaTolerance | 否 | 是 |
|
||||
| 19 | queryBufferSize | 是 | 是 |
|
||||
| 20 | maxNumOfDistinctRes | 是 | 是 |
|
||||
| 21 | minSlidingTime | 是 | 是 |
|
||||
| 22 | minIntervalTime | 是 | 是 |
|
||||
| 23 | countAlwaysReturnValue | 是 | 是 |
|
||||
| 24 | dataDir | 是 | 是 |
|
||||
| 25 | minimalDataDirGB | 是 | 是 |
|
||||
| 26 | supportVnodes | 否 | 是 |
|
||||
| 27 | tempDir | 是 | 是 |
|
||||
| 28 | minimalTmpDirGB | 是 | 是 |
|
||||
| 29 | compressMsgSize | 是 | 是 |
|
||||
| 30 | compressColData | 是 | 是 |
|
||||
| 31 | smlChildTableName | 是 | 是 |
|
||||
| 32 | smlTagName | 是 | 是 |
|
||||
| 33 | smlDataFormat | 否 | 是 |
|
||||
| 34 | statusInterval | 是 | 是 |
|
||||
| 35 | shellActivityTimer | 是 | 是 |
|
||||
| 36 | transPullupInterval | 否 | 是 |
|
||||
| 37 | mqRebalanceInterval | 否 | 是 |
|
||||
| 38 | ttlUnit | 否 | 是 |
|
||||
| 39 | ttlPushInterval | 否 | 是 |
|
||||
| 40 | numOfTaskQueueThreads | 否 | 是 |
|
||||
| 41 | numOfRpcThreads | 否 | 是 |
|
||||
| 42 | numOfCommitThreads | 是 | 是 |
|
||||
| 43 | numOfMnodeReadThreads | 否 | 是 |
|
||||
| 44 | numOfVnodeQueryThreads | 否 | 是 |
|
||||
| 45 | numOfVnodeStreamThreads | 否 | 是 |
|
||||
| 46 | numOfVnodeFetchThreads | 否 | 是 |
|
||||
| 47 | numOfVnodeWriteThreads | 否 | 是 |
|
||||
| 48 | numOfVnodeSyncThreads | 否 | 是 |
|
||||
| 49 | numOfVnodeRsmaThreads | 否 | 是 |
|
||||
| 50 | numOfQnodeQueryThreads | 否 | 是 |
|
||||
| 51 | numOfQnodeFetchThreads | 否 | 是 |
|
||||
| 52 | numOfSnodeSharedThreads | 否 | 是 |
|
||||
| 53 | numOfSnodeUniqueThreads | 否 | 是 |
|
||||
| 54 | rpcQueueMemoryAllowed | 否 | 是 |
|
||||
| 55 | logDir | 是 | 是 |
|
||||
| 56 | minimalLogDirGB | 是 | 是 |
|
||||
| 57 | numOfLogLines | 是 | 是 |
|
||||
| 58 | asyncLog | 是 | 是 |
|
||||
| 59 | logKeepDays | 是 | 是 |
|
||||
| 60 | debugFlag | 是 | 是 |
|
||||
| 61 | tmrDebugFlag | 是 | 是 |
|
||||
| 62 | uDebugFlag | 是 | 是 |
|
||||
| 63 | rpcDebugFlag | 是 | 是 |
|
||||
| 64 | jniDebugFlag | 是 | 是 |
|
||||
| 65 | qDebugFlag | 是 | 是 |
|
||||
| 66 | cDebugFlag | 是 | 是 |
|
||||
| 67 | dDebugFlag | 是 | 是 |
|
||||
| 68 | vDebugFlag | 是 | 是 |
|
||||
| 69 | mDebugFlag | 是 | 是 |
|
||||
| 70 | wDebugFlag | 是 | 是 |
|
||||
| 71 | sDebugFlag | 是 | 是 |
|
||||
| 72 | tsdbDebugFlag | 是 | 是 |
|
||||
| 73 | tqDebugFlag | 否 | 是 |
|
||||
| 74 | fsDebugFlag | 是 | 是 |
|
||||
| 75 | udfDebugFlag | 否 | 是 |
|
||||
| 76 | smaDebugFlag | 否 | 是 |
|
||||
| 77 | idxDebugFlag | 否 | 是 |
|
||||
| 78 | tdbDebugFlag | 否 | 是 |
|
||||
| 79 | metaDebugFlag | 否 | 是 |
|
||||
| 80 | timezone | 是 | 是 |
|
||||
| 81 | locale | 是 | 是 |
|
||||
| 82 | charset | 是 | 是 |
|
||||
| 83 | udf | 是 | 是 |
|
||||
| 84 | enableCoreFile | 是 | 是 |
|
||||
| 85 | arbitrator | 是 | 否 |
|
||||
| 86 | numOfThreadsPerCore | 是 | 否 |
|
||||
| 87 | numOfMnodes | 是 | 否 |
|
||||
| 88 | vnodeBak | 是 | 否 |
|
||||
| 89 | balance | 是 | 否 |
|
||||
| 90 | balanceInterval | 是 | 否 |
|
||||
| 91 | offlineThreshold | 是 | 否 |
|
||||
| 92 | role | 是 | 否 |
|
||||
| 93 | dnodeNopLoop | 是 | 否 |
|
||||
| 94 | keepTimeOffset | 是 | 否 |
|
||||
| 95 | rpcTimer | 是 | 否 |
|
||||
| 96 | rpcMaxTime | 是 | 否 |
|
||||
| 97 | rpcForceTcp | 是 | 否 |
|
||||
| 98 | tcpConnTimeout | 是 | 否 |
|
||||
| 99 | syncCheckInterval | 是 | 否 |
|
||||
| 100 | maxTmrCtrl | 是 | 否 |
|
||||
| 101 | monitorReplica | 是 | 否 |
|
||||
| 102 | smlTagNullName | 是 | 否 |
|
||||
| 103 | keepColumnName | 是 | 否 |
|
||||
| 104 | ratioOfQueryCores | 是 | 否 |
|
||||
| 105 | maxStreamCompDelay | 是 | 否 |
|
||||
| 106 | maxFirstStreamCompDelay | 是 | 否 |
|
||||
| 107 | retryStreamCompDelay | 是 | 否 |
|
||||
| 108 | streamCompDelayRatio | 是 | 否 |
|
||||
| 109 | maxVgroupsPerDb | 是 | 否 |
|
||||
| 110 | maxTablesPerVnode | 是 | 否 |
|
||||
| 111 | minTablesPerVnode | 是 | 否 |
|
||||
| 112 | tableIncStepPerVnode | 是 | 否 |
|
||||
| 113 | cache | 是 | 否 |
|
||||
| 114 | blocks | 是 | 否 |
|
||||
| 115 | days | 是 | 否 |
|
||||
| 116 | keep | 是 | 否 |
|
||||
| 117 | minRows | 是 | 否 |
|
||||
| 118 | maxRows | 是 | 否 |
|
||||
| 119 | quorum | 是 | 否 |
|
||||
| 120 | comp | 是 | 否 |
|
||||
| 121 | walLevel | 是 | 否 |
|
||||
| 122 | fsync | 是 | 否 |
|
||||
| 123 | replica | 是 | 否 |
|
||||
| 124 | partitions | 是 | 否 |
|
||||
| 125 | quorum | 是 | 否 |
|
||||
| 126 | update | 是 | 否 |
|
||||
| 127 | cachelast | 是 | 否 |
|
||||
| 128 | maxSQLLength | 是 | 否 |
|
||||
| 129 | maxWildCardsLength | 是 | 否 |
|
||||
| 130 | maxRegexStringLen | 是 | 否 |
|
||||
| 131 | maxNumOfOrderedRes | 是 | 否 |
|
||||
| 132 | maxConnections | 是 | 否 |
|
||||
| 133 | mnodeEqualVnodeNum | 是 | 否 |
|
||||
| 134 | http | 是 | 否 |
|
||||
| 135 | httpEnableRecordSql | 是 | 否 |
|
||||
| 136 | httpMaxThreads | 是 | 否 |
|
||||
| 137 | restfulRowLimit | 是 | 否 |
|
||||
| 138 | httpDbNameMandatory | 是 | 否 |
|
||||
| 139 | httpKeepAlive | 是 | 否 |
|
||||
| 140 | enableRecordSql | 是 | 否 |
|
||||
| 141 | maxBinaryDisplayWidth | 是 | 否 |
|
||||
| 142 | stream | 是 | 否 |
|
||||
| 143 | retrieveBlockingModel | 是 | 否 |
|
||||
| 144 | tsdbMetaCompactRatio | 是 | 否 |
|
||||
| 145 | defaultJSONStrType | 是 | 否 |
|
||||
| 146 | walFlushSize | 是 | 否 |
|
||||
| 147 | keepTimeOffset | 是 | 否 |
|
||||
| 148 | flowctrl | 是 | 否 |
|
||||
| 149 | slaveQuery | 是 | 否 |
|
||||
| 150 | adjustMaster | 是 | 否 |
|
||||
| 151 | topicBinaryLen | 是 | 否 |
|
||||
| 152 | telegrafUseFieldNum | 是 | 否 |
|
||||
| 153 | deadLockKillQuery | 是 | 否 |
|
||||
| 154 | clientMerge | 是 | 否 |
|
||||
| 155 | sdbDebugFlag | 是 | 否 |
|
||||
| 156 | odbcDebugFlag | 是 | 否 |
|
||||
| 157 | httpDebugFlag | 是 | 否 |
|
||||
| 158 | monDebugFlag | 是 | 否 |
|
||||
| 159 | cqDebugFlag | 是 | 否 |
|
||||
| 160 | shortcutFlag | 是 | 否 |
|
||||
| 161 | probeSeconds | 是 | 否 |
|
||||
| 162 | probeKillSeconds | 是 | 否 |
|
||||
| 163 | probeInterval | 是 | 否 |
|
||||
| 164 | lossyColumns | 是 | 否 |
|
||||
| 165 | fPrecision | 是 | 否 |
|
||||
| 166 | dPrecision | 是 | 否 |
|
||||
| 167 | maxRange | 是 | 否 |
|
||||
| 168 | range | 是 | 否 |
|
||||
|
|
|
@ -67,9 +67,12 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c3="passit",c2=false,c4=4f64 1626006833639000000
|
|||
"measurement,tag_key1=tag_value1,tag_key2=tag_value2"
|
||||
```
|
||||
|
||||
:::tip
|
||||
需要注意的是,这里的 tag_key1, tag_key2 并不是用户输入的标签的原始顺序,而是使用了标签名称按照字符串升序排列后的结果。所以,tag_key1 并不是在行协议中输入的第一个标签。
|
||||
排列完成以后计算该字符串的 MD5 散列值 "md5_val"。然后将计算的结果与字符串组合生成表名:“t_md5_val”。其中的 “t_” 是固定的前缀,每个通过该映射关系自动生成的表都具有该前缀。
|
||||
为了让用户可以指定生成的表名,可以通过配置 smlChildTableName 来指定(比如 配置 smlChildTableName=tname 插入数据为 st,tname=cpu1,t1=4 c1=3 1626006833639000000 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一次自动建表时指定的 tag_set,其他的会忽略)。
|
||||
:::tip
|
||||
为了让用户可以指定生成的表名,可以通过在taos.cfg里配置 smlChildTableName 参数来指定。
|
||||
举例如下:配置 smlChildTableName=tname 插入数据为 st,tname=cpu1,t1=4 c1=3 1626006833639000000 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。
|
||||
|
||||
2. 如果解析行协议获得的超级表不存在,则会创建这个超级表(不建议手动创建超级表,不然插入数据可能异常)。
|
||||
3. 如果解析行协议获得子表不存在,则 Schemaless 会按照步骤 1 或 2 确定的子表名来创建子表。
|
||||
|
|
|
@ -6,6 +6,13 @@ description: TDengine 发布历史、Release Notes 及下载链接
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.0.1.3
|
||||
|
||||
<Release type="tdengine" version="3.0.1.3" />
|
||||
|
||||
## 3.0.1.2
|
||||
|
||||
<Release type="tdengine" version="3.0.1.2" />
|
||||
|
||||
## 3.0.1.1
|
||||
|
||||
|
|
|
@ -6,6 +6,14 @@ description: taosTools 的发布历史、Release Notes 和下载链接
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 2.2.3
|
||||
|
||||
<Release type="tools" version="2.2.3" />
|
||||
|
||||
## 2.2.2
|
||||
|
||||
<Release type="tools" version="2.2.2" />
|
||||
|
||||
## 2.2.0
|
||||
|
||||
<Release type="tools" version="2.2.0" />
|
||||
|
|
Binary file not shown.
|
@ -1,6 +1,12 @@
|
|||
# TDengine driver connector for Lua
|
||||
|
||||
It's a Lua implementation for [TDengine](https://github.com/taosdata/TDengine), an open-sourced big data platform designed and optimized for the Internet of Things (IoT), Connected Cars, Industrial IoT, and IT Infrastructure and Application Monitoring. You may need to install Lua5.3 .
|
||||
As TDengine is built with lua-enable with default configure, the built-in lua lib conflicts with external lua lib. The following commands require TDengine built with lua-disable.
|
||||
To disable built-in lua:
|
||||
```
|
||||
mkdir debug && cd debug
|
||||
cmake .. -DBUILD_LUA=false && cmake --build .
|
||||
```
|
||||
|
||||
## Lua Dependencies
|
||||
- Lua:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../../../include/client/taos.h"
|
||||
#include "taos.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
|
@ -29,13 +29,13 @@ static int l_connect(lua_State *L){
|
|||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
|
||||
lua_getfield(L, 1,"host");
|
||||
if (lua_isstring(L,-1)){
|
||||
if (lua_isstring(L, -1)){
|
||||
host = lua_tostring(L, -1);
|
||||
// printf("host = %s\n", host);
|
||||
}
|
||||
|
||||
lua_getfield(L, 1, "port");
|
||||
if (lua_isnumber(L,-1)){
|
||||
if (lua_isnumber(L, -1)){
|
||||
port = lua_tonumber(L, -1);
|
||||
//printf("port = %d\n", port);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ static int l_connect(lua_State *L){
|
|||
//printf("password = %s\n", password);
|
||||
}
|
||||
|
||||
lua_settop(L,0);
|
||||
lua_settop(L, 0);
|
||||
|
||||
taos_init();
|
||||
|
||||
|
@ -102,7 +102,7 @@ static int l_query(lua_State *L){
|
|||
printf("failed, reason:%s\n", taos_errstr(result));
|
||||
lua_pushinteger(L, -1);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L, taos_errstr(taos));
|
||||
lua_pushstring(L, taos_errstr(result));
|
||||
lua_setfield(L, table_index, "error");
|
||||
|
||||
return 1;
|
||||
|
@ -113,7 +113,6 @@ static int l_query(lua_State *L){
|
|||
int rows = 0;
|
||||
int num_fields = taos_field_count(result);
|
||||
const TAOS_FIELD *fields = taos_fetch_fields(result);
|
||||
//char temp[256];
|
||||
|
||||
const int affectRows = taos_affected_rows(result);
|
||||
// printf(" affect rows:%d\r\n", affectRows);
|
||||
|
@ -122,12 +121,12 @@ static int l_query(lua_State *L){
|
|||
lua_pushinteger(L, affectRows);
|
||||
lua_setfield(L, table_index, "affected");
|
||||
lua_newtable(L);
|
||||
|
||||
|
||||
while ((row = taos_fetch_row(result))) {
|
||||
//printf("row index:%d\n",rows);
|
||||
rows++;
|
||||
|
||||
lua_pushnumber(L,rows);
|
||||
lua_pushnumber(L, rows);
|
||||
lua_newtable(L);
|
||||
|
||||
for (int i = 0; i < num_fields; ++i) {
|
||||
|
@ -136,17 +135,21 @@ static int l_query(lua_State *L){
|
|||
}
|
||||
|
||||
lua_pushstring(L,fields[i].name);
|
||||
|
||||
int32_t* length = taos_fetch_lengths(result);
|
||||
switch (fields[i].type) {
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
lua_pushinteger(L,*((short *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
lua_pushinteger(L,*((int *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
break;
|
||||
|
@ -156,9 +159,11 @@ static int l_query(lua_State *L){
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
lua_pushnumber(L,*((double *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
lua_pushstring(L,(char *)row[i]);
|
||||
//printf("type:%d, max len:%d, current len:%d\n",fields[i].type, fields[i].bytes, length[i]);
|
||||
lua_pushlstring(L,(char *)row[i], length[i]);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
|
@ -166,6 +171,7 @@ static int l_query(lua_State *L){
|
|||
case TSDB_DATA_TYPE_BOOL:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
default:
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
|
@ -197,7 +203,7 @@ void async_query_callback(void *param, TAOS_RES *result, int code){
|
|||
printf("failed, reason:%s\n", taos_errstr(result));
|
||||
lua_pushinteger(L, -1);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L,"something is wrong");// taos_errstr(taos));
|
||||
lua_pushstring(L, taos_errstr(result));
|
||||
lua_setfield(L, table_index, "error");
|
||||
}else{
|
||||
//printf("success to async query.\n");
|
||||
|
@ -214,9 +220,9 @@ void async_query_callback(void *param, TAOS_RES *result, int code){
|
|||
|
||||
static int l_async_query(lua_State *L){
|
||||
int r = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
TAOS * taos = (TAOS*)lua_topointer(L,1);
|
||||
const char * sqlstr = lua_tostring(L,2);
|
||||
// int stime = luaL_checknumber(L,3);
|
||||
TAOS * taos = (TAOS*)lua_topointer(L, 1);
|
||||
const char * sqlstr = lua_tostring(L, 2);
|
||||
// int stime = luaL_checknumber(L, 3);
|
||||
|
||||
lua_newtable(L);
|
||||
int table_index = lua_gettop(L);
|
||||
|
@ -224,7 +230,7 @@ static int l_async_query(lua_State *L){
|
|||
struct async_query_callback_param *p = malloc(sizeof(struct async_query_callback_param));
|
||||
p->state = L;
|
||||
p->callback=r;
|
||||
// printf("r:%d, L:%d\n",r,L);
|
||||
// printf("r:%d, L:%d\n", r, L);
|
||||
taos_query_a(taos,sqlstr,async_query_callback,p);
|
||||
|
||||
lua_pushnumber(L, 0);
|
||||
|
@ -235,112 +241,6 @@ static int l_async_query(lua_State *L){
|
|||
return 1;
|
||||
}
|
||||
|
||||
void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){
|
||||
struct cb_param* p = (struct cb_param*) param;
|
||||
TAOS_FIELD *fields = taos_fetch_fields(result);
|
||||
int numFields = taos_num_fields(result);
|
||||
|
||||
// printf("\nnumfields:%d\n", numFields);
|
||||
//printf("\n\r-----------------------------------------------------------------------------------\n");
|
||||
|
||||
lua_State *L = p->state;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, p->callback);
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for (int i = 0; i < numFields; ++i) {
|
||||
if (row[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lua_pushstring(L,fields[i].name);
|
||||
|
||||
switch (fields[i].type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
lua_pushinteger(L,*((short *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
lua_pushinteger(L,*((int *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
lua_pushnumber(L,*((float *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
lua_pushnumber(L,*((double *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
lua_pushstring(L,(char *)row[i]);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
default:
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
}
|
||||
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
||||
lua_call(L, 1, 0);
|
||||
|
||||
// printf("-----------------------------------------------------------------------------------\n\r");
|
||||
}
|
||||
|
||||
static int l_open_stream(lua_State *L){
|
||||
int r = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
TAOS * taos = (TAOS*)lua_topointer(L,1);
|
||||
const char * sqlstr = lua_tostring(L,2);
|
||||
int stime = luaL_checknumber(L,3);
|
||||
|
||||
lua_newtable(L);
|
||||
int table_index = lua_gettop(L);
|
||||
|
||||
struct cb_param *p = malloc(sizeof(struct cb_param));
|
||||
p->state = L;
|
||||
p->callback=r;
|
||||
// printf("r:%d, L:%d\n",r,L);
|
||||
void * s = taos_open_stream(taos,sqlstr,stream_cb,stime,p,NULL);
|
||||
if (s == NULL) {
|
||||
printf("failed to open stream, reason:%s\n", taos_errstr(taos));
|
||||
free(p);
|
||||
lua_pushnumber(L, -1);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L, taos_errstr(taos));
|
||||
lua_setfield(L, table_index, "error");
|
||||
lua_pushlightuserdata(L,NULL);
|
||||
lua_setfield(L, table_index, "stream");
|
||||
}else{
|
||||
// printf("success to open stream\n");
|
||||
lua_pushnumber(L, 0);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L, taos_errstr(taos));
|
||||
lua_setfield(L, table_index, "error");
|
||||
p->stream = s;
|
||||
lua_pushlightuserdata(L,p);
|
||||
lua_setfield(L, table_index, "stream");//stream has different content in lua and c.
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_close_stream(lua_State *L){
|
||||
//TODO:get stream and free cb_param
|
||||
struct cb_param *p = lua_touserdata(L,1);
|
||||
taos_close_stream(p->stream);
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_close(lua_State *L){
|
||||
TAOS *taos= (TAOS*)lua_topointer(L,1);
|
||||
|
@ -367,15 +267,13 @@ static const struct luaL_Reg lib[] = {
|
|||
{"query", l_query},
|
||||
{"query_a",l_async_query},
|
||||
{"close", l_close},
|
||||
{"open_stream", l_open_stream},
|
||||
{"close_stream", l_close_stream},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
extern int luaopen_luaconnector51(lua_State* L)
|
||||
{
|
||||
// luaL_register(L, "luaconnector51", lib);
|
||||
lua_newtable (L);
|
||||
lua_newtable(L);
|
||||
luaL_setfuncs(L,lib,0);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include "taos.h"
|
||||
#include <taos.h>
|
||||
|
||||
struct cb_param{
|
||||
lua_State* state;
|
||||
|
@ -29,7 +29,7 @@ static int l_connect(lua_State *L){
|
|||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
|
||||
lua_getfield(L, 1,"host");
|
||||
if (lua_isstring(L,-1)){
|
||||
if (lua_isstring(L, -1)){
|
||||
host = lua_tostring(L, -1);
|
||||
// printf("host = %s\n", host);
|
||||
}
|
||||
|
@ -58,8 +58,10 @@ static int l_connect(lua_State *L){
|
|||
//printf("password = %s\n", password);
|
||||
}
|
||||
|
||||
lua_settop(L,0);
|
||||
lua_settop(L, 0);
|
||||
|
||||
taos_init();
|
||||
|
||||
lua_newtable(L);
|
||||
int table_index = lua_gettop(L);
|
||||
|
||||
|
@ -124,7 +126,7 @@ static int l_query(lua_State *L){
|
|||
//printf("row index:%d\n",rows);
|
||||
rows++;
|
||||
|
||||
lua_pushnumber(L,rows);
|
||||
lua_pushnumber(L, rows);
|
||||
lua_newtable(L);
|
||||
|
||||
for (int i = 0; i < num_fields; ++i) {
|
||||
|
@ -201,7 +203,7 @@ void async_query_callback(void *param, TAOS_RES *result, int code){
|
|||
printf("failed, reason:%s\n", taos_errstr(result));
|
||||
lua_pushinteger(L, -1);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L,"something is wrong");// taos_errstr(taos));
|
||||
lua_pushstring(L, taos_errstr(result));
|
||||
lua_setfield(L, table_index, "error");
|
||||
}else{
|
||||
//printf("success to async query.\n");
|
||||
|
@ -218,9 +220,9 @@ void async_query_callback(void *param, TAOS_RES *result, int code){
|
|||
|
||||
static int l_async_query(lua_State *L){
|
||||
int r = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
TAOS * taos = (TAOS*)lua_topointer(L,1);
|
||||
const char * sqlstr = lua_tostring(L,2);
|
||||
// int stime = luaL_checknumber(L,3);
|
||||
TAOS * taos = (TAOS*)lua_topointer(L, 1);
|
||||
const char * sqlstr = lua_tostring(L, 2);
|
||||
// int stime = luaL_checknumber(L, 3);
|
||||
|
||||
lua_newtable(L);
|
||||
int table_index = lua_gettop(L);
|
||||
|
@ -228,7 +230,7 @@ static int l_async_query(lua_State *L){
|
|||
struct async_query_callback_param *p = malloc(sizeof(struct async_query_callback_param));
|
||||
p->state = L;
|
||||
p->callback=r;
|
||||
// printf("r:%d, L:%d\n",r,L);
|
||||
// printf("r:%d, L:%d\n", r, L);
|
||||
taos_query_a(taos,sqlstr,async_query_callback,p);
|
||||
|
||||
lua_pushnumber(L, 0);
|
||||
|
|
|
@ -9,6 +9,50 @@ local config = {
|
|||
max_packet_size = 1024 * 1024
|
||||
}
|
||||
|
||||
function dump(obj)
|
||||
local getIndent, quoteStr, wrapKey, wrapVal, dumpObj
|
||||
getIndent = function(level)
|
||||
return string.rep("\t", level)
|
||||
end
|
||||
quoteStr = function(str)
|
||||
return '"' .. string.gsub(str, '"', '\\"') .. '"'
|
||||
end
|
||||
wrapKey = function(val)
|
||||
if type(val) == "number" then
|
||||
return "[" .. val .. "]"
|
||||
elseif type(val) == "string" then
|
||||
return "[" .. quoteStr(val) .. "]"
|
||||
else
|
||||
return "[" .. tostring(val) .. "]"
|
||||
end
|
||||
end
|
||||
wrapVal = function(val, level)
|
||||
if type(val) == "table" then
|
||||
return dumpObj(val, level)
|
||||
elseif type(val) == "number" then
|
||||
return val
|
||||
elseif type(val) == "string" then
|
||||
return quoteStr(val)
|
||||
else
|
||||
return tostring(val)
|
||||
end
|
||||
end
|
||||
dumpObj = function(obj, level)
|
||||
if type(obj) ~= "table" then
|
||||
return wrapVal(obj)
|
||||
end
|
||||
level = level + 1
|
||||
local tokens = {}
|
||||
tokens[#tokens + 1] = "{"
|
||||
for k, v in pairs(obj) do
|
||||
tokens[#tokens + 1] = getIndent(level) .. wrapKey(k) .. " = " .. wrapVal(v, level) .. ","
|
||||
end
|
||||
tokens[#tokens + 1] = getIndent(level - 1) .. "}"
|
||||
return table.concat(tokens, "\n")
|
||||
end
|
||||
return dumpObj(obj, 0)
|
||||
end
|
||||
|
||||
local conn
|
||||
local res = driver.connect(config)
|
||||
if res.code ~=0 then
|
||||
|
@ -37,7 +81,7 @@ else
|
|||
print("select db--- pass.")
|
||||
end
|
||||
|
||||
res = driver.query(conn,"create table m1 (ts timestamp, speed int,owner binary(20))")
|
||||
res = driver.query(conn,"create table m1 (ts timestamp, speed int, owner binary(20), mark nchar(30))")
|
||||
if res.code ~=0 then
|
||||
print("create table---failed: "..res.error)
|
||||
return
|
||||
|
@ -45,7 +89,7 @@ else
|
|||
print("create table--- pass.")
|
||||
end
|
||||
|
||||
res = driver.query(conn,"insert into m1 values ('2019-09-01 00:00:00.001',0,'robotspace'), ('2019-09-01 00:00:00.002',1,'Hilink'),('2019-09-01 00:00:00.003',2,'Harmony')")
|
||||
res = driver.query(conn,"insert into m1 values ('2019-09-01 00:00:00.001', 0, 'robotspace', '世界人民大团结万岁'), ('2019-09-01 00:00:00.002', 1, 'Hilink', '⾾⾿⿀⿁⿂⿃⿄⿅⿆⿇⿈⿉⿊⿋⿌⿍⿎⿏⿐⿑⿒⿓⿔⿕'),('2019-09-01 00:00:00.003', 2, 'Harmony', '₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵')")
|
||||
if res.code ~=0 then
|
||||
print("insert records failed: "..res.error)
|
||||
return
|
||||
|
@ -64,21 +108,25 @@ if res.code ~=0 then
|
|||
return
|
||||
else
|
||||
if (#(res.item) == 3) then
|
||||
print("select--- pass")
|
||||
print("select--- pass")
|
||||
print(res.item[1].mark)
|
||||
print(res.item[2].mark)
|
||||
print(res.item[3].mark)
|
||||
|
||||
else
|
||||
print("select--- failed: expect 3 affected records, actually received "..#(res.item))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
res = driver.query(conn,"CREATE TABLE thermometer (ts timestamp, degree double) TAGS(location binary(20), type int)")
|
||||
res = driver.query(conn,"create table thermometer (ts timestamp, degree double) tags(location binary(20), type int)")
|
||||
if res.code ~=0 then
|
||||
print(res.error)
|
||||
return
|
||||
else
|
||||
print("create super table--- pass")
|
||||
end
|
||||
res = driver.query(conn,"CREATE TABLE therm1 USING thermometer TAGS ('beijing', 1)")
|
||||
res = driver.query(conn,"create table therm1 using thermometer tags ('beijing', 1)")
|
||||
if res.code ~=0 then
|
||||
print(res.error)
|
||||
return
|
||||
|
@ -86,7 +134,7 @@ else
|
|||
print("create table--- pass")
|
||||
end
|
||||
|
||||
res = driver.query(conn,"INSERT INTO therm1 VALUES ('2019-09-01 00:00:00.001', 20),('2019-09-01 00:00:00.002', 21)")
|
||||
res = driver.query(conn,"insert into therm1 values ('2019-09-01 00:00:00.001', 20),('2019-09-01 00:00:00.002', 21)")
|
||||
|
||||
if res.code ~=0 then
|
||||
print(res.error)
|
||||
|
@ -99,14 +147,14 @@ else
|
|||
end
|
||||
end
|
||||
|
||||
res = driver.query(conn,"SELECT COUNT(*) count, AVG(degree) AS av, MAX(degree), MIN(degree) FROM thermometer WHERE location='beijing' or location='tianjin' GROUP BY location, type")
|
||||
res = driver.query(conn,"select count(*) as cnt, avg(degree) as av, max(degree), min(degree) from thermometer where location='beijing' or location='tianjin' group by location, type")
|
||||
if res.code ~=0 then
|
||||
print("select from super table--- failed:"..res.error)
|
||||
return
|
||||
else
|
||||
print("select from super table--- pass")
|
||||
for i = 1, #(res.item) do
|
||||
print("res:"..res.item[i].count)
|
||||
print("res:"..res.item[i].cnt)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -127,30 +175,19 @@ end
|
|||
|
||||
driver.query_a(conn,"INSERT INTO therm1 VALUES ('2019-09-01 00:00:00.005', 100),('2019-09-01 00:00:00.006', 101),('2019-09-01 00:00:00.007', 102)", async_query_callback)
|
||||
|
||||
|
||||
function stream_callback(t)
|
||||
print("------------------------")
|
||||
print("continuous query result:")
|
||||
for key, value in pairs(t) do
|
||||
print("key:"..key..", value:"..value)
|
||||
end
|
||||
end
|
||||
|
||||
local stream
|
||||
res = driver.open_stream(conn,"SELECT COUNT(*) as count, AVG(degree) as avg, MAX(degree) as max, MIN(degree) as min FROM thermometer interval(2s) sliding(2s);)",0, stream_callback)
|
||||
res = driver.query(conn, "create stream stream_avg_degree into avg_degree as select avg(degree) from thermometer interval(5s) sliding(1s)")
|
||||
if res.code ~=0 then
|
||||
print("open stream--- failed:"..res.error)
|
||||
print("create stream--- failed:"..res.error)
|
||||
return
|
||||
else
|
||||
print("open stream--- pass")
|
||||
stream = res.stream
|
||||
print("create stream--- pass")
|
||||
end
|
||||
|
||||
print("From now on we start continous insert in an definite (infinite if you want) loop.")
|
||||
print("From now on we start continous insertion in an definite loop, please wait for about 10 seconds and check stream table avg_degree for result.")
|
||||
local loop_index = 0
|
||||
while loop_index < 30 do
|
||||
while loop_index < 10 do
|
||||
local t = os.time()*1000
|
||||
local v = loop_index
|
||||
local v = math.random(20)
|
||||
res = driver.query(conn,string.format("INSERT INTO therm1 VALUES (%d, %d)",t,v))
|
||||
|
||||
if res.code ~=0 then
|
||||
|
@ -162,7 +199,5 @@ while loop_index < 30 do
|
|||
os.execute("sleep " .. 1)
|
||||
loop_index = loop_index + 1
|
||||
end
|
||||
|
||||
driver.close_stream(stream)
|
||||
|
||||
driver.query(conn,"DROP STREAM IF EXISTS stream_avg_degree")
|
||||
driver.close(conn)
|
||||
|
|
|
@ -254,7 +254,7 @@ enum tmq_res_t {
|
|||
TMQ_RES_INVALID = -1,
|
||||
TMQ_RES_DATA = 1,
|
||||
TMQ_RES_TABLE_META = 2,
|
||||
TMQ_RES_TAOSX = 3,
|
||||
TMQ_RES_METADATA = 3,
|
||||
};
|
||||
|
||||
typedef struct tmq_raw_data {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue