diff --git a/docs/en/07-develop/02-model/index.mdx b/docs/en/07-develop/02-model/index.mdx index e0378cc77c..b647c845d0 100644 --- a/docs/en/07-develop/02-model/index.mdx +++ b/docs/en/07-develop/02-model/index.mdx @@ -9,15 +9,15 @@ The data model employed by TDengine is similar to that of a relational database. The [characteristics of time-series data](https://www.taosdata.com/blog/2019/07/09/86.html) from different data collection points may be different. Characteristics include collection frequency, retention policy and others which determine how you create and configure the database. For e.g. days to keep, number of replicas, data block size, whether data updates are allowed and other configurable parameters would be determined by the characteristics of your data and your business requirements. For TDengine to operate with the best performance, we strongly recommend that you create and configure different databases for data with different characteristics. This allows you, for example, to set up different storage and retention policies. When creating a database, there are a lot of parameters that can be configured such as, the days to keep data, the number of replicas, the number of memory blocks, time precision, the minimum and maximum number of rows in each data block, whether compression is enabled, the time range of the data in single data file and so on. Below is an example of the SQL statement to create a database. ```sql -CREATE DATABASE power KEEP 365 DAYS 10 BLOCKS 6 UPDATE 1; +CREATE DATABASE power KEEP 365 DURATION 10 BUFFER 16 VGROUPS 100 WAL 1; ``` In the above SQL statement: - a database named "power" will be created - the data in it will be kept for 365 days, which means that data older than 365 days will be deleted automatically - a new data file will be created every 10 days -- the number of memory blocks is 6 -- data is allowed to be updated +- the size of memory cache for writing is 16 MB +- data will be firstly written to WAL without FSYNC For more details please refer to [Database](/taos-sql/database). @@ -30,7 +30,6 @@ USE power; :::note - Any table or STable must belong to a database. To create a table or STable, the database it belongs to must be ready. -- JOIN operations can't be performed on tables from two different databases. - Timestamp needs to be specified when inserting rows or querying historical rows. ::: @@ -52,7 +51,7 @@ Similar to creating a regular table, when creating a STable, the name and schema For each kind of data collection point, a corresponding STable must be created. There may be many STables in an application. For electrical power system, we need to create a STable respectively for meters, transformers, busbars, switches. There may be multiple kinds of data collection points on a single device, for example there may be one data collection point for electrical data like current and voltage and another data collection point for environmental data like temperature, humidity and wind direction. Multiple STables are required for these kinds of devices. -At most 4096 (or 1024 prior to version 2.1.7.0) columns are allowed in a STable. If there are more than 4096 of metrics to be collected for a data collection point, multiple STables are required. There can be multiple databases in a system, while one or more STables can exist in a database. +At most 4096 columns are allowed in a STable. If there are more than 4096 of metrics to be collected for a data collection point, multiple STables are required. There can be multiple databases in a system, while one or more STables can exist in a database. ## Create Table @@ -66,12 +65,11 @@ In the above SQL statement, "d1001" is the table name, "meters" is the STable na In the TDengine system, it's recommended to create a table for a data collection point via STable. A table created via STable is called subtable in some parts of the TDengine documentation. All SQL commands applied on regular tables can be applied on subtables. -:::warning -It's not recommended to create a table in a database while using a STable from another database as template. - :::tip It's suggested to use the globally unique ID of a data collection point as the table name. For example the device serial number could be used as a unique ID. If a unique ID doesn't exist, multiple IDs that are not globally unique can be combined to form a globally unique ID. It's not recommended to use a globally unique ID as tag value. +::: + ## Create Table Automatically In some circumstances, it's unknown whether the table already exists when inserting rows. The table can be created automatically using the SQL statement below, and nothing will happen if the table already exists. diff --git a/docs/en/07-develop/03-insert-data/01-sql-writing.mdx b/docs/en/07-develop/03-insert-data/01-sql-writing.mdx index d8c4453f40..da0e87abbc 100644 --- a/docs/en/07-develop/03-insert-data/01-sql-writing.mdx +++ b/docs/en/07-develop/03-insert-data/01-sql-writing.mdx @@ -42,7 +42,7 @@ INSERT INTO d1001 VALUES (1538548684000, 10.2, 220, 0.23) (1538548696650, 10.3, ### Insert into Multiple Tables -Data can be inserted into multiple tables in the same SQL statement. The example below inserts 2 rows into table "d1001" and 1 row into table "d1002". +Data can be inserted into multiple tables in single SQL statement. The example below inserts 2 rows into table "d1001" and 1 row into table "d1002". ```sql INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, 218, 0.33) d1002 VALUES (1538548696800, 12.3, 221, 0.31); @@ -52,15 +52,15 @@ For more details about `INSERT` please refer to [INSERT](/taos-sql/insert). :::info -- Inserting in batches can improve performance. Normally, the higher the batch size, the better the performance. Please note that a single row can't exceed 48K bytes and each SQL statement can't exceed 1MB. -- Inserting with multiple threads can also improve performance. However, depending on the system resources on the application side and the server side, when the number of inserting threads grows beyond a specific point the performance may drop instead of improving. The proper number of threads needs to be tested in a specific environment to find the best number. +- Inserting in batches can improve performance. Normally, the higher the batch size, the better the performance. Please note that a single row can't exceed 48 KB bytes and each SQL statement can't exceed 1 MB. +- Inserting with multiple threads can also improve performance. However, depending on the system resources on the application side and the server side, when the number of inserting threads grows beyond a specific point the performance may drop instead of improving. The proper number of threads needs to be tested in a specific environment to find the best number. The proper number of threads may be impacted by the system resources on the server side, the system resources on the client side, the table schemas, etc. ::: :::warning -- If the timestamp for the row to be inserted already exists in the table, the behavior depends on the value of parameter `UPDATE`. If it's set to 0 (the default value), the row will be discarded. If it's set to 1, the new values will override the old values for the same row. -- The timestamp to be inserted must be newer than the timestamp of subtracting current time by the parameter `KEEP`. If `KEEP` is set to 3650 days, then the data older than 3650 days ago can't be inserted. The timestamp to be inserted can't be newer than the timestamp of current time plus parameter `DAYS`. If `DAYS` is set to 2, the data newer than 2 days later can't be inserted. +- If the timestamp for the row to be inserted already exists in the table, the old data will be overritten by the new values for the columns for which new values are provided, columns for which no new values are provided are not impacted. +- The timestamp to be inserted must be newer than the timestamp of subtracting current time by the parameter `KEEP`. If `KEEP` is set to 3650 days, then the data older than 3650 days ago can't be inserted. The timestamp to be inserted can't be newer than the timestamp of current time plus parameter `DURATION`. If `DAYS` is set to 2, the data newer than 2 days later can't be inserted. ::: @@ -101,7 +101,7 @@ For more details about `INSERT` please refer to [INSERT](/taos-sql/insert). ### Insert with Parameter Binding -TDengine also provides API support for parameter binding. Similar to MySQL, only `?` can be used in these APIs to represent the parameters to bind. From version 2.1.1.0 and 2.1.2.0, parameter binding support for inserting data has improved significantly to improve the insert performance by avoiding the cost of parsing SQL statements. +TDengine also provides API support for parameter binding. Similar to MySQL, only `?` can be used in these APIs to represent the parameters to bind. Parameter binding support for inserting data has improved significantly to improve the insert performance by avoiding the cost of parsing SQL statements. Parameter binding is available only with native connection. diff --git a/docs/en/12-taos-sql/02-database.md b/docs/en/12-taos-sql/02-database.md index 80581b2f1b..c2961d6241 100644 --- a/docs/en/12-taos-sql/02-database.md +++ b/docs/en/12-taos-sql/02-database.md @@ -32,7 +32,6 @@ CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1]; - cacheLast: [Description](/reference/config/#cachelast) - replica: [Description](/reference/config/#replica) - quorum: [Description](/reference/config/#quorum) - - maxVgroupsPerDb: [Description](/reference/config/#maxvgroupsperdb) - comp: [Description](/reference/config/#comp) - precision: [Description](/reference/config/#precision) 6. Please note that all of the parameters mentioned in this section are configured in configuration file `taos.cfg` on the TDengine server. If not specified in the `create database` statement, the values from taos.cfg are used by default. To override default parameters, they must be specified in the `create database` statement. diff --git a/docs/zh/07-develop/02-model/index.mdx b/docs/zh/07-develop/02-model/index.mdx index 7e2762b6e7..be545e8813 100644 --- a/docs/zh/07-develop/02-model/index.mdx +++ b/docs/zh/07-develop/02-model/index.mdx @@ -8,13 +8,13 @@ TDengine 采用类关系型数据模型,需要建库、建表。因此对于 ## 创建库 -不同类型的数据采集点往往具有不同的数据特征,包括数据采集频率的高低,数据保留时间的长短,副本的数目,数据块的大小,是否允许更新数据等等。为了在各种场景下 TDengine 都能最大效率的工作,TDengine 建议将不同数据特征的表创建在不同的库里,因为每个库可以配置不同的存储策略。创建一个库时,除 SQL 标准的选项外,还可以指定保留时长、副本数、内存块个数、时间精度、文件块里最大最小记录条数、是否压缩、一个数据文件覆盖的天数等多种参数。比如: +不同类型的数据采集点往往具有不同的数据特征,包括数据采集频率的高低,数据保留时间的长短,副本的数目,数据块的大小,是否允许更新数据等等。为了在各种场景下 TDengine 都能最大效率的工作,TDengine 建议将不同数据特征的表创建在不同的库里,因为每个库可以配置不同的存储策略。创建一个库时,除 SQL 标准的选项外,还可以指定保留时长、副本数、缓存大小、时间精度、文件块里最大最小记录条数、是否压缩、一个数据文件覆盖的天数等多种参数。比如: ```sql -CREATE DATABASE power KEEP 365 DAYS 10 BLOCKS 6 UPDATE 1; +CREATE DATABASE power KEEP 365 DURATION 10 BUFFER 16 VGROUPS 100 WAL 1; ``` -上述语句将创建一个名为 power 的库,这个库的数据将保留 365 天(超过 365 天将被自动删除),每 10 天一个数据文件,内存块数为 6,允许更新数据。详细的语法及参数请见 [数据库管理](/taos-sql/database) 章节。 +上述语句将创建一个名为 power 的库,这个库的数据将保留 365 天(超过 365 天将被自动删除),每 10 天一个数据文件,每个 VNODE 的写入内存池的大小为 16 MB,数据库的 VGROUPS 数量,对该数据库入会写 WAL 但不执行 FSYNC。详细的语法及参数请见 [数据库管理](/taos-sql/database) 章节。 创建库之后,需要使用 SQL 命令 `USE` 将当前库切换过来,例如: @@ -27,7 +27,6 @@ USE power; :::note - 任何一张表或超级表必须属于某个库,在创建表之前,必须先创建库。 -- 处于两个不同库的表是不能进行 JOIN 操作的。 - 创建并插入记录、查询历史记录的时候,均需要指定时间戳。 ::: @@ -40,15 +39,11 @@ USE power; CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int); ``` -:::note -这一指令中的 STABLE 关键字,在 2.0.15 之前的版本中需写作 TABLE 。 -::: - 与创建普通表一样,创建超级表时,需要提供表名(示例中为 meters),表结构 Schema,即数据列的定义。第一列必须为时间戳(示例中为 ts),其他列为采集的物理量(示例中为 current, voltage, phase),数据类型可以为整型、浮点型、字符串等。除此之外,还需要提供标签的 schema (示例中为 location, groupId),标签的数据类型可以为整型、浮点型、字符串等。采集点的静态属性往往可以作为标签,比如采集点的地理位置、设备型号、设备组 ID、管理员 ID 等等。标签的 schema 可以事后增加、删除、修改。具体定义以及细节请见 [TAOS SQL 的超级表管理](/taos-sql/stable) 章节。 每一种类型的数据采集点需要建立一个超级表,因此一个物联网系统,往往会有多个超级表。对于电网,我们就需要对智能电表、变压器、母线、开关等都建立一个超级表。在物联网中,一个设备就可能有多个数据采集点(比如一台风力发电的风机,有的采集点采集电流、电压等电参数,有的采集点采集温度、湿度、风向等环境参数),这个时候,对这一类型的设备,需要建立多张超级表。 -一张超级表最多容许 4096 列 (在 2.1.7.0 版本之前,列数限制为 1024 列),如果一个采集点采集的物理量个数超过 4096,需要建多张超级表来处理。一个系统可以有多个 DB,一个 DB 里可以有一到多个超级表。 +一张超级表最多容许 4096 列,如果一个采集点采集的物理量个数超过 4096,需要建多张超级表来处理。一个系统可以有多个 DB,一个 DB 里可以有一到多个超级表。 ## 创建表 @@ -60,11 +55,6 @@ CREATE TABLE d1001 USING meters TAGS ("California.SanFrancisco", 2); 其中 d1001 是表名,meters 是超级表的表名,后面紧跟标签 Location 的具体标签值 "California.SanFrancisco",标签 groupId 的具体标签值 2。虽然在创建表时,需要指定标签值,但可以事后修改。详细细则请见 [TAOS SQL 的表管理](/taos-sql/table) 章节。 -:::warning -目前 TDengine 没有从技术层面限制使用一个 database (db1) 的超级表作为模板建立另一个 database (db2) 的子表,后续会禁止这种用法,不建议使用这种方法建表。 - -::: - TDengine 建议将数据采集点的全局唯一 ID 作为表名(比如设备序列号)。但对于有的场景,并没有唯一的 ID,可以将多个 ID 组合成一个唯一的 ID。不建议将具有唯一性的 ID 作为标签值。 ### 自动建表 diff --git a/docs/zh/07-develop/03-insert-data/01-sql-writing.mdx b/docs/zh/07-develop/03-insert-data/01-sql-writing.mdx index 99a92573c8..214cbdaa96 100644 --- a/docs/zh/07-develop/03-insert-data/01-sql-writing.mdx +++ b/docs/zh/07-develop/03-insert-data/01-sql-writing.mdx @@ -52,15 +52,15 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, :::info -- 要提高写入效率,需要批量写入。一批写入的记录条数越多,插入效率就越高。但一条记录不能超过 48K,一条 SQL 语句总长度不能超过 1M 。 -- TDengine 支持多线程同时写入,要进一步提高写入速度,一个客户端需要打开 20 个以上的线程同时写。但线程数达到一定数量后,无法再提高,甚至还会下降,因为线程频繁切换,带来额外开销。 +- 要提高写入效率,需要批量写入。一般来说一批写入的记录条数越多,插入效率就越高。但一条记录不能超过 48K,一条 SQL 语句总长度不能超过 1M 。 +- TDengine 支持多线程同时写入,要进一步提高写入速度,一个客户端需要打开多个同时写。但线程数达到一定数量后,无法再提高,甚至还会下降,因为线程频繁切换,会带来额外开销,合适的线程数量与服务端的处理能力,服务端的具体配置,数据库的参数,数据定义的 Schema,写入数据的 Batch Size 等很多因素相关。一般来说,服务端和客户端处理能力越强,所能支持的并发写入的线程可以越多;数据库配置时的 vgroups 越多(但仍然要在服务端的处理能力以内)则所能支持的并发写入越多;数据定义的 Schema 越简单,所能支持的并发写入越多。 ::: :::warning -- 对同一张表,如果新插入记录的时间戳已经存在,默认情形下(UPDATE=0)新记录将被直接抛弃,也就是说,在一张表里,时间戳必须是唯一的。如果应用自动生成记录,很有可能生成的时间戳是一样的,这样,成功插入的记录条数会小于应用插入的记录条数。如果在创建数据库时使用了 UPDATE 1 选项,插入相同时间戳的新记录将覆盖原有记录。 -- 写入的数据的时间戳必须大于当前时间减去配置参数 keep 的时间。如果 keep 配置为 3650 天,那么无法写入比 3650 天还早的数据。写入数据的时间戳也不能大于当前时间加配置参数 days。如果 days 为 2,那么无法写入比当前时间还晚 2 天的数据。 +- 对同一张表,如果新插入记录的时间戳已经存在,则指定了新值的列会用新值覆盖旧值,而没有指定新值的列则不受影响。 +- 写入的数据的时间戳必须大于当前时间减去配置参数 keep 的时间。如果 keep 配置为 3650 天,那么无法写入比 3650 天还早的数据。写入数据的时间戳也不能大于当前时间加配置参数 duration。如果 duration 为 2,那么无法写入比当前时间还晚 2 天的数据。 ::: @@ -104,7 +104,7 @@ INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, ### 参数绑定写入 -TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 类似,这些 API 目前也仅支持用问号 `?` 来代表待绑定的参数。从 2.1.1.0 和 2.1.2.0 版本开始,TDengine 大幅改进了参数绑定接口对数据写入(INSERT)场景的支持。这样在通过参数绑定接口写入数据时,就避免了 SQL 语法解析的资源消耗,从而在绝大多数情况下显著提升写入性能。 +TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 类似,这些 API 目前也仅支持用问号 `?` 来代表待绑定的参数。在通过参数绑定接口写入数据时,就避免了 SQL 语法解析的资源消耗,从而在绝大多数情况下显著提升写入性能。 需要注意的是,只有使用原生连接的连接器,才能使用参数绑定功能。 diff --git a/docs/zh/12-taos-sql/02-database.md b/docs/zh/12-taos-sql/02-database.md index 566fec3241..e3a0aa7c87 100644 --- a/docs/zh/12-taos-sql/02-database.md +++ b/docs/zh/12-taos-sql/02-database.md @@ -32,7 +32,6 @@ CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1]; - cacheLast: [详细说明](/reference/config/#cachelast) - replica: [详细说明](/reference/config/#replica) - quorum: [详细说明](/reference/config/#quorum) - - maxVgroupsPerDb: [详细说明](/reference/config/#maxvgroupsperdb) - comp: [详细说明](/reference/config/#comp) - precision: [详细说明](/reference/config/#precision) 6. 请注意上面列出的所有参数都可以配置在配置文件 `taosd.cfg` 中作为创建数据库时使用的默认配置, `create database` 的参数中明确指定的会覆盖配置文件中的设置。 diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 3d15e8b087..d8264ac5b5 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -108,6 +108,7 @@ typedef struct SDataBlockInfo { // TODO: optimize and remove following int32_t childId; // used for stream, do not serialize EStreamType type; // used for stream, do not serialize + STimeWindow calWin; // used for stream, do not serialize } SDataBlockInfo; typedef struct SSDataBlock { diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index eaa8ac5cc4..1011b90ce8 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -64,18 +64,22 @@ int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type); int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type); int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); -// STSRow2 +// SColVal #define COL_VAL_NONE(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .isNone = 1}) #define COL_VAL_NULL(CID, TYPE) ((SColVal){.cid = (CID), .type = (TYPE), .isNull = 1}) #define COL_VAL_VALUE(CID, TYPE, V) ((SColVal){.cid = (CID), .type = (TYPE), .value = (V)}) +// STSRow2 +#define TSROW_LEN(PROW, V) tGetI32v((uint8_t *)(PROW)->data, (V) ? &(V) : NULL) +#define TSROW_SVER(PROW, V) tGetI32v((PROW)->data + TSROW_LEN(PROW, NULL), (V) ? &(V) : NULL) + int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow); int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow); void tTSRowFree(STSRow2 *pRow); void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal); int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray); int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow); -int32_t tGetTSRow(uint8_t *p, STSRow2 *pRow); +int32_t tGetTSRow(uint8_t *p, STSRow2 **ppRow); // STSRowBuilder #define tsRowBuilderInit() ((STSRowBuilder){0}) @@ -97,7 +101,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag); int32_t tTagToValArray(const STag *pTag, SArray **ppArray); void debugPrintSTag(STag *pTag, const char *tag, int32_t ln); // TODO: remove -int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, void* pMsgBuf); +int32_t parseJsontoTagData(const char *json, SArray *pTagVals, STag **ppTag, void *pMsgBuf); // STRUCT ================= struct STColumn { @@ -123,16 +127,16 @@ struct STSchema { #define TSROW_KV_SMALL ((uint8_t)0x10U) #define TSROW_KV_MID ((uint8_t)0x20U) #define TSROW_KV_BIG ((uint8_t)0x40U) +#pragma pack(push, 1) struct STSRow2 { - TSKEY ts; - uint8_t flags; - int32_t sver; - uint32_t nData; - uint8_t *pData; + TSKEY ts; + uint8_t flags; + uint8_t data[]; }; +#pragma pack(pop) struct STSRowBuilder { - STSRow2 tsRow; + // STSRow2 tsRow; int32_t szBuf; uint8_t *pBuf; }; @@ -226,50 +230,6 @@ struct STag { memcpy(varDataVal(x), (str), (_size)); \ } while (0); -// ----------------- TSDB COLUMN DEFINITION - -#define colType(col) ((col)->type) -#define colFlags(col) ((col)->flags) -#define colColId(col) ((col)->colId) -#define colBytes(col) ((col)->bytes) -#define colOffset(col) ((col)->offset) - -#define colSetType(col, t) (colType(col) = (t)) -#define colSetFlags(col, f) (colFlags(col) = (f)) -#define colSetColId(col, id) (colColId(col) = (id)) -#define colSetBytes(col, b) (colBytes(col) = (b)) -#define colSetOffset(col, o) (colOffset(col) = (o)) - -// ----------------- TSDB SCHEMA DEFINITION - -#define schemaNCols(s) ((s)->numOfCols) -#define schemaVersion(s) ((s)->version) -#define schemaTLen(s) ((s)->tlen) -#define schemaFLen(s) ((s)->flen) -#define schemaVLen(s) ((s)->vlen) -#define schemaColAt(s, i) ((s)->columns + i) -#define tdFreeSchema(s) taosMemoryFreeClear((s)) - -STSchema *tdDupSchema(const STSchema *pSchema); -int32_t tdEncodeSchema(void **buf, STSchema *pSchema); -void *tdDecodeSchema(void *buf, STSchema **pRSchema); - -static FORCE_INLINE int32_t comparColId(const void *key1, const void *key2) { - if (*(int16_t *)key1 > ((STColumn *)key2)->colId) { - return 1; - } else if (*(int16_t *)key1 < ((STColumn *)key2)->colId) { - return -1; - } else { - return 0; - } -} - -static FORCE_INLINE STColumn *tdGetColOfID(STSchema *pSchema, int16_t colId) { - void *ptr = bsearch(&colId, (void *)pSchema->columns, schemaNCols(pSchema), sizeof(STColumn), comparColId); - if (ptr == NULL) return NULL; - return (STColumn *)ptr; -} - // ----------------- SCHEMA BUILDER DEFINITION typedef struct { int32_t tCols; @@ -299,141 +259,6 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, col_id_t colId, col_bytes_t bytes); STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); -// ----------------- Semantic timestamp key definition -// typedef uint64_t TKEY; -#define TKEY TSKEY - -#define TKEY_INVALID UINT64_MAX -#define TKEY_NULL TKEY_INVALID -#define TKEY_NEGATIVE_FLAG (((TKEY)1) << 63) -#define TKEY_VALUE_FILTER (~(TKEY_NEGATIVE_FLAG)) - -#define TKEY_IS_NEGATIVE(tkey) (((tkey)&TKEY_NEGATIVE_FLAG) != 0) -#define TKEY_IS_DELETED(tkey) (false) - -#define tdGetTKEY(key) (key) -#define tdGetKey(tskey) (tskey) - -#define MIN_TS_KEY ((TSKEY)0x8000000000000001) -#define MAX_TS_KEY ((TSKEY)0x7fffffffffffffff) - -#define TD_TO_TKEY(key) tdGetTKEY(((key) < MIN_TS_KEY) ? MIN_TS_KEY : (((key) > MAX_TS_KEY) ? MAX_TS_KEY : key)) - -static FORCE_INLINE TKEY keyToTkey(TSKEY key) { - TSKEY lkey = key; - if (key > MAX_TS_KEY) { - lkey = MAX_TS_KEY; - } else if (key < MIN_TS_KEY) { - lkey = MIN_TS_KEY; - } - - return tdGetTKEY(lkey); -} - -static FORCE_INLINE int32_t tkeyComparFn(const void *tkey1, const void *tkey2) { - TSKEY key1 = tdGetKey(*(TKEY *)tkey1); - TSKEY key2 = tdGetKey(*(TKEY *)tkey2); - - if (key1 < key2) { - return -1; - } else if (key1 > key2) { - return 1; - } else { - return 0; - } -} - -// ----------------- Data column structure -// SDataCol arrangement: data => bitmap => dataOffset -typedef struct SDataCol { - int8_t type; // column type - uint8_t bitmap : 1; // 0: no bitmap if all rows are NORM, 1: has bitmap if has NULL/NORM rows - uint8_t reserve : 7; - int16_t colId; // column ID - int32_t bytes; // column data bytes defined - int32_t offset; // data offset in a SDataRow (including the header size) - int32_t spaceSize; // Total space size for this column - int32_t len; // column data length - VarDataOffsetT *dataOff; // For binary and nchar data, the offset in the data column - void *pData; // Actual data pointer - void *pBitmap; // Bitmap pointer - TSKEY ts; // only used in last NULL column -} SDataCol; - -#define isAllRowsNull(pCol) ((pCol)->len == 0) -#define isAllRowsNone(pCol) ((pCol)->len == 0) -static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; } - -int32_t tdAllocMemForCol(SDataCol *pCol, int32_t maxPoints); - -void dataColInit(SDataCol *pDataCol, STColumn *pCol, int32_t maxPoints); -int32_t dataColAppendVal(SDataCol *pCol, const void *value, int32_t numOfRows, int32_t maxPoints); -void *dataColSetOffset(SDataCol *pCol, int32_t nEle); - -bool isNEleNull(SDataCol *pCol, int32_t nEle); - -typedef struct { - col_id_t maxCols; // max number of columns - col_id_t numOfCols; // Total number of cols - int32_t maxPoints; // max number of points - int32_t numOfRows; - int32_t bitmapMode : 1; // default is 0(2 bits), otherwise 1(1 bit) - int32_t sversion : 31; // TODO: set sversion(not used yet) - SDataCol *cols; -} SDataCols; - -static FORCE_INLINE bool tdDataColsIsBitmapI(SDataCols *pCols) { return pCols->bitmapMode != TSDB_BITMODE_DEFAULT; } -static FORCE_INLINE void tdDataColsSetBitmapI(SDataCols *pCols) { pCols->bitmapMode = TSDB_BITMODE_ONE_BIT; } -static FORCE_INLINE bool tdIsBitmapModeI(int8_t bitmapMode) { return bitmapMode != TSDB_BITMODE_DEFAULT; } - -#define keyCol(pCols) (&((pCols)->cols[0])) // Key column -#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] // the idx row of column-wised data -#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx)) -static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) { - if (pCols->numOfRows) { - return dataColsTKeyAt(pCols, 0); - } else { - return TKEY_INVALID; - } -} - -static FORCE_INLINE TSKEY dataColsKeyAtRow(SDataCols *pCols, int32_t row) { - assert(row < pCols->numOfRows); - return dataColsKeyAt(pCols, row); -} - -static FORCE_INLINE TSKEY dataColsKeyFirst(SDataCols *pCols) { - if (pCols->numOfRows) { - return dataColsKeyAt(pCols, 0); - } else { - return TSDB_DATA_TIMESTAMP_NULL; - } -} - -static FORCE_INLINE TKEY dataColsTKeyLast(SDataCols *pCols) { - if (pCols->numOfRows) { - return dataColsTKeyAt(pCols, pCols->numOfRows - 1); - } else { - return TKEY_INVALID; - } -} - -static FORCE_INLINE TSKEY dataColsKeyLast(SDataCols *pCols) { - if (pCols->numOfRows) { - return dataColsKeyAt(pCols, pCols->numOfRows - 1); - } else { - return TSDB_DATA_TIMESTAMP_NULL; - } -} - -SDataCols *tdNewDataCols(int32_t maxCols, int32_t maxRows); -void tdResetDataCols(SDataCols *pCols); -int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema); -SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData); -SDataCols *tdFreeDataCols(SDataCols *pCols); -int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool update, - TDRowVerT maxVer); - #endif #ifdef __cplusplus diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 41674b7a70..944eaa28bc 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -67,7 +67,6 @@ extern int32_t tsNumOfVnodeQueryThreads; extern int32_t tsNumOfVnodeFetchThreads; extern int32_t tsNumOfVnodeWriteThreads; extern int32_t tsNumOfVnodeSyncThreads; -extern int32_t tsNumOfVnodeMergeThreads; extern int32_t tsNumOfQnodeQueryThreads; extern int32_t tsNumOfQnodeFetchThreads; extern int32_t tsNumOfSnodeSharedThreads; diff --git a/include/common/tmsg.h b/include/common/tmsg.h index e09de1e23e..0ab65e7978 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -723,7 +723,7 @@ typedef struct { int32_t buffer; // MB int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -736,7 +736,7 @@ typedef struct { int8_t compression; int8_t replications; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t schemaless; int8_t ignoreExist; int32_t numOfRetensions; @@ -752,7 +752,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -760,7 +760,7 @@ typedef struct { int32_t fsyncPeriod; int8_t walLevel; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t replications; } SAlterDbReq; @@ -822,6 +822,20 @@ typedef struct { int32_t tSerializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq); int32_t tDeserializeSTrimDbReq(void* buf, int32_t bufLen, STrimDbReq* pReq); +typedef struct { + int32_t timestamp; +} SVTrimDbReq; + +int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq); +int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq); + +typedef struct { + int32_t timestamp; +} SVDropTtlTableReq; + +int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq); +int32_t tDeserializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq); + typedef struct { int32_t numOfVgroups; int32_t numOfStables; @@ -840,7 +854,7 @@ typedef struct { int8_t compression; int8_t replications; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int32_t numOfRetensions; SArray* pRetensions; int8_t schemaless; @@ -1105,7 +1119,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -1120,7 +1134,7 @@ typedef struct { int8_t precision; int8_t compression; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t isTsma; int8_t standby; int8_t replica; @@ -1158,7 +1172,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -1166,7 +1180,7 @@ typedef struct { int32_t fsyncPeriod; int8_t walLevel; int8_t strict; - int8_t cacheLastRow; + int8_t cacheLast; int8_t selfIndex; int8_t replica; SReplica replicas[TSDB_MAX_REPLICA]; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 1dbfbfb2b9..488bc6346e 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -199,9 +199,10 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_ALTER_REPLICA, "alter-replica", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_CONFIRM, "alter-confirm", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_DROP_TTL_TABLE, "drop-ttl-stb", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_COMMIT, "commit vnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "vnode-compact", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TTL_TABLE, "vnode-drop-ttl-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TRIM, "vnode-trim", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_COMMIT, "vnode-commit", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_MAX_MSG, "vnd-max", NULL, NULL) TD_NEW_MSG_SEG(TDMT_SCH_MSG) diff --git a/include/common/trow.h b/include/common/trow.h index 086a6ce6fb..807a4c0f0a 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -168,7 +168,7 @@ typedef struct { // N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and // (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined. -#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN) +#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) ((s)->tlen + TD_ROW_HEAD_LEN) #define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i)) #define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t)) @@ -223,9 +223,10 @@ int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDR static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode); bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode); -int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t maxPoints, - int8_t bitmapMode, bool isMerge); -int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge); +// int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t +// maxPoints, +// int8_t bitmapMode, bool isMerge); +// int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge); int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType); int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType); @@ -318,12 +319,9 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SC bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal); bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx, SCellVal *pVal); bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal); -STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2); -int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int32_t row, int8_t bitmapMode); bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t flen, uint32_t offset, col_id_t colIdx, SCellVal *pVal); bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVal); -int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, int8_t bitmapMode); void tdSCellValPrint(SCellVal *pVal, int8_t colType); void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag); diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 70056783ea..3bed77d682 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -52,6 +52,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption); * @param pMnode The mnode object to close. */ void mndClose(SMnode *pMnode); +void mndPreClose(SMnode *pMnode); /** * @brief Start mnode diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 783193db49..630e983f81 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -42,25 +42,28 @@ typedef struct SReadHandle { bool initTqReader; } SReadHandle; +// in queue mode, data streams are seperated by msg typedef enum { OPTR_EXEC_MODEL_BATCH = 0x1, OPTR_EXEC_MODEL_STREAM = 0x2, + OPTR_EXEC_MODEL_QUEUE = 0x3, } EOPTR_EXEC_MODEL; /** - * Create the exec task for streaming mode + * Create the exec task for stream mode * @param pMsg - * @param streamReadHandle + * @param SReadHandle * @return */ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers); /** - * Switch the stream scan to snapshot mode - * @param tinfo + * Create the exec task for queue mode + * @param pMsg + * @param SReadHandle * @return */ -int32_t qStreamScanSnapshot(qTaskInfo_t tinfo); +qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers); /** * Set the input data block for the stream scan. @@ -111,7 +114,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, * @return */ int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, - int32_t* tversion); + int32_t* tversion); /** * The main task execution function, including query on both table and multiple tables, diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index d6cb2c27b0..ac9784b91b 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -14,6 +14,7 @@ */ #include "os.h" +#include "query.h" #include "tdatablock.h" #include "tmsg.h" #include "tmsgcb.h" @@ -119,6 +120,7 @@ static FORCE_INLINE void* streamQueueCurItem(SStreamQueue* queue) { return queue static FORCE_INLINE void* streamQueueNextItem(SStreamQueue* queue) { int8_t dequeueFlag = atomic_exchange_8(&queue->status, STREAM_QUEUE__PROCESSING); if (dequeueFlag == STREAM_QUEUE__FAILED) { + ASSERT(0); ASSERT(queue->qItem != NULL); return streamQueueCurItem(queue); } else { @@ -305,6 +307,7 @@ static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED); return -1; } + qInfo("task %d %p submit enqueue %p %p %p", pTask->taskId, pTask, pItem, pSubmitClone, pSubmitClone->data); taosWriteQitem(pTask->inputQueue->queue, pSubmitClone); } else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) { taosWriteQitem(pTask->inputQueue->queue, pItem); diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 0a8e55bb4f..7e2d09dd63 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -45,7 +45,6 @@ extern "C" { #define WAL_MAGIC 0xFAFBFCFDULL typedef enum { - TAOS_WAL_NOLOG = 0, TAOS_WAL_WRITE = 1, TAOS_WAL_FSYNC = 2, } EWalType; @@ -74,7 +73,7 @@ typedef struct { int8_t isWeek; uint64_t seqNum; uint64_t term; -} SSyncLogMeta; +} SWalSyncInfo; typedef struct { int8_t protoVer; @@ -84,7 +83,7 @@ typedef struct { int64_t ingestTs; // not implemented // sync meta - SSyncLogMeta syncMeta; + SWalSyncInfo syncMeta; char body[]; } SWalCont; @@ -149,11 +148,22 @@ SWal *walOpen(const char *path, SWalCfg *pCfg); int32_t walAlter(SWal *, SWalCfg *pCfg); void walClose(SWal *); -// write -int32_t walWriteWithSyncInfo(SWal *, int64_t index, tmsg_t msgType, SSyncLogMeta syncMeta, const void *body, - int32_t bodyLen); +// write interfaces + +// By assigning index by the caller, wal gurantees linearizability int32_t walWrite(SWal *, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen); -void walFsync(SWal *, bool force); +int32_t walWriteWithSyncInfo(SWal *, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, + int32_t bodyLen); + +// This interface assign version automatically and return to caller. +// When using this interface with concurrent writes, +// wal will write all logs atomically, +// but not sure which one will be actually write first, +// and then the unique index of successful writen is returned. +// -1 will be returned for failed writes +int64_t walAppendLog(SWal *, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen); + +void walFsync(SWal *, bool force); // apis for lifecycle management int32_t walCommit(SWal *, int64_t ver); diff --git a/include/util/tRealloc.h b/include/util/tRealloc.h index 8d40f6cc5d..f3593d5818 100644 --- a/include/util/tRealloc.h +++ b/include/util/tRealloc.h @@ -25,10 +25,11 @@ extern "C" { static FORCE_INLINE int32_t tRealloc(uint8_t **ppBuf, int64_t size) { int32_t code = 0; int64_t bsize = 0; - uint8_t *pBuf; + uint8_t *pBuf = NULL; if (*ppBuf) { - bsize = *(int64_t *)((*ppBuf) - sizeof(int64_t)); + pBuf = (*ppBuf) - sizeof(int64_t); + bsize = *(int64_t *)pBuf; } if (bsize >= size) goto _exit; @@ -38,7 +39,7 @@ static FORCE_INLINE int32_t tRealloc(uint8_t **ppBuf, int64_t size) { bsize *= 2; } - pBuf = (uint8_t *)taosMemoryRealloc(*ppBuf ? (*ppBuf) - sizeof(int64_t) : *ppBuf, bsize + sizeof(int64_t)); + pBuf = (uint8_t *)taosMemoryRealloc(pBuf, bsize + sizeof(int64_t)); if (pBuf == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; diff --git a/include/util/tdef.h b/include/util/tdef.h index 84bc30b9e7..55194d8647 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -331,12 +331,12 @@ typedef enum ELogicConditionType { #define TSDB_DB_STRICT_OFF 0 #define TSDB_DB_STRICT_ON 1 #define TSDB_DEFAULT_DB_STRICT 0 -#define TSDB_MIN_DB_CACHE_LAST_ROW 0 -#define TSDB_MAX_DB_CACHE_LAST_ROW 3 -#define TSDB_DEFAULT_CACHE_LAST_ROW 0 -#define TSDB_MIN_DB_LAST_ROW_MEM 1 // MB -#define TSDB_MAX_DB_LAST_ROW_MEM 65536 -#define TSDB_DEFAULT_LAST_ROW_MEM 1 +#define TSDB_MIN_DB_CACHE_LAST 0 +#define TSDB_MAX_DB_CACHE_LAST 3 +#define TSDB_DEFAULT_CACHE_LAST 0 +#define TSDB_MIN_DB_CACHE_LAST_SIZE 1 // MB +#define TSDB_MAX_DB_CACHE_LAST_SIZE 65536 +#define TSDB_DEFAULT_CACHE_LAST_SIZE 1 #define TSDB_DB_STREAM_MODE_OFF 0 #define TSDB_DB_STREAM_MODE_ON 1 #define TSDB_DEFAULT_DB_STREAM_MODE 0 diff --git a/include/util/thash.h b/include/util/thash.h index fc8785a8fb..781c22a56a 100644 --- a/include/util/thash.h +++ b/include/util/thash.h @@ -188,7 +188,7 @@ void *taosHashGetKey(void *data, size_t* keyLen); void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen); /** - * release the prevous acquired obj + * release the previous acquired obj * * @param pHashObj * @param data diff --git a/include/util/tlockfree.h b/include/util/tlockfree.h index 44e43f81cf..8db6be8860 100644 --- a/include/util/tlockfree.h +++ b/include/util/tlockfree.h @@ -71,11 +71,11 @@ typedef void (*_ref_fn_t)(const void *pObj); // single writer multiple reader lock typedef volatile int32_t SRWLatch; -void taosInitRWLatch(SRWLatch *pLatch); -void taosWLockLatch(SRWLatch *pLatch); -void taosWUnLockLatch(SRWLatch *pLatch); -void taosRLockLatch(SRWLatch *pLatch); -void taosRUnLockLatch(SRWLatch *pLatch); +void taosInitRWLatch(SRWLatch *pLatch); +void taosWLockLatch(SRWLatch *pLatch); +void taosWUnLockLatch(SRWLatch *pLatch); +void taosRLockLatch(SRWLatch *pLatch); +void taosRUnLockLatch(SRWLatch *pLatch); int32_t taosWTryLockLatch(SRWLatch *pLatch); // copy on read diff --git a/include/util/tlog.h b/include/util/tlog.h index a8c9eeabde..d186c32841 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -94,7 +94,7 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons #define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); } #define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); } // clang-format on -#define BUF_PAGE_DEBUG +//#define BUF_PAGE_DEBUG #ifdef __cplusplus } #endif diff --git a/include/util/tqueue.h b/include/util/tqueue.h index 466c577c00..0f4f1db9ee 100644 --- a/include/util/tqueue.h +++ b/include/util/tqueue.h @@ -44,6 +44,8 @@ typedef struct STaosQset STaosQset; typedef struct STaosQall STaosQall; typedef struct { void *ahandle; + void *fp; + void *queue; int32_t workerId; int32_t threadNum; int64_t timestamp; @@ -65,6 +67,7 @@ void taosFreeQitem(void *pItem); void taosWriteQitem(STaosQueue *queue, void *pItem); int32_t taosReadQitem(STaosQueue *queue, void **ppItem); bool taosQueueEmpty(STaosQueue *queue); +void taosUpdateItemSize(STaosQueue *queue, int32_t items); int32_t taosQueueItemSize(STaosQueue *queue); int64_t taosQueueMemorySize(STaosQueue *queue); @@ -81,8 +84,8 @@ int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle); void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue); int32_t taosGetQueueNumber(STaosQset *qset); -int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, int64_t *ts, void **ahandle, FItem *itemFp); -int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahandle, FItems *itemsFp); +int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo); +int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo *qinfo); void taosResetQsetThread(STaosQset *qset, void *pItem); extern int64_t tsRpcQueueMemoryAllowed; diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index 77817e5cf6..f409834091 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -328,7 +328,7 @@ function install_header() { ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h ${csudo}ln -s ${install_main_dir}/include/taosudf.h ${inc_link_dir}/taosudf.h - ${csudo}ln -s ${install_main_dir}/include/taosws.h ${inc_link_dir}/taosws.h || : + [ -f ${install_main_dir}/include/taosws.h ] && ${csudo}ln -s ${install_main_dir}/include/taosws.h ${inc_link_dir}/taosws.h || : } function add_newHostname_to_hosts() { diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index 0f1080521e..ca3a9a19be 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -161,13 +161,11 @@ if [[ $productName == "TDengine" ]]; then mkdir -p ${install_dir}/connector if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then if [ "$osType" != "Darwin" ]; then - cp ${build_dir}/lib/*.jar ${install_dir}/connector || : - fi - if find ${connector_dir}/go -mindepth 1 -maxdepth 1 | read; then - cp -r ${connector_dir}/go ${install_dir}/connector - else - echo "WARNING: go connector not found, please check if want to use it!" + [ -f ${build_dir}/lib/*.jar ] && cp ${build_dir}/lib/*.jar ${install_dir}/connector || : fi + git clone --depth 1 https://github.com/taosdata/driver-go ${install_dir}/connector/go + rm -rf ${install_dir}/connector/go/.git ||: + git clone --depth 1 https://github.com/taosdata/taos-connector-python ${install_dir}/connector/python rm -rf ${install_dir}/connector/python/.git ||: # cp -r ${connector_dir}/python ${install_dir}/connector diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 7edab2141b..c37397005c 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -290,19 +290,17 @@ fi # Copy driver mkdir -p ${install_dir}/driver && cp ${lib_files} ${install_dir}/driver && echo "${versionComp}" >${install_dir}/driver/vercomp.txt -cp ${wslib_files} ${install_dir}/driver || : +[ -f ${wslib_files} ] && cp ${wslib_files} ${install_dir}/driver || : # Copy connector if [ "$verMode" == "cluster" ]; then connector_dir="${code_dir}/connector" mkdir -p ${install_dir}/connector if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then - cp ${build_dir}/lib/*.jar ${install_dir}/connector || : - if find ${connector_dir}/go -mindepth 1 -maxdepth 1 | read; then - cp -r ${connector_dir}/go ${install_dir}/connector - else - echo "WARNING: go connector not found, please check if want to use it!" - fi + [ -f ${build_dir}/lib/*.jar ] && cp ${build_dir}/lib/*.jar ${install_dir}/connector || : + git clone --depth 1 https://github.com/taosdata/driver-go ${install_dir}/connector/go + rm -rf ${install_dir}/connector/go/.git ||: + git clone --depth 1 https://github.com/taosdata/taos-connector-python ${install_dir}/connector/python rm -rf ${install_dir}/connector/python/.git ||: @@ -314,6 +312,7 @@ if [ "$verMode" == "cluster" ]; then git clone --depth 1 https://github.com/taosdata/libtaos-rs ${install_dir}/connector/rust rm -rf ${install_dir}/connector/rust/.git ||: + # cp -r ${connector_dir}/python ${install_dir}/connector # cp -r ${connector_dir}/nodejs ${install_dir}/connector fi diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index ec836f2eac..1bd5ed3ea4 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -114,6 +114,7 @@ function clean_header() { ${csudo}rm -f ${inc_link_dir}/taos.h || : ${csudo}rm -f ${inc_link_dir}/taosdef.h || : ${csudo}rm -f ${inc_link_dir}/taoserror.h || : + ${csudo}rm -f ${inc_link_dir}/taosudf.h || : ${csudo}rm -f ${inc_link_dir}/taosws.h || : } diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 91f21f6e6a..700a4d9daf 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -169,6 +169,7 @@ typedef struct SReqResultInfo { uint32_t numOfRows; uint64_t totalRows; uint32_t current; + bool localResultFetched; bool completed; int32_t precision; bool convertUcs4; @@ -222,8 +223,8 @@ typedef struct SRequestObj { SArray* tableList; SQueryExecMetric metric; SRequestSendRecvBody body; - bool stableQuery; // todo refactor - bool validateOnly; // todo refactor + bool stableQuery; // todo refactor + bool validateOnly; // todo refactor bool killed; uint32_t prevCode; // previous error code: todo refactor, add update flag for catalog @@ -324,7 +325,8 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); -int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, SRequestObj** pRequest); +int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, + SRequestObj** pRequest); void taos_close_internal(void* taos); @@ -358,9 +360,6 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList); // todo move to clie int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog); // todo move to xxx bool qnodeRequired(SRequestObj* pRequest); -void initTscQhandle(); -void cleanupTscQhandle(); - #ifdef __cplusplus } #endif diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index ba92ed238b..207ac01a2c 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -35,22 +35,10 @@ SAppInfo appInfo; int32_t clientReqRefPool = -1; int32_t clientConnRefPool = -1; -void *tscQhandle = NULL; - static TdThreadOnce tscinit = PTHREAD_ONCE_INIT; volatile int32_t tscInitRes = 0; -void initTscQhandle() { - // init handle - tscQhandle = taosInitScheduler(4096, 5, "tsc"); -} - -void cleanupTscQhandle() { - // destroy handle - taosCleanUpScheduler(tscQhandle); -} - -static int32_t registerRequest(SRequestObj *pRequest, STscObj* pTscObj) { +static int32_t registerRequest(SRequestObj *pRequest, STscObj *pTscObj) { // connection has been released already, abort creating request. pRequest->self = taosAddRef(clientReqRefPool, pRequest); @@ -72,7 +60,7 @@ static int32_t registerRequest(SRequestObj *pRequest, STscObj* pTscObj) { static void deregisterRequest(SRequestObj *pRequest) { assert(pRequest != NULL); - STscObj * pTscObj = pRequest->pTscObj; + STscObj *pTscObj = pRequest->pTscObj; SAppClusterSummary *pActivity = &pTscObj->pAppInfo->summary; int32_t currentInst = atomic_sub_fetch_64((int64_t *)&pActivity->currentRequests, 1); @@ -97,7 +85,8 @@ void closeTransporter(SAppInstInfo *pAppInfo) { static bool clientRpcRfp(int32_t code, tmsg_t msgType) { if (NEED_REDIRECT_ERROR(code)) { - if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH || msgType == TDMT_SCH_MERGE_FETCH) { + if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH || + msgType == TDMT_SCH_MERGE_FETCH) { return false; } return true; @@ -189,12 +178,15 @@ void destroyTscObj(void *pObj) { SClientHbKey connKey = {.tscRid = pTscObj->id, .connType = pTscObj->connType}; hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey); - int64_t connNum = atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); + destroyAllRequests(pTscObj->pRequests); + taosHashCleanup(pTscObj->pRequests); + schedulerStopQueryHb(pTscObj->pAppInfo->pTransporter); tscDebug("connObj 0x%" PRIx64 " p:%p destroyed, remain inst totalConn:%" PRId64, pTscObj->id, pTscObj, pTscObj->pAppInfo->numOfConns); + int64_t connNum = atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); if (0 == connNum) { destroyAppInst(pTscObj->pAppInfo); } @@ -248,7 +240,7 @@ void *createRequest(uint64_t connId, int32_t type) { return NULL; } - STscObj* pTscObj = acquireTscObj(connId); + STscObj *pTscObj = acquireTscObj(connId); if (pTscObj == NULL) { terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; @@ -345,7 +337,6 @@ void taos_init_imp(void) { // In the APIs of other program language, taos_cleanup is not available yet. // So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning. atexit(taos_cleanup); - initTscQhandle(); errno = TSDB_CODE_SUCCESS; taosSeedRand(taosGetTimestampSec()); @@ -404,7 +395,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { return 0; } - SConfig * pCfg = taosGetCfg(); + SConfig *pCfg = taosGetCfg(); SConfigItem *pItem = NULL; switch (option) { diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index e2d75d39e3..2a9d113108 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -671,8 +671,7 @@ static void *hbThreadFunc(void *param) { } #endif while (1) { - int8_t threadStop = atomic_val_compare_exchange_8(&clientHbMgr.threadStop, 1, 2); - if (1 == threadStop) { + if (1 == clientHbMgr.threadStop) { break; } @@ -760,9 +759,7 @@ static void hbStopThread() { return; } - while (2 != atomic_load_8(&clientHbMgr.threadStop)) { - taosUsleep(10); - } + taosThreadJoin(clientHbMgr.thread, NULL); tscDebug("hb thread stopped"); } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index a4a5ec7499..32c11983c2 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -148,7 +148,8 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst, connType); } -int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, SRequestObj** pRequest) { +int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, + SRequestObj** pRequest) { *pRequest = createRequest(connId, TSDB_SQL_SELECT); if (*pRequest == NULL) { tscError("failed to malloc sqlObj, %s", sql); @@ -165,7 +166,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, strntolower((*pRequest)->sqlstr, sql, (int32_t)sqlLen); (*pRequest)->sqlstr[sqlLen] = 0; - (*pRequest)->sqlLen = sqlLen; + (*pRequest)->sqlLen = sqlLen; (*pRequest)->validateOnly = validateSql; if (param == NULL) { @@ -351,7 +352,8 @@ int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList) { if (pNodeList) { pInfo->pQnodeList = taosArrayDup(pNodeList); taosArraySort(pInfo->pQnodeList, compareQueryNodeLoad); - tscDebug("QnodeList updated in cluster 0x%" PRIx64 ", num:%d", pInfo->clusterId, taosArrayGetSize(pInfo->pQnodeList)); + tscDebug("QnodeList updated in cluster 0x%" PRIx64 ", num:%d", pInfo->clusterId, + taosArrayGetSize(pInfo->pQnodeList)); } taosThreadMutexUnlock(&pInfo->qnodeMutex); @@ -649,22 +651,22 @@ _return: int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) { void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter; - SExecResult res = {0}; + SExecResult res = {0}; SRequestConnInfo conn = {.pTrans = pRequest->pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; SSchedulerReq req = { - .syncReq = true, - .pConn = &conn, - .pNodeList = pNodeList, - .pDag = pDag, - .sql = pRequest->sqlstr, - .startTs = pRequest->metric.start, - .execFp = NULL, - .cbParam = NULL, - .chkKillFp = chkRequestKilled, - .chkKillParam = (void*)pRequest->self, - .pExecRes = &res, + .syncReq = true, + .pConn = &conn, + .pNodeList = pNodeList, + .pDag = pDag, + .sql = pRequest->sqlstr, + .startTs = pRequest->metric.start, + .execFp = NULL, + .cbParam = NULL, + .chkKillFp = chkRequestKilled, + .chkKillParam = (void*)pRequest->self, + .pExecRes = &res, }; int32_t code = schedulerExecJob(&req, &pRequest->body.queryJob); @@ -778,7 +780,7 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) { return code; } - SEpSet epset = getEpSet_s(&pAppInfo->mgmtEp); + SEpSet epset = getEpSet_s(&pAppInfo->mgmtEp); SExecResult* pRes = &pRequest->body.resInfo.execRes; switch (pRes->msgType) { @@ -808,11 +810,16 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) { void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) { SRequestObj* pRequest = (SRequestObj*)param; pRequest->code = code; - memcpy(&pRequest->body.resInfo.execRes, pResult, sizeof(*pResult)); + + if (pResult) { + memcpy(&pRequest->body.resInfo.execRes, pResult, sizeof(*pResult)); + } if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_DELETE == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) { - pRequest->body.resInfo.numOfRows = pResult->numOfRows; + if (pResult) { + pRequest->body.resInfo.numOfRows = pResult->numOfRows; + } schedulerFreeJob(&pRequest->body.queryJob, 0); } @@ -964,17 +971,17 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM SRequestConnInfo conn = { .pTrans = pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self}; SSchedulerReq req = { - .syncReq = false, - .pConn = &conn, - .pNodeList = pNodeList, - .pDag = pDag, - .sql = pRequest->sqlstr, - .startTs = pRequest->metric.start, - .execFp = schedulerExecCb, - .cbParam = pRequest, - .chkKillFp = chkRequestKilled, - .chkKillParam = (void*)pRequest->self, - .pExecRes = NULL, + .syncReq = false, + .pConn = &conn, + .pNodeList = pNodeList, + .pDag = pDag, + .sql = pRequest->sqlstr, + .startTs = pRequest->metric.start, + .execFp = schedulerExecCb, + .cbParam = pRequest, + .chkKillFp = chkRequestKilled, + .chkKillParam = (void*)pRequest->self, + .pExecRes = NULL, }; code = schedulerExecJob(&req, &pRequest->body.queryJob); taosArrayDestroy(pNodeList); @@ -993,6 +1000,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM pRequest->body.queryFp(pRequest->body.param, pRequest, 0); break; default: + pRequest->body.queryFp(pRequest->body.param, pRequest, -1); break; } @@ -1266,8 +1274,8 @@ typedef struct SchedArg { SEpSet* pEpset; } SchedArg; -void doProcessMsgFromServer(SSchedMsg* schedMsg) { - SchedArg* arg = (SchedArg*)schedMsg->ahandle; +int32_t doProcessMsgFromServer(void* param) { + SchedArg* arg = (SchedArg*)param; SRpcMsg* pMsg = &arg->msg; SEpSet* pEpSet = arg->pEpset; @@ -1320,11 +1328,10 @@ void doProcessMsgFromServer(SSchedMsg* schedMsg) { rpcFreeCont(pMsg->pCont); destroySendMsgInfo(pSendInfo); taosMemoryFree(arg); + return TSDB_CODE_SUCCESS; } void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { - SSchedMsg schedMsg = {0}; - SEpSet* tEpSet = NULL; if (pEpSet != NULL) { tEpSet = taosMemoryCalloc(1, sizeof(SEpSet)); @@ -1335,9 +1342,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { arg->msg = *pMsg; arg->pEpset = tEpSet; - schedMsg.fp = doProcessMsgFromServer; - schedMsg.ahandle = arg; - taosScheduleTask(tscQhandle, &schedMsg); + taosAsyncExec(doProcessMsgFromServer, arg, NULL); } TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, const char* db, uint16_t port) { @@ -1416,9 +1421,9 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) } SReqResultInfo* pResInfo = &pRequest->body.resInfo; - SSchedulerReq req = { - .syncReq = true, - .pFetchRes = (void**)&pResInfo->pData, + SSchedulerReq req = { + .syncReq = true, + .pFetchRes = (void**)&pResInfo->pData, }; pRequest->code = schedulerFetchRows(pRequest->body.queryJob, &req); if (pRequest->code != TSDB_CODE_SUCCESS) { @@ -1473,12 +1478,16 @@ void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertU tsem_wait(&pParam->sem); } - if (pRequest->code == TSDB_CODE_SUCCESS && pResultInfo->numOfRows > 0 && setupOneRowPtr) { - doSetOneRowPtr(pResultInfo); - pResultInfo->current += 1; - } + if (pResultInfo->numOfRows == 0 || pRequest->code != TSDB_CODE_SUCCESS) { + return NULL; + } else { + if (setupOneRowPtr) { + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; + } - return pResultInfo->row; + return pResultInfo->row; + } } static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { @@ -1893,6 +1902,10 @@ int32_t appendTbToReq(SArray* pList, int32_t pos1, int32_t len1, int32_t pos2, i tbLen = len1; } + if (dbLen <= 0 || tbLen <= 0) { + return -1; + } + if (tNameSetDbName(&name, acctId, dbName, dbLen)) { return -1; } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 12de522cbc..73def5b9b1 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -72,7 +72,6 @@ void taos_cleanup(void) { catalogDestroy(); schedulerDestroy(); - cleanupTscQhandle(); rpcCleanup(); tscInfo("all local resources released"); taosCleanupCfg(); @@ -242,7 +241,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { #endif } else if (TD_RES_TMQ(res)) { - SMqRspObj * msg = ((SMqRspObj *)res); + SMqRspObj *msg = ((SMqRspObj *)res); SReqResultInfo *pResultInfo; if (msg->resIter == -1) { pResultInfo = tmqGetNextResInfo(res, true); @@ -418,7 +417,7 @@ int taos_affected_rows(TAOS_RES *res) { return 0; } - SRequestObj * pRequest = (SRequestObj *)res; + SRequestObj *pRequest = (SRequestObj *)res; SReqResultInfo *pResInfo = &pRequest->body.resInfo; return pResInfo->numOfRows; } @@ -601,7 +600,7 @@ int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { } SReqResultInfo *pResInfo = tscGetCurResInfo(res); - TAOS_FIELD * pField = &pResInfo->userFields[columnIndex]; + TAOS_FIELD *pField = &pResInfo->userFields[columnIndex]; if (!IS_VAR_DATA_TYPE(pField->type)) { return 0; } @@ -645,8 +644,8 @@ const char *taos_get_server_info(TAOS *taos) { typedef struct SqlParseWrapper { SParseContext *pCtx; SCatalogReq catalogReq; - SRequestObj * pRequest; - SQuery * pQuery; + SRequestObj *pRequest; + SQuery *pQuery; } SqlParseWrapper; static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) { @@ -665,8 +664,8 @@ static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) { void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { SqlParseWrapper *pWrapper = (SqlParseWrapper *)param; - SQuery * pQuery = pWrapper->pQuery; - SRequestObj * pRequest = pWrapper->pRequest; + SQuery *pQuery = pWrapper->pQuery; + SRequestObj *pRequest = pWrapper->pRequest; if (code == TSDB_CODE_SUCCESS) { code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery); @@ -684,7 +683,8 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { destorySqlParseWrapper(pWrapper); - tscDebug("0x%"PRIx64" analysis semantics completed, start async query, reqId:0x%"PRIx64, pRequest->self, pRequest->requestId); + tscDebug("0x%" PRIx64 " analysis semantics completed, start async query, reqId:0x%" PRIx64, pRequest->self, + pRequest->requestId); launchAsyncQuery(pRequest, pQuery, pResultMeta); } else { destorySqlParseWrapper(pWrapper); @@ -705,7 +705,7 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { } void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { - int64_t connId = *(int64_t*)taos; + int64_t connId = *(int64_t *)taos; taosAsyncQueryImpl(connId, sql, fp, param, false); } @@ -739,7 +739,7 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) { void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { SParseContext *pCxt = NULL; - STscObj * pTscObj = pRequest->pTscObj; + STscObj *pTscObj = pRequest->pTscObj; int32_t code = 0; if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) { @@ -852,23 +852,33 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { } // all data has returned to App already, no need to try again - if ((pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) && pResultInfo->completed) { + if (pResultInfo->completed && (pRequest->body.queryJob != 0)) { pResultInfo->numOfRows = 0; pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); return; } // it is a local executed query, no need to do async fetch - if (pResultInfo->current < pResultInfo->numOfRows && pRequest->body.queryJob == 0) { - pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); + if (pRequest->body.queryJob == 0) { + ASSERT(pResultInfo->completed && pResultInfo->numOfRows >= 0); + if (pResultInfo->localResultFetched) { + pResultInfo->numOfRows = 0; + pResultInfo->current = 0; + pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); + } else { + pResultInfo->localResultFetched = true; + pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows); + } return; } + SSchedulerReq req = { - .syncReq = false, - .fetchFp = fetchCallback, - .cbParam = pRequest, + .syncReq = false, + .fetchFp = fetchCallback, + .cbParam = pRequest, }; + schedulerFetchRows(pRequest->body.queryJob, &req); } @@ -876,14 +886,14 @@ void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { ASSERT(res != NULL && fp != NULL); ASSERT(TD_RES_QUERY(res)); - SRequestObj *pRequest = res; + SRequestObj *pRequest = res; SReqResultInfo *pResultInfo = &pRequest->body.resInfo; // set the current block is all consumed - pResultInfo->current = pResultInfo->numOfRows; pResultInfo->convertUcs4 = false; - taos_fetch_rows_a(res, fp, param); + // it is a local executed query, no need to do async fetch + taos_fetch_rows_a(pRequest, fp, param); } const void *taos_get_raw_block(TAOS_RES *res) { @@ -918,7 +928,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { int64_t connId = *(int64_t *)taos; const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024; // 12MB list int32_t code = 0; - SRequestObj * pRequest = NULL; + SRequestObj *pRequest = NULL; SCatalogReq catalogReq = {0}; if (NULL == tableNameList) { @@ -940,7 +950,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { goto _return; } - STscObj* pTscObj = pRequest->pTscObj; + STscObj *pTscObj = pRequest->pTscObj; code = transferTableNameList(tableNameList, pTscObj->acctId, pTscObj->db, &catalogReq.pTableMeta); if (code) { goto _return; @@ -962,7 +972,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { goto _return; } - SSyncQueryParam* pParam = pRequest->body.param; + SSyncQueryParam *pParam = pRequest->body.param; tsem_wait(&pParam->sem); _return: diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index dcccbb17c9..94bd5dd787 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -179,7 +179,6 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (code != 0) { terrno = code; if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash); - taosMemoryFreeClear(output.dbVgroup); tscError("0x%" PRIx64 " failed to build use db output since %s", pRequest->requestId, terrstr()); } else if (output.dbVgroup && output.dbVgroup->vgHash) { @@ -189,12 +188,14 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { if (code1 != TSDB_CODE_SUCCESS) { tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code1)); - taosMemoryFreeClear(output.dbVgroup); } else { catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); + output.dbVgroup = NULL; } } + taosMemoryFreeClear(output.dbVgroup); + tFreeSUsedbRsp(&usedbRsp); char db[TSDB_DB_NAME_LEN] = {0}; diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index d653b8720f..92ed830dee 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -357,6 +357,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.inExecCache = true; if (pStmt->sql.autoCreateTbl) { + tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName); return TSDB_CODE_SUCCESS; } } @@ -365,9 +366,11 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (pStmt->bInfo.inExecCache) { ASSERT(taosHashGetSize(pStmt->exec.pBlockHash) == 1); pStmt->bInfo.needParse = false; + tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName); return TSDB_CODE_SUCCESS; } + tscDebug("no stmt block cache for tb %s", pStmt->bInfo.tbFName); return TSDB_CODE_SUCCESS; } @@ -391,6 +394,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } + tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64 , pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid); + return TSDB_CODE_SUCCESS; } @@ -406,6 +411,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + tscDebug("tb %s not exist", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -420,6 +427,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (uid == pStmt->bInfo.tbUid) { pStmt->bInfo.needParse = false; + tscDebug("tb %s is current table", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -440,6 +449,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.boundTags = pCache->boundTags; pStmt->bInfo.tagsCached = true; + tscDebug("tb %s in execBlock list, set to current", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -461,6 +472,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } + tscDebug("tb %s in sqlBlock list, set to current", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -510,6 +523,8 @@ TAOS_STMT* stmtInit(STscObj* taos) { int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("stmt start to prepare"); + if (pStmt->sql.status >= STMT_PREPARE) { STMT_ERR_RET(stmtResetStmt(pStmt)); } @@ -529,6 +544,8 @@ int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("stmt start to set tbName: %s", tbName); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME)); int32_t insert = 0; @@ -559,6 +576,8 @@ int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("stmt start to set tbTags"); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS)); if (pStmt->bInfo.inExecCache) { @@ -572,6 +591,7 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) { STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } + tscDebug("start to bind stmt tag values"); STMT_ERR_RET(qBindStmtTagsValue(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, pStmt->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); @@ -617,6 +637,8 @@ int stmtFetchColFields(STscStmt* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("start to bind stmt data, colIdx: %d", colIdx); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && @@ -707,6 +729,8 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { int stmtAddBatch(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("stmt start to add batch"); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_ADD_BATCH)); STMT_ERR_RET(stmtCacheBlock(pStmt)); @@ -715,6 +739,8 @@ int stmtAddBatch(TAOS_STMT* stmt) { } int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) { + tscDebug("stmt start to update tbUid, blockNum: %d", pRsp->nBlocks); + if (pRsp->nBlocks <= 0) { tscError("invalid submit resp block number %d", pRsp->nBlocks); STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR); @@ -727,11 +753,6 @@ int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) { char* key = taosHashGetKey(pIter, &keyLen); STableMeta* pMeta = qGetTableMetaInDataBlock(pBlock); - if (pMeta->uid != pStmt->bInfo.tbUid) { - tscError("table uid %" PRIx64 " mis-match with current table uid %" PRIx64, pMeta->uid, pStmt->bInfo.tbUid); - STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR); - } - if (pMeta->uid) { pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); continue; @@ -775,6 +796,8 @@ int stmtExec(TAOS_STMT* stmt) { SSubmitRsp* pRsp = NULL; bool autoCreateTbl = pStmt->exec.autoCreateTbl; + tscDebug("stmt start to exec"); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); if (STMT_TYPE_QUERY == pStmt->sql.type) { diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 110b839216..b0542e350f 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -1149,11 +1149,10 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) { tDecoderInit(&decoder, POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), pMsg->len - sizeof(SMqRspHead)); tDecodeSMqDataRsp(&decoder, &pRspWrapper->dataRsp); memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead)); - /*tDecodeSMqDataBlkRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->dataRsp);*/ } else { ASSERT(rspType == TMQ_MSG_TYPE__POLL_META_RSP); - memcpy(&pRspWrapper->metaRsp, pMsg->pData, sizeof(SMqRspHead)); tDecodeSMqMetaRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->metaRsp); + memcpy(&pRspWrapper->metaRsp, pMsg->pData, sizeof(SMqRspHead)); } taosMemoryFree(pMsg->pData); @@ -2427,15 +2426,15 @@ static void destroyCreateTbReqBatch(void* data) { taosArrayDestroy(pTbBatch->req.pArray); } -static int32_t taosCreateTable(TAOS *taos, void *meta, int32_t metaLen){ - SVCreateTbBatchReq req = {0}; - SDecoder coder = {0}; - int32_t code = TSDB_CODE_SUCCESS; - SRequestObj *pRequest = NULL; - SQuery *pQuery = NULL; - SHashObj *pVgroupHashmap = NULL; +static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) { + SVCreateTbBatchReq req = {0}; + SDecoder coder = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj* pRequest = NULL; + SQuery* pQuery = NULL; + SHashObj* pVgroupHashmap = NULL; - code = buildRequest(*(int64_t*) taos, "", 0, NULL, false, &pRequest); + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); if (code != TSDB_CODE_SUCCESS) { goto end; } @@ -2455,8 +2454,8 @@ static int32_t taosCreateTable(TAOS *taos, void *meta, int32_t metaLen){ STscObj* pTscObj = pRequest->pTscObj; - SVCreateTbReq *pCreateReq = NULL; - SCatalog* pCatalog = NULL; + SVCreateTbReq* pCreateReq = NULL; + SCatalog* pCatalog = NULL; code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog); if (code != TSDB_CODE_SUCCESS) { goto end; @@ -2540,13 +2539,13 @@ static void destroyDropTbReqBatch(void* data) { taosArrayDestroy(pTbBatch->req.pArray); } -static int32_t taosDropTable(TAOS *taos, void *meta, int32_t metaLen){ - SVDropTbBatchReq req = {0}; - SDecoder coder = {0}; - int32_t code = TSDB_CODE_SUCCESS; - SRequestObj *pRequest = NULL; - SQuery *pQuery = NULL; - SHashObj *pVgroupHashmap = NULL; +static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) { + SVDropTbBatchReq req = {0}; + SDecoder coder = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj* pRequest = NULL; + SQuery* pQuery = NULL; + SHashObj* pVgroupHashmap = NULL; code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); if (code != TSDB_CODE_SUCCESS) { @@ -2568,8 +2567,8 @@ static int32_t taosDropTable(TAOS *taos, void *meta, int32_t metaLen){ STscObj* pTscObj = pRequest->pTscObj; - SVDropTbReq *pDropReq = NULL; - SCatalog *pCatalog = NULL; + SVDropTbReq* pDropReq = NULL; + SCatalog* pCatalog = NULL; code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog); if (code != TSDB_CODE_SUCCESS) { goto end; @@ -2640,17 +2639,16 @@ end: return code; } -static int32_t taosAlterTable(TAOS *taos, void *meta, int32_t metaLen){ - SVAlterTbReq req = {0}; - SDecoder coder = {0}; - int32_t code = TSDB_CODE_SUCCESS; - SRequestObj *pRequest = NULL; - SQuery *pQuery = NULL; - SArray *pArray = NULL; - SVgDataBlocks *pVgData = NULL; +static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) { + SVAlterTbReq req = {0}; + SDecoder coder = {0}; + int32_t code = TSDB_CODE_SUCCESS; + SRequestObj* pRequest = NULL; + SQuery* pQuery = NULL; + SArray* pArray = NULL; + SVgDataBlocks* pVgData = NULL; - - code = buildRequest(*(int64_t*) taos, "", 0, NULL, false, &pRequest); + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); if (code != TSDB_CODE_SUCCESS) { goto end; } diff --git a/source/common/src/systable.c b/source/common/src/systable.c index ba8a8e1220..08997bcaf8 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -123,6 +123,9 @@ static const SSysDbTableSchema userStbsSchema[] = { {.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "watermark", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "max_delay", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "rollup", .bytes = 128 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SSysDbTableSchema streamSchema[] = { @@ -146,8 +149,8 @@ static const SSysDbTableSchema userTblsSchema[] = { {.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "type", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SSysDbTableSchema userTblDistSchema[] = { diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 1fa37d5ef0..9b65e08d29 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -320,7 +320,9 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p memcpy(pColumnInfoData->pData, pSource->pData, pSource->varmeta.length); } else { memcpy(pColumnInfoData->nullbitmap, pSource->nullbitmap, BitmapLen(numOfRows)); - memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows); + if (pSource->pData) { + memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows); + } } pColumnInfoData->hasNull = pSource->hasNull; @@ -1736,56 +1738,57 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock); int32_t rows = pDataBlock->info.rows; int32_t len = 0; - len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|group id:%" PRIu64 "|\n", flag, - (int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.groupId); + len += snprintf(dumpBuf + len, size - len, "\n%s |block type %d |child id %d|group id:%" PRIu64 "| uid:%ld\n", flag, + (int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.groupId, + pDataBlock->info.uid); if (len >= size - 1) return dumpBuf; for (int32_t j = 0; j < rows; j++) { len += snprintf(dumpBuf + len, size - len, "%s |", flag); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; for (int32_t k = 0; k < colNum; k++) { SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k); void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); - if (colDataIsNull(pColInfoData, rows, j, NULL) || !var) { + if (colDataIsNull(pColInfoData, rows, j, NULL) || !pColInfoData->pData) { len += snprintf(dumpBuf + len, size - len, " %15s |", "NULL"); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; continue; } switch (pColInfoData->info.type) { case TSDB_DATA_TYPE_TIMESTAMP: formatTimestamp(pBuf, *(uint64_t*)var, TSDB_TIME_PRECISION_MILLI); len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_INT: len += snprintf(dumpBuf + len, size - len, " %15d |", *(int32_t*)var); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_UINT: len += snprintf(dumpBuf + len, size - len, " %15u |", *(uint32_t*)var); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_BIGINT: len += snprintf(dumpBuf + len, size - len, " %15ld |", *(int64_t*)var); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_UBIGINT: len += snprintf(dumpBuf + len, size - len, " %15lu |", *(uint64_t*)var); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_FLOAT: len += snprintf(dumpBuf + len, size - len, " %15f |", *(float*)var); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; break; case TSDB_DATA_TYPE_DOUBLE: len += snprintf(dumpBuf + len, size - len, " %15lf |", *(double*)var); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; break; } } len += snprintf(dumpBuf + len, size - len, "\n"); - if (len >= size -1) return dumpBuf; + if (len >= size - 1) return dumpBuf; } len += snprintf(dumpBuf + len, size - len, "%s |end\n", flag); return dumpBuf; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index ec7be79934..8eeab77a15 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -175,7 +175,8 @@ static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) { } while (0) int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) { - int32_t code = 0; + int32_t code = 0; +#if 0 STColumn *pTColumn; SColVal *pColVal; int32_t nColVal = taosArrayGetSize(pArray); @@ -462,30 +463,22 @@ int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, S } } +#endif _exit: return code; } int32_t tTSRowClone(const STSRow2 *pRow, STSRow2 **ppRow) { int32_t code = 0; + int32_t rLen; - (*ppRow) = (STSRow2 *)taosMemoryMalloc(sizeof(**ppRow)); + TSROW_LEN(pRow, rLen); + (*ppRow) = (STSRow2 *)taosMemoryMalloc(rLen); if (*ppRow == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; } - **ppRow = *pRow; - (*ppRow)->pData = NULL; - - if (pRow->nData) { - (*ppRow)->pData = taosMemoryMalloc(pRow->nData); - if ((*ppRow)->pData == NULL) { - taosMemoryFree(*ppRow); - code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; - } - memcpy((*ppRow)->pData, pRow->pData, pRow->nData); - } + memcpy(*ppRow, pRow, rLen); _exit: return code; @@ -493,12 +486,12 @@ _exit: void tTSRowFree(STSRow2 *pRow) { if (pRow) { - if (pRow->pData) taosMemoryFree(pRow->pData); taosMemoryFree(pRow); } } void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { +#if 0 uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0; STColumn *pTColumn = &pTSchema->columns[iCol]; uint8_t flags = pRow->flags & (uint8_t)0xf; @@ -643,10 +636,12 @@ _return_null: _return_value: *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value); return; +#endif } int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) { int32_t code = 0; +#if 0 SColVal cv; (*ppArray) = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)); @@ -660,52 +655,27 @@ int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) { taosArrayPush(*ppArray, &cv); } +#endif _exit: return code; } int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow) { - int32_t n = 0; + int32_t n; - n += tPutI64(p ? p + n : p, pRow->ts); - n += tPutI8(p ? p + n : p, pRow->flags); - n += tPutI32v(p ? p + n : p, pRow->sver); - - ASSERT(pRow->flags & 0xf); - - switch (pRow->flags & 0xf) { - case TSROW_HAS_NONE: - case TSROW_HAS_NULL: - ASSERT(pRow->nData == 0); - ASSERT(pRow->pData == NULL); - break; - default: - ASSERT(pRow->nData && pRow->pData); - n += tPutBinary(p ? p + n : p, pRow->pData, pRow->nData); - break; + TSROW_LEN(pRow, n); + if (p) { + memcpy(p, pRow, n); } return n; } -int32_t tGetTSRow(uint8_t *p, STSRow2 *pRow) { - int32_t n = 0; +int32_t tGetTSRow(uint8_t *p, STSRow2 **ppRow) { + int32_t n; - n += tGetI64(p + n, &pRow->ts); - n += tGetI8(p + n, &pRow->flags); - n += tGetI32v(p + n, &pRow->sver); - - ASSERT(pRow->flags); - switch (pRow->flags & 0xf) { - case TSROW_HAS_NONE: - case TSROW_HAS_NULL: - pRow->nData = 0; - pRow->pData = NULL; - break; - default: - n += tGetBinary(p + n, &pRow->pData, &pRow->nData); - break; - } + *ppRow = (STSRow2 *)p; + TSROW_LEN(*ppRow, n); return n; } @@ -904,15 +874,13 @@ static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) { return n; } -bool tTagIsJson(const void *pTag){ - return (((const STag *)pTag)->flags & TD_TAG_JSON); -} +bool tTagIsJson(const void *pTag) { return (((const STag *)pTag)->flags & TD_TAG_JSON); } -bool tTagIsJsonNull(void *data){ - STag *pTag = (STag*)data; - int8_t isJson = tTagIsJson(pTag); - if(!isJson) return false; - return ((STag*)data)->nTag == 0; +bool tTagIsJsonNull(void *data) { + STag *pTag = (STag *)data; + int8_t isJson = tTagIsJson(pTag); + if (!isJson) return false; + return ((STag *)data)->nTag == 0; } int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag) { @@ -1097,112 +1065,6 @@ _err: } #if 1 // =================================================================================================================== -static void dataColSetNEleNull(SDataCol *pCol, int nEle); -int tdAllocMemForCol(SDataCol *pCol, int maxPoints) { - int spaceNeeded = pCol->bytes * maxPoints; - if (IS_VAR_DATA_TYPE(pCol->type)) { - spaceNeeded += sizeof(VarDataOffsetT) * maxPoints; - } -#ifdef TD_SUPPORT_BITMAP - int32_t nBitmapBytes = (int32_t)TD_BITMAP_BYTES(maxPoints); - spaceNeeded += (int)nBitmapBytes; - // TODO: Currently, the compression of bitmap parts is affiliated to the column data parts, thus allocate 1 more - // TYPE_BYTES as to comprise complete TYPE_BYTES. Otherwise, invalid read/write would be triggered. - // spaceNeeded += TYPE_BYTES[pCol->type]; // the bitmap part is append as a single part since 2022.04.03, thus - // remove the additional space -#endif - - if (pCol->spaceSize < spaceNeeded) { - void *ptr = taosMemoryRealloc(pCol->pData, spaceNeeded); - if (ptr == NULL) { - uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)spaceNeeded, strerror(errno)); - return -1; - } else { - pCol->pData = ptr; - pCol->spaceSize = spaceNeeded; - } - } -#ifdef TD_SUPPORT_BITMAP - - if (IS_VAR_DATA_TYPE(pCol->type)) { - pCol->pBitmap = POINTER_SHIFT(pCol->pData, pCol->bytes * maxPoints); - pCol->dataOff = POINTER_SHIFT(pCol->pBitmap, nBitmapBytes); - } else { - pCol->pBitmap = POINTER_SHIFT(pCol->pData, pCol->bytes * maxPoints); - } -#else - if (IS_VAR_DATA_TYPE(pCol->type)) { - pCol->dataOff = POINTER_SHIFT(pCol->pData, pCol->bytes * maxPoints); - } -#endif - return 0; -} - -/** - * Duplicate the schema and return a new object - */ -STSchema *tdDupSchema(const STSchema *pSchema) { - int tlen = sizeof(STSchema) + sizeof(STColumn) * schemaNCols(pSchema); - STSchema *tSchema = (STSchema *)taosMemoryMalloc(tlen); - if (tSchema == NULL) return NULL; - - memcpy((void *)tSchema, (void *)pSchema, tlen); - - return tSchema; -} - -/** - * Encode a schema to dst, and return the next pointer - */ -int tdEncodeSchema(void **buf, STSchema *pSchema) { - int tlen = 0; - tlen += taosEncodeFixedI32(buf, schemaVersion(pSchema)); - tlen += taosEncodeFixedI32(buf, schemaNCols(pSchema)); - - for (int i = 0; i < schemaNCols(pSchema); i++) { - STColumn *pCol = schemaColAt(pSchema, i); - tlen += taosEncodeFixedI8(buf, colType(pCol)); - tlen += taosEncodeFixedI8(buf, colFlags(pCol)); - tlen += taosEncodeFixedI16(buf, colColId(pCol)); - tlen += taosEncodeFixedI16(buf, colBytes(pCol)); - } - - return tlen; -} - -/** - * Decode a schema from a binary. - */ -void *tdDecodeSchema(void *buf, STSchema **pRSchema) { - int version = 0; - int numOfCols = 0; - STSchemaBuilder schemaBuilder; - - buf = taosDecodeFixedI32(buf, &version); - buf = taosDecodeFixedI32(buf, &numOfCols); - - if (tdInitTSchemaBuilder(&schemaBuilder, version) < 0) return NULL; - - for (int i = 0; i < numOfCols; i++) { - col_type_t type = 0; - int8_t flags = 0; - col_id_t colId = 0; - col_bytes_t bytes = 0; - buf = taosDecodeFixedI8(buf, &type); - buf = taosDecodeFixedI8(buf, &flags); - buf = taosDecodeFixedI16(buf, &colId); - buf = taosDecodeFixedI32(buf, &bytes); - if (tdAddColToSchema(&schemaBuilder, type, flags, colId, bytes) < 0) { - tdDestroyTSchemaBuilder(&schemaBuilder); - return NULL; - } - } - - *pRSchema = tdGetSchemaFromBuilder(&schemaBuilder); - tdDestroyTSchemaBuilder(&schemaBuilder); - return buf; -} - int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) { if (pBuilder == NULL) return -1; @@ -1239,22 +1101,22 @@ int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, c } STColumn *pCol = &(pBuilder->columns[pBuilder->nCols]); - colSetType(pCol, type); - colSetColId(pCol, colId); - colSetFlags(pCol, flags); + pCol->type = type; + pCol->colId = colId; + pCol->flags = flags; if (pBuilder->nCols == 0) { - colSetOffset(pCol, 0); + pCol->offset = 0; } else { STColumn *pTCol = &(pBuilder->columns[pBuilder->nCols - 1]); - colSetOffset(pCol, pTCol->offset + TYPE_BYTES[pTCol->type]); + pCol->offset = pTCol->offset + TYPE_BYTES[pTCol->type]; } if (IS_VAR_DATA_TYPE(type)) { - colSetBytes(pCol, bytes); + pCol->bytes = bytes; pBuilder->tlen += (TYPE_BYTES[type] + bytes); pBuilder->vlen += bytes - sizeof(VarDataLenT); } else { - colSetBytes(pCol, TYPE_BYTES[type]); + pCol->bytes = TYPE_BYTES[type]; pBuilder->tlen += TYPE_BYTES[type]; pBuilder->vlen += TYPE_BYTES[type]; } @@ -1275,151 +1137,19 @@ STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder) { STSchema *pSchema = (STSchema *)taosMemoryMalloc(tlen); if (pSchema == NULL) return NULL; - schemaVersion(pSchema) = pBuilder->version; - schemaNCols(pSchema) = pBuilder->nCols; - schemaTLen(pSchema) = pBuilder->tlen; - schemaFLen(pSchema) = pBuilder->flen; - schemaVLen(pSchema) = pBuilder->vlen; + pSchema->version = pBuilder->version; + pSchema->numOfCols = pBuilder->nCols; + pSchema->tlen = pBuilder->tlen; + pSchema->flen = pBuilder->flen; + pSchema->vlen = pBuilder->vlen; #ifdef TD_SUPPORT_BITMAP - schemaTLen(pSchema) += (int)TD_BITMAP_BYTES(schemaNCols(pSchema)); + pSchema->tlen += (int)TD_BITMAP_BYTES(pSchema->numOfCols); #endif - memcpy(schemaColAt(pSchema, 0), pBuilder->columns, sizeof(STColumn) * pBuilder->nCols); + memcpy(&pSchema->columns[0], pBuilder->columns, sizeof(STColumn) * pBuilder->nCols); return pSchema; } -void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) { - pDataCol->type = colType(pCol); - pDataCol->colId = colColId(pCol); - pDataCol->bytes = colBytes(pCol); - pDataCol->offset = colOffset(pCol) + 0; // TD_DATA_ROW_HEAD_SIZE; - - pDataCol->len = 0; -} - -static FORCE_INLINE const void *tdGetColDataOfRowUnsafe(SDataCol *pCol, int row) { - if (IS_VAR_DATA_TYPE(pCol->type)) { - return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]); - } else { - return POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row); - } -} - -bool isNEleNull(SDataCol *pCol, int nEle) { - if (isAllRowsNull(pCol)) return true; - for (int i = 0; i < nEle; ++i) { - if (!isNull(tdGetColDataOfRowUnsafe(pCol, i), pCol->type)) return false; - } - return true; -} - -void *dataColSetOffset(SDataCol *pCol, int nEle) { - ASSERT(((pCol->type == TSDB_DATA_TYPE_BINARY) || (pCol->type == TSDB_DATA_TYPE_NCHAR))); - - void *tptr = pCol->pData; - // char *tptr = (char *)(pCol->pData); - - VarDataOffsetT offset = 0; - for (int i = 0; i < nEle; ++i) { - pCol->dataOff[i] = offset; - offset += varDataTLen(tptr); - tptr = POINTER_SHIFT(tptr, varDataTLen(tptr)); - } - return POINTER_SHIFT(tptr, varDataTLen(tptr)); -} - -SDataCols *tdNewDataCols(int maxCols, int maxRows) { - SDataCols *pCols = (SDataCols *)taosMemoryCalloc(1, sizeof(SDataCols)); - if (pCols == NULL) { - uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)sizeof(SDataCols), strerror(errno)); - return NULL; - } - - pCols->maxPoints = maxRows; - pCols->maxCols = maxCols; - pCols->numOfRows = 0; - pCols->numOfCols = 0; - pCols->bitmapMode = TSDB_BITMODE_DEFAULT; - - if (maxCols > 0) { - pCols->cols = (SDataCol *)taosMemoryCalloc(maxCols, sizeof(SDataCol)); - if (pCols->cols == NULL) { - uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)sizeof(SDataCol) * maxCols, - strerror(errno)); - tdFreeDataCols(pCols); - return NULL; - } -#if 0 // no need as calloc used - int i; - for (i = 0; i < maxCols; i++) { - pCols->cols[i].spaceSize = 0; - pCols->cols[i].len = 0; - pCols->cols[i].pData = NULL; - pCols->cols[i].dataOff = NULL; - } -#endif - } - - return pCols; -} - -int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { - int i; - int oldMaxCols = pCols->maxCols; - if (schemaNCols(pSchema) > oldMaxCols) { - pCols->maxCols = schemaNCols(pSchema); - void *ptr = (SDataCol *)taosMemoryRealloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols); - if (ptr == NULL) return -1; - pCols->cols = ptr; - for (i = oldMaxCols; i < pCols->maxCols; ++i) { - pCols->cols[i].pData = NULL; - pCols->cols[i].dataOff = NULL; - pCols->cols[i].pBitmap = NULL; - pCols->cols[i].spaceSize = 0; - } - } -#if 0 - tdResetDataCols(pCols); // redundant loop to reset len/blen to 0, already reset in following dataColInit(...) -#endif - - pCols->numOfRows = 0; - pCols->bitmapMode = TSDB_BITMODE_DEFAULT; - pCols->numOfCols = schemaNCols(pSchema); - - for (i = 0; i < schemaNCols(pSchema); ++i) { - dataColInit(pCols->cols + i, schemaColAt(pSchema, i), pCols->maxPoints); - } - - return 0; -} - -SDataCols *tdFreeDataCols(SDataCols *pCols) { - int i; - if (pCols) { - if (pCols->cols) { - int maxCols = pCols->maxCols; - for (i = 0; i < maxCols; ++i) { - SDataCol *pCol = &pCols->cols[i]; - taosMemoryFreeClear(pCol->pData); - } - taosMemoryFree(pCols->cols); - pCols->cols = NULL; - } - taosMemoryFree(pCols); - } - return NULL; -} - -void tdResetDataCols(SDataCols *pCols) { - if (pCols != NULL) { - pCols->numOfRows = 0; - pCols->bitmapMode = 0; - for (int i = 0; i < pCols->maxCols; ++i) { - dataColReset(pCols->cols + i); - } - } -} - #endif \ No newline at end of file diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 496c7beb47..24bf4e5c2d 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -58,9 +58,8 @@ int32_t tsNumOfVnodeQueryThreads = 2; int32_t tsNumOfVnodeFetchThreads = 4; int32_t tsNumOfVnodeWriteThreads = 2; int32_t tsNumOfVnodeSyncThreads = 2; -int32_t tsNumOfVnodeMergeThreads = 2; int32_t tsNumOfQnodeQueryThreads = 2; -int32_t tsNumOfQnodeFetchThreads = 1; +int32_t tsNumOfQnodeFetchThreads = 4; int32_t tsNumOfSnodeSharedThreads = 2; int32_t tsNumOfSnodeUniqueThreads = 2; @@ -106,11 +105,6 @@ int32_t tsCompressMsgSize = -1; */ int32_t tsCompressColData = -1; -/* - * denote if 3.0 query pattern compatible for 2.0 - */ -int32_t tsCompatibleModel = 1; - // count/hyperloglog function always return values in case of all NULL data or Empty data set. int32_t tsCountAlwaysReturnValue = 1; @@ -120,7 +114,7 @@ int32_t tsMinSlidingTime = 10; // the maxinum number of distict query result int32_t tsMaxNumOfDistinctResults = 1000 * 10000; -// 1 us for interval time range, changed accordingly +// 1 database precision unit for interval time range, changed accordingly int32_t tsMinIntervalTime = 1; // 20sec, the maximum value of stream computing delay, changed accordingly @@ -414,30 +408,28 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { tsNumOfMnodeReadThreads = TRANGE(tsNumOfMnodeReadThreads, 1, 4); if (cfgAddInt32(pCfg, "numOfMnodeReadThreads", tsNumOfMnodeReadThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeQueryThreads = tsNumOfCores / 2; + tsNumOfVnodeQueryThreads = tsNumOfCores / 4; tsNumOfVnodeQueryThreads = TMAX(tsNumOfVnodeQueryThreads, 2); if (cfgAddInt32(pCfg, "numOfVnodeQueryThreads", tsNumOfVnodeQueryThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeFetchThreads = TRANGE(tsNumOfVnodeFetchThreads, 1, 1); + tsNumOfVnodeFetchThreads = tsNumOfCores / 4; + tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4); if (cfgAddInt32(pCfg, "numOfVnodeFetchThreads", tsNumOfVnodeFetchThreads, 1, 1024, 0) != 0) return -1; tsNumOfVnodeWriteThreads = tsNumOfCores; tsNumOfVnodeWriteThreads = TMAX(tsNumOfVnodeWriteThreads, 1); if (cfgAddInt32(pCfg, "numOfVnodeWriteThreads", tsNumOfVnodeWriteThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeSyncThreads = tsNumOfCores / 2; + tsNumOfVnodeSyncThreads = tsNumOfCores; tsNumOfVnodeSyncThreads = TMAX(tsNumOfVnodeSyncThreads, 1); if (cfgAddInt32(pCfg, "numOfVnodeSyncThreads", tsNumOfVnodeSyncThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeMergeThreads = tsNumOfCores / 8; - tsNumOfVnodeMergeThreads = TRANGE(tsNumOfVnodeMergeThreads, 1, 1); - if (cfgAddInt32(pCfg, "numOfVnodeMergeThreads", tsNumOfVnodeMergeThreads, 1, 1024, 0) != 0) return -1; - tsNumOfQnodeQueryThreads = tsNumOfCores / 2; tsNumOfQnodeQueryThreads = TMAX(tsNumOfQnodeQueryThreads, 1); if (cfgAddInt32(pCfg, "numOfQnodeQueryThreads", tsNumOfQnodeQueryThreads, 1, 1024, 0) != 0) return -1; - tsNumOfQnodeFetchThreads = TRANGE(tsNumOfQnodeFetchThreads, 1, 1); + tsNumOfQnodeFetchThreads = tsNumOfCores / 2; + tsNumOfQnodeFetchThreads = TMAX(tsNumOfQnodeFetchThreads, 4); if (cfgAddInt32(pCfg, "numOfQnodeFetchThreads", tsNumOfQnodeFetchThreads, 1, 1024, 0) != 0) return -1; tsNumOfSnodeSharedThreads = tsNumOfCores / 4; @@ -598,7 +590,6 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; - tsNumOfVnodeMergeThreads = cfgGetItem(pCfg, "numOfVnodeMergeThreads")->i32; tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32; tsNumOfQnodeFetchThreads = cfgGetItem(pCfg, "numOfQnodeFetchThreads")->i32; tsNumOfSnodeSharedThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; @@ -840,8 +831,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; } else if (strcasecmp("numOfVnodeSyncThreads", name) == 0) { tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; - } else if (strcasecmp("numOfVnodeMergeThreads", name) == 0) { - tsNumOfVnodeMergeThreads = cfgGetItem(pCfg, "numOfVnodeMergeThreads")->i32; } else if (strcasecmp("numOfQnodeQueryThreads", name) == 0) { tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32; } else if (strcasecmp("numOfQnodeFetchThreads", name) == 0) { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 9d8f49bdd5..eca8d49b6a 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2001,7 +2001,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -2014,7 +2014,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tEncodeI8(&encoder, pReq->compression) < 0) return -1; if (tEncodeI8(&encoder, pReq->replications) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->schemaless) < 0) return -1; if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1; @@ -2043,7 +2043,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -2056,7 +2056,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->schemaless) < 0) return -1; if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1; @@ -2098,7 +2098,7 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -2106,7 +2106,7 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->replications) < 0) return -1; tEndEncode(&encoder); @@ -2124,7 +2124,7 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -2132,7 +2132,7 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1; tEndDecode(&decoder); @@ -2672,6 +2672,56 @@ int32_t tDeserializeSTrimDbReq(void *buf, int32_t bufLen, STrimDbReq *pReq) { return 0; } +int32_t tSerializeSVTrimDbReq(void *buf, int32_t bufLen, SVTrimDbReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->timestamp) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSVTrimDbReq(void *buf, int32_t bufLen, SVTrimDbReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->timestamp) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + +int32_t tSerializeSVDropTtlTableReq(void *buf, int32_t bufLen, SVDropTtlTableReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->timestamp) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSVDropTtlTableReq(void *buf, int32_t bufLen, SVDropTtlTableReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->timestamp) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -2694,7 +2744,7 @@ int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { if (tEncodeI8(&encoder, pRsp->compression) < 0) return -1; if (tEncodeI8(&encoder, pRsp->replications) < 0) return -1; if (tEncodeI8(&encoder, pRsp->strict) < 0) return -1; - if (tEncodeI8(&encoder, pRsp->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->cacheLast) < 0) return -1; if (tEncodeI32(&encoder, pRsp->numOfRetensions) < 0) return -1; for (int32_t i = 0; i < pRsp->numOfRetensions; ++i) { SRetention *pRetension = taosArrayGet(pRsp->pRetensions, i); @@ -2733,7 +2783,7 @@ int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) { if (tDecodeI8(&decoder, &pRsp->compression) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->replications) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pRsp->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->cacheLast) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->numOfRetensions) < 0) return -1; if (pRsp->numOfRetensions > 0) { pRsp->pRetensions = taosArrayInit(pRsp->numOfRetensions, sizeof(SRetention)); @@ -3644,7 +3694,7 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -3659,7 +3709,7 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeI8(&encoder, pReq->precision) < 0) return -1; if (tEncodeI8(&encoder, pReq->compression) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->standby) < 0) return -1; if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; @@ -3702,7 +3752,7 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -3717,7 +3767,7 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1; if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->standby) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1; if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1; @@ -3827,7 +3877,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq if (tEncodeI32(&encoder, pReq->buffer) < 0) return -1; if (tEncodeI32(&encoder, pReq->pageSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->pages) < 0) return -1; - if (tEncodeI32(&encoder, pReq->lastRowMem) < 0) return -1; + if (tEncodeI32(&encoder, pReq->cacheLastSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; @@ -3835,7 +3885,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->strict) < 0) return -1; - if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pReq->cacheLast) < 0) return -1; if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { @@ -3858,7 +3908,7 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR if (tDecodeI32(&decoder, &pReq->buffer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pageSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pages) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->lastRowMem) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->cacheLastSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; @@ -3866,7 +3916,7 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->cacheLast) < 0) return -1; if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { @@ -4912,7 +4962,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) { if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1; if (tDecodeTag(pCoder, (STag **)&pReq->ctb.pTag) < 0) return -1; } else if (pReq->type == TSDB_NORMAL_TABLE) { - if (tDecodeSSchemaWrapper(pCoder, &pReq->ntb.schemaRow) < 0) return -1; + if (tDecodeSSchemaWrapperEx(pCoder, &pReq->ntb.schemaRow) < 0) return -1; } else { ASSERT(0); } @@ -5476,6 +5526,11 @@ bool tOffsetEqual(const STqOffsetVal *pLeft, const STqOffsetVal *pRight) { ASSERT(0); // TODO return pLeft->uid == pRight->uid && pLeft->ts == pRight->ts; + } else { + ASSERT(0); + /*ASSERT(pLeft->type == TMQ_OFFSET__RESET_NONE || pLeft->type == TMQ_OFFSET__RESET_EARLIEAST ||*/ + /*pLeft->type == TMQ_OFFSET__RESET_LATEST);*/ + /*return true;*/ } } return false; diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 052b6ffe58..f64250bce6 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -32,28 +32,10 @@ const uint8_t tdVTypeByte[2][3] = {{ }; // declaration -static uint8_t tdGetBitmapByte(uint8_t byte); -static int32_t tdCompareColId(const void *arg1, const void *arg2); +static uint8_t tdGetBitmapByte(uint8_t byte); +static int32_t tdCompareColId(const void *arg1, const void *arg2); static FORCE_INLINE int32_t compareKvRowColId(const void *key1, const void *key2); -// static void dataColSetNEleNull(SDataCol *pCol, int nEle); - -/** - * @brief src2 data has more priority than src1 - * - * @param target - * @param src1 - * @param iter1 - * @param limit1 - * @param src2 - * @param iter2 - * @param limit2 - * @param tRows - * @param update - */ -static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2, - int limit2, int tRows, bool update); - // implementation /** * @brief Compress bitmap bytes comprised of 2-bits to counterpart of 1-bit. @@ -287,33 +269,6 @@ void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap) { } } -static FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index, bool setBitmap, int8_t bitmapMode) { - if (IS_VAR_DATA_TYPE(pCol->type)) { - pCol->dataOff[index] = pCol->len; - char *ptr = POINTER_SHIFT(pCol->pData, pCol->len); - setVardataNull(ptr, pCol->type); - pCol->len += varDataTLen(ptr); - } else { - setNull(POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * index), pCol->type, pCol->bytes); - pCol->len += TYPE_BYTES[pCol->type]; - } - if (setBitmap) { - tdSetBitmapValType(pCol->pBitmap, index, TD_VTYPE_NONE, bitmapMode); - } -} - -// static void dataColSetNEleNull(SDataCol *pCol, int nEle) { -// if (IS_VAR_DATA_TYPE(pCol->type)) { -// pCol->len = 0; -// for (int i = 0; i < nEle; i++) { -// dataColSetNullAt(pCol, i); -// } -// } else { -// setNullN(pCol->pData, pCol->type, pCol->bytes, nEle); -// pCol->len = TYPE_BYTES[pCol->type] * nEle; -// } -// } - /** * @brief Set bitmap area by byte preferentially and then by bit. * @@ -362,56 +317,6 @@ bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode return true; } -static FORCE_INLINE void dataColSetNoneAt(SDataCol *pCol, int index, bool setBitmap, int8_t bitmapMode) { - if (IS_VAR_DATA_TYPE(pCol->type)) { - pCol->dataOff[index] = pCol->len; - char *ptr = POINTER_SHIFT(pCol->pData, pCol->len); - setVardataNull(ptr, pCol->type); - pCol->len += varDataTLen(ptr); - } else { - setNull(POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * index), pCol->type, pCol->bytes); - pCol->len += TYPE_BYTES[pCol->type]; - } - if (setBitmap) { - tdSetBitmapValType(pCol->pBitmap, index, TD_VTYPE_NONE, bitmapMode); - } -} - -static void dataColSetNEleNone(SDataCol *pCol, int nEle, int8_t bitmapMode) { - if (IS_VAR_DATA_TYPE(pCol->type)) { - pCol->len = 0; - for (int i = 0; i < nEle; ++i) { - dataColSetNoneAt(pCol, i, false, bitmapMode); - } - } else { - setNullN(pCol->pData, pCol->type, pCol->bytes, nEle); - pCol->len = TYPE_BYTES[pCol->type] * nEle; - } -#ifdef TD_SUPPORT_BITMAP - tdSetBitmapValTypeN(pCol->pBitmap, nEle, TD_VTYPE_NONE, bitmapMode); -#endif -} - -#if 0 -void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver) { - // TODO -} - -void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver) { - // TODO -} - -void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) { - // TODO -} - -int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) { - // TODO - return 0; -} - -#endif - STSRow *tdRowDup(STSRow *row) { STSRow *trow = taosMemoryMalloc(TD_ROW_LEN(row)); if (trow == NULL) return NULL; @@ -420,511 +325,6 @@ STSRow *tdRowDup(STSRow *row) { return trow; } -/** - * @brief - * - * @param pCol - * @param valType - * @param val - * @param numOfRows - * @param maxPoints - * @param bitmapMode default is 0(2 bits), otherwise 1(1 bit) - * @param isMerge merge to current row - * @return int - */ -int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int numOfRows, int maxPoints, - int8_t bitmapMode, bool isMerge) { - TASSERT(pCol != NULL); - - // Assume that the columns not specified during insert/upsert mean None. - if (isAllRowsNone(pCol)) { - if (tdValIsNone(valType)) { - // all None value yet, just return - return 0; - } - - if (tdAllocMemForCol(pCol, maxPoints) < 0) return -1; - if (numOfRows > 0) { - // Find the first not None value, fill all previous values as None - dataColSetNEleNone(pCol, numOfRows, bitmapMode); - } - } - const void *value = val; - if (!tdValTypeIsNorm(valType) || !val) { - // TODO: - // 1. back compatibility and easy to debug with codes of 2.0 to save NULL values. - // 2. later on, considering further optimization, don't save Null/None for VarType. - value = getNullValue(pCol->type); - } - if (!isMerge) { - if (IS_VAR_DATA_TYPE(pCol->type)) { - // set offset - pCol->dataOff[numOfRows] = pCol->len; - // Copy data - memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value)); - // Update the length - pCol->len += varDataTLen(value); - } else { - ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfRows); - memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes); - pCol->len += pCol->bytes; - } - } else if (!tdValTypeIsNone(valType)) { - if (IS_VAR_DATA_TYPE(pCol->type)) { - // keep the last offset - // discard the last var data - int32_t lastVarLen = varDataTLen(POINTER_SHIFT(pCol->pData, pCol->dataOff[numOfRows])); - pCol->len -= lastVarLen; - // Copy data - memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value)); - // Update the length - pCol->len += varDataTLen(value); - } else { - ASSERT(pCol->len - TYPE_BYTES[pCol->type] == TYPE_BYTES[pCol->type] * numOfRows); - memcpy(POINTER_SHIFT(pCol->pData, pCol->len - TYPE_BYTES[pCol->type]), value, pCol->bytes); - } - } - -#ifdef TD_SUPPORT_BITMAP - if (!isMerge || !tdValTypeIsNone(valType)) { - tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode); - } -#endif - return 0; -} - -// internal -static int32_t tdAppendTpRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) { -#if 0 - ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < TD_ROW_KEY(pRow)); -#endif - - // Multi-Version rows with the same key and different versions supported - ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) <= TD_ROW_KEY(pRow)); - - int rcol = 1; - int dcol = 1; - void *pBitmap = tdGetBitmapAddrTp(pRow, pSchema->flen); - - SDataCol *pDataCol = &(pCols->cols[0]); - ASSERT(pDataCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID); - tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - - while (dcol < pCols->numOfCols) { - pDataCol = &(pCols->cols[dcol]); - if (rcol >= schemaNCols(pSchema)) { - tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - ++dcol; - continue; - } - - STColumn *pRowCol = schemaColAt(pSchema, rcol); - SCellVal sVal = {0}; - if (pRowCol->colId == pDataCol->colId) { - if (tdGetTpRowValOfCol(&sVal, pRow, pBitmap, pRowCol->type, pRowCol->offset - sizeof(TSKEY), rcol - 1) < 0) { - return terrno; - } - tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - ++dcol; - ++rcol; - } else if (pRowCol->colId < pDataCol->colId) { - ++rcol; - } else { - tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - ++dcol; - } - } -#if 0 - ++pCols->numOfRows; -#endif - - return TSDB_CODE_SUCCESS; -} -// internal -static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) { - ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < TD_ROW_KEY(pRow)); - - int rcol = 0; - int dcol = 1; - int tRowCols = tdRowGetNCols(pRow) - 1; // the primary TS key not included in kvRowColIdx part - int tSchemaCols = schemaNCols(pSchema) - 1; - void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow)); - - SDataCol *pDataCol = &(pCols->cols[0]); - ASSERT(pDataCol->colId == PRIMARYKEY_TIMESTAMP_COL_ID); - tdAppendValToDataCol(pDataCol, TD_VTYPE_NORM, &pRow->ts, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - - while (dcol < pCols->numOfCols) { - pDataCol = &(pCols->cols[dcol]); - if (rcol >= tRowCols || rcol >= tSchemaCols) { - tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - ++dcol; - continue; - } - - SKvRowIdx *pIdx = tdKvRowColIdxAt(pRow, rcol); - int16_t colIdx = -1; - if (pIdx) { - colIdx = POINTER_DISTANCE(pIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx); - } - TASSERT(colIdx >= 0); - SCellVal sVal = {0}; - if (pIdx->colId == pDataCol->colId) { - if (tdGetKvRowValOfCol(&sVal, pRow, pBitmap, pIdx->offset, colIdx) < 0) { - return terrno; - } - tdAppendValToDataCol(pDataCol, sVal.valType, sVal.val, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - ++dcol; - ++rcol; - } else if (pIdx->colId < pDataCol->colId) { - ++rcol; - } else { - tdAppendValToDataCol(pDataCol, TD_VTYPE_NULL, NULL, pCols->numOfRows, pCols->maxPoints, pCols->bitmapMode, - isMerge); - ++dcol; - } - } -#if 0 - ++pCols->numOfRows; -#endif - - return TSDB_CODE_SUCCESS; -} - -/** - * @brief exposed - * - * @param pRow - * @param pSchema - * @param pCols - */ -int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool isMerge) { -#ifdef TD_DEBUG_PRINT_TSDB_LOAD_DCOLS - printf("%s:%d ts: %" PRIi64 " sver:%d maxCols:%" PRIi16 " nCols:%" PRIi16 ", nRows:%d\n", __func__, __LINE__, - TD_ROW_KEY(pRow), TD_ROW_SVER(pRow), pCols->maxCols, pCols->numOfCols, pCols->numOfRows); -#endif - if (TD_IS_TP_ROW(pRow)) { - return tdAppendTpRowToDataCol(pRow, pSchema, pCols, isMerge); - } else if (TD_IS_KV_ROW(pRow)) { - return tdAppendKvRowToDataCol(pRow, pSchema, pCols, isMerge); - } else { - ASSERT(0); - } - return TSDB_CODE_SUCCESS; -} - -/** - * @brief source data has more priority than target - * - * @param target - * @param source - * @param rowsToMerge - * @param pOffset - * @param update - * @param maxVer - * @return int - */ -int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool update, - TDRowVerT maxVer) { - ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows); - ASSERT(target->numOfCols == source->numOfCols); - int offset = 0; - - if (pOffset == NULL) { - pOffset = &offset; - } - - SDataCols *pTarget = NULL; - - if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyAtRow(source, *pOffset))) { // No overlap - ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints); - // TODO: filter the maxVer - TSKEY lastKey = TSKEY_INITIAL_VAL; - for (int i = 0; i < rowsToMerge; ++i) { - bool merge = false; - for (int j = 0; j < source->numOfCols; j++) { - if (source->cols[j].len > 0 || target->cols[j].len > 0) { - SCellVal sVal = {0}; - if (tdGetColDataOfRow(&sVal, source->cols + j, i + (*pOffset), source->bitmapMode) < 0) { - TASSERT(0); - } - - if (j == 0) { - if (lastKey == *(TSKEY *)sVal.val) { - if (!update) { - break; - } - merge = true; - } else if (lastKey != TSKEY_INITIAL_VAL) { - ++target->numOfRows; - } - - lastKey = *(TSKEY *)sVal.val; - } - if (i == 0) { - (target->cols + j)->bitmap = (source->cols + j)->bitmap; - } - - tdAppendValToDataCol(target->cols + j, sVal.valType, sVal.val, target->numOfRows, target->maxPoints, - target->bitmapMode, merge); - } - } - } - if (lastKey != TSKEY_INITIAL_VAL) { - ++target->numOfRows; - } - (*pOffset) += rowsToMerge; - } else { - pTarget = tdDupDataCols(target, true); - if (pTarget == NULL) goto _err; - - int iter1 = 0; - tdMergeTwoDataCols(target, pTarget, &iter1, pTarget->numOfRows, source, pOffset, source->numOfRows, - pTarget->numOfRows + rowsToMerge, update); - } - - tdFreeDataCols(pTarget); - return 0; - -_err: - tdFreeDataCols(pTarget); - return -1; -} - -static void tdAppendValToDataCols(SDataCols *target, SDataCols *src, int iter, bool isMerge) { - for (int i = 0; i < src->numOfCols; ++i) { - ASSERT(target->cols[i].type == src->cols[i].type); - if (src->cols[i].len > 0 || target->cols[i].len > 0) { - SCellVal sVal = {0}; - if (tdGetColDataOfRow(&sVal, src->cols + i, iter, src->bitmapMode) < 0) { - TASSERT(0); - } - if (isMerge) { - if (!tdValTypeIsNone(sVal.valType)) { - tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, - target->bitmapMode, isMerge); - } else { - // Keep the origin value for None - } - } else { - tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, - target->bitmapMode, isMerge); - } - } - } -} -/** - * @brief src2 data has more priority than src1 - * - * @param target - * @param src1 - * @param iter1 - * @param limit1 - * @param src2 - * @param iter2 - * @param limit2 - * @param tRows - * @param update - */ -static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2, - int limit2, int tRows, bool update) { - tdResetDataCols(target); - target->bitmapMode = src1->bitmapMode; - ASSERT(limit1 <= src1->numOfRows && limit2 <= src2->numOfRows); - int32_t nRows = 0; - - // TODO: filter the maxVer - // TODO: handle the delete function - TSKEY lastKey = TSKEY_INITIAL_VAL; - while (nRows < tRows) { - if (*iter1 >= limit1 && *iter2 >= limit2) break; - - TSKEY key1 = (*iter1 >= limit1) ? INT64_MAX : dataColsKeyAt(src1, *iter1); - // TKEY tkey1 = (*iter1 >= limit1) ? TKEY_NULL : dataColsTKeyAt(src1, *iter1); - TSKEY key2 = (*iter2 >= limit2) ? INT64_MAX : dataColsKeyAt(src2, *iter2); - // TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2); - - // ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1))); - - if (key1 <= key2) { - // select key1 if not delete - if (update && (lastKey == key1)) { - tdAppendValToDataCols(target, src1, *iter1, true); - } else if (lastKey != key1) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++target->numOfRows; - } - tdAppendValToDataCols(target, src1, *iter1, false); - } - ++nRows; - ++(*iter1); - lastKey = key1; - } else { - // use key2 if not deleted - // TODO: handle the delete function - if (update && (lastKey == key2)) { - tdAppendValToDataCols(target, src2, *iter2, true); - } else if (lastKey != key2) { - if (lastKey != TSKEY_INITIAL_VAL) { - ++target->numOfRows; - } - tdAppendValToDataCols(target, src2, *iter2, false); - } - - ++nRows; - ++(*iter2); - lastKey = key2; - } - - ASSERT(target->numOfRows <= target->maxPoints - 1); - } - if (lastKey != TSKEY_INITIAL_VAL) { - ++target->numOfRows; - } -} - -STSRow *mergeTwoRows(void *buffer, STSRow *row1, STSRow *row2, STSchema *pSchema1, STSchema *pSchema2) { -#if 0 - ASSERT(TD_ROW_KEY(row1) == TD_ROW_KEY(row2)); - ASSERT(schemaVersion(pSchema1) == TD_ROW_SVER(row1)); - ASSERT(schemaVersion(pSchema2) == TD_ROW_SVER(row2)); - ASSERT(schemaVersion(pSchema1) >= schemaVersion(pSchema2)); -#endif - -#if 0 - SArray *stashRow = taosArrayInit(pSchema1->numOfCols, sizeof(SColInfo)); - if (stashRow == NULL) { - return NULL; - } - - STSRow pRow = buffer; - STpRow dataRow = memRowDataBody(pRow); - memRowSetType(pRow, SMEM_ROW_DATA); - dataRowSetVersion(dataRow, schemaVersion(pSchema1)); // use latest schema version - dataRowSetLen(dataRow, (TDRowLenT)(TD_DATA_ROW_HEAD_SIZE + pSchema1->flen)); - - TDRowLenT dataLen = 0, kvLen = TD_MEM_ROW_KV_HEAD_SIZE; - - int32_t i = 0; // row1 - int32_t j = 0; // row2 - int32_t nCols1 = schemaNCols(pSchema1); - int32_t nCols2 = schemaNCols(pSchema2); - SColInfo colInfo = {0}; - int32_t kvIdx1 = 0, kvIdx2 = 0; - - while (i < nCols1) { - STColumn *pCol = schemaColAt(pSchema1, i); - void * val1 = tdGetMemRowDataOfColEx(row1, pCol->colId, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset, &kvIdx1); - // if val1 != NULL, use val1; - if (val1 != NULL && !isNull(val1, pCol->type)) { - tdAppendColVal(dataRow, val1, pCol->type, pCol->offset); - kvLen += tdGetColAppendLen(SMEM_ROW_KV, val1, pCol->type); - setSColInfo(&colInfo, pCol->colId, pCol->type, val1); - taosArrayPush(stashRow, &colInfo); - ++i; // next col - continue; - } - - void *val2 = NULL; - while (j < nCols2) { - STColumn *tCol = schemaColAt(pSchema2, j); - if (tCol->colId < pCol->colId) { - ++j; - continue; - } - if (tCol->colId == pCol->colId) { - val2 = tdGetMemRowDataOfColEx(row2, tCol->colId, tCol->type, TD_DATA_ROW_HEAD_SIZE + tCol->offset, &kvIdx2); - } else if (tCol->colId > pCol->colId) { - // set NULL - } - break; - } // end of while(jtype); - } - tdAppendColVal(dataRow, val2, pCol->type, pCol->offset); - if (!isNull(val2, pCol->type)) { - kvLen += tdGetColAppendLen(SMEM_ROW_KV, val2, pCol->type); - setSColInfo(&colInfo, pCol->colId, pCol->type, val2); - taosArrayPush(stashRow, &colInfo); - } - - ++i; // next col - } - - dataLen = TD_ROW_LEN(pRow); - - if (kvLen < dataLen) { - // scan stashRow and generate SKVRow - memset(buffer, 0, sizeof(dataLen)); - STSRow tRow = buffer; - memRowSetType(tRow, SMEM_ROW_KV); - SKVRow kvRow = (SKVRow)memRowKvBody(tRow); - int16_t nKvNCols = (int16_t) taosArrayGetSize(stashRow); - kvRowSetLen(kvRow, (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nKvNCols)); - kvRowSetNCols(kvRow, nKvNCols); - memRowSetKvVersion(tRow, pSchema1->version); - - int32_t toffset = 0; - int16_t k; - for (k = 0; k < nKvNCols; ++k) { - SColInfo *pColInfo = taosArrayGet(stashRow, k); - tdAppendKvColVal(kvRow, pColInfo->colVal, true, pColInfo->colId, pColInfo->colType, toffset); - toffset += sizeof(SColIdx); - } - ASSERT(kvLen == TD_ROW_LEN(tRow)); - } - taosArrayDestroy(stashRow); - return buffer; -#endif - return NULL; -} - -SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) { - SDataCols *pRet = tdNewDataCols(pDataCols->maxCols, pDataCols->maxPoints); - if (pRet == NULL) return NULL; - - pRet->numOfCols = pDataCols->numOfCols; - pRet->bitmapMode = pDataCols->bitmapMode; - pRet->sversion = pDataCols->sversion; - if (keepData) pRet->numOfRows = pDataCols->numOfRows; - - for (int i = 0; i < pDataCols->numOfCols; ++i) { - pRet->cols[i].type = pDataCols->cols[i].type; - pRet->cols[i].bitmap = pDataCols->cols[i].bitmap; - pRet->cols[i].colId = pDataCols->cols[i].colId; - pRet->cols[i].bytes = pDataCols->cols[i].bytes; - pRet->cols[i].offset = pDataCols->cols[i].offset; - - if (keepData) { - if (pDataCols->cols[i].len > 0) { - if (tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints) < 0) { - tdFreeDataCols(pRet); - return NULL; - } - pRet->cols[i].len = pDataCols->cols[i].len; - memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len); - if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) { - int dataOffSize = sizeof(VarDataOffsetT) * pDataCols->maxPoints; - memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, dataOffSize); - } - if (!TD_COL_ROWS_NORM(pRet->cols + i)) { - memcpy(pRet->cols[i].pBitmap, pDataCols->cols[i].pBitmap, TD_BITMAP_BYTES(pDataCols->numOfRows)); - } - } - } - } - - return pRet; -} - void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag) { STSRowIter iter = {0}; tdSTSRowIterInit(&iter, pSchema); @@ -1020,32 +420,6 @@ void tdSCellValPrint(SCellVal *pVal, int8_t colType) { } } -int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, int8_t bitmapMode) { - ASSERT(rows > 0); - int32_t result = 0; - - if (IS_VAR_DATA_TYPE(pDataCol->type)) { - result += pDataCol->dataOff[rows - 1]; - SCellVal val = {0}; - if (tdGetColDataOfRow(&val, pDataCol, rows - 1, bitmapMode) < 0) { - TASSERT(0); - } - - // Currently, count the varDataTLen in of Null/None cols considering back compatibility test for 2.4 - result += varDataTLen(val.val); - // TODO: later on, don't save Null/None for VarDataT for 3.0 - // if (tdValTypeIsNorm(val.valType)) { - // result += varDataTLen(val.val); - // } - } else { - result += TYPE_BYTES[pDataCol->type] * rows; - } - - ASSERT(pDataCol->len == result); - - return result; -} - bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCellVal *pVal) { if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { tdRowSetVal(pVal, TD_VTYPE_NORM, TD_ROW_KEY_ADDR(pRow)); @@ -1082,40 +456,6 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl return true; } -int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int32_t row, int8_t bitmapMode) { - if (isAllRowsNone(pCol)) { - pVal->valType = TD_VTYPE_NONE; -#ifdef TD_SUPPORT_READ2 - pVal->val = (void *)getNullValue(pCol->type); -#else - pVal->val = NULL; -#endif - return TSDB_CODE_SUCCESS; - } - - if (TD_COL_ROWS_NORM(pCol)) { - pVal->valType = TD_VTYPE_NORM; - } else if (tdGetBitmapValType(pCol->pBitmap, row, &(pVal->valType), bitmapMode) < 0) { - return terrno; - } - - if (tdValTypeIsNorm(pVal->valType)) { - if (IS_VAR_DATA_TYPE(pCol->type)) { - pVal->val = POINTER_SHIFT(pCol->pData, pCol->dataOff[row]); - } else { - pVal->val = POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row); - } - } else { - pVal->valType = TD_VTYPE_NULL; -#ifdef TD_SUPPORT_READ2 - pVal->val = (void *)getNullValue(pCol->type); -#else - pVal->val = NULL; -#endif - } - return TSDB_CODE_SUCCESS; -} - bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal) { if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { pVal->val = &pIter->pRow->ts; diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index a52bb6b516..d16e35ff07 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -285,8 +285,8 @@ int32_t debugPrintSColVal(SColVal *cv, int8_t type) { } void debugPrintTSRow(STSRow2 *row, STSchema *pTSchema, const char *tags, int32_t ln) { - printf("%s:%d %s:v%d:%d ", tags, ln, (row->flags & 0xf0) ? "KV" : "TP", row->sver, row->nData); - for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) { + // printf("%s:%d %s:v%d:%d ", tags, ln, (row->flags & 0xf0) ? "KV" : "TP", row->sver, row->nData); + for (int16_t i = 0; i < pTSchema->numOfCols; ++i) { SColVal cv = {0}; tTSRowGet(row, pTSchema, i, &cv); debugPrintSColVal(&cv, pTSchema->columns[i].type); @@ -393,7 +393,7 @@ static int32_t checkSColVal(const char *rawVal, SColVal *cv, int8_t type) { } static void checkTSRow(const char **data, STSRow2 *row, STSchema *pTSchema) { - for (int16_t i = 0; i < schemaNCols(pTSchema); ++i) { + for (int16_t i = 0; i < pTSchema->numOfCols; ++i) { SColVal cv = {0}; tTSRowGet(row, pTSchema, i, &cv); checkSColVal(data[i], &cv, pTSchema->columns[i].type); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 4e3449feb7..b9a02728fc 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -171,6 +171,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_USE_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_COMPACT_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TRIM_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_GET_DB_CFG, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_VGROUP_LIST, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_REDISTRIBUTE_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 012e61d239..84491a82b0 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -150,6 +150,7 @@ static void mmStop(SMnodeMgmt *pMgmt) { dDebug("mnode-mgmt start to stop"); taosThreadRwlockWrlock(&pMgmt->lock); pMgmt->stopped = 1; + mndPreClose(pMgmt->pMnode); taosThreadRwlockUnlock(&pMgmt->lock); mndStop(pMgmt->pMnode); diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index 6f00767eb0..6fc0ab4e5d 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -31,7 +31,7 @@ typedef struct SVnodeMgmt { const char *path; const char *name; SQWorkerPool queryPool; - SQWorkerPool fetchPool; + SWWorkerPool fetchPool; SWWorkerPool syncPool; SWWorkerPool writePool; SWWorkerPool applyPool; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index 90f852eed1..cbcb541200 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -31,7 +31,7 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) { SVnodeObj *pVnode = *ppVnode; if (pVnode && num < size) { int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1); - // dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount); + // dTrace("vgId:%d, acquire vnode list, ref:%d", pVnode->vgId, refCount); pVnodes[num++] = (*ppVnode); pIter = taosHashIterate(pMgmt->hash, pIter); } else { diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 5ffddd0127..7e7139ba53 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -138,6 +138,8 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pCfg->dbId = pCreate->dbUid; pCfg->szPage = pCreate->pageSize * 1024; pCfg->szCache = pCreate->pages; + pCfg->cacheLast = pCreate->cacheLast; + pCfg->cacheLastSize = pCreate->cacheLastSize; pCfg->szBuf = (uint64_t)pCreate->buffer * 1024 * 1024; pCfg->isWeak = true; pCfg->isTsma = pCreate->isTsma; @@ -210,7 +212,8 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return -1; } - dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d", createReq.vgId, createReq.isTsma, createReq.standby); + dDebug("vgId:%d, start to create vnode, tsma:%d standby:%d cacheLast:%d cacheLastSize:%d", createReq.vgId, + createReq.isTsma, createReq.standby, createReq.cacheLast, createReq.cacheLastSize); vmGenerateVnodeCfg(&createReq, &vnodeCfg); if (vmTsmaAdjustDays(&vnodeCfg, &createReq) < 0) { @@ -370,6 +373,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIRM, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_HASHRANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TRIM, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 051e5defb0..36f6fab699 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -23,6 +23,7 @@ SVnodeObj *vmAcquireVnode(SVnodeMgmt *pMgmt, int32_t vgId) { taosHashGetDup(pMgmt->hash, &vgId, sizeof(int32_t), (void *)&pVnode); if (pVnode == NULL || pVnode->dropped) { terrno = TSDB_CODE_VND_INVALID_VGROUP_ID; + pVnode = NULL; } else { int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1); // dTrace("vgId:%d, acquire vnode, ref:%d", pVnode->vgId, refCount); @@ -75,11 +76,14 @@ int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) { void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { char path[TSDB_FILENAME_LEN] = {0}; + vnodePreClose(pVnode->pImpl); + taosThreadRwlockWrlock(&pMgmt->lock); taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t)); taosThreadRwlockUnlock(&pMgmt->lock); - vmReleaseVnode(pMgmt, pVnode); + + dTrace("vgId:%d, wait for vnode ref become 0", pVnode->vgId); while (pVnode->refCount > 0) taosMsleep(10); dTrace("vgId:%d, wait for vnode queue is empty", pVnode->vgId); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index 1d795c74f2..93f93b1ab7 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -81,21 +81,26 @@ static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { taosFreeQitem(pMsg); } -static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { - SVnodeObj *pVnode = pInfo->ahandle; - const STraceId *trace = &pMsg->info.traceId; +static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { + SVnodeObj *pVnode = pInfo->ahandle; + SRpcMsg *pMsg = NULL; - dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg); - int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo); - if (code != 0) { - if (terrno != 0) code = terrno; - dGError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr()); - vmSendRsp(pMsg, code); + for (int32_t i = 0; i < numOfMsgs; ++i) { + if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; + const STraceId *trace = &pMsg->info.traceId; + dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg); + + int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo); + if (code != 0) { + if (terrno != 0) code = terrno; + dGError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr()); + vmSendRsp(pMsg, code); + } + + dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); } - - dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); } static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { @@ -201,9 +206,9 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { int32_t code = vmPutMsgToQueue(pMgmt, pMsg, qtype); if (code != 0) { dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); rpcFreeCont(pMsg->pCont); pRpc->pCont = NULL; + taosFreeQitem(pMsg); } return code; @@ -232,8 +237,8 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) { default: break; } + vmReleaseVnode(pMgmt, pVnode); } - vmReleaseVnode(pMgmt, pVnode); return size; } @@ -242,7 +247,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue); pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyWriteMsg); pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue); - pVnode->pFetchQ = tQWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItem)vmProcessFetchQueue); + pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue); if (pVnode->pWriteQ == NULL || pVnode->pSyncQ == NULL || pVnode->pApplyQ == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL) { @@ -250,7 +255,11 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { return -1; } - dDebug("vgId:%d, queue is alloced", pVnode->vgId); + dDebug("vgId:%d, write-queue:%p is alloced", pVnode->vgId, pVnode->pWriteQ); + dDebug("vgId:%d, sync-queue:%p is alloced", pVnode->vgId, pVnode->pSyncQ); + dDebug("vgId:%d, apply-queue:%p is alloced", pVnode->vgId, pVnode->pApplyQ); + dDebug("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ); + dDebug("vgId:%d, fetch-queue:%p is alloced", pVnode->vgId, pVnode->pFetchQ); return 0; } @@ -259,7 +268,7 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { tWWorkerFreeQueue(&pMgmt->applyPool, pVnode->pApplyQ); tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ); tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ); - tQWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ); + tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ); pVnode->pWriteQ = NULL; pVnode->pSyncQ = NULL; pVnode->pApplyQ = NULL; @@ -275,11 +284,10 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { pQPool->max = tsNumOfVnodeQueryThreads; if (tQWorkerInit(pQPool) != 0) return -1; - SQWorkerPool *pFPool = &pMgmt->fetchPool; + SWWorkerPool *pFPool = &pMgmt->fetchPool; pFPool->name = "vnode-fetch"; - pFPool->min = tsNumOfVnodeFetchThreads; pFPool->max = tsNumOfVnodeFetchThreads; - if (tQWorkerInit(pFPool) != 0) return -1; + if (tWWorkerInit(pFPool) != 0) return -1; SWWorkerPool *pWPool = &pMgmt->writePool; pWPool->name = "vnode-write"; @@ -325,6 +333,6 @@ void vmStopWorker(SVnodeMgmt *pMgmt) { tWWorkerCleanup(&pMgmt->applyPool); tWWorkerCleanup(&pMgmt->syncPool); tQWorkerCleanup(&pMgmt->queryPool); - tQWorkerCleanup(&pMgmt->fetchPool); + tWWorkerCleanup(&pMgmt->fetchPool); dDebug("vnode workers are closed"); } diff --git a/source/dnode/mgmt/test/vnode/vnode.cpp b/source/dnode/mgmt/test/vnode/vnode.cpp index 8aba4f81b5..520d844dbd 100644 --- a/source/dnode/mgmt/test/vnode/vnode.cpp +++ b/source/dnode/mgmt/test/vnode/vnode.cpp @@ -45,7 +45,7 @@ TEST_F(DndTestVnode, 01_Create_Vnode) { createReq.compression = 2; createReq.replica = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.selfIndex = 0; for (int r = 0; r < createReq.replica; ++r) { SReplica* pReplica = &createReq.replicas[r]; @@ -80,7 +80,7 @@ TEST_F(DndTestVnode, 02_Alter_Vnode) { alterReq.walLevel = 1; alterReq.replica = 1; alterReq.strict = 1; - alterReq.cacheLastRow = 0; + alterReq.cacheLast = 0; alterReq.selfIndex = 0; for (int r = 0; r < alterReq.replica; ++r) { SReplica* pReplica = &alterReq.replicas[r]; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index f39a848992..7ac991451e 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -246,7 +246,7 @@ typedef struct { int32_t buffer; int32_t pageSize; int32_t pages; - int32_t lastRowMem; + int32_t cacheLastSize; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; @@ -260,7 +260,7 @@ typedef struct { int8_t replications; int8_t strict; int8_t hashMethod; // default is 1 - int8_t cacheLastRow; + int8_t cacheLast; int32_t numOfRetensions; SArray* pRetensions; int8_t schemaless; diff --git a/source/dnode/mnode/impl/inc/mndPrivilege.h b/source/dnode/mnode/impl/inc/mndPrivilege.h index 0c56f6f155..a149c0f0e2 100644 --- a/source/dnode/mnode/impl/inc/mndPrivilege.h +++ b/source/dnode/mnode/impl/inc/mndPrivilege.h @@ -54,6 +54,7 @@ typedef enum { MND_OPER_ALTER_DB, MND_OPER_DROP_DB, MND_OPER_COMPACT_DB, + MND_OPER_TRIM_DB, MND_OPER_USE_DB, MND_OPER_WRITE_DB, MND_OPER_READ_DB, diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 156afb09fc..b1c2b0e277 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -42,6 +42,7 @@ static int32_t mndProcessAlterDbReq(SRpcMsg *pReq); static int32_t mndProcessDropDbReq(SRpcMsg *pReq); static int32_t mndProcessUseDbReq(SRpcMsg *pReq); static int32_t mndProcessCompactDbReq(SRpcMsg *pReq); +static int32_t mndProcessTrimDbReq(SRpcMsg *pReq); static int32_t mndRetrieveDbs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity); static void mndCancelGetNextDb(SMnode *pMnode, void *pIter); static int32_t mndProcessGetDbCfgReq(SRpcMsg *pReq); @@ -62,6 +63,7 @@ int32_t mndInitDb(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_DROP_DB, mndProcessDropDbReq); mndSetMsgHandle(pMnode, TDMT_MND_USE_DB, mndProcessUseDbReq); mndSetMsgHandle(pMnode, TDMT_MND_COMPACT_DB, mndProcessCompactDbReq); + mndSetMsgHandle(pMnode, TDMT_MND_TRIM_DB, mndProcessTrimDbReq); mndSetMsgHandle(pMnode, TDMT_MND_GET_DB_CFG, mndProcessGetDbCfgReq); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DB, mndRetrieveDbs); @@ -93,7 +95,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { SDB_SET_INT32(pRaw, dataPos, pDb->cfg.buffer, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pageSize, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.pages, _OVER) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.lastRowMem, _OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheLastSize, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, _OVER) @@ -106,7 +108,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.strict, _OVER) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow, _OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLast, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.hashMethod, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfRetensions, _OVER) for (int32_t i = 0; i < pDb->cfg.numOfRetensions; ++i) { @@ -166,7 +168,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.buffer, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pageSize, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.pages, _OVER) - SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.lastRowMem, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.cacheLastSize, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysPerFile, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, _OVER) @@ -179,7 +181,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.compression, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.replications, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.strict, _OVER) - SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLastRow, _OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLast, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.hashMethod, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfRetensions, _OVER) if (pDb->cfg.numOfRetensions > 0) { @@ -234,7 +236,7 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) { pOld->cfg.buffer = pNew->cfg.buffer; pOld->cfg.pageSize = pNew->cfg.pageSize; pOld->cfg.pages = pNew->cfg.pages; - pOld->cfg.lastRowMem = pNew->cfg.lastRowMem; + pOld->cfg.cacheLastSize = pNew->cfg.cacheLastSize; pOld->cfg.daysPerFile = pNew->cfg.daysPerFile; pOld->cfg.daysToKeep0 = pNew->cfg.daysToKeep0; pOld->cfg.daysToKeep1 = pNew->cfg.daysToKeep1; @@ -242,7 +244,7 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) { pOld->cfg.fsyncPeriod = pNew->cfg.fsyncPeriod; pOld->cfg.walLevel = pNew->cfg.walLevel; pOld->cfg.strict = pNew->cfg.strict; - pOld->cfg.cacheLastRow = pNew->cfg.cacheLastRow; + pOld->cfg.cacheLast = pNew->cfg.cacheLast; pOld->cfg.replications = pNew->cfg.replications; taosWUnLockLatch(&pOld->lock); return 0; @@ -291,7 +293,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->buffer < TSDB_MIN_BUFFER_PER_VNODE || pCfg->buffer > TSDB_MAX_BUFFER_PER_VNODE) return -1; if (pCfg->pageSize < TSDB_MIN_PAGESIZE_PER_VNODE || pCfg->pageSize > TSDB_MAX_PAGESIZE_PER_VNODE) return -1; if (pCfg->pages < TSDB_MIN_PAGES_PER_VNODE || pCfg->pages > TSDB_MAX_PAGES_PER_VNODE) return -1; - if (pCfg->lastRowMem < TSDB_MIN_DB_LAST_ROW_MEM || pCfg->lastRowMem > TSDB_MAX_DB_LAST_ROW_MEM) return -1; + if (pCfg->cacheLastSize < TSDB_MIN_DB_CACHE_LAST_SIZE || pCfg->cacheLastSize > TSDB_MAX_DB_CACHE_LAST_SIZE) return -1; if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1; if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1; if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1; @@ -310,7 +312,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->replications != 1 && pCfg->replications != 3) return -1; if (pCfg->strict < TSDB_DB_STRICT_OFF || pCfg->strict > TSDB_DB_STRICT_ON) return -1; if (pCfg->schemaless < TSDB_DB_SCHEMALESS_OFF || pCfg->schemaless > TSDB_DB_SCHEMALESS_ON) return -1; - if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1; + if (pCfg->cacheLast < TSDB_MIN_DB_CACHE_LAST || pCfg->cacheLast > TSDB_MAX_DB_CACHE_LAST) return -1; if (pCfg->hashMethod != 1) return -1; if (pCfg->replications > mndGetDnodeSize(pMnode)) { terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; @@ -339,8 +341,8 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->compression < 0) pCfg->compression = TSDB_DEFAULT_COMP_LEVEL; if (pCfg->replications < 0) pCfg->replications = TSDB_DEFAULT_DB_REPLICA; if (pCfg->strict < 0) pCfg->strict = TSDB_DEFAULT_DB_STRICT; - if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; - if (pCfg->lastRowMem <= 0) pCfg->lastRowMem = TSDB_DEFAULT_LAST_ROW_MEM; + if (pCfg->cacheLast < 0) pCfg->cacheLast = TSDB_DEFAULT_CACHE_LAST; + if (pCfg->cacheLastSize <= 0) pCfg->cacheLastSize = TSDB_DEFAULT_CACHE_LAST_SIZE; if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0; if (pCfg->schemaless < 0) pCfg->schemaless = TSDB_DB_SCHEMALESS_OFF; } @@ -439,7 +441,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, .buffer = pCreate->buffer, .pageSize = pCreate->pageSize, .pages = pCreate->pages, - .lastRowMem = pCreate->lastRowMem, + .cacheLastSize = pCreate->cacheLastSize, .daysPerFile = pCreate->daysPerFile, .daysToKeep0 = pCreate->daysToKeep0, .daysToKeep1 = pCreate->daysToKeep1, @@ -452,7 +454,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, .compression = pCreate->compression, .replications = pCreate->replications, .strict = pCreate->strict, - .cacheLastRow = pCreate->cacheLastRow, + .cacheLast = pCreate->cacheLast, .hashMethod = 1, .schemaless = pCreate->schemaless, }; @@ -623,13 +625,13 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { #endif } - if (pAlter->cacheLastRow >= 0 && pAlter->cacheLastRow != pDb->cfg.cacheLastRow) { - pDb->cfg.cacheLastRow = pAlter->cacheLastRow; + if (pAlter->cacheLast >= 0 && pAlter->cacheLast != pDb->cfg.cacheLast) { + pDb->cfg.cacheLast = pAlter->cacheLast; terrno = 0; } - if (pAlter->lastRowMem > 0 && pAlter->lastRowMem != pDb->cfg.lastRowMem) { - pDb->cfg.lastRowMem = pAlter->lastRowMem; + if (pAlter->cacheLastSize > 0 && pAlter->cacheLastSize != pDb->cfg.cacheLastSize) { + pDb->cfg.cacheLastSize = pAlter->cacheLastSize; terrno = 0; } @@ -801,7 +803,7 @@ static int32_t mndProcessGetDbCfgReq(SRpcMsg *pReq) { cfgRsp.compression = pDb->cfg.compression; cfgRsp.replications = pDb->cfg.replications; cfgRsp.strict = pDb->cfg.strict; - cfgRsp.cacheLastRow = pDb->cfg.cacheLastRow; + cfgRsp.cacheLast = pDb->cfg.cacheLast; cfgRsp.numOfRetensions = pDb->cfg.numOfRetensions; cfgRsp.pRetensions = pDb->cfg.pRetensions; cfgRsp.schemaless = pDb->cfg.schemaless; @@ -1268,6 +1270,8 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, return 0; } +static int32_t mndCompactDb(SMnode *pMnode, SDbObj *pDb) { return 0; } + static int32_t mndProcessCompactDbReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1; @@ -1279,7 +1283,7 @@ static int32_t mndProcessCompactDbReq(SRpcMsg *pReq) { goto _OVER; } - mDebug("db:%s, start to sync", compactReq.db); + mDebug("db:%s, start to compact", compactReq.db); pDb = mndAcquireDb(pMnode, compactReq.db); if (pDb == NULL) { @@ -1290,7 +1294,7 @@ static int32_t mndProcessCompactDbReq(SRpcMsg *pReq) { goto _OVER; } - // code = mndCompactDb(); + code = mndCompactDb(pMnode, pDb); _OVER: if (code != 0) { @@ -1301,6 +1305,75 @@ _OVER: return code; } +static int32_t mndTrimDb(SMnode *pMnode, SDbObj *pDb) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + SVTrimDbReq trimReq = {.timestamp = taosGetTimestampSec()}; + int32_t reqLen = tSerializeSVTrimDbReq(NULL, 0, &trimReq); + int32_t contLen = reqLen + sizeof(SMsgHead); + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + SMsgHead *pHead = rpcMallocCont(contLen); + if (pHead == NULL) { + sdbCancelFetch(pSdb, pVgroup); + sdbRelease(pSdb, pVgroup); + continue; + } + pHead->contLen = htonl(contLen); + pHead->vgId = htonl(pVgroup->vgId); + tSerializeSVTrimDbReq((char *)pHead + sizeof(SMsgHead), contLen, &trimReq); + + SRpcMsg rpcMsg = {.msgType = TDMT_VND_TRIM, .pCont = pHead, .contLen = contLen}; + SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); + int32_t code = tmsgSendReq(&epSet, &rpcMsg); + if (code != 0) { + mError("vgId:%d, failed to send vnode-trim request to vnode since 0x%x", pVgroup->vgId, code); + } else { + mDebug("vgId:%d, send vnode-trim request to vnode, time:%d", pVgroup->vgId, trimReq.timestamp); + } + sdbRelease(pSdb, pVgroup); + } + + return 0; +} + +static int32_t mndProcessTrimDbReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + int32_t code = -1; + SDbObj *pDb = NULL; + STrimDbReq trimReq = {0}; + + if (tDeserializeSTrimDbReq(pReq->pCont, pReq->contLen, &trimReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto _OVER; + } + + mDebug("db:%s, start to trim", trimReq.db); + + pDb = mndAcquireDb(pMnode, trimReq.db); + if (pDb == NULL) { + goto _OVER; + } + + if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_TRIM_DB, pDb) != 0) { + goto _OVER; + } + + code = mndTrimDb(pMnode, pDb); + +_OVER: + if (code != 0) { + mError("db:%s, failed to process trim db req since %s", trimReq.db, terrstr()); + } + + mndReleaseDb(pMnode, pDb); + return code; +} + const char *mndGetDbStr(const char *src) { char *pos = strstr(src, TS_PATH_DELIMITER); if (pos != NULL) ++pos; @@ -1467,7 +1540,7 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.compression, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheLastRow, false); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheLast, false); const char *precStr = NULL; switch (pDb->cfg.precision) { diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index f18f3c983e..df8dc42d17 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -366,6 +366,12 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return pMnode; } +void mndPreClose(SMnode *pMnode) { + if (pMnode != NULL) { + syncLeaderTransfer(pMnode->syncMgmt.sync); + } +} + void mndClose(SMnode *pMnode) { if (pMnode != NULL) { mDebug("start to close mnode"); @@ -531,8 +537,7 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { if (!IsReq(pMsg)) return 0; if (pMsg->msgType == TDMT_SCH_QUERY || pMsg->msgType == TDMT_SCH_MERGE_QUERY || pMsg->msgType == TDMT_SCH_QUERY_CONTINUE || pMsg->msgType == TDMT_SCH_QUERY_HEARTBEAT || - pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_SCH_MERGE_FETCH || - pMsg->msgType == TDMT_SCH_DROP_TASK) { + pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_SCH_MERGE_FETCH || pMsg->msgType == TDMT_SCH_DROP_TASK) { return 0; } if (mndAcquireRpcRef(pMsg->info.node) == 0) return 0; diff --git a/source/dnode/mnode/impl/src/mndPrivilege.c b/source/dnode/mnode/impl/src/mndPrivilege.c index dc321e38d1..e4422c480f 100644 --- a/source/dnode/mnode/impl/src/mndPrivilege.c +++ b/source/dnode/mnode/impl/src/mndPrivilege.c @@ -155,7 +155,8 @@ int32_t mndCheckDbPrivilege(SMnode *pMnode, const char *user, EOperType operType if (pUser->sysInfo) goto _OVER; } - if (operType == MND_OPER_ALTER_DB || operType == MND_OPER_DROP_DB || operType == MND_OPER_COMPACT_DB) { + if (operType == MND_OPER_ALTER_DB || operType == MND_OPER_DROP_DB || operType == MND_OPER_COMPACT_DB || + operType == MND_OPER_TRIM_DB) { if (strcmp(pUser->user, pDb->createUser) == 0 && pUser->sysInfo) goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 388441b1dc..c040f0d05b 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -204,6 +204,8 @@ _OVER: mError("sma:%s, failed to decode from raw:%p since %s", pSma->name, pRaw, terrstr()); taosMemoryFreeClear(pSma->expr); taosMemoryFreeClear(pSma->tagsFilter); + taosMemoryFreeClear(pSma->sql); + taosMemoryFreeClear(pSma->ast); taosMemoryFreeClear(pRow); return NULL; } @@ -221,6 +223,8 @@ static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSma) { mTrace("sma:%s, perform delete action, row:%p", pSma->name, pSma); taosMemoryFreeClear(pSma->tagsFilter); taosMemoryFreeClear(pSma->expr); + taosMemoryFreeClear(pSma->sql); + taosMemoryFreeClear(pSma->ast); return 0; } @@ -527,10 +531,20 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea streamObj.version = 1; streamObj.sql = pCreate->sql; streamObj.smaId = smaObj.uid; - streamObj.watermark = 0; - streamObj.trigger = STREAM_TRIGGER_AT_ONCE; + streamObj.watermark = pCreate->watermark; + streamObj.trigger = STREAM_TRIGGER_WINDOW_CLOSE; + streamObj.triggerParam = pCreate->maxDelay; streamObj.ast = strdup(smaObj.ast); + // check the maxDelay + if (streamObj.triggerParam < TSDB_MIN_ROLLUP_MAX_DELAY) { + int64_t msInterval = convertTimeFromPrecisionToUnit(pCreate->interval, pDb->cfg.precision, TIME_UNIT_MILLISECOND); + streamObj.triggerParam = msInterval > TSDB_MIN_ROLLUP_MAX_DELAY ? msInterval : TSDB_MIN_ROLLUP_MAX_DELAY; + } + if (streamObj.triggerParam > TSDB_MAX_ROLLUP_MAX_DELAY) { + streamObj.triggerParam = TSDB_MAX_ROLLUP_MAX_DELAY; + } + if (mndAllocSmaVgroup(pMnode, pDb, &streamObj.fixedSinkVg) != 0) { mError("sma:%s, failed to create since %s", smaObj.name, terrstr()); return -1; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 8ce22c2b2e..1e57625028 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -813,16 +813,18 @@ int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p } static int32_t mndProcessTtlTimer(SRpcMsg *pReq) { - SMnode *pMnode = pReq->info.node; - SSdb *pSdb = pMnode->pSdb; - SVgObj *pVgroup = NULL; - void *pIter = NULL; + SMnode *pMnode = pReq->info.node; + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + SVDropTtlTableReq ttlReq = {.timestamp = taosGetTimestampSec()}; + int32_t reqLen = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq); + int32_t contLen = reqLen + sizeof(SMsgHead); while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); if (pIter == NULL) break; - int32_t contLen = sizeof(SMsgHead) + sizeof(int32_t); SMsgHead *pHead = rpcMallocCont(contLen); if (pHead == NULL) { sdbCancelFetch(pSdb, pVgroup); @@ -831,17 +833,15 @@ static int32_t mndProcessTtlTimer(SRpcMsg *pReq) { } pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - - int32_t t = taosGetTimestampSec(); - *(int32_t *)((char *)pHead + sizeof(SMsgHead)) = htonl(t); + tSerializeSVDropTtlTableReq((char *)pHead + sizeof(SMsgHead), contLen, &ttlReq); SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen}; SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); int32_t code = tmsgSendReq(&epSet, &rpcMsg); if (code != 0) { - mError("failed to send ttl time seed, code:0x%x", code); + mError("vgId:%d, failed to send drop ttl table request to vnode since 0x%x", pVgroup->vgId, code); } else { - mDebug("send ttl time seed success, time:%d", t); + mDebug("vgId:%d, send drop ttl table request to vnode, time:%d", pVgroup->vgId, ttlReq.timestamp); } sdbRelease(pSdb, pVgroup); } @@ -2109,7 +2109,7 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables - pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); if (pStb->commentLen > 0) { char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(comment, pStb->comment); @@ -2122,6 +2122,34 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc colDataAppendNULL(pColInfo, numOfRows); } + char watermark[64 + VARSTR_HEADER_SIZE] = {0}; + sprintf(varDataVal(watermark), "%" PRId64 "a,%" PRId64 "a", pStb->watermark[0], pStb->watermark[1]); + varDataSetLen(watermark, strlen(varDataVal(watermark))); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)watermark, false); + + char maxDelay[64 + VARSTR_HEADER_SIZE] = {0}; + sprintf(varDataVal(maxDelay), "%" PRId64 "a,%" PRId64 "a", pStb->maxdelay[0], pStb->maxdelay[1]); + varDataSetLen(maxDelay, strlen(varDataVal(maxDelay))); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)maxDelay, false); + + char rollup[128 + VARSTR_HEADER_SIZE] = {0}; + int32_t rollupNum = (int32_t)taosArrayGetSize(pStb->pFuncs); + for (int32_t i = 0; i < rollupNum; ++i) { + char *funcName = taosArrayGet(pStb->pFuncs, i); + if (i) { + strcat(varDataVal(rollup), ", "); + } + strcat(varDataVal(rollup), funcName); + } + varDataSetLen(rollup, strlen(varDataVal(rollup))); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)rollup, false); + numOfRows++; sdbRelease(pSdb, pStb); } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index d77b39003a..3c3864b620 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -56,20 +56,22 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM sdbSetApplyInfo(pMnode->pSdb, cbMeta.index, cbMeta.term, cbMeta.lastConfigIndex); } - if (pMgmt->transId == transId) { + if (pMgmt->transId == transId && transId != 0) { if (pMgmt->errCode != 0) { mError("trans:%d, failed to propose since %s", transId, tstrerror(pMgmt->errCode)); } pMgmt->transId = 0; tsem_post(&pMgmt->syncSem); } else { +#if 1 + mError("trans:%d, invalid commit msg since trandId not match with %d", transId, pMgmt->transId); +#else STrans *pTrans = mndAcquireTrans(pMnode, transId); if (pTrans != NULL) { mndTransExecute(pMnode, pTrans); mndReleaseTrans(pMnode, pTrans); } -#if 0 - sdbWriteFile(pMnode->pSdb, SDB_WRITE_DELTA); + // sdbWriteFile(pMnode->pSdb, SDB_WRITE_DELTA); #endif } } @@ -199,6 +201,7 @@ int32_t mndInitSync(SMnode *pMnode) { } // decrease election timer + setPingTimerMS(pMgmt->sync, 5000); setElectTimerMS(pMgmt->sync, 600); setHeartbeatTimerMS(pMgmt->sync, 300); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 85f1ce6843..0b24b570a5 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -207,7 +207,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.buffer = pDb->cfg.buffer; createReq.pageSize = pDb->cfg.pageSize; createReq.pages = pDb->cfg.pages; - createReq.lastRowMem = pDb->cfg.lastRowMem; + createReq.cacheLastSize = pDb->cfg.cacheLastSize; createReq.daysPerFile = pDb->cfg.daysPerFile; createReq.daysToKeep0 = pDb->cfg.daysToKeep0; createReq.daysToKeep1 = pDb->cfg.daysToKeep1; @@ -219,7 +219,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.precision = pDb->cfg.precision; createReq.compression = pDb->cfg.compression; createReq.strict = pDb->cfg.strict; - createReq.cacheLastRow = pDb->cfg.cacheLastRow; + createReq.cacheLast = pDb->cfg.cacheLast; createReq.replica = pVgroup->replica; createReq.selfIndex = -1; createReq.hashBegin = pVgroup->hashBegin; @@ -277,7 +277,7 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_ alterReq.buffer = pDb->cfg.buffer; alterReq.pageSize = pDb->cfg.pageSize; alterReq.pages = pDb->cfg.pages; - alterReq.lastRowMem = pDb->cfg.lastRowMem; + alterReq.cacheLastSize = pDb->cfg.cacheLastSize; alterReq.daysPerFile = pDb->cfg.daysPerFile; alterReq.daysToKeep0 = pDb->cfg.daysToKeep0; alterReq.daysToKeep1 = pDb->cfg.daysToKeep1; @@ -285,7 +285,7 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_ alterReq.fsyncPeriod = pDb->cfg.fsyncPeriod; alterReq.walLevel = pDb->cfg.walLevel; alterReq.strict = pDb->cfg.strict; - alterReq.cacheLastRow = pDb->cfg.cacheLastRow; + alterReq.cacheLast = pDb->cfg.cacheLast; alterReq.replica = pVgroup->replica; for (int32_t v = 0; v < pVgroup->replica; ++v) { @@ -307,7 +307,7 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_ terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - contLen += +sizeof(SMsgHead); + contLen += sizeof(SMsgHead); void *pReq = taosMemoryMalloc(contLen); if (pReq == NULL) { @@ -742,8 +742,8 @@ int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDbInput, SVgObj *pVgroup) { int64_t vgroupMemroy = 0; if (pDb != NULL) { vgroupMemroy = (int64_t)pDb->cfg.buffer * 1024 * 1024 + (int64_t)pDb->cfg.pages * pDb->cfg.pageSize * 1024; - if (pDb->cfg.cacheLastRow > 0) { - vgroupMemroy += (int64_t)pDb->cfg.lastRowMem * 1024 * 1024; + if (pDb->cfg.cacheLast > 0) { + vgroupMemroy += (int64_t)pDb->cfg.cacheLastSize * 1024 * 1024; } } diff --git a/source/dnode/mnode/impl/test/db/db.cpp b/source/dnode/mnode/impl/test/db/db.cpp index a3d129c7c4..0fb8e9d530 100644 --- a/source/dnode/mnode/impl/test/db/db.cpp +++ b/source/dnode/mnode/impl/test/db/db.cpp @@ -50,7 +50,7 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; createReq.numOfStables = 0; createReq.numOfRetensions = 0; @@ -84,7 +84,7 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { alterdbReq.fsyncPeriod = 4000; alterdbReq.walLevel = 2; alterdbReq.strict = 1; - alterdbReq.cacheLastRow = 1; + alterdbReq.cacheLast = 1; alterdbReq.replications = 1; int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq); @@ -146,7 +146,7 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; createReq.numOfStables = 0; createReq.numOfRetensions = 0; diff --git a/source/dnode/mnode/impl/test/dnode/mdnode.cpp b/source/dnode/mnode/impl/test/dnode/mdnode.cpp index 0b42b28219..8e4e728416 100644 --- a/source/dnode/mnode/impl/test/dnode/mdnode.cpp +++ b/source/dnode/mnode/impl/test/dnode/mdnode.cpp @@ -288,7 +288,7 @@ TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; createReq.numOfStables = 0; createReq.numOfRetensions = 0; @@ -319,7 +319,7 @@ TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) { alterdbReq.fsyncPeriod = 4000; alterdbReq.walLevel = 2; alterdbReq.strict = 1; - alterdbReq.cacheLastRow = 1; + alterdbReq.cacheLast = 1; alterdbReq.replications = 3; int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq); @@ -345,7 +345,7 @@ TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) { alterdbReq.fsyncPeriod = 4000; alterdbReq.walLevel = 2; alterdbReq.strict = 1; - alterdbReq.cacheLastRow = 1; + alterdbReq.cacheLast = 1; alterdbReq.replications = 1; int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq); diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp index d795816f57..ce6954279f 100644 --- a/source/dnode/mnode/impl/test/sma/sma.cpp +++ b/source/dnode/mnode/impl/test/sma/sma.cpp @@ -55,7 +55,7 @@ void* MndTestSma::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/mnode/impl/test/stb/stb.cpp b/source/dnode/mnode/impl/test/stb/stb.cpp index 63bb1bf540..dfdd8f3a49 100644 --- a/source/dnode/mnode/impl/test/stb/stb.cpp +++ b/source/dnode/mnode/impl/test/stb/stb.cpp @@ -56,7 +56,7 @@ void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 433a0ab5cc..353cedf636 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -48,7 +48,7 @@ void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index 3b1a5fa3c5..d8b6964114 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -315,7 +315,7 @@ TEST_F(MndTestUser, 03_Alter_User) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index b42b0f2b44..9f32964fa9 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -51,6 +51,7 @@ void vnodeCleanup(); int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs); void vnodeDestroy(const char *path, STfs *pTfs); SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb); +void vnodePreClose(SVnode *pVnode); void vnodeClose(SVnode *pVnode); int32_t vnodeStart(SVnode *pVnode); @@ -136,11 +137,13 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader *pHandle); void *tsdbGetIdx(SMeta *pMeta); void *tsdbGetIvtIdx(SMeta *pMeta); -int32_t tsdbLastRowReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t *colId, int32_t numOfCols, - void **pReader); +int32_t tsdbLastRowReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t numOfCols, void **pReader); int32_t tsdbRetrieveLastRow(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds); int32_t tsdbLastrowReaderClose(void *pReader); -int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int64_t* suid); +int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid); + +void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity); +size_t tsdbCacheGetCapacity(SVnode *pVnode); // tq @@ -210,11 +213,13 @@ struct SVnodeCfg { int32_t vgId; char dbname[TSDB_DB_FNAME_LEN]; uint64_t dbId; + int32_t cacheLastSize; int32_t szPage; int32_t szCache; uint64_t szBuf; bool isHeap; bool isWeak; + int8_t cacheLast; int8_t isTsma; int8_t isRsma; int8_t hashMethod; diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h index d5b719dfb9..e767d94ebd 100644 --- a/source/dnode/vnode/src/inc/sma.h +++ b/source/dnode/vnode/src/inc/sma.h @@ -67,7 +67,6 @@ struct SRSmaStat { int64_t submitVer; int64_t refId; // shared by fetch tasks int8_t triggerStat; // shared by fetch tasks - int8_t runningStat; // for persistence task SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo; }; @@ -83,7 +82,6 @@ struct SSmaStat { #define SMA_RSMA_STAT(s) (&(s)->rsmaStat) #define RSMA_INFO_HASH(r) ((r)->rsmaInfoHash) #define RSMA_TRIGGER_STAT(r) (&(r)->triggerStat) -#define RSMA_RUNNING_STAT(r) (&(r)->runningStat) #define RSMA_REF_ID(r) ((r)->refId) #define RSMA_SUBMIT_VER(r) ((r)->submitVer) @@ -93,7 +91,7 @@ enum { TASK_TRIGGER_STAT_INACTIVE = 2, TASK_TRIGGER_STAT_PAUSED = 3, TASK_TRIGGER_STAT_CANCELLED = 4, - TASK_TRIGGER_STAT_FINISHED = 5, + TASK_TRIGGER_STAT_DROPPED = 5, }; void tdDestroySmaEnv(SSmaEnv *pSmaEnv); diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index 8abaac6dff..c62b7e95bf 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -89,8 +89,6 @@ typedef struct { STqExecTb execTb; STqExecDb execDb; }; - // TODO remove it - int64_t tsdbEndVer; } STqExecHandle; @@ -101,6 +99,8 @@ typedef struct { int32_t epoch; int8_t fetchMeta; + int64_t snapshotVer; + // TODO remove SWalReader* pWalReader; @@ -131,7 +131,7 @@ typedef struct { static STqMgmt tqMgmt = {0}; // tqRead -int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal* offset); +int64_t tqScan(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* offset); int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum); // tqExec diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index cce3da60cb..4df9f96514 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -32,39 +32,38 @@ extern "C" { #define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) // clang-format on -typedef struct TSDBROW TSDBROW; -typedef struct TABLEID TABLEID; -typedef struct TSDBKEY TSDBKEY; -typedef struct SDelData SDelData; -typedef struct SDelIdx SDelIdx; -typedef struct STbData STbData; -typedef struct SMemTable SMemTable; -typedef struct STbDataIter STbDataIter; -typedef struct STable STable; -typedef struct SMapData SMapData; -typedef struct SBlockIdx SBlockIdx; -typedef struct SBlock SBlock; -typedef struct SBlockStatis SBlockStatis; -typedef struct SAggrBlkCol SAggrBlkCol; -typedef struct SColData SColData; -typedef struct SBlockDataHdr SBlockDataHdr; -typedef struct SBlockData SBlockData; -typedef struct SDelFile SDelFile; -typedef struct STsdbCacheFile STsdbCacheFile; -typedef struct SHeadFile SHeadFile; -typedef struct SDataFile SDataFile; -typedef struct SLastFile SLastFile; -typedef struct SSmaFile SSmaFile; -typedef struct SDFileSet SDFileSet; -typedef struct SDataFWriter SDataFWriter; -typedef struct SDataFReader SDataFReader; -typedef struct SDelFWriter SDelFWriter; -typedef struct SDelFReader SDelFReader; -typedef struct SRowIter SRowIter; -typedef struct STsdbFS STsdbFS; -typedef struct SRowMerger SRowMerger; -typedef struct STsdbFSState STsdbFSState; -typedef struct STsdbSnapHdr STsdbSnapHdr; +typedef struct TSDBROW TSDBROW; +typedef struct TABLEID TABLEID; +typedef struct TSDBKEY TSDBKEY; +typedef struct SDelData SDelData; +typedef struct SDelIdx SDelIdx; +typedef struct STbData STbData; +typedef struct SMemTable SMemTable; +typedef struct STbDataIter STbDataIter; +typedef struct STable STable; +typedef struct SMapData SMapData; +typedef struct SBlockIdx SBlockIdx; +typedef struct SBlock SBlock; +typedef struct SBlockStatis SBlockStatis; +typedef struct SAggrBlkCol SAggrBlkCol; +typedef struct SColData SColData; +typedef struct SBlockDataHdr SBlockDataHdr; +typedef struct SBlockData SBlockData; +typedef struct SDelFile SDelFile; +typedef struct SHeadFile SHeadFile; +typedef struct SDataFile SDataFile; +typedef struct SLastFile SLastFile; +typedef struct SSmaFile SSmaFile; +typedef struct SDFileSet SDFileSet; +typedef struct SDataFWriter SDataFWriter; +typedef struct SDataFReader SDataFReader; +typedef struct SDelFWriter SDelFWriter; +typedef struct SDelFReader SDelFReader; +typedef struct SRowIter SRowIter; +typedef struct STsdbFS STsdbFS; +typedef struct SRowMerger SRowMerger; +typedef struct STsdbFSState STsdbFSState; +typedef struct STsdbSnapHdr STsdbSnapHdr; #define TSDB_MAX_SUBBLOCKS 8 #define TSDB_FHDR_SIZE 512 @@ -163,6 +162,7 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData); // other int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision); void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey); +int32_t tsdbFidLevel(int32_t fid, STsdbKeepCfg *pKeepCfg, int64_t now); int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline); void tsdbCalcColDataSMA(SColData *pColData, SColumnDataAgg *pColAgg); // tsdbMemTable ============================================================================================== @@ -200,6 +200,7 @@ int32_t tsdbFSRollback(STsdbFS *pFS); int32_t tsdbFSStateUpsertDelFile(STsdbFSState *pState, SDelFile *pDelFile); int32_t tsdbFSStateUpsertDFileSet(STsdbFSState *pState, SDFileSet *pSet); +void tsdbFSStateDeleteDFileSet(STsdbFSState *pState, int32_t fid); SDelFile *tsdbFSStateGetDelFile(STsdbFSState *pState); SDFileSet *tsdbFSStateGetDFileSet(STsdbFSState *pState, int32_t fid); // tsdbReaderWriter.c ============================================================================================== @@ -213,6 +214,7 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_ SBlockIdx *pBlockIdx, SBlock *pBlock, int8_t cmprAlg); SDFileSet *tsdbDataFWriterGetWSet(SDataFWriter *pWriter); +int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo); // SDataFReader int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet); int32_t tsdbDataFReaderClose(SDataFReader **ppReader); @@ -235,17 +237,26 @@ int32_t tsdbDelFReaderClose(SDelFReader **ppReader); int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, uint8_t **ppBuf); int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx, uint8_t **ppBuf); +#define TSDB_CACHE_NO(c) ((c).cacheLast == 0) +#define TSDB_CACHE_LAST_ROW(c) (((c).cacheLast & 1) > 0) +#define TSDB_CACHE_LAST(c) (((c).cacheLast & 2) > 0) + // tsdbCache int32_t tsdbOpenCache(STsdb *pTsdb); void tsdbCloseCache(SLRUCache *pCache); -int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row); +int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb); int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, STSRow *row, bool dup); int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h); +int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); +int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); +void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity); +size_t tsdbCacheGetCapacity(SVnode *pVnode); + int32_t tsdbCacheLastArray2Row(SArray *pLastArray, STSRow **ppRow, STSchema *pSchema); // structs ======================= diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 0c386babde..7b298ba830 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -122,6 +122,7 @@ int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepC int tsdbClose(STsdb** pTsdb); int32_t tsdbBegin(STsdb* pTsdb); int32_t tsdbCommit(STsdb* pTsdb); +int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now); int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg); int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, @@ -171,8 +172,9 @@ int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg); int32_t tdProcessTSmaInsert(SSma* pSma, int64_t indexUid, const char* msg); int64_t tdRSmaGetMaxSubmitVer(SSma* pSma, int8_t level); -int32_t tdProcessRSmaCreate(SVnode* pVnode, SVCreateStbReq* pReq); +int32_t tdProcessRSmaCreate(SSma* pSma, SVCreateStbReq* pReq); int32_t tdProcessRSmaSubmit(SSma* pSma, void* pMsg, int32_t inputType); +int32_t tdProcessRSmaDrop(SSma* pSma, SVDropStbReq* pReq); int32_t tdFetchTbUidList(SSma* pSma, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid); int32_t tdUpdateTbUidList(SSma* pSma, STbUidStore* pUidStore); void tdUidStoreDestory(STbUidStore* pStore); diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index db959a83b0..e1236c2853 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -147,6 +147,8 @@ int metaTbCursorNext(SMTbCursor *pTbCur) { return -1; } + tDecoderClear(&pTbCur->mr.coder); + metaGetTableEntryByVersion(&pTbCur->mr, *(int64_t *)pTbCur->pVal, *(tb_uid_t *)pTbCur->pKey); if (pTbCur->mr.me.type == TSDB_SUPER_TABLE) { continue; diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index 5eb9665326..2cf4fd51a9 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -254,26 +254,7 @@ static void tdDestroyRSmaStat(void *pRSmaStat) { // step 1: set rsma trigger stat cancelled atomic_store_8(RSMA_TRIGGER_STAT(pStat), TASK_TRIGGER_STAT_CANCELLED); - // step 2: wait the persistence thread to finish - int32_t nLoops = 0; - if (atomic_load_8(RSMA_RUNNING_STAT(pStat)) == 1) { - while (1) { - if (atomic_load_8(RSMA_TRIGGER_STAT(pStat)) == TASK_TRIGGER_STAT_FINISHED) { - smaDebug("vgId:%d, rsma persist task finished already", SMA_VID(pSma)); - break; - } else { - smaDebug("vgId:%d, rsma persist task not finished yet since rsma stat in %" PRIi8, SMA_VID(pSma), - atomic_load_8(RSMA_TRIGGER_STAT(pStat))); - } - ++nLoops; - if (nLoops > 1000) { - sched_yield(); - nLoops = 0; - } - } - } - - // step 3: destroy the rsma info and associated fetch tasks + // step 2: destroy the rsma info and associated fetch tasks // TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready. if (taosHashGetSize(RSMA_INFO_HASH(pStat)) > 0) { void *infoHash = taosHashIterate(RSMA_INFO_HASH(pStat), NULL); @@ -285,8 +266,8 @@ static void tdDestroyRSmaStat(void *pRSmaStat) { } taosHashCleanup(RSMA_INFO_HASH(pStat)); - // step 5: wait all triggered fetch tasks finished - nLoops = 0; + // step 3: wait all triggered fetch tasks finished + int32_t nLoops = 0; while (1) { if (T_REF_VAL_GET((SSmaStat *)pStat) == 0) { smaDebug("vgId:%d, rsma fetch tasks all finished", SMA_VID(pSma)); diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index efa2886e48..06ffb639de 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -37,8 +37,6 @@ static SRSmaInfo *tdGetRSmaInfoBySuid(SSma *pSma, int64_t suid); static int32_t tdRSmaFetchAndSubmitResult(SRSmaInfoItem *pItem, STSchema *pTSchema, int64_t suid, SRSmaStat *pStat, int8_t blkType); static void tdRSmaFetchTrigger(void *param, void *tmrId); -static void tdRSmaPersistTrigger(void *param, void *tmrId); -static void *tdRSmaPersistExec(void *param); static void tdRSmaQTaskInfoGetFName(int32_t vid, int64_t version, char *outputName); static int32_t tdRSmaQTaskInfoIterInit(SRSmaQTaskInfoIter *pIter, STFile *pTFile); @@ -67,9 +65,12 @@ struct SRSmaInfo { static SRSmaInfo *tdGetRSmaInfoByItem(SRSmaInfoItem *pItem) { // adapt accordingly if definition of SRSmaInfo update - int32_t rsmaInfoHeadLen = sizeof(int64_t) + sizeof(STSchema *); - ASSERT(pItem->level == 1 || pItem->level == 2); - return (SRSmaInfo *)POINTER_SHIFT(pItem, -sizeof(SRSmaInfoItem) * (pItem->level - 1) - rsmaInfoHeadLen); + SRSmaInfo *pResult = NULL; + int32_t rsmaInfoHeadLen = sizeof(int64_t) + sizeof(STSchema *); + ASSERT(pItem->level == TSDB_RETENTION_L1 || pItem->level == TSDB_RETENTION_L2); + pResult = (SRSmaInfo *)POINTER_SHIFT(pItem, -(sizeof(SRSmaInfoItem) * (pItem->level - 1) + rsmaInfoHeadLen)); + ASSERT(pResult->pTSchema->numOfCols > 1); + return pResult; } struct SRSmaQTaskInfoItem { @@ -278,7 +279,7 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat if (pItem->maxDelay > TSDB_MAX_ROLLUP_MAX_DELAY) { pItem->maxDelay = TSDB_MAX_ROLLUP_MAX_DELAY; } - pItem->level = (idx == 0 ? TSDB_RETENTION_L1 : TSDB_RETENTION_L2); + pItem->level = idx == 0 ? TSDB_RETENTION_L1 : TSDB_RETENTION_L2; smaInfo("vgId:%d table:%" PRIi64 " level:%" PRIi8 " maxdelay:%" PRIi64 " watermark:%" PRIi64 ", finally maxdelay:%" PRIi32, SMA_VID(pSma), pRSmaInfo->suid, idx + 1, param->maxdelay[idx], param->watermark[idx], pItem->maxDelay); @@ -375,20 +376,48 @@ _err: /** * @brief Check and init qTaskInfo_t, only applicable to stable with SRSmaParam currently * - * @param pVnode + * @param pSma * @param pReq * @return int32_t */ -int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) { - SSma *pSma = pVnode->pSma; +int32_t tdProcessRSmaCreate(SSma *pSma, SVCreateStbReq *pReq) { + SVnode *pVnode = pSma->pVnode; if (!pReq->rollup) { - smaTrace("vgId:%d, return directly since no rollup for stable %s %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid); + smaTrace("vgId:%d, not create rsma for stable %s %" PRIi64 " since no rollup in req", TD_VID(pVnode), pReq->name, + pReq->suid); + return TSDB_CODE_SUCCESS; + } + + if (!VND_IS_RSMA(pVnode)) { + smaTrace("vgId:%d, not create rsma for stable %s %" PRIi64 " since vnd is not rsma", TD_VID(pVnode), pReq->name, + pReq->suid); return TSDB_CODE_SUCCESS; } return tdProcessRSmaCreateImpl(pSma, &pReq->rsmaParam, pReq->suid, pReq->name); } +/** + * @brief drop cache for stb + * + * @param pSma + * @param pReq + * @return int32_t + */ +int32_t tdProcessRSmaDrop(SSma *pSma, SVDropStbReq *pReq) { + SVnode *pVnode = pSma->pVnode; + if (!VND_IS_RSMA(pVnode)) { + smaTrace("vgId:%d, not create rsma for stable %s %" PRIi64 " since vnd is not rsma", TD_VID(pVnode), pReq->name, + pReq->suid); + return TSDB_CODE_SUCCESS; + } + + + + smaDebug("vgId:%d, drop rsma for table %" PRIi64 " succeed", TD_VID(pVnode), pReq->suid); + return TSDB_CODE_SUCCESS; + } + /** * @brief store suid/[uids], prefer to use array and then hash * @@ -1174,123 +1203,6 @@ _err: return TSDB_CODE_FAILED; } -static void *tdRSmaPersistExec(void *param) { - setThreadName("rsma-task-persist"); - SRSmaStat *pRSmaStat = param; - SSma *pSma = pRSmaStat->pSma; - - int8_t triggerStat = atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat)); - - if (TASK_TRIGGER_STAT_CANCELLED == triggerStat || TASK_TRIGGER_STAT_PAUSED == triggerStat) { - goto _end; - } - - // execution - tdRSmaPersistExecImpl(pRSmaStat); - -_end: - if (TASK_TRIGGER_STAT_INACTIVE == atomic_val_compare_exchange_8(RSMA_TRIGGER_STAT(pRSmaStat), - TASK_TRIGGER_STAT_INACTIVE, - TASK_TRIGGER_STAT_ACTIVE)) { - smaDebug("vgId:%d, rsma persist task is active again", SMA_VID(pSma)); - } else if (TASK_TRIGGER_STAT_CANCELLED == atomic_val_compare_exchange_8(RSMA_TRIGGER_STAT(pRSmaStat), - TASK_TRIGGER_STAT_CANCELLED, - TASK_TRIGGER_STAT_FINISHED)) { - smaDebug("vgId:%d, rsma persist task is cancelled", SMA_VID(pSma)); - } else { - smaWarn("vgId:%d, rsma persist task in stat %" PRIi8, SMA_VID(pSma), atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat))); - } - - atomic_store_8(RSMA_RUNNING_STAT(pRSmaStat), 0); - smaDebug("vgId:%d, release rsetId rsetId:%" PRIi64 " refId:%d", SMA_VID(pSma), smaMgmt.rsetId, pRSmaStat->refId); - tdReleaseSmaRef(smaMgmt.rsetId, pRSmaStat->refId, __func__, __LINE__); - taosThreadExit(NULL); - return NULL; -} - -static void tdRSmaPersistTask(SRSmaStat *pRSmaStat) { - TdThreadAttr thAttr; - taosThreadAttrInit(&thAttr); - taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_DETACHED); - TdThread tid; - - if (taosThreadCreate(&tid, &thAttr, tdRSmaPersistExec, pRSmaStat) != 0) { - if (TASK_TRIGGER_STAT_INACTIVE == atomic_val_compare_exchange_8(RSMA_TRIGGER_STAT(pRSmaStat), - TASK_TRIGGER_STAT_INACTIVE, - TASK_TRIGGER_STAT_ACTIVE)) { - smaDebug("vgId:%d, persist task is active again", SMA_VID(pRSmaStat->pSma)); - } else if (TASK_TRIGGER_STAT_CANCELLED == atomic_val_compare_exchange_8(RSMA_TRIGGER_STAT(pRSmaStat), - TASK_TRIGGER_STAT_CANCELLED, - TASK_TRIGGER_STAT_FINISHED)) { - smaDebug("vgId:%d, persist task is cancelled and set finished", SMA_VID(pRSmaStat->pSma)); - } else { - smaWarn("vgId:%d, persist task in abnormal stat %" PRIi8, SMA_VID(pRSmaStat->pSma), - atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat))); - } - atomic_store_8(RSMA_RUNNING_STAT(pRSmaStat), 0); - smaDebug("vgId:%d, release rsetId rsetId:%" PRIi64 " refId:%d)", SMA_VID(pRSmaStat->pSma), smaMgmt.rsetId, - pRSmaStat->refId); - tdReleaseSmaRef(smaMgmt.rsetId, pRSmaStat->refId, __func__, __LINE__); - } - - taosThreadAttrDestroy(&thAttr); -} - -/** - * @brief trigger to persist rsma qTaskInfo - * - * @param param - * @param tmrId - */ -static void tdRSmaPersistTrigger(void *param, void *tmrId) { - SRSmaStat *rsmaStat = param; - SRSmaStat *pRSmaStat = (SRSmaStat *)taosAcquireRef(smaMgmt.rsetId, rsmaStat->refId); - ASSERT(0); - if (!pRSmaStat) { - smaDebug("rsma persistence task not start since already destroyed"); - return; - } - - int8_t tmrStat = - atomic_val_compare_exchange_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_ACTIVE, TASK_TRIGGER_STAT_INACTIVE); - switch (tmrStat) { - case TASK_TRIGGER_STAT_ACTIVE: { - atomic_store_8(RSMA_RUNNING_STAT(pRSmaStat), 1); - if (TASK_TRIGGER_STAT_CANCELLED != atomic_val_compare_exchange_8(RSMA_TRIGGER_STAT(pRSmaStat), - TASK_TRIGGER_STAT_CANCELLED, - TASK_TRIGGER_STAT_FINISHED)) { - smaDebug("vgId:%d, rsma persistence start since active", SMA_VID(pRSmaStat->pSma)); - - // start persist task - tdRSmaPersistTask(pRSmaStat); - - // taosTmrReset(tdRSmaPersistTrigger, 5000, pRSmaStat, pRSmaStat->tmrHandle, - // RSMA_TMR_ID(pRSmaStat)); - } else { - atomic_store_8(RSMA_RUNNING_STAT(pRSmaStat), 0); - } - return; - } break; - case TASK_TRIGGER_STAT_CANCELLED: { - atomic_store_8(RSMA_TRIGGER_STAT(pRSmaStat), TASK_TRIGGER_STAT_FINISHED); - smaDebug("rsma persistence not start since cancelled and finished"); - } break; - case TASK_TRIGGER_STAT_PAUSED: { - smaDebug("rsma persistence not start since paused"); - } break; - case TASK_TRIGGER_STAT_INACTIVE: { - smaDebug("rsma persistence not start since inactive"); - } break; - case TASK_TRIGGER_STAT_INIT: { - smaDebug("rsma persistence not start since init"); - } break; - default: { - smaWarn("rsma persistence not start since unknown stat %" PRIi8, tmrStat); - } break; - } - taosReleaseRef(smaMgmt.rsetId, rsmaStat->refId); -} - /** * @brief trigger to get rsma result * @@ -1314,8 +1226,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { int8_t rsmaTriggerStat = atomic_load_8(RSMA_TRIGGER_STAT(pStat)); switch (rsmaTriggerStat) { case TASK_TRIGGER_STAT_PAUSED: - case TASK_TRIGGER_STAT_CANCELLED: - case TASK_TRIGGER_STAT_FINISHED: { + case TASK_TRIGGER_STAT_CANCELLED: { tdReleaseSmaRef(smaMgmt.rsetId, pItem->refId, __func__, __LINE__); smaDebug("vgId:%d, not fetch rsma level %" PRIi8 " data since stat is %" PRIi8 ", rsetId rsetId:%" PRIi64 " refId:%d", @@ -1328,8 +1239,6 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { SRSmaInfo *pRSmaInfo = tdGetRSmaInfoByItem(pItem); - ASSERT(pRSmaInfo->suid > 0); - int8_t fetchTriggerStat = atomic_val_compare_exchange_8(&pItem->triggerStat, TASK_TRIGGER_STAT_ACTIVE, TASK_TRIGGER_STAT_INACTIVE); switch (fetchTriggerStat) { diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 3873073f03..df80a4c218 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -244,6 +244,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { STqOffsetVal reqOffset = pReq->reqOffset; STqOffsetVal fetchOffsetNew; + // todo + workerId = 0; + // 1.find handle STqHandle* pHandle = taosHashGet(pTq->handles, pReq->subKey, strlen(pReq->subKey)); /*ASSERT(pHandle);*/ @@ -284,7 +287,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { fetchOffsetNew = pOffset->val; char formatBuf[80]; tFormatOffset(formatBuf, 80, &fetchOffsetNew); - tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, offset reset to %s", consumerId, pHandle->subKey, formatBuf); + tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, vg %d, offset reset to %s", consumerId, pHandle->subKey, + TD_VID(pTq->pVnode), formatBuf); } else { if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) { if (pReq->useSnapshot && pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { @@ -299,8 +303,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } } else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) { tqOffsetResetToLog(&dataRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal)); - tqDebug("tmq poll: consumer %ld, subkey %s, offset reset to %ld", consumerId, pHandle->subKey, - dataRsp.rspOffset.version); + tqDebug("tmq poll: consumer %ld, subkey %s, vg %d, offset reset to %ld", consumerId, pHandle->subKey, + TD_VID(pTq->pVnode), dataRsp.rspOffset.version); if (tqSendDataRsp(pTq, pMsg, pReq, &dataRsp) < 0) { code = -1; } @@ -318,10 +322,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { // 3.query if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - if (fetchOffsetNew.type == TMQ_OFFSET__LOG) { - fetchOffsetNew.version++; - } - if (tqScan(pTq, &pHandle->execHandle, &dataRsp, &fetchOffsetNew) < 0) { + /*if (fetchOffsetNew.type == TMQ_OFFSET__LOG) {*/ + /*fetchOffsetNew.version++;*/ + /*}*/ + if (tqScan(pTq, pHandle, &dataRsp, &fetchOffsetNew) < 0) { ASSERT(0); code = -1; goto OVER; @@ -394,7 +398,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } else { ASSERT(pHandle->fetchMeta); ASSERT(IS_META_MSG(pHead->msgType)); - tqInfo("fetch meta msg, ver:%" PRId64 ", type:%d", pHead->version, pHead->msgType); + tqDebug("fetch meta msg, ver:%" PRId64 ", type:%d", pHead->version, pHead->msgType); SMqMetaRsp metaRsp = {0}; /*metaRsp.reqOffset = pReq->reqOffset.version;*/ /*metaRsp.rspOffset = fetchVer;*/ @@ -480,30 +484,28 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { pHandle->fetchMeta = req.withMeta; pHandle->pWalReader = walOpenReader(pTq->pVnode->pWal, NULL); - /*for (int32_t i = 0; i < 5; i++) {*/ - /*pHandle->execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode);*/ - /*}*/ + + // TODO version should be assigned in preprocess int64_t ver = walGetCommittedVer(pTq->pVnode->pWal); if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { pHandle->execHandle.execCol.qmsg = req.qmsg; + pHandle->snapshotVer = ver; req.qmsg = NULL; for (int32_t i = 0; i < 5; i++) { SReadHandle handle = { - .tqReader = pHandle->execHandle.pExecReader[i], .meta = pTq->pVnode->pMeta, .vnode = pTq->pVnode, .initTableReader = true, .initTqReader = true, .version = ver, }; - pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle); + pHandle->execHandle.execCol.task[i] = qCreateQueueExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle); ASSERT(pHandle->execHandle.execCol.task[i]); void* scanner = NULL; qExtractStreamScanner(pHandle->execHandle.execCol.task[i], &scanner); ASSERT(scanner); pHandle->execHandle.pExecReader[i] = qExtractReaderFromStreamScanner(scanner); ASSERT(pHandle->execHandle.pExecReader[i]); - pHandle->execHandle.tsdbEndVer = ver; } } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) { for (int32_t i = 0; i < 5; i++) { diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c index 54e46e7b9a..0bdbe82b77 100644 --- a/source/dnode/vnode/src/tq/tqExec.c +++ b/source/dnode/vnode/src/tq/tqExec.c @@ -59,13 +59,13 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, SMqDataRsp* pRsp) { return 0; } -int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffsetVal* pOffset) { - qTaskInfo_t task = pExec->execCol.task[0]; +int64_t tqScan(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset) { + const STqExecHandle* pExec = &pHandle->execHandle; + qTaskInfo_t task = pExec->execCol.task[0]; if (qStreamPrepareScan(task, pOffset) < 0) { ASSERT(pOffset->type == TMQ_OFFSET__LOG); pRsp->rspOffset = *pOffset; - pRsp->rspOffset.version--; return 0; } @@ -73,9 +73,11 @@ int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffset while (1) { SSDataBlock* pDataBlock = NULL; uint64_t ts = 0; + tqDebug("task start to execute"); if (qExecTask(task, &pDataBlock, &ts) < 0) { ASSERT(0); } + tqDebug("task execute end, get %p", pDataBlock); if (pDataBlock != NULL) { tqAddBlockDataToRsp(pDataBlock, pRsp); @@ -97,7 +99,7 @@ int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffset } if (pRsp->blockNum == 0 && pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) { - tqOffsetResetToLog(pOffset, pExec->tsdbEndVer + 1); + tqOffsetResetToLog(pOffset, pHandle->snapshotVer + 1); qStreamPrepareScan(task, pOffset); continue; } @@ -116,7 +118,7 @@ int64_t tqScan(STQ* pTq, const STqExecHandle* pExec, SMqDataRsp* pRsp, STqOffset if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) { ASSERT(pRsp->rspOffset.version + 1 >= pRsp->reqOffset.version); } - + tqDebug("task exec exited"); break; } diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index 67fa4ed166..e6df58696d 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -19,6 +19,7 @@ static int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle) { if (tStartEncode(pEncoder) < 0) return -1; if (tEncodeCStr(pEncoder, pHandle->subKey) < 0) return -1; if (tEncodeI64(pEncoder, pHandle->consumerId) < 0) return -1; + if (tEncodeI64(pEncoder, pHandle->snapshotVer) < 0) return -1; if (tEncodeI32(pEncoder, pHandle->epoch) < 0) return -1; if (tEncodeI8(pEncoder, pHandle->execHandle.subType) < 0) return -1; if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { @@ -32,6 +33,7 @@ static int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) { if (tStartDecode(pDecoder) < 0) return -1; if (tDecodeCStrTo(pDecoder, pHandle->subKey) < 0) return -1; if (tDecodeI64(pDecoder, &pHandle->consumerId) < 0) return -1; + if (tDecodeI64(pDecoder, &pHandle->snapshotVer) < 0) return -1; if (tDecodeI32(pDecoder, &pHandle->epoch) < 0) return -1; if (tDecodeI8(pDecoder, &pHandle->execHandle.subType) < 0) return -1; if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { @@ -78,19 +80,25 @@ int32_t tqMetaOpen(STQ* pTq) { tDecoderInit(&decoder, (uint8_t*)pVal, vLen); tDecodeSTqHandle(&decoder, &handle); handle.pWalReader = walOpenReader(pTq->pVnode->pWal, NULL); - for (int32_t i = 0; i < 5; i++) { - handle.execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode); - } + /*for (int32_t i = 0; i < 5; i++) {*/ + /*handle.execHandle.pExecReader[i] = tqOpenReader(pTq->pVnode);*/ + /*}*/ if (handle.execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { for (int32_t i = 0; i < 5; i++) { SReadHandle reader = { - .tqReader = handle.execHandle.pExecReader[i], .meta = pTq->pVnode->pMeta, - .pMsgCb = &pTq->pVnode->msgCb, .vnode = pTq->pVnode, + .initTableReader = true, + .initTqReader = true, + .version = handle.snapshotVer, }; - handle.execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(handle.execHandle.execCol.qmsg, &reader); + handle.execHandle.execCol.task[i] = qCreateQueueExecTaskInfo(handle.execHandle.execCol.qmsg, &reader); ASSERT(handle.execHandle.execCol.task[i]); + void* scanner = NULL; + qExtractStreamScanner(handle.execHandle.execCol.task[i], &scanner); + ASSERT(scanner); + handle.execHandle.pExecReader[i] = qExtractReaderFromStreamScanner(scanner); + ASSERT(handle.execHandle.pExecReader[i]); } } else { handle.execHandle.execDb.pFilterOutTbUid = diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 0c5f851d97..605f4bf3d5 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -15,11 +15,15 @@ #include "tsdb.h" +typedef struct { + TSKEY ts; + SColVal colVal; +} SLastCol; + int32_t tsdbOpenCache(STsdb *pTsdb) { int32_t code = 0; SLRUCache *pCache = NULL; - // TODO: get cfg from vnode config: pTsdb->pVnode->config.lruCapacity - size_t cfgCapacity = 1024 * 1024; + size_t cfgCapacity = pTsdb->pVnode->config.cacheLastSize * 1024 * 1024; pCache = taosLRUCacheInit(cfgCapacity, -1, .5); if (pCache == NULL) { @@ -61,10 +65,11 @@ static void deleteTableCacheLastrow(const void *key, size_t keyLen, void *value) static void deleteTableCacheLast(const void *key, size_t keyLen, void *value) { taosArrayDestroy(value); } -static int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { +int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { int32_t code = 0; - char key[32] = {0}; - int keyLen = 0; + + char key[32] = {0}; + int keyLen = 0; // getTableCacheKey(uid, "lr", key, &keyLen); getTableCacheKey(uid, 0, key, &keyLen); @@ -83,18 +88,79 @@ static int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKe return code; } -static int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { +int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { int32_t code = 0; - char key[32] = {0}; - int keyLen = 0; + + char key[32] = {0}; + int keyLen = 0; // getTableCacheKey(uid, "l", key, &keyLen); getTableCacheKey(uid, 1, key, &keyLen); LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); if (h) { - // clear last cache anyway, no matter where eKey ends. - taosLRUCacheRelease(pCache, h, true); + SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); + bool invalidate = false; + int16_t nCol = taosArrayGetSize(pLast); + for (int16_t iCol = 0; iCol < nCol; ++iCol) { + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (eKey >= tTsVal->ts) { + invalidate = true; + break; + } + } + + if (invalidate) { + taosLRUCacheRelease(pCache, h, true); + } else { + taosLRUCacheRelease(pCache, h, false); + } + // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); + } + + return code; +} + +int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + // getTableCacheKey(uid, "lr", key, &keyLen); + getTableCacheKey(uid, 0, key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + STSRow *pRow = (STSRow *)taosLRUCacheValue(pCache, h); + if (pRow->ts <= eKey) { + taosLRUCacheRelease(pCache, h, true); + } else { + taosLRUCacheRelease(pCache, h, false); + } + + // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); + } + + // getTableCacheKey(uid, "l", key, &keyLen); + getTableCacheKey(uid, 1, key, &keyLen); + h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); + bool invalidate = false; + int16_t nCol = taosArrayGetSize(pLast); + + for (int16_t iCol = 0; iCol < nCol; ++iCol) { + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (eKey >= tTsVal->ts) { + invalidate = true; + break; + } + } + + if (invalidate) { + taosLRUCacheRelease(pCache, h, true); + } else { + taosLRUCacheRelease(pCache, h, false); + } // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); } @@ -173,20 +239,59 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST return code; } -int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row) { +int32_t tsdbCacheInsertLast(SLRUCache *pCache, tb_uid_t uid, STSRow *row, STsdb *pTsdb) { int32_t code = 0; STSRow *cacheRow = NULL; char key[32] = {0}; int keyLen = 0; - ((void)(row)); + // ((void)(row)); // getTableCacheKey(uid, "l", key, &keyLen); getTableCacheKey(uid, 1, key, &keyLen); LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); if (h) { + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + TSKEY keyTs = row->ts; + bool invalidate = false; + + SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); + int16_t nCol = taosArrayGetSize(pLast); + int16_t iCol = 0; + + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (keyTs > tTsVal->ts) { + STColumn *pTColumn = &pTSchema->columns[0]; + SColVal tColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = keyTs}); + + taosArraySet(pLast, iCol, &(SLastCol){.ts = keyTs, .colVal = tColVal}); + } + + for (++iCol; iCol < nCol; ++iCol) { + SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); + if (keyTs >= tTsVal->ts) { + SColVal *tColVal = &tTsVal->colVal; + + SColVal colVal = {0}; + tTSRowGetVal(row, pTSchema, iCol, &colVal); + if (colVal.isNone || colVal.isNull) { + if (keyTs == tTsVal->ts && !tColVal->isNone && !tColVal->isNull) { + invalidate = true; + + break; + } + } else { + taosArraySet(pLast, iCol, &(SLastCol){.ts = keyTs, .colVal = colVal}); + } + } + } + + taosMemoryFreeClear(pTSchema); + + taosLRUCacheRelease(pCache, h, invalidate); + // clear last cache anyway, lazy load when get last lookup - taosLRUCacheRelease(pCache, h, true); + // taosLRUCacheRelease(pCache, h, true); } return code; @@ -361,12 +466,13 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) { case SFSNEXTROW_FS: state->aDFileSet = state->pTsdb->fs->cState->aDFileSet; state->nFileSet = taosArrayGetSize(state->aDFileSet); - state->iFileSet = state->nFileSet - 1; + state->iFileSet = state->nFileSet; state->pBlockData = NULL; case SFSNEXTROW_FILESET: { SDFileSet *pFileSet = NULL; + _next_fileset: if (--state->iFileSet >= 0) { pFileSet = (SDFileSet *)taosArrayGet(state->aDFileSet, state->iFileSet); } else { @@ -403,6 +509,10 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) { state->pBlockIdx = taosArraySearch(state->aBlockIdx, state->pBlockIdxExp, tCmprBlockIdx, TD_EQ); if (code) goto _err; + if (!state->pBlockIdx) { + goto _next_fileset; + } + tMapDataReset(&state->blockMap); code = tsdbReadBlock(state->pDataFReader, state->pBlockIdx, &state->blockMap, NULL); /* code = tsdbReadBlock(state->pDataFReader, &state->blockIdx, &state->blockMap, NULL); */ @@ -516,12 +626,46 @@ typedef struct SMemNextRowIter { SMEMNEXTROWSTATES state; STbData *pMem; // [input] STbDataIter iter; // mem buffer skip list iterator + // bool iterOpened; + // TSDBROW *curRow; } SMemNextRowIter; static int32_t getNextRowFromMem(void *iter, TSDBROW **ppRow) { + // static int32_t getNextRowFromMem(void *iter, SArray *pRowArray) { SMemNextRowIter *state = (SMemNextRowIter *)iter; int32_t code = 0; + /* + if (!state->iterOpened) { + if (state->pMem != NULL) { + tsdbTbDataIterOpen(state->pMem, NULL, 1, &state->iter); + state->iterOpened = true; + + TSDBROW *pMemRow = tsdbTbDataIterGet(&state->iter); + if (pMemRow) { + state->curRow = pMemRow; + } else { + return code; + } + } else { + return code; + } + } + + taosArrayPush(pRowArray, state->curRow); + while (tsdbTbDataIterNext(&state->iter)) { + TSDBROW *row = tsdbTbDataIterGet(&state->iter); + + if (TSDBROW_TS(row) < TSDBROW_TS(state->curRow)) { + state->curRow = row; + break; + } else { + taosArrayPush(pRowArray, row); + } + } + + return code; + */ switch (state->state) { case SMEMNEXTROW_ENTER: { if (state->pMem != NULL) { @@ -599,7 +743,7 @@ _exit: return code; } -static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int *iSkyline) { +static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int64_t *iSkyline) { bool deleted = false; while (*iSkyline > 0) { TSDBKEY *pItemBack = (TSDBKEY *)taosArrayGet(pSkyline, *iSkyline); @@ -626,9 +770,11 @@ static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int *iSkyline) { } typedef int32_t (*_next_row_fn_t)(void *iter, TSDBROW **ppRow); +// typedef int32_t (*_next_row_fn_t)(void *iter, SArray *pRowArray); typedef int32_t (*_next_row_clear_fn_t)(void *iter); -typedef struct TsdbNextRowState { +// typedef struct TsdbNextRowState { +typedef struct { TSDBROW *pRow; bool stop; bool next; @@ -637,6 +783,388 @@ typedef struct TsdbNextRowState { _next_row_clear_fn_t nextRowClearFn; } TsdbNextRowState; +typedef struct { + // STsdb *pTsdb; + SArray *pSkyline; + int64_t iSkyline; + + SBlockIdx idx; + SMemNextRowIter memState; + SMemNextRowIter imemState; + SFSNextRowIter fsState; + TSDBROW memRow, imemRow, fsRow; + + TsdbNextRowState input[3]; +} CacheNextRowIter; + +static int32_t nextRowIterOpen(CacheNextRowIter *pIter, tb_uid_t uid, STsdb *pTsdb) { + int code = 0; + + tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + STbData *pMem = NULL; + if (pTsdb->mem) { + tsdbGetTbDataFromMemTable(pTsdb->mem, suid, uid, &pMem); + } + + STbData *pIMem = NULL; + if (pTsdb->imem) { + tsdbGetTbDataFromMemTable(pTsdb->imem, suid, uid, &pIMem); + } + + pIter->pSkyline = taosArrayInit(32, sizeof(TSDBKEY)); + + SDelIdx delIdx; + + SDelFile *pDelFile = tsdbFSStateGetDelFile(pTsdb->fs->cState); + if (pDelFile) { + SDelFReader *pDelFReader; + + code = tsdbDelFReaderOpen(&pDelFReader, pDelFile, pTsdb, NULL); + if (code) goto _err; + + code = getTableDelIdx(pDelFReader, suid, uid, &delIdx); + if (code) goto _err; + + code = getTableDelSkyline(pMem, pIMem, pDelFReader, &delIdx, pIter->pSkyline); + if (code) goto _err; + + tsdbDelFReaderClose(&pDelFReader); + } else { + code = getTableDelSkyline(pMem, pIMem, NULL, NULL, pIter->pSkyline); + if (code) goto _err; + } + + pIter->iSkyline = taosArrayGetSize(pIter->pSkyline) - 1; + + pIter->idx = (SBlockIdx){.suid = suid, .uid = uid}; + + pIter->fsState.state = SFSNEXTROW_FS; + pIter->fsState.pTsdb = pTsdb; + pIter->fsState.pBlockIdxExp = &pIter->idx; + + pIter->input[0] = (TsdbNextRowState){&pIter->memRow, true, false, &pIter->memState, getNextRowFromMem, NULL}; + pIter->input[1] = (TsdbNextRowState){&pIter->imemRow, true, false, &pIter->imemState, getNextRowFromMem, NULL}; + pIter->input[2] = + (TsdbNextRowState){&pIter->fsRow, false, true, &pIter->fsState, getNextRowFromFS, clearNextRowFromFS}; + + if (pMem) { + pIter->memState.pMem = pMem; + pIter->memState.state = SMEMNEXTROW_ENTER; + pIter->input[0].stop = false; + pIter->input[0].next = true; + } + + if (pIMem) { + pIter->imemState.pMem = pIMem; + pIter->imemState.state = SMEMNEXTROW_ENTER; + pIter->input[1].stop = false; + pIter->input[1].next = true; + } + + return code; +_err: + return code; +} + +static int32_t nextRowIterClose(CacheNextRowIter *pIter) { + int code = 0; + + for (int i = 0; i < 3; ++i) { + if (pIter->input[i].nextRowClearFn) { + pIter->input[i].nextRowClearFn(pIter->input[i].iter); + } + } + + if (pIter->pSkyline) { + taosArrayDestroy(pIter->pSkyline); + } + + return code; +_err: + return code; +} + +// iterate next row non deleted backward ts, version (from high to low) +static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow) { + int code = 0; + + for (int i = 0; i < 3; ++i) { + if (pIter->input[i].next && !pIter->input[i].stop) { + code = pIter->input[i].nextRowFn(pIter->input[i].iter, &pIter->input[i].pRow); + if (code) goto _err; + + if (pIter->input[i].pRow == NULL) { + pIter->input[i].stop = true; + pIter->input[i].next = false; + } + } + } + + if (pIter->input[0].stop && pIter->input[1].stop && pIter->input[2].stop) { + *ppRow = NULL; + return code; + } + + // select maxpoint(s) from mem, imem, fs + TSDBROW *max[3] = {0}; + int iMax[3] = {-1, -1, -1}; + int nMax = 0; + TSKEY maxKey = TSKEY_MIN; + + for (int i = 0; i < 3; ++i) { + if (!pIter->input[i].stop && pIter->input[i].pRow != NULL) { + TSDBKEY key = TSDBROW_KEY(pIter->input[i].pRow); + + // merging & deduplicating on client side + if (maxKey <= key.ts) { + if (maxKey < key.ts) { + nMax = 0; + maxKey = key.ts; + } + + iMax[nMax] = i; + max[nMax++] = pIter->input[i].pRow; + } + } + } + + // delete detection + TSDBROW *merge[3] = {0}; + int iMerge[3] = {-1, -1, -1}; + int nMerge = 0; + for (int i = 0; i < nMax; ++i) { + TSDBKEY maxKey = TSDBROW_KEY(max[i]); + + bool deleted = tsdbKeyDeleted(&maxKey, pIter->pSkyline, &pIter->iSkyline); + if (!deleted) { + iMerge[nMerge] = iMax[i]; + merge[nMerge++] = max[i]; + } + + pIter->input[iMax[i]].next = deleted; + } + + if (nMerge > 0) { + pIter->input[iMerge[0]].next = true; + + *ppRow = merge[0]; + } else { + *ppRow = NULL; + } + + return code; +_err: + return code; +} + +static int32_t mergeLastRow2(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRow) { + int32_t code = 0; + + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + int16_t nCol = pTSchema->numOfCols; + int16_t iCol = 0; + int16_t noneCol = 0; + bool setNoneCol = false; + SArray *pColArray = taosArrayInit(nCol, sizeof(SColVal)); + SColVal *pColVal = &(SColVal){0}; + + // tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + TSKEY lastRowTs = TSKEY_MAX; + + CacheNextRowIter iter = {0}; + nextRowIterOpen(&iter, uid, pTsdb); + + do { + TSDBROW *pRow = NULL; + nextRowIterGet(&iter, &pRow); + + if (!pRow) { + break; + } + + if (lastRowTs == TSKEY_MAX) { + lastRowTs = TSDBROW_TS(pRow); + STColumn *pTColumn = &pTSchema->columns[0]; + + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = lastRowTs}); + if (taosArrayPush(pColArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + for (iCol = 1; iCol < nCol; ++iCol) { + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + + if (taosArrayPush(pColArray, pColVal) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + if (pColVal->isNone && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + if (!setNoneCol) { + // goto build the result ts row + break; + } else { + continue; + } + } + + if ((TSDBROW_TS(pRow) < lastRowTs)) { + // goto build the result ts row + break; + } + + // merge into pColArray + setNoneCol = false; + for (iCol = noneCol; iCol < nCol; ++iCol) { + // high version's column value + SColVal *tColVal = (SColVal *)taosArrayGet(pColArray, iCol); + + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + if (tColVal->isNone && !pColVal->isNone) { + taosArraySet(pColArray, iCol, pColVal); + } else if (tColVal->isNone && pColVal->isNone && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + } while (setNoneCol); + + // build the result ts row here + *dup = false; + if (taosArrayGetSize(pColArray) == nCol) { + code = tdSTSRowNew(pColArray, pTSchema, ppRow); + if (code) goto _err; + } else { + *ppRow = NULL; + } + + nextRowIterClose(&iter); + taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; + +_err: + nextRowIterClose(&iter); + taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; +} + +static int32_t mergeLast2(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { + int32_t code = 0; + + STSchema *pTSchema = metaGetTbTSchema(pTsdb->pVnode->pMeta, uid, -1); + int16_t nCol = pTSchema->numOfCols; + int16_t iCol = 0; + int16_t noneCol = 0; + bool setNoneCol = false; + SArray *pColArray = taosArrayInit(nCol, sizeof(SLastCol)); + SColVal *pColVal = &(SColVal){0}; + + // tb_uid_t suid = getTableSuidByUid(uid, pTsdb); + + TSKEY lastRowTs = TSKEY_MAX; + + CacheNextRowIter iter = {0}; + nextRowIterOpen(&iter, uid, pTsdb); + + do { + TSDBROW *pRow = NULL; + nextRowIterGet(&iter, &pRow); + + if (!pRow) { + break; + } + + TSKEY rowTs = TSDBROW_TS(pRow); + + if (lastRowTs == TSKEY_MAX) { + lastRowTs = rowTs; + STColumn *pTColumn = &pTSchema->columns[0]; + + *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.ts = lastRowTs}); + if (taosArrayPush(pColArray, &(SLastCol){.ts = lastRowTs, .colVal = *pColVal}) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + for (iCol = 1; iCol < nCol; ++iCol) { + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + + if (taosArrayPush(pColArray, &(SLastCol){.ts = lastRowTs, .colVal = *pColVal}) == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + if ((pColVal->isNone || pColVal->isNull) && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + if (!setNoneCol) { + // goto build the result ts row + break; + } else { + continue; + } + } + /* + if ((TSDBROW_TS(pRow) < lastRowTs)) { + // goto build the result ts row + break; + } + */ + // merge into pColArray + setNoneCol = false; + for (iCol = noneCol; iCol < nCol; ++iCol) { + // high version's column value + SColVal *tColVal = (SColVal *)taosArrayGet(pColArray, iCol); + + tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal); + if ((tColVal->isNone || tColVal->isNull) && (!pColVal->isNone && !pColVal->isNull)) { + taosArraySet(pColArray, iCol, &(SLastCol){.ts = rowTs, .colVal = *pColVal}); + //} else if (tColVal->isNone && pColVal->isNone && !setNoneCol) { + } else if ((tColVal->isNone || tColVal->isNull) && (pColVal->isNone || pColVal->isNull) && !setNoneCol) { + noneCol = iCol; + setNoneCol = true; + } + } + } while (setNoneCol); + + // build the result ts row here + //*dup = false; + if (taosArrayGetSize(pColArray) <= 0) { + *ppLastArray = NULL; + taosArrayDestroy(pColArray); + } else { + *ppLastArray = pColArray; + } + /* if (taosArrayGetSize(pColArray) == nCol) { + code = tdSTSRowNew(pColArray, pTSchema, ppRow); + if (code) goto _err; + } else { + *ppRow = NULL; + }*/ + + nextRowIterClose(&iter); + // taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; + +_err: + nextRowIterClose(&iter); + // taosArrayDestroy(pColArray); + taosMemoryFreeClear(pTSchema); + return code; +} + static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRow) { int32_t code = 0; SArray *pSkyline = NULL; @@ -682,7 +1210,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo if (code) goto _err; } - int iSkyline = taosArrayGetSize(pSkyline) - 1; + int64_t iSkyline = taosArrayGetSize(pSkyline) - 1; SBlockIdx idx = {.suid = suid, .uid = uid}; @@ -719,12 +1247,14 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo do { for (int i = 0; i < 3; ++i) { if (input[i].next && !input[i].stop) { - code = input[i].nextRowFn(input[i].iter, &input[i].pRow); - if (code) goto _err; - if (input[i].pRow == NULL) { - input[i].stop = true; - input[i].next = false; + code = input[i].nextRowFn(input[i].iter, &input[i].pRow); + if (code) goto _err; + + if (input[i].pRow == NULL) { + input[i].stop = true; + input[i].next = false; + } } } } @@ -758,14 +1288,14 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo // delete detection TSDBROW *merge[3] = {0}; - // int iMerge[3] = {-1, -1, -1}; - int nMerge = 0; + int iMerge[3] = {-1, -1, -1}; + int nMerge = 0; for (int i = 0; i < nMax; ++i) { TSDBKEY maxKey = TSDBROW_KEY(max[i]); bool deleted = tsdbKeyDeleted(&maxKey, pSkyline, &iSkyline); if (!deleted) { - // iMerge[nMerge] = i; + iMerge[nMerge] = i; merge[nMerge++] = max[i]; } @@ -792,7 +1322,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo } } - } while (*ppRow == NULL); + } while (1); for (int i = 0; i < 3; ++i) { if (input[i].nextRowClearFn) { @@ -819,11 +1349,6 @@ _err: return code; } -typedef struct { - TSKEY ts; - SColVal colVal; -} SLastCol; - // static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, STSRow **ppRow) { static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { int32_t code = 0; @@ -873,7 +1398,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) { if (code) goto _err; } - int iSkyline = taosArrayGetSize(pSkyline) - 1; + int64_t iSkyline = taosArrayGetSize(pSkyline) - 1; SBlockIdx idx = {.suid = suid, .uid = uid}; @@ -1128,7 +1653,7 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUH } else { STSRow *pRow = NULL; bool dup = false; // which is always false for now - code = mergeLastRow(uid, pTsdb, &dup, &pRow); + code = mergeLastRow2(uid, pTsdb, &dup, &pRow); // if table's empty or error, return code of -1 if (code < 0 || pRow == NULL) { if (!dup && pRow) { @@ -1195,7 +1720,8 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand // STSRow *pRow = NULL; // code = mergeLast(uid, pTsdb, &pRow); SArray *pLastArray = NULL; - code = mergeLast(uid, pTsdb, &pLastArray); + // code = mergeLast(uid, pTsdb, &pLastArray); + code = mergeLast2(uid, pTsdb, &pLastArray); // if table's empty or error, return code of -1 // if (code < 0 || pRow == NULL) { if (code < 0 || pLastArray == NULL) { @@ -1219,52 +1745,6 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand return code; } -int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { - int32_t code = 0; - char key[32] = {0}; - int keyLen = 0; - - // getTableCacheKey(uid, "lr", key, &keyLen); - getTableCacheKey(uid, 0, key, &keyLen); - LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); - if (h) { - STSRow *pRow = (STSRow *)taosLRUCacheValue(pCache, h); - if (pRow->ts <= eKey) { - taosLRUCacheRelease(pCache, h, true); - } else { - taosLRUCacheRelease(pCache, h, false); - } - - // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); - } - - // getTableCacheKey(uid, "l", key, &keyLen); - getTableCacheKey(uid, 1, key, &keyLen); - h = taosLRUCacheLookup(pCache, key, keyLen); - if (h) { - SArray *pLast = (SArray *)taosLRUCacheValue(pCache, h); - bool invalidate = false; - int16_t nCol = taosArrayGetSize(pLast); - - for (int16_t iCol = 0; iCol < nCol; ++iCol) { - SLastCol *tTsVal = (SLastCol *)taosArrayGet(pLast, iCol); - if (eKey >= tTsVal->ts) { - invalidate = true; - break; - } - } - - if (invalidate) { - taosLRUCacheRelease(pCache, h, true); - } else { - taosLRUCacheRelease(pCache, h, false); - } - // void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen); - } - - return code; -} - int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h) { int32_t code = 0; @@ -1272,3 +1752,9 @@ int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h) { return code; } + +void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity) { + taosLRUCacheSetCapacity(pVnode->pTsdb->lruCache, capacity); +} + +size_t tsdbCacheGetCapacity(SVnode *pVnode) { return taosLRUCacheGetCapacity(pVnode->pTsdb->lruCache); } diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index 150ed620bf..5c09c7663f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -22,7 +22,6 @@ typedef struct SLastrowReader { SVnode* pVnode; STSchema* pSchema; uint64_t uid; - // int32_t* pSlotIds; char** transferBuf; // todo remove it soon int32_t numOfCols; int32_t type; @@ -31,25 +30,27 @@ typedef struct SLastrowReader { } SLastrowReader; static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReader, const int32_t* slotIds) { + ASSERT(pReader->numOfCols <= taosArrayGetSize(pBlock->pDataBlock)); int32_t numOfRows = pBlock->info.rows; - size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); SColVal colVal = {0}; - for (int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < pReader->numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); if (slotIds[i] == -1) { colDataAppend(pColInfoData, numOfRows, (const char*)&pRow->ts, false); } else { - tTSRowGetVal(pRow, pReader->pSchema, slotIds[i], &colVal); + int32_t slotId = slotIds[i]; + + tTSRowGetVal(pRow, pReader->pSchema, slotId, &colVal); if (IS_VAR_DATA_TYPE(colVal.type)) { if (colVal.isNull || colVal.isNone) { colDataAppendNULL(pColInfoData, numOfRows); } else { - varDataSetLen(pReader->transferBuf[i], colVal.value.nData); - memcpy(varDataVal(pReader->transferBuf[i]), colVal.value.pData, colVal.value.nData); - colDataAppend(pColInfoData, numOfRows, pReader->transferBuf[i], false); + varDataSetLen(pReader->transferBuf[slotId], colVal.value.nData); + memcpy(varDataVal(pReader->transferBuf[slotId]), colVal.value.pData, colVal.value.nData); + colDataAppend(pColInfoData, numOfRows, pReader->transferBuf[slotId], false); } } else { colDataAppend(pColInfoData, numOfRows, (const char*)&colVal.value, colVal.isNull || colVal.isNone); @@ -60,8 +61,7 @@ static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReade pBlock->info.rows += 1; } -int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t* colId, int32_t numOfCols, - void** pReader) { +int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t numOfCols, void** pReader) { SLastrowReader* p = taosMemoryCalloc(1, sizeof(SLastrowReader)); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -70,13 +70,18 @@ int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, p->type = type; p->pVnode = pVnode; p->numOfCols = numOfCols; - p->transferBuf = taosMemoryCalloc(p->numOfCols, POINTER_BYTES); + + if (taosArrayGetSize(pTableIdList) == 0) { + *pReader = p; + return TSDB_CODE_SUCCESS; + } STableKeyInfo* pKeyInfo = taosArrayGet(pTableIdList, 0); p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, pKeyInfo->uid, -1); p->pTableList = pTableIdList; - for (int32_t i = 0; i < p->numOfCols; ++i) { + p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES); + for (int32_t i = 0; i < p->pSchema->numOfCols; ++i) { if (IS_VAR_DATA_TYPE(p->pSchema->columns[i].type)) { p->transferBuf[i] = taosMemoryMalloc(p->pSchema->columns[i].bytes); } @@ -89,10 +94,11 @@ int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t tsdbLastrowReaderClose(void* pReader) { SLastrowReader* p = pReader; - for (int32_t i = 0; i < p->numOfCols; ++i) { + for (int32_t i = 0; i < p->pSchema->numOfCols; ++i) { taosMemoryFreeClear(p->transferBuf[i]); } + taosMemoryFree(p->pSchema); taosMemoryFree(p->transferBuf); taosMemoryFree(pReader); return TSDB_CODE_SUCCESS; diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 4a33dab08c..53b6735c30 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -688,6 +688,14 @@ _exit: return code; } +void tsdbFSStateDeleteDFileSet(STsdbFSState *pState, int32_t fid) { + int32_t idx; + + idx = taosArraySearchIdx(pState->aDFileSet, &(SDFileSet){.fid = fid}, tDFileSetCmprFn, TD_EQ); + ASSERT(idx >= 0); + taosArrayRemove(pState->aDFileSet, idx); +} + SDelFile *tsdbFSStateGetDelFile(STsdbFSState *pState) { return pState->pDelFile; } SDFileSet *tsdbFSStateGetDFileSet(STsdbFSState *pState, int32_t fid) { diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 9381f673d8..82de931872 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -181,8 +181,12 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid pMemTable->maxVersion = TMAX(pMemTable->maxVersion, version); pMemTable->nDel++; - if (tsdbKeyCmprFn(&lastKey, &pTbData->maxKey) >= 0) { - tsdbCacheDelete(pTsdb->lruCache, pTbData->uid, eKey); + if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config) && tsdbKeyCmprFn(&lastKey, &pTbData->maxKey) >= 0) { + tsdbCacheDeleteLastrow(pTsdb->lruCache, pTbData->uid, eKey); + } + + if (TSDB_CACHE_LAST(pMemTable->pTsdb->pVnode->config)) { + tsdbCacheDeleteLast(pTsdb->lruCache, pTbData->uid, eKey); } tsdbError("vgId:%d, delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64 @@ -556,12 +560,14 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i pTbData->maxKey = key.ts; } - if (pLastRow != NULL) { + if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config) && pLastRow != NULL) { tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, pLastRow, true); } } - tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, pLastRow); + if (TSDB_CACHE_LAST(pMemTable->pTsdb->pVnode->config)) { + tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, pLastRow, pMemTable->pTsdb); + } pTbData->minVersion = TMIN(pTbData->minVersion, version); pTbData->maxVersion = TMAX(pTbData->maxVersion, version); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 2a3b61605a..e86a14a30f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -71,7 +71,7 @@ typedef struct SFilesetIter { typedef struct SFileDataBlockInfo { int32_t - tbBlockIdx; // index position in STableBlockScanInfo in order to check whether neighbor block overlaps with it + tbBlockIdx; // index position in STableBlockScanInfo in order to check whether neighbor block overlaps with it uint64_t uid; } SFileDataBlockInfo; @@ -119,10 +119,10 @@ struct STsdbReader { int32_t type; // query type: 1. retrieve all data blocks, 2. retrieve direct prev|next rows SBlockLoadSuppInfo suppInfo; - SIOCostSummary cost; - STSchema* pSchema; - SDataFReader* pFileReader; - SVersionRange verRange; + SIOCostSummary cost; + STSchema* pSchema; + SDataFReader* pFileReader; + SVersionRange verRange; }; static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter); @@ -287,9 +287,7 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, const STsdbFSState* pFSt return TSDB_CODE_SUCCESS; } -static void cleanupFilesetIterator(SFilesetIter* pIter) { - taosArrayDestroy(pIter->pFileList); -} +static void cleanupFilesetIterator(SFilesetIter* pIter) { taosArrayDestroy(pIter->pFileList); } static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) { bool asc = ASCENDING_TRAVERSE(pIter->order); @@ -304,6 +302,10 @@ static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) { STimeWindow win = {0}; while (1) { +// if (pReader->pFileReader != NULL) { +// tsdbDataFReaderClose(&pReader->pFileReader); +// } + pReader->status.pCurrentFileset = (SDFileSet*)taosArrayGet(pIter->pFileList, pIter->index); int32_t code = tsdbDataFReaderOpen(&pReader->pFileReader, pReader->pTsdb, pReader->status.pCurrentFileset); @@ -323,11 +325,9 @@ static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) { if ((asc && (win.ekey < pReader->window.skey)) || ((!asc) && (win.skey > pReader->window.ekey))) { pIter->index += step; - if ((asc && pIter->index >= pIter->numOfFiles) || ((!asc) && pIter->index < 0)) { return false; } - continue; } @@ -351,9 +351,7 @@ static void resetDataBlockIterator(SDataBlockIter* pIter, int32_t order) { } } -static void cleanupDataBlockIterator(SDataBlockIter* pIter) { - taosArrayDestroy(pIter->blockList); -} +static void cleanupDataBlockIterator(SDataBlockIter* pIter) { taosArrayDestroy(pIter->blockList); } static void initReaderStatus(SReaderStatus* pStatus) { pStatus->pTableIter = NULL; @@ -394,15 +392,14 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd initReaderStatus(&pReader->status); - pReader->pTsdb = - getTsdbByRetentions(pVnode, pCond->twindows.skey, pVnode->config.tsdbCfg.retentions, idstr, &level); + pReader->pTsdb = getTsdbByRetentions(pVnode, pCond->twindows.skey, pVnode->config.tsdbCfg.retentions, idstr, &level); pReader->suid = pCond->suid; pReader->order = pCond->order; pReader->capacity = 4096; pReader->idStr = (idstr != NULL) ? strdup(idstr) : NULL; pReader->verRange = getQueryVerRange(pVnode, pCond, level); pReader->type = pCond->type; - pReader->window = updateQueryTimeWindow(pVnode->pTsdb, &pCond->twindows); + pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows); ASSERT(pCond->numOfCols > 0); @@ -835,7 +832,7 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI uint8_t *pb = NULL, *pb1 = NULL; int32_t code = tsdbReadColData(pReader->pFileReader, &pBlockScanInfo->blockIdx, pBlock, pSupInfo->colIds, numOfCols, - pBlockData, &pb, &pb1); + pBlockData, &pb, &pb1); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -1461,18 +1458,18 @@ static bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SBl } TSDBKEY* pFirst = taosArrayGet(pBlockScanInfo->delSkyline, 0); - TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline); + TSDBKEY* pLast = taosArrayGetLast(pBlockScanInfo->delSkyline); // ts is not overlap if (pBlock->minKey.ts > pLast->ts || pBlock->maxKey.ts < pFirst->ts) { return false; } - int32_t step = ASCENDING_TRAVERSE(order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(order) ? 1 : -1; // version is not overlap size_t num = taosArrayGetSize(pBlockScanInfo->delSkyline); - for(int32_t i = pBlockScanInfo->fileDelIndex; i < num; i += step) { + for (int32_t i = pBlockScanInfo->fileDelIndex; i < num; i += step) { TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i); if (p->ts >= pBlock->minKey.ts && p->ts <= pBlock->maxKey.ts) { if (p->version >= pBlock->minVersion) { @@ -1504,8 +1501,8 @@ static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pFBloc } // has duplicated ts of different version in this block - bool hasDup = (pBlock->nSubBlock == 1)? pBlock->hasDup:true; - bool overlapWithDel= overlapWithDelSkyline(pScanInfo, pBlock, pReader->order); + bool hasDup = (pBlock->nSubBlock == 1) ? pBlock->hasDup : true; + bool overlapWithDel = overlapWithDelSkyline(pScanInfo, pBlock, pReader->order); return (overlapWithNeighbor || hasDup || dataBlockPartiallyRequired(&pReader->window, &pReader->verRange, pBlock) || keyOverlapFileBlock(key, pBlock, &pReader->verRange) || (pBlock->nRow > pReader->capacity) || overlapWithDel); @@ -2205,15 +2202,15 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* ret if (level == TSDB_RETENTION_L0) { *pLevel = TSDB_RETENTION_L0; - tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L0, str); + tsdbDebug("vgId:%d, rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L0, str); return VND_RSMA0(pVnode); } else if (level == TSDB_RETENTION_L1) { *pLevel = TSDB_RETENTION_L1; - tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L1, str); + tsdbDebug("vgId:%d, rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L1, str); return VND_RSMA1(pVnode); } else { *pLevel = TSDB_RETENTION_L2; - tsdbDebug("vgId:%d, read handle %p rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L2, str); + tsdbDebug("vgId:%d, rsma level %d is selected to query %s", vgId, TSDB_RETENTION_L2, str); return VND_RSMA2(pVnode); } } @@ -2222,17 +2219,18 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* ret } SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level) { - int64_t startVer = (pCond->startVersion == -1)? 0:pCond->startVersion; + int64_t startVer = (pCond->startVersion == -1) ? 0 : pCond->startVersion; if (VND_IS_RSMA(pVnode)) { return (SVersionRange){.minVer = startVer, .maxVer = tdRSmaGetMaxSubmitVer(pVnode->pSma, level)}; } int64_t endVer = 0; - if (pCond->endVersion == -1) { // user not specified end version, set current maximum version of vnode as the endVersion + if (pCond->endVersion == + -1) { // user not specified end version, set current maximum version of vnode as the endVersion endVer = pVnode->state.applied; } else { - endVer = (pCond->endVersion > pVnode->state.applied)? pVnode->state.applied:pCond->endVersion; + endVer = (pCond->endVersion > pVnode->state.applied) ? pVnode->state.applied : pCond->endVersion; } return (SVersionRange){.minVer = startVer, .maxVer = endVer}; @@ -2276,9 +2274,9 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32 if (pDelList == NULL) { return false; } - size_t num = taosArrayGetSize(pDelList); - bool asc = ASCENDING_TRAVERSE(order); - int32_t step = asc? 1:-1; + size_t num = taosArrayGetSize(pDelList); + bool asc = ASCENDING_TRAVERSE(order); + int32_t step = asc ? 1 : -1; if (asc) { if (*index >= num - 1) { @@ -2439,6 +2437,7 @@ static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowInd SVersionRange* pVerRange, int32_t step) { while (pBlockData->aTSKEY[rowIndex] == key && rowIndex < pBlockData->nRow && rowIndex >= 0) { if (pBlockData->aVersion[rowIndex] > pVerRange->maxVer || pBlockData->aVersion[rowIndex] < pVerRange->minVer) { + rowIndex += step; continue; } @@ -2825,7 +2824,7 @@ void tsdbReaderClose(STsdbReader* pReader) { taosMemoryFree(pSupInfo->colIds); taosArrayDestroy(pSupInfo->pColAgg); - for(int32_t i = 0; i < blockDataGetNumOfCols(pReader->pResBlock); ++i) { + for (int32_t i = 0; i < blockDataGetNumOfCols(pReader->pResBlock); ++i) { if (pSupInfo->buildBuf[i] != NULL) { taosMemoryFreeClear(pSupInfo->buildBuf[i]); } @@ -2837,6 +2836,9 @@ void tsdbReaderClose(STsdbReader* pReader) { destroyBlockScanInfo(pReader->status.pTableMap); blockDataDestroy(pReader->pResBlock); + if (pReader->pFileReader != NULL) { + tsdbDataFReaderClose(&pReader->pFileReader); + } #if 0 // if (pReader->status.pTableScanInfo != NULL) { @@ -3013,8 +3015,8 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { return TSDB_CODE_SUCCESS; } - pReader->order = pCond->order; - pReader->type = BLOCK_LOAD_OFFSET_ORDER; + pReader->order = pCond->order; + pReader->type = BLOCK_LOAD_OFFSET_ORDER; pReader->status.loadFromFile = true; pReader->status.pTableIter = NULL; @@ -3025,11 +3027,14 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { memset(pReader->suppInfo.plist, 0, POINTER_BYTES); pReader->suppInfo.tsColAgg.colId = PRIMARYKEY_TIMESTAMP_COL_ID; + tsdbDataFReaderClose(&pReader->pFileReader); // todo set the correct numOfTables int32_t numOfTables = 1; SDataBlockIter* pBlockIter = &pReader->status.blockIter; + tsdbDataFReaderClose(&pReader->pFileReader); + STsdbFSState* pFState = pReader->pTsdb->fs->cState; initFilesetIterator(&pReader->status.fileIter, pFState, pReader->order, pReader->idStr); resetDataBlockIterator(&pReader->status.blockIter, pReader->order); @@ -3116,13 +3121,12 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa pTableBlockInfo->numOfBlocks += pBlockIter->numOfBlocks; } -/* - hasNext = blockIteratorNext(&pStatus->blockIter); -*/ + /* + hasNext = blockIteratorNext(&pStatus->blockIter); + */ - -// tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pReader, numOfBlocks, numOfTables, -// pReader->pFileGroup->fid, pReader->idStr); + // tsdbDebug("%p %d blocks found in file for %d table(s), fid:%d, %s", pReader, numOfBlocks, numOfTables, + // pReader->pFileGroup->fid, pReader->idStr); } return code; @@ -3160,7 +3164,7 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) { return rows; } -int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int64_t *suid) { +int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int64_t* suid) { int32_t sversion = 1; SMetaReader mr = {0}; @@ -3173,7 +3177,7 @@ int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int6 } *suid = 0; - + if (mr.me.type == TSDB_CHILD_TABLE) { *suid = mr.me.ctbEntry.suid; code = metaGetTableEntryByUid(&mr, *suid); @@ -3190,8 +3194,7 @@ int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int6 metaReaderClear(&mr); *pSchema = metaGetTbTSchema(pVnode->pMeta, uid, sversion); - + return TSDB_CODE_SUCCESS; } - diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index e96ee03b03..4e7a9d3b04 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -1913,3 +1913,114 @@ _err: taosArrayDestroy(aBlockCol); return code; } + +int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo) { + int32_t code = 0; + int64_t n; + int64_t size; + TdFilePtr pOutFD = NULL; // TODO + TdFilePtr PInFD = NULL; // TODO + char fNameFrom[TSDB_FILENAME_LEN]; + char fNameTo[TSDB_FILENAME_LEN]; + + // head + tsdbDataFileName(pTsdb, pSetFrom, TSDB_HEAD_FILE, fNameFrom); + tsdbDataFileName(pTsdb, pSetTo, TSDB_HEAD_FILE, fNameTo); + + pOutFD = taosOpenFile(fNameTo, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); + if (pOutFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + PInFD = taosOpenFile(fNameFrom, TD_FILE_READ); + if (PInFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + n = taosFSendFile(pOutFD, PInFD, 0, pSetFrom->fHead.size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + taosCloseFile(&pOutFD); + taosCloseFile(&PInFD); + + // data + tsdbDataFileName(pTsdb, pSetFrom, TSDB_DATA_FILE, fNameFrom); + tsdbDataFileName(pTsdb, pSetTo, TSDB_DATA_FILE, fNameTo); + + pOutFD = taosOpenFile(fNameTo, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); + if (pOutFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + PInFD = taosOpenFile(fNameFrom, TD_FILE_READ); + if (PInFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + n = taosFSendFile(pOutFD, PInFD, 0, pSetFrom->fData.size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + taosCloseFile(&pOutFD); + taosCloseFile(&PInFD); + + // last + tsdbDataFileName(pTsdb, pSetFrom, TSDB_LAST_FILE, fNameFrom); + tsdbDataFileName(pTsdb, pSetTo, TSDB_LAST_FILE, fNameTo); + pOutFD = taosOpenFile(fNameTo, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); + if (pOutFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + PInFD = taosOpenFile(fNameFrom, TD_FILE_READ); + if (PInFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + n = taosFSendFile(pOutFD, PInFD, 0, pSetFrom->fLast.size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + taosCloseFile(&pOutFD); + taosCloseFile(&PInFD); + + // sma + tsdbDataFileName(pTsdb, pSetFrom, TSDB_SMA_FILE, fNameFrom); + tsdbDataFileName(pTsdb, pSetTo, TSDB_SMA_FILE, fNameTo); + + pOutFD = taosOpenFile(fNameTo, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); + if (pOutFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + PInFD = taosOpenFile(fNameFrom, TD_FILE_READ); + if (PInFD == NULL) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + + n = taosFSendFile(pOutFD, PInFD, 0, pSetFrom->fSma.size); + if (n < 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _err; + } + taosCloseFile(&pOutFD); + taosCloseFile(&PInFD); + + return code; + +_err: + tsdbError("vgId:%d tsdb DFileSet copy failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + return code; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index e73f3f947c..2ae646a571 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -15,19 +15,80 @@ #include "tsdb.h" +static int32_t tsdbDoRetentionImpl(STsdb *pTsdb, int64_t now, int8_t try, int8_t *canDo) { + int32_t code = 0; + STsdbFSState *pState; + + if (try) { + pState = pTsdb->fs->cState; + *canDo = 0; + } else { + pState = pTsdb->fs->nState; + } + + for (int32_t iSet = 0; iSet < taosArrayGetSize(pState->aDFileSet); iSet++) { + SDFileSet *pDFileSet = (SDFileSet *)taosArrayGet(pState->aDFileSet, iSet); + int32_t expLevel = tsdbFidLevel(pDFileSet->fid, &pTsdb->keepCfg, now); + SDiskID did; + + // check + if (expLevel == pDFileSet->diskId.id) continue; + + // delete or move + if (expLevel < 0) { + if (try) { + *canDo = 1; + } else { + tsdbFSStateDeleteDFileSet(pState, pDFileSet->fid); + iSet--; + } + } else { + // alloc + if (tfsAllocDisk(pTsdb->pVnode->pTfs, expLevel, &did) < 0) { + code = terrno; + goto _exit; + } + + if (did.level == pDFileSet->diskId.level) continue; + + if (try) { + *canDo = 1; + } else { + // copy the file to new disk + + SDFileSet nDFileSet = *pDFileSet; + nDFileSet.diskId = did; + + tfsMkdirRecurAt(pTsdb->pVnode->pTfs, pTsdb->path, did); + + code = tsdbDFileSetCopy(pTsdb, pDFileSet, &nDFileSet); + if (code) goto _exit; + + code = tsdbFSStateUpsertDFileSet(pState, &nDFileSet); + if (code) goto _exit; + } + } + } + +_exit: + return code; +} + int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) { int32_t code = 0; + int8_t canDo; + + // try + tsdbDoRetentionImpl(pTsdb, now, 1, &canDo); + if (!canDo) goto _exit; // begin code = tsdbFSBegin(pTsdb->fs); if (code) goto _err; // do retention - for (int32_t iSet = 0; iSet < taosArrayGetSize(pTsdb->fs->nState->aDFileSet); iSet++) { - SDFileSet *pDFileSet = (SDFileSet *)taosArrayGet(pTsdb->fs->nState->aDFileSet, iSet); - - // TODO - } + code = tsdbDoRetentionImpl(pTsdb, now, 0, NULL); + if (code) goto _err; // commit code = tsdbFSCommit(pTsdb->fs); @@ -38,5 +99,6 @@ _exit: _err: tsdbError("vgId:%d tsdb do retention failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + tsdbFSRollback(pTsdb->fs); return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index 54087a7871..06d4a86116 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -312,6 +312,9 @@ struct STsdbSnapWriter { // config int32_t minutes; int8_t precision; + int32_t minRow; + int32_t maxRow; + int8_t cmprAlg; // for data file int32_t fid; @@ -321,14 +324,18 @@ struct STsdbSnapWriter { SBlockIdx* pBlockIdx; SMapData mBlock; int32_t iBlock; + SBlock* pBlock; + SBlock block; SBlockData blockData; int32_t iRow; SDataFWriter* pDataFWriter; SArray* aBlockIdxN; + SBlockIdx* pBlockIdxN; SBlockIdx blockIdx; SMapData mBlockN; - SBlock block; + SBlock* pBlockN; + SBlock blockN; SBlockData nBlockData; // for del file @@ -394,13 +401,114 @@ _err: return code; } +static int32_t tsdbSnapWriteTableDataEnd(STsdbSnapWriter* pWrite) { + int32_t code = 0; + // TODO + return code; +} + +static int32_t tsdbSnapWriteTableData(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { + int32_t code = 0; + TABLEID id = {0}; // TODO + + // skip + while (pWriter->pBlockIdx && tTABLEIDCmprFn(&id, pWriter->pBlockIdx) < 0) { + code = tsdbSnapWriteTableDataEnd(pWriter); + if (code) goto _err; + + pWriter->iBlockIdx++; + if (pWriter->iBlockIdx < taosArrayGetSize(pWriter->aBlockIdx)) { + pWriter->pBlockIdx = (SBlockIdx*)taosArrayGet(pWriter->aBlockIdx, pWriter->iBlockIdx); + } else { + pWriter->pBlockIdx = NULL; + } + } + + // new or merge + if (pWriter->pBlockIdx == NULL || tTABLEIDCmprFn(&id, pWriter->pBlockIdx) < 0) { + int32_t c; + + if (pWriter->pBlockIdxN && ((c = tTABLEIDCmprFn(&id, pWriter->pBlockIdxN)) != 0)) { + ASSERT(c > 0); + + code = tsdbSnapWriteTableDataEnd(pWriter); + if (code) goto _err; + } + + if (pWriter->pBlockIdxN == NULL) { + pWriter->pBlockIdx = &pWriter->blockIdx; + pWriter->pBlockIdx->suid = id.suid; + pWriter->pBlockIdx->uid = id.uid; + } + + // loop to write the data + TSDBROW* pRow = NULL; // todo + int32_t nRow = 0; // todo + SBlockData* pBlockData = NULL; // todo + for (int32_t iRow = 0; iRow < nRow; iRow++) { + code = tBlockDataAppendRow(&pWriter->nBlockData, &tsdbRowFromBlockData(pBlockData, iRow), NULL); + if (code) goto _err; + + if (pWriter->nBlockData.nRow > pWriter->maxRow * 4 / 5) { + code = tsdbWriteBlockData(pWriter->pDataFWriter, &pWriter->nBlockData, NULL, NULL, pWriter->pBlockIdxN, + pWriter->pBlockN, pWriter->cmprAlg); + if (code) goto _err; + } + } + } else { + // skip + while (true) { + if (pWriter->pBlock == NULL) break; + if (pWriter->pBlock->last) break; + if (tBlockCmprFn(&(SBlock){.minKey = {0}, .maxKey = {0}}, pWriter->pBlock) >= 0) break; + + code = tMapDataPutItem(&pWriter->mBlockN, pWriter->pBlock, tPutBlock); + if (code) goto _err; + } + + if (pWriter->pBlock) { + if (pWriter->pBlock->last) { + // load the last block and merge with the data (todo) + } else { + int32_t c = tBlockCmprFn(&(SBlock){0 /*TODO*/}, pWriter->pBlock); + + if (c > 0) { + // commit until pWriter->pBlock (todo) + } else { + // load the block and merge with the data (todo) + } + } + } else { + int32_t nRow = 0; + SBlockData* pBlockData = NULL; + + for (int32_t iRow = 0; iRow < nRow; iRow++) { + code = tBlockDataAppendRow(&pWriter->nBlockData, &tsdbRowFromBlockData(pBlockData, iRow), NULL); + if (code) goto _err; + + if (pWriter->nBlockData.nRow >= pWriter->maxRow * 4 / 5) { + code = tsdbWriteBlockData(pWriter->pDataFWriter, &pWriter->nBlockData, NULL, NULL, pWriter->pBlockIdxN, + pWriter->pBlockN, pWriter->cmprAlg); + if (code) goto _err; + + tBlockDataClearData(&pWriter->nBlockData); + } + } + } + } + + return code; + +_err: + tsdbError("vgId:%d tsdb snapshot write table data failed since %s", TD_VID(pWriter->pTsdb->pVnode), tstrerror(code)); + return code; +} + static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint32_t nData) { int32_t code = 0; STsdb* pTsdb = pWriter->pTsdb; - int64_t suid = 0; // todo - int64_t uid = 0; // todo - int64_t skey; // todo - int64_t ekey; // todo + int64_t skey; // todo + int64_t ekey; // todo int32_t fid = tsdbKeyFid(skey, pWriter->minutes, pWriter->precision); ASSERT(fid == tsdbKeyFid(ekey, pWriter->minutes, pWriter->precision)); @@ -440,47 +548,8 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3 taosArrayClear(pWriter->aBlockIdxN); } - // process - TABLEID id = {0}; // TODO - TSKEY minKey = 0; // TODO - TSKEY maxKey = 0; // TODO - - while (true) { - if (pWriter->pBlockIdx) { - int32_t c = tTABLEIDCmprFn(&id, pWriter->pBlockIdx); - - if (c == 0) { - } else if (c < 0) { - // keep merge - } else { - // code = tsdbSnapWriteTableDataEnd(pWriter); - if (code) goto _err; - - pWriter->iBlockIdx++; - if (pWriter->iBlockIdx < taosArrayGetSize(pWriter->aBlockIdx)) { - pWriter->pBlockIdx = (SBlockIdx*)taosArrayGet(pWriter->aBlockIdx, pWriter->iBlockIdx); - } else { - pWriter->pBlockIdx = NULL; - } - - if (pWriter->pBlockIdx) { - code = tsdbReadBlock(pWriter->pDataFReader, pWriter->pBlockIdx, &pWriter->mBlock, NULL); - if (code) goto _err; - } - } - } else { - int32_t c = tTABLEIDCmprFn(&id, &pWriter->blockIdx); - - if (c == 0) { - // merge commit the block data - } else if (c > 0) { - // code = tsdbSnapWriteTableDataEnd(pWriter); - if (code) goto _err; - } else { - ASSERT(0); - } - } - } + code = tsdbSnapWriteTableData(pWriter, pData, nData); + if (code) goto _err; return code; diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 415a674737..dc6c823368 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -465,17 +465,37 @@ void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minK *maxKey = *minKey + minutes * tsTickPerMin[precision] - 1; } -// int tsdFidLevel(int fid, TSKEY now, minute) { -// if (fid >= pRtn->maxFid) { -// return 0; -// } else if (fid >= pRtn->midFid) { -// return 1; -// } else if (fid >= pRtn->minFid) { -// return 2; -// } else { -// return -1; -// } -// } +int32_t tsdbFidLevel(int32_t fid, STsdbKeepCfg *pKeepCfg, int64_t now) { + int32_t aFid[3]; + TSKEY key; + + if (pKeepCfg->precision == TSDB_TIME_PRECISION_MILLI) { + now = now * 1000; + } else if (pKeepCfg->precision == TSDB_TIME_PRECISION_MICRO) { + now = now * 1000000l; + } else if (pKeepCfg->precision == TSDB_TIME_PRECISION_NANO) { + now = now * 1000000000l; + } else { + ASSERT(0); + } + + key = now - pKeepCfg->keep0 * tsTickPerMin[pKeepCfg->precision]; + aFid[0] = tsdbKeyFid(key, pKeepCfg->days, pKeepCfg->precision); + key = now - pKeepCfg->keep1 * tsTickPerMin[pKeepCfg->precision]; + aFid[1] = tsdbKeyFid(key, pKeepCfg->days, pKeepCfg->precision); + key = now - pKeepCfg->keep2 * tsTickPerMin[pKeepCfg->precision]; + aFid[2] = tsdbKeyFid(key, pKeepCfg->days, pKeepCfg->precision); + + if (fid >= aFid[0]) { + return 0; + } else if (fid >= aFid[1]) { + return 1; + } else if (fid >= aFid[2]) { + return 2; + } else { + return -1; + } +} // TSDBROW ====================================================== void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) { diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index c74baa6d7b..eac1fd1a74 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -15,30 +15,39 @@ #include "vnd.h" -const SVnodeCfg vnodeCfgDefault = { - .vgId = -1, - .dbname = "", - .dbId = 0, - .szPage = 4096, - .szCache = 256, - .szBuf = 96 * 1024 * 1024, - .isHeap = false, - .isWeak = 0, - .tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI, - .update = 1, - .compression = 2, - .slLevel = 5, - .days = 14400, - .minRows = 100, - .maxRows = 4096, - .keep2 = 5256000, - .keep0 = 5256000, - .keep1 = 5256000}, - .walCfg = - {.vgId = -1, .fsyncPeriod = 0, .retentionPeriod = 0, .rollPeriod = 0, .segSize = 0, .level = TAOS_WAL_WRITE}, - .hashBegin = 0, - .hashEnd = 0, - .hashMethod = 0}; +const SVnodeCfg vnodeCfgDefault = {.vgId = -1, + .dbname = "", + .dbId = 0, + .szPage = 4096, + .szCache = 256, + .cacheLast = 3, + .cacheLastSize = 8, + .szBuf = 96 * 1024 * 1024, + .isHeap = false, + .isWeak = 0, + .tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI, + .update = 1, + .compression = 2, + .slLevel = 5, + .days = 14400, + .minRows = 100, + .maxRows = 4096, + .keep2 = 5256000, + .keep0 = 5256000, + .keep1 = 5256000}, + .walCfg = + { + .vgId = -1, + .fsyncPeriod = 0, + .retentionPeriod = -1, + .rollPeriod = -1, + .segSize = -1, + .retentionSize = -1, + .level = TAOS_WAL_WRITE, + }, + .hashBegin = 0, + .hashEnd = 0, + .hashMethod = 0}; int vnodeCheckCfg(const SVnodeCfg *pCfg) { // TODO @@ -53,6 +62,8 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { if (tjsonAddIntegerToObject(pJson, "dbId", pCfg->dbId) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "szPage", pCfg->szPage) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "szCache", pCfg->szCache) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "cacheLast", pCfg->cacheLast) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "cacheLastSize", pCfg->cacheLastSize) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "szBuf", pCfg->szBuf) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "isHeap", pCfg->isHeap) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "isWeak", pCfg->isWeak) < 0) return -1; @@ -79,7 +90,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { SJson *pNodeRetentions = tjsonCreateArray(); tjsonAddItemToObject(pJson, "retentions", pNodeRetentions); for (int32_t i = 0; i < nRetention; ++i) { - SJson * pNodeRetention = tjsonCreateObject(); + SJson *pNodeRetention = tjsonCreateObject(); const SRetention *pRetention = pCfg->tsdbCfg.retentions + i; tjsonAddIntegerToObject(pNodeRetention, "freq", pRetention->freq); tjsonAddIntegerToObject(pNodeRetention, "freqUnit", pRetention->freqUnit); @@ -126,6 +137,10 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (code < 0) return -1; tjsonGetNumberValue(pJson, "szCache", pCfg->szCache, code); if (code < 0) return -1; + tjsonGetNumberValue(pJson, "cacheLast", pCfg->cacheLast, code); + if (code < 0) return -1; + tjsonGetNumberValue(pJson, "cacheLastSize", pCfg->cacheLastSize, code); + if (code < 0) return -1; tjsonGetNumberValue(pJson, "szBuf", pCfg->szBuf, code); if (code < 0) return -1; tjsonGetNumberValue(pJson, "isHeap", pCfg->isHeap, code); @@ -156,7 +171,7 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (code < 0) return -1; tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2, code); if (code < 0) return -1; - SJson * pNodeRetentions = tjsonGetObjectItem(pJson, "retentions"); + SJson *pNodeRetentions = tjsonGetObjectItem(pJson, "retentions"); int32_t nRetention = tjsonGetArraySize(pNodeRetentions); if (nRetention > TSDB_RETENTION_MAX) { nRetention = TSDB_RETENTION_MAX; diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index ed829666cd..ebbb691e28 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -15,7 +15,7 @@ #include "vnd.h" -#define VND_INFO_FNAME "vnode.json" +#define VND_INFO_FNAME "vnode.json" #define VND_INFO_FNAME_TMP "vnode_tmp.json" static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData); @@ -230,6 +230,7 @@ int vnodeCommit(SVnode *pVnode) { ASSERT(0); return -1; } + walBeginSnapshot(pVnode->pWal, pVnode->state.applied); // preCommit smaPreCommit(pVnode->pSma); @@ -278,6 +279,7 @@ int vnodeCommit(SVnode *pVnode) { smaPostCommit(pVnode->pSma); // apply the commit (TODO) + walEndSnapshot(pVnode->pWal); vnodeBufPoolReset(pVnode->onCommit); pVnode->onCommit->next = pVnode->pPool; pVnode->pPool = pVnode->onCommit; diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index e59f8ae558..0914827950 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -28,7 +28,7 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { } // create vnode env - if (tfsMkdir(pTfs, path) < 0) { + if (tfsMkdirAt(pTfs, path, (SDiskID){0}) < 0) { vError("vgId:%d, failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno)); return -1; } @@ -117,6 +117,13 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { // open wal sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR); taosRealPath(tdir, NULL, sizeof(tdir)); + +// for test tsdb snapshot +#if 0 + pVnode->config.walCfg.segSize = 200; + pVnode->config.walCfg.retentionSize = 2000; +#endif + pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg)); if (pVnode->pWal == NULL) { vError("vgId:%d, failed to open vnode wal since %s", TD_VID(pVnode), tstrerror(terrno)); @@ -168,6 +175,12 @@ _err: return NULL; } +void vnodePreClose(SVnode *pVnode) { + if (pVnode) { + syncLeaderTransfer(pVnode->sync); + } +} + void vnodeClose(SVnode *pVnode) { if (pVnode) { vnodeCommit(pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index dceeb4c282..d25ae817c7 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -24,8 +24,10 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); -static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); +static int32_t vnodeProcessAlterHashRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); +static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); +static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) { @@ -172,9 +174,12 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp case TDMT_VND_DROP_TTL_TABLE: if (vnodeProcessDropTtlTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; break; - case TDMT_VND_CREATE_SMA: { + case TDMT_VND_TRIM: + if (vnodeProcessTrimReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; + break; + case TDMT_VND_CREATE_SMA: if (vnodeProcessCreateTSmaReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; - } break; + break; /* TSDB */ case TDMT_VND_SUBMIT: if (vnodeProcessSubmitReq(pVnode, version, pMsg->pCont, pMsg->contLen, pRsp) < 0) goto _err; @@ -215,9 +220,10 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp vnodeProcessAlterConfirmReq(pVnode, version, pReq, len, pRsp); break; case TDMT_VND_ALTER_HASHRANGE: - vnodeProcessAlterHasnRangeReq(pVnode, version, pReq, len, pRsp); + vnodeProcessAlterHashRangeReq(pVnode, version, pReq, len, pRsp); break; case TDMT_VND_ALTER_CONFIG: + vnodeProcessAlterConfigReq(pVnode, version, pReq, len, pRsp); break; case TDMT_VND_COMMIT: goto _do_commit; @@ -345,13 +351,38 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) { pMetaRsp->precision = pVnode->config.tsdbCfg.precision; } +static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { + int32_t code = 0; + SVTrimDbReq trimReq = {0}; + + vInfo("vgId:%d, trim vnode request will be processed, time:%d", pVnode->config.vgId, trimReq.timestamp); + + // decode + if (tDeserializeSVTrimDbReq(pReq, len, &trimReq) != 0) { + code = TSDB_CODE_INVALID_MSG; + goto _exit; + } + + // process + code = tsdbDoRetention(pVnode->pTsdb, trimReq.timestamp); + if (code) goto _exit; + +_exit: + return code; +} + static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { SArray *tbUids = taosArrayInit(8, sizeof(int64_t)); if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY; - int32_t t = ntohl(*(int32_t *)pReq); - vDebug("rec ttl time:%d", t); - int32_t ret = metaTtlDropTable(pVnode->pMeta, t, tbUids); + SVDropTtlTableReq ttlReq = {0}; + if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto end; + } + + vInfo("vgId:%d, drop ttl table req will be processed, time:%d", pVnode->config.vgId, ttlReq.timestamp); + int32_t ret = metaTtlDropTable(pVnode->pMeta, ttlReq.timestamp, tbUids); if (ret != 0) { goto end; } @@ -386,7 +417,7 @@ static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *p goto _err; } - if (tdProcessRSmaCreate(pVnode, &req) < 0) { + if (tdProcessRSmaCreate(pVnode->pSma, &req) < 0) { pRsp->code = terrno; goto _err; } @@ -542,6 +573,11 @@ static int32_t vnodeProcessDropStbReq(SVnode *pVnode, int64_t version, void *pRe goto _exit; } + if (tdProcessRSmaDrop(pVnode->pSma, &req) < 0) { + rcode = terrno; + goto _exit; + } + // return rsp _exit: pRsp->code = rcode; @@ -886,7 +922,7 @@ static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void return 0; } -static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { +static int32_t vnodeProcessAlterHashRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { vInfo("vgId:%d, alter hashrange msg will be processed", TD_VID(pVnode)); // todo @@ -896,6 +932,23 @@ static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, vo return 0; } +static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { + SAlterVnodeReq alterReq = {0}; + if (tDeserializeSAlterVnodeReq(pReq, len, &alterReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return TSDB_CODE_INVALID_MSG; + } + + vInfo("vgId:%d, start to alter vnode config, cacheLast:%d cacheLastSize:%d", TD_VID(pVnode), alterReq.cacheLast, + alterReq.cacheLastSize); + if (pVnode->config.cacheLastSize != alterReq.cacheLastSize) { + pVnode->config.cacheLastSize = alterReq.cacheLastSize; + // TODO: save config + tsdbCacheSetCapacity(pVnode, (size_t)pVnode->config.cacheLastSize * 1024 * 1024); + } + return 0; +} + static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { int32_t code = 0; SDecoder *pCoder = &(SDecoder){0}; diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index 97ce8eaab7..bdcfe208d6 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -569,7 +569,7 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { return -1; } - setPingTimerMS(pVnode->sync, 3000); + setPingTimerMS(pVnode->sync, 5000); setElectTimerMS(pVnode->sync, 500); setHeartbeatTimerMS(pVnode->sync, 100); return 0; diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 7637c66b84..fb9f588bae 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -480,8 +480,6 @@ typedef struct SCtgOperation { #define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 -#define CTG_IS_LOCKED(_lock) atomic_load_32((_lock)) - #define CTG_LOCK(type, _lock) do { \ if (CTG_READ == (type)) { \ assert(atomic_load_32((_lock)) >= 0); \ @@ -644,6 +642,7 @@ void ctgFreeSTableIndex(void *info); void ctgClearSubTaskRes(SCtgSubRes *pRes); void ctgFreeQNode(SCtgQNode *node); void ctgClearHandle(SCatalog* pCtg); +void ctgFreeTbCacheImpl(SCtgTbCache *pCache); extern SCatalogMgmt gCtgMgmt; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 3a7ad4a2d6..ca50702894 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -1293,6 +1293,7 @@ void catalogDestroy(void) { if (!taosCheckCurrentInDll()) { ctgClearCacheEnqueue(NULL, true, true, true); + taosThreadJoin(gCtgMgmt.updateThread, NULL); } taosHashCleanup(gCtgMgmt.pCluster); diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 455f2bd6a7..e77df8f7f2 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -789,9 +789,13 @@ _return: int32_t ctgCallUserCb(void* param) { SCtgJob* pJob = (SCtgJob*)param; + + qDebug("QID:0x%" PRIx64 " ctg start to call user cb with rsp %s", pJob->queryId, tstrerror(pJob->jobResCode)); (*pJob->userFp)(&pJob->jobRes, pJob->userParam, pJob->jobResCode); + qDebug("QID:0x%" PRIx64 " ctg end to call user cb", pJob->queryId); + taosRemoveRef(gCtgMgmt.jobPool, pJob->refId); return TSDB_CODE_SUCCESS; @@ -822,8 +826,6 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) { _return: - qDebug("QID:0x%" PRIx64 " ctg call user callback with rsp %s", pJob->queryId, tstrerror(code)); - pJob->jobResCode = code; //taosSsleep(2); diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index 77c1e5b8b1..499ce77276 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -647,6 +647,8 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) { CTG_RET(TSDB_CODE_OUT_OF_MEMORY); } + bool syncOp = operation->syncOp; + char* opName = gCtgCacheOperation[operation->opId].name; if (operation->syncOp) { tsem_init(&operation->rspSem, 0, 0); } @@ -664,14 +666,14 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) { gCtgMgmt.queue.tail = node; CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.queue.qlock); + ctgDebug("action [%s] added into queue", opName); + CTG_QUEUE_INC(); CTG_RT_STAT_INC(numOfOpEnqueue, 1); tsem_post(&gCtgMgmt.queue.reqSem); - ctgDebug("action [%s] added into queue", gCtgCacheOperation[operation->opId].name); - - if (operation->syncOp) { + if (syncOp) { tsem_wait(&operation->rspSem); taosMemoryFree(operation); } @@ -840,6 +842,7 @@ _return: ctgFreeVgInfo(dbInfo); taosMemoryFreeClear(op->data); + taosMemoryFreeClear(op); CTG_RET(code); } @@ -852,7 +855,7 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy SCtgUpdateTbMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTbMetaMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTbMetaMsg)); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } char *p = strchr(output->dbFName, '.'); @@ -871,6 +874,11 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool sy _return: + if (output) { + taosMemoryFree(output->tbMeta); + taosMemoryFree(output); + } + taosMemoryFreeClear(msg); CTG_RET(code); @@ -1753,6 +1761,16 @@ int32_t ctgOpDropStbMeta(SCtgCacheOperation *operation) { CTG_CACHE_STAT_DEC(numOfStb, 1); } + SCtgTbCache* pTbCache = taosHashGet(dbCache->tbCache, msg->stbName, strlen(msg->stbName)); + if (NULL == pTbCache) { + ctgDebug("stb %s already not in cache", msg->stbName); + goto _return; + } + + CTG_LOCK(CTG_WRITE, &pTbCache->metaLock); + ctgFreeTbCacheImpl(pTbCache); + CTG_UNLOCK(CTG_WRITE, &pTbCache->metaLock); + if (taosHashRemove(dbCache->tbCache, msg->stbName, strlen(msg->stbName))) { ctgError("stb not exist in cache, dbFName:%s, stb:%s, suid:0x%"PRIx64, msg->dbFName, msg->stbName, msg->suid); } else { @@ -1780,14 +1798,24 @@ int32_t ctgOpDropTbMeta(SCtgCacheOperation *operation) { SCtgDBCache *dbCache = NULL; ctgGetDBCache(pCtg, msg->dbFName, &dbCache); if (NULL == dbCache) { - return TSDB_CODE_SUCCESS; + goto _return; } if (dbCache->dbId != msg->dbId) { ctgDebug("dbId 0x%" PRIx64 " not match with curId 0x%"PRIx64", dbFName:%s, tbName:%s", msg->dbId, dbCache->dbId, msg->dbFName, msg->tbName); - return TSDB_CODE_SUCCESS; + goto _return; } + SCtgTbCache* pTbCache = taosHashGet(dbCache->tbCache, msg->tbName, strlen(msg->tbName)); + if (NULL == pTbCache) { + ctgDebug("tb %s already not in cache", msg->tbName); + goto _return; + } + + CTG_LOCK(CTG_WRITE, &pTbCache->metaLock); + ctgFreeTbCacheImpl(pTbCache); + CTG_UNLOCK(CTG_WRITE, &pTbCache->metaLock); + if (taosHashRemove(dbCache->tbCache, msg->tbName, strlen(msg->tbName))) { ctgError("tb %s not exist in cache, dbFName:%s", msg->tbName, msg->dbFName); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); @@ -2063,6 +2091,8 @@ void* ctgUpdateThreadFunc(void* param) { if (operation->syncOp) { tsem_post(&operation->rspSem); + } else { + taosMemoryFreeClear(operation); } CTG_RT_STAT_INC(numOfOpDequeue, 1); diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 59ad009527..8e0a5b7de3 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -261,6 +261,8 @@ int32_t ctgHandleMsgCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { _return: + taosMemoryFree(pMsg->pData); + if (pJob) { taosReleaseRef(gCtgMgmt.jobPool, cbParam->refId); } diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index ad73fe40d2..a996a70973 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -152,6 +152,7 @@ void ctgFreeStbMetaCache(SCtgDBCache *dbCache) { } void ctgFreeTbCacheImpl(SCtgTbCache *pCache) { + qDebug("tbMeta freed, p:%p", pCache->pMeta); taosMemoryFreeClear(pCache->pMeta); if (pCache->pIndex) { taosArrayDestroyEx(pCache->pIndex->pIndex, tFreeSTableIndexInfo); @@ -831,6 +832,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput) if (output->tbMeta) { int32_t metaSize = CTG_META_SIZE(output->tbMeta); (*pOutput)->tbMeta = taosMemoryMalloc(metaSize); + qDebug("tbMeta cloned, size:%d, p:%p", metaSize, (*pOutput)->tbMeta); if (NULL == (*pOutput)->tbMeta) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); taosMemoryFreeClear(*pOutput); diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 3245fcd16a..51b721f818 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -109,7 +109,7 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.cacheLastRow = 0; + createReq.cacheLast = 0; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 7f70a78b12..a2816209a9 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -223,7 +223,7 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbFName, S "CREATE DATABASE `%s` BUFFER %d CACHELAST %d COMP %d DURATION %dm " "FSYNC %d MAXROWS %d MINROWS %d KEEP %dm,%dm,%dm PAGES %d PAGESIZE %d PRECISION '%s' REPLICA %d " "STRICT %d WAL %d VGROUPS %d SINGLE_STABLE %d", - dbFName, pCfg->buffer, pCfg->cacheLastRow, pCfg->compression, pCfg->daysPerFile, pCfg->fsyncPeriod, + dbFName, pCfg->buffer, pCfg->cacheLast, pCfg->compression, pCfg->daysPerFile, pCfg->fsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->daysToKeep0, pCfg->daysToKeep1, pCfg->daysToKeep2, pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->strict, pCfg->walLevel, pCfg->numOfVgroups, 1 == pCfg->numOfStables); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 72efaa165d..aab2f51421 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -389,6 +389,7 @@ typedef struct SStreamScanInfo { SSDataBlock* pPullDataRes; // pull data SSDataBlock SSDataBlock* pDeleteDataRes; // delete data SSDataBlock int32_t deleteDataIndex; + STimeWindow updateWin; // status for tmq // SSchemaWrapper schema; @@ -540,6 +541,9 @@ typedef struct SIndefOperatorInfo { SArray* pPseudoColInfo; SExprSupp scalarSup; SNode* pCondition; + uint64_t groupId; + + SSDataBlock* pNextGroupRes; } SIndefOperatorInfo; typedef struct SFillOperatorInfo { @@ -552,6 +556,7 @@ typedef struct SFillOperatorInfo { STimeWindow win; SNode* pCondition; SArray* pColMatchColInfo; + int32_t primaryTsCol; } SFillOperatorInfo; typedef struct SGroupbyOperatorInfo { @@ -775,6 +780,8 @@ int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLo int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList); void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win); +STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order); + int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t *order, int32_t* scanFlag); int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz); diff --git a/source/libs/executor/inc/tfill.h b/source/libs/executor/inc/tfill.h index 3b80b262ca..0349632b9a 100644 --- a/source/libs/executor/inc/tfill.h +++ b/source/libs/executor/inc/tfill.h @@ -42,6 +42,7 @@ typedef struct SFillInfo { TSKEY start; // start timestamp TSKEY end; // endKey for fill TSKEY currentKey; // current active timestamp, the value may be changed during the fill procedure. + int32_t tsSlotId; // primary time stamp slot id int32_t order; // order [TSDB_ORDER_ASC|TSDB_ORDER_DESC] int32_t type; // fill type int32_t numOfRows; // number of rows in the input data block @@ -74,8 +75,8 @@ struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, co bool taosFillHasMoreResults(struct SFillInfo* pFillInfo); SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols, - SInterval* pInterval, int32_t fillType, - struct SFillColInfo* pCol, const char* id); + SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t slotId, + const char* id); void* taosDestroyFillInfo(struct SFillInfo *pFillInfo); int64_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, SSDataBlock* p, int32_t capacity); diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c new file mode 100644 index 0000000000..7b1351a024 --- /dev/null +++ b/source/libs/executor/src/cachescanoperator.c @@ -0,0 +1,145 @@ +/* + * 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 "os.h" +#include "function.h" +#include "tname.h" + +#include "tdatablock.h" +#include "tmsg.h" + +#include "executorimpl.h" +#include "tcompare.h" +#include "thash.h" +#include "ttypes.h" +#include "executorInt.h" + +static SSDataBlock* doScanLastrow(SOperatorInfo* pOperator); +static void destroyLastrowScanOperator(void* param, int32_t numOfOutput); +static int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds); + +SOperatorInfo* createLastrowScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandle* readHandle, SArray* pTableList, + SExecTaskInfo* pTaskInfo) { + SLastrowScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SLastrowScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pInfo == NULL || pOperator == NULL) { + goto _error; + } + + pInfo->pTableList = pTableList; + pInfo->readHandle = *readHandle; + pInfo->pRes = createResDataBlock(pScanNode->node.pOutputDataBlockDesc); + + int32_t numOfCols = 0; + pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->pScanCols, pScanNode->node.pOutputDataBlockDesc, &numOfCols, + COL_MATCH_FROM_COL_ID); + int32_t* pCols = taosMemoryMalloc(numOfCols * sizeof(int32_t)); + for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) { + SColMatchInfo* pColMatch = taosArrayGet(pInfo->pColMatchInfo, i); + pCols[i] = pColMatch->colId; + } + + int32_t code = extractTargetSlotId(pInfo->pColMatchInfo, pTaskInfo, &pInfo->pSlotIds); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + tsdbLastRowReaderOpen(readHandle->vnode, LASTROW_RETRIEVE_TYPE_ALL, pTableList, taosArrayGetSize(pInfo->pColMatchInfo), + &pInfo->pLastrowReader); + taosMemoryFree(pCols); + + pOperator->name = "LastrowScanOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); + + initResultSizeInfo(pOperator, 1024); + blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); + + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doScanLastrow, NULL, NULL, destroyLastrowScanOperator, NULL, NULL, NULL); + pOperator->cost.openCost = 0; + return pOperator; + + _error: + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + return NULL; +} + +SSDataBlock* doScanLastrow(SOperatorInfo* pOperator) { + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + SLastrowScanInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + int32_t size = taosArrayGetSize(pInfo->pTableList); + if (size == 0) { + setTaskStatus(pTaskInfo, TASK_COMPLETED); + return NULL; + } + + // check if it is a group by tbname + if (size == taosArrayGetSize(pInfo->pTableList)) { + blockDataCleanup(pInfo->pRes); + tsdbRetrieveLastRow(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds); + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; + } else { + // todo fetch the result for each group + } + + return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; +} + +void destroyLastrowScanOperator(void* param, int32_t numOfOutput) { + SLastrowScanInfo* pInfo = (SLastrowScanInfo*)param; + blockDataDestroy(pInfo->pRes); + tsdbLastrowReaderClose(pInfo->pLastrowReader); + + taosMemoryFreeClear(param); +} + +int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds) { + size_t numOfCols = taosArrayGetSize(pColMatchInfo); + + *pSlotIds = taosMemoryMalloc(numOfCols * sizeof(int32_t)); + if (*pSlotIds == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + for (int32_t i = 0; i < numOfCols; ++i) { + SColMatchInfo* pColMatch = taosArrayGet(pColMatchInfo, i); + for (int32_t j = 0; j < pTaskInfo->schemaVer.sw->nCols; ++j) { + if (pColMatch->colId == pTaskInfo->schemaVer.sw->pSchema[j].colId && + pColMatch->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { + (*pSlotIds)[pColMatch->targetSlotId] = -1; + break; + } + + if (pColMatch->colId == pTaskInfo->schemaVer.sw->pSchema[j].colId) { + (*pSlotIds)[pColMatch->targetSlotId] = j; + break; + } + } + } + + return TSDB_CODE_SUCCESS; +} \ No newline at end of file diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index adbfa2c4ba..2469062d09 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -191,6 +191,7 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { pBlock->info.blockId = pNode->dataBlockId; pBlock->info.type = STREAM_INVALID; + pBlock->info.calWin = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; for (int32_t i = 0; i < numOfCols; ++i) { SSlotDescNode* pDescNode = (SSlotDescNode*)nodesListGetNode(pNode->pSlots, i); @@ -869,7 +870,7 @@ static STimeWindow doCalculateTimeWindow(int64_t ts, SInterval* pInterval) { return w; } -static STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order) { +STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order) { int32_t factor = (order == TSDB_ORDER_ASC)? -1:1; STimeWindow win = *pWindow; diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 9f6b12c13a..6e4f02527f 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -106,6 +106,30 @@ int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numO return code; } +qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers) { + if (msg == NULL) { + // TODO create raw scan + return NULL; + } + + struct SSubplan* plan = NULL; + int32_t code = qStringToSubplan(msg, &plan); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return NULL; + } + + qTaskInfo_t pTaskInfo = NULL; + code = qCreateExecTask(readers, 0, 0, plan, &pTaskInfo, NULL, NULL, OPTR_EXEC_MODEL_QUEUE); + if (code != TSDB_CODE_SUCCESS) { + // TODO: destroy SSubplan & pTaskInfo + terrno = code; + return NULL; + } + + return pTaskInfo; +} + qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers) { if (msg == NULL) { return NULL; @@ -186,7 +210,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo } int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, - int32_t* tversion) { + int32_t* tversion) { ASSERT(tinfo != NULL && dbName != NULL && tableName != NULL); SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; diff --git a/source/libs/executor/src/executorMain.c b/source/libs/executor/src/executorMain.c index b30800680b..5d9fea523c 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -269,13 +269,13 @@ const STqOffset* qExtractStatusFromStreamScanner(void* scanner) { void* qStreamExtractMetaMsg(qTaskInfo_t tinfo) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); + ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE); return pTaskInfo->streamInfo.metaBlk; } int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); + ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE); memcpy(pOffset, &pTaskInfo->streamInfo.lastStatus, sizeof(STqOffsetVal)); return 0; } @@ -283,35 +283,41 @@ int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) { int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; SOperatorInfo* pOperator = pTaskInfo->pRoot; - ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); + ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE); pTaskInfo->streamInfo.prepareStatus = *pOffset; - // TODO: optimize - /*if (pTaskInfo->streamInfo.lastStatus.type != pOffset->type ||*/ - /*pTaskInfo->streamInfo.prepareStatus.version != pTaskInfo->streamInfo.lastStatus.version) {*/ - while (1) { - uint8_t type = pOperator->operatorType; - pOperator->status = OP_OPENED; - if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { - SStreamScanInfo* pInfo = pOperator->info; - if (pOffset->type == TMQ_OFFSET__LOG) { - if (tqSeekVer(pInfo->tqReader, pOffset->version) < 0) { - return -1; - } - ASSERT(pInfo->tqReader->pWalReader->curVersion == pOffset->version); - } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) { - /*pInfo->blockType = STREAM_INPUT__TABLE_SCAN;*/ - int64_t uid = pOffset->uid; - int64_t ts = pOffset->ts; - - if (uid == 0) { - if (taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList) != 0) { - STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, 0); - uid = pTableInfo->uid; - ts = INT64_MIN; + if (!tOffsetEqual(pOffset, &pTaskInfo->streamInfo.lastStatus)) { + while (1) { + uint8_t type = pOperator->operatorType; + pOperator->status = OP_OPENED; + if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { + SStreamScanInfo* pInfo = pOperator->info; + if (pOffset->type == TMQ_OFFSET__LOG) { +#if 0 + if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.lastStatus) && + pInfo->tqReader->pWalReader->curVersion != pOffset->version) { + qError("prepare scan ver %ld actual ver %ld, last %ld", pOffset->version, + pInfo->tqReader->pWalReader->curVersion, pTaskInfo->streamInfo.lastStatus.version); + ASSERT(0); } - } - if (pTaskInfo->streamInfo.lastStatus.type != TMQ_OFFSET__SNAPSHOT_DATA || - pTaskInfo->streamInfo.lastStatus.uid != uid || pTaskInfo->streamInfo.lastStatus.ts != ts) { +#endif + if (tqSeekVer(pInfo->tqReader, pOffset->version + 1) < 0) { + return -1; + } + ASSERT(pInfo->tqReader->pWalReader->curVersion == pOffset->version + 1); + } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) { + /*pInfo->blockType = STREAM_INPUT__TABLE_SCAN;*/ + int64_t uid = pOffset->uid; + int64_t ts = pOffset->ts; + + if (uid == 0) { + if (taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList) != 0) { + STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, 0); + uid = pTableInfo->uid; + ts = INT64_MIN; + } + } + /*if (pTaskInfo->streamInfo.lastStatus.type != TMQ_OFFSET__SNAPSHOT_DATA ||*/ + /*pTaskInfo->streamInfo.lastStatus.uid != uid || pTaskInfo->streamInfo.lastStatus.ts != ts) {*/ STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info; int32_t tableSz = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList); bool found = false; @@ -320,6 +326,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset) { if (pTableInfo->uid == uid) { found = true; pTableScanInfo->currentTable = i; + break; } } @@ -335,18 +342,18 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, const STqOffsetVal* pOffset) { qDebug("tsdb reader offset seek to uid %ld ts %ld, table cur set to %d , all table num %d", uid, ts, pTableScanInfo->currentTable, tableSz); - } + /*}*/ + } else { + ASSERT(0); + } + return 0; } else { - ASSERT(0); + ASSERT(pOperator->numOfDownstream == 1); + pOperator = pOperator->pDownstream[0]; } - return 0; - } else { - ASSERT(pOperator->numOfDownstream == 1); - pOperator = pOperator->pDownstream[0]; } } - /*}*/ return 0; } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 1de02e3545..6f4a6b805d 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -538,16 +538,14 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt return code; } -static int32_t doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunctionCtx* pCtx) { +static int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) { for (int32_t k = 0; k < pOperator->exprSupp.numOfExprs; ++k) { if (functionNeedToExecute(&pCtx[k])) { // todo add a dummy funtion to avoid process check if (pCtx[k].fpSet.process == NULL) { continue; } -#ifdef BUF_PAGE_DEBUG - qDebug("page_process"); -#endif + int32_t code = pCtx[k].fpSet.process(&pCtx[k]); if (code != TSDB_CODE_SUCCESS) { qError("%s aggregate function error happens, code: %s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code)); @@ -571,34 +569,39 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc setPseudoOutputColInfo(pResult, pCtx, pPseudoList); pResult->info.groupId = pSrcBlock->info.groupId; - // if the source equals to the destination, it is to create a new column as the result of scalar function or some - // operators. + // if the source equals to the destination, it is to create a new column as the result of scalar + // function or some operators. bool createNewColModel = (pResult == pSrcBlock); int32_t numOfRows = 0; for (int32_t k = 0; k < numOfOutput; ++k) { - int32_t outputSlotId = pExpr[k].base.resSchema.slotId; - SqlFunctionCtx* pfCtx = &pCtx[k]; + int32_t outputSlotId = pExpr[k].base.resSchema.slotId; + SqlFunctionCtx* pfCtx = &pCtx[k]; + SInputColumnInfoData* pInputData = &pfCtx->input; if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); if (pResult->info.rows > 0 && !createNewColModel) { - colDataMergeCol(pColInfoData, pResult->info.rows, &pResult->info.capacity, pfCtx->input.pData[0], - pfCtx->input.numOfRows); + colDataMergeCol(pColInfoData, pResult->info.rows, &pResult->info.capacity, pInputData->pData[0], + pInputData->numOfRows); } else { - colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows, &pResult->info); + colDataAssign(pColInfoData, pInputData->pData[0], pInputData->numOfRows, &pResult->info); } - numOfRows = pfCtx->input.numOfRows; + numOfRows = pInputData->numOfRows; } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_VALUE) { SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); int32_t offset = createNewColModel ? 0 : pResult->info.rows; - for (int32_t i = 0; i < pSrcBlock->info.rows; ++i) { - colDataAppend(pColInfoData, i + offset, - taosVariantGet(&pExpr[k].base.pParam[0].param, pExpr[k].base.pParam[0].param.nType), - TSDB_DATA_TYPE_NULL == pExpr[k].base.pParam[0].param.nType); + + int32_t type = pExpr[k].base.pParam[0].param.nType; + if (TSDB_DATA_TYPE_NULL == type) { + colDataAppendNNULL(pColInfoData, offset, pSrcBlock->info.rows); + } else { + for (int32_t i = 0; i < pSrcBlock->info.rows; ++i) { + colDataAppend(pColInfoData, i + offset, taosVariantGet(&pExpr[k].base.pParam[0].param, type), false); + } } numOfRows = pSrcBlock->info.rows; @@ -623,14 +626,12 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc numOfRows = dest.numOfRows; taosArrayDestroy(pBlockList); } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_FUNCTION) { - ASSERT(!fmIsAggFunc(pfCtx->functionId)); - // _rowts/_c0, not tbname column if (fmIsPseudoColumnFunc(pfCtx->functionId) && (!fmIsScanPseudoColumnFunc(pfCtx->functionId))) { // do nothing } else if (fmIsIndefiniteRowsFunc(pfCtx->functionId)) { - SResultRowEntryInfo* pResInfo = GET_RES_INFO(&pCtx[k]); - pfCtx->fpSet.init(&pCtx[k], pResInfo); + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pfCtx); + pfCtx->fpSet.init(pfCtx, pResInfo); pfCtx->pOutput = taosArrayGet(pResult->pDataBlock, outputSlotId); pfCtx->offset = createNewColModel ? 0 : pResult->info.rows; // set the start offset @@ -642,6 +643,23 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc } numOfRows = pfCtx->fpSet.process(pfCtx); + } else if (fmIsAggFunc(pfCtx->functionId)) { + // _group_key function for "partition by tbname" + csum(col_name) query + SColumnInfoData* pOutput = taosArrayGet(pResult->pDataBlock, outputSlotId); + int32_t slotId = pfCtx->param[0].pCol->slotId; + + // todo handle the json tag + SColumnInfoData* pInput = taosArrayGet(pSrcBlock->pDataBlock, slotId); + for (int32_t f = 0; f < pSrcBlock->info.rows; ++f) { + bool isNull = colDataIsNull_s(pInput, f); + if (isNull) { + colDataAppendNULL(pOutput, pResult->info.rows + f); + } else { + char* data = colDataGetData(pInput, f); + colDataAppend(pOutput, pResult->info.rows + f, data, isNull); + } + } + } else { SArray* pBlockList = taosArrayInit(4, POINTER_BYTES); taosArrayPush(pBlockList, &pSrcBlock); @@ -675,25 +693,6 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc return TSDB_CODE_SUCCESS; } -static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { - if (IS_VAR_DATA_TYPE(type)) { - // todo disable this - - // if (pResultRow->key == NULL) { - // pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); - // varDataCopy(pResultRow->key, pData); - // } else { - // ASSERT(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); - // } - } else { - int64_t v = -1; - GET_TYPED_DATA(v, int64_t, type, pData); - - pResultRow->win.skey = v; - pResultRow->win.ekey = v; - } -} - bool functionNeedToExecute(SqlFunctionCtx* pCtx) { struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); @@ -2447,7 +2446,6 @@ _error: doDestroyExchangeOperatorInfo(pInfo); } - taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; @@ -2975,25 +2973,10 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { // the pDataBlock are always the same one, no need to call this again setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.groupId, pAggInfo); setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, true); - code = doAggregateImpl(pOperator, 0, pSup->pCtx); + code = doAggregateImpl(pOperator, pSup->pCtx); if (code != 0) { longjmp(pTaskInfo->env, code); } - -#if 0 // test for encode/decode result info - if(pOperator->fpSet.encodeResultRow){ - char *result = NULL; - int32_t length = 0; - pOperator->fpSet.encodeResultRow(pOperator, &result, &length); - SAggSupporter* pSup = &pAggInfo->aggSup; - taosHashClear(pSup->pResultRowHashTable); - pInfo->resultRowInfo.size = 0; - pOperator->fpSet.decodeResultRow(pOperator, result); - if(result){ - taosMemoryFree(result); - } - } -#endif } closeAllResultRows(&pAggInfo->binfo.resultRowInfo); @@ -3256,6 +3239,10 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_EXEC_DONE) { + if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) { + pOperator->status = OP_OPENED; + return NULL; + } return NULL; } @@ -3289,11 +3276,15 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { while (1) { // The downstream exec may change the value of the newgroup, so use a local variable instead. + qDebug("projection call next"); SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); if (pBlock == NULL) { - // TODO optimize - /*if (pTaskInfo->execModel != OPTR_EXEC_MODEL_STREAM) {*/ + qDebug("projection get null"); + + /*if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH) {*/ doSetOperatorCompleted(pOperator); + /*} else if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {*/ + /*pOperator->status = OP_RES_TO_RETURN;*/ /*}*/ break; } @@ -3397,6 +3388,8 @@ static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) { assert(pBlock != NULL); } + blockDataUpdateTsWindow(pBlock, pInfo->primaryTsCol); + if (*newgroup && pInfo->totalInputRows > 0) { // there are already processed current group data block pInfo->existNewGroupBlock = pBlock; *newgroup = false; @@ -3508,11 +3501,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { pOperator->numOfDownstream = 0; } - if (pOperator->exprSupp.pExprInfo != NULL) { - destroyExprInfo(pOperator->exprSupp.pExprInfo, pOperator->exprSupp.numOfExprs); - } - - taosMemoryFreeClear(pOperator->exprSupp.pExprInfo); + cleanupExprSupp(&pOperator->exprSupp); taosMemoryFreeClear(pOperator); } @@ -3591,6 +3580,25 @@ void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) { initResultRowInfo(&pInfo->resultRowInfo); } +static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) { + if (pCtx == NULL) { + return NULL; + } + + for (int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) { + taosVariantDestroy(&pCtx[i].param[j].param); + } + + taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx); + taosMemoryFree(pCtx[i].input.pData); + taosMemoryFree(pCtx[i].input.pColumnDataAgg); + } + + taosMemoryFreeClear(pCtx); + return NULL; +} + int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr) { pSup->pExprInfo = pExprInfo; pSup->numOfExprs = numOfExpr; @@ -3604,6 +3612,16 @@ int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr) { return TSDB_CODE_SUCCESS; } +void cleanupExprSupp(SExprSupp* pSupp) { + destroySqlFunctionCtx(pSupp->pCtx, pSupp->numOfExprs); + if (pSupp->pExprInfo != NULL) { + destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs); + } + + taosMemoryFreeClear(pSupp->pExprInfo); + taosMemoryFree(pSupp->rowEntryInfoOffset); +} + SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo) { @@ -3654,25 +3672,6 @@ _error: return NULL; } -static void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput) { - if (pCtx == NULL) { - return NULL; - } - - for (int32_t i = 0; i < numOfOutput; ++i) { - for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) { - taosVariantDestroy(&pCtx[i].param[j].param); - } - - taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx); - taosMemoryFree(pCtx[i].input.pData); - taosMemoryFree(pCtx[i].input.pColumnDataAgg); - } - - taosMemoryFreeClear(pCtx); - return NULL; -} - void cleanupBasicInfo(SOptrBasicInfo* pInfo) { assert(pInfo != NULL); cleanupResultRowInfo(&pInfo->resultRowInfo); @@ -3714,13 +3713,6 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) { taosMemoryFreeClear(param); } -void cleanupExprSupp(SExprSupp* pSupp) { - destroySqlFunctionCtx(pSupp->pCtx, pSupp->numOfExprs); - destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs); - - taosMemoryFree(pSupp->rowEntryInfoOffset); -} - static void destroyIndefinitOperatorInfo(void* param, int32_t numOfOutput) { SIndefOperatorInfo* pInfo = (SIndefOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); @@ -3825,6 +3817,41 @@ _error: return NULL; } +static void doHandleDataBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, SOperatorInfo* downstream, + SExecTaskInfo* pTaskInfo) { + int32_t order = 0; + int32_t scanFlag = 0; + + SIndefOperatorInfo* pIndefInfo = pOperator->info; + SOptrBasicInfo* pInfo = &pIndefInfo->binfo; + SExprSupp* pSup = &pOperator->exprSupp; + + // the pDataBlock are always the same one, no need to call this again + int32_t code = getTableScanInfo(downstream, &order, &scanFlag); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + + // there is an scalar expression that needs to be calculated before apply the group aggregation. + SExprSupp* pScalarSup = &pIndefInfo->scalarSup; + if (pScalarSup->pExprInfo != NULL) { + code = projectApplyFunctions(pScalarSup->pExprInfo, pBlock, pBlock, pScalarSup->pCtx, pScalarSup->numOfExprs, + pIndefInfo->pPseudoColInfo); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + } + + setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); + blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); + + code = projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, + pIndefInfo->pPseudoColInfo); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } +} + static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { SIndefOperatorInfo* pIndefInfo = pOperator->info; SOptrBasicInfo* pInfo = &pIndefInfo->binfo; @@ -3839,8 +3866,6 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { } int64_t st = 0; - int32_t order = 0; - int32_t scanFlag = 0; if (pOperator->cost.openCost == 0) { st = taosGetTimestampUs(); @@ -3849,41 +3874,53 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { - // The downstream exec may change the value of the newgroup, so use a local variable instead. - SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); - if (pBlock == NULL) { - doSetOperatorCompleted(pOperator); - break; + // here we need to handle the existsed group results + if (pIndefInfo->pNextGroupRes != NULL) { // todo extract method + for (int32_t k = 0; k < pSup->numOfExprs; ++k) { + SqlFunctionCtx* pCtx = &pSup->pCtx[k]; + + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + pResInfo->initialized = false; + pCtx->pOutput = NULL; + } + + doHandleDataBlock(pOperator, pIndefInfo->pNextGroupRes, downstream, pTaskInfo); + pIndefInfo->pNextGroupRes = NULL; } - // the pDataBlock are always the same one, no need to call this again - int32_t code = getTableScanInfo(pOperator->pDownstream[0], &order, &scanFlag); - if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, code); - } + if (pInfo->pRes->info.rows < pOperator->resultInfo.threshold) { + while (1) { + // The downstream exec may change the value of the newgroup, so use a local variable instead. + SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); + if (pBlock == NULL) { + doSetOperatorCompleted(pOperator); + break; + } - // there is an scalar expression that needs to be calculated before apply the group aggregation. - SExprSupp* pScalarSup = &pIndefInfo->scalarSup; - if (pScalarSup->pExprInfo != NULL) { - code = projectApplyFunctions(pScalarSup->pExprInfo, pBlock, pBlock, pScalarSup->pCtx, pScalarSup->numOfExprs, - pIndefInfo->pPseudoColInfo); - if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, code); + if (pIndefInfo->groupId == 0 && pBlock->info.groupId != 0) { + pIndefInfo->groupId = pBlock->info.groupId; // this is the initial group result + } else { + if (pIndefInfo->groupId != pBlock->info.groupId) { // reset output buffer and computing status + pIndefInfo->groupId = pBlock->info.groupId; + pIndefInfo->pNextGroupRes = pBlock; + break; + } + } + + doHandleDataBlock(pOperator, pBlock, downstream, pTaskInfo); + if (pInfo->pRes->info.rows >= pOperator->resultInfo.threshold) { + break; + } } } - setInputDataBlock(pOperator, pSup->pCtx, pBlock, order, scanFlag, false); - blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); - - code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, - pOperator->exprSupp.numOfExprs, pIndefInfo->pPseudoColInfo); - if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, code); + doFilter(pIndefInfo->pCondition, pInfo->pRes); + size_t rows = pInfo->pRes->info.rows; + if (rows >= 0) { + break; } } - doFilter(pIndefInfo->pCondition, pInfo->pRes); - size_t rows = pInfo->pRes->info.rows; pOperator->resultInfo.totalRows += rows; @@ -3928,24 +3965,23 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy if (numOfRows * pResBlock->info.rowSize > TWOMB) { numOfRows = TWOMB / pResBlock->info.rowSize; } + initResultSizeInfo(pOperator, numOfRows); - initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfExpr, keyBufSize, pTaskInfo->id.str); + initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfExpr, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); setFunctionResultOutput(pOperator, &pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfExpr); pInfo->binfo.pRes = pResBlock; - pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pSup->pCtx, numOfExpr); pInfo->pCondition = pPhyNode->node.pConditions; + pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pSup->pCtx, numOfExpr); pOperator->name = "IndefinitOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC; pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->exprSupp.numOfExprs = numOfExpr; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL, @@ -3971,12 +4007,15 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t STimeWindow w = TSWINDOW_INITIALIZER; getAlignQueryTimeWindow(pInterval, pInterval->precision, win.skey, &w); + w = getFirstQualifiedTimeWindow(win.skey, &w, pInterval, TSDB_ORDER_ASC); int32_t order = TSDB_ORDER_ASC; - pInfo->pFillInfo = taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval, fillType, pColInfo, id); + pInfo->pFillInfo = taosCreateFillInfo(order, w.skey, 0, capacity, numOfCols, pInterval, + fillType, pColInfo, pInfo->primaryTsCol, id); pInfo->win = win; pInfo->p = taosMemoryCalloc(numOfCols, POINTER_BYTES); + if (pInfo->pFillInfo == NULL || pInfo->p == NULL) { taosMemoryFree(pInfo->pFillInfo); taosMemoryFree(pInfo->p); @@ -4006,10 +4045,11 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* SResultInfo* pResultInfo = &pOperator->resultInfo; initResultSizeInfo(pOperator, 4096); + pInfo->primaryTsCol = ((SColumnNode*)pPhyFillNode->pWStartTs)->slotId; int32_t numOfOutputCols = 0; - SArray* pColMatchColInfo = - extractColMatchInfo(pPhyFillNode->pTargets, pPhyFillNode->node.pOutputDataBlockDesc, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); + SArray* pColMatchColInfo = extractColMatchInfo(pPhyFillNode->pTargets, pPhyFillNode->node.pOutputDataBlockDesc, + &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); int32_t code = initFillInfo(pInfo, pExprInfo, num, (SNodeListNode*)pPhyFillNode->pValues, pPhyFillNode->timeRange, pResultInfo->capacity, pTaskInfo->id.str, pInterval, type); @@ -4017,18 +4057,18 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* goto _error; } - pInfo->pRes = pResBlock; - pInfo->multigroupResult = multigroupResult; - pInfo->pCondition = pPhyFillNode->node.pConditions; - pInfo->pColMatchColInfo = pColMatchColInfo; - pOperator->name = "FillOperator"; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_FILL; - pOperator->exprSupp.pExprInfo = pExprInfo; + pInfo->pRes = pResBlock; + pInfo->multigroupResult = multigroupResult; + pInfo->pCondition = pPhyFillNode->node.pConditions; + pInfo->pColMatchColInfo = pColMatchColInfo; + pOperator->name = "FillOperator"; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_FILL; + pOperator->exprSupp.pExprInfo = pExprInfo; pOperator->exprSupp.numOfExprs = num; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroySFillOperatorInfo, NULL, NULL, NULL); @@ -4078,6 +4118,8 @@ int32_t extractTableSchemaInfo(SReadHandle* pHandle, uint64_t uid, SExecTaskInfo pTaskInfo->schemaVer.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow); pTaskInfo->schemaVer.tversion = mr.me.stbEntry.schemaTag.version; } else if (mr.me.type == TSDB_CHILD_TABLE) { + tDecoderClear(&mr.coder); + tb_uid_t suid = mr.me.ctbEntry.suid; metaGetTableEntryByUid(&mr, suid); pTaskInfo->schemaVer.sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 311d7f0d5a..ee20bc7ba6 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -637,6 +637,7 @@ static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) { int32_t* pageId = taosArrayGet(pGroupInfo->pPageList, pInfo->pageIndex); void* page = getBufPage(pInfo->pBuf, *pageId); + blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->rowCapacity); blockDataFromBuf1(pInfo->binfo.pRes, page, pInfo->rowCapacity); pInfo->pageIndex += 1; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 407f799496..64c740decf 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -578,6 +578,7 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) { taosArrayDestroy(pTableScanInfo->pColMatchInfo); } + cleanupExprSupp(&pTableScanInfo->pseudoSup); taosMemoryFreeClear(param); } @@ -883,6 +884,28 @@ static bool prepareRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pBlock, int32_ return true; } +static STimeWindow getSlidingWindow(TSKEY* tsCol, SInterval* pInterval, SDataBlockInfo* pDataBlockInfo, int32_t* pRowIndex) { + SResultRowInfo dumyInfo; + dumyInfo.cur.pageId = -1; + STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCol[*pRowIndex], pInterval, + TSDB_ORDER_ASC); + STimeWindow endWin = win; + STimeWindow preWin = win; + while (1) { + (*pRowIndex) += getNumOfRowsInTimeWindow(pDataBlockInfo, tsCol, *pRowIndex, endWin.ekey, + binarySearchForKey, NULL, TSDB_ORDER_ASC); + do { + preWin = endWin; + getNextTimeWindow(pInterval, &endWin, TSDB_ORDER_ASC); + } while (tsCol[(*pRowIndex) - 1] >= endWin.skey); + endWin = preWin; + if (win.ekey == endWin.ekey || (*pRowIndex) == pDataBlockInfo->rows ) { + win.ekey = endWin.ekey; + return win; + } + win.ekey = endWin.ekey; + } +} static bool prepareDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_t tsColIndex, int32_t* pRowIndex) { STimeWindow win = { .skey = INT64_MIN, @@ -904,10 +927,13 @@ static bool prepareDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_t t setGroupId(pInfo, pSDB, GROUPID_COLUMN_INDEX, *pRowIndex); (*pRowIndex) += updateSessionWindowInfo(pCurWin, tsCols, NULL, pSDB->info.rows, *pRowIndex, gap, NULL); } else { - win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[*pRowIndex], &pInfo->interval, TSDB_ORDER_ASC); setGroupId(pInfo, pSDB, GROUPID_COLUMN_INDEX, *pRowIndex); - (*pRowIndex) += - getNumOfRowsInTimeWindow(&pSDB->info, tsCols, *pRowIndex, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); + pInfo->updateWin.skey = tsCols[*pRowIndex]; + win = getSlidingWindow(tsCols, &pInfo->interval, &pSDB->info, pRowIndex); + pInfo->updateWin.ekey = tsCols[*pRowIndex - 1]; + // win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[*pRowIndex], &pInfo->interval, TSDB_ORDER_ASC); + // (*pRowIndex) += + // getNumOfRowsInTimeWindow(&pSDB->info, tsCols, *pRowIndex, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); } needRead = true; } else if (isStateWindow(pInfo)) { @@ -973,10 +999,12 @@ static SSDataBlock* doDataScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32_ } } if (!pResult) { + pInfo->updateWin = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; return NULL; } if (pResult->info.groupId == pInfo->groupId) { + pResult->info.calWin = pInfo->updateWin; return pResult; } } @@ -1134,12 +1162,6 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock pInfo->pRes->info.type = STREAM_NORMAL; pInfo->pRes->info.capacity = pBlock->info.rows; - // for generating rollup SMA result, each time is an independent time serie. - // TODO temporarily used, when the statement of "partition by tbname" is ready, remove this - if (pInfo->assignBlockUid) { - pInfo->pRes->info.groupId = pBlock->info.uid; - } - uint64_t* groupIdPre = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t)); if (groupIdPre) { pInfo->pRes->info.groupId = *groupIdPre; @@ -1147,6 +1169,12 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock pInfo->pRes->info.groupId = 0; } + // for generating rollup SMA result, each time is an independent time serie. + // TODO temporarily used, when the statement of "partition by tbname" is ready, remove this + if (pInfo->assignBlockUid) { + pInfo->pRes->info.groupId = pBlock->info.uid; + } + // todo extract method for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) { SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); @@ -1208,6 +1236,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { /*return NULL;*/ /*}*/ + qDebug("stream scan called"); if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__LOG) { while (1) { SFetchRet ret = {0}; @@ -1219,6 +1248,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } // TODO clean data block if (pInfo->pRes->info.rows > 0) { + qDebug("stream scan log return %d rows", pInfo->pRes->info.rows); return pInfo->pRes; } } else if (ret.fetchType == FETCH_TYPE__META) { @@ -1229,6 +1259,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } else if (ret.fetchType == FETCH_TYPE__NONE) { pTaskInfo->streamInfo.lastStatus = ret.offset; ASSERT(pTaskInfo->streamInfo.lastStatus.version + 1 >= pTaskInfo->streamInfo.prepareStatus.version); + qDebug("stream scan log return null"); return NULL; } else { ASSERT(0); @@ -1236,7 +1267,12 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } } else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) { SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp); - return pResult && pResult->info.rows > 0 ? pResult : NULL; + if (pResult && pResult->info.rows > 0) { + qDebug("stream scan tsdb return %d rows", pResult->info.rows); + return pResult; + } + qDebug("stream scan tsdb return null"); + return NULL; } else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_META) { // TODO scan meta ASSERT(0); @@ -1255,8 +1291,13 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { int32_t current = pInfo->validBlockIndex++; SSDataBlock* pBlock = taosArrayGetP(pInfo->pBlockLists, current); // TODO move into scan + pBlock->info.calWin.skey = INT64_MIN; + pBlock->info.calWin.ekey = INT64_MAX; blockDataUpdateTsWindow(pBlock, 0); switch (pBlock->info.type) { + case STREAM_NORMAL: + case STREAM_GET_ALL: + return pBlock; case STREAM_RETRIEVE: { pInfo->blockType = STREAM_INPUT__DATA_SUBMIT; pInfo->scanMode = STREAM_SCAN_FROM_DATAREADER_RETRIEVE; @@ -1286,6 +1327,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } return pBlock; } else if (pInfo->blockType == STREAM_INPUT__DATA_SUBMIT) { + qDebug("scan mode %d", pInfo->scanMode); if (pInfo->scanMode == STREAM_SCAN_FROM_RES) { blockDataDestroy(pInfo->pUpdateRes); pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; @@ -1380,7 +1422,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } } } - + qDebug("scan rows: %d", pBlockInfo->rows); return (pBlockInfo->rows == 0) ? NULL : pInfo->pRes; #if 0 @@ -1532,6 +1574,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys pInfo->pStreamScanOp = pOperator; pInfo->deleteDataIndex = 0; pInfo->pDeleteDataRes = createPullDataBlock(); + pInfo->updateWin = (STimeWindow){.skey = INT64_MAX, .ekey = INT64_MAX}; pOperator->name = "StreamScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; @@ -2859,101 +2902,3 @@ _error: return NULL; } -static SSDataBlock* doScanLastrow(SOperatorInfo* pOperator) { - if (pOperator->status == OP_EXEC_DONE) { - return NULL; - } - - SLastrowScanInfo* pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - int32_t size = taosArrayGetSize(pInfo->pTableList); - if (size == 0) { - setTaskStatus(pTaskInfo, TASK_COMPLETED); - return NULL; - } - - // check if it is a group by tbname - if (size == taosArrayGetSize(pInfo->pTableList)) { - blockDataCleanup(pInfo->pRes); - tsdbRetrieveLastRow(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds); - return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; - } else { - // todo fetch the result for each group - } - - return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; -} - -static void destroyLastrowScanOperator(void* param, int32_t numOfOutput) { - SLastrowScanInfo* pInfo = (SLastrowScanInfo*)param; - blockDataDestroy(pInfo->pRes); - tsdbLastrowReaderClose(pInfo->pLastrowReader); - - taosMemoryFreeClear(param); -} - -SOperatorInfo* createLastrowScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandle* readHandle, SArray* pTableList, - SExecTaskInfo* pTaskInfo) { - SLastrowScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SLastrowScanInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL) { - goto _error; - } - - pInfo->pTableList = pTableList; - pInfo->readHandle = *readHandle; - pInfo->pRes = createResDataBlock(pScanNode->node.pOutputDataBlockDesc); - - int32_t numOfCols = 0; - pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->pScanCols, pScanNode->node.pOutputDataBlockDesc, &numOfCols, - COL_MATCH_FROM_COL_ID); - int32_t* pCols = taosMemoryMalloc(numOfCols * sizeof(int32_t)); - for (int32_t i = 0; i < numOfCols; ++i) { - SColMatchInfo* pColMatch = taosArrayGet(pInfo->pColMatchInfo, i); - pCols[i] = pColMatch->colId; - } - - pInfo->pSlotIds = taosMemoryMalloc(numOfCols * sizeof(pInfo->pSlotIds[0])); - for (int32_t i = 0; i < numOfCols; ++i) { - SColMatchInfo* pColMatch = taosArrayGet(pInfo->pColMatchInfo, i); - for (int32_t j = 0; j < pTaskInfo->schemaVer.sw->nCols; ++j) { - if (pColMatch->colId == pTaskInfo->schemaVer.sw->pSchema[j].colId && - pColMatch->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { - pInfo->pSlotIds[pColMatch->targetSlotId] = -1; - break; - } - - if (pColMatch->colId == pTaskInfo->schemaVer.sw->pSchema[j].colId) { - pInfo->pSlotIds[pColMatch->targetSlotId] = j; - break; - } - } - } - - tsdbLastRowReaderOpen(readHandle->vnode, LASTROW_RETRIEVE_TYPE_ALL, pTableList, pCols, numOfCols, - &pInfo->pLastrowReader); - taosMemoryFree(pCols); - - pOperator->name = "LastrowScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); - - initResultSizeInfo(pOperator, 1024); - blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); - - pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doScanLastrow, NULL, NULL, destroyLastrowScanOperator, NULL, NULL, NULL); - pOperator->cost.openCost = 0; - return pOperator; - -_error: - pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; - taosMemoryFree(pInfo); - taosMemoryFree(pOperator); - return NULL; -} diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index b0e2166baf..c008c7c4a9 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -14,6 +14,7 @@ */ #include "os.h" +#include "query.h" #include "taosdef.h" #include "tmsg.h" #include "ttypes.h" @@ -48,14 +49,15 @@ static void setTagsValue(SFillInfo* pFillInfo, void** data, int32_t genRows) { } } -static void setNullRow(SSDataBlock* pBlock, int32_t numOfCol, int32_t rowIndex) { +static void setNullRow(SSDataBlock* pBlock, int64_t ts, int32_t rowIndex) { // the first are always the timestamp column, so start from the second column. for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* p = taosArrayGet(pBlock->pDataBlock, i); - if (p->info.type == TSDB_DATA_TYPE_TIMESTAMP && i == 0) { - continue; + if (p->info.type == TSDB_DATA_TYPE_TIMESTAMP) { + colDataAppend(p, rowIndex, (const char*)&ts, false); + } else { + colDataAppendNULL(p, rowIndex); } - colDataAppendNULL(p, rowIndex); } } @@ -64,16 +66,17 @@ static void setNullRow(SSDataBlock* pBlock, int32_t numOfCol, int32_t rowIndex) static void doSetVal(SColumnInfoData* pDstColInfoData, int32_t rowIndex, const SGroupKeys* pKey); -static void doFillOneRowResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSDataBlock* pSrcBlock, int64_t ts, - bool outOfBound) { +static void doFillOneRow(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSDataBlock* pSrcBlock, int64_t ts, + bool outOfBound) { SPoint point1, point2, point; int32_t step = GET_FORWARD_DIRECTION_FACTOR(pFillInfo->order); // set the primary timestamp column value int32_t index = pFillInfo->numOfCurrent; - SColumnInfoData* pCol0 = taosArrayGet(pBlock->pDataBlock, 0); + SColumnInfoData* pCol0 = taosArrayGet(pBlock->pDataBlock, pFillInfo->tsSlotId); char* val = colDataGetData(pCol0, index); + // set the primary timestamp value *(TSKEY*)val = pFillInfo->currentKey; // set the other values @@ -92,7 +95,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSData } } else if (pFillInfo->type == TSDB_FILL_NEXT) { SArray* p = FILL_IS_ASC_FILL(pFillInfo) ? pFillInfo->next : pFillInfo->prev; - + // todo refactor: start from 0 not 1 for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) { SFillColInfo* pCol = &pFillInfo->pFillCol[i]; if (TSDB_COL_IS_TAG(pCol->flag)) { @@ -106,7 +109,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSData } else if (pFillInfo->type == TSDB_FILL_LINEAR) { // TODO : linear interpolation supports NULL value if (outOfBound) { - setNullRow(pBlock, pFillInfo->numOfCols, index); + setNullRow(pBlock, pFillInfo->currentKey, index); } else { for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) { SFillColInfo* pCol = &pFillInfo->pFillCol[i]; @@ -143,7 +146,7 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSData } } } else if (pFillInfo->type == TSDB_FILL_NULL) { // fill with NULL - setNullRow(pBlock, pFillInfo->numOfCols, index); + setNullRow(pBlock, pFillInfo->currentKey, index); } else { // fill with user specified value for each column for (int32_t i = 1; i < pFillInfo->numOfCols; ++i) { SFillColInfo* pCol = &pFillInfo->pFillCol[i]; @@ -166,6 +169,8 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, SSData int64_t v = 0; GET_TYPED_DATA(v, int64_t, pVar->nType, &pVar->i); colDataAppend(pDst, index, (char*)&v, false); + } else if (pDst->info.type == TSDB_DATA_TYPE_TIMESTAMP) { + colDataAppend(pDst, index, (const char*)&pFillInfo->currentKey, false); } } } @@ -247,7 +252,7 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, SSDataBlock* pBlock, int32_t // fill the gap between two input rows while (((pFillInfo->currentKey < ts && ascFill) || (pFillInfo->currentKey > ts && !ascFill)) && pFillInfo->numOfCurrent < outputRows) { - doFillOneRowResult(pFillInfo, pBlock, pFillInfo->pSrcBlock, ts, false); + doFillOneRow(pFillInfo, pBlock, pFillInfo->pSrcBlock, ts, false); } // output buffer is full, abort @@ -343,7 +348,7 @@ static int64_t appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int */ pFillInfo->numOfCurrent = 0; while (pFillInfo->numOfCurrent < resultCapacity) { - doFillOneRowResult(pFillInfo, pBlock, pFillInfo->pSrcBlock, pFillInfo->start, true); + doFillOneRow(pFillInfo, pBlock, pFillInfo->pSrcBlock, pFillInfo->start, true); } pFillInfo->numOfTotal += pFillInfo->numOfCurrent; @@ -408,7 +413,7 @@ static int32_t taosNumOfRemainRows(SFillInfo* pFillInfo) { } struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols, - SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, + SInterval* pInterval, int32_t fillType, struct SFillColInfo* pCol, int32_t primaryTsSlotId, const char* id) { if (fillType == TSDB_FILL_NONE) { return NULL; @@ -420,6 +425,8 @@ struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTag return NULL; } + pFillInfo->tsSlotId = primaryTsSlotId; + taosResetFillInfo(pFillInfo, skey); pFillInfo->order = order; @@ -589,11 +596,10 @@ int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, SSDataBlock* p, int32_t ca assert(numOfRes == pFillInfo->numOfCurrent); } - // qDebug("fill:%p, generated fill result, src block:%d, index:%d, brange:%"PRId64"-%"PRId64", currentKey:%"PRId64", - // current:%d, total:%d, %p", - // pFillInfo, pFillInfo->numOfRows, pFillInfo->index, pFillInfo->start, pFillInfo->end, pFillInfo->currentKey, - // pFillInfo->numOfCurrent, - // pFillInfo->numOfTotal, pFillInfo->handle); + qDebug("fill:%p, generated fill result, src block:%d, index:%d, brange:%" PRId64 "-%" PRId64 ", currentKey:%" PRId64 + ", current : % d, total : % d, %s", pFillInfo, + pFillInfo->numOfRows, pFillInfo->index, pFillInfo->start, pFillInfo->end, pFillInfo->currentKey, + pFillInfo->numOfCurrent, pFillInfo->numOfTotal, pFillInfo->id); return numOfRes; } diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 78775073a4..773484a9b3 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -419,6 +419,14 @@ static bool setTimeWindowInterpolationEndTs(SIntervalAggOperatorInfo* pInfo, SEx return true; } +bool inSlidingWindow(SInterval* pInterval, STimeWindow* pWin, SDataBlockInfo* pBlockInfo) { + if (pInterval->interval != pInterval->sliding && + (pWin->ekey < pBlockInfo->calWin.skey || pWin->skey > pBlockInfo->calWin.ekey)) { + return false; + } + return true; +} + static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, SDataBlockInfo* pDataBlockInfo, TSKEY* primaryKeys, int32_t prevPosition, int32_t order) { bool ascQuery = (order == TSDB_ORDER_ASC); @@ -432,6 +440,10 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, return -1; } + if (!inSlidingWindow(pInterval, pNext, pDataBlockInfo) && order == TSDB_ORDER_ASC) { + return -1; + } + TSKEY skey = ascQuery ? pNext->skey : pNext->ekey; int32_t startPos = 0; @@ -801,7 +813,8 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul STimeWindow win = getActiveTimeWindow(pInfo->aggSup.pResultBuf, pResultRowInfo, ts, &pInfo->interval, pInfo->order); int32_t ret = TSDB_CODE_SUCCESS; - if (!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) { + if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) && + inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) { ret = setTimeWindowOutputBuf(pResultRowInfo, &win, (scanFlag == MAIN_SCAN), &pResult, tableGroupId, pSup->pCtx, numOfOutput, pSup->rowEntryInfoOffset, &pInfo->aggSup, pTaskInfo); if (ret != TSDB_CODE_SUCCESS || pResult == NULL) { @@ -834,7 +847,8 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul doWindowBorderInterpolation(pInfo, pBlock, pResult, &win, startPos, forwardRows, pSup); } - if (!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) { + if ((!pInfo->ignoreExpiredData || !isCloseWindow(&win, &pInfo->twAggSup)) && + inSlidingWindow(&pInfo->interval, &win, &pBlock->info)) { updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, true); doApplyFunctions(pTaskInfo, pSup->pCtx, &win, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, tsCols, pBlock->info.rows, numOfOutput, pInfo->order); @@ -1278,18 +1292,25 @@ static void doClearWindows(SAggSupporter* pAggSup, SExprSupp* pSup1, SInterval* SColumnInfoData* pGpCol = taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX); pGpDatas = (uint64_t*)pGpCol->pData; } - int32_t step = 0; - for (int32_t i = 0; i < pBlock->info.rows; i += step) { - SResultRowInfo dumyInfo; - dumyInfo.cur.pageId = -1; - STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[i], pInterval, TSDB_ORDER_ASC); - step = getNumOfRowsInTimeWindow(&pBlock->info, tsCols, i, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); - uint64_t winGpId = pGpDatas ? pGpDatas[i] : pBlock->info.groupId; - bool res = doClearWindow(pAggSup, pSup1, (char*)&win.skey, sizeof(TKEY), winGpId, numOfOutput); + int32_t step = 0; + int32_t startPos = 0; + SResultRowInfo dumyInfo; + dumyInfo.cur.pageId = -1; + STimeWindow win = getActiveTimeWindow(NULL, &dumyInfo, tsCols[0], pInterval, TSDB_ORDER_ASC); + while (1) { + step = + getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, win.ekey, binarySearchForKey, NULL, TSDB_ORDER_ASC); + uint64_t winGpId = pGpDatas ? pGpDatas[startPos] : pBlock->info.groupId; + bool res = doClearWindow(pAggSup, pSup1, (char*)&win.skey, sizeof(TSKEY), winGpId, numOfOutput); if (pUpWins && res) { SWinRes winRes = {.ts = win.skey, .groupId = winGpId}; taosArrayPush(pUpWins, &winRes); } + int32_t prevEndPos = step - 1 + startPos; + startPos = getNextQualifiedWindow(pInterval, &win, &pBlock->info, tsCols, prevEndPos, TSDB_ORDER_ASC); + if (startPos < 0) { + break; + } } } @@ -1332,13 +1353,13 @@ static int32_t closeIntervalWindow(SHashObj* pHashMap, STimeWindowAggSupp* pSup, if (chIds && pPullDataMap) { SArray* chAy = *(SArray**)chIds; int32_t size = taosArrayGetSize(chAy); - qInfo("window %" PRId64 " wait child size:%d", win.skey, size); + qDebug("window %" PRId64 " wait child size:%d", win.skey, size); for (int32_t i = 0; i < size; i++) { - qInfo("window %" PRId64 " wait chid id:%d", win.skey, *(int32_t*)taosArrayGet(chAy, i)); + qDebug("window %" PRId64 " wait chid id:%d", win.skey, *(int32_t*)taosArrayGet(chAy, i)); } continue; } else if (pPullDataMap) { - qInfo("close window %" PRId64, win.skey); + qDebug("close window %" PRId64, win.skey); } SResultRowPosition* pPos = (SResultRowPosition*)pIte; if (pSup->calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) { @@ -2434,7 +2455,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc } while (1) { bool isClosed = isCloseWindow(&nextWin, &pInfo->twAggSup); - if (pInfo->ignoreExpiredData && isClosed) { + if ((pInfo->ignoreExpiredData && isClosed) || !inSlidingWindow(&pInfo->interval, &nextWin, &pSDataBlock->info)) { startPos = getNexWindowPos(&pInfo->interval, &pSDataBlock->info, tsCols, startPos, nextWin.ekey, &nextWin); if (startPos < 0) { break; @@ -2491,8 +2512,8 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc if (IS_FINAL_OP(pInfo)) { forwardRows = 1; } else { - forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, NULL, - TSDB_ORDER_ASC); + forwardRows = getNumOfRowsInTimeWindow(&pSDataBlock->info, tsCols, startPos, nextWin.ekey, binarySearchForKey, + NULL, TSDB_ORDER_ASC); } if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE && pUpdated) { saveResultRow(pResult, tableGroupId, pUpdated); @@ -2609,6 +2630,8 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { SExprSupp* pSup = &pOperator->exprSupp; + qDebug("interval status %d %s", pOperator->status, IS_FINAL_OP(pInfo) ? "interval Final" : "interval Semi"); + if (pOperator->status == OP_EXEC_DONE) { return NULL; } else if (pOperator->status == OP_RES_TO_RETURN) { @@ -2659,7 +2682,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { clearSpecialDataBlock(pInfo->pUpdateRes); removeDeleteResults(pUpdated, pInfo->pDelWins); pOperator->status = OP_RES_TO_RETURN; - qInfo("%s return data", IS_FINAL_OP(pInfo) ? "interval Final" : "interval Semi"); + qDebug("%s return data", IS_FINAL_OP(pInfo) ? "interval Final" : "interval Semi"); break; } printDataBlock(pBlock, IS_FINAL_OP(pInfo) ? "interval Final recv" : "interval Semi recv"); @@ -3101,12 +3124,7 @@ int64_t getSessionWindowEndkey(void* data, int32_t index) { } bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap) { - int64_t sGap = ts - pWin->skey + gap; - int64_t eGap = pWin->ekey - ts + gap; - // if ((sGap < 0 && sGap >= -gap) || (eGap < 0 && eGap >= -gap) || (sGap >= 0 && eGap >= 0)) { - // return true; - // } - if (sGap >= 0 && eGap >= 0) { + if (ts + gap >= pWin->skey && ts - gap <= pWin->ekey) { return true; } return false; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 06944edadd..e8e37e5c6b 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -157,6 +157,7 @@ int32_t elapsedCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx); bool getHistogramFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); int32_t histogramFunction(SqlFunctionCtx* pCtx); +int32_t histogramFunctionPartial(SqlFunctionCtx* pCtx); int32_t histogramFunctionMerge(SqlFunctionCtx* pCtx); int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); int32_t histogramPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 1e7e7e57c3..1ed6dcad39 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -48,8 +48,8 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) { return TIME_UNIT_INVALID; } - if (TSDB_TIME_PRECISION_MILLI == dbPrec && (0 == strcasecmp(pVal->literal, "1u") || - 0 == strcasecmp(pVal->literal, "1b"))) { + if (TSDB_TIME_PRECISION_MILLI == dbPrec && + (0 == strcasecmp(pVal->literal, "1u") || 0 == strcasecmp(pVal->literal, "1b"))) { return TIME_UNIT_TOO_SMALL; } @@ -57,10 +57,9 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) { return TIME_UNIT_TOO_SMALL; } - if (pVal->literal[0] != '1' || (pVal->literal[1] != 'u' && pVal->literal[1] != 'a' && - pVal->literal[1] != 's' && pVal->literal[1] != 'm' && - pVal->literal[1] != 'h' && pVal->literal[1] != 'd' && - pVal->literal[1] != 'w' && pVal->literal[1] != 'b')) { + if (pVal->literal[0] != '1' || + (pVal->literal[1] != 'u' && pVal->literal[1] != 'a' && pVal->literal[1] != 's' && pVal->literal[1] != 'm' && + pVal->literal[1] != 'h' && pVal->literal[1] != 'd' && pVal->literal[1] != 'w' && pVal->literal[1] != 'b')) { return TIME_UNIT_INVALID; } @@ -678,9 +677,10 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } - uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (TSDB_DATA_TYPE_TIMESTAMP != paraType) { - return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + SNode* pPara1 = nodesListGetNode(pFunc->pParameterList, 0); + if (QUERY_NODE_COLUMN != nodeType(pPara1) || PRIMARYKEY_TIMESTAMP_COL_ID != ((SColumnNode*)pPara1)->colId) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "The first parameter of the ELAPSED function can only be the timestamp primary key"); } // param1 @@ -694,8 +694,7 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len pValue->notReserved = true; - paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if (!IS_INTEGER_TYPE(paraType)) { + if (!IS_INTEGER_TYPE(pValue->node.resType.type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -706,8 +705,9 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "ELAPSED function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "ELAPSED function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + return buildFuncErrMsg( + pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "ELAPSED function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); } } @@ -1229,7 +1229,8 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32 "STATEDURATION function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "STATEDURATION function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + "STATEDURATION function time unit parameter should be one of the following: [1b, 1u, 1a, " + "1s, 1m, 1h, 1d, 1w]"); } } @@ -1426,9 +1427,12 @@ static int32_t translateIrate(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - // first(col_list) will be rewritten as first(col) - if (1 != LIST_LENGTH(pFunc->pParameterList)) { - return TSDB_CODE_SUCCESS; + int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList); + for (int32_t i = 0; i < numOfParams; ++i) { + SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i); + if (QUERY_NODE_VALUE == nodeType(pParamNode)) { + return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); + } } pFunc->node.resType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType; @@ -1740,8 +1744,9 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_ return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "TIMETRUNCATE function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + return buildFuncErrMsg( + pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); } addDbPrecisonParam(&pFunc->pParameterList, dbPrec); @@ -1779,8 +1784,9 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "TIMEDIFF function time unit parameter should be greater than db precision"); } else if (ret == TIME_UNIT_INVALID) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, - "TIMEDIFF function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); + return buildFuncErrMsg( + pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "TIMEDIFF function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); } } @@ -1970,7 +1976,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "leastsquares", .type = FUNCTION_TYPE_LEASTSQUARES, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, .translateFunc = translateLeastSQR, .getEnvFunc = getLeastSQRFuncEnv, .initFunc = leastSQRFunctionSetup, @@ -2211,7 +2217,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "last_row", .type = FUNCTION_TYPE_LAST_ROW, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC, .translateFunc = translateFirstLast, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, @@ -2320,7 +2326,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .translateFunc = translateHistogramPartial, .getEnvFunc = getHistogramFuncEnv, .initFunc = histogramFunctionSetup, - .processFunc = histogramFunction, + .processFunc = histogramFunctionPartial, .finalizeFunc = histogramPartialFinalize, .invertFunc = NULL, .combineFunc = histogramCombine, diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 932bfb8793..ccf28bfd78 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -80,8 +80,10 @@ typedef struct STopBotRes { } STopBotRes; typedef struct SFirstLastRes { - bool hasResult; - bool isNull; // used for last_row function only + bool hasResult; + // used for last_row function only, isNullRes in SResultRowEntry can not be passed to downstream.So, + // this attribute is required + bool isNull; int32_t bytes; char buf[]; } SFirstLastRes; @@ -338,6 +340,104 @@ typedef struct SGroupKeyInfo { } \ } while (0) +#define LIST_ADD_N(_res, _col, _start, _rows, _t, numOfElem) \ + do { \ + _t* d = (_t*)(_col->pData); \ + for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \ + if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \ + continue; \ + }; \ + (_res) += (d)[i]; \ + (numOfElem)++; \ + } \ + } while (0) + +#define LIST_SUB_N(_res, _col, _start, _rows, _t, numOfElem) \ + do { \ + _t* d = (_t*)(_col->pData); \ + for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \ + if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \ + continue; \ + }; \ + (_res) -= (d)[i]; \ + (numOfElem)++; \ + } \ + } while (0) + +#define LIST_AVG_N(sumT, T) \ + do { \ + T* plist = (T*)pCol->pData; \ + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { \ + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { \ + continue; \ + } \ + \ + numOfElem += 1; \ + pAvgRes->count -= 1; \ + sumT -= plist[i]; \ + } \ + } while (0) + +#define LIST_STDDEV_SUB_N(sumT, T) \ + do { \ + T* plist = (T*)pCol->pData; \ + for (int32_t i = start; i < numOfRows + start; ++i) { \ + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { \ + continue; \ + } \ + numOfElem += 1; \ + pStddevRes->count -= 1; \ + sumT -= plist[i]; \ + pStddevRes->quadraticISum -= plist[i] * plist[i]; \ + } \ + } while (0) + +#define LEASTSQR_CAL(p, x, y, index, step) \ + do { \ + (p)[0][0] += (double)(x) * (x); \ + (p)[0][1] += (double)(x); \ + (p)[0][2] += (double)(x) * (y)[index]; \ + (p)[1][2] += (y)[index]; \ + (x) += step; \ + } while (0) + + +#define STATE_COMP(_op, _lval, _param) STATE_COMP_IMPL(_op, _lval, GET_STATE_VAL(_param)) + +#define GET_STATE_VAL(param) ((param.nType == TSDB_DATA_TYPE_BIGINT) ? (param.i) : (param.d)) + +#define STATE_COMP_IMPL(_op, _lval, _rval) \ + do { \ + switch (_op) { \ + case STATE_OPER_LT: \ + return ((_lval) < (_rval)); \ + break; \ + case STATE_OPER_GT: \ + return ((_lval) > (_rval)); \ + break; \ + case STATE_OPER_LE: \ + return ((_lval) <= (_rval)); \ + break; \ + case STATE_OPER_GE: \ + return ((_lval) >= (_rval)); \ + break; \ + case STATE_OPER_NE: \ + return ((_lval) != (_rval)); \ + break; \ + case STATE_OPER_EQ: \ + return ((_lval) == (_rval)); \ + break; \ + default: \ + break; \ + } \ + } while (0) + +#define INIT_INTP_POINT(_p, _k, _v) \ + do { \ + (_p).key = (_k); \ + (_p).val = (_v); \ + } while (0) + bool dummyGetEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* UNUSED_PARAM(pEnv)) { return true; } bool dummyInit(SqlFunctionCtx* UNUSED_PARAM(pCtx), SResultRowEntryInfo* UNUSED_PARAM(pResultInfo)) { return true; } @@ -499,30 +599,6 @@ int32_t combineFunction(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) { return TSDB_CODE_SUCCESS; } -#define LIST_ADD_N(_res, _col, _start, _rows, _t, numOfElem) \ - do { \ - _t* d = (_t*)(_col->pData); \ - for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \ - if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \ - continue; \ - }; \ - (_res) += (d)[i]; \ - (numOfElem)++; \ - } \ - } while (0) - -#define LIST_SUB_N(_res, _col, _start, _rows, _t, numOfElem) \ - do { \ - _t* d = (_t*)(_col->pData); \ - for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \ - if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \ - continue; \ - }; \ - (_res) -= (d)[i]; \ - (numOfElem)++; \ - } \ - } while (0) - int32_t sumFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; @@ -907,31 +983,19 @@ int32_t avgFunctionMerge(SqlFunctionCtx* pCtx) { SAvgRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SAvgRes* pInputInfo = (SAvgRes*)varDataVal(data); + int32_t start = pInput->startRowIndex; - avgTransferInfo(pInputInfo, pInfo); + for(int32_t i = start; i < start + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SAvgRes* pInputInfo = (SAvgRes*)varDataVal(data); + avgTransferInfo(pInputInfo, pInfo); + } SET_VAL(GET_RES_INFO(pCtx), 1, 1); return TSDB_CODE_SUCCESS; } -#define LIST_AVG_N(sumT, T) \ - do { \ - T* plist = (T*)pCol->pData; \ - for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { \ - if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { \ - continue; \ - } \ - \ - numOfElem += 1; \ - pAvgRes->count -= 1; \ - sumT -= plist[i]; \ - } \ - } while (0) - int32_t avgInvertFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; @@ -1082,9 +1146,9 @@ static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBl static int32_t findRowIndex(int32_t start, int32_t num, SColumnInfoData* pCol, const char* tval) { // the data is loaded, not only the block SMA value - for(int32_t i = start; i < num + start; ++i) { + for (int32_t i = start; i < num + start; ++i) { char* p = colDataGetData(pCol, i); - if (memcpy((void*)tval, p, pCol->info.bytes) == 0) { + if (memcpy((void*)tval, p, pCol->info.bytes) == 0) { return i; } } @@ -1092,7 +1156,6 @@ static int32_t findRowIndex(int32_t start, int32_t num, SColumnInfoData* pCol, c ASSERT(0); } - int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { int32_t numOfElems = 0; @@ -1569,10 +1632,14 @@ void setNullSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t } void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuplePos* pTuplePos, int32_t rowIndex) { + if (pCtx->subsidiaries.num <= 0) { + return; + } + int32_t pageId = pTuplePos->pageId; int32_t offset = pTuplePos->offset; - if (pTuplePos->pageId != -1 && pCtx->subsidiaries.num > 0) { + if (pTuplePos->pageId != -1) { int32_t numOfCols = pCtx->subsidiaries.num; SFilePage* pPage = getBufPage(pCtx->pBuf, pageId); @@ -1872,7 +1939,7 @@ int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx) { SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - for(int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) { + for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) { char* data = colDataGetData(pCol, i); SStddevRes* pInputInfo = (SStddevRes*)varDataVal(data); stddevTransferInfo(pInputInfo, pInfo); @@ -1882,20 +1949,6 @@ int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx) { return TSDB_CODE_SUCCESS; } -#define LIST_STDDEV_SUB_N(sumT, T) \ - do { \ - T* plist = (T*)pCol->pData; \ - for (int32_t i = start; i < numOfRows + start; ++i) { \ - if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { \ - continue; \ - } \ - numOfElem += 1; \ - pStddevRes->count -= 1; \ - sumT -= plist[i]; \ - pStddevRes->quadraticISum -= plist[i] * plist[i]; \ - } \ - } while (0) - int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; @@ -2044,15 +2097,6 @@ bool leastSQRFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInf return true; } -#define LEASTSQR_CAL(p, x, y, index, step) \ - do { \ - (p)[0][0] += (double)(x) * (x); \ - (p)[0][1] += (double)(x); \ - (p)[0][2] += (double)(x) * (y)[index]; \ - (p)[1][2] += (y)[index]; \ - (x) += step; \ - } while (0) - int32_t leastSQRFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; @@ -2512,11 +2556,13 @@ int32_t apercentileFunctionMerge(SqlFunctionCtx* pCtx) { SAPercentileInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SAPercentileInfo* pInputInfo = (SAPercentileInfo*)varDataVal(data); + int32_t start = pInput->startRowIndex; - apercentileTransferInfo(pInputInfo, pInfo); + for(int32_t i = start; i < start + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SAPercentileInfo* pInputInfo = (SAPercentileInfo*)varDataVal(data); + apercentileTransferInfo(pInputInfo, pInfo); + } SET_VAL(pResInfo, 1, 1); return TSDB_CODE_SUCCESS; @@ -2729,7 +2775,6 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) { } } pInfo->hasResult = true; - // DO_UPDATE_TAG_COLUMNS(pCtx, ts); pResInfo->numOfRes = 1; break; } @@ -2826,7 +2871,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { } pInfo->hasResult = true; pResInfo->numOfRes = 1; - // DO_UPDATE_TAG_COLUMNS(pCtx, ts); } break; } @@ -2877,13 +2921,17 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SFirstLastRes* pInputInfo = (SFirstLastRes*)varDataVal(data); + int32_t start = pInput->startRowIndex; + int32_t numOfElems = 0; - firstLastTransferInfo(pCtx, pInputInfo, pInfo, isFirstQuery); - - int32_t numOfElems = pInputInfo->hasResult ? 1 : 0; + for(int32_t i = start; i < start + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SFirstLastRes* pInputInfo = (SFirstLastRes*)varDataVal(data); + firstLastTransferInfo(pCtx, pInputInfo, pInfo, isFirstQuery); + if (!numOfElems) { + numOfElems = pInputInfo->hasResult ? 1 : 0; + } + } SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); @@ -2902,7 +2950,7 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo); - colDataAppend(pCol, pBlock->info.rows, pRes->buf, pResInfo->isNullRes); + colDataAppend(pCol, pBlock->info.rows, pRes->buf, pRes->isNull||pResInfo->isNullRes); // handle selectivity STuplePos* pTuplePos = (STuplePos*)(pRes->buf + pRes->bytes + sizeof(TSKEY)); setSelectivityValue(pCtx, pBlock, pTuplePos, pBlock->info.rows); @@ -3465,8 +3513,7 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS setBufPageDirty(pPage, true); releaseBufPage(pCtx->pBuf, pPage); #ifdef BUF_PAGE_DEBUG - qDebug("page_saveTuple pos:%p,pageId:%d, offset:%d\n", pPos, pPos->pageId, - pPos->offset); + qDebug("page_saveTuple pos:%p,pageId:%d, offset:%d\n", pPos, pPos->pageId, pPos->offset); #endif } @@ -3703,11 +3750,13 @@ int32_t spreadFunctionMerge(SqlFunctionCtx* pCtx) { SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SSpreadInfo* pInputInfo = (SSpreadInfo*)varDataVal(data); + int32_t start = pInput->startRowIndex; - spreadTransferInfo(pInputInfo, pInfo); + for(int32_t i = start; i < start + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SSpreadInfo* pInputInfo = (SSpreadInfo*)varDataVal(data); + spreadTransferInfo(pInputInfo, pInfo); + } SET_VAL(GET_RES_INFO(pCtx), 1, 1); @@ -3765,7 +3814,7 @@ bool elapsedFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo SElapsedInfo* pInfo = GET_ROWCELL_INTERBUF(pResultInfo); pInfo->result = 0; - pInfo->min = MAX_TS_KEY; + pInfo->min = TSKEY_MAX; pInfo->max = 0; if (pCtx->numOfParams > 1) { @@ -3792,7 +3841,7 @@ int32_t elapsedFunction(SqlFunctionCtx* pCtx) { } if (pInput->colDataAggIsSet) { - if (pInfo->min == MAX_TS_KEY) { + if (pInfo->min == TSKEY_MAX) { pInfo->min = GET_INT64_VAL(&pAgg->min); pInfo->max = GET_INT64_VAL(&pAgg->max); } else { @@ -3873,11 +3922,13 @@ int32_t elapsedFunctionMerge(SqlFunctionCtx* pCtx) { SElapsedInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SElapsedInfo* pInputInfo = (SElapsedInfo*)varDataVal(data); + int32_t start = pInput->startRowIndex; - elapsedTransferInfo(pInputInfo, pInfo); + for(int32_t i = start; i < start + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SElapsedInfo* pInputInfo = (SElapsedInfo*)varDataVal(data); + elapsedTransferInfo(pInputInfo, pInfo); + } SET_VAL(GET_RES_INFO(pCtx), 1, 1); return TSDB_CODE_SUCCESS; @@ -4098,7 +4149,7 @@ bool histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultIn return true; } -int32_t histogramFunction(SqlFunctionCtx* pCtx) { +static int32_t histogramFunctionImpl(SqlFunctionCtx* pCtx, bool isPartial) { SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); SInputColumnInfoData* pInput = &pCtx->input; @@ -4130,10 +4181,22 @@ int32_t histogramFunction(SqlFunctionCtx* pCtx) { } } - SET_VAL(GET_RES_INFO(pCtx), numOfElems, pInfo->numOfBins); + if (!isPartial) { + SET_VAL(GET_RES_INFO(pCtx), numOfElems, pInfo->numOfBins); + } else { + SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); + } return TSDB_CODE_SUCCESS; } +int32_t histogramFunction(SqlFunctionCtx* pCtx) { + return histogramFunctionImpl(pCtx, false); +} + +int32_t histogramFunctionPartial(SqlFunctionCtx* pCtx) { + return histogramFunctionImpl(pCtx, true); +} + static void histogramTransferInfo(SHistoFuncInfo* pInput, SHistoFuncInfo* pOutput) { pOutput->normalized = pInput->normalized; pOutput->numOfBins = pInput->numOfBins; @@ -4152,11 +4215,13 @@ int32_t histogramFunctionMerge(SqlFunctionCtx* pCtx) { SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SHistoFuncInfo* pInputInfo = (SHistoFuncInfo*)varDataVal(data); + int32_t start = pInput->startRowIndex; - histogramTransferInfo(pInputInfo, pInfo); + for(int32_t i = start; i < start + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SHistoFuncInfo* pInputInfo = (SHistoFuncInfo*)varDataVal(data); + histogramTransferInfo(pInputInfo, pInfo); + } SET_VAL(GET_RES_INFO(pCtx), pInfo->numOfBins, pInfo->numOfBins); return TSDB_CODE_SUCCESS; @@ -4199,6 +4264,7 @@ int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { } int32_t histogramPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SHistoFuncInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); int32_t resultBytes = getHistogramInfoSize(); char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char)); @@ -4212,7 +4278,7 @@ int32_t histogramPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { colDataAppend(pCol, pBlock->info.rows, res, false); taosMemoryFree(res); - return 1; + return pResInfo->numOfRes; } int32_t histogramCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) { @@ -4370,11 +4436,13 @@ int32_t hllFunctionMerge(SqlFunctionCtx* pCtx) { SHLLInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - int32_t start = pInput->startRowIndex; - char* data = colDataGetData(pCol, start); - SHLLInfo* pInputInfo = (SHLLInfo*)varDataVal(data); + int32_t start = pInput->startRowIndex; - hllTransferInfo(pInputInfo, pInfo); + for(int32_t i = start; i < start + pInput->numOfRows; ++i) { + char* data = colDataGetData(pCol, i); + SHLLInfo* pInputInfo = (SHLLInfo*)varDataVal(data); + hllTransferInfo(pInputInfo, pInfo); + } SET_VAL(GET_RES_INFO(pCtx), 1, 1); return TSDB_CODE_SUCCESS; @@ -4448,36 +4516,6 @@ static int8_t getStateOpType(char* opStr) { return opType; } -#define GET_STATE_VAL(param) ((param.nType == TSDB_DATA_TYPE_BIGINT) ? (param.i) : (param.d)) - -#define STATE_COMP(_op, _lval, _param) STATE_COMP_IMPL(_op, _lval, GET_STATE_VAL(_param)) - -#define STATE_COMP_IMPL(_op, _lval, _rval) \ - do { \ - switch (_op) { \ - case STATE_OPER_LT: \ - return ((_lval) < (_rval)); \ - break; \ - case STATE_OPER_GT: \ - return ((_lval) > (_rval)); \ - break; \ - case STATE_OPER_LE: \ - return ((_lval) <= (_rval)); \ - break; \ - case STATE_OPER_GE: \ - return ((_lval) >= (_rval)); \ - break; \ - case STATE_OPER_NE: \ - return ((_lval) != (_rval)); \ - break; \ - case STATE_OPER_EQ: \ - return ((_lval) == (_rval)); \ - break; \ - default: \ - break; \ - } \ - } while (0) - static bool checkStateOp(int8_t op, SColumnInfoData* pCol, int32_t index, SVariant param) { char* data = colDataGetData(pCol, index); switch (pCol->info.type) { @@ -5185,12 +5223,6 @@ static double twa_get_area(SPoint1 s, SPoint1 e) { return val; } -#define INIT_INTP_POINT(_p, _k, _v) \ - do { \ - (_p).key = (_k); \ - (_p).val = (_v); \ - } while (0) - int32_t twaFunction(SqlFunctionCtx* pCtx) { SInputColumnInfoData* pInput = &pCtx->input; SColumnInfoData* pInputCol = pInput->pData[0]; @@ -5958,28 +5990,41 @@ int32_t lastrowFunction(SqlFunctionCtx* pCtx) { int32_t type = pInputCol->info.type; int32_t bytes = pInputCol->info.bytes; + pInfo->bytes = bytes; + // last_row function does not ignore the null value for (int32_t i = pInput->numOfRows + pInput->startRowIndex - 1; i >= pInput->startRowIndex; --i) { - if (pInputCol->hasNull && colDataIsNull_s(pInputCol, i)) { - continue; - } - numOfElems++; char* data = colDataGetData(pInputCol, i); TSKEY cts = getRowPTs(pInput->pPTS, i); if (pResInfo->numOfRes == 0 || *(TSKEY*)(pInfo->buf + bytes) < cts) { - if (IS_VAR_DATA_TYPE(type)) { - bytes = varDataTLen(data); - pInfo->bytes = bytes; + + if (colDataIsNull_s(pInputCol, i)) { + pInfo->isNull = true; + } else { + if (IS_VAR_DATA_TYPE(type)) { + bytes = varDataTLen(data); + pInfo->bytes = bytes; + } + + memcpy(pInfo->buf, data, bytes); } - memcpy(pInfo->buf, data, bytes); *(TSKEY*)(pInfo->buf + bytes) = cts; pInfo->hasResult = true; pResInfo->numOfRes = 1; + + if (pCtx->subsidiaries.num > 0) { + STuplePos* pTuplePos = (STuplePos*)(pInfo->buf + bytes + sizeof(TSKEY)); + if (!pInfo->hasResult) { + saveTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos); + } else { + copyTupleData(pCtx, i, pCtx->pSrcBlock, pTuplePos); + } + } } } diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 294488a38d..3c285cc7f1 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2481,7 +2481,6 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) { int32_t code = tjsonToObject(pJson, jkSubplanId, jsonToSubplanId, &pNode->id); if (TSDB_CODE_SUCCESS == code) { tjsonGetNumberValue(pJson, jkSubplanType, pNode->subplanType, code); - ; } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetIntValue(pJson, jkSubplanMsgType, &pNode->msgType); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index cc442d1103..4abb8f5c2c 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -956,7 +956,8 @@ void nodesDestroyNode(SNode* pNode) { } case QUERY_NODE_PHYSICAL_SUBPLAN: { SSubplan* pSubplan = (SSubplan*)pNode; - nodesDestroyList(pSubplan->pChildren); + // nodesDestroyList(pSubplan->pChildren); + nodesClearList(pSubplan->pChildren); nodesDestroyNode((SNode*)pSubplan->pNode); nodesDestroyNode((SNode*)pSubplan->pDataSink); nodesDestroyNode((SNode*)pSubplan->pTagCond); @@ -972,7 +973,7 @@ void nodesDestroyNode(SNode* pNode) { SNode* pElement = NULL; FOREACH(pElement, pPlan->pSubplans) { if (first) { - first = false; + // first = false; nodesDestroyNode(pElement); } else { nodesClearList(((SNodeListNode*)pElement)->pNodeList); @@ -1793,7 +1794,7 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { } else if (pCol->hasIndex) { pCxt->hasTagIndexCol = true; pCxt->hasTagCol = true; - } else if (COLUMN_TYPE_TAG == pCol->colType) { + } else if (COLUMN_TYPE_TAG == pCol->colType || COLUMN_TYPE_TBNAME == pCol->colType) { pCxt->hasTagCol = true; } else { pCxt->hasOtherCol = true; diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index 167970838b..ea78735d5e 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -20,6 +20,7 @@ #include "os.h" #include "tname.h" #include "ttypes.h" +#include "query.h" #define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED) diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index cd0b5c1d6c..606d35a65b 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -556,6 +556,7 @@ signed_literal(A) ::= TIMESTAMP NK_STRING(B). signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); } signed_literal(A) ::= NULL(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &B); } signed_literal(A) ::= literal_func(B). { A = releaseRawExprNode(pCxt, B); } +signed_literal(A) ::= NK_QUESTION(B). { A = createPlaceholderValueNode(pCxt, &B); } %type literal_list { SNodeList* } %destructor literal_list { nodesDestroyList($$); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index c451e52540..c60e5541e0 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -339,6 +339,10 @@ SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) { SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) { CHECK_PARSER_STATUS(pCxt); + if (NULL == pCxt->pQueryCxt->pStmtCb) { + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pLiteral->z); + return NULL; + } SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); CHECK_OUT_OF_MEM(val); val->literal = strndup(pLiteral->z, pLiteral->n); @@ -755,8 +759,8 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) { SDatabaseOptions* pOptions = (SDatabaseOptions*)nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS); CHECK_OUT_OF_MEM(pOptions); pOptions->buffer = TSDB_DEFAULT_BUFFER_PER_VNODE; - pOptions->cacheLast = TSDB_DEFAULT_CACHE_LAST_ROW; - pOptions->cacheLastSize = TSDB_DEFAULT_LAST_ROW_MEM; + pOptions->cacheLast = TSDB_DEFAULT_CACHE_LAST; + pOptions->cacheLastSize = TSDB_DEFAULT_CACHE_LAST_SIZE; pOptions->compressionLevel = TSDB_DEFAULT_COMP_LEVEL; pOptions->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; pOptions->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 4dff42592a..b799ae5fb1 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -218,7 +218,7 @@ static SNode* createConstantValue() { static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { SNode* pProj = NULL; WHERE_EACH(pProj, pSelect->pProjectionList) { - if (subquery && isUselessCol((SExprNode*)pProj)) { + if (subquery && !pSelect->isDistinct && isUselessCol((SExprNode*)pProj)) { ERASE_NODE(pSelect->pProjectionList); continue; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 2494c5a8a7..f986d24a7e 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -133,7 +133,10 @@ static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, con assert(*p == TS_PATH_DELIMITER[0]); int32_t dbLen = p - pTableName->z; - char name[TSDB_DB_FNAME_LEN] = {0}; + if (dbLen <= 0) { + return buildInvalidOperationMsg(pMsgBuf, msg2); + } + char name[TSDB_DB_FNAME_LEN] = {0}; strncpy(name, pTableName->z, dbLen); dbLen = strdequote(name); diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index 84bcef7185..290c65de12 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -630,6 +630,17 @@ int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) { memcpy(*pDst, pSrc, sizeof(STableDataBlocks)); ((STableDataBlocks*)(*pDst))->cloned = true; + STableDataBlocks* pBlock = (STableDataBlocks*)(*pDst); + if (pBlock->pTableMeta) { + void *pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pBlock->pTableMeta)); + if (NULL == pNewMeta) { + taosMemoryFreeClear(*pDst); + return TSDB_CODE_OUT_OF_MEMORY; + } + memcpy(pNewMeta, pBlock->pTableMeta, TABLE_META_SIZE(pBlock->pTableMeta)); + pBlock->pTableMeta = pNewMeta; + } + return qResetStmtDataBlock(*pDst, false); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index f92713565b..ca000fcf2d 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -461,12 +461,10 @@ static bool isDistinctOrderBy(STranslateContext* pCxt) { ((SSelectStmt*)pCxt->pCurrStmt)->isDistinct); } -static bool belongTable(const char* currentDb, const SColumnNode* pCol, const STableNode* pTable) { +static bool belongTable(const SColumnNode* pCol, const STableNode* pTable) { int cmp = 0; if ('\0' != pCol->dbName[0]) { cmp = strcmp(pCol->dbName, pTable->dbName); - } else { - cmp = (QUERY_NODE_REAL_TABLE == nodeType(pTable) ? strcmp(currentDb, pTable->dbName) : 0); } if (0 == cmp) { cmp = strcmp(pCol->tableAlias, pTable->tableAlias); @@ -630,7 +628,7 @@ static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode** bool foundTable = false; for (size_t i = 0; i < nums; ++i) { STableNode* pTable = taosArrayGetP(pTables, i); - if (belongTable(pCxt->pParseCxt->db, (*pCol), pTable)) { + if (belongTable((*pCol), pTable)) { foundTable = true; bool foundCol = false; pCxt->errCode = findAndSetColumn(pCxt, pCol, pTable, &foundCol); @@ -2175,14 +2173,28 @@ static int64_t getMonthsFromTimeVal(int64_t val, int32_t fromPrecision, char uni return -1; } +static const char* getPrecisionStr(uint8_t precision) { + switch (precision) { + case TSDB_TIME_PRECISION_MILLI: + return TSDB_TIME_PRECISION_MILLI_STR; + case TSDB_TIME_PRECISION_MICRO: + return TSDB_TIME_PRECISION_MICRO_STR; + case TSDB_TIME_PRECISION_NANO: + return TSDB_TIME_PRECISION_NANO_STR; + default: + break; + } + return "unknown"; +} + static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* pInterval) { uint8_t precision = ((SColumnNode*)pInterval->pCol)->node.resType.precision; SValueNode* pInter = (SValueNode*)pInterval->pInterval; bool valInter = TIME_IS_VAR_DURATION(pInter->unit); - if (pInter->datum.i <= 0 || - (!valInter && convertTimePrecision(pInter->datum.i, precision, TSDB_TIME_PRECISION_MICRO) < tsMinIntervalTime)) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL, tsMinIntervalTime); + if (pInter->datum.i <= 0 || (!valInter && pInter->datum.i < tsMinIntervalTime)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL, tsMinIntervalTime, + getPrecisionStr(precision)); } if (NULL != pInterval->pOffset) { @@ -2756,6 +2768,11 @@ static int32_t translateInsertProject(STranslateContext* pCxt, SInsertStmt* pIns } } + if (NULL == pPrimaryKeyExpr) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMNS_NUM, + "Primary timestamp column can not be null"); + } + return addOrderByPrimaryKeyToQuery(pCxt, pPrimaryKeyExpr, pInsert->pQuery); } @@ -2838,8 +2855,8 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS pReq->compression = pStmt->pOptions->compressionLevel; pReq->replications = pStmt->pOptions->replica; pReq->strict = pStmt->pOptions->strict; - pReq->cacheLastRow = pStmt->pOptions->cacheLast; - pReq->lastRowMem = pStmt->pOptions->cacheLastSize; + pReq->cacheLast = pStmt->pOptions->cacheLast; + pReq->cacheLastSize = pStmt->pOptions->cacheLastSize; pReq->schemaless = pStmt->pOptions->schemaless; pReq->ignoreExist = pStmt->ignoreExists; return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq); @@ -3000,12 +3017,11 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName int32_t code = checkRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE); if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "cacheLast", pOptions->cacheLast, TSDB_MIN_DB_CACHE_LAST_ROW, - TSDB_MAX_DB_CACHE_LAST_ROW); + code = checkRangeOption(pCxt, "cacheLast", pOptions->cacheLast, TSDB_MIN_DB_CACHE_LAST, TSDB_MAX_DB_CACHE_LAST); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "cacheLastSize", pOptions->cacheLastSize, TSDB_MIN_DB_LAST_ROW_MEM, - TSDB_MAX_DB_LAST_ROW_MEM); + code = checkRangeOption(pCxt, "cacheLastSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_LAST_SIZE, + TSDB_MAX_DB_CACHE_LAST_SIZE); } if (TSDB_CODE_SUCCESS == code) { code = checkRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); @@ -3118,7 +3134,7 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, pReq->buffer = pStmt->pOptions->buffer; pReq->pageSize = -1; pReq->pages = pStmt->pOptions->pages; - pReq->lastRowMem = -1; + pReq->cacheLastSize = -1; pReq->daysPerFile = -1; pReq->daysToKeep0 = pStmt->pOptions->keep[0]; pReq->daysToKeep1 = pStmt->pOptions->keep[1]; @@ -3126,8 +3142,8 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod; pReq->walLevel = pStmt->pOptions->walLevel; pReq->strict = pStmt->pOptions->strict; - pReq->cacheLastRow = pStmt->pOptions->cacheLast; - pReq->lastRowMem = pStmt->pOptions->cacheLastSize; + pReq->cacheLast = pStmt->pOptions->cacheLast; + pReq->cacheLastSize = pStmt->pOptions->cacheLastSize; pReq->replications = pStmt->pOptions->replica; return; } @@ -4017,8 +4033,15 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pReq->intervalUnit); if (NULL != pStmt->pOptions->pStreamOptions) { SStreamOptions* pStreamOpt = (SStreamOptions*)pStmt->pOptions->pStreamOptions; - pReq->maxDelay = (NULL != pStreamOpt->pDelay ? ((SValueNode*)pStreamOpt->pDelay)->datum.i : 0); - pReq->watermark = (NULL != pStreamOpt->pWatermark ? ((SValueNode*)pStreamOpt->pWatermark)->datum.i : 0); + pReq->maxDelay = (NULL != pStreamOpt->pDelay ? ((SValueNode*)pStreamOpt->pDelay)->datum.i : -1); + pReq->watermark = (NULL != pStreamOpt->pWatermark ? ((SValueNode*)pStreamOpt->pWatermark)->datum.i + : TSDB_DEFAULT_ROLLUP_WATERMARK); + if (pReq->watermark < TSDB_MIN_ROLLUP_WATERMARK) { + pReq->watermark = TSDB_MIN_ROLLUP_WATERMARK; + } + if (pReq->watermark > TSDB_MAX_ROLLUP_WATERMARK) { + pReq->watermark = TSDB_MAX_ROLLUP_WATERMARK; + } } int32_t code = getSmaIndexDstVgId(pCxt, pStmt->tableName, &pReq->dstVgId); @@ -4734,8 +4757,13 @@ static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t* int32_t index = 0; FOREACH(pNode, pProjections) { SExprNode* pExpr = (SExprNode*)pNode; - (*pSchema)[index].type = pExpr->resType.type; - (*pSchema)[index].bytes = pExpr->resType.bytes; + if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) { + (*pSchema)[index].type = TSDB_DATA_TYPE_VARCHAR; + (*pSchema)[index].bytes = 0; + } else { + (*pSchema)[index].type = pExpr->resType.type; + (*pSchema)[index].bytes = pExpr->resType.bytes; + } (*pSchema)[index].colId = index + 1; if ('\0' != pExpr->userAlias[0]) { strcpy((*pSchema)[index].name, pExpr->userAlias); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 7a23338035..dedd9cabfc 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -60,7 +60,7 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_EXPRIE_STATEMENT: return "This statement is no longer supported"; case TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL: - return "Interval cannot be less than %d us"; + return "Interval cannot be less than %d %s"; case TSDB_CODE_PAR_DB_NOT_SPECIFIED: return "Database not specified"; case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME: diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 218b5d9f4b..fdba0e2fcc 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -41,7 +41,7 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) { } else if (TK_SELECT == t.type) { return false; } - if (0 == t.type) { + if (0 == t.type || 0 == t.n) { break; } } while (pStr - pSql < length); diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index cb09860758..d01050ceeb 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -140,16 +140,16 @@ typedef union { #define ParseCTX_STORE #define YYFALLBACK 1 #define YYNSTATE 666 -#define YYNRULE 488 +#define YYNRULE 489 #define YYNTOKEN 255 #define YY_MAX_SHIFT 665 -#define YY_MIN_SHIFTREDUCE 969 -#define YY_MAX_SHIFTREDUCE 1456 -#define YY_ERROR_ACTION 1457 -#define YY_ACCEPT_ACTION 1458 -#define YY_NO_ACTION 1459 -#define YY_MIN_REDUCE 1460 -#define YY_MAX_REDUCE 1947 +#define YY_MIN_SHIFTREDUCE 970 +#define YY_MAX_SHIFTREDUCE 1458 +#define YY_ERROR_ACTION 1459 +#define YY_ACCEPT_ACTION 1460 +#define YY_NO_ACTION 1461 +#define YY_MIN_REDUCE 1462 +#define YY_MAX_REDUCE 1950 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -216,260 +216,240 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2520) +#define YY_ACTTAB_COUNT (2318) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 529, 1698, 433, 552, 434, 1495, 441, 1587, 434, 1495, - /* 10 */ 1769, 113, 39, 37, 386, 62, 517, 1583, 471, 380, - /* 20 */ 338, 1766, 1258, 1002, 324, 79, 1782, 1695, 1598, 30, - /* 30 */ 260, 122, 143, 1333, 103, 1256, 1554, 102, 101, 100, - /* 40 */ 99, 98, 97, 96, 95, 94, 1591, 1762, 1768, 327, - /* 50 */ 71, 302, 557, 1925, 1800, 555, 1328, 1512, 1283, 574, - /* 60 */ 1925, 14, 581, 1006, 1007, 500, 1924, 1752, 1264, 580, - /* 70 */ 1922, 120, 1594, 159, 39, 37, 1396, 1922, 498, 487, - /* 80 */ 496, 529, 338, 557, 1258, 1, 250, 1867, 551, 1019, - /* 90 */ 550, 1018, 164, 1925, 1813, 1333, 61, 1256, 89, 1783, - /* 100 */ 583, 1785, 1786, 579, 469, 574, 161, 662, 1859, 1598, - /* 110 */ 1922, 343, 305, 1855, 1643, 1645, 71, 61, 1328, 1020, - /* 120 */ 43, 1335, 1336, 14, 1925, 1461, 1925, 33, 32, 117, - /* 130 */ 1264, 40, 38, 36, 35, 34, 475, 161, 1593, 160, - /* 140 */ 142, 1922, 1472, 1922, 1483, 1782, 103, 2, 214, 102, - /* 150 */ 101, 100, 99, 98, 97, 96, 95, 94, 474, 1155, - /* 160 */ 1156, 486, 485, 484, 170, 1925, 1259, 483, 1257, 662, - /* 170 */ 118, 480, 325, 1800, 479, 478, 477, 1458, 1923, 74, - /* 180 */ 140, 556, 1922, 1335, 1336, 1752, 1752, 555, 580, 1600, - /* 190 */ 1644, 1645, 69, 1262, 1263, 68, 1311, 1312, 1314, 1315, - /* 200 */ 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, - /* 210 */ 1332, 1334, 1337, 1813, 36, 35, 34, 90, 1783, 583, - /* 220 */ 1785, 1786, 579, 529, 574, 162, 371, 1859, 1259, 555, - /* 230 */ 1257, 329, 1855, 154, 113, 419, 162, 350, 1482, 33, + /* 0 */ 529, 1700, 433, 552, 434, 1497, 441, 1589, 434, 1497, + /* 10 */ 1772, 113, 39, 37, 386, 62, 517, 1585, 471, 380, + /* 20 */ 338, 1768, 1259, 1003, 324, 79, 1785, 1697, 1600, 30, + /* 30 */ 260, 122, 143, 1335, 103, 1257, 1556, 102, 101, 100, + /* 40 */ 99, 98, 97, 96, 95, 94, 1593, 1764, 1770, 327, + /* 50 */ 71, 302, 557, 1928, 1803, 555, 1330, 1514, 1285, 574, + /* 60 */ 1928, 14, 581, 1007, 1008, 500, 1927, 1754, 1265, 580, + /* 70 */ 1925, 120, 1596, 159, 39, 37, 1398, 1925, 498, 487, + /* 80 */ 496, 529, 338, 557, 1259, 1, 250, 1870, 551, 1020, + /* 90 */ 550, 1019, 164, 1928, 1816, 1335, 61, 1257, 89, 1786, + /* 100 */ 583, 1788, 1789, 579, 469, 574, 161, 662, 1862, 1600, + /* 110 */ 1925, 343, 305, 1858, 1645, 1647, 71, 61, 1330, 1021, + /* 120 */ 43, 1337, 1338, 14, 1928, 1463, 1928, 33, 32, 117, + /* 130 */ 1265, 40, 38, 36, 35, 34, 475, 161, 1595, 160, + /* 140 */ 142, 1925, 1474, 1925, 1485, 1785, 103, 2, 214, 102, + /* 150 */ 101, 100, 99, 98, 97, 96, 95, 94, 474, 1156, + /* 160 */ 1157, 486, 485, 484, 170, 1928, 1260, 483, 1258, 662, + /* 170 */ 118, 480, 325, 1803, 479, 478, 477, 1460, 1926, 74, + /* 180 */ 140, 556, 1925, 1337, 1338, 1754, 1754, 555, 580, 1602, + /* 190 */ 1646, 1647, 69, 1263, 1264, 68, 1313, 1314, 1316, 1317, + /* 200 */ 1318, 1319, 1320, 576, 572, 1328, 1329, 1331, 1332, 1333, + /* 210 */ 1334, 1336, 1339, 1816, 36, 35, 34, 90, 1786, 583, + /* 220 */ 1788, 1789, 579, 529, 574, 162, 371, 1862, 1260, 555, + /* 230 */ 1258, 329, 1858, 154, 113, 419, 162, 350, 1484, 33, /* 240 */ 32, 476, 450, 40, 38, 36, 35, 34, 373, 369, - /* 250 */ 1283, 1598, 552, 1886, 1393, 1262, 1263, 162, 1311, 1312, - /* 260 */ 1314, 1315, 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, - /* 270 */ 1330, 1331, 1332, 1334, 1337, 39, 37, 1453, 1925, 1752, - /* 280 */ 122, 174, 173, 338, 220, 1258, 40, 38, 36, 35, - /* 290 */ 34, 159, 306, 61, 42, 1922, 1333, 1739, 1256, 1113, - /* 300 */ 605, 604, 603, 1117, 602, 1119, 1120, 601, 1122, 598, - /* 310 */ 1800, 1128, 595, 1130, 1131, 592, 589, 1296, 545, 1328, - /* 320 */ 120, 1782, 33, 32, 14, 1355, 40, 38, 36, 35, - /* 330 */ 34, 1264, 39, 37, 554, 155, 1867, 1868, 86, 1872, - /* 340 */ 338, 552, 1258, 1769, 359, 1650, 1238, 1239, 2, 1800, - /* 350 */ 341, 119, 326, 1333, 1766, 1256, 544, 581, 140, 1590, - /* 360 */ 344, 1648, 1752, 529, 580, 1400, 1452, 1600, 140, 122, - /* 370 */ 662, 1282, 1282, 379, 165, 378, 1328, 1600, 557, 1356, - /* 380 */ 1762, 1768, 333, 1576, 1335, 1336, 1460, 432, 1264, 1813, - /* 390 */ 436, 1598, 574, 89, 1783, 583, 1785, 1786, 579, 1481, - /* 400 */ 574, 440, 1361, 1859, 436, 8, 215, 305, 1855, 120, - /* 410 */ 112, 111, 110, 109, 108, 107, 106, 105, 104, 1925, - /* 420 */ 482, 481, 632, 630, 156, 1867, 1868, 662, 1872, 1259, - /* 430 */ 208, 1257, 159, 162, 162, 61, 1922, 75, 516, 1480, - /* 440 */ 1752, 1335, 1336, 450, 29, 336, 1350, 1351, 1352, 1353, - /* 450 */ 1354, 1358, 1359, 1360, 1479, 315, 1262, 1263, 546, 1311, - /* 460 */ 1312, 1314, 1315, 1316, 1317, 1318, 576, 572, 1326, 1327, - /* 470 */ 1329, 1330, 1331, 1332, 1334, 1337, 1392, 33, 32, 1925, - /* 480 */ 1752, 40, 38, 36, 35, 34, 1259, 1357, 1257, 73, - /* 490 */ 304, 1650, 159, 519, 541, 1752, 1922, 33, 32, 348, - /* 500 */ 1284, 40, 38, 36, 35, 34, 316, 1649, 314, 313, - /* 510 */ 1362, 473, 616, 1262, 1263, 475, 1311, 1312, 1314, 1315, - /* 520 */ 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, - /* 530 */ 1332, 1334, 1337, 39, 37, 1338, 438, 474, 1006, 1007, - /* 540 */ 1925, 338, 1280, 1258, 1782, 162, 1874, 1478, 1313, 1019, - /* 550 */ 306, 1018, 27, 159, 1333, 1427, 1256, 1922, 1589, 33, - /* 560 */ 32, 221, 222, 40, 38, 36, 35, 34, 1285, 1766, - /* 570 */ 1871, 552, 1800, 547, 542, 162, 1574, 1328, 1281, 1020, - /* 580 */ 556, 529, 529, 1355, 153, 1752, 1477, 580, 1752, 1264, - /* 590 */ 39, 37, 384, 385, 22, 1762, 1768, 1637, 338, 122, - /* 600 */ 1258, 1522, 1075, 11, 10, 140, 9, 574, 1650, 1598, - /* 610 */ 1598, 1333, 1813, 1256, 1601, 342, 90, 1783, 583, 1785, - /* 620 */ 1786, 579, 304, 574, 1648, 519, 1859, 1752, 662, 529, - /* 630 */ 329, 1855, 154, 252, 1328, 1077, 616, 1356, 1874, 120, - /* 640 */ 389, 1473, 1335, 1336, 158, 1343, 1264, 1694, 1688, 299, - /* 650 */ 517, 1282, 1885, 1264, 157, 1867, 1868, 1598, 1872, 172, - /* 660 */ 1361, 1696, 1870, 9, 639, 638, 637, 636, 346, 561, + /* 250 */ 1285, 1600, 552, 1889, 1395, 1263, 1264, 162, 1313, 1314, + /* 260 */ 1316, 1317, 1318, 1319, 1320, 576, 572, 1328, 1329, 1331, + /* 270 */ 1332, 1333, 1334, 1336, 1339, 39, 37, 1455, 1928, 1754, + /* 280 */ 122, 174, 173, 338, 220, 1259, 40, 38, 36, 35, + /* 290 */ 34, 159, 306, 61, 42, 1925, 1335, 1741, 1257, 1114, + /* 300 */ 605, 604, 603, 1118, 602, 1120, 1121, 601, 1123, 598, + /* 310 */ 1803, 1129, 595, 1131, 1132, 592, 589, 1298, 545, 1330, + /* 320 */ 120, 1785, 33, 32, 14, 1357, 40, 38, 36, 35, + /* 330 */ 34, 1265, 39, 37, 554, 155, 1870, 1871, 86, 1875, + /* 340 */ 338, 552, 1259, 1772, 359, 1652, 1239, 1240, 2, 1803, + /* 350 */ 341, 119, 326, 1335, 1768, 1257, 544, 581, 140, 1592, + /* 360 */ 344, 1650, 1754, 529, 580, 1402, 1454, 1602, 140, 122, + /* 370 */ 662, 1284, 1284, 379, 165, 378, 1330, 1602, 557, 1358, + /* 380 */ 1764, 1770, 333, 1578, 1337, 1338, 1462, 432, 1265, 1816, + /* 390 */ 436, 1600, 574, 89, 1786, 583, 1788, 1789, 579, 1483, + /* 400 */ 574, 440, 1363, 1862, 436, 8, 215, 305, 1858, 120, + /* 410 */ 112, 111, 110, 109, 108, 107, 106, 105, 104, 1928, + /* 420 */ 482, 481, 632, 630, 156, 1870, 1871, 662, 1875, 1260, + /* 430 */ 208, 1258, 159, 162, 162, 61, 1925, 75, 516, 1482, + /* 440 */ 1754, 1337, 1338, 450, 29, 336, 1352, 1353, 1354, 1355, + /* 450 */ 1356, 1360, 1361, 1362, 1481, 315, 1263, 1264, 546, 1313, + /* 460 */ 1314, 1316, 1317, 1318, 1319, 1320, 576, 572, 1328, 1329, + /* 470 */ 1331, 1332, 1333, 1334, 1336, 1339, 1394, 33, 32, 1928, + /* 480 */ 1754, 40, 38, 36, 35, 34, 1260, 1359, 1258, 73, + /* 490 */ 304, 1652, 159, 519, 541, 1754, 1925, 33, 32, 348, + /* 500 */ 1286, 40, 38, 36, 35, 34, 316, 1651, 314, 313, + /* 510 */ 1364, 473, 616, 1263, 1264, 475, 1313, 1314, 1316, 1317, + /* 520 */ 1318, 1319, 1320, 576, 572, 1328, 1329, 1331, 1332, 1333, + /* 530 */ 1334, 1336, 1339, 39, 37, 1340, 438, 474, 1007, 1008, + /* 540 */ 1928, 338, 1282, 1259, 1785, 162, 1877, 1480, 1315, 1020, + /* 550 */ 306, 1019, 27, 159, 1335, 1429, 1257, 1925, 1591, 33, + /* 560 */ 32, 221, 222, 40, 38, 36, 35, 34, 1287, 1768, + /* 570 */ 1874, 552, 1803, 547, 542, 162, 1576, 1330, 1283, 1021, + /* 580 */ 556, 529, 529, 1357, 153, 1754, 1479, 580, 1754, 1265, + /* 590 */ 39, 37, 384, 385, 22, 1764, 1770, 1639, 338, 122, + /* 600 */ 1259, 1524, 1076, 11, 10, 140, 9, 574, 1652, 1600, + /* 610 */ 1600, 1335, 1816, 1257, 1603, 342, 90, 1786, 583, 1788, + /* 620 */ 1789, 579, 304, 574, 1650, 519, 1862, 1754, 662, 529, + /* 630 */ 329, 1858, 154, 252, 1330, 1078, 616, 1358, 1877, 120, + /* 640 */ 389, 1557, 1337, 1338, 158, 1345, 1265, 1696, 1690, 299, + /* 650 */ 517, 1284, 1888, 1265, 157, 1870, 1871, 1600, 1875, 172, + /* 660 */ 1363, 1698, 1873, 9, 639, 638, 637, 636, 346, 1587, /* 670 */ 635, 634, 633, 123, 628, 627, 626, 625, 624, 623, - /* 680 */ 622, 621, 133, 617, 1525, 662, 1282, 1259, 1369, 1257, - /* 690 */ 33, 32, 1874, 1476, 40, 38, 36, 35, 34, 1335, - /* 700 */ 1336, 232, 29, 336, 1350, 1351, 1352, 1353, 1354, 1358, - /* 710 */ 1359, 1360, 7, 1475, 1262, 1263, 1869, 1311, 1312, 1314, - /* 720 */ 1315, 1316, 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, - /* 730 */ 1331, 1332, 1334, 1337, 1752, 33, 32, 1879, 1389, 40, - /* 740 */ 38, 36, 35, 34, 1259, 608, 1257, 486, 485, 484, - /* 750 */ 44, 4, 1258, 483, 1752, 272, 118, 480, 1628, 619, - /* 760 */ 479, 478, 477, 1474, 1585, 1256, 1417, 1693, 1407, 299, - /* 770 */ 612, 1262, 1263, 1641, 1311, 1312, 1314, 1315, 1316, 1317, - /* 780 */ 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, 1332, 1334, - /* 790 */ 1337, 39, 37, 301, 613, 1280, 614, 1641, 1264, 338, - /* 800 */ 1581, 1258, 412, 1782, 1752, 424, 211, 538, 1415, 1416, - /* 810 */ 1418, 1419, 1333, 1296, 1256, 131, 130, 611, 610, 609, - /* 820 */ 11, 10, 397, 1575, 425, 575, 399, 59, 1313, 529, - /* 830 */ 529, 1800, 529, 1471, 620, 1328, 1570, 662, 1573, 581, - /* 840 */ 404, 405, 26, 449, 1752, 509, 580, 1264, 33, 32, - /* 850 */ 1507, 1505, 40, 38, 36, 35, 34, 1598, 1598, 390, - /* 860 */ 1598, 33, 32, 1313, 2, 40, 38, 36, 35, 34, - /* 870 */ 562, 1813, 489, 492, 1752, 91, 1783, 583, 1785, 1786, - /* 880 */ 579, 28, 574, 607, 631, 1859, 662, 33, 32, 1858, - /* 890 */ 1855, 40, 38, 36, 35, 34, 1259, 1389, 1257, 423, - /* 900 */ 1335, 1336, 418, 417, 416, 415, 414, 411, 410, 409, + /* 680 */ 622, 621, 133, 617, 1527, 662, 1284, 1260, 1371, 1258, + /* 690 */ 33, 32, 1877, 1478, 40, 38, 36, 35, 34, 1337, + /* 700 */ 1338, 232, 29, 336, 1352, 1353, 1354, 1355, 1356, 1360, + /* 710 */ 1361, 1362, 7, 1477, 1263, 1264, 1872, 1313, 1314, 1316, + /* 720 */ 1317, 1318, 1319, 1320, 576, 572, 1328, 1329, 1331, 1332, + /* 730 */ 1333, 1334, 1336, 1339, 1754, 33, 32, 1882, 1391, 40, + /* 740 */ 38, 36, 35, 34, 1260, 561, 1258, 486, 485, 484, + /* 750 */ 44, 4, 1259, 483, 1754, 272, 118, 480, 1630, 608, + /* 760 */ 479, 478, 477, 1476, 619, 1257, 1419, 1695, 1409, 299, + /* 770 */ 612, 1263, 1264, 1643, 1313, 1314, 1316, 1317, 1318, 1319, + /* 780 */ 1320, 576, 572, 1328, 1329, 1331, 1332, 1333, 1334, 1336, + /* 790 */ 1339, 39, 37, 301, 613, 1282, 614, 1643, 1265, 338, + /* 800 */ 1583, 1259, 412, 1785, 1754, 424, 1268, 538, 1417, 1418, + /* 810 */ 1420, 1421, 1335, 1298, 1257, 131, 130, 611, 610, 609, + /* 820 */ 11, 10, 397, 529, 425, 211, 399, 631, 1315, 529, + /* 830 */ 529, 1803, 529, 1473, 404, 1330, 620, 662, 1572, 581, + /* 840 */ 405, 449, 26, 1597, 1754, 59, 580, 1265, 33, 32, + /* 850 */ 1509, 1600, 40, 38, 36, 35, 34, 1600, 1600, 390, + /* 860 */ 1600, 33, 32, 1315, 2, 40, 38, 36, 35, 34, + /* 870 */ 374, 1816, 489, 570, 1754, 91, 1786, 583, 1788, 1789, + /* 880 */ 579, 28, 574, 1457, 1458, 1862, 662, 33, 32, 1861, + /* 890 */ 1858, 40, 38, 36, 35, 34, 1260, 1391, 1258, 423, + /* 900 */ 1337, 1338, 418, 417, 416, 415, 414, 411, 410, 409, /* 910 */ 408, 407, 403, 402, 401, 400, 394, 393, 392, 391, - /* 920 */ 614, 388, 387, 1262, 1263, 529, 1470, 374, 199, 141, - /* 930 */ 1555, 197, 564, 529, 278, 614, 1595, 52, 513, 131, - /* 940 */ 130, 611, 610, 609, 1727, 1259, 255, 1257, 276, 58, - /* 950 */ 41, 219, 57, 1598, 131, 130, 611, 610, 609, 1267, - /* 960 */ 1770, 1598, 502, 1469, 1782, 1455, 1456, 1752, 177, 429, - /* 970 */ 427, 1766, 1262, 1263, 1468, 1311, 1312, 1314, 1315, 1316, - /* 980 */ 1317, 1318, 576, 572, 1326, 1327, 1329, 1330, 1331, 1332, - /* 990 */ 1334, 1337, 1800, 1206, 223, 539, 61, 1762, 1768, 529, - /* 1000 */ 581, 468, 529, 1925, 1752, 1752, 139, 580, 1467, 574, - /* 1010 */ 510, 1266, 1466, 514, 529, 1752, 159, 1772, 201, 1465, - /* 1020 */ 1922, 200, 1464, 203, 1463, 527, 202, 1598, 570, 503, - /* 1030 */ 1598, 1801, 1813, 244, 88, 125, 90, 1783, 583, 1785, - /* 1040 */ 1786, 579, 1598, 574, 529, 1782, 1859, 529, 529, 1752, - /* 1050 */ 329, 1855, 1938, 1752, 205, 528, 1774, 204, 261, 345, - /* 1060 */ 1752, 1893, 552, 1752, 1046, 1752, 559, 128, 1501, 66, - /* 1070 */ 65, 383, 1598, 1800, 169, 1598, 1598, 347, 522, 85, - /* 1080 */ 377, 581, 129, 50, 335, 334, 1752, 1496, 580, 82, - /* 1090 */ 122, 236, 1270, 300, 1272, 1638, 367, 1047, 365, 361, - /* 1100 */ 357, 166, 352, 349, 249, 1333, 1889, 1265, 254, 553, - /* 1110 */ 229, 557, 257, 1813, 50, 3, 657, 90, 1783, 583, - /* 1120 */ 1785, 1786, 579, 1782, 574, 1106, 1414, 1859, 1328, 41, - /* 1130 */ 120, 329, 1855, 1938, 239, 565, 162, 41, 491, 259, - /* 1140 */ 1264, 80, 1916, 587, 1269, 250, 1867, 551, 53, 550, - /* 1150 */ 5, 1800, 1925, 501, 351, 1280, 354, 1363, 128, 581, - /* 1160 */ 1347, 358, 1222, 129, 1752, 159, 580, 207, 311, 1922, - /* 1170 */ 114, 128, 1319, 1075, 312, 406, 1782, 268, 1690, 569, - /* 1180 */ 271, 494, 171, 413, 421, 488, 1134, 420, 422, 1286, - /* 1190 */ 206, 1813, 426, 428, 430, 90, 1783, 583, 1785, 1786, - /* 1200 */ 579, 1138, 574, 431, 1800, 1859, 1145, 439, 1289, 329, - /* 1210 */ 1855, 1938, 581, 1143, 132, 442, 180, 1752, 56, 580, - /* 1220 */ 1878, 55, 443, 182, 1288, 1290, 445, 444, 1782, 185, - /* 1230 */ 447, 187, 1287, 557, 189, 451, 70, 448, 1273, 470, - /* 1240 */ 1268, 472, 192, 1588, 1813, 303, 196, 1732, 285, 1783, - /* 1250 */ 583, 1785, 1786, 579, 1584, 574, 1800, 93, 269, 198, - /* 1260 */ 134, 135, 504, 1586, 581, 1276, 1582, 136, 137, 1752, - /* 1270 */ 209, 580, 505, 212, 1925, 511, 572, 1326, 1327, 1329, - /* 1280 */ 1330, 1331, 1332, 515, 508, 557, 216, 161, 518, 537, - /* 1290 */ 227, 1922, 321, 1782, 126, 1731, 1813, 127, 1700, 520, - /* 1300 */ 285, 1783, 583, 1785, 1786, 579, 323, 574, 523, 1782, - /* 1310 */ 225, 524, 270, 525, 78, 1599, 1285, 1890, 533, 535, - /* 1320 */ 540, 1800, 234, 238, 1900, 536, 1925, 328, 6, 581, - /* 1330 */ 543, 549, 534, 532, 1752, 531, 580, 1800, 248, 159, - /* 1340 */ 1389, 121, 1284, 1922, 566, 578, 563, 48, 1899, 330, - /* 1350 */ 1752, 1875, 580, 1840, 585, 1881, 245, 243, 1642, 148, - /* 1360 */ 247, 1813, 273, 264, 1782, 91, 1783, 583, 1785, 1786, - /* 1370 */ 579, 246, 574, 1571, 658, 1859, 1782, 1813, 659, 568, - /* 1380 */ 1855, 293, 1783, 583, 1785, 1786, 579, 577, 574, 571, - /* 1390 */ 1831, 661, 1800, 51, 147, 275, 1746, 1921, 253, 286, - /* 1400 */ 581, 296, 295, 277, 1800, 1752, 560, 580, 256, 1941, - /* 1410 */ 567, 63, 581, 258, 1745, 1744, 64, 1752, 1743, 580, - /* 1420 */ 353, 1740, 355, 356, 1250, 1251, 167, 360, 1738, 362, - /* 1430 */ 363, 364, 1813, 1737, 366, 1736, 144, 1783, 583, 1785, - /* 1440 */ 1786, 579, 368, 574, 1813, 1735, 370, 1734, 91, 1783, - /* 1450 */ 583, 1785, 1786, 579, 1782, 574, 1717, 372, 1859, 375, - /* 1460 */ 168, 376, 1225, 1856, 1224, 1711, 1710, 381, 1782, 382, - /* 1470 */ 1709, 1708, 1194, 1683, 1682, 1681, 67, 1680, 1782, 1679, - /* 1480 */ 558, 1939, 1800, 1678, 1677, 1676, 395, 322, 396, 1675, - /* 1490 */ 581, 398, 1674, 1673, 1672, 1752, 1800, 580, 1671, 1670, - /* 1500 */ 1669, 530, 1668, 1667, 581, 1666, 1800, 1665, 1664, 1752, - /* 1510 */ 1663, 580, 1662, 1661, 581, 1660, 1659, 1658, 124, 1752, - /* 1520 */ 1657, 580, 1813, 1656, 1655, 1654, 294, 1783, 583, 1785, - /* 1530 */ 1786, 579, 1653, 574, 1652, 1782, 1813, 1651, 1527, 1526, - /* 1540 */ 294, 1783, 583, 1785, 1786, 579, 1813, 574, 1524, 1196, - /* 1550 */ 289, 1783, 583, 1785, 1786, 579, 1492, 574, 1491, 1782, - /* 1560 */ 175, 178, 176, 1800, 152, 115, 1009, 1008, 435, 179, - /* 1570 */ 116, 581, 1725, 1719, 437, 1707, 1752, 186, 580, 184, - /* 1580 */ 1706, 1692, 1577, 1523, 1521, 1782, 452, 1800, 548, 453, - /* 1590 */ 1519, 1517, 1039, 454, 456, 578, 457, 460, 1515, 458, - /* 1600 */ 1752, 1504, 580, 1813, 461, 462, 464, 144, 1783, 583, - /* 1610 */ 1785, 1786, 579, 1800, 574, 465, 466, 1503, 337, 1488, - /* 1620 */ 1579, 581, 1149, 1578, 1148, 195, 1752, 1813, 580, 49, - /* 1630 */ 1074, 293, 1783, 583, 1785, 1786, 579, 629, 574, 1782, - /* 1640 */ 1832, 1073, 1072, 631, 1071, 1068, 1067, 1066, 1065, 1513, - /* 1650 */ 317, 1508, 1940, 1813, 318, 665, 1506, 294, 1783, 583, - /* 1660 */ 1785, 1786, 579, 490, 574, 319, 493, 1800, 1487, 267, - /* 1670 */ 495, 1486, 339, 497, 1485, 581, 499, 92, 1724, 1232, - /* 1680 */ 1752, 1718, 580, 151, 506, 1705, 138, 1703, 655, 651, - /* 1690 */ 647, 643, 265, 1704, 54, 213, 507, 1702, 1701, 320, - /* 1700 */ 15, 1699, 512, 1691, 218, 226, 224, 1813, 41, 76, - /* 1710 */ 77, 294, 1783, 583, 1785, 1786, 579, 194, 574, 231, - /* 1720 */ 87, 521, 1782, 230, 82, 228, 16, 23, 242, 47, - /* 1730 */ 233, 146, 1429, 235, 1411, 237, 467, 463, 459, 455, - /* 1740 */ 193, 1413, 1242, 145, 240, 24, 1782, 1406, 241, 81, - /* 1750 */ 1800, 10, 1772, 25, 1441, 1386, 526, 251, 581, 45, - /* 1760 */ 46, 1385, 1771, 1752, 149, 580, 1446, 18, 72, 1435, - /* 1770 */ 1440, 191, 331, 1445, 1800, 1444, 332, 1274, 1348, 17, - /* 1780 */ 1816, 573, 581, 1304, 13, 19, 1323, 1752, 217, 580, - /* 1790 */ 1813, 150, 163, 1321, 279, 1783, 583, 1785, 1786, 579, - /* 1800 */ 31, 574, 1782, 586, 1112, 584, 1320, 12, 20, 1230, - /* 1810 */ 21, 210, 1135, 340, 1813, 588, 590, 582, 280, 1783, - /* 1820 */ 583, 1785, 1786, 579, 591, 574, 593, 596, 599, 1132, - /* 1830 */ 1800, 606, 594, 190, 183, 597, 188, 1129, 581, 1123, - /* 1840 */ 446, 1127, 1121, 1752, 1782, 580, 1144, 600, 83, 84, - /* 1850 */ 60, 262, 1140, 1126, 1782, 1062, 1037, 1125, 615, 181, - /* 1860 */ 618, 1124, 263, 1081, 1060, 1055, 1782, 1059, 1058, 1057, - /* 1870 */ 1813, 1056, 1800, 1054, 281, 1783, 583, 1785, 1786, 579, - /* 1880 */ 581, 574, 1800, 1053, 1078, 1752, 1076, 580, 1050, 1049, - /* 1890 */ 581, 1048, 1045, 1044, 1800, 1752, 1043, 580, 1042, 1520, - /* 1900 */ 640, 642, 581, 1518, 644, 646, 641, 1752, 1516, 580, - /* 1910 */ 648, 645, 1813, 650, 649, 1514, 288, 1783, 583, 1785, - /* 1920 */ 1786, 579, 1813, 574, 652, 653, 290, 1783, 583, 1785, - /* 1930 */ 1786, 579, 654, 574, 1813, 656, 999, 1484, 282, 1783, - /* 1940 */ 583, 1785, 1786, 579, 1502, 574, 266, 1782, 660, 1459, - /* 1950 */ 1260, 274, 663, 664, 1459, 1459, 1459, 1459, 1459, 1459, - /* 1960 */ 1459, 1459, 1459, 1459, 1459, 1459, 1782, 1459, 1459, 1459, - /* 1970 */ 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, - /* 1980 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, - /* 1990 */ 580, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, 1459, - /* 2000 */ 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, 580, - /* 2010 */ 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 291, - /* 2020 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1782, 1459, 1459, - /* 2030 */ 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 283, 1783, - /* 2040 */ 583, 1785, 1786, 579, 1459, 574, 1782, 1459, 1459, 1459, - /* 2050 */ 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, - /* 2060 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, - /* 2070 */ 580, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, 1459, - /* 2080 */ 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, 580, - /* 2090 */ 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 292, - /* 2100 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1459, 1459, 1459, - /* 2110 */ 1459, 1459, 1459, 1782, 1813, 1459, 1459, 1459, 284, 1783, - /* 2120 */ 583, 1785, 1786, 579, 1459, 574, 1459, 1459, 1459, 1782, - /* 2130 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1782, - /* 2140 */ 1459, 1800, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 581, - /* 2150 */ 1459, 1459, 1459, 1459, 1752, 1459, 580, 1800, 1459, 1459, - /* 2160 */ 1459, 1459, 1459, 1459, 1459, 581, 1459, 1800, 1459, 1459, - /* 2170 */ 1752, 1459, 580, 1459, 1459, 581, 1459, 1459, 1459, 1459, - /* 2180 */ 1752, 1813, 580, 1459, 1459, 297, 1783, 583, 1785, 1786, - /* 2190 */ 579, 1459, 574, 1782, 1459, 1459, 1459, 1813, 1459, 1459, - /* 2200 */ 1459, 298, 1783, 583, 1785, 1786, 579, 1813, 574, 1459, - /* 2210 */ 1459, 1794, 1783, 583, 1785, 1786, 579, 1459, 574, 1459, - /* 2220 */ 1459, 1800, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 581, - /* 2230 */ 1459, 1459, 1459, 1459, 1752, 1459, 580, 1459, 1459, 1459, - /* 2240 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1782, 1459, 1459, - /* 2250 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, - /* 2260 */ 1459, 1813, 1459, 1459, 1459, 1793, 1783, 583, 1785, 1786, - /* 2270 */ 579, 1459, 574, 1459, 1459, 1800, 1459, 1459, 1459, 1459, - /* 2280 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, - /* 2290 */ 580, 1459, 1459, 1459, 1459, 1459, 1459, 1782, 1459, 1459, - /* 2300 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, - /* 2310 */ 1459, 1459, 1459, 1459, 1782, 1813, 1459, 1459, 1459, 1792, - /* 2320 */ 1783, 583, 1785, 1786, 579, 1800, 574, 1459, 1459, 1459, - /* 2330 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, - /* 2340 */ 580, 1459, 1800, 1459, 1459, 1459, 1459, 1459, 1459, 1459, - /* 2350 */ 581, 1459, 1459, 1459, 1459, 1752, 1459, 580, 1459, 1459, - /* 2360 */ 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 309, - /* 2370 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1782, 1459, 1459, - /* 2380 */ 1459, 1459, 1813, 1459, 1459, 1459, 308, 1783, 583, 1785, - /* 2390 */ 1786, 579, 1459, 574, 1459, 1459, 1459, 1459, 1782, 1459, - /* 2400 */ 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, 1459, - /* 2410 */ 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, 1459, - /* 2420 */ 580, 1459, 1459, 1459, 1459, 1459, 1800, 1459, 1459, 1459, - /* 2430 */ 1459, 1459, 1459, 1459, 581, 1459, 1459, 1459, 1459, 1752, - /* 2440 */ 1782, 580, 1459, 1459, 1459, 1813, 1459, 1459, 1459, 310, - /* 2450 */ 1783, 583, 1785, 1786, 579, 1459, 574, 1459, 1459, 1459, - /* 2460 */ 1459, 1459, 1459, 1459, 1459, 1459, 1813, 1459, 1800, 1459, - /* 2470 */ 307, 1783, 583, 1785, 1786, 579, 581, 574, 1459, 1459, - /* 2480 */ 1459, 1752, 1459, 580, 1459, 1459, 1459, 1459, 1459, 1459, - /* 2490 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, - /* 2500 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1813, 1459, - /* 2510 */ 1459, 1459, 287, 1783, 583, 1785, 1786, 579, 1459, 574, + /* 920 */ 575, 388, 387, 1263, 1264, 529, 564, 529, 1507, 141, + /* 930 */ 1472, 529, 199, 529, 278, 197, 1729, 201, 510, 1271, + /* 940 */ 200, 1047, 514, 194, 527, 1260, 562, 1258, 276, 58, + /* 950 */ 492, 203, 57, 1600, 202, 1600, 607, 146, 502, 1600, + /* 960 */ 509, 1600, 467, 463, 459, 455, 193, 1785, 177, 429, + /* 970 */ 427, 1754, 1263, 1264, 1048, 1313, 1314, 1316, 1317, 1318, + /* 980 */ 1319, 1320, 576, 572, 1328, 1329, 1331, 1332, 1333, 1334, + /* 990 */ 1336, 1339, 335, 334, 72, 1803, 61, 191, 529, 1928, + /* 1000 */ 529, 205, 1273, 581, 204, 1349, 139, 1475, 1754, 528, + /* 1010 */ 580, 261, 159, 1335, 1773, 1266, 1925, 52, 513, 529, + /* 1020 */ 255, 539, 85, 468, 1471, 1768, 1600, 1470, 1600, 1267, + /* 1030 */ 345, 1469, 82, 41, 88, 1816, 1330, 1577, 1468, 90, + /* 1040 */ 1786, 583, 1788, 1789, 579, 1785, 574, 1600, 1265, 1862, + /* 1050 */ 1467, 1764, 1770, 329, 1858, 1941, 1503, 503, 244, 190, + /* 1060 */ 183, 1575, 188, 574, 1896, 1754, 446, 1466, 1754, 66, + /* 1070 */ 65, 383, 1754, 1803, 169, 1465, 1207, 1804, 347, 1754, + /* 1080 */ 377, 581, 219, 125, 559, 181, 1754, 569, 580, 1775, + /* 1090 */ 1498, 1754, 1640, 300, 128, 129, 367, 50, 365, 361, + /* 1100 */ 357, 166, 352, 349, 657, 1892, 236, 50, 1754, 41, + /* 1110 */ 249, 553, 254, 1816, 257, 259, 1754, 90, 1786, 583, + /* 1120 */ 1788, 1789, 579, 1785, 574, 223, 522, 1862, 1777, 565, + /* 1130 */ 80, 329, 1858, 1941, 614, 3, 162, 229, 1107, 41, + /* 1140 */ 1416, 53, 1919, 5, 351, 1282, 1274, 354, 1269, 239, + /* 1150 */ 1365, 1803, 1321, 131, 130, 611, 610, 609, 614, 581, + /* 1160 */ 587, 128, 1270, 358, 1754, 1785, 580, 311, 1076, 129, + /* 1170 */ 114, 128, 312, 1277, 1279, 1223, 268, 131, 130, 611, + /* 1180 */ 610, 609, 271, 406, 572, 1328, 1329, 1331, 1332, 1333, + /* 1190 */ 1334, 1816, 1692, 1803, 171, 90, 1786, 583, 1788, 1789, + /* 1200 */ 579, 581, 574, 1135, 1139, 1862, 1754, 413, 580, 329, + /* 1210 */ 1858, 1941, 1146, 1144, 132, 421, 426, 420, 422, 428, + /* 1220 */ 1881, 430, 557, 1288, 431, 439, 1785, 180, 1291, 442, + /* 1230 */ 443, 182, 1290, 1816, 444, 1292, 1785, 285, 1786, 583, + /* 1240 */ 1788, 1789, 579, 445, 574, 491, 185, 447, 1289, 187, + /* 1250 */ 448, 189, 70, 451, 1803, 192, 470, 472, 1590, 196, + /* 1260 */ 501, 1586, 581, 1928, 1803, 303, 1734, 1754, 93, 580, + /* 1270 */ 198, 209, 581, 269, 207, 134, 161, 1754, 135, 580, + /* 1280 */ 1925, 1588, 504, 557, 1584, 136, 137, 508, 494, 505, + /* 1290 */ 212, 511, 488, 1785, 1816, 515, 216, 206, 285, 1786, + /* 1300 */ 583, 1788, 1789, 579, 1816, 574, 537, 1785, 91, 1786, + /* 1310 */ 583, 1788, 1789, 579, 126, 574, 518, 1733, 1862, 1702, + /* 1320 */ 321, 1803, 568, 1858, 1928, 56, 520, 523, 55, 578, + /* 1330 */ 323, 127, 524, 525, 1754, 1803, 580, 159, 225, 227, + /* 1340 */ 270, 1925, 1601, 581, 78, 1287, 533, 540, 1754, 535, + /* 1350 */ 580, 234, 1893, 1903, 536, 1902, 238, 1785, 328, 543, + /* 1360 */ 6, 1816, 1884, 549, 534, 293, 1786, 583, 1788, 1789, + /* 1370 */ 579, 577, 574, 571, 1834, 1816, 243, 1785, 148, 144, + /* 1380 */ 1786, 583, 1788, 1789, 579, 1803, 574, 532, 531, 248, + /* 1390 */ 1391, 245, 246, 581, 121, 247, 1286, 1878, 1754, 566, + /* 1400 */ 580, 563, 48, 330, 253, 1803, 1924, 1573, 1644, 273, + /* 1410 */ 322, 658, 585, 581, 560, 1944, 1843, 264, 1754, 661, + /* 1420 */ 580, 51, 659, 558, 1942, 1816, 147, 277, 256, 91, + /* 1430 */ 1786, 583, 1788, 1789, 579, 1748, 574, 286, 275, 1862, + /* 1440 */ 567, 258, 296, 1785, 1859, 1816, 63, 295, 1747, 294, + /* 1450 */ 1786, 583, 1788, 1789, 579, 1785, 574, 1746, 64, 1745, + /* 1460 */ 353, 1742, 355, 1251, 356, 1785, 1252, 167, 360, 1740, + /* 1470 */ 364, 1803, 362, 363, 1739, 366, 530, 1738, 368, 581, + /* 1480 */ 1737, 1736, 370, 1803, 1754, 1719, 580, 372, 168, 375, + /* 1490 */ 376, 581, 1226, 1803, 1225, 1713, 1754, 1712, 580, 381, + /* 1500 */ 382, 581, 1711, 1710, 1195, 1685, 1754, 1684, 580, 1683, + /* 1510 */ 67, 1816, 1682, 1681, 1680, 294, 1786, 583, 1788, 1789, + /* 1520 */ 579, 1785, 574, 1816, 1679, 1678, 396, 289, 1786, 583, + /* 1530 */ 1788, 1789, 579, 1816, 574, 1785, 395, 144, 1786, 583, + /* 1540 */ 1788, 1789, 579, 1677, 574, 398, 1676, 1675, 1674, 1803, + /* 1550 */ 124, 1662, 1661, 1660, 1659, 1658, 1657, 578, 1673, 1672, + /* 1560 */ 1671, 1670, 1754, 1803, 580, 548, 1669, 1668, 337, 1667, + /* 1570 */ 1666, 581, 1665, 1664, 1663, 1656, 1754, 1655, 580, 1197, + /* 1580 */ 1654, 1653, 1943, 1529, 175, 1528, 176, 1526, 1785, 1816, + /* 1590 */ 1494, 178, 1010, 293, 1786, 583, 1788, 1789, 579, 1493, + /* 1600 */ 574, 115, 1835, 1816, 179, 1009, 152, 294, 1786, 583, + /* 1610 */ 1788, 1789, 579, 665, 574, 453, 1803, 435, 116, 1727, + /* 1620 */ 1721, 339, 437, 1709, 581, 184, 1708, 267, 186, 1754, + /* 1630 */ 1785, 580, 1694, 1579, 1525, 1523, 452, 454, 1521, 456, + /* 1640 */ 457, 151, 1519, 460, 1785, 458, 655, 651, 647, 643, + /* 1650 */ 265, 1040, 461, 462, 1517, 466, 1816, 464, 1803, 465, + /* 1660 */ 294, 1786, 583, 1788, 1789, 579, 581, 574, 1506, 1505, + /* 1670 */ 1490, 1754, 1803, 580, 1581, 1150, 49, 1149, 87, 1580, + /* 1680 */ 581, 230, 1075, 1074, 195, 1754, 1073, 580, 1072, 629, + /* 1690 */ 1515, 1069, 631, 1068, 1067, 1066, 1510, 317, 1816, 318, + /* 1700 */ 1508, 490, 279, 1786, 583, 1788, 1789, 579, 1785, 574, + /* 1710 */ 319, 493, 1816, 1489, 526, 495, 280, 1786, 583, 1788, + /* 1720 */ 1789, 579, 1488, 574, 497, 1487, 499, 92, 1726, 1233, + /* 1730 */ 1785, 1720, 506, 1707, 1705, 1706, 1803, 54, 1704, 1703, + /* 1740 */ 1701, 1693, 226, 231, 581, 82, 217, 213, 507, 1754, + /* 1750 */ 1785, 580, 218, 320, 41, 16, 15, 512, 1803, 1431, + /* 1760 */ 138, 521, 228, 224, 47, 242, 581, 1231, 76, 210, + /* 1770 */ 77, 1754, 23, 580, 17, 241, 1816, 1243, 1803, 235, + /* 1780 */ 281, 1786, 583, 1788, 1789, 579, 581, 574, 1413, 1775, + /* 1790 */ 233, 1754, 1785, 580, 237, 25, 251, 145, 1816, 46, + /* 1800 */ 1415, 240, 288, 1786, 583, 1788, 1789, 579, 1785, 574, + /* 1810 */ 1408, 24, 81, 1774, 149, 1388, 1387, 18, 1816, 1443, + /* 1820 */ 1803, 1442, 290, 1786, 583, 1788, 1789, 579, 581, 574, + /* 1830 */ 45, 1448, 1437, 1754, 331, 580, 1803, 1447, 13, 1446, + /* 1840 */ 332, 10, 1275, 19, 581, 1819, 1306, 1325, 573, 1754, + /* 1850 */ 1323, 580, 1322, 150, 1350, 31, 12, 20, 163, 582, + /* 1860 */ 1816, 1785, 21, 586, 282, 1786, 583, 1788, 1789, 579, + /* 1870 */ 340, 574, 584, 1785, 1136, 588, 1816, 1133, 590, 591, + /* 1880 */ 291, 1786, 583, 1788, 1789, 579, 593, 574, 594, 1803, + /* 1890 */ 596, 599, 1130, 1113, 1124, 597, 600, 581, 1128, 1122, + /* 1900 */ 83, 1803, 1754, 84, 580, 1127, 1126, 1125, 1145, 581, + /* 1910 */ 262, 606, 60, 1141, 1754, 1785, 580, 1063, 1082, 1038, + /* 1920 */ 615, 618, 263, 1061, 1060, 1785, 1056, 1059, 1058, 1816, + /* 1930 */ 1057, 1055, 1054, 283, 1786, 583, 1788, 1789, 579, 1785, + /* 1940 */ 574, 1816, 1079, 1803, 1077, 292, 1786, 583, 1788, 1789, + /* 1950 */ 579, 581, 574, 1803, 1051, 1050, 1754, 1049, 580, 1046, + /* 1960 */ 1045, 581, 1044, 1043, 1522, 640, 1754, 1803, 580, 1520, + /* 1970 */ 641, 642, 644, 645, 646, 581, 1518, 648, 649, 1516, + /* 1980 */ 1754, 652, 580, 1816, 650, 653, 654, 284, 1786, 583, + /* 1990 */ 1788, 1789, 579, 1816, 574, 1785, 1504, 297, 1786, 583, + /* 2000 */ 1788, 1789, 579, 656, 574, 1785, 1000, 1816, 1486, 266, + /* 2010 */ 660, 298, 1786, 583, 1788, 1789, 579, 1785, 574, 1261, + /* 2020 */ 274, 663, 664, 1803, 1461, 1461, 1461, 1461, 1461, 1461, + /* 2030 */ 1461, 581, 1461, 1803, 1461, 1461, 1754, 1461, 580, 1461, + /* 2040 */ 1461, 581, 1461, 1461, 1461, 1803, 1754, 1461, 580, 1461, + /* 2050 */ 1461, 1461, 1461, 581, 1461, 1461, 1461, 1461, 1754, 1461, + /* 2060 */ 580, 1461, 1461, 1816, 1461, 1461, 1461, 1797, 1786, 583, + /* 2070 */ 1788, 1789, 579, 1816, 574, 1461, 1461, 1796, 1786, 583, + /* 2080 */ 1788, 1789, 579, 1785, 574, 1816, 1461, 1461, 1461, 1795, + /* 2090 */ 1786, 583, 1788, 1789, 579, 1785, 574, 1461, 1461, 1461, + /* 2100 */ 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1461, + /* 2110 */ 1461, 1803, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 581, + /* 2120 */ 1461, 1461, 1461, 1803, 1754, 1461, 580, 1461, 1461, 1461, + /* 2130 */ 1461, 581, 1461, 1461, 1461, 1461, 1754, 1461, 580, 1461, + /* 2140 */ 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1785, 1461, + /* 2150 */ 1461, 1816, 1461, 1461, 1461, 309, 1786, 583, 1788, 1789, + /* 2160 */ 579, 1461, 574, 1816, 1461, 1461, 1461, 308, 1786, 583, + /* 2170 */ 1788, 1789, 579, 1461, 574, 1461, 1803, 1461, 1461, 1461, + /* 2180 */ 1461, 1461, 1461, 1461, 581, 1461, 1461, 1461, 1461, 1754, + /* 2190 */ 1461, 580, 1461, 1461, 1461, 1461, 1461, 1461, 1785, 1461, + /* 2200 */ 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1785, 1461, + /* 2210 */ 552, 1461, 1461, 1461, 1461, 1461, 1816, 1461, 1461, 1461, + /* 2220 */ 310, 1786, 583, 1788, 1789, 579, 1803, 574, 1461, 1461, + /* 2230 */ 1461, 1461, 1461, 1461, 581, 1461, 1803, 1461, 122, 1754, + /* 2240 */ 1461, 580, 1461, 1461, 581, 1461, 1461, 1461, 1461, 1754, + /* 2250 */ 1461, 580, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 557, + /* 2260 */ 1461, 1461, 1461, 1461, 1461, 1461, 1816, 1461, 1461, 1461, + /* 2270 */ 307, 1786, 583, 1788, 1789, 579, 1816, 574, 120, 1461, + /* 2280 */ 287, 1786, 583, 1788, 1789, 579, 1461, 574, 1461, 1461, + /* 2290 */ 1461, 1461, 1461, 250, 1870, 551, 1461, 550, 1461, 1461, + /* 2300 */ 1928, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1461, 1461, + /* 2310 */ 1461, 1461, 1461, 159, 1461, 1461, 1461, 1925, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 266, 0, 262, 266, 264, 265, 262, 287, 264, 265, @@ -536,9 +516,9 @@ static const YYCODETYPE yy_lookahead[] = { /* 610 */ 294, 33, 326, 35, 295, 293, 330, 331, 332, 333, /* 620 */ 334, 335, 177, 337, 302, 180, 340, 299, 107, 266, /* 630 */ 344, 345, 346, 153, 56, 68, 60, 148, 328, 334, - /* 640 */ 277, 259, 121, 122, 358, 14, 68, 311, 294, 313, + /* 640 */ 277, 275, 121, 122, 358, 14, 68, 311, 294, 313, /* 650 */ 301, 20, 366, 68, 349, 350, 351, 294, 353, 305, - /* 660 */ 171, 312, 352, 85, 63, 64, 65, 66, 67, 43, + /* 660 */ 171, 312, 352, 85, 63, 64, 65, 66, 67, 287, /* 670 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, /* 680 */ 79, 80, 81, 82, 0, 107, 20, 166, 86, 168, /* 690 */ 8, 9, 328, 258, 12, 13, 14, 15, 16, 121, @@ -546,195 +526,175 @@ static const YYCODETYPE yy_lookahead[] = { /* 710 */ 221, 222, 39, 258, 193, 194, 352, 196, 197, 198, /* 720 */ 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, /* 730 */ 209, 210, 211, 212, 299, 8, 9, 223, 224, 12, - /* 740 */ 13, 14, 15, 16, 166, 96, 168, 63, 64, 65, - /* 750 */ 42, 43, 22, 69, 299, 279, 72, 73, 282, 68, - /* 760 */ 76, 77, 78, 258, 287, 35, 193, 311, 86, 313, + /* 740 */ 13, 14, 15, 16, 166, 43, 168, 63, 64, 65, + /* 750 */ 42, 43, 22, 69, 299, 279, 72, 73, 282, 96, + /* 760 */ 76, 77, 78, 258, 68, 35, 193, 311, 86, 313, /* 770 */ 296, 193, 194, 299, 196, 197, 198, 199, 200, 201, /* 780 */ 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, /* 790 */ 212, 12, 13, 18, 296, 20, 97, 299, 68, 20, - /* 800 */ 287, 22, 27, 258, 299, 30, 287, 234, 235, 236, + /* 800 */ 287, 22, 27, 258, 299, 30, 35, 234, 235, 236, /* 810 */ 237, 238, 33, 86, 35, 116, 117, 118, 119, 120, - /* 820 */ 1, 2, 47, 0, 49, 287, 51, 3, 197, 266, - /* 830 */ 266, 286, 266, 258, 274, 56, 276, 107, 0, 294, - /* 840 */ 277, 277, 2, 277, 299, 319, 301, 68, 8, 9, - /* 850 */ 0, 0, 12, 13, 14, 15, 16, 294, 294, 84, + /* 820 */ 1, 2, 47, 266, 49, 287, 51, 43, 197, 266, + /* 830 */ 266, 286, 266, 258, 277, 56, 274, 107, 276, 294, + /* 840 */ 277, 277, 2, 277, 299, 3, 301, 68, 8, 9, + /* 850 */ 0, 294, 12, 13, 14, 15, 16, 294, 294, 84, /* 860 */ 294, 8, 9, 197, 85, 12, 13, 14, 15, 16, - /* 870 */ 244, 326, 22, 22, 299, 330, 331, 332, 333, 334, - /* 880 */ 335, 2, 337, 287, 43, 340, 107, 8, 9, 344, + /* 870 */ 86, 326, 22, 61, 299, 330, 331, 332, 333, 334, + /* 880 */ 335, 2, 337, 121, 122, 340, 107, 8, 9, 344, /* 890 */ 345, 12, 13, 14, 15, 16, 166, 224, 168, 124, /* 900 */ 121, 122, 127, 128, 129, 130, 131, 132, 133, 134, /* 910 */ 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, - /* 920 */ 97, 146, 147, 193, 194, 266, 258, 86, 89, 18, - /* 930 */ 275, 92, 43, 266, 23, 97, 277, 153, 154, 116, - /* 940 */ 117, 118, 119, 120, 277, 166, 376, 168, 37, 38, - /* 950 */ 43, 43, 41, 294, 116, 117, 118, 119, 120, 35, - /* 960 */ 288, 294, 315, 258, 258, 121, 122, 299, 57, 58, - /* 970 */ 59, 299, 193, 194, 258, 196, 197, 198, 199, 200, + /* 920 */ 287, 146, 147, 193, 194, 266, 43, 266, 0, 18, + /* 930 */ 258, 266, 89, 266, 23, 92, 277, 89, 277, 168, + /* 940 */ 92, 35, 277, 33, 277, 166, 244, 168, 37, 38, + /* 950 */ 22, 89, 41, 294, 92, 294, 287, 47, 315, 294, + /* 960 */ 319, 294, 52, 53, 54, 55, 56, 258, 57, 58, + /* 970 */ 59, 299, 193, 194, 68, 196, 197, 198, 199, 200, /* 980 */ 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, - /* 990 */ 211, 212, 286, 86, 86, 367, 85, 325, 326, 266, - /* 1000 */ 294, 267, 266, 356, 299, 299, 153, 301, 258, 337, - /* 1010 */ 277, 35, 258, 277, 266, 299, 369, 46, 89, 258, - /* 1020 */ 373, 92, 258, 89, 258, 277, 92, 294, 61, 322, - /* 1030 */ 294, 286, 326, 363, 123, 43, 330, 331, 332, 333, - /* 1040 */ 334, 335, 294, 337, 266, 258, 340, 266, 266, 299, - /* 1050 */ 344, 345, 346, 299, 89, 277, 85, 92, 277, 277, - /* 1060 */ 299, 355, 266, 299, 35, 299, 242, 43, 0, 158, - /* 1070 */ 159, 160, 294, 286, 163, 294, 294, 267, 86, 85, - /* 1080 */ 169, 294, 43, 43, 12, 13, 299, 265, 301, 95, - /* 1090 */ 294, 43, 168, 182, 22, 298, 185, 68, 187, 188, - /* 1100 */ 189, 190, 191, 192, 347, 33, 329, 35, 370, 354, - /* 1110 */ 86, 315, 370, 326, 43, 357, 48, 330, 331, 332, - /* 1120 */ 333, 334, 335, 258, 337, 86, 86, 340, 56, 43, - /* 1130 */ 334, 344, 345, 346, 86, 246, 225, 43, 4, 370, - /* 1140 */ 68, 85, 355, 43, 168, 349, 350, 351, 290, 353, - /* 1150 */ 227, 286, 356, 19, 324, 20, 266, 86, 43, 294, - /* 1160 */ 193, 47, 164, 43, 299, 369, 301, 33, 323, 373, - /* 1170 */ 43, 43, 86, 35, 272, 266, 258, 317, 266, 107, - /* 1180 */ 86, 47, 42, 306, 148, 51, 86, 304, 304, 20, - /* 1190 */ 56, 326, 266, 266, 266, 330, 331, 332, 333, 334, - /* 1200 */ 335, 86, 337, 260, 286, 340, 86, 260, 20, 344, - /* 1210 */ 345, 346, 294, 86, 86, 321, 270, 299, 84, 301, - /* 1220 */ 355, 87, 301, 270, 20, 20, 316, 314, 258, 270, - /* 1230 */ 314, 270, 20, 315, 270, 266, 270, 307, 166, 260, - /* 1240 */ 168, 286, 270, 286, 326, 260, 286, 299, 330, 331, - /* 1250 */ 332, 333, 334, 335, 286, 337, 286, 266, 321, 286, - /* 1260 */ 286, 286, 174, 286, 294, 193, 286, 286, 286, 299, - /* 1270 */ 268, 301, 320, 268, 356, 266, 204, 205, 206, 207, - /* 1280 */ 208, 209, 210, 266, 301, 315, 268, 369, 299, 232, - /* 1290 */ 268, 373, 314, 258, 310, 299, 326, 310, 299, 299, - /* 1300 */ 330, 331, 332, 333, 334, 335, 299, 337, 150, 258, - /* 1310 */ 294, 308, 282, 307, 268, 294, 20, 329, 299, 299, - /* 1320 */ 233, 286, 310, 310, 362, 299, 356, 299, 239, 294, - /* 1330 */ 299, 157, 241, 240, 299, 228, 301, 286, 324, 369, - /* 1340 */ 224, 294, 20, 373, 245, 294, 243, 85, 362, 248, - /* 1350 */ 299, 328, 301, 343, 290, 365, 361, 364, 299, 362, - /* 1360 */ 359, 326, 266, 268, 258, 330, 331, 332, 333, 334, - /* 1370 */ 335, 360, 337, 276, 36, 340, 258, 326, 261, 344, - /* 1380 */ 345, 330, 331, 332, 333, 334, 335, 336, 337, 338, - /* 1390 */ 339, 260, 286, 318, 313, 269, 0, 372, 371, 280, - /* 1400 */ 294, 280, 280, 256, 286, 299, 372, 301, 371, 377, - /* 1410 */ 372, 176, 294, 371, 0, 0, 42, 299, 0, 301, - /* 1420 */ 76, 0, 35, 186, 35, 35, 35, 186, 0, 35, - /* 1430 */ 35, 186, 326, 0, 186, 0, 330, 331, 332, 333, - /* 1440 */ 334, 335, 35, 337, 326, 0, 22, 0, 330, 331, - /* 1450 */ 332, 333, 334, 335, 258, 337, 0, 35, 340, 171, - /* 1460 */ 85, 170, 168, 345, 166, 0, 0, 162, 258, 161, - /* 1470 */ 0, 0, 46, 0, 0, 0, 145, 0, 258, 0, - /* 1480 */ 374, 375, 286, 0, 0, 0, 140, 291, 35, 0, - /* 1490 */ 294, 140, 0, 0, 0, 299, 286, 301, 0, 0, - /* 1500 */ 0, 291, 0, 0, 294, 0, 286, 0, 0, 299, - /* 1510 */ 0, 301, 0, 0, 294, 0, 0, 0, 42, 299, - /* 1520 */ 0, 301, 326, 0, 0, 0, 330, 331, 332, 333, - /* 1530 */ 334, 335, 0, 337, 0, 258, 326, 0, 0, 0, - /* 1540 */ 330, 331, 332, 333, 334, 335, 326, 337, 0, 22, - /* 1550 */ 330, 331, 332, 333, 334, 335, 0, 337, 0, 258, - /* 1560 */ 56, 42, 56, 286, 43, 39, 14, 14, 46, 40, - /* 1570 */ 39, 294, 0, 0, 46, 0, 299, 157, 301, 39, - /* 1580 */ 0, 0, 0, 0, 0, 258, 35, 286, 368, 47, - /* 1590 */ 0, 0, 62, 39, 35, 294, 47, 35, 0, 39, - /* 1600 */ 299, 0, 301, 326, 47, 39, 35, 330, 331, 332, - /* 1610 */ 333, 334, 335, 286, 337, 47, 39, 0, 291, 0, - /* 1620 */ 0, 294, 35, 0, 22, 92, 299, 326, 301, 94, - /* 1630 */ 35, 330, 331, 332, 333, 334, 335, 43, 337, 258, - /* 1640 */ 339, 35, 35, 43, 35, 35, 35, 35, 35, 0, - /* 1650 */ 22, 0, 375, 326, 22, 19, 0, 330, 331, 332, - /* 1660 */ 333, 334, 335, 49, 337, 22, 35, 286, 0, 33, - /* 1670 */ 35, 0, 291, 35, 0, 294, 22, 20, 0, 35, - /* 1680 */ 299, 0, 301, 47, 22, 0, 172, 0, 52, 53, - /* 1690 */ 54, 55, 56, 0, 153, 150, 153, 0, 0, 153, - /* 1700 */ 85, 0, 155, 0, 86, 39, 85, 326, 43, 85, - /* 1710 */ 85, 330, 331, 332, 333, 334, 335, 33, 337, 46, - /* 1720 */ 84, 151, 258, 87, 95, 149, 229, 85, 46, 43, - /* 1730 */ 85, 47, 86, 86, 86, 85, 52, 53, 54, 55, - /* 1740 */ 56, 86, 181, 85, 85, 85, 258, 86, 43, 85, - /* 1750 */ 286, 2, 46, 43, 35, 86, 120, 46, 294, 223, - /* 1760 */ 43, 86, 46, 299, 46, 301, 86, 43, 84, 86, - /* 1770 */ 35, 87, 35, 35, 286, 35, 35, 22, 193, 229, - /* 1780 */ 85, 85, 294, 22, 229, 43, 86, 299, 152, 301, - /* 1790 */ 326, 46, 46, 86, 330, 331, 332, 333, 334, 335, - /* 1800 */ 85, 337, 258, 35, 22, 96, 86, 85, 85, 173, - /* 1810 */ 85, 175, 86, 35, 326, 85, 35, 195, 330, 331, - /* 1820 */ 332, 333, 334, 335, 85, 337, 35, 35, 35, 86, - /* 1830 */ 286, 97, 85, 149, 150, 85, 152, 86, 294, 86, - /* 1840 */ 156, 109, 86, 299, 258, 301, 35, 85, 85, 85, - /* 1850 */ 85, 43, 22, 109, 258, 35, 62, 109, 61, 175, - /* 1860 */ 83, 109, 43, 68, 35, 22, 258, 35, 35, 35, - /* 1870 */ 326, 35, 286, 35, 330, 331, 332, 333, 334, 335, - /* 1880 */ 294, 337, 286, 35, 68, 299, 35, 301, 35, 35, - /* 1890 */ 294, 35, 35, 35, 286, 299, 35, 301, 35, 0, - /* 1900 */ 35, 39, 294, 0, 35, 39, 47, 299, 0, 301, - /* 1910 */ 35, 47, 326, 39, 47, 0, 330, 331, 332, 333, - /* 1920 */ 334, 335, 326, 337, 35, 47, 330, 331, 332, 333, - /* 1930 */ 334, 335, 39, 337, 326, 35, 35, 0, 330, 331, - /* 1940 */ 332, 333, 334, 335, 0, 337, 22, 258, 21, 378, - /* 1950 */ 22, 22, 21, 20, 378, 378, 378, 378, 378, 378, - /* 1960 */ 378, 378, 378, 378, 378, 378, 258, 378, 378, 378, - /* 1970 */ 378, 378, 378, 378, 378, 286, 378, 378, 378, 378, - /* 1980 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, - /* 1990 */ 301, 378, 378, 378, 286, 378, 378, 378, 378, 378, - /* 2000 */ 378, 378, 294, 378, 378, 378, 378, 299, 378, 301, - /* 2010 */ 378, 378, 378, 378, 378, 326, 378, 378, 378, 330, - /* 2020 */ 331, 332, 333, 334, 335, 378, 337, 258, 378, 378, - /* 2030 */ 378, 378, 378, 378, 326, 378, 378, 378, 330, 331, - /* 2040 */ 332, 333, 334, 335, 378, 337, 258, 378, 378, 378, - /* 2050 */ 378, 378, 378, 378, 378, 286, 378, 378, 378, 378, - /* 2060 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, - /* 2070 */ 301, 378, 378, 378, 286, 378, 378, 378, 378, 378, - /* 2080 */ 378, 378, 294, 378, 378, 378, 378, 299, 378, 301, - /* 2090 */ 378, 378, 378, 378, 378, 326, 378, 378, 378, 330, - /* 2100 */ 331, 332, 333, 334, 335, 378, 337, 378, 378, 378, - /* 2110 */ 378, 378, 378, 258, 326, 378, 378, 378, 330, 331, - /* 2120 */ 332, 333, 334, 335, 378, 337, 378, 378, 378, 258, - /* 2130 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 258, - /* 2140 */ 378, 286, 378, 378, 378, 378, 378, 378, 378, 294, - /* 2150 */ 378, 378, 378, 378, 299, 378, 301, 286, 378, 378, - /* 2160 */ 378, 378, 378, 378, 378, 294, 378, 286, 378, 378, - /* 2170 */ 299, 378, 301, 378, 378, 294, 378, 378, 378, 378, - /* 2180 */ 299, 326, 301, 378, 378, 330, 331, 332, 333, 334, - /* 2190 */ 335, 378, 337, 258, 378, 378, 378, 326, 378, 378, - /* 2200 */ 378, 330, 331, 332, 333, 334, 335, 326, 337, 378, - /* 2210 */ 378, 330, 331, 332, 333, 334, 335, 378, 337, 378, - /* 2220 */ 378, 286, 378, 378, 378, 378, 378, 378, 378, 294, - /* 2230 */ 378, 378, 378, 378, 299, 378, 301, 378, 378, 378, - /* 2240 */ 378, 378, 378, 378, 378, 378, 378, 258, 378, 378, - /* 2250 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, - /* 2260 */ 378, 326, 378, 378, 378, 330, 331, 332, 333, 334, - /* 2270 */ 335, 378, 337, 378, 378, 286, 378, 378, 378, 378, - /* 2280 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, - /* 2290 */ 301, 378, 378, 378, 378, 378, 378, 258, 378, 378, - /* 2300 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, - /* 2310 */ 378, 378, 378, 378, 258, 326, 378, 378, 378, 330, - /* 2320 */ 331, 332, 333, 334, 335, 286, 337, 378, 378, 378, - /* 2330 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, - /* 2340 */ 301, 378, 286, 378, 378, 378, 378, 378, 378, 378, - /* 2350 */ 294, 378, 378, 378, 378, 299, 378, 301, 378, 378, - /* 2360 */ 378, 378, 378, 378, 378, 326, 378, 378, 378, 330, - /* 2370 */ 331, 332, 333, 334, 335, 378, 337, 258, 378, 378, - /* 2380 */ 378, 378, 326, 378, 378, 378, 330, 331, 332, 333, - /* 2390 */ 334, 335, 378, 337, 378, 378, 378, 378, 258, 378, - /* 2400 */ 378, 378, 378, 378, 378, 286, 378, 378, 378, 378, - /* 2410 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, - /* 2420 */ 301, 378, 378, 378, 378, 378, 286, 378, 378, 378, - /* 2430 */ 378, 378, 378, 378, 294, 378, 378, 378, 378, 299, - /* 2440 */ 258, 301, 378, 378, 378, 326, 378, 378, 378, 330, - /* 2450 */ 331, 332, 333, 334, 335, 378, 337, 378, 378, 378, - /* 2460 */ 378, 378, 378, 378, 378, 378, 326, 378, 286, 378, - /* 2470 */ 330, 331, 332, 333, 334, 335, 294, 337, 378, 378, - /* 2480 */ 378, 299, 378, 301, 378, 378, 378, 378, 378, 378, - /* 2490 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, - /* 2500 */ 378, 378, 378, 378, 378, 378, 378, 378, 326, 378, - /* 2510 */ 378, 378, 330, 331, 332, 333, 334, 335, 378, 337, + /* 990 */ 211, 212, 12, 13, 84, 286, 85, 87, 266, 356, + /* 1000 */ 266, 89, 22, 294, 92, 193, 153, 259, 299, 277, + /* 1010 */ 301, 277, 369, 33, 288, 35, 373, 153, 154, 266, + /* 1020 */ 376, 367, 85, 267, 258, 299, 294, 258, 294, 35, + /* 1030 */ 277, 258, 95, 43, 123, 326, 56, 0, 258, 330, + /* 1040 */ 331, 332, 333, 334, 335, 258, 337, 294, 68, 340, + /* 1050 */ 258, 325, 326, 344, 345, 346, 0, 322, 363, 149, + /* 1060 */ 150, 0, 152, 337, 355, 299, 156, 258, 299, 158, + /* 1070 */ 159, 160, 299, 286, 163, 258, 86, 286, 267, 299, + /* 1080 */ 169, 294, 43, 43, 242, 175, 299, 107, 301, 46, + /* 1090 */ 265, 299, 298, 182, 43, 43, 185, 43, 187, 188, + /* 1100 */ 189, 190, 191, 192, 48, 329, 43, 43, 299, 43, + /* 1110 */ 347, 354, 370, 326, 370, 370, 299, 330, 331, 332, + /* 1120 */ 333, 334, 335, 258, 337, 86, 86, 340, 85, 246, + /* 1130 */ 85, 344, 345, 346, 97, 357, 225, 86, 86, 43, + /* 1140 */ 86, 290, 355, 227, 324, 20, 166, 266, 168, 86, + /* 1150 */ 86, 286, 86, 116, 117, 118, 119, 120, 97, 294, + /* 1160 */ 43, 43, 168, 47, 299, 258, 301, 323, 35, 43, + /* 1170 */ 43, 43, 272, 193, 194, 164, 317, 116, 117, 118, + /* 1180 */ 119, 120, 86, 266, 204, 205, 206, 207, 208, 209, + /* 1190 */ 210, 326, 266, 286, 42, 330, 331, 332, 333, 334, + /* 1200 */ 335, 294, 337, 86, 86, 340, 299, 306, 301, 344, + /* 1210 */ 345, 346, 86, 86, 86, 148, 266, 304, 304, 266, + /* 1220 */ 355, 266, 315, 20, 260, 260, 258, 270, 20, 321, + /* 1230 */ 301, 270, 20, 326, 314, 20, 258, 330, 331, 332, + /* 1240 */ 333, 334, 335, 316, 337, 4, 270, 314, 20, 270, + /* 1250 */ 307, 270, 270, 266, 286, 270, 260, 286, 286, 286, + /* 1260 */ 19, 286, 294, 356, 286, 260, 299, 299, 266, 301, + /* 1270 */ 286, 268, 294, 321, 33, 286, 369, 299, 286, 301, + /* 1280 */ 373, 286, 174, 315, 286, 286, 286, 301, 47, 320, + /* 1290 */ 268, 266, 51, 258, 326, 266, 268, 56, 330, 331, + /* 1300 */ 332, 333, 334, 335, 326, 337, 232, 258, 330, 331, + /* 1310 */ 332, 333, 334, 335, 310, 337, 299, 299, 340, 299, + /* 1320 */ 314, 286, 344, 345, 356, 84, 299, 150, 87, 294, + /* 1330 */ 299, 310, 308, 307, 299, 286, 301, 369, 294, 268, + /* 1340 */ 282, 373, 294, 294, 268, 20, 299, 233, 299, 299, + /* 1350 */ 301, 310, 329, 362, 299, 362, 310, 258, 299, 299, + /* 1360 */ 239, 326, 365, 157, 241, 330, 331, 332, 333, 334, + /* 1370 */ 335, 336, 337, 338, 339, 326, 364, 258, 362, 330, + /* 1380 */ 331, 332, 333, 334, 335, 286, 337, 240, 228, 324, + /* 1390 */ 224, 361, 360, 294, 294, 359, 20, 328, 299, 245, + /* 1400 */ 301, 243, 85, 248, 371, 286, 372, 276, 299, 266, + /* 1410 */ 291, 36, 290, 294, 372, 377, 343, 268, 299, 260, + /* 1420 */ 301, 318, 261, 374, 375, 326, 313, 256, 371, 330, + /* 1430 */ 331, 332, 333, 334, 335, 0, 337, 280, 269, 340, + /* 1440 */ 372, 371, 280, 258, 345, 326, 176, 280, 0, 330, + /* 1450 */ 331, 332, 333, 334, 335, 258, 337, 0, 42, 0, + /* 1460 */ 76, 0, 35, 35, 186, 258, 35, 35, 186, 0, + /* 1470 */ 186, 286, 35, 35, 0, 186, 291, 0, 35, 294, + /* 1480 */ 0, 0, 22, 286, 299, 0, 301, 35, 85, 171, + /* 1490 */ 170, 294, 168, 286, 166, 0, 299, 0, 301, 162, + /* 1500 */ 161, 294, 0, 0, 46, 0, 299, 0, 301, 0, + /* 1510 */ 145, 326, 0, 0, 0, 330, 331, 332, 333, 334, + /* 1520 */ 335, 258, 337, 326, 0, 0, 35, 330, 331, 332, + /* 1530 */ 333, 334, 335, 326, 337, 258, 140, 330, 331, 332, + /* 1540 */ 333, 334, 335, 0, 337, 140, 0, 0, 0, 286, + /* 1550 */ 42, 0, 0, 0, 0, 0, 0, 294, 0, 0, + /* 1560 */ 0, 0, 299, 286, 301, 368, 0, 0, 291, 0, + /* 1570 */ 0, 294, 0, 0, 0, 0, 299, 0, 301, 22, + /* 1580 */ 0, 0, 375, 0, 56, 0, 56, 0, 258, 326, + /* 1590 */ 0, 42, 14, 330, 331, 332, 333, 334, 335, 0, + /* 1600 */ 337, 39, 339, 326, 40, 14, 43, 330, 331, 332, + /* 1610 */ 333, 334, 335, 19, 337, 47, 286, 46, 39, 0, + /* 1620 */ 0, 291, 46, 0, 294, 39, 0, 33, 157, 299, + /* 1630 */ 258, 301, 0, 0, 0, 0, 35, 39, 0, 35, + /* 1640 */ 47, 47, 0, 35, 258, 39, 52, 53, 54, 55, + /* 1650 */ 56, 62, 47, 39, 0, 39, 326, 35, 286, 47, + /* 1660 */ 330, 331, 332, 333, 334, 335, 294, 337, 0, 0, + /* 1670 */ 0, 299, 286, 301, 0, 35, 94, 22, 84, 0, + /* 1680 */ 294, 87, 35, 35, 92, 299, 35, 301, 35, 43, + /* 1690 */ 0, 35, 43, 35, 35, 35, 0, 22, 326, 22, + /* 1700 */ 0, 49, 330, 331, 332, 333, 334, 335, 258, 337, + /* 1710 */ 22, 35, 326, 0, 120, 35, 330, 331, 332, 333, + /* 1720 */ 334, 335, 0, 337, 35, 0, 22, 20, 0, 35, + /* 1730 */ 258, 0, 22, 0, 0, 0, 286, 153, 0, 0, + /* 1740 */ 0, 0, 39, 46, 294, 95, 152, 150, 153, 299, + /* 1750 */ 258, 301, 86, 153, 43, 229, 85, 155, 286, 86, + /* 1760 */ 172, 151, 149, 85, 43, 46, 294, 173, 85, 175, + /* 1770 */ 85, 299, 85, 301, 229, 43, 326, 181, 286, 86, + /* 1780 */ 330, 331, 332, 333, 334, 335, 294, 337, 86, 46, + /* 1790 */ 85, 299, 258, 301, 85, 43, 46, 85, 326, 43, + /* 1800 */ 86, 85, 330, 331, 332, 333, 334, 335, 258, 337, + /* 1810 */ 86, 85, 85, 46, 46, 86, 86, 43, 326, 35, + /* 1820 */ 286, 35, 330, 331, 332, 333, 334, 335, 294, 337, + /* 1830 */ 223, 86, 86, 299, 35, 301, 286, 35, 229, 35, + /* 1840 */ 35, 2, 22, 43, 294, 85, 22, 86, 85, 299, + /* 1850 */ 86, 301, 86, 46, 193, 85, 85, 85, 46, 195, + /* 1860 */ 326, 258, 85, 35, 330, 331, 332, 333, 334, 335, + /* 1870 */ 35, 337, 96, 258, 86, 85, 326, 86, 35, 85, + /* 1880 */ 330, 331, 332, 333, 334, 335, 35, 337, 85, 286, + /* 1890 */ 35, 35, 86, 22, 86, 85, 85, 294, 109, 86, + /* 1900 */ 85, 286, 299, 85, 301, 109, 109, 109, 35, 294, + /* 1910 */ 43, 97, 85, 22, 299, 258, 301, 35, 68, 62, + /* 1920 */ 61, 83, 43, 35, 35, 258, 22, 35, 35, 326, + /* 1930 */ 35, 35, 35, 330, 331, 332, 333, 334, 335, 258, + /* 1940 */ 337, 326, 68, 286, 35, 330, 331, 332, 333, 334, + /* 1950 */ 335, 294, 337, 286, 35, 35, 299, 35, 301, 35, + /* 1960 */ 35, 294, 35, 35, 0, 35, 299, 286, 301, 0, + /* 1970 */ 47, 39, 35, 47, 39, 294, 0, 35, 47, 0, + /* 1980 */ 299, 35, 301, 326, 39, 47, 39, 330, 331, 332, + /* 1990 */ 333, 334, 335, 326, 337, 258, 0, 330, 331, 332, + /* 2000 */ 333, 334, 335, 35, 337, 258, 35, 326, 0, 22, + /* 2010 */ 21, 330, 331, 332, 333, 334, 335, 258, 337, 22, + /* 2020 */ 22, 21, 20, 286, 378, 378, 378, 378, 378, 378, + /* 2030 */ 378, 294, 378, 286, 378, 378, 299, 378, 301, 378, + /* 2040 */ 378, 294, 378, 378, 378, 286, 299, 378, 301, 378, + /* 2050 */ 378, 378, 378, 294, 378, 378, 378, 378, 299, 378, + /* 2060 */ 301, 378, 378, 326, 378, 378, 378, 330, 331, 332, + /* 2070 */ 333, 334, 335, 326, 337, 378, 378, 330, 331, 332, + /* 2080 */ 333, 334, 335, 258, 337, 326, 378, 378, 378, 330, + /* 2090 */ 331, 332, 333, 334, 335, 258, 337, 378, 378, 378, + /* 2100 */ 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, + /* 2110 */ 378, 286, 378, 378, 378, 378, 378, 378, 378, 294, + /* 2120 */ 378, 378, 378, 286, 299, 378, 301, 378, 378, 378, + /* 2130 */ 378, 294, 378, 378, 378, 378, 299, 378, 301, 378, + /* 2140 */ 378, 378, 378, 378, 378, 378, 378, 378, 258, 378, + /* 2150 */ 378, 326, 378, 378, 378, 330, 331, 332, 333, 334, + /* 2160 */ 335, 378, 337, 326, 378, 378, 378, 330, 331, 332, + /* 2170 */ 333, 334, 335, 378, 337, 378, 286, 378, 378, 378, + /* 2180 */ 378, 378, 378, 378, 294, 378, 378, 378, 378, 299, + /* 2190 */ 378, 301, 378, 378, 378, 378, 378, 378, 258, 378, + /* 2200 */ 378, 378, 378, 378, 378, 378, 378, 378, 258, 378, + /* 2210 */ 266, 378, 378, 378, 378, 378, 326, 378, 378, 378, + /* 2220 */ 330, 331, 332, 333, 334, 335, 286, 337, 378, 378, + /* 2230 */ 378, 378, 378, 378, 294, 378, 286, 378, 294, 299, + /* 2240 */ 378, 301, 378, 378, 294, 378, 378, 378, 378, 299, + /* 2250 */ 378, 301, 378, 378, 378, 378, 378, 378, 378, 315, + /* 2260 */ 378, 378, 378, 378, 378, 378, 326, 378, 378, 378, + /* 2270 */ 330, 331, 332, 333, 334, 335, 326, 337, 334, 378, + /* 2280 */ 330, 331, 332, 333, 334, 335, 378, 337, 378, 378, + /* 2290 */ 378, 378, 378, 349, 350, 351, 378, 353, 378, 378, + /* 2300 */ 356, 378, 378, 378, 378, 378, 378, 378, 378, 378, + /* 2310 */ 378, 378, 378, 369, 378, 378, 378, 373, }; #define YY_SHIFT_COUNT (665) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1944) +#define YY_SHIFT_MAX (2008) static const unsigned short int yy_shift_ofst[] = { /* 0 */ 911, 0, 0, 62, 62, 263, 263, 263, 320, 320, /* 10 */ 263, 263, 521, 578, 779, 578, 578, 578, 578, 578, /* 20 */ 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, /* 30 */ 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, - /* 40 */ 578, 578, 209, 209, 35, 35, 35, 1072, 1072, 1072, - /* 50 */ 1072, 208, 350, 32, 32, 167, 167, 19, 19, 11, + /* 40 */ 578, 578, 209, 209, 35, 35, 35, 980, 980, 980, + /* 50 */ 980, 208, 350, 32, 32, 167, 167, 19, 19, 11, /* 60 */ 38, 32, 32, 167, 167, 167, 167, 167, 167, 167, /* 70 */ 167, 167, 182, 167, 167, 167, 230, 352, 167, 167, /* 80 */ 352, 438, 167, 352, 352, 352, 167, 452, 775, 231, @@ -742,162 +702,162 @@ static const unsigned short int yy_shift_ofst[] = { /* 100 */ 730, 730, 730, 730, 730, 730, 730, 730, 730, 730, /* 110 */ 730, 730, 730, 418, 38, 522, 522, 383, 567, 576, /* 120 */ 480, 480, 480, 567, 558, 230, 1, 1, 352, 352, - /* 130 */ 585, 585, 649, 691, 201, 201, 201, 201, 201, 201, - /* 140 */ 201, 1636, 125, 684, 119, 573, 69, 313, 343, 351, - /* 150 */ 631, 529, 494, 39, 548, 514, 673, 514, 708, 824, - /* 160 */ 824, 824, 250, 666, 1056, 923, 1135, 1114, 1138, 998, - /* 170 */ 1135, 1135, 1140, 1036, 1036, 1135, 1135, 1135, 1169, 1169, - /* 180 */ 1188, 182, 230, 182, 1204, 1205, 182, 1204, 182, 1212, - /* 190 */ 182, 182, 1135, 182, 1169, 352, 352, 352, 352, 352, - /* 200 */ 352, 352, 352, 352, 352, 352, 1135, 1169, 585, 1188, - /* 210 */ 452, 1088, 230, 452, 1135, 1135, 1204, 452, 1057, 585, - /* 220 */ 585, 585, 585, 1057, 585, 1158, 558, 1212, 452, 649, - /* 230 */ 452, 558, 1296, 585, 1087, 1057, 585, 585, 1087, 1057, - /* 240 */ 585, 585, 352, 1089, 1174, 1087, 1091, 1093, 1107, 923, - /* 250 */ 1116, 558, 1322, 1099, 1103, 1101, 1099, 1103, 1099, 1103, - /* 260 */ 1262, 1056, 585, 691, 1135, 452, 1338, 1169, 2520, 2520, - /* 270 */ 2520, 2520, 2520, 2520, 2520, 601, 1684, 386, 1134, 469, - /* 280 */ 551, 682, 840, 879, 853, 727, 823, 314, 314, 314, - /* 290 */ 314, 314, 314, 314, 314, 838, 699, 274, 274, 445, + /* 130 */ 585, 585, 663, 696, 201, 201, 201, 201, 201, 201, + /* 140 */ 201, 1594, 125, 684, 119, 573, 69, 313, 343, 351, + /* 150 */ 631, 529, 494, 39, 548, 514, 673, 514, 708, 842, + /* 160 */ 842, 842, 250, 666, 1045, 916, 1125, 1116, 1133, 1011, + /* 170 */ 1125, 1125, 1152, 1067, 1067, 1125, 1125, 1125, 1203, 1203, + /* 180 */ 1208, 182, 230, 182, 1212, 1215, 182, 1212, 182, 1228, + /* 190 */ 182, 182, 1125, 182, 1203, 352, 352, 352, 352, 352, + /* 200 */ 352, 352, 352, 352, 352, 352, 1125, 1203, 585, 1208, + /* 210 */ 452, 1108, 230, 452, 1125, 1125, 1212, 452, 1074, 585, + /* 220 */ 585, 585, 585, 1074, 585, 1177, 558, 1228, 452, 663, + /* 230 */ 452, 558, 1325, 585, 1114, 1074, 585, 585, 1114, 1074, + /* 240 */ 585, 585, 352, 1121, 1206, 1114, 1123, 1147, 1160, 916, + /* 250 */ 1166, 558, 1376, 1154, 1158, 1155, 1154, 1158, 1154, 1158, + /* 260 */ 1317, 1045, 585, 696, 1125, 452, 1375, 1203, 2318, 2318, + /* 270 */ 2318, 2318, 2318, 2318, 2318, 601, 910, 386, 1241, 469, + /* 280 */ 551, 682, 840, 879, 853, 727, 1037, 314, 314, 314, + /* 290 */ 314, 314, 314, 314, 314, 1061, 699, 274, 274, 445, /* 300 */ 65, 108, 156, 44, 168, 602, 339, 200, 200, 200, - /* 310 */ 200, 297, 841, 839, 929, 934, 965, 57, 850, 851, - /* 320 */ 92, 784, 907, 908, 992, 1024, 1039, 1040, 1048, 819, - /* 330 */ 844, 626, 889, 1071, 924, 976, 967, 1086, 971, 1094, - /* 340 */ 1100, 1115, 1120, 1127, 1128, 994, 1029, 1068, 1396, 1235, - /* 350 */ 1414, 1415, 1374, 1418, 1344, 1421, 1387, 1237, 1389, 1390, - /* 360 */ 1391, 1241, 1428, 1394, 1395, 1245, 1433, 1248, 1435, 1407, - /* 370 */ 1445, 1424, 1447, 1422, 1456, 1375, 1288, 1291, 1294, 1298, - /* 380 */ 1465, 1466, 1305, 1308, 1470, 1471, 1426, 1473, 1474, 1475, - /* 390 */ 1331, 1477, 1479, 1483, 1484, 1485, 1346, 1453, 1489, 1351, - /* 400 */ 1492, 1493, 1494, 1498, 1499, 1500, 1502, 1503, 1505, 1507, - /* 410 */ 1508, 1510, 1512, 1513, 1476, 1515, 1516, 1517, 1520, 1523, - /* 420 */ 1524, 1527, 1525, 1532, 1534, 1537, 1538, 1504, 1539, 1506, - /* 430 */ 1548, 1556, 1519, 1526, 1521, 1552, 1522, 1553, 1528, 1558, - /* 440 */ 1529, 1531, 1572, 1573, 1575, 1540, 1420, 1580, 1581, 1582, - /* 450 */ 1530, 1583, 1584, 1551, 1542, 1554, 1590, 1559, 1549, 1560, - /* 460 */ 1591, 1562, 1557, 1566, 1598, 1571, 1568, 1577, 1601, 1617, - /* 470 */ 1619, 1620, 1535, 1533, 1587, 1602, 1623, 1595, 1606, 1607, - /* 480 */ 1609, 1594, 1600, 1610, 1611, 1612, 1613, 1649, 1628, 1651, - /* 490 */ 1632, 1614, 1656, 1643, 1631, 1668, 1635, 1671, 1638, 1674, - /* 500 */ 1654, 1657, 1678, 1541, 1644, 1681, 1514, 1662, 1543, 1545, - /* 510 */ 1685, 1687, 1546, 1547, 1693, 1697, 1698, 1615, 1618, 1561, - /* 520 */ 1701, 1621, 1570, 1624, 1703, 1666, 1576, 1625, 1629, 1673, - /* 530 */ 1665, 1497, 1642, 1646, 1645, 1647, 1648, 1650, 1686, 1655, - /* 540 */ 1658, 1659, 1660, 1661, 1705, 1682, 1706, 1664, 1710, 1550, - /* 550 */ 1669, 1675, 1711, 1536, 1717, 1716, 1718, 1680, 1724, 1555, - /* 560 */ 1683, 1719, 1735, 1737, 1738, 1740, 1741, 1683, 1749, 1755, - /* 570 */ 1585, 1742, 1695, 1700, 1696, 1707, 1715, 1720, 1745, 1722, - /* 580 */ 1723, 1746, 1761, 1622, 1725, 1709, 1726, 1768, 1778, 1730, - /* 590 */ 1743, 1781, 1739, 1751, 1791, 1747, 1753, 1792, 1750, 1756, - /* 600 */ 1793, 1762, 1732, 1744, 1748, 1752, 1782, 1734, 1763, 1764, - /* 610 */ 1811, 1765, 1808, 1808, 1830, 1794, 1797, 1820, 1795, 1777, - /* 620 */ 1819, 1829, 1832, 1833, 1834, 1836, 1843, 1838, 1848, 1816, - /* 630 */ 1594, 1851, 1600, 1853, 1854, 1856, 1857, 1858, 1861, 1863, - /* 640 */ 1899, 1865, 1859, 1862, 1903, 1869, 1864, 1866, 1908, 1875, - /* 650 */ 1867, 1874, 1915, 1889, 1878, 1893, 1944, 1900, 1901, 1937, - /* 660 */ 1924, 1927, 1928, 1929, 1931, 1933, + /* 310 */ 200, 297, 784, 843, 848, 862, 912, 57, 850, 928, + /* 320 */ 92, 864, 990, 1039, 1040, 1051, 1052, 1054, 1063, 819, + /* 330 */ 762, 702, 883, 1064, 771, 994, 812, 1066, 1043, 1096, + /* 340 */ 1117, 1118, 1126, 1127, 1128, 937, 906, 1056, 1435, 1270, + /* 350 */ 1448, 1457, 1416, 1459, 1384, 1461, 1427, 1278, 1428, 1431, + /* 360 */ 1432, 1282, 1469, 1437, 1438, 1284, 1474, 1289, 1477, 1443, + /* 370 */ 1480, 1460, 1481, 1452, 1485, 1403, 1318, 1320, 1324, 1328, + /* 380 */ 1495, 1497, 1337, 1339, 1502, 1503, 1458, 1505, 1507, 1509, + /* 390 */ 1365, 1512, 1513, 1514, 1524, 1525, 1396, 1491, 1543, 1405, + /* 400 */ 1546, 1547, 1548, 1558, 1559, 1560, 1561, 1566, 1567, 1569, + /* 410 */ 1570, 1572, 1573, 1574, 1508, 1551, 1552, 1553, 1554, 1555, + /* 420 */ 1556, 1557, 1575, 1577, 1580, 1581, 1583, 1528, 1585, 1530, + /* 430 */ 1587, 1590, 1549, 1562, 1563, 1578, 1571, 1591, 1576, 1599, + /* 440 */ 1564, 1579, 1619, 1620, 1623, 1586, 1471, 1626, 1632, 1633, + /* 450 */ 1589, 1634, 1635, 1601, 1568, 1598, 1638, 1604, 1593, 1606, + /* 460 */ 1642, 1608, 1605, 1614, 1654, 1622, 1612, 1616, 1668, 1669, + /* 470 */ 1670, 1674, 1582, 1592, 1640, 1655, 1679, 1647, 1648, 1651, + /* 480 */ 1653, 1646, 1649, 1656, 1658, 1659, 1660, 1690, 1675, 1696, + /* 490 */ 1677, 1652, 1700, 1688, 1676, 1713, 1680, 1722, 1689, 1725, + /* 500 */ 1704, 1707, 1728, 1584, 1694, 1731, 1588, 1710, 1595, 1597, + /* 510 */ 1733, 1734, 1600, 1602, 1735, 1738, 1739, 1671, 1666, 1596, + /* 520 */ 1740, 1678, 1610, 1683, 1741, 1703, 1613, 1685, 1650, 1697, + /* 530 */ 1711, 1526, 1687, 1673, 1705, 1693, 1702, 1709, 1721, 1714, + /* 540 */ 1712, 1716, 1726, 1724, 1732, 1719, 1743, 1727, 1752, 1545, + /* 550 */ 1729, 1730, 1750, 1607, 1756, 1767, 1768, 1745, 1774, 1609, + /* 560 */ 1746, 1784, 1786, 1799, 1802, 1804, 1805, 1746, 1839, 1820, + /* 570 */ 1661, 1800, 1760, 1761, 1763, 1764, 1770, 1766, 1807, 1771, + /* 580 */ 1772, 1812, 1824, 1664, 1777, 1776, 1788, 1828, 1835, 1790, + /* 590 */ 1791, 1843, 1794, 1806, 1851, 1803, 1808, 1855, 1810, 1813, + /* 600 */ 1856, 1811, 1789, 1796, 1797, 1798, 1871, 1814, 1815, 1818, + /* 610 */ 1873, 1827, 1867, 1867, 1891, 1857, 1859, 1882, 1850, 1838, + /* 620 */ 1879, 1888, 1889, 1892, 1893, 1895, 1904, 1896, 1897, 1874, + /* 630 */ 1646, 1909, 1649, 1919, 1920, 1922, 1924, 1925, 1927, 1928, + /* 640 */ 1964, 1930, 1923, 1932, 1969, 1937, 1926, 1935, 1976, 1942, + /* 650 */ 1931, 1945, 1979, 1946, 1938, 1947, 1996, 1968, 1971, 2008, + /* 660 */ 1987, 1989, 1997, 1998, 2000, 2002, }; #define YY_REDUCE_COUNT (274) #define YY_REDUCE_MIN (-312) -#define YY_REDUCE_MAX (2182) +#define YY_REDUCE_MAX (1950) static const short yy_reduce_ofst[] = { - /* 0 */ -78, -232, 63, 286, -113, 706, 787, 865, 918, 970, - /* 10 */ 545, 1035, 1051, 1106, 1118, 1196, 1210, 1220, 1277, 1301, - /* 20 */ 1327, 1381, 1464, 1488, 1544, 1586, 1596, 1608, 1689, 1708, - /* 30 */ 1769, 1788, 1855, 1871, 1881, 1935, 1989, 2039, 2056, 2119, - /* 40 */ 2140, 2182, -263, 796, -14, 75, 305, -278, 55, 270, - /* 50 */ 672, -296, 123, 184, 647, -266, -43, -260, -256, -303, - /* 60 */ -186, -230, -191, -185, 97, 315, 316, 363, 563, 564, - /* 70 */ 566, 659, -154, 667, 733, 736, -285, -106, 748, 778, - /* 80 */ 59, 24, 781, 72, 322, 82, 782, 70, -252, -312, + /* 0 */ -78, -232, 63, 286, -113, 709, 787, 865, 907, 968, + /* 10 */ 545, 978, 1035, 1049, 1099, 1119, 1185, 1197, 1207, 1263, + /* 20 */ 1277, 1330, 1372, 1386, 1450, 1472, 1492, 1534, 1550, 1603, + /* 30 */ 1615, 1657, 1667, 1681, 1737, 1747, 1759, 1825, 1837, 1890, + /* 40 */ 1940, 1950, -263, 1944, -14, 75, 305, -278, 55, 270, + /* 50 */ 726, -296, 123, 184, 643, -266, -43, -260, -256, -303, + /* 60 */ -186, -230, -191, -185, 97, 315, 316, 363, 557, 563, + /* 70 */ 564, 566, -154, 659, 661, 665, -285, -106, 667, 732, + /* 80 */ 59, 24, 734, 72, 322, 82, 753, 70, -252, -312, /* 90 */ -312, -312, -117, -239, -114, -20, 141, 181, 196, 289, - /* 100 */ 328, 435, 455, 505, 575, 668, 705, 716, 750, 754, - /* 110 */ 761, 764, 766, 299, -110, 124, 138, -220, 148, -243, + /* 100 */ 328, 435, 455, 505, 575, 672, 766, 769, 773, 780, + /* 110 */ 792, 809, 817, 299, -110, 124, 138, -220, 148, -243, /* 120 */ 218, 310, 364, 150, 354, 349, 336, 456, 319, 205, - /* 130 */ 474, 498, 476, 560, -280, -270, 477, 513, 519, 538, - /* 140 */ 596, 526, 382, 655, 570, 628, 734, 707, 670, 745, - /* 150 */ 745, 810, 822, 797, 777, 755, 755, 755, 757, 738, - /* 160 */ 742, 769, 758, 745, 858, 830, 890, 845, 902, 860, - /* 170 */ 909, 912, 877, 883, 884, 926, 927, 928, 943, 947, - /* 180 */ 894, 946, 921, 953, 913, 910, 959, 916, 961, 930, - /* 190 */ 964, 966, 969, 972, 979, 955, 957, 960, 968, 973, - /* 200 */ 974, 975, 977, 980, 981, 982, 991, 985, 948, 937, - /* 210 */ 1002, 952, 983, 1005, 1009, 1017, 978, 1018, 984, 989, - /* 220 */ 996, 999, 1000, 987, 1007, 1003, 1016, 1006, 1022, 1030, - /* 230 */ 1046, 1021, 988, 1019, 962, 1012, 1020, 1026, 986, 1013, - /* 240 */ 1028, 1031, 745, 990, 993, 997, 995, 1011, 1001, 1014, - /* 250 */ 755, 1047, 1023, 1025, 1027, 1032, 1034, 1037, 1038, 1042, - /* 260 */ 1010, 1064, 1059, 1097, 1096, 1095, 1117, 1131, 1075, 1081, - /* 270 */ 1119, 1121, 1122, 1126, 1147, + /* 130 */ 474, 498, 476, 562, -280, -270, 382, 513, 538, 633, + /* 140 */ 669, 641, 748, 366, 644, 654, 756, 735, 695, 791, + /* 150 */ 791, 811, 825, 794, 776, 757, 757, 757, 763, 742, + /* 160 */ 744, 745, 778, 791, 851, 820, 881, 844, 900, 859, + /* 170 */ 917, 926, 901, 913, 914, 950, 953, 955, 964, 965, + /* 180 */ 908, 957, 929, 961, 920, 927, 976, 933, 979, 943, + /* 190 */ 981, 982, 987, 985, 996, 971, 972, 973, 975, 984, + /* 200 */ 989, 992, 995, 998, 999, 1000, 1002, 1005, 967, 952, + /* 210 */ 1003, 969, 986, 1022, 1025, 1029, 1006, 1028, 1004, 1017, + /* 220 */ 1018, 1020, 1027, 1021, 1031, 1024, 1044, 1026, 1071, 1058, + /* 230 */ 1076, 1048, 1023, 1047, 991, 1041, 1050, 1055, 993, 1046, + /* 240 */ 1059, 1060, 791, 997, 1012, 1016, 1030, 1032, 1036, 1065, + /* 250 */ 757, 1100, 1069, 1034, 1033, 1038, 1042, 1057, 1068, 1070, + /* 260 */ 1073, 1122, 1109, 1131, 1143, 1149, 1161, 1159, 1103, 1113, + /* 270 */ 1157, 1162, 1167, 1169, 1171, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 10 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 20 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 30 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 40 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 50 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 60 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 70 */ 1457, 1457, 1531, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 80 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1529, 1684, 1457, - /* 90 */ 1861, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 100 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 110 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1531, 1457, 1529, - /* 120 */ 1873, 1873, 1873, 1457, 1457, 1457, 1728, 1728, 1457, 1457, - /* 130 */ 1457, 1457, 1627, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 140 */ 1457, 1720, 1457, 1457, 1942, 1457, 1457, 1726, 1896, 1457, - /* 150 */ 1457, 1457, 1457, 1580, 1888, 1865, 1879, 1866, 1863, 1927, - /* 160 */ 1927, 1927, 1882, 1457, 1596, 1892, 1457, 1457, 1457, 1712, - /* 170 */ 1457, 1457, 1689, 1686, 1686, 1457, 1457, 1457, 1457, 1457, - /* 180 */ 1457, 1531, 1457, 1531, 1457, 1457, 1531, 1457, 1531, 1457, - /* 190 */ 1531, 1531, 1457, 1531, 1457, 1457, 1457, 1457, 1457, 1457, - /* 200 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 210 */ 1529, 1722, 1457, 1529, 1457, 1457, 1457, 1529, 1901, 1457, - /* 220 */ 1457, 1457, 1457, 1901, 1457, 1457, 1457, 1457, 1529, 1457, - /* 230 */ 1529, 1457, 1457, 1457, 1903, 1901, 1457, 1457, 1903, 1901, - /* 240 */ 1457, 1457, 1457, 1915, 1911, 1903, 1919, 1917, 1894, 1892, - /* 250 */ 1879, 1457, 1457, 1933, 1929, 1945, 1933, 1929, 1933, 1929, - /* 260 */ 1457, 1596, 1457, 1457, 1457, 1529, 1489, 1457, 1714, 1728, - /* 270 */ 1630, 1630, 1630, 1532, 1462, 1457, 1457, 1457, 1457, 1457, - /* 280 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1799, 1914, 1913, - /* 290 */ 1837, 1836, 1835, 1833, 1798, 1457, 1592, 1797, 1796, 1457, - /* 300 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1790, 1791, 1789, - /* 310 */ 1788, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 320 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1862, - /* 330 */ 1457, 1930, 1934, 1457, 1457, 1457, 1457, 1457, 1773, 1457, - /* 340 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 350 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 360 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 370 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 380 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 390 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 400 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 410 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 420 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 430 */ 1457, 1457, 1457, 1457, 1494, 1457, 1457, 1457, 1457, 1457, - /* 440 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 450 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 460 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 470 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 480 */ 1457, 1561, 1560, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 490 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 500 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 510 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 520 */ 1732, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 530 */ 1895, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 540 */ 1457, 1457, 1457, 1457, 1457, 1457, 1773, 1457, 1912, 1457, - /* 550 */ 1872, 1868, 1457, 1457, 1864, 1772, 1457, 1457, 1928, 1457, - /* 560 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1857, 1457, - /* 570 */ 1457, 1830, 1815, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 580 */ 1457, 1457, 1457, 1784, 1457, 1457, 1457, 1457, 1457, 1624, - /* 590 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 600 */ 1457, 1457, 1609, 1607, 1606, 1605, 1457, 1602, 1457, 1457, - /* 610 */ 1457, 1457, 1633, 1632, 1457, 1457, 1457, 1457, 1457, 1457, - /* 620 */ 1552, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 630 */ 1543, 1457, 1542, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 640 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 650 */ 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, 1457, - /* 660 */ 1457, 1457, 1457, 1457, 1457, 1457, + /* 0 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 10 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 20 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 30 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 40 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 50 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 60 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 70 */ 1459, 1459, 1533, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 80 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1531, 1686, 1459, + /* 90 */ 1864, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 100 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 110 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1533, 1459, 1531, + /* 120 */ 1876, 1876, 1876, 1459, 1459, 1459, 1730, 1730, 1459, 1459, + /* 130 */ 1459, 1459, 1629, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 140 */ 1459, 1722, 1459, 1459, 1945, 1459, 1459, 1728, 1899, 1459, + /* 150 */ 1459, 1459, 1459, 1582, 1891, 1868, 1882, 1869, 1866, 1930, + /* 160 */ 1930, 1930, 1885, 1459, 1598, 1895, 1459, 1459, 1459, 1714, + /* 170 */ 1459, 1459, 1691, 1688, 1688, 1459, 1459, 1459, 1459, 1459, + /* 180 */ 1459, 1533, 1459, 1533, 1459, 1459, 1533, 1459, 1533, 1459, + /* 190 */ 1533, 1533, 1459, 1533, 1459, 1459, 1459, 1459, 1459, 1459, + /* 200 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 210 */ 1531, 1724, 1459, 1531, 1459, 1459, 1459, 1531, 1904, 1459, + /* 220 */ 1459, 1459, 1459, 1904, 1459, 1459, 1459, 1459, 1531, 1459, + /* 230 */ 1531, 1459, 1459, 1459, 1906, 1904, 1459, 1459, 1906, 1904, + /* 240 */ 1459, 1459, 1459, 1918, 1914, 1906, 1922, 1920, 1897, 1895, + /* 250 */ 1882, 1459, 1459, 1936, 1932, 1948, 1936, 1932, 1936, 1932, + /* 260 */ 1459, 1598, 1459, 1459, 1459, 1531, 1491, 1459, 1716, 1730, + /* 270 */ 1632, 1632, 1632, 1534, 1464, 1459, 1459, 1459, 1459, 1459, + /* 280 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1802, 1917, 1916, + /* 290 */ 1840, 1839, 1838, 1836, 1801, 1459, 1594, 1800, 1799, 1459, + /* 300 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1793, 1794, 1792, + /* 310 */ 1791, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 320 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1865, + /* 330 */ 1459, 1933, 1937, 1459, 1459, 1459, 1459, 1459, 1776, 1459, + /* 340 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 350 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 360 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 370 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 380 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 390 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 400 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 410 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 420 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 430 */ 1459, 1459, 1459, 1459, 1496, 1459, 1459, 1459, 1459, 1459, + /* 440 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 450 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 460 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 470 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 480 */ 1459, 1563, 1562, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 490 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 500 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 510 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 520 */ 1734, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 530 */ 1898, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 540 */ 1459, 1459, 1459, 1459, 1459, 1459, 1776, 1459, 1915, 1459, + /* 550 */ 1875, 1871, 1459, 1459, 1867, 1775, 1459, 1459, 1931, 1459, + /* 560 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1860, 1459, + /* 570 */ 1459, 1833, 1818, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 580 */ 1459, 1459, 1459, 1787, 1459, 1459, 1459, 1459, 1459, 1626, + /* 590 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 600 */ 1459, 1459, 1611, 1609, 1608, 1607, 1459, 1604, 1459, 1459, + /* 610 */ 1459, 1459, 1635, 1634, 1459, 1459, 1459, 1459, 1459, 1459, + /* 620 */ 1554, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 630 */ 1545, 1459, 1544, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 640 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 650 */ 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, 1459, + /* 660 */ 1459, 1459, 1459, 1459, 1459, 1459, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1953,185 +1913,186 @@ static const char *const yyRuleName[] = { /* 306 */ "signed_literal ::= duration_literal", /* 307 */ "signed_literal ::= NULL", /* 308 */ "signed_literal ::= literal_func", - /* 309 */ "literal_list ::= signed_literal", - /* 310 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 311 */ "db_name ::= NK_ID", - /* 312 */ "table_name ::= NK_ID", - /* 313 */ "column_name ::= NK_ID", - /* 314 */ "function_name ::= NK_ID", - /* 315 */ "table_alias ::= NK_ID", - /* 316 */ "column_alias ::= NK_ID", - /* 317 */ "user_name ::= NK_ID", - /* 318 */ "index_name ::= NK_ID", - /* 319 */ "topic_name ::= NK_ID", - /* 320 */ "stream_name ::= NK_ID", - /* 321 */ "cgroup_name ::= NK_ID", - /* 322 */ "expression ::= literal", - /* 323 */ "expression ::= pseudo_column", - /* 324 */ "expression ::= column_reference", - /* 325 */ "expression ::= function_expression", - /* 326 */ "expression ::= subquery", - /* 327 */ "expression ::= NK_LP expression NK_RP", - /* 328 */ "expression ::= NK_PLUS expression", - /* 329 */ "expression ::= NK_MINUS expression", - /* 330 */ "expression ::= expression NK_PLUS expression", - /* 331 */ "expression ::= expression NK_MINUS expression", - /* 332 */ "expression ::= expression NK_STAR expression", - /* 333 */ "expression ::= expression NK_SLASH expression", - /* 334 */ "expression ::= expression NK_REM expression", - /* 335 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 336 */ "expression ::= expression NK_BITAND expression", - /* 337 */ "expression ::= expression NK_BITOR expression", - /* 338 */ "expression_list ::= expression", - /* 339 */ "expression_list ::= expression_list NK_COMMA expression", - /* 340 */ "column_reference ::= column_name", - /* 341 */ "column_reference ::= table_name NK_DOT column_name", - /* 342 */ "pseudo_column ::= ROWTS", - /* 343 */ "pseudo_column ::= TBNAME", - /* 344 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 345 */ "pseudo_column ::= QSTARTTS", - /* 346 */ "pseudo_column ::= QENDTS", - /* 347 */ "pseudo_column ::= WSTARTTS", - /* 348 */ "pseudo_column ::= WENDTS", - /* 349 */ "pseudo_column ::= WDURATION", - /* 350 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 351 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 352 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 353 */ "function_expression ::= literal_func", - /* 354 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 355 */ "literal_func ::= NOW", - /* 356 */ "noarg_func ::= NOW", - /* 357 */ "noarg_func ::= TODAY", - /* 358 */ "noarg_func ::= TIMEZONE", - /* 359 */ "noarg_func ::= DATABASE", - /* 360 */ "noarg_func ::= CLIENT_VERSION", - /* 361 */ "noarg_func ::= SERVER_VERSION", - /* 362 */ "noarg_func ::= SERVER_STATUS", - /* 363 */ "noarg_func ::= CURRENT_USER", - /* 364 */ "noarg_func ::= USER", - /* 365 */ "star_func ::= COUNT", - /* 366 */ "star_func ::= FIRST", - /* 367 */ "star_func ::= LAST", - /* 368 */ "star_func ::= LAST_ROW", - /* 369 */ "star_func_para_list ::= NK_STAR", - /* 370 */ "star_func_para_list ::= other_para_list", - /* 371 */ "other_para_list ::= star_func_para", - /* 372 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 373 */ "star_func_para ::= expression", - /* 374 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 375 */ "predicate ::= expression compare_op expression", - /* 376 */ "predicate ::= expression BETWEEN expression AND expression", - /* 377 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 378 */ "predicate ::= expression IS NULL", - /* 379 */ "predicate ::= expression IS NOT NULL", - /* 380 */ "predicate ::= expression in_op in_predicate_value", - /* 381 */ "compare_op ::= NK_LT", - /* 382 */ "compare_op ::= NK_GT", - /* 383 */ "compare_op ::= NK_LE", - /* 384 */ "compare_op ::= NK_GE", - /* 385 */ "compare_op ::= NK_NE", - /* 386 */ "compare_op ::= NK_EQ", - /* 387 */ "compare_op ::= LIKE", - /* 388 */ "compare_op ::= NOT LIKE", - /* 389 */ "compare_op ::= MATCH", - /* 390 */ "compare_op ::= NMATCH", - /* 391 */ "compare_op ::= CONTAINS", - /* 392 */ "in_op ::= IN", - /* 393 */ "in_op ::= NOT IN", - /* 394 */ "in_predicate_value ::= NK_LP literal_list NK_RP", - /* 395 */ "boolean_value_expression ::= boolean_primary", - /* 396 */ "boolean_value_expression ::= NOT boolean_primary", - /* 397 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 398 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 399 */ "boolean_primary ::= predicate", - /* 400 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 401 */ "common_expression ::= expression", - /* 402 */ "common_expression ::= boolean_value_expression", - /* 403 */ "from_clause_opt ::=", - /* 404 */ "from_clause_opt ::= FROM table_reference_list", - /* 405 */ "table_reference_list ::= table_reference", - /* 406 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 407 */ "table_reference ::= table_primary", - /* 408 */ "table_reference ::= joined_table", - /* 409 */ "table_primary ::= table_name alias_opt", - /* 410 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 411 */ "table_primary ::= subquery alias_opt", - /* 412 */ "table_primary ::= parenthesized_joined_table", - /* 413 */ "alias_opt ::=", - /* 414 */ "alias_opt ::= table_alias", - /* 415 */ "alias_opt ::= AS table_alias", - /* 416 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 417 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 418 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 419 */ "join_type ::=", - /* 420 */ "join_type ::= INNER", - /* 421 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 422 */ "set_quantifier_opt ::=", - /* 423 */ "set_quantifier_opt ::= DISTINCT", - /* 424 */ "set_quantifier_opt ::= ALL", - /* 425 */ "select_list ::= select_item", - /* 426 */ "select_list ::= select_list NK_COMMA select_item", - /* 427 */ "select_item ::= NK_STAR", - /* 428 */ "select_item ::= common_expression", - /* 429 */ "select_item ::= common_expression column_alias", - /* 430 */ "select_item ::= common_expression AS column_alias", - /* 431 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 432 */ "where_clause_opt ::=", - /* 433 */ "where_clause_opt ::= WHERE search_condition", - /* 434 */ "partition_by_clause_opt ::=", - /* 435 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 436 */ "twindow_clause_opt ::=", - /* 437 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 438 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 439 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 440 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 441 */ "sliding_opt ::=", - /* 442 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 443 */ "fill_opt ::=", - /* 444 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 445 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 446 */ "fill_mode ::= NONE", - /* 447 */ "fill_mode ::= PREV", - /* 448 */ "fill_mode ::= NULL", - /* 449 */ "fill_mode ::= LINEAR", - /* 450 */ "fill_mode ::= NEXT", - /* 451 */ "group_by_clause_opt ::=", - /* 452 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 453 */ "group_by_list ::= expression", - /* 454 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 455 */ "having_clause_opt ::=", - /* 456 */ "having_clause_opt ::= HAVING search_condition", - /* 457 */ "range_opt ::=", - /* 458 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", - /* 459 */ "every_opt ::=", - /* 460 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", - /* 461 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 462 */ "query_expression_body ::= query_primary", - /* 463 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 464 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 465 */ "query_primary ::= query_specification", - /* 466 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", - /* 467 */ "order_by_clause_opt ::=", - /* 468 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 469 */ "slimit_clause_opt ::=", - /* 470 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 471 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 472 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 473 */ "limit_clause_opt ::=", - /* 474 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 475 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 476 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 477 */ "subquery ::= NK_LP query_expression NK_RP", - /* 478 */ "search_condition ::= common_expression", - /* 479 */ "sort_specification_list ::= sort_specification", - /* 480 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 481 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 482 */ "ordering_specification_opt ::=", - /* 483 */ "ordering_specification_opt ::= ASC", - /* 484 */ "ordering_specification_opt ::= DESC", - /* 485 */ "null_ordering_opt ::=", - /* 486 */ "null_ordering_opt ::= NULLS FIRST", - /* 487 */ "null_ordering_opt ::= NULLS LAST", + /* 309 */ "signed_literal ::= NK_QUESTION", + /* 310 */ "literal_list ::= signed_literal", + /* 311 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 312 */ "db_name ::= NK_ID", + /* 313 */ "table_name ::= NK_ID", + /* 314 */ "column_name ::= NK_ID", + /* 315 */ "function_name ::= NK_ID", + /* 316 */ "table_alias ::= NK_ID", + /* 317 */ "column_alias ::= NK_ID", + /* 318 */ "user_name ::= NK_ID", + /* 319 */ "index_name ::= NK_ID", + /* 320 */ "topic_name ::= NK_ID", + /* 321 */ "stream_name ::= NK_ID", + /* 322 */ "cgroup_name ::= NK_ID", + /* 323 */ "expression ::= literal", + /* 324 */ "expression ::= pseudo_column", + /* 325 */ "expression ::= column_reference", + /* 326 */ "expression ::= function_expression", + /* 327 */ "expression ::= subquery", + /* 328 */ "expression ::= NK_LP expression NK_RP", + /* 329 */ "expression ::= NK_PLUS expression", + /* 330 */ "expression ::= NK_MINUS expression", + /* 331 */ "expression ::= expression NK_PLUS expression", + /* 332 */ "expression ::= expression NK_MINUS expression", + /* 333 */ "expression ::= expression NK_STAR expression", + /* 334 */ "expression ::= expression NK_SLASH expression", + /* 335 */ "expression ::= expression NK_REM expression", + /* 336 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 337 */ "expression ::= expression NK_BITAND expression", + /* 338 */ "expression ::= expression NK_BITOR expression", + /* 339 */ "expression_list ::= expression", + /* 340 */ "expression_list ::= expression_list NK_COMMA expression", + /* 341 */ "column_reference ::= column_name", + /* 342 */ "column_reference ::= table_name NK_DOT column_name", + /* 343 */ "pseudo_column ::= ROWTS", + /* 344 */ "pseudo_column ::= TBNAME", + /* 345 */ "pseudo_column ::= table_name NK_DOT TBNAME", + /* 346 */ "pseudo_column ::= QSTARTTS", + /* 347 */ "pseudo_column ::= QENDTS", + /* 348 */ "pseudo_column ::= WSTARTTS", + /* 349 */ "pseudo_column ::= WENDTS", + /* 350 */ "pseudo_column ::= WDURATION", + /* 351 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 352 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 353 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 354 */ "function_expression ::= literal_func", + /* 355 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 356 */ "literal_func ::= NOW", + /* 357 */ "noarg_func ::= NOW", + /* 358 */ "noarg_func ::= TODAY", + /* 359 */ "noarg_func ::= TIMEZONE", + /* 360 */ "noarg_func ::= DATABASE", + /* 361 */ "noarg_func ::= CLIENT_VERSION", + /* 362 */ "noarg_func ::= SERVER_VERSION", + /* 363 */ "noarg_func ::= SERVER_STATUS", + /* 364 */ "noarg_func ::= CURRENT_USER", + /* 365 */ "noarg_func ::= USER", + /* 366 */ "star_func ::= COUNT", + /* 367 */ "star_func ::= FIRST", + /* 368 */ "star_func ::= LAST", + /* 369 */ "star_func ::= LAST_ROW", + /* 370 */ "star_func_para_list ::= NK_STAR", + /* 371 */ "star_func_para_list ::= other_para_list", + /* 372 */ "other_para_list ::= star_func_para", + /* 373 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 374 */ "star_func_para ::= expression", + /* 375 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 376 */ "predicate ::= expression compare_op expression", + /* 377 */ "predicate ::= expression BETWEEN expression AND expression", + /* 378 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 379 */ "predicate ::= expression IS NULL", + /* 380 */ "predicate ::= expression IS NOT NULL", + /* 381 */ "predicate ::= expression in_op in_predicate_value", + /* 382 */ "compare_op ::= NK_LT", + /* 383 */ "compare_op ::= NK_GT", + /* 384 */ "compare_op ::= NK_LE", + /* 385 */ "compare_op ::= NK_GE", + /* 386 */ "compare_op ::= NK_NE", + /* 387 */ "compare_op ::= NK_EQ", + /* 388 */ "compare_op ::= LIKE", + /* 389 */ "compare_op ::= NOT LIKE", + /* 390 */ "compare_op ::= MATCH", + /* 391 */ "compare_op ::= NMATCH", + /* 392 */ "compare_op ::= CONTAINS", + /* 393 */ "in_op ::= IN", + /* 394 */ "in_op ::= NOT IN", + /* 395 */ "in_predicate_value ::= NK_LP literal_list NK_RP", + /* 396 */ "boolean_value_expression ::= boolean_primary", + /* 397 */ "boolean_value_expression ::= NOT boolean_primary", + /* 398 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 399 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 400 */ "boolean_primary ::= predicate", + /* 401 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 402 */ "common_expression ::= expression", + /* 403 */ "common_expression ::= boolean_value_expression", + /* 404 */ "from_clause_opt ::=", + /* 405 */ "from_clause_opt ::= FROM table_reference_list", + /* 406 */ "table_reference_list ::= table_reference", + /* 407 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 408 */ "table_reference ::= table_primary", + /* 409 */ "table_reference ::= joined_table", + /* 410 */ "table_primary ::= table_name alias_opt", + /* 411 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 412 */ "table_primary ::= subquery alias_opt", + /* 413 */ "table_primary ::= parenthesized_joined_table", + /* 414 */ "alias_opt ::=", + /* 415 */ "alias_opt ::= table_alias", + /* 416 */ "alias_opt ::= AS table_alias", + /* 417 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 418 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 419 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 420 */ "join_type ::=", + /* 421 */ "join_type ::= INNER", + /* 422 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 423 */ "set_quantifier_opt ::=", + /* 424 */ "set_quantifier_opt ::= DISTINCT", + /* 425 */ "set_quantifier_opt ::= ALL", + /* 426 */ "select_list ::= select_item", + /* 427 */ "select_list ::= select_list NK_COMMA select_item", + /* 428 */ "select_item ::= NK_STAR", + /* 429 */ "select_item ::= common_expression", + /* 430 */ "select_item ::= common_expression column_alias", + /* 431 */ "select_item ::= common_expression AS column_alias", + /* 432 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 433 */ "where_clause_opt ::=", + /* 434 */ "where_clause_opt ::= WHERE search_condition", + /* 435 */ "partition_by_clause_opt ::=", + /* 436 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 437 */ "twindow_clause_opt ::=", + /* 438 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 439 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 440 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 441 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 442 */ "sliding_opt ::=", + /* 443 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 444 */ "fill_opt ::=", + /* 445 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 446 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 447 */ "fill_mode ::= NONE", + /* 448 */ "fill_mode ::= PREV", + /* 449 */ "fill_mode ::= NULL", + /* 450 */ "fill_mode ::= LINEAR", + /* 451 */ "fill_mode ::= NEXT", + /* 452 */ "group_by_clause_opt ::=", + /* 453 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 454 */ "group_by_list ::= expression", + /* 455 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 456 */ "having_clause_opt ::=", + /* 457 */ "having_clause_opt ::= HAVING search_condition", + /* 458 */ "range_opt ::=", + /* 459 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", + /* 460 */ "every_opt ::=", + /* 461 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", + /* 462 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 463 */ "query_expression_body ::= query_primary", + /* 464 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 465 */ "query_expression_body ::= query_expression_body UNION query_expression_body", + /* 466 */ "query_primary ::= query_specification", + /* 467 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", + /* 468 */ "order_by_clause_opt ::=", + /* 469 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 470 */ "slimit_clause_opt ::=", + /* 471 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 472 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 473 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 474 */ "limit_clause_opt ::=", + /* 475 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 476 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 477 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 478 */ "subquery ::= NK_LP query_expression NK_RP", + /* 479 */ "search_condition ::= common_expression", + /* 480 */ "sort_specification_list ::= sort_specification", + /* 481 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 482 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 483 */ "ordering_specification_opt ::=", + /* 484 */ "ordering_specification_opt ::= ASC", + /* 485 */ "ordering_specification_opt ::= DESC", + /* 486 */ "null_ordering_opt ::=", + /* 487 */ "null_ordering_opt ::= NULLS FIRST", + /* 488 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -3040,185 +3001,186 @@ static const struct { { 288, -1 }, /* (306) signed_literal ::= duration_literal */ { 288, -1 }, /* (307) signed_literal ::= NULL */ { 288, -1 }, /* (308) signed_literal ::= literal_func */ - { 327, -1 }, /* (309) literal_list ::= signed_literal */ - { 327, -3 }, /* (310) literal_list ::= literal_list NK_COMMA signed_literal */ - { 266, -1 }, /* (311) db_name ::= NK_ID */ - { 294, -1 }, /* (312) table_name ::= NK_ID */ - { 286, -1 }, /* (313) column_name ::= NK_ID */ - { 301, -1 }, /* (314) function_name ::= NK_ID */ - { 328, -1 }, /* (315) table_alias ::= NK_ID */ - { 329, -1 }, /* (316) column_alias ::= NK_ID */ - { 260, -1 }, /* (317) user_name ::= NK_ID */ - { 307, -1 }, /* (318) index_name ::= NK_ID */ - { 314, -1 }, /* (319) topic_name ::= NK_ID */ - { 321, -1 }, /* (320) stream_name ::= NK_ID */ - { 316, -1 }, /* (321) cgroup_name ::= NK_ID */ - { 330, -1 }, /* (322) expression ::= literal */ - { 330, -1 }, /* (323) expression ::= pseudo_column */ - { 330, -1 }, /* (324) expression ::= column_reference */ - { 330, -1 }, /* (325) expression ::= function_expression */ - { 330, -1 }, /* (326) expression ::= subquery */ - { 330, -3 }, /* (327) expression ::= NK_LP expression NK_RP */ - { 330, -2 }, /* (328) expression ::= NK_PLUS expression */ - { 330, -2 }, /* (329) expression ::= NK_MINUS expression */ - { 330, -3 }, /* (330) expression ::= expression NK_PLUS expression */ - { 330, -3 }, /* (331) expression ::= expression NK_MINUS expression */ - { 330, -3 }, /* (332) expression ::= expression NK_STAR expression */ - { 330, -3 }, /* (333) expression ::= expression NK_SLASH expression */ - { 330, -3 }, /* (334) expression ::= expression NK_REM expression */ - { 330, -3 }, /* (335) expression ::= column_reference NK_ARROW NK_STRING */ - { 330, -3 }, /* (336) expression ::= expression NK_BITAND expression */ - { 330, -3 }, /* (337) expression ::= expression NK_BITOR expression */ - { 291, -1 }, /* (338) expression_list ::= expression */ - { 291, -3 }, /* (339) expression_list ::= expression_list NK_COMMA expression */ - { 332, -1 }, /* (340) column_reference ::= column_name */ - { 332, -3 }, /* (341) column_reference ::= table_name NK_DOT column_name */ - { 331, -1 }, /* (342) pseudo_column ::= ROWTS */ - { 331, -1 }, /* (343) pseudo_column ::= TBNAME */ - { 331, -3 }, /* (344) pseudo_column ::= table_name NK_DOT TBNAME */ - { 331, -1 }, /* (345) pseudo_column ::= QSTARTTS */ - { 331, -1 }, /* (346) pseudo_column ::= QENDTS */ - { 331, -1 }, /* (347) pseudo_column ::= WSTARTTS */ - { 331, -1 }, /* (348) pseudo_column ::= WENDTS */ - { 331, -1 }, /* (349) pseudo_column ::= WDURATION */ - { 333, -4 }, /* (350) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 333, -4 }, /* (351) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 333, -6 }, /* (352) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 333, -1 }, /* (353) function_expression ::= literal_func */ - { 326, -3 }, /* (354) literal_func ::= noarg_func NK_LP NK_RP */ - { 326, -1 }, /* (355) literal_func ::= NOW */ - { 337, -1 }, /* (356) noarg_func ::= NOW */ - { 337, -1 }, /* (357) noarg_func ::= TODAY */ - { 337, -1 }, /* (358) noarg_func ::= TIMEZONE */ - { 337, -1 }, /* (359) noarg_func ::= DATABASE */ - { 337, -1 }, /* (360) noarg_func ::= CLIENT_VERSION */ - { 337, -1 }, /* (361) noarg_func ::= SERVER_VERSION */ - { 337, -1 }, /* (362) noarg_func ::= SERVER_STATUS */ - { 337, -1 }, /* (363) noarg_func ::= CURRENT_USER */ - { 337, -1 }, /* (364) noarg_func ::= USER */ - { 335, -1 }, /* (365) star_func ::= COUNT */ - { 335, -1 }, /* (366) star_func ::= FIRST */ - { 335, -1 }, /* (367) star_func ::= LAST */ - { 335, -1 }, /* (368) star_func ::= LAST_ROW */ - { 336, -1 }, /* (369) star_func_para_list ::= NK_STAR */ - { 336, -1 }, /* (370) star_func_para_list ::= other_para_list */ - { 338, -1 }, /* (371) other_para_list ::= star_func_para */ - { 338, -3 }, /* (372) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 339, -1 }, /* (373) star_func_para ::= expression */ - { 339, -3 }, /* (374) star_func_para ::= table_name NK_DOT NK_STAR */ - { 340, -3 }, /* (375) predicate ::= expression compare_op expression */ - { 340, -5 }, /* (376) predicate ::= expression BETWEEN expression AND expression */ - { 340, -6 }, /* (377) predicate ::= expression NOT BETWEEN expression AND expression */ - { 340, -3 }, /* (378) predicate ::= expression IS NULL */ - { 340, -4 }, /* (379) predicate ::= expression IS NOT NULL */ - { 340, -3 }, /* (380) predicate ::= expression in_op in_predicate_value */ - { 341, -1 }, /* (381) compare_op ::= NK_LT */ - { 341, -1 }, /* (382) compare_op ::= NK_GT */ - { 341, -1 }, /* (383) compare_op ::= NK_LE */ - { 341, -1 }, /* (384) compare_op ::= NK_GE */ - { 341, -1 }, /* (385) compare_op ::= NK_NE */ - { 341, -1 }, /* (386) compare_op ::= NK_EQ */ - { 341, -1 }, /* (387) compare_op ::= LIKE */ - { 341, -2 }, /* (388) compare_op ::= NOT LIKE */ - { 341, -1 }, /* (389) compare_op ::= MATCH */ - { 341, -1 }, /* (390) compare_op ::= NMATCH */ - { 341, -1 }, /* (391) compare_op ::= CONTAINS */ - { 342, -1 }, /* (392) in_op ::= IN */ - { 342, -2 }, /* (393) in_op ::= NOT IN */ - { 343, -3 }, /* (394) in_predicate_value ::= NK_LP literal_list NK_RP */ - { 344, -1 }, /* (395) boolean_value_expression ::= boolean_primary */ - { 344, -2 }, /* (396) boolean_value_expression ::= NOT boolean_primary */ - { 344, -3 }, /* (397) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 344, -3 }, /* (398) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 345, -1 }, /* (399) boolean_primary ::= predicate */ - { 345, -3 }, /* (400) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 346, -1 }, /* (401) common_expression ::= expression */ - { 346, -1 }, /* (402) common_expression ::= boolean_value_expression */ - { 347, 0 }, /* (403) from_clause_opt ::= */ - { 347, -2 }, /* (404) from_clause_opt ::= FROM table_reference_list */ - { 348, -1 }, /* (405) table_reference_list ::= table_reference */ - { 348, -3 }, /* (406) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 349, -1 }, /* (407) table_reference ::= table_primary */ - { 349, -1 }, /* (408) table_reference ::= joined_table */ - { 350, -2 }, /* (409) table_primary ::= table_name alias_opt */ - { 350, -4 }, /* (410) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 350, -2 }, /* (411) table_primary ::= subquery alias_opt */ - { 350, -1 }, /* (412) table_primary ::= parenthesized_joined_table */ - { 352, 0 }, /* (413) alias_opt ::= */ - { 352, -1 }, /* (414) alias_opt ::= table_alias */ - { 352, -2 }, /* (415) alias_opt ::= AS table_alias */ - { 353, -3 }, /* (416) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 353, -3 }, /* (417) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 351, -6 }, /* (418) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 354, 0 }, /* (419) join_type ::= */ - { 354, -1 }, /* (420) join_type ::= INNER */ - { 356, -12 }, /* (421) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 357, 0 }, /* (422) set_quantifier_opt ::= */ - { 357, -1 }, /* (423) set_quantifier_opt ::= DISTINCT */ - { 357, -1 }, /* (424) set_quantifier_opt ::= ALL */ - { 358, -1 }, /* (425) select_list ::= select_item */ - { 358, -3 }, /* (426) select_list ::= select_list NK_COMMA select_item */ - { 366, -1 }, /* (427) select_item ::= NK_STAR */ - { 366, -1 }, /* (428) select_item ::= common_expression */ - { 366, -2 }, /* (429) select_item ::= common_expression column_alias */ - { 366, -3 }, /* (430) select_item ::= common_expression AS column_alias */ - { 366, -3 }, /* (431) select_item ::= table_name NK_DOT NK_STAR */ - { 324, 0 }, /* (432) where_clause_opt ::= */ - { 324, -2 }, /* (433) where_clause_opt ::= WHERE search_condition */ - { 359, 0 }, /* (434) partition_by_clause_opt ::= */ - { 359, -3 }, /* (435) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 363, 0 }, /* (436) twindow_clause_opt ::= */ - { 363, -6 }, /* (437) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 363, -4 }, /* (438) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 363, -6 }, /* (439) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 363, -8 }, /* (440) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 310, 0 }, /* (441) sliding_opt ::= */ - { 310, -4 }, /* (442) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 362, 0 }, /* (443) fill_opt ::= */ - { 362, -4 }, /* (444) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 362, -6 }, /* (445) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 367, -1 }, /* (446) fill_mode ::= NONE */ - { 367, -1 }, /* (447) fill_mode ::= PREV */ - { 367, -1 }, /* (448) fill_mode ::= NULL */ - { 367, -1 }, /* (449) fill_mode ::= LINEAR */ - { 367, -1 }, /* (450) fill_mode ::= NEXT */ - { 364, 0 }, /* (451) group_by_clause_opt ::= */ - { 364, -3 }, /* (452) group_by_clause_opt ::= GROUP BY group_by_list */ - { 368, -1 }, /* (453) group_by_list ::= expression */ - { 368, -3 }, /* (454) group_by_list ::= group_by_list NK_COMMA expression */ - { 365, 0 }, /* (455) having_clause_opt ::= */ - { 365, -2 }, /* (456) having_clause_opt ::= HAVING search_condition */ - { 360, 0 }, /* (457) range_opt ::= */ - { 360, -6 }, /* (458) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ - { 361, 0 }, /* (459) every_opt ::= */ - { 361, -4 }, /* (460) every_opt ::= EVERY NK_LP duration_literal NK_RP */ - { 315, -4 }, /* (461) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 369, -1 }, /* (462) query_expression_body ::= query_primary */ - { 369, -4 }, /* (463) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 369, -3 }, /* (464) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 373, -1 }, /* (465) query_primary ::= query_specification */ - { 373, -6 }, /* (466) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ - { 370, 0 }, /* (467) order_by_clause_opt ::= */ - { 370, -3 }, /* (468) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 371, 0 }, /* (469) slimit_clause_opt ::= */ - { 371, -2 }, /* (470) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 371, -4 }, /* (471) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 371, -4 }, /* (472) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 372, 0 }, /* (473) limit_clause_opt ::= */ - { 372, -2 }, /* (474) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 372, -4 }, /* (475) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 372, -4 }, /* (476) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 334, -3 }, /* (477) subquery ::= NK_LP query_expression NK_RP */ - { 355, -1 }, /* (478) search_condition ::= common_expression */ - { 374, -1 }, /* (479) sort_specification_list ::= sort_specification */ - { 374, -3 }, /* (480) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 375, -3 }, /* (481) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 376, 0 }, /* (482) ordering_specification_opt ::= */ - { 376, -1 }, /* (483) ordering_specification_opt ::= ASC */ - { 376, -1 }, /* (484) ordering_specification_opt ::= DESC */ - { 377, 0 }, /* (485) null_ordering_opt ::= */ - { 377, -2 }, /* (486) null_ordering_opt ::= NULLS FIRST */ - { 377, -2 }, /* (487) null_ordering_opt ::= NULLS LAST */ + { 288, -1 }, /* (309) signed_literal ::= NK_QUESTION */ + { 327, -1 }, /* (310) literal_list ::= signed_literal */ + { 327, -3 }, /* (311) literal_list ::= literal_list NK_COMMA signed_literal */ + { 266, -1 }, /* (312) db_name ::= NK_ID */ + { 294, -1 }, /* (313) table_name ::= NK_ID */ + { 286, -1 }, /* (314) column_name ::= NK_ID */ + { 301, -1 }, /* (315) function_name ::= NK_ID */ + { 328, -1 }, /* (316) table_alias ::= NK_ID */ + { 329, -1 }, /* (317) column_alias ::= NK_ID */ + { 260, -1 }, /* (318) user_name ::= NK_ID */ + { 307, -1 }, /* (319) index_name ::= NK_ID */ + { 314, -1 }, /* (320) topic_name ::= NK_ID */ + { 321, -1 }, /* (321) stream_name ::= NK_ID */ + { 316, -1 }, /* (322) cgroup_name ::= NK_ID */ + { 330, -1 }, /* (323) expression ::= literal */ + { 330, -1 }, /* (324) expression ::= pseudo_column */ + { 330, -1 }, /* (325) expression ::= column_reference */ + { 330, -1 }, /* (326) expression ::= function_expression */ + { 330, -1 }, /* (327) expression ::= subquery */ + { 330, -3 }, /* (328) expression ::= NK_LP expression NK_RP */ + { 330, -2 }, /* (329) expression ::= NK_PLUS expression */ + { 330, -2 }, /* (330) expression ::= NK_MINUS expression */ + { 330, -3 }, /* (331) expression ::= expression NK_PLUS expression */ + { 330, -3 }, /* (332) expression ::= expression NK_MINUS expression */ + { 330, -3 }, /* (333) expression ::= expression NK_STAR expression */ + { 330, -3 }, /* (334) expression ::= expression NK_SLASH expression */ + { 330, -3 }, /* (335) expression ::= expression NK_REM expression */ + { 330, -3 }, /* (336) expression ::= column_reference NK_ARROW NK_STRING */ + { 330, -3 }, /* (337) expression ::= expression NK_BITAND expression */ + { 330, -3 }, /* (338) expression ::= expression NK_BITOR expression */ + { 291, -1 }, /* (339) expression_list ::= expression */ + { 291, -3 }, /* (340) expression_list ::= expression_list NK_COMMA expression */ + { 332, -1 }, /* (341) column_reference ::= column_name */ + { 332, -3 }, /* (342) column_reference ::= table_name NK_DOT column_name */ + { 331, -1 }, /* (343) pseudo_column ::= ROWTS */ + { 331, -1 }, /* (344) pseudo_column ::= TBNAME */ + { 331, -3 }, /* (345) pseudo_column ::= table_name NK_DOT TBNAME */ + { 331, -1 }, /* (346) pseudo_column ::= QSTARTTS */ + { 331, -1 }, /* (347) pseudo_column ::= QENDTS */ + { 331, -1 }, /* (348) pseudo_column ::= WSTARTTS */ + { 331, -1 }, /* (349) pseudo_column ::= WENDTS */ + { 331, -1 }, /* (350) pseudo_column ::= WDURATION */ + { 333, -4 }, /* (351) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 333, -4 }, /* (352) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 333, -6 }, /* (353) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + { 333, -1 }, /* (354) function_expression ::= literal_func */ + { 326, -3 }, /* (355) literal_func ::= noarg_func NK_LP NK_RP */ + { 326, -1 }, /* (356) literal_func ::= NOW */ + { 337, -1 }, /* (357) noarg_func ::= NOW */ + { 337, -1 }, /* (358) noarg_func ::= TODAY */ + { 337, -1 }, /* (359) noarg_func ::= TIMEZONE */ + { 337, -1 }, /* (360) noarg_func ::= DATABASE */ + { 337, -1 }, /* (361) noarg_func ::= CLIENT_VERSION */ + { 337, -1 }, /* (362) noarg_func ::= SERVER_VERSION */ + { 337, -1 }, /* (363) noarg_func ::= SERVER_STATUS */ + { 337, -1 }, /* (364) noarg_func ::= CURRENT_USER */ + { 337, -1 }, /* (365) noarg_func ::= USER */ + { 335, -1 }, /* (366) star_func ::= COUNT */ + { 335, -1 }, /* (367) star_func ::= FIRST */ + { 335, -1 }, /* (368) star_func ::= LAST */ + { 335, -1 }, /* (369) star_func ::= LAST_ROW */ + { 336, -1 }, /* (370) star_func_para_list ::= NK_STAR */ + { 336, -1 }, /* (371) star_func_para_list ::= other_para_list */ + { 338, -1 }, /* (372) other_para_list ::= star_func_para */ + { 338, -3 }, /* (373) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 339, -1 }, /* (374) star_func_para ::= expression */ + { 339, -3 }, /* (375) star_func_para ::= table_name NK_DOT NK_STAR */ + { 340, -3 }, /* (376) predicate ::= expression compare_op expression */ + { 340, -5 }, /* (377) predicate ::= expression BETWEEN expression AND expression */ + { 340, -6 }, /* (378) predicate ::= expression NOT BETWEEN expression AND expression */ + { 340, -3 }, /* (379) predicate ::= expression IS NULL */ + { 340, -4 }, /* (380) predicate ::= expression IS NOT NULL */ + { 340, -3 }, /* (381) predicate ::= expression in_op in_predicate_value */ + { 341, -1 }, /* (382) compare_op ::= NK_LT */ + { 341, -1 }, /* (383) compare_op ::= NK_GT */ + { 341, -1 }, /* (384) compare_op ::= NK_LE */ + { 341, -1 }, /* (385) compare_op ::= NK_GE */ + { 341, -1 }, /* (386) compare_op ::= NK_NE */ + { 341, -1 }, /* (387) compare_op ::= NK_EQ */ + { 341, -1 }, /* (388) compare_op ::= LIKE */ + { 341, -2 }, /* (389) compare_op ::= NOT LIKE */ + { 341, -1 }, /* (390) compare_op ::= MATCH */ + { 341, -1 }, /* (391) compare_op ::= NMATCH */ + { 341, -1 }, /* (392) compare_op ::= CONTAINS */ + { 342, -1 }, /* (393) in_op ::= IN */ + { 342, -2 }, /* (394) in_op ::= NOT IN */ + { 343, -3 }, /* (395) in_predicate_value ::= NK_LP literal_list NK_RP */ + { 344, -1 }, /* (396) boolean_value_expression ::= boolean_primary */ + { 344, -2 }, /* (397) boolean_value_expression ::= NOT boolean_primary */ + { 344, -3 }, /* (398) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 344, -3 }, /* (399) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 345, -1 }, /* (400) boolean_primary ::= predicate */ + { 345, -3 }, /* (401) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 346, -1 }, /* (402) common_expression ::= expression */ + { 346, -1 }, /* (403) common_expression ::= boolean_value_expression */ + { 347, 0 }, /* (404) from_clause_opt ::= */ + { 347, -2 }, /* (405) from_clause_opt ::= FROM table_reference_list */ + { 348, -1 }, /* (406) table_reference_list ::= table_reference */ + { 348, -3 }, /* (407) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 349, -1 }, /* (408) table_reference ::= table_primary */ + { 349, -1 }, /* (409) table_reference ::= joined_table */ + { 350, -2 }, /* (410) table_primary ::= table_name alias_opt */ + { 350, -4 }, /* (411) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 350, -2 }, /* (412) table_primary ::= subquery alias_opt */ + { 350, -1 }, /* (413) table_primary ::= parenthesized_joined_table */ + { 352, 0 }, /* (414) alias_opt ::= */ + { 352, -1 }, /* (415) alias_opt ::= table_alias */ + { 352, -2 }, /* (416) alias_opt ::= AS table_alias */ + { 353, -3 }, /* (417) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 353, -3 }, /* (418) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 351, -6 }, /* (419) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 354, 0 }, /* (420) join_type ::= */ + { 354, -1 }, /* (421) join_type ::= INNER */ + { 356, -12 }, /* (422) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 357, 0 }, /* (423) set_quantifier_opt ::= */ + { 357, -1 }, /* (424) set_quantifier_opt ::= DISTINCT */ + { 357, -1 }, /* (425) set_quantifier_opt ::= ALL */ + { 358, -1 }, /* (426) select_list ::= select_item */ + { 358, -3 }, /* (427) select_list ::= select_list NK_COMMA select_item */ + { 366, -1 }, /* (428) select_item ::= NK_STAR */ + { 366, -1 }, /* (429) select_item ::= common_expression */ + { 366, -2 }, /* (430) select_item ::= common_expression column_alias */ + { 366, -3 }, /* (431) select_item ::= common_expression AS column_alias */ + { 366, -3 }, /* (432) select_item ::= table_name NK_DOT NK_STAR */ + { 324, 0 }, /* (433) where_clause_opt ::= */ + { 324, -2 }, /* (434) where_clause_opt ::= WHERE search_condition */ + { 359, 0 }, /* (435) partition_by_clause_opt ::= */ + { 359, -3 }, /* (436) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 363, 0 }, /* (437) twindow_clause_opt ::= */ + { 363, -6 }, /* (438) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 363, -4 }, /* (439) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + { 363, -6 }, /* (440) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 363, -8 }, /* (441) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 310, 0 }, /* (442) sliding_opt ::= */ + { 310, -4 }, /* (443) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 362, 0 }, /* (444) fill_opt ::= */ + { 362, -4 }, /* (445) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 362, -6 }, /* (446) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 367, -1 }, /* (447) fill_mode ::= NONE */ + { 367, -1 }, /* (448) fill_mode ::= PREV */ + { 367, -1 }, /* (449) fill_mode ::= NULL */ + { 367, -1 }, /* (450) fill_mode ::= LINEAR */ + { 367, -1 }, /* (451) fill_mode ::= NEXT */ + { 364, 0 }, /* (452) group_by_clause_opt ::= */ + { 364, -3 }, /* (453) group_by_clause_opt ::= GROUP BY group_by_list */ + { 368, -1 }, /* (454) group_by_list ::= expression */ + { 368, -3 }, /* (455) group_by_list ::= group_by_list NK_COMMA expression */ + { 365, 0 }, /* (456) having_clause_opt ::= */ + { 365, -2 }, /* (457) having_clause_opt ::= HAVING search_condition */ + { 360, 0 }, /* (458) range_opt ::= */ + { 360, -6 }, /* (459) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ + { 361, 0 }, /* (460) every_opt ::= */ + { 361, -4 }, /* (461) every_opt ::= EVERY NK_LP duration_literal NK_RP */ + { 315, -4 }, /* (462) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 369, -1 }, /* (463) query_expression_body ::= query_primary */ + { 369, -4 }, /* (464) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 369, -3 }, /* (465) query_expression_body ::= query_expression_body UNION query_expression_body */ + { 373, -1 }, /* (466) query_primary ::= query_specification */ + { 373, -6 }, /* (467) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ + { 370, 0 }, /* (468) order_by_clause_opt ::= */ + { 370, -3 }, /* (469) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 371, 0 }, /* (470) slimit_clause_opt ::= */ + { 371, -2 }, /* (471) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 371, -4 }, /* (472) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 371, -4 }, /* (473) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 372, 0 }, /* (474) limit_clause_opt ::= */ + { 372, -2 }, /* (475) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 372, -4 }, /* (476) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 372, -4 }, /* (477) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 334, -3 }, /* (478) subquery ::= NK_LP query_expression NK_RP */ + { 355, -1 }, /* (479) search_condition ::= common_expression */ + { 374, -1 }, /* (480) sort_specification_list ::= sort_specification */ + { 374, -3 }, /* (481) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 375, -3 }, /* (482) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 376, 0 }, /* (483) ordering_specification_opt ::= */ + { 376, -1 }, /* (484) ordering_specification_opt ::= ASC */ + { 376, -1 }, /* (485) ordering_specification_opt ::= DESC */ + { 377, 0 }, /* (486) null_ordering_opt ::= */ + { 377, -2 }, /* (487) null_ordering_opt ::= NULLS FIRST */ + { 377, -2 }, /* (488) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3434,30 +3396,30 @@ static YYACTIONTYPE yy_reduce( case 49: /* dnode_endpoint ::= NK_STRING */ case 50: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==50); case 51: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==51); - case 311: /* db_name ::= NK_ID */ yytestcase(yyruleno==311); - case 312: /* table_name ::= NK_ID */ yytestcase(yyruleno==312); - case 313: /* column_name ::= NK_ID */ yytestcase(yyruleno==313); - case 314: /* function_name ::= NK_ID */ yytestcase(yyruleno==314); - case 315: /* table_alias ::= NK_ID */ yytestcase(yyruleno==315); - case 316: /* column_alias ::= NK_ID */ yytestcase(yyruleno==316); - case 317: /* user_name ::= NK_ID */ yytestcase(yyruleno==317); - case 318: /* index_name ::= NK_ID */ yytestcase(yyruleno==318); - case 319: /* topic_name ::= NK_ID */ yytestcase(yyruleno==319); - case 320: /* stream_name ::= NK_ID */ yytestcase(yyruleno==320); - case 321: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==321); - case 356: /* noarg_func ::= NOW */ yytestcase(yyruleno==356); - case 357: /* noarg_func ::= TODAY */ yytestcase(yyruleno==357); - case 358: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==358); - case 359: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==359); - case 360: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==360); - case 361: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==361); - case 362: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==362); - case 363: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==363); - case 364: /* noarg_func ::= USER */ yytestcase(yyruleno==364); - case 365: /* star_func ::= COUNT */ yytestcase(yyruleno==365); - case 366: /* star_func ::= FIRST */ yytestcase(yyruleno==366); - case 367: /* star_func ::= LAST */ yytestcase(yyruleno==367); - case 368: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==368); + case 312: /* db_name ::= NK_ID */ yytestcase(yyruleno==312); + case 313: /* table_name ::= NK_ID */ yytestcase(yyruleno==313); + case 314: /* column_name ::= NK_ID */ yytestcase(yyruleno==314); + case 315: /* function_name ::= NK_ID */ yytestcase(yyruleno==315); + case 316: /* table_alias ::= NK_ID */ yytestcase(yyruleno==316); + case 317: /* column_alias ::= NK_ID */ yytestcase(yyruleno==317); + case 318: /* user_name ::= NK_ID */ yytestcase(yyruleno==318); + case 319: /* index_name ::= NK_ID */ yytestcase(yyruleno==319); + case 320: /* topic_name ::= NK_ID */ yytestcase(yyruleno==320); + case 321: /* stream_name ::= NK_ID */ yytestcase(yyruleno==321); + case 322: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==322); + case 357: /* noarg_func ::= NOW */ yytestcase(yyruleno==357); + case 358: /* noarg_func ::= TODAY */ yytestcase(yyruleno==358); + case 359: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==359); + case 360: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==360); + case 361: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==361); + case 362: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==362); + case 363: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==363); + case 364: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==364); + case 365: /* noarg_func ::= USER */ yytestcase(yyruleno==365); + case 366: /* star_func ::= COUNT */ yytestcase(yyruleno==366); + case 367: /* star_func ::= FIRST */ yytestcase(yyruleno==367); + case 368: /* star_func ::= LAST */ yytestcase(yyruleno==368); + case 369: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==369); { yylhsminor.yy533 = yymsp[0].minor.yy0; } yymsp[0].minor.yy533 = yylhsminor.yy533; break; @@ -3516,7 +3478,7 @@ static YYACTIONTYPE yy_reduce( case 71: /* exists_opt ::= */ yytestcase(yyruleno==71); case 252: /* analyze_opt ::= */ yytestcase(yyruleno==252); case 260: /* agg_func_opt ::= */ yytestcase(yyruleno==260); - case 422: /* set_quantifier_opt ::= */ yytestcase(yyruleno==422); + case 423: /* set_quantifier_opt ::= */ yytestcase(yyruleno==423); { yymsp[1].minor.yy173 = false; } break; case 70: /* exists_opt ::= IF EXISTS */ @@ -3663,10 +3625,10 @@ static YYACTIONTYPE yy_reduce( case 183: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==183); case 188: /* col_name_list ::= col_name */ yytestcase(yyruleno==188); case 235: /* func_list ::= func */ yytestcase(yyruleno==235); - case 309: /* literal_list ::= signed_literal */ yytestcase(yyruleno==309); - case 371: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==371); - case 425: /* select_list ::= select_item */ yytestcase(yyruleno==425); - case 479: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==479); + case 310: /* literal_list ::= signed_literal */ yytestcase(yyruleno==310); + case 372: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==372); + case 426: /* select_list ::= select_item */ yytestcase(yyruleno==426); + case 480: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==480); { yylhsminor.yy712 = createNodeList(pCxt, yymsp[0].minor.yy560); } yymsp[0].minor.yy712 = yylhsminor.yy712; break; @@ -3675,10 +3637,10 @@ static YYACTIONTYPE yy_reduce( case 184: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==184); case 189: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==189); case 236: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==236); - case 310: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==310); - case 372: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==372); - case 426: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==426); - case 480: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==480); + case 311: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==311); + case 373: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==373); + case 427: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==427); + case 481: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==481); { yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, yymsp[0].minor.yy560); } yymsp[-2].minor.yy712 = yylhsminor.yy712; break; @@ -3761,9 +3723,9 @@ static YYACTIONTYPE yy_reduce( break; case 136: /* specific_cols_opt ::= */ case 167: /* tags_def_opt ::= */ yytestcase(yyruleno==167); - case 434: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==434); - case 451: /* group_by_clause_opt ::= */ yytestcase(yyruleno==451); - case 467: /* order_by_clause_opt ::= */ yytestcase(yyruleno==467); + case 435: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==435); + case 452: /* group_by_clause_opt ::= */ yytestcase(yyruleno==452); + case 468: /* order_by_clause_opt ::= */ yytestcase(yyruleno==468); { yymsp[1].minor.yy712 = NULL; } break; case 137: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ @@ -3853,7 +3815,7 @@ static YYACTIONTYPE yy_reduce( { yymsp[-5].minor.yy196 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 168: /* tags_def_opt ::= tags_def */ - case 370: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==370); + case 371: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==371); { yylhsminor.yy712 = yymsp[0].minor.yy712; } yymsp[0].minor.yy712 = yylhsminor.yy712; break; @@ -3902,12 +3864,12 @@ static YYACTIONTYPE yy_reduce( { yymsp[-1].minor.yy389.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy389.val = yymsp[0].minor.yy0; } break; case 181: /* duration_list ::= duration_literal */ - case 338: /* expression_list ::= expression */ yytestcase(yyruleno==338); + case 339: /* expression_list ::= expression */ yytestcase(yyruleno==339); { yylhsminor.yy712 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy560)); } yymsp[0].minor.yy712 = yylhsminor.yy712; break; case 182: /* duration_list ::= duration_list NK_COMMA duration_literal */ - case 339: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==339); + case 340: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==340); { yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, releaseRawExprNode(pCxt, yymsp[0].minor.yy560)); } yymsp[-2].minor.yy712 = yylhsminor.yy712; break; @@ -4031,16 +3993,16 @@ static YYACTIONTYPE yy_reduce( break; case 226: /* like_pattern_opt ::= */ case 266: /* into_opt ::= */ yytestcase(yyruleno==266); - case 403: /* from_clause_opt ::= */ yytestcase(yyruleno==403); - case 432: /* where_clause_opt ::= */ yytestcase(yyruleno==432); - case 436: /* twindow_clause_opt ::= */ yytestcase(yyruleno==436); - case 441: /* sliding_opt ::= */ yytestcase(yyruleno==441); - case 443: /* fill_opt ::= */ yytestcase(yyruleno==443); - case 455: /* having_clause_opt ::= */ yytestcase(yyruleno==455); - case 457: /* range_opt ::= */ yytestcase(yyruleno==457); - case 459: /* every_opt ::= */ yytestcase(yyruleno==459); - case 469: /* slimit_clause_opt ::= */ yytestcase(yyruleno==469); - case 473: /* limit_clause_opt ::= */ yytestcase(yyruleno==473); + case 404: /* from_clause_opt ::= */ yytestcase(yyruleno==404); + case 433: /* where_clause_opt ::= */ yytestcase(yyruleno==433); + case 437: /* twindow_clause_opt ::= */ yytestcase(yyruleno==437); + case 442: /* sliding_opt ::= */ yytestcase(yyruleno==442); + case 444: /* fill_opt ::= */ yytestcase(yyruleno==444); + case 456: /* having_clause_opt ::= */ yytestcase(yyruleno==456); + case 458: /* range_opt ::= */ yytestcase(yyruleno==458); + case 460: /* every_opt ::= */ yytestcase(yyruleno==460); + case 470: /* slimit_clause_opt ::= */ yytestcase(yyruleno==470); + case 474: /* limit_clause_opt ::= */ yytestcase(yyruleno==474); { yymsp[1].minor.yy560 = NULL; } break; case 227: /* like_pattern_opt ::= LIKE NK_STRING */ @@ -4115,7 +4077,7 @@ static YYACTIONTYPE yy_reduce( break; case 253: /* analyze_opt ::= ANALYZE */ case 261: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==261); - case 423: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==423); + case 424: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==424); { yymsp[0].minor.yy173 = true; } break; case 254: /* explain_options ::= */ @@ -4151,9 +4113,9 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy533); } break; case 267: /* into_opt ::= INTO full_table_name */ - case 404: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==404); - case 433: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==433); - case 456: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==456); + case 405: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==405); + case 434: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==434); + case 457: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==457); { yymsp[-1].minor.yy560 = yymsp[0].minor.yy560; } break; case 269: /* stream_options ::= stream_options TRIGGER AT_ONCE */ @@ -4227,22 +4189,22 @@ static YYACTIONTYPE yy_reduce( break; case 292: /* literal ::= duration_literal */ case 302: /* signed_literal ::= signed */ yytestcase(yyruleno==302); - case 322: /* expression ::= literal */ yytestcase(yyruleno==322); - case 323: /* expression ::= pseudo_column */ yytestcase(yyruleno==323); - case 324: /* expression ::= column_reference */ yytestcase(yyruleno==324); - case 325: /* expression ::= function_expression */ yytestcase(yyruleno==325); - case 326: /* expression ::= subquery */ yytestcase(yyruleno==326); - case 353: /* function_expression ::= literal_func */ yytestcase(yyruleno==353); - case 395: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==395); - case 399: /* boolean_primary ::= predicate */ yytestcase(yyruleno==399); - case 401: /* common_expression ::= expression */ yytestcase(yyruleno==401); - case 402: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==402); - case 405: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==405); - case 407: /* table_reference ::= table_primary */ yytestcase(yyruleno==407); - case 408: /* table_reference ::= joined_table */ yytestcase(yyruleno==408); - case 412: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==412); - case 462: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==462); - case 465: /* query_primary ::= query_specification */ yytestcase(yyruleno==465); + case 323: /* expression ::= literal */ yytestcase(yyruleno==323); + case 324: /* expression ::= pseudo_column */ yytestcase(yyruleno==324); + case 325: /* expression ::= column_reference */ yytestcase(yyruleno==325); + case 326: /* expression ::= function_expression */ yytestcase(yyruleno==326); + case 327: /* expression ::= subquery */ yytestcase(yyruleno==327); + case 354: /* function_expression ::= literal_func */ yytestcase(yyruleno==354); + case 396: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==396); + case 400: /* boolean_primary ::= predicate */ yytestcase(yyruleno==400); + case 402: /* common_expression ::= expression */ yytestcase(yyruleno==402); + case 403: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==403); + case 406: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==406); + case 408: /* table_reference ::= table_primary */ yytestcase(yyruleno==408); + case 409: /* table_reference ::= joined_table */ yytestcase(yyruleno==409); + case 413: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==413); + case 463: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==463); + case 466: /* query_primary ::= query_specification */ yytestcase(yyruleno==466); { yylhsminor.yy560 = yymsp[0].minor.yy560; } yymsp[0].minor.yy560 = yylhsminor.yy560; break; @@ -4301,9 +4263,9 @@ static YYACTIONTYPE yy_reduce( break; case 306: /* signed_literal ::= duration_literal */ case 308: /* signed_literal ::= literal_func */ yytestcase(yyruleno==308); - case 373: /* star_func_para ::= expression */ yytestcase(yyruleno==373); - case 428: /* select_item ::= common_expression */ yytestcase(yyruleno==428); - case 478: /* search_condition ::= common_expression */ yytestcase(yyruleno==478); + case 374: /* star_func_para ::= expression */ yytestcase(yyruleno==374); + case 429: /* select_item ::= common_expression */ yytestcase(yyruleno==429); + case 479: /* search_condition ::= common_expression */ yytestcase(yyruleno==479); { yylhsminor.yy560 = releaseRawExprNode(pCxt, yymsp[0].minor.yy560); } yymsp[0].minor.yy560 = yylhsminor.yy560; break; @@ -4311,26 +4273,30 @@ static YYACTIONTYPE yy_reduce( { yylhsminor.yy560 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 327: /* expression ::= NK_LP expression NK_RP */ - case 400: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==400); + case 309: /* signed_literal ::= NK_QUESTION */ +{ yylhsminor.yy560 = createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy560 = yylhsminor.yy560; + break; + case 328: /* expression ::= NK_LP expression NK_RP */ + case 401: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==401); { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 328: /* expression ::= NK_PLUS expression */ + case 329: /* expression ::= NK_PLUS expression */ { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy560)); } yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 329: /* expression ::= NK_MINUS expression */ + case 330: /* expression ::= NK_MINUS expression */ { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy560), NULL)); } yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 330: /* expression ::= expression NK_PLUS expression */ + case 331: /* expression ::= expression NK_PLUS expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4338,7 +4304,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 331: /* expression ::= expression NK_MINUS expression */ + case 332: /* expression ::= expression NK_MINUS expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4346,7 +4312,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 332: /* expression ::= expression NK_STAR expression */ + case 333: /* expression ::= expression NK_STAR expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4354,7 +4320,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 333: /* expression ::= expression NK_SLASH expression */ + case 334: /* expression ::= expression NK_SLASH expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4362,7 +4328,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 334: /* expression ::= expression NK_REM expression */ + case 335: /* expression ::= expression NK_REM expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4370,14 +4336,14 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 335: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 336: /* expression ::= column_reference NK_ARROW NK_STRING */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 336: /* expression ::= expression NK_BITAND expression */ + case 337: /* expression ::= expression NK_BITAND expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4385,7 +4351,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 337: /* expression ::= expression NK_BITOR expression */ + case 338: /* expression ::= expression NK_BITOR expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4393,53 +4359,53 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 340: /* column_reference ::= column_name */ + case 341: /* column_reference ::= column_name */ { yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy533, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy533)); } yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 341: /* column_reference ::= table_name NK_DOT column_name */ + case 342: /* column_reference ::= table_name NK_DOT column_name */ { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533, createColumnNode(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy533)); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 342: /* pseudo_column ::= ROWTS */ - case 343: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==343); - case 345: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==345); - case 346: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==346); - case 347: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==347); - case 348: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==348); - case 349: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==349); - case 355: /* literal_func ::= NOW */ yytestcase(yyruleno==355); + case 343: /* pseudo_column ::= ROWTS */ + case 344: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==344); + case 346: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==346); + case 347: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==347); + case 348: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==348); + case 349: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==349); + case 350: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==350); + case 356: /* literal_func ::= NOW */ yytestcase(yyruleno==356); { yylhsminor.yy560 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 344: /* pseudo_column ::= table_name NK_DOT TBNAME */ + case 345: /* pseudo_column ::= table_name NK_DOT TBNAME */ { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy533)))); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 350: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 351: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==351); + case 351: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 352: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==352); { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy533, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy533, yymsp[-1].minor.yy712)); } yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 352: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + case 353: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), yymsp[-1].minor.yy196)); } yymsp[-5].minor.yy560 = yylhsminor.yy560; break; - case 354: /* literal_func ::= noarg_func NK_LP NK_RP */ + case 355: /* literal_func ::= noarg_func NK_LP NK_RP */ { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy533, NULL)); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 369: /* star_func_para_list ::= NK_STAR */ + case 370: /* star_func_para_list ::= NK_STAR */ { yylhsminor.yy712 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy712 = yylhsminor.yy712; break; - case 374: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 431: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==431); + case 375: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 432: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==432); { yylhsminor.yy560 = createColumnNode(pCxt, &yymsp[-2].minor.yy533, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 375: /* predicate ::= expression compare_op expression */ - case 380: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==380); + case 376: /* predicate ::= expression compare_op expression */ + case 381: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==381); { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4447,7 +4413,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 376: /* predicate ::= expression BETWEEN expression AND expression */ + case 377: /* predicate ::= expression BETWEEN expression AND expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4455,7 +4421,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-4].minor.yy560 = yylhsminor.yy560; break; - case 377: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 378: /* predicate ::= expression NOT BETWEEN expression AND expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4463,71 +4429,71 @@ static YYACTIONTYPE yy_reduce( } yymsp[-5].minor.yy560 = yylhsminor.yy560; break; - case 378: /* predicate ::= expression IS NULL */ + case 379: /* predicate ::= expression IS NULL */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), NULL)); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 379: /* predicate ::= expression IS NOT NULL */ + case 380: /* predicate ::= expression IS NOT NULL */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy560); yylhsminor.yy560 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), NULL)); } yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 381: /* compare_op ::= NK_LT */ + case 382: /* compare_op ::= NK_LT */ { yymsp[0].minor.yy128 = OP_TYPE_LOWER_THAN; } break; - case 382: /* compare_op ::= NK_GT */ + case 383: /* compare_op ::= NK_GT */ { yymsp[0].minor.yy128 = OP_TYPE_GREATER_THAN; } break; - case 383: /* compare_op ::= NK_LE */ + case 384: /* compare_op ::= NK_LE */ { yymsp[0].minor.yy128 = OP_TYPE_LOWER_EQUAL; } break; - case 384: /* compare_op ::= NK_GE */ + case 385: /* compare_op ::= NK_GE */ { yymsp[0].minor.yy128 = OP_TYPE_GREATER_EQUAL; } break; - case 385: /* compare_op ::= NK_NE */ + case 386: /* compare_op ::= NK_NE */ { yymsp[0].minor.yy128 = OP_TYPE_NOT_EQUAL; } break; - case 386: /* compare_op ::= NK_EQ */ + case 387: /* compare_op ::= NK_EQ */ { yymsp[0].minor.yy128 = OP_TYPE_EQUAL; } break; - case 387: /* compare_op ::= LIKE */ + case 388: /* compare_op ::= LIKE */ { yymsp[0].minor.yy128 = OP_TYPE_LIKE; } break; - case 388: /* compare_op ::= NOT LIKE */ + case 389: /* compare_op ::= NOT LIKE */ { yymsp[-1].minor.yy128 = OP_TYPE_NOT_LIKE; } break; - case 389: /* compare_op ::= MATCH */ + case 390: /* compare_op ::= MATCH */ { yymsp[0].minor.yy128 = OP_TYPE_MATCH; } break; - case 390: /* compare_op ::= NMATCH */ + case 391: /* compare_op ::= NMATCH */ { yymsp[0].minor.yy128 = OP_TYPE_NMATCH; } break; - case 391: /* compare_op ::= CONTAINS */ + case 392: /* compare_op ::= CONTAINS */ { yymsp[0].minor.yy128 = OP_TYPE_JSON_CONTAINS; } break; - case 392: /* in_op ::= IN */ + case 393: /* in_op ::= IN */ { yymsp[0].minor.yy128 = OP_TYPE_IN; } break; - case 393: /* in_op ::= NOT IN */ + case 394: /* in_op ::= NOT IN */ { yymsp[-1].minor.yy128 = OP_TYPE_NOT_IN; } break; - case 394: /* in_predicate_value ::= NK_LP literal_list NK_RP */ + case 395: /* in_predicate_value ::= NK_LP literal_list NK_RP */ { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy712)); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 396: /* boolean_value_expression ::= NOT boolean_primary */ + case 397: /* boolean_value_expression ::= NOT boolean_primary */ { SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy560), NULL)); } yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 397: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 398: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4535,7 +4501,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 398: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 399: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy560); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy560); @@ -4543,47 +4509,47 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 406: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ + case 407: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ { yylhsminor.yy560 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy560, yymsp[0].minor.yy560, NULL); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 409: /* table_primary ::= table_name alias_opt */ + case 410: /* table_primary ::= table_name alias_opt */ { yylhsminor.yy560 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy533, &yymsp[0].minor.yy533); } yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 410: /* table_primary ::= db_name NK_DOT table_name alias_opt */ + case 411: /* table_primary ::= db_name NK_DOT table_name alias_opt */ { yylhsminor.yy560 = createRealTableNode(pCxt, &yymsp[-3].minor.yy533, &yymsp[-1].minor.yy533, &yymsp[0].minor.yy533); } yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 411: /* table_primary ::= subquery alias_opt */ + case 412: /* table_primary ::= subquery alias_opt */ { yylhsminor.yy560 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560), &yymsp[0].minor.yy533); } yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 413: /* alias_opt ::= */ + case 414: /* alias_opt ::= */ { yymsp[1].minor.yy533 = nil_token; } break; - case 414: /* alias_opt ::= table_alias */ + case 415: /* alias_opt ::= table_alias */ { yylhsminor.yy533 = yymsp[0].minor.yy533; } yymsp[0].minor.yy533 = yylhsminor.yy533; break; - case 415: /* alias_opt ::= AS table_alias */ + case 416: /* alias_opt ::= AS table_alias */ { yymsp[-1].minor.yy533 = yymsp[0].minor.yy533; } break; - case 416: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 417: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==417); + case 417: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 418: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==418); { yymsp[-2].minor.yy560 = yymsp[-1].minor.yy560; } break; - case 418: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + case 419: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ { yylhsminor.yy560 = createJoinTableNode(pCxt, yymsp[-4].minor.yy36, yymsp[-5].minor.yy560, yymsp[-2].minor.yy560, yymsp[0].minor.yy560); } yymsp[-5].minor.yy560 = yylhsminor.yy560; break; - case 419: /* join_type ::= */ + case 420: /* join_type ::= */ { yymsp[1].minor.yy36 = JOIN_TYPE_INNER; } break; - case 420: /* join_type ::= INNER */ + case 421: /* join_type ::= INNER */ { yymsp[0].minor.yy36 = JOIN_TYPE_INNER; } break; - case 421: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 422: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { yymsp[-11].minor.yy560 = createSelectStmt(pCxt, yymsp[-10].minor.yy173, yymsp[-9].minor.yy712, yymsp[-8].minor.yy560); yymsp[-11].minor.yy560 = addWhereClause(pCxt, yymsp[-11].minor.yy560, yymsp[-7].minor.yy560); @@ -4596,75 +4562,75 @@ static YYACTIONTYPE yy_reduce( yymsp[-11].minor.yy560 = addFillClause(pCxt, yymsp[-11].minor.yy560, yymsp[-3].minor.yy560); } break; - case 424: /* set_quantifier_opt ::= ALL */ + case 425: /* set_quantifier_opt ::= ALL */ { yymsp[0].minor.yy173 = false; } break; - case 427: /* select_item ::= NK_STAR */ + case 428: /* select_item ::= NK_STAR */ { yylhsminor.yy560 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } yymsp[0].minor.yy560 = yylhsminor.yy560; break; - case 429: /* select_item ::= common_expression column_alias */ + case 430: /* select_item ::= common_expression column_alias */ { yylhsminor.yy560 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560), &yymsp[0].minor.yy533); } yymsp[-1].minor.yy560 = yylhsminor.yy560; break; - case 430: /* select_item ::= common_expression AS column_alias */ + case 431: /* select_item ::= common_expression AS column_alias */ { yylhsminor.yy560 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), &yymsp[0].minor.yy533); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 435: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 452: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==452); - case 468: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==468); + case 436: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 453: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==453); + case 469: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==469); { yymsp[-2].minor.yy712 = yymsp[0].minor.yy712; } break; - case 437: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + case 438: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ { yymsp[-5].minor.yy560 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } break; - case 438: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + case 439: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ { yymsp[-3].minor.yy560 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } break; - case 439: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + case 440: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ { yymsp[-5].minor.yy560 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), NULL, yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 440: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + case 441: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ { yymsp[-7].minor.yy560 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy560), releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), yymsp[-1].minor.yy560, yymsp[0].minor.yy560); } break; - case 442: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - case 460: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==460); + case 443: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + case 461: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==461); { yymsp[-3].minor.yy560 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy560); } break; - case 444: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ + case 445: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ { yymsp[-3].minor.yy560 = createFillNode(pCxt, yymsp[-1].minor.yy18, NULL); } break; - case 445: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + case 446: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ { yymsp[-5].minor.yy560 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy712)); } break; - case 446: /* fill_mode ::= NONE */ + case 447: /* fill_mode ::= NONE */ { yymsp[0].minor.yy18 = FILL_MODE_NONE; } break; - case 447: /* fill_mode ::= PREV */ + case 448: /* fill_mode ::= PREV */ { yymsp[0].minor.yy18 = FILL_MODE_PREV; } break; - case 448: /* fill_mode ::= NULL */ + case 449: /* fill_mode ::= NULL */ { yymsp[0].minor.yy18 = FILL_MODE_NULL; } break; - case 449: /* fill_mode ::= LINEAR */ + case 450: /* fill_mode ::= LINEAR */ { yymsp[0].minor.yy18 = FILL_MODE_LINEAR; } break; - case 450: /* fill_mode ::= NEXT */ + case 451: /* fill_mode ::= NEXT */ { yymsp[0].minor.yy18 = FILL_MODE_NEXT; } break; - case 453: /* group_by_list ::= expression */ + case 454: /* group_by_list ::= expression */ { yylhsminor.yy712 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } yymsp[0].minor.yy712 = yylhsminor.yy712; break; - case 454: /* group_by_list ::= group_by_list NK_COMMA expression */ + case 455: /* group_by_list ::= group_by_list NK_COMMA expression */ { yylhsminor.yy712 = addNodeToList(pCxt, yymsp[-2].minor.yy712, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy560))); } yymsp[-2].minor.yy712 = yylhsminor.yy712; break; - case 458: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ + case 459: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ { yymsp[-5].minor.yy560 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy560), releaseRawExprNode(pCxt, yymsp[-1].minor.yy560)); } break; - case 461: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 462: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { yylhsminor.yy560 = addOrderByClause(pCxt, yymsp[-3].minor.yy560, yymsp[-2].minor.yy712); yylhsminor.yy560 = addSlimitClause(pCxt, yylhsminor.yy560, yymsp[-1].minor.yy560); @@ -4672,57 +4638,57 @@ static YYACTIONTYPE yy_reduce( } yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 463: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + case 464: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ { yylhsminor.yy560 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy560, yymsp[0].minor.yy560); } yymsp[-3].minor.yy560 = yylhsminor.yy560; break; - case 464: /* query_expression_body ::= query_expression_body UNION query_expression_body */ + case 465: /* query_expression_body ::= query_expression_body UNION query_expression_body */ { yylhsminor.yy560 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy560, yymsp[0].minor.yy560); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 466: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ + case 467: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ { yymsp[-5].minor.yy560 = addOrderByClause(pCxt, yymsp[-4].minor.yy560, yymsp[-3].minor.yy712); yymsp[-5].minor.yy560 = addSlimitClause(pCxt, yymsp[-5].minor.yy560, yymsp[-2].minor.yy560); yymsp[-5].minor.yy560 = addLimitClause(pCxt, yymsp[-5].minor.yy560, yymsp[-1].minor.yy560); } break; - case 470: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 474: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==474); + case 471: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 475: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==475); { yymsp[-1].minor.yy560 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 471: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 475: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==475); + case 472: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 476: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==476); { yymsp[-3].minor.yy560 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 472: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 476: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==476); + case 473: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 477: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==477); { yymsp[-3].minor.yy560 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 477: /* subquery ::= NK_LP query_expression NK_RP */ + case 478: /* subquery ::= NK_LP query_expression NK_RP */ { yylhsminor.yy560 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy560); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 481: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + case 482: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ { yylhsminor.yy560 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy560), yymsp[-1].minor.yy218, yymsp[0].minor.yy109); } yymsp[-2].minor.yy560 = yylhsminor.yy560; break; - case 482: /* ordering_specification_opt ::= */ + case 483: /* ordering_specification_opt ::= */ { yymsp[1].minor.yy218 = ORDER_ASC; } break; - case 483: /* ordering_specification_opt ::= ASC */ + case 484: /* ordering_specification_opt ::= ASC */ { yymsp[0].minor.yy218 = ORDER_ASC; } break; - case 484: /* ordering_specification_opt ::= DESC */ + case 485: /* ordering_specification_opt ::= DESC */ { yymsp[0].minor.yy218 = ORDER_DESC; } break; - case 485: /* null_ordering_opt ::= */ + case 486: /* null_ordering_opt ::= */ { yymsp[1].minor.yy109 = NULL_ORDER_DEFAULT; } break; - case 486: /* null_ordering_opt ::= NULLS FIRST */ + case 487: /* null_ordering_opt ::= NULLS FIRST */ { yymsp[-1].minor.yy109 = NULL_ORDER_FIRST; } break; - case 487: /* null_ordering_opt ::= NULLS LAST */ + case 488: /* null_ordering_opt ::= NULLS LAST */ { yymsp[-1].minor.yy109 = NULL_ORDER_LAST; } break; default: diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp index b39a066ba1..e9c8fb5326 100644 --- a/source/libs/parser/test/parInitialCTest.cpp +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -76,8 +76,8 @@ TEST_F(ParserInitialCTest, createDatabase) { expect.db[len] = '\0'; expect.ignoreExist = igExists; expect.buffer = TSDB_DEFAULT_BUFFER_PER_VNODE; - expect.cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; - expect.lastRowMem = TSDB_DEFAULT_LAST_ROW_MEM; + expect.cacheLast = TSDB_DEFAULT_CACHE_LAST; + expect.cacheLastSize = TSDB_DEFAULT_CACHE_LAST_SIZE; expect.compression = TSDB_DEFAULT_COMP_LEVEL; expect.daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; expect.fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; @@ -98,8 +98,8 @@ TEST_F(ParserInitialCTest, createDatabase) { }; auto setDbBufferFunc = [&](int32_t buffer) { expect.buffer = buffer; }; - auto setDbCachelastFunc = [&](int8_t cachelast) { expect.cacheLastRow = cachelast; }; - auto setDbCachelastSize = [&](int8_t cachelastSize) { expect.lastRowMem = cachelastSize; }; + auto setDbCachelastFunc = [&](int8_t cachelast) { expect.cacheLast = cachelast; }; + auto setDbCachelastSize = [&](int8_t cachelastSize) { expect.cacheLastSize = cachelastSize; }; auto setDbCompressionFunc = [&](int8_t compressionLevel) { expect.compression = compressionLevel; }; auto setDbDaysFunc = [&](int32_t daysPerFile) { expect.daysPerFile = daysPerFile; }; auto setDbFsyncFunc = [&](int32_t fsyncPeriod) { expect.fsyncPeriod = fsyncPeriod; }; @@ -155,8 +155,8 @@ TEST_F(ParserInitialCTest, createDatabase) { ASSERT_EQ(req.compression, expect.compression); ASSERT_EQ(req.replications, expect.replications); ASSERT_EQ(req.strict, expect.strict); - ASSERT_EQ(req.cacheLastRow, expect.cacheLastRow); - ASSERT_EQ(req.lastRowMem, expect.lastRowMem); + ASSERT_EQ(req.cacheLast, expect.cacheLast); + ASSERT_EQ(req.cacheLastSize, expect.cacheLastSize); // ASSERT_EQ(req.schemaless, expect.schemaless); ASSERT_EQ(req.ignoreExist, expect.ignoreExist); ASSERT_EQ(req.numOfRetensions, expect.numOfRetensions); diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp index 8ad9feb536..0aa1773c28 100644 --- a/source/libs/parser/test/parSelectTest.cpp +++ b/source/libs/parser/test/parSelectTest.cpp @@ -337,70 +337,69 @@ TEST_F(ParserSelectTest, semanticCheck) { useDb("root", "test"); // TSDB_CODE_PAR_INVALID_COLUMN - run("SELECT c1, cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT c1, cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN); - run("SELECT t1.c1, t1.cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT t1.c1, t1.cc1 FROM t1", TSDB_CODE_PAR_INVALID_COLUMN); // TSDB_CODE_PAR_TABLE_NOT_EXIST - run("SELECT * FROM t10", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + run("SELECT * FROM t10", TSDB_CODE_PAR_TABLE_NOT_EXIST); - run("SELECT * FROM test.t10", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + run("SELECT * FROM test.t10", TSDB_CODE_PAR_TABLE_NOT_EXIST); - run("SELECT t2.c1 FROM t1", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + run("SELECT t2.c1 FROM t1", TSDB_CODE_PAR_TABLE_NOT_EXIST); // TSDB_CODE_PAR_AMBIGUOUS_COLUMN - run("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1", TSDB_CODE_PAR_AMBIGUOUS_COLUMN); - run("SELECT c2 FROM (SELECT c1 c2, c2 FROM t1)", TSDB_CODE_PAR_AMBIGUOUS_COLUMN, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM (SELECT c1 c2, c2 FROM t1)", TSDB_CODE_PAR_AMBIGUOUS_COLUMN); // TSDB_CODE_PAR_WRONG_VALUE_TYPE - run("SELECT timestamp '2010a' FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); + run("SELECT timestamp '2010a' FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE); - run("SELECT LAST(*) + SUM(c1) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); + run("SELECT LAST(*) + SUM(c1) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE); - run("SELECT CEIL(LAST(ts, c1)) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); + run("SELECT CEIL(LAST(ts, c1)) FROM t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE); // TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION - run("SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, - PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); - run("SELECT c2 FROM t1 WHERE COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 WHERE COUNT(*) > 0", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); - run("SELECT c2 FROM t1 GROUP BY COUNT(*)", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 GROUP BY COUNT(*)", TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); // TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT - run("SELECT c2 FROM t1 order by 0", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 order by 0", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT); - run("SELECT c2 FROM t1 order by 2", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, PARSER_STAGE_TRANSLATE); + run("SELECT c2 FROM t1 order by 2", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT); // TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION - run("SELECT COUNT(*) cnt FROM t1 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) cnt FROM t1 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); - run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c1 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); - run("SELECT COUNT(*), c1 cnt FROM t1 GROUP BY c2 having c2 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*), c1 cnt FROM t1 GROUP BY c2 having c2 > 0", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); - run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c2 > 0 order by c1", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c2 > 0 order by c1", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION); // TSDB_CODE_PAR_NOT_SINGLE_GROUP - run("SELECT COUNT(*), c1 FROM t1", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*), c1 FROM t1", TSDB_CODE_PAR_NOT_SINGLE_GROUP); - run("SELECT COUNT(*) FROM t1 order by c1", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + run("SELECT COUNT(*) FROM t1 order by c1", TSDB_CODE_PAR_NOT_SINGLE_GROUP); - run("SELECT c1 FROM t1 order by COUNT(*)", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + run("SELECT c1 FROM t1 order by COUNT(*)", TSDB_CODE_PAR_NOT_SINGLE_GROUP); // TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION - run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION); - run("SELECT distinct c1 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT distinct c1 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION); - run("SELECT distinct c2 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION, - PARSER_STAGE_TRANSLATE); + run("SELECT distinct c2 FROM t1 WHERE c1 > 0 order by COUNT(c2)", TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION); +} + +TEST_F(ParserSelectTest, syntaxError) { + useDb("root", "test"); + + run("SELECT CAST(? AS BINARY(10)) FROM t1", TSDB_CODE_PAR_SYNTAX_ERROR, PARSER_STAGE_PARSE); } TEST_F(ParserSelectTest, setOperator) { diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index c29a03f617..4d4756c3ac 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -475,12 +475,12 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, int32_t code = TSDB_CODE_SUCCESS; // set grouyp keys, agg funcs and having conditions - if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) { + if (TSDB_CODE_SUCCESS == code) { code = nodesCollectFuncs(pSelect, SQL_CLAUSE_GROUP_BY, fmIsAggFunc, &pAgg->pAggFuncs); } // rewrite the expression in subsequent clauses - if (TSDB_CODE_SUCCESS == code) { + if (TSDB_CODE_SUCCESS == code && NULL != pAgg->pAggFuncs) { code = rewriteExprsForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY); } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 45f947e128..ad75720892 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -80,6 +80,23 @@ static void optResetParent(SLogicNode* pNode) { FOREACH(pChild, pNode->pChildren) { ((SLogicNode*)pChild)->pParent = pNode; } } +static EDealRes optRebuildTbanme(SNode** pNode, void* pContext) { + if (QUERY_NODE_COLUMN == nodeType(*pNode) && COLUMN_TYPE_TBNAME == ((SColumnNode*)*pNode)->colType) { + SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pFunc) { + *(int32_t*)pContext = TSDB_CODE_OUT_OF_MEMORY; + return DEAL_RES_ERROR; + } + strcpy(pFunc->functionName, "tbname"); + pFunc->funcType = FUNCTION_TYPE_TBNAME; + pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType; + nodesDestroyNode(*pNode); + *pNode = (SNode*)pFunc; + return DEAL_RES_IGNORE_CHILD; + } + return DEAL_RES_CONTINUE; +} + EDealRes scanPathOptHaveNormalColImpl(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode)) { // *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType); @@ -315,6 +332,12 @@ static int32_t pushDownCondOptCalcTimeRange(SOptimizeContext* pCxt, SScanLogicNo return code; } +static int32_t pushDownCondOptRebuildTbanme(SNode** pTagCond) { + int32_t code = TSDB_CODE_SUCCESS; + nodesRewriteExpr(pTagCond, optRebuildTbanme, &code); + return code; +} + static int32_t pushDownCondOptDealScan(SOptimizeContext* pCxt, SScanLogicNode* pScan) { if (NULL == pScan->node.pConditions || OPTIMIZE_FLAG_TEST_MASK(pScan->node.optimizedFlag, OPTIMIZE_FLAG_PUSH_DOWN_CONDE) || @@ -326,6 +349,9 @@ static int32_t pushDownCondOptDealScan(SOptimizeContext* pCxt, SScanLogicNode* p SNode* pOtherCond = NULL; int32_t code = nodesPartitionCond(&pScan->node.pConditions, &pPrimaryKeyCond, &pScan->pTagIndexCond, &pScan->pTagCond, &pOtherCond); + if (TSDB_CODE_SUCCESS == code && NULL != pScan->pTagCond) { + code = pushDownCondOptRebuildTbanme(&pScan->pTagCond); + } if (TSDB_CODE_SUCCESS == code && NULL != pPrimaryKeyCond) { code = pushDownCondOptCalcTimeRange(pCxt, pScan, &pPrimaryKeyCond, &pOtherCond); } @@ -1389,26 +1415,9 @@ static bool partTagsOptMayBeOptimized(SLogicNode* pNode) { return !planOptNodeListHasCol(partTagsGetPartKeys(pNode)) && partTagsOptAreSupportedFuncs(partTagsGetFuncs(pNode)); } -static EDealRes partTagsOptRebuildTbanmeImpl(SNode** pNode, void* pContext) { - if (QUERY_NODE_COLUMN == nodeType(*pNode) && COLUMN_TYPE_TBNAME == ((SColumnNode*)*pNode)->colType) { - SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); - if (NULL == pFunc) { - *(int32_t*)pContext = TSDB_CODE_OUT_OF_MEMORY; - return DEAL_RES_ERROR; - } - strcpy(pFunc->functionName, "tbname"); - pFunc->funcType = FUNCTION_TYPE_TBNAME; - pFunc->node.resType = ((SColumnNode*)*pNode)->node.resType; - nodesDestroyNode(*pNode); - *pNode = (SNode*)pFunc; - return DEAL_RES_IGNORE_CHILD; - } - return DEAL_RES_CONTINUE; -} - static int32_t partTagsOptRebuildTbanme(SNodeList* pPartKeys) { int32_t code = TSDB_CODE_SUCCESS; - nodesRewriteExprs(pPartKeys, partTagsOptRebuildTbanmeImpl, &code); + nodesRewriteExprs(pPartKeys, optRebuildTbanme, &code); return code; } @@ -1980,7 +1989,8 @@ static bool lastRowScanOptMayBeOptimized(SLogicNode* pNode) { SNode* pFunc = NULL; FOREACH(pFunc, ((SAggLogicNode*)pNode)->pAggFuncs) { - if (FUNCTION_TYPE_LAST_ROW != ((SFunctionNode*)pFunc)->funcType) { + if (FUNCTION_TYPE_LAST_ROW != ((SFunctionNode*)pFunc)->funcType && + FUNCTION_TYPE_SELECT_VALUE != ((SFunctionNode*)pFunc)->funcType) { return false; } } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index d10fe1ce0c..8c9c06be35 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1519,6 +1519,7 @@ static SSubplan* makeSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubpl static int32_t buildInsertValuesSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { pSubplan->msgType = pModify->msgType; + pSubplan->execNode.nodeId = pModify->pVgDataBlocks->vg.vgId; pSubplan->execNode.epSet = pModify->pVgDataBlocks->vg.epSet; return createDataInserter(pCxt, pModify->pVgDataBlocks, &pSubplan->pDataSink); } diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index d7eccf4b8e..987da0dd17 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -877,7 +877,7 @@ static int32_t stbSplSplitSortNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) return code; } -static int32_t stbSplSplitScanNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) { +static int32_t stbSplSplitScanNodeWithoutPartTags(SSplitContext* pCxt, SStableSplitInfo* pInfo) { int32_t code = splCreateExchangeNodeForSubplan(pCxt, pInfo->pSubplan, pInfo->pSplitNode, SUBPLAN_TYPE_MERGE); if (TSDB_CODE_SUCCESS == code) { code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren, @@ -887,6 +887,25 @@ static int32_t stbSplSplitScanNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) return code; } +static int32_t stbSplSplitScanNodeWithPartTags(SSplitContext* pCxt, SStableSplitInfo* pInfo) { + int32_t code = stbSplCreateMergeNode(pCxt, pInfo->pSubplan, pInfo->pSplitNode, NULL, pInfo->pSplitNode, true); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren, + (SNode*)splCreateScanSubplan(pCxt, pInfo->pSplitNode, SPLIT_FLAG_STABLE_SPLIT)); + } + pInfo->pSubplan->subplanType = SUBPLAN_TYPE_MERGE; + ++(pCxt->groupId); + return code; +} + +static int32_t stbSplSplitScanNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) { + SScanLogicNode* pScan = (SScanLogicNode*)pInfo->pSplitNode; + if (NULL != pScan->pGroupTags) { + return stbSplSplitScanNodeWithPartTags(pCxt, pInfo); + } + return stbSplSplitScanNodeWithoutPartTags(pCxt, pInfo); +} + static SNode* stbSplFindPrimaryKeyFromScan(SScanLogicNode* pScan) { SNode* pCol = NULL; FOREACH(pCol, pScan->pScanCols) { diff --git a/source/libs/planner/test/planOptimizeTest.cpp b/source/libs/planner/test/planOptimizeTest.cpp index 615a41d15d..316148df27 100644 --- a/source/libs/planner/test/planOptimizeTest.cpp +++ b/source/libs/planner/test/planOptimizeTest.cpp @@ -37,6 +37,8 @@ TEST_F(PlanOptimizeTest, pushDownCondition) { run("SELECT ts, c1 FROM st1 WHERE tag1 > 4"); + run("SELECT ts, c1 FROM st1 WHERE TBNAME = 'st1s1'"); + run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 or tag1 < 2"); run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello'"); diff --git a/source/libs/planner/test/planPartByTest.cpp b/source/libs/planner/test/planPartByTest.cpp index 48a4c12577..f1dd9403dd 100644 --- a/source/libs/planner/test/planPartByTest.cpp +++ b/source/libs/planner/test/planPartByTest.cpp @@ -59,4 +59,6 @@ TEST_F(PlanPartitionByTest, withGroupBy) { useDb("root", "test"); run("select count(*) from t1 partition by c1 group by c2"); + + run("SELECT TBNAME, c1 FROM st1 PARTITION BY TBNAME GROUP BY c1"); } diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index 4780249ec9..0f90b54adb 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -330,6 +330,10 @@ class PlannerTestBaseImpl { cxt.pMsg = stmtEnv_.msgBuf_.data(); cxt.msgLen = stmtEnv_.msgBuf_.max_size(); cxt.svrVer = "3.0.0.0"; + if (prepare) { + SStmtCallback stmtCb = {0}; + cxt.pStmtCb = &stmtCb; + } DO_WITH_THROW(qParseSql, &cxt, pQuery); if (prepare) { diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index b4e217ef74..eeb44c4f82 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -282,7 +282,7 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t } *str = '"'; - int32_t length = taosUcs4ToMbs((TdUcs4 *)buf, bufSize, str + 1); + int32_t length = taosUcs4ToMbs((TdUcs4*)buf, bufSize, str + 1); if (length <= 0) { return TSDB_CODE_TSC_INVALID_VALUE; } @@ -310,15 +310,15 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t return TSDB_CODE_TSC_INVALID_VALUE; } - if(len) *len = n; + if (len) *len = n; return TSDB_CODE_SUCCESS; } char* parseTagDatatoJson(void* p) { - char* string = NULL; + char* string = NULL; SArray* pTagVals = NULL; - cJSON* json = NULL; + cJSON* json = NULL; if (tTagToValArray((const STag*)p, &pTagVals) != 0) { goto end; } @@ -327,7 +327,7 @@ char* parseTagDatatoJson(void* p) { if (nCols == 0) { goto end; } - char tagJsonKey[256] = {0}; + char tagJsonKey[256] = {0}; json = cJSON_CreateObject(); if (json == NULL) { goto end; @@ -390,7 +390,7 @@ char* parseTagDatatoJson(void* p) { end: cJSON_Delete(json); taosArrayDestroy(pTagVals); - if(string == NULL){ + if (string == NULL) { string = strdup(TSDB_DATA_NULL_STR_L); } return string; diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 42121e8813..0348f13191 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3623,7 +3623,8 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && node->opType >= OP_TYPE_NOT_EQUAL) { + if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && + (node->opType >= OP_TYPE_NOT_EQUAL) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index dd55894266..e610fcb62e 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -729,6 +729,7 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { if (colDataIsNull_s(output.columnData, 0)) { res->node.resType.type = TSDB_DATA_TYPE_NULL; + res->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes; } else { res->node.resType.type = output.columnData->info.type; res->node.resType.bytes = output.columnData->info.bytes; @@ -819,6 +820,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { if (colDataIsNull_s(output.columnData, 0)) { if(node->node.resType.type != TSDB_DATA_TYPE_JSON){ res->node.resType.type = TSDB_DATA_TYPE_NULL; + res->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes; }else{ res->node.resType = node->node.resType; res->isNull = true; diff --git a/source/libs/scheduler/inc/schInt.h b/source/libs/scheduler/inc/schInt.h index 052fdefa61..0a0d319025 100644 --- a/source/libs/scheduler/inc/schInt.h +++ b/source/libs/scheduler/inc/schInt.h @@ -54,6 +54,11 @@ typedef enum { SCH_OP_GET_STATUS, } SCH_OP_TYPE; +typedef struct SSchDebug { + bool lockEnable; + bool apiEnable; +} SSchDebug; + typedef struct SSchTrans { void *pTrans; void *pHandle; @@ -186,7 +191,7 @@ typedef struct SSchTaskProfile { typedef struct SSchTask { uint64_t taskId; // task id - SRWLatch lock; // task lock + SRWLatch lock; // task reentrant lock int32_t maxExecTimes; // task may exec times int32_t execId; // task current execute try index SSchLevel *level; // level @@ -356,8 +361,41 @@ extern SSchedulerMgmt schMgmt; #define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); } return _code; } while (0) #define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(code); goto _return; } } while (0) -#define SCH_LOCK(type, _lock) (SCH_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock)) -#define SCH_UNLOCK(type, _lock) (SCH_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock)) +#define SCH_LOCK_DEBUG(...) do { if (gSCHDebug.lockEnable) { qDebug(__VA_ARGS__); } } while (0) + +#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000 + +#define SCH_LOCK(type, _lock) do { \ + if (SCH_READ == (type)) { \ + assert(atomic_load_32(_lock) >= 0); \ + SCH_LOCK_DEBUG("SCH RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosRLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32(_lock) > 0); \ + } else { \ + assert(atomic_load_32(_lock) >= 0); \ + SCH_LOCK_DEBUG("SCH WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosWLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32(_lock) == TD_RWLATCH_WRITE_FLAG_COPY); \ + } \ +} while (0) + +#define SCH_UNLOCK(type, _lock) do { \ + if (SCH_READ == (type)) { \ + assert(atomic_load_32((_lock)) > 0); \ + SCH_LOCK_DEBUG("SCH RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosRUnLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ + } else { \ + assert(atomic_load_32((_lock)) & TD_RWLATCH_WRITE_FLAG_COPY); \ + SCH_LOCK_DEBUG("SCH WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + taosWUnLockLatch(_lock); \ + SCH_LOCK_DEBUG("SCH WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \ + assert(atomic_load_32((_lock)) >= 0); \ + } \ +} while (0) void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask); @@ -434,6 +472,9 @@ int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level); int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask); int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel, int32_t levelNum); int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask); +void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode); + +extern SSchDebug gSCHDebug; #ifdef __cplusplus diff --git a/source/libs/scheduler/src/schDbg.c b/source/libs/scheduler/src/schDbg.c index 7f013b8f32..a6398522d3 100644 --- a/source/libs/scheduler/src/schDbg.c +++ b/source/libs/scheduler/src/schDbg.c @@ -17,6 +17,7 @@ #include "schInt.h" tsem_t schdRspSem; +SSchDebug gSCHDebug = {0}; void schdExecCallback(SExecResult* pResult, void* param, int32_t code) { if (code) { diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index d2f9624eee..e482814ee7 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -337,14 +337,14 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { SCH_SET_JOB_TYPE(pJob, plan->subplanType); SSchTask task = {0}; - SCH_ERR_JRET(schInitTask(pJob, &task, plan, pLevel, levelNum)); - SSchTask *pTask = taosArrayPush(pLevel->subTasks, &task); if (NULL == pTask) { SCH_TASK_ELOG("taosArrayPush task to level failed, level:%d, taskIdx:%d", pLevel->level, n); SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_ERR_JRET(schInitTask(pJob, pTask, plan, pLevel, levelNum)); + SCH_ERR_JRET(schAppendJobDataSrc(pJob, pTask)); if (0 != taosHashPut(planToTask, &plan, POINTER_BYTES, &pTask, POINTER_BYTES)) { @@ -543,9 +543,12 @@ int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask) { int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { if (rsp->tbFName[0]) { + SCH_LOCK(SCH_WRITE, &pJob->resLock); + if (NULL == pJob->execRes.res) { pJob->execRes.res = taosArrayInit(pJob->taskNum, sizeof(STbVerInfo)); if (NULL == pJob->execRes.res) { + SCH_UNLOCK(SCH_WRITE, &pJob->resLock); SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } @@ -557,6 +560,8 @@ int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { taosArrayPush((SArray *)pJob->execRes.res, &tbInfo); pJob->execRes.msgType = TDMT_SCH_QUERY; + + SCH_UNLOCK(SCH_WRITE, &pJob->resLock); } return TSDB_CODE_SUCCESS; @@ -758,6 +763,17 @@ int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq) { return TSDB_CODE_SUCCESS; } +void schDirectPostJobRes(SSchedulerReq* pReq, int32_t errCode) { + if (NULL == pReq || pReq->syncReq) { + return; + } + + if (pReq->execFp) { + (*pReq->execFp)(NULL, pReq->cbParam, errCode); + } else if (pReq->fetchFp) { + (*pReq->fetchFp)(NULL, pReq->cbParam, errCode); + } +} void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode) { int32_t op = 0; @@ -796,17 +812,13 @@ void schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq) { int32_t code = 0; - int8_t status = 0; - - if (schJobNeedToStop(pJob, &status)) { - SCH_JOB_ELOG("abort op %s cause of job need to stop, status:%s", schGetOpStr(type), jobTaskStatusStr(status)); - SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); - } + int8_t status = SCH_GET_JOB_STATUS(pJob); switch (type) { case SCH_OP_EXEC: if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) { SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op)); + schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR); SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } @@ -817,11 +829,16 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq case SCH_OP_FETCH: if (SCH_OP_NULL != atomic_val_compare_exchange_32(&pJob->opStatus.op, SCH_OP_NULL, type)) { SCH_JOB_ELOG("job already in %s operation", schGetOpStr(pJob->opStatus.op)); + schDirectPostJobRes(pReq, TSDB_CODE_TSC_APP_ERROR); SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } SCH_JOB_DLOG("job start %s operation", schGetOpStr(pJob->opStatus.op)); - + + pJob->userRes.fetchRes = pReq->pFetchRes; + pJob->userRes.fetchFp = pReq->fetchFp; + pJob->userRes.cbParam = pReq->cbParam; + pJob->opStatus.syncReq = pReq->syncReq; if (!SCH_JOB_NEED_FETCH(pJob)) { @@ -834,10 +851,6 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); } - pJob->userRes.fetchRes = pReq->pFetchRes; - pJob->userRes.fetchFp = pReq->fetchFp; - pJob->userRes.cbParam = pReq->cbParam; - break; case SCH_OP_GET_STATUS: if (pJob->status < JOB_TASK_STATUS_INIT || pJob->levelNum <= 0 || NULL == pJob->levels) { @@ -850,6 +863,11 @@ int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq SCH_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } + if (schJobNeedToStop(pJob, &status)) { + SCH_JOB_ELOG("abort op %s cause of job need to stop, status:%s", schGetOpStr(type), jobTaskStatusStr(status)); + SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); + } + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 2257ba8328..1b893739bd 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -35,7 +35,7 @@ int32_t schValidateRspMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgType) { SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), TMSG_INFO(msgType)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); - } + } if (taskStatus != JOB_TASK_STATUS_PART_SUCC) { SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType)); @@ -75,7 +75,7 @@ int32_t schValidateRspMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgType) { // Note: no more task error processing, handled in function internal int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; - char *msg = pMsg->pData; + char *msg = pMsg->pData; int32_t msgSize = pMsg->len; int32_t msgType = pMsg->msgType; @@ -253,15 +253,15 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa rsp->sversion = ntohl(rsp->sversion); rsp->tversion = ntohl(rsp->tversion); rsp->affectedRows = be64toh(rsp->affectedRows); - + SCH_ERR_JRET(rsp->code); SCH_ERR_JRET(schSaveJobQueryRes(pJob, rsp)); atomic_add_fetch_32(&pJob->resNumOfRows, rsp->affectedRows); - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; @@ -375,7 +375,8 @@ int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { SSchTask *pTask = NULL; SSchJob *pJob = NULL; - qDebug("begin to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, tstrerror(rspCode)); + qDebug("begin to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, + tstrerror(rspCode)); SCH_ERR_RET(schProcessOnCbBegin(&pJob, &pTask, pParam->queryId, pParam->refId, pParam->taskId)); @@ -387,7 +388,8 @@ int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { taosMemoryFreeClear(pMsg->pData); taosMemoryFreeClear(param); - qDebug("end to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, tstrerror(rspCode)); + qDebug("end to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, + tstrerror(rspCode)); SCH_RET(code); } @@ -424,7 +426,7 @@ int32_t schHandleCommitCallback(void *param, SDataBuf *pMsg, int32_t code) { } int32_t schHandleHbCallback(void *param, SDataBuf *pMsg, int32_t code) { - SSchedulerHbRsp rsp = {0}; + SSchedulerHbRsp rsp = {0}; SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; if (code) { @@ -453,8 +455,8 @@ _return: SCH_RET(code); } - -int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bool isHb, SSchTrans *trans, void **pParam) { +int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bool isHb, SSchTrans *trans, + void **pParam) { if (!isHb) { SSchTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam)); if (NULL == param) { @@ -940,7 +942,8 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, if (NULL == addr) { addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); isCandidateAddr = true; - SCH_TASK_DLOG("target candidateIdx %d", pTask->candidateIdx); + SCH_TASK_DLOG("target candidateIdx %d, epInUse %d/%d", pTask->candidateIdx, addr->epSet.inUse, + addr->epSet.numOfEps); } switch (msgType) { diff --git a/source/libs/scheduler/src/schStatus.c b/source/libs/scheduler/src/schStatus.c index 091b1359e0..a4fa4f2839 100644 --- a/source/libs/scheduler/src/schStatus.c +++ b/source/libs/scheduler/src/schStatus.c @@ -77,6 +77,7 @@ int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq int32_t code = errCode; if (NULL == pJob) { + schDirectPostJobRes(pReq, errCode); SCH_RET(code); } diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index e1e4ed8769..71d123b799 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -21,11 +21,9 @@ #include "tref.h" #include "trpc.h" - - void schFreeTask(SSchJob *pJob, SSchTask *pTask) { schDeregisterTaskHb(pJob, pTask); - + if (pTask->candidateAddrs) { taosArrayDestroy(pTask->candidateAddrs); } @@ -43,19 +41,21 @@ void schFreeTask(SSchJob *pJob, SSchTask *pTask) { if (pTask->execNodes) { taosHashCleanup(pTask->execNodes); } -} + taosMemoryFree(pTask->profile.execTime); +} int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel, int32_t levelNum) { int32_t code = 0; - + pTask->plan = pPlan; pTask->level = pLevel; pTask->execId = -1; pTask->maxExecTimes = SCH_TASK_MAX_EXEC_TIMES(pLevel->level, levelNum); pTask->timeoutUsec = SCH_DEFAULT_TASK_TIMEOUT_USEC; pTask->taskId = schGenTaskId(); - pTask->execNodes = taosHashInit(SCH_MAX_CANDIDATE_EP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + pTask->execNodes = + taosHashInit(SCH_MAX_CANDIDATE_EP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); pTask->profile.execTime = taosMemoryCalloc(pTask->maxExecTimes, sizeof(int64_t)); if (NULL == pTask->execNodes || NULL == pTask->profile.execTime) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -109,8 +109,8 @@ int32_t schDropTaskExecNode(SSchJob *pJob, SSchTask *pTask, void *handle, int32_ } else { SCH_TASK_DLOG("execId %d removed from execNodeList", execId); } - - if (execId != pTask->execId) { // ignore it + + if (execId != pTask->execId) { // ignore it SCH_TASK_DLOG("execId %d is not current execId %d", execId, pTask->execId); SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); } @@ -148,13 +148,13 @@ int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode) if (TSDB_CODE_SCH_IGNORE_ERROR == errCode) { return TSDB_CODE_SCH_IGNORE_ERROR; } - + int8_t status = 0; if (schJobNeedToStop(pJob, &status)) { SCH_TASK_DLOG("no more task failure processing cause of job status %s", jobTaskStatusStr(status)); SCH_ERR_RET(TSDB_CODE_SCH_IGNORE_ERROR); } - + if (SCH_GET_TASK_STATUS(pTask) != JOB_TASK_STATUS_EXEC) { SCH_TASK_ELOG("task already not in EXEC status, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR); @@ -203,8 +203,6 @@ int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode) SCH_RET(errCode); } - - // Note: no more task error processing, handled in function internal int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { bool moved = false; @@ -263,16 +261,17 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { SSchTask *parent = *(SSchTask **)taosArrayGet(pTask->parents, i); int32_t readyNum = atomic_add_fetch_32(&parent->childReady, 1); - SCH_LOCK(SCH_WRITE, &parent->lock); - SDownstreamSourceNode source = {.type = QUERY_NODE_DOWNSTREAM_SOURCE, - .taskId = pTask->taskId, - .schedId = schMgmt.sId, - .execId = pTask->execId, - .addr = pTask->succeedAddr, - .fetchMsgType = SCH_FETCH_TYPE(pTask), - }; + SCH_LOCK(SCH_WRITE, &parent->planLock); + SDownstreamSourceNode source = { + .type = QUERY_NODE_DOWNSTREAM_SOURCE, + .taskId = pTask->taskId, + .schedId = schMgmt.sId, + .execId = pTask->execId, + .addr = pTask->succeedAddr, + .fetchMsgType = SCH_FETCH_TYPE(pTask), + }; qSetSubplanExecutionNode(parent->plan, pTask->plan->id.groupId, &source); - SCH_UNLOCK(SCH_WRITE, &parent->lock); + SCH_UNLOCK(SCH_WRITE, &parent->planLock); if (SCH_TASK_READY_FOR_LAUNCH(readyNum, parent)) { SCH_TASK_DLOG("all %d children task done, start to launch parent task 0x%" PRIx64, readyNum, parent->taskId); @@ -290,29 +289,29 @@ int32_t schRescheduleTask(SSchJob *pJob, SSchTask *pTask) { return TSDB_CODE_SUCCESS; } - if (SCH_TASK_TIMEOUT(pTask) && JOB_TASK_STATUS_EXEC == pTask->status && - pJob->fetchTask != pTask && taosArrayGetSize(pTask->candidateAddrs) > 1) { + if (SCH_TASK_TIMEOUT(pTask) && JOB_TASK_STATUS_EXEC == pTask->status && pJob->fetchTask != pTask && + taosArrayGetSize(pTask->candidateAddrs) > 1) { SCH_TASK_DLOG("task execId %d will be rescheduled now", pTask->execId); schDropTaskOnExecNode(pJob, pTask); taosHashClear(pTask->execNodes); - + SCH_ERR_RET(schProcessOnTaskFailure(pJob, pTask, TSDB_CODE_SCH_TIMEOUT_ERROR)); } return TSDB_CODE_SUCCESS; } -int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) { +int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32_t rspCode) { int32_t code = 0; - + if ((pTask->execId + 1) >= pTask->maxExecTimes) { SCH_TASK_DLOG("task no more retry since reach max try times, execId:%d", pTask->execId); - schSwitchJobStatus(pJob, JOB_TASK_STATUS_FAIL, (void*)&rspCode); + schSwitchJobStatus(pJob, JOB_TASK_STATUS_FAIL, (void *)&rspCode); return TSDB_CODE_SUCCESS; } SCH_TASK_DLOG("task will be redirected now, status:%s", SCH_GET_TASK_STATUS_STR(pTask)); - + schDropTaskOnExecNode(pJob, pTask); taosHashClear(pTask->execNodes); SCH_ERR_JRET(schRemoveTaskFromExecList(pJob, pTask)); @@ -327,25 +326,24 @@ int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32 if (pData) { SCH_ERR_JRET(schUpdateTaskCandidateAddr(pJob, pTask, pData->pEpSet)); } - + if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { if (JOB_TASK_STATUS_EXEC == SCH_GET_TASK_STATUS(pTask)) { SCH_ERR_JRET(schLaunchTasksInFlowCtrlList(pJob, pTask)); } - } + } SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); - + SCH_ERR_JRET(schLaunchTask(pJob, pTask)); return TSDB_CODE_SUCCESS; } - // merge plan - + pTask->childReady = 0; - + qClearSubplanExecutionNode(pTask->plan); // Note: current error task and upper level merge task @@ -354,10 +352,10 @@ int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32 } SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); - + int32_t childrenNum = taosArrayGetSize(pTask->children); for (int32_t i = 0; i < childrenNum; ++i) { - SSchTask* pChild = taosArrayGetP(pTask->children, i); + SSchTask *pChild = taosArrayGetP(pTask->children, i); SCH_LOCK_TASK(pChild); schDoTaskRedirect(pJob, pChild, NULL, rspCode); SCH_UNLOCK_TASK(pChild); @@ -370,7 +368,7 @@ _return: SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); } -int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode) { +int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32_t rspCode) { int32_t code = 0; if (SCH_IS_DATA_BIND_TASK(pTask)) { @@ -536,7 +534,7 @@ int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(schRemoveTaskFromExecList(pJob, pTask)); SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); - + if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) { SCH_ERR_RET(schLaunchTasksInFlowCtrlList(pJob, pTask)); } @@ -544,7 +542,8 @@ int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) { schDeregisterTaskHb(pJob, pTask); if (SCH_IS_DATA_BIND_TASK(pTask)) { - SCH_SWITCH_EPSET(&pTask->plan->execNode); + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); + SCH_SWITCH_EPSET(addr); } else { SCH_ERR_RET(schSwitchTaskCandidateAddr(pJob, pTask)); } @@ -557,20 +556,21 @@ int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) { int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { int32_t addNum = 0; int32_t nodeNum = 0; - + if (pJob->nodeList) { nodeNum = taosArrayGetSize(pJob->nodeList); for (int32_t i = 0; i < nodeNum && addNum < SCH_MAX_CANDIDATE_EP_NUM; ++i) { SQueryNodeLoad *nload = taosArrayGet(pJob->nodeList, i); SQueryNodeAddr *naddr = &nload->addr; - + if (NULL == taosArrayPush(pTask->candidateAddrs, naddr)) { SCH_TASK_ELOG("taosArrayPush execNode to candidate addrs failed, addNum:%d, errno:%d", addNum, errno); SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - SCH_TASK_DLOG("set %dth candidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, SCH_GET_CUR_EP(naddr)->port); + SCH_TASK_DLOG("set %dth candidate addr, id %d, fqdn:%s, port:%d", i, naddr->nodeId, SCH_GET_CUR_EP(naddr)->fqdn, + SCH_GET_CUR_EP(naddr)->port); ++addNum; } @@ -584,7 +584,6 @@ int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { return TSDB_CODE_SUCCESS; } - int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) { if (NULL != pTask->candidateAddrs) { return TSDB_CODE_SUCCESS; @@ -627,16 +626,17 @@ int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) { return TSDB_CODE_SUCCESS; } -int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSet) { +int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet *pEpSet) { if (NULL == pTask->candidateAddrs || 1 != taosArrayGetSize(pTask->candidateAddrs)) { - SCH_TASK_ELOG("not able to update cndidate addr, addr num %d", (int32_t)(pTask->candidateAddrs ? taosArrayGetSize(pTask->candidateAddrs): 0)); + SCH_TASK_ELOG("not able to update cndidate addr, addr num %d", + (int32_t)(pTask->candidateAddrs ? taosArrayGetSize(pTask->candidateAddrs) : 0)); SCH_ERR_RET(TSDB_CODE_APP_ERROR); } - SQueryNodeAddr* pAddr = taosArrayGet(pTask->candidateAddrs, 0); + SQueryNodeAddr *pAddr = taosArrayGet(pTask->candidateAddrs, 0); - SEp* pOld = &pAddr->epSet.eps[pAddr->epSet.inUse]; - SEp* pNew = &pEpSet->eps[pEpSet->inUse]; + SEp *pOld = &pAddr->epSet.eps[pAddr->epSet.inUse]; + SEp *pNew = &pEpSet->eps[pEpSet->inUse]; SCH_TASK_DLOG("update task ep from %s:%d to %s:%d", pOld->fqdn, pOld->port, pNew->fqdn, pNew->port); @@ -646,7 +646,7 @@ int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSe } int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask) { - int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); + int32_t candidateNum = taosArrayGetSize(pTask->candidateAddrs); if (++pTask->candidateIdx >= candidateNum) { pTask->candidateIdx = 0; } @@ -654,8 +654,6 @@ int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask) { return TSDB_CODE_SUCCESS; } - - int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask) { int32_t code = taosHashRemove(pJob->execTasks, &pTask->taskId, sizeof(pTask->taskId)); if (code) { @@ -691,33 +689,32 @@ void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask) { SCH_TASK_DLOG("task has been dropped on %d exec nodes", size); } - - -int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList) { - int32_t taskNum = (int32_t)taosArrayGetSize(pStatusList); +int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId *pEpId, SArray *pStatusList) { + int32_t taskNum = (int32_t)taosArrayGetSize(pStatusList); SSchTask *pTask = NULL; - SSchJob *pJob = NULL; + SSchJob *pJob = NULL; - qDebug("%d task status in hb rsp from nodeId:%d, fqdn:%s, port:%d", taskNum, pEpId->nodeId, pEpId->ep.fqdn, pEpId->ep.port); + qDebug("%d task status in hb rsp from nodeId:%d, fqdn:%s, port:%d", taskNum, pEpId->nodeId, pEpId->ep.fqdn, + pEpId->ep.port); for (int32_t i = 0; i < taskNum; ++i) { STaskStatus *pStatus = taosArrayGet(pStatusList, i); - int32_t code = 0; - - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s", - pStatus->queryId, pStatus->taskId, pStatus->execId, jobTaskStatusStr(pStatus->status)); + int32_t code = 0; + + qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s", pStatus->queryId, pStatus->taskId, + pStatus->execId, jobTaskStatusStr(pStatus->status)); if (schProcessOnCbBegin(&pJob, &pTask, pStatus->queryId, pStatus->refId, pStatus->taskId)) { continue; } if (pStatus->execId != pTask->execId) { - //TODO + // TODO SCH_TASK_DLOG("execId %d mis-match current execId %d", pStatus->execId, pTask->execId); schProcessOnCbEnd(pJob, pTask, 0); continue; } - + if (pStatus->status == JOB_TASK_STATUS_FAIL) { // RECORD AND HANDLE ERROR!!!! schProcessOnCbEnd(pJob, pTask, 0); @@ -831,7 +828,6 @@ void schDropTaskInHashList(SSchJob *pJob, SHashObj *list) { } } - // Note: no more error processing, handled in function internal int32_t schLaunchFetchTask(SSchJob *pJob) { int32_t code = 0; @@ -850,5 +846,3 @@ _return: SCH_RET(schProcessOnTaskFailure(pJob, pJob->fetchTask, code)); } - - diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c index 8b8badd67a..becfac0cac 100644 --- a/source/libs/stream/src/stream.c +++ b/source/libs/stream/src/stream.c @@ -173,7 +173,8 @@ int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq, } int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { - qInfo("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId, pReq->upstreamTaskId); + qDebug("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId, + pReq->upstreamTaskId); // 1. handle input streamTaskEnqueue(pTask, pReq, pRsp); @@ -208,7 +209,7 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, S int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp) { ASSERT(pRsp->inputStatus == TASK_OUTPUT_STATUS__NORMAL || pRsp->inputStatus == TASK_OUTPUT_STATUS__BLOCKED); - qInfo("task %d receive dispatch rsp", pTask->taskId); + qDebug("task %d receive dispatch rsp", pTask->taskId); int8_t old = atomic_exchange_8(&pTask->outputStatus, pRsp->inputStatus); ASSERT(old == TASK_OUTPUT_STATUS__WAIT); @@ -242,7 +243,7 @@ int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) } int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq, SRpcMsg* pRsp) { - qInfo("task %d receive retrieve req from node %d task %d", pTask->taskId, pReq->srcNodeId, pReq->srcTaskId); + qDebug("task %d receive retrieve req from node %d task %d", pTask->taskId, pReq->srcNodeId, pReq->srcTaskId); streamTaskEnqueueRetrieve(pTask, pReq, pRsp); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 8034840fce..98b0874b00 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -303,7 +303,7 @@ int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb) { } ASSERT(pBlock->type == STREAM_INPUT__DATA_BLOCK); - qInfo("stream continue dispatching: task %d", pTask->taskId); + qDebug("stream continue dispatching: task %d", pTask->taskId); SRpcMsg dispatchMsg = {0}; SEpSet* pEpSet = NULL; diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index d178c19615..36885e73c0 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -26,10 +26,12 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) } else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) { ASSERT(pTask->isDataScan); SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data; + qDebug("task %d %p set submit input %p %p %d", pTask->taskId, pTask, pSubmit, pSubmit->data, *pSubmit->dataRef); qSetStreamInput(exec, pSubmit->data, STREAM_INPUT__DATA_SUBMIT, false); } else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) { SStreamDataBlock* pBlock = (SStreamDataBlock*)data; SArray* blocks = pBlock->blocks; + qDebug("task %d %p set ssdata input", pTask->taskId, pTask); qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__DATA_BLOCK, false); } else if (pItem->type == STREAM_INPUT__DROP) { // TODO exec drop diff --git a/source/libs/sync/inc/syncEnv.h b/source/libs/sync/inc/syncEnv.h index beddec64c5..dd032f1481 100644 --- a/source/libs/sync/inc/syncEnv.h +++ b/source/libs/sync/inc/syncEnv.h @@ -30,7 +30,7 @@ extern "C" { #define TIMER_MAX_MS 0x7FFFFFFF #define ENV_TICK_TIMER_MS 1000 -#define PING_TIMER_MS 1000 +#define PING_TIMER_MS 5000 #define ELECT_TIMER_MS_MIN 1300 #define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2) #define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN) diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 9742f93824..e361c8021c 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -251,6 +251,9 @@ void syncStartStandBy(int64_t rid); bool syncNodeCanChange(SSyncNode* pSyncNode); bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg); +int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode); +int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader); + // for debug -------------- void syncNodePrint(SSyncNode* pObj); void syncNodePrint2(char* s, SSyncNode* pObj); diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index f7bee01030..b3cdd079a4 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -83,7 +83,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { newCommitIndex = index; if (gRaftDetailLog) { - sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%" PRId64 " commit, pSyncNode->commitIndex:%" PRId64, + sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%" PRId64 + " commit, pSyncNode->commitIndex:%" PRId64, newCommitIndex, pSyncNode->commitIndex); } diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/src/syncIO.c index 663745a7d7..d9f11ba80f 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/src/syncIO.c @@ -242,13 +242,13 @@ static int32_t syncIOStopInternal(SSyncIO *io) { } static void *syncIOConsumerFunc(void *param) { - SSyncIO * io = param; - STaosQall *qall; - SRpcMsg * pRpcMsg, rpcMsg; - qall = taosAllocateQall(); + SSyncIO *io = param; + STaosQall *qall = taosAllocateQall(); + SRpcMsg *pRpcMsg, rpcMsg; + SQueueInfo qinfo = {0}; while (1) { - int numOfMsgs = taosReadAllQitemsFromQset(io->pQset, qall, NULL, NULL); + int numOfMsgs = taosReadAllQitemsFromQset(io->pQset, qall, &qinfo); sTrace("syncIOConsumerFunc %d msgs are received", numOfMsgs); if (numOfMsgs <= 0) { break; @@ -369,6 +369,8 @@ static void *syncIOConsumerFunc(void *param) { taosFreeQitem(pRpcMsg); } + + taosUpdateItemSize(qinfo.queue, numOfMsgs); } taosFreeQall(qall); diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 1db60495c2..abc0f53611 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -273,16 +273,8 @@ int32_t syncLeaderTransfer(int64_t rid) { } ASSERT(rid == pSyncNode->rid); - if (pSyncNode->peersNum == 0) { - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - - SNodeInfo newLeader = (pSyncNode->peersNodeInfo)[0]; + int32_t ret = syncNodeLeaderTransfer(pSyncNode); taosReleaseRef(tsNodeRefId, pSyncNode->rid); - - int32_t ret = syncLeaderTransferTo(rid, newLeader); return ret; } @@ -293,15 +285,39 @@ int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) { return -1; } ASSERT(rid == pSyncNode->rid); - int32_t ret = 0; - if (pSyncNode->replicaNum == 1) { - sError("only one replica, cannot drop leader"); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + int32_t ret = syncNodeLeaderTransferTo(pSyncNode, newLeader); + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return ret; +} + +int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) { + if (pSyncNode->peersNum == 0) { + sError("only one replica, cannot leader transfer"); terrno = TSDB_CODE_SYN_ONE_REPLICA; return -1; } + SNodeInfo newLeader = (pSyncNode->peersNodeInfo)[0]; + int32_t ret = syncNodeLeaderTransferTo(pSyncNode, newLeader); + return ret; +} + +int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) { + int32_t ret = 0; + + if (pSyncNode->replicaNum == 1) { + sError("only one replica, cannot leader transfer"); + terrno = TSDB_CODE_SYN_ONE_REPLICA; + return -1; + } + + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "begin leader transfer to %s:%u", newLeader.nodeFqdn, newLeader.nodePort); + syncNodeEventLog(pSyncNode, logBuf); + } while (0); + SyncLeaderTransfer* pMsg = syncLeaderTransferBuild(pSyncNode->vgId); pMsg->newLeaderId.addr = syncUtilAddr2U64(newLeader.nodeFqdn, newLeader.nodePort); pMsg->newLeaderId.vgId = pSyncNode->vgId; @@ -312,7 +328,6 @@ int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) { syncLeaderTransferDestroy(pMsg); ret = syncNodePropose(pSyncNode, &rpcMsg, false); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); return ret; } @@ -824,8 +839,8 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { } else { ret = -1; terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - sError("vgId:%d optimized index:%" PRId64 " error, msgtype:%s,%d", pSyncNode->vgId, retIndex, TMSG_INFO(pMsg->msgType), - pMsg->msgType); + sError("vgId:%d optimized index:%" PRId64 " error, msgtype:%s,%d", pSyncNode->vgId, retIndex, + TMSG_INFO(pMsg->msgType), pMsg->msgType); } } else { @@ -1084,19 +1099,13 @@ void syncNodeStart(SSyncNode* pSyncNode) { // Raft 3.6.2 Committing entries from previous terms syncNodeAppendNoop(pSyncNode); syncMaybeAdvanceCommitIndex(pSyncNode); - - return; + } else { + syncNodeBecomeFollower(pSyncNode, "first start"); } - syncNodeBecomeFollower(pSyncNode, "first start"); - - // int32_t ret = 0; - // ret = syncNodeStartPingTimer(pSyncNode); - // ASSERT(ret == 0); - - if (gRaftDetailLog) { - syncNodeLog2("==state change become leader immediately==", pSyncNode); - } + int32_t ret = 0; + ret = syncNodeStartPingTimer(pSyncNode); + ASSERT(ret == 0); } void syncNodeStartStandBy(SSyncNode* pSyncNode) { @@ -1147,14 +1156,6 @@ void syncNodeClose(SSyncNode* pSyncNode) { pSyncNode->pNewNodeReceiver = NULL; } - /* - if (pSyncNode->pSnapshot != NULL) { - taosMemoryFree(pSyncNode->pSnapshot); - } - */ - - // tsem_destroy(&pSyncNode->restoreSem); - // free memory in syncFreeNode // taosMemoryFree(pSyncNode); } @@ -1219,7 +1220,7 @@ int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) { &pSyncNode->pPingTimer); atomic_store_64(&pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser); } else { - sError("sync env is stop, syncNodeStartPingTimer"); + sError("vgId:%d, start ping timer error, sync env is stop", pSyncNode->vgId); } return ret; } @@ -1240,7 +1241,7 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { &pSyncNode->pElectTimer); atomic_store_64(&pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser); } else { - sError("sync env is stop, syncNodeStartElectTimer"); + sError("vgId:%d, start elect timer error, sync env is stop", pSyncNode->vgId); } return ret; } @@ -1280,7 +1281,7 @@ int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode) { &pSyncNode->pHeartbeatTimer); atomic_store_64(&pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser); } else { - sError("sync env is stop, syncNodeStartHeartbeatTimer"); + sError("vgId:%d, start heartbeat timer error, sync env is stop", pSyncNode->vgId); } return ret; } @@ -1527,7 +1528,9 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 ", lastsnapshot:%" PRId64 ", standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 + ", snapshot:%" PRId64 + ", standby:%d, " "strategy:%d, batch:%d, " "replica-num:%d, " "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", @@ -1546,7 +1549,9 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 ", lastsnapshot:%" PRId64 ", standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 + ", snapshot:%" PRId64 + ", standby:%d, " "strategy:%d, batch:%d, " "replica-num:%d, " "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", @@ -1590,7 +1595,9 @@ void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 ", lastsnapshot:%" PRId64 ", standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 + ", snapshot:%" PRId64 + ", standby:%d, " "replica-num:%d, " "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, @@ -1607,7 +1614,9 @@ void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 ", lastsnapshot:%" PRId64 ", standby:%d, " + "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 + ", snapshot:%" PRId64 + ", standby:%d, " "replica-num:%d, " "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, @@ -1636,7 +1645,9 @@ char* syncNode2SimpleStr(const SSyncNode* pSyncNode) { SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); snprintf(s, len, - "vgId:%d, sync %s, term:%" PRIu64 ", commit:%" PRId64 ", beginlog:%" PRId64 ", lastlog:%" PRId64 ", lastsnapshot:%" PRId64 ", standby:%d, " + "vgId:%d, sync %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 + ", snapshot:%" PRId64 + ", standby:%d, " "replica-num:%d, " "lconfig:%" PRId64 ", changing:%d, restore:%d", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, @@ -1839,8 +1850,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde char tmpbuf[512]; char* oldStr = syncCfg2SimpleStr(&oldConfig); char* newStr = syncCfg2SimpleStr(pNewConfig); - snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%" PRId64 ", %s --> %s", oldConfig.replicaNum, - pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); + snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%" PRId64 ", %s --> %s", + oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); taosMemoryFree(oldStr); taosMemoryFree(newStr); @@ -1863,8 +1874,8 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde char tmpbuf[512]; char* oldStr = syncCfg2SimpleStr(&oldConfig); char* newStr = syncCfg2SimpleStr(pNewConfig); - snprintf(tmpbuf, sizeof(tmpbuf), "do not config change from %d to %d, index:%" PRId64 ", %s --> %s", oldConfig.replicaNum, - pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); + snprintf(tmpbuf, sizeof(tmpbuf), "do not config change from %d to %d, index:%" PRId64 ", %s --> %s", + oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); taosMemoryFree(oldStr); taosMemoryFree(newStr); syncNodeEventLog(pSyncNode, tmpbuf); @@ -2399,7 +2410,8 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) { // log state char logBuf[1024] = {0}; snprintf(logBuf, sizeof(logBuf), - "==syncNodeOnPingCb== vgId:%d, state: %d, %s, term:%" PRIu64 " electTimerLogicClock:%" PRIu64 ", " + "==syncNodeOnPingCb== vgId:%d, state: %d, %s, term:%" PRIu64 " electTimerLogicClock:%" PRIu64 + ", " "electTimerLogicClockUser:%" PRIu64 ", electTimerMS:%d", ths->vgId, ths->state, syncUtilState2String(ths->state), ths->pRaftStore->currentTerm, ths->electTimerLogicClock, ths->electTimerLogicClockUser, ths->electTimerMS); @@ -2596,7 +2608,7 @@ const char* syncStr(ESyncState state) { static int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) { SyncLeaderTransfer* pSyncLeaderTransfer = syncLeaderTransferFromRpcMsg2(pRpcMsg); - syncNodeEventLog(ths, "begin leader transfer"); + syncNodeEventLog(ths, "do leader transfer"); bool sameId = syncUtilSameId(&(pSyncLeaderTransfer->newLeaderId), &(ths->myRaftId)); bool sameNodeInfo = strcmp(pSyncLeaderTransfer->newNodeInfo.nodeFqdn, ths->myNodeInfo.nodeFqdn) == 0 && diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index c06bd2338d..0bbeaaf5b0 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -101,7 +101,7 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) { char *syncCfg2Str(SSyncCfg *pSyncCfg) { cJSON *pJson = syncCfg2Json(pSyncCfg); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -109,7 +109,7 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) { char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) { if (pSyncCfg != NULL) { int32_t len = 512; - char *s = taosMemoryMalloc(len); + char * s = taosMemoryMalloc(len); memset(s, 0, len); snprintf(s, len, "{replica-num:%d, my-index:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); @@ -206,7 +206,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { char *raftCfg2Str(SRaftCfg *pRaftCfg) { cJSON *pJson = raftCfg2Json(pRaftCfg); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -285,7 +285,7 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) { (pRaftCfg->configIndexArr)[i] = atoll(pIndex->valuestring); } - cJSON *pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); + cJSON * pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); int32_t code = syncCfgFromJson(pJsonSyncCfg, &(pRaftCfg->cfg)); ASSERT(code == 0); diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index a135002f44..edc01c9a05 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -122,8 +122,8 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI char logBuf[128]; snprintf(logBuf, sizeof(logBuf), - "wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", snapshotIndex, err, - err, errStr, sysErr, sysErrStr); + "wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + snapshotIndex, err, err, errStr, sysErr, sysErrStr); syncNodeErrorLog(pData->pSyncNode, logBuf); return -1; @@ -201,19 +201,56 @@ static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) { return SYNC_TERM_INVALID; } +static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + + SyncIndex index = 0; + SWalSyncInfo syncMeta; + syncMeta.isWeek = pEntry->isWeak; + syncMeta.seqNum = pEntry->seqNum; + syncMeta.term = pEntry->term; + index = walAppendLog(pWal, pEntry->originalRpcType, syncMeta, pEntry->data, pEntry->dataLen); + if (index < 0) { + int32_t err = terrno; + const char* errStr = tstrerror(err); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pEntry->index, err, err, errStr, sysErr, sysErrStr); + syncNodeErrorLog(pData->pSyncNode, logBuf); + + ASSERT(0); + return -1; + } + pEntry->index = index; + + do { + char eventLog[128]; + snprintf(eventLog, sizeof(eventLog), "write index:%" PRId64 ", type:%s,%d, type2:%s,%d", pEntry->index, + TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType); + syncNodeEventLog(pData->pSyncNode, eventLog); + } while (0); + + return 0; +} + +#if 0 static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; SyncIndex writeIndex = raftLogWriteIndex(pLogStore); if (pEntry->index != writeIndex) { - sError("vgId:%d wal write index error, entry-index:%" PRId64 " update to %" PRId64, pData->pSyncNode->vgId, pEntry->index, - writeIndex); + sError("vgId:%d wal write index error, entry-index:%" PRId64 " update to %" PRId64, pData->pSyncNode->vgId, + pEntry->index, writeIndex); pEntry->index = writeIndex; } int code = 0; - SSyncLogMeta syncMeta; + SWalSyncInfo syncMeta; syncMeta.isWeek = pEntry->isWeak; syncMeta.seqNum = pEntry->seqNum; syncMeta.term = pEntry->term; @@ -243,6 +280,7 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr return code; } +#endif // entry found, return 0 // entry not found, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST @@ -272,8 +310,8 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, - err, errStr, sysErr, sysErrStr); + snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + index, err, err, errStr, sysErr, sysErrStr); if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { syncNodeEventLog(pData->pSyncNode, logBuf); } else { @@ -361,6 +399,8 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp //------------------------------- // log[0 .. n] + +#if 0 int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; @@ -369,7 +409,7 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { ASSERT(pEntry->index == lastIndex + 1); int code = 0; - SSyncLogMeta syncMeta; + SWalSyncInfo syncMeta; syncMeta.isWeek = pEntry->isWeak; syncMeta.seqNum = pEntry->seqNum; syncMeta.term = pEntry->term; @@ -397,6 +437,44 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { return code; } +#endif + +int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + + SyncIndex index = 0; + SWalSyncInfo syncMeta; + syncMeta.isWeek = pEntry->isWeak; + syncMeta.seqNum = pEntry->seqNum; + syncMeta.term = pEntry->term; + + index = walAppendLog(pWal, pEntry->originalRpcType, syncMeta, pEntry->data, pEntry->dataLen); + if (index < 0) { + int32_t err = terrno; + const char* errStr = tstrerror(err); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pEntry->index, err, err, errStr, sysErr, sysErrStr); + syncNodeErrorLog(pData->pSyncNode, logBuf); + + ASSERT(0); + return -1; + } + pEntry->index = index; + + do { + char eventLog[128]; + snprintf(eventLog, sizeof(eventLog), "write2 index:%" PRId64 ", type:%s,%d, type2:%s,%d", pEntry->index, + TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType); + syncNodeEventLog(pData->pSyncNode, eventLog); + } while (0); + + return 0; +} SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { SSyncLogStoreData* pData = pLogStore->data; @@ -418,8 +496,8 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, - err, err, errStr, sysErr, sysErrStr); + snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + index, err, err, errStr, sysErr, sysErrStr); if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { syncNodeEventLog(pData->pSyncNode, logBuf); } else { diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 18e94e0523..b6bc4bc816 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -135,7 +135,8 @@ int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) { SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); - sError("vgId:%d sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 ", match-index:%d, raftid:%" PRId64, + sError("vgId:%d sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 + ", match-index:%d, raftid:%" PRId64, pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); return -1; @@ -224,7 +225,8 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) { SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); - sError("vgId:%d sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 ", match-index:%d, raftid:%" PRId64, + sError("vgId:%d sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64 + ", match-index:%d, raftid:%" PRId64, pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); return -1; @@ -314,11 +316,12 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c char host[128]; uint16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - sDebug( - "vgId:%d, send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 ", pterm:%" PRIu64 ", commit:%" PRId64 ", " - "datalen:%d}", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen); + sDebug("vgId:%d, send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", pterm:%" PRIu64 ", commit:%" PRId64 + ", " + "datalen:%d}", + pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, + pMsg->commitIndex, pMsg->dataLen); } while (0); SRpcMsg rpcMsg; diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index db1a33c28b..a6ca0e6d78 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -55,7 +55,8 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 ", maybe replica already dropped", + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", maybe replica already dropped", host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm); syncNodeEventLog(ths, logBuf); } while (0); @@ -97,8 +98,9 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 ", reply-grant:%d", host, port, - pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", reply-grant:%d", + host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); syncNodeEventLog(ths, logBuf); } while (0); @@ -181,7 +183,8 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 ", maybe replica already dropped", + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", maybe replica already dropped", host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm); syncNodeEventLog(ths, logBuf); } while (0); @@ -221,8 +224,9 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 ", reply-grant:%d", host, port, - pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); + "recv sync-request-vote from %s:%d, term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 + ", reply-grant:%d", + host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); syncNodeEventLog(ths, logBuf); } while (0); diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 12af7cf531..8ab4f75c5c 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -66,8 +66,8 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "syncNodeOnRequestVoteReplyCb error term, receive:%" PRIu64 " current:%" PRIu64, pMsg->term, - ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), "syncNodeOnRequestVoteReplyCb error term, receive:%" PRIu64 " current:%" PRIu64, + pMsg->term, ths->pRaftStore->currentTerm); syncNodePrint2(logBuf, ths); sError("%s", logBuf); return ret; @@ -190,8 +190,9 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl if (pMsg->term > ths->pRaftStore->currentTerm) { char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "recv SyncRequestVoteReply, error term, receive_term:%" PRIu64 " current_term:%" PRIu64, - pMsg->term, ths->pRaftStore->currentTerm); + snprintf(logBuf, sizeof(logBuf), + "recv SyncRequestVoteReply, error term, receive_term:%" PRIu64 " current_term:%" PRIu64, pMsg->term, + ths->pRaftStore->currentTerm); syncNodePrint2(logBuf, ths); sError("%s", logBuf); return ret; diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 3079aa17ca..87cc5685f3 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -153,8 +153,8 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho // event log do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "snapshot sender update lcindex from %" PRId64 " to %" PRId64, oldLastConfigIndex, - newLastConfigIndex); + snprintf(logBuf, sizeof(logBuf), "snapshot sender update lcindex from %" PRId64 " to %" PRId64, + oldLastConfigIndex, newLastConfigIndex); char *eventLog = snapshotSender2SimpleStr(pSender, logBuf); syncNodeEventLog(pSender->pSyncNode, eventLog); taosMemoryFree(eventLog); @@ -389,7 +389,9 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) { syncUtilU642Addr(destId.addr, host, sizeof(host), &port); snprintf(s, len, - "%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64 " seq:%d ack:%d finish:%d pterm:%" PRIu64 " " + "%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64 + " seq:%d ack:%d finish:%d pterm:%" PRIu64 + " " "replica-index:%d %s:%d}", event, pSender, pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, @@ -692,7 +694,9 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) syncUtilU642Addr(fromId.addr, host, sizeof(host), &port); snprintf(s, len, - "%s {%p start:%d ack:%d term:%" PRIu64 " pterm:%" PRIu64 " from:%s:%d s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " " + "%s {%p start:%d ack:%d term:%" PRIu64 " pterm:%" PRIu64 " from:%s:%d s-param:%" PRId64 " e-param:%" PRId64 + " laindex:%" PRId64 " laterm:%" PRIu64 + " " "lcindex:%" PRId64 "}", event, pReceiver, pReceiver->start, pReceiver->ack, pReceiver->term, pReceiver->privateTerm, host, port, pReceiver->snapshotParam.start, pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c index 0d3a3c3cc5..52181a3da8 100644 --- a/source/libs/sync/src/syncTimeout.c +++ b/source/libs/sync/src/syncTimeout.c @@ -17,6 +17,11 @@ #include "syncElection.h" #include "syncReplication.h" +int32_t syncNodeTimerRoutine(SSyncNode* ths) { + syncNodeEventLog(ths, "timer routines ... "); + return 0; +} + int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) { int32_t ret = 0; syncTimeoutLog2("==syncNodeOnTimeoutCb==", pMsg); @@ -24,8 +29,11 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) { if (pMsg->timeoutType == SYNC_TIMEOUT_PING) { if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) { ++(ths->pingTimerCounter); + // syncNodePingAll(ths); - syncNodePingPeers(ths); + // syncNodePingPeers(ths); + + syncNodeTimerRoutine(ths); } } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) { @@ -40,7 +48,7 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) { syncNodeReplicate(ths); } } else { - sTrace("unknown timeoutType:%d", pMsg->timeoutType); + sError("vgId:%d, unknown timeout-type:%d", ths->vgId, pMsg->timeoutType); } return ret; diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index de82df3fbd..339ebe90e7 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -45,7 +45,8 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 " \n", + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); @@ -56,17 +57,19 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + snprintf( + logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), + cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -147,8 +150,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, cbMeta.flag, - cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, + cbMeta.flag, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); } SSyncFSM* createFsm() { @@ -267,7 +270,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncConfigChangeTest.cpp b/source/libs/sync/test/syncConfigChangeTest.cpp index 80a5e65274..ba3fc77650 100644 --- a/source/libs/sync/test/syncConfigChangeTest.cpp +++ b/source/libs/sync/test/syncConfigChangeTest.cpp @@ -44,8 +44,9 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), + cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); @@ -54,17 +55,19 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; - snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + snprintf( + logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), + cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -78,8 +81,8 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, cbMeta.flag, - cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64, + cbMeta.flag, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term); } SSyncFSM* createFsm() { @@ -188,7 +191,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncEntryCacheTest.cpp b/source/libs/sync/test/syncEntryCacheTest.cpp index 787c08e507..6250181b25 100644 --- a/source/libs/sync/test/syncEntryCacheTest.cpp +++ b/source/libs/sync/test/syncEntryCacheTest.cpp @@ -5,6 +5,7 @@ #include "syncRaftLog.h" #include "syncRaftStore.h" #include "syncUtil.h" +#include "tskiplist.h" void logTest() { sTrace("--- sync log test: trace"); @@ -148,15 +149,131 @@ void test4() { raftCacheLog2((char*)"==test4 after get-and-del entry 3==", pCache); } +static char* keyFn(const void* pData) { + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pData; + return (char*)(&(pEntry->index)); +} + +static int cmpFn(const void* p1, const void* p2) { return memcmp(p1, p2, sizeof(SyncIndex)); } + +void printSkipList(SSkipList* pSkipList) { + ASSERT(pSkipList != NULL); + + SSkipListIterator* pIter = tSkipListCreateIter(pSkipList); + while (tSkipListIterNext(pIter)) { + SSkipListNode* pNode = tSkipListIterGet(pIter); + ASSERT(pNode != NULL); + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode); + syncEntryPrint2((char*)"", pEntry); + } +} + +void delSkipListFirst(SSkipList* pSkipList, int n) { + ASSERT(pSkipList != NULL); + + sTrace("delete first %d -------------", n); + SSkipListIterator* pIter = tSkipListCreateIter(pSkipList); + for (int i = 0; i < n; ++i) { + tSkipListIterNext(pIter); + SSkipListNode* pNode = tSkipListIterGet(pIter); + tSkipListRemoveNode(pSkipList, pNode); + } +} + + +SSyncRaftEntry* getLogEntry2(SSkipList* pSkipList, SyncIndex index) { + SyncIndex index2 = index; + SSyncRaftEntry *pEntry = NULL; + int arraySize = 0; + + SArray* entryPArray = tSkipListGet(pSkipList, (char*)(&index2)); + arraySize = taosArrayGetSize(entryPArray); + if (arraySize > 0) { + SSkipListNode** ppNode = (SSkipListNode**)taosArrayGet(entryPArray, 0); + ASSERT(*ppNode != NULL); + pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(*ppNode); + } + taosArrayDestroy(entryPArray); + + sTrace("get index2: %ld, arraySize:%d -------------", index, arraySize); + syncEntryLog2((char*)"getLogEntry2", pEntry); + return pEntry; +} + + +SSyncRaftEntry* getLogEntry(SSkipList* pSkipList, SyncIndex index) { + sTrace("get index: %ld -------------", index); + SyncIndex index2 = index; + SSyncRaftEntry *pEntry = NULL; + SSkipListIterator* pIter = tSkipListCreateIterFromVal(pSkipList, (const char *)&index2, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); + if (tSkipListIterNext(pIter)) { + SSkipListNode* pNode = tSkipListIterGet(pIter); + ASSERT(pNode != NULL); + pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode); + } + + syncEntryLog2((char*)"getLogEntry", pEntry); + return pEntry; +} + +void test5() { + SSkipList* pSkipList = + tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, sizeof(SyncIndex), cmpFn, SL_ALLOW_DUP_KEY, keyFn); + ASSERT(pSkipList != NULL); + + sTrace("insert 9 - 5"); + for (int i = 9; i >= 5; --i) { + SSyncRaftEntry* pEntry = createEntry(i); + SSkipListNode* pSkipListNode = tSkipListPut(pSkipList, pEntry); + } + + sTrace("insert 0 - 4"); + for (int i = 0; i <= 4; ++i) { + SSyncRaftEntry* pEntry = createEntry(i); + SSkipListNode* pSkipListNode = tSkipListPut(pSkipList, pEntry); + } + + sTrace("insert 7 7 7 7 7"); + for (int i = 0; i <= 4; ++i) { + SSyncRaftEntry* pEntry = createEntry(7); + SSkipListNode* pSkipListNode = tSkipListPut(pSkipList, pEntry); + } + + sTrace("print: -------------"); + printSkipList(pSkipList); + + delSkipListFirst(pSkipList, 3); + + sTrace("print: -------------"); + printSkipList(pSkipList); + + getLogEntry(pSkipList, 2); + getLogEntry(pSkipList, 5); + getLogEntry(pSkipList, 7); + getLogEntry(pSkipList, 7); + + getLogEntry2(pSkipList, 2); + getLogEntry2(pSkipList, 5); + getLogEntry2(pSkipList, 7); + getLogEntry2(pSkipList, 7); + + + tSkipListDestroy(pSkipList); +} + int main(int argc, char** argv) { gRaftDetailLog = true; tsAsyncLog = 0; sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE + DEBUG_DEBUG; - test1(); - test2(); - test3(); - test4(); + /* + test1(); + test2(); + test3(); + test4(); + */ + + test5(); return 0; } diff --git a/source/libs/sync/test/syncReplicateTest.cpp b/source/libs/sync/test/syncReplicateTest.cpp index 9148ab6195..d3ba4bc136 100644 --- a/source/libs/sync/test/syncReplicateTest.cpp +++ b/source/libs/sync/test/syncReplicateTest.cpp @@ -40,8 +40,9 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); @@ -51,15 +52,16 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -143,7 +145,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncRespMgrTest.cpp b/source/libs/sync/test/syncRespMgrTest.cpp index 9e982e0a59..35daff796f 100644 --- a/source/libs/sync/test/syncRespMgrTest.cpp +++ b/source/libs/sync/test/syncRespMgrTest.cpp @@ -35,8 +35,8 @@ void syncRespMgrDelTest(uint64_t begin, uint64_t end) { } void printStub(SRespStub *p) { - printf("createTime:%" PRId64 ", rpcMsg.code:%d rpcMsg.ahandle:%" PRId64 " rpcMsg.handle:%" PRId64 " \n", p->createTime, p->rpcMsg.code, - (int64_t)(p->rpcMsg.info.ahandle), (int64_t)(p->rpcMsg.info.handle)); + printf("createTime:%" PRId64 ", rpcMsg.code:%d rpcMsg.ahandle:%" PRId64 " rpcMsg.handle:%" PRId64 " \n", + p->createTime, p->rpcMsg.code, (int64_t)(p->rpcMsg.info.ahandle), (int64_t)(p->rpcMsg.info.handle)); } void syncRespMgrPrint() { printf("\n----------------syncRespMgrPrint--------------\n"); diff --git a/source/libs/sync/test/syncSnapshotTest.cpp b/source/libs/sync/test/syncSnapshotTest.cpp index 9e50fa62ef..e0d33598b0 100644 --- a/source/libs/sync/test/syncSnapshotTest.cpp +++ b/source/libs/sync/test/syncSnapshotTest.cpp @@ -43,8 +43,9 @@ void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { if (cbMeta.index > beginIndex) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } else { sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); @@ -54,15 +55,16 @@ void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } diff --git a/source/libs/sync/test/syncTestTool.cpp b/source/libs/sync/test/syncTestTool.cpp index 714b73a9e5..f35c6f8a2f 100644 --- a/source/libs/sync/test/syncTestTool.cpp +++ b/source/libs/sync/test/syncTestTool.cpp @@ -40,7 +40,9 @@ void cleanup() { walCleanUp(); } void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 " " + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 + " " "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); @@ -50,7 +52,9 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 " " + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 + " " "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); @@ -60,7 +64,9 @@ void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 " " + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 + ", term:%" PRIu64 + " " "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); @@ -128,7 +134,8 @@ int32_t SnapshotStopWrite(struct SSyncFSM* pFsm, void* pWriter, bool isApply) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==SnapshotStopWrite== pFsm:%p, pWriter:%p, isApply:%d, gSnapshotLastApplyIndex:%" PRId64 ", " + "==callback== ==SnapshotStopWrite== pFsm:%p, pWriter:%p, isApply:%d, gSnapshotLastApplyIndex:%" PRId64 + ", " "gSnapshotLastApplyTerm:%" PRId64, pFsm, pWriter, isApply, gSnapshotLastApplyIndex, gSnapshotLastApplyTerm); sTrace("%s", logBuf); @@ -148,7 +155,8 @@ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFini void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) { char* s = syncCfg2Str(&(cbMeta.newCfg)); - sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64 ", newCfg:%s", + sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64 + ", newCfg:%s", cbMeta.flag, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term, s); taosMemoryFree(s); } @@ -156,7 +164,9 @@ void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMe void LeaderTransferCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), - "==callback== ==LeaderTransferCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 " " + "==callback== ==LeaderTransferCb== pFsm:%p, index:%" PRId64 + ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 + " " "currentTerm:%" PRIu64 " \n", pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag, cbMeta.term, cbMeta.currentTerm); @@ -300,7 +310,8 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = TDMT_VND_SUBMIT; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, taosGetTimestampMs()); + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncWriteTest.cpp b/source/libs/sync/test/syncWriteTest.cpp index d99923a8b9..3bf068e3c7 100644 --- a/source/libs/sync/test/syncWriteTest.cpp +++ b/source/libs/sync/test/syncWriteTest.cpp @@ -33,23 +33,25 @@ const char *pDir = "./syncWriteTest"; void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index, - cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index e73ddedd73..5bb6349d9b 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -311,6 +311,17 @@ void transCtxMerge(STransCtx* dst, STransCtx* src); void* transCtxDumpVal(STransCtx* ctx, int32_t key); void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType); +// request list +typedef struct STransReq { + queue q; + void* data; +} STransReq; + +void transReqQueueInit(queue* q); +void* transReqQueuePushReq(queue* q); +void* transReqQueueRemove(void* arg); +void transReqQueueClear(queue* q); + // queue sending msgs typedef struct { SArray* q; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 0600b1130d..5d087d5769 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -19,7 +19,7 @@ typedef struct SCliConn { T_REF_DECLARE() uv_connect_t connReq; uv_stream_t* stream; - uv_write_t writeReq; + queue wreqQueue; void* hostThrd; @@ -573,8 +573,7 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { return; } if (nread < 0) { - tWarn("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), - T_REF_VAL_GET(conn)); + tWarn("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), T_REF_VAL_GET(conn)); conn->broken = true; cliHandleExcept(conn); } @@ -587,9 +586,10 @@ static SCliConn* cliCreateConn(SCliThrd* pThrd) { uv_tcp_init(pThrd->loop, (uv_tcp_t*)(conn->stream)); conn->stream->data = conn; - conn->writeReq.data = conn; conn->connReq.data = conn; + transReqQueueInit(&conn->wreqQueue); + transQueueInit(&conn->cliMsgs, NULL); QUEUE_INIT(&conn->conn); conn->hostThrd = pThrd; @@ -628,6 +628,8 @@ static void cliDestroy(uv_handle_t* handle) { transCtxCleanup(&conn->ctx); transQueueDestroy(&conn->cliMsgs); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); + transReqQueueClear(&conn->wreqQueue); + transDestroyBuffer(&conn->readBuf); taosMemoryFree(conn); } @@ -650,7 +652,8 @@ static bool cliHandleNoResp(SCliConn* conn) { return res; } static void cliSendCb(uv_write_t* req, int status) { - SCliConn* pConn = req->data; + SCliConn* pConn = transReqQueueRemove(req); + if (pConn == NULL) return; if (status == 0) { tTrace("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); @@ -708,8 +711,8 @@ void cliSend(SCliConn* pConn) { CONN_SET_PERSIST_BY_APP(pConn); } - pConn->writeReq.data = pConn; - uv_write(&pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); + uv_write_t* req = transReqQueuePushReq(&pConn->wreqQueue); + uv_write(req, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb); return; _RETURN: return; diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 812123441c..84af8da513 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -293,6 +293,48 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) { return ret; } +void transReqQueueInit(queue* q) { + // init req queue + QUEUE_INIT(q); +} +void* transReqQueuePushReq(queue* q) { + uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); + STransReq* wreq = taosMemoryCalloc(1, sizeof(STransReq)); + wreq->data = req; + req->data = wreq; + QUEUE_PUSH(q, &wreq->q); + return req; +} +void* transReqQueueRemove(void* arg) { + void* ret = NULL; + uv_write_t* req = arg; + STransReq* wreq = req && req->data ? req->data : NULL; + + assert(wreq->data == req); + if (wreq == NULL || wreq->data == NULL) { + taosMemoryFree(wreq->data); + taosMemoryFree(wreq); + return req; + } + + QUEUE_REMOVE(&wreq->q); + + ret = req && req->handle ? req->handle->data : NULL; + taosMemoryFree(wreq->data); + taosMemoryFree(wreq); + + return ret; +} +void transReqQueueClear(queue* q) { + while (!QUEUE_IS_EMPTY(q)) { + queue* h = QUEUE_HEAD(q); + QUEUE_REMOVE(h); + STransReq* req = QUEUE_DATA(h, STransReq, q); + taosMemoryFree(req->data); + taosMemoryFree(req); + } +} + void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) { queue->q = taosArrayInit(2, sizeof(void*)); queue->freeFunc = (void (*)(const void*))freeFunc; diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index a239f90c29..68e12a1963 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -29,7 +29,7 @@ typedef struct { typedef struct SSvrConn { T_REF_DECLARE() uv_tcp_t* pTcp; - uv_write_t pWriter; + queue wreqQueue; uv_timer_t pTimer; queue queue; @@ -265,8 +265,8 @@ static void uvHandleReq(SSvrConn* pConn) { transMsg.info.refId = pConn->refId; transMsg.info.traceId = pHead->traceId; - tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, - pConn, pConn->refId); + tGTrace("%s handle %p conn:%p translated to app, refId:%" PRIu64, transLabel(pTransInst), transMsg.info.handle, pConn, + pConn->refId); assert(transMsg.info.handle != NULL); if (pHead->noResp == 1) { @@ -316,7 +316,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { memset(&conn->regArg, 0, sizeof(conn->regArg)); } } - transUnrefSrvHandle(conn); + destroyConn(conn, true); } } void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { @@ -331,7 +331,9 @@ void uvOnTimeoutCb(uv_timer_t* handle) { } void uvOnSendCb(uv_write_t* req, int status) { - SSvrConn* conn = req->data; + SSvrConn* conn = transReqQueueRemove(req); + if (conn == NULL) return; + if (status == 0) { tTrace("conn %p data already was written on stream", conn); if (!transQueueEmpty(&conn->srvMsgs)) { @@ -390,7 +392,6 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { pHead->traceId = pMsg->info.traceId; pHead->hasEpSet = pMsg->info.hasEpSet; - if (pConn->status == ConnNormal) { pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); } else { @@ -433,12 +434,12 @@ static void uvStartSendRespInternal(SSvrMsg* smsg) { uvPrepareSendData(smsg, &wb); transRefSrvHandle(pConn); - uv_write(&pConn->pWriter, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); + uv_write_t* req = transReqQueuePushReq(&pConn->wreqQueue); + uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); } static void uvStartSendResp(SSvrMsg* smsg) { // impl SSvrConn* pConn = smsg->pConn; - if (pConn->broken == true) { // persist by transFreeMsg(smsg->msg.pCont); @@ -635,8 +636,6 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { uv_tcp_init(pThrd->loop, pConn->pTcp); pConn->pTcp->data = pConn; - pConn->pWriter.data = pConn; - transSetConnOption((uv_tcp_t*)pConn->pTcp); if (uv_accept(q, (uv_stream_t*)(pConn->pTcp)) == 0) { @@ -744,6 +743,8 @@ static SSvrConn* createConn(void* hThrd) { SWorkThrd* pThrd = hThrd; SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn)); + + transReqQueueInit(&pConn->wreqQueue); QUEUE_INIT(&pConn->queue); QUEUE_PUSH(&pThrd->conn, &pConn->queue); @@ -778,9 +779,6 @@ static void destroyConn(SSvrConn* conn, bool clear) { tTrace("conn %p to be destroyed", conn); uv_close((uv_handle_t*)conn->pTcp, uvDestroyConn); } - //} else { - // uvDestroyConn((uv_handle_t*)conn->pTcp); - //} } } static void destroyConnRegArg(SSvrConn* conn) { @@ -819,6 +817,8 @@ static void uvDestroyConn(uv_handle_t* handle) { SSvrMsg* msg = transQueueGet(&conn->srvMsgs, i); destroySmsg(msg); } + + transReqQueueClear(&conn->wreqQueue); transQueueDestroy(&conn->srvMsgs); QUEUE_REMOVE(&conn->queue); diff --git a/source/libs/transport/test/pushServer.c b/source/libs/transport/test/pushServer.c index 6a4ff213d0..754433a5e6 100644 --- a/source/libs/transport/test/pushServer.c +++ b/source/libs/transport/test/pushServer.c @@ -31,12 +31,12 @@ void processShellMsg() { STaosQall *qall; SRpcMsg * pRpcMsg, rpcMsg; int type; - void * pvnode; + SQueueInfo qinfo = {0}; qall = taosAllocateQall(); while (1) { - int numOfMsgs = taosReadAllQitemsFromQset(qset, qall, &pvnode, NULL); + int numOfMsgs = taosReadAllQitemsFromQset(qset, qall, &qinfo); tDebug("%d shell msgs are received", numOfMsgs); if (numOfMsgs <= 0) break; @@ -86,6 +86,8 @@ void processShellMsg() { rpcSendResponse(&nRpcMsg); } } + + taosUpdateItemSize(qinfo.queue, numOfMsgs); } taosFreeQall(qall); diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index 2767780ff3..20667fc918 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -146,12 +146,12 @@ int walMetaDeserialize(SWal* pWal, const char* bytes); // seek section int walChangeWrite(SWal* pWal, int64_t ver); -int walSetWrite(SWal* pWal); +int walInitWriteFile(SWal* pWal); // seek section end int64_t walGetSeq(); int walSeekWriteVer(SWal* pWal, int64_t ver); -int walRoll(SWal* pWal); +int32_t walRollImpl(SWal* pWal); #ifdef __cplusplus } diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 313fd06c8e..991b50f7c0 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -51,10 +51,10 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); - int64_t file_size = 0; - taosStatFile(fnameStr, &file_size, NULL); - int readSize = TMIN(WAL_MAX_SIZE + 2, file_size); - pLastFileInfo->fileSize = file_size; + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + int readSize = TMIN(WAL_MAX_SIZE + 2, fileSize); + pLastFileInfo->fileSize = fileSize; TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); if (pFile == NULL) { @@ -141,34 +141,53 @@ int walCheckAndRepairMeta(SWal* pWal) { regfree(&idxRegPattern); taosArraySort(pLogInfoArray, compareWalFileInfo); - int oldSz = 0; - if (pWal->fileInfoSet) { - oldSz = taosArrayGetSize(pWal->fileInfoSet); - } - int newSz = taosArrayGetSize(pLogInfoArray); - if (oldSz > newSz) { - taosArrayPopFrontBatch(pWal->fileInfoSet, oldSz - newSz); - } else if (oldSz < newSz) { - for (int i = oldSz; i < newSz; i++) { + int metaFileNum = taosArrayGetSize(pWal->fileInfoSet); + int actualFileNum = taosArrayGetSize(pLogInfoArray); + +#if 0 + for (int32_t fileNo = actualFileNum - 1; fileNo >= 0; fileNo--) { + SWalFileInfo* pFileInfo = taosArrayGet(pLogInfoArray, fileNo); + char fnameStr[WAL_FILE_LEN]; + walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + if (fileSize == 0) { + taosRemoveFile(fnameStr); + walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); + taosRemoveFile(fnameStr); + taosArrayPop(pLogInfoArray); + } else { + break; + } + } + + actualFileNum = taosArrayGetSize(pLogInfoArray); +#endif + + if (metaFileNum > actualFileNum) { + taosArrayPopFrontBatch(pWal->fileInfoSet, metaFileNum - actualFileNum); + } else if (metaFileNum < actualFileNum) { + for (int i = metaFileNum; i < actualFileNum; i++) { SWalFileInfo* pFileInfo = taosArrayGet(pLogInfoArray, i); taosArrayPush(pWal->fileInfoSet, pFileInfo); } } taosArrayDestroy(pLogInfoArray); - pWal->writeCur = newSz - 1; - if (newSz > 0) { + pWal->writeCur = actualFileNum - 1; + if (actualFileNum > 0) { pWal->vers.firstVer = ((SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, 0))->firstVer; - SWalFileInfo* pLastFileInfo = taosArrayGet(pWal->fileInfoSet, newSz - 1); + SWalFileInfo* pLastFileInfo = taosArrayGet(pWal->fileInfoSet, actualFileNum - 1); char fnameStr[WAL_FILE_LEN]; walBuildLogName(pWal, pLastFileInfo->firstVer, fnameStr); - int64_t file_size = 0; - taosStatFile(fnameStr, &file_size, NULL); + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + /*ASSERT(fileSize != 0);*/ - if (oldSz != newSz || pLastFileInfo->fileSize != file_size) { - pLastFileInfo->fileSize = file_size; + if (metaFileNum != actualFileNum || pLastFileInfo->fileSize != fileSize) { + pLastFileInfo->fileSize = fileSize; pWal->vers.lastVer = walScanLogGetLastVer(pWal); ((SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet))->lastVer = pWal->vers.lastVer; ASSERT(pWal->vers.lastVer != -1); @@ -382,9 +401,9 @@ int walLoadMeta(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildMetaName(pWal, metaVer, fnameStr); // read metafile - int64_t file_size = 0; - taosStatFile(fnameStr, &file_size, NULL); - int size = (int)file_size; + int64_t fileSize = 0; + taosStatFile(fnameStr, &fileSize, NULL); + int size = (int)fileSize; char* buf = taosMemoryMalloc(size + 5); if (buf == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index eb0c7f56bd..908523f2a6 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -66,6 +66,7 @@ void walCloseReader(SWalReader *pRead) { } int32_t walNextValidMsg(SWalReader *pRead) { + wDebug("vgId:%d wal start to fetch", pRead->pWal->cfg.vgId); int64_t fetchVer = pRead->curVersion; int64_t endVer = pRead->cond.scanUncommited ? walGetLastVer(pRead->pWal) : walGetCommittedVer(pRead->pWal); while (fetchVer <= endVer) { @@ -176,7 +177,7 @@ int32_t walReadSeekVerImpl(SWalReader *pRead, int64_t ver) { return -1; } - wDebug("wal version reset from %ld to %ld", pRead->curVersion, ver); + wDebug("wal version reset from %ld(invalid: %d) to %ld", pRead->curVersion, pRead->curInvalid, ver); pRead->curVersion = ver; return 0; @@ -242,6 +243,7 @@ static int32_t walFetchHeadNew(SWalReader *pRead, int64_t fetchVer) { return -1; } } + pRead->curInvalid = 0; return 0; } @@ -301,6 +303,7 @@ static int32_t walSkipFetchBodyNew(SWalReader *pRead) { int64_t code; ASSERT(pRead->curVersion == pRead->pHead->head.version); + ASSERT(pRead->curInvalid == 0); code = taosLSeekFile(pRead->pLogFile, pRead->pHead->head.bodyLen, SEEK_CUR); if (code < 0) { @@ -404,6 +407,7 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) { } int32_t walReadVer(SWalReader *pRead, int64_t ver) { + wDebug("vgId:%d wal start to read ver %ld", pRead->pWal->cfg.vgId, ver); int64_t contLen; bool seeked = false; diff --git a/source/libs/wal/src/walSeek.c b/source/libs/wal/src/walSeek.c index b99206fe98..78d45c84e2 100644 --- a/source/libs/wal/src/walSeek.c +++ b/source/libs/wal/src/walSeek.c @@ -48,7 +48,7 @@ static int64_t walSeekWritePos(SWal* pWal, int64_t ver) { return 0; } -int walSetWrite(SWal* pWal) { +int walInitWriteFile(SWal* pWal) { TdFilePtr pIdxTFile, pLogTFile; SWalFileInfo* pRet = taosArrayGetLast(pWal->fileInfoSet); ASSERT(pRet != NULL); @@ -70,6 +70,7 @@ int walSetWrite(SWal* pWal) { // switch file pWal->pWriteIdxTFile = pIdxTFile; pWal->pWriteLogTFile = pLogTFile; + pWal->writeCur = taosArrayGetSize(pWal->fileInfoSet) - 1; return 0; } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 900d866a1d..26dc3cdffb 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -99,7 +99,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // delete files int fileSetSize = taosArrayGetSize(pWal->fileInfoSet); - for (int i = pWal->writeCur; i < fileSetSize; i++) { + for (int i = pWal->writeCur + 1; i < fileSetSize; i++) { walBuildLogName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr); taosRemoveFile(fnameStr); walBuildIdxName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr); @@ -113,18 +113,21 @@ int32_t walRollback(SWal *pWal, int64_t ver) { TdFilePtr pIdxTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND); if (pIdxTFile == NULL) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } int64_t idxOff = walGetVerIdxOffset(pWal, ver); code = taosLSeekFile(pIdxTFile, idxOff, SEEK_SET); if (code < 0) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } // read idx file and get log file pos SWalIdxEntry entry; if (taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } @@ -133,12 +136,14 @@ int32_t walRollback(SWal *pWal, int64_t ver) { walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr); TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ | TD_FILE_APPEND); if (pLogTFile == NULL) { + ASSERT(0); // TODO taosThreadMutexUnlock(&pWal->mutex); return -1; } code = taosLSeekFile(pLogTFile, entry.offset, SEEK_SET); if (code < 0) { + ASSERT(0); // TODO taosThreadMutexUnlock(&pWal->mutex); return -1; @@ -148,6 +153,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { ASSERT(taosValidFile(pLogTFile)); int64_t size = taosReadFile(pLogTFile, &head, sizeof(SWalCkHead)); if (size != sizeof(SWalCkHead)) { + ASSERT(0); taosThreadMutexUnlock(&pWal->mutex); return -1; } @@ -201,19 +207,49 @@ int32_t walRollback(SWal *pWal, int64_t ver) { return 0; } +static FORCE_INLINE int32_t walCheckAndRoll(SWal *pWal) { + if (taosArrayGetSize(pWal->fileInfoSet) == 0) { + /*pWal->vers.firstVer = index;*/ + if (walRollImpl(pWal) < 0) { + return -1; + } + } else { + int64_t passed = walGetSeq() - pWal->lastRollSeq; + if (pWal->cfg.rollPeriod != -1 && pWal->cfg.rollPeriod != 0 && passed > pWal->cfg.rollPeriod) { + if (walRollImpl(pWal) < 0) { + return -1; + } + } else if (pWal->cfg.segSize != -1 && pWal->cfg.segSize != 0 && walGetLastFileSize(pWal) > pWal->cfg.segSize) { + if (walRollImpl(pWal) < 0) { + return -1; + } + } + } + return 0; +} + int32_t walBeginSnapshot(SWal *pWal, int64_t ver) { pWal->vers.verInSnapshotting = ver; // check file rolling if (pWal->cfg.retentionPeriod == 0) { - walRoll(pWal); + taosThreadMutexLock(&pWal->mutex); + if (walGetLastFileSize(pWal) != 0) { + walRollImpl(pWal); + } + taosThreadMutexUnlock(&pWal->mutex); } return 0; } int32_t walEndSnapshot(SWal *pWal) { + int32_t code = 0; + taosThreadMutexLock(&pWal->mutex); int64_t ver = pWal->vers.verInSnapshotting; - if (ver == -1) return 0; + if (ver == -1) { + code = -1; + goto END; + }; pWal->vers.snapshotVer = ver; int ts = taosGetTimestampSec(); @@ -229,7 +265,7 @@ int32_t walEndSnapshot(SWal *pWal) { } // iterate files, until the searched result for (SWalFileInfo *iter = pWal->fileInfoSet->pData; iter < pInfo; iter++) { - if ((pWal->cfg.retentionSize != -1 && pWal->totSize > pWal->cfg.retentionSize) || + if ((pWal->cfg.retentionSize != -1 && newTotSize > pWal->cfg.retentionSize) || (pWal->cfg.retentionPeriod != -1 && iter->closeTs + pWal->cfg.retentionPeriod > ts)) { // delete according to file size or close time deleteCnt++; @@ -259,28 +295,30 @@ int32_t walEndSnapshot(SWal *pWal) { pWal->vers.verInSnapshotting = -1; // save snapshot ver, commit ver - int code = walSaveMeta(pWal); + code = walSaveMeta(pWal); if (code < 0) { - return -1; + goto END; } - return 0; +END: + taosThreadMutexUnlock(&pWal->mutex); + return code; } -int walRoll(SWal *pWal) { +int32_t walRollImpl(SWal *pWal) { int32_t code = 0; if (pWal->pWriteIdxTFile != NULL) { code = taosCloseFile(&pWal->pWriteIdxTFile); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + goto END; } } if (pWal->pWriteLogTFile != NULL) { code = taosCloseFile(&pWal->pWriteLogTFile); if (code != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + goto END; } } TdFilePtr pIdxTFile, pLogTFile; @@ -291,18 +329,20 @@ int walRoll(SWal *pWal) { pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + code = -1; + goto END; } walBuildLogName(pWal, newFileFirstVersion, fnameStr); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + code = -1; + goto END; } - // terrno set inner + // error code was set inner code = walRollFileInfo(pWal); if (code != 0) { - return -1; + goto END; } // switch file @@ -312,10 +352,14 @@ int walRoll(SWal *pWal) { ASSERT(pWal->writeCur >= 0); pWal->lastRollSeq = walGetSeq(); - return 0; + + walSaveMeta(pWal); + +END: + return code; } -static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { +static int32_t walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { SWalIdxEntry entry = {.ver = ver, .offset = offset}; int64_t idxOffset = taosLSeekFile(pWal->pWriteIdxTFile, 0, SEEK_END); wDebug("vgId:%d, write index, index:%" PRId64 ", offset:%" PRId64 ", at %" PRId64, pWal->cfg.vgId, ver, offset, @@ -329,61 +373,14 @@ static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { return 0; } -int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLogMeta syncMeta, const void *body, - int32_t bodyLen) { - int32_t code = 0; - - // no wal - if (pWal->cfg.level == TAOS_WAL_NOLOG) return 0; - - if (bodyLen > TSDB_MAX_WAL_SIZE) { - terrno = TSDB_CODE_WAL_SIZE_LIMIT; - return -1; - } - taosThreadMutexLock(&pWal->mutex); - - if (index == pWal->vers.lastVer + 1) { - if (taosArrayGetSize(pWal->fileInfoSet) == 0) { - pWal->vers.firstVer = index; - if (walRoll(pWal) < 0) { - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - } else { - int64_t passed = walGetSeq() - pWal->lastRollSeq; - if (pWal->cfg.rollPeriod != -1 && pWal->cfg.rollPeriod != 0 && passed > pWal->cfg.rollPeriod) { - if (walRoll(pWal) < 0) { - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - } else if (pWal->cfg.segSize != -1 && pWal->cfg.segSize != 0 && walGetLastFileSize(pWal) > pWal->cfg.segSize) { - if (walRoll(pWal) < 0) { - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - } - } - } else { - // reject skip log or rewrite log - // must truncate explicitly first - terrno = TSDB_CODE_WAL_INVALID_VER; - taosThreadMutexUnlock(&pWal->mutex); - return -1; - } - - /*if (!tfValid(pWal->pWriteLogTFile)) return -1;*/ - - ASSERT(pWal->writeCur >= 0); - - if (pWal->pWriteIdxTFile == NULL || pWal->pWriteLogTFile == NULL) { - walSetWrite(pWal); - taosLSeekFile(pWal->pWriteLogTFile, 0, SEEK_END); - taosLSeekFile(pWal->pWriteIdxTFile, 0, SEEK_END); - } - - pWal->writeHead.head.version = index; +// TODO gurantee atomicity by truncate failed writing +static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, + const void *body, int32_t bodyLen) { + int64_t code = 0; int64_t offset = walGetCurFileOffset(pWal); + + pWal->writeHead.head.version = index; pWal->writeHead.head.bodyLen = bodyLen; pWal->writeHead.head.msgType = msgType; @@ -398,7 +395,8 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog terrno = TAOS_SYSTEM_ERROR(errno); wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); - return -1; + code = -1; + goto END; } if (taosWriteFile(pWal->pWriteLogTFile, (char *)body, bodyLen) != bodyLen) { @@ -406,13 +404,14 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog terrno = TAOS_SYSTEM_ERROR(errno); wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); - return -1; + code = -1; + goto END; } code = walWriteIndex(pWal, index, offset); - if (code != 0) { - // TODO - return -1; + if (code < 0) { + // TODO ftruncate + goto END; } // set status @@ -425,13 +424,88 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog walGetCurFileInfo(pWal)->lastVer = index; walGetCurFileInfo(pWal)->fileSize += sizeof(SWalCkHead) + bodyLen; - taosThreadMutexUnlock(&pWal->mutex); - return 0; +END: + return -1; +} + +int64_t walAppendLog(SWal *pWal, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen) { + if (bodyLen > TSDB_MAX_WAL_SIZE) { + terrno = TSDB_CODE_WAL_SIZE_LIMIT; + return -1; + } + + taosThreadMutexLock(&pWal->mutex); + + int64_t index = pWal->vers.lastVer + 1; + + if (walCheckAndRoll(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + if (pWal->pWriteIdxTFile == NULL || pWal->pWriteIdxTFile == NULL || pWal->writeCur < 0) { + if (walInitWriteFile(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + } + + ASSERT(pWal->pWriteIdxTFile != NULL && pWal->pWriteLogTFile != NULL && pWal->writeCur >= 0); + + if (walWriteImpl(pWal, index, msgType, syncMeta, body, bodyLen) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + taosThreadMutexUnlock(&pWal->mutex); + return index; +} + +int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, + int32_t bodyLen) { + int32_t code = 0; + + if (bodyLen > TSDB_MAX_WAL_SIZE) { + terrno = TSDB_CODE_WAL_SIZE_LIMIT; + return -1; + } + taosThreadMutexLock(&pWal->mutex); + + // concurrency control: + // if logs are write with assigned index, + // smaller index must be write before larger one + if (index != pWal->vers.lastVer + 1) { + terrno = TSDB_CODE_WAL_INVALID_VER; + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + if (walCheckAndRoll(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + if (pWal->pWriteIdxTFile == NULL || pWal->pWriteIdxTFile == NULL || pWal->writeCur < 0) { + if (walInitWriteFile(pWal) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + } + + ASSERT(pWal->pWriteIdxTFile != NULL && pWal->pWriteLogTFile != NULL && pWal->writeCur >= 0); + + if (walWriteImpl(pWal, index, msgType, syncMeta, body, bodyLen) < 0) { + taosThreadMutexUnlock(&pWal->mutex); + return -1; + } + + taosThreadMutexUnlock(&pWal->mutex); + return code; } int32_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen) { - SSyncLogMeta syncMeta = { + SWalSyncInfo syncMeta = { .isWeek = -1, .seqNum = UINT64_MAX, .term = UINT64_MAX, diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 243a234abe..b755a35815 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -106,8 +106,8 @@ int32_t taosMkDir(const char *dirname) { int32_t taosMulMkDir(const char *dirname) { if (dirname == NULL) return -1; - char temp[1024]; - char * pos = temp; + char temp[1024]; + char *pos = temp; int32_t code = 0; #ifdef WINDOWS taosRealPath(dirname, temp, sizeof(temp)); @@ -127,11 +127,11 @@ int32_t taosMulMkDir(const char *dirname) { for (; *pos != '\0'; pos++) { if (*pos == TD_DIRSEP[0]) { *pos = '\0'; - #ifdef WINDOWS +#ifdef WINDOWS code = _mkdir(temp, 0755); - #else +#else code = mkdir(temp, 0755); - #endif +#endif if (code < 0 && errno != EEXIST) { return code; } @@ -140,11 +140,11 @@ int32_t taosMulMkDir(const char *dirname) { } if (*(pos - 1) != TD_DIRSEP[0]) { - #ifdef WINDOWS +#ifdef WINDOWS code = _mkdir(temp, 0755); - #else +#else code = mkdir(temp, 0755); - #endif +#endif if (code < 0 && errno != EEXIST) { return code; } @@ -267,7 +267,7 @@ char *taosDirName(char *name) { } else { name[0] = 0; } - return name; + return name; #else return dirname(name); #endif @@ -334,9 +334,9 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) { } char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) { - if (pDirEntry == NULL) { - return NULL; - } + /*if (pDirEntry == NULL) {*/ + /*return NULL;*/ + /*}*/ #ifdef WINDOWS return pDirEntry->findFileData.cFileName; #else diff --git a/source/util/src/tlockfree.c b/source/util/src/tlockfree.c index a755a67cc8..6f7b6f6901 100644 --- a/source/util/src/tlockfree.c +++ b/source/util/src/tlockfree.c @@ -53,6 +53,7 @@ void taosWLockLatch(SRWLatch *pLatch) { } } +// no reentrant int32_t taosWTryLockLatch(SRWLatch *pLatch) { SRWLatch oLatch, nLatch; oLatch = atomic_load_32(pLatch); @@ -90,4 +91,4 @@ void taosRLockLatch(SRWLatch *pLatch) { } } -void taosRUnLockLatch(SRWLatch *pLatch) { atomic_fetch_sub_32(pLatch, 1); } \ No newline at end of file +void taosRUnLockLatch(SRWLatch *pLatch) { atomic_fetch_sub_32(pLatch, 1); } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 94311bc435..50beba8a9b 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -115,7 +115,7 @@ bool taosQueueEmpty(STaosQueue *queue) { bool empty = false; taosThreadMutexLock(&queue->mutex); - if (queue->head == NULL && queue->tail == NULL) { + if (queue->head == NULL && queue->tail == NULL && queue->numOfItems == 0 && queue->memOfItems == 0) { empty = true; } taosThreadMutexUnlock(&queue->mutex); @@ -123,6 +123,14 @@ bool taosQueueEmpty(STaosQueue *queue) { return empty; } +void taosUpdateItemSize(STaosQueue *queue, int32_t items) { + if (queue == NULL) return; + + taosThreadMutexLock(&queue->mutex); + queue->numOfItems -= items; + taosThreadMutexUnlock(&queue->mutex); +} + int32_t taosQueueItemSize(STaosQueue *queue) { if (queue == NULL) return 0; @@ -257,6 +265,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) { queue->tail = NULL; queue->numOfItems = 0; queue->memOfItems = 0; + uTrace("read %d items from queue:%p, items:%d mem:%" PRId64, code, queue, queue->numOfItems, queue->memOfItems); if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems); } @@ -397,7 +406,7 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) { int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; } -int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, int64_t *ts, void **ahandle, FItem *itemFp) { +int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) { STaosQnode *pNode = NULL; int32_t code = 0; @@ -417,17 +426,18 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, int64_t *ts, void if (queue->head) { pNode = queue->head; *ppItem = pNode->item; - if (ahandle) *ahandle = queue->ahandle; - if (itemFp) *itemFp = queue->itemFp; - if (ts) *ts = pNode->timestamp; + qinfo->ahandle = queue->ahandle; + qinfo->fp = queue->itemFp; + qinfo->queue = queue; + qinfo->timestamp = pNode->timestamp; queue->head = pNode->next; if (queue->head == NULL) queue->tail = NULL; - queue->numOfItems--; + // queue->numOfItems--; queue->memOfItems -= pNode->size; atomic_sub_fetch_32(&qset->numOfItems, 1); code = 1; - uTrace("item:%p is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems, + uTrace("item:%p is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems - 1, queue->memOfItems); } @@ -440,7 +450,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, int64_t *ts, void return code; } -int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahandle, FItems *itemsFp) { +int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo *qinfo) { STaosQueue *queue; int32_t code = 0; @@ -461,13 +471,16 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand qall->start = queue->head; qall->numOfItems = queue->numOfItems; code = qall->numOfItems; - if (ahandle) *ahandle = queue->ahandle; - if (itemsFp) *itemsFp = queue->itemsFp; + qinfo->ahandle = queue->ahandle; + qinfo->fp = queue->itemsFp; + qinfo->queue = queue; queue->head = NULL; queue->tail = NULL; - queue->numOfItems = 0; + // queue->numOfItems = 0; queue->memOfItems = 0; + uTrace("read %d items from queue:%p, items:0 mem:%" PRId64, code, queue, queue->memOfItems); + atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems); for (int32_t j = 1; j < qall->numOfItems; ++j) { tsem_wait(&qset->sem); diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 88bd36f0cb..1f0731812c 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -70,27 +70,27 @@ void tQWorkerCleanup(SQWorkerPool *pool) { static void *tQWorkerThreadFp(SQWorker *worker) { SQWorkerPool *pool = worker->pool; - FItem fp = NULL; - - void *msg = NULL; - void *ahandle = NULL; - int32_t code = 0; - int64_t ts = 0; + SQueueInfo qinfo = {0}; + void *msg = NULL; + int32_t code = 0; taosBlockSIGPIPE(); setThreadName(pool->name); uDebug("worker:%s:%d is running", pool->name, worker->id); while (1) { - if (taosReadQitemFromQset(pool->qset, (void **)&msg, &ts, &ahandle, &fp) == 0) { + if (taosReadQitemFromQset(pool->qset, (void **)&msg, &qinfo) == 0) { uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, pool->qset); break; } - if (fp != NULL) { - SQueueInfo info = {.ahandle = ahandle, .workerId = worker->id, .threadNum = pool->num, .timestamp = ts}; - (*fp)(&info, msg); + if (qinfo.fp != NULL) { + qinfo.workerId = worker->id; + qinfo.threadNum = pool->num; + (*((FItem)qinfo.fp))(&qinfo, msg); } + + taosUpdateItemSize(qinfo.queue, 1); } return NULL; @@ -195,28 +195,28 @@ void tWWorkerCleanup(SWWorkerPool *pool) { static void *tWWorkerThreadFp(SWWorker *worker) { SWWorkerPool *pool = worker->pool; - FItems fp = NULL; - - void *msg = NULL; - void *ahandle = NULL; - int32_t numOfMsgs = 0; - int32_t qtype = 0; + SQueueInfo qinfo = {0}; + void *msg = NULL; + int32_t code = 0; + int32_t numOfMsgs = 0; taosBlockSIGPIPE(); setThreadName(pool->name); uDebug("worker:%s:%d is running", pool->name, worker->id); while (1) { - numOfMsgs = taosReadAllQitemsFromQset(worker->qset, worker->qall, &ahandle, &fp); + numOfMsgs = taosReadAllQitemsFromQset(worker->qset, worker->qall, &qinfo); if (numOfMsgs == 0) { uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, worker->qset); break; } - if (fp != NULL) { - SQueueInfo info = {.ahandle = ahandle, .workerId = worker->id, .threadNum = pool->num}; - (*fp)(&info, worker->qall, numOfMsgs); + if (qinfo.fp != NULL) { + qinfo.workerId = worker->id; + qinfo.threadNum = pool->num; + (*((FItems)qinfo.fp))(&qinfo, worker->qall, numOfMsgs); } + taosUpdateItemSize(qinfo.queue, numOfMsgs); } return NULL; diff --git a/tests/pytest/crash_gen/shared/misc.py b/tests/pytest/crash_gen/shared/misc.py index 78923bcc29..fd73f97fcb 100644 --- a/tests/pytest/crash_gen/shared/misc.py +++ b/tests/pytest/crash_gen/shared/misc.py @@ -4,7 +4,8 @@ import logging import os import sys from typing import Optional - +import time , datetime +from datetime import datetime import taos @@ -43,6 +44,10 @@ class MyLoggingAdapter(logging.LoggerAdapter): class Logging: logger = None # type: Optional[MyLoggingAdapter] + @classmethod + def _get_datetime(cls): + return datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-1] + @classmethod def getLogger(cls): return cls.logger @@ -64,22 +69,22 @@ class Logging: # global logger cls.logger = MyLoggingAdapter(_logger, {}) cls.logger.setLevel(logging.DEBUG if debugMode else logging.INFO) # default seems to be INFO - + @classmethod def info(cls, msg): - cls.logger.info(msg) + cls.logger.info("[time]: " + cls._get_datetime() +" [msg]: "+ msg) @classmethod def debug(cls, msg): - cls.logger.debug(msg) + cls.logger.debug("[time]: " + cls._get_datetime() +" [msg]: "+ msg) @classmethod def warning(cls, msg): - cls.logger.warning(msg) + cls.logger.warning("[time]: " + cls._get_datetime() +" [msg]: "+ msg) @classmethod def error(cls, msg): - cls.logger.error(msg) + cls.logger.error("[time]: " + cls._get_datetime() +" [msg]: "+ msg) class Status: STATUS_EMPTY = 99 diff --git a/tests/pytest/util/sqlset.py b/tests/pytest/util/sqlset.py index 1897b3cf23..bccd49a209 100644 --- a/tests/pytest/util/sqlset.py +++ b/tests/pytest/util/sqlset.py @@ -41,6 +41,30 @@ class TDSetSql: create_stb_sql = f'create table {stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})' return create_stb_sql + def set_insertsql(self,column_dict,tbname,binary_str,nchar_str): + sql = '' + for k, v in column_dict.items(): + if v.lower() == 'timestamp' or v.lower() == 'tinyint' or v.lower() == 'smallint' or v.lower() == 'int' or v.lower() == 'bigint' or \ + v.lower() == 'tinyint unsigned' or v.lower() == 'smallint unsigned' or v.lower() == 'int unsigned' or v.lower() == 'bigint unsigned' or v.lower() == 'bool': + sql += '%d,' + elif v.lower() == 'float' or v.lower() == 'double': + sql += '%f,' + elif 'binary' in v.lower(): + sql += f'"{binary_str}%d",' + elif 'nchar' in v.lower(): + sql += f'"{nchar_str}%d",' + return (f'insert into {tbname} values({sql[:-1]})') - - \ No newline at end of file + def insert_values(self,column_dict,i,insert_sql,insert_list,ts): + for k, v in column_dict.items(): + if v.lower() in[ 'tinyint' , 'smallint' , 'int', 'bigint' , 'tinyint unsigned' , 'smallint unsigned' , 'int unsigned' , 'bigint unsigned'] or\ + 'binary' in v.lower() or 'nchar' in v.lower(): + insert_list.append(0 + i) + elif v.lower() == 'float' or v.lower() == 'double': + insert_list.append(0.1 + i) + elif v.lower() == 'bool': + insert_list.append(i % 2) + elif v.lower() == 'timestamp': + insert_list.append(ts + i) + tdSql.execute(insert_sql%(tuple(insert_list))) + \ No newline at end of file diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 94414edbf2..50d4c04a93 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -96,11 +96,11 @@ ./test.sh -f tsim/stream/basic2.sim ./test.sh -f tsim/stream/drop_stream.sim ./test.sh -f tsim/stream/distributeInterval0.sim -# ./test.sh -f tsim/stream/distributeIntervalRetrive0.sim +./test.sh -f tsim/stream/distributeIntervalRetrive0.sim # ./test.sh -f tsim/stream/distributesession0.sim ./test.sh -f tsim/stream/session0.sim ./test.sh -f tsim/stream/session1.sim -# ./test.sh -f tsim/stream/state0.sim +./test.sh -f tsim/stream/state0.sim ./test.sh -f tsim/stream/triggerInterval0.sim # ./test.sh -f tsim/stream/triggerSession0.sim ./test.sh -f tsim/stream/partitionby.sim @@ -164,12 +164,13 @@ # --- sma ./test.sh -f tsim/sma/drop_sma.sim ./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim -#./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim -#./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim +./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim +./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim # --- valgrind ./test.sh -f tsim/valgrind/checkError1.sim ./test.sh -f tsim/valgrind/checkError2.sim +./test.sh -f tsim/valgrind/checkError3.sim # --- vnode # ./test.sh -f tsim/vnode/replica3_basic.sim diff --git a/tests/script/tsim/query/scalarNull.sim b/tests/script/tsim/query/scalarNull.sim index 07bd5e57cd..ae4b2a9624 100644 --- a/tests/script/tsim/query/scalarNull.sim +++ b/tests/script/tsim/query/scalarNull.sim @@ -89,5 +89,10 @@ endi #TODO: MOVE IT TO NORMAL CASE sql_error select * from tb1 where not (null); +sql select sum(1/0) from tb1; +if $rows != 1 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stream/distributeIntervalRetrive0.sim b/tests/script/tsim/stream/distributeIntervalRetrive0.sim index cde5c7058f..32170e3c41 100644 --- a/tests/script/tsim/stream/distributeIntervalRetrive0.sim +++ b/tests/script/tsim/stream/distributeIntervalRetrive0.sim @@ -76,7 +76,7 @@ if $data01 != 5 then goto loop1 endi -if $data02 != 14 then +if $data02 != 38 then print =====data02=$data02 goto loop1 endi @@ -134,7 +134,7 @@ if $data01 != 6 then goto loop2 endi -if $data02 != 18 then +if $data02 != 42 then print =====data02=$data02 goto loop2 endi @@ -192,7 +192,7 @@ if $data01 != 7 then goto loop3 endi -if $data02 != 22 then +if $data02 != 46 then print =====data02=$data02 goto loop3 endi @@ -232,60 +232,4 @@ endi print loop3 over -$loop_count = 0 -loop4: -sleep 1000 -sql select * from streamtST1; - -$loop_count = $loop_count + 1 -if $loop_count == 10 then - return -1 -endi - -# row 0 -if $data01 != 7 then - print =====data01=$data01 - goto loop4 -endi - -if $data02 != 22 then - print =====data02=$data02 - goto loop4 -endi - -# row 1 -if $data11 != 3 then - print =====data11=$data11 - goto loop4 -endi - -if $data12 != 10 then - print =====data12=$data12 - goto loop4 -endi - -#row2 -if $data21 != 3 then - print =====data21=$data21 - goto loop4 -endi - -if $data22 != 11 then - print =====data22=$data22 - goto loop4 -endi - -#row 3 -if $data31 != 5 then - print =====data31=$data31 - goto loop4 -endi - -if $data32 != 60 then - print =====data32=$data32 - goto loop4 -endi - -print loop4 over - system sh/stop_dnodes.sh diff --git a/tests/script/tsim/sync/electTest.sim b/tests/script/tsim/sync/electTest.sim new file mode 100644 index 0000000000..5433434014 --- /dev/null +++ b/tests/script/tsim/sync/electTest.sim @@ -0,0 +1,193 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 + +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 + +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +if $data[0][0] != 1 then + return -1 +endi +if $data[0][4] != ready then + goto check_dnode_ready +endi + +sql connect +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 + +$loop_cnt = 0 +check_dnode_ready_1: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 10 then + print ====> dnodes not ready! + return -1 +endi +sql show dnodes +print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +if $data[0][4] != ready then + goto check_dnode_ready_1 +endi +if $data[1][4] != ready then + goto check_dnode_ready_1 +endi +if $data[2][4] != ready then + goto check_dnode_ready_1 +endi +if $data[3][4] != ready then + goto check_dnode_ready_1 +endi + +$replica = 3 +$vgroups = 1 + +print ============= create database +sql create database db replica $replica vgroups $vgroups + +$loop_cnt = 0 +check_db_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 100 then + print ====> db not ready! + return -1 +endi +sql show databases +print ===> rows: $rows +print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][6] $data[2][11] $data[2][12] $data[2][13] $data[2][14] $data[2][15] $data[2][16] $data[2][17] $data[2][18] $data[2][19] +if $rows != 3 then + return -1 +endi +if $data[2][19] != ready then + goto check_db_ready +endi + +sql use db + +$loop_cnt = 0 +check_vg_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 300 then + print ====> vgroups not ready! + return -1 +endi + +sql show vgroups +print ===> rows: $rows +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11] + +if $rows != $vgroups then + return -1 +endi + +if $data[0][4] == leader then + if $data[0][6] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][3] + endi + endi +elif $data[0][6] == leader then + if $data[0][4] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][5] + endi + endi +elif $data[0][8] == leader then + if $data[0][4] == follower then + if $data[0][6] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][7] + endi + endi +else + goto check_vg_ready +endi + + +vg_ready: +print ====> create stable/child table +sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb tags(1000) + + +print ===> write 100 records +$N = 100 +$count = 0 +while $count < $N + $ms = 1591200000000 + $count + sql insert into ct1 values( $ms , $count , 2.1, 3.1) + $count = $count + 1 +endw + + +#sql flush database db; + + +sleep 3000 + + +print ===> stop dnode1 dnode2 dnode3 dnode4 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT +system sh/exec.sh -n dnode4 -s stop -x SIGINT + + + +######################################################## +print ===> start dnode1 dnode2 dnode3 dnode4 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +sleep 3000 + +print =============== query data +sql connect +sql use db +sql select * from ct1 +print rows: $rows +print $data00 $data01 $data02 +if $rows != 100 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT +#system sh/exec.sh -n dnode2 -s stop -x SIGINT +#system sh/exec.sh -n dnode3 -s stop -x SIGINT +#system sh/exec.sh -n dnode4 -s stop -x SIGINT +######################################################### + + + diff --git a/tests/script/tsim/sync/vnodesnapshot-test.sim b/tests/script/tsim/sync/vnodesnapshot-test.sim new file mode 100644 index 0000000000..3cf8cb4d93 --- /dev/null +++ b/tests/script/tsim/sync/vnodesnapshot-test.sim @@ -0,0 +1,270 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 + +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 + +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +if $data[0][0] != 1 then + return -1 +endi +if $data[0][4] != ready then + goto check_dnode_ready +endi + +sql connect +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 + +$loop_cnt = 0 +check_dnode_ready_1: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 10 then + print ====> dnodes not ready! + return -1 +endi +sql show dnodes +print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +if $data[0][4] != ready then + goto check_dnode_ready_1 +endi +if $data[1][4] != ready then + goto check_dnode_ready_1 +endi +if $data[2][4] != ready then + goto check_dnode_ready_1 +endi +if $data[3][4] != ready then + goto check_dnode_ready_1 +endi + +$replica = 3 +$vgroups = 1 + +print ============= create database +sql create database db replica $replica vgroups $vgroups + +$loop_cnt = 0 +check_db_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 100 then + print ====> db not ready! + return -1 +endi +sql show databases +print ===> rows: $rows +print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][6] $data[2][11] $data[2][12] $data[2][13] $data[2][14] $data[2][15] $data[2][16] $data[2][17] $data[2][18] $data[2][19] +if $rows != 3 then + return -1 +endi +if $data[2][19] != ready then + goto check_db_ready +endi + +sql use db + +$loop_cnt = 0 +check_vg_ready: +$loop_cnt = $loop_cnt + 1 +sleep 200 +if $loop_cnt == 300 then + print ====> vgroups not ready! + return -1 +endi + +sql show vgroups +print ===> rows: $rows +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11] + +if $rows != $vgroups then + return -1 +endi + +if $data[0][4] == leader then + if $data[0][6] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][3] + endi + endi +elif $data[0][6] == leader then + if $data[0][4] == follower then + if $data[0][8] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][5] + endi + endi +elif $data[0][8] == leader then + if $data[0][4] == follower then + if $data[0][6] == follower then + print ---- vgroup $data[0][0] leader locate on dnode $data[0][7] + endi + endi +else + goto check_vg_ready +endi + + +vg_ready: +print ====> create stable/child table +sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb tags(1000) + + +print ===> stop dnode4 +system sh/exec.sh -n dnode4 -s stop -x SIGINT +sleep 3000 + + +print ===> write 100 records +$N = 100 +$count = 0 +while $count < $N + $ms = 1591200000000 + $count + sql insert into ct1 values( $ms , $count , 2.1, 3.1) + $count = $count + 1 +endw + + +#sql flush database db; + + +sleep 3000 + + +print ===> stop dnode1 dnode2 dnode3 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT + + + +######################################################## +print ===> start dnode1 dnode2 dnode3 dnode4 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +sleep 3000 + +print =============== query data +sql connect +sql use db +sql select * from ct1 +print rows: $rows +print $data00 $data01 $data02 +if $rows != 100 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT +system sh/exec.sh -n dnode4 -s stop -x SIGINT +######################################################## + + +######################################################## +print ===> start dnode1 dnode3 dnode4 +system sh/exec.sh -n dnode1 -s start +#system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +sleep 7000 + +print =============== query data +sql connect +sql use db +sql select * from ct1 +print rows: $rows +print $data00 $data01 $data02 +if $rows != 100 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +#system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT +system sh/exec.sh -n dnode4 -s stop -x SIGINT +######################################################## + + +######################################################## +print ===> start dnode1 dnode2 dnode4 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +#system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start + +sleep 3000 + +print =============== query data +sql select * from ct1 +print rows: $rows +print $data00 $data01 $data02 +if $rows != 100 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +#system sh/exec.sh -n dnode3 -s stop -x SIGINT +system sh/exec.sh -n dnode4 -s stop -x SIGINT +######################################################## + + +######################################################## +print ===> start dnode1 dnode2 dnode3 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +#system sh/exec.sh -n dnode4 -s start + +sleep 3000 + +print =============== query data +sql select * from ct1 +print rows: $rows +print $data00 $data01 $data02 +if $rows != 100 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT +#system sh/exec.sh -n dnode4 -s stop -x SIGINT +######################################################## + + diff --git a/tests/script/tsim/valgrind/basic1.sim b/tests/script/tsim/valgrind/basic1.sim index 2c5b8a5d96..f0430195c9 100644 --- a/tests/script/tsim/valgrind/basic1.sim +++ b/tests/script/tsim/valgrind/basic1.sim @@ -35,36 +35,51 @@ if $rows != 1 then return -1 endi -print =============== step3: create show table +print =============== step4: create show table sql create table ct1 using stb tags(1000) +sql create table ct2 using stb tags(2000) +sql create table ct3 using stb tags(3000) sql show tables -if $rows != 1 then +if $rows != 3 then return -1 endi print =============== step5: insert data sql insert into ct1 values(now+0s, 10, 2.0, 3.0) sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) +sql insert into ct2 values(now+0s, 10, 2.0, 3.0) +sql insert into ct2 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) +sql insert into ct3 values('2021-01-01 00:00:00.000', 10, 2.0, 3.0) -print =============== step6: select data -#sql select * from ct1 -#sql select * from stb +print =============== step6: query data +sql select * from ct1 +sql select * from stb +sql select c1, c2, c3 from ct1 +sql select ts, c1, c2, c3 from stb + +print =============== step7: count +sql select count(*) from ct1; +#sql select count(*) from stb; +#sql select count(ts), count(c1), count(c2), count(c3) from ct1 +#sql select count(ts), count(c1), count(c2), count(c3) from stb + +print =============== step8: func +#sql select first(ts), first(c1), first(c2), first(c3) from ct1 +#sql select min(c1), min(c2), min(c3) from ct1 +#sql select max(c1), max(c2), max(c3) from ct1 +#sql select sum(c1), sum(c2), sum(c3) from ct1 _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT - print =============== check -print ----> start to check if there are ERRORS in vagrind log file for each dnode -system_content sh/checkValgrind.sh -n dnode1 - -print cmd return result ----> [ $system_content ] -if $system_content <= 0 then - return 0 -endi - $null= -if $system_content == $null then - return 0 + +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result ----> [ $system_content ] +if $system_content > 1 then + return -1 endi -return -1 +if $system_content == $null then + return -1 +endi diff --git a/tests/script/tsim/valgrind/basic2.sim b/tests/script/tsim/valgrind/basic2.sim index 154617bc18..15e092da35 100644 --- a/tests/script/tsim/valgrind/basic2.sim +++ b/tests/script/tsim/valgrind/basic2.sim @@ -23,48 +23,74 @@ if $data(1)[4] != ready then endi print =============== step2: create db -sql create database d1 vgroups 1 buffer 3 +sql create database d1 vgroups 3 buffer 3 sql show databases sql use d1 sql show vgroups -print =============== step3: create show stable -sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned) +print =============== step3: create show stable, include all type +sql create table if not exists stb (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(16), c9 nchar(16), c10 timestamp, c11 tinyint unsigned, c12 smallint unsigned, c13 int unsigned, c14 bigint unsigned) tags (t1 bool, t2 tinyint, t3 smallint, t4 int, t5 bigint, t6 float, t7 double, t8 binary(16), t9 nchar(16), t10 timestamp, t11 tinyint unsigned, t12 smallint unsigned, t13 int unsigned, t14 bigint unsigned) +sql create stable if not exists stb_1 (ts timestamp, c1 int) tags (j int) +sql create table stb_2 (ts timestamp, c1 int) tags (t1 int) +sql create stable stb_3 (ts timestamp, c1 int) tags (t1 int) sql show stables -if $rows != 1 then +if $rows != 4 then return -1 endi -print =============== step3: create show table -sql create table ct1 using stb tags(1000) -#sql show tables -#if $rows != 1 then -# return -1 -#endi +print =============== step4: ccreate child table +sql create table c1 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql create table c2 using stb tags(false, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 2', 'child tbl 2', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql show tables +if $rows != 2 then + return -1 +endi print =============== step5: insert data -sql insert into ct1 values(now+0s, 10, 2.0, 3.0) -sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) +sql insert into c1 values(now-1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+2s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c2 values(now-1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c2 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+2s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) -print =============== step6: select data -sql select * from ct1 +print =============== step6: alter insert +sql insert into c3 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) values(now-1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c3 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) + +goto _OVER +print =============== stepa: query data +sql select * from c1 sql select * from stb +sql select * from stb_1 +sql select ts, c1, c2, c3 from c1 +sql select ts, c1, c2, c3 from stb +sql select ts, c1 from stb_2 +sql select ts, c1, t1 from c1 +sql select ts, c1, t1 from stb +sql select ts, c1, t1 from stb_2 + +print =============== stepb: count +#sql select count(*) from c1; +#sql select count(*) from stb; +#sql select count(ts), count(c1), count(c2), count(c3) from c1 +#sql select count(ts), count(c1), count(c2), count(c3) from stb + +print =============== stepc: func +#sql select first(ts), first(c1), first(c2), first(c3) from c1 +#sql select min(c1), min(c2), min(c3) from c1 +#sql select max(c1), max(c2), max(c3) from c1 +#sql select sum(c1), sum(c2), sum(c3) from c1 _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT - print =============== check -print ----> start to check if there are ERRORS in vagrind log file for each dnode -system_content sh/checkValgrind.sh -n dnode1 - -print cmd return result ----> [ $system_content ] -if $system_content <= 0 then - return 0 -endi - $null= -if $system_content == $null then - return 0 + +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result ----> [ $system_content ] +if $system_content > 1 then + return -1 endi -return -1 +if $system_content == $null then + return -1 +endi diff --git a/tests/script/tsim/valgrind/checkError1.sim b/tests/script/tsim/valgrind/checkError1.sim index 1a76d8ce5c..fe4f4654b1 100644 --- a/tests/script/tsim/valgrind/checkError1.sim +++ b/tests/script/tsim/valgrind/checkError1.sim @@ -36,7 +36,12 @@ sql create dnode $hostname port 7200 sql drop dnode 2 sql alter dnode 1 'debugflag 131' -print =============== step4: +print =============== create database, stable, table +sql create database db vgroups 3 +sql use db +sql create table stb (ts timestamp, c int) tags (t int) +sql create table t0 using stb tags (0) +sql create table tba (ts timestamp, c1 binary(10), c2 nchar(10)); print =============== run show xxxx sql show dnodes @@ -50,7 +55,17 @@ if $rows != 1 then endi sql show databases -if $rows != 2 then +if $rows != 3 then + return -1 +endi + +sql show stables +if $rows != 1 then + return -1 +endi + +sql show tables +if $rows != 2 then return -1 endi @@ -70,11 +85,31 @@ if $rows != 1 then return -1 endi +sql select * from information_schema.user_databases +if $rows != 3 then + return -1 +endi + +sql select * from information_schema.user_stables +if $rows != 1 then + return -1 +endi + +sql select * from information_schema.user_tables +if $rows != 30 then + return -1 +endi + sql select * from information_schema.user_users if $rows != 1 then return -1 endi +sql select * from information_schema.`vgroups` +if $rows != 3 then + return -1 +endi + sql show variables; if $rows != 4 then return -1 @@ -94,17 +129,14 @@ print =============== stop system sh/exec.sh -n dnode1 -s stop -x SIGINT print =============== check -print ----> start to check if there are ERRORS in vagrind log file for each dnode -system_content sh/checkValgrind.sh -n dnode1 - -print cmd return result ----> [ $system_content ] -if $system_content <= 0 then - return 0 -endi - $null= -if $system_content == $null then - return 0 + +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result ----> [ $system_content ] +if $system_content > 1 then + return -1 endi -return -1 +if $system_content == $null then + return -1 +endi diff --git a/tests/script/tsim/valgrind/checkError2.sim b/tests/script/tsim/valgrind/checkError2.sim index 3a2819776d..3939b7c854 100644 --- a/tests/script/tsim/valgrind/checkError2.sim +++ b/tests/script/tsim/valgrind/checkError2.sim @@ -35,12 +35,12 @@ if $rows != 1 then return -1 endi -print =============== step3: create show table +print =============== step4: create show table sql create table ct1 using stb tags(1000) -#sql show tables -#if $rows != 1 then -# return -1 -#endi +sql show tables +if $rows != 1 then + return -1 +endi print =============== step5: insert data sql insert into ct1 values(now+0s, 10, 2.0, 3.0) @@ -48,23 +48,20 @@ sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s print =============== step6: select data sql select * from ct1 -#sql select * from stb +sql select * from stb _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT print =============== check -print ----> start to check if there are ERRORS in vagrind log file for each dnode -system_content sh/checkValgrind.sh -n dnode1 - -print cmd return result ----> [ $system_content ] -if $system_content <= 2 then - return 0 -endi - $null= -if $system_content == $null then - return 0 + +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result ----> [ $system_content ] +if $system_content > 1 then + return -1 endi -return -1 +if $system_content == $null then + return -1 +endi diff --git a/tests/script/tsim/valgrind/checkError3.sim b/tests/script/tsim/valgrind/checkError3.sim index 5a60dfe254..d5a407f6f8 100644 --- a/tests/script/tsim/valgrind/checkError3.sim +++ b/tests/script/tsim/valgrind/checkError3.sim @@ -4,7 +4,7 @@ system sh/cfg.sh -n dnode1 -c debugflag -v 131 system sh/exec.sh -n dnode1 -s start -v sql connect -print =============== step1: show dnodes +print =============== step1: create drop show dnodes $x = 0 step1: $x = $x + 1 @@ -22,124 +22,74 @@ if $data(1)[4] != ready then goto step1 endi -print =============== step2: create alter drop show user -sql create user u1 pass 'taosdata' -sql show users -sql alter user u1 sysinfo 1 -sql alter user u1 enable 1 -sql alter user u1 pass 'taosdata' -sql drop user u1 -sql_error alter user u2 sysinfo 0 - -print =============== step3: create drop dnode -sql create dnode $hostname port 7200 -sql drop dnode 2 -sql alter dnode 1 'debugflag 131' - -print =============== create database, stable, table -sql create database db vgroups 3 -sql use db -sql create table stb (ts timestamp, c int) tags (t int) -sql create table t0 using stb tags (0) -sql create table tba (ts timestamp, c1 binary(10), c2 nchar(10)); - -print =============== run show xxxx -sql show dnodes -if $rows != 1 then - return -1 -endi - -sql show mnodes -if $rows != 1 then - return -1 -endi - +print =============== step2: create db +sql create database d1 vgroups 3 buffer 3 sql show databases -if $rows != 3 then - return -1 -endi +sql use d1 +sql show vgroups +print =============== step3: create show stable, include all type +sql create table if not exists stb (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(16), c9 nchar(16), c10 timestamp, c11 tinyint unsigned, c12 smallint unsigned, c13 int unsigned, c14 bigint unsigned) tags (t1 bool, t2 tinyint, t3 smallint, t4 int, t5 bigint, t6 float, t7 double, t8 binary(16), t9 nchar(16), t10 timestamp, t11 tinyint unsigned, t12 smallint unsigned, t13 int unsigned, t14 bigint unsigned) +sql create stable if not exists stb_1 (ts timestamp, c1 int) tags (j int) +sql create table stb_2 (ts timestamp, c1 int) tags (t1 int) +sql create stable stb_3 (ts timestamp, c1 int) tags (t1 int) sql show stables -if $rows != 1 then +if $rows != 4 then return -1 endi +print =============== step4: ccreate child table +sql create table c1 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql create table c2 using stb tags(false, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 2', 'child tbl 2', '2022-02-25 18:00:00.000', 10, 20, 30, 40) sql show tables if $rows != 2 then return -1 endi -sql show users -if $rows != 1 then - return -1 -endi +print =============== step5: insert data +sql insert into c1 values(now-1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+2s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c2 values(now-1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c2 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+2s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) -print =============== run select * from information_schema.xxxx -sql select * from information_schema.`dnodes` -if $rows != 1 then - return -1 -endi +print =============== step6: alter insert +sql insert into c3 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) values(now-1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) +sql insert into c3 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) -sql select * from information_schema.`mnodes` -if $rows != 1 then - return -1 -endi +print =============== stepa: query data +sql select * from c1 +sql select * from stb +sql select * from stb_1 +sql select ts, c1, c2, c3 from c1 +sql select ts, c1, c2, c3 from stb +sql select ts, c1 from stb_2 +sql select ts, c1, t1 from c1 +sql select ts, c1, t1 from stb +sql select ts, c1, t1 from stb_2 -sql select * from information_schema.user_databases -if $rows != 3 then - return -1 -endi +print =============== stepb: count +#sql select count(*) from c1; +#sql select count(*) from stb; +#sql select count(ts), count(c1), count(c2), count(c3) from c1 +#sql select count(ts), count(c1), count(c2), count(c3) from stb -sql select * from information_schema.user_stables -if $rows != 1 then - return -1 -endi +print =============== stepc: func +#sql select first(ts), first(c1), first(c2), first(c3) from c1 +#sql select min(c1), min(c2), min(c3) from c1 +#sql select max(c1), max(c2), max(c3) from c1 +#sql select sum(c1), sum(c2), sum(c3) from c1 -sql select * from information_schema.user_tables -if $rows != 31 then - return -1 -endi - -sql select * from information_schema.user_users -if $rows != 1 then - return -1 -endi - -sql select * from information_schema.`vgroups` -if $rows != 3 then - return -1 -endi - -sql show variables; -if $rows != 4 then - return -1 -endi - -sql show dnode 1 variables; -if $rows <= 0 then - return -1 -endi - -sql show local variables; -if $rows <= 0 then - return -1 -endi - -print =============== stop +_OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT - print =============== check -print ----> start to check if there are ERRORS in vagrind log file for each dnode -system_content sh/checkValgrind.sh -n dnode1 - -print cmd return result ----> [ $system_content ] -if $system_content <= 0 then - return 0 -endi - $null= -if $system_content == $null then - return 0 + +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result ----> [ $system_content ] +if $system_content > 1 then + return -1 endi -return -1 +if $system_content == $null then + return -1 +endi diff --git a/tests/system-test/1-insert/alter_table.py b/tests/system-test/1-insert/alter_table.py index a2613c39e7..4a9cfd30c7 100644 --- a/tests/system-test/1-insert/alter_table.py +++ b/tests/system-test/1-insert/alter_table.py @@ -184,20 +184,37 @@ class TDTestCase: for k,v in self.tag_dict.items(): if v.lower() == 'tinyint': self.tag_check(i,k,tag_tinyint) + for error in [constant.TINYINT_MIN-1,constant.TINYINT_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'smallint': self.tag_check(i,k,tag_smallint) + for error in [constant.SMALLINT_MIN-1,constant.SMALLINT_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'int': self.tag_check(i,k,tag_int) + for error in [constant.INT_MIN-1,constant.INT_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'bigint': self.tag_check(i,k,tag_bigint) + for error in [constant.BIGINT_MIN-1,constant.BIGINT_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'tinyint unsigned': self.tag_check(i,k,tag_untinyint) + for error in [constant.TINYINT_UN_MIN-1,constant.TINYINT_UN_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'smallint unsigned': self.tag_check(i,k,tag_unsmallint) + for error in [constant.SMALLINT_UN_MIN-1,constant.SMALLINT_UN_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'int unsigned': - self.tag_check(i,k,tag_unint) - elif v.lower() == 'bigint unsigned': - self.tag_check(i,k,tag_unbigint) + self.tag_check(i,k,tag_unint) + for error in [constant.INT_UN_MIN-1,constant.INT_UN_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') + #! bug TD-17106 + # elif v.lower() == 'bigint unsigned': + # self.tag_check(i,k,tag_unbigint) + # for error in [constant.BIGINT_UN_MIN-1,constant.BIGINT_UN_MAX+1]: + # tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'bool': self.tag_check(i,k,tag_bool) elif v.lower() == 'float': @@ -207,6 +224,9 @@ class TDTestCase: tdSql.checkEqual(tdSql.queryResult[0][0],tdSql.queryResult[0][0]) else: tdLog.exit(f'select {k} from {self.stbname}_{i},data check failure') + #! bug TD-17106 + # for error in [constant.FLOAT_MIN*1.1,constant.FLOAT_MAX*1.1]: + # tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'double': tdSql.execute(f'alter table {self.stbname}_{i} set tag {k} = {tag_double}') tdSql.query(f'select {k} from {self.stbname}_{i}') @@ -214,11 +234,17 @@ class TDTestCase: tdSql.checkEqual(tdSql.queryResult[0][0],tdSql.queryResult[0][0]) else: tdLog.exit(f'select {k} from {self.stbname}_{i},data check failure') + for error in [constant.DOUBLE_MIN*1.1,constant.DOUBLE_MAX*1.1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif 'binary' in v.lower(): + tag_binary_error = tdCom.getLongName(self.binary_length+1) + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = "{tag_binary_error}"') tdSql.execute(f'alter table {self.stbname}_{i} set tag {k} = "{tag_binary}"') tdSql.query(f'select {k} from {self.stbname}_{i}') tdSql.checkData(0,0,tag_binary) elif 'nchar' in v.lower(): + tag_nchar_error = tdCom.getLongName(self.nchar_length+1) + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = "{tag_nchar_error}"') tdSql.execute(f'alter table {self.stbname}_{i} set tag {k} = "{tag_nchar}"') tdSql.query(f'select {k} from {self.stbname}_{i}') tdSql.checkData(0,0,tag_nchar) diff --git a/tests/system-test/2-query/To_iso8601.py b/tests/system-test/2-query/To_iso8601.py index da7b7e272f..a80978bcda 100644 --- a/tests/system-test/2-query/To_iso8601.py +++ b/tests/system-test/2-query/To_iso8601.py @@ -16,18 +16,18 @@ class TDTestCase: self.rowNum = 10 self.ts = 1640966400000 # 2022-1-1 00:00:00.000 def check_customize_param_ms(self): - + time_zone = time.strftime('%z') tdSql.execute('create database db1 precision "ms"') tdSql.execute('use db1') tdSql.execute('create table if not exists ntb(ts timestamp, c1 int, c2 timestamp)') for i in range(self.rowNum): - tdSql.execute("insert into ntb values(%d, %d, %d)" + tdSql.execute("insert into ntb values(%d, %d, %d)" % (self.ts + i, i + 1, self.ts + i)) tdSql.query('select to_iso8601(ts) from ntb') for i in range(self.rowNum): tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{time_zone}') - + timezone_list = ['+0000','+0100','+0200','+0300','+0330','+0400','+0500','+0530','+0600','+0700','+0800','+0900','+1000','+1100','+1200',\ '+00','+01','+02','+03','+04','+05','+06','+07','+08','+09','+10','+11','+12',\ '+00:00','+01:00','+02:00','+03:00','+03:30','+04:00','+05:00','+05:30','+06:00','+07:00','+08:00','+09:00','+10:00','+11:00','+12:00',\ @@ -39,7 +39,7 @@ class TDTestCase: tdSql.query(f'select to_iso8601(ts,"{j}") from ntb') for i in range(self.rowNum): tdSql.checkEqual(tdSql.queryResult[i][0],f'2022-01-01T00:00:00.00{i}{j}') - + error_param_list = [0,100.5,'a','!'] for i in error_param_list: tdSql.error(f'select to_iso8601(ts,"{i}") from ntb') @@ -47,7 +47,7 @@ class TDTestCase: error_timezone_param = ['+13','-13','+1300','-1300','+0001','-0001','-0330','-0530'] for i in error_timezone_param: tdSql.error(f'select to_iso8601(ts,"{i}") from ntb') - + def check_base_function(self): tdSql.prepare() tdLog.printNoPrefix("==========step1:create tables==========") @@ -75,12 +75,12 @@ class TDTestCase: tdSql.query("select to_iso8601(ts) from ntb") tdSql.checkRows(3) tdSql.query("select to_iso8601(ts) from db.ntb") - + tdSql.query("select to_iso8601(today()) from ntb") tdSql.checkRows(3) tdSql.query("select to_iso8601(now()) from ntb") tdSql.checkRows(3) - + tdSql.error("select to_iso8601(timezone()) from ntb") tdSql.error("select to_iso8601('abc') from ntb") @@ -104,7 +104,7 @@ class TDTestCase: for i in err_param: tdSql.error(f"select to_iso8601({i}) from ntb") tdSql.error(f"select to_iso8601({i}) from db.ntb") - + tdSql.query("select to_iso8601(now) from stb") tdSql.checkRows(3) tdSql.query("select to_iso8601(now()) from stb") @@ -126,7 +126,7 @@ class TDTestCase: tdSql.query(f"select to_iso8601(today()) {i}null from db.stb") tdSql.checkRows(3) tdSql.checkData(0,0,None) - + def run(self): # sourcery skip: extract-duplicate-method self.check_base_function() self.check_customize_param_ms() diff --git a/tests/system-test/2-query/Today.py b/tests/system-test/2-query/Today.py index e6199d629e..43c5263af6 100644 --- a/tests/system-test/2-query/Today.py +++ b/tests/system-test/2-query/Today.py @@ -58,7 +58,7 @@ class TDTestCase: tag_sql += f"{k} {v}," create_stb_sql = f'create table {stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})' return create_stb_sql - + def data_check(self,column_dict={},tbname = '',values_list = [],tb_num = 1,tb = 'tb',precision = 'ms'): for k,v in column_dict.items(): num_up = 0 @@ -175,7 +175,7 @@ class TDTestCase: tdSql.execute('drop database db') def run(self): # sourcery skip: extract-duplicate-method - + self.today_check_ntb() self.today_check_stb_tb() diff --git a/tests/system-test/2-query/abs.py b/tests/system-test/2-query/abs.py index 7ebb2eba8c..6dc65ce3c2 100644 --- a/tests/system-test/2-query/abs.py +++ b/tests/system-test/2-query/abs.py @@ -47,7 +47,7 @@ class TDTestCase: c9 = "'nchar_val'" c10 = ts tdSql.execute(f" insert into {tbname} values ({ts},{c1},{c2},{c3},{c4},{c5},{c6},{c7},{c8},{c9},{c10})") - + tdSql.execute("use test") tbnames = ["stb", "sub_tb_1"] support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] @@ -60,7 +60,7 @@ class TDTestCase: origin_sql = "select {} from {} order by tbname".format(colname, tbname) if coltype[1] in support_types: self.check_result_auto(origin_sql , abs_sql) - + def prepare_datas(self): tdSql.execute( diff --git a/tests/system-test/2-query/and_or_for_byte.py b/tests/system-test/2-query/and_or_for_byte.py index 416e62c0f2..62951e571f 100644 --- a/tests/system-test/2-query/and_or_for_byte.py +++ b/tests/system-test/2-query/and_or_for_byte.py @@ -47,7 +47,7 @@ class TDTestCase: c9 = "'nchar_val'" c10 = ts tdSql.execute(f" insert into {tbname} values ({ts},{c1},{c2},{c3},{c4},{c5},{c6},{c7},{c8},{c9},{c10})") - + tdSql.execute("use test") tbnames = ["stb", "sub_tb_1"] support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] @@ -62,7 +62,7 @@ class TDTestCase: cols = random.sample(colnames,3) self.check_function("&",False,tbname,cols[0],cols[1],cols[2]) self.check_function("|",False,tbname,cols[0],cols[1],cols[2]) - + def prepare_datas(self): tdSql.execute( @@ -215,14 +215,14 @@ class TDTestCase: "abs value check pass , it work as expected ,sql is \"%s\" " % abs_query) def check_function(self, opera ,agg, tbname , *args): - + if opera =="&": pass elif opera =="|": pass else: pass - work_sql = " select " + work_sql = " select " for ind , arg in enumerate(args): if ind ==len(args)-1: work_sql += f"cast({arg} as bigint) " @@ -235,7 +235,7 @@ class TDTestCase: work_sql+= f" from {tbname} " tdSql.query(work_sql) work_result = tdSql.queryResult - + origin_sql = " select " for ind , arg in enumerate(args): if ind ==len(args)-1: @@ -323,7 +323,7 @@ class TDTestCase: tdSql.checkData(0,0,None) tdSql.checkData(1,0,640) tdSql.checkData(10,0,0) - + # used for regular table tdSql.query("select abs(c1)&c3&c3 from t1") tdSql.checkData(0, 0, None) @@ -349,7 +349,7 @@ class TDTestCase: self.check_function("&",False,"stb1","c1","floor(t1)","abs(c1+c2)","t1+1") self.check_function("&",True,"stb1","max(c1)","min(floor(t1))","sum(abs(c1+c2))","last(t1)+1") self.check_function("&",False,"stb1","abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))))","floor(t1)","abs(c1+c2)","t1+1") - + # mix with common col tdSql.query("select c1&abs(c1)&c2&c3 ,c1,c2, t1 from ct1") tdSql.checkData(0, 0, 8) @@ -388,7 +388,7 @@ class TDTestCase: # agg functions mix with agg functions tdSql.query("select sum(c1&abs(c1)&c2&c3) ,max(c5), count(c5) from stb1") - + tdSql.query("select max(c1)&max(c2)|first(ts), count(c5) from ct1") # bug fix for compute @@ -409,7 +409,7 @@ class TDTestCase: tdSql.checkData(1, 2, 894.900000000) - + def check_boundary_values(self): @@ -490,7 +490,7 @@ class TDTestCase: self.check_function("&", False ,"ct4","123","abs(c1)","t1","abs(t2)","abs(t3)","abs(t4)","t5") self.check_function("&", False ,"ct4","c1+2","abs(t2+2)","t3","abs(t4)","abs(t5)","abs(c1)","t5") - tdSql.query(" select sum(c1) from stb1 where t1+10 >1; ") + tdSql.query(" select sum(c1) from stb1 where t1+10 >1; ") tdSql.query("select c1 ,t1 from stb1 where t1 =0 ") tdSql.checkRows(13) self.check_function("&", False ,"t1","c1+2","abs(c2)") @@ -534,7 +534,7 @@ class TDTestCase: self.support_super_table_test() self.insert_datas_and_check_abs(self.tb_nums,self.row_nums,self.time_step) - + def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/apercentile.py b/tests/system-test/2-query/apercentile.py index 150c4d3f17..6e4b4eeb8a 100644 --- a/tests/system-test/2-query/apercentile.py +++ b/tests/system-test/2-query/apercentile.py @@ -15,90 +15,118 @@ from util.log import * from util.cases import * from util.sql import * import numpy as np - +from util.sqlset import TDSetSql class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor(),logSql) self.rowNum = 10 self.ts = 1537146000000 - - def check_apercentile(self,data,expect_data,param,percent,column): - if param == "default": - if abs((expect_data-data) <= expect_data * 0.2): - tdLog.info(f"apercentile function values check success with col{column}, param = {param},percent = {percent}") - else: - tdLog.notice(f"apercentile function value has not as expected with col{column}, param = {param},percent = {percent}") - sys.exit(1) - elif param == "t-digest": - if abs((expect_data-data) <= expect_data * 0.2): - tdLog.info(f"apercentile function values check success with col{column}, param = {param},percent = {percent}") - else: - tdLog.notice(f"apercentile function value has not as expected with col{column}, param = {param},percent = {percent}") - sys.exit(1) + self.setsql = TDSetSql() + self.ntbname = 'ntb' + self.stbname = 'stb' + self.binary_length = 20 # the length of binary for column_dict + self.nchar_length = 20 # the length of nchar for column_dict + self.column_dict = { + 'ts' : 'timestamp', + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': f'binary({self.binary_length})', + 'col13': f'nchar({self.nchar_length})' + } - def run(self): + self.tag_dict = { + 'ts_tag' : 'timestamp', + 't1': 'tinyint', + 't2': 'smallint', + 't3': 'int', + 't4': 'bigint', + 't5': 'tinyint unsigned', + 't6': 'smallint unsigned', + 't7': 'int unsigned', + 't8': 'bigint unsigned', + 't9': 'float', + 't10': 'double', + 't11': 'bool', + 't12': f'binary({self.binary_length})', + 't13': f'nchar({self.nchar_length})' + } + self.binary_str = 'taosdata' + self.nchar_str = '涛思数据' + self.tbnum = 2 + self.tag_ts = self.ts + self.tag_tinyint = 1 + self.tag_smallint = 2 + self.tag_int = 3 + self.tag_bigint = 4 + self.tag_utint = 5 + self.tag_usint = 6 + self.tag_uint = 7 + self.tag_ubint = 8 + self.tag_float = 9.1 + self.tag_double = 10.1 + self.tag_bool = True + self.tag_values = [ + f'{self.tag_ts},{self.tag_tinyint},{self.tag_smallint},{self.tag_int},{self.tag_bigint},\ + {self.tag_utint},{self.tag_usint},{self.tag_uint},{self.tag_ubint},{self.tag_float},{self.tag_double},{self.tag_bool},"{self.binary_str}","{self.nchar_str}"' + + ] + + self.percent = [1,50,100] + self.param_list = ['default','t-digest'] + def insert_data(self,column_dict,tbname,row_num): + insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str) + for i in range(row_num): + insert_list = [] + self.setsql.insert_values(column_dict,i,insert_sql,insert_list,self.ts) + + + def function_check_ntb(self): tdSql.prepare() + tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict)) + self.insert_data(self.column_dict,self.ntbname,self.rowNum) + for k,v in self.column_dict.items(): + for percent in self.percent: + for param in self.param_list: + if v.lower() in ['timestamp','bool'] or 'binary' in v.lower() or 'nchar' in v.lower(): + tdSql.error(f'select apercentile({k},{percent},"{param}") from {self.ntbname}') + else: + tdSql.query(f"select apercentile({k},{percent},'{param}') from {self.ntbname}") + def function_check_stb(self): + tdSql.prepare() + tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) + for i in range(self.tbnum): + tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]})") + self.insert_data(self.column_dict,f'{self.stbname}_{i}',self.rowNum) + for i in range(self.tbnum): + for k,v in self.column_dict.items(): + for percent in self.percent: + for param in self.param_list: + if v.lower() in ['timestamp','bool'] or 'binary' in v.lower() or 'nchar' in v.lower(): + tdSql.error(f'select apercentile({k},{percent},"{param}") from {self.stbname}_{i}') + else: + tdSql.query(f"select apercentile({k},{percent},'{param}') from {self.stbname}_{i}") + for k,v in self.column_dict.items(): + for percent in self.percent: + for param in self.param_list: + if v.lower() in ['timestamp','bool'] or 'binary' in v.lower() or 'nchar' in v.lower(): + tdSql.error(f'select apercentile({k},{percent},"{param}") from {self.stbname}') + else: + tdSql.query(f"select apercentile({k},{percent},'{param}') from {self.stbname}") + def run(self): + self.function_check_ntb() + self.function_check_stb() - intData = [] - floatData = [] - percent_list = [0,50,100] - param_list = ['default','t-digest'] - tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, - col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') - for i in range(self.rowNum): - tdSql.execute("insert into test values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - intData.append(i + 1) - floatData.append(i + 0.1) - - # percentile verifacation - - tdSql.error("select apercentile(ts ,20) from test") - tdSql.error("select apercentile(col7 ,20) from test") - tdSql.error("select apercentile(col8 ,20) from test") - tdSql.error("select apercentile(col9 ,20) from test") - - column_list = [1,2,3,4,5,6,11,12,13,14] - - for i in column_list: - for j in percent_list: - for k in param_list: - tdSql.query(f"select apercentile(col{i},{j},'{k}') from test") - data = tdSql.getData(0, 0) - tdSql.query(f"select percentile(col{i},{j}) from test") - expect_data = tdSql.getData(0, 0) - self.check_apercentile(data,expect_data,k,j,i) - - error_param_list = [-1,101,'"a"'] - for i in error_param_list: - tdSql.error(f'select apercentile(col1,{i}) from test') - - tdSql.execute("create table meters (ts timestamp, voltage int) tags(loc nchar(20))") - tdSql.execute("create table t0 using meters tags('beijing')") - tdSql.execute("create table t1 using meters tags('shanghai')") - for i in range(self.rowNum): - tdSql.execute("insert into t0 values(%d, %d)" % (self.ts + i, i + 1)) - tdSql.execute("insert into t1 values(%d, %d)" % (self.ts + i, i + 1)) - - column_list = ['voltage'] - for i in column_list: - for j in percent_list: - for k in param_list: - tdSql.query(f"select apercentile({i}, {j},'{k}') from t0") - data = tdSql.getData(0, 0) - tdSql.query(f"select percentile({i},{j}) from t0") - expect_data = tdSql.getData(0,0) - self.check_apercentile(data,expect_data,k,j,i) - tdSql.query(f"select apercentile({i}, {j},'{k}') from meters") - tdSql.checkRows(1) - table_list = ["meters","t0"] - for i in error_param_list: - for j in table_list: - for k in column_list: - tdSql.error(f'select apercentile({k},{i}) from {j}') - def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/bottom.py b/tests/system-test/2-query/bottom.py index a95daf22f4..1b7c967348 100644 --- a/tests/system-test/2-query/bottom.py +++ b/tests/system-test/2-query/bottom.py @@ -48,34 +48,13 @@ class TDTestCase: 'col12': 'binary(20)', 'col13': 'nchar(20)' } - + self.param_list = [1,100] def insert_data(self,column_dict,tbname,row_num): - sql = '' - for k, v in column_dict.items(): - if v.lower() == 'timestamp' or v.lower() == 'tinyint' or v.lower() == 'smallint' or v.lower() == 'int' or v.lower() == 'bigint' or \ - v.lower() == 'tinyint unsigned' or v.lower() == 'smallint unsigned' or v.lower() == 'int unsigned' or v.lower() == 'bigint unsigned' or v.lower() == 'bool': - sql += '%d,' - elif v.lower() == 'float' or v.lower() == 'double': - sql += '%f,' - elif 'binary' in v.lower(): - sql += f'"{self.binary_str}%d",' - elif 'nchar' in v.lower(): - sql += f'"{self.nchar_str}%d",' - insert_sql = f'insert into {tbname} values({sql[:-1]})' + insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str) for i in range(row_num): insert_list = [] - for k, v in column_dict.items(): - if v.lower() in[ 'tinyint' , 'smallint' , 'int', 'bigint' , 'tinyint unsigned' , 'smallint unsigned' , 'int unsigned' , 'bigint unsigned'] or\ - 'binary' in v.lower() or 'nchar' in v.lower(): - insert_list.append(0 + i) - elif v.lower() == 'float' or v.lower() == 'double': - insert_list.append(0.1 + i) - elif v.lower() == 'bool': - insert_list.append(i % 2) - elif v.lower() == 'timestamp': - insert_list.append(self.ts + i) - tdSql.execute(insert_sql%(tuple(insert_list))) + self.setsql.insert_values(column_dict,i,insert_sql,insert_list,self.ts) def bottom_check_data(self,tbname,tb_type): new_column_dict = {} for param in self.param_list: @@ -129,7 +108,7 @@ class TDTestCase: tdSql.execute(self.setsql.set_create_stable_sql(stbname,self.column_dict,tag_dict)) for i in range(self.tbnum): tdSql.execute(f"create table {stbname}_{i} using {stbname} tags({tag_values[0]})") - tdSql.execute(self.insert_data(self.column_dict,f'{stbname}_{i}',self.rowNum)) + self.insert_data(self.column_dict,f'{stbname}_{i}',self.rowNum) tdSql.query('show tables') vgroup_list = [] for i in range(len(tdSql.queryResult)): @@ -146,11 +125,11 @@ class TDTestCase: self.bottom_check_data(f'{stbname}_{i}','child_table') self.bottom_check_data(f'{stbname}','stable') tdSql.execute(f'drop database {self.dbname}') - + def run(self): self.bottom_check_ntb() self.bottom_check_stb() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/ceil.py b/tests/system-test/2-query/ceil.py index 9816751e55..f1379e6661 100644 --- a/tests/system-test/2-query/ceil.py +++ b/tests/system-test/2-query/ceil.py @@ -9,14 +9,14 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'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 ,"udfDebugFlag":143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - + def prepare_datas(self): tdSql.execute( '''create table stb1 @@ -24,7 +24,7 @@ class TDTestCase: tags (t1 int) ''' ) - + tdSql.execute( ''' create table t1 @@ -66,14 +66,14 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - + def check_result_auto(self ,origin_query , ceil_query): pass ceil_result = tdSql.getResult(ceil_query) origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -88,13 +88,13 @@ class TDTestCase: for row_index , row in enumerate(ceil_result): for col_index , elem in enumerate(row): if auto_result[row_index][col_index] != elem: - check_status = False + check_status = False if not check_status: tdLog.notice("ceil function value has not as expected , sql is \"%s\" "%ceil_query ) sys.exit(1) else: tdLog.info("ceil value check pass , it work as expected ,sql is \"%s\" "%ceil_query ) - + def test_errors(self): error_sql_lists = [ "select ceil from t1", @@ -128,42 +128,42 @@ class TDTestCase: ] for error_sql in error_sql_lists: tdSql.error(error_sql) - + def support_types(self): type_error_sql_lists = [ - "select ceil(ts) from t1" , + "select ceil(ts) from t1" , "select ceil(c7) from t1", "select ceil(c8) from t1", "select ceil(c9) from t1", - "select ceil(ts) from ct1" , + "select ceil(ts) from ct1" , "select ceil(c7) from ct1", "select ceil(c8) from ct1", "select ceil(c9) from ct1", - "select ceil(ts) from ct3" , + "select ceil(ts) from ct3" , "select ceil(c7) from ct3", "select ceil(c8) from ct3", "select ceil(c9) from ct3", - "select ceil(ts) from ct4" , + "select ceil(ts) from ct4" , "select ceil(c7) from ct4", "select ceil(c8) from ct4", "select ceil(c9) from ct4", - "select ceil(ts) from stb1" , + "select ceil(ts) from stb1" , "select ceil(c7) from stb1", "select ceil(c8) from stb1", "select ceil(c9) from stb1" , - "select ceil(ts) from stbbb1" , + "select ceil(ts) from stbbb1" , "select ceil(c7) from stbbb1", "select ceil(ts) from tbname", "select ceil(c9) from tbname" ] - + for type_sql in type_error_sql_lists: tdSql.error(type_sql) - - + + type_sql_lists = [ "select ceil(c1) from t1", "select ceil(c2) from t1", @@ -193,16 +193,16 @@ class TDTestCase: "select ceil(c5) from stb1", "select ceil(c6) from stb1", - "select ceil(c6) as alisb from stb1", - "select ceil(c6) alisb from stb1", + "select ceil(c6) as alisb from stb1", + "select ceil(c6) alisb from stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - + def basic_ceil_function(self): - # basic query + # basic query tdSql.query("select c1 from ct3") tdSql.checkRows(0) tdSql.query("select c1 from t1") @@ -222,7 +222,7 @@ class TDTestCase: tdSql.query("select ceil(c5) from ct3") tdSql.checkRows(0) tdSql.query("select ceil(c6) from ct3") - + # used for regular table tdSql.query("select ceil(c1) from t1") tdSql.checkData(0, 0, None) @@ -240,7 +240,7 @@ class TDTestCase: tdSql.checkData(5, 5, None) self.check_result_auto( "select c1, c2, c3 , c4, c5 from t1", "select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from t1") - + # used for sub table tdSql.query("select ceil(c1) from ct1") tdSql.checkData(0, 0, 8) @@ -252,20 +252,20 @@ class TDTestCase: self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct1", "select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from ct1") self.check_result_auto("select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from ct1;","select c1 from ct1" ) - # used for stable table - + # used for stable table + tdSql.query("select ceil(c1) from stb1") tdSql.checkRows(25) self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct4 ", "select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from ct4") self.check_result_auto("select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from ct4;" , "select c1 from ct4" ) - + # used for not exists table tdSql.error("select ceil(c1) from stbbb1") tdSql.error("select ceil(c1) from tbname") tdSql.error("select ceil(c1) from ct5") - # mix with common col + # mix with common col tdSql.query("select c1, ceil(c1) from ct1") tdSql.checkData(0 , 0 ,8) tdSql.checkData(0 , 1 ,8) @@ -290,7 +290,7 @@ class TDTestCase: tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 3 ,None) - + tdSql.checkData(3 , 0 , 6) tdSql.checkData(3 , 1 , 6) tdSql.checkData(3 , 2 ,6.66000) @@ -311,7 +311,7 @@ class TDTestCase: tdSql.query("select max(c5), count(c5) from stb1") tdSql.query("select max(c5), count(c5) from ct1") - + # bug fix for count tdSql.query("select count(c1) from ct4 ") tdSql.checkData(0,0,9) @@ -322,7 +322,7 @@ class TDTestCase: tdSql.query("select count(*) from stb1 ") tdSql.checkData(0,0,25) - # bug fix for compute + # bug fix for compute tdSql.query("select c1, abs(c1) -0 ,ceil(c1)-0 from ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) @@ -373,10 +373,10 @@ class TDTestCase: tdSql.checkData(0,3,8.000000000) tdSql.checkData(0,4,7.900000000) tdSql.checkData(0,5,3.000000000) - + def ceil_Arithmetic(self): pass - + def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") @@ -405,14 +405,14 @@ class TDTestCase: tdSql.execute( f"insert into sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - + tdSql.error( f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) self.check_result_auto( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select ceil(c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) ,ceil(c6) from sub1_bound") self.check_result_auto( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select ceil(c1), ceil(c2) ,ceil(c3), ceil(c3), ceil(c2) ,ceil(c1) from sub1_bound") self.check_result_auto("select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from sub1_bound;" , "select ceil(c1) from sub1_bound" ) - + # check basic elem for table per row tdSql.query("select ceil(c1+0.2) ,ceil(c2) , ceil(c3+0.3) , ceil(c4-0.3), ceil(c5/2), ceil(c6/2) from sub1_bound ") tdSql.checkData(0, 0, 2147483648.000000000) @@ -426,7 +426,7 @@ class TDTestCase: tdSql.checkData(4, 4, -169499995645668991474575059260979281920.000000000) self.check_result_auto("select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from sub1_bound" ,"select ceil(c1+1) ,ceil(c2) , ceil(c3*1) , ceil(c4/2), ceil(c5)/2, ceil(c6) from sub1_bound ") - + def support_super_table_test(self): tdSql.execute(" use db ") self.check_result_auto( " select c5 from stb1 order by ts " , "select ceil(c5) from stb1 order by ts" ) @@ -444,26 +444,26 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: ceil basic query ============") + tdLog.printNoPrefix("==========step4: ceil basic query ============") self.basic_ceil_function() - tdLog.printNoPrefix("==========step5: ceil boundary query ============") + tdLog.printNoPrefix("==========step5: ceil boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step6: ceil filter query ============") + tdLog.printNoPrefix("==========step6: ceil filter query ============") self.abs_func_filter() diff --git a/tests/system-test/2-query/cos.py b/tests/system-test/2-query/cos.py index e50ec6d523..e0941b9157 100644 --- a/tests/system-test/2-query/cos.py +++ b/tests/system-test/2-query/cos.py @@ -9,13 +9,13 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'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 ,"udfDebugFlag":143} def init(self, conn, powSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - + def prepare_datas(self): tdSql.execute( '''create table stb1 @@ -23,7 +23,7 @@ class TDTestCase: tags (t1 int) ''' ) - + tdSql.execute( ''' create table t1 @@ -65,14 +65,14 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - + def check_result_auto_cos(self ,origin_query , pow_query): pow_result = tdSql.getResult(pow_query) origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -90,7 +90,7 @@ class TDTestCase: if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None): check_status = False elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001): - check_status = False + check_status = False else: pass if not check_status: @@ -98,7 +98,7 @@ class TDTestCase: sys.exit(1) else: tdLog.info("cos value check pass , it work as expected ,sql is \"%s\" "%pow_query ) - + def test_errors(self): error_sql_lists = [ "select cos from t1", @@ -132,42 +132,42 @@ class TDTestCase: ] for error_sql in error_sql_lists: tdSql.error(error_sql) - + def support_types(self): type_error_sql_lists = [ - "select cos(ts) from t1" , + "select cos(ts) from t1" , "select cos(c7) from t1", "select cos(c8) from t1", "select cos(c9) from t1", - "select cos(ts) from ct1" , + "select cos(ts) from ct1" , "select cos(c7) from ct1", "select cos(c8) from ct1", "select cos(c9) from ct1", - "select cos(ts) from ct3" , + "select cos(ts) from ct3" , "select cos(c7) from ct3", "select cos(c8) from ct3", "select cos(c9) from ct3", - "select cos(ts) from ct4" , + "select cos(ts) from ct4" , "select cos(c7) from ct4", "select cos(c8) from ct4", "select cos(c9) from ct4", - "select cos(ts) from stb1" , + "select cos(ts) from stb1" , "select cos(c7) from stb1", "select cos(c8) from stb1", "select cos(c9) from stb1" , - "select cos(ts) from stbbb1" , + "select cos(ts) from stbbb1" , "select cos(c7) from stbbb1", "select cos(ts) from tbname", "select cos(c9) from tbname" ] - + for type_sql in type_error_sql_lists: tdSql.error(type_sql) - - + + type_sql_lists = [ "select cos(c1) from t1", "select cos(c2) from t1", @@ -197,16 +197,16 @@ class TDTestCase: "select cos(c5) from stb1", "select cos(c6) from stb1", - "select cos(c6) as alisb from stb1", - "select cos(c6) alisb from stb1", + "select cos(c6) as alisb from stb1", + "select cos(c6) alisb from stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - + def basic_cosin_function(self): - # basic query + # basic query tdSql.query("select c1 from ct3") tdSql.checkRows(0) tdSql.query("select c1 from t1") @@ -247,7 +247,7 @@ class TDTestCase: tdSql.checkData(5, 5, None) self.check_result_auto_cos( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from t1", "select cos(abs(c1)), cos(abs(c2)) ,cos(abs(c3)), cos(abs(c4)), cos(abs(c5)) from t1") - + # used for sub table tdSql.query("select c2 ,cos(c2) from ct1") tdSql.checkData(0, 1, 0.975339851) @@ -263,7 +263,7 @@ class TDTestCase: tdSql.checkData(5 , 2, None) self.check_result_auto_cos( "select c1, c2, c3 , c4, c5 from ct1", "select cos(c1), cos(c2) ,cos(c3), cos(c4), cos(c5) from ct1") - + # nest query for cos functions tdSql.query("select c4 , cos(c4) ,cos(cos(c4)) , cos(cos(cos(c4))) from ct1;") tdSql.checkData(0 , 0 , 88) @@ -281,21 +281,21 @@ class TDTestCase: tdSql.checkData(11 , 2 , 0.999207254) tdSql.checkData(11 , 3 , 0.540969209) - # used for stable table - + # used for stable table + tdSql.query("select cos(c1) from stb1") tdSql.checkRows(25) - + # used for not exists table tdSql.error("select cos(c1) from stbbb1") tdSql.error("select cos(c1) from tbname") tdSql.error("select cos(c1) from ct5") - # mix with common col + # mix with common col tdSql.query("select c1, cos(c1) from ct1") tdSql.query("select c2, cos(c2) from ct4") - + # mix with common functions tdSql.query("select c1, cos(c1),cos(c1), cos(cos(c1)) from ct4 ") @@ -303,7 +303,7 @@ class TDTestCase: tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 3 ,None) - + tdSql.checkData(3 , 0 , 6) tdSql.checkData(3 , 1 ,0.960170287) tdSql.checkData(3 , 2 ,0.960170287) @@ -324,8 +324,8 @@ class TDTestCase: tdSql.query("select max(c5), count(c5) from stb1") tdSql.query("select max(c5), count(c5) from ct1") - - # # bug fix for compute + + # # bug fix for compute tdSql.query("select c1, cos(c1) -0 ,cos(c1-4)-0 from ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) @@ -394,10 +394,10 @@ class TDTestCase: tdSql.checkData(0,3,8.000000000) tdSql.checkData(0,4,7.900000000) tdSql.checkData(0,5,0.000000000) - + def pow_Arithmetic(self): pass - + def check_boundary_values(self): PI=3.1415926 @@ -426,11 +426,11 @@ class TDTestCase: f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) self.check_result_auto_cos( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from sub1_bound ", "select cos(abs(c1)), cos(abs(c2)) ,cos(abs(c3)), cos(abs(c4)), cos(abs(c5)) from sub1_bound") - + self.check_result_auto_cos( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select cos(c1), cos(c2) ,cos(c3), cos(c3), cos(c2) ,cos(c1) from sub1_bound") self.check_result_auto_cos("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select cos(abs(c1)) from sub1_bound" ) - + # check basic elem for table per row tdSql.query("select cos(abs(c1)) ,cos(abs(c2)) , cos(abs(c3)) , cos(abs(c4)), cos(abs(c5)), cos(abs(c6)) from sub1_bound ") tdSql.checkData(0,0,math.cos(2147483647)) @@ -489,36 +489,36 @@ class TDTestCase: self.check_result_auto_cos( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select cos(t1) ,cos(c5) from stb1 where c1 > 0 order by tbname" ) self.check_result_auto_cos( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select cos(t1) , cos(c5) from stb1 where c1 > 0 order by tbname" ) pass - + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: cos basic query ============") + tdLog.printNoPrefix("==========step4: cos basic query ============") self.basic_cosin_function() - tdLog.printNoPrefix("==========step5: big number cos query ============") + tdLog.printNoPrefix("==========step5: big number cos query ============") self.test_big_number() - tdLog.printNoPrefix("==========step6: cos boundary query ============") + tdLog.printNoPrefix("==========step6: cos boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step7: cos filter query ============") + tdLog.printNoPrefix("==========step7: cos filter query ============") self.abs_func_filter() diff --git a/tests/system-test/2-query/count.py b/tests/system-test/2-query/count.py index a70a2e72f2..c4c1d19898 100644 --- a/tests/system-test/2-query/count.py +++ b/tests/system-test/2-query/count.py @@ -13,24 +13,24 @@ class TDTestCase: def run(self): tdSql.prepare() - tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''') tdSql.execute("create table stb_1 using stb tags('beijing')") tdSql.execute("create table stb_2 using stb tags('shanghai')") - tdSql.execute('''create table ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute('''create table ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') - + for i in range(self.rowNum): - tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - tdSql.execute("insert into stb_2 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute("insert into stb_2 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - + for i in range(self.rowNum): - tdSql.execute("insert into ntb values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute("insert into ntb values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - + tdSql.query("select count(*) from stb") tdSql.checkData(0,0,20) tdSql.query("select count(*) from db.stb") @@ -95,7 +95,7 @@ class TDTestCase: tdSql.query("select count(ts) from db.stb_1") - tdSql.checkData(0,0,10) + tdSql.checkData(0,0,10) tdSql.query("select count(ts) from db.stb_1") tdSql.checkData(0,0,10) tdSql.query("select count(col1) from stb_1") @@ -171,7 +171,7 @@ class TDTestCase: tdSql.query("select count(col1),count(ts) from stb") tdSql.checkData(0,0,20) tdSql.checkData(0,1,21) - + tdSql.query("select count(col1) from db.stb") tdSql.checkData(0,0,20) tdSql.query("select count(col1),count(ts) from db.stb") @@ -184,7 +184,7 @@ class TDTestCase: tdSql.query("select count(col1) from stb group by col7") tdSql.checkRows(3) - + def stop(self): @@ -193,4 +193,4 @@ class TDTestCase: tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/count_partition.py b/tests/system-test/2-query/count_partition.py new file mode 100644 index 0000000000..a25b4c09c1 --- /dev/null +++ b/tests/system-test/2-query/count_partition.py @@ -0,0 +1,176 @@ +# author : wenzhouwww +from util.log import * +from util.sql import * +from util.cases import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.row_nums = 10 + self.tb_nums = 10 + self.ts = 1537146000000 + + def prepare_datas(self, stb_name , tb_nums , row_nums ): + tdSql.execute(" use db ") + tdSql.execute(f" create stable {stb_name} (ts timestamp , c1 int , c2 bigint , c3 float , c4 double , c5 smallint , c6 tinyint , c7 bool , c8 binary(36) , c9 nchar(36) , uc1 int unsigned,\ + uc2 bigint unsigned ,uc3 smallint unsigned , uc4 tinyint unsigned ) tags(t1 timestamp , t2 int , t3 bigint , t4 float , t5 double , t6 smallint , t7 tinyint , t8 bool , t9 binary(36)\ + , t10 nchar(36) , t11 int unsigned , t12 bigint unsigned ,t13 smallint unsigned , t14 tinyint unsigned ) ") + + for i in range(tb_nums): + tbname = f"sub_{stb_name}_{i}" + ts = self.ts + i*10000 + tdSql.execute(f"create table {tbname} using {stb_name} tags ({ts} , {i} , {i}*10 ,{i}*1.0,{i}*1.0 , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )") + + for row in range(row_nums): + ts = self.ts + row*1000 + tdSql.execute(f"insert into {tbname} values({ts} , {row} , {row} , {row} , {row} , 1 , 2 , 'true' , 'binary_{row}' , 'nchar_{row}' , {row} , {row} , 1 ,2 )") + + for null in range(5): + ts = self.ts + row_nums*1000 + null*1000 + tdSql.execute(f"insert into {tbname} values({ts} , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL )") + + def basic_query(self): + tdSql.query("select count(*) from stb") + tdSql.checkData(0,0,(self.row_nums + 5 )*self.tb_nums) + tdSql.query("select count(c1) from stb") + tdSql.checkData(0,0,(self.row_nums )*self.tb_nums) + tdSql.query(" select tbname , count(*) from stb partition by tbname ") + tdSql.checkRows(self.tb_nums) + tdSql.query(" select count(c1) from stb group by t1 order by t1 ") + tdSql.checkRows(self.tb_nums) + tdSql.error(" select count(c1) from stb group by c1 order by t1 ") + tdSql.error(" select count(t1) from stb group by c1 order by t1 ") + tdSql.query(" select count(c1) from stb group by tbname order by tbname ") + tdSql.checkRows(self.tb_nums) + # bug need fix + # tdSql.query(" select count(t1) from stb group by t2 order by t2 ") + # tdSql.checkRows(self.tb_nums) + tdSql.query(" select count(c1) from stb group by c1 order by c1 ") + tdSql.checkRows(self.row_nums+1) + + tdSql.query(" select c1 , count(c1) from stb group by c1 order by c1 ") + tdSql.checkRows(self.row_nums+1) + + tdSql.query("select count(c1) from stb group by abs(c1) order by abs(c1)") + tdSql.checkRows(self.row_nums+1) + tdSql.query("select abs(c1+c3), count(c1+c3) from stb group by abs(c1+c3) order by abs(c1+c3)") + tdSql.checkRows(self.row_nums+1) + tdSql.query("select count(c1+c3)+max(c2) ,abs(c1) from stb group by abs(c1) order by abs(c1)") + tdSql.checkRows(self.row_nums+1) + tdSql.error("select count(c1+c3)+max(c2) ,abs(c1) ,abs(t1) from stb group by abs(c1) order by abs(t1)+c2") + tdSql.error("select count(c1+c3)+max(c2) ,abs(c1) from stb group by abs(c1) order by abs(c1)+c2") + tdSql.query("select abs(c1+c3)+abs(c2) , count(c1+c3)+count(c2) from stb group by abs(c1+c3)+abs(c2) order by abs(c1+c3)+abs(c2)") + tdSql.checkRows(self.row_nums+1) + + tdSql.query("select count(c1) , count(t2) from stb where abs(c1+t2)=1 partition by tbname") + tdSql.checkRows(2) + tdSql.query("select count(c1) from stb where abs(c1+t2)=1 partition by tbname") + tdSql.checkRows(2) + + tdSql.query("select tbname , count(c1) from stb partition by tbname order by tbname") + tdSql.checkRows(self.tb_nums) + tdSql.checkData(0,1,self.row_nums) + + tdSql.error("select tbname , count(c1) from stb partition by t1 order by t1") + tdSql.error("select tbname , count(t1) from stb partition by t1 order by t1") + tdSql.error("select tbname , count(t1) from stb partition by t2 order by t2") + + # # bug need fix + # tdSql.query("select t2 , count(t1) from stb partition by t2 order by t2") + # tdSql.checkRows(self.tb_nums) + + tdSql.query("select tbname , count(c1) from stb partition by tbname order by tbname") + tdSql.checkRows(self.tb_nums) + tdSql.checkData(0,1,self.row_nums) + + + tdSql.error("select tbname , count(c1) from stb partition by t2 order by t2") + + tdSql.query("select c2, count(c1) from stb partition by c2 order by c2 desc") + tdSql.checkRows(self.tb_nums+1) + tdSql.checkData(0,1,self.tb_nums) + + tdSql.error("select tbname , count(c1) from stb partition by c1 order by c2") + + + tdSql.query("select tbname , abs(t2) from stb partition by c2 order by t2") + tdSql.checkRows(self.tb_nums*(self.row_nums+5)) + + tdSql.query("select count(c1) , count(t2) from stb partition by c2 ") + tdSql.checkRows(self.row_nums+1) + tdSql.checkData(0,1,self.row_nums) + + tdSql.query("select count(c1) , count(t2) ,c2 from stb partition by c2 order by c2") + tdSql.checkRows(self.row_nums+1) + + tdSql.query("select count(c1) , count(t1) ,max(c2) ,tbname from stb partition by tbname order by tbname") + tdSql.checkRows(self.tb_nums) + tdSql.checkCols(4) + + tdSql.query("select count(c1) , count(t2) ,t1 from stb partition by t1 order by t1") + tdSql.checkRows(self.tb_nums) + tdSql.checkData(0,0,self.row_nums) + + # bug need fix + # tdSql.query("select count(c1) , count(t1) ,abs(c1) from stb partition by abs(c1) order by abs(c1)") + # tdSql.checkRows(self.row_nums+1) + + + tdSql.query("select count(ceil(c2)) , count(floor(t2)) ,count(floor(c2)) from stb partition by abs(c2) order by abs(c2)") + tdSql.checkRows(self.row_nums+1) + + + tdSql.query("select count(ceil(c1-2)) , count(floor(t2+1)) ,max(c2-c1) from stb partition by abs(floor(c1)) order by abs(floor(c1))") + tdSql.checkRows(self.row_nums+1) + + + # interval + tdSql.query("select count(c1) from stb interval(2s) sliding(1s)") + + # bug need fix + + tdSql.query('select max(c1) from stb where ts>="2022-07-06 16:00:00.000 " and ts < "2022-07-06 17:00:00.000 " interval(50s) sliding(30s) fill(NULL)') + + tdSql.query(" select tbname , count(c1) from stb partition by tbname interval(10s) slimit 5 soffset 1 ") + + tdSql.query("select tbname , count(c1) from stb partition by tbname interval(10s)") + + tdSql.query("select tbname , count(c1) from sub_stb_1 partition by tbname interval(10s)") + tdSql.checkData(0,0,'sub_stb_1') + tdSql.checkData(0,1,self.row_nums) + + # tdSql.query(" select tbname , count(c1) from stb partition by tbname order by tbname slimit 5 soffset 0 ") + # tdSql.checkRows(5) + + # tdSql.query(" select tbname , count(c1) from stb partition by tbname order by tbname slimit 5 soffset 1 ") + # tdSql.checkRows(5) + + tdSql.query(" select tbname , count(c1) from sub_stb_1 partition by tbname interval(10s) sliding(5s) ") + + tdSql.query(f'select max(c1) from stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)') + tdSql.query(f'select max(c1) from stb where ts>={self.ts} and ts < {self.ts}+10000 interval(50s) sliding(30s)') + tdSql.query(f'select tbname , count(c1) from stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)') + + + def run(self): + tdSql.prepare() + self.prepare_datas("stb",self.tb_nums,self.row_nums) + self.basic_query() + + # # coverage case for taosd crash about bug fix + tdSql.query(" select sum(c1) from stb where t2+10 >1 ") + tdSql.query(" select count(c1),count(t1) from stb where -t2<1 ") + tdSql.query(" select tbname ,max(ceil(c1)) from stb group by tbname ") + tdSql.query(" select avg(abs(c1)) , tbname from stb group by tbname ") + tdSql.query(" select t1,c1 from stb where abs(t2+c1)=1 ") + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/2-query/csum.py b/tests/system-test/2-query/csum.py index 5bd1d4d45e..708aa35183 100644 --- a/tests/system-test/2-query/csum.py +++ b/tests/system-test/2-query/csum.py @@ -419,7 +419,7 @@ class TDTestCase: tdSql.checkData(3,0,4) tdSql.query("select csum(abs(c1))+2 from t1 ") tdSql.checkRows(4) - + def csum_support_stable(self): tdSql.query(" select csum(1) from stb1 ") tdSql.checkRows(70) @@ -434,17 +434,17 @@ class TDTestCase: tdSql.query("select csum(st1+c1) from stb1 partition by tbname") tdSql.checkRows(40) - # # bug need fix + # # bug need fix # tdSql.query("select csum(st1+c1) from stb1 partition by tbname slimit 1 ") # tdSql.checkRows(4) # tdSql.error("select csum(st1+c1) from stb1 partition by tbname limit 1 ") - # bug need fix + # bug need fix tdSql.query("select csum(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(40) + tdSql.checkRows(40) - # bug need fix + # bug need fix # tdSql.query("select tbname , csum(c1) from stb1 partition by tbname") # tdSql.checkRows(40) # tdSql.query("select tbname , csum(st1) from stb1 partition by tbname") @@ -452,7 +452,7 @@ class TDTestCase: # tdSql.query("select tbname , csum(st1) from stb1 partition by tbname slimit 1") # tdSql.checkRows(7) - # partition by tags + # partition by tags # tdSql.query("select st1 , csum(c1) from stb1 partition by st1") # tdSql.checkRows(40) # tdSql.query("select csum(c1) from stb1 partition by st1") @@ -491,4 +491,4 @@ class TDTestCase: tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/elapsed.py b/tests/system-test/2-query/elapsed.py index dfebb61d62..d2f1331e00 100644 --- a/tests/system-test/2-query/elapsed.py +++ b/tests/system-test/2-query/elapsed.py @@ -1315,24 +1315,26 @@ class TDTestCase: tdSql.error("select elapsed(tsv ,1s) from (select elapsed(ts,1s) tsv from regular_table_1);") tdSql.error("select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1);") # # bug fix - # tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from regular_table_1) ;") + tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from regular_table_1) ;") # case TD-12276 - # tdSql.error("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts asc );") + tdSql.query("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts asc );") + tdSql.checkData(0,0,90.000000000) - # tdSql.error("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts desc );") + tdSql.query("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts desc );") + tdSql.checkData(0,0,90.000000000) - # tdSql.error("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) interval(1s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from regular_table_1 order by ts ) interval(1s);") - # tdSql.error("select elapsed(ts,1s) from (select ts ,q_int,tbname from regular_table_1 order by ts ) interval(1s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,q_int,tbname from regular_table_1 order by ts ) interval(10s);") # sub table tdSql.query("select elapsed(ts,1s) from (select ts from sub_table1_1 );") - # tdSql.error("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from sub_table1_1 order by ts ) interval(1s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,max(q_int),tbname from sub_table1_1 order by ts ) interval(1s);") - # tdSql.error("select elapsed(ts,1s) from (select ts ,q_int,tbname from sub_table1_1 order by ts ) interval(1s);") + tdSql.query("select elapsed(ts,1s) from (select ts ,q_int,tbname from sub_table1_1 order by ts ) interval(10s);") tdSql.query("select elapsed(ts,1s) from (select ts ,tbname,top(q_int,3) from sub_table1_1 ) interval(10s);") @@ -1342,7 +1344,7 @@ class TDTestCase: tdSql.query("select elapsed(ts,1s) from (select ts ,tbname from sub_table1_1 ) interval(10s);") - # tdSql.error("select elapsed(ts,1s) from (select ts ,count(*),tbname from sub_table1_1 order by ts ) interval(1s);") + tdSql.error("select elapsed(ts,1s) from (select ts ,count(*),tbname from sub_table1_1 order by ts ) interval(1s);") querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)","elapsed(ts,1s)"] @@ -1488,8 +1490,8 @@ class TDTestCase: tdSql.query('select elapsed(ts,1s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') - # tdSql.error('select elapsed(ts,1s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') - # tdSql.error('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) session(ts,1w) ; ') + tdSql.query('select elapsed(ts,1s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ') + # tdSql.query('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) session(ts,1w) ; ') tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ') tdSql.checkRows(0) @@ -1506,14 +1508,14 @@ class TDTestCase: tdSql.checkRows(10) tdSql.checkData(0,0,0) - # tdSql.error('select elapsed(ts,1s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') + tdSql.query('select elapsed(ts,1s) from ( select * from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') - # tdSql.error('select elapsed(ts,1s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') + tdSql.query('select elapsed(ts,1s) from ( select ts ,q_int from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ') - # tdSql.error('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) state_window(q_int) ; ') + tdSql.error('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) state_window(q_int) ; ') - # tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int); ') - # tdSql.checkRows(0) + tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" state_window(q_int); ') + tdSql.checkRows(0) def continuous_query(self): diff --git a/tests/system-test/2-query/floor.py b/tests/system-test/2-query/floor.py index 7f5c7f5591..29fddda0ae 100644 --- a/tests/system-test/2-query/floor.py +++ b/tests/system-test/2-query/floor.py @@ -16,7 +16,7 @@ class TDTestCase: def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - + def prepare_datas(self): tdSql.execute( '''create table stb1 @@ -24,7 +24,7 @@ class TDTestCase: tags (t1 int) ''' ) - + tdSql.execute( ''' create table t1 @@ -66,14 +66,14 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - + def check_result_auto(self ,origin_query , floor_query): pass floor_result = tdSql.getResult(floor_query) origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -88,13 +88,13 @@ class TDTestCase: for row_index , row in enumerate(floor_result): for col_index , elem in enumerate(row): if auto_result[row_index][col_index] != elem: - check_status = False + check_status = False if not check_status: tdLog.notice("floor function value has not as expected , sql is \"%s\" "%floor_query ) sys.exit(1) else: tdLog.info("floor value check pass , it work as expected ,sql is \"%s\" "%floor_query ) - + def test_errors(self): error_sql_lists = [ "select floor from t1", @@ -128,42 +128,42 @@ class TDTestCase: ] for error_sql in error_sql_lists: tdSql.error(error_sql) - + def support_types(self): type_error_sql_lists = [ - "select floor(ts) from t1" , + "select floor(ts) from t1" , "select floor(c7) from t1", "select floor(c8) from t1", "select floor(c9) from t1", - "select floor(ts) from ct1" , + "select floor(ts) from ct1" , "select floor(c7) from ct1", "select floor(c8) from ct1", "select floor(c9) from ct1", - "select floor(ts) from ct3" , + "select floor(ts) from ct3" , "select floor(c7) from ct3", "select floor(c8) from ct3", "select floor(c9) from ct3", - "select floor(ts) from ct4" , + "select floor(ts) from ct4" , "select floor(c7) from ct4", "select floor(c8) from ct4", "select floor(c9) from ct4", - "select floor(ts) from stb1" , + "select floor(ts) from stb1" , "select floor(c7) from stb1", "select floor(c8) from stb1", "select floor(c9) from stb1" , - "select floor(ts) from stbbb1" , + "select floor(ts) from stbbb1" , "select floor(c7) from stbbb1", "select floor(ts) from tbname", "select floor(c9) from tbname" ] - + for type_sql in type_error_sql_lists: tdSql.error(type_sql) - - + + type_sql_lists = [ "select floor(c1) from t1", "select floor(c2) from t1", @@ -193,16 +193,16 @@ class TDTestCase: "select floor(c5) from stb1", "select floor(c6) from stb1", - "select floor(c6) as alisb from stb1", - "select floor(c6) alisb from stb1", + "select floor(c6) as alisb from stb1", + "select floor(c6) alisb from stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - + def basic_floor_function(self): - # basic query + # basic query tdSql.query("select c1 from ct3") tdSql.checkRows(0) tdSql.query("select c1 from t1") @@ -222,7 +222,7 @@ class TDTestCase: tdSql.query("select floor(c5) from ct3") tdSql.checkRows(0) tdSql.query("select floor(c6) from ct3") - + # used for regular table tdSql.query("select floor(c1) from t1") tdSql.checkData(0, 0, None) @@ -240,7 +240,7 @@ class TDTestCase: tdSql.checkData(5, 5, None) self.check_result_auto( "select c1, c2, c3 , c4, c5 from t1", "select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from t1") - + # used for sub table tdSql.query("select floor(c1) from ct1") tdSql.checkData(0, 0, 8) @@ -252,20 +252,20 @@ class TDTestCase: self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct1", "select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from ct1") self.check_result_auto("select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from ct1;","select c1 from ct1" ) - # used for stable table - + # used for stable table + tdSql.query("select floor(c1) from stb1") tdSql.checkRows(25) self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct4 ", "select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from ct4") self.check_result_auto("select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from ct4;" , "select c1 from ct4" ) - + # used for not exists table tdSql.error("select floor(c1) from stbbb1") tdSql.error("select floor(c1) from tbname") tdSql.error("select floor(c1) from ct5") - # mix with common col + # mix with common col tdSql.query("select c1, floor(c1) from ct1") tdSql.checkData(0 , 0 ,8) tdSql.checkData(0 , 1 ,8) @@ -290,7 +290,7 @@ class TDTestCase: tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 3 ,None) - + tdSql.checkData(3 , 0 , 6) tdSql.checkData(3 , 1 , 6) tdSql.checkData(3 , 2 ,6.66000) @@ -311,7 +311,7 @@ class TDTestCase: tdSql.query("select max(c5), count(c5) from stb1") tdSql.query("select max(c5), count(c5) from ct1") - + # bug fix for count tdSql.query("select count(c1) from ct4 ") tdSql.checkData(0,0,9) @@ -322,7 +322,7 @@ class TDTestCase: tdSql.query("select count(*) from stb1 ") tdSql.checkData(0,0,25) - # bug fix for compute + # bug fix for compute tdSql.query("select c1, abs(c1) -0 ,floor(c1)-0 from ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) @@ -373,10 +373,10 @@ class TDTestCase: tdSql.checkData(0,3,8.000000000) tdSql.checkData(0,4,7.900000000) tdSql.checkData(0,5,3.000000000) - + def floor_Arithmetic(self): pass - + def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") @@ -405,14 +405,14 @@ class TDTestCase: tdSql.execute( f"insert into sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - + tdSql.error( f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) self.check_result_auto( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select floor(c1), floor(c2) ,floor(c3), floor(c4), floor(c5) ,floor(c6) from sub1_bound") self.check_result_auto( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select floor(c1), floor(c2) ,floor(c3), floor(c3), floor(c2) ,floor(c1) from sub1_bound") self.check_result_auto("select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from sub1_bound;" , "select floor(c1) from sub1_bound" ) - + # check basic elem for table per row tdSql.query("select floor(c1+0.2) ,floor(c2) , floor(c3+0.3) , floor(c4-0.3), floor(c5/2), floor(c6/2) from sub1_bound ") tdSql.checkData(0, 0, 2147483647.000000000) @@ -444,26 +444,26 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: floor basic query ============") + tdLog.printNoPrefix("==========step4: floor basic query ============") self.basic_floor_function() - tdLog.printNoPrefix("==========step5: floor boundary query ============") + tdLog.printNoPrefix("==========step5: floor boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step6: floor filter query ============") + tdLog.printNoPrefix("==========step6: floor filter query ============") self.abs_func_filter() diff --git a/tests/system-test/2-query/function_diff.py b/tests/system-test/2-query/function_diff.py index 2bcacd5ae3..5e95510c1d 100644 --- a/tests/system-test/2-query/function_diff.py +++ b/tests/system-test/2-query/function_diff.py @@ -360,27 +360,27 @@ class TDTestCase: tdSql.checkRows(229) tdSql.checkData(0,0,0) tdSql.query("select diff(c1) from stb1 partition by tbname ") - tdSql.checkRows(199) + tdSql.checkRows(190) # tdSql.query("select diff(st1) from stb1 partition by tbname") # tdSql.checkRows(229) tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) - # # bug need fix + # # bug need fix # tdSql.query("select diff(st1+c1) from stb1 partition by tbname slimit 1 ") # tdSql.checkRows(19) # tdSql.error("select diff(st1+c1) from stb1 partition by tbname limit 1 ") - # bug need fix + # bug need fix tdSql.query("select diff(st1+c1) from stb1 partition by tbname") - tdSql.checkRows(199) + tdSql.checkRows(190) - # bug need fix + # bug need fix # tdSql.query("select tbname , diff(c1) from stb1 partition by tbname") # tdSql.checkRows(199) # tdSql.query("select tbname , diff(st1) from stb1 partition by tbname") @@ -388,7 +388,7 @@ class TDTestCase: # tdSql.query("select tbname , diff(st1) from stb1 partition by tbname slimit 1") # tdSql.checkRows(19) - # partition by tags + # partition by tags # tdSql.query("select st1 , diff(c1) from stb1 partition by st1") # tdSql.checkRows(199) # tdSql.query("select diff(c1) from stb1 partition by st1") @@ -488,4 +488,4 @@ class TDTestCase: tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/function_stateduration.py b/tests/system-test/2-query/function_stateduration.py index a716d67236..3478b7fef9 100644 --- a/tests/system-test/2-query/function_stateduration.py +++ b/tests/system-test/2-query/function_stateduration.py @@ -11,7 +11,7 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'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 ,"udfDebugFlag":143} @@ -388,11 +388,11 @@ class TDTestCase: tdSql.execute( f"insert into sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - + tdSql.error( f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - + tdSql.query("select stateduration(c1,'GT',1,1s) from sub1_bound") tdSql.checkRows(5) @@ -400,29 +400,29 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4:support opers ============") + tdLog.printNoPrefix("==========step4:support opers ============") self.support_opers() - tdLog.printNoPrefix("==========step5: stateduration basic query ============") + tdLog.printNoPrefix("==========step5: stateduration basic query ============") self.basic_stateduration_function() - tdLog.printNoPrefix("==========step6: stateduration boundary query ============") + tdLog.printNoPrefix("==========step6: stateduration boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step6: stateduration unit time test ============") + tdLog.printNoPrefix("==========step6: stateduration unit time test ============") self.check_unit_time() diff --git a/tests/system-test/2-query/last.py b/tests/system-test/2-query/last.py index ee65d22a22..d07d0c83eb 100644 --- a/tests/system-test/2-query/last.py +++ b/tests/system-test/2-query/last.py @@ -34,7 +34,7 @@ class TDTestCase: tag_sql += f"{k} {v}," create_stb_sql = f'create table {stbname} (ts timestamp,{column_sql[:-1]}) tags({tag_sql[:-1]})' return create_stb_sql - + def last_check_stb_tb_base(self): tdSql.prepare() stbname = tdCom.getLongName(5, "letters") @@ -201,7 +201,7 @@ class TDTestCase: tdSql.execute(f'use {dbname}') # build 20 child tables,every table insert 10 rows - tdSql.execute(f'''create table {stbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, + tdSql.execute(f'''create table {stbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''') for i in range(self.tbnum): tdSql.execute( diff --git a/tests/system-test/2-query/mavg.py b/tests/system-test/2-query/mavg.py index 346d9e1df3..91e5e013b4 100644 --- a/tests/system-test/2-query/mavg.py +++ b/tests/system-test/2-query/mavg.py @@ -159,7 +159,7 @@ class TDTestCase: return tdSql.error(self.mavg_query_form( sel=sel, func=func, col=col, m_comm=m_comm, k=k, r_comm=r_comm, alias=alias, fr=fr, table_expr=table_expr, condition=condition - )) + )) if all(["group" in condition.lower(), "tbname" not in condition.lower()]): print(f"case in {line}: ", end='') @@ -295,7 +295,7 @@ class TDTestCase: pre_result = np.array(tdSql.queryResult)[np.array(tdSql.queryResult) != None] if (platform.system().lower() == 'windows' and pre_result.dtype == 'int32'): pre_result = np.array(pre_result, dtype = 'int64') - + pre_mavg = pre_mavg = np.convolve(pre_result, np.ones(k), "valid")[offset_val:]/k tdSql.query(self.mavg_query_form( sel=sel, func=func, col=col, m_comm=m_comm, k=k, r_comm=r_comm, alias=alias, fr=fr, @@ -669,7 +669,7 @@ class TDTestCase: tdSql.checkData(0,0,1.000000000) tdSql.checkData(1,0,1.000000000) tdSql.checkData(5,0,1.000000000) - + tdSql.query("select mavg(abs(c1),1) from t1") tdSql.checkRows(4) @@ -678,27 +678,27 @@ class TDTestCase: tdSql.checkRows(68) tdSql.checkData(0,0,1.000000000) tdSql.query("select mavg(c1,3) from stb1 partition by tbname ") - tdSql.checkRows(38) + tdSql.checkRows(20) # tdSql.query("select mavg(st1,3) from stb1 partition by tbname") # tdSql.checkRows(38) tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) - # # bug need fix + # # bug need fix # tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname slimit 1 ") # tdSql.checkRows(2) # tdSql.error("select mavg(st1+c1,3) from stb1 partition by tbname limit 1 ") - # bug need fix + # bug need fix tdSql.query("select mavg(st1+c1,3) from stb1 partition by tbname") - tdSql.checkRows(38) + tdSql.checkRows(20) - # bug need fix + # bug need fix # tdSql.query("select tbname , mavg(c1,3) from stb1 partition by tbname") # tdSql.checkRows(38) # tdSql.query("select tbname , mavg(st1,3) from stb1 partition by tbname") @@ -706,7 +706,7 @@ class TDTestCase: # tdSql.query("select tbname , mavg(st1,3) from stb1 partition by tbname slimit 1") # tdSql.checkRows(2) - # partition by tags + # partition by tags # tdSql.query("select st1 , mavg(c1,3) from stb1 partition by st1") # tdSql.checkRows(38) # tdSql.query("select mavg(c1,3) from stb1 partition by st1") @@ -743,4 +743,4 @@ class TDTestCase: tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/max.py b/tests/system-test/2-query/max.py index 0ca3f8f71a..8a5dca3763 100644 --- a/tests/system-test/2-query/max.py +++ b/tests/system-test/2-query/max.py @@ -5,7 +5,7 @@ import numpy as np class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'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 ,"udfDebugFlag":143, "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } @@ -19,15 +19,15 @@ class TDTestCase: self.nchar_str = '涛思数据' def max_check_stb_and_tb_base(self): tdSql.prepare() - intData = [] + intData = [] floatData = [] - tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, + tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''') tdSql.execute("create table stb_1 using stb tags('beijing')") for i in range(self.rowNum): tdSql.execute(f"insert into stb_1 values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) - intData.append(i + 1) + intData.append(i + 1) floatData.append(i + 0.1) for i in ['ts','col11','col12','col13']: for j in ['db.stb','stb','db.stb_1','stb_1']: @@ -45,17 +45,17 @@ class TDTestCase: tdSql.query("select max(col1) from stb where col2<=5") tdSql.checkData(0,0,5) tdSql.execute('drop database db') - + def max_check_ntb_base(self): tdSql.prepare() - intData = [] + intData = [] floatData = [] - tdSql.execute('''create table ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, + tdSql.execute('''create table ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20))''') for i in range(self.rowNum): tdSql.execute(f"insert into ntb values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) - intData.append(i + 1) + intData.append(i + 1) floatData.append(i + 0.1) for i in ['ts','col11','col12','col13']: for j in ['db.ntb','ntb']: @@ -79,7 +79,7 @@ class TDTestCase: same_sql = f"select {col_name} from {tbname} order by {col_name} desc limit 1" tdSql.query(max_sql) - max_result = tdSql.queryResult + max_result = tdSql.queryResult tdSql.query(same_sql) same_result = tdSql.queryResult @@ -91,7 +91,7 @@ class TDTestCase: def support_distributed_aggregate(self): - + # prepate datas for 20 tables distributed at different vgroups tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") tdSql.execute(" use testdb ") @@ -161,17 +161,17 @@ class TDTestCase: vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] - + # check sub_table of per vnode ,make sure sub_table has been distributed tdSql.query("show tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) count = 0 for k ,v in vnode_tables.items(): @@ -180,8 +180,8 @@ class TDTestCase: if count < 2: tdLog.exit(" the datas of all not satisfy sub_table has been distributed ") - # check max function work status - + # check max function work status + tdSql.query("show tables like 'ct%'") table_names = tdSql.queryResult tablenames = [] @@ -190,23 +190,23 @@ class TDTestCase: tdSql.query("desc stb1") col_names = tdSql.queryResult - + colnames = [] for col_name in col_names: if col_name[1] in ["INT" ,"BIGINT" ,"SMALLINT" ,"TINYINT" , "FLOAT" ,"DOUBLE"]: colnames.append(col_name[0]) - + for tablename in tablenames: for colname in colnames: self.check_max_functions(tablename,colname) - # max function with basic filter + # max function with basic filter print(vnode_tables) - def run(self): + def run(self): - # max verifacation + # max verifacation self.max_check_stb_and_tb_base() self.max_check_ntb_base() diff --git a/tests/system-test/2-query/max_partition.py b/tests/system-test/2-query/max_partition.py new file mode 100644 index 0000000000..90b8d25cb1 --- /dev/null +++ b/tests/system-test/2-query/max_partition.py @@ -0,0 +1,189 @@ +# author : wenzhouwww +from util.log import * +from util.sql import * +from util.cases import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.row_nums = 10 + self.tb_nums = 10 + self.ts = 1537146000000 + + def prepare_datas(self, stb_name , tb_nums , row_nums ): + tdSql.execute(" use db ") + tdSql.execute(f" create stable {stb_name} (ts timestamp , c1 int , c2 bigint , c3 float , c4 double , c5 smallint , c6 tinyint , c7 bool , c8 binary(36) , c9 nchar(36) , uc1 int unsigned,\ + uc2 bigint unsigned ,uc3 smallint unsigned , uc4 tinyint unsigned ) tags(t1 timestamp , t2 int , t3 bigint , t4 float , t5 double , t6 smallint , t7 tinyint , t8 bool , t9 binary(36)\ + , t10 nchar(36) , t11 int unsigned , t12 bigint unsigned ,t13 smallint unsigned , t14 tinyint unsigned ) ") + + for i in range(tb_nums): + tbname = f"sub_{stb_name}_{i}" + ts = self.ts + i*10000 + tdSql.execute(f"create table {tbname} using {stb_name} tags ({ts} , {i} , {i}*10 ,{i}*1.0,{i}*1.0 , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )") + + for row in range(row_nums): + ts = self.ts + row*1000 + tdSql.execute(f"insert into {tbname} values({ts} , {row} , {row} , {row} , {row} , 1 , 2 , 'true' , 'binary_{row}' , 'nchar_{row}' , {row} , {row} , 1 ,2 )") + + for null in range(5): + ts = self.ts + row_nums*1000 + null*1000 + tdSql.execute(f"insert into {tbname} values({ts} , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL )") + + def basic_query(self): + tdSql.query("select count(*) from stb") + tdSql.checkData(0,0,(self.row_nums + 5 )*self.tb_nums) + tdSql.query("select max(c1) from stb") + tdSql.checkData(0,0,(self.row_nums -1)) + tdSql.query(" select tbname , max(c1) from stb partition by tbname ") + tdSql.checkRows(self.tb_nums) + tdSql.query(" select max(c1) from stb group by t1 order by t1 ") + tdSql.checkRows(self.tb_nums) + tdSql.query(" select max(c1) from stb group by c1 order by t1 ") + tdSql.query(" select max(t2) from stb group by c1 order by t1 ") + tdSql.query(" select max(c1) from stb group by tbname order by tbname ") + tdSql.checkRows(self.tb_nums) + # bug need fix + # tdSql.query(" select max(t1) from stb group by t2 order by t2 ") + # tdSql.checkRows(self.tb_nums) + tdSql.query(" select max(c1) from stb group by c1 order by c1 ") + tdSql.checkRows(self.row_nums+1) + + tdSql.query(" select c1 , max(c1) from stb group by c1 order by c1 ") + tdSql.checkRows(self.row_nums+1) + + # support selective functions + tdSql.query(" select c1 ,c2 ,c3 , max(c1) ,c4 ,c5 ,t11 from stb group by c1 order by c1 desc ") + tdSql.checkRows(self.row_nums+1) + + tdSql.query(" select c1, tbname , max(c1) ,c4 ,c5 ,t11 from stb group by c1 order by c1 desc ") + tdSql.checkRows(self.row_nums+1) + + # bug need fix + # tdSql.query(" select tbname , max(c1) from sub_stb_1 where c1 is null group by c1 order by c1 desc ") + # tdSql.checkRows(1) + # tdSql.checkData(0,0,"sub_stb_1") + + tdSql.query("select max(c1) ,c2 ,t2,tbname from stb group by abs(c1) order by abs(c1)") + tdSql.checkRows(self.row_nums+1) + tdSql.query("select abs(c1+c3), count(c1+c3) ,max(c1+t2) from stb group by abs(c1+c3) order by abs(c1+c3)") + tdSql.checkRows(self.row_nums+1) + tdSql.query("select max(c1+c3)+min(c2) ,abs(c1) from stb group by abs(c1) order by abs(c1)") + tdSql.checkRows(self.row_nums+1) + tdSql.error("select count(c1+c3)+max(c2) ,abs(c1) ,abs(t1) from stb group by abs(c1) order by abs(t1)+c2") + tdSql.error("select count(c1+c3)+max(c2) ,abs(c1) from stb group by abs(c1) order by abs(c1)+c2") + tdSql.query("select abs(c1+c3)+abs(c2) , count(c1+c3)+max(c2) from stb group by abs(c1+c3)+abs(c2) order by abs(c1+c3)+abs(c2)") + tdSql.checkRows(self.row_nums+1) + + tdSql.query(" select max(c1) , max(t2) from stb where abs(c1+t2)=1 partition by tbname ") + tdSql.checkRows(2) + tdSql.query(" select max(c1) from stb where abs(c1+t2)=1 partition by tbname ") + tdSql.checkRows(2) + + tdSql.query(" select tbname , max(c1) from stb partition by tbname order by tbname ") + tdSql.checkRows(self.tb_nums) + tdSql.checkData(0,1,self.row_nums-1) + + tdSql.query("select tbname , max(c2) from stb partition by t1 order by t1") + tdSql.query("select tbname , max(t2) from stb partition by t1 order by t1") + tdSql.query("select tbname , max(t2) from stb partition by t2 order by t2") + + # # bug need fix + # tdSql.query("select t2 , max(t2) from stb partition by t2 order by t2") + # tdSql.checkRows(self.tb_nums) + + tdSql.query("select tbname , max(c1) from stb partition by tbname order by tbname") + tdSql.checkRows(self.tb_nums) + tdSql.checkData(0,1,self.row_nums-1) + + + tdSql.query("select tbname , max(c1) from stb partition by t2 order by t2") + + tdSql.query("select c2, max(c1) from stb partition by c2 order by c2 desc") + tdSql.checkRows(self.tb_nums+1) + tdSql.checkData(0,1,self.row_nums-1) + + tdSql.query("select tbname , max(c1) from stb partition by c1 order by c2") + + + tdSql.query("select tbname , abs(t2) from stb partition by c2 order by t2") + tdSql.checkRows(self.tb_nums*(self.row_nums+5)) + + tdSql.query("select max(c1) , count(t2) from stb partition by c2 ") + tdSql.checkRows(self.row_nums+1) + tdSql.checkData(0,1,self.row_nums) + + tdSql.query("select count(c1) , max(t2) ,c2 from stb partition by c2 order by c2") + tdSql.checkRows(self.row_nums+1) + + tdSql.query("select count(c1) , count(t1) ,max(c2) ,tbname from stb partition by tbname order by tbname") + tdSql.checkRows(self.tb_nums) + tdSql.checkCols(4) + + tdSql.query("select count(c1) , max(t2) ,t1 from stb partition by t1 order by t1") + tdSql.checkRows(self.tb_nums) + tdSql.checkData(0,0,self.row_nums) + + # bug need fix + # tdSql.query("select count(c1) , max(t1) ,abs(c1) from stb partition by abs(c1) order by abs(c1)") + # tdSql.checkRows(self.row_nums+1) + + + tdSql.query("select max(ceil(c2)) , max(floor(t2)) ,max(floor(c2)) from stb partition by abs(c2) order by abs(c2)") + tdSql.checkRows(self.row_nums+1) + + + tdSql.query("select max(ceil(c1-2)) , max(floor(t2+1)) ,max(c2-c1) from stb partition by abs(floor(c1)) order by abs(floor(c1))") + tdSql.checkRows(self.row_nums+1) + + + # interval + tdSql.query("select max(c1) from stb interval(2s) sliding(1s)") + + # bug need fix + + tdSql.query('select max(c1) from stb where ts>="2022-07-06 16:00:00.000 " and ts < "2022-07-06 17:00:00.000 " interval(50s) sliding(30s) fill(NULL)') + + tdSql.query(" select tbname , count(c1) from stb partition by tbname interval(10s) slimit 5 soffset 1 ") + + tdSql.query("select tbname , max(c1) from stb partition by tbname interval(10s)") + tdSql.checkRows(self.row_nums*2) + + tdSql.query("select tbname , count(c1) from sub_stb_1 partition by tbname interval(10s)") + tdSql.checkData(0,0,'sub_stb_1') + tdSql.checkData(0,1,self.row_nums) + + # bug need fix + # tdSql.query(" select tbname , max(c1) from stb partition by tbname order by tbname slimit 5 soffset 0 ") + # tdSql.checkRows(5) + + # tdSql.query(" select tbname , max(c1) from stb partition by tbname order by tbname slimit 5 soffset 1 ") + # tdSql.checkRows(5) + + tdSql.query(" select tbname , max(c1) from sub_stb_1 partition by tbname interval(10s) sliding(5s) ") + + tdSql.query(f'select max(c1) from stb where ts>={self.ts} and ts < {self.ts}+1000 interval(50s) sliding(30s)') + tdSql.query(f'select tbname , max(c1) from stb where ts>={self.ts} and ts < {self.ts}+1000 interval(50s) sliding(30s)') + + + def run(self): + tdSql.prepare() + self.prepare_datas("stb",self.tb_nums,self.row_nums) + self.basic_query() + + # # coverage case for taosd crash about bug fix + tdSql.query(" select sum(c1) from stb where t2+10 >1 ") + tdSql.query(" select count(c1),count(t1) from stb where -t2<1 ") + tdSql.query(" select tbname ,max(ceil(c1)) from stb group by tbname ") + tdSql.query(" select avg(abs(c1)) , tbname from stb group by tbname ") + tdSql.query(" select t1,c1 from stb where abs(t2+c1)=1 ") + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/2-query/min.py b/tests/system-test/2-query/min.py index 60a8c105f1..c27e9926ff 100644 --- a/tests/system-test/2-query/min.py +++ b/tests/system-test/2-query/min.py @@ -12,30 +12,30 @@ class TDTestCase: self.rowNum = 10 self.ts = 1537146000000 - + def run(self): tdSql.prepare() - intData = [] + intData = [] floatData = [] - tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''') tdSql.execute("create table stb_1 using stb tags('beijing')") - tdSql.execute('''create table ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute('''create table ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') for i in range(self.rowNum): - tdSql.execute("insert into ntb values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute("insert into ntb values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - intData.append(i + 1) + intData.append(i + 1) floatData.append(i + 0.1) for i in range(self.rowNum): - tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - intData.append(i + 1) - floatData.append(i + 0.1) + intData.append(i + 1) + floatData.append(i + 0.1) - # max verifacation + # max verifacation tdSql.error("select min(ts) from stb_1") tdSql.error("select min(ts) from db.stb_1") tdSql.error("select min(col7) from stb_1") @@ -206,7 +206,7 @@ class TDTestCase: tdSql.query("select min(col1) from ntb where col2>=5") tdSql.checkData(0,0,5) - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/nestedQuery.py b/tests/system-test/2-query/nestedQuery.py index 9f2b8c4b56..757a75cf88 100755 --- a/tests/system-test/2-query/nestedQuery.py +++ b/tests/system-test/2-query/nestedQuery.py @@ -23,10 +23,10 @@ from util.dnodes import tdDnodes from util.dnodes import * class TDTestCase: - updatecfgDict = {'maxSQLLength':1048576,'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + 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 ,"udfDebugFlag":143} - + def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) @@ -34,28 +34,28 @@ class TDTestCase: testcasePath = os.path.split(__file__)[0] testcaseFilename = os.path.split(__file__)[-1] os.system("rm -rf %s/%s.sql" % (testcasePath,testcaseFilename)) - + now = time.time() self.ts = int(round(now * 1000)) self.num = 10 self.fornum = 5 # def case_common(self): - # db = "nested" - # self.dropandcreateDB("%s" % db, 1) + # db = "nested" + # self.dropandcreateDB("%s" % db, 1) # conn1 = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos/") - # cur1 = conn1.cursor() + # cur1 = conn1.cursor() # cur1.execute('use "%s";' %self.db) # sql = 'select * from stable_1 limit 5;' # cur1.execute(sql) - # return(conn1,cur1) - + # return(conn1,cur1) + def data_matrix_equal(self, sql1,row1_s,row1_e,col1_s,col1_e, sql2,row2_s,row2_e,col2_s,col2_e): # ----row1_start----col1_start---- - # - - - - 是一个矩阵内的数据相等- - - - # - - - - - - - - - - - - - - - - + # - - - - 是一个矩阵内的数据相等- - - + # - - - - - - - - - - - - - - - - # ----row1_end------col1_end------ self.sql1 = sql1 list1 =[] @@ -67,9 +67,9 @@ class TDTestCase: #print("data=%s" %(tdSql.getData(i1,j1))) list1.append(tdSql.getData(i1,j1)) print("=====list1-------list1---=%s" %set(list1)) - + tdSql.execute("reset query cache;") - self.sql2 = sql2 + self.sql2 = sql2 list2 =[] tdSql.query(sql2) for i2 in range(row2_s-1,row2_e): @@ -78,8 +78,8 @@ class TDTestCase: #print("jjjj222=%d"%j2) #print("data=%s" %(tdSql.getData(i2,j2))) list2.append(tdSql.getData(i2,j2)) - print("=====list2-------list2---=%s" %set(list2)) - + print("=====list2-------list2---=%s" %set(list2)) + if (list1 == list2) and len(list2)>0: # print(("=====matrix===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) tdLog.info(("===matrix===sql1:'%s' matrix_result = sql2:'%s' matrix_result") %(sql1,sql2)) @@ -105,7 +105,7 @@ class TDTestCase: print(("=====matrix_error===sql1.list1:'%s',sql2.list2:'%s'") %(list1,list2)) tdLog.info(("sql1:'%s' matrix_result != sql2:'%s' matrix_result") %(sql1,sql2)) return tdSql.checkEqual(list1,list2) - + def restartDnodes(self): pass # tdDnodes.stop(1) @@ -125,7 +125,7 @@ class TDTestCase: 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);''') - + tdSql.execute('''create stable stable_null_data (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);''') @@ -133,35 +133,35 @@ class TDTestCase: tdSql.execute('''create stable stable_null_childtable (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);''') - + #tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '0' , '0' , '0' , '0' , 0 , 'binary1' , 'nchar1' , '0' , '0' ,'0') ;''') - tdSql.execute('''create table stable_1_1 using stable_1 tags('stable_1_1', '%d' , '%d', '%d' , '%d' , 0 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(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 stable_1_1 using stable_1 tags('stable_1_1', '%d' , '%d', '%d' , '%d' , 0 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(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 stable_1_2 using stable_1 tags('stable_1_2', '2147483647' , '9223372036854775807' , '32767' , '127' , 1 , 'binary2' , 'nchar2' , '2' , '22' , \'1999-09-09 09:09:09.090\') ;''') tdSql.execute('''create table stable_1_3 using stable_1 tags('stable_1_3', '-2147483647' , '-9223372036854775807' , '-32767' , '-127' , false , 'binary3' , 'nchar3nchar3' , '-3.3' , '-33.33' , \'2099-09-09 09:09:09.090\') ;''') #tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - tdSql.execute('''create table stable_1_4 using stable_1 tags('stable_1_4', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(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 stable_1_4 using stable_1 tags('stable_1_4', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(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 stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,'0') ;''') # tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') # tdSql.execute('''create table stable_null_data_1 using stable_null_data tags('stable_null_data_1', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0') ;''') - - tdSql.execute('''create table stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,\'2099-09-09 09:09:09.090\') ;''') - tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '%d' , '%d', '%d' , '%d' , 0 , 'binary2.%s' , 'nchar2.%s' , '%f', '%f' ,'%d') ;''' - %(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 stable_null_data_1 using stable_null_data tags('stable_null_data_1', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' - %(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 stable_2_1 using stable_2 tags('stable_2_1' , '0' , '0' , '0' , '0' , 0 , 'binary21' , 'nchar21' , '0' , '0' ,\'2099-09-09 09:09:09.090\') ;''') + tdSql.execute('''create table stable_2_2 using stable_2 tags('stable_2_2' , '%d' , '%d', '%d' , '%d' , 0 , 'binary2.%s' , 'nchar2.%s' , '%f', '%f' ,'%d') ;''' + %(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 stable_null_data_1 using stable_null_data tags('stable_null_data_1', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(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))) #regular table tdSql.execute('''create table regular_table_1 \ @@ -179,50 +179,50 @@ class TDTestCase: 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) ;''') - for i in range(num_random*n): - tdSql.execute('''insert into stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' - % (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) , + for i in range(num_random*n): + tdSql.execute('''insert into stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' + % (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.address() , ts + i)) - tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' - % (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) , + tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' + % (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.address() , ts + i)) - tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (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) , + tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' + % (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.address() , ts + i)) - tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (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) , + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' + % (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.address() , ts + i)) - - tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), - fake.random_int(min=-9223372036854775807, max=0, step=1), - fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , + + tdSql.execute('''insert into stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' + % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), + fake.random_int(min=-9223372036854775807, max=0, step=1), + fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i +1)) - tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' - % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), - fake.random_int(min=-9223372036854775807, max=0, step=1), - fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d) ;''' + % (ts + i*1000 +1, fake.random_int(min=-2147483647, max=0, step=1), + fake.random_int(min=-9223372036854775807, max=0, step=1), + fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i +1)) - tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' - % (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) , + tdSql.execute('''insert into stable_2_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d) ;''' + % (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.address() , ts + i)) - # tdSql.execute('''insert into regular_table_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d)''' - # % (ts + i*1000, fake.random_int(min=-2147483647, max=0, step=1), - # fake.random_int(min=-9223372036854775807, max=0, step=1), - # fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , + # tdSql.execute('''insert into regular_table_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts) values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d)''' + # % (ts + i*1000, fake.random_int(min=-2147483647, max=0, step=1), + # fake.random_int(min=-9223372036854775807, max=0, step=1), + # fake.random_int(min=-32767, max=0, step=1) , fake.random_int(min=-127, max=0, step=1) , # fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.address() , ts + i)) tdSql.query("select count(*) from stable_1;") @@ -234,9 +234,9 @@ class TDTestCase: def run(self): tdSql.prepare() os.system("rm -rf nestedQuery3.py.sql") - - startTime = time.time() - + + startTime = time.time() + db = "nest" self.dropandcreateDB_random("%s" %db, 1) @@ -252,11 +252,11 @@ class TDTestCase: qt_select= q_select + t_select # distinct regular column select - dq_select= ['distinct q_int', 'distinct q_bigint' , 'distinct q_smallint' , 'distinct q_tinyint' , + dq_select= ['distinct q_int', 'distinct q_bigint' , 'distinct q_smallint' , 'distinct q_tinyint' , 'distinct q_bool' , 'distinct q_binary' , 'distinct q_nchar' ,'distinct q_float' , 'distinct q_double' ,'distinct q_ts '] # distinct tag column select - dt_select= ['distinct loc', 'distinct t_int', 'distinct t_bigint' , 'distinct t_smallint' , 'distinct t_tinyint' , + dt_select= ['distinct loc', 'distinct t_int', 'distinct t_bigint' , 'distinct t_smallint' , 'distinct t_tinyint' , 'distinct t_bool' , 'distinct t_binary' , 'distinct t_nchar' ,'distinct t_float' , 'distinct t_double' ,'distinct t_ts '] # distinct regular and tag column select @@ -267,12 +267,12 @@ class TDTestCase: s_s_select= ['tbname' , '_rowts' , '_c0', '_C0' ] unionall_or_union= [ ' union ' , ' union all ' ] - # regular column where + # regular column where q_where = ['ts < now +1s','q_bigint >= -9223372036854775807 and q_bigint <= 9223372036854775807', 'q_int <= 2147483647 and q_int >= -2147483647', - 'q_smallint >= -32767 and q_smallint <= 32767','q_tinyint >= -127 and q_tinyint <= 127','q_float >= -1.7E308 and q_float <= 1.7E308', - 'q_double >= -1.7E308 and q_double <= 1.7E308', 'q_binary like \'binary%\' or q_binary = \'0\' ' , 'q_nchar like \'nchar%\' or q_nchar = \'0\' ' , + 'q_smallint >= -32767 and q_smallint <= 32767','q_tinyint >= -127 and q_tinyint <= 127','q_float >= -1.7E308 and q_float <= 1.7E308', + 'q_double >= -1.7E308 and q_double <= 1.7E308', 'q_binary like \'binary%\' or q_binary = \'0\' ' , 'q_nchar like \'nchar%\' or q_nchar = \'0\' ' , 'q_bool = true or q_bool = false' , 'q_bool in (0 , 1)' , 'q_bool in ( true , false)' , 'q_bool = 0 or q_bool = 1', - 'q_bigint between -9223372036854775807 and 9223372036854775807',' q_int between -2147483647 and 2147483647','q_smallint between -32767 and 32767', + 'q_bigint between -9223372036854775807 and 9223372036854775807',' q_int between -2147483647 and 2147483647','q_smallint between -32767 and 32767', 'q_tinyint between -127 and 127 ','q_float >= -3.4E38 ','q_float <= 3.4E38 ','q_double >= -1.7E308 ', 'q_double <= 1.7E308 ','q_float between -3.4E38 and 3.4E38 ','q_double between -1.7E308 and 1.7E308 ' , 'q_float is not null ' ,'q_double is not null ' ,] @@ -284,33 +284,33 @@ class TDTestCase: 't1.q_smallint >= -32767 and t1.q_smallint <= 32767 and t2.q_smallint >= -32767 and t2.q_smallint <= 32767', 't1.q_tinyint >= -127 and t1.q_tinyint <= 127 and t2.q_tinyint >= -127 and t2.q_tinyint <= 127', 't1.q_float >= - 1.7E308 and t1.q_float <= 1.7E308 and t2.q_float >= - 1.7E308 and t2.q_float <= 1.7E308', - 't1.q_double >= - 1.7E308 and t1.q_double <= 1.7E308 and t2.q_double >= - 1.7E308 and t2.q_double <= 1.7E308', - 't1.q_binary like \'binary%\' and t2.q_binary like \'binary%\' ' , - 't1.q_nchar like \'nchar%\' and t2.q_nchar like \'nchar%\' ' , - 't1.q_bool in (0 , 1) and t2.q_bool in (0 , 1)' , 't1.q_bool in ( true , false) and t2.q_bool in ( true , false)' , + 't1.q_double >= - 1.7E308 and t1.q_double <= 1.7E308 and t2.q_double >= - 1.7E308 and t2.q_double <= 1.7E308', + 't1.q_binary like \'binary%\' and t2.q_binary like \'binary%\' ' , + 't1.q_nchar like \'nchar%\' and t2.q_nchar like \'nchar%\' ' , + 't1.q_bool in (0 , 1) and t2.q_bool in (0 , 1)' , 't1.q_bool in ( true , false) and t2.q_bool in ( true , false)' , 't1.q_bigint between -9223372036854775807 and 9223372036854775807 and t2.q_bigint between -9223372036854775807 and 9223372036854775807', 't1.q_int between -2147483647 and 2147483647 and t2.q_int between -2147483647 and 2147483647', - 't1.q_smallint between -32767 and 32767 and t2.q_smallint between -32767 and 32767', + 't1.q_smallint between -32767 and 32767 and t2.q_smallint between -32767 and 32767', 't1.q_tinyint between -127 and 127 and t2.q_tinyint between -127 and 127 ','t1.q_float between -1.7E308 and 1.7E308 and t2.q_float between -1.7E308 and 1.7E308', 't1.q_double between -1.7E308 and 1.7E308 and t2.q_double between -1.7E308 and 1.7E308'] #TD-6201 ,'t1.q_bool between 0 and 1 or t2.q_bool between 0 and 1'] #'t1.q_bool = true and t1.q_bool = false and t2.q_bool = true and t2.q_bool = false' , 't1.q_bool = 0 and t1.q_bool = 1 and t2.q_bool = 0 and t2.q_bool = 1' , - q_u_or_where = ['(t1.q_binary like \'binary%\' or t1.q_binary = \'0\' or t2.q_binary like \'binary%\' or t2.q_binary = \'0\' )' , - '(t1.q_nchar like \'nchar%\' or t1.q_nchar = \'0\' or t2.q_nchar like \'nchar%\' or t2.q_nchar = \'0\' )' , '(t1.q_bool = true or t1.q_bool = false or t2.q_bool = true or t2.q_bool = false)' , + q_u_or_where = ['(t1.q_binary like \'binary%\' or t1.q_binary = \'0\' or t2.q_binary like \'binary%\' or t2.q_binary = \'0\' )' , + '(t1.q_nchar like \'nchar%\' or t1.q_nchar = \'0\' or t2.q_nchar like \'nchar%\' or t2.q_nchar = \'0\' )' , '(t1.q_bool = true or t1.q_bool = false or t2.q_bool = true or t2.q_bool = false)' , '(t1.q_bool in (0 , 1) or t2.q_bool in (0 , 1))' , '(t1.q_bool in ( true , false) or t2.q_bool in ( true , false))' , '(t1.q_bool = 0 or t1.q_bool = 1 or t2.q_bool = 0 or t2.q_bool = 1)' , '(t1.q_bigint between -9223372036854775807 and 9223372036854775807 or t2.q_bigint between -9223372036854775807 and 9223372036854775807)', '(t1.q_int between -2147483647 and 2147483647 or t2.q_int between -2147483647 and 2147483647)', - '(t1.q_smallint between -32767 and 32767 or t2.q_smallint between -32767 and 32767)', + '(t1.q_smallint between -32767 and 32767 or t2.q_smallint between -32767 and 32767)', '(t1.q_tinyint between -127 and 127 or t2.q_tinyint between -127 and 127 )','(t1.q_float between -1.7E308 and 1.7E308 or t2.q_float between -1.7E308 and 1.7E308)', '(t1.q_double between -1.7E308 and 1.7E308 or t2.q_double between -1.7E308 and 1.7E308)'] # tag column where t_where = ['ts < now +1s','t_bigint >= -9223372036854775807 and t_bigint <= 9223372036854775807','t_int <= 2147483647 and t_int >= -2147483647', 't_smallint >= -32767 and t_smallint <= 32767','q_tinyint >= -127 and t_tinyint <= 127','t_float >= -1.7E308 and t_float <= 1.7E308', - 't_double >= -1.7E308 and t_double <= 1.7E308', 't_binary like \'binary%\' or t_binary = \'0\' ' , 't_nchar like \'nchar%\' or t_nchar = \'0\'' , + 't_double >= -1.7E308 and t_double <= 1.7E308', 't_binary like \'binary%\' or t_binary = \'0\' ' , 't_nchar like \'nchar%\' or t_nchar = \'0\'' , 't_bool = true or t_bool = false' , 't_bool in (0 , 1)' , 't_bool in ( true , false)' , 't_bool = 0 or t_bool = 1', - 't_bigint between -9223372036854775807 and 9223372036854775807',' t_int between -2147483647 and 2147483647','t_smallint between -32767 and 32767', + 't_bigint between -9223372036854775807 and 9223372036854775807',' t_int between -2147483647 and 2147483647','t_smallint between -32767 and 32767', 't_tinyint between -127 and 127 ','t_float between -1.7E308 and 1.7E308','t_double between -1.7E308 and 1.7E308'] #TD-6201,'t_bool between 0 and 1' @@ -320,27 +320,27 @@ class TDTestCase: 't1.t_smallint >= -32767 and t1.t_smallint <= 32767 and t2.t_smallint >= -32767 and t2.t_smallint <= 32767', 't1.t_tinyint >= -127 and t1.t_tinyint <= 127 and t2.t_tinyint >= -127 and t2.t_tinyint <= 127', 't1.t_float >= -1.7E308 and t1.t_float <= 1.7E308 and t2.t_float >= -1.7E308 and t2.t_float <= 1.7E308', - 't1.t_double >= -1.7E308 and t1.t_double <= 1.7E308 and t2.t_double >= -1.7E308 and t2.t_double <= 1.7E308', - '(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\') ' , - '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , + 't1.t_double >= -1.7E308 and t1.t_double <= 1.7E308 and t2.t_double >= -1.7E308 and t2.t_double <= 1.7E308', + '(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\') ' , + '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , 't1.t_bool in (0 , 1) and t2.t_bool in (0 , 1)' , 't1.t_bool in ( true , false) and t2.t_bool in ( true , false)' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', 't1.t_bigint between -9223372036854775807 and 9223372036854775807 and t2.t_bigint between -9223372036854775807 and 9223372036854775807', 't1.t_int between -2147483647 and 2147483647 and t2.t_int between -2147483647 and 2147483647', - 't1.t_smallint between -32767 and 32767 and t2.t_smallint between -32767 and 32767', + 't1.t_smallint between -32767 and 32767 and t2.t_smallint between -32767 and 32767', '(t1.t_tinyint between -127 and 127 and t2.t_tinyint between -127 and 127) ','t1.t_float between -1.7E308 and 1.7E308 and t2.t_float between -1.7E308 and 1.7E308', '(t1.t_double between -1.7E308 and 1.7E308 and t2.t_double between -1.7E308 and 1.7E308)'] #TD-6201,'t1.t_bool between 0 and 1 or t2.q_bool between 0 and 1'] - t_u_or_where = ['(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\' )' , - '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , + t_u_or_where = ['(t1.t_binary like \'binary%\' or t1.t_binary = \'0\' or t2.t_binary like \'binary%\' or t2.t_binary = \'0\' )' , + '(t1.t_nchar like \'nchar%\' or t1.t_nchar = \'0\' or t2.t_nchar like \'nchar%\' or t2.t_nchar = \'0\' )' , '(t1.t_bool = true or t1.t_bool = false or t2.t_bool = true or t2.t_bool = false)' , '(t1.t_bool in (0 , 1) or t2.t_bool in (0 , 1))' , '(t1.t_bool in ( true , false) or t2.t_bool in ( true , false))' , '(t1.t_bool = 0 or t1.t_bool = 1 or t2.t_bool = 0 or t2.t_bool = 1)', '(t1.t_bigint between -9223372036854775807 and 9223372036854775807 or t2.t_bigint between -9223372036854775807 and 9223372036854775807)', '(t1.t_int between -2147483647 and 2147483647 or t2.t_int between -2147483647 and 2147483647)', - '(t1.t_smallint between -32767 and 32767 or t2.t_smallint between -32767 and 32767)', + '(t1.t_smallint between -32767 and 32767 or t2.t_smallint between -32767 and 32767)', '(t1.t_tinyint between -127 and 127 or t2.t_tinyint between -127 and 127 )','(t1.t_float between -1.7E308 and 1.7E308 or t2.t_float between -1.7E308 and 1.7E308)', '(t1.t_double between -1.7E308 and 1.7E308 or t2.t_double between -1.7E308 and 1.7E308)'] - # regular and tag column where + # regular and tag column where qt_where = q_where + t_where qt_u_where = q_u_where + t_u_where # now,qt_u_or_where is not support @@ -354,78 +354,78 @@ class TDTestCase: session_where = ['session(ts,10a)' , 'session(ts,10s)', 'session(ts,10m)' , 'session(ts,10h)','session(ts,10d)' , 'session(ts,10w)'] session_u_where = ['session(t1.ts,10a)' , 'session(t1.ts,10s)', 'session(t1.ts,10m)' , 'session(t1.ts,10h)','session(t1.ts,10d)' , 'session(t1.ts,10w)', 'session(t2.ts,10a)' , 'session(t2.ts,10s)', 'session(t2.ts,10m)' , 'session(t2.ts,10h)','session(t2.ts,10d)' , 'session(t2.ts,10w)'] - + fill_where = ['FILL(NONE)','FILL(PREV)','FILL(NULL)','FILL(LINEAR)','FILL(NEXT)','FILL(VALUE, 1.23)'] - + state_window = ['STATE_WINDOW(q_tinyint)','STATE_WINDOW(q_bigint)','STATE_WINDOW(q_int)','STATE_WINDOW(q_bool)','STATE_WINDOW(q_smallint)'] state_u_window = ['STATE_WINDOW(t1.q_tinyint)','STATE_WINDOW(t1.q_bigint)','STATE_WINDOW(t1.q_int)','STATE_WINDOW(t1.q_bool)','STATE_WINDOW(t1.q_smallint)', 'STATE_WINDOW(t2.q_tinyint)','STATE_WINDOW(t2.q_bigint)','STATE_WINDOW(t2.q_int)','STATE_WINDOW(t2.q_bool)','STATE_WINDOW(t2.q_smallint)'] - # order by where + # order by where order_where = ['order by ts' , 'order by ts asc'] order_u_where = ['order by t1.ts' , 'order by t1.ts asc' , 'order by t2.ts' , 'order by t2.ts asc'] order_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' ] orders_desc_where = ['order by ts' , 'order by ts asc' , 'order by ts desc' , 'order by loc' , 'order by loc asc' , 'order by loc desc'] - - group_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', + + group_where = ['group by tbname , loc' , 'group by tbname', 'group by tbname, t_bigint', 'group by tbname,t_int', 'group by tbname, t_smallint', 'group by tbname,t_tinyint', 'group by tbname,t_float', 'group by tbname,t_double' , 'group by tbname,t_binary', 'group by tbname,t_nchar', 'group by tbname,t_bool' ,'group by tbname ,loc ,t_bigint', 'group by tbname,t_binary ,t_nchar ,t_bool' , 'group by tbname,t_int ,t_smallint ,t_tinyint' , 'group by tbname,t_float ,t_double ' , - 'PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', + 'PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] - group_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', + group_where_j = ['group by t1.loc' , 'group by t1.t_bigint', 'group by t1.t_int', 'group by t1.t_smallint', 'group by t1.t_tinyint', 'group by t1.t_float', 'group by t1.t_double' , 'group by t1.t_binary', 'group by t1.t_nchar', 'group by t1.t_bool' ,'group by t1.loc ,t1.t_bigint', 'group by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'group by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'group by t1.t_float ,t1.t_double ' , - 'PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', + 'PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', - 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', + 'group by t2.loc' , 'group by t2.t_bigint', 'group by t2.t_int', 'group by t2.t_smallint', 'group by t2.t_tinyint', 'group by t2.t_float', 'group by t2.t_double' , 'group by t2.t_binary', 'group by t2.t_nchar', 'group by t2.t_bool' ,'group by t2.loc ,t2.t_bigint', 'group by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'group by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'group by t2.t_float ,t2.t_double ' , - 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', + 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', - 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] - - partiton_where = ['PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', + 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] + + partiton_where = ['PARTITION BY tbname , loc' , 'PARTITION BY tbname', 'PARTITION BY tbname, t_bigint', 'PARTITION BY tbname,t_int', 'PARTITION BY tbname, t_smallint', 'PARTITION BY tbname,t_tinyint', 'PARTITION BY tbname,t_float', 'PARTITION BY tbname,t_double' , 'PARTITION BY tbname,t_binary', 'PARTITION BY tbname,t_nchar', 'PARTITION BY tbname,t_bool' ,'PARTITION BY tbname ,loc ,t_bigint', 'PARTITION BY tbname,t_binary ,t_nchar ,t_bool' , 'PARTITION BY tbname,t_int ,t_smallint ,t_tinyint' , 'PARTITION BY tbname,t_float ,t_double '] - partiton_where_j = ['PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', + partiton_where_j = ['PARTITION BY t1.loc' , 'PARTITION by t1.t_bigint', 'PARTITION by t1.t_int', 'PARTITION by t1.t_smallint', 'PARTITION by t1.t_tinyint', 'PARTITION by t1.t_float', 'PARTITION by t1.t_double' , 'PARTITION by t1.t_binary', 'PARTITION by t1.t_nchar', 'PARTITION by t1.t_bool' ,'PARTITION BY t1.loc ,t1.t_bigint', 'PARTITION by t1.t_binary ,t1.t_nchar ,t1.t_bool' , 'PARTITION by t1.t_int ,t1.t_smallint ,t1.t_tinyint' , 'PARTITION by t1.t_float ,t1.t_double ', - 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', + 'PARTITION BY t2.loc' , 'PARTITION by t2.t_bigint', 'PARTITION by t2.t_int', 'PARTITION by t2.t_smallint', 'PARTITION by t2.t_tinyint', 'PARTITION by t2.t_float', 'PARTITION by t2.t_double' , 'PARTITION by t2.t_binary', 'PARTITION by t2.t_nchar', 'PARTITION by t2.t_bool' ,'PARTITION BY t2.loc ,t2.t_bigint', - 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] + 'PARTITION by t2.t_binary ,t2.t_nchar ,t2.t_bool' , 'PARTITION by t2.t_int ,t2.t_smallint ,t2.t_tinyint' , 'PARTITION by t2.t_float ,t2.t_double '] - - group_where_regular = ['group by tbname ' , 'group by tbname', 'group by tbname, q_bigint', 'group by tbname,q_int', 'group by tbname, q_smallint', 'group by tbname,q_tinyint', + + group_where_regular = ['group by tbname ' , 'group by tbname', 'group by tbname, q_bigint', 'group by tbname,q_int', 'group by tbname, q_smallint', 'group by tbname,q_tinyint', 'group by tbname,q_float', 'group by tbname,q_double' , 'group by tbname,q_binary', 'group by tbname,q_nchar', 'group by tbname,q_bool' ,'group by tbname ,q_bigint', 'group by tbname,q_binary ,q_nchar ,q_bool' , 'group by tbname,q_int ,q_smallint ,q_tinyint' , 'group by tbname,q_float ,q_double ' , - 'PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', + 'PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] - group_where_regular_j = ['group by t1.q_bigint', 'group by t1.q_int', 'group by t1.q_smallint', 'group by t1.q_tinyint', + group_where_regular_j = ['group by t1.q_bigint', 'group by t1.q_int', 'group by t1.q_smallint', 'group by t1.q_tinyint', 'group by t1.q_float', 'group by t1.q_double' , 'group by t1.q_binary', 'group by t1.q_nchar', 'group by t1.q_bool' ,'group by t1.q_bigint', 'group by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'group by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'group by t1.q_float ,t1.q_double ' , - 'PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', + 'PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', - 'group by t2.q_bigint', 'group by t2.q_int', 'group by t2.q_smallint', 'group by t2.q_tinyint', + 'group by t2.q_bigint', 'group by t2.q_int', 'group by t2.q_smallint', 'group by t2.q_tinyint', 'group by t2.q_float', 'group by t2.q_double' , 'group by t2.q_binary', 'group by t2.q_nchar', 'group by t2.q_bool' ,'group by t2.q_bigint', 'group by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'group by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'group by t2.q_float ,t2.q_double ' , - 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', + 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', - 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] - - partiton_where_regular = ['PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', + 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] + + partiton_where_regular = ['PARTITION BY tbname ' , 'PARTITION BY tbname', 'PARTITION BY tbname, q_bigint', 'PARTITION BY tbname,q_int', 'PARTITION BY tbname, q_smallint', 'PARTITION BY tbname,q_tinyint', 'PARTITION BY tbname,q_float', 'PARTITION BY tbname,q_double' , 'PARTITION BY tbname,q_binary', 'PARTITION BY tbname,q_nchar', 'PARTITION BY tbname,q_bool' ,'PARTITION BY tbname ,q_bigint', 'PARTITION BY tbname,q_binary ,q_nchar ,q_bool' , 'PARTITION BY tbname,q_int ,q_smallint ,q_tinyint' , 'PARTITION BY tbname,q_float ,q_double '] - partiton_where_regular_j = ['PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', + partiton_where_regular_j = ['PARTITION by t1.q_bigint', 'PARTITION by t1.q_int', 'PARTITION by t1.q_smallint', 'PARTITION by t1.q_tinyint', 'PARTITION by t1.q_float', 'PARTITION by t1.q_double' , 'PARTITION by t1.q_binary', 'PARTITION by t1.q_nchar', 'PARTITION by t1.q_bool' ,'PARTITION BY t1.q_bigint', 'PARTITION by t1.q_binary ,t1.q_nchar ,t1.q_bool' , 'PARTITION by t1.q_int ,t1.q_smallint ,t1.q_tinyint' , 'PARTITION by t1.q_float ,t1.q_double ', - 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', + 'PARTITION by t2.q_bigint', 'PARTITION by t2.q_int', 'PARTITION by t2.q_smallint', 'PARTITION by t2.q_tinyint', 'PARTITION by t2.q_float', 'PARTITION by t2.q_double' , 'PARTITION by t2.q_binary', 'PARTITION by t2.q_nchar', 'PARTITION by t2.q_bool' ,'PARTITION BY t2.q_bigint', - 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] - + 'PARTITION by t2.q_binary ,t2.q_nchar ,t2.q_bool' , 'PARTITION by t2.q_int ,t2.q_smallint ,t2.q_tinyint' , 'PARTITION by t2.q_float ,t2.q_double '] + having_support = ['having count(q_int) > 0','having count(q_bigint) > 0','having count(q_smallint) > 0','having count(q_tinyint) > 0','having count(q_float) > 0','having count(q_double) > 0','having count(q_bool) > 0', 'having avg(q_int) > 0','having avg(q_bigint) > 0','having avg(q_smallint) > 0','having avg(q_tinyint) > 0','having avg(q_float) > 0','having avg(q_double) > 0', 'having sum(q_int) > 0','having sum(q_bigint) > 0','having sum(q_smallint) > 0','having sum(q_tinyint) > 0','having sum(q_float) > 0','having sum(q_double) > 0', @@ -440,9 +440,9 @@ class TDTestCase: having_not_support = ['having TOP(q_int,10) > 0','having TOP(q_bigint,10) > 0','having TOP(q_smallint,10) > 0','having TOP(q_tinyint,10) > 0','having TOP(q_float,10) > 0','having TOP(q_double,10) > 0','having TOP(q_bool,10) > 0', 'having BOTTOM(q_int,10) > 0','having BOTTOM(q_bigint,10) > 0','having BOTTOM(q_smallint,10) > 0','having BOTTOM(q_tinyint,10) > 0','having BOTTOM(q_float,10) > 0','having BOTTOM(q_double,10) > 0','having BOTTOM(q_bool,10) > 0', 'having LEASTSQUARES(q_int) > 0','having LEASTSQUARES(q_bigint) > 0','having LEASTSQUARES(q_smallint) > 0','having LEASTSQUARES(q_tinyint) > 0','having LEASTSQUARES(q_float) > 0','having LEASTSQUARES(q_double) > 0','having LEASTSQUARES(q_bool) > 0', - 'having FIRST(q_bool) > 0','having IRATE(q_bool) > 0','having PERCENTILE(q_bool,10) > 0','having avg(q_bool) > 0','having LAST_ROW(q_bool) > 0','having sum(q_bool) > 0','having STDDEV(q_bool) > 0','having APERCENTILE(q_bool,10) > 0','having TWA(q_bool) > 0','having LAST(q_bool) > 0', + 'having FIRST(q_bool) > 0','having IRATE(q_bool) > 0','having PERCENTILE(q_bool,10) > 0','having avg(q_bool) > 0','having LAST_ROW(q_bool) > 0','having sum(q_bool) > 0','having STDDEV(q_bool) > 0','having APERCENTILE(q_bool,10) > 0','having TWA(q_bool) > 0','having LAST(q_bool) > 0', 'having PERCENTILE(q_int,10) > 0','having PERCENTILE(q_bigint,10) > 0','having PERCENTILE(q_smallint,10) > 0','having PERCENTILE(q_tinyint,10) > 0','having PERCENTILE(q_float,10) > 0','having PERCENTILE(q_double,10) > 0'] - having_tagnot_support = ['having LAST_ROW(q_int) > 0','having LAST_ROW(q_bigint) > 0','having LAST_ROW(q_smallint) > 0','having LAST_ROW(q_tinyint) > 0','having LAST_ROW(q_float) > 0','having LAST_ROW(q_double) > 0'] + having_tagnot_support = ['having LAST_ROW(q_int) > 0','having LAST_ROW(q_bigint) > 0','having LAST_ROW(q_smallint) > 0','having LAST_ROW(q_tinyint) > 0','having LAST_ROW(q_float) > 0','having LAST_ROW(q_double) > 0'] having_support_j = ['having count(t1.q_int) > 0','having count(t1.q_bigint) > 0','having count(t1.q_smallint) > 0','having count(t1.q_tinyint) > 0','having count(t1.q_float) > 0','having count(t1.q_double) > 0','having count(t1.q_bool) > 0', 'having avg(t1.q_int) > 0','having avg(t1.q_bigint) > 0','having avg(t1.q_smallint) > 0','having avg(t1.q_tinyint) > 0','having avg(t1.q_float) > 0','having avg(t1.q_double) > 0', @@ -455,7 +455,7 @@ class TDTestCase: 'having FIRST(t1.q_int) > 0','having FIRST(t1.q_bigint) > 0','having FIRST(t1.q_smallint) > 0','having FIRST(t1.q_tinyint) > 0','having FIRST(t1.q_float) > 0','having FIRST(t1.q_double) > 0', 'having LAST(t1.q_int) > 0','having LAST(t1.q_bigint) > 0','having LAST(t1.q_smallint) > 0','having LAST(t1.q_tinyint) > 0','having LAST(t1.q_float) > 0','having LAST(t1.q_double) > 0', 'having APERCENTILE(t1.q_int,10) > 0','having APERCENTILE(t1.q_bigint,10) > 0','having APERCENTILE(t1.q_smallint,10) > 0','having APERCENTILE(t1.q_tinyint,10) > 0','having APERCENTILE(t1.q_float,10) > 0','having APERCENTILE(t1.q_double,10) > 0'] - + # limit offset where limit_where = ['limit 1 offset 1' , 'limit 1' , 'limit 2 offset 1' , 'limit 2', 'limit 12 offset 1' , 'limit 20', 'limit 20 offset 10' , 'limit 200'] limit1_where = ['limit 1 offset 1' , 'limit 1' ] @@ -464,8 +464,8 @@ class TDTestCase: # slimit soffset where slimit_where = ['slimit 1 soffset 1' , 'slimit 1' , 'slimit 2 soffset 1' , 'slimit 2'] slimit1_where = ['slimit 2 soffset 1' , 'slimit 1' ] - - # aggregate function include [all:count(*)\avg\sum\stddev ||regualr:twa\irate\leastsquares ||group by tbname:twa\irate\] + + # aggregate function include [all:count(*)\avg\sum\stddev ||regualr:twa\irate\leastsquares ||group by tbname:twa\irate\] # select function include [all: min\max\first(*)\last(*)\top\bottom\apercentile\last_row(*)(not with interval)\interp(*)(FILL) ||regualr: percentile] # calculation function include [all:spread\+-*/ ||regualr:diff\derivative ||group by tbname:diff\derivative\] # **_ns_** express is not support stable, therefore, separated from regular tables @@ -475,7 +475,7 @@ class TDTestCase: # calc_select_all calc_select_regular calc_select_in_ts calc_select_fill calc_select_not_interval # select function include [all: min\max\first(*)\last(*)\top\bottom\apercentile\last_row(*)(not with interval)\interp(*)(FILL) ||regualr: percentile] - + calc_select_all = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , 'first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , @@ -483,7 +483,7 @@ class TDTestCase: 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)'] calc_select_in_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , @@ -494,23 +494,23 @@ class TDTestCase: calc_select_in = ['min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' , 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)'] - + calc_select_not_support_ts = ['first(q_int)' , 'first(q_bigint)' , 'first(q_smallint)' , 'first(q_tinyint)' , 'first(q_float)' ,'first(q_double)' ,'first(q_binary)' ,'first(q_nchar)' ,'first(q_bool)' ,'first(q_ts)' , 'last(q_int)' , 'last(q_bigint)' , 'last(q_smallint)' , 'last(q_tinyint)' , 'last(q_float)' ,'last(q_double)' , 'last(q_binary)' ,'last(q_nchar)' ,'last(q_bool)' ,'last(q_ts)' , - 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , + 'last_row(q_int)' , 'last_row(q_bigint)' , 'last_row(q_smallint)' , 'last_row(q_tinyint)' , 'last_row(q_float)' , 'last_row(q_double)' , 'last_row(q_bool)' ,'last_row(q_binary)' ,'last_row(q_nchar)' ,'last_row(q_ts)', - 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)'] - + 'apercentile(q_int,20)' , 'apercentile(q_bigint,20)' ,'apercentile(q_smallint,20)' ,'apercentile(q_tinyint,20)' ,'apercentile(q_float,20)' ,'apercentile(q_double,20)'] + calc_select_support_ts = ['bottom(q_int,20)' , 'bottom(q_bigint,20)' , 'bottom(q_smallint,20)' , 'bottom(q_tinyint,20)' ,'bottom(q_float,20)' , 'bottom(q_double,20)' , 'top(q_int,20)' , 'top(q_bigint,20)' , 'top(q_smallint,20)' ,'top(q_tinyint,20)' ,'top(q_float,20)' ,'top(q_double,20)' , 'min(q_int)' , 'min(q_bigint)' , 'min(q_smallint)' , 'min(q_tinyint)' , 'min(q_float)' ,'min(q_double)' , 'max(q_int)' , 'max(q_bigint)' , 'max(q_smallint)' , 'max(q_tinyint)' ,'max(q_float)' ,'max(q_double)' ] - + calc_select_regular = [ 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)'] - + calc_select_fill = ['INTERP(q_int)' ,'INTERP(q_bigint)' ,'INTERP(q_smallint)' ,'INTERP(q_tinyint)', 'INTERP(q_float)' ,'INTERP(q_double)'] interp_where = ['ts = now' , 'ts = \'2020-09-13 20:26:40.000\'' , 'ts = \'2020-09-13 20:26:40.009\'' ,'tbname in (\'table_1\') and ts = now' ,'tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and ts = \'2020-09-13 20:26:40.000\'','tbname like \'table%\' and ts = \'2020-09-13 20:26:40.002\''] @@ -535,28 +535,28 @@ class TDTestCase: ] calc_select_in_not_support_ts_j = ['apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , - 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , + 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , - 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , + 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)'] calc_select_in_j = ['min(t1.q_int)' , 'min(t1.q_bigint)' , 'min(t1.q_smallint)' , 'min(t1.q_tinyint)' , 'min(t1.q_float)' ,'min(t1.q_double)' , 'max(t1.q_int)' , 'max(t1.q_bigint)' , 'max(t1.q_smallint)' , 'max(t1.q_tinyint)' ,'max(t1.q_float)' ,'max(t1.q_double)' , 'apercentile(t1.q_int,20)' , 'apercentile(t1.q_bigint,20)' ,'apercentile(t1.q_smallint,20)' ,'apercentile(t1.q_tinyint,20)' ,'apercentile(t1.q_float,20)' ,'apercentile(t1.q_double,20)' , - 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , + 'last_row(t1.q_int)' , 'last_row(t1.q_bigint)' , 'last_row(t1.q_smallint)' , 'last_row(t1.q_tinyint)' , 'last_row(t1.q_float)' , 'last_row(t1.q_double)' , 'last_row(t1.q_bool)' ,'last_row(t1.q_binary)' ,'last_row(t1.q_nchar)' ,'last_row(t1.q_ts)' , 'min(t2.q_int)' , 'min(t2.q_bigint)' , 'min(t2.q_smallint)' , 'min(t2.q_tinyint)' , 'min(t2.q_float)' ,'min(t2.q_double)' , 'max(t2.q_int)' , 'max(t2.q_bigint)' , 'max(t2.q_smallint)' , 'max(t2.q_tinyint)' ,'max(t2.q_float)' ,'max(t2.q_double)' , 'apercentile(t2.q_int,20)' , 'apercentile(t2.q_bigint,20)' ,'apercentile(t2.q_smallint,20)' ,'apercentile(t2.q_tinyint,20)' ,'apercentile(t2.q_float,20)' ,'apercentile(t2.q_double,20)' , - 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , - 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)'] + 'last_row(t2.q_int)' , 'last_row(t2.q_bigint)' , 'last_row(t2.q_smallint)' , 'last_row(t2.q_tinyint)' , 'last_row(t2.q_float)' , + 'last_row(t2.q_double)' , 'last_row(t2.q_bool)' ,'last_row(t2.q_binary)' ,'last_row(t2.q_nchar)' ,'last_row(t2.q_ts)'] calc_select_all_j = calc_select_in_ts_j + calc_select_in_j calc_select_regular_j = [ 'PERCENTILE(t1.q_int,10)' ,'PERCENTILE(t1.q_bigint,20)' , 'PERCENTILE(t1.q_smallint,30)' ,'PERCENTILE(t1.q_tinyint,40)' ,'PERCENTILE(t1.q_float,50)' ,'PERCENTILE(t1.q_double,60)' , 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)'] - + calc_select_fill_j = ['INTERP(t1.q_int)' ,'INTERP(t1.q_bigint)' ,'INTERP(t1.q_smallint)' ,'INTERP(t1.q_tinyint)', 'INTERP(t1.q_float)' ,'INTERP(t1.q_double)' , 'INTERP(t2.q_int)' ,'INTERP(t2.q_bigint)' ,'INTERP(t2.q_smallint)' ,'INTERP(t2.q_tinyint)', 'INTERP(t2.q_float)' ,'INTERP(t2.q_double)'] interp_where_j = ['t1.ts = now' , 't1.ts = \'2020-09-13 20:26:40.000\'' , 't1.ts = \'2020-09-13 20:26:40.009\'' ,'t2.ts = now' , 't2.ts = \'2020-09-13 20:26:40.000\'' , 't2.ts = \'2020-09-13 20:26:40.009\'' , @@ -578,7 +578,7 @@ class TDTestCase: 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)'] calc_aggregate_groupbytbname = ['twa(q_int)' ,'twa(q_bigint)' , 'twa(q_smallint)' ,'twa(q_tinyint)' ,'twa (q_float)' ,'twa(q_double)' , - 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)' ] + 'IRATE(q_int)' ,'IRATE(q_bigint)' , 'IRATE(q_smallint)' ,'IRATE(q_tinyint)' ,'IRATE (q_float)' ,'IRATE(q_double)' ] #two table join calc_aggregate_all_j = ['count(t1.*)' , 'count(t1.q_int)' ,'count(t1.q_bigint)' , 'count(t1.q_smallint)' ,'count(t1.q_tinyint)' ,'count(t1.q_float)' , @@ -606,18 +606,18 @@ class TDTestCase: calc_aggregate_groupbytbname_j = ['twa(t1.q_int)' ,'twa(t1.q_bigint)' , 'twa(t1.q_smallint)' ,'twa(t1.q_tinyint)' ,'twa (t1.q_float)' ,'twa(t1.q_double)' , 'IRATE(t1.q_int)' ,'IRATE(t1.q_bigint)' , 'IRATE(t1.q_smallint)' ,'IRATE(t1.q_tinyint)' ,'IRATE (t1.q_float)' ,'IRATE(t1.q_double)' , 'twa(t2.q_int)' ,'twa(t2.q_bigint)' , 'twa(t2.q_smallint)' ,'twa(t2.q_tinyint)' ,'twa (t2.q_float)' ,'twa(t2.q_double)' , - 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)' ] - + 'IRATE(t2.q_int)' ,'IRATE(t2.q_bigint)' , 'IRATE(t2.q_smallint)' ,'IRATE(t2.q_tinyint)' ,'IRATE (t2.q_float)' ,'IRATE(t2.q_double)' ] + # calc_calculate_all calc_calculate_regular calc_calculate_groupbytbname # calculation function include [all:spread\+-*/ ||regualr:diff\derivative ||group by tbname:diff\derivative\] - calc_calculate_all = ['SPREAD(ts)' , 'SPREAD(q_ts)' , 'SPREAD(q_int)' ,'SPREAD(q_bigint)' , 'SPREAD(q_smallint)' ,'SPREAD(q_tinyint)' ,'SPREAD(q_float)' ,'SPREAD(q_double)' , + calc_calculate_all = ['SPREAD(ts)' , 'SPREAD(q_ts)' , 'SPREAD(q_int)' ,'SPREAD(q_bigint)' , 'SPREAD(q_smallint)' ,'SPREAD(q_tinyint)' ,'SPREAD(q_float)' ,'SPREAD(q_double)' , '(SPREAD(q_int) + SPREAD(q_bigint))' , '(SPREAD(q_smallint) - SPREAD(q_float))', '(SPREAD(q_double) * SPREAD(q_tinyint))' , '(SPREAD(q_double) / SPREAD(q_float))'] calc_calculate_regular = ['DIFF(q_int)' ,'DIFF(q_bigint)' , 'DIFF(q_smallint)' ,'DIFF(q_tinyint)' ,'DIFF(q_float)' ,'DIFF(q_double)' , 'DIFF(q_int,0)' ,'DIFF(q_bigint,0)' , 'DIFF(q_smallint,0)' ,'DIFF(q_tinyint,0)' ,'DIFF(q_float,0)' ,'DIFF(q_double,0)' , 'DIFF(q_int,1)' ,'DIFF(q_bigint,1)' , 'DIFF(q_smallint,1)' ,'DIFF(q_tinyint,1)' ,'DIFF(q_float,1)' ,'DIFF(q_double,1)' , 'DERIVATIVE(q_int,15s,0)' , 'DERIVATIVE(q_bigint,10s,1)' , 'DERIVATIVE(q_smallint,20s,0)' ,'DERIVATIVE(q_tinyint,10s,1)' ,'DERIVATIVE(q_float,6s,0)' ,'DERIVATIVE(q_double,3s,1)' ] calc_calculate_groupbytbname = calc_calculate_regular - + #two table join calc_calculate_all_j = ['SPREAD(t1.ts)' , 'SPREAD(t1.q_ts)' , 'SPREAD(t1.q_int)' ,'SPREAD(t1.q_bigint)' , 'SPREAD(t1.q_smallint)' ,'SPREAD(t1.q_tinyint)' ,'SPREAD(t1.q_float)' ,'SPREAD(t1.q_double)' , 'SPREAD(t2.ts)' , 'SPREAD(t2.q_ts)' , 'SPREAD(t2.q_int)' ,'SPREAD(t2.q_bigint)' , 'SPREAD(t2.q_smallint)' ,'SPREAD(t2.q_tinyint)' ,'SPREAD(t2.q_float)' ,'SPREAD(t2.q_double)' , @@ -646,17 +646,17 @@ class TDTestCase: #sql = "select ts , * from ( select " ===暂时不支持select * ,用下面这一行 sql = "select ts from ( select " sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(q_select) sql += "ts from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) - - #1 outer union not support + + #1 outer union not support #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 1-2 from stable_1;") for i in range(self.fornum): @@ -677,11 +677,11 @@ class TDTestCase: sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) - + #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 1-2 from stable_1;") for i in range(self.fornum): @@ -702,11 +702,11 @@ class TDTestCase: sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(200) - + #1 inter union not support tdSql.query("select 1-3 from stable_1;") for i in range(self.fornum): @@ -716,7 +716,7 @@ class TDTestCase: sql += "%s, " % random.choice(q_select) sql += "ts from regular_table_1 where " sql += "%s " % random.choice(q_where) - sql += "" + sql += "" sql += " union select " sql += "%s, " % random.choice(s_r_select) sql += "%s, " % random.choice(q_select) @@ -724,8 +724,8 @@ class TDTestCase: sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15606 tdSql.query(sql) # tdSql.checkRows(200) tdSql.query("select 1-3 from stable_1;") @@ -743,60 +743,60 @@ class TDTestCase: sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15607 tdSql.query(sql) # tdSql.checkRows(300) - - #join:TD-6020\TD-6149 select * from (select column form regular_table1,regular_table2 where t1.ts=t2.ts and <\>\in\and\or order by) + + #join:TD-6020\TD-6149 select * from (select column form regular_table1,regular_table2 where t1.ts=t2.ts and <\>\in\and\or order by) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 1-4 from stable_1;") for i in range(self.fornum): #sql = "select ts , * from ( select t1.ts ," sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(order_u_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) tdSql.query("select 1-5 from stable_1;") for i in range(self.fornum): sql = "select ts , * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += "%s " % random.choice(order_u_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.error(sql) # TD-15587 tdSql.query(sql) # tdSql.checkRows(100) - #2 select column from (select * form regular_table ) where <\>\in\and\or order by + #2 select column from (select * form regular_table ) where <\>\in\and\or order by #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 2-1 from stable_1;") for i in range(self.fornum): sql = "select ts ," sql += "%s, " % random.choice(s_r_select) - sql += "%s " % random.choice(q_select) + sql += "%s " % random.choice(q_select) sql += " from ( select * from regular_table_1 ) where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(100) @@ -805,31 +805,31 @@ class TDTestCase: tdSql.query("select 2-2 from stable_1;") for i in range(self.fornum): sql = "select ts , * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) sql += "t2.ts from regular_table_1 t1 , regular_table_2 t2 ) where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(order_u_where) #sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) - #3 select * from (select column\tag form stable where <\>\in\and\or order by ) + #3 select * from (select column\tag form stable where <\>\in\and\or order by ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 3-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(q_select) - sql += "%s, " % random.choice(t_select) + sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(t_select) sql += "ts from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_where) sql += ") ;" - tdLog.info(sql) + tdLog.info(sql) tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(300) @@ -839,35 +839,35 @@ class TDTestCase: sql += "%s " % random.choice(s_r_select) sql += "from ( select " sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(q_select) - sql += "%s, " % random.choice(t_select) + sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(t_select) sql += "ts from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_where) sql += ") ;" - tdLog.info(sql) + tdLog.info(sql) tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(300) - # select ts,* from (select column\tag form stable1,stable2 where t1.ts = t2.ts and <\>\in\and\or order by ) + # select ts,* from (select column\tag form stable1,stable2 where t1.ts = t2.ts and <\>\in\and\or order by ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 3-2 from stable_1;") for i in range(self.fornum): sql = "select ts , * from ( select t1.ts , " - sql += "t1.%s, " % random.choice(s_s_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(s_s_select) - sql += "t2.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(s_s_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(s_s_select) + sql += "t2.%s, " % random.choice(q_select) sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(order_u_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) # TD-15609 tdSql.query(sql) # tdSql.checkRows(100) - + #3 outer union not support rsDn = self.restartDnodes() tdSql.query("select 3-3 from stable_1;") @@ -887,8 +887,8 @@ class TDTestCase: sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(200) for i in range(self.fornum): @@ -907,11 +907,11 @@ class TDTestCase: sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(400) - + #3 inter union not support tdSql.query("select 3-4 from stable_1;") for i in range(self.fornum): @@ -929,57 +929,57 @@ class TDTestCase: sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += ")" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.error(sql) #join:select * from (select column form stable1,stable2 where t1.ts=t2.ts and <\>\in\and\or order by) tdSql.query("select 3-5 from stable_1;") for i in range(self.fornum): sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_u_where) sql += "%s " % random.choice(order_u_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) # TD-15609 tdSql.query(sql) # tdSql.checkRows(100) tdSql.query("select 3-6 from stable_1;") for i in range(self.fornum): sql = "select * from ( select t1.ts ," - sql += "t1.%s, " % random.choice(q_select) - sql += "t1.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) - sql += "t2.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t1.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) + sql += "t2.%s, " % random.choice(q_select) sql += "t2.ts from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_u_or_where) sql += "%s " % random.choice(order_u_where) sql += ");" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) # TD-15609 同上 tdSql.query(sql) # tdSql.checkRows(100) - #4 select column from (select * form stable where <\>\in\and\or order by ) + #4 select column from (select * form stable where <\>\in\and\or order by ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 4-1 from stable_1;") for i in range(self.fornum): sql = "select ts , " sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) - sql += "%s " % random.choice(t_select) + sql += "%s, " % random.choice(q_select) + sql += "%s " % random.choice(t_select) sql += " from ( select * from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15616 tdSql.query(sql) # tdSql.checkRows(300) @@ -992,8 +992,8 @@ class TDTestCase: sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15500 tdSql.query(sql) #5-1 select distinct column\tag from (select calc form stable where <\>\in\and\or order by limit offset ) @@ -1001,13 +1001,13 @@ class TDTestCase: for i in range(self.fornum): sql = "select distinct c5_1 " sql += " from ( select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(calc_select_in_ts) sql += " as c5_1 from stable_1 where " sql += "%s " % random.choice(qt_where) #sql += "%s " % random.choice(order_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) #tdSql.checkRows(1)有的函数还没有提交,会不返回结果,先忽略 @@ -1020,8 +1020,8 @@ class TDTestCase: sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_desc_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.error(sql) tdSql.query("select 6-1 from stable_1;") for i in range(self.fornum): @@ -1029,8 +1029,8 @@ class TDTestCase: sql += "%s " % random.choice(dt_select) sql += " from stable_1 where " sql += "%s ) ;" % random.choice(qt_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) #tdSql.checkRows(1)#数量不一致,不在校验 @@ -1044,8 +1044,8 @@ class TDTestCase: sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice([limit_where[0] , limit_where[1]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.error(sql) #distinct 和 order by 不能混合使用 tdSql.query("select 7-1 from stable_1;") for i in range(self.fornum): @@ -1056,166 +1056,166 @@ class TDTestCase: #sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice([limit_where[0] , limit_where[1]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(1) #calc_select,TWA/Diff/Derivative/Irate are not allowed to apply to super table directly #8 select * from (select ts,calc form ragular_table where <\>\in\and\or order by ) - + # dcDB = self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 8-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select ts ," - sql += "%s " % random.choice(calc_select_support_ts) + sql += "%s " % random.choice(calc_select_support_ts) sql += "from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function tdSql.query("select 8-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_not_support_ts) + sql += "%s " % random.choice(calc_select_not_support_ts) sql += "from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function - + tdLog.info(sql) + tdLog.info(len(sql)) + #TD-15651 tdSql.query(sql) # 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function + for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(calc_select_in_ts) sql += "from regular_table_1 where " sql += "%s " % random.choice(q_where) #sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) ##top返回结果有问题nest.sql tdSql.checkRows(1) tdSql.query("select 8-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select t1.ts, " - sql += "%s " % random.choice(calc_select_in_support_ts_j) + sql += "%s " % random.choice(calc_select_in_support_ts_j) sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql)# 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql)# 聚合函数不在可以和ts一起使用了 DB error: Not a single-group group function for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_not_support_ts_j) + sql += "%s " % random.choice(calc_select_in_not_support_ts_j) sql += "from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #TD-15651 tdSql.query(sql) - ##top返回结果有问题 tdSql.checkRows(1) + tdLog.info(sql) + tdLog.info(len(sql)) + #TD-15651 tdSql.query(sql) + ##top返回结果有问题 tdSql.checkRows(1) - #9 select * from (select ts,calc form stable where <\>\in\and\or order by ) + #9 select * from (select ts,calc form stable where <\>\in\and\or order by ) # self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 9-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_not_support_ts) + sql += "%s " % random.choice(calc_select_not_support_ts) sql += "from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) tdSql.query("select 9-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select ts ," - sql += "%s " % random.choice(calc_select_support_ts) + sql += "%s " % random.choice(calc_select_support_ts) sql += "from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + tdSql.query("select 9-3 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_not_support_ts_j) + sql += "%s " % random.choice(calc_select_in_not_support_ts_j) sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += " and %s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) tdSql.query("select 9-4 from stable_1;") for i in range(self.fornum): sql = "select * from ( select t1.ts," - sql += "%s " % random.choice(calc_select_in_support_ts_j) + sql += "%s " % random.choice(calc_select_in_support_ts_j) sql += "from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += " and %s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - - #10 select calc from (select * form regualr_table where <\>\in\and\or order by ) + + #10 select calc from (select * form regualr_table where <\>\in\and\or order by ) tdSql.query("select 10-1 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(calc_select_in_ts) + sql = "select " + sql += "%s " % random.choice(calc_select_in_ts) sql += "as calc10_1 from ( select * from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(1) - + #10-1 select calc from (select * form regualr_table where <\>\in\and\or order by ) - # rsDn = self.restartDnodes() + # rsDn = self.restartDnodes() # self.dropandcreateDB_random("%s" %db, 1) # rsDn = self.restartDnodes() tdSql.query("select 10-2 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql = "select " + sql += "%s " % random.choice(calc_select_all) sql += "as calc10_2 from ( select * from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) # tdSql.checkRows(1) - #10-2 select calc from (select * form regualr_tables where <\>\in\and\or order by ) + #10-2 select calc from (select * form regualr_tables where <\>\in\and\or order by ) tdSql.query("select 10-3 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s as calc10_3 " % random.choice(calc_select_all) + sql = "select " + sql += "%s as calc10_3 " % random.choice(calc_select_all) sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += " and %s " % random.choice(q_u_or_where) @@ -1223,14 +1223,14 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " sql += "%s ;" % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) tdSql.query("select 10-4 from stable_1;") for i in range(self.fornum): - sql = "select " - sql += "%s as calc10_4 " % random.choice(calc_select_all) + sql = "select " + sql += "%s as calc10_4 " % random.choice(calc_select_all) sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += " and %s " % random.choice(q_u_or_where) @@ -1238,112 +1238,112 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) # tdSql.checkRows(1) - #11 select calc from (select * form stable where <\>\in\and\or order by limit ) + #11 select calc from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 11-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(calc_select_in_ts) sql += "as calc11_1 from ( select * from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.checkRows(1) - #11-1 select calc from (select * form stable where <\>\in\and\or order by limit ) + #11-1 select calc from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 11-2 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql += "%s " % random.choice(calc_select_all) sql += "as calc11_1 from ( select * from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice(limit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) #不好计算结果 tdSql.checkRows(1) - + #11-2 select calc from (select * form stables where <\>\in\and\or order by limit ) tdSql.query("select 11-3 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql += "%s " % random.choice(calc_select_all) sql += "as calc11_1 from ( select * from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) tdSql.query("select 11-4 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_select_all) + sql += "%s " % random.choice(calc_select_all) sql += "as calc11_1 from ( select * from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) - #12 select calc-diff from (select * form regualr_table where <\>\in\and\or order by limit ) + #12 select calc-diff from (select * form regualr_table where <\>\in\and\or order by limit ) ##self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 12-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(calc_calculate_regular) sql += " from ( select * from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) ##目前derivative不支持 tdSql.query(sql) # tdSql.checkRows(1) tdSql.query("select 12-2 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(calc_calculate_regular) sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #目前derivative不支持 tdSql.query(sql) # tdSql.checkRows(1) tdSql.query("select 12-2.2 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(calc_calculate_regular) sql += " from ( select * from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #目前derivative不支持 tdSql.query(sql) #12-1 select calc-diff from (select * form stable where <\>\in\and\or order by limit ) @@ -1351,7 +1351,7 @@ class TDTestCase: rsDn = self.restartDnodes() for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(calc_calculate_regular) sql += " from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(group_where) @@ -1359,15 +1359,15 @@ class TDTestCase: sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #目前derivative不支持 tdSql.query(sql) tdSql.query("select 12-4 from stable_1;") #join query does not support group by for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_calculate_regular_j) + sql += "%s " % random.choice(calc_calculate_regular_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(group_where_j) @@ -1375,15 +1375,15 @@ class TDTestCase: #sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql) 目前de函数不支持,另外看看需要不需要将group by和pari by分开 tdSql.query("select 12-5 from stable_1;") #join query does not support group by for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_calculate_regular_j) + sql += "%s " % random.choice(calc_calculate_regular_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(group_where_j) @@ -1391,41 +1391,41 @@ class TDTestCase: sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) sql += " ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #derivative not support tdSql.query(sql) - + #13 select calc-diff as diffns from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 13-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(calc_calculate_regular) sql += " as calc13_1 from ( select * from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(orders_desc_where) sql += "%s " % random.choice([limit_where[2] , limit_where[3]] ) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #derivative not support tdSql.query(sql) #14 select * from (select calc_aggregate_alls as agg from stable where <\>\in\and\or group by order by slimit soffset ) - # TD-5955 select * from ( select count (q_double) from stable_1 where t_bool = true or t_bool = false group by loc order by ts asc slimit 1 ) ; + # TD-5955 select * from ( select count (q_double) from stable_1 where t_bool = true or t_bool = false group by loc order by ts asc slimit 1 ) ; tdSql.query("select 14-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all) - sql += "%s " % random.choice(calc_aggregate_all) + sql += "%s as calc14_1, " % random.choice(calc_aggregate_all) + sql += "%s as calc14_2, " % random.choice(calc_aggregate_all) + sql += "%s " % random.choice(calc_aggregate_all) sql += " as calc14_3 from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(group_where) sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice(slimit1_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15678 tdSql.query(sql) # tdSql.checkRows(1) @@ -1433,9 +1433,9 @@ class TDTestCase: tdSql.query("select 14-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all) - sql += "%s " % random.choice(calc_aggregate_all) + sql += "%s as calc14_1, " % random.choice(calc_aggregate_all) + sql += "%s as calc14_2, " % random.choice(calc_aggregate_all) + sql += "%s " % random.choice(calc_aggregate_all) sql += " as calc14_3 from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(group_where) @@ -1444,310 +1444,310 @@ class TDTestCase: sql += "%s " % random.choice(slimit1_where) sql += ") " sql += "%s " % random.choice(group_where) - tdLog.info(sql) + tdLog.info(sql) tdLog.info(len(sql)) #TD-15678 tdSql.query(sql) - # tdSql.checkRows(1) + # tdSql.checkRows(1) #14-2 select * from (select calc_aggregate_all_js as agg from stables where <\>\in\and\or group by order by slimit soffset ) tdSql.query("select 14-3 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all_j) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all_j) - sql += "%s " % random.choice(calc_aggregate_all_j) + sql += "%s as calc14_1, " % random.choice(calc_aggregate_all_j) + sql += "%s as calc14_2, " % random.choice(calc_aggregate_all_j) + sql += "%s " % random.choice(calc_aggregate_all_j) sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(partiton_where_j) sql += "%s " % random.choice(slimit1_where) sql += ") " sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 14-4 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc14_1, " % random.choice(calc_aggregate_all_j) - sql += "%s as calc14_2, " % random.choice(calc_aggregate_all_j) - sql += "%s " % random.choice(calc_aggregate_all_j) + sql += "%s as calc14_1, " % random.choice(calc_aggregate_all_j) + sql += "%s as calc14_2, " % random.choice(calc_aggregate_all_j) + sql += "%s " % random.choice(calc_aggregate_all_j) sql += " as calc14_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(partiton_where_j) sql += "%s " % random.choice(slimit1_where) sql += ") " sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) #15 TD-6320 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by slimit soffset ) tdSql.query("select 15-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular) - sql += "%s " % random.choice(calc_aggregate_regular) + sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular) + sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular) + sql += "%s " % random.choice(calc_aggregate_regular) sql += " as calc15_3 from regular_table_1 where " sql += "%s " % random.choice(q_where) - sql += "%s " % random.choice(group_where_regular) + sql += "%s " % random.choice(group_where_regular) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql) #Invalid function name: twa' # tdSql.checkRows(1) - + tdSql.query("select 15-2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular_j) - sql += "%s " % random.choice(calc_aggregate_regular_j) + sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular_j) + sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular_j) + sql += "%s " % random.choice(calc_aggregate_regular_j) sql += " as calc15_3 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) - sql += "%s " % random.choice(group_where_regular_j) + sql += "%s " % random.choice(group_where_regular_j) sql += "%s " % random.choice(limit_u_where) sql += ") " sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql) #Invalid function name: twa' tdSql.query("select 15-2.2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular_j) - sql += "%s " % random.choice(calc_aggregate_regular_j) + sql += "%s as calc15_1, " % random.choice(calc_aggregate_regular_j) + sql += "%s as calc15_2, " % random.choice(calc_aggregate_regular_j) + sql += "%s " % random.choice(calc_aggregate_regular_j) sql += " as calc15_3 from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) - sql += "%s " % random.choice(group_where_regular_j) + sql += "%s " % random.choice(group_where_regular_j) sql += "%s " % random.choice(limit_u_where) sql += ") " sql += "%s ;" % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql) #Invalid function name: twa' rsDn = self.restartDnodes() tdSql.query("select 15-3 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s " % random.choice(calc_aggregate_groupbytbname) + sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname) + sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname) + sql += "%s " % random.choice(calc_aggregate_groupbytbname) sql += " as calc15_3 from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(group_where) sql += "%s " % random.choice(having_support) sql += "%s " % random.choice(order_desc_where) sql += ") " - sql += "order by calc15_1 " + sql += "order by calc15_1 " sql += "%s " % random.choice(limit_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql) #Invalid function name: twa',可能还的去掉order by tdSql.query("select 15-4 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s " % random.choice(calc_aggregate_groupbytbname_j) sql += " as calc15_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(group_where_j) sql += "%s " % random.choice(having_support_j) #sql += "%s " % random.choice(orders_desc_where) sql += ") " - sql += "order by calc15_1 " + sql += "order by calc15_1 " sql += "%s " % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql) #'Invalid function name: irate' tdSql.query("select 15-4.2 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname_j) - sql += "%s " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname_j) + sql += "%s " % random.choice(calc_aggregate_groupbytbname_j) sql += " as calc15_3 from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(group_where_j) sql += "%s " % random.choice(having_support_j) sql += "%s " % random.choice(orders_desc_where) sql += ") " - sql += "order by calc15_1 " + sql += "order by calc15_1 " sql += "%s " % random.choice(limit_u_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15678 #tdSql.query(sql) tdSql.query("select 15-5 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname) - sql += "%s " % random.choice(calc_aggregate_groupbytbname) + sql += "%s as calc15_1, " % random.choice(calc_aggregate_groupbytbname) + sql += "%s as calc15_2, " % random.choice(calc_aggregate_groupbytbname) + sql += "%s " % random.choice(calc_aggregate_groupbytbname) sql += " as calc15_3 from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(group_where) sql += ") " - sql += "order by calc15_1 " + sql += "order by calc15_1 " sql += "%s " % random.choice(limit_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql) #'Invalid function name: irate' - #16 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by limit offset ) + #16 select * from (select calc_aggregate_regulars as agg from regular_table where <\>\in\and\or order by limit offset ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 16-1 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s as calc16_0 , " % random.choice(calc_calculate_all) - sql += "%s as calc16_1 , " % random.choice(calc_aggregate_all) - sql += "%s as calc16_2 " % random.choice(calc_select_in) + sql += "%s as calc16_1 , " % random.choice(calc_aggregate_all) + sql += "%s as calc16_2 " % random.choice(calc_select_in) sql += " from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(group_where) #sql += "%s " % random.choice(having_support)having和 partition不能混合使用 sql += ") " - sql += "order by calc16_0 " + sql += "order by calc16_0 " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15651 tdSql.query(sql) tdSql.query("select 16-2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s as calc16_0 " % random.choice(calc_calculate_all_j) - sql += ", %s as calc16_1 " % random.choice(calc_aggregate_all_j) - #sql += ", %s as calc16_2 " % random.choice(calc_select_in_j) + sql += ", %s as calc16_1 " % random.choice(calc_aggregate_all_j) + #sql += ", %s as calc16_2 " % random.choice(calc_select_in_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += ") " - sql += "order by calc16_0 " + sql += "order by calc16_0 " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 16-2.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s as calc16_0 " % random.choice(calc_calculate_all_j) - sql += ", %s as calc16_1 " % random.choice(calc_aggregate_all_j) + sql += ", %s as calc16_1 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += ") " - sql += "order by calc16_0 " + sql += "order by calc16_0 " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + tdSql.query("select 16-3 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_regular) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(calc_calculate_regular) sql += " from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "limit 2 ) " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql)#Invalid function name: derivative' tdSql.query("select 16-4 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_regular_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(calc_calculate_regular_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "limit 2 ) " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql)#Invalid function name: derivative' tdSql.query("select 16-4.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_regular_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(calc_calculate_regular_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += "limit 2 ) " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #tdSql.query(sql)#Invalid function name: derivative' - + tdSql.query("select 16-5 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s as calc16_1 , " % random.choice(calc_calculate_all) - sql += "%s as calc16_1 , " % random.choice(calc_calculate_regular) - sql += "%s as calc16_2 " % random.choice(calc_select_all) + sql += "%s as calc16_1 , " % random.choice(calc_calculate_regular) + sql += "%s as calc16_2 " % random.choice(calc_select_all) sql += " from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(group_where) #sql += "%s " % random.choice(having_support) sql += ") " - sql += "order by calc16_1 " + sql += "order by calc16_1 " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) # tdSql.query(sql) - + tdSql.query("select 16-6 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname) sql += " from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(group_where) sql += "limit 2 ) " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #Invalid function name: derivative' tdSql.query(sql) tdSql.query("select 16-7 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "limit 2 ) " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #Invalid function name: derivative' tdSql.query(sql) tdSql.query("select 16-8 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " - sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname_j) + sql = "select * from ( select " + sql += "%s as calc16_1 " % random.choice(calc_calculate_groupbytbname_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "limit 2 ) " sql += "%s " % random.choice(limit1_where) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #Invalid function name: derivative' tdSql.query(sql) #17 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or interval_sliding group by having order by limit offset )interval_sliding #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 17-1 from stable_1;") for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can + #this is having_support , but tag-select cannot mix with last_row,other select can sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) sql += "%s as cal17_0 , " % random.choice(calc_calculate_all) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) sql += " from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(partiton_where) @@ -1757,17 +1757,17 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15719 tdSql.query(sql) - + tdSql.query("select 17-2 from stable_1;") for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can + #this is having_support , but tag-select cannot mix with last_row,other select can sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) sql += "%s as cal17_0 , " % random.choice(calc_calculate_all_j) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(interval_sliding) @@ -1775,17 +1775,17 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 17-2.2 from stable_1;") for i in range(self.fornum): - #this is having_support , but tag-select cannot mix with last_row,other select can + #this is having_support , but tag-select cannot mix with last_row,other select can sql = "select apercentile(cal17_0, %d)/10 ,apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) sql += "%s as cal17_0 , " % random.choice(calc_calculate_all_j) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(interval_sliding) @@ -1793,8 +1793,8 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) self.restartDnodes() @@ -1802,8 +1802,8 @@ class TDTestCase: for i in range(self.fornum): #this is having_tagnot_support , because tag-select cannot mix with last_row... sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) sql += " from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(partiton_where) @@ -1813,16 +1813,16 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15770 tdSql.query(sql) tdSql.query("select 17-4 from stable_1;") for i in range(self.fornum): #this is having_tagnot_support , because tag-select cannot mix with last_row... sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(interval_sliding) @@ -1830,16 +1830,16 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 17-4.2 from stable_1;") for i in range(self.fornum): #this is having_tagnot_support , because tag-select cannot mix with last_row... sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(interval_sliding) @@ -1847,16 +1847,16 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 17-5 from stable_1;") for i in range(self.fornum): - #having_not_support + #having_not_support sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) sql += " from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(partiton_where) @@ -1866,15 +1866,15 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15719 tdSql.query(sql) - + tdSql.query("select 17-6 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) sql += " from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(interval_sliding) @@ -1882,15 +1882,15 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15770 tdSql.query(sql) tdSql.query("select 17-7 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(interval_sliding) @@ -1898,15 +1898,15 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 17-7.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += "%s " % random.choice(interval_sliding) @@ -1914,16 +1914,16 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) self.restartDnodes() tdSql.query("select 17-8 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all) sql += " from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(interval_sliding) @@ -1931,15 +1931,15 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + tdSql.query("select 17-9 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(interval_sliding) @@ -1947,15 +1947,15 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 17-10 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal17_1, %d)/1000 ,apercentile(cal17_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal17_2 " % random.choice(calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += "%s " % random.choice(interval_sliding) @@ -1963,16 +1963,16 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) #18 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding tdSql.query("select 18-1 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) sql += " from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(session_where) @@ -1981,15 +1981,15 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + tdSql.query("select 18-2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(session_u_where) @@ -1997,15 +1997,15 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 18-2.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += "%s " % random.choice(session_u_where) @@ -2013,16 +2013,16 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) self.restartDnodes() tdSql.query("select 18-3 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) sql += " from stable_1_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(session_where) @@ -2031,15 +2031,15 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 18-4 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(session_u_where) @@ -2047,15 +2047,15 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 18-4.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(q_u_or_where) sql += "%s " % random.choice(session_u_where) @@ -2063,15 +2063,15 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 18-5 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all) sql += " from stable_1 where " sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(session_where) @@ -2080,15 +2080,15 @@ class TDTestCase: sql += "%s " % random.choice(limit1_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #TD-15770 tdSql.query(sql) tdSql.query("select 18-6 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(t_join_where) sql += "%s " % random.choice(session_u_where) @@ -2096,15 +2096,15 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + tdSql.query("select 18-7 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal18_1, %d)/1000 ,apercentile(cal18_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal18_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1, stable_2 t2 where t1.ts = t2.ts and " sql += "%s " % random.choice(qt_u_or_where) sql += "%s " % random.choice(session_u_where) @@ -2112,426 +2112,426 @@ class TDTestCase: sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - #19 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding + #19 select apercentile from (select calc_aggregate_alls form regualr_table or stable where <\>\in\and\or session order by limit )interval_sliding #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 19-1 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) sql += " from regular_table_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(state_window) #sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit1_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 19-2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) + sql += "%s " % random.choice(q_u_where) sql += "%s " % random.choice(state_u_window) #sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 19-2.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) + sql += "%s " % random.choice(q_u_or_where) sql += "%s " % random.choice(state_u_window) #sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + tdSql.query("select 19-3 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) sql += " from stable_1_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(state_window) #sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit1_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 19-4 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) + sql += "%s " % random.choice(q_u_where) #sql += "%s " % random.choice(state_window) #sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 19-4.2 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1_1 t1, stable_1_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_or_where) + sql += "%s " % random.choice(q_u_or_where) #sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 19-5 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all) sql += " from stable_1 where " - sql += "%s " % random.choice(q_where) + sql += "%s " % random.choice(q_where) sql += "%s " % random.choice(state_window) sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit1_where) sql += ") " sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.error(sql) #'STATE_WINDOW not support for super table query' - + tdSql.query("select 19-6 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(q_u_where) + sql += "%s " % random.choice(q_u_where) #sql += "%s " % random.choice(state_window) #sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) tdSql.query("select 19-7 from stable_1;") for i in range(self.fornum): sql = "select apercentile(cal19_1, %d)/1000 ,apercentile(cal19_2, %d)*10+%d from ( select " %(random.randint(0,100) , random.randint(0,100) ,random.randint(-1000,1000)) - sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) - sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_1 ," % random.choice(calc_aggregate_all_j) + sql += "%s as cal19_2 " % random.choice(calc_aggregate_all_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " - sql += "%s " % random.choice(qt_u_or_where) + sql += "%s " % random.choice(qt_u_or_where) #sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " #sql += "%s " % random.choice(interval_sliding) - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - #20 select * from (select calc_select_fills form regualr_table or stable where <\>\in\and\or fill_where group by order by limit offset ) + #20 select * from (select calc_select_fills form regualr_table or stable where <\>\in\and\or fill_where group by order by limit offset ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 20-1 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill) - sql += "%s ," % random.choice(calc_select_fill) - sql += "%s " % random.choice(calc_select_fill) + sql += "%s ," % random.choice(calc_select_fill) + sql += "%s " % random.choice(calc_select_fill) sql += " from stable_1 where " - sql += "%s " % random.choice(interp_where) + sql += "%s " % random.choice(interp_where) sql += "%s " % random.choice(fill_where) sql += "%s " % random.choice(group_where) sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) rsDn = self.restartDnodes() tdSql.query("select 20-2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) + sql += "%s ," % random.choice(calc_select_fill_j) + sql += "%s " % random.choice(calc_select_fill_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " sql += "%s and " % random.choice(t_join_where) - sql += "%s " % random.choice(interp_where_j) + sql += "%s " % random.choice(interp_where_j) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) tdSql.query("select 20-2.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) + sql += "%s ," % random.choice(calc_select_fill_j) + sql += "%s " % random.choice(calc_select_fill_j) sql += " from stable_1 t1 , stable_2 t2 where t1.ts = t2.ts and " sql += "%s and " % random.choice(qt_u_or_where) - sql += "%s " % random.choice(interp_where_j) + sql += "%s " % random.choice(interp_where_j) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) tdSql.query("select 20-3 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill) - sql += "%s ," % random.choice(calc_select_fill) - sql += "%s " % random.choice(calc_select_fill) + sql += "%s ," % random.choice(calc_select_fill) + sql += "%s " % random.choice(calc_select_fill) sql += " from stable_1 where " - sql += "%s " % interp_where[2] + sql += "%s " % interp_where[2] sql += "%s " % random.choice(fill_where) sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) - + tdSql.query("select 20-4 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) - sql += " from stable_1 t1, table_1 t2 where t1.ts = t2.ts and " + sql += "%s ," % random.choice(calc_select_fill_j) + sql += "%s " % random.choice(calc_select_fill_j) + sql += " from stable_1 t1, table_1 t2 where t1.ts = t2.ts and " #sql += "%s and " % random.choice(t_join_where) sql += "%s " % interp_where_j[random.randint(0,5)] sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) #interp不支持 tdSql.query(sql) tdSql.query("select 20-4.2 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) - sql += " from stable_1 t1, stable_1_1 t2 where t1.ts = t2.ts and " + sql += "%s ," % random.choice(calc_select_fill_j) + sql += "%s " % random.choice(calc_select_fill_j) + sql += " from stable_1 t1, stable_1_1 t2 where t1.ts = t2.ts and " sql += "%s and " % random.choice(qt_u_or_where) sql += "%s " % interp_where_j[random.randint(0,5)] sql += "%s " % random.choice(fill_where) sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) ##interp不支持 tdSql.error(sql) - + tdSql.query("select 20-5 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill) - sql += "%s ," % random.choice(calc_select_fill) - sql += "%s " % random.choice(calc_select_fill) + sql += "%s ," % random.choice(calc_select_fill) + sql += "%s " % random.choice(calc_select_fill) sql += " from regular_table_1 where " - sql += "%s " % interp_where[1] + sql += "%s " % interp_where[1] sql += "%s " % random.choice(fill_where) sql += "%s " % random.choice(order_where) sql += "%s " % random.choice(limit_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) ##interp不支持 tdSql.query(sql) tdSql.query("select 20-6 from stable_1;") for i in range(self.fornum): - sql = "select * from ( select " + sql = "select * from ( select " sql += "%s , " % random.choice(calc_select_fill_j) - sql += "%s ," % random.choice(calc_select_fill_j) - sql += "%s " % random.choice(calc_select_fill_j) + sql += "%s ," % random.choice(calc_select_fill_j) + sql += "%s " % random.choice(calc_select_fill_j) sql += " from regular_table_1 t1, regular_table_2 t2 where t1.ts = t2.ts and " - #sql += "%s " % random.choice(interp_where_j) - sql += "%s " % interp_where_j[random.randint(0,5)] + #sql += "%s " % random.choice(interp_where_j) + sql += "%s " % interp_where_j[random.randint(0,5)] sql += "%s " % random.choice(order_u_where) sql += "%s " % random.choice(limit_u_where) sql += ") " - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) ##interp不支持 tdSql.query(sql) #1 select * from (select * from (select * form regular_table where <\>\in\and\or order by limit )) tdSql.query("select 1-1 from stable_1;") - for i in range(self.fornum): + for i in range(self.fornum): # sql_start = "select * from ( " # sql_end = ")" for_num = random.randint(1, 15); - sql = "select * from (" * for_num + sql = "select * from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(s_r_select) + sql += "%s, " % random.choice(q_select) sql += "ts from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(s_r_select) - sql2 += "%s, " % random.choice(q_select) + sql2 += "%s, " % random.choice(s_r_select) + sql2 += "%s, " % random.choice(q_select) sql2 += "ts from regular_table_1 where " sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql2) - tdLog.info(len(sql2)) - + sql2 += ")) " + tdLog.info(sql2) + tdLog.info(len(sql2)) + self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql ,1,10,3,3) self.data_matrix_equal('%s' %sql ,1,10,3,3,'%s' %sql2 ,1,10,3,3) - + for i in range(self.fornum): for_num = random.randint(1, 15); - sql = "select ts from (" * for_num + sql = "select ts from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_r_select) - sql += "%s, " % random.choice(q_select) + sql += "%s, " % random.choice(s_r_select) + sql += "%s, " % random.choice(q_select) sql += "ts from regular_table_1 where " sql += "%s " % random.choice(q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(s_r_select) - sql2 += "%s, " % random.choice(q_select) + sql2 += "%s, " % random.choice(s_r_select) + sql2 += "%s, " % random.choice(q_select) sql2 += "ts from regular_table_1 where " sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql2 += ")) " + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) - + #2 select * from (select * from (select * form stable where <\>\in\and\or order by limit )) tdSql.query("select 2-1 from stable_1;") for i in range(self.fornum): for_num = random.randint(1, 15); - sql = "select * from (" * for_num + sql = "select * from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(qt_select) + sql += "%s, " % random.choice(s_s_select) + sql += "%s, " % random.choice(qt_select) sql += "ts from stable_1 where " sql += "%s " % random.choice(q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + sql2 = "select * from ( select * from ( select " - sql2 += "%s, " % random.choice(s_s_select) - sql2 += "%s, " % random.choice(qt_select) + sql2 += "%s, " % random.choice(s_s_select) + sql2 += "%s, " % random.choice(qt_select) sql2 += "ts from stable_1 where " sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql2 += ")) " + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.data_matrix_equal('%s' %sql ,1,10,3,3,'%s' %sql2 ,1,10,3,3) - + for i in range(self.fornum): for_num = random.randint(1, 15); - sql = "select ts from (" * for_num + sql = "select ts from (" * for_num sql += "select * from ( select * from ( select " - sql += "%s, " % random.choice(s_s_select) - sql += "%s, " % random.choice(qt_select) + sql += "%s, " % random.choice(s_s_select) + sql += "%s, " % random.choice(qt_select) sql += "ts from stable_1 where " sql += "%s " % random.choice(q_where) sql += ")) " - sql += ")" * for_num - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql += ")" * for_num + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + sql2 = "select ts from ( select * from ( select " - sql2 += "%s, " % random.choice(s_s_select) - sql2 += "%s, " % random.choice(qt_select) + sql2 += "%s, " % random.choice(s_s_select) + sql2 += "%s, " % random.choice(qt_select) sql2 += "ts from stable_1 where " sql2 += "%s " % random.choice(q_where) - sql2 += ")) " - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.query(sql) - + sql2 += ")) " + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.query(sql) + self.data_matrix_equal('%s' %sql ,1,10,1,1,'%s' %sql2 ,1,10,1,1) - - #3 select ts ,calc from (select * form stable where <\>\in\and\or order by limit ) + + #3 select ts ,calc from (select * form stable where <\>\in\and\or order by limit ) #self.dropandcreateDB_random("%s" %db, 1) tdSql.query("select 3-1 from stable_1;") for i in range(self.fornum): sql = "select " - sql += "%s " % random.choice(calc_calculate_regular) + sql += "%s " % random.choice(calc_calculate_regular) sql += " from ( select * from stable_1 where " sql += "%s " % random.choice(qt_where) sql += "%s " % random.choice(orders_desc_where) sql += "%s " % random.choice(limit_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - #'Invalid function name: derivative' tdSql.query(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + #'Invalid function name: derivative' tdSql.query(sql) #4 select * from (select calc form stable where <\>\in\and\or order by limit ) tdSql.query("select 4-1 from stable_1;") for i in range(self.fornum): sql = "select * from ( select " - sql += "%s " % random.choice(calc_select_in_ts) + sql += "%s " % random.choice(calc_select_in_ts) sql += "from stable_1 where " sql += "%s " % random.choice(qt_where) #sql += "%s " % random.choice(order_desc_where) sql += "%s " % random.choice(limit_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) + tdLog.info(sql) + tdLog.info(len(sql)) tdSql.query(sql) - + #5 select ts ,tbname from (select * form stable where <\>\in\and\or order by limit ) tdSql.query("select 5-1 from stable_1;") for i in range(self.fornum): sql = "select ts , tbname , " - sql += "%s ," % random.choice(calc_calculate_regular) + sql += "%s ," % random.choice(calc_calculate_regular) sql += "%s ," % random.choice(dqt_select) sql += "%s " % random.choice(qt_select) sql += " from ( select * from stable_1 where " @@ -2539,9 +2539,9 @@ class TDTestCase: sql += "%s " % random.choice(orders_desc_where) sql += "%s " % random.choice(limit_where) sql += ") ;" - tdLog.info(sql) - tdLog.info(len(sql)) - tdSql.error(sql) + tdLog.info(sql) + tdLog.info(len(sql)) + tdSql.error(sql) #special sql tdSql.query("select 6-1 from stable_1;") @@ -2570,7 +2570,7 @@ class TDTestCase: endTime = time.time() print("total time %ds" % (endTime - startTime)) - + def stop(self): diff --git a/tests/system-test/2-query/percentile.py b/tests/system-test/2-query/percentile.py index c2584fd394..43b5c5610a 100644 --- a/tests/system-test/2-query/percentile.py +++ b/tests/system-test/2-query/percentile.py @@ -11,12 +11,14 @@ # -*- coding: utf-8 -*- -from platform import java_ver + from util.log import * from util.cases import * from util.sql import * import numpy as np +from util.sqlset import TDSetSql + class TDTestCase: def init(self, conn, logSql): @@ -25,55 +27,126 @@ class TDTestCase: self.rowNum = 10 self.ts = 1537146000000 + self.setsql = TDSetSql() + self.ntbname = 'ntb' + self.stbname = 'stb' + self.binary_length = 20 # the length of binary for column_dict + self.nchar_length = 20 # the length of nchar for column_dict + self.column_dict = { + 'ts' : 'timestamp', + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': f'binary({self.binary_length})', + 'col13': f'nchar({self.nchar_length})' + } - def run(self): - tdSql.prepare() - + self.tag_dict = { + 'ts_tag' : 'timestamp', + 't1': 'tinyint', + 't2': 'smallint', + 't3': 'int', + 't4': 'bigint', + 't5': 'tinyint unsigned', + 't6': 'smallint unsigned', + 't7': 'int unsigned', + 't8': 'bigint unsigned', + 't9': 'float', + 't10': 'double', + 't11': 'bool', + 't12': f'binary({self.binary_length})', + 't13': f'nchar({self.nchar_length})' + } + self.binary_str = 'taosdata' + self.nchar_str = '涛思数据' + self.tbnum = 2 + self.tag_ts = self.ts + self.tag_tinyint = 1 + self.tag_smallint = 2 + self.tag_int = 3 + self.tag_bigint = 4 + self.tag_utint = 5 + self.tag_usint = 6 + self.tag_uint = 7 + self.tag_ubint = 8 + self.tag_float = 9.1 + self.tag_double = 10.1 + self.tag_bool = True + self.tag_values = [ + f'{self.tag_ts},{self.tag_tinyint},{self.tag_smallint},{self.tag_int},{self.tag_bigint},\ + {self.tag_utint},{self.tag_usint},{self.tag_uint},{self.tag_ubint},{self.tag_float},{self.tag_double},{self.tag_bool},"{self.binary_str}","{self.nchar_str}"' + + ] + + self.param = [1,50,100] + + def insert_data(self,column_dict,tbname,row_num): intData = [] floatData = [] - - tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, - col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') - for i in range(self.rowNum): - tdSql.execute("insert into test values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - intData.append(i + 1) - floatData.append(i + 0.1) - - # percentile verifacation - tdSql.error("select percentile(ts ,20) from test") - tdSql.error("select percentile(col7 ,20) from test") - tdSql.error("select percentile(col8 ,20) from test") - tdSql.error("select percentile(col9 ,20) from test") - column_list = [1,2,3,4,11,12,13,14] - percent_list = [0,50,100] - for i in column_list: - for j in percent_list: - tdSql.query(f"select percentile(col{i}, {j}) from test") - tdSql.checkData(0, 0, np.percentile(intData, j)) - - for i in [5,6]: - for j in percent_list: - tdSql.query(f"select percentile(col{i}, {j}) from test") - tdSql.checkData(0, 0, np.percentile(floatData, j)) - - tdSql.execute("create table meters (ts timestamp, voltage int) tags(loc nchar(20))") - tdSql.execute("create table t0 using meters tags('beijing')") - tdSql.execute("create table t1 using meters tags('shanghai')") - for i in range(self.rowNum): - tdSql.execute("insert into t0 values(%d, %d)" % (self.ts + i, i + 1)) - tdSql.execute("insert into t1 values(%d, %d)" % (self.ts + i, i + 1)) - - # tdSql.error("select percentile(voltage, 20) from meters") - - - - tdSql.execute("create table st(ts timestamp, k int)") - tdSql.execute("insert into st values(now, -100)(now+1a,-99)") - tdSql.query("select apercentile(k, 20) from st") - tdSql.checkData(0, 0, -100.00) - - + insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str) + for i in range(row_num): + insert_list = [] + self.setsql.insert_values(column_dict,i,insert_sql,insert_list,self.ts) + intData.append(i) + floatData.append(i + 0.1) + return intData,floatData + def check_tags(self,tags,param,num,value): + tdSql.query(f'select percentile({tags}, {param}) from {self.stbname}_{num}') + print(tdSql.queryResult) + tdSql.checkEqual(tdSql.queryResult[0][0], value) + def function_check_ntb(self): + tdSql.prepare() + tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict)) + intData,floatData = self.insert_data(self.column_dict,self.ntbname,self.rowNum) + for k,v in self.column_dict.items(): + for param in self.param: + if v.lower() in ['timestamp','bool'] or 'binary' in v.lower() or 'nchar' in v.lower(): + tdSql.error(f'select percentile({k},{param}) from {self.ntbname}') + elif v.lower() in ['tinyint','smallint','int','bigint','tinyint unsigned','smallint unsigned','int unsigned','bigint unsigned']: + tdSql.query(f'select percentile({k}, {param}) from {self.ntbname}') + tdSql.checkData(0, 0, np.percentile(intData, param)) + else: + tdSql.query(f'select percentile({k}, {param}) from {self.ntbname}') + tdSql.checkData(0, 0, np.percentile(floatData, param)) + def function_check_ctb(self): + tdSql.prepare() + tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) + for i in range(self.tbnum): + tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]})") + intData,floatData = self.insert_data(self.column_dict,f'{self.stbname}_{i}',self.rowNum) + for i in range(self.tbnum): + for k,v in self.column_dict.items(): + for param in self.param: + if v.lower() in ['timestamp','bool'] or 'binary' in v.lower() or 'nchar' in v.lower(): + tdSql.error(f'select percentile({k},{param}) from {self.stbname}_{i}') + elif v.lower() in ['tinyint','smallint','int','bigint','tinyint unsigned','smallint unsigned','int unsigned','bigint unsigned']: + tdSql.query(f'select percentile({k}, {param}) from {self.stbname}_{i}') + tdSql.checkData(0, 0, np.percentile(intData, param)) + else: + tdSql.query(f'select percentile({k}, {param}) from {self.stbname}_{i}') + tdSql.checkData(0, 0, np.percentile(floatData, param)) + + for k,v in self.tag_dict.items(): + for param in self.param: + if v.lower() in ['timestamp','bool'] or 'binary' in v.lower() or 'nchar' in v.lower(): + tdSql.error(f'select percentile({k},{param}) from {self.stbname}_{i}') + else: + tdSql.query(f'select {k} from {self.stbname}_{i}') + data_num = tdSql.queryResult[0][0] + tdSql.query(f'select percentile({k},{param}) from {self.stbname}_{i}') + tdSql.checkData(0,0,data_num) + + def run(self): + self.function_check_ntb() + self.function_check_ctb() def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/queryQnode.py b/tests/system-test/2-query/queryQnode.py index 8b893a93d7..3fdc09478d 100644 --- a/tests/system-test/2-query/queryQnode.py +++ b/tests/system-test/2-query/queryQnode.py @@ -32,9 +32,9 @@ class TDTestCase: # # --------------- main frame ------------------- # - clientCfgDict = {'queryPolicy': '1','debugFlag': 135} + clientCfgDict = {'queryPolicy': '1','debugFlag': 143} clientCfgDict["queryPolicy"] = '1' - clientCfgDict["debugFlag"] = 131 + clientCfgDict["debugFlag"] = 143 updatecfgDict = {'clientCfg': {}} updatecfgDict = {'debugFlag': 143} @@ -480,4 +480,4 @@ class TDTestCase: # add case with filename # tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/round.py b/tests/system-test/2-query/round.py index 9111586472..551e225a4d 100644 --- a/tests/system-test/2-query/round.py +++ b/tests/system-test/2-query/round.py @@ -8,14 +8,14 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'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 ,"udfDebugFlag":143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - + def prepare_datas(self): tdSql.execute( '''create table stb1 @@ -23,7 +23,7 @@ class TDTestCase: tags (t1 int) ''' ) - + tdSql.execute( ''' create table t1 @@ -65,14 +65,14 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - + def check_result_auto(self ,origin_query , round_query): pass round_result = tdSql.getResult(round_query) origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -87,13 +87,13 @@ class TDTestCase: for row_index , row in enumerate(round_result): for col_index , elem in enumerate(row): if auto_result[row_index][col_index] != elem: - check_status = False + check_status = False if not check_status: tdLog.notice("round function value has not as expected , sql is \"%s\" "%round_query ) sys.exit(1) else: tdLog.info("round value check pass , it work as expected ,sql is \"%s\" "%round_query ) - + def test_errors(self): error_sql_lists = [ "select round from t1", @@ -127,42 +127,42 @@ class TDTestCase: ] for error_sql in error_sql_lists: tdSql.error(error_sql) - + def support_types(self): type_error_sql_lists = [ - "select round(ts) from t1" , + "select round(ts) from t1" , "select round(c7) from t1", "select round(c8) from t1", "select round(c9) from t1", - "select round(ts) from ct1" , + "select round(ts) from ct1" , "select round(c7) from ct1", "select round(c8) from ct1", "select round(c9) from ct1", - "select round(ts) from ct3" , + "select round(ts) from ct3" , "select round(c7) from ct3", "select round(c8) from ct3", "select round(c9) from ct3", - "select round(ts) from ct4" , + "select round(ts) from ct4" , "select round(c7) from ct4", "select round(c8) from ct4", "select round(c9) from ct4", - "select round(ts) from stb1" , + "select round(ts) from stb1" , "select round(c7) from stb1", "select round(c8) from stb1", "select round(c9) from stb1" , - "select round(ts) from stbbb1" , + "select round(ts) from stbbb1" , "select round(c7) from stbbb1", "select round(ts) from tbname", "select round(c9) from tbname" ] - + for type_sql in type_error_sql_lists: tdSql.error(type_sql) - - + + type_sql_lists = [ "select round(c1) from t1", "select round(c2) from t1", @@ -192,16 +192,16 @@ class TDTestCase: "select round(c5) from stb1", "select round(c6) from stb1", - "select round(c6) as alisb from stb1", - "select round(c6) alisb from stb1", + "select round(c6) as alisb from stb1", + "select round(c6) alisb from stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - + def basic_round_function(self): - # basic query + # basic query tdSql.query("select c1 from ct3") tdSql.checkRows(0) tdSql.query("select c1 from t1") @@ -221,7 +221,7 @@ class TDTestCase: tdSql.query("select round(c5) from ct3") tdSql.checkRows(0) tdSql.query("select round(c6) from ct3") - + # used for regular table tdSql.query("select round(c1) from t1") tdSql.checkData(0, 0, None) @@ -239,7 +239,7 @@ class TDTestCase: tdSql.checkData(5, 5, None) self.check_result_auto( "select c1, c2, c3 , c4, c5 from t1", "select (c1), round(c2) ,round(c3), round(c4), round(c5) from t1") - + # used for sub table tdSql.query("select round(c1) from ct1") tdSql.checkData(0, 0, 8) @@ -251,20 +251,20 @@ class TDTestCase: self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct1", "select (c1), round(c2) ,round(c3), round(c4), round(c5) from ct1") self.check_result_auto("select round(round(round(round(round(round(round(round(round(round(c1)))))))))) nest_col_func from ct1;","select c1 from ct1" ) - # used for stable table - + # used for stable table + tdSql.query("select round(c1) from stb1") tdSql.checkRows(25) self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct4 ", "select (c1), round(c2) ,round(c3), round(c4), round(c5) from ct4") self.check_result_auto("select round(round(round(round(round(round(round(round(round(round(c1)))))))))) nest_col_func from ct4;" , "select c1 from ct4" ) - + # used for not exists table tdSql.error("select round(c1) from stbbb1") tdSql.error("select round(c1) from tbname") tdSql.error("select round(c1) from ct5") - # mix with common col + # mix with common col tdSql.query("select c1, round(c1) from ct1") tdSql.checkData(0 , 0 ,8) tdSql.checkData(0 , 1 ,8) @@ -289,7 +289,7 @@ class TDTestCase: tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 3 ,None) - + tdSql.checkData(3 , 0 , 6) tdSql.checkData(3 , 1 , 6) tdSql.checkData(3 , 2 ,6.66000) @@ -315,7 +315,7 @@ class TDTestCase: tdSql.query("select max(c5), count(c5) from stb1") tdSql.query("select max(c5), count(c5) from ct1") - + # bug fix for count tdSql.query("select count(c1) from ct4 ") tdSql.checkData(0,0,9) @@ -326,7 +326,7 @@ class TDTestCase: tdSql.query("select count(*) from stb1 ") tdSql.checkData(0,0,25) - # bug fix for compute + # bug fix for compute tdSql.query("select c1, abs(c1) -0 ,round(c1)-0 from ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) @@ -378,10 +378,10 @@ class TDTestCase: tdSql.checkData(0,4,7.900000000) tdSql.checkData(0,5,3.000000000) tdSql.checkData(0,6,7.500000000) - + def round_Arithmetic(self): pass - + def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") @@ -410,14 +410,14 @@ class TDTestCase: tdSql.execute( f"insert into sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - + tdSql.error( f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) self.check_result_auto( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select round(c1), round(c2) ,round(c3), round(c4), round(c5) ,round(c6) from sub1_bound") self.check_result_auto( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select round(c1), round(c2) ,round(c3), round(c3), round(c2) ,round(c1) from sub1_bound") self.check_result_auto("select round(round(round(round(round(round(round(round(round(round(c1)))))))))) nest_col_func from sub1_bound;" , "select round(c1) from sub1_bound" ) - + # check basic elem for table per row tdSql.query("select round(c1+0.2) ,round(c2) , round(c3+0.3) , round(c4-0.3), round(c5/2), round(c6/2) from sub1_bound ") tdSql.checkData(0, 0, 2147483647.000000000) @@ -444,32 +444,32 @@ class TDTestCase: self.check_result_auto( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select round(t1) ,round(c5) from stb1 where c1 > 0 order by tbname" ) self.check_result_auto( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select round(t1) , round(c5) from stb1 where c1 > 0 order by tbname" ) pass - - + + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: round basic query ============") + tdLog.printNoPrefix("==========step4: round basic query ============") self.basic_round_function() - tdLog.printNoPrefix("==========step5: round boundary query ============") + tdLog.printNoPrefix("==========step5: round boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step6: round filter query ============") + tdLog.printNoPrefix("==========step6: round filter query ============") self.abs_func_filter() diff --git a/tests/system-test/2-query/sqrt.py b/tests/system-test/2-query/sqrt.py index e21f5b397e..425d59f118 100644 --- a/tests/system-test/2-query/sqrt.py +++ b/tests/system-test/2-query/sqrt.py @@ -9,13 +9,13 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'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 ,"udfDebugFlag":143} def init(self, conn, powSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - + def prepare_datas(self): tdSql.execute( '''create table stb1 @@ -23,7 +23,7 @@ class TDTestCase: tags (t1 int) ''' ) - + tdSql.execute( ''' create table t1 @@ -65,14 +65,14 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - + def check_result_auto_sqrt(self ,origin_query , pow_query): pow_result = tdSql.getResult(pow_query) origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -92,7 +92,7 @@ class TDTestCase: if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None): check_status = False elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001): - check_status = False + check_status = False else: pass if not check_status: @@ -100,7 +100,7 @@ class TDTestCase: sys.exit(1) else: tdLog.info("sqrt value check pass , it work as expected ,sql is \"%s\" "%pow_query ) - + def test_errors(self): error_sql_lists = [ "select sqrt from t1", @@ -134,42 +134,42 @@ class TDTestCase: ] for error_sql in error_sql_lists: tdSql.error(error_sql) - + def support_types(self): type_error_sql_lists = [ - "select sqrt(ts) from t1" , + "select sqrt(ts) from t1" , "select sqrt(c7) from t1", "select sqrt(c8) from t1", "select sqrt(c9) from t1", - "select sqrt(ts) from ct1" , + "select sqrt(ts) from ct1" , "select sqrt(c7) from ct1", "select sqrt(c8) from ct1", "select sqrt(c9) from ct1", - "select sqrt(ts) from ct3" , + "select sqrt(ts) from ct3" , "select sqrt(c7) from ct3", "select sqrt(c8) from ct3", "select sqrt(c9) from ct3", - "select sqrt(ts) from ct4" , + "select sqrt(ts) from ct4" , "select sqrt(c7) from ct4", "select sqrt(c8) from ct4", "select sqrt(c9) from ct4", - "select sqrt(ts) from stb1" , + "select sqrt(ts) from stb1" , "select sqrt(c7) from stb1", "select sqrt(c8) from stb1", "select sqrt(c9) from stb1" , - "select sqrt(ts) from stbbb1" , + "select sqrt(ts) from stbbb1" , "select sqrt(c7) from stbbb1", "select sqrt(ts) from tbname", "select sqrt(c9) from tbname" ] - + for type_sql in type_error_sql_lists: tdSql.error(type_sql) - - + + type_sql_lists = [ "select sqrt(c1) from t1", "select sqrt(c2) from t1", @@ -199,16 +199,16 @@ class TDTestCase: "select sqrt(c5) from stb1", "select sqrt(c6) from stb1", - "select sqrt(c6) as alisb from stb1", - "select sqrt(c6) alisb from stb1", + "select sqrt(c6) as alisb from stb1", + "select sqrt(c6) alisb from stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - + def basic_sqrt_function(self): - # basic query + # basic query tdSql.query("select c1 from ct3") tdSql.checkRows(0) tdSql.query("select c1 from t1") @@ -249,7 +249,7 @@ class TDTestCase: tdSql.checkData(5, 5, None) self.check_result_auto_sqrt( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from t1", "select sqrt(abs(c1)), sqrt(abs(c2)) ,sqrt(abs(c3)), sqrt(abs(c4)), sqrt(abs(c5)) from t1") - + # used for sub table tdSql.query("select c2 ,sqrt(c2) from ct1") tdSql.checkData(0, 1, 298.140906284) @@ -265,7 +265,7 @@ class TDTestCase: tdSql.checkData(5 , 2, None) self.check_result_auto_sqrt( "select c1, c2, c3 , c4, c5 from ct1", "select sqrt(c1), sqrt(c2) ,sqrt(c3), sqrt(c4), sqrt(c5) from ct1") - + # nest query for sqrt functions tdSql.query("select c4 , sqrt(c4) ,sqrt(sqrt(c4)) , sqrt(sqrt(sqrt(c4))) from ct1;") tdSql.checkData(0 , 0 , 88) @@ -283,18 +283,18 @@ class TDTestCase: tdSql.checkData(11 , 2 , None) tdSql.checkData(11 , 3 , None) - # used for stable table - + # used for stable table + tdSql.query("select sqrt(c1) from stb1") tdSql.checkRows(25) - + # used for not exists table tdSql.error("select sqrt(c1) from stbbb1") tdSql.error("select sqrt(c1) from tbname") tdSql.error("select sqrt(c1) from ct5") - # mix with common col + # mix with common col tdSql.query("select c1, sqrt(c1) from ct1") tdSql.checkData(0 , 0 ,8) tdSql.checkData(0 , 1 ,2.828427125) @@ -314,7 +314,7 @@ class TDTestCase: tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 3 ,None) - + tdSql.checkData(3 , 0 , 6) tdSql.checkData(3 , 1 ,2.449489743) tdSql.checkData(3 , 2 ,2.449489743) @@ -335,7 +335,7 @@ class TDTestCase: tdSql.query("select max(c5), count(c5) from stb1") tdSql.query("select max(c5), count(c5) from ct1") - + # bug fix for count tdSql.query("select count(c1) from ct4 ") tdSql.checkData(0,0,9) @@ -346,7 +346,7 @@ class TDTestCase: tdSql.query("select count(*) from stb1 ") tdSql.checkData(0,0,25) - # # bug fix for compute + # # bug fix for compute tdSql.query("select c1, sqrt(c1) -0 ,sqrt(c1-4)-0 from ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) @@ -397,16 +397,16 @@ class TDTestCase: tdSql.checkRows(13) # # bug for compute in functions - # tdSql.query("select c1, abs(1/0) from ct1") + # tdSql.query("select c1, abs(1/0) from ct1") # tdSql.checkData(0, 0, 8) # tdSql.checkData(0, 1, 1) - tdSql.query("select c1, sqrt(1) from ct1") + tdSql.query("select c1, sqrt(1) from ct1") tdSql.checkData(0, 1, 1.000000000) tdSql.checkRows(13) # two cols start sqrt(x,y) - tdSql.query("select c1,c2, sqrt(c2) from ct1") + tdSql.query("select c1,c2, sqrt(c2) from ct1") tdSql.checkData(0, 2, 298.140906284) tdSql.checkData(1, 2, 278.885281074) tdSql.checkData(4, 2, 0.000000000) @@ -445,10 +445,10 @@ class TDTestCase: tdSql.checkData(0,3,1.000000000) tdSql.checkData(0,4,0.900000000) tdSql.checkData(0,5,1.000000000) - + def pow_Arithmetic(self): pass - + def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") @@ -475,11 +475,11 @@ class TDTestCase: f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) self.check_result_auto_sqrt( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from sub1_bound ", "select sqrt(abs(c1)), sqrt(abs(c2)) ,sqrt(abs(c3)), sqrt(abs(c4)), sqrt(abs(c5)) from sub1_bound") - + self.check_result_auto_sqrt( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select sqrt(c1), sqrt(c2) ,sqrt(c3), sqrt(c3), sqrt(c2) ,sqrt(c1) from sub1_bound") self.check_result_auto_sqrt("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select sqrt(abs(c1)) from sub1_bound" ) - + # check basic elem for table per row tdSql.query("select sqrt(abs(c1)) ,sqrt(abs(c2)) , sqrt(abs(c3)) , sqrt(abs(c4)), sqrt(abs(c5)), sqrt(abs(c6)) from sub1_bound ") tdSql.checkData(0,0,math.sqrt(2147483647)) @@ -504,7 +504,7 @@ class TDTestCase: tdSql.checkData(0,1,math.sqrt(9223372036854775807)) tdSql.checkData(0,2,math.sqrt(32767.000000000)) tdSql.checkData(0,3,math.sqrt(63.500000000)) - + def support_super_table_test(self): tdSql.execute(" use db ") self.check_result_auto_sqrt( " select c5 from stb1 order by ts " , "select sqrt(c5) from stb1 order by ts" ) @@ -522,42 +522,42 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: sqrt basic query ============") + tdLog.printNoPrefix("==========step4: sqrt basic query ============") self.basic_sqrt_function() - tdLog.printNoPrefix("==========step5: big number sqrt query ============") + tdLog.printNoPrefix("==========step5: big number sqrt query ============") self.test_big_number() - tdLog.printNoPrefix("==========step6: base number for sqrt query ============") + tdLog.printNoPrefix("==========step6: base number for sqrt query ============") self.pow_base_test() - tdLog.printNoPrefix("==========step7: sqrt boundary query ============") + tdLog.printNoPrefix("==========step7: sqrt boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step8: sqrt filter query ============") + tdLog.printNoPrefix("==========step8: sqrt filter query ============") self.abs_func_filter() tdLog.printNoPrefix("==========step9: check sqrt result of stable query ============") - self.support_super_table_test() + self.support_super_table_test() + - def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/statecount.py b/tests/system-test/2-query/statecount.py index 162a5a61fe..90e8bebab4 100644 --- a/tests/system-test/2-query/statecount.py +++ b/tests/system-test/2-query/statecount.py @@ -11,7 +11,7 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'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 ,"udfDebugFlag":143} @@ -476,7 +476,7 @@ class TDTestCase: self.check_unit_time() self.query_precision() - + def stop(self): diff --git a/tests/system-test/2-query/stateduration.py b/tests/system-test/2-query/stateduration.py index 23169553dc..6b50446814 100644 --- a/tests/system-test/2-query/stateduration.py +++ b/tests/system-test/2-query/stateduration.py @@ -25,10 +25,10 @@ class TDTestCase: def run(self): tdSql.prepare() # timestamp = 1ms , time_unit = 1s - tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') for i in range(self.row_num): - tdSql.execute("insert into test values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute("insert into test values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) integer_list = [1,2,3,4,11,12,13,14] float_list = [5,6] @@ -72,10 +72,10 @@ class TDTestCase: tdSql.error(f"select stateduration(col1,{i},5) from test") # timestamp = 1s, time_unit =1s - tdSql.execute('''create table test1(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + tdSql.execute('''create table test1(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''') for i in range(self.row_num): - tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" % (self.ts + i*1000, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) for i in integer_list: diff --git a/tests/system-test/2-query/timezone.py b/tests/system-test/2-query/timezone.py index ce2cdc062e..3707d25c88 100644 --- a/tests/system-test/2-query/timezone.py +++ b/tests/system-test/2-query/timezone.py @@ -18,24 +18,24 @@ class TDTestCase: self.arithmetic_operators = ['+','-','*','/'] self.arithmetic_values = [0,1,100,15.5] # name of normal table - self.ntbname = 'ntb' + self.ntbname = 'ntb' # name of stable - self.stbname = 'stb' + self.stbname = 'stb' # structure of column - self.column_dict = { + self.column_dict = { 'ts':'timestamp', 'c1':'int', 'c2':'float', 'c3':'double' } # structure of tag - self.tag_dict = { + self.tag_dict = { 't0':'int' } # number of child tables - self.tbnum = 2 + self.tbnum = 2 # values of tag,the number of values should equal to tbnum - self.tag_values = [ + self.tag_values = [ f'10', f'100' ] @@ -62,7 +62,7 @@ class TDTestCase: time_zone = time_zone_1 + " " + time_zone_2 print("expected time zone: " + time_zone) return time_zone - + def tb_type_check(self,tb_type): if tb_type in ['normal_table','child_table']: tdSql.checkRows(len(self.values_list)) @@ -115,7 +115,7 @@ class TDTestCase: timezone = self.get_system_timezone() self.timezone_check_ntb(timezone) self.timezone_check_stb(timezone) - + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/system-test/2-query/top.py b/tests/system-test/2-query/top.py index 86e201ea9a..a7a433a897 100644 --- a/tests/system-test/2-query/top.py +++ b/tests/system-test/2-query/top.py @@ -45,36 +45,14 @@ class TDTestCase: 'col12': 'binary(20)', 'col13': 'nchar(20)' } - + self.param_list = [1,100] def insert_data(self,column_dict,tbname,row_num): - sql = '' - for k, v in column_dict.items(): - if v.lower() == 'timestamp' or v.lower() == 'tinyint' or v.lower() == 'smallint' or v.lower() == 'int' or v.lower() == 'bigint' or \ - v.lower() == 'tinyint unsigned' or v.lower() == 'smallint unsigned' or v.lower() == 'int unsigned' or v.lower() == 'bigint unsigned' or v.lower() == 'bool': - sql += '%d,' - elif v.lower() == 'float' or v.lower() == 'double': - sql += '%f,' - elif 'binary' in v.lower(): - sql += f'"{self.binary_str}%d",' - elif 'nchar' in v.lower(): - sql += f'"{self.nchar_str}%d",' - insert_sql = f'insert into {tbname} values({sql[:-1]})' + insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str) for i in range(row_num): insert_list = [] - for k, v in column_dict.items(): - if v.lower() in[ 'tinyint' , 'smallint' , 'int', 'bigint' , 'tinyint unsigned' , 'smallint unsigned' , 'int unsigned' , 'bigint unsigned'] or\ - 'binary' in v.lower() or 'nchar' in v.lower(): - insert_list.append(1 + i) - elif v.lower() == 'float' or v.lower() == 'double': - insert_list.append(0.1 + i) - elif v.lower() == 'bool': - insert_list.append(i % 2) - elif v.lower() == 'timestamp': - insert_list.append(self.ts + i) - tdSql.execute(insert_sql%(tuple(insert_list))) - pass + self.setsql.insert_values(column_dict,i,insert_sql,insert_list,self.ts) def top_check_data(self,tbname,tb_type): new_column_dict = {} for param in self.param_list: @@ -86,7 +64,7 @@ class TDTestCase: tdSql.checkRows(self.rowNum) values_list = [] for i in range(self.rowNum): - tp = (self.rowNum-i,) + tp = (self.rowNum-i-1,) values_list.insert(0,tp) tdSql.checkEqual(tdSql.queryResult,values_list) elif tb_type == 'stable': @@ -96,7 +74,7 @@ class TDTestCase: tdSql.checkRows(param) values_list = [] for i in range(param): - tp = (self.rowNum-i,) + tp = (self.rowNum-i-1,) values_list.insert(0,tp) tdSql.checkEqual(tdSql.queryResult,values_list) elif tb_type == 'stable': @@ -129,10 +107,10 @@ class TDTestCase: tdSql.execute(f"create database if not exists {dbname} vgroups 2") tdSql.execute(f'use {dbname}') tdSql.execute(self.setsql.set_create_stable_sql(stbname,self.column_dict,tag_dict)) - + for i in range(self.tbnum): tdSql.execute(f"create table {stbname}_{i} using {stbname} tags({tag_values[0]})") - tdSql.execute(self.insert_data(self.column_dict,f'{stbname}_{i}',self.rowNum)) + self.insert_data(self.column_dict,f'{stbname}_{i}',self.rowNum) tdSql.query('show tables') vgroup_list = [] for i in range(len(tdSql.queryResult)): @@ -163,7 +141,7 @@ class TDTestCase: self.top_check_ntb() self.top_check_stb() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/7-tmq/dataFromTsdbNWal.py b/tests/system-test/7-tmq/dataFromTsdbNWal.py new file mode 100644 index 0000000000..a55fbbfd18 --- /dev/null +++ b/tests/system-test/7-tmq/dataFromTsdbNWal.py @@ -0,0 +1,254 @@ + +import taos +import sys +import time +import socket +import os +import threading +import math + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.vgroups = 1 + self.ctbNum = 100 + self.rowsPerTbl = 10000 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 1, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 10, + 'rowsPerTbl': 10000, + 'batchNum': 1000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 10, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("restart taosd to ensure that the data falls into the disk") + # tdDnodes.stop(1) + # tdDnodes.start(1) + tdSql.query("flush database %s"%(paraDict['dbName'])) + return + + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 1, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 10, + 'rowsPerTbl': 10000, + 'batchNum': 10, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + paraDict['batchNum'] = 100 + paraDict['startTs'] = paraDict['startTs'] + self.rowsPerTbl + + topicNameList = ['topic1'] + expectRowsList = [] + tmqCom.initConsumerTable() + + tdLog.info("create topics from stb with filter") + queryString = "select * from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + # sqlString = "create topic %s as stable %s" %(topicNameList[0], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicNameList[0], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + # tdSql.query(queryString) + # expectRowsList.append(tdSql.getRows()) + + # init consume info, and start tmq_sim, then check consume result + tdLog.info("insert consume info to consume processor") + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 + topicList = topicNameList[0] + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1, enable.auto.commit:true, auto.commit.interval.ms:1000, auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + # after start consume, continue insert some data + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + # + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + + tdLog.info("wait the consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + + if expectRowsList[0] != resultList[0]: + tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[0], resultList[0])) + tdLog.exit("%d tmq consume rows error!"%consumerId) + + tmqCom.checkFileContent(consumerId, queryString) + + time.sleep(10) + for i in range(len(topicNameList)): + tdSql.query("drop topic %s"%topicNameList[i]) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def tmqCase2(self): + tdLog.printNoPrefix("======== test case 2: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 1, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 10, + 'rowsPerTbl': 10000, + 'batchNum': 10, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + topicNameList = ['topic1'] + expectRowsList = [] + tmqCom.initConsumerTable() + + tdLog.info("create topics from stb with filter") + queryString = "select * from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + # sqlString = "create topic %s as stable %s" %(topicNameList[0], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicNameList[0], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + totalRowsInserted = expectRowsList[0] + + # init consume info, and start tmq_sim, then check consume result + tdLog.info("insert consume info to consume processor") + consumerId = 1 + expectrowcnt = math.ceil(paraDict["rowsPerTbl"] * paraDict["ctbNum"] / 3) + topicList = topicNameList[0] + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1, enable.auto.commit:true, auto.commit.interval.ms:1000, auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor 0") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + tdLog.info("wait the consume result") + + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + + if not (expectrowcnt <= resultList[0] and totalRowsInserted >= resultList[0]): + tdLog.info("act consume rows: %d, expect consume rows between %d and %d"%(resultList[0], expectrowcnt, totalRowsInserted)) + tdLog.exit("%d tmq consume rows error!"%consumerId) + + firstConsumeRows = resultList[0] + + # reinit consume info, and start tmq_sim, then check consume result + tmqCom.initConsumerTable() + consumerId = 2 + expectrowcnt = math.ceil(paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2/3) + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor 1") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + tdLog.info("wait the consume result") + + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + + actConsumeTotalRows = firstConsumeRows + resultList[0] + + if not (expectrowcnt >= resultList[0] and totalRowsInserted == actConsumeTotalRows): + tdLog.info("act consume rows, first: %d, second: %d "%(firstConsumeRows, resultList[0])) + tdLog.info("and sum of two consume rows: %d should be equal to total inserted rows: %d"%(actConsumeTotalRows, totalRowsInserted)) + tdLog.exit("%d tmq consume rows error!"%consumerId) + + time.sleep(10) + for i in range(len(topicNameList)): + tdSql.query("drop topic %s"%topicNameList[i]) + + tdLog.printNoPrefix("======== test case 2 end ...... ") + + def run(self): + tdSql.prepare() + self.prepareTestEnv() + self.tmqCase1() + # self.tmqCase2() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmqAutoCreateTbl.py b/tests/system-test/7-tmq/tmqAutoCreateTbl.py new file mode 100644 index 0000000000..1622ad7621 --- /dev/null +++ b/tests/system-test/7-tmq/tmqAutoCreateTbl.py @@ -0,0 +1,238 @@ + +import taos +import sys +import time +import socket +import os +import threading +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.vgroups = 4 + self.ctbNum = 1000 + self.rowsPerTbl = 1000 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 400, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + # tdLog.info("create ctb") + # tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + # ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + # tdLog.info("insert data") + # tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctbx",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + + # tdLog.info("restart taosd to ensure that the data falls into the disk") + # tdSql.query("flush database %s"%(paraDict['dbName'])) + return + + # 自动建表完成数据插入,启动消费 + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 400, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + # tmqCom.initConsumerTable() + # tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + # tdLog.info("create stb") + # tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + # tdLog.info("insert data by auto create ctb") + # tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctb",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + if totalConsumeRows != totalRowsInserted: + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def tmqCase2(self): + tdLog.printNoPrefix("======== test case 2: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 1000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + # tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + # tdLog.info("create stb") + # tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + # tdLog.info("create ctb") + # tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + # ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + # tdLog.info("insert data") + # tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("create some new child table and insert data ") + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctby",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + if totalConsumeRows != totalRowsInserted: + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 2 end ...... ") + + + def run(self): + tdSql.prepare() + self.prepareTestEnv() + self.tmqCase1() + # self.tmqCase2() TD-17267 + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmqCommon.py b/tests/system-test/7-tmq/tmqCommon.py index 7f9d36bd26..2030563a9a 100644 --- a/tests/system-test/7-tmq/tmqCommon.py +++ b/tests/system-test/7-tmq/tmqCommon.py @@ -361,19 +361,25 @@ class TMQCom: if startTs == 0: t = time.time() startTs = int(round(t * 1000)) - + #tdLog.debug("doing insert data into stable:%s rows:%d ..."%(stbName, allRows)) rowsBatched = 0 for i in range(ctbNum): - sql += " %s.%s_%d using %s.%s tags (%d) values "%(dbName,ctbPrefix,i+ctbStartIdx,dbName,stbName,i) + tagBinaryValue = 'beijing' + if (i % 2 == 0): + tagBinaryValue = 'shanghai' + elif (i % 3 == 0): + tagBinaryValue = 'changsha' + + sql += " %s.%s_%d using %s.%s tags (%d, %d, %d, '%s', '%s') values "%(dbName,ctbPrefix,i+ctbStartIdx,dbName,stbName,i+ctbStartIdx,i+ctbStartIdx,i+ctbStartIdx,tagBinaryValue,tagBinaryValue) for j in range(rowsPerTbl): - sql += "(%d, %d, 'tmqrow_%d') "%(startTs + j, j, j) + sql += "(%d, %d, %d, %d, 'binary_%d', 'nchar_%d', now) "%(startTs+j, j,j, j,i+ctbStartIdx,rowsBatched) rowsBatched += 1 if ((rowsBatched == batchNum) or (j == rowsPerTbl - 1)): tsql.execute(sql) rowsBatched = 0 if j < rowsPerTbl - 1: - sql = "insert into %s.%s_%d using %s.%s tags (%d) values " %(dbName,ctbPrefix,i+ctbStartIdx,dbName,stbName,i) + sql = "insert into %s.%s_%d using %s.%s tags (%d, %d, %d, '%s', '%s') values " %(dbName,ctbPrefix,i+ctbStartIdx,dbName,stbName,i+ctbStartIdx,i+ctbStartIdx,i+ctbStartIdx,tagBinaryValue,tagBinaryValue) else: sql = "insert into " #end sql diff --git a/tests/system-test/7-tmq/tmqDnodeRestart.py b/tests/system-test/7-tmq/tmqDnodeRestart.py new file mode 100644 index 0000000000..8354991578 --- /dev/null +++ b/tests/system-test/7-tmq/tmqDnodeRestart.py @@ -0,0 +1,253 @@ + +import taos +import sys +import time +import socket +import os +import threading +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.vgroups = 2 + self.ctbNum = 100 + self.rowsPerTbl = 10000 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 3, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 500, + 'rowsPerTbl': 1000, + 'batchNum': 500, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("restart taosd to ensure that the data falls into the disk") + # tdDnodes.stop(1) + # tdDnodes.start(1) + tdSql.query("flush database %s"%(paraDict['dbName'])) + return + + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 400, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + # paraDict['vgroups'] = self.vgroups + # paraDict['ctbNum'] = self.ctbNum + # paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:500,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + # time.sleep(3) + tmqCom.getStartCommitNotifyFromTmqsim() + tdLog.info("================= restart dnode ===========================") + tdDnodes.stop(1) + tdDnodes.start(1) + time.sleep(5) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + if totalConsumeRows != totalRowsInserted: + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def tmqCase2(self): + tdLog.printNoPrefix("======== test case 2: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 1000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + # paraDict['vgroups'] = self.vgroups + # paraDict['ctbNum'] = self.ctbNum + # paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("create some new child table and insert data ") + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctb",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + + tmqCom.getStartCommitNotifyFromTmqsim() + tdLog.info("================= restart dnode ===========================") + tdDnodes.stop(1) + tdDnodes.start(1) + time.sleep(5) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + if totalConsumeRows != totalRowsInserted: + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 2 end ...... ") + + def run(self): + tdSql.prepare() + + self.tmqCase1() + self.tmqCase2() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmqUpdate-1ctb.py b/tests/system-test/7-tmq/tmqUpdate-1ctb.py new file mode 100644 index 0000000000..9e2d06d1bd --- /dev/null +++ b/tests/system-test/7-tmq/tmqUpdate-1ctb.py @@ -0,0 +1,259 @@ + +import taos +import sys +import time +import socket +import os +import threading +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.snapshot = 0 + self.vgroups = 2 + self.ctbNum = 1 + self.rowsPerTbl = 100000 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1, + 'rowsPerTbl': 100000, + 'batchNum': 1200, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + # tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + # tdLog.info("restart taosd to ensure that the data falls into the disk") + # tdSql.query("flush database %s"%(paraDict['dbName'])) + return + + # 自动建表完成数据插入,启动消费 + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1, + 'rowsPerTbl': 100000, + 'batchNum': 3000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + paraDict['snapshot'] = self.snapshot + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + # update to half tables + paraDict['rowsPerTbl'] = int(self.rowsPerTbl / 2) + # tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + # paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + consumerId = 0 + expectrowcnt = int(paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 3/2) + topicList = topicFromStb1 + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + tdLog.info("act consume rows: %d, expect consume rows: %d, act insert rows: %d"%(totalConsumeRows, expectrowcnt, totalRowsInserted)) + if totalConsumeRows != expectrowcnt: + tdLog.exit("tmq consume rows error!") + + tmqCom.checkFileContent(consumerId, queryString) + + tdSql.query("drop topic %s"%topicFromStb1) + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def tmqCase2(self): + tdLog.printNoPrefix("======== test case 2: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1, + 'rowsPerTbl': 10000, + 'batchNum': 5000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['snapshot'] = self.snapshot + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tdLog.info("restart taosd to ensure that the data falls into the disk") + tdSql.query("flush database %s"%(paraDict['dbName'])) + + # update to half tables + paraDict['startTs'] = paraDict['startTs'] + int(self.rowsPerTbl / 2) + paraDict['rowsPerTbl'] = int(self.rowsPerTbl / 2) + tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + # tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tmqCom.initConsumerTable() + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + # paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + consumerId = 1 + expectrowcnt = int(paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2) + topicList = topicFromStb1 + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + tdLog.info("act consume rows: %d, act insert rows: %d, expect consume rows: %d, "%(totalConsumeRows, totalRowsInserted, expectrowcnt)) + + if totalConsumeRows != expectrowcnt: + tdLog.exit("tmq consume rows error!") + + # tmqCom.checkFileContent(consumerId, queryString) + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 2 end ...... ") + + def run(self): + tdSql.prepare() + self.prepareTestEnv() + tdLog.printNoPrefix("=============================================") + tdLog.printNoPrefix("======== snapshot is 0: only consume from wal") + self.tmqCase1() + self.tmqCase2() + + self.prepareTestEnv() + tdLog.printNoPrefix("====================================================================") + tdLog.printNoPrefix("======== snapshot is 1: firstly consume from tsbs, and then from wal") + self.snapshot = 1 + self.tmqCase1() + self.tmqCase2() + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmqUpdate-multiCtb.py b/tests/system-test/7-tmq/tmqUpdate-multiCtb.py new file mode 100644 index 0000000000..9e2d06d1bd --- /dev/null +++ b/tests/system-test/7-tmq/tmqUpdate-multiCtb.py @@ -0,0 +1,259 @@ + +import taos +import sys +import time +import socket +import os +import threading +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.snapshot = 0 + self.vgroups = 2 + self.ctbNum = 1 + self.rowsPerTbl = 100000 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1, + 'rowsPerTbl': 100000, + 'batchNum': 1200, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + # tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + # tdLog.info("restart taosd to ensure that the data falls into the disk") + # tdSql.query("flush database %s"%(paraDict['dbName'])) + return + + # 自动建表完成数据插入,启动消费 + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1, + 'rowsPerTbl': 100000, + 'batchNum': 3000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + paraDict['snapshot'] = self.snapshot + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + # update to half tables + paraDict['rowsPerTbl'] = int(self.rowsPerTbl / 2) + # tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + # paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + consumerId = 0 + expectrowcnt = int(paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 3/2) + topicList = topicFromStb1 + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + tdLog.info("act consume rows: %d, expect consume rows: %d, act insert rows: %d"%(totalConsumeRows, expectrowcnt, totalRowsInserted)) + if totalConsumeRows != expectrowcnt: + tdLog.exit("tmq consume rows error!") + + tmqCom.checkFileContent(consumerId, queryString) + + tdSql.query("drop topic %s"%topicFromStb1) + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def tmqCase2(self): + tdLog.printNoPrefix("======== test case 2: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1, + 'rowsPerTbl': 10000, + 'batchNum': 5000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['snapshot'] = self.snapshot + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tdLog.info("restart taosd to ensure that the data falls into the disk") + tdSql.query("flush database %s"%(paraDict['dbName'])) + + # update to half tables + paraDict['startTs'] = paraDict['startTs'] + int(self.rowsPerTbl / 2) + paraDict['rowsPerTbl'] = int(self.rowsPerTbl / 2) + tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + # tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tmqCom.initConsumerTable() + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + # paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + consumerId = 1 + expectrowcnt = int(paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2) + topicList = topicFromStb1 + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + tdLog.info("act consume rows: %d, act insert rows: %d, expect consume rows: %d, "%(totalConsumeRows, totalRowsInserted, expectrowcnt)) + + if totalConsumeRows != expectrowcnt: + tdLog.exit("tmq consume rows error!") + + # tmqCom.checkFileContent(consumerId, queryString) + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 2 end ...... ") + + def run(self): + tdSql.prepare() + self.prepareTestEnv() + tdLog.printNoPrefix("=============================================") + tdLog.printNoPrefix("======== snapshot is 0: only consume from wal") + self.tmqCase1() + self.tmqCase2() + + self.prepareTestEnv() + tdLog.printNoPrefix("====================================================================") + tdLog.printNoPrefix("======== snapshot is 1: firstly consume from tsbs, and then from wal") + self.snapshot = 1 + self.tmqCase1() + self.tmqCase2() + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmqUpdate1.py b/tests/system-test/7-tmq/tmqUpdate1.py new file mode 100644 index 0000000000..5f11090385 --- /dev/null +++ b/tests/system-test/7-tmq/tmqUpdate1.py @@ -0,0 +1,175 @@ + +import taos +import sys +import time +import socket +import os +import threading +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.vgroups = 4 + self.ctbNum = 1000 + self.rowsPerTbl = 1000 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 400, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + paraDict['ctbNum'] = int(self.ctbNum / 2) + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + # tdLog.info("restart taosd to ensure that the data falls into the disk") + # tdSql.query("flush database %s"%(paraDict['dbName'])) + return + + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 1000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tdLog.info("restart taosd to ensure that the data falls into the disk") + tdSql.query("flush database %s"%(paraDict['dbName'])) + + # update to half tables + paraDict['ctbNum'] = int(self.ctbNum / 4) + tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']+paraDict['ctbNum']) + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']+paraDict['ctbNum']) + + tmqCom.initConsumerTable() + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + paraDict['ctbNum'] = self.ctbNum + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * (1 + 1) + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt + paraDict["rowsPerTbl"] * paraDict["ctbNum"],topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + paraDict['ctbNum'] = int(self.ctbNum / 2) + paraDict['ctbStartIdx'] += paraDict['ctbNum'] + _ = tmqCom.asyncInsertDataByInterlace(paraDict) + time.sleep(3) + pthread = tmqCom.asyncInsertDataByInterlace(paraDict) + pthread.join() + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + tdLog.info("act consume rows: %d, act insert rows: %d, expect consume rows: %d, "%(totalConsumeRows, totalRowsInserted, expectrowcnt)) + + if totalConsumeRows <= totalRowsInserted or totalConsumeRows != expectrowcnt: + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + + def run(self): + tdSql.prepare() + self.prepareTestEnv() + self.tmqCase1() + # self.tmqCase2() + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/99-TDcase/TD-17255.py b/tests/system-test/99-TDcase/TD-17255.py new file mode 100644 index 0000000000..9eb8d531f7 --- /dev/null +++ b/tests/system-test/99-TDcase/TD-17255.py @@ -0,0 +1,333 @@ + +import taos +import sys +import time +import socket +import os +import threading +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.vgroups = 2 + self.ctbNum = 100 + self.rowsPerTbl = 10000 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepareTestEnv(self): + tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 3, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 500, + 'rowsPerTbl': 1000, + 'batchNum': 500, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 3, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("restart taosd to ensure that the data falls into the disk") + # tdDnodes.stop(1) + # tdDnodes.start(1) + tdSql.query("flush database %s"%(paraDict['dbName'])) + return + + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 400, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + # paraDict['vgroups'] = self.vgroups + # paraDict['ctbNum'] = self.ctbNum + # paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:500,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + # time.sleep(3) + tmqCom.getStartCommitNotifyFromTmqsim() + tdLog.info("================= restart dnode ===========================") + tdDnodes.stop(1) + tdDnodes.start(1) + time.sleep(5) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + if totalConsumeRows != totalRowsInserted: + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def tmqCase2(self): + tdLog.printNoPrefix("======== test case 2: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 1000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + # paraDict['vgroups'] = self.vgroups + # paraDict['ctbNum'] = self.ctbNum + # paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("create ctb") + tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("insert data") + tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + tdLog.info("create some new child table and insert data ") + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctb",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + + tmqCom.getStartCommitNotifyFromTmqsim() + tdLog.info("================= restart dnode ===========================") + tdDnodes.stop(1) + tdDnodes.start(1) + time.sleep(5) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + if totalConsumeRows != totalRowsInserted: + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 2 end ...... ") + + # 自动建表完成数据插入,启动消费 + def tmqCase3(self): + tdLog.printNoPrefix("======== test case 3: ") + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 1000, + 'rowsPerTbl': 1000, + 'batchNum': 400, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 5, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 1} + + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl + + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + tdLog.info("create stb") + tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + tdLog.info("insert data by auto create ctb") + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctb",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + + tdLog.info("create topics from stb1") + topicFromStb1 = 'topic_stb1' + queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicFromStb1, queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] + topicList = topicFromStb1 + ifcheckdata = 0 + ifManualCommit = 0 + keyList = 'group.id:cgrp1,\ + enable.auto.commit:true,\ + auto.commit.interval.ms:1000,\ + auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) + + # tdLog.info("================= restart dnode ===========================") + # tdDnodes.stop(1) + # tdDnodes.start(1) + # time.sleep(2) + + tdLog.info("insert process end, and start to check consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + totalConsumeRows = 0 + for i in range(expectRows): + totalConsumeRows += resultList[i] + + tdSql.query(queryString) + totalRowsInserted = tdSql.getRows() + + if totalConsumeRows != totalRowsInserted: + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.exit("tmq consume rows error!") + + tdSql.query("drop topic %s"%topicFromStb1) + + tdLog.printNoPrefix("======== test case 3 end ...... ") + + + def run(self): + tdSql.prepare() + + self.tmqCase1() + # self.tmqCase2() + self.tmqCase3() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 3b0dd76a30..269f83a139 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -21,7 +21,7 @@ python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.py python3 ./test.py -f 1-insert/test_stmt_muti_insert_query.py python3 ./test.py -f 1-insert/test_stmt_set_tbname_tag.py python3 ./test.py -f 1-insert/alter_stable.py -#python3 ./test.py -f 1-insert/alter_table.py +python3 ./test.py -f 1-insert/alter_table.py python3 ./test.py -f 1-insert/insertWithMoreVgroup.py python3 ./test.py -f 1-insert/table_comment.py python3 ./test.py -f 1-insert/time_range_wise.py @@ -118,9 +118,11 @@ python3 ./test.py -f 2-query/distribute_agg_stddev.py python3 ./test.py -f 2-query/twa.py python3 ./test.py -f 2-query/irate.py python3 ./test.py -f 2-query/and_or_for_byte.py - +python3 ./test.py -f 2-query/count_partition.py python3 ./test.py -f 2-query/function_null.py -#python3 ./test.py -f 2-query/queryQnode.py +python3 ./test.py -f 2-query/queryQnode.py +python3 ./test.py -f 2-query/max_partition.py + python3 ./test.py -f 6-cluster/5dnode1mnode.py #BUG python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3 @@ -174,8 +176,8 @@ python3 ./test.py -f 7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-1ctb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb.py - - +python3 ./test.py -f 7-tmq/tmqAutoCreateTbl.py +#python3 ./test.py -f 7-tmq/tmqDnodeRestart.py #------------querPolicy 2----------- @@ -263,6 +265,8 @@ python3 ./test.py -f 2-query/distribute_agg_stddev.py -Q 2 python3 ./test.py -f 2-query/twa.py -Q 2 python3 ./test.py -f 2-query/irate.py -Q 2 python3 ./test.py -f 2-query/function_null.py -Q 2 +python3 ./test.py -f 2-query/count_partition.py -Q 2 +python3 ./test.py -f 2-query/max_partition.py -Q 2 #------------querPolicy 3----------- @@ -348,3 +352,5 @@ python3 ./test.py -f 2-query/distribute_agg_stddev.py -Q 3 python3 ./test.py -f 2-query/twa.py -Q 3 python3 ./test.py -f 2-query/irate.py -Q 3 python3 ./test.py -f 2-query/function_null.py -Q 3 +python3 ./test.py -f 2-query/count_partition.py -Q 3 +python3 ./test.py -f 2-query/max_partition.py -Q 3 \ No newline at end of file diff --git a/tests/test/c/sdbDump.c b/tests/test/c/sdbDump.c index 42f1bb4062..4d0f582dc6 100644 --- a/tests/test/c/sdbDump.c +++ b/tests/test/c/sdbDump.c @@ -72,6 +72,7 @@ void dumpDb(SSdb *pSdb, SJson *json) { tjsonAddIntegerToObject(item, "buffer", pObj->cfg.buffer); tjsonAddIntegerToObject(item, "pageSize", pObj->cfg.pageSize); tjsonAddIntegerToObject(item, "pages", pObj->cfg.pages); + tjsonAddIntegerToObject(item, "cacheLastSize", pObj->cfg.cacheLastSize); tjsonAddIntegerToObject(item, "daysPerFile", pObj->cfg.daysPerFile); tjsonAddIntegerToObject(item, "daysToKeep0", pObj->cfg.daysToKeep0); tjsonAddIntegerToObject(item, "daysToKeep1", pObj->cfg.daysToKeep1); @@ -84,7 +85,7 @@ void dumpDb(SSdb *pSdb, SJson *json) { tjsonAddIntegerToObject(item, "compression", pObj->cfg.compression); tjsonAddIntegerToObject(item, "replications", pObj->cfg.replications); tjsonAddIntegerToObject(item, "strict", pObj->cfg.strict); - tjsonAddIntegerToObject(item, "cacheLastRow", pObj->cfg.cacheLastRow); + tjsonAddIntegerToObject(item, "cacheLast", pObj->cfg.cacheLast); tjsonAddIntegerToObject(item, "hashMethod", pObj->cfg.hashMethod); tjsonAddIntegerToObject(item, "numOfRetensions", pObj->cfg.numOfRetensions); tjsonAddIntegerToObject(item, "schemaless", pObj->cfg.schemaless); diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 85fe456670..b4f86d52b5 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -52,6 +52,7 @@ typedef struct { // char autoOffsetRest[16]; // none, earliest, latest TdFilePtr pConsumeRowsFile; + TdFilePtr pConsumeMetaFile; int32_t ifCheckData; int64_t expectMsgCnt; @@ -445,7 +446,7 @@ static void dumpToFileForCheck(TdFilePtr pFile, TAOS_ROW row, TAOS_FIELD* fields taosFprintfFile(pFile, "\n"); } -static int32_t msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIndex) { +static int32_t data_msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIndex) { char buf[1024]; int32_t totalRows = 0; @@ -496,6 +497,52 @@ static int32_t msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIndex) return totalRows; } + +static int32_t meta_msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIndex) { + char buf[1024]; + int32_t totalRows = 0; + + // printf("topic: %s\n", tmq_get_topic_name(msg)); + int32_t vgroupId = tmq_get_vgroup_id(msg); + const char* dbName = tmq_get_db_name(msg); + + taosFprintfFile(g_fp, "consumerId: %d, msg index:%" PRId64 "\n", pInfo->consumerId, msgIndex); + taosFprintfFile(g_fp, "dbName: %s, topic: %s, vgroupId: %d\n", dbName != NULL ? dbName : "invalid table", + tmq_get_topic_name(msg), vgroupId); + + { + tmq_raw_data *raw = tmq_get_raw_meta(msg); + + if(raw){ + TAOS_RES* pRes = taos_query(pInfo->taos, "use metadb"); + if (taos_errno(pRes) != 0) { + pError("error when use metadb, reason:%s\n", taos_errstr(pRes)); + taosFprintfFile(g_fp, "error when use metadb, reason:%s\n", taos_errstr(pRes)); + taosCloseFile(&g_fp); + taos_free_result(pRes); + exit(-1); + } + taos_free_result(pRes); + taosFprintfFile(g_fp, "raw:%p\n", raw); + + int32_t ret = taos_write_raw_meta(pInfo->taos, raw); + taosMemoryFree(raw); + } + + char* result = tmq_get_json_meta(msg); + if(result){ + //printf("meta result: %s\n", result); + taosFprintfFile(pInfo->pConsumeMetaFile, "%s\n", result); + taosMemoryFree(result); + } + } + + totalRows++; + + return totalRows; +} + + int queryDB(TAOS* taos, char* command) { TAOS_RES* pRes = taos_query(taos, command); int code = taos_errno(pRes); @@ -526,7 +573,7 @@ int32_t notifyMainScript(SThreadInfo* pInfo, int32_t cmdId) { static int32_t g_once_commit_flag = 0; static void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) { - pError("tmq_commit_cb_print() commit %d\n", code); + taosFprintfFile(g_fp, "tmq_commit_cb_print() commit %d\n", code); if (0 == g_once_commit_flag) { g_once_commit_flag = 1; @@ -630,8 +677,12 @@ void loop_consume(SThreadInfo* pInfo) { // getCurrentTimeString(tmpString)); sprintf(filename, "%s/../log/consumerid_%d.txt", configDir, pInfo->consumerId); pInfo->pConsumeRowsFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); - if (pInfo->pConsumeRowsFile == NULL) { - taosFprintfFile(g_fp, "%s create file fail for save rows content\n", getCurrentTimeString(tmpString)); + + sprintf(filename, "%s/../log/meta_consumerid_%d.txt", configDir, pInfo->consumerId); + pInfo->pConsumeMetaFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + + if (pInfo->pConsumeRowsFile == NULL || pInfo->pConsumeMetaFile == NULL) { + taosFprintfFile(g_fp, "%s create file fail for save rows or save meta\n", getCurrentTimeString(tmpString)); return; } } @@ -645,7 +696,11 @@ void loop_consume(SThreadInfo* pInfo) { TAOS_RES* tmqMsg = tmq_consumer_poll(pInfo->tmq, consumeDelay); if (tmqMsg) { if (0 != g_stConfInfo.showMsgFlag) { - totalRows += msg_process(tmqMsg, pInfo, totalMsgs); + 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); } taos_free_result(tmqMsg);