diff --git a/README.md b/README.md
index a8126d74d4..1034a19f37 100644
--- a/README.md
+++ b/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:
diff --git a/cmake/cmake.version b/cmake/cmake.version
index d5721f7671..fcb31adc39 100644
--- a/cmake/cmake.version
+++ b/cmake/cmake.version
@@ -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.2")
ENDIF ()
IF (DEFINED VERCOMPATIBLE)
diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in
index 5cc580a9c6..52e2c0944a 100644
--- a/cmake/taostools_CMakeLists.txt.in
+++ b/cmake/taostools_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taos-tools
ExternalProject_Add(taos-tools
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
- GIT_TAG 509ec72
+ GIT_TAG 8207c74
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/cmake/taosws_CMakeLists.txt.in b/cmake/taosws_CMakeLists.txt.in
index 04b1262caf..ca8fff8da5 100644
--- a/cmake/taosws_CMakeLists.txt.in
+++ b/cmake/taosws_CMakeLists.txt.in
@@ -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
diff --git a/docs/en/12-taos-sql/01-data-type.md b/docs/en/12-taos-sql/01-data-type.md
index 876de50f35..60046629a4 100644
--- a/docs/en/12-taos-sql/01-data-type.md
+++ b/docs/en/12-taos-sql/01-data-type.md
@@ -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.
diff --git a/docs/en/12-taos-sql/06-select.md b/docs/en/12-taos-sql/06-select.md
index 118a248373..786444ad77 100644
--- a/docs/en/12-taos-sql/06-select.md
+++ b/docs/en/12-taos-sql/06-select.md
@@ -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.
diff --git a/docs/examples/csharp/.gitignore b/docs/examples/csharp/.gitignore
index b3aff79f37..694da603b9 100644
--- a/docs/examples/csharp/.gitignore
+++ b/docs/examples/csharp/.gitignore
@@ -1,4 +1,12 @@
bin
obj
.vs
-*.sln
\ No newline at end of file
+*.sln
+wsConnect/obj
+wsInsert/obj
+wsQuery/obj
+wsStmt/obj
+wsConnect/bin
+wsInsert/bin
+wsQuery/bin
+wsStmt/bin
\ No newline at end of file
diff --git a/docs/examples/csharp/wsConnect/Program.cs b/docs/examples/csharp/wsConnect/Program.cs
new file mode 100644
index 0000000000..2e89372c3e
--- /dev/null
+++ b/docs/examples/csharp/wsConnect/Program.cs
@@ -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);
+ }
+ }
+}
\ No newline at end of file
diff --git a/docs/examples/csharp/wsConnect/wsConnect.csproj b/docs/examples/csharp/wsConnect/wsConnect.csproj
new file mode 100644
index 0000000000..34951dc761
--- /dev/null
+++ b/docs/examples/csharp/wsConnect/wsConnect.csproj
@@ -0,0 +1,13 @@
+
+
+
+ Exe
+ net5.0
+ enable
+
+
+
+
+
+
+
diff --git a/docs/examples/csharp/wsInsert/Program.cs b/docs/examples/csharp/wsInsert/Program.cs
new file mode 100644
index 0000000000..4ff830b437
--- /dev/null
+++ b/docs/examples/csharp/wsInsert/Program.cs
@@ -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
\ No newline at end of file
diff --git a/docs/examples/csharp/wsInsert/wsInsert.csproj b/docs/examples/csharp/wsInsert/wsInsert.csproj
new file mode 100644
index 0000000000..34951dc761
--- /dev/null
+++ b/docs/examples/csharp/wsInsert/wsInsert.csproj
@@ -0,0 +1,13 @@
+
+
+
+ Exe
+ net5.0
+ enable
+
+
+
+
+
+
+
diff --git a/docs/examples/csharp/wsQuery/Program.cs b/docs/examples/csharp/wsQuery/Program.cs
new file mode 100644
index 0000000000..bf3cf2bbe2
--- /dev/null
+++ b/docs/examples/csharp/wsQuery/Program.cs
@@ -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 metas = LibTaosWS.WSGetFields(wsRes);
+ // get retrieved data
+ List 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 |
\ No newline at end of file
diff --git a/docs/examples/csharp/wsQuery/wsQuery.csproj b/docs/examples/csharp/wsQuery/wsQuery.csproj
new file mode 100644
index 0000000000..34951dc761
--- /dev/null
+++ b/docs/examples/csharp/wsQuery/wsQuery.csproj
@@ -0,0 +1,13 @@
+
+
+
+ Exe
+ net5.0
+ enable
+
+
+
+
+
+
+
diff --git a/docs/examples/csharp/wsStmt/Program.cs b/docs/examples/csharp/wsStmt/Program.cs
new file mode 100644
index 0000000000..54de77ec1f
--- /dev/null
+++ b/docs/examples/csharp/wsStmt/Program.cs
@@ -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...
\ No newline at end of file
diff --git a/docs/examples/csharp/wsStmt/wsStmt.csproj b/docs/examples/csharp/wsStmt/wsStmt.csproj
new file mode 100644
index 0000000000..34951dc761
--- /dev/null
+++ b/docs/examples/csharp/wsStmt/wsStmt.csproj
@@ -0,0 +1,13 @@
+
+
+
+ Exe
+ net5.0
+ enable
+
+
+
+
+
+
+
diff --git a/docs/zh/07-develop/01-connect/_connect_cs.mdx b/docs/zh/07-develop/01-connect/_connect_cs.mdx
index 13b8a5dff2..9d0755fc64 100644
--- a/docs/zh/07-develop/01-connect/_connect_cs.mdx
+++ b/docs/zh/07-develop/01-connect/_connect_cs.mdx
@@ -2,7 +2,7 @@
{{#include docs/examples/csharp/ConnectExample.cs}}
```
-:::info
-C# 连接器目前只支持原生连接。
+```csharp title="WebSocket 连接"
+{{#include docs/examples/csharp/wsConnect/Program.cs}}
+```
-:::
diff --git a/docs/zh/08-connector/40-csharp.mdx b/docs/zh/08-connector/40-csharp.mdx
index 4e49d84835..9ba8be2c22 100644
--- a/docs/zh/08-connector/40-csharp.mdx
+++ b/docs/zh/08-connector/40-csharp.mdx
@@ -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"
## 支持的功能特性
+
+
+
+
1. 连接管理
2. 普通查询
3. 连续查询
4. 参数绑定
-5. 订阅功能
+5. 数据订阅(TMQ)
6. Schemaless
+
+
+
+
+
+1. 连接管理
+2. 普通查询
+3. 连续查询
+4. 参数绑定
+
+
+
+
## 安装步骤
@@ -79,7 +96,13 @@ dotnet add exmaple.csproj reference src/TDengine.csproj
## 建立连接
-``` C#
+
+
+
+
+使用 host、username、password、port 等信息建立连接。
+
+``` csharp
using TDengineDriver;
namespace TDengineExample
@@ -109,17 +132,63 @@ namespace TDengineExample
}
}
}
-
```
+
+
+
+
+使用 DSN 建立 WebSocket 连接 DSN 连接。 描述字符串基本结构如下:
+
+```text
+[]://[[:@]:][/][?=[&=]]
+|------------|---|-----------|-----------|------|------|------------|-----------------------|
+| 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}}
+```
+
+
+
+
## 使用示例
### 写入数据
#### SQL 写入
+
+
+
+
+
+
+
+
+```csharp
+{{#include docs/examples/csharp/wsInsert/Program.cs}}
+```
+
+
+
+
+
#### InfluxDB 行协议写入
@@ -132,12 +201,50 @@ namespace TDengineExample
+#### 参数绑定
+
+
+
+
+
+``` csharp
+{{#include docs/examples/csharp/StmtInsertExample.cs}}
+```
+
+
+
+
+
+```csharp
+{{#include docs/examples/csharp/wsStmt/Program.cs}}
+```
+
+
+
+
+
### 查询数据
#### 同步查询
+
+
+
+
+
+
+
+
+```csharp
+{{#include docs/examples/csharp/wsQuery/Program.cs}}
+```
+
+
+
+
+
#### 异步查询
@@ -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。 |
diff --git a/docs/zh/12-taos-sql/01-data-type.md b/docs/zh/12-taos-sql/01-data-type.md
index ee7b3a4715..128fa20930 100644
--- a/docs/zh/12-taos-sql/01-data-type.md
+++ b/docs/zh/12-taos-sql/01-data-type.md
@@ -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 会被认为是有效的浮点数。
:::
diff --git a/docs/zh/12-taos-sql/06-select.md b/docs/zh/12-taos-sql/06-select.md
index c49351b0c9..394e4a99d5 100644
--- a/docs/zh/12-taos-sql/06-select.md
+++ b/docs/zh/12-taos-sql/06-select.md
@@ -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` 可以视为超级表中一个特殊的标签,代表子表的表名。
diff --git a/docs/zh/12-taos-sql/10-function.md b/docs/zh/12-taos-sql/10-function.md
index 86e9aaa80f..9726406b4d 100644
--- a/docs/zh/12-taos-sql/10-function.md
+++ b/docs/zh/12-taos-sql/10-function.md
@@ -1233,7 +1233,7 @@ SELECT SERVER_VERSION();
### SERVER_STATUS
```sql
-SELECT SERVER_VERSION();
+SELECT SERVER_STATUS();
```
**说明**:返回服务端当前的状态。
diff --git a/include/client/taos.h b/include/client/taos.h
index 49cfbb52b8..270b647a77 100644
--- a/include/client/taos.h
+++ b/include/client/taos.h
@@ -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 {
diff --git a/include/common/tcommon.h b/include/common/tcommon.h
index ba4baa0130..2544cedda7 100644
--- a/include/common/tcommon.h
+++ b/include/common/tcommon.h
@@ -116,6 +116,7 @@ enum {
STREAM_INPUT__DATA_RETRIEVE,
STREAM_INPUT__GET_RES,
STREAM_INPUT__CHECKPOINT,
+ STREAM_INPUT__REF_DATA_BLOCK,
STREAM_INPUT__DESTROY,
};
diff --git a/include/common/tglobal.h b/include/common/tglobal.h
index 234937ea7e..33c4daac4b 100644
--- a/include/common/tglobal.h
+++ b/include/common/tglobal.h
@@ -122,6 +122,7 @@ extern SDiskCfg tsDiskCfg[];
// udf
extern bool tsStartUdfd;
+extern char tsUdfdResFuncs[];
// schemaless
extern char tsSmlChildTableName[];
diff --git a/include/libs/stream/streamState.h b/include/libs/stream/streamState.h
index 80fa7a7218..849d83a58b 100644
--- a/include/libs/stream/streamState.h
+++ b/include/libs/stream/streamState.h
@@ -34,7 +34,7 @@ typedef struct {
TXN txn;
} SStreamState;
-SStreamState* streamStateOpen(char* path, SStreamTask* pTask);
+SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath);
void streamStateClose(SStreamState* pState);
int32_t streamStateBegin(SStreamState* pState);
int32_t streamStateCommit(SStreamState* pState);
diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h
index 554d66d621..bdc12f7e3f 100644
--- a/include/libs/stream/tstream.h
+++ b/include/libs/stream/tstream.h
@@ -125,6 +125,14 @@ typedef struct {
SArray* blocks; // SArray
} SStreamDataBlock;
+// ref data block, for delete
+typedef struct {
+ int8_t type;
+ int64_t ver;
+ int32_t* dataRef;
+ SSDataBlock* pBlock;
+} SStreamRefDataBlock;
+
typedef struct {
int8_t type;
} SStreamCheckpoint;
@@ -339,7 +347,8 @@ static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem
qDebug("task %d %p submit enqueue %p %p %p", pTask->taskId, pTask, pItem, pSubmitClone, pSubmitClone->data);
taosWriteQitem(pTask->inputQueue->queue, pSubmitClone);
// qStreamInput(pTask->exec.executor, pSubmitClone);
- } else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
+ } else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE ||
+ pItem->type == STREAM_INPUT__REF_DATA_BLOCK) {
taosWriteQitem(pTask->inputQueue->queue, pItem);
// qStreamInput(pTask->exec.executor, pItem);
} else if (pItem->type == STREAM_INPUT__CHECKPOINT) {
@@ -492,7 +501,9 @@ typedef struct {
int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq);
int32_t tDecodeStreamRetrieveReq(SDecoder* pDecoder, SStreamRetrieveReq* pReq);
-void tFreeStreamDispatchReq(SStreamDispatchReq* pReq);
+void tDeleteStreamRetrieveReq(SStreamRetrieveReq* pReq);
+
+void tDeleteStreamDispatchReq(SStreamDispatchReq* pReq);
int32_t streamSetupTrigger(SStreamTask* pTask);
diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h
index e6a4dd1d49..285e079b3e 100644
--- a/include/libs/sync/sync.h
+++ b/include/libs/sync/sync.h
@@ -22,6 +22,7 @@ extern "C" {
#include "cJSON.h"
#include "tdef.h"
+#include "tlrucache.h"
#include "tmsgcb.h"
extern bool gRaftDetailLog;
@@ -153,7 +154,8 @@ typedef struct SSyncFSM {
// abstract definition of log store in raft
// SWal implements it
typedef struct SSyncLogStore {
- void* data;
+ SLRUCache* pCache;
+ void* data;
// append one log entry
int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index 01d42d6950..840e7309fe 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -619,6 +619,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_RSMA_EMPTY_INFO TAOS_DEF_ERROR_CODE(0, 0x3156)
#define TSDB_CODE_RSMA_INVALID_SCHEMA TAOS_DEF_ERROR_CODE(0, 0x3157)
#define TSDB_CODE_RSMA_REGEX_MATCH TAOS_DEF_ERROR_CODE(0, 0x3158)
+#define TSDB_CODE_RSMA_STREAM_STATE_OPEN TAOS_DEF_ERROR_CODE(0, 0x3159)
+#define TSDB_CODE_RSMA_STREAM_STATE_COMMIT TAOS_DEF_ERROR_CODE(0, 0x3160)
//index
#define TSDB_CODE_INDEX_REBUILDING TAOS_DEF_ERROR_CODE(0, 0x3200)
diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h
index 7a9c665556..44503c6638 100644
--- a/source/client/inc/clientInt.h
+++ b/source/client/inc/clientInt.h
@@ -52,7 +52,7 @@ enum {
RES_TYPE__QUERY = 1,
RES_TYPE__TMQ,
RES_TYPE__TMQ_META,
- RES_TYPE__TAOSX,
+ RES_TYPE__TMQ_METADATA,
};
#define SHOW_VARIABLES_RESULT_COLS 2
@@ -60,9 +60,9 @@ enum {
#define SHOW_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE)
#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY)
-#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ || *(int8_t*)res == RES_TYPE__TAOSX)
+#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ)
#define TD_RES_TMQ_META(res) (*(int8_t*)res == RES_TYPE__TMQ_META)
-#define TD_RES_TMQ_TAOSX(res) (*(int8_t*)res == RES_TYPE__TAOSX)
+#define TD_RES_TMQ_METADATA(res) (*(int8_t*)res == RES_TYPE__TMQ_METADATA)
typedef struct SAppInstInfo SAppInstInfo;
diff --git a/source/client/src/TMQConnector.c b/source/client/src/TMQConnector.c
index fcf6957df9..26bf55055f 100644
--- a/source/client/src/TMQConnector.c
+++ b/source/client/src/TMQConnector.c
@@ -212,7 +212,7 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAsync(JN
tmq_commit_async(tmq, res, commit_cb, consumer);
}
-JNIEXPORT int JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqUnsubscribeImp(JNIEnv *env, jobject jobj, jlong jtmq) {
+JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqUnsubscribeImp(JNIEnv *env, jobject jobj, jlong jtmq) {
tmq_t *tmq = (tmq_t *)jtmq;
if (tmq == NULL) {
jniError("jobj:%p, tmq is closed", jobj);
@@ -222,7 +222,7 @@ JNIEXPORT int JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqUnsubscribeImp(
return tmq_unsubscribe((tmq_t *)tmq);
}
-JNIEXPORT int JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqConsumerCloseImp(JNIEnv *env, jobject jobj,
+JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqConsumerCloseImp(JNIEnv *env, jobject jobj,
jlong jtmq) {
tmq_t *tmq = (tmq_t *)jtmq;
if (tmq == NULL) {
diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c
index 7ce80553a0..75ccd44977 100644
--- a/source/client/src/clientHb.c
+++ b/source/client/src/clientHb.c
@@ -878,12 +878,18 @@ int hbMgrInit() {
clientHbMgr.appHbMgrs = taosArrayInit(0, sizeof(void *));
TdThreadMutexAttr attr = {0};
- taosThreadMutexAttrSetType(&attr, PTHREAD_MUTEX_RECURSIVE);
+
int ret = taosThreadMutexAttrInit(&attr);
assert(ret == 0);
- taosThreadMutexInit(&clientHbMgr.lock, &attr);
- taosThreadMutexAttrDestroy(&attr);
+ ret = taosThreadMutexAttrSetType(&attr, PTHREAD_MUTEX_RECURSIVE);
+ assert(ret == 0);
+
+ ret = taosThreadMutexInit(&clientHbMgr.lock, &attr);
+ assert(ret == 0);
+
+ ret = taosThreadMutexAttrDestroy(&attr);
+ assert(ret == 0);
// init handle funcs
hbMgrInitHandle();
diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c
index dd650e1dff..0f193ba379 100644
--- a/source/client/src/clientImpl.c
+++ b/source/client/src/clientImpl.c
@@ -189,6 +189,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
tscError("%d failed to add to request container, reqId:0x%" PRIx64 ", conn:%d, %s", (*pRequest)->self,
(*pRequest)->requestId, pTscObj->id, sql);
+ taosMemoryFree(param);
destroyRequest(*pRequest);
*pRequest = NULL;
return TSDB_CODE_TSC_OUT_OF_MEMORY;
diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c
index 77bd71c756..a03b6cd5a5 100644
--- a/source/client/src/clientMain.c
+++ b/source/client/src/clientMain.c
@@ -148,7 +148,7 @@ int taos_errno(TAOS_RES *res) {
return terrno;
}
- if (TD_RES_TMQ(res)) {
+ if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
return 0;
}
@@ -162,7 +162,7 @@ const char *taos_errstr(TAOS_RES *res) {
return (const char *)tstrerror(terrno);
}
- if (TD_RES_TMQ(res)) {
+ if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
return "success";
}
@@ -184,7 +184,7 @@ void taos_free_result(TAOS_RES *res) {
SRequestObj *pRequest = (SRequestObj *)res;
tscDebug("0x%" PRIx64 " taos_free_result start to free query", pRequest->requestId);
destroyRequest(pRequest);
- } else if (TD_RES_TMQ_TAOSX(res)) {
+ } else if (TD_RES_TMQ_METADATA(res)) {
SMqTaosxRspObj *pRsp = (SMqTaosxRspObj *)res;
if (pRsp->rsp.blockData) taosArrayDestroyP(pRsp->rsp.blockData, taosMemoryFree);
if (pRsp->rsp.blockDataLen) taosArrayDestroy(pRsp->rsp.blockDataLen);
@@ -264,7 +264,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
return doFetchRows(pRequest, true, true);
#endif
- } else if (TD_RES_TMQ(res)) {
+ } else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
SMqRspObj *msg = ((SMqRspObj *)res);
SReqResultInfo *pResultInfo;
if (msg->resIter == -1) {
@@ -437,7 +437,7 @@ const char *taos_data_type(int type) {
const char *taos_get_client_info() { return version; }
int taos_affected_rows(TAOS_RES *res) {
- if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res)) {
+ if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res)) {
return 0;
}
@@ -454,7 +454,7 @@ int taos_result_precision(TAOS_RES *res) {
if (TD_RES_QUERY(res)) {
SRequestObj *pRequest = (SRequestObj *)res;
return pRequest->body.resInfo.precision;
- } else if (TD_RES_TMQ(res)) {
+ } else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
SReqResultInfo *info = tmqGetCurResInfo(res);
return info->precision;
}
@@ -487,7 +487,7 @@ int taos_select_db(TAOS *taos, const char *db) {
}
void taos_stop_query(TAOS_RES *res) {
- if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res)) {
+ if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res)) {
return;
}
@@ -559,7 +559,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
(*rows) = pResultInfo->row;
(*numOfRows) = pResultInfo->numOfRows;
return pRequest->code;
- } else if (TD_RES_TMQ(res)) {
+ } else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res, true);
if (pResultInfo == NULL) return -1;
@@ -578,7 +578,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
return 0;
}
- if (TD_RES_TMQ(res)) {
+ if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res, false);
if (pResultInfo == NULL) {
(*numOfRows) = 0;
diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c
index c135965f07..eb7b45cc05 100644
--- a/source/client/src/clientRawBlockWrite.c
+++ b/source/client/src/clientRawBlockWrite.c
@@ -30,7 +30,7 @@ static char* buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* sch
char* string = NULL;
cJSON* json = cJSON_CreateObject();
if (json == NULL) {
- return string;
+ return NULL;
}
cJSON* type = cJSON_CreateString("create");
cJSON_AddItemToObject(json, "type", type);
@@ -39,10 +39,10 @@ static char* buildCreateTableJson(SSchemaWrapper* schemaRow, SSchemaWrapper* sch
// sprintf(uid, "%"PRIi64, id);
// cJSON* id_ = cJSON_CreateString(uid);
// cJSON_AddItemToObject(json, "id", id_);
- cJSON* tableName = cJSON_CreateString(name);
- cJSON_AddItemToObject(json, "tableName", tableName);
cJSON* tableType = cJSON_CreateString(t == TSDB_NORMAL_TABLE ? "normal" : "super");
cJSON_AddItemToObject(json, "tableType", tableType);
+ cJSON* tableName = cJSON_CreateString(name);
+ cJSON_AddItemToObject(json, "tableName", tableName);
// cJSON* version = cJSON_CreateNumber(1);
// cJSON_AddItemToObject(json, "version", version);
@@ -112,10 +112,10 @@ static char* buildAlterSTableJson(void* alterData, int32_t alterDataLen) {
// cJSON_AddItemToObject(json, "uid", uid);
SName name = {0};
tNameFromString(&name, req.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
- cJSON* tableName = cJSON_CreateString(name.tname);
- cJSON_AddItemToObject(json, "tableName", tableName);
cJSON* tableType = cJSON_CreateString("super");
cJSON_AddItemToObject(json, "tableType", tableType);
+ cJSON* tableName = cJSON_CreateString(name.tname);
+ cJSON_AddItemToObject(json, "tableName", tableName);
cJSON* alterType = cJSON_CreateNumber(req.alterType);
cJSON_AddItemToObject(json, "alterType", alterType);
@@ -199,8 +199,6 @@ static char* processCreateStb(SMqMetaRsp* metaRsp) {
goto _err;
}
string = buildCreateTableJson(&req.schemaRow, &req.schemaTag, req.name, req.suid, TSDB_SUPER_TABLE);
- tDecoderClear(&coder);
- return string;
_err:
tDecoderClear(&coder);
@@ -221,32 +219,22 @@ static char* processAlterStb(SMqMetaRsp* metaRsp) {
goto _err;
}
string = buildAlterSTableJson(req.alterOriData, req.alterOriDataLen);
- tDecoderClear(&coder);
- return string;
_err:
tDecoderClear(&coder);
return string;
}
-static char* buildCreateCTableJson(STag* pTag, char* sname, char* name, SArray* tagName, int64_t id, uint8_t tagNum) {
- char* string = NULL;
- SArray* pTagVals = NULL;
- cJSON* json = cJSON_CreateObject();
- if (json == NULL) {
- return string;
- }
- cJSON* type = cJSON_CreateString("create");
- cJSON_AddItemToObject(json, "type", type);
- // char cid[32] = {0};
- // sprintf(cid, "%"PRIi64, id);
- // cJSON* cid_ = cJSON_CreateString(cid);
- // cJSON_AddItemToObject(json, "id", cid_);
+static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq){
+ STag* pTag = (STag*)pCreateReq->ctb.pTag;
+ char* sname = pCreateReq->ctb.name;
+ char* name = pCreateReq->name;
+ SArray* tagName = pCreateReq->ctb.tagName;
+ int64_t id = pCreateReq->uid;
+ uint8_t tagNum = pCreateReq->ctb.tagNum;
cJSON* tableName = cJSON_CreateString(name);
cJSON_AddItemToObject(json, "tableName", tableName);
- cJSON* tableType = cJSON_CreateString("child");
- cJSON_AddItemToObject(json, "tableType", tableType);
cJSON* using = cJSON_CreateString(sname);
cJSON_AddItemToObject(json, "using", using);
cJSON* tagNumJson = cJSON_CreateNumber(tagNum);
@@ -255,6 +243,7 @@ static char* buildCreateCTableJson(STag* pTag, char* sname, char* name, SArray*
// cJSON_AddItemToObject(json, "version", version);
cJSON* tags = cJSON_CreateArray();
+ SArray* pTagVals = NULL;
int32_t code = tTagToValArray(pTag, &pTagVals);
if (code) {
goto end;
@@ -313,11 +302,37 @@ static char* buildCreateCTableJson(STag* pTag, char* sname, char* name, SArray*
cJSON_AddItemToArray(tags, tag);
}
-end:
+ end:
cJSON_AddItemToObject(json, "tags", tags);
+ taosArrayDestroy(pTagVals);
+}
+
+static char* buildCreateCTableJson(SVCreateTbReq* pCreateReq, int32_t nReqs) {
+ char* string = NULL;
+ cJSON* json = cJSON_CreateObject();
+ if (json == NULL) {
+ return NULL;
+ }
+ cJSON* type = cJSON_CreateString("create");
+ cJSON_AddItemToObject(json, "type", type);
+ // char cid[32] = {0};
+ // sprintf(cid, "%"PRIi64, id);
+ // cJSON* cid_ = cJSON_CreateString(cid);
+ // cJSON_AddItemToObject(json, "id", cid_);
+
+ cJSON* tableType = cJSON_CreateString("child");
+ cJSON_AddItemToObject(json, "tableType", tableType);
+
+ buildChildElement(json, pCreateReq);
+ cJSON* createList = cJSON_CreateArray();
+ for(int i = 0; nReqs > 1 && i < nReqs; i++){
+ cJSON* create = cJSON_CreateObject();
+ buildChildElement(create, pCreateReq + i);
+ cJSON_AddItemToArray(createList, create);
+ }
+ cJSON_AddItemToObject(json, "createList", createList);
string = cJSON_PrintUnformatted(json);
cJSON_Delete(json);
- taosArrayDestroy(pTagVals);
return string;
}
@@ -335,21 +350,58 @@ static char* processCreateTable(SMqMetaRsp* metaRsp) {
}
// loop to create table
- for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
- pCreateReq = req.pReqs + iReq;
+ if (req.nReqs > 0) {
+ pCreateReq = req.pReqs;
if (pCreateReq->type == TSDB_CHILD_TABLE) {
- string = buildCreateCTableJson((STag*)pCreateReq->ctb.pTag, pCreateReq->ctb.name, pCreateReq->name,
- pCreateReq->ctb.tagName, pCreateReq->uid, pCreateReq->ctb.tagNum);
+ string = buildCreateCTableJson(req.pReqs, req.nReqs);
} else if (pCreateReq->type == TSDB_NORMAL_TABLE) {
- string =
- buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE);
+ string = buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE);
}
}
+_exit:
+ for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
+ pCreateReq = req.pReqs + iReq;
+ taosMemoryFreeClear(pCreateReq->comment);
+ if (pCreateReq->type == TSDB_CHILD_TABLE) {
+ taosArrayDestroy(pCreateReq->ctb.tagName);
+ }
+ }
tDecoderClear(&decoder);
+ return string;
+}
+
+static char* processAutoCreateTable(STaosxRsp* rsp) {
+ ASSERT(rsp->createTableNum != 0);
+
+ SDecoder* decoder = taosMemoryCalloc(rsp->createTableNum, sizeof(SDecoder));
+ SVCreateTbReq* pCreateReq = taosMemoryCalloc(rsp->createTableNum, sizeof(SVCreateTbReq));
+ char* string = NULL;
+
+ // loop to create table
+ for (int32_t iReq = 0; iReq < rsp->createTableNum; iReq++) {
+ // decode
+ void** data = taosArrayGet(rsp->createTableReq, iReq);
+ int32_t *len = taosArrayGet(rsp->createTableLen, iReq);
+ tDecoderInit(&decoder[iReq], *data, *len);
+ if (tDecodeSVCreateTbReq(&decoder[iReq], pCreateReq + iReq) < 0) {
+ goto _exit;
+ }
+
+ ASSERT(pCreateReq[iReq].type == TSDB_CHILD_TABLE);
+ }
+ string = buildCreateCTableJson(pCreateReq, rsp->createTableNum);
_exit:
- tDecoderClear(&decoder);
+ for(int i = 0; i < rsp->createTableNum; i++){
+ tDecoderClear(&decoder[i]);
+ taosMemoryFreeClear(pCreateReq[i].comment);
+ if (pCreateReq[i].type == TSDB_CHILD_TABLE) {
+ taosArrayDestroy(pCreateReq[i].ctb.tagName);
+ }
+ }
+ taosMemoryFree(decoder);
+ taosMemoryFree(pCreateReq);
return string;
}
@@ -374,10 +426,10 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) {
cJSON_AddItemToObject(json, "type", type);
// cJSON* uid = cJSON_CreateNumber(id);
// cJSON_AddItemToObject(json, "uid", uid);
- cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName);
- cJSON_AddItemToObject(json, "tableName", tableName);
cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL ? "child" : "normal");
cJSON_AddItemToObject(json, "tableType", tableType);
+ cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName);
+ cJSON_AddItemToObject(json, "tableName", tableName);
cJSON* alterType = cJSON_CreateNumber(vAlterTbReq.action);
cJSON_AddItemToObject(json, "alterType", alterType);
@@ -462,6 +514,7 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) {
string = cJSON_PrintUnformatted(json);
_exit:
+ cJSON_Delete(json);
tDecoderClear(&decoder);
return string;
}
@@ -485,14 +538,15 @@ static char* processDropSTable(SMqMetaRsp* metaRsp) {
}
cJSON* type = cJSON_CreateString("drop");
cJSON_AddItemToObject(json, "type", type);
- cJSON* tableName = cJSON_CreateString(req.name);
- cJSON_AddItemToObject(json, "tableName", tableName);
cJSON* tableType = cJSON_CreateString("super");
cJSON_AddItemToObject(json, "tableType", tableType);
+ cJSON* tableName = cJSON_CreateString(req.name);
+ cJSON_AddItemToObject(json, "tableName", tableName);
string = cJSON_PrintUnformatted(json);
_exit:
+ cJSON_Delete(json);
tDecoderClear(&decoder);
return string;
}
@@ -533,6 +587,7 @@ static char* processDropTable(SMqMetaRsp* metaRsp) {
string = cJSON_PrintUnformatted(json);
_exit:
+ cJSON_Delete(json);
tDecoderClear(&decoder);
return string;
}
@@ -549,6 +604,7 @@ static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) {
goto end;
}
+ pRequest->syncQuery = true;
if (!pRequest->pDb) {
code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
goto end;
@@ -637,6 +693,7 @@ static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) {
goto end;
}
+ pRequest->syncQuery = true;
if (!pRequest->pDb) {
code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
goto end;
@@ -717,6 +774,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
goto end;
}
+ pRequest->syncQuery = true;
if (!pRequest->pDb) {
code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
goto end;
@@ -830,6 +888,14 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
code = pRequest->code;
end:
+ for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
+ pCreateReq = req.pReqs + iReq;
+ taosMemoryFreeClear(pCreateReq->comment);
+ if (pCreateReq->type == TSDB_CHILD_TABLE) {
+ taosArrayDestroy(pCreateReq->ctb.tagName);
+ }
+ }
+
taosHashCleanup(pVgroupHashmap);
destroyRequest(pRequest);
tDecoderClear(&coder);
@@ -860,7 +926,7 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
if (code != TSDB_CODE_SUCCESS) {
goto end;
}
-
+ pRequest->syncQuery = true;
if (!pRequest->pDb) {
code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
goto end;
@@ -1033,6 +1099,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
goto end;
}
+ pRequest->syncQuery = true;
if (!pRequest->pDb) {
code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
goto end;
@@ -1152,6 +1219,7 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
goto end;
}
+ pRequest->syncQuery = true;
if (!pRequest->pDb) {
uError("WriteRaw:not use db");
code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
@@ -1339,6 +1407,7 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
return terrno;
}
+ pRequest->syncQuery = true;
rspObj.resIter = -1;
rspObj.resType = RES_TYPE__TMQ;
@@ -1529,6 +1598,8 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
subReq->length += sizeof(SSubmitBlk) + schemaLen + totalLen;
subReq->numOfBlocks++;
taosMemoryFreeClear(pTableMeta);
+ rspObj.resInfo.pRspMsg = NULL;
+ doFreeReqResultInfo(&rspObj.resInfo);
}
pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
@@ -1578,6 +1649,313 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
code = pRequest->code;
end:
+ tDeleteSMqDataRsp(&rspObj.rsp);
+ rspObj.resInfo.pRspMsg = NULL;
+ doFreeReqResultInfo(&rspObj.resInfo);
+ tDecoderClear(&decoder);
+ qDestroyQuery(pQuery);
+ destroyRequest(pRequest);
+ taosHashCleanup(pVgHash);
+ taosMemoryFreeClear(pTableMeta);
+ return code;
+}
+
+static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen) {
+ int32_t code = TSDB_CODE_SUCCESS;
+ SHashObj* pVgHash = NULL;
+ SQuery* pQuery = NULL;
+ SMqTaosxRspObj rspObj = {0};
+ SDecoder decoder = {0};
+ STableMeta* pTableMeta = NULL;
+
+ terrno = TSDB_CODE_SUCCESS;
+ SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT);
+ if (!pRequest) {
+ uError("WriteRaw:createRequest error request is null");
+ return terrno;
+ }
+
+ pRequest->syncQuery = true;
+ rspObj.resIter = -1;
+ rspObj.resType = RES_TYPE__TMQ_METADATA;
+
+ tDecoderInit(&decoder, data, dataLen);
+ code = tDecodeSTaosxRsp(&decoder, &rspObj.rsp);
+ if (code != 0) {
+ uError("WriteRaw:decode smqDataRsp error");
+ code = TSDB_CODE_INVALID_MSG;
+ goto end;
+ }
+
+ if (!pRequest->pDb) {
+ uError("WriteRaw:not use db");
+ code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
+ goto end;
+ }
+
+ pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
+ taosHashSetFreeFp(pVgHash, destroyVgHash);
+ struct SCatalog* pCatalog = NULL;
+ code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
+ if (code != TSDB_CODE_SUCCESS) {
+ uError("WriteRaw: get gatlog error");
+ goto end;
+ }
+
+ SRequestConnInfo conn = {0};
+ conn.pTrans = pRequest->pTscObj->pAppInfo->pTransporter;
+ conn.requestId = pRequest->requestId;
+ conn.requestObjRefId = pRequest->self;
+ conn.mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
+
+ printf("raw data block num:%d\n", rspObj.rsp.blockNum);
+ while (++rspObj.resIter < rspObj.rsp.blockNum) {
+ SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(rspObj.rsp.blockData, rspObj.resIter);
+ if (!rspObj.rsp.withSchema) {
+ uError("WriteRaw:no schema, iter:%d", rspObj.resIter);
+ goto end;
+ }
+ SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(rspObj.rsp.blockSchema, rspObj.resIter);
+ setResSchemaInfo(&rspObj.resInfo, pSW->pSchema, pSW->nCols);
+
+ code = setQueryResultFromRsp(&rspObj.resInfo, pRetrieve, false, false);
+ if (code != TSDB_CODE_SUCCESS) {
+ uError("WriteRaw: setQueryResultFromRsp error");
+ goto end;
+ }
+
+ const char* tbName = (const char*)taosArrayGetP(rspObj.rsp.blockTbName, rspObj.resIter);
+ if (!tbName) {
+ uError("WriteRaw: tbname is null");
+ code = TSDB_CODE_TMQ_INVALID_MSG;
+ goto end;
+ }
+
+ printf("raw data tbname:%s\n", tbName);
+ SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
+ strcpy(pName.dbname, pRequest->pDb);
+ strcpy(pName.tname, tbName);
+
+ VgData vgData = {0};
+ code = catalogGetTableHashVgroup(pCatalog, &conn, &pName, &(vgData.vg));
+ if (code != TSDB_CODE_SUCCESS) {
+ uError("WriteRaw:catalogGetTableHashVgroup failed. table name: %s", tbName);
+ goto end;
+ }
+
+ // find schema data info
+ int32_t schemaLen = 0;
+ void* schemaData = NULL;
+ for(int j = 0; j < rspObj.rsp.createTableNum; j++){
+ void** dataTmp = taosArrayGet(rspObj.rsp.createTableReq, j);
+ int32_t* lenTmp = taosArrayGet(rspObj.rsp.createTableLen, j);
+
+ SDecoder decoderTmp = {0};
+ SVCreateTbReq pCreateReq = {0};
+
+ tDecoderInit(&decoderTmp, *dataTmp, *lenTmp);
+ if (tDecodeSVCreateTbReq(&decoderTmp, &pCreateReq) < 0) {
+ tDecoderClear(&decoderTmp);
+ taosMemoryFreeClear(pCreateReq.comment);
+ taosArrayDestroy(pCreateReq.ctb.tagName);
+ goto end;
+ }
+
+ ASSERT (pCreateReq.type == TSDB_CHILD_TABLE);
+ if(strcmp(tbName, pCreateReq.name) == 0){
+ schemaLen = *lenTmp;
+ schemaData = *dataTmp;
+ strcpy(pName.tname, pCreateReq.ctb.name);
+ tDecoderClear(&decoderTmp);
+ taosMemoryFreeClear(pCreateReq.comment);
+ taosArrayDestroy(pCreateReq.ctb.tagName);
+ break;
+ }
+ tDecoderClear(&decoderTmp);
+ taosMemoryFreeClear(pCreateReq.comment);
+ taosArrayDestroy(pCreateReq.ctb.tagName);
+ }
+
+ code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
+ if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
+ uError("WriteRaw:catalogGetTableMeta table not exist. table name: %s", tbName);
+ code = TSDB_CODE_SUCCESS;
+ continue;
+ }
+ if (code != TSDB_CODE_SUCCESS) {
+ uError("WriteRaw:catalogGetTableMeta failed. table name: %s", tbName);
+ goto end;
+ }
+
+ uint16_t fLen = 0;
+ int32_t rowSize = 0;
+ int16_t nVar = 0;
+ for (int i = 0; i < pTableMeta->tableInfo.numOfColumns; i++) {
+ SSchema* schema = &pTableMeta->schema[i];
+ fLen += TYPE_BYTES[schema->type];
+ rowSize += schema->bytes;
+ if (IS_VAR_DATA_TYPE(schema->type)) {
+ nVar++;
+ }
+ }
+
+ int32_t rows = rspObj.resInfo.numOfRows;
+ int32_t extendedRowSize = rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + nVar * sizeof(VarDataOffsetT) +
+ (int32_t)TD_BITMAP_BYTES(pTableMeta->tableInfo.numOfColumns - 1);
+
+ int32_t submitLen = sizeof(SSubmitBlk) + schemaLen + rows * extendedRowSize;
+
+ SSubmitReq* subReq = NULL;
+ SSubmitBlk* blk = NULL;
+ void* hData = taosHashGet(pVgHash, &vgData.vg.vgId, sizeof(vgData.vg.vgId));
+ if (hData) {
+ vgData = *(VgData*)hData;
+
+ int32_t totalLen = ((SSubmitReq*)(vgData.data))->length + submitLen;
+ void* tmp = taosMemoryRealloc(vgData.data, totalLen);
+ if (tmp == NULL) {
+ code = TSDB_CODE_TSC_OUT_OF_MEMORY;
+ goto end;
+ }
+ vgData.data = tmp;
+ ((VgData*)hData)->data = tmp;
+ subReq = (SSubmitReq*)(vgData.data);
+ blk = POINTER_SHIFT(vgData.data, subReq->length);
+ } else {
+ int32_t totalLen = sizeof(SSubmitReq) + submitLen;
+ void* tmp = taosMemoryCalloc(1, totalLen);
+ if (tmp == NULL) {
+ code = TSDB_CODE_TSC_OUT_OF_MEMORY;
+ goto end;
+ }
+ vgData.data = tmp;
+ taosHashPut(pVgHash, (const char*)&vgData.vg.vgId, sizeof(vgData.vg.vgId), (char*)&vgData, sizeof(vgData));
+ subReq = (SSubmitReq*)(vgData.data);
+ subReq->length = sizeof(SSubmitReq);
+ subReq->numOfBlocks = 0;
+
+ blk = POINTER_SHIFT(vgData.data, sizeof(SSubmitReq));
+ }
+
+ // pSW->pSchema should be same as pTableMeta->schema
+ // ASSERT(pSW->nCols == pTableMeta->tableInfo.numOfColumns);
+ uint64_t suid = (TSDB_NORMAL_TABLE == pTableMeta->tableType ? 0 : pTableMeta->suid);
+ uint64_t uid = pTableMeta->uid;
+ int16_t sver = pTableMeta->sversion;
+
+ void* blkSchema = POINTER_SHIFT(blk, sizeof(SSubmitBlk));
+ if(schemaData){
+ memcpy(blkSchema, schemaData, schemaLen);
+ }
+ STSRow* rowData = POINTER_SHIFT(blkSchema, schemaLen);
+
+ SRowBuilder rb = {0};
+ tdSRowInit(&rb, sver);
+ tdSRowSetTpInfo(&rb, pTableMeta->tableInfo.numOfColumns, fLen);
+ int32_t totalLen = 0;
+
+ SHashObj* schemaHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
+ for (int i = 0; i < pSW->nCols; i++) {
+ SSchema* schema = &pSW->pSchema[i];
+ taosHashPut(schemaHash, schema->name, strlen(schema->name), &i, sizeof(int32_t));
+ }
+
+ for (int32_t j = 0; j < rows; j++) {
+ tdSRowResetBuf(&rb, rowData);
+
+ doSetOneRowPtr(&rspObj.resInfo);
+ rspObj.resInfo.current += 1;
+
+ int32_t offset = 0;
+ for (int32_t k = 0; k < pTableMeta->tableInfo.numOfColumns; k++) {
+ const SSchema* pColumn = &pTableMeta->schema[k];
+ int32_t* index = taosHashGet(schemaHash, pColumn->name, strlen(pColumn->name));
+ if (!index) {
+ tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
+ } else {
+ char* colData = rspObj.resInfo.row[*index];
+ if (!colData) {
+ tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, offset, k);
+ } else {
+ if (IS_VAR_DATA_TYPE(pColumn->type)) {
+ colData -= VARSTR_HEADER_SIZE;
+ }
+ tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, colData, true, offset, k);
+ }
+ }
+
+ offset += TYPE_BYTES[pColumn->type];
+ }
+ tdSRowEnd(&rb);
+ int32_t rowLen = TD_ROW_LEN(rowData);
+ rowData = POINTER_SHIFT(rowData, rowLen);
+ totalLen += rowLen;
+ }
+
+ taosHashCleanup(schemaHash);
+ blk->uid = htobe64(uid);
+ blk->suid = htobe64(suid);
+ blk->sversion = htonl(sver);
+ blk->schemaLen = htonl(schemaLen);
+ blk->numOfRows = htonl(rows);
+ blk->dataLen = htonl(totalLen);
+ subReq->length += sizeof(SSubmitBlk) + schemaLen + totalLen;
+ subReq->numOfBlocks++;
+ taosMemoryFreeClear(pTableMeta);
+ rspObj.resInfo.pRspMsg = NULL;
+ doFreeReqResultInfo(&rspObj.resInfo);
+ }
+
+ pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
+ if (NULL == pQuery) {
+ uError("create SQuery error");
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto end;
+ }
+ pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
+ pQuery->haveResultSet = false;
+ pQuery->msgType = TDMT_VND_SUBMIT;
+ pQuery->pRoot = (SNode*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT);
+ if (NULL == pQuery->pRoot) {
+ uError("create pQuery->pRoot error");
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto end;
+ }
+ SVnodeModifOpStmt* nodeStmt = (SVnodeModifOpStmt*)(pQuery->pRoot);
+ nodeStmt->payloadType = PAYLOAD_TYPE_KV;
+
+ int32_t numOfVg = taosHashGetSize(pVgHash);
+ nodeStmt->pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
+
+ VgData* vData = (VgData*)taosHashIterate(pVgHash, NULL);
+ while (vData) {
+ SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
+ if (NULL == dst) {
+ code = TSDB_CODE_TSC_OUT_OF_MEMORY;
+ goto end;
+ }
+ dst->vg = vData->vg;
+ SSubmitReq* subReq = (SSubmitReq*)(vData->data);
+ dst->numOfTables = subReq->numOfBlocks;
+ dst->size = subReq->length;
+ dst->pData = (char*)subReq;
+ vData->data = NULL; // no need free
+ subReq->header.vgId = htonl(dst->vg.vgId);
+ subReq->version = htonl(1);
+ subReq->header.contLen = htonl(subReq->length);
+ subReq->length = htonl(subReq->length);
+ subReq->numOfBlocks = htonl(subReq->numOfBlocks);
+ taosArrayPush(nodeStmt->pDataBlocks, &dst);
+ vData = (VgData*)taosHashIterate(pVgHash, vData);
+ }
+
+ launchQueryImpl(pRequest, pQuery, true, NULL);
+ code = pRequest->code;
+
+ end:
+ tDeleteSTaosxRsp(&rspObj.rsp);
+ rspObj.resInfo.pRspMsg = NULL;
+ doFreeReqResultInfo(&rspObj.resInfo);
tDecoderClear(&decoder);
qDestroyQuery(pQuery);
destroyRequest(pRequest);
@@ -1587,10 +1965,15 @@ end:
}
char* tmq_get_json_meta(TAOS_RES* res) {
- if (!TD_RES_TMQ_META(res)) {
+ if (!TD_RES_TMQ_META(res) && !TD_RES_TMQ_METADATA(res)) {
return NULL;
}
+ if(TD_RES_TMQ_METADATA(res)){
+ SMqTaosxRspObj* pMetaDataRspObj = (SMqTaosxRspObj*)res;
+ return processAutoCreateTable(&pMetaDataRspObj->rsp);
+ }
+
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_CREATE_STB) {
return processCreateStb(&pMetaRspObj->metaRsp);
@@ -1638,6 +2021,25 @@ int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
raw->raw = buf;
raw->raw_len = len;
raw->raw_type = RES_TYPE__TMQ;
+ } else if (TD_RES_TMQ_METADATA(res)) {
+ SMqTaosxRspObj* rspObj = ((SMqTaosxRspObj*)res);
+
+ int32_t len = 0;
+ int32_t code = 0;
+ tEncodeSize(tEncodeSTaosxRsp, &rspObj->rsp, len, code);
+ if (code < 0) {
+ return -1;
+ }
+
+ void* buf = taosMemoryCalloc(1, len);
+ SEncoder encoder = {0};
+ tEncoderInit(&encoder, buf, len);
+ tEncodeSTaosxRsp(&encoder, &rspObj->rsp);
+ tEncoderClear(&encoder);
+
+ raw->raw = buf;
+ raw->raw_len = len;
+ raw->raw_type = RES_TYPE__TMQ_METADATA;
} else {
return TSDB_CODE_TMQ_INVALID_MSG;
}
@@ -1645,7 +2047,7 @@ int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
}
void tmq_free_raw(tmq_raw_data raw) {
- if (raw.raw_type == RES_TYPE__TMQ) {
+ if (raw.raw_type == RES_TYPE__TMQ || raw.raw_type == RES_TYPE__TMQ_METADATA) {
taosMemoryFree(raw.raw);
}
}
@@ -1671,6 +2073,8 @@ int32_t tmq_write_raw(TAOS* taos, tmq_raw_data raw) {
return taosDeleteData(taos, raw.raw, raw.raw_len);
} else if (raw.raw_type == RES_TYPE__TMQ) {
return tmqWriteRawDataImpl(taos, raw.raw, raw.raw_len);
+ } else if (raw.raw_type == RES_TYPE__TMQ_METADATA) {
+ return tmqWriteRawMetaDataImpl(taos, raw.raw, raw.raw_len);
}
return TSDB_CODE_INVALID_PARA;
}
diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c
index fc95bd86dc..c9c02a77e1 100644
--- a/source/client/src/clientTmq.c
+++ b/source/client/src/clientTmq.c
@@ -515,6 +515,10 @@ int32_t tmqCommitMsgImpl(tmq_t* tmq, const TAOS_RES* msg, int8_t async, tmq_comm
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)msg;
topic = pMetaRspObj->topic;
vgId = pMetaRspObj->vgId;
+ } else if(TD_RES_TMQ_METADATA(msg)) {
+ SMqTaosxRspObj* pRspObj = (SMqTaosxRspObj*)msg;
+ topic = pRspObj->topic;
+ vgId = pRspObj->vgId;
} else {
return TSDB_CODE_TMQ_INVALID_MSG;
}
@@ -1471,16 +1475,16 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) {
SMqTaosxRspObj* tmqBuildTaosxRspFromWrapper(SMqPollRspWrapper* pWrapper) {
SMqTaosxRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqTaosxRspObj));
- pRspObj->resType = RES_TYPE__TAOSX;
+ pRspObj->resType = RES_TYPE__TMQ_METADATA;
tstrncpy(pRspObj->topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN);
tstrncpy(pRspObj->db, pWrapper->topicHandle->db, TSDB_DB_FNAME_LEN);
pRspObj->vgId = pWrapper->vgHandle->vgId;
pRspObj->resIter = -1;
- memcpy(&pRspObj->rsp, &pWrapper->dataRsp, sizeof(SMqTaosxRspObj));
+ memcpy(&pRspObj->rsp, &pWrapper->taosxRsp, sizeof(STaosxRsp));
pRspObj->resInfo.totalRows = 0;
pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI;
- if (!pWrapper->dataRsp.withSchema) {
+ if (!pWrapper->taosxRsp.withSchema) {
setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
}
@@ -1654,8 +1658,14 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
rspWrapper = NULL;
continue;
}
+
// build rsp
- SMqRspObj* pRsp = tmqBuildRspFromWrapper(pollRspWrapper);
+ void* pRsp = NULL;
+ if(pollRspWrapper->taosxRsp.createTableNum == 0){
+ pRsp = tmqBuildRspFromWrapper(pollRspWrapper);
+ }else{
+ pRsp = tmqBuildTaosxRspFromWrapper(pollRspWrapper);
+ }
taosFreeQitem(pollRspWrapper);
return pRsp;
} else {
@@ -1775,11 +1785,11 @@ tmq_res_t tmq_get_res_type(TAOS_RES* res) {
} else if (TD_RES_TMQ_META(res)) {
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
if (pMetaRspObj->metaRsp.resMsgType == TDMT_VND_DELETE) {
- return TMQ_RES_TAOSX;
+ return TMQ_RES_DATA;
}
return TMQ_RES_TABLE_META;
- } else if (TD_RES_TMQ_TAOSX(res)) {
- return TMQ_RES_DATA;
+ } else if (TD_RES_TMQ_METADATA(res)) {
+ return TMQ_RES_METADATA;
} else {
return TMQ_RES_INVALID;
}
@@ -1792,6 +1802,9 @@ const char* tmq_get_topic_name(TAOS_RES* res) {
} else if (TD_RES_TMQ_META(res)) {
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
return strchr(pMetaRspObj->topic, '.') + 1;
+ } else if (TD_RES_TMQ_METADATA(res)) {
+ SMqTaosxRspObj* pRspObj = (SMqTaosxRspObj*)res;
+ return strchr(pRspObj->topic, '.') + 1;
} else {
return NULL;
}
@@ -1804,6 +1817,9 @@ const char* tmq_get_db_name(TAOS_RES* res) {
} else if (TD_RES_TMQ_META(res)) {
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
return strchr(pMetaRspObj->db, '.') + 1;
+ } else if (TD_RES_TMQ_METADATA(res)) {
+ SMqTaosxRspObj* pRspObj = (SMqTaosxRspObj*)res;
+ return strchr(pRspObj->db, '.') + 1;
} else {
return NULL;
}
@@ -1816,6 +1832,9 @@ int32_t tmq_get_vgroup_id(TAOS_RES* res) {
} else if (TD_RES_TMQ_META(res)) {
SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res;
return pMetaRspObj->vgId;
+ } else if (TD_RES_TMQ_METADATA(res)) {
+ SMqTaosxRspObj* pRspObj = (SMqTaosxRspObj*)res;
+ return pRspObj->vgId;
} else {
return -1;
}
@@ -1829,7 +1848,14 @@ const char* tmq_get_table_name(TAOS_RES* res) {
return NULL;
}
return (const char*)taosArrayGetP(pRspObj->rsp.blockTbName, pRspObj->resIter);
- }
+ } else if (TD_RES_TMQ_METADATA(res)) {
+ SMqTaosxRspObj* pRspObj = (SMqTaosxRspObj*)res;
+ if (!pRspObj->rsp.withTbName || pRspObj->rsp.blockTbName == NULL || pRspObj->resIter < 0 ||
+ pRspObj->resIter >= pRspObj->rsp.blockNum) {
+ return NULL;
+ }
+ return (const char*)taosArrayGetP(pRspObj->rsp.blockTbName, pRspObj->resIter);
+ }
return NULL;
}
diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c
index 16b8e55cf7..8a8e6a83a5 100644
--- a/source/common/src/tdatablock.c
+++ b/source/common/src/tdatablock.c
@@ -1446,6 +1446,7 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) {
int32_t payloadSize = pageSize - blockDataGetSerialMetaSize(numOfCols);
int32_t rowSize = pBlock->info.rowSize;
int32_t nRows = payloadSize / rowSize;
+ ASSERT(nRows >= 1);
// the true value must be less than the value of nRows
int32_t additional = 0;
diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c
index e119dae743..d080456db8 100644
--- a/source/common/src/tglobal.c
+++ b/source/common/src/tglobal.c
@@ -165,6 +165,7 @@ int32_t tsTtlUnit = 86400;
int32_t tsTtlPushInterval = 86400;
int32_t tsGrantHBInterval = 60;
int32_t tsUptimeInterval = 300; // seconds
+char tsUdfdResFuncs[1024] = ""; // udfd resident funcs that teardown when udfd exits
#ifndef _STORAGE
int32_t taosSetTfsCfg(SConfig *pCfg) {
@@ -425,6 +426,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
if (cfgAddInt32(pCfg, "uptimeInterval", tsUptimeInterval, 1, 100000, 1) != 0) return -1;
if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1;
+ if (cfgAddString(pCfg, "udfdResFuncs", tsUdfdResFuncs, 0) != 0) return -1;
GRANT_CFG_ADD;
return 0;
}
@@ -723,6 +725,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsUptimeInterval = cfgGetItem(pCfg, "uptimeInterval")->i32;
tsStartUdfd = cfgGetItem(pCfg, "udf")->bval;
+ tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs));
if (tsQueryBufferSize >= 0) {
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c
index fffaf214ed..0990815024 100644
--- a/source/common/src/tmsg.c
+++ b/source/common/src/tmsg.c
@@ -6018,12 +6018,18 @@ int32_t tDecodeSTaosxRsp(SDecoder *pDecoder, STaosxRsp *pRsp) {
void tDeleteSTaosxRsp(STaosxRsp *pRsp) {
taosArrayDestroy(pRsp->blockDataLen);
+ pRsp->blockDataLen = NULL;
taosArrayDestroyP(pRsp->blockData, (FDelete)taosMemoryFree);
+ pRsp->blockData = NULL;
taosArrayDestroyP(pRsp->blockSchema, (FDelete)tDeleteSSchemaWrapper);
+ pRsp->blockSchema = NULL;
taosArrayDestroyP(pRsp->blockTbName, (FDelete)taosMemoryFree);
+ pRsp->blockTbName = NULL;
taosArrayDestroy(pRsp->createTableLen);
+ pRsp->createTableLen = NULL;
taosArrayDestroyP(pRsp->createTableReq, (FDelete)taosMemoryFree);
+ pRsp->createTableReq = NULL;
}
int32_t tEncodeSSingleDeleteReq(SEncoder *pEncoder, const SSingleDeleteReq *pReq) {
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index a9723abacc..537c9ca834 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -540,7 +540,7 @@ typedef struct {
} SMqConsumerEp;
SMqConsumerEp* tCloneSMqConsumerEp(const SMqConsumerEp* pEp);
-void tDeleteSMqConsumerEp(SMqConsumerEp* pEp);
+void tDeleteSMqConsumerEp(void* pEp);
int32_t tEncodeSMqConsumerEp(void** buf, const SMqConsumerEp* pEp);
void* tDecodeSMqConsumerEp(const void* buf, SMqConsumerEp* pEp);
diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c
index 4470a6b064..cdfa208665 100644
--- a/source/dnode/mnode/impl/src/mndConsumer.c
+++ b/source/dnode/mnode/impl/src/mndConsumer.c
@@ -197,11 +197,12 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
SMqConsumerLostMsg *pLostMsg = rpcMallocCont(sizeof(SMqConsumerLostMsg));
pLostMsg->consumerId = pConsumer->consumerId;
- SRpcMsg *pRpcMsg = taosMemoryCalloc(1, sizeof(SRpcMsg));
- pRpcMsg->msgType = TDMT_MND_MQ_CONSUMER_LOST;
- pRpcMsg->pCont = pLostMsg;
- pRpcMsg->contLen = sizeof(SMqConsumerLostMsg);
- tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, pRpcMsg);
+ SRpcMsg pRpcMsg = {
+ .msgType = TDMT_MND_MQ_CONSUMER_LOST,
+ .pCont = pLostMsg,
+ .contLen = sizeof(SMqConsumerLostMsg),
+ };
+ tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
}
if (status == MQ_CONSUMER_STATUS__LOST_REBD || status == MQ_CONSUMER_STATUS__READY) {
// do nothing
@@ -280,11 +281,12 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg));
pRecoverMsg->consumerId = consumerId;
- SRpcMsg *pRpcMsg = taosMemoryCalloc(1, sizeof(SRpcMsg));
- pRpcMsg->msgType = TDMT_MND_MQ_CONSUMER_RECOVER;
- pRpcMsg->pCont = pRecoverMsg;
- pRpcMsg->contLen = sizeof(SMqConsumerRecoverMsg);
- tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, pRpcMsg);
+ SRpcMsg pRpcMsg = {
+ .msgType = TDMT_MND_MQ_CONSUMER_RECOVER,
+ .pCont = pRecoverMsg,
+ .contLen = sizeof(SMqConsumerRecoverMsg),
+ };
+ tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
}
mndReleaseConsumer(pMnode, pConsumer);
@@ -318,11 +320,12 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg));
pRecoverMsg->consumerId = consumerId;
- SRpcMsg *pRpcMsg = taosMemoryCalloc(1, sizeof(SRpcMsg));
- pRpcMsg->msgType = TDMT_MND_MQ_CONSUMER_RECOVER;
- pRpcMsg->pCont = pRecoverMsg;
- pRpcMsg->contLen = sizeof(SMqConsumerRecoverMsg);
- tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, pRpcMsg);
+ SRpcMsg pRpcMsg = {
+ .msgType = TDMT_MND_MQ_CONSUMER_RECOVER,
+ .pCont = pRecoverMsg,
+ .contLen = sizeof(SMqConsumerRecoverMsg),
+ };
+ tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
}
#endif
diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c
index f1280700f0..50d26ce9a5 100644
--- a/source/dnode/mnode/impl/src/mndDef.c
+++ b/source/dnode/mnode/impl/src/mndDef.c
@@ -338,8 +338,8 @@ SMqConsumerEp *tCloneSMqConsumerEp(const SMqConsumerEp *pConsumerEpOld) {
return pConsumerEpNew;
}
-void tDeleteSMqConsumerEp(SMqConsumerEp *pConsumerEp) {
- //
+void tDeleteSMqConsumerEp(void *data) {
+ SMqConsumerEp *pConsumerEp = (SMqConsumerEp*)data;
taosArrayDestroyP(pConsumerEp->vgs, (FDelete)tDeleteSMqVgEp);
}
diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt
index 7a99d26683..1f7a059ffc 100644
--- a/source/dnode/vnode/CMakeLists.txt
+++ b/source/dnode/vnode/CMakeLists.txt
@@ -51,7 +51,6 @@ target_sources(
"src/tsdb/tsdbCacheRead.c"
"src/tsdb/tsdbRetention.c"
"src/tsdb/tsdbDiskData.c"
- "src/tsdb/tsdbCompress.c"
"src/tsdb/tsdbCompact.c"
"src/tsdb/tsdbMergeTree.c"
diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h
index 9931462e5f..dade85b12d 100644
--- a/source/dnode/vnode/src/inc/sma.h
+++ b/source/dnode/vnode/src/inc/sma.h
@@ -146,6 +146,7 @@ struct SRSmaInfoItem {
uint16_t nScanned;
int32_t maxDelay; // ms
tmr_h tmrId;
+ void *pStreamState;
};
struct SRSmaInfo {
@@ -224,8 +225,10 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type);
int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash);
int32_t tdRSmaProcessRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer);
-void tdRSmaQTaskInfoGetFileName(int32_t vid, int64_t version, char *outputName);
-void tdRSmaQTaskInfoGetFullName(int32_t vid, int64_t version, const char *path, char *outputName);
+void tdRSmaQTaskInfoGetFileName(int32_t vgId, int64_t version, char *outputName);
+void tdRSmaQTaskInfoGetFullName(int32_t vgId, int64_t version, const char *path, char *outputName);
+void tdRSmaQTaskInfoGetFullPath(int32_t vgId, int8_t level, const char *path, char *outputName);
+void tdRSmaQTaskInfoGetFullPathEx(int32_t vgId, tb_uid_t suid, int8_t level, const char *path, char *outputName);
static FORCE_INLINE void tdRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo) {
int32_t ref = T_REF_INC(pRSmaInfo);
diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h
index 0e85e7bfb6..4c8045d651 100644
--- a/source/dnode/vnode/src/inc/vnodeInt.h
+++ b/source/dnode/vnode/src/inc/vnodeInt.h
@@ -184,7 +184,7 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg);
-SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid,
+SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema, SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid,
const char* stbFullName, SBatchDeleteReq* pDeleteReq);
// sma
diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c
index a34569b08e..24ade017d3 100644
--- a/source/dnode/vnode/src/meta/metaQuery.c
+++ b/source/dnode/vnode/src/meta/metaQuery.c
@@ -319,8 +319,12 @@ _query:
pSchema = tCloneSSchemaWrapper(&meNew.stbEntry.schemaRow);
tDecoderClear(&dcNew);
tdbTbcClose(pCur);
+ tdbFree(pKey);
+ tdbFree(pVal);
goto _exit;
}
+ tdbFree(pKey);
+ tdbFree(pVal);
tdbTbcClose(pCur);
}
} else if (me.type == TSDB_CHILD_TABLE) {
@@ -347,11 +351,13 @@ _query:
tDecoderClear(&dc);
_exit:
+ tDecoderClear(&dc);
metaULock(pMeta);
tdbFree(pData);
return pSchema;
_err:
+ tDecoderClear(&dc);
metaULock(pMeta);
tdbFree(pData);
return NULL;
@@ -383,10 +389,8 @@ int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList) {
ttlKey = *(STtlIdxKey *)pKey;
taosArrayPush(uidList, &ttlKey.uid);
}
- tdbTbcClose(pCur);
-
tdbFree(pKey);
-
+ tdbTbcClose(pCur);
return 0;
}
diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c
index 0edbd092e6..9fdbe50f88 100644
--- a/source/dnode/vnode/src/meta/metaSnapshot.c
+++ b/source/dnode/vnode/src/meta/metaSnapshot.c
@@ -353,6 +353,8 @@ int32_t buildSnapContext(SMeta* pMeta, int64_t snapVersion, int64_t suid, int8_t
metaDebug("tmqsnap init idVersion uid:%" PRIi64 " version:%" PRIi64 " index:%d", *uid, idData->version, idData->index);
}
+ tdbFree(pKey);
+ tdbFree(pVal);
return TDB_CODE_SUCCESS;
}
@@ -528,6 +530,7 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void **pBuf, int32_t *contLen, in
}
}
}
+ taosArrayDestroy(pTagVals);
}
// SIdInfo* sidInfo = (SIdInfo*)taosHashGet(ctx->idVersion, &me.ctbEntry.suid, sizeof(tb_uid_t));
// if(sidInfo->version >= idInfo->version){
diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c
index 22ec8118a2..932afe8937 100644
--- a/source/dnode/vnode/src/meta/metaTable.c
+++ b/source/dnode/vnode/src/meta/metaTable.c
@@ -362,8 +362,9 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
// update uid index
metaUpdateUidIdx(pMeta, &nStbEntry);
- if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf);
metaULock(pMeta);
+
+ if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf);
tDecoderClear(&dc);
tdbTbcClose(pTbDbc);
tdbTbcClose(pUidIdxc);
@@ -922,6 +923,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
taosArrayDestroy(pTagArray);
}
+ metaWLock(pMeta);
+
// save to table.db
metaSaveToTbDb(pMeta, &ctbEntry);
@@ -936,6 +939,8 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags,
((STag *)(ctbEntry.ctbEntry.pTags))->len, &pMeta->txn);
+ metaULock(pMeta);
+
tDecoderClear(&dc1);
tDecoderClear(&dc2);
if (ctbEntry.ctbEntry.pTags) taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
@@ -1192,10 +1197,11 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
const void *pTagData = NULL; //
int32_t nTagData = 0;
SDecoder dc = {0};
-
+ int32_t ret = 0;
// get super table
if (tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData) != 0) {
- return -1;
+ ret = -1;
+ goto end;
}
tbDbKey.uid = pCtbEntry->ctbEntry.suid;
tbDbKey.version = ((SUidIdxVal *)pData)[0].version;
@@ -1221,17 +1227,20 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
// nTagData = ((const STag *)pCtbEntry->ctbEntry.pTags)->len;
pTagData = pCtbEntry->ctbEntry.pTags;
nTagData = ((const STag *)pCtbEntry->ctbEntry.pTags)->len;
- return metaSaveJsonVarToIdx(pMeta, pCtbEntry, pTagColumn);
+ ret = metaSaveJsonVarToIdx(pMeta, pCtbEntry, pTagColumn);
+ goto end;
}
if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type,
pCtbEntry->uid, &pTagIdxKey, &nTagIdxKey) < 0) {
- return -1;
+ ret = -1;
+ goto end;
}
tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, &pMeta->txn);
+end:
metaDestroyTagIdxKey(pTagIdxKey);
tDecoderClear(&dc);
tdbFree(pData);
- return 0;
+ return ret;
}
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c
index ec8fcb2932..412def646f 100644
--- a/source/dnode/vnode/src/sma/smaRollup.c
+++ b/source/dnode/vnode/src/sma/smaRollup.c
@@ -92,6 +92,18 @@ void tdRSmaQTaskInfoGetFullName(int32_t vgId, int64_t version, const char *path,
tdGetVndFileName(vgId, path, VNODE_RSMA_DIR, TD_QTASKINFO_FNAME_PREFIX, version, outputName);
}
+void tdRSmaQTaskInfoGetFullPath(int32_t vgId, int8_t level, const char *path, char *outputName) {
+ tdGetVndDirName(vgId, path, VNODE_RSMA_DIR, true, outputName);
+ int32_t rsmaLen = strlen(outputName);
+ snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi8, level);
+}
+
+void tdRSmaQTaskInfoGetFullPathEx(int32_t vgId, tb_uid_t suid, int8_t level, const char *path, char *outputName) {
+ tdGetVndDirName(vgId, path, VNODE_RSMA_DIR, true, outputName);
+ int32_t rsmaLen = strlen(outputName);
+ snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi64 "%s%" PRIi8, suid, TD_DIRSEP, level);
+}
+
static FORCE_INLINE int32_t tdRSmaQTaskInfoContLen(int32_t lenWithHead) {
return lenWithHead - RSMA_QTASKINFO_HEAD_LEN;
}
@@ -130,6 +142,10 @@ void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo, bool isDeepFree) {
taosTmrStopA(&pItem->tmrId);
}
+ if (isDeepFree && pItem->pStreamState) {
+ streamStateClose(pItem->pStreamState);
+ }
+
if (isDeepFree && pInfo->taskInfo[i]) {
tdRSmaQTaskInfoFree(&pInfo->taskInfo[i], SMA_VID(pSma), i + 1);
} else {
@@ -290,12 +306,33 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
SRetention *pRetention = SMA_RETENTION(pSma);
STsdbCfg *pTsdbCfg = SMA_TSDB_CFG(pSma);
SVnode *pVnode = pSma->pVnode;
+ char taskInfDir[TSDB_FILENAME_LEN] = {0};
+ void *pStreamState = NULL;
+
+ // set the backend of stream state
+ tdRSmaQTaskInfoGetFullPathEx(TD_VID(pVnode), pRSmaInfo->suid, idx + 1, tfsGetPrimaryPath(pVnode->pTfs), taskInfDir);
+ if (!taosCheckExistFile(taskInfDir)) {
+ char *s = strdup(taskInfDir);
+ if (taosMulMkDir(taosDirName(s)) != 0) {
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ taosMemoryFree(s);
+ return TSDB_CODE_FAILED;
+ }
+ taosMemoryFree(s);
+ }
+ pStreamState = streamStateOpen(taskInfDir, NULL, true);
+ if (!pStreamState) {
+ terrno = TSDB_CODE_RSMA_STREAM_STATE_OPEN;
+ return TSDB_CODE_FAILED;
+ }
+
+
SReadHandle handle = {
.meta = pVnode->pMeta,
.vnode = pVnode,
.initTqReader = 1,
+ .pStateBackend = pStreamState,
};
-
pRSmaInfo->taskInfo[idx] = qCreateStreamExecTaskInfo(param->qmsg[idx], &handle);
if (!pRSmaInfo->taskInfo[idx]) {
terrno = TSDB_CODE_RSMA_QTASKINFO_CREATE;
@@ -303,6 +340,7 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
}
SRSmaInfoItem *pItem = &(pRSmaInfo->items[idx]);
pItem->triggerStat = TASK_TRIGGER_STAT_ACTIVE; // fetch the data when reboot
+ pItem->pStreamState = pStreamState;
if (param->maxdelay[idx] < TSDB_MIN_ROLLUP_MAX_DELAY) {
int64_t msInterval =
convertTimeFromPrecisionToUnit(pRetention[idx + 1].freq, pTsdbCfg->precision, TIME_UNIT_MILLISECOND);
@@ -322,7 +360,6 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
pItem->fetchLevel = pItem->level;
taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
-
smaInfo("vgId:%d, item:%p table:%" PRIi64 " level:%" PRIi8 " maxdelay:%" PRIi64 " watermark:%" PRIi64
", finally maxdelay:%" PRIi32,
@@ -1226,16 +1263,17 @@ int32_t tdRSmaProcessRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer)
if (tdRSmaRestoreQTaskInfoInit(pSma, &nTables) < 0) {
goto _err;
}
-
if (nTables <= 0) {
smaDebug("vgId:%d, no need to restore rsma task %" PRIi8 " since no tables", SMA_VID(pSma), type);
return TSDB_CODE_SUCCESS;
}
+#if 0
// step 2: retrieve qtaskinfo items from the persistence file(rsma/qtaskinfo) and restore
if (tdRSmaRestoreQTaskInfoReload(pSma, type, qtaskFileVer) < 0) {
goto _err;
}
+#endif
// step 3: reload ts data from checkpoint
if (tdRSmaRestoreTSDataReload(pSma) < 0) {
@@ -1440,6 +1478,50 @@ static int32_t tdRSmaQTaskInfoRestore(SSma *pSma, int8_t type, SRSmaQTaskInfoIte
return TSDB_CODE_SUCCESS;
}
+int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
+ SSma *pSma = pRSmaStat->pSma;
+ SVnode *pVnode = pSma->pVnode;
+ int32_t vid = SMA_VID(pSma);
+
+ if (taosHashGetSize(pInfoHash) <= 0) {
+ return TSDB_CODE_SUCCESS;
+ }
+
+ int64_t fsMaxVer = tdRSmaFSMaxVer(pSma, pRSmaStat);
+ if (pRSmaStat->commitAppliedVer <= fsMaxVer) {
+ smaDebug("vgId:%d, rsma persist, no need as applied %" PRIi64 " not larger than fsMaxVer %" PRIi64, vid,
+ pRSmaStat->commitAppliedVer, fsMaxVer);
+ return TSDB_CODE_SUCCESS;
+ }
+
+ void *infoHash = NULL;
+ while ((infoHash = taosHashIterate(pInfoHash, infoHash))) {
+ SRSmaInfo *pRSmaInfo = *(SRSmaInfo **)infoHash;
+
+ if (RSMA_INFO_IS_DEL(pRSmaInfo)) {
+ continue;
+ }
+
+ for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
+ SRSmaInfoItem *pItem = RSMA_INFO_ITEM(pRSmaInfo, i);
+ if (pItem && pItem->pStreamState) {
+ if (streamStateCommit(pItem->pStreamState) < 0) {
+ terrno = TSDB_CODE_RSMA_STREAM_STATE_COMMIT;
+ goto _err;
+ }
+ smaDebug("vgId:%d, rsma persist, stream state commit success, table %" PRIi64 " level %d", vid, pRSmaInfo->suid,
+ i + 1);
+ }
+ }
+ }
+
+ return TSDB_CODE_SUCCESS;
+_err:
+ smaError("vgId:%d, rsma persist failed since %s", vid, terrstr());
+ return TSDB_CODE_FAILED;
+}
+
+#if 0
int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
SSma *pSma = pRSmaStat->pSma;
SVnode *pVnode = pSma->pVnode;
@@ -1459,7 +1541,7 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
int64_t fsMaxVer = tdRSmaFSMaxVer(pSma, pRSmaStat);
if (pRSmaStat->commitAppliedVer <= fsMaxVer) {
smaDebug("vgId:%d, rsma persist, no need as applied %" PRIi64 " not larger than fsMaxVer %" PRIi64, vid,
- pRSmaStat->commitAppliedVer, fsMaxVer);
+ pRSmaStat->commitAppliedVer, fsMaxVer);
return TSDB_CODE_SUCCESS;
}
@@ -1579,6 +1661,8 @@ _err:
return TSDB_CODE_FAILED;
}
+#endif
+
/**
* @brief trigger to get rsma result in async mode
*
@@ -1926,7 +2010,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
if ((pEnv->flag & SMA_ENV_FLG_CLOSE) && (atomic_load_64(&pRSmaStat->nBufItems) <= 0)) {
smaDebug("vgId:%d, exec task end, flag:%" PRIi8 ", nBufItems:%" PRIi64, SMA_VID(pSma), pEnv->flag,
- atomic_load_64(&pRSmaStat->nBufItems));
+ atomic_load_64(&pRSmaStat->nBufItems));
break;
}
}
diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c
index e2cb51f586..6c32fbbc84 100644
--- a/source/dnode/vnode/src/sma/smaTimeRange.c
+++ b/source/dnode/vnode/src/sma/smaTimeRange.c
@@ -204,7 +204,7 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
}
SBatchDeleteReq deleteReq;
- SSubmitReq *pSubmitReq = tqBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, true,
+ SSubmitReq *pSubmitReq = tqBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq);
if (!pSubmitReq) {
diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c
index c8841e5e16..29217e29a4 100644
--- a/source/dnode/vnode/src/tq/tq.c
+++ b/source/dnode/vnode/src/tq/tq.c
@@ -51,6 +51,20 @@ void tqCleanUp() {
}
}
+static void destroySTqHandle(void* data) {
+ STqHandle* pData = (STqHandle*)data;
+ qDestroyTask(pData->execHandle.task);
+ if (pData->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
+ } else if (pData->execHandle.subType == TOPIC_SUB_TYPE__DB) {
+ tqCloseReader(pData->execHandle.pExecReader);
+ walCloseReader(pData->pWalReader);
+ taosHashCleanup(pData->execHandle.execDb.pFilterOutTbUid);
+ } else if (pData->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
+ walCloseReader(pData->pWalReader);
+ tqCloseReader(pData->execHandle.pExecReader);
+ }
+}
+
STQ* tqOpen(const char* path, SVnode* pVnode) {
STQ* pTq = taosMemoryCalloc(1, sizeof(STQ));
if (pTq == NULL) {
@@ -62,6 +76,8 @@ STQ* tqOpen(const char* path, SVnode* pVnode) {
pTq->pHandle = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK);
+ taosHashSetFreeFp(pTq->pHandle, destroySTqHandle);
+
pTq->pPushMgr = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
pTq->pCheckInfo = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK);
@@ -141,11 +157,8 @@ int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, con
ASSERT(taosArrayGetSize(pRsp->blockData) == pRsp->blockNum);
ASSERT(taosArrayGetSize(pRsp->blockDataLen) == pRsp->blockNum);
- if (pRsp->withSchema) {
- ASSERT(taosArrayGetSize(pRsp->blockSchema) == pRsp->blockNum);
- } else {
- ASSERT(taosArrayGetSize(pRsp->blockSchema) == 0);
- }
+ ASSERT(!pRsp->withSchema);
+ ASSERT(taosArrayGetSize(pRsp->blockSchema) == 0);
if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) {
if (pRsp->blockNum > 0) {
@@ -520,6 +533,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
int64_t fetchVer = fetchOffsetNew.version + 1;
pCkHead = taosMemoryMalloc(sizeof(SWalCkHead) + 2048);
if (pCkHead == NULL) {
+ tDeleteSTaosxRsp(&taosxRsp);
return -1;
}
@@ -580,14 +594,17 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
if (tqSendMetaPollRsp(pTq, pMsg, pReq, &metaRsp) < 0) {
code = -1;
taosMemoryFree(pCkHead);
+ tDeleteSTaosxRsp(&taosxRsp);
return code;
}
code = 0;
if (pCkHead) taosMemoryFree(pCkHead);
+ tDeleteSTaosxRsp(&taosxRsp);
return code;
}
}
}
+ tDeleteSTaosxRsp(&taosxRsp);
return 0;
}
@@ -647,7 +664,10 @@ int32_t tqProcessVgChangeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLe
tqError("vgId:%d, build new consumer handle %s for consumer %d, but old consumerId is %ld", req.vgId, req.subKey,
req.newConsumerId, req.oldConsumerId);
}
- ASSERT(req.newConsumerId != -1);
+ if (req.newConsumerId == -1) {
+ tqError("vgId:%d, tq invalid rebalance request, new consumerId %ld", req.vgId, req.newConsumerId);
+ return 0;
+ }
STqHandle tqHandle = {0};
pHandle = &tqHandle;
/*taosInitRWLatch(&pExec->lock);*/
@@ -760,7 +780,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask) {
// expand executor
if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
- pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask);
+ pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false);
if (pTask->pState == NULL) {
return -1;
}
@@ -774,7 +794,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask) {
pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle);
ASSERT(pTask->exec.executor);
} else if (pTask->taskLevel == TASK_LEVEL__AGG) {
- pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask);
+ pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false);
if (pTask->pState == NULL) {
return -1;
}
@@ -859,6 +879,9 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
taosArrayDestroy(pRes->uidList);
+ int32_t* pRef = taosMemoryMalloc(sizeof(int32_t));
+ *pRef = 1;
+
void* pIter = NULL;
while (1) {
pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
@@ -868,6 +891,33 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
qDebug("delete req enqueue stream task: %d, ver: %" PRId64, pTask->taskId, ver);
+ if (!failed) {
+ SStreamRefDataBlock* pRefBlock = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM);
+ pRefBlock->type = STREAM_INPUT__REF_DATA_BLOCK;
+ pRefBlock->pBlock = pDelBlock;
+ pRefBlock->dataRef = pRef;
+ atomic_add_fetch_32(pRefBlock->dataRef, 1);
+
+ if (streamTaskInput(pTask, (SStreamQueueItem*)pRefBlock) < 0) {
+ qError("stream task input del failed, task id %d", pTask->taskId);
+ continue;
+ }
+ if (streamSchedExec(pTask) < 0) {
+ qError("stream task launch failed, task id %d", pTask->taskId);
+ continue;
+ }
+ } else {
+ streamTaskInputFail(pTask);
+ }
+ }
+ int32_t ref = atomic_sub_fetch_32(pRef, 1);
+ ASSERT(ref >= 0);
+ if (ref == 0) {
+ taosMemoryFree(pDelBlock);
+ taosMemoryFree(pRef);
+ }
+
+#if 0
SStreamDataBlock* pStreamBlock = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
pStreamBlock->type = STREAM_INPUT__DATA_BLOCK;
pStreamBlock->blocks = taosArrayInit(0, sizeof(SSDataBlock));
@@ -891,6 +941,7 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
}
}
blockDataDestroy(pDelBlock);
+#endif
return 0;
}
@@ -1028,6 +1079,7 @@ int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg) {
SDecoder decoder;
tDecoderInit(&decoder, msgBody, msgLen);
tDecodeStreamRetrieveReq(&decoder, &req);
+ tDecoderClear(&decoder);
int32_t taskId = req.dstTaskId;
SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId);
if (pTask) {
@@ -1036,6 +1088,7 @@ int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg) {
.code = 0,
};
streamProcessRetrieveReq(pTask, &req, &rsp);
+ tDeleteStreamRetrieveReq(&req);
return 0;
} else {
return -1;
diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c
index d00907f677..a24f920235 100644
--- a/source/dnode/vnode/src/tq/tqExec.c
+++ b/source/dnode/vnode/src/tq/tqExec.c
@@ -243,14 +243,15 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
}
if (pHandle->fetchMeta) {
SSubmitBlk* pBlk = pReader->pBlock;
- if (pBlk->schemaLen > 0) {
+ int32_t schemaLen = htonl(pBlk->schemaLen);
+ if (schemaLen > 0) {
if (pRsp->createTableNum == 0) {
pRsp->createTableLen = taosArrayInit(0, sizeof(int32_t));
pRsp->createTableReq = taosArrayInit(0, sizeof(void*));
}
- void* createReq = taosMemoryCalloc(1, pBlk->schemaLen);
- memcpy(createReq, pBlk->data, pBlk->schemaLen);
- taosArrayPush(pRsp->createTableLen, &pBlk->schemaLen);
+ void* createReq = taosMemoryCalloc(1, schemaLen);
+ memcpy(createReq, pBlk->data, schemaLen);
+ taosArrayPush(pRsp->createTableLen, &schemaLen);
taosArrayPush(pRsp->createTableReq, &createReq);
pRsp->createTableNum++;
}
@@ -277,14 +278,15 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp
}
if (pHandle->fetchMeta) {
SSubmitBlk* pBlk = pReader->pBlock;
- if (pBlk->schemaLen > 0) {
+ int32_t schemaLen = htonl(pBlk->schemaLen);
+ if (schemaLen > 0) {
if (pRsp->createTableNum == 0) {
pRsp->createTableLen = taosArrayInit(0, sizeof(int32_t));
pRsp->createTableReq = taosArrayInit(0, sizeof(void*));
}
- void* createReq = taosMemoryCalloc(1, pBlk->schemaLen);
- memcpy(createReq, pBlk->data, pBlk->schemaLen);
- taosArrayPush(pRsp->createTableLen, &pBlk->schemaLen);
+ void* createReq = taosMemoryCalloc(1, schemaLen);
+ memcpy(createReq, pBlk->data, schemaLen);
+ taosArrayPush(pRsp->createTableLen, &schemaLen);
taosArrayPush(pRsp->createTableReq, &createReq);
pRsp->createTableNum++;
}
diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c
index d8d8025151..7097591c35 100644
--- a/source/dnode/vnode/src/tq/tqOffset.c
+++ b/source/dnode/vnode/src/tq/tqOffset.c
@@ -145,6 +145,7 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
ASSERT(0);
tqError("write offset incomplete, len %d, write len %" PRId64, bodyLen, writeLen);
taosHashCancelIterate(pStore->pHash, pIter);
+ taosMemoryFree(buf);
return -1;
}
taosMemoryFree(buf);
diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c
index 375130fa2c..8e5f328efa 100644
--- a/source/dnode/vnode/src/tq/tqRead.c
+++ b/source/dnode/vnode/src/tq/tqRead.c
@@ -80,6 +80,13 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont *pHead){
void* buf = taosMemoryMalloc(tlen);
if (NULL == buf) {
taosArrayDestroy(reqNew.pArray);
+ for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
+ pCreateReq = req.pReqs + iReq;
+ taosMemoryFreeClear(pCreateReq->comment);
+ if (pCreateReq->type == TSDB_CHILD_TABLE) {
+ taosArrayDestroy(pCreateReq->ctb.tagName);
+ }
+ }
goto end;
}
SEncoder coderNew = {0};
@@ -91,6 +98,14 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont *pHead){
taosMemoryFree(buf);
taosArrayDestroy(reqNew.pArray);
}
+
+ for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
+ pCreateReq = req.pReqs + iReq;
+ taosMemoryFreeClear(pCreateReq->comment);
+ if (pCreateReq->type == TSDB_CHILD_TABLE) {
+ taosArrayDestroy(pCreateReq->ctb.tagName);
+ }
+ }
} else if (msgType == TDMT_VND_ALTER_TABLE) {
SVAlterTbReq req = {0};
diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c
index 522bf46aa1..16c2a5d033 100644
--- a/source/dnode/vnode/src/tq/tqSink.c
+++ b/source/dnode/vnode/src/tq/tqSink.c
@@ -48,7 +48,7 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl
return 0;
}
-SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema, bool createTb,
+SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema, SSchemaWrapper* pTagSchemaWrapper, bool createTb,
int64_t suid, const char* stbFullName, SBatchDeleteReq* pDeleteReq) {
SSubmitReq* ret = NULL;
SArray* schemaReqs = NULL;
@@ -89,6 +89,32 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
return NULL;
}
+ SArray *tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
+ char tagNameStr[TSDB_COL_NAME_LEN] = {0};
+ strcpy(tagNameStr, "group_id");
+ taosArrayPush(tagName, tagNameStr);
+
+// STag* pTag = NULL;
+// taosArrayClear(tagArray);
+// SArray *tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
+// for(int j = 0; j < pTagSchemaWrapper->nCols; j++){
+// STagVal tagVal = {
+// .cid = pTagSchemaWrapper->pSchema[j].colId,
+// .type = pTagSchemaWrapper->pSchema[j].type,
+// .i64 = (int64_t)pDataBlock->info.groupId,
+// };
+// taosArrayPush(tagArray, &tagVal);
+// taosArrayPush(tagName, pTagSchemaWrapper->pSchema[j].name);
+// }
+//
+// tTagNew(tagArray, 1, false, &pTag);
+// if (pTag == NULL) {
+// terrno = TSDB_CODE_OUT_OF_MEMORY;
+// taosArrayDestroy(tagArray);
+// taosArrayDestroy(tagName);
+// return NULL;
+// }
+
SVCreateTbReq createTbReq = {0};
SName name = {0};
tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
@@ -99,6 +125,8 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
createTbReq.type = TSDB_CHILD_TABLE;
createTbReq.ctb.suid = suid;
createTbReq.ctb.pTag = (uint8_t*)pTag;
+ createTbReq.ctb.tagNum = taosArrayGetSize(tagArray);
+ createTbReq.ctb.tagName = tagName;
int32_t code;
int32_t schemaLen;
@@ -113,6 +141,7 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
void* schemaStr = taosMemoryMalloc(schemaLen);
if (schemaStr == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
+ tdDestroySVCreateTbReq(&createTbReq);
return NULL;
}
taosArrayPush(schemaReqs, &schemaStr);
@@ -123,6 +152,7 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
code = tEncodeSVCreateTbReq(&encoder, &createTbReq);
if (code < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
+ tdDestroySVCreateTbReq(&createTbReq);
return NULL;
}
tEncoderClear(&encoder);
@@ -231,7 +261,7 @@ void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
ASSERT(pTask->tbSink.pTSchema);
deleteReq.deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
- SSubmitReq* submitReq = tqBlockToSubmit(pVnode, pRes, pTask->tbSink.pTSchema, true, pTask->tbSink.stbUid,
+ SSubmitReq* submitReq = tqBlockToSubmit(pVnode, pRes, pTask->tbSink.pTSchema, pTask->tbSink.pSchemaWrapper, true, pTask->tbSink.stbUid,
pTask->tbSink.stbFullName, &deleteReq);
tqDebug("vgId:%d, task %d convert blocks over, put into write-queue", TD_VID(pVnode), pTask->taskId);
@@ -274,7 +304,6 @@ void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
};
if (tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &msg) != 0) {
- rpcFreeCont(submitReq);
tqDebug("failed to put into write-queue since %s", terrstr());
}
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbCompress.c b/source/dnode/vnode/src/tsdb/tsdbCompress.c
deleted file mode 100644
index 76be7c1070..0000000000
--- a/source/dnode/vnode/src/tsdb/tsdbCompress.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-#include "tsdb.h"
-
-// Integer =====================================================
-typedef struct {
- int8_t rawCopy;
- int64_t prevVal;
- int32_t nVal;
- int32_t nBuf;
- uint8_t *pBuf;
-} SIntCompressor;
-
-#define I64_SAFE_ADD(a, b) (((a) >= 0 && (b) <= INT64_MAX - (b)) || ((a) < 0 && (b) >= INT64_MIN - (a)))
-#define SIMPLE8B_MAX ((uint64_t)1152921504606846974LL)
-
-static int32_t tsdbCmprI64(SIntCompressor *pCompressor, int64_t val) {
- int32_t code = 0;
-
- // raw copy
- if (pCompressor->rawCopy) {
- memcpy(pCompressor->pBuf + pCompressor->nBuf, &val, sizeof(val));
- pCompressor->nBuf += sizeof(val);
- pCompressor->nVal++;
- goto _exit;
- }
-
- if (!I64_SAFE_ADD(val, pCompressor->prevVal)) {
- pCompressor->rawCopy = 1;
- // TODO: decompress and copy
- pCompressor->nVal++;
- goto _exit;
- }
-
- int64_t diff = val - pCompressor->prevVal;
- uint8_t zigzag = ZIGZAGE(int64_t, diff);
-
- if (zigzag >= SIMPLE8B_MAX) {
- pCompressor->rawCopy = 1;
- // TODO: decompress and copy
- pCompressor->nVal++;
- goto _exit;
- }
-
-_exit:
- return code;
-}
-
-// Timestamp =====================================================
-
-// Float =====================================================
\ No newline at end of file
diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
index 45fe29f0fa..5f03a82bc0 100644
--- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
+++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
@@ -320,6 +320,7 @@ void tLDataIterNextBlock(SLDataIter *pIter) {
pIter->pSttBlk = NULL;
if (index != -1) {
+ pIter->iSttBlk = index;
pIter->pSttBlk = (SSttBlk *)taosArrayGet(pIter->pBlockLoadInfo->aSttBlk, pIter->iSttBlk);
}
}
diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c
index 65d4e9aaf1..a941b5955c 100644
--- a/source/dnode/vnode/src/vnd/vnodeSync.c
+++ b/source/dnode/vnode/src/vnd/vnodeSync.c
@@ -676,6 +676,18 @@ static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsm
static void vnodeRestoreFinish(struct SSyncFSM *pFsm) {
SVnode *pVnode = pFsm->data;
+
+ do {
+ int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
+ if (itemSize == 0) {
+ vInfo("vgId:%d, apply queue is empty, restore finish", pVnode->config.vgId);
+ break;
+ } else {
+ vInfo("vgId:%d, restore not finish since %d items in apply queue", pVnode->config.vgId);
+ taosMsleep(10);
+ }
+ } while (true);
+
pVnode->restored = true;
vDebug("vgId:%d, sync restore finished", pVnode->config.vgId);
}
diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h
index a2828779a2..b25bd4fd09 100644
--- a/source/libs/executor/inc/executorimpl.h
+++ b/source/libs/executor/inc/executorimpl.h
@@ -463,6 +463,7 @@ typedef struct SPartitionDataInfo {
typedef struct STimeWindowAggSupp {
int8_t calTrigger;
int64_t waterMark;
+ int64_t deleteMark;
TSKEY maxTs;
TSKEY minTs;
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
@@ -1064,6 +1065,7 @@ bool functionNeedToExecute(SqlFunctionCtx* pCtx);
bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup);
bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup);
bool isDeletedWindow(STimeWindow* pWin, uint64_t groupId, SAggSupporter* pSup);
+bool isDeletedStreamWindow(STimeWindow* pWin, uint64_t groupId, SOperatorInfo* pOperator, STimeWindowAggSupp* pTwSup);
void appendOneRow(SSDataBlock* pBlock, TSKEY* pStartTs, TSKEY* pEndTs, uint64_t* pUid, uint64_t* pGp);
void printDataBlock(SSDataBlock* pBlock, const char* flag);
uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t rowId);
@@ -1091,7 +1093,7 @@ int32_t setOutputBuf(STimeWindow* win, SResultRow** pResult, int64_t tableGroupI
int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup,
SExecTaskInfo* pTaskInfo);
int32_t releaseOutputBuf(SExecTaskInfo* pTaskInfo, SWinKey* pKey, SResultRow* pResult);
-int32_t saveOutput(SExecTaskInfo* pTaskInfo, SWinKey* pKey, SResultRow* pResult, int32_t resSize);
+int32_t saveOutputBuf(SExecTaskInfo* pTaskInfo, SWinKey* pKey, SResultRow* pResult, int32_t resSize);
#ifdef __cplusplus
}
diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c
index d75f0580e1..b26603b394 100644
--- a/source/libs/executor/src/executil.c
+++ b/source/libs/executor/src/executil.c
@@ -989,7 +989,8 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
if (pNode->output) {
(*numOfOutputCols) += 1;
- } else {
+ } else if (info != NULL) {
+ // select distinct tbname from stb where tbname='abc';
info->output = false;
}
}
@@ -1341,7 +1342,7 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi
return TSDB_CODE_SUCCESS;
}
-void cleanupQueryTableDataCond(SQueryTableDataCond* pCond) { taosMemoryFree(pCond->colList); }
+void cleanupQueryTableDataCond(SQueryTableDataCond* pCond) { taosMemoryFreeClear(pCond->colList); }
int32_t convertFillType(int32_t mode) {
int32_t type = TSDB_FILL_NONE;
diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c
index 44541ee27c..45b88ec6a5 100644
--- a/source/libs/executor/src/executor.c
+++ b/source/libs/executor/src/executor.c
@@ -876,6 +876,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
tsdbReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pTaskInfo->tableqinfoList.pTableList,
&pInfo->dataReader, NULL);
+ cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
strcpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName);
tDeleteSSchemaWrapper(pTaskInfo->streamInfo.schema);
pTaskInfo->streamInfo.schema = mtInfo.schema;
diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c
index e1fad21b0e..bbfef5998e 100644
--- a/source/libs/executor/src/executorimpl.c
+++ b/source/libs/executor/src/executorimpl.c
@@ -3391,6 +3391,10 @@ static void cleanupTableSchemaInfo(SSchemaInfo* pSchemaInfo) {
tDeleteSSchemaWrapper(pSchemaInfo->qsw);
}
+static void cleanupStreamInfo(SStreamTaskInfo* pStreamInfo) {
+ tDeleteSSchemaWrapper(pStreamInfo->schema);
+}
+
static int32_t sortTableGroup(STableListInfo* pTableListInfo) {
taosArrayClear(pTableListInfo->pGroupList);
SArray* sortSupport = taosArrayInit(16, sizeof(uint64_t));
@@ -4084,6 +4088,7 @@ void doDestroyTask(SExecTaskInfo* pTaskInfo) {
doDestroyTableList(&pTaskInfo->tableqinfoList);
destroyOperatorInfo(pTaskInfo->pRoot);
cleanupTableSchemaInfo(&pTaskInfo->schemaInfo);
+ cleanupStreamInfo(&pTaskInfo->streamInfo);
nodesDestroyNode((SNode*)pTaskInfo->pSubplan);
@@ -4207,9 +4212,8 @@ int32_t setOutputBuf(STimeWindow* win, SResultRow** pResult, int64_t tableGroupI
};
char* value = NULL;
int32_t size = pAggSup->resultRowSize;
- /*if (streamStateGet(pTaskInfo->streamInfo.pState, &key, (void**)&value, &size) < 0) {*/
- /*value = taosMemoryCalloc(1, size);*/
- /*}*/
+
+ tSimpleHashPut(pAggSup->pResultRowHashTable, &key, sizeof(SWinKey), NULL, 0);
if (streamStateAddIfNotExist(pTaskInfo->streamInfo.pState, &key, (void**)&value, &size) < 0) {
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
@@ -4227,7 +4231,7 @@ int32_t releaseOutputBuf(SExecTaskInfo* pTaskInfo, SWinKey* pKey, SResultRow* pR
return TSDB_CODE_SUCCESS;
}
-int32_t saveOutput(SExecTaskInfo* pTaskInfo, SWinKey* pKey, SResultRow* pResult, int32_t resSize) {
+int32_t saveOutputBuf(SExecTaskInfo* pTaskInfo, SWinKey* pKey, SResultRow* pResult, int32_t resSize) {
streamStatePut(pTaskInfo->streamInfo.pState, pKey, pResult, resSize);
return TSDB_CODE_SUCCESS;
}
@@ -4300,8 +4304,9 @@ int32_t buildDataBlockFromGroupRes(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock
}
}
}
- releaseOutputBuf(pTaskInfo, &key, pRow);
+
pBlock->info.rows += pRow->numOfRows;
+ releaseOutputBuf(pTaskInfo, &key, pRow);
}
blockDataUpdateTsWindow(pBlock, 0);
return TSDB_CODE_SUCCESS;
diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c
index 60e1c2d86d..0db85353c5 100644
--- a/source/libs/executor/src/scanoperator.c
+++ b/source/libs/executor/src/scanoperator.c
@@ -1336,7 +1336,7 @@ static void checkUpdateData(SStreamScanInfo* pInfo, bool invertible, SSDataBlock
// must check update info first.
bool update = updateInfoIsUpdated(pInfo->pUpdateInfo, pBlock->info.uid, tsCol[rowId]);
bool closedWin = isClosed && isSignleIntervalWindow(pInfo) &&
- isDeletedWindow(&win, pBlock->info.groupId, pInfo->windowSup.pIntervalAggSup);
+ isDeletedStreamWindow(&win, pBlock->info.groupId, pInfo->pTableScanOp, &pInfo->twAggSup);
if ((update || closedWin) && out) {
qDebug("stream update check not pass, update %d, closedWin %d", update, closedWin);
uint64_t gpId = closedWin && pInfo->partitionSup.needCalc
@@ -1485,6 +1485,40 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
}
}
+static int32_t filterDelBlockByUid(SSDataBlock* pDst, const SSDataBlock* pSrc, SStreamScanInfo* pInfo) {
+ STqReader* pReader = pInfo->tqReader;
+ int32_t rows = pSrc->info.rows;
+ blockDataEnsureCapacity(pDst, rows);
+
+ SColumnInfoData* pSrcStartCol = taosArrayGet(pSrc->pDataBlock, START_TS_COLUMN_INDEX);
+ uint64_t* startCol = (uint64_t*)pSrcStartCol->pData;
+ SColumnInfoData* pSrcEndCol = taosArrayGet(pSrc->pDataBlock, END_TS_COLUMN_INDEX);
+ uint64_t* endCol = (uint64_t*)pSrcEndCol->pData;
+ SColumnInfoData* pSrcUidCol = taosArrayGet(pSrc->pDataBlock, UID_COLUMN_INDEX);
+ uint64_t* uidCol = (uint64_t*)pSrcUidCol->pData;
+
+ SColumnInfoData* pDstStartCol = taosArrayGet(pDst->pDataBlock, START_TS_COLUMN_INDEX);
+ SColumnInfoData* pDstEndCol = taosArrayGet(pDst->pDataBlock, END_TS_COLUMN_INDEX);
+ SColumnInfoData* pDstUidCol = taosArrayGet(pDst->pDataBlock, UID_COLUMN_INDEX);
+ int32_t j = 0;
+ for (int32_t i = 0; i < rows; i++) {
+ if (taosHashGet(pReader->tbIdHash, &uidCol[i], sizeof(uint64_t))) {
+ colDataAppend(pDstStartCol, j, (const char*)&startCol[i], false);
+ colDataAppend(pDstEndCol, j, (const char*)&endCol[i], false);
+ colDataAppend(pDstUidCol, j, (const char*)&uidCol[i], false);
+
+ colDataAppendNULL(taosArrayGet(pDst->pDataBlock, GROUPID_COLUMN_INDEX), j);
+ colDataAppendNULL(taosArrayGet(pDst->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX), j);
+ colDataAppendNULL(taosArrayGet(pDst->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX), j);
+ j++;
+ }
+ }
+ pDst->info = pSrc->info;
+ pDst->info.rows = j;
+
+ return 0;
+}
+
static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
// NOTE: this operator does never check if current status is done or not
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
@@ -1573,6 +1607,12 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
} break;
case STREAM_DELETE_DATA: {
printDataBlock(pBlock, "stream scan delete recv");
+ if (pInfo->tqReader) {
+ SSDataBlock* pDelBlock = createSpecialDataBlock(STREAM_DELETE_DATA);
+ filterDelBlockByUid(pDelBlock, pBlock, pInfo);
+ pBlock = pDelBlock;
+ }
+ printDataBlock(pBlock, "stream scan delete recv filtered");
if (!isIntervalWindow(pInfo) && !isSessionWindow(pInfo) && !isStateWindow(pInfo)) {
generateDeleteResultBlock(pInfo, pBlock, pInfo->pDeleteDataRes);
pInfo->pDeleteDataRes->info.type = STREAM_DELETE_RESULT;
@@ -1785,6 +1825,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
qDebug("tmqsnap change get data uid:%ld", mtInfo.uid);
qStreamPrepareScan(pTaskInfo, &pTaskInfo->streamInfo.prepareStatus, pInfo->sContext->subType);
}
+ tDeleteSSchemaWrapper(mtInfo.schema);
qDebug("tmqsnap stream scan tsdb return null");
return NULL;
} else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_META) {
@@ -1936,11 +1977,6 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
pInfo->pTagCond = pTagCond;
pInfo->pGroupTags = pTableScanNode->pGroupTags;
- pInfo->twAggSup = (STimeWindowAggSupp){
- .waterMark = pTableScanNode->watermark,
- .calTrigger = pTableScanNode->triggerType,
- .maxTs = INT64_MIN,
- };
int32_t numOfCols = 0;
pInfo->pColMatchInfo = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
@@ -1990,7 +2026,6 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
pInfo->pUpdateInfo = NULL;
pInfo->pTableScanOp = pTableScanOp;
- pInfo->interval = pTSInfo->pdInfo.interval;
pInfo->readHandle = *pHandle;
pInfo->tableUid = pScanPhyNode->uid;
diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c
index 5b38b81b30..c29fab14c3 100644
--- a/source/libs/executor/src/timewindowoperator.c
+++ b/source/libs/executor/src/timewindowoperator.c
@@ -867,6 +867,10 @@ static int32_t saveWinResultRow(SResultRow* result, uint64_t groupId, SHashObj*
return saveWinResult(result->win.skey, result->pageId, result->offset, groupId, pUpdatedMap);
}
+static int32_t saveWinResultInfo(TSKEY ts, uint64_t groupId, SHashObj* pUpdatedMap) {
+ return saveWinResult(ts, -1, -1, groupId, pUpdatedMap);
+}
+
static int32_t saveResultRow(SResultRow* result, uint64_t groupId, SArray* pUpdated) {
return saveResult(result->win.skey, result->pageId, result->offset, groupId, pUpdated);
}
@@ -918,12 +922,16 @@ static void removeDeleteResults(SHashObj* pUpdatedMap, SArray* pDelWins) {
}
}
-bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup) {
- ASSERT(pSup->maxTs == INT64_MIN || pSup->maxTs > 0);
- return pSup->maxTs != INT64_MIN && ts < pSup->maxTs - pSup->waterMark;
+bool isOverdue(TSKEY ekey, STimeWindowAggSupp* pTwSup) {
+ ASSERT(pTwSup->maxTs == INT64_MIN || pTwSup->maxTs > 0);
+ return pTwSup->maxTs != INT64_MIN && ekey < pTwSup->maxTs - pTwSup->waterMark;
}
-bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup) { return isOverdue(pWin->ekey, pSup); }
+bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pTwSup) { return isOverdue(pWin->ekey, pTwSup); }
+
+bool needDeleteWindowBuf(STimeWindow* pWin, STimeWindowAggSupp* pTwSup) {
+ return pTwSup->maxTs != INT64_MIN && pWin->ekey < pTwSup->maxTs - pTwSup->deleteMark;
+}
static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pBlock,
int32_t scanFlag) {
@@ -1374,6 +1382,41 @@ static bool doClearWindow(SAggSupporter* pAggSup, SExprSupp* pSup, char* pData,
return true;
}
+static bool doDeleteWindow(SOperatorInfo* pOperator, TSKEY ts, uint64_t groupId, int32_t numOfOutput) {
+ SStreamIntervalOperatorInfo* pInfo = pOperator->info;
+ SWinKey key = {.ts = ts, .groupId = groupId};
+ tSimpleHashRemove(pInfo->aggSup.pResultRowHashTable, &key, sizeof(SWinKey));
+ streamStateDel(pOperator->pTaskInfo->streamInfo.pState, &key);
+ return true;
+}
+
+static void doDeleteWindows(SOperatorInfo* pOperator, SInterval* pInterval, int32_t numOfOutput, SSDataBlock* pBlock,
+ SArray* pUpWins, SHashObj* pUpdatedMap) {
+ SColumnInfoData* pStartTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
+ TSKEY* startTsCols = (TSKEY*)pStartTsCol->pData;
+ SColumnInfoData* pEndTsCol = taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
+ TSKEY* endTsCols = (TSKEY*)pEndTsCol->pData;
+ SColumnInfoData* pGpCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
+ uint64_t* pGpDatas = (uint64_t*)pGpCol->pData;
+ for (int32_t i = 0; i < pBlock->info.rows; i++) {
+ SResultRowInfo dumyInfo;
+ dumyInfo.cur.pageId = -1;
+ STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, startTsCols[i], pInterval, TSDB_ORDER_ASC);
+ while (win.ekey <= endTsCols[i]) {
+ uint64_t winGpId = pGpDatas[i];
+ bool res = doDeleteWindow(pOperator, win.skey, winGpId, numOfOutput);
+ SWinKey winRes = {.ts = win.skey, .groupId = winGpId};
+ if (pUpWins && res) {
+ taosArrayPush(pUpWins, &winRes);
+ }
+ if (pUpdatedMap) {
+ taosHashRemove(pUpdatedMap, &winRes, sizeof(SWinKey));
+ }
+ getNextTimeWindow(pInterval, pInterval->precision, TSDB_ORDER_ASC, &win);
+ }
+ }
+}
+
bool doDeleteIntervalWindow(SAggSupporter* pAggSup, TSKEY ts, uint64_t groupId) {
size_t bytes = sizeof(TSKEY);
SET_RES_WINDOW_KEY(pAggSup->keyBuf, &ts, bytes, groupId);
@@ -1383,8 +1426,6 @@ bool doDeleteIntervalWindow(SAggSupporter* pAggSup, TSKEY ts, uint64_t groupId)
// window has been closed
return false;
}
- // SFilePage* bufPage = getBufPage(pAggSup->pResultBuf, p1->pageId);
- // dBufSetBufPageRecycled(pAggSup->pResultBuf, bufPage);
tSimpleHashRemove(pAggSup->pResultRowHashTable, pAggSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
return true;
}
@@ -1512,6 +1553,49 @@ static int32_t closeIntervalWindow(SSHashObj* pHashMap, STimeWindowAggSupp* pSup
return TSDB_CODE_SUCCESS;
}
+static int32_t closeStreamIntervalWindow(SSHashObj* pHashMap, STimeWindowAggSupp* pTwSup, SInterval* pInterval,
+ SHashObj* pPullDataMap, SHashObj* closeWins, SOperatorInfo* pOperator) {
+ qDebug("===stream===close interval window");
+ void* pIte = NULL;
+ size_t keyLen = 0;
+ int32_t iter = 0;
+ while ((pIte = tSimpleHashIterate(pHashMap, pIte, &iter)) != NULL) {
+ void* key = tSimpleHashGetKey(pIte, &keyLen);
+ SWinKey* pWinKey = (SWinKey*)key;
+ void* chIds = taosHashGet(pPullDataMap, pWinKey, sizeof(SWinKey));
+ STimeWindow win = {
+ .skey = pWinKey->ts,
+ .ekey = taosTimeAdd(win.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1,
+ };
+ if (isCloseWindow(&win, pTwSup)) {
+ if (chIds && pPullDataMap) {
+ SArray* chAy = *(SArray**)chIds;
+ int32_t size = taosArrayGetSize(chAy);
+ qDebug("===stream===window %" PRId64 " wait child size:%d", pWinKey->ts, size);
+ for (int32_t i = 0; i < size; i++) {
+ qDebug("===stream===window %" PRId64 " wait child id:%d", pWinKey->ts, *(int32_t*)taosArrayGet(chAy, i));
+ }
+ continue;
+ } else if (pPullDataMap) {
+ qDebug("===stream===close window %" PRId64, pWinKey->ts);
+ }
+
+ if (pTwSup->calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
+ int32_t code = saveWinResultInfo(pWinKey->ts, pWinKey->groupId, closeWins);
+ if (code != TSDB_CODE_SUCCESS) {
+ return code;
+ }
+ }
+ tSimpleHashIterateRemove(pHashMap, pWinKey, sizeof(SWinKey), &pIte, &iter);
+
+ if (needDeleteWindowBuf(&win, pTwSup)) {
+ streamStateDel(pOperator->pTaskInfo->streamInfo.pState, pWinKey);
+ }
+ }
+ }
+ return TSDB_CODE_SUCCESS;
+}
+
static void closeChildIntervalWindow(SArray* pChildren, TSKEY maxTs) {
int32_t size = taosArrayGetSize(pChildren);
for (int32_t i = 0; i < size; i++) {
@@ -1669,16 +1753,17 @@ static bool timeWindowinterpNeeded(SqlFunctionCtx* pCtx, int32_t numOfCols, SInt
}
void initIntervalDownStream(SOperatorInfo* downstream, uint16_t type, SAggSupporter* pSup, SInterval* pInterval,
- int64_t waterMark) {
+ STimeWindowAggSupp* pTwSup) {
if (downstream->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
- initIntervalDownStream(downstream->pDownstream[0], type, pSup, pInterval, waterMark);
+ initIntervalDownStream(downstream->pDownstream[0], type, pSup, pInterval, pTwSup);
return;
}
SStreamScanInfo* pScanInfo = downstream->info;
pScanInfo->windowSup.parentType = type;
pScanInfo->windowSup.pIntervalAggSup = pSup;
- pScanInfo->pUpdateInfo = updateInfoInitP(pInterval, waterMark);
+ pScanInfo->pUpdateInfo = updateInfoInitP(pInterval, pTwSup->waterMark);
pScanInfo->interval = *pInterval;
+ pScanInfo->twAggSup = *pTwSup;
}
void initStreamFunciton(SqlFunctionCtx* pCtx, int32_t numOfExpr) {
@@ -1763,11 +1848,6 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, NULL,
destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
- if (nodeType(pPhyNode) == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL) {
- initIntervalDownStream(downstream, QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL, &pInfo->aggSup, &pInfo->interval,
- pInfo->twAggSup.waterMark);
- }
-
code = appendDownstream(pOperator, &downstream, 1);
if (code != TSDB_CODE_SUCCESS) {
goto _error;
@@ -2784,6 +2864,19 @@ bool isDeletedWindow(STimeWindow* pWin, uint64_t groupId, SAggSupporter* pSup) {
return p1 == NULL;
}
+bool isDeletedStreamWindow(STimeWindow* pWin, uint64_t groupId, SOperatorInfo* pOperator, STimeWindowAggSupp* pTwSup) {
+ if (pWin->ekey < pTwSup->maxTs - pTwSup->deleteMark) {
+ SWinKey key = {.ts = pWin->skey, .groupId = groupId};
+ void* pVal = NULL;
+ int32_t size = 0;
+ if (streamStateGet(pOperator->pTaskInfo->streamInfo.pState, &key, &pVal, &size) < 0) {
+ return false;
+ }
+ streamStateReleaseBuf(pOperator->pTaskInfo->streamInfo.pState, &key, pVal);
+ }
+ return false;
+}
+
int32_t getNexWindowPos(SInterval* pInterval, SDataBlockInfo* pBlockInfo, TSKEY* tsCols, int32_t startPos, TSKEY eKey,
STimeWindow* pNextWin) {
int32_t forwardRows =
@@ -3341,7 +3434,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo,
aggEncodeResultRow, aggDecodeResultRow, NULL);
if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL) {
- initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, pInfo->twAggSup.waterMark);
+ initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup);
}
code = appendDownstream(pOperator, &downstream, 1);
if (code != TSDB_CODE_SUCCESS) {
@@ -4918,8 +5011,8 @@ static void doMergeAlignedIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultR
SExprSupp* pSup = &pOperatorInfo->exprSupp;
SInterval* pInterval = &iaInfo->interval;
- int32_t startPos = 0;
- int64_t* tsCols = extractTsCol(pBlock, iaInfo);
+ int32_t startPos = 0;
+ int64_t* tsCols = extractTsCol(pBlock, iaInfo);
TSKEY ts = getStartTsKey(&pBlock->info.window, tsCols);
@@ -4938,7 +5031,7 @@ static void doMergeAlignedIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultR
win.skey = miaInfo->curTs;
win.ekey = taosTimeAdd(win.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1;
- int32_t ret = setSingleOutputTupleBuf(pResultRowInfo, &win, &miaInfo->pResultRow, pSup, &iaInfo->aggSup);
+ int32_t ret = setSingleOutputTupleBuf(pResultRowInfo, &win, &miaInfo->pResultRow, pSup, &iaInfo->aggSup);
if (ret != TSDB_CODE_SUCCESS || miaInfo->pResultRow == NULL) {
T_LONG_JMP(pTaskInfo->env, ret);
}
@@ -4963,7 +5056,7 @@ static void doMergeAlignedIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultR
currWin.ekey = taosTimeAdd(currWin.skey, pInterval->interval, pInterval->intervalUnit, pInterval->precision) - 1;
startPos = currPos;
- ret = setSingleOutputTupleBuf(pResultRowInfo, &win, &miaInfo->pResultRow, pSup, &iaInfo->aggSup);
+ ret = setSingleOutputTupleBuf(pResultRowInfo, &win, &miaInfo->pResultRow, pSup, &iaInfo->aggSup);
if (ret != TSDB_CODE_SUCCESS || miaInfo->pResultRow == NULL) {
T_LONG_JMP(pTaskInfo->env, ret);
}
@@ -5032,7 +5125,7 @@ static void doMergeAlignedIntervalAgg(SOperatorInfo* pOperator) {
pMiaInfo->prefetchedBlock = pBlock;
cleanupAfterGroupResultGen(pMiaInfo, pRes);
break;
- } else {
+ } else {
// continue
}
}
@@ -5197,7 +5290,7 @@ static int32_t finalizeWindowResult(SOperatorInfo* pOperatorInfo, uint64_t table
SResultRowPosition* p1 = (SResultRowPosition*)tSimpleHashGet(
iaInfo->aggSup.pResultRowHashTable, iaInfo->aggSup.keyBuf, GET_RES_WINDOW_KEY_LEN(TSDB_KEYSIZE));
ASSERT(p1 != NULL);
-// finalizeResultRows(iaInfo->aggSup.pResultBuf, p1, pResultBlock, pTaskInfo);
+ // finalizeResultRows(iaInfo->aggSup.pResultBuf, p1, pResultBlock, pTaskInfo);
tSimpleHashRemove(iaInfo->aggSup.pResultRowHashTable, iaInfo->aggSup.keyBuf, GET_RES_WINDOW_KEY_LEN(TSDB_KEYSIZE));
return TSDB_CODE_SUCCESS;
}
@@ -5222,7 +5315,7 @@ static int32_t outputPrevIntervalResult(SOperatorInfo* pOperatorInfo, uint64_t t
STimeWindow* prevWin = &prevGrpWin->window;
if ((ascScan && newWin->skey > prevWin->ekey) || ((!ascScan) && newWin->skey < prevWin->ekey)) {
-// finalizeWindowResult(pOperatorInfo, tableGroupId, prevWin, pResultBlock);
+ // finalizeWindowResult(pOperatorInfo, tableGroupId, prevWin, pResultBlock);
tdListPopNode(miaInfo->groupIntervals, listNode);
}
}
@@ -5382,7 +5475,7 @@ static SSDataBlock* doMergeIntervalAgg(SOperatorInfo* pOperator) {
if (listNode != NULL) {
SGroupTimeWindow* grpWin = (SGroupTimeWindow*)(listNode->data);
-// finalizeWindowResult(pOperator, grpWin->groupId, &grpWin->window, pRes);
+ // finalizeWindowResult(pOperator, grpWin->groupId, &grpWin->window, pRes);
pRes->info.groupId = grpWin->groupId;
}
}
@@ -5591,7 +5684,7 @@ static void doStreamIntervalAggImpl2(SOperatorInfo* pOperatorInfo, SSDataBlock*
forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, NULL,
TSDB_ORDER_ASC);
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdatedMap) {
- saveWinResultRow(pResult, tableGroupId, pUpdatedMap);
+ saveWinResultInfo(pResult->win.skey, tableGroupId, pUpdatedMap);
}
updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, true);
doApplyFunctions(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows,
@@ -5600,7 +5693,7 @@ static void doStreamIntervalAggImpl2(SOperatorInfo* pOperatorInfo, SSDataBlock*
.ts = nextWin.skey,
.groupId = tableGroupId,
};
- saveOutput(pTaskInfo, &key, pResult, pInfo->aggSup.resultRowSize);
+ saveOutputBuf(pTaskInfo, &key, pResult, pInfo->aggSup.resultRowSize);
releaseOutputBuf(pTaskInfo, &key, pResult);
int32_t prevEndPos = (forwardRows - 1) * step + startPos;
ASSERT(pSDataBlock->info.window.skey > 0 && pSDataBlock->info.window.ekey > 0);
@@ -5645,7 +5738,8 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
return pInfo->pDelRes;
}
- doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
+ doBuildResult(pOperator, pInfo->binfo.pRes, &pInfo->groupResInfo);
+ // doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainResults(&pInfo->groupResInfo)) {
pOperator->status = OP_EXEC_DONE;
qDebug("===stream===single interval is done");
@@ -5671,13 +5765,14 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
printDataBlock(pBlock, "single interval recv");
if (pBlock->info.type == STREAM_CLEAR) {
- doClearWindows(&pInfo->aggSup, &pOperator->exprSupp, &pInfo->interval, pOperator->exprSupp.numOfExprs, pBlock,
- NULL);
+ doDeleteWindows(pOperator, &pInfo->interval, pOperator->exprSupp.numOfExprs, pBlock, NULL, NULL);
qDebug("%s clear existed time window results for updates checked", GET_TASKID(pTaskInfo));
continue;
} else if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT) {
- doDeleteSpecifyIntervalWindow(&pInfo->aggSup, &pInfo->twAggSup, pBlock, pInfo->pDelWins, &pInfo->interval,
- pUpdatedMap);
+ // doDeleteSpecifyIntervalWindow(&pInfo->aggSup, &pInfo->twAggSup, pBlock, pInfo->pDelWins, &pInfo->interval,
+ // pUpdatedMap);
+ doDeleteWindows(pOperator, &pInfo->interval, pOperator->exprSupp.numOfExprs, pBlock, pInfo->pDelWins,
+ pUpdatedMap);
continue;
} else if (pBlock->info.type == STREAM_GET_ALL) {
getAllIntervalWindow(pInfo->aggSup.pResultRowHashTable, pUpdatedMap);
@@ -5704,9 +5799,9 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
maxTs = TMAX(maxTs, pBlock->info.window.ekey);
minTs = TMIN(minTs, pBlock->info.window.skey);
- doStreamIntervalAggImpl(pOperator, &pInfo->binfo.resultRowInfo, pBlock, MAIN_SCAN, pUpdatedMap);
+ // doStreamIntervalAggImpl(pOperator, &pInfo->binfo.resultRowInfo, pBlock, MAIN_SCAN, pUpdatedMap);
// new disc buf
- /*doStreamIntervalAggImpl2(pOperator, pBlock, pBlock->info.groupId, pUpdatedMap);*/
+ doStreamIntervalAggImpl2(pOperator, pBlock, pBlock->info.groupId, pUpdatedMap);
}
pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs);
pInfo->twAggSup.minTs = TMIN(pInfo->twAggSup.minTs, minTs);
@@ -5741,8 +5836,8 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
#endif
pOperator->status = OP_RES_TO_RETURN;
- closeIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, NULL, pUpdatedMap,
- pInfo->pRecycledPages, pInfo->aggSup.pResultBuf);
+ closeStreamIntervalWindow(pInfo->aggSup.pResultRowHashTable, &pInfo->twAggSup, &pInfo->interval, NULL, pUpdatedMap,
+ pOperator);
void* pIte = NULL;
while ((pIte = taosHashIterate(pUpdatedMap, pIte)) != NULL) {
@@ -5751,7 +5846,8 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
taosArraySort(pUpdated, resultrowComparAsc);
// new disc buf
- finalizeUpdatedResult(pOperator->exprSupp.numOfExprs, pInfo->aggSup.pResultBuf, pUpdated, pSup->rowEntryInfoOffset);
+ // finalizeUpdatedResult(pOperator->exprSupp.numOfExprs, pInfo->aggSup.pResultBuf, pUpdated,
+ // pSup->rowEntryInfoOffset);
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
removeDeleteResults(pUpdatedMap, pInfo->pDelWins);
@@ -5762,9 +5858,9 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
return pInfo->pDelRes;
}
- doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
+ // doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf);
// new disc buf
- // doBuildResult(pOperator, pInfo->binfo.pRes, &pInfo->groupResInfo);
+ doBuildResult(pOperator, pInfo->binfo.pRes, &pInfo->groupResInfo);
printDataBlock(pInfo->binfo.pRes, "single interval");
return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes;
}
@@ -5809,6 +5905,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
.calTrigger = pIntervalPhyNode->window.triggerType,
.maxTs = INT64_MIN,
.minTs = INT64_MAX,
+ .deleteMark = INT64_MAX,
};
ASSERT(twAggSupp.calTrigger != STREAM_TRIGGER_MAX_DELAY);
pOperator->pTaskInfo = pTaskInfo;
@@ -5856,7 +5953,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
createOperatorFpSet(operatorDummyOpenFn, doStreamIntervalAgg, NULL, NULL, destroyStreamIntervalOperatorInfo,
aggEncodeResultRow, aggDecodeResultRow, NULL);
- initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, pInfo->twAggSup.waterMark);
+ initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup);
code = appendDownstream(pOperator, &downstream, 1);
if (code != TSDB_CODE_SUCCESS) {
goto _error;
diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c
index 9b502eded7..a23f58a732 100644
--- a/source/libs/function/src/builtinsimpl.c
+++ b/source/libs/function/src/builtinsimpl.c
@@ -5297,12 +5297,12 @@ bool modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) {
}
static void doModeAdd(SModeInfo* pInfo, char* data) {
- int32_t hashKeyBytes = IS_VAR_DATA_TYPE(pInfo->colType) ? varDataTLen(data) : pInfo->colBytes;
+ int32_t hashKeyBytes = IS_STR_DATA_TYPE(pInfo->colType) ? varDataTLen(data) : pInfo->colBytes;
SModeItem** pHashItem = taosHashGet(pInfo->pHash, data, hashKeyBytes);
if (pHashItem == NULL) {
int32_t size = sizeof(SModeItem) + pInfo->colBytes;
SModeItem* pItem = (SModeItem*)(pInfo->pItems + pInfo->numOfPoints * size);
- memcpy(pItem->data, data, pInfo->colBytes);
+ memcpy(pItem->data, data, hashKeyBytes);
pItem->count += 1;
taosHashPut(pInfo->pHash, data, hashKeyBytes, &pItem, sizeof(SModeItem*));
diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c
index 3f472b53a0..62427e0488 100644
--- a/source/libs/function/src/tudf.c
+++ b/source/libs/function/src/tudf.c
@@ -961,6 +961,7 @@ void releaseUdfFuncHandle(char* udfName) {
strcpy(key.udfName, udfName);
SUdfcFuncStub *foundStub = taosArraySearch(gUdfdProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ);
if (!foundStub) {
+ uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
return;
}
if (foundStub->refCount > 0) {
diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c
index a45e4585e8..636f006d6e 100644
--- a/source/libs/function/src/udfd.c
+++ b/source/libs/function/src/udfd.c
@@ -41,6 +41,8 @@ typedef struct SUdfdContext {
uv_mutex_t udfsMutex;
SHashObj * udfsHash;
+ SArray* residentFuncs;
+
bool printVersion;
} SUdfdContext;
@@ -67,6 +69,7 @@ typedef struct SUdf {
EUdfState state;
uv_mutex_t lock;
uv_cond_t condReady;
+ bool resident;
char name[TSDB_FUNC_NAME_LEN];
int8_t funcType;
@@ -200,6 +203,14 @@ void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
if (udf->initFunc) {
udf->initFunc();
}
+ udf->resident = false;
+ for (int32_t i = 0; i < taosArrayGetSize(global.residentFuncs); ++i) {
+ char* funcName = taosArrayGet(global.residentFuncs, i);
+ if (strcmp(setup->udfName, funcName) == 0) {
+ udf->resident = true;
+ break;
+ }
+ }
udf->state = UDF_STATE_READY;
uv_cond_broadcast(&udf->condReady);
uv_mutex_unlock(&udf->lock);
@@ -345,7 +356,7 @@ void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
uv_mutex_lock(&global.udfsMutex);
udf->refCount--;
- if (udf->refCount == 0) {
+ if (udf->refCount == 0 && !udf->resident) {
unloadUdf = true;
taosHashRemove(global.udfsHash, udf->name, strlen(udf->name));
}
@@ -576,9 +587,9 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggFinishFunc));
char mergeFuncName[TSDB_FUNC_NAME_LEN + 6] = {0};
char *mergeSuffix = "_merge";
- strncpy(finishFuncName, processFuncName, sizeof(finishFuncName));
- strncat(finishFuncName, mergeSuffix, strlen(mergeSuffix));
- uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggMergeFunc));
+ strncpy(mergeFuncName, processFuncName, sizeof(mergeFuncName));
+ strncat(mergeFuncName, mergeSuffix, strlen(mergeSuffix));
+ uv_dlsym(&udf->lib, mergeFuncName, (void **)(&udf->aggMergeFunc));
}
return 0;
}
@@ -919,8 +930,6 @@ static int32_t udfdRun() {
uv_run(global.loop, UV_RUN_DEFAULT);
uv_loop_close(global.loop);
- uv_mutex_destroy(&global.udfsMutex);
- taosHashCleanup(global.udfsHash);
return 0;
}
@@ -941,6 +950,47 @@ void udfdConnectMnodeThreadFunc(void *args) {
}
}
+int32_t udfdInitResidentFuncs() {
+ if (strlen(tsUdfdResFuncs) == 0) {
+ return TSDB_CODE_SUCCESS;
+ }
+
+ global.residentFuncs = taosArrayInit(2, TSDB_FUNC_NAME_LEN);
+ char* pSave = tsUdfdResFuncs;
+ char* token;
+ while ((token = strtok_r(pSave, ",", &pSave)) != NULL) {
+ char func[TSDB_FUNC_NAME_LEN] = {0};
+ strncpy(func, token, strlen(token));
+ taosArrayPush(global.residentFuncs, func);
+ }
+
+ return TSDB_CODE_SUCCESS;
+}
+
+int32_t udfdDeinitResidentFuncs() {
+ for (int32_t i = 0; i < taosArrayGetSize(global.residentFuncs); ++i) {
+ char* funcName = taosArrayGet(global.residentFuncs, i);
+ SUdf** udfInHash = taosHashGet(global.udfsHash, funcName, strlen(funcName));
+ if (udfInHash) {
+ taosHashRemove(global.udfsHash, funcName, strlen(funcName));
+ SUdf* udf = *udfInHash;
+ if (udf->destroyFunc) {
+ (udf->destroyFunc)();
+ }
+ uv_dlclose(&udf->lib);
+ taosMemoryFree(udf);
+ }
+ }
+ taosArrayDestroy(global.residentFuncs);
+ return TSDB_CODE_SUCCESS;
+}
+
+int32_t udfdCleanup() {
+ uv_mutex_destroy(&global.udfsMutex);
+ taosHashCleanup(global.udfsHash);
+ return 0;
+}
+
int main(int argc, char *argv[]) {
if (!taosCheckSystemIsLittleEnd()) {
printf("failed to start since on non-little-end machines\n");
@@ -978,6 +1028,8 @@ int main(int argc, char *argv[]) {
return -5;
}
+ udfdInitResidentFuncs();
+
uv_thread_t mnodeConnectThread;
uv_thread_create(&mnodeConnectThread, udfdConnectMnodeThreadFunc, NULL);
@@ -986,5 +1038,7 @@ int main(int argc, char *argv[]) {
removeListeningPipe();
udfdCloseClientRpc();
+ udfdDeinitResidentFuncs();
+ udfdCleanup();
return 0;
}
diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c
index 1af61b0ca8..ca9bb16c05 100644
--- a/source/libs/parser/src/parInsert.c
+++ b/source/libs/parser/src/parInsert.c
@@ -1059,7 +1059,7 @@ end:
for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
STagVal* p = (STagVal*)taosArrayGet(pTagVals, i);
if (IS_VAR_DATA_TYPE(p->type)) {
- taosMemoryFree(p->pData);
+ taosMemoryFreeClear(p->pData);
}
}
taosArrayDestroy(pTagVals);
@@ -2040,7 +2040,7 @@ end:
for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
if (p->type == TSDB_DATA_TYPE_NCHAR) {
- taosMemoryFree(p->pData);
+ taosMemoryFreeClear(p->pData);
}
}
taosArrayDestroy(pTagArray);
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index ea9eefbb29..f0d5e5d67e 100644
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -6664,12 +6664,7 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
break;
}
} while (0);
- for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
- STagVal* p = (STagVal*)taosArrayGet(pTagVals, i);
- if (IS_VAR_DATA_TYPE(p->type)) {
- taosMemoryFree(p->pData);
- }
- }
+
taosArrayDestroy(pTagVals);
if (code != TSDB_CODE_SUCCESS) {
return code;
diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c
index daab80667c..3075be1a00 100644
--- a/source/libs/parser/src/parUtil.c
+++ b/source/libs/parser/src/parUtil.c
@@ -410,6 +410,12 @@ end:
if (retCode == TSDB_CODE_SUCCESS) {
tTagNew(pTagVals, 1, true, ppTag);
}
+ for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
+ STagVal* p = (STagVal*)taosArrayGet(pTagVals, i);
+ if (IS_VAR_DATA_TYPE(p->type)) {
+ taosMemoryFreeClear(p->pData);
+ }
+ }
cJSON_Delete(root);
return retCode;
}
diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c
index 3af3786363..106e674152 100644
--- a/source/libs/planner/src/planSpliter.c
+++ b/source/libs/planner/src/planSpliter.c
@@ -915,20 +915,30 @@ static int32_t stbSplSplitSortNode(SSplitContext* pCxt, SStableSplitInfo* pInfo)
}
static int32_t stbSplSplitScanNodeWithoutPartTags(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
- int32_t code = splCreateExchangeNodeForSubplan(pCxt, pInfo->pSubplan, pInfo->pSplitNode, SUBPLAN_TYPE_MERGE);
+ SLogicNode* pSplitNode = pInfo->pSplitNode;
+ if (NULL != pInfo->pSplitNode->pParent && QUERY_NODE_LOGIC_PLAN_PROJECT == nodeType(pInfo->pSplitNode->pParent) &&
+ NULL == pInfo->pSplitNode->pParent->pLimit && NULL == pInfo->pSplitNode->pParent->pSlimit) {
+ pSplitNode = pInfo->pSplitNode->pParent;
+ }
+ int32_t code = splCreateExchangeNodeForSubplan(pCxt, pInfo->pSubplan, pSplitNode, SUBPLAN_TYPE_MERGE);
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
- (SNode*)splCreateScanSubplan(pCxt, pInfo->pSplitNode, SPLIT_FLAG_STABLE_SPLIT));
+ (SNode*)splCreateScanSubplan(pCxt, pSplitNode, SPLIT_FLAG_STABLE_SPLIT));
}
++(pCxt->groupId);
return code;
}
static int32_t stbSplSplitScanNodeWithPartTags(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
- int32_t code = stbSplCreateMergeNode(pCxt, pInfo->pSubplan, pInfo->pSplitNode, NULL, pInfo->pSplitNode, true);
+ SLogicNode* pSplitNode = pInfo->pSplitNode;
+ if (NULL != pInfo->pSplitNode->pParent && QUERY_NODE_LOGIC_PLAN_PROJECT == nodeType(pInfo->pSplitNode->pParent) &&
+ NULL == pInfo->pSplitNode->pParent->pLimit && NULL == pInfo->pSplitNode->pParent->pSlimit) {
+ pSplitNode = pInfo->pSplitNode->pParent;
+ }
+ int32_t code = stbSplCreateMergeNode(pCxt, pInfo->pSubplan, pSplitNode, NULL, pSplitNode, true);
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
- (SNode*)splCreateScanSubplan(pCxt, pInfo->pSplitNode, SPLIT_FLAG_STABLE_SPLIT));
+ (SNode*)splCreateScanSubplan(pCxt, pSplitNode, SPLIT_FLAG_STABLE_SPLIT));
}
pInfo->pSubplan->subplanType = SUBPLAN_TYPE_MERGE;
++(pCxt->groupId);
diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c
index ecc25e9c2d..c38c9ac1cf 100644
--- a/source/libs/qworker/src/qwMsg.c
+++ b/source/libs/qworker/src/qwMsg.c
@@ -632,6 +632,7 @@ int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SD
QW_ERR_JRET(qwProcessDelete(QW_FPARAMS(), &qwMsg, pRes));
+ taosMemoryFreeClear(req.msg);
QW_SCH_TASK_DLOG("processDelete end, node:%p", node);
_return:
diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c
index d6e87c2736..4a63cd3bb2 100644
--- a/source/libs/stream/src/stream.c
+++ b/source/libs/stream/src/stream.c
@@ -182,7 +182,7 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, S
pReq->upstreamTaskId);
streamTaskEnqueue(pTask, pReq, pRsp);
- tFreeStreamDispatchReq(pReq);
+ tDeleteStreamDispatchReq(pReq);
if (exec) {
if (streamTryExec(pTask) < 0) {
diff --git a/source/libs/stream/src/streamData.c b/source/libs/stream/src/streamData.c
index cd5f499c34..e6705a77b2 100644
--- a/source/libs/stream/src/streamData.c
+++ b/source/libs/stream/src/streamData.c
@@ -179,5 +179,15 @@ void streamFreeQitem(SStreamQueueItem* data) {
taosArrayDestroy(pMerge->reqs);
taosArrayDestroy(pMerge->dataRefs);
taosFreeQitem(pMerge);
+ } else if (type == STREAM_INPUT__REF_DATA_BLOCK) {
+ SStreamRefDataBlock* pRefBlock = (SStreamRefDataBlock*)data;
+
+ int32_t ref = atomic_sub_fetch_32(pRefBlock->dataRef, 1);
+ ASSERT(ref >= 0);
+ if (ref == 0) {
+ blockDataDestroy(pRefBlock->pBlock);
+ taosMemoryFree(pRefBlock->dataRef);
+ }
+ taosFreeQitem(pRefBlock);
}
}
diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c
index 7cdb7c0db9..e6960ae350 100644
--- a/source/libs/stream/src/streamDispatch.c
+++ b/source/libs/stream/src/streamDispatch.c
@@ -62,7 +62,7 @@ int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq) {
return 0;
}
-void tFreeStreamDispatchReq(SStreamDispatchReq* pReq) {
+void tDeleteStreamDispatchReq(SStreamDispatchReq* pReq) {
taosArrayDestroyP(pReq->data, taosMemoryFree);
taosArrayDestroy(pReq->dataLen);
}
@@ -95,7 +95,10 @@ int32_t tDecodeStreamRetrieveReq(SDecoder* pDecoder, SStreamRetrieveReq* pReq) {
return 0;
}
+void tDeleteStreamRetrieveReq(SStreamRetrieveReq* pReq) { taosMemoryFree(pReq->pRetrieve); }
+
int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock) {
+ int32_t code = -1;
SRetrieveTableRsp* pRetrieve = NULL;
void* buf = NULL;
int32_t dataStrLen = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock);
@@ -143,7 +146,7 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock)
buf = rpcMallocCont(sizeof(SMsgHead) + len);
if (buf == NULL) {
- goto FAIL;
+ goto CLEAR;
}
((SMsgHead*)buf)->vgId = htonl(pEpInfo->nodeId);
@@ -151,6 +154,7 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock)
SEncoder encoder;
tEncoderInit(&encoder, abuf, len);
tEncodeStreamRetrieveReq(&encoder, &req);
+ tEncoderClear(&encoder);
SRpcMsg rpcMsg = {
.code = 0,
@@ -161,17 +165,18 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock)
if (tmsgSendReq(&pEpInfo->epSet, &rpcMsg) < 0) {
ASSERT(0);
- return -1;
+ goto CLEAR;
}
+ buf = NULL;
qDebug("task %d(child %d) send retrieve req to task %d at node %d, reqId %" PRId64, pTask->taskId,
pTask->selfChildId, pEpInfo->taskId, pEpInfo->nodeId, req.reqId);
}
- return 0;
-FAIL:
- if (pRetrieve) taosMemoryFree(pRetrieve);
- if (buf) taosMemoryFree(buf);
- return -1;
+ code = 0;
+CLEAR:
+ taosMemoryFree(pRetrieve);
+ rpcFreeCont(buf);
+ return code;
}
static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDispatchReq* pReq) {
diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c
index 102bad7426..5ad5aa549d 100644
--- a/source/libs/stream/src/streamExec.c
+++ b/source/libs/stream/src/streamExec.c
@@ -38,6 +38,9 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
SArray* blocks = pMerged->reqs;
qDebug("task %d %p set submit input (merged), batch num: %d", pTask->taskId, pTask, (int32_t)blocks->size);
qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__MERGED_SUBMIT);
+ } else if (pItem->type == STREAM_INPUT__REF_DATA_BLOCK) {
+ const SStreamRefDataBlock* pRefBlock = (const SStreamRefDataBlock*)data;
+ qSetMultiStreamInput(exec, pRefBlock->pBlock, 1, STREAM_INPUT__DATA_BLOCK);
} else {
ASSERT(0);
}
diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c
index 6cd5132bb9..fde8bca77b 100644
--- a/source/libs/stream/src/streamState.c
+++ b/source/libs/stream/src/streamState.c
@@ -18,14 +18,19 @@
#include "tcommon.h"
#include "ttimer.h"
-SStreamState* streamStateOpen(char* path, SStreamTask* pTask) {
+SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath) {
SStreamState* pState = taosMemoryCalloc(1, sizeof(SStreamState));
if (pState == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
+
char statePath[300];
- sprintf(statePath, "%s/%d", path, pTask->taskId);
+ if (!specPath) {
+ sprintf(statePath, "%s/%d", path, pTask->taskId);
+ } else {
+ memcpy(statePath, path, 300);
+ }
if (tdbOpen(statePath, 4096, 256, &pState->db) < 0) {
goto _err;
}
@@ -135,15 +140,9 @@ int32_t streamStateAddIfNotExist(SStreamState* pState, const SWinKey* key, void*
if (streamStateGet(pState, key, pVal, pVLen) == 0) {
return 0;
}
- void* tmp = taosMemoryCalloc(1, size);
- if (streamStatePut(pState, key, &tmp, size) == 0) {
- taosMemoryFree(tmp);
- int32_t code = streamStateGet(pState, key, pVal, pVLen);
- ASSERT(code == 0);
- return code;
- }
- taosMemoryFree(tmp);
- return -1;
+ *pVal = tdbRealloc(NULL, size);
+ memset(*pVal, 0, size);
+ return 0;
}
int32_t streamStateReleaseBuf(SStreamState* pState, const SWinKey* key, void* pVal) {
@@ -191,9 +190,14 @@ SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const SWinKey* key
if (pCur == NULL) {
return NULL;
}
+ if (tdbTbcOpen(pState->pStateDb, &pCur->pCur, NULL) < 0) {
+ taosMemoryFree(pCur);
+ return NULL;
+ }
int32_t c;
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
+ tdbTbcClose(pCur->pCur);
taosMemoryFree(pCur);
return NULL;
}
@@ -212,9 +216,14 @@ SStreamStateCur* streamStateSeekKeyPrev(SStreamState* pState, const SWinKey* key
if (pCur == NULL) {
return NULL;
}
+ if (tdbTbcOpen(pState->pStateDb, &pCur->pCur, NULL) < 0) {
+ taosMemoryFree(pCur);
+ return NULL;
+ }
int32_t c;
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
+ tdbTbcClose(pCur->pCur);
taosMemoryFree(pCur);
return NULL;
}
diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c
index 1e68fe346c..b604d25816 100644
--- a/source/libs/sync/src/syncCommit.c
+++ b/source/libs/sync/src/syncCommit.c
@@ -69,15 +69,26 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
if (agree) {
// term
- SSyncRaftEntry* pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, index);
- ASSERT(pEntry != NULL);
-
+ SSyncRaftEntry* pEntry = NULL;
+ SLRUCache* pCache = pSyncNode->pLogStore->pCache;
+ LRUHandle* h = taosLRUCacheLookup(pCache, &index, sizeof(index));
+ if (h) {
+ pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h);
+ } else {
+ pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, index);
+ ASSERT(pEntry != NULL);
+ }
// cannot commit, even if quorum agree. need check term!
if (pEntry->term <= pSyncNode->pRaftStore->currentTerm) {
// update commit index
newCommitIndex = index;
- syncEntryDestory(pEntry);
+ if (h) {
+ taosLRUCacheRelease(pCache, h, false);
+ } else {
+ syncEntryDestory(pEntry);
+ }
+
break;
} else {
do {
@@ -88,7 +99,11 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
} while (0);
}
- syncEntryDestory(pEntry);
+ if (h) {
+ taosLRUCacheRelease(pCache, h, false);
+ } else {
+ syncEntryDestory(pEntry);
+ }
}
}
diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c
index 6f29b54f80..17157fbd23 100644
--- a/source/libs/sync/src/syncMain.c
+++ b/source/libs/sync/src/syncMain.c
@@ -2581,6 +2581,20 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) {
return ret;
}
+static void deleteCacheEntry(const void* key, size_t keyLen, void* value) { taosMemoryFree(value); }
+
+static int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHandle** h) {
+ int code = 0;
+ int entryLen = sizeof(*pEntry) + pEntry->dataLen;
+ LRUStatus status = taosLRUCacheInsert(pLogStore->pCache, &pEntry->index, sizeof(pEntry->index), pEntry, entryLen,
+ deleteCacheEntry, h, TAOS_LRU_PRIORITY_LOW);
+ if (status != TAOS_LRU_STATUS_OK) {
+ code = -1;
+ }
+
+ return code;
+}
+
static int32_t syncNodeAppendNoop(SSyncNode* ths) {
int32_t ret = 0;
@@ -2589,13 +2603,21 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId);
ASSERT(pEntry != NULL);
+ LRUHandle* h = NULL;
+ syncCacheEntry(ths->pLogStore, pEntry, &h);
+
if (ths->state == TAOS_SYNC_STATE_LEADER) {
int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
ASSERT(code == 0);
syncNodeReplicate(ths, false);
}
- syncEntryDestory(pEntry);
+ if (h) {
+ taosLRUCacheRelease(ths->pLogStore->pCache, h, false);
+ } else {
+ syncEntryDestory(pEntry);
+ }
+
return ret;
}
@@ -2654,6 +2676,9 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
SSyncRaftEntry* pEntry = syncEntryBuild2((SyncClientRequest*)pMsg, term, index);
ASSERT(pEntry != NULL);
+ LRUHandle* h = NULL;
+ syncCacheEntry(ths->pLogStore, pEntry, &h);
+
if (ths->state == TAOS_SYNC_STATE_LEADER) {
// append entry
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
@@ -2685,7 +2710,12 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
}
}
- syncEntryDestory(pEntry);
+ if (h) {
+ taosLRUCacheRelease(ths->pLogStore->pCache, h, false);
+ } else {
+ syncEntryDestory(pEntry);
+ }
+
return ret;
}
@@ -2973,9 +3003,15 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
if (i != SYNC_INDEX_INVALID) {
SSyncRaftEntry* pEntry;
- code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, i, &pEntry);
- ASSERT(code == 0);
- ASSERT(pEntry != NULL);
+ SLRUCache* pCache = ths->pLogStore->pCache;
+ LRUHandle* h = taosLRUCacheLookup(pCache, &i, sizeof(i));
+ if (h) {
+ pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h);
+ } else {
+ code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, i, &pEntry);
+ ASSERT(code == 0);
+ ASSERT(pEntry != NULL);
+ }
SRpcMsg rpcMsg;
syncEntry2OriginalRpc(pEntry, &rpcMsg);
@@ -3058,7 +3094,11 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
}
rpcFreeCont(rpcMsg.pCont);
- syncEntryDestory(pEntry);
+ if (h) {
+ taosLRUCacheRelease(pCache, h, false);
+ } else {
+ syncEntryDestory(pEntry);
+ }
}
}
}
diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c
index 0649e064e4..496c8419de 100644
--- a/source/libs/sync/src/syncRaftLog.c
+++ b/source/libs/sync/src/syncRaftLog.c
@@ -53,6 +53,15 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore));
ASSERT(pLogStore != NULL);
+ pLogStore->pCache = taosLRUCacheInit(10 * 1024 * 1024, 1, .5);
+ if (pLogStore->pCache == NULL) {
+ terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
+ taosMemoryFree(pLogStore);
+ return NULL;
+ }
+
+ taosLRUCacheSetStrictCapacity(pLogStore->pCache, false);
+
pLogStore->data = taosMemoryMalloc(sizeof(SSyncLogStoreData));
ASSERT(pLogStore->data != NULL);
@@ -102,6 +111,10 @@ void logStoreDestory(SSyncLogStore* pLogStore) {
taosThreadMutexDestroy(&(pData->mutex));
taosMemoryFree(pLogStore->data);
+
+ taosLRUCacheEraseUnrefEntries(pLogStore->pCache);
+ taosLRUCacheCleanup(pLogStore->pCache);
+
taosMemoryFree(pLogStore);
}
}
@@ -243,7 +256,7 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry) {
SSyncLogStoreData* pData = pLogStore->data;
SWal* pWal = pData->pWal;
- int32_t code;
+ int32_t code = 0;
*ppEntry = NULL;
@@ -257,6 +270,7 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index,
taosThreadMutexLock(&(pData->mutex));
code = walReadVer(pWalHandle, index);
+ // code = walReadVerCached(pWalHandle, index);
if (code != 0) {
int32_t err = terrno;
const char* errStr = tstrerror(err);
@@ -412,6 +426,7 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
ASSERT(pWalHandle != NULL);
int32_t code = walReadVer(pWalHandle, index);
+ // int32_t code = walReadVerCached(pWalHandle, index);
if (code != 0) {
int32_t err = terrno;
const char* errStr = tstrerror(err);
diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c
index 543ffc55b6..04711eb6a0 100644
--- a/source/libs/tdb/src/db/tdbPager.c
+++ b/source/libs/tdb/src/db/tdbPager.c
@@ -248,6 +248,7 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
return 0;
}
+ // loop to write the dirty pages to file
SRBTreeIter iter = tRBTreeIterCreate(&pPager->rbt, 1);
SRBTreeNode *pNode = NULL;
while ((pNode = tRBTreeIterNext(&iter)) != NULL) {
@@ -257,6 +258,15 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
ASSERT(0);
return -1;
}
+ }
+
+ tdbTrace("tdbttl commit:%p, %d/%d", pPager, pPager->dbOrigSize, pPager->dbFileSize);
+ pPager->dbOrigSize = pPager->dbFileSize;
+
+ // release the page
+ iter = tRBTreeIterCreate(&pPager->rbt, 1);
+ while ((pNode = tRBTreeIterNext(&iter)) != NULL) {
+ pPage = (SPage *)pNode;
pPage->isDirty = 0;
@@ -265,29 +275,6 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
}
tRBTreeCreate(&pPager->rbt, pageCmpFn);
- /*
- // loop to write the dirty pages to file
- for (pPage = pPager->pDirty; pPage; pPage = pPage->pDirtyNext) {
- // TODO: update the page footer
- ret = tdbPagerWritePageToDB(pPager, pPage);
- if (ret < 0) {
- ASSERT(0);
- return -1;
- }
- }
-
- // release the page
- for (pPage = pPager->pDirty; pPage; pPage = pPager->pDirty) {
- pPager->pDirty = pPage->pDirtyNext;
- pPage->pDirtyNext = NULL;
-
- pPage->isDirty = 0;
-
- tdbPCacheRelease(pPager->pCache, pPage, pTxn);
- }
- */
- tdbTrace("tdbttl commit:%p, %d", pPager, pPager->dbOrigSize);
- pPager->dbOrigSize = pPager->dbFileSize;
// sync the db file
tdbOsFSync(pPager->fd);
diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c
index 93ced912f8..5284aeff77 100644
--- a/source/libs/wal/src/walMeta.c
+++ b/source/libs/wal/src/walMeta.c
@@ -268,7 +268,7 @@ int walRollFileInfo(SWal* pWal) {
char* walMetaSerialize(SWal* pWal) {
char buf[30];
ASSERT(pWal->fileInfoSet);
- int sz = pWal->fileInfoSet->size;
+ int sz = taosArrayGetSize(pWal->fileInfoSet);
cJSON* pRoot = cJSON_CreateObject();
cJSON* pMeta = cJSON_CreateObject();
cJSON* pFiles = cJSON_CreateArray();
@@ -384,8 +384,10 @@ static int walFindCurMetaVer(SWal* pWal) {
int code = regexec(&walMetaRegexPattern, name, 0, NULL, 0);
if (code == 0) {
sscanf(name, "meta-ver%d", &metaVer);
+ wDebug("vgId:%d, wal find current meta: %s is the meta file, ver %d", pWal->cfg.vgId, name, metaVer);
break;
}
+ wDebug("vgId:%d, wal find current meta: %s is not meta file", pWal->cfg.vgId, name);
}
taosCloseDir(&pDir);
regfree(&walMetaRegexPattern);
@@ -422,6 +424,7 @@ int walLoadMeta(SWal* pWal) {
// find existing meta file
int metaVer = walFindCurMetaVer(pWal);
if (metaVer == -1) {
+ wDebug("vgId:%d wal find meta ver %d", pWal->cfg.vgId, metaVer);
return -1;
}
char fnameStr[WAL_FILE_LEN];
diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c
index ba877915b1..62b9d87628 100644
--- a/source/util/src/tcompression.c
+++ b/source/util/src/tcompression.c
@@ -50,6 +50,7 @@
#define _DEFAULT_SOURCE
#include "tcompression.h"
#include "lz4.h"
+#include "tRealloc.h"
#include "tlog.h"
#ifdef TD_TSZ
@@ -814,24 +815,24 @@ int32_t tsCompressFloatImp(const char *const input, const int32_t nelements, cha
uint32_t predicted = prev_value;
uint32_t diff = curr.bits ^ predicted;
- int32_t leading_zeros = FLOAT_BYTES * BITS_PER_BYTE;
- int32_t trailing_zeros = leading_zeros;
+ int32_t clz = FLOAT_BYTES * BITS_PER_BYTE;
+ int32_t ctz = clz;
if (diff) {
- trailing_zeros = BUILDIN_CTZ(diff);
- leading_zeros = BUILDIN_CLZ(diff);
+ ctz = BUILDIN_CTZ(diff);
+ clz = BUILDIN_CLZ(diff);
}
uint8_t nbytes = 0;
uint8_t flag;
- if (trailing_zeros > leading_zeros) {
- nbytes = (uint8_t)(FLOAT_BYTES - trailing_zeros / BITS_PER_BYTE);
+ if (ctz > clz) {
+ nbytes = (uint8_t)(FLOAT_BYTES - ctz / BITS_PER_BYTE);
if (nbytes > 0) nbytes--;
flag = ((uint8_t)1 << 3) | nbytes;
} else {
- nbytes = (uint8_t)(FLOAT_BYTES - leading_zeros / BITS_PER_BYTE);
+ nbytes = (uint8_t)(FLOAT_BYTES - clz / BITS_PER_BYTE);
if (nbytes > 0) nbytes--;
flag = nbytes;
}
@@ -994,3 +995,621 @@ int32_t tsDecompressDoubleLossyImp(const char *input, int32_t compressedSize, co
return tdszDecompress(SZ_DOUBLE, input + 1, compressedSize - 1, nelements, output);
}
#endif
+
+/*************************************************************************
+ * STREAM COMPRESSION
+ *************************************************************************/
+#define I64_SAFE_ADD(a, b) (((a) >= 0 && (b) <= INT64_MAX - (b)) || ((a) < 0 && (b) >= INT64_MIN - (a)))
+typedef struct SCompressor SCompressor;
+
+static int32_t tCompBool(SCompressor *pCmprsor, const void *pData, int32_t nData);
+static int32_t tCompInt(SCompressor *pCmprsor, const void *pData, int32_t nData);
+static int32_t tCompFloat(SCompressor *pCmprsor, const void *pData, int32_t nData);
+static int32_t tCompDouble(SCompressor *pCmprsor, const void *pData, int32_t nData);
+static int32_t tCompTimestamp(SCompressor *pCmprsor, const void *pData, int32_t nData);
+static int32_t tCompBinary(SCompressor *pCmprsor, const void *pData, int32_t nData);
+static struct {
+ int8_t type;
+ int32_t bytes;
+ int8_t isVarLen;
+ int32_t (*cmprFn)(SCompressor *, const void *, int32_t nData);
+} DATA_TYPE_INFO[] = {
+ {TSDB_DATA_TYPE_NULL, 0, 0, NULL}, // TSDB_DATA_TYPE_NULL
+ {TSDB_DATA_TYPE_BOOL, 1, 0, tCompBool}, // TSDB_DATA_TYPE_BOOL
+ {TSDB_DATA_TYPE_TINYINT, 1, 0, tCompInt}, // TSDB_DATA_TYPE_TINYINT
+ {TSDB_DATA_TYPE_SMALLINT, 2, 0, tCompInt}, // TSDB_DATA_TYPE_SMALLINT
+ {TSDB_DATA_TYPE_INT, 4, 0, tCompInt}, // TSDB_DATA_TYPE_INT
+ {TSDB_DATA_TYPE_BIGINT, 8, 0, tCompInt}, // TSDB_DATA_TYPE_BIGINT
+ {TSDB_DATA_TYPE_FLOAT, 4, 0, tCompFloat}, // TSDB_DATA_TYPE_FLOAT
+ {TSDB_DATA_TYPE_DOUBLE, 8, 0, tCompDouble}, // TSDB_DATA_TYPE_DOUBLE
+ {TSDB_DATA_TYPE_VARCHAR, 1, 1, tCompBinary}, // TSDB_DATA_TYPE_VARCHAR
+ {TSDB_DATA_TYPE_TIMESTAMP, 8, 0, tCompTimestamp}, // pTSDB_DATA_TYPE_TIMESTAMP
+ {TSDB_DATA_TYPE_NCHAR, 1, 1, tCompBinary}, // TSDB_DATA_TYPE_NCHAR
+ {TSDB_DATA_TYPE_UTINYINT, 1, 0, tCompInt}, // TSDB_DATA_TYPE_UTINYINT
+ {TSDB_DATA_TYPE_USMALLINT, 2, 0, tCompInt}, // TSDB_DATA_TYPE_USMALLINT
+ {TSDB_DATA_TYPE_UINT, 4, 0, tCompInt}, // TSDB_DATA_TYPE_UINT
+ {TSDB_DATA_TYPE_UBIGINT, 8, 0, tCompInt}, // TSDB_DATA_TYPE_UBIGINT
+ {TSDB_DATA_TYPE_JSON, 1, 1, tCompBinary}, // TSDB_DATA_TYPE_JSON
+ {TSDB_DATA_TYPE_VARBINARY, 1, 1, tCompBinary}, // TSDB_DATA_TYPE_VARBINARY
+ {TSDB_DATA_TYPE_DECIMAL, 1, 1, tCompBinary}, // TSDB_DATA_TYPE_DECIMAL
+ {TSDB_DATA_TYPE_BLOB, 1, 1, tCompBinary}, // TSDB_DATA_TYPE_BLOB
+ {TSDB_DATA_TYPE_MEDIUMBLOB, 1, 1, tCompBinary}, // TSDB_DATA_TYPE_MEDIUMBLOB
+};
+
+struct SCompressor {
+ int8_t type;
+ int8_t cmprAlg;
+ int8_t autoAlloc;
+ int32_t nVal;
+ uint8_t *aBuf[2];
+ int64_t nBuf[2];
+ union {
+ // Timestamp ----
+ struct {
+ int64_t ts_prev_val;
+ int64_t ts_prev_delta;
+ uint8_t *ts_flag_p;
+ };
+ // Integer ----
+ struct {
+ int64_t i_prev;
+ int32_t i_selector;
+ int32_t i_start;
+ int32_t i_end;
+ uint64_t i_aZigzag[241];
+ int8_t i_aBitN[241];
+ };
+ // Float ----
+ struct {
+ uint32_t f_prev;
+ uint8_t *f_flag_p;
+ };
+ // Double ----
+ struct {
+ uint64_t d_prev;
+ uint8_t *d_flag_p;
+ };
+ };
+};
+
+// Timestamp =====================================================
+static int32_t tCompSetCopyMode(SCompressor *pCmprsor) {
+ int32_t code = 0;
+
+ if (pCmprsor->nVal) {
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[1], sizeof(int64_t) * pCmprsor->nVal);
+ if (code) return code;
+ }
+ pCmprsor->nBuf[1] = 0;
+
+ int64_t n = 1;
+ int64_t value;
+ int64_t delta;
+ uint64_t vZigzag;
+ while (n < pCmprsor->nBuf[0]) {
+ uint8_t aN[2];
+ aN[0] = pCmprsor->aBuf[0][n] & 0xf;
+ aN[1] = pCmprsor->aBuf[0][n] >> 4;
+
+ n++;
+
+ for (int32_t i = 0; i < 2; i++) {
+ vZigzag = 0;
+ for (uint8_t j = 0; j < aN[i]; j++) {
+ vZigzag |= (((uint64_t)pCmprsor->aBuf[0][n]) << (8 * j));
+ n++;
+ }
+
+ int64_t delta_of_delta = ZIGZAG_DECODE(int64_t, vZigzag);
+ if (pCmprsor->nBuf[1] == 0) {
+ delta = 0;
+ value = delta_of_delta;
+ } else {
+ delta = delta_of_delta + delta;
+ value = delta + value;
+ }
+
+ memcpy(pCmprsor->aBuf[1] + pCmprsor->nBuf[1], &value, sizeof(int64_t));
+ pCmprsor->nBuf[1] += sizeof(int64_t);
+
+ if (n >= pCmprsor->nBuf[0]) break;
+ }
+ }
+
+ ASSERT(n == pCmprsor->nBuf[0]);
+
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[1] + 1);
+ if (code) return code;
+ }
+ memcpy(pCmprsor->aBuf[0] + 1, pCmprsor->aBuf[1], pCmprsor->nBuf[1]);
+ pCmprsor->nBuf[0] = 1 + pCmprsor->nBuf[1];
+ }
+ pCmprsor->aBuf[0][0] = 0;
+
+ return code;
+}
+static int32_t tCompTimestamp(SCompressor *pCmprsor, const void *pData, int32_t nData) {
+ int32_t code = 0;
+
+ int64_t ts = *(int64_t *)pData;
+ ASSERT(pCmprsor->type == TSDB_DATA_TYPE_TIMESTAMP);
+ ASSERT(nData == 8);
+
+ if (pCmprsor->aBuf[0][0] == 1) {
+ if (pCmprsor->nVal == 0) {
+ pCmprsor->ts_prev_val = ts;
+ pCmprsor->ts_prev_delta = -ts;
+ }
+
+ if (!I64_SAFE_ADD(ts, -pCmprsor->ts_prev_val)) {
+ code = tCompSetCopyMode(pCmprsor);
+ if (code) return code;
+ goto _copy_cmpr;
+ }
+ int64_t delta = ts - pCmprsor->ts_prev_val;
+
+ if (!I64_SAFE_ADD(delta, -pCmprsor->ts_prev_delta)) {
+ code = tCompSetCopyMode(pCmprsor);
+ if (code) return code;
+ goto _copy_cmpr;
+ }
+ int64_t delta_of_delta = delta - pCmprsor->ts_prev_delta;
+ uint64_t vZigzag = ZIGZAG_ENCODE(int64_t, delta_of_delta);
+
+ pCmprsor->ts_prev_val = ts;
+ pCmprsor->ts_prev_delta = delta;
+
+ if ((pCmprsor->nVal & 0x1) == 0) {
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0] + 17);
+ if (code) return code;
+ }
+
+ pCmprsor->ts_flag_p = pCmprsor->aBuf[0] + pCmprsor->nBuf[0];
+ pCmprsor->nBuf[0]++;
+ pCmprsor->ts_flag_p[0] = 0;
+ while (vZigzag) {
+ pCmprsor->aBuf[0][pCmprsor->nBuf[0]] = (vZigzag & 0xff);
+ pCmprsor->nBuf[0]++;
+ pCmprsor->ts_flag_p[0]++;
+ vZigzag >>= 8;
+ }
+ } else {
+ while (vZigzag) {
+ pCmprsor->aBuf[0][pCmprsor->nBuf[0]] = (vZigzag & 0xff);
+ pCmprsor->nBuf[0]++;
+ pCmprsor->ts_flag_p[0] += 0x10;
+ vZigzag >>= 8;
+ }
+ }
+ } else {
+ _copy_cmpr:
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0] + sizeof(ts));
+ if (code) return code;
+ }
+
+ memcpy(pCmprsor->aBuf[0] + pCmprsor->nBuf[0], &ts, sizeof(ts));
+ pCmprsor->nBuf[0] += sizeof(ts);
+ }
+ pCmprsor->nVal++;
+
+ return code;
+}
+
+// Integer =====================================================
+#define SIMPLE8B_MAX ((uint64_t)1152921504606846974LL)
+static const uint8_t BIT_PER_INTEGER[] = {0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 15, 20, 30, 60};
+static const int32_t SELECTOR_TO_ELEMS[] = {240, 120, 60, 30, 20, 15, 12, 10, 8, 7, 6, 5, 4, 3, 2, 1};
+static const uint8_t BIT_TO_SELECTOR[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 11, 12, 12, 12,
+ 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15};
+
+static int32_t tCompInt(SCompressor *pCmprsor, const void *pData, int32_t nData) {
+ int32_t code = 0;
+
+ ASSERT(nData == DATA_TYPE_INFO[pCmprsor->type].bytes);
+
+ if (pCmprsor->aBuf[0][0] == 0) {
+ int64_t val;
+
+ switch (pCmprsor->type) {
+ case TSDB_DATA_TYPE_TINYINT:
+ val = *(int8_t *)pData;
+ break;
+ case TSDB_DATA_TYPE_SMALLINT:
+ val = *(int16_t *)pData;
+ break;
+ case TSDB_DATA_TYPE_INT:
+ val = *(int32_t *)pData;
+ break;
+ case TSDB_DATA_TYPE_BIGINT:
+ val = *(int64_t *)pData;
+ break;
+ case TSDB_DATA_TYPE_UTINYINT:
+ val = *(uint8_t *)pData;
+ break;
+ case TSDB_DATA_TYPE_USMALLINT:
+ val = *(uint16_t *)pData;
+ break;
+ case TSDB_DATA_TYPE_UINT:
+ val = *(uint32_t *)pData;
+ break;
+ case TSDB_DATA_TYPE_UBIGINT:
+ val = *(int64_t *)pData;
+ break;
+ default:
+ ASSERT(0);
+ break;
+ }
+
+ if (!I64_SAFE_ADD(val, -pCmprsor->i_prev)) {
+ // TODO
+ goto _copy_cmpr;
+ }
+
+ int64_t diff = val - pCmprsor->i_prev;
+ uint64_t vZigzag = ZIGZAG_ENCODE(int64_t, diff);
+ if (vZigzag >= SIMPLE8B_MAX) {
+ // TODO
+ goto _copy_cmpr;
+ }
+
+ int8_t nBit = (vZigzag) ? (64 - BUILDIN_CLZL(vZigzag)) : 0;
+ pCmprsor->i_prev = val;
+
+ while (1) {
+ int32_t nEle = (pCmprsor->i_end + 241 - pCmprsor->i_start) % 241;
+
+ if (nEle + 1 <= SELECTOR_TO_ELEMS[pCmprsor->i_selector] && nEle + 1 <= SELECTOR_TO_ELEMS[BIT_TO_SELECTOR[nBit]]) {
+ if (pCmprsor->i_selector < BIT_TO_SELECTOR[nBit]) {
+ pCmprsor->i_selector = BIT_TO_SELECTOR[nBit];
+ }
+ pCmprsor->i_end = (pCmprsor->i_end + 1) % 241;
+ pCmprsor->i_aZigzag[pCmprsor->i_end] = vZigzag;
+ pCmprsor->i_aBitN[pCmprsor->i_end] = nBit;
+ break;
+ } else {
+ while (nEle < SELECTOR_TO_ELEMS[pCmprsor->i_selector]) {
+ pCmprsor->i_selector++;
+ }
+ nEle = SELECTOR_TO_ELEMS[pCmprsor->i_selector];
+
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0] + sizeof(uint64_t));
+ if (code) return code;
+ }
+
+ uint64_t *bp = (uint64_t *)(pCmprsor->aBuf[0] + pCmprsor->nBuf[0]);
+ pCmprsor->nBuf[0] += sizeof(uint64_t);
+ bp[0] = pCmprsor->i_selector;
+ uint8_t bits = BIT_PER_INTEGER[pCmprsor->i_selector];
+ for (int32_t iVal = 0; iVal < nEle; iVal++) {
+ bp[0] |= ((pCmprsor->i_aZigzag[pCmprsor->i_start] & ((((uint64_t)1) << bits) - 1)) << (bits * iVal + 4));
+ pCmprsor->i_start = (pCmprsor->i_start + 1) % 241;
+ }
+
+ // reset and continue
+ pCmprsor->i_selector = 0;
+ for (int32_t iVal = pCmprsor->i_start; iVal < pCmprsor->i_end; iVal = (iVal + 1) % 241) {
+ if (pCmprsor->i_selector < BIT_TO_SELECTOR[pCmprsor->i_aBitN[iVal]]) {
+ pCmprsor->i_selector = BIT_TO_SELECTOR[pCmprsor->i_aBitN[iVal]];
+ }
+ }
+ }
+ }
+ } else {
+ _copy_cmpr:
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0] + nData);
+ if (code) return code;
+
+ memcpy(pCmprsor->aBuf[0] + pCmprsor->nBuf[0], pData, nData);
+ pCmprsor->nBuf[0] += nData;
+ }
+ pCmprsor->nVal++;
+
+ return code;
+}
+
+// Float =====================================================
+static int32_t tCompFloat(SCompressor *pCmprsor, const void *pData, int32_t nData) {
+ int32_t code = 0;
+
+ ASSERT(nData == sizeof(float));
+
+ union {
+ float f;
+ uint32_t u;
+ } val = {.f = *(float *)pData};
+
+ uint32_t diff = val.u ^ pCmprsor->f_prev;
+ pCmprsor->f_prev = val.u;
+
+ int32_t clz, ctz;
+ if (diff) {
+ clz = BUILDIN_CLZ(diff);
+ ctz = BUILDIN_CTZ(diff);
+ } else {
+ clz = 32;
+ ctz = 32;
+ }
+
+ uint8_t nBytes;
+ if (clz < ctz) {
+ nBytes = sizeof(uint32_t) - ctz / BITS_PER_BYTE;
+ if (nBytes) diff >>= (32 - nBytes * BITS_PER_BYTE);
+ } else {
+ nBytes = sizeof(uint32_t) - clz / BITS_PER_BYTE;
+ }
+ if (nBytes == 0) nBytes++;
+
+ if ((pCmprsor->nVal & 0x1) == 0) {
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0] + 9);
+ if (code) return code;
+ }
+
+ pCmprsor->f_flag_p = &pCmprsor->aBuf[0][pCmprsor->nBuf[0]];
+ pCmprsor->nBuf[0]++;
+
+ if (clz < ctz) {
+ pCmprsor->f_flag_p[0] = (0x08 | (nBytes - 1));
+ } else {
+ pCmprsor->f_flag_p[0] = nBytes - 1;
+ }
+ } else {
+ if (clz < ctz) {
+ pCmprsor->f_flag_p[0] |= ((0x08 | (nBytes - 1)) << 4);
+ } else {
+ pCmprsor->f_flag_p[0] |= ((nBytes - 1) << 4);
+ }
+ }
+ for (; nBytes; nBytes--) {
+ pCmprsor->aBuf[0][pCmprsor->nBuf[0]] = (diff & 0xff);
+ pCmprsor->nBuf[0]++;
+ diff >>= BITS_PER_BYTE;
+ }
+ pCmprsor->nVal++;
+
+ return code;
+}
+
+// Double =====================================================
+static int32_t tCompDouble(SCompressor *pCmprsor, const void *pData, int32_t nData) {
+ int32_t code = 0;
+
+ ASSERT(nData == sizeof(double));
+
+ union {
+ double d;
+ uint64_t u;
+ } val = {.d = *(double *)pData};
+
+ uint64_t diff = val.u ^ pCmprsor->d_prev;
+ pCmprsor->d_prev = val.u;
+
+ int32_t clz, ctz;
+ if (diff) {
+ clz = BUILDIN_CLZL(diff);
+ ctz = BUILDIN_CTZL(diff);
+ } else {
+ clz = 64;
+ ctz = 64;
+ }
+
+ uint8_t nBytes;
+ if (clz < ctz) {
+ nBytes = sizeof(uint64_t) - ctz / BITS_PER_BYTE;
+ if (nBytes) diff >>= (64 - nBytes * BITS_PER_BYTE);
+ } else {
+ nBytes = sizeof(uint64_t) - clz / BITS_PER_BYTE;
+ }
+ if (nBytes == 0) nBytes++;
+
+ if ((pCmprsor->nVal & 0x1) == 0) {
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0] + 17);
+ if (code) return code;
+ }
+
+ pCmprsor->d_flag_p = &pCmprsor->aBuf[0][pCmprsor->nBuf[0]];
+ pCmprsor->nBuf[0]++;
+
+ if (clz < ctz) {
+ pCmprsor->d_flag_p[0] = (0x08 | (nBytes - 1));
+ } else {
+ pCmprsor->d_flag_p[0] = nBytes - 1;
+ }
+ } else {
+ if (clz < ctz) {
+ pCmprsor->d_flag_p[0] |= ((0x08 | (nBytes - 1)) << 4);
+ } else {
+ pCmprsor->d_flag_p[0] |= ((nBytes - 1) << 4);
+ }
+ }
+ for (; nBytes; nBytes--) {
+ pCmprsor->aBuf[0][pCmprsor->nBuf[0]] = (diff & 0xff);
+ pCmprsor->nBuf[0]++;
+ diff >>= BITS_PER_BYTE;
+ }
+ pCmprsor->nVal++;
+
+ return code;
+}
+
+// Binary =====================================================
+static int32_t tCompBinary(SCompressor *pCmprsor, const void *pData, int32_t nData) {
+ int32_t code = 0;
+
+ if (nData) {
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0] + nData);
+ if (code) return code;
+ }
+
+ memcpy(pCmprsor->aBuf[0] + pCmprsor->nBuf[0], pData, nData);
+ pCmprsor->nBuf[0] += nData;
+ }
+ pCmprsor->nVal++;
+
+ return code;
+}
+
+// Bool =====================================================
+static const uint8_t BOOL_CMPR_TABLE[] = {0b01, 0b0100, 0b010000, 0b01000000};
+
+static int32_t tCompBool(SCompressor *pCmprsor, const void *pData, int32_t nData) {
+ int32_t code = 0;
+
+ bool vBool = *(int8_t *)pData;
+
+ int32_t mod4 = pCmprsor->nVal & 3;
+ if (mod4 == 0) {
+ pCmprsor->nBuf[0]++;
+
+ if (pCmprsor->autoAlloc) {
+ code = tRealloc(&pCmprsor->aBuf[0], pCmprsor->nBuf[0]);
+ if (code) return code;
+ }
+
+ pCmprsor->aBuf[0][pCmprsor->nBuf[0] - 1] = 0;
+ }
+ if (vBool) {
+ pCmprsor->aBuf[0][pCmprsor->nBuf[0] - 1] |= BOOL_CMPR_TABLE[mod4];
+ }
+ pCmprsor->nVal++;
+
+ return code;
+}
+
+// SCompressor =====================================================
+int32_t tCompressorCreate(SCompressor **ppCmprsor) {
+ int32_t code = 0;
+
+ *ppCmprsor = (SCompressor *)taosMemoryCalloc(1, sizeof(SCompressor));
+ if ((*ppCmprsor) == NULL) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+
+ code = tRealloc(&(*ppCmprsor)->aBuf[0], 1024);
+ if (code) {
+ taosMemoryFree(*ppCmprsor);
+ *ppCmprsor = NULL;
+ goto _exit;
+ }
+
+_exit:
+ return code;
+}
+
+int32_t tCompressorDestroy(SCompressor *pCmprsor) {
+ int32_t code = 0;
+
+ if (pCmprsor) {
+ int32_t nBuf = sizeof(pCmprsor->aBuf) / sizeof(pCmprsor->aBuf[0]);
+ for (int32_t iBuf = 0; iBuf < nBuf; iBuf++) {
+ tFree(pCmprsor->aBuf[iBuf]);
+ }
+
+ taosMemoryFree(pCmprsor);
+ }
+
+ return code;
+}
+
+int32_t tCompressorReset(SCompressor *pCmprsor, int8_t type, int8_t cmprAlg, int8_t autoAlloc) {
+ int32_t code = 0;
+
+ pCmprsor->type = type;
+ pCmprsor->cmprAlg = cmprAlg;
+ pCmprsor->autoAlloc = autoAlloc;
+ pCmprsor->nVal = 0;
+
+ switch (type) {
+ case TSDB_DATA_TYPE_TIMESTAMP:
+ pCmprsor->ts_prev_val = 0;
+ pCmprsor->ts_prev_delta = 0;
+ pCmprsor->ts_flag_p = NULL;
+ pCmprsor->aBuf[0][0] = 1; // For timestamp, 1 means compressed, 0 otherwise
+ pCmprsor->nBuf[0] = 1;
+ break;
+ case TSDB_DATA_TYPE_BOOL:
+ pCmprsor->nBuf[0] = 0;
+ break;
+ case TSDB_DATA_TYPE_BINARY:
+ pCmprsor->nBuf[0] = 0;
+ break;
+ case TSDB_DATA_TYPE_FLOAT:
+ pCmprsor->f_prev = 0;
+ pCmprsor->f_flag_p = NULL;
+ pCmprsor->aBuf[0][0] = 0; // 0 means compressed, 1 otherwise (for backward compatibility)
+ pCmprsor->nBuf[0] = 1;
+ break;
+ case TSDB_DATA_TYPE_DOUBLE:
+ pCmprsor->d_prev = 0;
+ pCmprsor->d_flag_p = NULL;
+ pCmprsor->aBuf[0][0] = 0; // 0 means compressed, 1 otherwise (for backward compatibility)
+ pCmprsor->nBuf[0] = 1;
+ break;
+ case TSDB_DATA_TYPE_TINYINT:
+ case TSDB_DATA_TYPE_SMALLINT:
+ case TSDB_DATA_TYPE_INT:
+ case TSDB_DATA_TYPE_BIGINT:
+ case TSDB_DATA_TYPE_UTINYINT:
+ case TSDB_DATA_TYPE_USMALLINT:
+ case TSDB_DATA_TYPE_UINT:
+ case TSDB_DATA_TYPE_UBIGINT:
+ pCmprsor->i_prev = 0;
+ pCmprsor->i_selector = 0;
+ pCmprsor->i_start = 0;
+ pCmprsor->i_end = 0;
+ pCmprsor->aBuf[0][0] = 0; // 0 means compressed, 1 otherwise (for backward compatibility)
+ pCmprsor->nBuf[0] = 1;
+ break;
+ default:
+ break;
+ }
+
+ return code;
+}
+
+int32_t tCompGen(SCompressor *pCmprsor, const uint8_t **ppData, int64_t *nData) {
+ int32_t code = 0;
+
+ if (pCmprsor->nVal == 0) {
+ *ppData = NULL;
+ *nData = 0;
+ return code;
+ }
+
+ if (pCmprsor->cmprAlg == TWO_STAGE_COMP /*|| IS_VAR_DATA_TYPE(pCmprsor->type)*/) {
+ code = tRealloc(&pCmprsor->aBuf[1], pCmprsor->nBuf[0] + 1);
+ if (code) return code;
+
+ int64_t ret = LZ4_compress_default(pCmprsor->aBuf[0], pCmprsor->aBuf[1] + 1, pCmprsor->nBuf[0], pCmprsor->nBuf[0]);
+ if (ret) {
+ pCmprsor->aBuf[1][0] = 0;
+ pCmprsor->nBuf[1] = ret + 1;
+ } else {
+ pCmprsor->aBuf[1][0] = 1;
+ memcpy(pCmprsor->aBuf[1] + 1, pCmprsor->aBuf[0], pCmprsor->nBuf[0]);
+ pCmprsor->nBuf[1] = pCmprsor->nBuf[0] + 1;
+ }
+
+ *ppData = pCmprsor->aBuf[1];
+ *nData = pCmprsor->nBuf[1];
+ } else {
+ *ppData = pCmprsor->aBuf[0];
+ *nData = pCmprsor->nBuf[0];
+ }
+
+ return code;
+}
+
+int32_t tCompress(SCompressor *pCmprsor, const void *pData, int64_t nData) {
+ return DATA_TYPE_INFO[pCmprsor->type].cmprFn(pCmprsor, pData, nData);
+}
\ No newline at end of file
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index 50c42ff170..1906a77127 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -621,6 +621,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_FETCH_MSG_MSSED_UP, "Rsma fetch msg is m
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_EMPTY_INFO, "Rsma info is empty")
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_INVALID_SCHEMA, "Rsma invalid schema")
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_REGEX_MATCH, "Rsma regex match")
+TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_STREAM_STATE_OPEN, "Rsma stream state open")
+TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_STREAM_STATE_COMMIT, "Rsma stream state commit")
//index
TAOS_DEFINE_ERROR(TSDB_CODE_INDEX_REBUILDING, "Index is rebuilding")
diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c
index 2767fed937..e1a8697ad5 100644
--- a/source/util/src/tpagedbuf.c
+++ b/source/util/src/tpagedbuf.c
@@ -284,7 +284,6 @@ static char* evacOneDataPage(SDiskbasedBuf* pBuf) {
// all pages are referenced by user, try to allocate new space
if (pn == NULL) {
- assert(0);
int32_t prev = pBuf->inMemPages;
// increase by 50% of previous mem pages
@@ -304,7 +303,6 @@ static char* evacOneDataPage(SDiskbasedBuf* pBuf) {
bufPage = flushPageToDisk(pBuf, d);
}
- ASSERT((bufPage != NULL) || terrno != TSDB_CODE_SUCCESS);
return bufPage;
}
@@ -377,12 +375,6 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
char* availablePage = NULL;
if (NO_IN_MEM_AVAILABLE_PAGES(pBuf)) {
availablePage = evacOneDataPage(pBuf);
-
- // Failed to allocate a new buffer page, and there is an error occurs.
- if (availablePage == NULL) {
- assert(0);
- return NULL;
- }
}
SPageInfo* pi = NULL;
@@ -652,4 +644,4 @@ void clearDiskbasedBuf(SDiskbasedBuf* pBuf) {
pBuf->totalBufSize = 0;
pBuf->allocateId = -1;
pBuf->fileSize = 0;
-}
\ No newline at end of file
+}
diff --git a/tests/docs-examples-test/csharp.sh b/tests/docs-examples-test/csharp.sh
index a8f1ce4119..d7f2670478 100644
--- a/tests/docs-examples-test/csharp.sh
+++ b/tests/docs-examples-test/csharp.sh
@@ -6,23 +6,24 @@ pgrep taosd || taosd >> /dev/null 2>&1 &
pgrep taosadapter || taosadapter >> /dev/null 2>&1 &
cd ../../docs/examples/csharp
-dotnet run --project connect.csproj
+#dotnet run --project connect.csproj
-taos -s "drop database if exists power"
-dotnet run --project sqlinsert.csproj
-dotnet run --project query.csproj
-dotnet run --project asyncquery.csproj
-dotnet run --project subscribe.csproj
+#taos -s "drop database if exists power"
+#dotnet run --project sqlinsert.csproj
+#dotnet run --project query.csproj
+#dotnet run --project asyncquery.csproj
+#dotnet run --project subscribe.csproj
-taos -s "drop topic if exists topic_example"
-taos -s "drop database if exists power"
-dotnet run --project stmtinsert.csproj
+#taos -s "drop topic if exists topic_example"
+#taos -s "drop database if exists power"
+#dotnet run --project stmtinsert.csproj
-taos -s "drop database if exists test"
-dotnet run --project influxdbline.csproj
+#taos -s "drop database if exists test"
+#dotnet run --project influxdbline.csproj
-taos -s "drop database if exists test"
-dotnet run --project optstelnet.csproj
+#taos -s "drop database if exists test"
+#dotnet run --project optstelnet.csproj
-taos -s "drop database if exists test"
-dotnet run --project optsjson.csproj
\ No newline at end of file
+#taos -s "drop database if exists test"
+#dotnet run --project optsjson.csproji
+echo "uncomment temporily"
diff --git a/tests/script/sh/gpd.c b/tests/script/sh/gpd.c
new file mode 100644
index 0000000000..8d69bacb5e
--- /dev/null
+++ b/tests/script/sh/gpd.c
@@ -0,0 +1,74 @@
+#include
+#include
+#include
+#ifdef LINUX
+#include
+#endif
+#ifdef WINDOWS
+#include
+#endif
+#include "taosudf.h"
+
+TAOS* taos = NULL;
+
+DLL_EXPORT int32_t gpd_init() {
+ taos = taos_connect("localhost", "root", "taosdata", "", 7100);
+ return 0;
+}
+
+DLL_EXPORT int32_t gpd_destroy() {
+ taos_close(taos);
+ taos_cleanup();
+ return 0;
+}
+
+DLL_EXPORT int32_t gpd(SUdfDataBlock* block, SUdfColumn *resultCol) {
+ SUdfColumnMeta *meta = &resultCol->colMeta;
+ meta->bytes = 4;
+ meta->type = TSDB_DATA_TYPE_INT;
+ meta->scale = 0;
+ meta->precision = 0;
+
+ SUdfColumnData *resultData = &resultCol->colData;
+ resultData->numOfRows = block->numOfRows;
+ for (int32_t i = 0; i < resultData->numOfRows; ++i) {
+ int j = 0;
+ for (; j < block->numOfCols; ++j) {
+ if (udfColDataIsNull(block->udfCols[j], i)) {
+ udfColDataSetNull(resultCol, i);
+ break;
+ }
+ }
+ if ( j == block->numOfCols) {
+ int32_t luckyNum = 88;
+ udfColDataSet(resultCol, i, (char *)&luckyNum, false);
+ }
+ }
+ TAOS_RES* res = taos_query(taos, "create database if not exists gpd");
+ if (taos_errno(res) != 0) {
+ char* errstr = taos_errstr(res);
+ }
+ res = taos_query(taos, "create table gpd.st (ts timestamp, f int) tags(t int)");
+ if (taos_errno(res) != 0) {
+ char* errstr = taos_errstr(res);
+ }
+
+ taos_query(taos, "insert into gpd.t using gpd.st tags(1) values(now, 1) ");
+ if (taos_errno(res) != 0) {
+ char* errstr = taos_errstr(res);
+ }
+
+ taos_query(taos, "select * from gpd.t");
+ if (taos_errno(res) != 0) {
+ char* errstr = taos_errstr(res);
+ }
+
+ //to simulate actual processing delay by udf
+#ifdef LINUX
+ usleep(1 * 1000); // usleep takes sleep time in us (1 millionth of a second)
+#endif
+#ifdef WINDOWS
+ Sleep(1);
+#endif
+ return 0;
+}
diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim
index 7f8b1044ef..0b48a815e2 100644
--- a/tests/script/tsim/query/udf.sim
+++ b/tests/script/tsim/query/udf.sim
@@ -144,18 +144,18 @@ if $data20 != 8.000000000 then
return -1
endi
-sql drop function bit_and;
-sql show functions;
-if $rows != 1 then
- return -1
-endi
-if $data00 != @l2norm@ then
- return -1
- endi
-sql drop function l2norm;
-sql show functions;
-if $rows != 0 then
- return -1
-endi
+#sql drop function bit_and;
+#sql show functions;
+#if $rows != 1 then
+# return -1
+#endi
+#if $data00 != @l2norm@ then
+# return -1
+# endi
+#sql drop function l2norm;
+#sql show functions;
+#if $rows != 0 then
+# return -1
+#endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/system-test/1-insert/database_pre_suf.py b/tests/system-test/1-insert/database_pre_suf.py
new file mode 100755
index 0000000000..fe788af0db
--- /dev/null
+++ b/tests/system-test/1-insert/database_pre_suf.py
@@ -0,0 +1,377 @@
+###################################################################
+# Copyright (c) 2016 by TAOS Technologies, Inc.
+# All rights reserved.
+#
+# This file is proprietary and confidential to TAOS Technologies.
+# No part of this file may be reproduced, stored, transmitted,
+# disclosed or used in any form or by any means other than as
+# expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import random
+import os
+import time
+import taos
+import subprocess
+from faker import Faker
+from util.log import tdLog
+from util.cases import tdCases
+from util.sql import tdSql
+from util.dnodes import tdDnodes
+from util.dnodes import *
+
+class TDTestCase:
+ updatecfgDict = {'maxSQLLength':1048576,'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 ,
+ "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143,
+ "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143}
+
+ def init(self, conn, logSql):
+ tdLog.debug("start to execute %s" % __file__)
+ tdSql.init(conn.cursor(), logSql)
+
+ self.testcasePath = os.path.split(__file__)[0]
+ self.testcaseFilename = os.path.split(__file__)[-1]
+ os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename))
+
+ self.db = "pre_suf"
+
+ def dropandcreateDB_random(self,database,n,vgroups,table_prefix,table_suffix,check_result):
+ ts = 1630000000000
+ num_random = 100
+ fake = Faker('zh_CN')
+ tdSql.execute('''drop database if exists %s ;''' %database)
+ tdSql.execute('''create database %s keep 36500 vgroups %d table_prefix %d table_suffix %d;'''%(database,vgroups,table_prefix,table_suffix))
+ tdSql.execute('''use %s;'''%database)
+
+ tdSql.execute('''create stable stable_1 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
+ q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\
+ q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\
+ q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
+ tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
+ tdSql.execute('''create stable stable_2 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
+ q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
+ tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
+
+ for i in range(10*n):
+ tdSql.execute('''create table bj_%d (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
+ tdSql.execute('''create table sh_%d (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
+ tdSql.execute('''create table bj_table_%d_r (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
+ tdSql.execute('''create table sh_table_%d_r (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
+ tdSql.execute('''create table hn_table_%d_r \
+ (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
+ q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\
+ q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\
+ q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;'''%i)
+ tdSql.execute('''create table bj_stable_1_%d using stable_1 tags('bj_stable_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+ tdSql.execute('''create table sh_table_%d_a using stable_1 tags('sh_a_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+ tdSql.execute('''create table sh_table_%d_b using stable_1 tags('sh_b_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+ tdSql.execute('''create table sh_table_%d_c using stable_1 tags('sh_c_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+
+ tdSql.execute('''create table bj_table_%d_a using stable_1 tags('bj_a_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+ tdSql.execute('''create table bj_table_%d_b using stable_1 tags('bj_b_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+ tdSql.execute('''create table bj_table_%d_c using stable_1 tags('bj_c_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+
+
+ tdSql.execute('''create table tj_table_%d_a using stable_2 tags('tj_a_table_2_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+ tdSql.execute('''create table tj_table_%d_b using stable_2 tags('tj_b_table_2_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;'''
+ %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+
+
+ # create stream
+ tdSql.execute('''create stream current_stream into stream_max_stable_1 as select _wstart as start, _wend as end, max(q_int) as max_int, min(q_bigint) as min_int from stable_1 where ts is not null interval (5s);''')
+
+ # insert data
+ for i in range(num_random*n):
+ tdSql.execute('''insert into bj_stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts,\
+ q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+ values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+ 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;'''
+ % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1),
+ fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1),
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() ,
+ fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+ tdSql.execute('''insert into hn_table_1_r (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+ q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+ values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+ 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;'''
+ % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) ,
+ fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) ,
+ fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) ,
+ fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() ,
+ fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+ tdSql.execute('''insert into bj_stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+ q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8)\
+ values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+ 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;'''
+ % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1),
+ fake.random_int(min=0, max=9223372036854775807, step=1),
+ fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) ,
+ fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() ,
+ fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+ tdSql.execute('''insert into hn_table_2_r (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+ q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+ values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+ 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;'''
+ % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1),
+ fake.random_int(min=0, max=9223372036854775807, step=1),
+ fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) ,
+ fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() ,
+ fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+ tdSql.execute('''insert into bj_stable_1_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+ q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+ values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+ 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;'''
+ % (ts + i*1000, fake.random_int(min=-0, max=2147483647, step=1),
+ fake.random_int(min=-0, max=9223372036854775807, step=1),
+ fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) ,
+ fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() ,
+ fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+ tdSql.execute('''insert into bj_stable_1_4 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+ q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+ values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+ 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;'''
+ % (ts + i*1000 +1, fake.random_int(min=-0, max=2147483647, step=1),
+ fake.random_int(min=-0, max=9223372036854775807, step=1),
+ fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) ,
+ fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() ,
+ fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+ tdSql.execute('''insert into bj_stable_1_5 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+ q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+ values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+ 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;'''
+ % (ts + i*1000 +10, fake.random_int(min=-0, max=2147483647, step=1),
+ fake.random_int(min=-0, max=9223372036854775807, step=1),
+ fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) ,
+ fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() ,
+ fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+ tdSql.query("select count(*) from stable_1;")
+ tdSql.checkData(0,0,5*num_random*n)
+ tdSql.query("select count(*) from hn_table_1_r;")
+ tdSql.checkData(0,0,num_random*n)
+
+ # stream data check
+ tdSql.query("select start,end,max_int from stream_max_stable_1 ;")
+ tdSql.checkRows(20)
+ tdSql.query("select sum(max_int) from stream_max_stable_1 ;")
+ stream_data_1 = tdSql.queryResult[0][0]
+ tdSql.query("select sum(min_int) from stream_max_stable_1 ;")
+ stream_data_2 = tdSql.queryResult[0][0]
+ tdSql.query("select sum(max_int),sum(min_int) from (select _wstart as start, _wend as end, max(q_int) as max_int, min(q_bigint) as min_int from stable_1 where ts is not null interval (5s));")
+ sql_data_1 = tdSql.queryResult[0][0]
+ sql_data_2 = tdSql.queryResult[0][1]
+
+ self.stream_value_check(stream_data_1,sql_data_1)
+ self.stream_value_check(stream_data_2,sql_data_2)
+
+ tdSql.query("select sum(max_int),sum(min_int) from (select _wstart as start, _wend as end, max(q_int) as max_int, min(q_bigint) as min_int from stable_1 interval (5s));")
+ sql_data_1 = tdSql.queryResult[0][0]
+ sql_data_2 = tdSql.queryResult[0][1]
+
+ self.stream_value_check(stream_data_1,sql_data_1)
+ self.stream_value_check(stream_data_2,sql_data_2)
+
+ tdSql.query("select max(max_int) from stream_max_stable_1 ;")
+ stream_data_1 = tdSql.queryResult[0][0]
+ tdSql.query("select min(min_int) from stream_max_stable_1 ;")
+ stream_data_2 = tdSql.queryResult[0][0]
+ tdSql.query("select max(q_int) as max_int, min(q_bigint) as min_int from stable_1;")
+ sql_data_1 = tdSql.queryResult[0][0]
+ sql_data_2 = tdSql.queryResult[0][1]
+
+ self.stream_value_check(stream_data_1,sql_data_1)
+ self.stream_value_check(stream_data_2,sql_data_2)
+
+
+ tdSql.query(" select * from information_schema.ins_databases where name = '%s';" %database)
+ print(tdSql.queryResult)
+
+ # tdSql.query(" select table_prefix,table_suffix from information_schema.ins_databases where name = '%s';" %database)
+ # print(tdSql.queryResult)
+ #TD-19082
+
+ #tdSql.query(" select * from information_schema.ins_tables where db_name = '%s';" %database)
+ #print(tdSql.queryResult)
+
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s';" %database)
+ queryRows = len(tdSql.queryResult)
+ for i in range(queryRows):
+ print("row=%d, vgroup_id=%s, tbname=%s " %(i,tdSql.queryResult[i][1],tdSql.queryResult[i][0]))
+
+ tdLog.info("\n=============flush database ====================\n")
+
+ tdSql.execute(" flush database %s;" %database)
+
+ tdSql.query(" select * from information_schema.ins_databases where name = '%s';" %database)
+ print(tdSql.queryResult)
+
+ # tdSql.query(" select table_prefix,table_suffix from information_schema.ins_databases where name = '%s';" %database)
+ # print(tdSql.queryResult)
+ #TD-19082
+
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s';" %database)
+ queryRows = len(tdSql.queryResult)
+ for i in range(queryRows):
+ print("row=%d, vgroup_id=%s, tbname=%s " %(i,tdSql.queryResult[i][1],tdSql.queryResult[i][0]))
+
+
+ # check in one vgroup
+ if check_result == 'Y':
+ #base table : sh_table_0_a
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_0_a';" %(database))
+ base_value_table_name = tdSql.queryResult[0][0]
+ base_value_table_vgroup = tdSql.queryResult[0][1]
+
+ #check table :sh_table_i_a
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_a';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_a';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :sh_table_i_b
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_b';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_b';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :sh_table_i_c
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_c';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_c';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :sh_table_i_r
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_r';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_r';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :bj_table_i_a
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_a';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_a';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :bj_table_i_b
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_b';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_b';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :bj_table_i_c
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_c';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_c';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :bj_table_i_r
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_r';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_r';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :hn_table_i_r
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'hn_table_%%_r';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='hn_table_%d_r';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :tj_table_i_a
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'tj_table_%%_a';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='tj_table_%d_a';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ #check table :tj_table_i_b
+ check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'tj_table_%%_b';" %(database))
+ for i in range(check_rows):
+ tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='tj_table_%d_b';" %(database,i))
+ self.value_check(base_value_table_name,base_value_table_vgroup)
+
+ else:
+ pass
+
+ def value_check(self,base_value_table_name,base_value_table_vgroup):
+ check_value_table_name = tdSql.queryResult[0][0]
+ check_value_table_vgroup = tdSql.queryResult[0][1]
+ #tdLog.info(f"{base_value_table_name},{base_value_table_vgroup},{check_value_table_name},{check_value_table_vgroup}")
+
+ if base_value_table_vgroup==check_value_table_vgroup:
+ tdLog.info(f"checkEqual success, base_table_name={base_value_table_name},base_table_host={base_value_table_vgroup} ,check_table_name={check_value_table_name},check_table_host={check_value_table_vgroup}")
+ else :
+ tdLog.exit(f"checkEqual error, base_table_name=={base_value_table_name},base_table_host={base_value_table_vgroup} ,check_table_name={check_value_table_name},check_table_host={check_value_table_vgroup}")
+
+ def stream_value_check(self,stream_data,sql_data):
+ if stream_data==sql_data:
+ tdLog.info(f"checkEqual success, stream_data={stream_data},sql_data={sql_data}")
+ else :
+ tdLog.exit(f"checkEqual error, stream_data=={stream_data},sql_data={sql_data}")
+
+ def run(self):
+ startTime = time.time()
+
+ os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename))
+
+ #(self,database,n,vgroups,table_prefix,table_suffix)
+ self.dropandcreateDB_random("%s" %self.db, 1,2,0,0,'N')
+ self.dropandcreateDB_random("%s" %self.db, 1,2,0,2,'N')
+ self.dropandcreateDB_random("%s" %self.db, 1,2,2,0,'N')
+ self.dropandcreateDB_random("%s" %self.db, 1,2,3,3,'Y')
+ self.dropandcreateDB_random("%s" %self.db, 1,3,3,3,'Y')
+ self.dropandcreateDB_random("%s" %self.db, 1,4,4,4,'Y')
+ self.dropandcreateDB_random("%s" %self.db, 1,5,5,5,'Y')
+
+
+ #taos -f sql
+ print("taos -f sql start!")
+ taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename)
+ _ = subprocess.check_output(taos_cmd1, shell=True)
+ print("taos -f sql over!")
+
+
+ endTime = time.time()
+ print("total time %ds" % (endTime - startTime))
+
+
+
+ def stop(self):
+ tdSql.close()
+ tdLog.success("%s successfully executed" % __file__)
+
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
diff --git a/tests/system-test/7-tmq/tmq_taosx.py b/tests/system-test/7-tmq/tmq_taosx.py
index 07602ec29f..626e935733 100644
--- a/tests/system-test/7-tmq/tmq_taosx.py
+++ b/tests/system-test/7-tmq/tmq_taosx.py
@@ -31,18 +31,20 @@ class TDTestCase:
while True:
dst = queryFile.readline()
src = consumeFile.readline()
-
- if dst:
+ if src:
if dst != src:
- tdLog.exit("compare error: %s != %s"%src, dst)
+ tdLog.exit("compare error: %s != %s"%(src, dst))
else:
break
return
- def checkDropData(self):
+ def checkDropData(self, drop):
tdSql.execute('use db_taosx')
tdSql.query("show tables")
- tdSql.checkRows(2)
+ if drop:
+ tdSql.checkRows(10)
+ else:
+ tdSql.checkRows(15)
tdSql.query("select * from jt order by i")
tdSql.checkRows(2)
tdSql.checkData(0, 1, 1)
@@ -50,15 +52,72 @@ class TDTestCase:
tdSql.checkData(0, 2, '{"k1":1,"k2":"hello"}')
tdSql.checkData(1, 2, None)
+ tdSql.query("select * from sttb order by ts")
+ tdSql.checkRows(2)
+ tdSql.checkData(0, 1, 13)
+ tdSql.checkData(1, 1, 16)
+ tdSql.checkData(0, 2, 22)
+ tdSql.checkData(1, 2, 25)
+ tdSql.checkData(0, 5, "sttb3")
+ tdSql.checkData(1, 5, "sttb4")
+
+ tdSql.query("select * from stt order by ts")
+ tdSql.checkRows(2)
+ tdSql.checkData(0, 1, 1)
+ tdSql.checkData(1, 1, 21)
+ tdSql.checkData(0, 2, 2)
+ tdSql.checkData(1, 2, 21)
+ tdSql.checkData(0, 5, "stt3")
+ tdSql.checkData(1, 5, "stt4")
+
tdSql.execute('use abc1')
tdSql.query("show tables")
- tdSql.checkRows(2)
+ if drop:
+ tdSql.checkRows(10)
+ else:
+ tdSql.checkRows(15)
tdSql.query("select * from jt order by i")
tdSql.checkRows(2)
tdSql.checkData(0, 1, 1)
tdSql.checkData(1, 1, 11)
tdSql.checkData(0, 2, '{"k1":1,"k2":"hello"}')
tdSql.checkData(1, 2, None)
+
+ tdSql.query("select * from sttb order by ts")
+ tdSql.checkRows(2)
+ tdSql.checkData(0, 1, 13)
+ tdSql.checkData(1, 1, 16)
+ tdSql.checkData(0, 2, 22)
+ tdSql.checkData(1, 2, 25)
+ tdSql.checkData(0, 5, "sttb3")
+ tdSql.checkData(1, 5, "sttb4")
+
+ tdSql.query("select * from stt order by ts")
+ tdSql.checkRows(2)
+ tdSql.checkData(0, 1, 1)
+ tdSql.checkData(1, 1, 21)
+ tdSql.checkData(0, 2, 2)
+ tdSql.checkData(1, 2, 21)
+ tdSql.checkData(0, 5, "stt3")
+ tdSql.checkData(1, 5, "stt4")
+
+ return
+
+ def checkDataTable(self):
+ tdSql.execute('use db_taosx')
+ tdSql.query("select * from meters_summary")
+ tdSql.checkRows(1)
+ tdSql.checkData(0, 1, 120)
+ tdSql.checkData(0, 2, 1)
+ tdSql.checkData(0, 3, "San Francisco")
+
+ tdSql.execute('use abc1')
+ tdSql.query("select * from meters_summary")
+ tdSql.checkRows(1)
+ tdSql.checkData(0, 1, 120)
+ tdSql.checkData(0, 2, 1)
+ tdSql.checkData(0, 3, "San Francisco")
+
return
def checkData(self):
@@ -145,6 +204,19 @@ class TDTestCase:
self.checkJson(cfgPath, "tmq_taosx_tmp")
self.checkData()
+ self.checkDropData(False)
+
+ return
+
+ def checkWal1VgroupTable(self):
+ buildPath = tdCom.getBuildPath()
+ cfgPath = tdCom.getClientCfgPath()
+ cmdStr = '%s/build/bin/tmq_taosx_ci -c %s -sv 1 -dv 1 -t'%(buildPath, cfgPath)
+ tdLog.info(cmdStr)
+ os.system(cmdStr)
+
+ self.checkJson(cfgPath, "tmq_taosx_tmp")
+ self.checkDataTable()
return
@@ -155,6 +227,7 @@ class TDTestCase:
os.system(cmdStr)
self.checkData()
+ self.checkDropData(False)
return
@@ -164,7 +237,7 @@ class TDTestCase:
tdLog.info(cmdStr)
os.system(cmdStr)
- self.checkDropData()
+ self.checkDropData(True)
return
@@ -177,6 +250,19 @@ class TDTestCase:
self.checkJson(cfgPath, "tmq_taosx_tmp_snapshot")
self.checkData()
+ self.checkDropData(False)
+
+ return
+
+ def checkSnapshot1VgroupTable(self):
+ buildPath = tdCom.getBuildPath()
+ cfgPath = tdCom.getClientCfgPath()
+ cmdStr = '%s/build/bin/tmq_taosx_ci -c %s -sv 1 -dv 1 -s -t'%(buildPath, cfgPath)
+ tdLog.info(cmdStr)
+ os.system(cmdStr)
+
+ self.checkJson(cfgPath, "tmq_taosx_tmp_snapshot")
+ self.checkDataTable()
return
@@ -187,6 +273,7 @@ class TDTestCase:
os.system(cmdStr)
self.checkData()
+ self.checkDropData(False)
return
@@ -196,7 +283,7 @@ class TDTestCase:
tdLog.info(cmdStr)
os.system(cmdStr)
- self.checkDropData()
+ self.checkDropData(True)
return
@@ -205,6 +292,9 @@ class TDTestCase:
self.checkWal1Vgroup()
self.checkSnapshot1Vgroup()
+ self.checkWal1VgroupTable()
+ self.checkSnapshot1VgroupTable()
+
self.checkWalMultiVgroups()
self.checkSnapshotMultiVgroups()
diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh
index 604add0eb3..847bc300b3 100755
--- a/tests/system-test/fulltest.sh
+++ b/tests/system-test/fulltest.sh
@@ -35,6 +35,7 @@ python3 ./test.py -f 1-insert/mutil_stage.py
python3 ./test.py -f 1-insert/table_param_ttl.py -R
python3 ./test.py -f 1-insert/update_data_muti_rows.py
python3 ./test.py -f 1-insert/db_tb_name_check.py
+python3 ./test.py -f 1-insert/database_pre_suf.py
python3 ./test.py -f 2-query/abs.py
python3 ./test.py -f 2-query/abs.py -R
@@ -156,8 +157,8 @@ python3 ./test.py -f 2-query/sin.py
python3 ./test.py -f 2-query/sin.py -R
python3 ./test.py -f 2-query/smaTest.py
python3 ./test.py -f 2-query/smaTest.py -R
-#python3 ./test.py -f 2-query/sml.py
-#python3 ./test.py -f 2-query/sml.py -R
+python3 ./test.py -f 2-query/sml.py
+python3 ./test.py -f 2-query/sml.py -R
python3 ./test.py -f 2-query/spread.py
python3 ./test.py -f 2-query/spread.py -R
python3 ./test.py -f 2-query/sqrt.py
@@ -512,6 +513,6 @@ python3 ./test.py -f 2-query/count_partition.py -Q 3
python3 ./test.py -f 2-query/max_partition.py -Q 3
python3 ./test.py -f 2-query/last_row.py -Q 3
python3 ./test.py -f 2-query/tsbsQuery.py -Q 3
-#python3 ./test.py -f 2-query/sml.py -Q 3
+python3 ./test.py -f 2-query/sml.py -Q 3
python3 ./test.py -f 2-query/interp.py -Q 3
diff --git a/tools/shell/src/shellUtil.c b/tools/shell/src/shellUtil.c
index 0430428c38..8c47d16555 100644
--- a/tools/shell/src/shellUtil.c
+++ b/tools/shell/src/shellUtil.c
@@ -143,7 +143,7 @@ void shellCheckConnectMode() {
shell.args.port = 6041;
}
shell.args.dsn = taosMemoryCalloc(1, 1024);
- snprintf(shell.args.dsn, 1024, "ws://%s:%d/rest/ws",
+ snprintf(shell.args.dsn, 1024, "ws://%s:%d",
shell.args.host, shell.args.port);
}
shell.args.cloud = false;
diff --git a/tools/shell/src/shellWebsocket.c b/tools/shell/src/shellWebsocket.c
index b8b8392b96..94bb909e29 100644
--- a/tools/shell/src/shellWebsocket.c
+++ b/tools/shell/src/shellWebsocket.c
@@ -206,26 +206,31 @@ void shellRunSingleCommandWebsocketImp(char *command) {
printMode = true; // When output to a file, the switch does not work.
}
- if (!shell.ws_conn && shell_conn_ws_server(0)) {
- return;
- }
-
shell.stop_query = false;
- st = taosGetTimestampUs();
+ WS_RES* res;
- WS_RES* res = ws_query_timeout(shell.ws_conn, command, shell.args.timeout);
- int code = ws_errno(res);
- if (code != 0) {
- et = taosGetTimestampUs();
- fprintf(stderr, "\nDB: error: %s (%.6fs)\n", ws_errstr(res), (et - st)/1E6);
- if (code == TSDB_CODE_WS_SEND_TIMEOUT || code == TSDB_CODE_WS_RECV_TIMEOUT) {
- fprintf(stderr, "Hint: use -t to increase the timeout in seconds\n");
- } else if (code == TSDB_CODE_WS_INTERNAL_ERRO || code == TSDB_CODE_WS_CLOSED) {
- fprintf(stderr, "TDengine server is down, will try to reconnect\n");
- shell.ws_conn = NULL;
+ for (int reconnectNum = 0; reconnectNum < 2; reconnectNum++) {
+ if (!shell.ws_conn && shell_conn_ws_server(0)) {
+ return;
}
- ws_free_result(res);
- return;
+ st = taosGetTimestampUs();
+
+ res = ws_query_timeout(shell.ws_conn, command, shell.args.timeout);
+ int code = ws_errno(res);
+ if (code != 0 && !shell.stop_query) {
+ et = taosGetTimestampUs();
+ fprintf(stderr, "\nDB: error: %s (%.6fs)\n", ws_errstr(res), (et - st)/1E6);
+ if (code == TSDB_CODE_WS_SEND_TIMEOUT || code == TSDB_CODE_WS_RECV_TIMEOUT) {
+ fprintf(stderr, "Hint: use -t to increase the timeout in seconds\n");
+ } else if (code == TSDB_CODE_WS_INTERNAL_ERRO || code == TSDB_CODE_WS_CLOSED) {
+ fprintf(stderr, "TDengine server is down, will try to reconnect\n");
+ shell.ws_conn = NULL;
+ }
+ ws_free_result(res);
+ if (reconnectNum == 0) continue;
+ return;
+ }
+ break;
}
double execute_time = ws_take_timing(res)/1E6;
diff --git a/utils/test/c/tmqSim.c b/utils/test/c/tmqSim.c
index 71b31ba107..a043aa7a6d 100644
--- a/utils/test/c/tmqSim.c
+++ b/utils/test/c/tmqSim.c
@@ -653,23 +653,23 @@ static int32_t meta_msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIn
int32_t code = tmq_get_raw(msg, &raw);
if(code == TSDB_CODE_SUCCESS){
- int retCode = queryDB(pInfo->taos, "use metadb");
- if (retCode != 0) {
- taosFprintfFile(g_fp, "error when use metadb\n");
- taosCloseFile(&g_fp);
- exit(-1);
- }
- taosFprintfFile(g_fp, "raw:%p\n", &raw);
-
- tmq_write_raw(pInfo->taos, raw);
+// int retCode = queryDB(pInfo->taos, "use metadb");
+// if (retCode != 0) {
+// taosFprintfFile(g_fp, "error when use metadb\n");
+// taosCloseFile(&g_fp);
+// exit(-1);
+// }
+// taosFprintfFile(g_fp, "raw:%p\n", &raw);
+//
+// tmq_write_raw(pInfo->taos, raw);
}
char* result = tmq_get_json_meta(msg);
- if(result){
+ if(result && strcmp(result, "") != 0){
//printf("meta result: %s\n", result);
taosFprintfFile(pInfo->pConsumeMetaFile, "%s\n", result);
- taosMemoryFree(result);
}
+ tmq_free_json_meta(result);
}
totalRows++;
@@ -818,8 +818,12 @@ void loop_consume(SThreadInfo* pInfo) {
tmq_res_t msgType = tmq_get_res_type(tmqMsg);
if (msgType == TMQ_RES_TABLE_META) {
totalRows += meta_msg_process(tmqMsg, pInfo, totalMsgs);
- } else if (msgType == TMQ_RES_DATA)
- totalRows += data_msg_process(tmqMsg, pInfo, totalMsgs);
+ } else if (msgType == TMQ_RES_DATA){
+ totalRows += data_msg_process(tmqMsg, pInfo, totalMsgs);
+ } else if (msgType == TMQ_RES_METADATA){
+ meta_msg_process(tmqMsg, pInfo, totalMsgs);
+ totalRows += data_msg_process(tmqMsg, pInfo, totalMsgs);
+ }
}
taos_free_result(tmqMsg);
diff --git a/utils/test/c/tmq_taosx_ci.c b/utils/test/c/tmq_taosx_ci.c
index f917b9159e..3a598ba98b 100644
--- a/utils/test/c/tmq_taosx_ci.c
+++ b/utils/test/c/tmq_taosx_ci.c
@@ -54,24 +54,24 @@ static void msg_process(TAOS_RES* msg) {
printf("db: %s\n", tmq_get_db_name(msg));
printf("vg: %d\n", tmq_get_vgroup_id(msg));
TAOS *pConn = use_db();
- if (tmq_get_res_type(msg) == TMQ_RES_TABLE_META) {
+ if (tmq_get_res_type(msg) == TMQ_RES_TABLE_META || tmq_get_res_type(msg) == TMQ_RES_METADATA) {
char* result = tmq_get_json_meta(msg);
if (result) {
printf("meta result: %s\n", result);
+ if(g_fp && strcmp(result, "") != 0){
+ taosFprintfFile(g_fp, result);
+ taosFprintfFile(g_fp, "\n");
+ }
}
- if(g_fp){
- taosFprintfFile(g_fp, result);
- taosFprintfFile(g_fp, "\n");
- }
-
tmq_free_json_meta(result);
}
tmq_raw_data raw = {0};
tmq_get_raw(msg, &raw);
+ printf("write raw data type: %d\n", raw.raw_type);
int32_t ret = tmq_write_raw(pConn, raw);
printf("write raw data: %s\n", tmq_err2str(ret));
-
+ tmq_free_raw(raw);
taos_close(pConn);
}
@@ -309,6 +309,41 @@ int buildDatabase(TAOS* pConn, TAOS_RES* pRes){
}
taos_free_result(pRes);
}
+
+ pRes = taos_query(pConn,
+ "create stable if not exists stt (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int, t3 "
+ "nchar(8), t4 bool)");
+ if (taos_errno(pRes) != 0) {
+ printf("failed to create super table stt, reason:%s\n", taos_errstr(pRes));
+ return -1;
+ }
+ taos_free_result(pRes);
+
+ pRes = taos_query(pConn,
+ "create stable if not exists sttb (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int, t3 "
+ "nchar(8), t4 bool)");
+ if (taos_errno(pRes) != 0) {
+ printf("failed to create super table sttb, reason:%s\n", taos_errstr(pRes));
+ return -1;
+ }
+ taos_free_result(pRes);
+
+ pRes = taos_query(pConn, "create table if not exists stt1 using stt tags(2, \"stt1\", true) sttb1 using sttb tags(4, \"sttb1\", true) "
+ "stt2 using stt tags(43, \"stt2\", false) sttb2 using sttb tags(54, \"sttb2\", true)");
+ if (taos_errno(pRes) != 0) {
+ printf("failed to create child table stt1, reason:%s\n", taos_errstr(pRes));
+ return -1;
+ }
+ taos_free_result(pRes);
+
+ pRes = taos_query(pConn, "insert into stt3 using stt tags(23, \"stt3\", true) values(now + 1s, 1, 2, 'stt3') sttb3 using sttb tags(4, \"sttb3\", true) values(now + 2s, 13, 22, 'sttb3') "
+ "stt4 using stt tags(433, \"stt4\", false) values(now + 3s, 21, 21, 'stt4') sttb4 using sttb tags(543, \"sttb4\", true) values(now + 4s, 16, 25, 'sttb4')");
+ if (taos_errno(pRes) != 0) {
+ printf("failed to create child table stt1, reason:%s\n", taos_errstr(pRes));
+ return -1;
+ }
+ taos_free_result(pRes);
+
return 0;
}
@@ -542,47 +577,83 @@ void initLogFile() {
}
if(g_conf.snapShot){
- char *result[] = {
- "{\"type\":\"create\",\"tableName\":\"st1\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":64},{\"name\":\"c4\",\"type\":5}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1},{\"name\":\"t2\",\"type\":8,\"length\":64}]}",
- "{\"type\":\"create\",\"tableName\":\"ct0\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]}",
- "{\"type\":\"create\",\"tableName\":\"ct1\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}]}",
- "{\"type\":\"create\",\"tableName\":\"ct2\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[]}",
- "{\"type\":\"create\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":5000}]}",
- "{\"type\":\"create\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c2\",\"type\":10,\"length\":8},{\"name\":\"cc3\",\"type\":5}],\"tags\":[]}",
- "{\"type\":\"create\",\"tableName\":\"jt\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"i\",\"type\":4}],\"tags\":[{\"name\":\"t\",\"type\":15}]}",
- "{\"type\":\"create\",\"tableName\":\"jt1\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[{\"name\":\"t\",\"type\":15,\"value\":\"{\\\"k1\\\":1,\\\"k2\\\":\\\"hello\\\"}\"}]}",
- "{\"type\":\"create\",\"tableName\":\"jt2\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[]}",
- };
-
- for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
- taosFprintfFile(pFile2, result[i]);
- taosFprintfFile(pFile2, "\n");
+ if(g_conf.subTable){
+ char *result[] = {
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"meters_summary\",\"columns\":[{\"name\":\"_wstart\",\"type\":9},{\"name\":\"current\",\"type\":6},{\"name\":\"groupid\",\"type\":4},{\"name\":\"location\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"group_id\",\"type\":14}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"t_d2a450ee819dcf7576f0282d9ac22dbc\",\"using\":\"meters_summary\",\"tagNum\":1,\"tags\":[{\"name\":\"group_id\",\"type\":14,\"value\":1.313555008277358e+19}],\"createList\":[]}"
+ };
+ for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
+ taosFprintfFile(pFile2, result[i]);
+ taosFprintfFile(pFile2, "\n");
+ }
+ }else{
+ char *result[] = {
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"st1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":64},{\"name\":\"c4\",\"type\":5}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1},{\"name\":\"t2\",\"type\":8,\"length\":64}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct1\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct2\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct3\",\"using\":\"st1\",\"tagNum\":4,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":5000}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"normal\",\"tableName\":\"n1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c2\",\"type\":10,\"length\":8},{\"name\":\"cc3\",\"type\":5}],\"tags\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"jt\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"i\",\"type\":4}],\"tags\":[{\"name\":\"t\",\"type\":15}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"jt1\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[{\"name\":\"t\",\"type\":15,\"value\":\"{\\\"k1\\\":1,\\\"k2\\\":\\\"hello\\\"}\"}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"jt2\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"stt\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"sttb\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"stt1\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt1\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"sttb1\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":4},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb1\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"stt2\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":43},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt2\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":0}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"sttb2\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":54},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb2\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"stt3\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":23},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt3\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"sttb3\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":4},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb3\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"stt4\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":433},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt4\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":0}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"sttb4\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":543},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb4\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}"
+ };
+ for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
+ taosFprintfFile(pFile2, result[i]);
+ taosFprintfFile(pFile2, "\n");
+ }
}
}else{
- char *result[] = {
- "{\"type\":\"create\",\"tableName\":\"st1\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
- "{\"type\":\"create\",\"tableName\":\"ct0\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]}",
- "{\"type\":\"create\",\"tableName\":\"ct1\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}]}",
- "{\"type\":\"create\",\"tableName\":\"ct2\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[]}",
- "{\"type\":\"create\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":3000}]}",
- "{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":5,\"colName\":\"c4\",\"colType\":5}",
- "{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":7,\"colName\":\"c3\",\"colType\":8,\"colLength\":64}",
- "{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":1,\"colName\":\"t2\",\"colType\":8,\"colLength\":64}",
- "{\"type\":\"alter\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"alterType\":4,\"colName\":\"t1\",\"colValue\":\"5000\",\"colValueNull\":false}",
- "{\"type\":\"create\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":10,\"length\":4}],\"tags\":[]}",
- "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":5,\"colName\":\"c3\",\"colType\":5}",
- "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":7,\"colName\":\"c2\",\"colType\":10,\"colLength\":8}",
- "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":10,\"colName\":\"c3\",\"colNewName\":\"cc3\"}",
- "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":9}",
- "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":6,\"colName\":\"c1\"}",
- "{\"type\":\"create\",\"tableName\":\"jt\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"i\",\"type\":4}],\"tags\":[{\"name\":\"t\",\"type\":15}]}",
- "{\"type\":\"create\",\"tableName\":\"jt1\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[{\"name\":\"t\",\"type\":15,\"value\":\"{\\\"k1\\\":1,\\\"k2\\\":\\\"hello\\\"}\"}]}",
- "{\"type\":\"create\",\"tableName\":\"jt2\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[]}"
- };
+ if(g_conf.subTable){
+ char *result[] = {
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"meters_summary\",\"columns\":[{\"name\":\"_wstart\",\"type\":9},{\"name\":\"current\",\"type\":6},{\"name\":\"groupid\",\"type\":4},{\"name\":\"location\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"group_id\",\"type\":14}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"t_d2a450ee819dcf7576f0282d9ac22dbc\",\"using\":\"meters_summary\",\"tagNum\":1,\"tags\":[{\"name\":\"group_id\",\"type\":14,\"value\":1.313555008277358e+19}],\"createList\":[]}"
+ };
- for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
- taosFprintfFile(pFile2, result[i]);
- taosFprintfFile(pFile2, "\n");
+ for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
+ taosFprintfFile(pFile2, result[i]);
+ taosFprintfFile(pFile2, "\n");
+ }
+ }else{
+ char *result[] = {
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"st1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct0\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct1\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct2\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"ct3\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":3000}],\"createList\":[]}",
+ "{\"type\":\"alter\",\"tableType\":\"super\",\"tableName\":\"st1\",\"alterType\":5,\"colName\":\"c4\",\"colType\":5}",
+ "{\"type\":\"alter\",\"tableType\":\"super\",\"tableName\":\"st1\",\"alterType\":7,\"colName\":\"c3\",\"colType\":8,\"colLength\":64}",
+ "{\"type\":\"alter\",\"tableType\":\"super\",\"tableName\":\"st1\",\"alterType\":1,\"colName\":\"t2\",\"colType\":8,\"colLength\":64}",
+ "{\"type\":\"alter\",\"tableType\":\"child\",\"tableName\":\"ct3\",\"alterType\":4,\"colName\":\"t1\",\"colValue\":\"5000\",\"colValueNull\":false}",
+ "{\"type\":\"create\",\"tableType\":\"normal\",\"tableName\":\"n1\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":10,\"length\":4}],\"tags\":[]}",
+ "{\"type\":\"alter\",\"tableType\":\"normal\",\"tableName\":\"n1\",\"alterType\":5,\"colName\":\"c3\",\"colType\":5}",
+ "{\"type\":\"alter\",\"tableType\":\"normal\",\"tableName\":\"n1\",\"alterType\":7,\"colName\":\"c2\",\"colType\":10,\"colLength\":8}",
+ "{\"type\":\"alter\",\"tableType\":\"normal\",\"tableName\":\"n1\",\"alterType\":10,\"colName\":\"c3\",\"colNewName\":\"cc3\"}",
+ "{\"type\":\"alter\",\"tableType\":\"normal\",\"tableName\":\"n1\",\"alterType\":9}",
+ "{\"type\":\"alter\",\"tableType\":\"normal\",\"tableName\":\"n1\",\"alterType\":6,\"colName\":\"c1\"}",
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"jt\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"i\",\"type\":4}],\"tags\":[{\"name\":\"t\",\"type\":15}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"jt1\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[{\"name\":\"t\",\"type\":15,\"value\":\"{\\\"k1\\\":1,\\\"k2\\\":\\\"hello\\\"}\"}],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"jt2\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[],\"createList\":[]}",
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"stt\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
+ "{\"type\":\"create\",\"tableType\":\"super\",\"tableName\":\"sttb\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"stt1\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt1\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[{\"tableName\":\"stt1\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt1\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]},{\"tableName\":\"sttb1\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":4},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb1\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]},{\"tableName\":\"stt2\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":43},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt2\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":0}]},{\"tableName\":\"sttb2\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":54},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb2\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]}]}",
+ "{\"type\":\"create\",\"tableType\":\"child\",\"tableName\":\"stt3\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":23},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt3\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}],\"createList\":[{\"tableName\":\"stt3\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":23},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt3\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]},{\"tableName\":\"sttb3\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":4},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb3\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]},{\"tableName\":\"stt4\",\"using\":\"stt\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":433},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"stt4\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":0}]},{\"tableName\":\"sttb4\",\"using\":\"sttb\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":543},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"sttb4\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]}]}"
+ };
+
+ for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){
+ taosFprintfFile(pFile2, result[i]);
+ taosFprintfFile(pFile2, "\n");
+ }
}
}
@@ -619,5 +690,6 @@ int main(int argc, char* argv[]) {
tmq_t* tmq = build_consumer();
tmq_list_t* topic_list = build_topic_list();
basic_consume_loop(tmq, topic_list);
+ tmq_list_destroy(topic_list);
taosCloseFile(&g_fp);
}