diff --git a/cmake/cmake.define b/cmake/cmake.define index fb6ba8cc2e2703d17e45593a925fffdcbcb5bbb8..851d8f9a7325b0a2e21abf970893c0d0b1b9eff5 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -44,7 +44,6 @@ ENDIF () IF (TD_WINDOWS) MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}") - SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE) SET(COMMON_FLAGS "/W3 /D_WIN32") # IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index e797911adde33b1561e6d6094446dd28f0f1bc88..df69eb8aa1092dbb3730bdc64eaaf130c56aa32e 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -228,7 +228,7 @@ endif() # iconv if(${BUILD_WITH_ICONV}) - add_subdirectory(iconv EXCLUDE_FROM_ALL) + add_library(iconv STATIC iconv/win_iconv.c) endif(${BUILD_WITH_ICONV}) # wingetopt diff --git a/example/src/tmq.c b/example/src/tmq.c index 5b8f66f6665d91a04c418c9fb8978be0a81a7d8a..976d658fa6fc6557c11fde9e5c692fba801ab1f4 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -24,7 +24,7 @@ static void msg_process(TAOS_RES* msg) { char buf[1024]; memset(buf, 0, 1024); printf("topic: %s\n", tmq_get_topic_name(msg)); - printf("vg:%d\n", tmq_get_vgroup_id(msg)); + printf("vg: %d\n", tmq_get_vgroup_id(msg)); while (1) { TAOS_ROW row = taos_fetch_row(msg); if (row == NULL) break; @@ -140,8 +140,8 @@ int32_t create_topic() { return 0; } -void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets) { - printf("commit %d\n", resp); +void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets, void* param) { + printf("commit %d tmq %p offsets %p param %p\n", resp, tmq, offsets, param); } tmq_t* build_consumer() { @@ -161,7 +161,7 @@ tmq_t* build_consumer() { tmq_conf_set(conf, "td.connect.user", "root"); tmq_conf_set(conf, "td.connect.pass", "taosdata"); /*tmq_conf_set(conf, "td.connect.db", "abc1");*/ - tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print); + tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print, NULL); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); assert(tmq); return tmq; @@ -215,12 +215,24 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { return; } + tmq_list_t* subList = NULL; + tmq_subscription(tmq, &subList); + char** subTopics = tmq_list_to_c_array(subList); + int32_t sz = tmq_list_get_size(subList); + printf("subscribed topics: "); + for (int32_t i = 0; i < sz; i++) { + printf("%s, ", subTopics[i]); + } + printf("\n"); + tmq_list_destroy(subList); + while (running) { TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000); if (tmqmessage) { msg_process(tmqmessage); taos_free_result(tmqmessage); + tmq_commit(tmq, NULL, 1); /*if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0);*/ } } diff --git a/example/src/tstream.c b/example/src/tstream.c index 8ffa932bd29d6f89441c7f045611f42e058dd872..77a002499e0c2e6c3d2e2e1d6c23ab39ecc58b08 100644 --- a/example/src/tstream.c +++ b/example/src/tstream.c @@ -25,7 +25,7 @@ int32_t init_env() { return -1; } - TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); + TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); if (taos_errno(pRes) != 0) { printf("error in create db, reason:%s\n", taos_errstr(pRes)); return -1; @@ -78,11 +78,14 @@ int32_t create_stream() { taos_free_result(pRes); /*const char* sql = "select min(k), max(k), sum(k) from tu1";*/ - const char* sql = "select min(k), max(k), sum(k) as sum_of_k from st1"; + /*const char* sql = "select min(k), max(k), sum(k) as sum_of_k from st1";*/ /*const char* sql = "select sum(k) from tu1 interval(10m)";*/ - pRes = tmq_create_stream(pConn, "stream1", "out1", sql); + /*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/ + pRes = taos_query( + pConn, + "create stream stream1 trigger window_close as select min(k), max(k), sum(k) as sum_of_k from tu1 interval(10m)"); if (taos_errno(pRes) != 0) { - printf("failed to create stream out1, reason:%s\n", taos_errstr(pRes)); + printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes)); return -1; } taos_free_result(pRes); diff --git a/include/client/taos.h b/include/client/taos.h index 1ac92c61a57a9a7bcef10d03930de73466ecd8b4..6e209006681f2122a5a68ef890f9471adae61831 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -86,9 +86,9 @@ typedef struct taosField { } TAOS_FIELD; #ifdef WINDOWS - #define DLL_EXPORT __declspec(dllexport) +#define DLL_EXPORT __declspec(dllexport) #else - #define DLL_EXPORT +#define DLL_EXPORT #endif typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code); @@ -123,42 +123,42 @@ DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT setConfRet taos_set_config(const char *config); DLL_EXPORT int taos_init(void); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); -DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, +DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port); -DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); -DLL_EXPORT void taos_close(TAOS *taos); - -const char *taos_data_type(int type); - -DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); -DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); -DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags); -DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name); -DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name); - -DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); -DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); -DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); -DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); -DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); -DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); -DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); -DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); -DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt); - -DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); -DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen); - -DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); -DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result -DLL_EXPORT void taos_free_result(TAOS_RES *res); -DLL_EXPORT int taos_field_count(TAOS_RES *res); -DLL_EXPORT int taos_num_fields(TAOS_RES *res); -DLL_EXPORT int taos_affected_rows(TAOS_RES *res); +DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); +DLL_EXPORT void taos_close(TAOS *taos); + +const char *taos_data_type(int type); + +DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); +DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); +DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags); +DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name); +DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name); + +DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); +DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); +DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); +DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); +DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); +DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); +DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt); + +DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); +DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen); + +DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); +DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result +DLL_EXPORT void taos_free_result(TAOS_RES *res); +DLL_EXPORT int taos_field_count(TAOS_RES *res); +DLL_EXPORT int taos_num_fields(TAOS_RES *res); +DLL_EXPORT int taos_affected_rows(TAOS_RES *res); DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res); DLL_EXPORT int taos_select_db(TAOS *taos, const char *db); @@ -213,7 +213,7 @@ typedef struct tmq_topic_vgroup_list_t tmq_topic_vgroup_list_t; typedef struct tmq_conf_t tmq_conf_t; typedef struct tmq_list_t tmq_list_t; -typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *)); +typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *, void *param)); DLL_EXPORT tmq_list_t *tmq_list_new(); DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *); @@ -253,12 +253,12 @@ typedef enum tmq_conf_res_t tmq_conf_res_t; DLL_EXPORT tmq_conf_t *tmq_conf_new(); DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value); DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf); -DLL_EXPORT void tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb); +DLL_EXPORT void tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb, void *param); /* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */ -DLL_EXPORT char *tmq_get_topic_name(TAOS_RES *res); -DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); +DLL_EXPORT const char *tmq_get_topic_name(TAOS_RES *res); +DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); // TODO #if 0 DLL_EXPORT char *tmq_get_table_name(TAOS_RES *res); @@ -271,10 +271,8 @@ DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message); /* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */ #if 0 DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen); -#endif - DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql); - +#endif /* ------------------------------ TMQ END -------------------------------- */ #if 1 // Shuduo: temporary enable for app build typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code); diff --git a/include/common/systable.h b/include/common/systable.h new file mode 100644 index 0000000000000000000000000000000000000000..bd8aae998f9ab6a692b7c5793fbac0c58ae84eb7 --- /dev/null +++ b/include/common/systable.h @@ -0,0 +1,78 @@ +/* + * 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 . + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "os.h" + +#ifndef TDENGINE_SYSTABLE_H +#define TDENGINE_SYSTABLE_H + +#define TSDB_INFORMATION_SCHEMA_DB "information_schema" +#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" +#define TSDB_INS_TABLE_DNODES "dnodes" +#define TSDB_INS_TABLE_MNODES "mnodes" +#define TSDB_INS_TABLE_MODULES "modules" +#define TSDB_INS_TABLE_QNODES "qnodes" +#define TSDB_INS_TABLE_BNODES "bnodes" +#define TSDB_INS_TABLE_SNODES "snodes" +#define TSDB_INS_TABLE_CLUSTER "cluster" +#define TSDB_INS_TABLE_USER_DATABASES "user_databases" +#define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions" +#define TSDB_INS_TABLE_USER_INDEXES "user_indexes" +#define TSDB_INS_TABLE_USER_STABLES "user_stables" +#define TSDB_INS_TABLE_USER_STREAMS "user_streams" +#define TSDB_INS_TABLE_USER_TABLES "user_tables" +#define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed" +#define TSDB_INS_TABLE_USER_USERS "user_users" +#define TSDB_INS_TABLE_LICENCES "grants" +#define TSDB_INS_TABLE_VGROUPS "vgroups" +#define TSDB_INS_TABLE_VNODES "vnodes" +#define TSDB_INS_TABLE_CONFIGS "configs" + +#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" +#define TSDB_PERFS_TABLE_SMAS "smas" +#define TSDB_PERFS_TABLE_SUBSCRIBES "subscribes" +#define TSDB_PERFS_TABLE_CONNECTIONS "connections" +#define TSDB_PERFS_TABLE_QUERIES "queries" +#define TSDB_PERFS_TABLE_TOPICS "topics" +#define TSDB_PERFS_TABLE_CONSUMERS "consumers" +#define TSDB_PERFS_TABLE_SUBSCRIPTIONS "subscriptions" +#define TSDB_PERFS_TABLE_OFFSETS "offsets" +#define TSDB_PERFS_TABLE_TRANS "trans" +#define TSDB_PERFS_TABLE_STREAMS "streams" + +typedef struct SSysDbTableSchema { + const char *name; + const int32_t type; + const int32_t bytes; +} SSysDbTableSchema; + +typedef struct SSysTableMeta { + const char *name; + const SSysDbTableSchema *schema; + const int32_t colNum; +} SSysTableMeta; + +void getInfosDbMeta(const SSysTableMeta** pInfosTableMeta, size_t* size); +void getPerfDbMeta(const SSysTableMeta** pPerfsTableMeta, size_t* size); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_SYSTABLE_H diff --git a/include/common/taosdef.h b/include/common/taosdef.h index af8bda2593fdcd84533414176ee7084343f982aa..85d11be81755170b60d3e1b8c42d6a4ea9e305fd 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -71,17 +71,25 @@ typedef enum { TSDB_SMA_STAT_DROPPED = 2, // sma dropped } ETsdbSmaStat; // bit operation - typedef enum { TSDB_SMA_TYPE_BLOCK = 0, // Block-wise SMA TSDB_SMA_TYPE_TIME_RANGE = 1, // Time-range-wise SMA TSDB_SMA_TYPE_ROLLUP = 2, // Rollup SMA } ETsdbSmaType; +typedef enum { + TSDB_RSMA_RETENTION_0 = 0, + TSDB_RSMA_RETENTION_1 = 1, + TSDB_RSMA_RETENTION_2 = 2, + TSDB_RSMA_RETENTION_MAX = 3 +} ERSmaRetention; + extern char *qtypeStr[]; #define TSDB_PORT_HTTP 11 +#undef TD_DEBUG_PRINT_ROW + #ifdef __cplusplus } #endif diff --git a/include/common/tcommon.h b/include/common/tcommon.h index fa428a994a3bb2ebe9a3e90fd6dcfc1622fbd31a..c0eb53d8cab2def78719c938d99c4c293fd4f178 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -65,20 +65,18 @@ typedef struct SDataBlockInfo { STimeWindow window; int32_t rows; int32_t rowSize; - union { - int64_t uid; // from which table of uid, comes from this data block - int64_t blockId; - }; - uint64_t groupId; // no need to serialize - int16_t numOfCols; - int16_t hasVarCol; - int16_t capacity; + int64_t uid; // the uid of table, from which current data block comes + int64_t blockId; // block id, generated by physical planner + uint64_t groupId; // no need to serialize + int16_t numOfCols; + int16_t hasVarCol; + int16_t capacity; } SDataBlockInfo; typedef struct SSDataBlock { - SColumnDataAgg* pBlockAgg; - SArray* pDataBlock; // SArray - SDataBlockInfo info; + SColumnDataAgg** pBlockAgg; + SArray* pDataBlock; // SArray + SDataBlockInfo info; } SSDataBlock; typedef struct SVarColAttr { diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index a0f4351bbf725c23b8d9e9291fc6a04b5dfb0460..36286d5944be6eee78b37104be4dea27c4e05695 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -64,19 +64,19 @@ typedef struct { col_id_t colId; // column ID(start from PRIMARYKEY_TIMESTAMP_COL_ID(1)) int32_t type : 8; // column type int32_t bytes : 24; // column bytes (0~16M) - int32_t sma : 8; // block SMA: 0, no SMA, 1, sum/min/max, 2, ... + int32_t flags : 8; // flags: 0 no index, 1 SCHEMA_SMA_ON, 2 SCHEMA_IDX_ON int32_t offset : 24; // point offset in STpRow after the header part. } STColumn; #pragma pack(pop) #define colType(col) ((col)->type) -#define colSma(col) ((col)->sma) +#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 colSetSma(col, s) (colSma(col) = (s)) +#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)) @@ -146,7 +146,7 @@ typedef struct { int32_t tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder); void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version); -int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t sma, col_id_t colId, col_bytes_t bytes); +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 diff --git a/include/common/tmsg.h b/include/common/tmsg.h index fd7a843e7fbf02e291a01ce5cda4fbc4c555e5a4..7e049b1dd98ffc43e35828083d7f5c8987eecd0b 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -281,8 +281,10 @@ typedef struct SSchema { char name[TSDB_COL_NAME_LEN]; } SSchema; +#define IS_BSMA_ON(s) (((s)->flags & 0x01) == SCHEMA_SMA_ON) + #define SSCHMEA_TYPE(s) ((s)->type) -#define SSCHMEA_SMA(s) ((s)->sma) +#define SSCHMEA_FLAGS(s) ((s)->flags) #define SSCHMEA_COLID(s) ((s)->colId) #define SSCHMEA_BYTES(s) ((s)->bytes) #define SSCHMEA_NAME(s) ((s)->name) @@ -531,27 +533,24 @@ int32_t tDeserializeSQueryTableRsp(void* buf, int32_t bufLen, SQueryTableRsp* pR typedef struct { char db[TSDB_DB_FNAME_LEN]; int32_t numOfVgroups; - int32_t cacheBlockSize; // MB - int32_t totalBlocks; + int32_t numOfStables; // single_stable + int32_t buffer; // MB + int32_t pageSize; + int32_t pages; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; int32_t minRows; int32_t maxRows; - int32_t commitTime; int32_t fsyncPeriod; - int32_t ttl; int8_t walLevel; int8_t precision; // time resolution int8_t compression; int8_t replications; int8_t strict; - int8_t update; int8_t cacheLastRow; int8_t ignoreExist; - int8_t streamMode; - int8_t singleSTable; int32_t numOfRetensions; SArray* pRetensions; // SRetention } SCreateDbReq; @@ -562,7 +561,10 @@ void tFreeSCreateDbReq(SCreateDbReq* pReq); typedef struct { char db[TSDB_DB_FNAME_LEN]; - int32_t totalBlocks; + int32_t buffer; + int32_t pageSize; + int32_t pages; + int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; @@ -626,26 +628,23 @@ int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq); typedef struct { int32_t numOfVgroups; - int32_t cacheBlockSize; - int32_t totalBlocks; + int32_t numOfStables; + int32_t buffer; + int32_t pageSize; + int32_t pages; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; int32_t minRows; int32_t maxRows; - int32_t commitTime; int32_t fsyncPeriod; - int32_t ttl; int8_t walLevel; int8_t precision; int8_t compression; int8_t replications; int8_t strict; - int8_t update; int8_t cacheLastRow; - int8_t streamMode; - int8_t singleSTable; int32_t numOfRetensions; SArray* pRetensions; } SDbCfgRsp; @@ -845,15 +844,16 @@ typedef struct { char db[TSDB_DB_FNAME_LEN]; int64_t dbUid; int32_t vgVersion; - int32_t cacheBlockSize; - int32_t totalBlocks; + int32_t numOfStables; + int32_t buffer; + int32_t pageSize; + int32_t pages; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; int32_t minRows; int32_t maxRows; - int32_t commitTime; int32_t fsyncPeriod; uint32_t hashBegin; uint32_t hashEnd; @@ -862,11 +862,9 @@ typedef struct { int8_t precision; int8_t compression; int8_t strict; - int8_t update; int8_t cacheLastRow; int8_t replica; int8_t selfIndex; - int8_t streamMode; SReplica replicas[TSDB_MAX_REPLICA]; int32_t numOfRetensions; SArray* pRetensions; // SRetention @@ -896,10 +894,14 @@ int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq typedef struct { int32_t vgVersion; - int32_t totalBlocks; + int32_t buffer; + int32_t pageSize; + int32_t pages; + int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; + int32_t fsyncPeriod; int8_t walLevel; int8_t strict; int8_t cacheLastRow; @@ -954,7 +956,6 @@ typedef struct { int32_t numOfColumns; int8_t precision; int8_t tableType; - int8_t update; int32_t sversion; int32_t tversion; uint64_t suid; @@ -1039,6 +1040,7 @@ typedef struct { int8_t compressed; int32_t compLen; int32_t numOfRows; + int32_t numOfCols; char data[]; } SRetrieveTableRsp; @@ -1281,8 +1283,9 @@ typedef struct { #define STREAM_TRIGGER_WINDOW_CLOSE 2 typedef struct { - char name[TSDB_TOPIC_FNAME_LEN]; - char outputSTbName[TSDB_TABLE_FNAME_LEN]; + char name[TSDB_TABLE_FNAME_LEN]; + char sourceDB[TSDB_DB_FNAME_LEN]; + char targetStbFullName[TSDB_TABLE_FNAME_LEN]; int8_t igExists; char* sql; char* ast; @@ -1441,39 +1444,38 @@ typedef struct { SArray* lostConsumers; // SArray SArray* removedConsumers; // SArray SArray* newConsumers; // SArray -} SMqRebSubscribe; +} SMqRebInfo; -static FORCE_INLINE SMqRebSubscribe* tNewSMqRebSubscribe(const char* key) { - SMqRebSubscribe* pRebSub = (SMqRebSubscribe*)taosMemoryCalloc(1, sizeof(SMqRebSubscribe)); - if (pRebSub == NULL) { +static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) { + SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo)); + if (pRebInfo == NULL) { goto _err; } - strcpy(pRebSub->key, key); - pRebSub->lostConsumers = taosArrayInit(0, sizeof(int64_t)); - if (pRebSub->lostConsumers == NULL) { + strcpy(pRebInfo->key, key); + pRebInfo->lostConsumers = taosArrayInit(0, sizeof(int64_t)); + if (pRebInfo->lostConsumers == NULL) { goto _err; } - pRebSub->removedConsumers = taosArrayInit(0, sizeof(int64_t)); - if (pRebSub->removedConsumers == NULL) { + pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t)); + if (pRebInfo->removedConsumers == NULL) { goto _err; } - pRebSub->newConsumers = taosArrayInit(0, sizeof(int64_t)); - if (pRebSub->newConsumers == NULL) { + pRebInfo->newConsumers = taosArrayInit(0, sizeof(int64_t)); + if (pRebInfo->newConsumers == NULL) { goto _err; } - return pRebSub; + return pRebInfo; _err: - taosArrayDestroy(pRebSub->lostConsumers); - taosArrayDestroy(pRebSub->removedConsumers); - taosArrayDestroy(pRebSub->newConsumers); - taosMemoryFreeClear(pRebSub); + taosArrayDestroy(pRebInfo->lostConsumers); + taosArrayDestroy(pRebInfo->removedConsumers); + taosArrayDestroy(pRebInfo->newConsumers); + taosMemoryFreeClear(pRebInfo); return NULL; } // this message is sent from mnode to mnode(read thread to write thread), so there is no need for serialization or // deserialization typedef struct { - int8_t* mqInReb; SHashObj* rebSubHash; // SHashObj } SMqDoRebalanceMsg; @@ -1521,9 +1523,10 @@ typedef struct { char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2 } SRSmaParam; -int tEncodeSRSmaParam(SCoder* pCoder, const SRSmaParam* pRSmaParam); -int tDecodeSRSmaParam(SCoder* pCoder, SRSmaParam* pRSmaParam); +int32_t tEncodeSRSmaParam(SCoder* pCoder, const SRSmaParam* pRSmaParam); +int32_t tDecodeSRSmaParam(SCoder* pCoder, SRSmaParam* pRSmaParam); +// TDMT_VND_CREATE_STB ============== typedef struct SVCreateStbReq { const char* name; tb_uid_t suid; @@ -1536,17 +1539,14 @@ typedef struct SVCreateStbReq { int tEncodeSVCreateStbReq(SCoder* pCoder, const SVCreateStbReq* pReq); int tDecodeSVCreateStbReq(SCoder* pCoder, SVCreateStbReq* pReq); +// TDMT_VND_DROP_STB ============== typedef struct SVDropStbReq { - // data -#ifdef WINDOWS - size_t avoidCompilationErrors; -#endif - + const char* name; + tb_uid_t suid; } SVDropStbReq; -typedef struct SVCreateStbRsp { - int code; -} SVCreateStbRsp; +int32_t tEncodeSVDropStbReq(SCoder* pCoder, const SVDropStbReq* pReq); +int32_t tDecodeSVDropStbReq(SCoder* pCoder, SVDropStbReq* pReq); typedef struct SVCreateTbReq { tb_uid_t uid; @@ -1603,19 +1603,37 @@ int tDecodeSVCreateTbBatchRsp(SCoder* pCoder, SVCreateTbBatchRsp* pRsp); int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp); int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp); +// TDMT_VND_DROP_TABLE ================= typedef struct { - int64_t ver; - char* name; - uint8_t type; - tb_uid_t suid; + const char* name; + int8_t igNotExists; } SVDropTbReq; typedef struct { - int tmp; // TODO: to avoid compile error + int32_t code; } SVDropTbRsp; -int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq); -void* tDeserializeSVDropTbReq(void* buf, SVDropTbReq* pReq); +typedef struct { + int32_t nReqs; + union { + SVDropTbReq* pReqs; + SArray* pArray; + }; +} SVDropTbBatchReq; + +int32_t tEncodeSVDropTbBatchReq(SCoder* pCoder, const SVDropTbBatchReq* pReq); +int32_t tDecodeSVDropTbBatchReq(SCoder* pCoder, SVDropTbBatchReq* pReq); + +typedef struct { + int32_t nRsps; + union { + SVDropTbRsp* pRsps; + SArray* pArray; + }; +} SVDropTbBatchRsp; + +int32_t tEncodeSVDropTbBatchRsp(SCoder* pCoder, const SVDropTbBatchRsp* pRsp); +int32_t tDecodeSVDropTbBatchRsp(SCoder* pCoder, SVDropTbBatchRsp* pRsp); typedef struct { SMsgHead head; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index e1ee946ce4e0678d35a809304429a5d5d7d57b90..b0439c722cb187da01ea5e14f451a3d11e1d17d1 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -170,9 +170,9 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_UPDATE_TAG_VAL, "vnode-update-tag-val", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_TABLE_META, "vnode-table-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_TABLES_META, "vnode-tables-meta", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateTbReq, SVCreateTbRsp) + TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL) TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONSUME, "vnode-mq-consume", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_MQ_QUERY, "vnode-mq-query", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONNECT, "vnode-mq-connect", NULL, NULL) diff --git a/include/common/trow.h b/include/common/trow.h index 8732497dbb7bd585be4c1268fc5876f0a14fc737..02f84b372eee03182ba9bfdaf83740ad05332b19 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -214,6 +214,16 @@ STSRow *tdRowDup(STSRow *row); static FORCE_INLINE SKvRowIdx *tdKvRowColIdxAt(STSRow *pRow, col_id_t idx) { return (SKvRowIdx *)TD_ROW_COL_IDX(pRow) + idx; } + +static FORCE_INLINE int16_t tdKvRowColIdAt(STSRow *pRow, col_id_t idx) { + ASSERT(idx >= 0); + if (idx == 0) { + return PRIMARYKEY_TIMESTAMP_COL_ID; + } + + return ((SKvRowIdx *)TD_ROW_COL_IDX(pRow) + idx - 1)->colId; +} + static FORCE_INLINE void *tdKVRowColVal(STSRow *pRow, SKvRowIdx *pIdx) { return POINTER_SHIFT(pRow, pIdx->offset); } #define TD_ROW_OFFSET(p) ((p)->toffset); // During ParseInsert when without STSchema, how to get the offset for STpRow? @@ -585,6 +595,34 @@ static FORCE_INLINE int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, return TSDB_CODE_SUCCESS; } +/** + * @brief + * + * @param pBuilder + * @param nCols + * @param nBoundCols use -1 if not available + * @param flen + * @return FORCE_INLINE + */ +static FORCE_INLINE int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t flen) { + pBuilder->flen = flen; + pBuilder->nCols = nCols; + if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) { + TASSERT(0); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } +#ifdef TD_SUPPORT_BITMAP + // the primary TS key is stored separatedly + pBuilder->nBitmaps = (int16_t)TD_BITMAP_BYTES(pBuilder->nCols - 1); +#else + pBuilder->nBitmaps = 0; + pBuilder->nBoundBitmaps = 0; +#endif + return TSDB_CODE_SUCCESS; +} + + /** * @brief To judge row type: STpRow/SKvRow * @@ -668,7 +706,7 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { case TD_ROW_KV: #ifdef TD_SUPPORT_BITMAP pBuilder->pBitmap = tdGetBitmapAddrKv(pBuilder->pBuf, pBuilder->nBoundCols); - memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps); + memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBoundBitmaps); #endif len = TD_ROW_HEAD_LEN + TD_ROW_NCOLS_LEN + (pBuilder->nBoundCols - 1) * sizeof(SKvRowIdx) + pBuilder->nBoundBitmaps; // add @@ -1092,7 +1130,7 @@ static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, STSRow *pRow = pIter->pRow; SKvRowIdx *pKvIdx = NULL; bool colFound = false; - col_id_t kvNCols = tdRowGetNCols(pRow); + col_id_t kvNCols = tdRowGetNCols(pRow) - 1; while (*nIdx < kvNCols) { pKvIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(pRow), *nIdx * sizeof(SKvRowIdx)); if (pKvIdx->colId == colId) { @@ -1108,7 +1146,14 @@ static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, } } - if (!colFound) return false; + if (!colFound) { + if (colId <= pIter->maxColId) { + pVal->valType = TD_VTYPE_NONE; + return true; + } else { + return false; + } + } #ifdef TD_SUPPORT_BITMAP int16_t colIdx = -1; @@ -1352,11 +1397,11 @@ static void tdSCellValPrint(SCellVal *pVal, int8_t colType) { } } -static void tdSRowPrint(STSRow *row, STSchema *pSchema) { +static void tdSRowPrint(STSRow *row, STSchema *pSchema, const char* tag) { STSRowIter iter = {0}; tdSTSRowIterInit(&iter, pSchema); tdSTSRowIterReset(&iter, row); - printf(">>>"); + printf("%s >>>", tag); for (int i = 0; i < pSchema->numOfCols; ++i) { STColumn *stCol = pSchema->columns + i; SCellVal sVal = { 255, NULL}; @@ -1368,7 +1413,6 @@ static void tdSRowPrint(STSRow *row, STSchema *pSchema) { } printf("\n"); } - #ifdef TROW_ORIGIN_HZ typedef struct { uint32_t nRows; diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 50be63dd56d524b252beca5dbdcec362aa22b505..5c24617369ebea06cd277210b2294f5778318008 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -16,244 +16,244 @@ #ifndef _TD_COMMON_TOKEN_H_ #define _TD_COMMON_TOKEN_H_ -#define TK_OR 1 -#define TK_AND 2 -#define TK_UNION 3 -#define TK_ALL 4 -#define TK_MINUS 5 -#define TK_EXCEPT 6 -#define TK_INTERSECT 7 -#define TK_NK_BITAND 8 -#define TK_NK_BITOR 9 -#define TK_NK_LSHIFT 10 -#define TK_NK_RSHIFT 11 -#define TK_NK_PLUS 12 -#define TK_NK_MINUS 13 -#define TK_NK_STAR 14 -#define TK_NK_SLASH 15 -#define TK_NK_REM 16 -#define TK_NK_CONCAT 17 -#define TK_CREATE 18 -#define TK_ACCOUNT 19 -#define TK_NK_ID 20 -#define TK_PASS 21 -#define TK_NK_STRING 22 -#define TK_ALTER 23 -#define TK_PPS 24 -#define TK_TSERIES 25 -#define TK_STORAGE 26 -#define TK_STREAMS 27 -#define TK_QTIME 28 -#define TK_DBS 29 -#define TK_USERS 30 -#define TK_CONNS 31 -#define TK_STATE 32 -#define TK_USER 33 -#define TK_PRIVILEGE 34 -#define TK_DROP 35 -#define TK_DNODE 36 -#define TK_PORT 37 -#define TK_NK_INTEGER 38 -#define TK_DNODES 39 -#define TK_NK_IPTOKEN 40 -#define TK_LOCAL 41 -#define TK_QNODE 42 -#define TK_ON 43 -#define TK_BNODE 44 -#define TK_SNODE 45 -#define TK_MNODE 46 -#define TK_DATABASE 47 -#define TK_USE 48 -#define TK_IF 49 -#define TK_NOT 50 -#define TK_EXISTS 51 -#define TK_BLOCKS 52 -#define TK_CACHE 53 -#define TK_CACHELAST 54 -#define TK_COMP 55 -#define TK_DAYS 56 -#define TK_NK_VARIABLE 57 -#define TK_FSYNC 58 -#define TK_MAXROWS 59 -#define TK_MINROWS 60 -#define TK_KEEP 61 -#define TK_PRECISION 62 -#define TK_QUORUM 63 -#define TK_REPLICA 64 -#define TK_TTL 65 -#define TK_WAL 66 -#define TK_VGROUPS 67 -#define TK_SINGLE_STABLE 68 -#define TK_STREAM_MODE 69 -#define TK_RETENTIONS 70 -#define TK_STRICT 71 -#define TK_NK_COMMA 72 -#define TK_NK_COLON 73 -#define TK_TABLE 74 -#define TK_NK_LP 75 -#define TK_NK_RP 76 -#define TK_STABLE 77 -#define TK_ADD 78 -#define TK_COLUMN 79 -#define TK_MODIFY 80 -#define TK_RENAME 81 -#define TK_TAG 82 -#define TK_SET 83 -#define TK_NK_EQ 84 -#define TK_USING 85 -#define TK_TAGS 86 -#define TK_NK_DOT 87 -#define TK_COMMENT 88 -#define TK_BOOL 89 -#define TK_TINYINT 90 -#define TK_SMALLINT 91 -#define TK_INT 92 -#define TK_INTEGER 93 -#define TK_BIGINT 94 -#define TK_FLOAT 95 -#define TK_DOUBLE 96 -#define TK_BINARY 97 -#define TK_TIMESTAMP 98 -#define TK_NCHAR 99 -#define TK_UNSIGNED 100 -#define TK_JSON 101 -#define TK_VARCHAR 102 -#define TK_MEDIUMBLOB 103 -#define TK_BLOB 104 -#define TK_VARBINARY 105 -#define TK_DECIMAL 106 -#define TK_SMA 107 -#define TK_ROLLUP 108 -#define TK_FILE_FACTOR 109 -#define TK_NK_FLOAT 110 -#define TK_DELAY 111 -#define TK_SHOW 112 -#define TK_DATABASES 113 -#define TK_TABLES 114 -#define TK_STABLES 115 -#define TK_MNODES 116 -#define TK_MODULES 117 -#define TK_QNODES 118 -#define TK_FUNCTIONS 119 -#define TK_INDEXES 120 -#define TK_FROM 121 -#define TK_ACCOUNTS 122 -#define TK_APPS 123 -#define TK_CONNECTIONS 124 -#define TK_LICENCE 125 -#define TK_GRANTS 126 -#define TK_QUERIES 127 -#define TK_SCORES 128 -#define TK_TOPICS 129 -#define TK_VARIABLES 130 -#define TK_BNODES 131 -#define TK_SNODES 132 -#define TK_CLUSTER 133 -#define TK_LIKE 134 -#define TK_INDEX 135 -#define TK_FULLTEXT 136 -#define TK_FUNCTION 137 -#define TK_INTERVAL 138 -#define TK_TOPIC 139 -#define TK_AS 140 -#define TK_WITH 141 -#define TK_SCHEMA 142 -#define TK_DESC 143 -#define TK_DESCRIBE 144 -#define TK_RESET 145 -#define TK_QUERY 146 -#define TK_EXPLAIN 147 -#define TK_ANALYZE 148 -#define TK_VERBOSE 149 -#define TK_NK_BOOL 150 -#define TK_RATIO 151 -#define TK_COMPACT 152 -#define TK_VNODES 153 -#define TK_IN 154 -#define TK_OUTPUTTYPE 155 -#define TK_AGGREGATE 156 -#define TK_BUFSIZE 157 -#define TK_STREAM 158 -#define TK_INTO 159 -#define TK_TRIGGER 160 -#define TK_AT_ONCE 161 -#define TK_WINDOW_CLOSE 162 -#define TK_WATERMARK 163 -#define TK_KILL 164 -#define TK_CONNECTION 165 -#define TK_MERGE 166 -#define TK_VGROUP 167 -#define TK_REDISTRIBUTE 168 -#define TK_SPLIT 169 -#define TK_SYNCDB 170 -#define TK_NULL 171 -#define TK_NK_QUESTION 172 -#define TK_NK_ARROW 173 -#define TK_ROWTS 174 -#define TK_TBNAME 175 -#define TK_QSTARTTS 176 -#define TK_QENDTS 177 -#define TK_WSTARTTS 178 -#define TK_WENDTS 179 -#define TK_WDURATION 180 -#define TK_CAST 181 -#define TK_NOW 182 -#define TK_TODAY 183 -#define TK_TIMEZONE 184 -#define TK_COUNT 185 -#define TK_FIRST 186 -#define TK_LAST 187 -#define TK_LAST_ROW 188 -#define TK_BETWEEN 189 -#define TK_IS 190 -#define TK_NK_LT 191 -#define TK_NK_GT 192 -#define TK_NK_LE 193 -#define TK_NK_GE 194 -#define TK_NK_NE 195 -#define TK_MATCH 196 -#define TK_NMATCH 197 -#define TK_CONTAINS 198 -#define TK_JOIN 199 -#define TK_INNER 200 -#define TK_SELECT 201 -#define TK_DISTINCT 202 -#define TK_WHERE 203 -#define TK_PARTITION 204 -#define TK_BY 205 -#define TK_SESSION 206 -#define TK_STATE_WINDOW 207 -#define TK_SLIDING 208 -#define TK_FILL 209 -#define TK_VALUE 210 -#define TK_NONE 211 -#define TK_PREV 212 -#define TK_LINEAR 213 -#define TK_NEXT 214 -#define TK_GROUP 215 -#define TK_HAVING 216 -#define TK_ORDER 217 -#define TK_SLIMIT 218 -#define TK_SOFFSET 219 -#define TK_LIMIT 220 -#define TK_OFFSET 221 -#define TK_ASC 222 -#define TK_NULLS 223 -#define TK_ID 224 -#define TK_NK_BITNOT 225 -#define TK_INSERT 226 -#define TK_VALUES 227 -#define TK_IMPORT 228 -#define TK_NK_SEMI 229 -#define TK_FILE 230 +#define TK_OR 1 +#define TK_AND 2 +#define TK_UNION 3 +#define TK_ALL 4 +#define TK_MINUS 5 +#define TK_EXCEPT 6 +#define TK_INTERSECT 7 +#define TK_NK_BITAND 8 +#define TK_NK_BITOR 9 +#define TK_NK_LSHIFT 10 +#define TK_NK_RSHIFT 11 +#define TK_NK_PLUS 12 +#define TK_NK_MINUS 13 +#define TK_NK_STAR 14 +#define TK_NK_SLASH 15 +#define TK_NK_REM 16 +#define TK_NK_CONCAT 17 +#define TK_CREATE 18 +#define TK_ACCOUNT 19 +#define TK_NK_ID 20 +#define TK_PASS 21 +#define TK_NK_STRING 22 +#define TK_ALTER 23 +#define TK_PPS 24 +#define TK_TSERIES 25 +#define TK_STORAGE 26 +#define TK_STREAMS 27 +#define TK_QTIME 28 +#define TK_DBS 29 +#define TK_USERS 30 +#define TK_CONNS 31 +#define TK_STATE 32 +#define TK_USER 33 +#define TK_PRIVILEGE 34 +#define TK_DROP 35 +#define TK_DNODE 36 +#define TK_PORT 37 +#define TK_NK_INTEGER 38 +#define TK_DNODES 39 +#define TK_NK_IPTOKEN 40 +#define TK_LOCAL 41 +#define TK_QNODE 42 +#define TK_ON 43 +#define TK_BNODE 44 +#define TK_SNODE 45 +#define TK_MNODE 46 +#define TK_DATABASE 47 +#define TK_USE 48 +#define TK_IF 49 +#define TK_NOT 50 +#define TK_EXISTS 51 +#define TK_BUFFER 52 +#define TK_CACHELAST 53 +#define TK_COMP 54 +#define TK_DAYS 55 +#define TK_NK_VARIABLE 56 +#define TK_FSYNC 57 +#define TK_MAXROWS 58 +#define TK_MINROWS 59 +#define TK_KEEP 60 +#define TK_PAGES 61 +#define TK_PAGESIZE 62 +#define TK_PRECISION 63 +#define TK_REPLICA 64 +#define TK_STRICT 65 +#define TK_WAL 66 +#define TK_VGROUPS 67 +#define TK_SINGLE_STABLE 68 +#define TK_RETENTIONS 69 +#define TK_NK_COMMA 70 +#define TK_NK_COLON 71 +#define TK_TABLE 72 +#define TK_NK_LP 73 +#define TK_NK_RP 74 +#define TK_STABLE 75 +#define TK_ADD 76 +#define TK_COLUMN 77 +#define TK_MODIFY 78 +#define TK_RENAME 79 +#define TK_TAG 80 +#define TK_SET 81 +#define TK_NK_EQ 82 +#define TK_USING 83 +#define TK_TAGS 84 +#define TK_NK_DOT 85 +#define TK_COMMENT 86 +#define TK_BOOL 87 +#define TK_TINYINT 88 +#define TK_SMALLINT 89 +#define TK_INT 90 +#define TK_INTEGER 91 +#define TK_BIGINT 92 +#define TK_FLOAT 93 +#define TK_DOUBLE 94 +#define TK_BINARY 95 +#define TK_TIMESTAMP 96 +#define TK_NCHAR 97 +#define TK_UNSIGNED 98 +#define TK_JSON 99 +#define TK_VARCHAR 100 +#define TK_MEDIUMBLOB 101 +#define TK_BLOB 102 +#define TK_VARBINARY 103 +#define TK_DECIMAL 104 +#define TK_DELAY 105 +#define TK_FILE_FACTOR 106 +#define TK_NK_FLOAT 107 +#define TK_ROLLUP 108 +#define TK_TTL 109 +#define TK_SMA 110 +#define TK_SHOW 111 +#define TK_DATABASES 112 +#define TK_TABLES 113 +#define TK_STABLES 114 +#define TK_MNODES 115 +#define TK_MODULES 116 +#define TK_QNODES 117 +#define TK_FUNCTIONS 118 +#define TK_INDEXES 119 +#define TK_FROM 120 +#define TK_ACCOUNTS 121 +#define TK_APPS 122 +#define TK_CONNECTIONS 123 +#define TK_LICENCE 124 +#define TK_GRANTS 125 +#define TK_QUERIES 126 +#define TK_SCORES 127 +#define TK_TOPICS 128 +#define TK_VARIABLES 129 +#define TK_BNODES 130 +#define TK_SNODES 131 +#define TK_CLUSTER 132 +#define TK_LIKE 133 +#define TK_INDEX 134 +#define TK_FULLTEXT 135 +#define TK_FUNCTION 136 +#define TK_INTERVAL 137 +#define TK_TOPIC 138 +#define TK_AS 139 +#define TK_WITH 140 +#define TK_SCHEMA 141 +#define TK_DESC 142 +#define TK_DESCRIBE 143 +#define TK_RESET 144 +#define TK_QUERY 145 +#define TK_CACHE 146 +#define TK_EXPLAIN 147 +#define TK_ANALYZE 148 +#define TK_VERBOSE 149 +#define TK_NK_BOOL 150 +#define TK_RATIO 151 +#define TK_COMPACT 152 +#define TK_VNODES 153 +#define TK_IN 154 +#define TK_OUTPUTTYPE 155 +#define TK_AGGREGATE 156 +#define TK_BUFSIZE 157 +#define TK_STREAM 158 +#define TK_INTO 159 +#define TK_TRIGGER 160 +#define TK_AT_ONCE 161 +#define TK_WINDOW_CLOSE 162 +#define TK_WATERMARK 163 +#define TK_KILL 164 +#define TK_CONNECTION 165 +#define TK_MERGE 166 +#define TK_VGROUP 167 +#define TK_REDISTRIBUTE 168 +#define TK_SPLIT 169 +#define TK_SYNCDB 170 +#define TK_NULL 171 +#define TK_NK_QUESTION 172 +#define TK_NK_ARROW 173 +#define TK_ROWTS 174 +#define TK_TBNAME 175 +#define TK_QSTARTTS 176 +#define TK_QENDTS 177 +#define TK_WSTARTTS 178 +#define TK_WENDTS 179 +#define TK_WDURATION 180 +#define TK_CAST 181 +#define TK_NOW 182 +#define TK_TODAY 183 +#define TK_TIMEZONE 184 +#define TK_COUNT 185 +#define TK_FIRST 186 +#define TK_LAST 187 +#define TK_LAST_ROW 188 +#define TK_BETWEEN 189 +#define TK_IS 190 +#define TK_NK_LT 191 +#define TK_NK_GT 192 +#define TK_NK_LE 193 +#define TK_NK_GE 194 +#define TK_NK_NE 195 +#define TK_MATCH 196 +#define TK_NMATCH 197 +#define TK_CONTAINS 198 +#define TK_JOIN 199 +#define TK_INNER 200 +#define TK_SELECT 201 +#define TK_DISTINCT 202 +#define TK_WHERE 203 +#define TK_PARTITION 204 +#define TK_BY 205 +#define TK_SESSION 206 +#define TK_STATE_WINDOW 207 +#define TK_SLIDING 208 +#define TK_FILL 209 +#define TK_VALUE 210 +#define TK_NONE 211 +#define TK_PREV 212 +#define TK_LINEAR 213 +#define TK_NEXT 214 +#define TK_GROUP 215 +#define TK_HAVING 216 +#define TK_ORDER 217 +#define TK_SLIMIT 218 +#define TK_SOFFSET 219 +#define TK_LIMIT 220 +#define TK_OFFSET 221 +#define TK_ASC 222 +#define TK_NULLS 223 +#define TK_ID 224 +#define TK_NK_BITNOT 225 +#define TK_INSERT 226 +#define TK_VALUES 227 +#define TK_IMPORT 228 +#define TK_NK_SEMI 229 +#define TK_FILE 230 -#define TK_NK_SPACE 300 -#define TK_NK_COMMENT 301 -#define TK_NK_ILLEGAL 302 -#define TK_NK_HEX 303 // hex number 0x123 -#define TK_NK_OCT 304 // oct number -#define TK_NK_BIN 305 // bin format data 0b111 +#define TK_NK_SPACE 300 +#define TK_NK_COMMENT 301 +#define TK_NK_ILLEGAL 302 +#define TK_NK_HEX 303 // hex number 0x123 +#define TK_NK_OCT 304 // oct number +#define TK_NK_BIN 305 // bin format data 0b111 -#define TK_NK_NIL 65535 +#define TK_NK_NIL 65535 #endif /*_TD_COMMON_TOKEN_H_*/ diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 1613339d10d83d898c4f467556554c81221414ca..a56c6ca16dc785a14845d64f1ee897023f72d366 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -107,10 +107,9 @@ typedef enum { typedef enum { SDB_STATUS_INIT = 0, SDB_STATUS_CREATING = 1, - SDB_STATUS_UPDATING = 2, - SDB_STATUS_DROPPING = 3, + SDB_STATUS_DROPPING = 2, + SDB_STATUS_DROPPED = 3, SDB_STATUS_READY = 4, - SDB_STATUS_DROPPED = 5 } ESdbStatus; typedef enum { @@ -331,7 +330,6 @@ int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver); int32_t sdbGetRawTotalSize(SSdbRaw *pRaw); SSdbRow *sdbAllocRow(int32_t objSize); -void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc); void *sdbGetRowObj(SSdbRow *pRow); typedef struct SSdb { diff --git a/include/libs/executor/dataSinkMgt.h b/include/libs/executor/dataSinkMgt.h index 293e7ae52f55d72ff4b6af8166c8f84d6eb37f97..339743f153968a2ae6910ac68735bbf295925041 100644 --- a/include/libs/executor/dataSinkMgt.h +++ b/include/libs/executor/dataSinkMgt.h @@ -45,6 +45,7 @@ typedef struct SInputData { typedef struct SOutputData { int32_t numOfRows; + int32_t numOfCols; int8_t compressed; char* pData; bool queryEnd; diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 0cd1a9265da36d1f65e0c312fdf06342e34b8cd5..ad57cbf4e4a9b5afb67a3954ed29c19546ea1064 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -33,6 +33,7 @@ typedef struct SReadHandle { void* meta; void* config; void* vnode; + void* mnd; } SReadHandle; #define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1 diff --git a/include/libs/function/function.h b/include/libs/function/function.h index ec0d644aba1827790655e0a71c7303a18b035ea5..347303a051b29b48aedf154bcfd1cc2817fedb31 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -165,7 +165,7 @@ typedef struct SInputColumnInfoData { SColumnInfoData *pPTS; // primary timestamp column SColumnInfoData **pData; SColumnDataAgg **pColumnDataAgg; - uint64_t uid; // table uid + uint64_t uid; // table uid, used to set the tag value when building the final query result for selectivity functions. } SInputColumnInfoData; // sql function runtime context @@ -206,6 +206,8 @@ typedef struct SqlFunctionCtx { struct SDiskbasedBuf *pBuf; struct SSDataBlock *pSrcBlock; int32_t curBufPage; + + char udfName[TSDB_FUNC_NAME_LEN]; } SqlFunctionCtx; enum { @@ -334,8 +336,6 @@ int32_t udfcOpen(); */ int32_t udfcClose(); -typedef void *UdfcFuncHandle; - #ifdef __cplusplus } #endif diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 126a2ccf99c02daf1360d6fa551e3ed38726de77..f6304401fc0656ddab63302ca4aaace7d09180fc 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -40,6 +40,7 @@ typedef enum EFunctionType { FUNCTION_TYPE_STDDEV, FUNCTION_TYPE_SUM, FUNCTION_TYPE_TWA, + FUNCTION_TYPE_HISTOGRAM, // nonstandard SQL function FUNCTION_TYPE_BOTTOM = 500, @@ -162,6 +163,7 @@ EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet); int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet); +int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet); #ifdef __cplusplus } diff --git a/source/libs/function/inc/tudf.h b/include/libs/function/tudf.h similarity index 85% rename from source/libs/function/inc/tudf.h rename to include/libs/function/tudf.h index b72905b87210c21dbef2d8944f283e09f94a2382..e49f5cac45d1563b620004f106fad51481483039 100644 --- a/source/libs/function/inc/tudf.h +++ b/include/libs/function/tudf.h @@ -42,8 +42,7 @@ enum { UDFC_CODE_INVALID_STATE = -5 }; - - +typedef void *UdfcFuncHandle; /** * setup udf @@ -95,6 +94,7 @@ typedef struct SUdfDataBlock { typedef struct SUdfInterBuf { int32_t bufLen; char* buf; + int8_t numOfResult; //zero or one } SUdfInterBuf; // output: interBuf @@ -118,6 +118,10 @@ int32_t callUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t nu */ int32_t teardownUdf(UdfcFuncHandle handle); +bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); +int32_t udfAggProcess(struct SqlFunctionCtx *pCtx); +int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock); // end API to taosd and qworker //============================================================================================================================= // begin API to UDF writer. @@ -133,11 +137,11 @@ typedef int32_t (*TUdfTeardownFunc)(); //typedef int32_t addVariableLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t dataLen, char * data); typedef int32_t (*TUdfFreeUdfColumnFunc)(SUdfColumn* column); +typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock* block, SUdfColumn *resultCol); -typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock block, SUdfColumn *resultCol); -typedef int32_t (*TUdfAggInitFunc)(SUdfInterBuf *buf); -typedef int32_t (*TUdfAggProcessFunc)(SUdfDataBlock block, SUdfInterBuf *interBuf); -typedef int32_t (*TUdfAggFinalizeFunc)(SUdfInterBuf buf, SUdfInterBuf *resultData); +typedef int32_t (*TUdfAggStartFunc)(SUdfInterBuf *buf); +typedef int32_t (*TUdfAggProcessFunc)(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf); +typedef int32_t (*TUdfAggFinishFunc)(SUdfInterBuf* buf, SUdfInterBuf *resultData); // end API to UDF writer diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 44ff73c8bbad88f6f75e5c6a6083edce4d8b553b..22e2de9c266dcfc2a0b1883916e751fd9d2ef50d 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -23,294 +23,291 @@ extern "C" { #include "query.h" #include "querynodes.h" -#define DESCRIBE_RESULT_COLS 4 +#define DESCRIBE_RESULT_COLS 4 #define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE) -#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE) -#define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE) +#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE) +#define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE) typedef struct SDatabaseOptions { - ENodeType type; - SValueNode* pNumOfBlocks; - SValueNode* pCacheBlockSize; - SValueNode* pCachelast; - SValueNode* pCompressionLevel; + ENodeType type; + int32_t buffer; + int8_t cachelast; + int8_t compressionLevel; + int32_t daysPerFile; SValueNode* pDaysPerFile; - SValueNode* pFsyncPeriod; - SValueNode* pMaxRowsPerBlock; - SValueNode* pMinRowsPerBlock; - SNodeList* pKeep; - SValueNode* pPrecision; - SValueNode* pQuorum; - SValueNode* pReplica; - SValueNode* pTtl; - SValueNode* pWalLevel; - SValueNode* pNumOfVgroups; - SValueNode* pSingleStable; - SValueNode* pStreamMode; - SValueNode* pStrict; - SNodeList* pRetentions; + int32_t fsyncPeriod; + int32_t maxRowsPerBlock; + int32_t minRowsPerBlock; + SNodeList* pKeep; + int32_t keep[3]; + int32_t pages; + int32_t pagesize; + char precisionStr[3]; + int8_t precision; + int8_t replica; + int8_t strict; + int8_t walLevel; + int32_t numOfVgroups; + int8_t singleStable; + SNodeList* pRetentions; } SDatabaseOptions; typedef struct SCreateDatabaseStmt { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - bool ignoreExists; + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + bool ignoreExists; SDatabaseOptions* pOptions; } SCreateDatabaseStmt; typedef struct SUseDatabaseStmt { ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; + char dbName[TSDB_DB_NAME_LEN]; } SUseDatabaseStmt; typedef struct SDropDatabaseStmt { ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - bool ignoreNotExists; + char dbName[TSDB_DB_NAME_LEN]; + bool ignoreNotExists; } SDropDatabaseStmt; typedef struct SAlterDatabaseStmt { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; SDatabaseOptions* pOptions; } SAlterDatabaseStmt; typedef struct STableOptions { - ENodeType type; - SNodeList* pKeep; - SValueNode* pTtl; - SValueNode* pComments; + ENodeType type; + char comment[TSDB_STB_COMMENT_LEN]; + int32_t delay; + float filesFactor; + SNodeList* pRollupFuncs; + int32_t ttl; SNodeList* pSma; - SNodeList* pFuncs; - SValueNode* pFilesFactor; - SValueNode* pDelay; } STableOptions; typedef struct SColumnDefNode { ENodeType type; - char colName[TSDB_COL_NAME_LEN]; + char colName[TSDB_COL_NAME_LEN]; SDataType dataType; - char comments[TSDB_STB_COMMENT_LEN]; - bool sma; + char comments[TSDB_STB_COMMENT_LEN]; + bool sma; } SColumnDefNode; typedef struct SCreateTableStmt { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - bool ignoreExists; - SNodeList* pCols; - SNodeList* pTags; + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + bool ignoreExists; + SNodeList* pCols; + SNodeList* pTags; STableOptions* pOptions; } SCreateTableStmt; typedef struct SCreateSubTableClause { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - char useDbName[TSDB_DB_NAME_LEN]; - char useTableName[TSDB_TABLE_NAME_LEN]; - bool ignoreExists; + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + char useDbName[TSDB_DB_NAME_LEN]; + char useTableName[TSDB_TABLE_NAME_LEN]; + bool ignoreExists; SNodeList* pSpecificTags; SNodeList* pValsOfTags; } SCreateSubTableClause; typedef struct SCreateMultiTableStmt { - ENodeType type; + ENodeType type; SNodeList* pSubTables; } SCreateMultiTableStmt; typedef struct SDropTableClause { ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - bool ignoreNotExists; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + bool ignoreNotExists; } SDropTableClause; typedef struct SDropTableStmt { - ENodeType type; + ENodeType type; SNodeList* pTables; } SDropTableStmt; typedef struct SDropSuperTableStmt { ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - bool ignoreNotExists; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + bool ignoreNotExists; } SDropSuperTableStmt; typedef struct SAlterTableStmt { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - int8_t alterType; - char colName[TSDB_COL_NAME_LEN]; - char newColName[TSDB_COL_NAME_LEN]; + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + int8_t alterType; + char colName[TSDB_COL_NAME_LEN]; + char newColName[TSDB_COL_NAME_LEN]; STableOptions* pOptions; - SDataType dataType; - SValueNode* pVal; + SDataType dataType; + SValueNode* pVal; } SAlterTableStmt; typedef struct SCreateUserStmt { ENodeType type; - char useName[TSDB_USER_LEN]; - char password[TSDB_USET_PASSWORD_LEN]; + char useName[TSDB_USER_LEN]; + char password[TSDB_USET_PASSWORD_LEN]; } SCreateUserStmt; typedef struct SAlterUserStmt { ENodeType type; - char useName[TSDB_USER_LEN]; - char password[TSDB_USET_PASSWORD_LEN]; - int8_t alterType; + char useName[TSDB_USER_LEN]; + char password[TSDB_USET_PASSWORD_LEN]; + int8_t alterType; } SAlterUserStmt; typedef struct SDropUserStmt { ENodeType type; - char useName[TSDB_USER_LEN]; + char useName[TSDB_USER_LEN]; } SDropUserStmt; typedef struct SCreateDnodeStmt { ENodeType type; - char fqdn[TSDB_FQDN_LEN]; - int32_t port; + char fqdn[TSDB_FQDN_LEN]; + int32_t port; } SCreateDnodeStmt; typedef struct SDropDnodeStmt { ENodeType type; - int32_t dnodeId; - char fqdn[TSDB_FQDN_LEN]; - int32_t port; + int32_t dnodeId; + char fqdn[TSDB_FQDN_LEN]; + int32_t port; } SDropDnodeStmt; typedef struct SAlterDnodeStmt { ENodeType type; - int32_t dnodeId; - char config[TSDB_DNODE_CONFIG_LEN]; - char value[TSDB_DNODE_VALUE_LEN]; + int32_t dnodeId; + char config[TSDB_DNODE_CONFIG_LEN]; + char value[TSDB_DNODE_VALUE_LEN]; } SAlterDnodeStmt; typedef struct SShowStmt { ENodeType type; - SNode* pDbName; // SValueNode - SNode* pTbNamePattern; // SValueNode + SNode* pDbName; // SValueNode + SNode* pTbNamePattern; // SValueNode } SShowStmt; typedef struct SShowCreatStmt { ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; } SShowCreatStmt; -typedef enum EIndexType { - INDEX_TYPE_SMA = 1, - INDEX_TYPE_FULLTEXT -} EIndexType; +typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT } EIndexType; typedef struct SIndexOptions { - ENodeType type; + ENodeType type; SNodeList* pFuncs; - SNode* pInterval; - SNode* pOffset; - SNode* pSliding; + SNode* pInterval; + SNode* pOffset; + SNode* pSliding; } SIndexOptions; typedef struct SCreateIndexStmt { - ENodeType type; - EIndexType indexType; - bool ignoreExists; - char indexName[TSDB_INDEX_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - SNodeList* pCols; + ENodeType type; + EIndexType indexType; + bool ignoreExists; + char indexName[TSDB_INDEX_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + SNodeList* pCols; SIndexOptions* pOptions; } SCreateIndexStmt; typedef struct SDropIndexStmt { ENodeType type; - bool ignoreNotExists; - char indexName[TSDB_INDEX_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; + bool ignoreNotExists; + char indexName[TSDB_INDEX_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; } SDropIndexStmt; typedef struct SCreateComponentNodeStmt { ENodeType type; - int32_t dnodeId; + int32_t dnodeId; } SCreateComponentNodeStmt; typedef struct SDropComponentNodeStmt { ENodeType type; - int32_t dnodeId; + int32_t dnodeId; } SDropComponentNodeStmt; typedef struct STopicOptions { ENodeType type; - bool withTable; - bool withSchema; - bool withTag; + bool withTable; + bool withSchema; + bool withTag; } STopicOptions; typedef struct SCreateTopicStmt { - ENodeType type; - char topicName[TSDB_TABLE_NAME_LEN]; - char subscribeDbName[TSDB_DB_NAME_LEN]; - bool ignoreExists; - SNode* pQuery; + ENodeType type; + char topicName[TSDB_TABLE_NAME_LEN]; + char subscribeDbName[TSDB_DB_NAME_LEN]; + bool ignoreExists; + SNode* pQuery; STopicOptions* pOptions; } SCreateTopicStmt; typedef struct SDropTopicStmt { ENodeType type; - char topicName[TSDB_TABLE_NAME_LEN]; - bool ignoreNotExists; + char topicName[TSDB_TABLE_NAME_LEN]; + bool ignoreNotExists; } SDropTopicStmt; typedef struct SAlterLocalStmt { ENodeType type; - char config[TSDB_DNODE_CONFIG_LEN]; - char value[TSDB_DNODE_VALUE_LEN]; + char config[TSDB_DNODE_CONFIG_LEN]; + char value[TSDB_DNODE_VALUE_LEN]; } SAlterLocalStmt; typedef struct SDescribeStmt { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; STableMeta* pMeta; } SDescribeStmt; typedef struct SKillStmt { ENodeType type; - int32_t targetId; + int32_t targetId; } SKillStmt; typedef struct SStreamOptions { ENodeType type; - int8_t triggerType; - SNode* pWatermark; + int8_t triggerType; + SNode* pWatermark; } SStreamOptions; typedef struct SCreateStreamStmt { - ENodeType type; - char streamName[TSDB_TABLE_NAME_LEN]; - char targetDbName[TSDB_DB_NAME_LEN]; - char targetTabName[TSDB_TABLE_NAME_LEN]; - bool ignoreExists; + ENodeType type; + char streamName[TSDB_TABLE_NAME_LEN]; + char targetDbName[TSDB_DB_NAME_LEN]; + char targetTabName[TSDB_TABLE_NAME_LEN]; + bool ignoreExists; SStreamOptions* pOptions; - SNode* pQuery; + SNode* pQuery; } SCreateStreamStmt; typedef struct SDropStreamStmt { ENodeType type; - char streamName[TSDB_TABLE_NAME_LEN]; - bool ignoreNotExists; + char streamName[TSDB_TABLE_NAME_LEN]; + bool ignoreNotExists; } SDropStreamStmt; typedef struct SCreateFunctionStmt { ENodeType type; - bool ignoreExists; - char funcName[TSDB_FUNC_NAME_LEN]; - bool isAgg; - char libraryPath[PATH_MAX]; + bool ignoreExists; + char funcName[TSDB_FUNC_NAME_LEN]; + bool isAgg; + char libraryPath[PATH_MAX]; SDataType outputDt; - int32_t bufSize; + int32_t bufSize; } SCreateFunctionStmt; #ifdef __cplusplus diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 6f77e8edb69641aec4f2e2799e35da1bad8c49a2..6513a44e883f29e0966f0eace2f2419356fe0ad5 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -22,19 +22,20 @@ extern "C" { #include "tdef.h" -#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type) +#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type) #define setNodeType(nodeptr, type) (((SNode*)(nodeptr))->type = (type)) #define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0) -#define FOREACH(node, list) \ - for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext) +#define FOREACH(node, list) \ + for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); \ + (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext) #define REPLACE_NODE(newNode) cell->pNode = (SNode*)(newNode) #define INSERT_LIST(target, src) nodesListInsertList((target), cell, src) -#define WHERE_EACH(node, list) \ +#define WHERE_EACH(node, list) \ SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); \ while (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)) @@ -43,16 +44,26 @@ extern "C" { // only be use in WHERE_EACH #define ERASE_NODE(list) cell = nodesListErase((list), cell) -#define FORBOTH(node1, list1, node2, list2) \ - for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHead : NULL), *cell2 = (NULL != (list2) ? (list2)->pHead : NULL); \ - (NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), (node1 != NULL && node2 != NULL); \ - cell1 = cell1->pNext, cell2 = cell2->pNext) +#define FORBOTH(node1, list1, node2, list2) \ + for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHead : NULL), \ + *cell2 = (NULL != (list2) ? (list2)->pHead : NULL); \ + (NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), \ + (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), \ + (node1 != NULL && node2 != NULL); \ + cell1 = cell1->pNext, cell2 = cell2->pNext) #define REPLACE_LIST1_NODE(newNode) cell1->pNode = (SNode*)(newNode) #define REPLACE_LIST2_NODE(newNode) cell2->pNode = (SNode*)(newNode) -#define FOREACH_FOR_REWRITE(node, list) \ - for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext) +#define FOREACH_FOR_REWRITE(node, list) \ + for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); \ + (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext) + +#define DESTORY_LIST(list) \ + do { \ + nodesDestroyList(list); \ + list = NULL; \ + } while (0) typedef enum ENodeType { // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, @@ -202,7 +213,7 @@ typedef enum ENodeType { /** * The first field of a node of any type is guaranteed to be the ENodeType. - * Hence the type of any node can be gotten by casting it to SNode. + * Hence the type of any node can be gotten by casting it to SNode. */ typedef struct SNode { ENodeType type; @@ -211,41 +222,36 @@ typedef struct SNode { typedef struct SListCell { struct SListCell* pPrev; struct SListCell* pNext; - SNode* pNode; + SNode* pNode; } SListCell; typedef struct SNodeList { - int32_t length; + int32_t length; SListCell* pHead; SListCell* pTail; } SNodeList; -#define SNodeptr void* +#define SNodeptr void* SNodeptr nodesMakeNode(ENodeType type); -void nodesDestroyNode(SNodeptr pNode); +void nodesDestroyNode(SNodeptr pNode); SNodeList* nodesMakeList(); -int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode); -int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode); -int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode); -int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode); -int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc); -int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc); -int32_t nodesListPushFront(SNodeList* pList, SNodeptr pNode); +int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode); +int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode); +int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode); +int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode); +int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc); +int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc); +int32_t nodesListPushFront(SNodeList* pList, SNodeptr pNode); SListCell* nodesListErase(SNodeList* pList, SListCell* pCell); -void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc); -SNodeptr nodesListGetNode(SNodeList* pList, int32_t index); -void nodesDestroyList(SNodeList* pList); +void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc); +SNodeptr nodesListGetNode(SNodeList* pList, int32_t index); +void nodesDestroyList(SNodeList* pList); // Only clear the linked list structure, without releasing the elements inside void nodesClearList(SNodeList* pList); -typedef enum EDealRes { - DEAL_RES_CONTINUE = 1, - DEAL_RES_IGNORE_CHILD, - DEAL_RES_ERROR, - DEAL_RES_END -} EDealRes; +typedef enum EDealRes { DEAL_RES_CONTINUE = 1, DEAL_RES_IGNORE_CHILD, DEAL_RES_ERROR, DEAL_RES_END } EDealRes; typedef EDealRes (*FNodeWalker)(SNode* pNode, void* pContext); void nodesWalkExpr(SNodeptr pNode, FNodeWalker walker, void* pContext); @@ -261,18 +267,18 @@ void nodesRewriteExprsPostOrder(SNodeList* pList, FNodeRewriter rewriter, void* bool nodesEqualNode(const SNodeptr a, const SNodeptr b); -SNodeptr nodesCloneNode(const SNodeptr pNode); +SNodeptr nodesCloneNode(const SNodeptr pNode); SNodeList* nodesCloneList(const SNodeList* pList); const char* nodesNodeName(ENodeType type); -int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen); -int32_t nodesStringToNode(const char* pStr, SNode** pNode); +int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen); +int32_t nodesStringToNode(const char* pStr, SNode** pNode); int32_t nodesListToString(const SNodeList* pList, bool format, char** pStr, int32_t* pLen); int32_t nodesStringToList(const char* pStr, SNodeList** pList); -int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len); -char *nodesGetNameFromColumnNode(SNode *pNode); +int32_t nodesNodeToSQL(SNode* pNode, char* buf, int32_t bufSize, int32_t* len); +char* nodesGetNameFromColumnNode(SNode* pNode); int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots); #ifdef __cplusplus diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index d4197cd399391448e2795337f35fe9428b1b2e19..a34d4e3c80a75e29c5fb6e81125c98bcd5fec56f 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -340,7 +340,7 @@ typedef struct SQueryPlan { int32_t numOfSubplans; SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0. SExplainInfo explainInfo; - SNodeList* pPlaceholderValues; + SArray* pPlaceholderValues; } SQueryPlan; void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext); diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 238c4c85384393225390e8a31eeb0b4ab80e554e..5f1ee157e1ee51d66d7718781b15d0f0ad2b7a48 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -88,6 +88,7 @@ typedef struct SValueNode { double d; char* p; } datum; + int64_t typeData; char unit; } SValueNode; @@ -230,6 +231,7 @@ typedef struct SSelectStmt { uint8_t precision; bool isEmptyResult; bool hasAggFuncs; + bool isTimeOrderQuery; } SSelectStmt; typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType; @@ -294,13 +296,14 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext); typedef enum ECollectColType { COLLECT_COL_TYPE_COL = 1, COLLECT_COL_TYPE_TAG, COLLECT_COL_TYPE_ALL } ECollectColType; - int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type, SNodeList** pCols); typedef bool (*FFuncClassifier)(int32_t funcId); int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNodeList** pFuncs); +int32_t nodesCollectSpecialNodes(SSelectStmt* pSelect, ESqlClause clause, ENodeType type, SNodeList** pNodes); + bool nodesIsExprNode(const SNode* pNode); bool nodesIsUnaryOp(const SOperatorNode* pOp); @@ -312,6 +315,7 @@ bool nodesIsTimeorderQuery(const SNode* pQuery); bool nodesIsTimelineQuery(const SNode* pQuery); void* nodesGetValueFromNode(SValueNode* pNode); +int32_t nodesSetValueNodeValue(SValueNode* pNode, void *value); char* nodesGetStrValueFromNode(SValueNode* pNode); char* getFillModeString(EFillMode mode); void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal); diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 875cdc275530c4957318d9a43ccbd8579f0732c3..de71192a9bdb928c3c9dfed061d8fca972518731 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -73,6 +73,7 @@ typedef struct SQuery { SArray* pDbList; SArray* pTableList; bool showRewrite; + int32_t placeholderNum; } SQuery; int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery); diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index b78cbb639c8942e313fd8bfb300e4f6f9be3b3e9..adbd84b04477049647d87ec6bbf4a09fadbfdf75 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -34,7 +34,7 @@ typedef struct SPlanContext { bool showRewrite; int8_t triggerType; int64_t watermark; - bool isStmtQuery; + int32_t placeholderNum; void* pTransporter; struct SCatalog* pCatalog; char* pMsg; @@ -50,7 +50,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo // @pSource one execution location of this group of datasource subplans int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource); -int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_MULTI_BIND* pParams, int32_t colIdx); +int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_MULTI_BIND* pParams, int32_t colIdx, uint64_t queryId); // Convert to subplan to string for the scheduler to send to the executor int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index eadc90138919137a80c8110563d59bbe21a11b50..2e5574511b6ed8d7ac42e4840df17b3f70853598 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -35,19 +35,6 @@ enum { STREAM_CREATED_BY__SMA, }; -#if 0 -// pipe -> fetch/pipe queue -// merge -> merge queue -// write -> write queue -enum { - TASK_DISPATCH_MSG__SND_PIPE = 1, - TASK_DISPATCH_MSG__SND_MERGE, - TASK_DISPATCH_MSG__VND_PIPE, - TASK_DISPATCH_MSG__VND_MERGE, - TASK_DISPATCH_MSG__VND_WRITE, -}; -#endif - typedef struct { int32_t nodeId; // 0 for snode SEpSet epSet; @@ -100,10 +87,6 @@ typedef struct { int8_t reserved; } STaskSinkFetch; -typedef struct { - int8_t reserved; -} STaskSinkShow; - enum { TASK_SOURCE__SCAN = 1, TASK_SOURCE__PIPE, @@ -128,7 +111,6 @@ enum { TASK_SINK__TABLE, TASK_SINK__SMA, TASK_SINK__FETCH, - TASK_SINK__SHOW, }; typedef struct { @@ -155,7 +137,6 @@ typedef struct { STaskSinkTb tbSink; STaskSinkSma smaSink; STaskSinkFetch fetchSink; - STaskSinkShow showSink; }; // dispatch diff --git a/include/libs/stream/tstreamUpdate.h b/include/libs/stream/tstreamUpdate.h new file mode 100644 index 0000000000000000000000000000000000000000..5911759fe398135d3b8357ffd655ddb4e28cd237 --- /dev/null +++ b/include/libs/stream/tstreamUpdate.h @@ -0,0 +1,46 @@ +/* + * 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 . + */ +#ifndef _TSTREAMUPDATE_H_ +#define _TSTREAMUPDATE_H_ + +#include "taosdef.h" +#include "tarray.h" +#include "tmsg.h" +#include "tscalablebf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SUpdateInfo { + SArray *pTsBuckets; + uint64_t numBuckets; + SArray *pTsSBFs; + uint64_t numSBFs; + int64_t interval; + int64_t watermark; + TSKEY minTS; +} SUpdateInfo; + +SUpdateInfo *updateInfoInitP(SInterval* pInterval, int64_t watermark); +SUpdateInfo *updateInfoInit(int64_t interval, int32_t precision, int64_t watermark); +bool isUpdated(SUpdateInfo *pInfo, tb_uid_t tableId, TSKEY ts); +void updateInfoDestroy(SUpdateInfo *pInfo); + +#ifdef __cplusplus +} +#endif + +#endif /* ifndef _TSTREAMUPDATE_H_ */ \ No newline at end of file diff --git a/include/os/osDef.h b/include/os/osDef.h index 8da0c2c00cc7713d2d5dcdeda1b60634ea89b236..6f6199de7af6a09d7be1b4b60009f2d7507f2d46 100644 --- a/include/os/osDef.h +++ b/include/os/osDef.h @@ -62,7 +62,7 @@ extern "C" { #define strncasecmp _strnicmp #define wcsncasecmp _wcsnicmp #define strtok_r strtok_s - #define snprintf _snprintf + // #define snprintf _snprintf #define in_addr_t unsigned long // #define socklen_t int diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 0ddc5b91d3bba7cca9ea4e60bc6847213b3426f5..00708f0933a102d167a8353c01821804759d70c0 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -87,6 +87,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0113) #define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0114) #define TSDB_CODE_REPEAT_INIT TAOS_DEF_ERROR_CODE(0, 0x0115) +#define TSDB_CODE_DUP_KEY TAOS_DEF_ERROR_CODE(0, 0x0116) #define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0140) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0141) @@ -244,9 +245,10 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x03AC) #define TSDB_CODE_MND_COLUMN_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AD) #define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AE) +#define TSDB_CODE_MND_SINGLE_STB_MODE_DB TAOS_DEF_ERROR_CODE(0, 0x03B0) // mnode-infoSchema -#define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x03B0) +#define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x03BA) // mnode-func #define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0) @@ -317,6 +319,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_VND_TB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0515) #define TSDB_CODE_VND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0516) #define TSDB_CODE_VND_HASH_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0517) +#define TSDB_CODE_VND_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0518) // tsdb #define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600) @@ -586,7 +589,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_RANGE_OPTION TAOS_DEF_ERROR_CODE(0, 0x2619) #define TSDB_CODE_PAR_INVALID_STR_OPTION TAOS_DEF_ERROR_CODE(0, 0x261A) #define TSDB_CODE_PAR_INVALID_ENUM_OPTION TAOS_DEF_ERROR_CODE(0, 0x261B) -#define TSDB_CODE_PAR_INVALID_TTL_OPTION TAOS_DEF_ERROR_CODE(0, 0x261C) #define TSDB_CODE_PAR_INVALID_KEEP_NUM TAOS_DEF_ERROR_CODE(0, 0x261D) #define TSDB_CODE_PAR_INVALID_KEEP_ORDER TAOS_DEF_ERROR_CODE(0, 0x261E) #define TSDB_CODE_PAR_INVALID_KEEP_VALUE TAOS_DEF_ERROR_CODE(0, 0x261F) @@ -616,6 +618,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_OFFSET_LESS_ZERO TAOS_DEF_ERROR_CODE(0, 0x2637) #define TSDB_CODE_PAR_SLIMIT_LEAK_PARTITION_BY TAOS_DEF_ERROR_CODE(0, 0x2638) #define TSDB_CODE_PAR_INVALID_TOPIC_QUERY TAOS_DEF_ERROR_CODE(0, 0x2639) +#define TSDB_CODE_PAR_INVALID_DROP_STABLE TAOS_DEF_ERROR_CODE(0, 0x263A) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/include/util/tarray.h b/include/util/tarray.h index bbde90f28fefd695835870842759acdd6fcb8d9a..482f13de39094aeb0015dd17f2b5f3ed82ce0c89 100644 --- a/include/util/tarray.h +++ b/include/util/tarray.h @@ -218,6 +218,13 @@ void taosArrayClear(SArray* pArray); */ void taosArrayClearEx(SArray* pArray, void (*fp)(void*)); +/** + * clear the array (remove all element) + * @param pArray + * @param fp + */ +void taosArrayClearP(SArray* pArray, FDelete fp); + void* taosArrayDestroy(SArray* pArray); void taosArrayDestroyP(SArray* pArray, FDelete fp); void taosArrayDestroyEx(SArray* pArray, FDelete fp); diff --git a/include/util/tbloomfilter.h b/include/util/tbloomfilter.h new file mode 100644 index 0000000000000000000000000000000000000000..b168da594a172dfb84b089d92533993aaef001f8 --- /dev/null +++ b/include/util/tbloomfilter.h @@ -0,0 +1,50 @@ +/* + * 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 . + */ + +#ifndef _TD_UTIL_BLOOMFILTER_H_ +#define _TD_UTIL_BLOOMFILTER_H_ + +#include "os.h" +#include "thash.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SBloomFilter { + uint32_t hashFunctions; + uint64_t expectedEntries; + uint64_t numUnits; + uint64_t numBits; + uint64_t size; + _hash_fn_t hashFn1; + _hash_fn_t hashFn2; + void *buffer; + double errorRate; +} SBloomFilter; + +SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate); +int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len); +int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf, + uint32_t len); +void tBloomFilterDestroy(SBloomFilter *pBF); +void tBloomFilterDump(const SBloomFilter *pBF); +bool tBloomFilterIsFull(const SBloomFilter *pBF); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_UTIL_BLOOMFILTER_H_*/ \ No newline at end of file diff --git a/include/util/tdef.h b/include/util/tdef.h index cf0c75e58f9e1d1645e4f438e74978eb719cb7b8..316640797be355e053117a3e8db7b3de5009fce6 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -97,42 +97,6 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_TIME_PRECISION_MICRO_DIGITS 16 #define TSDB_TIME_PRECISION_NANO_DIGITS 19 -#define TSDB_INFORMATION_SCHEMA_DB "information_schema" -#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" -#define TSDB_INS_TABLE_DNODES "dnodes" -#define TSDB_INS_TABLE_MNODES "mnodes" -#define TSDB_INS_TABLE_MODULES "modules" -#define TSDB_INS_TABLE_QNODES "qnodes" -#define TSDB_INS_TABLE_BNODES "bnodes" -#define TSDB_INS_TABLE_SNODES "snodes" -#define TSDB_INS_TABLE_CLUSTER "cluster" -#define TSDB_INS_TABLE_USER_DATABASES "user_databases" -#define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions" -#define TSDB_INS_TABLE_USER_INDEXES "user_indexes" -#define TSDB_INS_TABLE_USER_STABLES "user_stables" -#define TSDB_INS_TABLE_USER_STREAMS "user_streams" -#define TSDB_INS_TABLE_USER_TABLES "user_tables" -#define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed" -#define TSDB_INS_TABLE_USER_USERS "user_users" -#define TSDB_INS_TABLE_LICENCES "grants" -#define TSDB_INS_TABLE_VGROUPS "vgroups" -#define TSDB_INS_TABLE_CONSUMERS "consumers" -#define TSDB_INS_TABLE_SUBSCRIBES "subscribes" -#define TSDB_INS_TABLE_TRANS "trans" -#define TSDB_INS_TABLE_SMAS "smas" -#define TSDB_INS_TABLE_CONFIGS "configs" -#define TSDB_INS_TABLE_CONNS "connections" -#define TSDB_INS_TABLE_QUERIES "queries" -#define TSDB_INS_TABLE_VNODES "vnodes" - -#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" -#define TSDB_PERFS_TABLE_CONNECTIONS "connections" -#define TSDB_PERFS_TABLE_QUERIES "queries" -#define TSDB_PERFS_TABLE_TOPICS "topics" -#define TSDB_PERFS_TABLE_CONSUMERS "consumers" -#define TSDB_PERFS_TABLE_SUBSCRIPTIONS "subscriptions" -#define TSDB_PERFS_TABLE_OFFSETS "offsets" - #define TSDB_INDEX_TYPE_SMA "SMA" #define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT" @@ -204,16 +168,6 @@ typedef enum ELogicConditionType { LOGIC_COND_TYPE_NOT, } ELogicConditionType; -#define FUNCTION_CEIL 4500 -#define FUNCTION_FLOOR 4501 -#define FUNCTION_ABS 4502 -#define FUNCTION_ROUND 4503 - -#define FUNCTION_LENGTH 4800 -#define FUNCTION_CONCAT 4801 -#define FUNCTION_LTRIM 4802 -#define FUNCTION_RTRIM 4803 - #define TSDB_NAME_DELIMITER_LEN 1 #define TSDB_UNI_LEN 24 @@ -323,72 +277,73 @@ typedef enum ELogicConditionType { #define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta -#define TSDB_MIN_VNODES_PER_DB 1 -#define TSDB_MAX_VNODES_PER_DB 4096 -#define TSDB_DEFAULT_VN_PER_DB 2 -#define TSDB_MIN_CACHE_BLOCK_SIZE 1 -#define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode -#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16 -#define TSDB_MIN_TOTAL_BLOCKS 3 -#define TSDB_MAX_TOTAL_BLOCKS 10000 -#define TSDB_DEFAULT_TOTAL_BLOCKS 6 -#define TSDB_MIN_DAYS_PER_FILE 60 // unit minute -#define TSDB_MAX_DAYS_PER_FILE (3650 * 1440) -#define TSDB_DEFAULT_DAYS_PER_FILE (10 * 1440) -#define TSDB_MIN_KEEP (1 * 1440) // data in db to be reserved. unit minute -#define TSDB_MAX_KEEP (365000 * 1440) // data in db to be reserved. -#define TSDB_DEFAULT_KEEP (3650 * 1440) // ten years -#define TSDB_MIN_MINROWS_FBLOCK 10 -#define TSDB_MAX_MINROWS_FBLOCK 1000 -#define TSDB_DEFAULT_MINROWS_FBLOCK 100 -#define TSDB_MIN_MAXROWS_FBLOCK 200 -#define TSDB_MAX_MAXROWS_FBLOCK 10000 -#define TSDB_DEFAULT_MAXROWS_FBLOCK 4096 -#define TSDB_MIN_COMMIT_TIME 30 -#define TSDB_MAX_COMMIT_TIME 40960 -#define TSDB_DEFAULT_COMMIT_TIME 3600 -#define TSDB_MIN_FSYNC_PERIOD 0 -#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond -#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second -#define TSDB_MIN_DB_TTL 1 -#define TSDB_DEFAULT_DB_TTL 1 -#define TSDB_MIN_WAL_LEVEL 1 -#define TSDB_MAX_WAL_LEVEL 2 -#define TSDB_DEFAULT_WAL_LEVEL 1 -#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI -#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO -#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI -#define TSDB_MIN_COMP_LEVEL 0 -#define TSDB_MAX_COMP_LEVEL 2 -#define TSDB_DEFAULT_COMP_LEVEL 2 -#define TSDB_MIN_DB_REPLICA 1 -#define TSDB_MAX_DB_REPLICA 3 -#define TSDB_DEFAULT_DB_REPLICA 1 -#define TSDB_DB_STRICT_OFF 0 -#define TSDB_DB_STRICT_ON 1 -#define TSDB_DEFAULT_DB_STRICT 0 -#define TSDB_MIN_DB_UPDATE 0 -#define TSDB_MAX_DB_UPDATE 2 -#define TSDB_DEFAULT_DB_UPDATE 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_DB_STREAM_MODE_OFF 0 -#define TSDB_DB_STREAM_MODE_ON 1 -#define TSDB_DEFAULT_DB_STREAM_MODE 0 -#define TSDB_DB_SINGLE_STABLE_ON 0 -#define TSDB_DB_SINGLE_STABLE_OFF 1 -#define TSDB_DEFAULT_DB_SINGLE_STABLE 0 - -#define TSDB_MIN_DB_FILE_FACTOR 0 -#define TSDB_MAX_DB_FILE_FACTOR 1 -#define TSDB_DEFAULT_DB_FILE_FACTOR 0.1 -#define TSDB_MIN_DB_DELAY 1 -#define TSDB_MAX_DB_DELAY 10 -#define TSDB_DEFAULT_DB_DELAY 2 -#define TSDB_MIN_EXPLAIN_RATIO 0 -#define TSDB_MAX_EXPLAIN_RATIO 1 -#define TSDB_DEFAULT_EXPLAIN_RATIO 0.001 +#define TSDB_MIN_VNODES_PER_DB 1 +#define TSDB_MAX_VNODES_PER_DB 4096 +#define TSDB_DEFAULT_VN_PER_DB 2 +#define TSDB_MIN_BUFFER_PER_VNODE 3 // unit MB +#define TSDB_MAX_BUFFER_PER_VNODE 16384 // unit MB +#define TSDB_DEFAULT_BUFFER_PER_VNODE 96 +#define TSDB_MIN_PAGES_PER_VNODE 64 +#define TSDB_MAX_PAGES_PER_VNODE 16384 +#define TSDB_DEFAULT_PAGES_PER_VNODE 256 +#define TSDB_MIN_PAGESIZE_PER_VNODE 1 // unit KB +#define TSDB_MAX_PAGESIZE_PER_VNODE 16384 +#define TSDB_DEFAULT_PAGESIZE_PER_VNODE 4 +#define TSDB_MIN_DAYS_PER_FILE 60 // unit minute +#define TSDB_MAX_DAYS_PER_FILE (3650 * 1440) +#define TSDB_DEFAULT_DAYS_PER_FILE (10 * 1440) +#define TSDB_MIN_DURATION_PER_FILE 60 // unit minute +#define TSDB_MAX_DURATION_PER_FILE (3650 * 1440) +#define TSDB_DEFAULT_DURATION_PER_FILE (10 * 1440) +#define TSDB_MIN_KEEP (1 * 1440) // data in db to be reserved. unit minute +#define TSDB_MAX_KEEP (365000 * 1440) // data in db to be reserved. +#define TSDB_DEFAULT_KEEP (3650 * 1440) // ten years +#define TSDB_MIN_MINROWS_FBLOCK 10 +#define TSDB_MAX_MINROWS_FBLOCK 1000 +#define TSDB_DEFAULT_MINROWS_FBLOCK 100 +#define TSDB_MIN_MAXROWS_FBLOCK 200 +#define TSDB_MAX_MAXROWS_FBLOCK 10000 +#define TSDB_DEFAULT_MAXROWS_FBLOCK 4096 +#define TSDB_MIN_FSYNC_PERIOD 0 +#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond +#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second +#define TSDB_MIN_WAL_LEVEL 1 +#define TSDB_MAX_WAL_LEVEL 2 +#define TSDB_DEFAULT_WAL_LEVEL 1 +#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI +#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO +#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI +#define TSDB_MIN_COMP_LEVEL 0 +#define TSDB_MAX_COMP_LEVEL 2 +#define TSDB_DEFAULT_COMP_LEVEL 2 +#define TSDB_MIN_DB_REPLICA 1 +#define TSDB_MAX_DB_REPLICA 3 +#define TSDB_DEFAULT_DB_REPLICA 1 +#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_DB_STREAM_MODE_OFF 0 +#define TSDB_DB_STREAM_MODE_ON 1 +#define TSDB_DEFAULT_DB_STREAM_MODE 0 +#define TSDB_DB_SINGLE_STABLE_ON 0 +#define TSDB_DB_SINGLE_STABLE_OFF 1 +#define TSDB_DEFAULT_DB_SINGLE_STABLE 0 + +#define TSDB_MIN_ROLLUP_FILE_FACTOR 0 +#define TSDB_MAX_ROLLUP_FILE_FACTOR 1 +#define TSDB_DEFAULT_ROLLUP_FILE_FACTOR 0.1 +#define TSDB_MIN_ROLLUP_DELAY 1 +#define TSDB_MAX_ROLLUP_DELAY 10 +#define TSDB_DEFAULT_ROLLUP_DELAY 2 +#define TSDB_MIN_TABLE_TTL 0 +#define TSDB_DEFAULT_TABLE_TTL 0 + +#define TSDB_MIN_EXPLAIN_RATIO 0 +#define TSDB_MAX_EXPLAIN_RATIO 1 +#define TSDB_DEFAULT_EXPLAIN_RATIO 0.001 #define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 @@ -415,21 +370,9 @@ typedef enum ELogicConditionType { * 1. ordinary sub query for select * from super_table * 2. all sqlobj generated by createSubqueryObj with this flag */ -#define TSDB_QUERY_TYPE_SUBQUERY 0x02u -#define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x04u // two-stage subquery for super table - -#define TSDB_QUERY_TYPE_TABLE_QUERY 0x08u // query ordinary table; below only apply to client side -#define TSDB_QUERY_TYPE_STABLE_QUERY 0x10u // query on super table -#define TSDB_QUERY_TYPE_JOIN_QUERY 0x20u // join query -#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40u // select *,columns... query -#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80u // join sub query at the second stage - -#define TSDB_QUERY_TYPE_TAG_FILTER_QUERY 0x400u #define TSDB_QUERY_TYPE_INSERT 0x100u // insert type -#define TSDB_QUERY_TYPE_MULTITABLE_QUERY 0x200u #define TSDB_QUERY_TYPE_FILE_INSERT 0x400u // insert data from file #define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type -#define TSDB_QUERY_TYPE_NEST_SUBQUERY 0x1000u // nested sub query #define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0) #define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type)) diff --git a/include/util/tencode.h b/include/util/tencode.h index c5066996f3ffb7091f3bf396b625c6ba50ce0ec0..b081d1a157369ad244fed870b126901f1009374a 100644 --- a/include/util/tencode.h +++ b/include/util/tencode.h @@ -79,17 +79,6 @@ typedef struct { #define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos) #define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE)) #define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE)) -// #define TCODER_MALLOC(PCODER, SIZE) \ -// ({ \ -// void* ptr = NULL; \ -// SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(*pMem) + (SIZE)); \ -// if (pMem) { \ -// pMem->next = (PCODER)->mList; \ -// (PCODER)->mList = pMem; \ -// ptr = (void*)&pMem[1]; \ -// } \ -// ptr; \ -// }) static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) { void* ptr = NULL; SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(SCoderMem*) + size); @@ -102,8 +91,9 @@ static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) { } #define tEncodeSize(E, S, SIZE, RET) \ - do{ \ + do { \ SCoder coder = {0}; \ + RET = 0; \ tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); \ if ((E)(&coder, S) == 0) { \ SIZE = coder.pos; \ @@ -111,7 +101,7 @@ static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) { RET = -1; \ } \ tCoderClear(&coder); \ - }while(0) + } while (0) // #define tEncodeSize(E, S, SIZE) \ // ({ \ // SCoder coder = {0}; \ diff --git a/source/libs/tdb/src/inc/tdbEnv.h b/include/util/tscalablebf.h similarity index 52% rename from source/libs/tdb/src/inc/tdbEnv.h rename to include/util/tscalablebf.h index 54f5818be1b6442fd7af45c1ceae572c21f731f1..8f88f65048ee02052329cf8e0dd655f3b8f6d48a 100644 --- a/source/libs/tdb/src/inc/tdbEnv.h +++ b/include/util/tscalablebf.h @@ -13,36 +13,30 @@ * along with this program. If not, see . */ -#ifndef _TDB_ENV_H_ -#define _TDB_ENV_H_ +#ifndef _TD_UTIL_SCALABLEBF_H_ +#define _TD_UTIL_SCALABLEBF_H_ + +#include "tbloomfilter.h" #ifdef __cplusplus extern "C" { #endif -typedef struct STEnv { - char *rootDir; - char *jfname; - int jfd; - SPCache *pCache; - SPager *pgrList; - int nPager; - int nPgrHash; - SPager **pgrHash; -} TENV; - -int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv); -int tdbEnvClose(TENV *pEnv); -int tdbBegin(TENV *pEnv, TXN *pTxn); -int tdbCommit(TENV *pEnv, TXN *pTxn); -int tdbRollback(TENV *pEnv, TXN *pTxn); +typedef struct SScalableBf { + SArray *bfArray; // array of bloom filters + uint32_t growth; + uint64_t numBits; +} SScalableBf; -void tdbEnvAddPager(TENV *pEnv, SPager *pPager); -void tdbEnvRemovePager(TENV *pEnv, SPager *pPager); -SPager *tdbEnvGetPager(TENV *pEnv, const char *fname); +SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate); +int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len); +int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf, + uint32_t len); +void tScalableBfDestroy(SScalableBf *pSBf); +void tScalableBfDump(const SScalableBf *pSBf); #ifdef __cplusplus } #endif -#endif /*_TDB_ENV_H_*/ \ No newline at end of file +#endif /*_TD_UTIL_SCALABLEBF_H_*/ \ No newline at end of file diff --git a/include/util/tskiplist.h b/include/util/tskiplist.h index a2382ad541e104430ad7334b458a8d50a5fb5284..eeae1b47daf2ff62511dfe1329ef55e62ed916be 100644 --- a/include/util/tskiplist.h +++ b/include/util/tskiplist.h @@ -52,72 +52,21 @@ typedef struct SSkipListNode { #define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)] #define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)] -/* - * @version 0.3 - * @date 2017/11/12 - * the simple version of skip list. - * - * for multi-thread safe purpose, we employ TdThreadRwlock to guarantee to generate - * deterministic result. Later, we will remove the lock in SkipList to further enhance the performance. - * In this case, one should use the concurrent skip list (by using michael-scott algorithm) instead of - * this simple version in a multi-thread environment, to achieve higher performance of read/write operations. - * - * Note: Duplicated primary key situation. - * In case of duplicated primary key, two ways can be employed to handle this situation: - * 1. add as normal insertion without special process. - * 2. add an overflow pointer at each list node, all nodes with the same key will be added in the overflow pointer. - * In this case, the total steps of each search will be reduced significantly. - * Currently, we implement the skip list in a line with the first means, maybe refactor it soon. - * - * Memory consumption: the memory alignment causes many memory wasted. So, employ a memory - * pool will significantly reduce the total memory consumption, as well as the calloc/malloc operation costs. - * - */ - -// state struct, record following information: -// number of links in each level. -// avg search steps, for latest 1000 queries -// avg search rsp time, for latest 1000 queries -// total memory size -typedef struct tSkipListState { - // in bytes, sizeof(SSkipList)+sizeof(SSkipListNode)*SSkipList->nSize - uint64_t nTotalMemSize; - uint64_t nLevelNodeCnt[MAX_SKIP_LIST_LEVEL]; - uint64_t queryCount; // total query count - - /* - * only record latest 1000 queries - * when the value==1000, = 0, - * nTotalStepsForQueries = 0, - * nTotalElapsedTimeForQueries = 0 - */ - uint64_t nRecQueries; - uint16_t nTotalStepsForQueries; - uint64_t nTotalElapsedTimeForQueries; - - uint16_t nInsertObjs; - uint16_t nTotalStepsForInsert; - uint64_t nTotalElapsedTimeForInsert; -} tSkipListState; - typedef enum { SSkipListPutSuccess = 0, SSkipListPutEarlyStop = 1, SSkipListPutSkipOne = 2 } SSkipListPutStatus; typedef struct SSkipList { - uint32_t seed; - __compar_fn_t comparFn; - __sl_key_fn_t keyFn; - TdThreadRwlock *lock; - uint16_t len; - uint8_t maxLevel; - uint8_t flags; - uint8_t type; // static info above - uint8_t level; - uint32_t size; - SSkipListNode *pHead; // point to the first element - SSkipListNode *pTail; // point to the last element -#if SKIP_LIST_RECORD_PERFORMANCE - tSkipListState state; // skiplist state -#endif + uint32_t seed; + __compar_fn_t comparFn; + __sl_key_fn_t keyFn; + TdThreadRwlock *lock; + uint16_t len; + uint8_t maxLevel; + uint8_t flags; + uint8_t type; // static info above + uint8_t level; + uint32_t size; + SSkipListNode *pHead; // point to the first element + SSkipListNode *pTail; // point to the last element tGenericSavedFunc *insertHandleFn; } SSkipList; diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 0ff542358d37609d6623fec49214b27fe3b39a0a..ce5b101b4a845d46526b4f4970e9b6cc1693cf1d 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -308,9 +308,8 @@ int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* v void hbMgrInitMqHbRspHandle(); SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery); -int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList); -int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList); - +int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList); +int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList); #ifdef __cplusplus } diff --git a/source/client/inc/clientStmt.h b/source/client/inc/clientStmt.h index 061d757551589e2e64210db20df7e2b0e6845b2d..43e886faf54c3f3b92fd604369d0e0286dab6133 100644 --- a/source/client/inc/clientStmt.h +++ b/source/client/inc/clientStmt.h @@ -46,6 +46,13 @@ typedef struct SStmtTableCache { void* boundTags; } SStmtTableCache; +typedef struct SStmtQueryResInfo { + TAOS_FIELD* fields; + TAOS_FIELD* userFields; + uint32_t numOfCols; + int32_t precision; +} SStmtQueryResInfo; + typedef struct SStmtBindInfo { bool needParse; uint64_t tbUid; @@ -66,16 +73,17 @@ typedef struct SStmtExecInfo { } SStmtExecInfo; typedef struct SStmtSQLInfo { - STMT_TYPE type; - STMT_STATUS status; - bool autoCreate; - uint64_t runTimes; - SHashObj* pTableCache; //SHash - SQuery* pQuery; - char* sqlStr; - int32_t sqlLen; - SArray* nodeList; - SQueryPlan* pQueryPlan; + STMT_TYPE type; + STMT_STATUS status; + bool autoCreate; + uint64_t runTimes; + SHashObj* pTableCache; //SHash + SQuery* pQuery; + char* sqlStr; + int32_t sqlLen; + SArray* nodeList; + SQueryPlan* pQueryPlan; + SStmtQueryResInfo queryRes; } SStmtSQLInfo; typedef struct STscStmt { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index b876f9b65cc42f6c833ea85ca97622ed1c6fd6f9..427cd72c0f290e13584af1d0ad94ab6f14d78ec1 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -234,7 +234,8 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra .showRewrite = pQuery->showRewrite, .pTransporter = pRequest->pTscObj->pAppInfo->pTransporter, .pMsg = pRequest->msgBuf, - .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE}; + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, + .placeholderNum = pQuery->placeholderNum}; int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog); if (TSDB_CODE_SUCCESS == code) { code = qCreateQueryPlan(&cxt, pPlan, pNodeList); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 0e7563bb13ba45c340089161dc7b2f073a1d18cf..818436b41177aa65b89a95ccbc5ae46074ade49c 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -110,16 +110,23 @@ int taos_errno(TAOS_RES *tres) { return terrno; } + if (TD_RES_TMQ(tres)) { + return 0; + } + return ((SRequestObj *)tres)->code; } const char *taos_errstr(TAOS_RES *res) { - SRequestObj *pRequest = (SRequestObj *)res; - - if (pRequest == NULL) { + if (res == NULL) { return (const char *)tstrerror(terrno); } + if (TD_RES_TMQ(res)) { + return "success"; + } + + SRequestObj *pRequest = (SRequestObj *)res; if (NULL != pRequest->msgBuf && (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR)) { return pRequest->msgBuf; } else { @@ -131,7 +138,7 @@ void taos_free_result(TAOS_RES *res) { if (NULL == res) { return; } - + if (TD_RES_QUERY(res)) { SRequestObj *pRequest = (SRequestObj *)res; destroyRequest(pRequest); @@ -632,9 +639,7 @@ int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) { return stmtSetTbName(stmt, name); } -int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name) { - return taos_stmt_set_tbname(stmt, name); -} +int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name) { return taos_stmt_set_tbname(stmt, name); } int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { if (stmt == NULL || bind == NULL) { @@ -648,7 +653,7 @@ int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } - + return stmtBindBatch(stmt, bind, -1); } @@ -696,7 +701,7 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, in terrno = TSDB_CODE_INVALID_PARA; return terrno; } - + return stmtBindBatch(stmt, bind, colIdx); } @@ -750,9 +755,7 @@ TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) { return stmtUseResult(stmt); } -char *taos_stmt_errstr(TAOS_STMT *stmt) { - return (char *)stmtErrstr(stmt); -} +char *taos_stmt_errstr(TAOS_STMT *stmt) { return (char *)stmtErrstr(stmt); } int taos_stmt_affected_rows(TAOS_STMT *stmt) { if (stmt == NULL) { diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 20c318e21215a488858b442de4c69f0ed96d9e26..5ddffa0cbd35ae1005b50e1004e071dddd5f2063 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -73,6 +73,49 @@ int32_t stmtGetTbName(TAOS_STMT *stmt, char **tbName) { return TSDB_CODE_SUCCESS; } +int32_t stmtBackupQueryFields(STscStmt* pStmt) { + SStmtQueryResInfo *pRes = &pStmt->sql.queryRes; + pRes->numOfCols = pStmt->exec.pRequest->body.resInfo.numOfCols; + pRes->precision = pStmt->exec.pRequest->body.resInfo.precision; + + int32_t size = pRes->numOfCols * sizeof(TAOS_FIELD); + pRes->fields = taosMemoryMalloc(size); + pRes->userFields = taosMemoryMalloc(size); + if (NULL == pRes->fields || NULL == pRes->userFields) { + STMT_ERR_RET(TSDB_CODE_TSC_OUT_OF_MEMORY); + } + memcpy(pRes->fields, pStmt->exec.pRequest->body.resInfo.fields, size); + memcpy(pRes->userFields, pStmt->exec.pRequest->body.resInfo.userFields, size); + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtRestoreQueryFields(STscStmt* pStmt) { + SStmtQueryResInfo *pRes = &pStmt->sql.queryRes; + int32_t size = pRes->numOfCols * sizeof(TAOS_FIELD); + + pStmt->exec.pRequest->body.resInfo.numOfCols = pRes->numOfCols; + pStmt->exec.pRequest->body.resInfo.precision = pRes->precision; + + if (NULL == pStmt->exec.pRequest->body.resInfo.fields) { + pStmt->exec.pRequest->body.resInfo.fields = taosMemoryMalloc(size); + if (NULL == pStmt->exec.pRequest->body.resInfo.fields) { + STMT_ERR_RET(TSDB_CODE_TSC_OUT_OF_MEMORY); + } + memcpy(pStmt->exec.pRequest->body.resInfo.fields, pRes->fields, size); + } + + if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { + pStmt->exec.pRequest->body.resInfo.userFields = taosMemoryMalloc(size); + if (NULL == pStmt->exec.pRequest->body.resInfo.userFields) { + STMT_ERR_RET(TSDB_CODE_TSC_OUT_OF_MEMORY); + } + memcpy(pStmt->exec.pRequest->body.resInfo.userFields, pRes->userFields, size); + } + + return TSDB_CODE_SUCCESS; +} + int32_t stmtSetBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags) { STscStmt* pStmt = (STscStmt*)stmt; @@ -219,6 +262,8 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool freeRequest) { } int32_t stmtCleanSQLInfo(STscStmt* pStmt) { + taosMemoryFree(pStmt->sql.queryRes.fields); + taosMemoryFree(pStmt->sql.queryRes.userFields); taosMemoryFree(pStmt->sql.sqlStr); qDestroyQuery(pStmt->sql.pQuery); qDestroyQueryPlan(pStmt->sql.pQueryPlan); @@ -258,37 +303,42 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STableMeta *pTableMeta = NULL; SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); STMT_ERR_RET(catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &pTableMeta)); - - if (pTableMeta->uid == pStmt->bInfo.tbUid) { + uint64_t uid = pTableMeta->uid; + uint64_t suid = pTableMeta->suid; + int8_t tableType = pTableMeta->tableType; + taosMemoryFree(pTableMeta); + + if (uid == pStmt->bInfo.tbUid) { pStmt->bInfo.needParse = false; - + return TSDB_CODE_SUCCESS; } - if (taosHashGet(pStmt->exec.pBlockHash, &pTableMeta->uid, sizeof(pTableMeta->uid))) { - SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pTableMeta->uid, sizeof(pTableMeta->uid)); + if (taosHashGet(pStmt->exec.pBlockHash, &uid, sizeof(uid))) { + SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &uid, sizeof(uid)); if (NULL == pCache) { - tscError("table uid %" PRIx64 "found in exec blockHash, but not in sql blockHash", pTableMeta->uid); + tscError("table uid %" PRIx64 "found in exec blockHash, but not in sql blockHash", uid); + STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR); } pStmt->bInfo.needParse = false; - pStmt->bInfo.tbUid = pTableMeta->uid; - pStmt->bInfo.tbSuid = pTableMeta->suid; - pStmt->bInfo.tbType = pTableMeta->tableType; + pStmt->bInfo.tbUid = uid; + pStmt->bInfo.tbSuid = suid; + pStmt->bInfo.tbType = tableType; pStmt->bInfo.boundTags = pCache->boundTags; - + return TSDB_CODE_SUCCESS; } - SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pTableMeta->uid, sizeof(pTableMeta->uid)); + SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &uid, sizeof(uid)); if (pCache) { pStmt->bInfo.needParse = false; - pStmt->bInfo.tbUid = pTableMeta->uid; - pStmt->bInfo.tbSuid = pTableMeta->suid; - pStmt->bInfo.tbType = pTableMeta->tableType; + pStmt->bInfo.tbUid = uid; + pStmt->bInfo.tbSuid = suid; + pStmt->bInfo.tbType = tableType; pStmt->bInfo.boundTags = pCache->boundTags; STableDataBlocks* pNewBlock = NULL; @@ -475,9 +525,12 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx) { STMT_ERR_RET(getQueryPlan(pStmt->exec.pRequest, pStmt->sql.pQuery, &pStmt->sql.nodeList)); pStmt->sql.pQueryPlan = pStmt->exec.pRequest->body.pDag; pStmt->exec.pRequest->body.pDag = NULL; + STMT_ERR_RET(stmtBackupQueryFields(pStmt)); + } else { + STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); } - STMT_RET(qStmtBindParam(pStmt->sql.pQueryPlan, bind, colIdx)); + STMT_RET(qStmtBindParam(pStmt->sql.pQueryPlan, bind, colIdx, pStmt->exec.pRequest->requestId)); } STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid)); @@ -487,7 +540,11 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx) { } if (colIdx < 0) { - qBindStmtColsValue(*pDataBlock, bind, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen); + int32_t code = qBindStmtColsValue(*pDataBlock, bind, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen); + if (code) { + tscError("qBindStmtColsValue failed, error:%s", tstrerror(code)); + STMT_ERR_RET(code); + } } else { if (colIdx != (pStmt->bInfo.sBindLastIdx + 1) && colIdx != 0) { tscError("bind column index not in sequence"); @@ -549,6 +606,8 @@ int stmtClose(TAOS_STMT *stmt) { STscStmt* pStmt = (STscStmt*)stmt; STMT_RET(stmtCleanSQLInfo(pStmt)); + + taosMemoryFree(stmt); } const char *stmtErrstr(TAOS_STMT *stmt) { @@ -601,7 +660,7 @@ int stmtGetParamNum(TAOS_STMT *stmt, int *nums) { pStmt->exec.pRequest->body.pDag = NULL; } - *nums = (pStmt->sql.pQueryPlan->pPlaceholderValues) ? pStmt->sql.pQueryPlan->pPlaceholderValues->length : 0; + *nums = taosArrayGetSize(pStmt->sql.pQueryPlan->pPlaceholderValues); } else { STMT_ERR_RET(stmtFetchColFields(stmt, nums, NULL)); } diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index b03947e2ca981bb963f14e5db23be380e59083a0..698c0cc4e7b712225cb97c01e608586abba027a7 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -68,6 +68,7 @@ struct tmq_conf_t { char* pass; char* db; tmq_commit_cb* commitCb; + void* commitCbUserParam; }; struct tmq_t { @@ -78,7 +79,8 @@ struct tmq_t { int32_t autoCommitInterval; int32_t resetOffsetCfg; int64_t consumerId; - tmq_commit_cb* commit_cb; + tmq_commit_cb* commitCb; + void* commitCbUserParam; // status int8_t status; @@ -372,10 +374,18 @@ int32_t tmqSubscribeCb(void* param, const SDataBuf* pMsg, int32_t code) { int32_t tmqCommitCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqCommitCbParam* pParam = (SMqCommitCbParam*)param; pParam->rspErr = code == 0 ? TMQ_RESP_ERR__SUCCESS : TMQ_RESP_ERR__FAIL; - if (pParam->tmq->commit_cb) { - pParam->tmq->commit_cb(pParam->tmq, pParam->rspErr, NULL); + if (pParam->tmq->commitCb) { + pParam->tmq->commitCb(pParam->tmq, pParam->rspErr, NULL, pParam->tmq->commitCbUserParam); + } + if (!pParam->async) + tsem_post(&pParam->rspSem); + else { + tsem_destroy(&pParam->rspSem); + /*if (pParam->pArray) {*/ + /*taosArrayDestroy(pParam->pArray);*/ + /*}*/ + taosMemoryFree(pParam); } - if (!pParam->async) tsem_post(&pParam->rspSem); return 0; } @@ -384,7 +394,7 @@ tmq_resp_err_t tmq_subscription(tmq_t* tmq, tmq_list_t** topics) { *topics = tmq_list_new(); } for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { - SMqClientTopic* topic = taosArrayGetP(tmq->clientTopics, i); + SMqClientTopic* topic = taosArrayGet(tmq->clientTopics, i); tmq_list_append(*topics, topic->topicName); } return TMQ_RESP_ERR__SUCCESS; @@ -477,7 +487,8 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { strcpy(pTmq->groupId, conf->groupId); pTmq->autoCommit = conf->autoCommit; pTmq->autoCommitInterval = conf->autoCommitInterval; - pTmq->commit_cb = conf->commitCb; + pTmq->commitCb = conf->commitCb; + pTmq->commitCbUserParam = conf->commitCbUserParam; pTmq->resetOffsetCfg = conf->resetOffset; // assign consumerId @@ -557,7 +568,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in tscError("failed to malloc request"); } - SMqCommitCbParam* pParam = taosMemoryMalloc(sizeof(SMqCommitCbParam)); + SMqCommitCbParam* pParam = taosMemoryCalloc(1, sizeof(SMqCommitCbParam)); if (pParam == NULL) { return -1; } @@ -572,6 +583,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in }; SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest); + sendInfo->requestObjRefId = 0; sendInfo->param = pParam; sendInfo->fp = tmqCommitCb; SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); @@ -582,13 +594,12 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in if (!async) { tsem_wait(&pParam->rspSem); resp = pParam->rspErr; - } - - tsem_destroy(&pParam->rspSem); - taosMemoryFree(pParam); + tsem_destroy(&pParam->rspSem); + taosMemoryFree(pParam); - if (pArray) { - taosArrayDestroy(pArray); + if (pArray) { + taosArrayDestroy(pArray); + } } return resp; @@ -667,7 +678,7 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { if (code != 0) goto FAIL; while (TSDB_CODE_MND_CONSUMER_NOT_READY == tmqAskEp(tmq, false)) { - tscDebug("not ready, retry"); + tscDebug("consumer not ready, retry"); taosMsleep(500); } @@ -688,11 +699,13 @@ FAIL: return code; } -void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) { +void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb, void* param) { // conf->commitCb = cb; + conf->commitCbUserParam = param; } +#if 0 TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) { STscObj* pTscObj = (STscObj*)taos; SRequestObj* pRequest = NULL; @@ -739,7 +752,7 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa .sql = (char*)sql, }; tNameExtractFullName(&name, req.name); - strcpy(req.outputSTbName, tbName); + strcpy(req.targetStbFullName, tbName); int tlen = tSerializeSCMCreateStreamReq(NULL, 0, &req); void* buf = taosMemoryMalloc(tlen); @@ -777,6 +790,7 @@ _return: return pRequest; } +#endif #if 0 int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) { @@ -1304,10 +1318,10 @@ const char* tmq_err2str(tmq_resp_err_t err) { return "fail"; } -char* tmq_get_topic_name(TAOS_RES* res) { +const char* tmq_get_topic_name(TAOS_RES* res) { if (TD_RES_TMQ(res)) { SMqRspObj* pRspObj = (SMqRspObj*)res; - return pRspObj->topic; + return strchr(pRspObj->topic, '.') + 1; } else { return NULL; } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 8e8c62cd946562d26ef5d3062683fc2f9c5bdc10..287422012197135a4b3013b0187c4fda231b783a 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -659,10 +659,15 @@ TEST(testCase, agg_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); - TAOS_RES* pRes = taos_query(pConn, "use abc1"); + TAOS_RES* pRes = taos_query(pConn, "use db"); + if (taos_errno(pRes) != 0) { + printf("failed to use db, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } taos_free_result(pRes); - pRes = taos_query(pConn, "select now() from m1"); + pRes = taos_query(pConn, "select tbname from st1"); if (taos_errno(pRes) != 0) { printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); diff --git a/source/common/src/systable.c b/source/common/src/systable.c new file mode 100644 index 0000000000000000000000000000000000000000..51f924280ae2447aa2de50ecda78bd661857e67d --- /dev/null +++ b/source/common/src/systable.c @@ -0,0 +1,340 @@ +/* + * 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 "systable.h" +#include "tdef.h" +#include "types.h" +#include "taos.h" + +#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE) +#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE) +#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE) + +static const SSysDbTableSchema dnodesSchema[] = { + {.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "max_vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema mnodesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema modulesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = 134 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "module", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema qnodesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema snodesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema bnodesSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema clusterSchema[] = { + {.name = "id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema userDBSchema[] = { + {.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "ntables", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "replica", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "strict", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "duration", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "keep", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "buffer", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "pagesize", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "pages", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "minrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "maxrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "wal", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "fsync", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "precision", .bytes = 2 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "single_stable", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + // {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update +}; + +static const SSysDbTableSchema userFuncSchema[] = { + {.name = "name", .bytes = TSDB_FUNC_NAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "comment", .bytes = PATH_MAX - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "aggregate", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "output_type", .bytes = TSDB_TYPE_STR_MAX_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "code_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "bufsize", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; + +static const SSysDbTableSchema userIdxSchema[] = { + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_database", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "column_name", .bytes = SYSTABLE_SCH_COL_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema userStbsSchema[] = { + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema userStreamsSchema[] = { + {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema userTblsSchema[] = { + {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.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 = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema userTblDistSchema[] = { + {.name = "db_name", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "distributed_histogram", .bytes = 500 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "min_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "max_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "avg_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "stddev_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "rows", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "storage_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "compression_ratio", .bytes = 8, .type = TSDB_DATA_TYPE_DOUBLE}, + {.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; + +static const SSysDbTableSchema userUsersSchema[] = { + {.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema grantsSchema[] = { + {.name = "version", .bytes = 8 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "expire time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "storage(GB)", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "databases", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "users", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "accounts", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "connections", .bytes = 11 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "streams", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "cpu cores", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "speed(PPS)", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "querytime", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema vgroupsSchema[] = { + {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v1_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v1_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "v2_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v2_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "v3_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "v3_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "nfiles", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; + +static const SSysDbTableSchema smaSchema[] = { + {.name = "sma_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema transSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "stage", .bytes = TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "type", .bytes = TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "last_error", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema configSchema[] = { + {.name = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "value", .bytes = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysTableMeta infosMeta[] = { + {TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema)}, + {TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)}, + {TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)}, + {TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)}, + {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, + {TSDB_INS_TABLE_BNODES, bnodesSchema, tListLen(bnodesSchema)}, + {TSDB_INS_TABLE_CLUSTER, clusterSchema, tListLen(clusterSchema)}, + {TSDB_INS_TABLE_USER_DATABASES, userDBSchema, tListLen(userDBSchema)}, + {TSDB_INS_TABLE_USER_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema)}, + {TSDB_INS_TABLE_USER_INDEXES, userIdxSchema, tListLen(userIdxSchema)}, + {TSDB_INS_TABLE_USER_STABLES, userStbsSchema, tListLen(userStbsSchema)}, + {TSDB_INS_TABLE_USER_STREAMS, userStreamsSchema, tListLen(userStreamsSchema)}, + {TSDB_INS_TABLE_USER_TABLES, userTblsSchema, tListLen(userTblsSchema)}, + {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, + {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, + {TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)}, + {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, + {TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema)}, +}; + +static const SSysDbTableSchema connectionsSchema[] = { + {.name = "conn_id", .bytes = 4, .type = TSDB_DATA_TYPE_UINT}, + {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "program", .bytes = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "end_point", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "login_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "last_access", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema topicSchema[] = { + {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + // TODO config +}; + +static const SSysDbTableSchema consumerSchema[] = { + {.name = "consumer_id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "app_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "topics", .bytes = TSDB_SHOW_LIST_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "end_point", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "subscribe_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "rebalance_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SSysDbTableSchema subscriptionSchema[] = { + {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "consumer_id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, +}; + +static const SSysDbTableSchema offsetSchema[] = { + {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "committed_offset", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "current_offset", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "skip_log_cnt", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, +}; + +static const SSysDbTableSchema querySchema[] = { + {.name = "query_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "connId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "end_point", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "qid", .bytes = 22 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "time", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "sql_obj_id", .bytes = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "ep", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "stable_query", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL}, + {.name = "sub_queries", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "sub_query_info", .bytes = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema streamSchema[] = { + {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "source_db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "target_db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "target_table", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "watermark", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "trigger", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, +}; + +static const SSysTableMeta perfsMeta[] = { + {TSDB_PERFS_TABLE_CONNECTIONS, connectionsSchema, tListLen(connectionsSchema)}, + {TSDB_PERFS_TABLE_QUERIES, querySchema, tListLen(querySchema)}, + {TSDB_PERFS_TABLE_TOPICS, topicSchema, tListLen(topicSchema)}, + {TSDB_PERFS_TABLE_CONSUMERS, consumerSchema, tListLen(consumerSchema)}, + {TSDB_PERFS_TABLE_SUBSCRIPTIONS, subscriptionSchema, tListLen(subscriptionSchema)}, + {TSDB_PERFS_TABLE_OFFSETS, offsetSchema, tListLen(offsetSchema)}, + {TSDB_PERFS_TABLE_TRANS, transSchema, tListLen(transSchema)}, + {TSDB_PERFS_TABLE_SMAS, smaSchema, tListLen(smaSchema)}, + {TSDB_PERFS_TABLE_STREAMS, streamSchema, tListLen(streamSchema)}, +}; + +void getInfosDbMeta(const SSysTableMeta** pInfosTableMeta, size_t* size) { + *pInfosTableMeta = infosMeta; + *size = tListLen(infosMeta); +} + +void getPerfDbMeta(const SSysTableMeta** pPerfsTableMeta, size_t* size) { + *pPerfsTableMeta = perfsMeta; + *size = tListLen(perfsMeta); +} diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 63e009ed0a452286216f6244273aaf407d25f598..4a6fef4626b3be0751c87b7a68a48a9aa2eaf063 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -225,12 +225,16 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co // Handle the bitmap char* p = taosMemoryRealloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * (numOfRow1 + numOfRow2)); if (p == NULL) { - // TODO + return TSDB_CODE_OUT_OF_MEMORY; } pColumnInfoData->varmeta.offset = (int32_t*)p; for (int32_t i = 0; i < numOfRow2; ++i) { - pColumnInfoData->varmeta.offset[i + numOfRow1] = pSource->varmeta.offset[i] + pColumnInfoData->varmeta.length; + if (pSource->varmeta.offset[i] == -1) { + pColumnInfoData->varmeta.offset[i + numOfRow1] = -1; + } else { + pColumnInfoData->varmeta.offset[i + numOfRow1] = pSource->varmeta.offset[i] + pColumnInfoData->varmeta.length; + } } // copy data @@ -239,7 +243,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co if (pColumnInfoData->varmeta.allocLen < len + oldLen) { char* tmp = taosMemoryRealloc(pColumnInfoData->pData, len + oldLen); if (tmp == NULL) { - return TSDB_CODE_VND_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; } pColumnInfoData->pData = tmp; @@ -486,7 +490,7 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3 SColumnInfoData* pDstCol = taosArrayGet(pDst->pDataBlock, i); for (int32_t j = startIndex; j < (startIndex + rowCount); ++j) { - bool isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg); + bool isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg[i]); char* p = colDataGetData(pColData, j); colDataAppend(pDstCol, j - startIndex, p, isNull); @@ -698,8 +702,8 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) { SColumnInfoData* pColInfoData = pOrder->pColData; // TARRAY_GET_ELEM(pDataBlock->pDataBlock, pOrder->colIndex); if (pColInfoData->hasNull) { - bool leftNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, left, pDataBlock->pBlockAgg); - bool rightNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, right, pDataBlock->pBlockAgg); + bool leftNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, left, NULL); + bool rightNull = colDataIsNull(pColInfoData, pDataBlock->info.rows, right, NULL); if (leftNull && rightNull) { continue; // continue to next slot } @@ -738,7 +742,7 @@ static int32_t doAssignOneTuple(SColumnInfoData* pDstCols, int32_t numOfRows, co SColumnInfoData* pDst = &pDstCols[i]; SColumnInfoData* pSrc = taosArrayGet(pSrcBlock->pDataBlock, i); - if (pSrc->hasNull && colDataIsNull(pSrc, pSrcBlock->info.rows, tupleIndex, pSrcBlock->pBlockAgg)) { + if (pSrc->hasNull && colDataIsNull(pSrc, pSrcBlock->info.rows, tupleIndex, pSrcBlock->pBlockAgg[i])) { code = colDataAppend(pDst, numOfRows, NULL, true); if (code != TSDB_CODE_SUCCESS) { return code; diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 2ed08ac81fda23e1ef12a95d840e1e4eb7043c3e..df598046e19123d00a2859b13759027d8e54cd44 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -87,7 +87,7 @@ int tdEncodeSchema(void **buf, STSchema *pSchema) { for (int i = 0; i < schemaNCols(pSchema); i++) { STColumn *pCol = schemaColAt(pSchema, i); tlen += taosEncodeFixedI8(buf, colType(pCol)); - tlen += taosEncodeFixedI8(buf, colSma(pCol)); + tlen += taosEncodeFixedI8(buf, colFlags(pCol)); tlen += taosEncodeFixedI16(buf, colColId(pCol)); tlen += taosEncodeFixedI16(buf, colBytes(pCol)); } @@ -110,14 +110,14 @@ void *tdDecodeSchema(void *buf, STSchema **pRSchema) { for (int i = 0; i < numOfCols; i++) { col_type_t type = 0; - int8_t sma = 0; + int8_t flags = 0; col_id_t colId = 0; col_bytes_t bytes = 0; buf = taosDecodeFixedI8(buf, &type); - buf = taosDecodeFixedI8(buf, &sma); + buf = taosDecodeFixedI8(buf, &flags); buf = taosDecodeFixedI16(buf, &colId); buf = taosDecodeFixedI32(buf, &bytes); - if (tdAddColToSchema(&schemaBuilder, type, sma, colId, bytes) < 0) { + if (tdAddColToSchema(&schemaBuilder, type, flags, colId, bytes) < 0) { tdDestroyTSchemaBuilder(&schemaBuilder); return NULL; } @@ -153,7 +153,7 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) { pBuilder->version = version; } -int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t sma, col_id_t colId, col_bytes_t bytes) { +int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, col_id_t colId, col_bytes_t bytes) { if (!isValidDataType(type)) return -1; if (pBuilder->nCols >= pBuilder->tCols) { @@ -166,7 +166,7 @@ int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t sma, col STColumn *pCol = &(pBuilder->columns[pBuilder->nCols]); colSetType(pCol, type); colSetColId(pCol, colId); - colSetSma(pCol, sma); + colSetFlags(pCol, flags); if (pBuilder->nCols == 0) { colSetOffset(pCol, 0); } else { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 8c1cfa510129fba002f832c4938c0418e0cc26df..874e09b40326f43d0c6944e37a1e66c44fe6ceab 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -490,21 +490,6 @@ int32_t tDeserializeSClientHbBatchRsp(void *buf, int32_t bufLen, SClientHbBatchR return 0; } -int32_t tSerializeSVDropTbReq(void **buf, SVDropTbReq *pReq) { - int32_t tlen = 0; - tlen += taosEncodeFixedI64(buf, pReq->ver); - tlen += taosEncodeString(buf, pReq->name); - tlen += taosEncodeFixedU8(buf, pReq->type); - return tlen; -} - -void *tDeserializeSVDropTbReq(void *buf, SVDropTbReq *pReq) { - buf = taosDecodeFixedI64(buf, &pReq->ver); - buf = taosDecodeString(buf, &pReq->name); - buf = taosDecodeFixedU8(buf, &pReq->type); - return buf; -} - int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -1676,27 +1661,24 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfVgroups) < 0) return -1; - if (tEncodeI32(&encoder, pReq->cacheBlockSize) < 0) return -1; - if (tEncodeI32(&encoder, pReq->totalBlocks) < 0) return -1; + if (tEncodeI32(&encoder, pReq->numOfStables) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1; if (tEncodeI32(&encoder, pReq->minRows) < 0) return -1; if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1; - if (tEncodeI32(&encoder, pReq->commitTime) < 0) return -1; if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; - if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1; if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->precision) < 0) return -1; 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->update) < 0) return -1; if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1; - if (tEncodeI8(&encoder, pReq->streamMode) < 0) return -1; - if (tEncodeI8(&encoder, pReq->singleSTable) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1; for (int32_t i = 0; i < pReq->numOfRetensions; ++i) { SRetention *pRetension = taosArrayGet(pReq->pRetensions, i); @@ -1719,27 +1701,24 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfVgroups) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->cacheBlockSize) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->totalBlocks) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->numOfStables) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1; if (tDecodeI32(&decoder, &pReq->minRows) < 0) return -1; if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->commitTime) < 0) return -1; if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1; if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1; 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->update) < 0) return -1; if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->streamMode) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->singleSTable) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1; pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention)); if (pReq->pRetensions == NULL) { @@ -1776,7 +1755,10 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; - if (tEncodeI32(&encoder, pReq->totalBlocks) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1; @@ -1798,7 +1780,10 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) { if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->totalBlocks) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1; @@ -2153,24 +2138,23 @@ int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeI32(&encoder, pRsp->numOfVgroups) < 0) return -1; - if (tEncodeI32(&encoder, pRsp->cacheBlockSize) < 0) return -1; - if (tEncodeI32(&encoder, pRsp->totalBlocks) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->numOfStables) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->buffer) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->pageSize) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->pages) < 0) return -1; if (tEncodeI32(&encoder, pRsp->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pRsp->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pRsp->daysToKeep1) < 0) return -1; if (tEncodeI32(&encoder, pRsp->daysToKeep2) < 0) return -1; if (tEncodeI32(&encoder, pRsp->minRows) < 0) return -1; if (tEncodeI32(&encoder, pRsp->maxRows) < 0) return -1; - if (tEncodeI32(&encoder, pRsp->commitTime) < 0) return -1; if (tEncodeI32(&encoder, pRsp->fsyncPeriod) < 0) return -1; if (tEncodeI8(&encoder, pRsp->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pRsp->precision) < 0) return -1; 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->update) < 0) return -1; if (tEncodeI8(&encoder, pRsp->cacheLastRow) < 0) return -1; - if (tEncodeI8(&encoder, pRsp->streamMode) < 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); @@ -2192,24 +2176,23 @@ int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) { if (tStartDecode(&decoder) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->numOfVgroups) < 0) return -1; - if (tDecodeI32(&decoder, &pRsp->cacheBlockSize) < 0) return -1; - if (tDecodeI32(&decoder, &pRsp->totalBlocks) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->numOfStables) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->buffer) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->pageSize) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->pages) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->daysToKeep1) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->daysToKeep2) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->minRows) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->maxRows) < 0) return -1; - if (tDecodeI32(&decoder, &pRsp->commitTime) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->fsyncPeriod) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->precision) < 0) return -1; 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->update) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->cacheLastRow) < 0) return -1; - if (tDecodeI8(&decoder, &pRsp->streamMode) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->numOfRetensions) < 0) return -1; pRsp->pRetensions = taosArrayInit(pRsp->numOfRetensions, sizeof(SRetention)); if (pRsp->pRetensions == NULL) { @@ -2368,7 +2351,6 @@ static int32_t tEncodeSTableMetaRsp(SCoder *pEncoder, STableMetaRsp *pRsp) { if (tEncodeI32(pEncoder, pRsp->numOfColumns) < 0) return -1; if (tEncodeI8(pEncoder, pRsp->precision) < 0) return -1; if (tEncodeI8(pEncoder, pRsp->tableType) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->update) < 0) return -1; if (tEncodeI32(pEncoder, pRsp->sversion) < 0) return -1; if (tEncodeI32(pEncoder, pRsp->tversion) < 0) return -1; if (tEncodeU64(pEncoder, pRsp->suid) < 0) return -1; @@ -2391,7 +2373,6 @@ static int32_t tDecodeSTableMetaRsp(SCoder *pDecoder, STableMetaRsp *pRsp) { if (tDecodeI32(pDecoder, &pRsp->numOfColumns) < 0) return -1; if (tDecodeI8(pDecoder, &pRsp->precision) < 0) return -1; if (tDecodeI8(pDecoder, &pRsp->tableType) < 0) return -1; - if (tDecodeI8(pDecoder, &pRsp->update) < 0) return -1; if (tDecodeI32(pDecoder, &pRsp->sversion) < 0) return -1; if (tDecodeI32(pDecoder, &pRsp->tversion) < 0) return -1; if (tDecodeU64(pDecoder, &pRsp->suid) < 0) return -1; @@ -2811,15 +2792,16 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; if (tEncodeI64(&encoder, pReq->dbUid) < 0) return -1; if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1; - if (tEncodeI32(&encoder, pReq->cacheBlockSize) < 0) return -1; - if (tEncodeI32(&encoder, pReq->totalBlocks) < 0) return -1; + if (tEncodeI32(&encoder, pReq->numOfStables) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1; if (tEncodeI32(&encoder, pReq->minRows) < 0) return -1; if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1; - if (tEncodeI32(&encoder, pReq->commitTime) < 0) return -1; if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; if (tEncodeU32(&encoder, pReq->hashBegin) < 0) return -1; if (tEncodeU32(&encoder, pReq->hashEnd) < 0) return -1; @@ -2828,11 +2810,9 @@ 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->update) < 0) return -1; if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; if (tEncodeI8(&encoder, pReq->replica) < 0) return -1; if (tEncodeI8(&encoder, pReq->selfIndex) < 0) return -1; - if (tEncodeI8(&encoder, pReq->streamMode) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { SReplica *pReplica = &pReq->replicas[i]; if (tEncodeSReplica(&encoder, pReplica) < 0) return -1; @@ -2862,15 +2842,16 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; if (tDecodeI64(&decoder, &pReq->dbUid) < 0) return -1; if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->cacheBlockSize) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->totalBlocks) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->numOfStables) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1; if (tDecodeI32(&decoder, &pReq->minRows) < 0) return -1; if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->commitTime) < 0) return -1; if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; if (tDecodeU32(&decoder, &pReq->hashBegin) < 0) return -1; if (tDecodeU32(&decoder, &pReq->hashEnd) < 0) return -1; @@ -2879,11 +2860,9 @@ 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->update) < 0) return -1; if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1; if (tDecodeI8(&decoder, &pReq->selfIndex) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->streamMode) < 0) return -1; for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { SReplica *pReplica = &pReq->replicas[i]; if (tDecodeSReplica(&decoder, pReplica) < 0) return -1; @@ -2983,10 +2962,14 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq if (tStartEncode(&encoder) < 0) return -1; if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1; - if (tEncodeI32(&encoder, pReq->totalBlocks) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep0) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep1) < 0) return -1; if (tEncodeI32(&encoder, pReq->daysToKeep2) < 0) return -1; + 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; @@ -3010,10 +2993,14 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR if (tStartDecode(&decoder) < 0) return -1; if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->totalBlocks) < 0) return -1; + 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->daysPerFile) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep0) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep1) < 0) return -1; if (tDecodeI32(&decoder, &pReq->daysToKeep2) < 0) return -1; + 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; @@ -3569,10 +3556,12 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; - if (tEncodeCStr(&encoder, pReq->outputSTbName) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->targetStbFullName) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; if (tEncodeI32(&encoder, sqlLen) < 0) return -1; if (tEncodeI32(&encoder, astLen) < 0) return -1; + if (tEncodeI8(&encoder, pReq->triggerType) < 0) return -1; + if (tEncodeI64(&encoder, pReq->watermark) < 0) return -1; if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1; if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1; @@ -3592,7 +3581,7 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; - if (tDecodeCStrTo(&decoder, pReq->outputSTbName) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->targetStbFullName) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; if (tDecodeI32(&decoder, &sqlLen) < 0) return -1; if (tDecodeI32(&decoder, &astLen) < 0) return -1; @@ -3621,6 +3610,43 @@ void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { taosMemoryFreeClear(pReq->ast); } +int32_t tEncodeSRSmaParam(SCoder *pCoder, const SRSmaParam *pRSmaParam) { + if (tEncodeFloat(pCoder, pRSmaParam->xFilesFactor) < 0) return -1; + if (tEncodeI32v(pCoder, pRSmaParam->delay) < 0) return -1; + if (tEncodeI32v(pCoder, pRSmaParam->qmsg1Len) < 0) return -1; + if (tEncodeI32v(pCoder, pRSmaParam->qmsg2Len) < 0) return -1; + if (pRSmaParam->qmsg1Len > 0) { + if (tEncodeBinary(pCoder, pRSmaParam->qmsg1, (uint64_t)pRSmaParam->qmsg1Len) < 0) // qmsg1Len contains len of '\0' + return -1; + } + if (pRSmaParam->qmsg2Len > 0) { + if (tEncodeBinary(pCoder, pRSmaParam->qmsg2, (uint64_t)pRSmaParam->qmsg2Len) < 0) // qmsg2Len contains len of '\0' + return -1; + } + + return 0; +} + +int32_t tDecodeSRSmaParam(SCoder *pCoder, SRSmaParam *pRSmaParam) { + if (tDecodeFloat(pCoder, &pRSmaParam->xFilesFactor) < 0) return -1; + if (tDecodeI32v(pCoder, &pRSmaParam->delay) < 0) return -1; + if (tDecodeI32v(pCoder, &pRSmaParam->qmsg1Len) < 0) return -1; + if (tDecodeI32v(pCoder, &pRSmaParam->qmsg2Len) < 0) return -1; + if (pRSmaParam->qmsg1Len > 0) { + uint64_t len; + if (tDecodeBinaryAlloc(pCoder, (void **)&pRSmaParam->qmsg1, &len) < 0) return -1; // qmsg1Len contains len of '\0' + } else { + pRSmaParam->qmsg1 = NULL; + } + if (pRSmaParam->qmsg2Len > 0) { + uint64_t len; + if (tDecodeBinaryAlloc(pCoder, (void **)&pRSmaParam->qmsg2, &len) < 0) return -1; // qmsg2Len contains len of '\0' + } else { + pRSmaParam->qmsg2 = NULL; + } + return 0; +} + int tEncodeSVCreateStbReq(SCoder *pCoder, const SVCreateStbReq *pReq) { if (tStartEncode(pCoder) < 0) return -1; @@ -3629,9 +3655,9 @@ int tEncodeSVCreateStbReq(SCoder *pCoder, const SVCreateStbReq *pReq) { if (tEncodeI8(pCoder, pReq->rollup) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pReq->schema) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1; - // if (pReq->rollup) { - // if (tEncodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1; - // } + if (pReq->rollup) { + if (tEncodeSRSmaParam(pCoder, &pReq->pRSmaParam) < 0) return -1; + } tEndEncode(pCoder); return 0; @@ -3645,9 +3671,9 @@ int tDecodeSVCreateStbReq(SCoder *pCoder, SVCreateStbReq *pReq) { if (tDecodeI8(pCoder, &pReq->rollup) < 0) return -1; if (tDecodeSSchemaWrapper(pCoder, &pReq->schema) < 0) return -1; if (tDecodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1; - // if (pReq->rollup) { - // if (tDecodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1; - // } + if (pReq->rollup) { + if (tDecodeSRSmaParam(pCoder, &pReq->pRSmaParam) < 0) return -1; + } tEndDecode(pCoder); return 0; @@ -3769,4 +3795,120 @@ int tDecodeSVCreateTbRsp(SCoder *pCoder, SVCreateTbRsp *pRsp) { tEndDecode(pCoder); return 0; -} \ No newline at end of file +} + +// TDMT_VND_DROP_TABLE ================= +static int32_t tEncodeSVDropTbReq(SCoder *pCoder, const SVDropTbReq *pReq) { + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeCStr(pCoder, pReq->name) < 0) return -1; + if (tEncodeI8(pCoder, pReq->igNotExists) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +static int32_t tDecodeSVDropTbReq(SCoder *pCoder, SVDropTbReq *pReq) { + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1; + if (tDecodeI8(pCoder, &pReq->igNotExists) < 0) return -1; + + tEndDecode(pCoder); + return 0; +} + +static int32_t tEncodeSVDropTbRsp(SCoder *pCoder, const SVDropTbRsp *pReq) { + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeI32(pCoder, pReq->code) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +static int32_t tDecodeSVDropTbRsp(SCoder *pCoder, SVDropTbRsp *pReq) { + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeI32(pCoder, &pReq->code) < 0) return -1; + + tEndDecode(pCoder); + return 0; +} + +int32_t tEncodeSVDropTbBatchReq(SCoder *pCoder, const SVDropTbBatchReq *pReq) { + int32_t nReqs = taosArrayGetSize(pReq->pArray); + SVDropTbReq *pDropTbReq; + + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeI32v(pCoder, nReqs) < 0) return -1; + for (int iReq = 0; iReq < nReqs; iReq++) { + pDropTbReq = (SVDropTbReq *)taosArrayGet(pReq->pArray, iReq); + if (tEncodeSVDropTbReq(pCoder, pDropTbReq) < 0) return -1; + } + + tEndEncode(pCoder); + return 0; +} + +int32_t tDecodeSVDropTbBatchReq(SCoder *pCoder, SVDropTbBatchReq *pReq) { + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeI32v(pCoder, &pReq->nReqs) < 0) return -1; + pReq->pReqs = (SVDropTbReq *)tCoderMalloc(pCoder, sizeof(SVDropTbReq) * pReq->nReqs); + if (pReq->pReqs == NULL) return -1; + for (int iReq = 0; iReq < pReq->nReqs; iReq++) { + if (tDecodeSVDropTbReq(pCoder, pReq->pReqs + iReq) < 0) return -1; + } + + tEndDecode(pCoder); + return 0; +} + +int32_t tEncodeSVDropTbBatchRsp(SCoder *pCoder, const SVDropTbBatchRsp *pRsp) { + int32_t nRsps = taosArrayGetSize(pRsp->pArray); + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeI32v(pCoder, nRsps) < 0) return -1; + for (int iRsp = 0; iRsp < nRsps; iRsp++) { + if (tEncodeSVDropTbRsp(pCoder, (SVDropTbRsp *)taosArrayGet(pRsp->pArray, iRsp)) < 0) return -1; + } + + tEndEncode(pCoder); + return 0; +} + +int32_t tDecodeSVDropTbBatchRsp(SCoder *pCoder, SVDropTbBatchRsp *pRsp) { + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeI32v(pCoder, &pRsp->nRsps) < 0) return -1; + pRsp->pRsps = (SVDropTbRsp *)tCoderMalloc(pCoder, sizeof(SVDropTbRsp) * pRsp->nRsps); + if (pRsp->pRsps == NULL) return -1; + for (int iRsp = 0; iRsp < pRsp->nRsps; iRsp++) { + if (tDecodeSVDropTbRsp(pCoder, pRsp->pRsps + iRsp) < 0) return -1; + } + + tEndDecode(pCoder); + return 0; +} + +int32_t tEncodeSVDropStbReq(SCoder *pCoder, const SVDropStbReq *pReq) { + if (tStartEncode(pCoder) < 0) return -1; + + if (tEncodeCStr(pCoder, pReq->name) < 0) return -1; + if (tEncodeI64(pCoder, pReq->suid) < 0) return -1; + + tEndEncode(pCoder); + return 0; +} + +int32_t tDecodeSVDropStbReq(SCoder *pCoder, SVDropStbReq *pReq) { + if (tStartDecode(pCoder) < 0) return -1; + + if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1; + if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1; + + tEndDecode(pCoder); + return 0; +} diff --git a/source/common/src/trow.c b/source/common/src/trow.c index c73f26e6dab78828965788e78a21ece9231d9aff..7157c1e0f0c2ec3953eacc73d07ae979b6b694b7 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -220,7 +220,7 @@ static uint8_t tdGetMergedBitmapByte(uint8_t byte) { } /** - * @brief Merge bitmap from 2 bits to 1 bits, and the memory buffer should be guaranteed by the invoker. + * @brief Merge bitmap from 2 bits to 1 bit, and the memory buffer should be guaranteed by the invoker. * * @param srcBitmap * @param nBits diff --git a/source/dnode/mgmt/implement/src/dmTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c index 7abf5d65cd2e00a4caad9a9abb357b96e4f9a3db..1dabc83f57738cb7b32c86ac70fdd5657061eec6 100644 --- a/source/dnode/mgmt/implement/src/dmTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -72,6 +72,7 @@ static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSe NodeMsgFp msgFp = NULL; uint16_t msgType = pRpc->msgType; bool needRelease = false; + bool isReq = msgType & 1U; if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { dmSetMnodeEpSet(pWrapper->pDnode, pEpSet); @@ -85,13 +86,13 @@ static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSe if (dmBuildMsg(pMsg, pRpc) != 0) goto _OVER; if (pWrapper->procType == DND_PROC_SINGLE) { - dTrace("msg:%p, is created, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, pMsg->user); + dTrace("msg:%p, created, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, pMsg->user); code = (*msgFp)(pWrapper, pMsg); } else if (pWrapper->procType == DND_PROC_PARENT) { - dTrace("msg:%p, is created and put into child queue, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), - pRpc->handle, pMsg->user); - code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle, - pRpc->refId, PROC_FUNC_REQ); + dTrace("msg:%p, created and put into child queue, type:%s handle:%p code:0x%04x user:%s contLen:%d", pMsg, + TMSG_INFO(msgType), pRpc->handle, pMsg->rpcMsg.code & 0XFFFF, pMsg->user, pRpc->contLen); + code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, + (isReq && (pMsg->rpcMsg.code == 0)) ? pRpc->handle : NULL, pRpc->refId, PROC_FUNC_REQ); } else { dTrace("msg:%p, should not processed in child process, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); ASSERT(1); @@ -100,12 +101,13 @@ static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSe _OVER: if (code == 0) { if (pWrapper->procType == DND_PROC_PARENT) { - dTrace("msg:%p, is freed in parent process", pMsg); + dTrace("msg:%p, freed in parent process", pMsg); taosFreeQitem(pMsg); rpcFreeCont(pRpc->pCont); } } else { - dError("msg:%p, type:%s failed to process since 0x%04x:%s", pMsg, TMSG_INFO(msgType), code & 0XFFFF, terrstr()); + dError("msg:%p, type:%s handle:%p failed to process since 0x%04x:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, + code & 0XFFFF, terrstr()); if (msgType & 1U) { if (terrno != 0) code = terrno; if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) { @@ -254,8 +256,17 @@ static void dmSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) { epSet.eps[i].port = htons(epSet.eps[i].port); } - - rpcSendRedirectRsp(pReq->handle, &epSet); + SRpcMsg resp; + SMEpSet msg = {.epSet = epSet}; + int32_t len = tSerializeSMEpSet(NULL, 0, &msg); + resp.pCont = rpcMallocCont(len); + resp.contLen = len; + tSerializeSMEpSet(resp.pCont, len, &msg); + + resp.code = TSDB_CODE_RPC_REDIRECT; + resp.handle = pReq->handle; + resp.refId = pReq->refId; + rpcSendResponse(&resp); } static inline void dmSendRpcRsp(SDnode *pDnode, const SRpcMsg *pRsp) { @@ -359,29 +370,31 @@ static void dmConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t static void dmConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, EProcFuncType ftype) { + int32_t code = pMsg->code & 0xFFFF; pMsg->pCont = pCont; - dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle, - pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle); - - switch (ftype) { - case PROC_FUNC_REGIST: - rpcRegisterBrokenLinkArg(pMsg); - break; - case PROC_FUNC_RELEASE: - taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); - rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); - rpcFreeCont(pCont); - break; - case PROC_FUNC_REQ: - dmSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); - break; - case PROC_FUNC_RSP: - pMsg->refId = taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); - dmSendRpcRsp(pWrapper->pDnode, pMsg); - break; - default: - break; + + if (ftype == PROC_FUNC_REQ) { + dTrace("msg:%p, get from parent queue, send req:%s handle:%p code:0x%04x, app:%p", pMsg, TMSG_INFO(pMsg->msgType), + pMsg->handle, code, pMsg->ahandle); + dmSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); + } else if (ftype == PROC_FUNC_RSP) { + dTrace("msg:%p, get from parent queue, rsp handle:%p code:0x%04x, app:%p", pMsg, pMsg->handle, code, pMsg->ahandle); + pMsg->refId = taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); + dmSendRpcRsp(pWrapper->pDnode, pMsg); + } else if (ftype == PROC_FUNC_REGIST) { + dTrace("msg:%p, get from parent queue, regist handle:%p code:0x%04x, app:%p", pMsg, pMsg->handle, code, + pMsg->ahandle); + rpcRegisterBrokenLinkArg(pMsg); + } else if (ftype == PROC_FUNC_RELEASE) { + dTrace("msg:%p, get from parent queue, release handle:%p code:0x%04x, app:%p", pMsg, pMsg->handle, code, + pMsg->ahandle); + taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); + rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); + rpcFreeCont(pCont); + } else { + dError("msg:%p, invalid ftype:%d while get from parent queue, handle:%p", pMsg, ftype, pMsg->handle); } + taosMemoryFree(pMsg); } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 185aa071d717b3bbe0a7a047569a479041c668db..b63a7f5b32be3dc86e3119c6161ea47072c66770 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -107,14 +107,14 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pCfg->vgId = pCreate->vgId; strcpy(pCfg->dbname, pCreate->db); - pCfg->szBuf = pCreate->cacheBlockSize * 1024 * 1024; - pCfg->streamMode = pCreate->streamMode; pCfg->isWeak = true; pCfg->tsdbCfg.days = 10; - pCfg->tsdbCfg.keep2 = 3650; // pCreate->daysToKeep0; - pCfg->tsdbCfg.keep0 = 3650; // pCreate->daysToKeep2; - pCfg->tsdbCfg.keep1 = 3650; // pCreate->daysToKeep0; - pCfg->tsdbCfg.retentions = pCreate->pRetensions; + pCfg->tsdbCfg.keep2 = 3650; + pCfg->tsdbCfg.keep0 = 3650; + pCfg->tsdbCfg.keep1 = 3650; + for (size_t i = 0; i < taosArrayGetSize(pCreate->pRetensions); ++i) { + memcpy(&pCfg->tsdbCfg.retentions[i], taosArrayGet(pCreate->pRetensions, i), sizeof(SRetention)); + } pCfg->walCfg.vgId = pCreate->vgId; pCfg->hashBegin = pCreate->hashBegin; pCfg->hashEnd = pCreate->hashEnd; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index bfeec26d237ebdab86863d3557848ac7564c870c..407158283b1998d155c6fa9d4f69249053ec508d 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -268,23 +268,23 @@ static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueTyp int32_t code = 0; switch (qtype) { case QUERY_QUEUE: - dTrace("msg:%p, will be written into vnode-query queue", pMsg); + dTrace("msg:%p, type:%s will be written into vnode-query queue", pMsg, TMSG_INFO(pRpc->msgType)); taosWriteQitem(pVnode->pQueryQ, pMsg); break; case FETCH_QUEUE: - dTrace("msg:%p, will be written into vnode-fetch queue", pMsg); + dTrace("msg:%p, type:%s will be written into vnode-fetch queue", pMsg, TMSG_INFO(pRpc->msgType)); taosWriteQitem(pVnode->pFetchQ, pMsg); break; case WRITE_QUEUE: - dTrace("msg:%p, will be written into vnode-write queue", pMsg); + dTrace("msg:%p, type:%s will be written into vnode-write queue", pMsg, TMSG_INFO(pRpc->msgType)); taosWriteQitem(pVnode->pWriteQ, pMsg); break; case SYNC_QUEUE: - dTrace("msg:%p, will be written into vnode-sync queue", pMsg); + dTrace("msg:%p, type:%s will be written into vnode-sync queue", pMsg, TMSG_INFO(pRpc->msgType)); taosWriteQitem(pVnode->pSyncQ, pMsg); break; case MERGE_QUEUE: - dTrace("msg:%p, will be written into vnode-merge queue", pMsg); + dTrace("msg:%p, type:%s will be written into vnode-merge queue", pMsg, TMSG_INFO(pRpc->msgType)); taosWriteQitem(pVnode->pMergeQ, pMsg); break; default: diff --git a/source/dnode/mgmt/test/vnode/vnode.cpp b/source/dnode/mgmt/test/vnode/vnode.cpp index 51b7d6818fdce72103f830eb4a9ba57c8b335197..769c484c6ae7d57196e70d569493d27ef7212872 100644 --- a/source/dnode/mgmt/test/vnode/vnode.cpp +++ b/source/dnode/mgmt/test/vnode/vnode.cpp @@ -33,22 +33,18 @@ TEST_F(DndTestVnode, 01_Create_Vnode) { strcpy(createReq.db, "1.d1"); createReq.dbUid = 9527; createReq.vgVersion = 1; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; createReq.daysPerFile = 10; createReq.daysToKeep0 = 3650; createReq.daysToKeep1 = 3650; createReq.daysToKeep2 = 3650; createReq.minRows = 100; createReq.minRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replica = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; createReq.selfIndex = 0; for (int r = 0; r < createReq.replica; ++r) { @@ -75,27 +71,15 @@ TEST_F(DndTestVnode, 01_Create_Vnode) { TEST_F(DndTestVnode, 02_Alter_Vnode) { for (int i = 0; i < 3; ++i) { SAlterVnodeReq alterReq = {0}; - alterReq.vgId = 2; - alterReq.dnodeId = 1; - strcpy(alterReq.db, "1.d1"); - alterReq.dbUid = 9527; alterReq.vgVersion = 2; - alterReq.cacheBlockSize = 16; - alterReq.totalBlocks = 10; alterReq.daysPerFile = 10; alterReq.daysToKeep0 = 3650; alterReq.daysToKeep1 = 3650; alterReq.daysToKeep2 = 3650; - alterReq.minRows = 100; - alterReq.minRows = 4096; - alterReq.commitTime = 3600; alterReq.fsyncPeriod = 3000; alterReq.walLevel = 1; - alterReq.precision = 0; - alterReq.compression = 2; alterReq.replica = 1; alterReq.strict = 1; - alterReq.update = 0; alterReq.cacheLastRow = 0; alterReq.selfIndex = 0; for (int r = 0; r < alterReq.replica; ++r) { diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h index 19e202dddc0c56cc7679d7a3d319ab7918e36528..a8bfe91cbf8edfb225510253b9536115b21cea30 100644 --- a/source/dnode/mnode/impl/inc/mndConsumer.h +++ b/source/dnode/mnode/impl/inc/mndConsumer.h @@ -44,6 +44,11 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw); int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer); +bool mndRebTryStart(); +void mndRebEnd(); +void mndRebCntInc(); +void mndRebCntDec(); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 055327570e99a59ccf3c592d75af3465cf49f90b..263fd0bad556bb0404cfc25c390fadbc03ce0520 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -257,26 +257,23 @@ typedef struct { typedef struct { int32_t numOfVgroups; - int32_t cacheBlockSize; - int32_t totalBlocks; + int32_t numOfStables; + int32_t buffer; + int32_t pageSize; + int32_t pages; int32_t daysPerFile; int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; int32_t minRows; int32_t maxRows; - int32_t commitTime; int32_t fsyncPeriod; - int32_t ttl; int8_t walLevel; int8_t precision; int8_t compression; int8_t replications; int8_t strict; - int8_t update; int8_t cacheLastRow; - int8_t streamMode; - int8_t singleSTable; int8_t hashMethod; // default is 1 int32_t numOfRetensions; SArray* pRetensions; @@ -316,7 +313,6 @@ typedef struct { int64_t pointsWritten; int8_t compact; int8_t replica; - int8_t streamMode; SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; } SVgObj; @@ -392,15 +388,12 @@ typedef struct { int8_t type; int8_t replica; int16_t numOfColumns; - int32_t rowSize; int32_t numOfRows; void* pIter; SMnode* pMnode; STableMetaRsp* pMeta; bool sysDbRsp; char db[TSDB_DB_FNAME_LEN]; - int16_t offset[TSDB_MAX_COLUMNS]; - int32_t bytes[TSDB_MAX_COLUMNS]; } SShowObj; typedef struct { @@ -514,24 +507,24 @@ void* tDecodeSMqVgEp(const void* buf, SMqVgEp* pVgEp); typedef struct { int64_t consumerId; // -1 for unassigned SArray* vgs; // SArray -} SMqConsumerEpInSub; +} SMqConsumerEp; -SMqConsumerEpInSub* tCloneSMqConsumerEpInSub(const SMqConsumerEpInSub* pEpInSub); -void tDeleteSMqConsumerEpInSub(SMqConsumerEpInSub* pEpInSub); -int32_t tEncodeSMqConsumerEpInSub(void** buf, const SMqConsumerEpInSub* pEpInSub); -void* tDecodeSMqConsumerEpInSub(const void* buf, SMqConsumerEpInSub* pEpInSub); +SMqConsumerEp* tCloneSMqConsumerEp(const SMqConsumerEp* pEp); +void tDeleteSMqConsumerEp(SMqConsumerEp* pEp); +int32_t tEncodeSMqConsumerEp(void** buf, const SMqConsumerEp* pEp); +void* tDecodeSMqConsumerEp(const void* buf, SMqConsumerEp* pEp); typedef struct { char key[TSDB_SUBSCRIBE_KEY_LEN]; SRWLatch lock; + int64_t dbUid; int32_t vgNum; int8_t subType; int8_t withTbName; int8_t withSchema; int8_t withTag; - SHashObj* consumerHash; // consumerId -> SMqConsumerEpInSub - // TODO put -1 into unassignVgs - // SArray* unassignedVgs; + SHashObj* consumerHash; // consumerId -> SMqConsumerEp + SArray* unassignedVgs; // SArray } SMqSubscribeObj; SMqSubscribeObj* tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]); @@ -542,7 +535,7 @@ void* tDecodeSubscribeObj(const void* buf, SMqSubscribeObj* pSub); typedef struct { int32_t epoch; - SArray* consumers; // SArray + SArray* consumers; // SArray } SMqSubActionLogEntry; SMqSubActionLogEntry* tCloneSMqSubActionLogEntry(SMqSubActionLogEntry* pEntry); @@ -561,9 +554,8 @@ int32_t tEncodeSMqSubActionLogObj(void** buf, const SMqSubActionLogO void* tDecodeSMqSubActionLogObj(const void* buf, SMqSubActionLogObj* pLog); typedef struct { - const SMqSubscribeObj* pOldSub; - const SMqTopicObj* pTopic; - const SMqRebSubscribe* pRebInfo; + int32_t oldConsumerNum; + const SMqRebInfo* pRebInfo; } SMqRebInputObj; typedef struct { @@ -583,8 +575,9 @@ typedef struct { typedef struct { char name[TSDB_TOPIC_FNAME_LEN]; - char db[TSDB_DB_FNAME_LEN]; - char outputSTbName[TSDB_TABLE_FNAME_LEN]; + char sourceDb[TSDB_DB_FNAME_LEN]; + char targetDb[TSDB_DB_FNAME_LEN]; + char targetSTbName[TSDB_TABLE_FNAME_LEN]; int64_t createTime; int64_t updateTime; int64_t uid; diff --git a/source/dnode/mnode/impl/inc/mndInfoSchema.h b/source/dnode/mnode/impl/inc/mndInfoSchema.h index 3aea99a909e02796dfbd9862c56339f9f1ba27c4..43d934c43101161bc63a487c644a5f6f3b218348 100644 --- a/source/dnode/mnode/impl/inc/mndInfoSchema.h +++ b/source/dnode/mnode/impl/inc/mndInfoSchema.h @@ -22,18 +22,6 @@ extern "C" { #endif -typedef struct SInfosTableSchema { - const char *name; - const int32_t type; - const int32_t bytes; -} SInfosTableSchema; - -typedef struct SInfosTableMeta { - const char *name; - const SInfosTableSchema *schema; - const int32_t colNum; -} SInfosTableMeta; - int32_t mndInitInfos(SMnode *pMnode); void mndCleanupInfos(SMnode *pMnode); int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp); diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 5083104039a71e75df1c7a803d2f2e8b10391ed3..b96444bebcc7d9df5eff88d7dc878b9fa170be5f 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -47,7 +47,7 @@ typedef int32_t (*MndInitFp)(SMnode *pMnode); typedef void (*MndCleanupFp)(SMnode *pMnode); typedef int32_t (*ShowRetrieveFp)(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); typedef void (*ShowFreeIterFp)(SMnode *pMnode, void *pIter); -typedef struct SQWorkerMgmt SQHandle; +typedef struct SQWorker SQHandle; typedef struct { const char *name; diff --git a/source/dnode/mnode/impl/inc/mndPerfSchema.h b/source/dnode/mnode/impl/inc/mndPerfSchema.h index 2c613e253ccc7cafaf6c75729234f90d9fc97e60..19f60229f926583f321ab350f6ac6043f6c9b096 100644 --- a/source/dnode/mnode/impl/inc/mndPerfSchema.h +++ b/source/dnode/mnode/impl/inc/mndPerfSchema.h @@ -22,18 +22,6 @@ extern "C" { #endif -typedef struct SPerfsTableSchema { - char *name; - int32_t type; - int32_t bytes; -} SPerfsTableSchema; - -typedef struct SPerfsTableMeta { - char *name; - const SPerfsTableSchema *schema; - int32_t colNum; -} SPerfsTableMeta; - int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp); int32_t mndInitPerfs(SMnode *pMnode); void mndCleanupPerfs(SMnode *pMnode); diff --git a/source/dnode/mnode/impl/inc/mndShow.h b/source/dnode/mnode/impl/inc/mndShow.h index 03f901e9c412e1ddf466cf336190d4fe7a590b0c..5a3e487e3d350e503186992a17ea9d3a4bc6416e 100644 --- a/source/dnode/mnode/impl/inc/mndShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -17,6 +17,7 @@ #define _TD_MND_SHOW_H_ #include "mndInt.h" +#include "systable.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mndStb.h b/source/dnode/mnode/impl/inc/mndStb.h index 82d93a4b9b2cd40fe4c8caed99e6e0011eee8944..a415d39434bca49af308ff149864fb29f3726a0b 100644 --- a/source/dnode/mnode/impl/inc/mndStb.h +++ b/source/dnode/mnode/impl/inc/mndStb.h @@ -29,6 +29,7 @@ void mndReleaseStb(SMnode *pMnode, SStbObj *pStb); SSdbRaw *mndStbActionEncode(SStbObj *pStb); int32_t mndValidateStbInfo(SMnode *pMnode, SSTableMetaVersion *pStbs, int32_t numOfStbs, void **ppRsp, int32_t *pRspLen); +int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndTopic.h b/source/dnode/mnode/impl/inc/mndTopic.h index fd82c60d37401ecf53eba98d98df6378ec4da54e..e3174a90a24d845fdbae2fa1efaf57f0f33baf8c 100644 --- a/source/dnode/mnode/impl/inc/mndTopic.h +++ b/source/dnode/mnode/impl/inc/mndTopic.h @@ -31,6 +31,8 @@ void mndReleaseTopic(SMnode *pMnode, SMqTopicObj *pTopic); SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic); SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw); +int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 5b5aff7c86ef204a1e75d6b0d20a295c454ab57c..7644ec3c4cab709e10ed89b7443c5bca466f6f7e 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -36,8 +36,8 @@ typedef struct { typedef enum { TEST_TRANS_START_FUNC = 1, TEST_TRANS_STOP_FUNC = 2, - CONSUME_TRANS_START_FUNC = 3, - CONSUME_TRANS_STOP_FUNC = 4, + MQ_REB_TRANS_START_FUNC = 3, + MQ_REB_TRANS_STOP_FUNC = 4, } ETrnFuncType; typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen); diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 168bd1db7694a047639a256dac49adb07494ff78..34d1223c0ae896e04776ae95cbe085f5d1b78a6c 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -453,7 +453,7 @@ static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false); char buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(buf, pObj->pDnode->ep, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(buf, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, buf, false); diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 57326b26ceb818fec893eabcadd10573c8182182..257db0dcd41a3af1d52cb5649155c79cabcbcc9e 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -194,7 +194,7 @@ static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock colDataAppend(pColInfo, numOfRows, (const char*) &pCluster->id, false); char buf[tListLen(pCluster->name) + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, buf, false); diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index ac75baeb35b38b3f938e9423053228b7aa610ff7..23a87b4691388d7b17ef25f08d3120844d1ca7b1 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -35,7 +35,7 @@ #define MND_CONSUMER_LOST_HB_CNT 3 -static int8_t mqInRebFlag = 0; +static int8_t mqRebLock = 0; static const char *mndConsumerStatusName(int status); @@ -75,6 +75,17 @@ int32_t mndInitConsumer(SMnode *pMnode) { void mndCleanupConsumer(SMnode *pMnode) {} +bool mndRebTryStart() { + int8_t old = atomic_val_compare_exchange_8(&mqRebLock, 0, 1); + return old == 0; +} + +void mndRebEnd() { atomic_sub_fetch_8(&mqRebLock, 1); } + +void mndRebCntInc() { atomic_add_fetch_8(&mqRebLock, 1); } + +void mndRebCntDec() { atomic_sub_fetch_8(&mqRebLock, 1); } + static int32_t mndProcessConsumerLostMsg(SNodeMsg *pMsg) { SMnode *pMnode = pMsg->pNode; SMqConsumerLostMsg *pLostMsg = pMsg->rpcMsg.pCont; @@ -123,15 +134,15 @@ FAIL: return -1; } -static SMqRebSubscribe *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { - SMqRebSubscribe *pRebSub = taosHashGet(pHash, key, strlen(key) + 1); +static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { + SMqRebInfo *pRebSub = taosHashGet(pHash, key, strlen(key) + 1); if (pRebSub == NULL) { pRebSub = tNewSMqRebSubscribe(key); if (pRebSub == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - taosHashPut(pHash, key, strlen(key) + 1, pRebSub, sizeof(SMqRebSubscribe)); + taosHashPut(pHash, key, strlen(key) + 1, pRebSub, sizeof(SMqRebInfo)); } return pRebSub; } @@ -143,8 +154,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { void *pIter = NULL; // rebalance cannot be parallel - int8_t old = atomic_val_compare_exchange_8(&mqInRebFlag, 0, 1); - if (old != 0) { + if (!mndRebTryStart()) { mInfo("mq rebalance already in progress, do nothing"); return 0; } @@ -152,7 +162,6 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { SMqDoRebalanceMsg *pRebMsg = rpcMallocCont(sizeof(SMqDoRebalanceMsg)); pRebMsg->rebSubHash = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK); // TODO set cleanfp - pRebMsg->mqInReb = &mqInRebFlag; // iterate all consumers, find all modification while (1) { @@ -180,7 +189,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { char key[TSDB_SUBSCRIBE_KEY_LEN]; char *removedTopic = taosArrayGetP(pConsumer->currentTopics, i); mndMakeSubscribeKey(key, pConsumer->cgroup, removedTopic); - SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); + SMqRebInfo *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId); } taosRUnLockLatch(&pConsumer->lock); @@ -191,7 +200,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { char key[TSDB_SUBSCRIBE_KEY_LEN]; char *newTopic = taosArrayGetP(pConsumer->rebNewTopics, i); mndMakeSubscribeKey(key, pConsumer->cgroup, newTopic); - SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); + SMqRebInfo *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); taosArrayPush(pRebSub->newConsumers, &pConsumer->consumerId); } @@ -200,7 +209,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { char key[TSDB_SUBSCRIBE_KEY_LEN]; char *removedTopic = taosArrayGetP(pConsumer->rebRemovedTopics, i); mndMakeSubscribeKey(key, pConsumer->cgroup, removedTopic); - SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); + SMqRebInfo *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId); } taosRUnLockLatch(&pConsumer->lock); @@ -223,7 +232,7 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { taosHashCleanup(pRebMsg->rebSubHash); rpcFreeCont(pRebMsg); mTrace("mq rebalance finished, no modification"); - atomic_store_8(&mqInRebFlag, 0); + mndRebEnd(); } return 0; } @@ -302,8 +311,8 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) { mndReleaseTopic(pMnode, pTopic); // 2.2 iterate all vg assigned to the consumer of that topic - SMqConsumerEpInSub *pEpInSub = taosHashGet(pSub->consumerHash, &consumerId, sizeof(int64_t)); - int32_t vgNum = taosArrayGetSize(pEpInSub->vgs); + SMqConsumerEp *pConsumerEp = taosHashGet(pSub->consumerHash, &consumerId, sizeof(int64_t)); + int32_t vgNum = taosArrayGetSize(pConsumerEp->vgs); topicEp.vgs = taosArrayInit(vgNum, sizeof(SMqSubVgEp)); if (topicEp.vgs == NULL) { @@ -313,7 +322,7 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) { } for (int32_t j = 0; j < vgNum; j++) { - SMqVgEp *pVgEp = taosArrayGetP(pEpInSub->vgs, j); + SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, j); char offsetKey[TSDB_PARTITION_KEY_LEN]; mndMakePartitionKey(offsetKey, pConsumer->cgroup, topic, pVgEp->vgId); // 2.2.1 build vg ep @@ -812,6 +821,7 @@ static int32_t mndRetrieveConsumer(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock colDataAppend(pColInfo, numOfRows, (const char *)status, false); // subscribed topics + // TODO: split into multiple rows char topics[TSDB_SHOW_LIST_LEN + VARSTR_HEADER_SIZE] = {0}; char *showStr = taosShowStrArray(pConsumer->assignedTopics); tstrncpy(varDataVal(topics), showStr, TSDB_SHOW_LIST_LEN); diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 15ebcf02dbbeeca55b653d548105d1d8f9122da3..442bfb5c8adfe5fb666ce21593590a7d578f3e65 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -23,6 +23,7 @@ #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" +#include "systable.h" #define DB_VER_NUMBER 1 #define DB_RESERVE_SIZE 64 @@ -84,26 +85,23 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups, _OVER) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize, _OVER) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks, _OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfStables, _OVER) + 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.daysPerFile, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows, _OVER) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime, _OVER) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod, _OVER) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.ttl, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.precision, _OVER) 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.update, _OVER) SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow, _OVER) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.streamMode, _OVER) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.singleSTable, _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) { @@ -158,26 +156,23 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pDb->cfgVersion, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->vgVersion, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfVgroups, _OVER) - SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.cacheBlockSize, _OVER) - SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.totalBlocks, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfStables, _OVER) + 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.daysPerFile, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep2, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.minRows, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.maxRows, _OVER) - SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.commitTime, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.fsyncPeriod, _OVER) - SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.ttl, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.walLevel, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.precision, _OVER) 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.update, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLastRow, _OVER) - SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.streamMode, _OVER) - SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.singleSTable, _OVER) SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.hashMethod, _OVER) SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfRetensions, _OVER) if (pDb->cfg.numOfRetensions > 0) { @@ -268,8 +263,10 @@ static int32_t mndCheckDbName(const char *dbName, SUserObj *pUser) { static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1; - if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1; - if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1; + if (pCfg->numOfStables < TSDB_DB_STREAM_MODE_OFF || pCfg->numOfStables > TSDB_DB_STREAM_MODE_ON) return -1; + 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->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; @@ -280,9 +277,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->minRows < TSDB_MIN_MINROWS_FBLOCK || pCfg->minRows > TSDB_MAX_MINROWS_FBLOCK) return -1; if (pCfg->maxRows < TSDB_MIN_MAXROWS_FBLOCK || pCfg->maxRows > TSDB_MAX_MAXROWS_FBLOCK) return -1; if (pCfg->minRows > pCfg->maxRows) return -1; - if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) return -1; if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) return -1; - if (pCfg->ttl < TSDB_MIN_DB_TTL) return -1; if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) return -1; if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) return -1; if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) return -1; @@ -290,36 +285,30 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->replications > mndGetDnodeSize(pMnode)) return -1; if (pCfg->strict < TSDB_DB_STRICT_OFF || pCfg->strict > TSDB_DB_STRICT_ON) return -1; if (pCfg->strict > pCfg->replications) return -1; - if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) return -1; if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1; - if (pCfg->streamMode < TSDB_DB_STREAM_MODE_OFF || pCfg->streamMode > TSDB_DB_STREAM_MODE_ON) return -1; - if (pCfg->singleSTable < TSDB_DB_SINGLE_STABLE_ON || pCfg->streamMode > TSDB_DB_SINGLE_STABLE_OFF) return -1; if (pCfg->hashMethod != 1) return -1; return TSDB_CODE_SUCCESS; } static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->numOfVgroups < 0) pCfg->numOfVgroups = TSDB_DEFAULT_VN_PER_DB; - if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE; - if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS; - if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; + if (pCfg->numOfStables < 0) pCfg->numOfStables = TSDB_DEFAULT_DB_SINGLE_STABLE; + if (pCfg->buffer < 0) pCfg->buffer = TSDB_DEFAULT_BUFFER_PER_VNODE; + if (pCfg->pageSize < 0) pCfg->pageSize = TSDB_DEFAULT_PAGES_PER_VNODE; + if (pCfg->pages < 0) pCfg->pages = TSDB_MAX_PAGESIZE_PER_VNODE; + if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DURATION_PER_FILE; if (pCfg->daysToKeep0 < 0) pCfg->daysToKeep0 = TSDB_DEFAULT_KEEP; if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep0; if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep1; if (pCfg->minRows < 0) pCfg->minRows = TSDB_DEFAULT_MINROWS_FBLOCK; if (pCfg->maxRows < 0) pCfg->maxRows = TSDB_DEFAULT_MAXROWS_FBLOCK; - if (pCfg->commitTime < 0) pCfg->commitTime = TSDB_DEFAULT_COMMIT_TIME; if (pCfg->fsyncPeriod < 0) pCfg->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; - if (pCfg->ttl < 0) pCfg->ttl = TSDB_DEFAULT_DB_TTL; if (pCfg->walLevel < 0) pCfg->walLevel = TSDB_DEFAULT_WAL_LEVEL; if (pCfg->precision < 0) pCfg->precision = TSDB_DEFAULT_PRECISION; 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->update < 0) pCfg->update = TSDB_DEFAULT_DB_UPDATE; if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; - if (pCfg->streamMode < 0) pCfg->streamMode = TSDB_DEFAULT_DB_STREAM_MODE; - if (pCfg->singleSTable < 0) pCfg->singleSTable = TSDB_DEFAULT_DB_SINGLE_STABLE; if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0; } @@ -445,26 +434,23 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate memcpy(dbObj.createUser, pUser->user, TSDB_USER_LEN); dbObj.cfg = (SDbCfg){ .numOfVgroups = pCreate->numOfVgroups, - .cacheBlockSize = pCreate->cacheBlockSize, - .totalBlocks = pCreate->totalBlocks, + .numOfStables = pCreate->numOfStables, + .buffer = pCreate->buffer, + .pageSize = pCreate->pageSize, + .pages = pCreate->pages, .daysPerFile = pCreate->daysPerFile, .daysToKeep0 = pCreate->daysToKeep0, .daysToKeep1 = pCreate->daysToKeep1, .daysToKeep2 = pCreate->daysToKeep2, .minRows = pCreate->minRows, .maxRows = pCreate->maxRows, - .commitTime = pCreate->commitTime, .fsyncPeriod = pCreate->fsyncPeriod, - .ttl = pCreate->ttl, .walLevel = pCreate->walLevel, .precision = pCreate->precision, .compression = pCreate->compression, .replications = pCreate->replications, .strict = pCreate->strict, - .update = pCreate->update, .cacheLastRow = pCreate->cacheLastRow, - .streamMode = pCreate->streamMode, - .singleSTable = pCreate->singleSTable, .hashMethod = 1, }; @@ -568,8 +554,23 @@ _OVER: static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { terrno = TSDB_CODE_MND_DB_OPTION_UNCHANGED; - if (pAlter->totalBlocks >= 0 && pAlter->totalBlocks != pDb->cfg.totalBlocks) { - pDb->cfg.totalBlocks = pAlter->totalBlocks; + if (pAlter->buffer >= 0 && pAlter->buffer != pDb->cfg.buffer) { + pDb->cfg.buffer = pAlter->buffer; + terrno = 0; + } + + if (pAlter->pages >= 0 && pAlter->pages != pDb->cfg.pages) { + pDb->cfg.pages = pAlter->pages; + terrno = 0; + } + + if (pAlter->pageSize >= 0 && pAlter->pageSize != pDb->cfg.pageSize) { + pDb->cfg.pageSize = pAlter->pageSize; + terrno = 0; + } + + if (pAlter->daysPerFile >= 0 && pAlter->daysPerFile != pDb->cfg.daysPerFile) { + pDb->cfg.daysPerFile = pAlter->daysPerFile; terrno = 0; } @@ -637,10 +638,14 @@ static int32_t mndSetAlterDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *p void *mndBuildAlterVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) { SAlterVnodeReq alterReq = {0}; alterReq.vgVersion = pVgroup->version; - alterReq.totalBlocks = pDb->cfg.totalBlocks; + alterReq.buffer = pDb->cfg.buffer; + alterReq.pages = pDb->cfg.pages; + alterReq.pageSize = pDb->cfg.pageSize; + alterReq.daysPerFile = pDb->cfg.daysPerFile; alterReq.daysToKeep0 = pDb->cfg.daysToKeep0; alterReq.daysToKeep1 = pDb->cfg.daysToKeep1; alterReq.daysToKeep2 = pDb->cfg.daysToKeep2; + alterReq.fsyncPeriod = pDb->cfg.fsyncPeriod; alterReq.walLevel = pDb->cfg.walLevel; alterReq.strict = pDb->cfg.strict; alterReq.cacheLastRow = pDb->cfg.cacheLastRow; @@ -833,26 +838,23 @@ static int32_t mndProcessGetDbCfgReq(SNodeMsg *pReq) { } cfgRsp.numOfVgroups = pDb->cfg.numOfVgroups; - cfgRsp.cacheBlockSize = pDb->cfg.cacheBlockSize; - cfgRsp.totalBlocks = pDb->cfg.totalBlocks; + cfgRsp.numOfStables = pDb->cfg.numOfStables; + cfgRsp.buffer = pDb->cfg.buffer; + cfgRsp.pageSize = pDb->cfg.pageSize; + cfgRsp.pages = pDb->cfg.pages; cfgRsp.daysPerFile = pDb->cfg.daysPerFile; cfgRsp.daysToKeep0 = pDb->cfg.daysToKeep0; cfgRsp.daysToKeep1 = pDb->cfg.daysToKeep1; cfgRsp.daysToKeep2 = pDb->cfg.daysToKeep2; cfgRsp.minRows = pDb->cfg.minRows; cfgRsp.maxRows = pDb->cfg.maxRows; - cfgRsp.commitTime = pDb->cfg.commitTime; cfgRsp.fsyncPeriod = pDb->cfg.fsyncPeriod; - cfgRsp.ttl = pDb->cfg.ttl; cfgRsp.walLevel = pDb->cfg.walLevel; cfgRsp.precision = pDb->cfg.precision; cfgRsp.compression = pDb->cfg.compression; cfgRsp.replications = pDb->cfg.replications; cfgRsp.strict = pDb->cfg.strict; - cfgRsp.update = pDb->cfg.update; cfgRsp.cacheLastRow = pDb->cfg.cacheLastRow; - cfgRsp.streamMode = pDb->cfg.streamMode; - cfgRsp.singleSTable = pDb->cfg.singleSTable; cfgRsp.numOfRetensions = pDb->cfg.numOfRetensions; cfgRsp.pRetensions = pDb->cfg.pRetensions; @@ -1191,7 +1193,7 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { } char *p = strchr(usedbReq.db, '.'); - if (p && 0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB)) { + if (p && ((0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB) || (0 == strcmp(p + 1, TSDB_PERFORMANCE_SCHEMA_DB))))) { memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN); int32_t vgVersion = mndGetGlobalVgroupVersion(pMnode); if (usedbReq.vgVersion < vgVersion) { @@ -1385,12 +1387,13 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in bool sysDb) { int32_t cols = 0; - char *buf = taosMemoryMalloc(pShow->bytes[cols]); + int32_t bytes = pShow->pMeta->pSchemas[cols].bytes; + char *buf = taosMemoryMalloc(bytes); const char *name = mndGetDbStr(pDb->name); if (name != NULL) { - STR_WITH_MAXSIZE_TO_VARSTR(buf, name, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(buf, name, bytes); } else { - STR_WITH_MAXSIZE_TO_VARSTR(buf, "NULL", pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(buf, "NULL", bytes); } char *status = "ready"; @@ -1428,7 +1431,6 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.replications, false); const char *src = pDb->cfg.strict ? "strict" : "nostrict"; - char b[9 + VARSTR_HEADER_SIZE] = {0}; STR_WITH_SIZE_TO_VARSTR(b, src, strlen(src)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, (const char *)b, false); @@ -1451,10 +1453,13 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in colDataAppend(pColInfo, rows, (const char *)tmp, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheBlockSize, false); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.buffer, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.pageSize, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.totalBlocks, false); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.pages, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.minRows, false); @@ -1495,14 +1500,10 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, rows, (const char *)t, false); + // single stable model + int8_t m = 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.ttl, false); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.singleSTable, false); - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.streamMode, false); + colDataAppend(pColInfo, rows, (const char *)&m, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols); colDataAppend(pColInfo, rows, (const char *)b, false); @@ -1520,7 +1521,6 @@ static void setInformationSchemaDbCfg(SDbObj *pDbObj) { pDbObj->cfg.numOfVgroups = 0; pDbObj->cfg.strict = 1; pDbObj->cfg.replications = 1; - pDbObj->cfg.update = 1; pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; } @@ -1532,7 +1532,6 @@ static void setPerfSchemaDbCfg(SDbObj *pDbObj) { pDbObj->cfg.numOfVgroups = 0; pDbObj->cfg.strict = 1; pDbObj->cfg.replications = 1; - pDbObj->cfg.update = 1; pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 767e59e4f6cf2931a1b028777e4af6421b7456a4..5bce6ac218e29c1bfda8a323af37af78c39c773a 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -211,42 +211,47 @@ void *tDecodeSMqVgEp(const void *buf, SMqVgEp *pVgEp) { return (void *)buf; } -SMqConsumerEpInSub *tCloneSMqConsumerEpInSub(const SMqConsumerEpInSub *pEpInSub) { - SMqConsumerEpInSub *pEpInSubNew = taosMemoryMalloc(sizeof(SMqConsumerEpInSub)); - if (pEpInSubNew == NULL) return NULL; - pEpInSubNew->consumerId = pEpInSub->consumerId; - pEpInSubNew->vgs = taosArrayDeepCopy(pEpInSub->vgs, (FCopy)tCloneSMqVgEp); - return pEpInSubNew; +SMqConsumerEp *tCloneSMqConsumerEp(const SMqConsumerEp *pConsumerEpOld) { + SMqConsumerEp *pConsumerEpNew = taosMemoryMalloc(sizeof(SMqConsumerEp)); + if (pConsumerEpNew == NULL) return NULL; + pConsumerEpNew->consumerId = pConsumerEpOld->consumerId; + pConsumerEpNew->vgs = taosArrayDeepCopy(pConsumerEpOld->vgs, (FCopy)tCloneSMqVgEp); + return pConsumerEpNew; } -void tDeleteSMqConsumerEpInSub(SMqConsumerEpInSub *pEpInSub) { - taosArrayDestroyEx(pEpInSub->vgs, (FDelete)tDeleteSMqVgEp); +void tDeleteSMqConsumerEp(SMqConsumerEp *pConsumerEp) { + // + taosArrayDestroyP(pConsumerEp->vgs, (FDelete)tDeleteSMqVgEp); } -int32_t tEncodeSMqConsumerEpInSub(void **buf, const SMqConsumerEpInSub *pEpInSub) { +int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) { int32_t tlen = 0; - tlen += taosEncodeFixedI64(buf, pEpInSub->consumerId); - int32_t sz = taosArrayGetSize(pEpInSub->vgs); + tlen += taosEncodeFixedI64(buf, pConsumerEp->consumerId); + tlen += taosEncodeArray(buf, pConsumerEp->vgs, (FEncode)tEncodeSMqVgEp); +#if 0 + int32_t sz = taosArrayGetSize(pConsumerEp->vgs); tlen += taosEncodeFixedI32(buf, sz); for (int32_t i = 0; i < sz; i++) { - SMqVgEp *pVgEp = taosArrayGetP(pEpInSub->vgs, i); + SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, i); tlen += tEncodeSMqVgEp(buf, pVgEp); } - /*tlen += taosEncodeArray(buf, pEpInSub->vgs, (FEncode)tEncodeSMqVgEp);*/ +#endif return tlen; } -void *tDecodeSMqConsumerEpInSub(const void *buf, SMqConsumerEpInSub *pEpInSub) { - buf = taosDecodeFixedI64(buf, &pEpInSub->consumerId); - /*buf = taosDecodeArray(buf, &pEpInSub->vgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqSubVgEp));*/ +void *tDecodeSMqConsumerEp(const void *buf, SMqConsumerEp *pConsumerEp) { + buf = taosDecodeFixedI64(buf, &pConsumerEp->consumerId); + buf = taosDecodeArray(buf, &pConsumerEp->vgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp)); +#if 0 int32_t sz; buf = taosDecodeFixedI32(buf, &sz); - pEpInSub->vgs = taosArrayInit(sz, sizeof(void *)); + pConsumerEp->vgs = taosArrayInit(sz, sizeof(void *)); for (int32_t i = 0; i < sz; i++) { SMqVgEp *pVgEp = taosMemoryMalloc(sizeof(SMqVgEp)); buf = tDecodeSMqVgEp(buf, pVgEp); - taosArrayPush(pEpInSub->vgs, &pVgEp); + taosArrayPush(pConsumerEp->vgs, &pVgEp); } +#endif return (void *)buf; } @@ -258,13 +263,11 @@ SMqSubscribeObj *tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]) { taosInitRWLatch(&pSubNew->lock); pSubNew->vgNum = 0; pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - // TODO set free fp - SMqConsumerEpInSub epInSub = { - .consumerId = -1, - .vgs = taosArrayInit(0, sizeof(void *)), - }; - int64_t unexistKey = -1; - taosHashPut(pSubNew->consumerHash, &unexistKey, sizeof(int64_t), &epInSub, sizeof(SMqConsumerEpInSub)); + // TODO set hash free fp + /*taosHashSetFreeFp(pSubNew->consumerHash, tDeleteSMqConsumerEp);*/ + + pSubNew->unassignedVgs = taosArrayInit(0, sizeof(void *)); + return pSubNew; } @@ -274,6 +277,7 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) { memcpy(pSubNew->key, pSub->key, TSDB_SUBSCRIBE_KEY_LEN); taosInitRWLatch(&pSubNew->lock); + pSubNew->dbUid = pSub->dbUid; pSubNew->subType = pSub->subType; pSubNew->withTbName = pSub->withTbName; pSubNew->withSchema = pSub->withSchema; @@ -281,30 +285,33 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) { pSubNew->vgNum = pSub->vgNum; pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - /*taosHashSetFreeFp(pSubNew->consumerHash, taosArrayDestroy);*/ - void *pIter = NULL; - SMqConsumerEpInSub *pEpInSub = NULL; + // TODO set hash free fp + /*taosHashSetFreeFp(pSubNew->consumerHash, tDeleteSMqConsumerEp);*/ + void *pIter = NULL; + SMqConsumerEp *pConsumerEp = NULL; while (1) { pIter = taosHashIterate(pSub->consumerHash, pIter); if (pIter == NULL) break; - pEpInSub = (SMqConsumerEpInSub *)pIter; - SMqConsumerEpInSub newEp = { - .consumerId = pEpInSub->consumerId, - .vgs = taosArrayDeepCopy(pEpInSub->vgs, (FCopy)tCloneSMqVgEp), + pConsumerEp = (SMqConsumerEp *)pIter; + SMqConsumerEp newEp = { + .consumerId = pConsumerEp->consumerId, + .vgs = taosArrayDeepCopy(pConsumerEp->vgs, (FCopy)tCloneSMqVgEp), }; - taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp, sizeof(SMqConsumerEpInSub)); + taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp, sizeof(SMqConsumerEp)); } + pSubNew->unassignedVgs = taosArrayDeepCopy(pSub->unassignedVgs, (FCopy)tCloneSMqVgEp); return pSubNew; } void tDeleteSubscribeObj(SMqSubscribeObj *pSub) { - /*taosArrayDestroyEx(pSub->consumerEps, (FDelete)tDeleteSMqConsumerEpInSub);*/ taosHashCleanup(pSub->consumerHash); + taosArrayDestroyP(pSub->unassignedVgs, (FDelete)tDeleteSMqVgEp); } int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) { int32_t tlen = 0; tlen += taosEncodeString(buf, pSub->key); + tlen += taosEncodeFixedI64(buf, pSub->dbUid); tlen += taosEncodeFixedI32(buf, pSub->vgNum); tlen += taosEncodeFixedI8(buf, pSub->subType); tlen += taosEncodeFixedI8(buf, pSub->withTbName); @@ -319,18 +326,19 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) { while (1) { pIter = taosHashIterate(pSub->consumerHash, pIter); if (pIter == NULL) break; - SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; - tlen += tEncodeSMqConsumerEpInSub(buf, pEpInSub); + SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter; + tlen += tEncodeSMqConsumerEp(buf, pConsumerEp); cnt++; } ASSERT(cnt == sz); - /*tlen += taosEncodeArray(buf, pSub->consumerEps, (FEncode)tEncodeSMqConsumerEpInSub);*/ + tlen += taosEncodeArray(buf, pSub->unassignedVgs, (FEncode)tEncodeSMqVgEp); return tlen; } void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) { // buf = taosDecodeStringTo(buf, pSub->key); + buf = taosDecodeFixedI64(buf, &pSub->dbUid); buf = taosDecodeFixedI32(buf, &pSub->vgNum); buf = taosDecodeFixedI8(buf, &pSub->subType); buf = taosDecodeFixedI8(buf, &pSub->withTbName); @@ -342,13 +350,12 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) { pSub->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); for (int32_t i = 0; i < sz; i++) { - /*SMqConsumerEpInSub* pEpInSub = taosMemoryMalloc(sizeof(SMqConsumerEpInSub));*/ - SMqConsumerEpInSub epInSub = {0}; - buf = tDecodeSMqConsumerEpInSub(buf, &epInSub); - taosHashPut(pSub->consumerHash, &epInSub.consumerId, sizeof(int64_t), &epInSub, sizeof(SMqConsumerEpInSub)); + SMqConsumerEp consumerEp = {0}; + buf = tDecodeSMqConsumerEp(buf, &consumerEp); + taosHashPut(pSub->consumerHash, &consumerEp.consumerId, sizeof(int64_t), &consumerEp, sizeof(SMqConsumerEp)); } - /*buf = taosDecodeArray(buf, &pSub->consumerEps, (FDecode)tDecodeSMqConsumerEpInSub, sizeof(SMqConsumerEpInSub));*/ + buf = taosDecodeArray(buf, &pSub->unassignedVgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp)); return (void *)buf; } @@ -356,12 +363,12 @@ SMqSubActionLogEntry *tCloneSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) { SMqSubActionLogEntry *pEntryNew = taosMemoryMalloc(sizeof(SMqSubActionLogEntry)); if (pEntryNew == NULL) return NULL; pEntryNew->epoch = pEntry->epoch; - pEntryNew->consumers = taosArrayDeepCopy(pEntry->consumers, (FCopy)tCloneSMqConsumerEpInSub); + pEntryNew->consumers = taosArrayDeepCopy(pEntry->consumers, (FCopy)tCloneSMqConsumerEp); return pEntryNew; } void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) { - taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEpInSub); + taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEp); } int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEntry) { @@ -381,12 +388,12 @@ SMqSubActionLogObj *tCloneSMqSubActionLogObj(SMqSubActionLogObj *pLog) { SMqSubActionLogObj *pLogNew = taosMemoryMalloc(sizeof(SMqSubActionLogObj)); if (pLogNew == NULL) return pLogNew; memcpy(pLogNew->key, pLog->key, TSDB_SUBSCRIBE_KEY_LEN); - pLogNew->logs = taosArrayDeepCopy(pLog->logs, (FCopy)tCloneSMqConsumerEpInSub); + pLogNew->logs = taosArrayDeepCopy(pLog->logs, (FCopy)tCloneSMqConsumerEp); return pLogNew; } void tDeleteSMqSubActionLogObj(SMqSubActionLogObj *pLog) { - taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEpInSub); + taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEp); } int32_t tEncodeSMqSubActionLogObj(void **buf, const SMqSubActionLogObj *pLog) { @@ -406,7 +413,7 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { int32_t sz = 0; /*int32_t outputNameSz = 0;*/ if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1; - if (tEncodeCStr(pEncoder, pObj->db) < 0) return -1; + if (tEncodeCStr(pEncoder, pObj->sourceDb) < 0) return -1; if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1; if (tEncodeI64(pEncoder, pObj->updateTime) < 0) return -1; if (tEncodeI64(pEncoder, pObj->uid) < 0) return -1; @@ -414,6 +421,9 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { if (tEncodeI32(pEncoder, pObj->version) < 0) return -1; if (tEncodeI8(pEncoder, pObj->status) < 0) return -1; if (tEncodeI8(pEncoder, pObj->createdBy) < 0) return -1; + if (tEncodeI8(pEncoder, pObj->trigger) < 0) return -1; + if (tEncodeI32(pEncoder, pObj->triggerParam) < 0) return -1; + if (tEncodeI64(pEncoder, pObj->waterMark) < 0) return -1; if (tEncodeI32(pEncoder, pObj->fixedSinkVgId) < 0) return -1; if (tEncodeI64(pEncoder, pObj->smaId) < 0) return -1; if (tEncodeCStr(pEncoder, pObj->sql) < 0) return -1; @@ -452,7 +462,7 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { if (tDecodeCStrTo(pDecoder, pObj->name) < 0) return -1; - if (tDecodeCStrTo(pDecoder, pObj->db) < 0) return -1; + if (tDecodeCStrTo(pDecoder, pObj->sourceDb) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->createTime) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->updateTime) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->uid) < 0) return -1; @@ -460,6 +470,9 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { if (tDecodeI32(pDecoder, &pObj->version) < 0) return -1; if (tDecodeI8(pDecoder, &pObj->status) < 0) return -1; if (tDecodeI8(pDecoder, &pObj->createdBy) < 0) return -1; + if (tDecodeI8(pDecoder, &pObj->trigger) < 0) return -1; + if (tDecodeI32(pDecoder, &pObj->triggerParam) < 0) return -1; + if (tDecodeI64(pDecoder, &pObj->waterMark) < 0) return -1; if (tDecodeI32(pDecoder, &pObj->fixedSinkVgId) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->smaId) < 0) return -1; if (tDecodeCStrAlloc(pDecoder, &pObj->sql) < 0) return -1; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 3eeec61dbbe059ffa2e69d3904e5ae8eac6d5a8d..a55cf412622fab0b18fbcde6d86b70cbfe11b92a 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -705,7 +705,7 @@ static int32_t mndRetrieveDnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p colDataAppend(pColInfo, numOfRows, (const char *)&pDnode->id, false); char buf[tListLen(pDnode->ep) + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, buf, false); diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 09d05870192db3e494118d90265309b07c54d567..b9331e6e03e6a0d7e478b8f32423e8e80d37035f 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -517,14 +517,14 @@ static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB cols = 0; char b1[tListLen(pFunc->name) + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(b1, pFunc->name, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(b1, pFunc->name, pShow->pMeta->pSchemas[cols].bytes); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)b1, false); if (pFunc->pComment) { - char *b2 = taosMemoryCalloc(1, pShow->bytes[cols]); - STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->bytes[cols]); + char *b2 = taosMemoryCalloc(1, pShow->pMeta->pSchemas[cols].bytes); + STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)b2, false); @@ -540,7 +540,7 @@ static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b3[TSDB_TYPE_STR_MAX_LEN] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen), - pShow->bytes[cols]); + pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)b3, false); diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index 07f8228cda2c8c8db4d14ae99a9eb7404c3723e5..c9bccaf1d02117dc43a7c631605543243bd6bb3b 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -14,265 +14,10 @@ */ #define _DEFAULT_SOURCE -#include "mndInfoSchema.h" +#include "systable.h" #include "mndInt.h" -#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE) -#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE) -#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE) - -static const SInfosTableSchema dnodesSchema[] = { - {.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "max_vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema mnodesSchema[] = { - {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SInfosTableSchema modulesSchema[] = { - {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = 134 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "module", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema qnodesSchema[] = { - {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SInfosTableSchema snodesSchema[] = { - {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SInfosTableSchema bnodesSchema[] = { - {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SInfosTableSchema clusterSchema[] = { - {.name = "id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SInfosTableSchema userDBSchema[] = { - {.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "ntables", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "replica", .bytes = 2, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "strict", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "days", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "keep", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "cache", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "minrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "maxrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "wal", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "fsync", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "precision", .bytes = 2 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "single_stable", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "stream_mode", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - // {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update -}; - -static const SInfosTableSchema userFuncSchema[] = { - {.name = "name", .bytes = TSDB_FUNC_NAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "comment", .bytes = PATH_MAX - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "aggregate", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "output_type", .bytes = TSDB_TYPE_STR_MAX_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "code_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "bufsize", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, -}; - -static const SInfosTableSchema userIdxSchema[] = { - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "index_database", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "index_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "column_name", .bytes = SYSTABLE_SCH_COL_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema userStbsSchema[] = { - {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema userStreamsSchema[] = { - {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema userTblsSchema[] = { - {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.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 = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema userTblDistSchema[] = { - {.name = "db_name", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "distributed_histogram", .bytes = 500 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "min_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "max_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "avg_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "stddev_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "rows", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "storage_size", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "compression_ratio", .bytes = 8, .type = TSDB_DATA_TYPE_DOUBLE}, - {.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, -}; - -static const SInfosTableSchema userUsersSchema[] = { - {.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SInfosTableSchema grantsSchema[] = { - {.name = "version", .bytes = 8 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "expire time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "storage(GB)", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "databases", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "users", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "accounts", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "connections", .bytes = 11 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "streams", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "cpu cores", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "speed(PPS)", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "querytime", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema vgroupsSchema[] = { - {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v1_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v1_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "v2_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v2_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "v3_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v3_status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "nfiles", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, -}; - -static const SInfosTableSchema smaSchema[] = { - {.name = "sma_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema transSchema[] = { - {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "created_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "stage", .bytes = TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "type", .bytes = TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "last_error", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema configSchema[] = { - {.name = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "value", .bytes = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableSchema connSchema[] = { - {.name = "connId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "program", .bytes = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "ip:port", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "login_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "last_access", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SInfosTableSchema querySchema[] = { - {.name = "queryId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "connId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "ip:port", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "qid", .bytes = 22 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "created_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "time", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "sql_obj_id", .bytes = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "ep", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "stable_query", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL}, - {.name = "sub_queries", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "sub_query_info", .bytes = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; - -static const SInfosTableMeta infosMeta[] = { - {TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema)}, - {TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)}, - {TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)}, - {TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)}, - {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, - {TSDB_INS_TABLE_BNODES, bnodesSchema, tListLen(bnodesSchema)}, - {TSDB_INS_TABLE_CLUSTER, clusterSchema, tListLen(clusterSchema)}, - {TSDB_INS_TABLE_USER_DATABASES, userDBSchema, tListLen(userDBSchema)}, - {TSDB_INS_TABLE_USER_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema)}, - {TSDB_INS_TABLE_USER_INDEXES, userIdxSchema, tListLen(userIdxSchema)}, - {TSDB_INS_TABLE_USER_STABLES, userStbsSchema, tListLen(userStbsSchema)}, - {TSDB_INS_TABLE_USER_STREAMS, userStreamsSchema, tListLen(userStreamsSchema)}, - {TSDB_INS_TABLE_USER_TABLES, userTblsSchema, tListLen(userTblsSchema)}, - {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, - {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, - {TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)}, - {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, - {TSDB_INS_TABLE_TRANS, transSchema, tListLen(transSchema)}, - {TSDB_INS_TABLE_SMAS, smaSchema, tListLen(smaSchema)}, - {TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema)}, - {TSDB_INS_TABLE_CONNS, connSchema, tListLen(connSchema)}, - {TSDB_INS_TABLE_QUERIES, querySchema, tListLen(querySchema)}, -}; - -static int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, SSchema **pDst) { +static int32_t mndInitInfosTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) { SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema)); if (NULL == schema) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -298,11 +43,15 @@ static int32_t mndInsInitMeta(SHashObj *hash) { meta.sversion = 1; meta.tversion = 1; - for (int32_t i = 0; i < tListLen(infosMeta); ++i) { - tstrncpy(meta.tbName, infosMeta[i].name, sizeof(meta.tbName)); - meta.numOfColumns = infosMeta[i].colNum; + size_t size = 0; + const SSysTableMeta* pInfosTableMeta = NULL; + getInfosDbMeta(&pInfosTableMeta, &size); + + for (int32_t i = 0; i < size; ++i) { + tstrncpy(meta.tbName, pInfosTableMeta[i].name, sizeof(meta.tbName)); + meta.numOfColumns = pInfosTableMeta[i].colNum; - if (mndInitInfosTableSchema(infosMeta[i].schema, infosMeta[i].colNum, &meta.pSchemas)) { + if (mndInitInfosTableSchema(pInfosTableMeta[i].schema, pInfosTableMeta[i].colNum, &meta.pSchemas)) { return -1; } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index b51c545a6d2739014275a58396054c5b96945836..b7d73581105a2ed8cec123d53824d06b18155e24 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -619,14 +619,14 @@ static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false); char b1[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, b1, false); const char *roles = syncStr(pObj->role); - char *b2 = taosMemoryCalloc(1, strlen(roles) + VARSTR_HEADER_SIZE); - STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->bytes[cols]); + char *b2 = taosMemoryCalloc(1, 12 + VARSTR_HEADER_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)b2, false); diff --git a/source/dnode/mnode/impl/src/mndPerfSchema.c b/source/dnode/mnode/impl/src/mndPerfSchema.c index 2cb8c4351e650fbd856294e0ddd0e4c6193ddb88..d7b2e3ec24a89c0a4576753f1e6343cffff9ce02 100644 --- a/source/dnode/mnode/impl/src/mndPerfSchema.c +++ b/source/dnode/mnode/impl/src/mndPerfSchema.c @@ -14,79 +14,11 @@ */ #define _DEFAULT_SOURCE -#include "mndPerfSchema.h" #include "mndInt.h" - -//!!!! Note: only APPEND columns in below tables, NO insert !!!! -static const SPerfsTableSchema connectionsSchema[] = { - {.name = "conn_id", .bytes = 4, .type = TSDB_DATA_TYPE_UINT}, - {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "program", .bytes = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "end_point", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "login_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "last_access", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; -static const SPerfsTableSchema queriesSchema[] = { - {.name = "query_id", .bytes = 4, .type = TSDB_DATA_TYPE_UBIGINT}, - {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "fqdn", .bytes = TSDB_FQDN_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "sub_queries", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "sub_query_info", .bytes = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, -}; - -static const SPerfsTableSchema topicSchema[] = { - {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - // TODO config -}; - -static const SPerfsTableSchema consumerSchema[] = { - {.name = "consumer_id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "app_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "topics", .bytes = TSDB_SHOW_LIST_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "end_point", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "subscribe_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "rebalance_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, -}; - -static const SPerfsTableSchema subscriptionSchema[] = { - {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "consumer_id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, -}; - -static const SPerfsTableSchema offsetSchema[] = { - {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "committed_offset", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "current_offset", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "skip_log_cnt", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, -}; - -static const SPerfsTableMeta perfsMeta[] = { - {TSDB_PERFS_TABLE_CONNECTIONS, connectionsSchema, tListLen(connectionsSchema)}, - {TSDB_PERFS_TABLE_QUERIES, queriesSchema, tListLen(queriesSchema)}, - {TSDB_PERFS_TABLE_TOPICS, topicSchema, tListLen(topicSchema)}, - {TSDB_PERFS_TABLE_CONSUMERS, consumerSchema, tListLen(consumerSchema)}, - {TSDB_PERFS_TABLE_SUBSCRIPTIONS, subscriptionSchema, tListLen(subscriptionSchema)}, - {TSDB_PERFS_TABLE_OFFSETS, offsetSchema, tListLen(offsetSchema)}, -}; +#include "systable.h" // connection/application/ -int32_t mndInitPerfsTableSchema(const SPerfsTableSchema *pSrc, int32_t colNum, SSchema **pDst) { +int32_t mndInitPerfsTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) { SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema)); if (NULL == schema) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -113,11 +45,15 @@ int32_t mndPerfsInitMeta(SHashObj *hash) { meta.sversion = 1; meta.tversion = 1; - for (int32_t i = 0; i < tListLen(perfsMeta); ++i) { - strcpy(meta.tbName, perfsMeta[i].name); - meta.numOfColumns = perfsMeta[i].colNum; + size_t size = 0; + const SSysTableMeta* pSysDbTableMeta = NULL; + getPerfDbMeta(&pSysDbTableMeta, &size); + + for (int32_t i = 0; i < size; ++i) { + strcpy(meta.tbName, pSysDbTableMeta[i].name); + meta.numOfColumns = pSysDbTableMeta[i].colNum; - if (mndInitPerfsTableSchema(perfsMeta[i].schema, perfsMeta[i].colNum, &meta.pSchemas)) { + if (mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas)) { return -1; } @@ -153,7 +89,6 @@ int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char } memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema)); - return 0; } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 7bd22c2de53b17b881b49f70e06bbe7872200a5c..59d07fd4aac6f5afc9069bec8d86af034d374d7b 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -570,38 +570,39 @@ static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int if (pConn == NULL) break; cols = 0; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; +#if 0 + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(uint32_t *)pWrite = pConn->id; cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->user, pShow->bytes[cols]); + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->user, pShow->pMeta->pSchemas[cols].bytes); cols++; // app name - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->app, pShow->bytes[cols]); + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->app, pShow->pMeta->pSchemas[cols].bytes); cols++; // app pid - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int32_t *)pWrite = pConn->pid; cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; taosIpPort2String(pConn->ip, pConn->port, ipStr); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->pMeta->pSchemas[cols].bytes); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int64_t *)pWrite = pConn->loginTimeMs; cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; if (pConn->lastAccessTimeMs < pConn->loginTimeMs) pConn->lastAccessTimeMs = pConn->loginTimeMs; *(int64_t *)pWrite = pConn->lastAccessTimeMs; cols++; +#endif numOfRows++; } @@ -643,67 +644,67 @@ static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, i SQueryDesc *pDesc = pConn->pQueries + i; cols = 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int64_t *)pWrite = htobe64(pDesc->queryId); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int64_t *)pWrite = htobe64(pConn->id); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->user, pShow->bytes[cols]); + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->user, pShow->pMeta->pSchemas[cols].bytes); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; snprintf(str, tListLen(str), "%s:%u", taosIpStr(pConn->ip), pConn->port); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->pMeta->pSchemas[cols].bytes); cols++; char handleBuf[24] = {0}; snprintf(handleBuf, tListLen(handleBuf), "%" PRIu64, htobe64(pDesc->qId)); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, handleBuf, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, handleBuf, pShow->pMeta->pSchemas[cols].bytes); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int64_t *)pWrite = htobe64(pDesc->stime); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int64_t *)pWrite = htobe64(pDesc->useconds); cols++; snprintf(str, tListLen(str), "0x%" PRIx64, htobe64(pDesc->sqlObjId)); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->bytes[cols]); + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->pMeta->pSchemas[cols].bytes); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int32_t *)pWrite = htonl(pDesc->pid); cols++; char epBuf[TSDB_EP_LEN + 1] = {0}; snprintf(epBuf, tListLen(epBuf), "%s:%u", pDesc->fqdn, pConn->port); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, epBuf, pShow->bytes[cols]); + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, epBuf, pShow->pMeta->pSchemas[cols].bytes); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(bool *)pWrite = pDesc->stableQuery; cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; *(int32_t *)pWrite = htonl(pDesc->numOfSub); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->subSqlInfo, pShow->bytes[cols]); + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->subSqlInfo, pShow->pMeta->pSchemas[cols].bytes); cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]); + pWrite = data + pShow->offset[cols] * rows + pShow->pMeta->pSchemas[cols].bytes * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->pMeta->pSchemas[cols].bytes); cols++; numOfRows++; diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index cec5933ba32b2e2f3fbcfb8a5ab48a4f8109ad18..ae223c34b48254a4e9b75b87d236661174c10cca 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -517,7 +517,7 @@ static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false); char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)ep, false); diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index d184e354c44223cf7bf2e99e022caa45dd9476fc..7aa55e21091df78f11475a7d245507d15eeb80fa 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -20,7 +20,7 @@ int32_t mndProcessQueryMsg(SNodeMsg *pReq) { SMnode *pMnode = pReq->pNode; - SReadHandle handle = {0}; + SReadHandle handle = {.mnd = pMnode}; mTrace("msg:%p, in query queue is processing", pReq); switch (pReq->rpcMsg.msgType) { diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 06aa3cec0705b5aa1cac8a3b49d140354d07e4eb..b760dd6aa8d584accd2569ca4605f61934cab12d 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -308,8 +308,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { // sink part if (level == 0) { // only for inplace - pTask->sinkType = TASK_SINK__SHOW; - pTask->showSink.reserved = 0; + pTask->sinkType = TASK_SINK__NONE; if (!hasExtraSink) { #if 1 if (pStream->createdBy == STREAM_CREATED_BY__SMA) { @@ -368,8 +367,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { pTask->sourceType = TASK_SOURCE__PIPE; // sink part - pTask->sinkType = TASK_SINK__SHOW; - /*pTask->sinkType = TASK_SINK__NONE;*/ + pTask->sinkType = TASK_SINK__NONE; // dispatch part ASSERT(hasExtraSink); @@ -382,7 +380,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { pTask->dispatchType = TASK_DISPATCH__SHUFFLE; pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC; - SDbObj* pDb = mndAcquireDb(pMnode, pStream->db); + SDbObj* pDb = mndAcquireDb(pMnode, pStream->sourceDb); ASSERT(pDb); if (mndExtractDbInfo(pMnode, pDb, &pTask->shuffleDispatcher.dbInfo, NULL) < 0) { sdbRelease(pSdb, pDb); @@ -456,7 +454,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { pTask->sourceType = TASK_SOURCE__MERGE; // sink part - pTask->sinkType = TASK_SINK__SHOW; + pTask->sinkType = TASK_SINK__NONE; // dispatch part pTask->dispatchType = TASK_DISPATCH__NONE; @@ -504,11 +502,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib plan = nodesListGetNode(inner->pNodeList, 0); } - int64_t unexistKey = -1; - SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t)); - ASSERT(pEpInSub); - - ASSERT(taosHashGetSize(pSub->consumerHash) == 1); + ASSERT(pSub->unassignedVgs); + ASSERT(taosHashGetSize(pSub->consumerHash) == 0); void* pIter = NULL; while (1) { @@ -524,7 +519,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp)); pVgEp->epSet = mndGetVgroupEpset(pMnode, pVgroup); pVgEp->vgId = pVgroup->vgId; - taosArrayPush(pEpInSub->vgs, &pVgEp); + taosArrayPush(pSub->unassignedVgs, &pVgEp); mDebug("init subscription %s, assign vg: %d", pSub->key, pVgEp->vgId); @@ -543,17 +538,11 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib } else { pVgEp->qmsg = strdup(""); } - - ASSERT(taosHashGetSize(pSub->consumerHash) == 1); - - /*taosArrayPush(pSub->unassignedVg, &consumerEp);*/ } - pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t)); - - ASSERT(pEpInSub->vgs->size > 0); + ASSERT(pSub->unassignedVgs->size > 0); - ASSERT(taosHashGetSize(pSub->consumerHash) == 1); + ASSERT(taosHashGetSize(pSub->consumerHash) == 0); qDestroyQueryPlan(pPlan); diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 94366a241d697025f0d0682d8b2bab24df12ad76..be333d154a4b39d2cf7fd9f65878663a03dda184 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "mndShow.h" +#include "systable.h" #define SHOW_STEP_SIZE 100 @@ -47,7 +48,7 @@ void mndCleanupShow(SMnode *pMnode) { } } -static int32_t convertToRetrieveType(char* name, int32_t len) { +static int32_t convertToRetrieveType(char *name, int32_t len) { int32_t type = -1; if (strncasecmp(name, TSDB_INS_TABLE_DNODES, len) == 0) { @@ -72,8 +73,6 @@ static int32_t convertToRetrieveType(char* name, int32_t len) { // type = TSDB_MGMT_TABLE_INDEX; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_STABLES, len) == 0) { type = TSDB_MGMT_TABLE_STB; - } else if (strncasecmp(name, TSDB_INS_TABLE_USER_STREAMS, len) == 0) { - type = TSDB_MGMT_TABLE_STREAMS; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, len) == 0) { type = TSDB_MGMT_TABLE_TABLE; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, len) == 0) { @@ -84,26 +83,28 @@ static int32_t convertToRetrieveType(char* name, int32_t len) { type = TSDB_MGMT_TABLE_GRANTS; } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, len) == 0) { type = TSDB_MGMT_TABLE_VGROUP; - } else if (strncasecmp(name, TSDB_INS_TABLE_CONSUMERS, len) == 0) { + } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) { type = TSDB_MGMT_TABLE_CONSUMERS; - } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIBES, len) == 0) { + } else if (strncasecmp(name, TSDB_PERFS_TABLE_SUBSCRIBES, len) == 0) { type = TSDB_MGMT_TABLE_SUBSCRIBES; - } else if (strncasecmp(name, TSDB_INS_TABLE_TRANS, len) == 0) { + } else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) { type = TSDB_MGMT_TABLE_TRANS; - } else if (strncasecmp(name, TSDB_INS_TABLE_SMAS, len) == 0) { + } else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) { type = TSDB_MGMT_TABLE_SMAS; } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, len) == 0) { type = TSDB_MGMT_TABLE_CONFIGS; - } else if (strncasecmp(name, TSDB_INS_TABLE_CONNS, len) == 0) { + } else if (strncasecmp(name, TSDB_PERFS_TABLE_CONNECTIONS, len) == 0) { type = TSDB_MGMT_TABLE_CONNS; - } else if (strncasecmp(name, TSDB_INS_TABLE_QUERIES, len) == 0) { + } else if (strncasecmp(name, TSDB_PERFS_TABLE_QUERIES, len) == 0) { type = TSDB_MGMT_TABLE_QUERIES; - } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) { + } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) { type = TSDB_MGMT_TABLE_VNODES; } else if (strncasecmp(name, TSDB_PERFS_TABLE_TOPICS, len) == 0) { type = TSDB_MGMT_TABLE_TOPICS; + } else if (strncasecmp(name, TSDB_PERFS_TABLE_STREAMS, len) == 0) { + type = TSDB_MGMT_TABLE_STREAMS; } else { -// ASSERT(0); + // ASSERT(0); } return type; @@ -115,12 +116,12 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) { int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1); if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1); - int32_t size = sizeof(SShowObj); + int32_t size = sizeof(SShowObj); SShowObj showObj = {0}; - showObj.id = showId; + showObj.id = showId; showObj.pMnode = pMnode; - showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb)); + showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb)); memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); int32_t keepTime = tsShellActivityTimer * 6 * 1000; @@ -208,16 +209,6 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { pShow->pMeta = pMeta; pShow->numOfColumns = pShow->pMeta->numOfColumns; - int32_t offset = 0; - - for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) { - pShow->offset[i] = offset; - - int32_t bytes = pShow->pMeta->pSchemas[i].bytes; - pShow->rowSize += bytes; - pShow->bytes[i] = bytes; - offset += bytes; - } } else { pShow = mndAcquireShowObj(pMnode, retrieveReq.showId); if (pShow == NULL) { diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index a474ccc5b6ba1defd31c4921ea4f343884a6f8d9..0e3e8b68ccd23dfd408b92dfc3fd306716a32a3c 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -40,7 +40,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq); static int32_t mndProcessMDropSmaReq(SNodeMsg *pReq); static int32_t mndProcessVCreateSmaRsp(SNodeMsg *pRsp); static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp); -static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); +static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextSma(SMnode *pMnode, void *pIter); int32_t mndInitSma(SMnode *pMnode) { @@ -406,7 +406,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre SStreamObj streamObj = {0}; tstrncpy(streamObj.name, pCreate->name, TSDB_STREAM_FNAME_LEN); - tstrncpy(streamObj.db, pDb->name, TSDB_DB_FNAME_LEN); + tstrncpy(streamObj.sourceDb, pDb->name, TSDB_DB_FNAME_LEN); streamObj.createTime = taosGetTimestampMs(); streamObj.updateTime = streamObj.createTime; streamObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); @@ -686,9 +686,9 @@ _OVER: return code; } -int32_t mndProcessGetSmaReq(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp *rsp, bool *exist) { - int32_t code = -1; - SSmaObj *pSma = NULL; +int32_t mndProcessGetSmaReq(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp *rsp, bool *exist) { + int32_t code = -1; + SSmaObj *pSma = NULL; pSma = mndAcquireSma(pMnode, indexReq->indexFName); if (pSma == NULL) { @@ -701,13 +701,14 @@ int32_t mndProcessGetSmaReq(SMnode *pMnode, SUserIndexReq *indexReq, SUserI strcpy(rsp->indexType, TSDB_INDEX_TYPE_SMA); SNodeList *pList = NULL; - int32_t extOffset = 0; + int32_t extOffset = 0; code = nodesStringToList(pSma->expr, &pList); if (0 == code) { SNode *node = NULL; FOREACH(node, pList) { SFunctionNode *pFunc = (SFunctionNode *)node; - extOffset += snprintf(rsp->indexExts + extOffset, sizeof(rsp->indexExts) - extOffset - 1, "%s%s", (extOffset ? ",":""), pFunc->functionName); + extOffset += snprintf(rsp->indexExts + extOffset, sizeof(rsp->indexExts) - extOffset - 1, "%s%s", + (extOffset ? "," : ""), pFunc->functionName); } *exist = true; @@ -718,13 +719,12 @@ int32_t mndProcessGetSmaReq(SMnode *pMnode, SUserIndexReq *indexReq, SUserI return code; } - static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp) { mndTransProcessRsp(pRsp); return 0; } -static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { +static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; @@ -758,8 +758,8 @@ static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlo char n1[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(n1, (char *)tNameGetTableName(&stbName)); - SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, numOfRows, (const char*) n, false); + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)n, false); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)&pSma->createdTime, false); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index b7d0ed8f5afa7558e72fc43a8645dba15b2a4892..58db4772e783fc74c9e2d4ef9119e60ae84444f4 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -463,7 +463,7 @@ static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false); char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)ep, false); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 41bcef25d1b671b60f1c0e1311e025783e1ac5a2..8ae0d5d19c83e78de136b887ccf5f2c1a2175428 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -428,17 +428,23 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt } static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) { - SName name = {0}; + SName name = {0}; + SVDropStbReq req = {0}; + int32_t contLen = 0; + int32_t ret = 0; + SMsgHead *pHead = NULL; + SCoder coder = {0}; + tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - SVDropTbReq req = {0}; - req.ver = 0; req.name = (char *)tNameGetTableName(&name); - req.type = TD_SUPER_TABLE; req.suid = pStb->uid; - int32_t contLen = tSerializeSVDropTbReq(NULL, &req) + sizeof(SMsgHead); - SMsgHead *pHead = taosMemoryMalloc(contLen); + tEncodeSize(tEncodeSVDropStbReq, &req, contLen, ret); + if (ret < 0) return NULL; + + contLen += sizeof(SMsgHead); + pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; @@ -448,7 +454,10 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, pHead->vgId = htonl(pVgroup->vgId); void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead)); - tSerializeSVDropTbReq(&pBuf, &req); + + tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, contLen - sizeof(SMsgHead), TD_ENCODER); + tEncodeSVDropStbReq(&coder, &req); + tCoderClear(&coder); *pContLen = contLen; return pHead; @@ -670,8 +679,8 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre memcpy(stbObj.pAst2, pCreate->pAst2, stbObj.ast2Len); } - stbObj.pColumns = taosMemoryMalloc(stbObj.numOfColumns * sizeof(SSchema)); - stbObj.pTags = taosMemoryMalloc(stbObj.numOfTags * sizeof(SSchema)); + stbObj.pColumns = taosMemoryCalloc(1, stbObj.numOfColumns * sizeof(SSchema)); + stbObj.pTags = taosMemoryCalloc(1, stbObj.numOfTags * sizeof(SSchema)); if (stbObj.pColumns == NULL || stbObj.pTags == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -722,7 +731,6 @@ _OVER: static int32_t mndProcessMCreateStbReq(SNodeMsg *pReq) { SMnode *pMnode = pReq->pNode; int32_t code = -1; - SStbObj *pTopicStb = NULL; SStbObj *pStb = NULL; SDbObj *pDb = NULL; SUserObj *pUser = NULL; @@ -753,12 +761,6 @@ static int32_t mndProcessMCreateStbReq(SNodeMsg *pReq) { goto _OVER; } - pTopicStb = mndAcquireStb(pMnode, createReq.name); - if (pTopicStb != NULL) { - terrno = TSDB_CODE_MND_NAME_CONFLICT_WITH_TOPIC; - goto _OVER; - } - pDb = mndAcquireDbByStb(pMnode, createReq.name); if (pDb == NULL) { terrno = TSDB_CODE_MND_DB_NOT_SELECTED; @@ -774,6 +776,13 @@ static int32_t mndProcessMCreateStbReq(SNodeMsg *pReq) { goto _OVER; } + int32_t numOfStbs = -1; + mndGetNumOfStbs(pMnode, pDb->name, &numOfStbs); + if (pDb->cfg.numOfStables == 1 && numOfStbs != 0) { + terrno = TSDB_CODE_MND_SINGLE_STB_MODE_DB; + goto _OVER; + } + code = mndCreateStb(pMnode, pReq, &createReq, pDb); if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -783,7 +792,6 @@ _OVER: } mndReleaseStb(pMnode, pStb); - mndReleaseStb(pMnode, pTopicStb); mndReleaseDb(pMnode, pDb); mndReleaseUser(pMnode, pUser); tFreeSMCreateStbReq(&createReq); @@ -1095,7 +1103,7 @@ static int32_t mndSetAlterStbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD SSdbRaw *pRedoRaw = mndStbActionEncode(pStb); if (pRedoRaw == NULL) return -1; if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_UPDATING) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1; return 0; } @@ -1427,7 +1435,6 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa pRsp->numOfColumns = pStb->numOfColumns; pRsp->precision = pDb->cfg.precision; pRsp->tableType = TSDB_SUPER_TABLE; - pRsp->update = pDb->cfg.update; pRsp->sversion = pStb->version; pRsp->suid = pStb->uid; pRsp->tuid = pStb->uid; @@ -1580,7 +1587,7 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableMetaVersion *pStbVersions, int return 0; } -static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs) { +int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs) { SSdb *pSdb = pMnode->pSdb; SDbObj *pDb = mndAcquireDb(pMnode, dbName); if (pDb == NULL) { diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 1062154e023432f0af070d12efa59ec725a431eb..5c6e2ce77114e30b94f4176ccb8fd02f93cb49ea 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -40,7 +40,7 @@ static int32_t mndProcessTaskDeployInternalRsp(SNodeMsg *pRsp); /*static int32_t mndProcessDropStreamInRsp(SNodeMsg *pRsp);*/ static int32_t mndProcessStreamMetaReq(SNodeMsg *pReq); static int32_t mndGetStreamMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); -static int32_t mndRetrieveStream(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveStream(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextStream(SMnode *pMnode, void *pIter); int32_t mndInitStream(SMnode *pMnode) { @@ -58,8 +58,8 @@ int32_t mndInitStream(SMnode *pMnode) { /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq);*/ /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndProcessDropStreamInRsp);*/ - // mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveStream); - /*mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextStream);*/ + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndRetrieveStream); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndCancelGetNextStream); return sdbSetTable(pMnode->pSdb, table); } @@ -294,8 +294,8 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe mDebug("stream:%s to create", pCreate->name); SStreamObj streamObj = {0}; tstrncpy(streamObj.name, pCreate->name, TSDB_STREAM_FNAME_LEN); - tstrncpy(streamObj.db, pDb->name, TSDB_DB_FNAME_LEN); - tstrncpy(streamObj.outputSTbName, pCreate->outputSTbName, TSDB_TABLE_FNAME_LEN); + tstrncpy(streamObj.sourceDb, pDb->name, TSDB_DB_FNAME_LEN); + tstrncpy(streamObj.targetSTbName, pCreate->targetStbFullName, TSDB_TABLE_FNAME_LEN); streamObj.createTime = taosGetTimestampMs(); streamObj.updateTime = streamObj.createTime; streamObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); @@ -308,6 +308,8 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe streamObj.smaId = 0; /*streamObj.physicalPlan = "";*/ streamObj.logicalPlan = "not implemented"; + streamObj.trigger = pCreate->triggerType; + streamObj.waterMark = pCreate->watermark; STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_STREAM, &pReq->rpcMsg); if (pTrans == NULL) { @@ -424,56 +426,58 @@ static int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfS return 0; } -static int32_t mndRetrieveStream(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveStream(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SStreamObj *pStream = NULL; - int32_t cols = 0; - char *pWrite; - char prefix[TSDB_DB_FNAME_LEN] = {0}; - - SDbObj *pDb = mndAcquireDb(pMnode, pShow->db); - if (pDb == NULL) return 0; - - tstrncpy(prefix, pShow->db, TSDB_DB_FNAME_LEN); - strcat(prefix, TS_PATH_DELIMITER); - int32_t prefixLen = (int32_t)strlen(prefix); while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_STREAM, pShow->pIter, (void **)&pStream); if (pShow->pIter == NULL) break; - if (pStream->dbUid != pDb->uid) { - if (strncmp(pStream->name, prefix, prefixLen) != 0) { - mError("Inconsistent stream data, name:%s, db:%s, dbUid:%" PRIu64, pStream->name, pDb->name, pDb->uid); - } + SColumnInfoData *pColInfo; + SName n; + int32_t cols = 0; - sdbRelease(pSdb, pStream); - continue; - } + char streamName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&n, pStream->name, T_NAME_ACCT | T_NAME_DB); + tNameGetDbName(&n, varDataVal(streamName)); + varDataSetLen(streamName, strlen(varDataVal(streamName))); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)streamName, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStream->createTime, false); - cols = 0; + char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0}; + tstrncpy(&sql[VARSTR_HEADER_SIZE], pStream->sql, TSDB_SHOW_SQL_LEN); + varDataSetLen(sql, strlen(&sql[VARSTR_HEADER_SIZE])); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)sql, false); - char streamName[TSDB_TABLE_NAME_LEN] = {0}; - tstrncpy(streamName, pStream->name + prefixLen, TSDB_TABLE_NAME_LEN); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, streamName); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStream->status, true); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pStream->createTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStream->sourceDb, true); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pStream->sql, pShow->bytes[cols]); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStream->targetDb, true); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStream->targetSTbName, true); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStream->waterMark, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStream->trigger, false); numOfRows++; sdbRelease(pSdb, pStream); } - mndReleaseDb(pMnode, pDb); pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 6a1994d7b86b28fdfed346338ce0254312554a7e..545caea03d350366f6849cc1807519c3849951fe 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -80,12 +80,14 @@ static SMqSubscribeObj *mndCreateSub(SMnode *pMnode, const SMqTopicObj *pTopic, terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + pSub->dbUid = pTopic->dbUid; pSub->subType = pTopic->subType; pSub->withTbName = pTopic->withTbName; pSub->withSchema = pTopic->withSchema; pSub->withTag = pTopic->withTag; - ASSERT(taosHashGetSize(pSub->consumerHash) == 1); + ASSERT(pSub->unassignedVgs->size == 0); + ASSERT(taosHashGetSize(pSub->consumerHash) == 0); if (mndSchedInitSubEp(pMnode, pTopic, pSub) < 0) { tDeleteSubscribeObj(pSub); @@ -93,7 +95,8 @@ static SMqSubscribeObj *mndCreateSub(SMnode *pMnode, const SMqTopicObj *pTopic, return NULL; } - ASSERT(taosHashGetSize(pSub->consumerHash) == 1); + ASSERT(pSub->unassignedVgs->size > 0); + ASSERT(taosHashGetSize(pSub->consumerHash) == 0); return pSub; } @@ -142,6 +145,10 @@ static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SM int32_t vgId = pRebVg->pVgEp->vgId; SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId); + if (pVgObj == NULL) { + taosMemoryFree(buf); + return -1; + } STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgObj); @@ -168,27 +175,20 @@ static int32_t mndSplitSubscribeKey(const char *key, char *topic, char *cgroup) return 0; } -static SMqRebSubscribe *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { - SMqRebSubscribe *pRebSub = taosHashGet(pHash, key, strlen(key) + 1); +static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { + SMqRebInfo *pRebSub = taosHashGet(pHash, key, strlen(key) + 1); if (pRebSub == NULL) { pRebSub = tNewSMqRebSubscribe(key); if (pRebSub == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - taosHashPut(pHash, key, strlen(key) + 1, pRebSub, sizeof(SMqRebSubscribe)); + taosHashPut(pHash, key, strlen(key) + 1, pRebSub, sizeof(SMqRebInfo)); } return pRebSub; } static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqRebOutputObj *pOutput) { - if (pInput->pTopic != NULL) { - // create subscribe - pOutput->pSub = mndCreateSub(pMnode, pInput->pTopic, pInput->pRebInfo->key); - ASSERT(taosHashGetSize(pOutput->pSub->consumerHash) == 1); - } else { - pOutput->pSub = tCloneSubscribeObj(pInput->pOldSub); - } int32_t totalVgNum = pOutput->pSub->vgNum; mInfo("mq rebalance subscription: %s, vgNum: %d", pOutput->pSub->key, pOutput->pSub->vgNum); @@ -196,21 +196,20 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR // 1. build temporary hash(vgId -> SMqRebOutputVg) to store modified vg SHashObj *pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); - ASSERT(taosHashGetSize(pOutput->pSub->consumerHash) > 0); // 2. check and get actual removed consumers, put their vg into hash int32_t removedNum = taosArrayGetSize(pInput->pRebInfo->removedConsumers); int32_t actualRemoved = 0; for (int32_t i = 0; i < removedNum; i++) { int64_t consumerId = *(int64_t *)taosArrayGet(pInput->pRebInfo->removedConsumers, i); ASSERT(consumerId > 0); - SMqConsumerEpInSub *pEpInSub = taosHashGet(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t)); - ASSERT(pEpInSub); - if (pEpInSub) { - ASSERT(consumerId == pEpInSub->consumerId); + SMqConsumerEp *pConsumerEp = taosHashGet(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t)); + ASSERT(pConsumerEp); + if (pConsumerEp) { + ASSERT(consumerId == pConsumerEp->consumerId); actualRemoved++; - int32_t consumerVgNum = taosArrayGetSize(pEpInSub->vgs); + int32_t consumerVgNum = taosArrayGetSize(pConsumerEp->vgs); for (int32_t j = 0; j < consumerVgNum; j++) { - SMqVgEp *pVgEp = taosArrayGetP(pEpInSub->vgs, j); + SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, j); SMqRebOutputVg outputVg = { .oldConsumerId = consumerId, .newConsumerId = -1, @@ -224,16 +223,12 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR } } ASSERT(removedNum == actualRemoved); - ASSERT(taosHashGetSize(pOutput->pSub->consumerHash) > 0); // if previously no consumer, there are vgs not assigned { - int64_t unexistKey = -1; - SMqConsumerEpInSub *pEpInSub = taosHashGet(pOutput->pSub->consumerHash, &unexistKey, sizeof(int64_t)); - ASSERT(pEpInSub); - int32_t consumerVgNum = taosArrayGetSize(pEpInSub->vgs); + int32_t consumerVgNum = taosArrayGetSize(pOutput->pSub->unassignedVgs); for (int32_t i = 0; i < consumerVgNum; i++) { - SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pEpInSub->vgs); + SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pOutput->pSub->unassignedVgs); SMqRebOutputVg rebOutput = { .oldConsumerId = -1, .newConsumerId = -1, @@ -244,12 +239,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR } // 3. calc vg number of each consumer - int32_t oldSz = 0; - if (pInput->pOldSub) { - oldSz = taosHashGetSize(pInput->pOldSub->consumerHash) - 1; - } - int32_t afterRebConsumerNum = - oldSz + taosArrayGetSize(pInput->pRebInfo->newConsumers) - taosArrayGetSize(pInput->pRebInfo->removedConsumers); + int32_t afterRebConsumerNum = pInput->oldConsumerNum + taosArrayGetSize(pInput->pRebInfo->newConsumers) - + taosArrayGetSize(pInput->pRebInfo->removedConsumers); int32_t minVgCnt = 0; int32_t imbConsumerNum = 0; // calc num @@ -264,23 +255,22 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR while (1) { pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter); if (pIter == NULL) break; - SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; - if (pEpInSub->consumerId == -1) continue; - ASSERT(pEpInSub->consumerId > 0); - int32_t consumerVgNum = taosArrayGetSize(pEpInSub->vgs); + SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter; + ASSERT(pConsumerEp->consumerId > 0); + int32_t consumerVgNum = taosArrayGetSize(pConsumerEp->vgs); // all old consumers still existing are touched // TODO optimize: touch only consumer whose vgs changed - taosArrayPush(pOutput->touchedConsumers, &pEpInSub->consumerId); + taosArrayPush(pOutput->touchedConsumers, &pConsumerEp->consumerId); if (consumerVgNum > minVgCnt) { if (imbCnt < imbConsumerNum) { if (consumerVgNum == minVgCnt + 1) { continue; } else { // pop until equal minVg + 1 - while (taosArrayGetSize(pEpInSub->vgs) > minVgCnt + 1) { - SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pEpInSub->vgs); + while (taosArrayGetSize(pConsumerEp->vgs) > minVgCnt + 1) { + SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pConsumerEp->vgs); SMqRebOutputVg outputVg = { - .oldConsumerId = pEpInSub->consumerId, + .oldConsumerId = pConsumerEp->consumerId, .newConsumerId = -1, .pVgEp = pVgEp, }; @@ -290,10 +280,10 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR } } else { // pop until equal minVg - while (taosArrayGetSize(pEpInSub->vgs) > minVgCnt) { - SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pEpInSub->vgs); + while (taosArrayGetSize(pConsumerEp->vgs) > minVgCnt) { + SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pConsumerEp->vgs); SMqRebOutputVg outputVg = { - .oldConsumerId = pEpInSub->consumerId, + .oldConsumerId = pConsumerEp->consumerId, .newConsumerId = -1, .pVgEp = pVgEp, }; @@ -309,14 +299,10 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR for (int32_t i = 0; i < consumerNum; i++) { int64_t consumerId = *(int64_t *)taosArrayGet(pInput->pRebInfo->newConsumers, i); ASSERT(consumerId > 0); - SMqConsumerEpInSub newConsumerEp; + SMqConsumerEp newConsumerEp; newConsumerEp.consumerId = consumerId; newConsumerEp.vgs = taosArrayInit(0, sizeof(void *)); - taosHashPut(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t), &newConsumerEp, - sizeof(SMqConsumerEpInSub)); - /*SMqConsumerEpInSub *pTestNew = taosHashGet(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t));*/ - /*ASSERT(pTestNew->consumerId == consumerId);*/ - /*ASSERT(pTestNew->vgs == newConsumerEp.vgs);*/ + taosHashPut(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t), &newConsumerEp, sizeof(SMqConsumerEp)); taosArrayPush(pOutput->newConsumers, &consumerId); } } @@ -329,25 +315,24 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR while (1) { pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter); if (pIter == NULL) break; - SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; - if (pEpInSub->consumerId == -1) continue; - ASSERT(pEpInSub->consumerId > 0); + SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter; + ASSERT(pConsumerEp->consumerId > 0); // push until equal minVg - while (taosArrayGetSize(pEpInSub->vgs) < minVgCnt) { + while (taosArrayGetSize(pConsumerEp->vgs) < minVgCnt) { // iter hash and find one vg pRemovedIter = taosHashIterate(pHash, pRemovedIter); ASSERT(pRemovedIter); pRebVg = (SMqRebOutputVg *)pRemovedIter; // push - taosArrayPush(pEpInSub->vgs, &pRebVg->pVgEp); - pRebVg->newConsumerId = pEpInSub->consumerId; + taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp); + pRebVg->newConsumerId = pConsumerEp->consumerId; taosArrayPush(pOutput->rebVgs, pRebVg); } } // 7. handle unassigned vg - if (taosHashGetSize(pOutput->pSub->consumerHash) != 1) { + if (taosHashGetSize(pOutput->pSub->consumerHash) != 0) { // if has consumer, assign all left vg while (1) { pRemovedIter = taosHashIterate(pHash, pRemovedIter); @@ -355,20 +340,14 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter); ASSERT(pIter); pRebVg = (SMqRebOutputVg *)pRemovedIter; - SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; - if (pEpInSub->consumerId == -1) continue; - ASSERT(pEpInSub->consumerId > 0); - taosArrayPush(pEpInSub->vgs, &pRebVg->pVgEp); - pRebVg->newConsumerId = pEpInSub->consumerId; + SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter; + ASSERT(pConsumerEp->consumerId > 0); + taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp); + pRebVg->newConsumerId = pConsumerEp->consumerId; taosArrayPush(pOutput->rebVgs, pRebVg); } } else { // if all consumer is removed, put all vg into unassigned - int64_t unexistKey = -1; - SMqConsumerEpInSub *pEpInSub = taosHashGet(pOutput->pSub->consumerHash, &unexistKey, sizeof(int64_t)); - ASSERT(pEpInSub); - ASSERT(pEpInSub->consumerId == -1); - pIter = NULL; SMqRebOutputVg *pRebOutput = NULL; while (1) { @@ -376,12 +355,18 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR if (pIter == NULL) break; pRebOutput = (SMqRebOutputVg *)pIter; ASSERT(pRebOutput->newConsumerId == -1); - taosArrayPush(pEpInSub->vgs, &pRebOutput->pVgEp); + taosArrayPush(pOutput->pSub->unassignedVgs, &pRebOutput->pVgEp); taosArrayPush(pOutput->rebVgs, pRebOutput); } } - // 8. generate logs + // 8. TODO generate logs + mInfo("rebalance calculation completed, rebalanced vg:"); + for (int32_t i = 0; i < taosArrayGetSize(pOutput->rebVgs); i++) { + SMqRebOutputVg *pOutputRebVg = taosArrayGet(pOutput->rebVgs, i); + mInfo("vg: %d moved from consumer %ld to consumer %ld", pOutputRebVg->pVgEp->vgId, pOutputRebVg->oldConsumerId, + pOutputRebVg->newConsumerId); + } // 9. clear taosHashCleanup(pHash); @@ -459,7 +444,12 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SNodeMsg *pMsg, const SMqRebO goto REB_FAIL; } } - // 4. commit log: modification log + // 4. TODO commit log: modification log + + // 5. set cb + mndTransSetCb(pTrans, MQ_REB_TRANS_START_FUNC, MQ_REB_TRANS_STOP_FUNC, NULL, 0); + + // 6. execution if (mndTransPrepare(pMnode, pTrans) != 0) goto REB_FAIL; mndTransDrop(pTrans); @@ -488,22 +478,34 @@ static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg) { rebOutput.touchedConsumers = taosArrayInit(0, sizeof(void *)); rebOutput.rebVgs = taosArrayInit(0, sizeof(SMqRebOutputVg)); - SMqRebSubscribe *pRebSub = (SMqRebSubscribe *)pIter; - SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pRebSub->key); + SMqRebInfo *pRebInfo = (SMqRebInfo *)pIter; + SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pRebInfo->key); + + rebInput.pRebInfo = pRebInfo; if (pSub == NULL) { // split sub key and extract topic char topic[TSDB_TOPIC_FNAME_LEN]; char cgroup[TSDB_CGROUP_LEN]; - mndSplitSubscribeKey(pRebSub->key, topic, cgroup); + mndSplitSubscribeKey(pRebInfo->key, topic, cgroup); SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); ASSERT(pTopic); taosRLockLatch(&pTopic->lock); - rebInput.pTopic = pTopic; - } - rebInput.pRebInfo = pRebSub; - rebInput.pOldSub = pSub; + rebOutput.pSub = mndCreateSub(pMnode, pTopic, pRebInfo->key); + ASSERT(taosHashGetSize(rebOutput.pSub->consumerHash) == 0); + + taosRUnLockLatch(&pTopic->lock); + mndReleaseTopic(pMnode, pTopic); + + rebInput.oldConsumerNum = 0; + } else { + taosRLockLatch(&pSub->lock); + rebInput.oldConsumerNum = taosHashGetSize(pSub->consumerHash); + rebOutput.pSub = tCloneSubscribeObj(pSub); + taosRUnLockLatch(&pSub->lock); + mndReleaseSubscribe(pMnode, pSub); + } // TODO replace assert with error check ASSERT(mndDoRebalance(pMnode, &rebInput, &rebOutput) == 0); @@ -512,21 +514,16 @@ static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg) { // possibly no vg is changed /*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/ - ASSERT(mndPersistRebResult(pMnode, pMsg, &rebOutput) == 0); - - if (rebInput.pTopic) { - SMqTopicObj *pTopic = (SMqTopicObj *)rebInput.pTopic; - taosRUnLockLatch(&pTopic->lock); - mndReleaseTopic(pMnode, pTopic); - } else { - mndReleaseSubscribe(pMnode, pSub); + // TODO replace assert with error check + if (mndPersistRebResult(pMnode, pMsg, &rebOutput) < 0) { + mError("persist rebalance output error, possibly vnode splitted or dropped"); } } // reset flag - atomic_store_8(pReq->mqInReb, 0); mInfo("mq rebalance completed successfully"); taosHashCleanup(pReq->rebSubHash); + mndRebEnd(); return 0; } @@ -590,7 +587,7 @@ static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) { int32_t dataPos = 0; int32_t tlen; SDB_GET_INT32(pRaw, dataPos, &tlen, SUB_DECODE_OVER); - buf = taosMemoryMalloc(tlen + 1); + buf = taosMemoryMalloc(tlen); if (buf == NULL) goto SUB_DECODE_OVER; SDB_GET_BINARY(pRaw, dataPos, buf, tlen, SUB_DECODE_OVER); SDB_GET_RESERVE(pRaw, dataPos, MND_SUBSCRIBE_RESERVE_SIZE, SUB_DECODE_OVER); @@ -631,6 +628,10 @@ static int32_t mndSubActionUpdate(SSdb *pSdb, SMqSubscribeObj *pOldSub, SMqSubsc pOldSub->consumerHash = pNewSub->consumerHash; pNewSub->consumerHash = tmp; + SArray *tmp1 = pOldSub->unassignedVgs; + pOldSub->unassignedVgs = pNewSub->unassignedVgs; + pNewSub->unassignedVgs = tmp1; + taosWUnLockLatch(&pOldSub->lock); return 0; } @@ -672,3 +673,36 @@ static int32_t mndProcessSubscribeInternalRsp(SNodeMsg *pRsp) { mndTransProcessRsp(pRsp); return 0; } + +static int32_t mndSetDropSubCommitLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub) { + SSdbRaw *pCommitRaw = mndSubActionEncode(pSub); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + +int32_t mndDropSubByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { + int32_t code = -1; + SSdb *pSdb = pMnode->pSdb; + + void *pIter = NULL; + SMqSubscribeObj *pSub = NULL; + while (1) { + pIter = sdbFetch(pSdb, SDB_SUBSCRIBE, pIter, (void **)&pSub); + if (pIter == NULL) break; + + if (pSub->dbUid != pDb->uid) { + sdbRelease(pSdb, pSub); + continue; + } + + if (mndSetDropSubCommitLogs(pMnode, pTrans, pSub) < 0) { + goto END; + } + } + + code = 0; +END: + return code; +} diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 731ee69105846f0ec9d44c6d9837281ea8952f95..0a8d1cee4ad873bf79f85ffbe44ce1f94ddb9511 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -38,6 +38,8 @@ static int32_t mndProcessDropTopicInRsp(SNodeMsg *pRsp); static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter); +static int32_t mndSetDropTopicCommitLogs(SMnode *pMnode, STrans *pTrans, SMqTopicObj *pTopic); + int32_t mndInitTopic(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_TOPIC, .keyType = SDB_KEY_BINARY, @@ -553,7 +555,41 @@ static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB return numOfRows; } +static int32_t mndSetDropTopicCommitLogs(SMnode *pMnode, STrans *pTrans, SMqTopicObj *pTopic) { + SSdbRaw *pCommitRaw = mndTopicActionEncode(pTopic); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + + return 0; +} + static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter) { SSdb *pSdb = pMnode->pSdb; sdbCancelFetch(pSdb, pIter); } + +int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { + int32_t code = -1; + SSdb *pSdb = pMnode->pSdb; + + void *pIter = NULL; + SMqTopicObj *pTopic = NULL; + while (1) { + pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic); + if (pIter == NULL) break; + + if (pTopic->dbUid != pDb->uid) { + sdbRelease(pSdb, pTopic); + continue; + } + + if (mndSetDropTopicCommitLogs(pMnode, pTrans, pTopic) < 0) { + goto END; + } + } + + code = 0; +END: + return code; +} diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index c08b0f6db94b19f270f608690bca875c0664a763..bbd952b6d0449c2c82650e461a03fd9fa83165fa 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "mndTrans.h" #include "mndAuth.h" +#include "mndConsumer.h" #include "mndDb.h" #include "mndShow.h" #include "mndSync.h" @@ -442,6 +443,10 @@ static TransCbFp mndTransGetCbFp(ETrnFuncType ftype) { return mndTransTestStartFunc; case TEST_TRANS_STOP_FUNC: return mndTransTestStopFunc; + case MQ_REB_TRANS_START_FUNC: + return mndRebCntInc; + case MQ_REB_TRANS_STOP_FUNC: + return mndRebCntDec; default: return NULL; } @@ -1346,17 +1351,17 @@ static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB colDataAppend(pColInfo, numOfRows, (const char *)&pTrans->createdTime, false); char stage[TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(stage, mndTransStr(pTrans->stage), pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(stage, mndTransStr(pTrans->stage), pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)stage, false); char dbname[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndGetDbStr(pTrans->dbname), pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndGetDbStr(pTrans->dbname), pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)dbname, false); char transType[TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndTransType(pTrans->transType), pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndTransType(pTrans->transType), pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)transType, false); @@ -1364,7 +1369,7 @@ static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB colDataAppend(pColInfo, numOfRows, (const char *)&pTrans->lastExecTime, false); char lastError[TSDB_TRANS_ERROR_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(dbname, pTrans->lastError, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(dbname, pTrans->lastError, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)lastError, false); diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index f739810065258796123f8d25da8a4ecf375bd9aa..2ced8130030969b3657465af7cc91c4a22dfaabb 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -39,14 +39,16 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p static void mndCancelGetNextUser(SMnode *pMnode, void *pIter); int32_t mndInitUser(SMnode *pMnode) { - SSdbTable table = {.sdbType = SDB_USER, - .keyType = SDB_KEY_BINARY, - .deployFp = (SdbDeployFp)mndCreateDefaultUsers, - .encodeFp = (SdbEncodeFp)mndUserActionEncode, - .decodeFp = (SdbDecodeFp)mndUserActionDecode, - .insertFp = (SdbInsertFp)mndUserActionInsert, - .updateFp = (SdbUpdateFp)mndUserActionUpdate, - .deleteFp = (SdbDeleteFp)mndUserActionDelete}; + SSdbTable table = { + .sdbType = SDB_USER, + .keyType = SDB_KEY_BINARY, + .deployFp = (SdbDeployFp)mndCreateDefaultUsers, + .encodeFp = (SdbEncodeFp)mndUserActionEncode, + .decodeFp = (SdbDecodeFp)mndUserActionDecode, + .insertFp = (SdbInsertFp)mndUserActionInsert, + .updateFp = (SdbUpdateFp)mndUserActionUpdate, + .deleteFp = (SdbDeleteFp)mndUserActionDelete, + }; mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserReq); mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserReq); @@ -655,7 +657,7 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols); char name[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->user, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->user, pShow->pMeta->pSchemas[cols].bytes); colDataAppend(pColInfo, numOfRows, (const char *)name, false); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index aab9ac61a24b760bfae8c206b763ba1b597dea5e..31e4a8ea7daa0df17f1cb5effb08c3f531474a93 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -190,25 +190,24 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg memcpy(createReq.db, pDb->name, TSDB_DB_FNAME_LEN); createReq.dbUid = pDb->uid; createReq.vgVersion = pVgroup->version; - createReq.cacheBlockSize = pDb->cfg.cacheBlockSize; - createReq.totalBlocks = pDb->cfg.totalBlocks; + createReq.numOfStables = pDb->cfg.numOfStables; + createReq.buffer = pDb->cfg.buffer; + createReq.pageSize = pDb->cfg.pageSize; + createReq.pages = pDb->cfg.pages; createReq.daysPerFile = pDb->cfg.daysPerFile; createReq.daysToKeep0 = pDb->cfg.daysToKeep0; createReq.daysToKeep1 = pDb->cfg.daysToKeep1; createReq.daysToKeep2 = pDb->cfg.daysToKeep2; createReq.minRows = pDb->cfg.minRows; createReq.maxRows = pDb->cfg.maxRows; - createReq.commitTime = pDb->cfg.commitTime; createReq.fsyncPeriod = pDb->cfg.fsyncPeriod; createReq.walLevel = pDb->cfg.walLevel; createReq.precision = pDb->cfg.precision; createReq.compression = pDb->cfg.compression; createReq.strict = pDb->cfg.strict; - createReq.update = pDb->cfg.update; createReq.cacheLastRow = pDb->cfg.cacheLastRow; createReq.replica = pVgroup->replica; createReq.selfIndex = -1; - createReq.streamMode = pVgroup->streamMode; createReq.hashBegin = pVgroup->hashBegin; createReq.hashEnd = pVgroup->hashEnd; createReq.hashMethod = pDb->cfg.hashMethod; @@ -398,7 +397,6 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { pVgroup->createdTime = taosGetTimestampMs(); pVgroup->updateTime = pVgroups->createdTime; pVgroup->version = 1; - pVgroup->streamMode = pDb->cfg.streamMode; pVgroup->hashBegin = hashMin + hashInterval * v; if (v == pDb->cfg.numOfVgroups - 1) { pVgroup->hashEnd = hashMax; @@ -542,7 +540,7 @@ static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* char buf1[20] = {0}; const char *role = syncStr(pVgroup->vnodeGid[i].role); - STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)buf1, false); diff --git a/source/dnode/mnode/impl/test/db/db.cpp b/source/dnode/mnode/impl/test/db/db.cpp index 6e72ce89d3512a471b4038a836114866b6d6309d..3c5bf5c0835893fe945b33ad5b5f9535030ad5ad 100644 --- a/source/dnode/mnode/impl/test/db/db.cpp +++ b/source/dnode/mnode/impl/test/db/db.cpp @@ -35,27 +35,24 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { SCreateDbReq createReq = {0}; strcpy(createReq.db, "1.d1"); createReq.numOfVgroups = 2; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; + createReq.buffer = -1; + createReq.pageSize = -1; + createReq.pages = -1; createReq.daysPerFile = 1000; createReq.daysToKeep0 = 3650; createReq.daysToKeep1 = 3650; createReq.daysToKeep2 = 3650; createReq.minRows = 100; createReq.maxRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; - createReq.ttl = 1; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; createReq.ignoreExist = 1; - createReq.streamMode = 0; - createReq.singleSTable = 0; + createReq.numOfStables = 0; createReq.numOfRetensions = 0; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); @@ -76,7 +73,7 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { { SAlterDbReq alterdbReq = {0}; strcpy(alterdbReq.db, "1.d1"); - alterdbReq.totalBlocks = 12; + alterdbReq.buffer = 12; alterdbReq.daysToKeep0 = 300; alterdbReq.daysToKeep1 = 400; alterdbReq.daysToKeep2 = 500; @@ -129,27 +126,24 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) { SCreateDbReq createReq = {0}; strcpy(createReq.db, "1.d2"); createReq.numOfVgroups = 2; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; + createReq.buffer = -1; + createReq.pageSize = -1; + createReq.pages = -1; createReq.daysPerFile = 1000; createReq.daysToKeep0 = 3650; createReq.daysToKeep1 = 3650; createReq.daysToKeep2 = 3650; createReq.minRows = 100; createReq.maxRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; - createReq.ttl = 1; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; createReq.ignoreExist = 1; - createReq.streamMode = 0; - createReq.singleSTable = 0; + createReq.numOfStables = 0; createReq.numOfRetensions = 0; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp index 998dca1401340f652eec59d238229afa7999eaed..b93adf99305492fec346a1fb981aef7e4e55979f 100644 --- a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp +++ b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp @@ -9,75 +9,896 @@ * */ -#include "sut.h" +#include -class MndTestShow : public ::testing::Test { +#include "sdb.h" + +class MndTestSdb : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9021); } - static void TearDownTestSuite() { test.Cleanup(); } + static void SetUpTestSuite() { + dDebugFlag = 143; + vDebugFlag = 0; + mDebugFlag = 143; + cDebugFlag = 0; + jniDebugFlag = 0; + tmrDebugFlag = 135; + uDebugFlag = 135; + rpcDebugFlag = 143; + qDebugFlag = 0; + wDebugFlag = 0; + sDebugFlag = 0; + tsdbDebugFlag = 0; + tsLogEmbedded = 1; + tsAsyncLog = 0; - static Testbase test; + const char *path = "/tmp/td"; + taosRemoveDir(path); + taosMkDir(path); + tstrncpy(tsLogDir, path, PATH_MAX); + if (taosInitLog("taosdlog", 1) != 0) { + printf("failed to init log file\n"); + } + } + static void TearDownTestSuite() { taosCloseLog(); } public: void SetUp() override {} void TearDown() override {} }; -Testbase MndTestShow::test; +typedef struct SMnode { + int32_t v100; + int32_t v200; + int32_t insertTimes; + int32_t deleteTimes; + SSdb *pSdb; +} SMnode; + +typedef struct SStrObj { + char key[24]; + int8_t v8; + int16_t v16; + int32_t v32; + int64_t v64; + char vstr[32]; + char unused[48]; +} SStrObj; + +typedef struct SI32Obj { + int32_t key; + int8_t v8; + int16_t v16; + int32_t v32; + int64_t v64; + char vstr[32]; + char unused[48]; +} SI32Obj; + +typedef struct SI64Obj { + int64_t key; + int8_t v8; + int16_t v16; + int32_t v32; + int64_t v64; + char vstr[32]; + char unused[48]; +} SI64Obj; + +SSdbRaw *strEncode(SStrObj *pObj) { + int32_t dataPos = 0; + SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, 1, sizeof(SStrObj)); + + sdbSetRawBinary(pRaw, dataPos, pObj->key, sizeof(pObj->key)); + dataPos += sizeof(pObj->key); + sdbSetRawInt8(pRaw, dataPos, pObj->v8); + dataPos += sizeof(pObj->v8); + sdbSetRawInt16(pRaw, dataPos, pObj->v16); + dataPos += sizeof(pObj->v16); + sdbSetRawInt32(pRaw, dataPos, pObj->v32); + dataPos += sizeof(pObj->v32); + sdbSetRawInt64(pRaw, dataPos, pObj->v64); + dataPos += sizeof(pObj->v64); + sdbSetRawBinary(pRaw, dataPos, pObj->vstr, sizeof(pObj->vstr)); + dataPos += sizeof(pObj->vstr); + sdbSetRawDataLen(pRaw, dataPos); + + return pRaw; +} + +SSdbRaw *i32Encode(SI32Obj *pObj) { + int32_t dataPos = 0; + SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, 2, sizeof(SI32Obj)); + + sdbSetRawInt32(pRaw, dataPos, pObj->key); + dataPos += sizeof(pObj->key); + sdbSetRawInt8(pRaw, dataPos, pObj->v8); + dataPos += sizeof(pObj->v8); + sdbSetRawInt16(pRaw, dataPos, pObj->v16); + dataPos += sizeof(pObj->v16); + sdbSetRawInt32(pRaw, dataPos, pObj->v32); + dataPos += sizeof(pObj->v32); + sdbSetRawInt64(pRaw, dataPos, pObj->v64); + dataPos += sizeof(pObj->v64); + sdbSetRawBinary(pRaw, dataPos, pObj->vstr, sizeof(pObj->vstr)); + dataPos += sizeof(pObj->vstr); + sdbSetRawDataLen(pRaw, dataPos); + + return pRaw; +} + +SSdbRaw *i64Encode(SI64Obj *pObj) { + int32_t dataPos = 0; + SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, 3, sizeof(SI64Obj)); + + sdbSetRawInt64(pRaw, dataPos, pObj->key); + dataPos += sizeof(pObj->key); + sdbSetRawInt8(pRaw, dataPos, pObj->v8); + dataPos += sizeof(pObj->v8); + sdbSetRawInt16(pRaw, dataPos, pObj->v16); + dataPos += sizeof(pObj->v16); + sdbSetRawInt32(pRaw, dataPos, pObj->v32); + dataPos += sizeof(pObj->v32); + sdbSetRawInt64(pRaw, dataPos, pObj->v64); + dataPos += sizeof(pObj->v64); + sdbSetRawBinary(pRaw, dataPos, pObj->vstr, sizeof(pObj->vstr)); + dataPos += sizeof(pObj->vstr); + sdbSetRawDataLen(pRaw, dataPos); + + return pRaw; +} + +SSdbRow *strDecode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sver != 1) return NULL; + + SSdbRow *pRow = sdbAllocRow(sizeof(SStrObj)); + if (pRow == NULL) return NULL; + + SStrObj *pObj = (SStrObj *)sdbGetRowObj(pRow); + if (pObj == NULL) return NULL; + + int32_t dataPos = 0; + sdbGetRawBinary(pRaw, dataPos, pObj->key, sizeof(pObj->key)); + dataPos += sizeof(pObj->key); + sdbGetRawInt8(pRaw, dataPos, &pObj->v8); + dataPos += sizeof(pObj->v8); + sdbGetRawInt16(pRaw, dataPos, &pObj->v16); + dataPos += sizeof(pObj->v16); + sdbGetRawInt32(pRaw, dataPos, &pObj->v32); + dataPos += sizeof(pObj->v32); + sdbGetRawInt64(pRaw, dataPos, &pObj->v64); + dataPos += sizeof(pObj->v64); + sdbGetRawBinary(pRaw, dataPos, pObj->vstr, sizeof(pObj->vstr)); + dataPos += sizeof(pObj->vstr); + + return pRow; +} + +SSdbRow *i32Decode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sver != 2) return NULL; + + SSdbRow *pRow = sdbAllocRow(sizeof(SI32Obj)); + if (pRow == NULL) return NULL; + + SI32Obj *pObj = (SI32Obj *)sdbGetRowObj(pRow); + if (pObj == NULL) return NULL; + + int32_t dataPos = 0; + sdbGetRawInt32(pRaw, dataPos, &pObj->key); + dataPos += sizeof(pObj->key); + sdbGetRawInt8(pRaw, dataPos, &pObj->v8); + dataPos += sizeof(pObj->v8); + sdbGetRawInt16(pRaw, dataPos, &pObj->v16); + dataPos += sizeof(pObj->v16); + sdbGetRawInt32(pRaw, dataPos, &pObj->v32); + dataPos += sizeof(pObj->v32); + sdbGetRawInt64(pRaw, dataPos, &pObj->v64); + dataPos += sizeof(pObj->v64); + sdbGetRawBinary(pRaw, dataPos, pObj->vstr, sizeof(pObj->vstr)); + dataPos += sizeof(pObj->vstr); + + return pRow; +} + +SSdbRow *i64Decode(SSdbRaw *pRaw) { + int8_t sver = 0; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sver != 3) return NULL; -TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) { - SShowReq showReq = {0}; - showReq.type = TSDB_MGMT_TABLE_MAX; + SSdbRow *pRow = sdbAllocRow(sizeof(SI64Obj)); + if (pRow == NULL) return NULL; - int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSShowReq(pReq, contLen, &showReq); - tFreeSShowReq(&showReq); + SI64Obj *pObj = (SI64Obj *)sdbGetRowObj(pRow); + if (pObj == NULL) return NULL; - SRpcMsg* pRsp = test.SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_NE(pRsp->code, 0); + int32_t dataPos = 0; + sdbGetRawInt64(pRaw, dataPos, &pObj->key); + dataPos += sizeof(pObj->key); + sdbGetRawInt8(pRaw, dataPos, &pObj->v8); + dataPos += sizeof(pObj->v8); + sdbGetRawInt16(pRaw, dataPos, &pObj->v16); + dataPos += sizeof(pObj->v16); + sdbGetRawInt32(pRaw, dataPos, &pObj->v32); + dataPos += sizeof(pObj->v32); + sdbGetRawInt64(pRaw, dataPos, &pObj->v64); + dataPos += sizeof(pObj->v64); + sdbGetRawBinary(pRaw, dataPos, pObj->vstr, sizeof(pObj->vstr)); + dataPos += sizeof(pObj->vstr); + + return pRow; } -TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) { - SShowReq showReq = {0}; - showReq.type = TSDB_MGMT_TABLE_START; +int32_t strInsert(SSdb *pSdb, SStrObj *pObj) { + SMnode *pMnode = pSdb->pMnode; + pMnode->insertTimes++; + return 0; +} - int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSShowReq(pReq, contLen, &showReq); - tFreeSShowReq(&showReq); +int32_t i32Insert(SSdb *pSdb, SI32Obj *pObj) { + SMnode *pMnode = pSdb->pMnode; + pMnode->insertTimes++; + return 0; +} - SRpcMsg* pRsp = test.SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_NE(pRsp->code, 0); +int32_t i64Insert(SSdb *pSdb, SI64Obj *pObj) { + SMnode *pMnode = pSdb->pMnode; + pMnode->insertTimes++; + return 0; } -TEST_F(MndTestShow, 03_ShowMsg_Conn) { - char passwd[] = "taosdata"; - char secretEncrypt[TSDB_PASSWORD_LEN] = {0}; - taosEncryptPass_c((uint8_t*)passwd, strlen(passwd), secretEncrypt); +int32_t strDelete(SSdb *pSdb, SStrObj *pObj, bool callFunc) { + if (callFunc) { + SMnode *pMnode = pSdb->pMnode; + pMnode->deleteTimes++; + } + return 0; +} - SConnectReq connectReq = {0}; - connectReq.pid = 1234; - strcpy(connectReq.app, "mnode_test_show"); - strcpy(connectReq.db, ""); - strcpy(connectReq.user, "root"); - strcpy(connectReq.passwd, secretEncrypt); +int32_t i32Delete(SSdb *pSdb, SI32Obj *pObj, bool callFunc) { + if (callFunc) { + SMnode *pMnode = pSdb->pMnode; + pMnode->deleteTimes++; + } + return 0; +} - int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSConnectReq(pReq, contLen, &connectReq); +int32_t i64Delete(SSdb *pSdb, SI64Obj *pObj, bool callFunc) { + if (callFunc) { + SMnode *pMnode = pSdb->pMnode; + pMnode->deleteTimes++; + } + return 0; +} - SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, 0); +int32_t strUpdate(SSdb *pSdb, SStrObj *pOld, SStrObj *pNew) { + pOld->v8 = pNew->v8; + pOld->v16 = pNew->v16; + pOld->v32 = pNew->v32; + pOld->v64 = pNew->v64; + strcpy(pOld->vstr, pNew->vstr); + return 0; +} - test.SendShowReq(TSDB_MGMT_TABLE_CONNS, "connections", ""); - // EXPECT_EQ(test.GetShowRows(), 1); +int32_t i32Update(SSdb *pSdb, SI32Obj *pOld, SI32Obj *pNew) { + pOld->v8 = pNew->v8; + pOld->v16 = pNew->v16; + pOld->v32 = pNew->v32; + pOld->v64 = pNew->v64; + strcpy(pOld->vstr, pNew->vstr); + return 0; } -TEST_F(MndTestShow, 04_ShowMsg_Cluster) { - test.SendShowReq(TSDB_MGMT_TABLE_CLUSTER, "cluster", ""); - EXPECT_EQ(test.GetShowRows(), 1); +int32_t i64Update(SSdb *pSdb, SI64Obj *pOld, SI64Obj *pNew) { + pOld->v8 = pNew->v8; + pOld->v16 = pNew->v16; + pOld->v32 = pNew->v32; + pOld->v64 = pNew->v64; + strcpy(pOld->vstr, pNew->vstr); + return 0; } + +void strSetDefault(SStrObj *pObj, int32_t index) { + memset(pObj, 0, sizeof(SStrObj)); + snprintf(pObj->key, sizeof(pObj->key), "k%d", index * 1000); + pObj->v8 = index; + pObj->v16 = index; + pObj->v32 = index * 1000; + pObj->v64 = index * 1000; + snprintf(pObj->vstr, sizeof(pObj->vstr), "v%d", index * 1000); +} + +void i32SetDefault(SI32Obj *pObj, int32_t index) { + memset(pObj, 0, sizeof(SI32Obj)); + pObj->key = index; + pObj->v8 = index; + pObj->v16 = index; + pObj->v32 = index * 1000; + pObj->v64 = index * 1000; + snprintf(pObj->vstr, sizeof(pObj->vstr), "v%d", index * 1000); +} + +void i64SetDefault(SI64Obj *pObj, int32_t index) { + memset(pObj, 0, sizeof(SI64Obj)); + pObj->key = index; + pObj->v8 = index; + pObj->v16 = index; + pObj->v32 = index * 1000; + pObj->v64 = index * 1000; + snprintf(pObj->vstr, sizeof(pObj->vstr), "v%d", index * 1000); +} + +int32_t strDefault(SMnode *pMnode) { + SStrObj strObj; + SSdbRaw *pRaw = NULL; + + strSetDefault(&strObj, 1); + pRaw = strEncode(&strObj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (sdbWrite(pMnode->pSdb, pRaw) != 0) return -1; + + strSetDefault(&strObj, 2); + pRaw = strEncode(&strObj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (sdbWriteWithoutFree(pMnode->pSdb, pRaw) != 0) return -1; + + EXPECT_EQ(sdbGetRawTotalSize(pRaw), 79); + sdbFreeRaw(pRaw); + + return 0; +} + +bool sdbTraverseSucc1(SMnode *pMnode, SStrObj *pObj, int32_t *p1, int32_t *p2, int32_t *p3) { + if (pObj->v8 == 1) { + *p1 += *p2 + *p3 + pObj->v8; + } + return true; +} + +bool sdbTraverseSucc2(SMnode *pMnode, SStrObj *pObj, int32_t *p1, int32_t *p2, int32_t *p3) { + *p1 += *p2 + *p3 + pObj->v8; + return true; +} + +bool sdbTraverseFail(SMnode *pMnode, SStrObj *pObj, int32_t *p1, int32_t *p2, int32_t *p3) { + *p1 += *p2 + *p3; + return false; +} + +TEST_F(MndTestSdb, 01_Write_Str) { + void *pIter = NULL; + int32_t num = 0; + SStrObj *pObj = NULL; + SMnode mnode = {0}; + SSdb *pSdb = NULL; + SSdbOpt opt = {0}; + SStrObj strObj = {0}; + SI32Obj i32Obj = {0}; + SI64Obj i64Obj = {0}; + SSdbRaw *pRaw = NULL; + int32_t p1 = 0; + int32_t p2 = 111; + int32_t p3 = 222; + + mnode.v100 = 100; + mnode.v200 = 200; + opt.pMnode = &mnode; + opt.path = "/tmp/mnode_test_sdb"; + taosRemoveDir(opt.path); + + SSdbTable strTable1; + memset(&strTable1, 0, sizeof(SSdbTable)); + strTable1.sdbType = SDB_USER; + strTable1.keyType = SDB_KEY_BINARY; + strTable1.deployFp = (SdbDeployFp)strDefault; + strTable1.encodeFp = (SdbEncodeFp)strEncode; + strTable1.decodeFp = (SdbDecodeFp)strDecode; + strTable1.insertFp = (SdbInsertFp)strInsert; + strTable1.updateFp = (SdbUpdateFp)strUpdate; + strTable1.deleteFp = (SdbDeleteFp)strDelete; + + SSdbTable strTable2; + memset(&strTable2, 0, sizeof(SSdbTable)); + strTable2.sdbType = SDB_VGROUP; + strTable2.keyType = SDB_KEY_INT32; + strTable2.encodeFp = (SdbEncodeFp)i32Encode; + strTable2.decodeFp = (SdbDecodeFp)i32Decode; + strTable2.insertFp = (SdbInsertFp)i32Insert; + strTable2.updateFp = (SdbUpdateFp)i32Update; + strTable2.deleteFp = (SdbDeleteFp)i32Delete; + + SSdbTable strTable3; + memset(&strTable3, 0, sizeof(SSdbTable)); + strTable3.sdbType = SDB_CONSUMER; + strTable3.keyType = SDB_KEY_INT64; + strTable3.encodeFp = (SdbEncodeFp)i64Encode; + strTable3.decodeFp = (SdbDecodeFp)i64Decode; + strTable3.insertFp = (SdbInsertFp)i64Insert; + strTable3.updateFp = (SdbUpdateFp)i64Update; + strTable3.deleteFp = (SdbDeleteFp)i64Delete; + + pSdb = sdbInit(&opt); + mnode.pSdb = pSdb; + + ASSERT_NE(pSdb, nullptr); + ASSERT_EQ(sdbSetTable(pSdb, strTable1), 0); + ASSERT_EQ(sdbSetTable(pSdb, strTable2), 0); + ASSERT_EQ(sdbSetTable(pSdb, strTable3), 0); + ASSERT_EQ(sdbDeploy(pSdb), 0); + + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k1000"); + ASSERT_NE(pObj, nullptr); + EXPECT_STREQ(pObj->key, "k1000"); + EXPECT_STREQ(pObj->vstr, "v1000"); + ASSERT_EQ(pObj->v8, 1); + ASSERT_EQ(pObj->v16, 1); + ASSERT_EQ(pObj->v32, 1000); + ASSERT_EQ(pObj->v64, 1000); + sdbRelease(pSdb, pObj); + + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k2000"); + ASSERT_NE(pObj, nullptr); + EXPECT_STREQ(pObj->key, "k2000"); + EXPECT_STREQ(pObj->vstr, "v2000"); + ASSERT_EQ(pObj->v8, 2); + ASSERT_EQ(pObj->v16, 2); + ASSERT_EQ(pObj->v32, 2000); + ASSERT_EQ(pObj->v64, 2000); + sdbRelease(pSdb, pObj); + + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k200"); + ASSERT_EQ(pObj, nullptr); + + pIter = NULL; + num = 0; + do { + pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pObj); + if (pIter == NULL) break; + ASSERT_NE(pObj, nullptr); + num++; + sdbRelease(pSdb, pObj); + } while (1); + ASSERT_EQ(num, 2); + + do { + pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pObj); + if (pIter == NULL) break; + if (strcmp(pObj->key, "k1000") == 0) { + sdbCancelFetch(pSdb, pIter); + break; + } + } while (1); + EXPECT_STREQ(pObj->key, "k1000"); + + p1 = 0; + p2 = 111; + p3 = 222; + sdbTraverse(pSdb, SDB_USER, (sdbTraverseFp)sdbTraverseSucc1, &p1, &p2, &p3); + ASSERT_EQ(p1, 334); + + p1 = 0; + p2 = 111; + p3 = 222; + sdbTraverse(pSdb, SDB_USER, (sdbTraverseFp)sdbTraverseSucc2, &p1, &p2, &p3); + ASSERT_EQ(p1, 669); + + p1 = 0; + p2 = 111; + p3 = 222; + sdbTraverse(pSdb, SDB_USER, (sdbTraverseFp)sdbTraverseFail, &p1, &p2, &p3); + ASSERT_EQ(p1, 333); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_USER), 2); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_USER), -1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_USER), 2 ); + ASSERT_EQ(sdbUpdateVer(pSdb, 0), -1); + ASSERT_EQ(sdbUpdateVer(pSdb, 1), 0); + ASSERT_EQ(sdbUpdateVer(pSdb, -1), -1); + ASSERT_EQ(mnode.insertTimes, 2); + ASSERT_EQ(mnode.deleteTimes, 0); + + { + // insert, call func + strSetDefault(&strObj, 3); + pRaw = strEncode(&strObj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k3000"); + ASSERT_NE(pObj, nullptr); + EXPECT_STREQ(pObj->key, "k3000"); + EXPECT_STREQ(pObj->vstr, "v3000"); + ASSERT_EQ(pObj->v8, 3); + ASSERT_EQ(pObj->v16, 3); + ASSERT_EQ(pObj->v32, 3000); + ASSERT_EQ(pObj->v64, 3000); + sdbRelease(pSdb, pObj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_USER), 3); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_USER), 3); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_USER), -1); + + // update, call func + strSetDefault(&strObj, 3); + strObj.v8 = 4; + pRaw = strEncode(&strObj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k3000"); + ASSERT_NE(pObj, nullptr); + EXPECT_STREQ(pObj->key, "k3000"); + EXPECT_STREQ(pObj->vstr, "v3000"); + ASSERT_EQ(pObj->v8, 4); + ASSERT_EQ(pObj->v16, 3); + ASSERT_EQ(pObj->v32, 3000); + ASSERT_EQ(pObj->v64, 3000); + sdbRelease(pSdb, pObj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_USER), 3); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_USER), 4); + ASSERT_EQ(sdbUpdateVer(pSdb, 0), -1); + ASSERT_EQ(sdbUpdateVer(pSdb, 1), 0); + ASSERT_EQ(sdbUpdateVer(pSdb, -1), -1); + ASSERT_EQ(mnode.insertTimes, 3); + ASSERT_EQ(mnode.deleteTimes, 0); + + // delete, call func 2 + strSetDefault(&strObj, 3); + strObj.v16 = 4; + pRaw = strEncode(&strObj); + sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k3000"); + ASSERT_EQ(pObj, nullptr); + ASSERT_EQ(sdbGetSize(pSdb, SDB_USER), 2); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_USER), 5); + ASSERT_EQ(mnode.insertTimes, 3); + ASSERT_EQ(mnode.deleteTimes, 1); + } + + { + int32_t key = 4; + i32SetDefault(&i32Obj, key); + pRaw = i32Encode(&i32Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + SI32Obj *pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); + ASSERT_NE(pI32Obj, nullptr); + ASSERT_EQ(pI32Obj->key, key); + ASSERT_EQ(pI32Obj->v8, 4); + ASSERT_EQ(pI32Obj->v16, 4); + ASSERT_EQ(pI32Obj->v32, 4000); + ASSERT_EQ(pI32Obj->v64, 4000); + sdbRelease(pSdb, pI32Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_VGROUP), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_VGROUP), 1); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_VGROUP), 5); + + i32SetDefault(&i32Obj, key); + i32Obj.v8 = 5; + pRaw = i32Encode(&i32Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); + ASSERT_NE(pI32Obj, nullptr); + ASSERT_EQ(pI32Obj->key, key); + ASSERT_EQ(pI32Obj->v8, 5); + ASSERT_EQ(pI32Obj->v16, 4); + ASSERT_EQ(pI32Obj->v32, 4000); + ASSERT_EQ(pI32Obj->v64, 4000); + sdbRelease(pSdb, pI32Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_VGROUP), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_VGROUP), 2); + ASSERT_EQ(mnode.insertTimes, 4); + ASSERT_EQ(mnode.deleteTimes, 1); + + // delete, call func 2 + key = 4; + i32SetDefault(&i32Obj, key); + pRaw = i32Encode(&i32Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); + ASSERT_EQ(pI32Obj, nullptr); + ASSERT_EQ(sdbGetSize(pSdb, SDB_VGROUP), 0); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_VGROUP), 3); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_VGROUP), 5); + ASSERT_EQ(mnode.insertTimes, 4); + ASSERT_EQ(mnode.deleteTimes, 2); + + key = 6; + i32SetDefault(&i32Obj, key); + pRaw = i32Encode(&i32Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); + ASSERT_NE(pI32Obj, nullptr); + ASSERT_EQ(pI32Obj->key, key); + ASSERT_EQ(pI32Obj->v8, 6); + ASSERT_EQ(pI32Obj->v16, 6); + ASSERT_EQ(pI32Obj->v32, 6000); + ASSERT_EQ(pI32Obj->v64, 6000); + sdbRelease(pSdb, pI32Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_VGROUP), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_VGROUP), 4); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_VGROUP), 7); + ASSERT_EQ(mnode.insertTimes, 5); + ASSERT_EQ(mnode.deleteTimes, 2); + } + + { + int64_t key = 4; + i64SetDefault(&i64Obj, key); + pRaw = i64Encode(&i64Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + SI64Obj *pI64Obj = (SI64Obj *)sdbAcquire(pSdb, SDB_CONSUMER, &key); + ASSERT_NE(pI64Obj, nullptr); + ASSERT_EQ(pI64Obj->key, key); + ASSERT_EQ(pI64Obj->v8, 4); + ASSERT_EQ(pI64Obj->v16, 4); + ASSERT_EQ(pI64Obj->v32, 4000); + ASSERT_EQ(pI64Obj->v64, 4000); + sdbRelease(pSdb, pI64Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_CONSUMER), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_CONSUMER), 1); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_CONSUMER), -1); + + i64SetDefault(&i64Obj, key); + i64Obj.v8 = 5; + pRaw = i64Encode(&i64Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pI64Obj = (SI64Obj *)sdbAcquire(pSdb, SDB_CONSUMER, &key); + ASSERT_NE(pI64Obj, nullptr); + ASSERT_EQ(pI64Obj->key, key); + ASSERT_EQ(pI64Obj->v8, 5); + ASSERT_EQ(pI64Obj->v16, 4); + ASSERT_EQ(pI64Obj->v32, 4000); + ASSERT_EQ(pI64Obj->v64, 4000); + sdbRelease(pSdb, pI64Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_CONSUMER), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_CONSUMER), 2); + ASSERT_EQ(mnode.insertTimes, 6); + ASSERT_EQ(mnode.deleteTimes, 2); + + // delete, call func 2 + key = 4; + i64SetDefault(&i64Obj, key); + pRaw = i64Encode(&i64Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_CONSUMER, &key); + ASSERT_EQ(pObj, nullptr); + ASSERT_EQ(sdbGetSize(pSdb, SDB_CONSUMER), 0); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_CONSUMER), 3); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_CONSUMER), -1); + ASSERT_EQ(mnode.insertTimes, 6); + ASSERT_EQ(mnode.deleteTimes, 3); + + key = 7; + i64SetDefault(&i64Obj, key); + pRaw = i64Encode(&i64Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pI64Obj = (SI64Obj *)sdbAcquire(pSdb, SDB_CONSUMER, &key); + ASSERT_NE(pI64Obj, nullptr); + ASSERT_EQ(pI64Obj->key, key); + ASSERT_EQ(pI64Obj->v8, 7); + ASSERT_EQ(pI64Obj->v16, 7); + ASSERT_EQ(pI64Obj->v32, 7000); + ASSERT_EQ(pI64Obj->v64, 7000); + sdbRelease(pSdb, pI64Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_CONSUMER), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_CONSUMER), 4); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_CONSUMER), -1); + ASSERT_EQ(mnode.insertTimes, 7); + ASSERT_EQ(mnode.deleteTimes, 3); + } + + // write version + ASSERT_EQ(sdbUpdateVer(pSdb, 1), 0); + ASSERT_EQ(sdbUpdateVer(pSdb, 1), 1); + ASSERT_EQ(sdbWriteFile(pSdb), 0); + ASSERT_EQ(sdbWriteFile(pSdb), 0); + + sdbCleanup(pSdb); + ASSERT_EQ(mnode.insertTimes, 7); + ASSERT_EQ(mnode.deleteTimes, 7); +} + +TEST_F(MndTestSdb, 01_Read_Str) { + void *pIter = NULL; + int32_t num = 0; + SStrObj *pObj = NULL; + SMnode mnode = {0}; + SSdb *pSdb = NULL; + SSdbOpt opt = {0}; + SStrObj strObj = {0}; + SSdbRaw *pRaw = NULL; + int32_t p1 = 0; + int32_t p2 = 111; + int32_t p3 = 222; + + mnode.v100 = 100; + mnode.v200 = 200; + opt.pMnode = &mnode; + opt.path = "/tmp/mnode_test_sdb"; + + SSdbTable strTable1; + memset(&strTable1, 0, sizeof(SSdbTable)); + strTable1.sdbType = SDB_USER; + strTable1.keyType = SDB_KEY_BINARY; + strTable1.deployFp = (SdbDeployFp)strDefault; + strTable1.encodeFp = (SdbEncodeFp)strEncode; + strTable1.decodeFp = (SdbDecodeFp)strDecode; + strTable1.insertFp = (SdbInsertFp)strInsert; + strTable1.updateFp = (SdbUpdateFp)strUpdate; + strTable1.deleteFp = (SdbDeleteFp)strDelete; + + SSdbTable strTable2; + memset(&strTable2, 0, sizeof(SSdbTable)); + strTable2.sdbType = SDB_VGROUP; + strTable2.keyType = SDB_KEY_INT32; + strTable2.encodeFp = (SdbEncodeFp)i32Encode; + strTable2.decodeFp = (SdbDecodeFp)i32Decode; + strTable2.insertFp = (SdbInsertFp)i32Insert; + strTable2.updateFp = (SdbUpdateFp)i32Update; + strTable2.deleteFp = (SdbDeleteFp)i32Delete; + + SSdbTable strTable3; + memset(&strTable3, 0, sizeof(SSdbTable)); + strTable3.sdbType = SDB_CONSUMER; + strTable3.keyType = SDB_KEY_INT64; + strTable3.encodeFp = (SdbEncodeFp)i64Encode; + strTable3.decodeFp = (SdbDecodeFp)i64Decode; + strTable3.insertFp = (SdbInsertFp)i64Insert; + strTable3.updateFp = (SdbUpdateFp)i64Update; + strTable3.deleteFp = (SdbDeleteFp)i64Delete; + + pSdb = sdbInit(&opt); + mnode.pSdb = pSdb; + ASSERT_NE(pSdb, nullptr); + ASSERT_NE(pSdb, nullptr); + ASSERT_EQ(sdbSetTable(pSdb, strTable1), 0); + ASSERT_EQ(sdbSetTable(pSdb, strTable2), 0); + ASSERT_EQ(sdbSetTable(pSdb, strTable3), 0); + ASSERT_EQ(sdbReadFile(pSdb), 0); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_USER), 2); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_USER), -1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_USER), 5); + ASSERT_EQ(sdbUpdateVer(pSdb, 0), 1); + ASSERT_EQ(mnode.insertTimes, 4); + ASSERT_EQ(mnode.deleteTimes, 0); + + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k1000"); + ASSERT_NE(pObj, nullptr); + EXPECT_STREQ(pObj->key, "k1000"); + EXPECT_STREQ(pObj->vstr, "v1000"); + ASSERT_EQ(pObj->v8, 1); + ASSERT_EQ(pObj->v16, 1); + ASSERT_EQ(pObj->v32, 1000); + ASSERT_EQ(pObj->v64, 1000); + sdbRelease(pSdb, pObj); + + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k2000"); + ASSERT_NE(pObj, nullptr); + EXPECT_STREQ(pObj->key, "k2000"); + EXPECT_STREQ(pObj->vstr, "v2000"); + ASSERT_EQ(pObj->v8, 2); + ASSERT_EQ(pObj->v16, 2); + ASSERT_EQ(pObj->v32, 2000); + ASSERT_EQ(pObj->v64, 2000); + sdbRelease(pSdb, pObj); + + pObj = (SStrObj *)sdbAcquire(pSdb, SDB_USER, "k200"); + ASSERT_EQ(pObj, nullptr); + + pIter = NULL; + num = 0; + do { + pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pObj); + if (pIter == NULL) break; + ASSERT_NE(pObj, nullptr); + num++; + sdbRelease(pSdb, pObj); + } while (1); + ASSERT_EQ(num, 2); + + do { + pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pObj); + if (pIter == NULL) break; + if (strcmp(pObj->key, "k1000") == 0) { + sdbCancelFetch(pSdb, pIter); + break; + } + } while (1); + EXPECT_STREQ(pObj->key, "k1000"); + + p1 = 0; + p2 = 111; + p3 = 222; + sdbTraverse(pSdb, SDB_USER, (sdbTraverseFp)sdbTraverseSucc1, &p1, &p2, &p3); + ASSERT_EQ(p1, 334); + + p1 = 0; + p2 = 111; + p3 = 222; + sdbTraverse(pSdb, SDB_USER, (sdbTraverseFp)sdbTraverseSucc2, &p1, &p2, &p3); + ASSERT_EQ(p1, 669); + + p1 = 0; + p2 = 111; + p3 = 222; + sdbTraverse(pSdb, SDB_USER, (sdbTraverseFp)sdbTraverseFail, &p1, &p2, &p3); + ASSERT_EQ(p1, 333); + + int32_t i32key = 6; + SI32Obj *pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &i32key); + ASSERT_NE(pI32Obj, nullptr); + ASSERT_EQ(pI32Obj->key, 6); + ASSERT_EQ(pI32Obj->v8, 6); + ASSERT_EQ(pI32Obj->v16, 6); + ASSERT_EQ(pI32Obj->v32, 6000); + ASSERT_EQ(pI32Obj->v64, 6000); + sdbRelease(pSdb, pI32Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_VGROUP), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_VGROUP), 4); + ASSERT_EQ(sdbGetMaxId(pSdb, SDB_VGROUP), 7); + + int64_t i64key = 7; + SI64Obj *pI64Obj = (SI64Obj *)sdbAcquire(pSdb, SDB_CONSUMER, &i64key); + ASSERT_NE(pI64Obj, nullptr); + ASSERT_EQ(pI64Obj->key, 7); + ASSERT_EQ(pI64Obj->v8, 7); + ASSERT_EQ(pI64Obj->v16, 7); + ASSERT_EQ(pI64Obj->v32, 7000); + ASSERT_EQ(pI64Obj->v64, 7000); + sdbRelease(pSdb, pI64Obj); + + ASSERT_EQ(sdbGetSize(pSdb, SDB_CONSUMER), 1); + ASSERT_EQ(sdbGetTableVer(pSdb, SDB_CONSUMER), 4); + + ASSERT_EQ(mnode.insertTimes, 4); + ASSERT_EQ(mnode.deleteTimes, 0); + + { + SI32Obj i32Obj = {0}; + int32_t key = 6; + i32SetDefault(&i32Obj, key); + pRaw = i32Encode(&i32Obj); + sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); + ASSERT_EQ(pI32Obj, nullptr); + int32_t code = terrno; + ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + SI32Obj i32Obj = {0}; + int32_t key = 8; + i32SetDefault(&i32Obj, key); + pRaw = i32Encode(&i32Obj); + EXPECT_NE(sdbSetRawStatus(pRaw, SDB_STATUS_INIT), 0); + sdbSetRawStatus(pRaw, SDB_STATUS_CREATING); + ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); + pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); + ASSERT_EQ(pI32Obj, nullptr); + int32_t code = terrno; + ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_CREATING); + } + + sdbCleanup(pSdb); + ASSERT_EQ(mnode.insertTimes, 5); + ASSERT_EQ(mnode.deleteTimes, 5); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp index 54a154e684b50abf4fea155bb5dd8da1efc47e78..4dc4e0477947d647961acd1859720f1013d6da45 100644 --- a/source/dnode/mnode/impl/test/sma/sma.cpp +++ b/source/dnode/mnode/impl/test/sma/sma.cpp @@ -40,24 +40,22 @@ void* MndTestSma::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { SCreateDbReq createReq = {0}; strcpy(createReq.db, dbname); createReq.numOfVgroups = 2; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; + createReq.buffer = -1; + createReq.pageSize = -1; + createReq.pages = -1; createReq.daysPerFile = 10 * 1440; createReq.daysToKeep0 = 3650 * 1440; createReq.daysToKeep1 = 3650 * 1440; createReq.daysToKeep2 = 3650 * 1440; createReq.minRows = 100; createReq.maxRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; - createReq.ttl = 1; 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 9270d38e1148f925bfb6a7d754041d0f679ea05c..220a73def60780863819e1aa8a54412b2af565c7 100644 --- a/source/dnode/mnode/impl/test/stb/stb.cpp +++ b/source/dnode/mnode/impl/test/stb/stb.cpp @@ -41,24 +41,22 @@ void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { SCreateDbReq createReq = {0}; strcpy(createReq.db, dbname); createReq.numOfVgroups = 2; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; + createReq.buffer = -1; + createReq.pageSize = -1; + createReq.pages = -1; createReq.daysPerFile = 1000; createReq.daysToKeep0 = 3650; createReq.daysToKeep1 = 3650; createReq.daysToKeep2 = 3650; createReq.minRows = 100; createReq.maxRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; - createReq.ttl = 1; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); @@ -343,7 +341,6 @@ TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { EXPECT_EQ(metaRsp.numOfTags, 3); EXPECT_EQ(metaRsp.precision, TSDB_TIME_PRECISION_MILLI); EXPECT_EQ(metaRsp.tableType, TSDB_SUPER_TABLE); - EXPECT_EQ(metaRsp.update, 0); EXPECT_EQ(metaRsp.sversion, 1); EXPECT_EQ(metaRsp.tversion, 0); EXPECT_GT(metaRsp.suid, 0); diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 917cb23fc9b4cd2cec2204a2b0f6494a638f9b57..eccc1b99d3f3dc8189712776e4ee852c6169cdfa 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -33,24 +33,22 @@ void* MndTestTopic::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { SCreateDbReq createReq = {0}; strcpy(createReq.db, dbname); createReq.numOfVgroups = 2; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; + createReq.buffer = -1; + createReq.pageSize = -1; + createReq.pages = -1; createReq.daysPerFile = 10 * 1440; createReq.daysToKeep0 = 3650 * 1440; createReq.daysToKeep1 = 3650 * 1440; createReq.daysToKeep2 = 3650 * 1440; createReq.minRows = 100; createReq.maxRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; - createReq.ttl = 1; 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 79464db134c1b1b6f842a68a72351ddfabf92716..ee961e9a275aac5e259aff5f6d93021e24231f33 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -286,24 +286,22 @@ TEST_F(MndTestUser, 03_Alter_User) { SCreateDbReq createReq = {0}; strcpy(createReq.db, "1.d2"); createReq.numOfVgroups = 2; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; + createReq.buffer = -1; + createReq.pageSize = -1; + createReq.pages = -1; createReq.daysPerFile = 10 * 1440; createReq.daysToKeep0 = 3650 * 1440; createReq.daysToKeep1 = 3650 * 1440; createReq.daysToKeep2 = 3650 * 1440; createReq.minRows = 100; createReq.maxRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; - createReq.ttl = 1; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); diff --git a/source/dnode/mnode/sdb/CMakeLists.txt b/source/dnode/mnode/sdb/CMakeLists.txt index 823bcdeacad3bffa2cc48f44377f707a6d747e21..e2ebed7a788c58cb6bbe2ba384eeabeb5cf3f2f0 100644 --- a/source/dnode/mnode/sdb/CMakeLists.txt +++ b/source/dnode/mnode/sdb/CMakeLists.txt @@ -6,5 +6,5 @@ target_include_directories( PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - sdb os common util + sdb os common util wal ) \ No newline at end of file diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index de71ac47b613a96e2306c2ddd54559b40eea1786..23c0f8a01c19ffa1b64dd15fd6d38dc893c8b130 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -31,8 +31,6 @@ extern "C" { #define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }} #define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }} -#define SDB_MAX_SIZE (32 * 1024) - typedef struct SSdbRaw { int8_t type; int8_t status; @@ -52,6 +50,8 @@ typedef struct SSdbRow { const char *sdbTableName(ESdbType type); void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); +void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index f85ff7a26e9cfdf4e8a2a626b0e1b4d8dce7d05a..51f40c12cd65a61e83f0395d6f6dc4783f9f03de 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -28,12 +28,12 @@ SSdb *sdbInit(SSdbOpt *pOption) { return NULL; } - char path[PATH_MAX + 100]; - snprintf(path, PATH_MAX + 100, "%s%sdata", pOption->path, TD_DIRSEP); + char path[PATH_MAX + 100] = {0}; + snprintf(path, sizeof(path), "%s%sdata", pOption->path, TD_DIRSEP); pSdb->currDir = strdup(path); - snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP); + snprintf(path, sizeof(path), "%s%ssync", pOption->path, TD_DIRSEP); pSdb->syncDir = strdup(path); - snprintf(path, PATH_MAX + 100, "%s%stmp", pOption->path, TD_DIRSEP); + snprintf(path, sizeof(path), "%s%stmp", pOption->path, TD_DIRSEP); pSdb->tmpDir = strdup(path); if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) { sdbCleanup(pSdb); @@ -50,7 +50,7 @@ SSdb *sdbInit(SSdbOpt *pOption) { for (ESdbType i = 0; i < SDB_MAX; ++i) { taosInitRWLatch(&pSdb->locks[i]); pSdb->maxId[i] = 0; - pSdb->tableVer[i] = -1; + pSdb->tableVer[i] = 0; pSdb->keyTypes[i] = SDB_KEY_INT32; } @@ -99,7 +99,7 @@ void sdbCleanup(SSdb *pSdb) { taosHashClear(hash); taosHashCleanup(hash); pSdb->hashObjs[i] = NULL; - mDebug("sdb table:%d is cleaned up", i); + mDebug("sdb table:%s is cleaned up", sdbTableName(i)); } taosMemoryFree(pSdb); @@ -141,7 +141,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { } static int32_t sdbCreateDir(SSdb *pSdb) { - if (taosMkDir(pSdb->currDir) != 0) { + if (taosMulMkDir(pSdb->currDir) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to create dir:%s since %s", pSdb->currDir, terrstr()); return -1; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 98ac04684ef828e6625b13b3b556917f2a6e55ee..f8bd14813c7a4e5707e7c7beb20dabb23d23d6e2 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -16,8 +16,9 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" #include "tchecksum.h" +#include "wal.h" -#define SDB_TABLE_SIZE 24 +#define SDB_TABLE_SIZE 24 #define SDB_RESERVE_SIZE 512 static int32_t sdbRunDeployFp(SSdb *pSdb) { @@ -49,7 +50,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { } for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { - int64_t maxId = -1; + int64_t maxId = 0; ret = taosReadFile(pFile, &maxId, sizeof(int64_t)); if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -65,7 +66,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { } for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { - int64_t ver = -1; + int64_t ver = 0; ret = taosReadFile(pFile, &ver, sizeof(int64_t)); if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -101,7 +102,7 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { } for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { - int64_t maxId = -1; + int64_t maxId = 0; if (i < SDB_MAX) { maxId = pSdb->maxId[i]; } @@ -112,7 +113,7 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { } for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { - int64_t ver = -1; + int64_t ver = 0; if (i < SDB_MAX) { ver = pSdb->tableVer[i]; } @@ -137,7 +138,7 @@ int32_t sdbReadFile(SSdb *pSdb) { int32_t readLen = 0; int64_t ret = 0; - SSdbRaw *pRaw = taosMemoryMalloc(SDB_MAX_SIZE); + SSdbRaw *pRaw = taosMemoryMalloc(WAL_MAX_SIZE + 100); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed read file since %s", terrstr()); @@ -164,6 +165,9 @@ int32_t sdbReadFile(SSdb *pSdb) { return -1; } + int64_t tableVer[SDB_MAX] = {0}; + memcpy(tableVer, pSdb->tableVer, sizeof(tableVer)); + while (1) { readLen = sizeof(SSdbRaw); ret = taosReadFile(pFile, pRaw, readLen); @@ -205,15 +209,16 @@ int32_t sdbReadFile(SSdb *pSdb) { code = sdbWriteWithoutFree(pSdb, pRaw); if (code != 0) { mError("failed to read file:%s since %s", file, terrstr()); - goto PARSE_SDB_DATA_ERROR; + goto _OVER; } } code = 0; pSdb->lastCommitVer = pSdb->curVer; + memcpy(pSdb->tableVer, tableVer, sizeof(tableVer)); mDebug("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); -PARSE_SDB_DATA_ERROR: +_OVER: taosCloseFile(&pFile); sdbFreeRaw(pRaw); @@ -258,7 +263,13 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) { SSdbRow **ppRow = taosHashIterate(hash, NULL); while (ppRow != NULL) { SSdbRow *pRow = *ppRow; - if (pRow == NULL || pRow->status != SDB_STATUS_READY) { + if (pRow == NULL) { + ppRow = taosHashIterate(hash, ppRow); + continue; + } + + if (pRow->status != SDB_STATUS_READY && pRow->status != SDB_STATUS_DROPPING) { + sdbPrintOper(pSdb, pRow, "not-write"); ppRow = taosHashIterate(hash, ppRow); continue; } diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index b34c2a82d87dfb526d2f2f3f5bc44c404f7a21f1..94008b2f7cc69690d1a4de7707dcb868044659af 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -static void sdbCheck(SSdb *pSdb, SSdbRow *pRow); +static void sdbCheckRow(SSdb *pSdb, SSdbRow *pRow); const char *sdbTableName(ESdbType type) { switch (type) { @@ -65,12 +65,10 @@ const char *sdbTableName(ESdbType type) { } } -static const char *sdbStatusStr(ESdbStatus status) { +static const char *sdbStatusName(ESdbStatus status) { switch (status) { case SDB_STATUS_CREATING: return "creating"; - case SDB_STATUS_UPDATING: - return "updating"; case SDB_STATUS_DROPPING: return "dropping"; case SDB_STATUS_READY: @@ -89,13 +87,13 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { if (keyType == SDB_KEY_BINARY) { mTrace("%s:%s, ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper, - pRow->pObj, sdbStatusStr(pRow->status)); + pRow->pObj, sdbStatusName(pRow->status)); } else if (keyType == SDB_KEY_INT32) { mTrace("%s:%d, ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, - oper, pRow->pObj, sdbStatusStr(pRow->status)); + oper, pRow->pObj, sdbStatusName(pRow->status)); } else if (keyType == SDB_KEY_INT64) { mTrace("%s:%" PRId64 ", ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, - pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status)); + pRow->refCount, oper, pRow->pObj, sdbStatusName(pRow->status)); } else { } } @@ -116,7 +114,7 @@ static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) { } static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, const void *pKey) { - int32_t keySize; + int32_t keySize = 0; EKeyType keyType = pSdb->keyTypes[type]; if (keyType == SDB_KEY_INT32) { @@ -149,7 +147,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) { taosWUnLockLatch(pLock); sdbFreeRow(pSdb, pRow, false); - terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE; + terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } @@ -183,18 +181,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pNewRow, int32_t keySize) { SRWLatch *pLock = &pSdb->locks[pNewRow->type]; - taosRLockLatch(pLock); + taosWLockLatch(pLock); SSdbRow **ppOldRow = taosHashGet(hash, pNewRow->pObj, keySize); if (ppOldRow == NULL || *ppOldRow == NULL) { - taosRUnLockLatch(pLock); + taosWUnLockLatch(pLock); return sdbInsertRow(pSdb, hash, pRaw, pNewRow, keySize); } SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; sdbPrintOper(pSdb, pOldRow, "update"); - taosRUnLockLatch(pLock); + taosWUnLockLatch(pLock); int32_t code = 0; SdbUpdateFp updateFp = pSdb->updateFps[pNewRow->type]; @@ -230,8 +228,7 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * pSdb->tableVer[pOldRow->type]++; sdbFreeRow(pSdb, pRow, false); - sdbCheck(pSdb, pOldRow); - // sdbRelease(pSdb, pOldRow->pObj); + sdbCheckRow(pSdb, pOldRow); return 0; } @@ -254,7 +251,6 @@ int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw) { case SDB_STATUS_CREATING: code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize); break; - case SDB_STATUS_UPDATING: case SDB_STATUS_READY: case SDB_STATUS_DROPPING: code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize); @@ -295,7 +291,6 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, const void *pKey) { SSdbRow *pRow = *ppRow; switch (pRow->status) { case SDB_STATUS_READY: - case SDB_STATUS_UPDATING: atomic_add_fetch_32(&pRow->refCount, 1); pRet = pRow->pObj; sdbPrintOper(pSdb, pRow, "acquire"); @@ -315,9 +310,9 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, const void *pKey) { return pRet; } -static void sdbCheck(SSdb *pSdb, SSdbRow *pRow) { +static void sdbCheckRow(SSdb *pSdb, SSdbRow *pRow) { SRWLatch *pLock = &pSdb->locks[pRow->type]; - taosRLockLatch(pLock); + taosWLockLatch(pLock); int32_t ref = atomic_load_32(&pRow->refCount); sdbPrintOper(pSdb, pRow, "check"); @@ -325,7 +320,7 @@ static void sdbCheck(SSdb *pSdb, SSdbRow *pRow) { sdbFreeRow(pSdb, pRow, true); } - taosRUnLockLatch(pLock); + taosWUnLockLatch(pLock); } void sdbRelease(SSdb *pSdb, void *pObj) { @@ -335,7 +330,7 @@ void sdbRelease(SSdb *pSdb, void *pObj) { if (pRow->type >= SDB_MAX) return; SRWLatch *pLock = &pSdb->locks[pRow->type]; - taosRLockLatch(pLock); + taosWLockLatch(pLock); int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1); sdbPrintOper(pSdb, pRow, "release"); @@ -343,7 +338,7 @@ void sdbRelease(SSdb *pSdb, void *pObj) { sdbFreeRow(pSdb, pRow, true); } - taosRUnLockLatch(pLock); + taosWUnLockLatch(pLock); } void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { @@ -355,16 +350,6 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { SRWLatch *pLock = &pSdb->locks[type]; taosRLockLatch(pLock); -#if 0 - if (pIter != NULL) { - SSdbRow *pLastRow = *(SSdbRow **)pIter; - int32_t ref = atomic_load_32(&pLastRow->refCount); - if (ref <= 0 && pLastRow->status == SDB_STATUS_DROPPED) { - sdbFreeRow(pSdb, pLastRow); - } - } -#endif - SSdbRow **ppRow = taosHashIterate(hash, pIter); while (ppRow != NULL) { SSdbRow *pRow = *ppRow; diff --git a/source/dnode/mnode/sdb/src/sdbRaw.c b/source/dnode/mnode/sdb/src/sdbRaw.c index 45464c3bd35835d5d9c41dd8c78949c46fa7de97..d09198f66f87453d88f67e26766a1183830999be 100644 --- a/source/dnode/mnode/sdb/src/sdbRaw.c +++ b/source/dnode/mnode/sdb/src/sdbRaw.c @@ -134,6 +134,11 @@ int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) { return -1; } + if (status == SDB_STATUS_INIT) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } + pRaw->status = status; return 0; } diff --git a/source/dnode/qnode/inc/qndInt.h b/source/dnode/qnode/inc/qndInt.h index 307bf3efb8913d4fae4966797835e432ebb051c5..c18a43c4fb20df1b939ee0d9f0ef8813abba58c6 100644 --- a/source/dnode/qnode/inc/qndInt.h +++ b/source/dnode/qnode/inc/qndInt.h @@ -29,7 +29,7 @@ extern "C" { #endif -typedef struct SQWorkerMgmt SQHandle; +typedef struct SQWorker SQHandle; typedef struct SQnode { int32_t qndId; diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index 907fddaec2529385856f09add338fa91159e7c69..7a226a4c6bcc1c3070b18737455c072822c3820b 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -17,7 +17,7 @@ #include "qndInt.h" #include "query.h" #include "qworker.h" -//#include "tudf.h" +#include "libs/function/function.h" SQnode *qndOpen(const SQnodeOpt *pOption) { SQnode *pQnode = taosMemoryCalloc(1, sizeof(SQnode)); @@ -26,7 +26,9 @@ SQnode *qndOpen(const SQnodeOpt *pOption) { return NULL; } - //udfcOpen(); + if (udfcOpen() != 0) { + qError("qnode can not open udfc"); + } if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, NULL, (void **)&pQnode->pQuery, &pOption->msgCb)) { taosMemoryFreeClear(pQnode); @@ -40,7 +42,7 @@ SQnode *qndOpen(const SQnodeOpt *pOption) { void qndClose(SQnode *pQnode) { qWorkerDestroy((void **)&pQnode->pQuery); - //udfcClose(); + udfcClose(); taosMemoryFree(pQnode); } diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 724c7b312ea2870f8a03cdb6e113ba82e685f546..85d0f76268ac55cbf131917f234ef66f108ce64d 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -8,7 +8,6 @@ target_sources( "src/vnd/vnodeBufPool.c" "src/vnd/vnodeCfg.c" "src/vnd/vnodeCommit.c" - "src/vnd/vnodeInt.c" "src/vnd/vnodeQuery.c" "src/vnd/vnodeStateMgr.c" "src/vnd/vnodeModule.c" @@ -33,7 +32,6 @@ target_sources( "src/tsdb/tsdbMemTable.c" "src/tsdb/tsdbRead.c" "src/tsdb/tsdbReadImpl.c" - "src/tsdb/tsdbScan.c" "src/tsdb/tsdbSma.c" "src/tsdb/tsdbWrite.c" diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 4213ce78bd36fd7a4cfa6828e496825bfc80b226..f4fccc2f497ff698eb627161f872133d25c6d414 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -32,12 +32,12 @@ #include "tmsg.h" #include "trow.h" -#include "tdbInt.h" +#include "tdb.h" #ifdef __cplusplus extern "C" { #endif - +#define TSDB_VNODE_SMA_DEBUG // TODO: evaluate to remove the macro and the relative codes // vnode typedef struct SVnode SVnode; typedef struct STsdbCfg STsdbCfg; // todo: remove @@ -57,9 +57,6 @@ int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); -int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); -int32_t vnodeCompact(SVnode *pVnode); -int32_t vnodeSync(SVnode *pVnode); int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); int vnodeValidateTableHash(SVnode *pVnode, char *tableFName); @@ -92,16 +89,16 @@ int metaTbCursorNext(SMTbCursor *pTbCur); #endif // tsdb -typedef struct STsdb STsdb; +// typedef struct STsdb STsdb; typedef void *tsdbReaderT; #define BLOCK_LOAD_OFFSET_SEQ_ORDER 1 #define BLOCK_LOAD_TABLE_SEQ_ORDER 2 #define BLOCK_LOAD_TABLE_RR_ORDER 3 -tsdbReaderT *tsdbQueryTables(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, +tsdbReaderT *tsdbQueryTables(SVnode *pVnode, SQueryTableDataCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, uint64_t taskId); -tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, +tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, void *pMemRef); int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo); bool isTsdbCacheLastRow(tsdbReaderT *pReader); @@ -111,12 +108,12 @@ int32_t tsdbQuerySTableByTagCond(void *pMeta, uint64_t uid, TSKEY skey, con int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT *pHandle); bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle); void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo); -int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg **pBlockStatis); +int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg ***pBlockStatis, bool* allHave); SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList); void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond *pCond); void tsdbDestroyTableGroup(STableGroupInfo *pGroupList); int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo); -int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo); +int32_t tsdbGetTableGroupFromIdList(SVnode *pVnode, SArray *pTableIdList, STableGroupInfo *pGroupInfo); // tq @@ -146,9 +143,19 @@ struct STsdbCfg { int32_t keep0; int32_t keep1; int32_t keep2; - SArray *retentions; + // TODO: save to tsdb cfg file + int8_t type; // ETsdbType + SRetention retentions[TSDB_RSMA_RETENTION_MAX]; }; +typedef enum { + TSDB_TYPE_TSDB = 0, // TSDB + TSDB_TYPE_TSMA = 1, // TSMA + TSDB_TYPE_RSMA_L0 = 2, // RSMA Level 0 + TSDB_TYPE_RSMA_L1 = 3, // RSMA Level 1 + TSDB_TYPE_RSMA_L2 = 4, // RSMA Level 2 +} ETsdbType; + struct SVnodeCfg { int32_t vgId; char dbname[TSDB_DB_NAME_LEN]; @@ -157,7 +164,6 @@ struct SVnodeCfg { int32_t szCache; uint64_t szBuf; bool isHeap; - int8_t streamMode; bool isWeak; STsdbCfg tsdbCfg; SWalCfg walCfg; diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index 0001a4323139447ae8ed836eb7e9495c48df9d1c..ca7e823d6b6cd7f542c486d5fec9dd63bb3b10f8 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -43,7 +43,6 @@ int metaEncodeEntry(SCoder* pCoder, const SMetaEntry* pME); int metaDecodeEntry(SCoder* pCoder, SMetaEntry* pME); // metaTable ================== -int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq); // metaQuery ================== int metaGetTableEntryByVersion(SMetaReader* pReader, int64_t version, tb_uid_t uid); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 4fc94da06a223b9c090a78b144aec467a25bf4a0..9ac843494942fff8c1dfe2d64789f18307ad3ff1 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -73,7 +73,6 @@ struct STsdb { SVnode *pVnode; bool repoLocked; TdThreadMutex mutex; - STsdbCfg config; STsdbMemTable *mem; STsdbMemTable *imem; SRtn rtn; @@ -185,7 +184,7 @@ struct STsdbFS { }; #define REPO_ID(r) TD_VID((r)->pVnode) -#define REPO_CFG(r) (&(r)->config) +#define REPO_CFG(r) (&(r)->pVnode->config.tsdbCfg) #define REPO_FS(r) ((r)->fs) #define REPO_META(r) ((r)->pVnode->pMeta) #define REPO_TFS(r) ((r)->pVnode->pTfs) @@ -534,23 +533,6 @@ static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) { } } -// tsdbDBDef -// typedef struct SDBFile SDBFile; -// typedef DB_ENV* TDBEnv; - -// struct SDBFile { -// int32_t fid; -// DB* pDB; -// char* path; -// }; - -// int32_t tsdbOpenDBF(TDBEnv pEnv, SDBFile* pDBF); -// void tsdbCloseDBF(SDBFile* pDBF); -// int32_t tsdbOpenBDBEnv(DB_ENV** ppEnv, const char* path); -// void tsdbCloseBDBEnv(DB_ENV* pEnv); -// int32_t tsdbSaveSmaToDB(SDBFile* pDBF, void* key, uint32_t keySize, void* data, uint32_t dataSize); -// void* tsdbGetSmaDataByKey(SDBFile* pDBF, void* key, uint32_t keySize, uint32_t* valueSize); - // tsdbFile #define TSDB_FILE_HEAD_SIZE 512 #define TSDB_FILE_DELIMITER 0xF00AFA0F diff --git a/source/dnode/vnode/src/inc/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h index 8fb18ddfea868f10cc226dc8e891fe5ae56aff2f..162d733cc3654bb2d743334ff6758508c7c98683 100644 --- a/source/dnode/vnode/src/inc/tsdbSma.h +++ b/source/dnode/vnode/src/inc/tsdbSma.h @@ -22,13 +22,13 @@ extern "C" { #endif -typedef int32_t (*__tb_ddl_fn_t)(void *ahandle, void **result, void *p1, void *p2); +// typedef int32_t (*__tb_ddl_fn_t)(void *ahandle, void **result, void *p1, void *p2); -struct STbDdlH { - void *ahandle; - void *result; - __tb_ddl_fn_t fp; -}; +// struct STbDdlH { +// void *ahandle; +// void *result; +// __tb_ddl_fn_t fp; +// }; static FORCE_INLINE int32_t tsdbUidStoreInit(STbUidStore **pStore) { ASSERT(*pStore == NULL); @@ -40,14 +40,6 @@ static FORCE_INLINE int32_t tsdbUidStoreInit(STbUidStore **pStore) { return TSDB_CODE_SUCCESS; } -int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid); -void tsdbUidStoreDestory(STbUidStore *pStore); -void *tsdbUidStoreFree(STbUidStore *pStore); - -int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq); -int32_t tsdbFetchTbUidList(void *pTsdb, void **result, void *suid, void *uid); -int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pUidStore); -int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType); #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 884f86a3bb3dab85fd9bc4b2af47a5c6de8beb94..5930dcaf962e9a2d2f055064a22a3ea9118de450 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -25,7 +25,7 @@ #include "tcompare.h" #include "tcompression.h" #include "tdatablock.h" -#include "tdbInt.h" +#include "tdb.h" #include "tencode.h" #include "tfs.h" #include "tglobal.h" @@ -52,12 +52,15 @@ typedef struct STsdb STsdb; typedef struct STQ STQ; typedef struct SVState SVState; typedef struct SVBufPool SVBufPool; -typedef struct SQWorkerMgmt SQHandle; +typedef struct SQWorker SQHandle; -#define VNODE_META_DIR "meta" -#define VNODE_TSDB_DIR "tsdb" -#define VNODE_TQ_DIR "tq" -#define VNODE_WAL_DIR "wal" +#define VNODE_META_DIR "meta" +#define VNODE_TSDB_DIR "tsdb" +#define VNODE_TQ_DIR "tq" +#define VNODE_WAL_DIR "wal" +#define VNODE_TSMA_DIR "tsma" +#define VNODE_RSMA1_DIR "rsma1" +#define VNODE_RSMA2_DIR "rsma2" // vnd.h void* vnodeBufPoolMalloc(SVBufPool* pPool, int size); @@ -72,6 +75,7 @@ int metaClose(SMeta* pMeta); int metaBegin(SMeta* pMeta); int metaCommit(SMeta* pMeta); int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq); +int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq); int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq); SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline); STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver); @@ -87,14 +91,19 @@ int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg); int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid); // tsdb -int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb); -int tsdbClose(STsdb* pTsdb); -int tsdbBegin(STsdb* pTsdb); -int tsdbCommit(STsdb* pTsdb); -int32_t tsdbUpdateSmaWindow(STsdb* pTsdb, SSubmitReq* pMsg, int64_t version); -int32_t tsdbCreateTSma(STsdb* pTsdb, char* pMsg); -int32_t tsdbInsertTSmaData(STsdb* pTsdb, int64_t indexUid, const char* msg); -int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); +int tsdbOpen(SVnode* pVnode, int8_t type); +int tsdbClose(STsdb* pTsdb); +int tsdbBegin(STsdb* pTsdb); +int tsdbCommit(STsdb* pTsdb); +int32_t tsdbUpdateSmaWindow(STsdb* pTsdb, SSubmitReq* pMsg, int64_t version); +int32_t tsdbCreateTSma(STsdb* pTsdb, char* pMsg); +int32_t tsdbInsertTSmaData(STsdb* pTsdb, int64_t indexUid, const char* msg); +int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); +tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, + uint64_t taskId); +tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, + void* pMemRef); +int32_t tsdbGetTableGroupFromIdListT(STsdb* tsdb, SArray* pTableIdList, STableGroupInfo* pGroupInfo); // tq STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal); @@ -107,6 +116,15 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId); +// sma + +int32_t tsdbRegisterRSma(STsdb* pTsdb, SMeta* pMeta, SVCreateStbReq* pReq); +int32_t tsdbFetchTbUidList(STsdb* pTsdb, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid); +int32_t tsdbUpdateTbUidList(STsdb* pTsdb, STbUidStore* pUidStore); +void tsdbUidStoreDestory(STbUidStore* pStore); +void* tsdbUidStoreFree(STbUidStore* pStore); +int32_t tsdbTriggerRSma(STsdb* pTsdb, SMeta* pMeta, void* pMsg, int32_t inputType); + typedef struct { int8_t streamType; // sma or other int8_t dstType; @@ -146,6 +164,8 @@ struct SVnode { SVBufPool* onRecycle; SMeta* pMeta; STsdb* pTsdb; + STsdb* pRSma1; + STsdb* pRSma2; SWal* pWal; STQ* pTq; SSink* pSink; @@ -154,6 +174,11 @@ struct SVnode { SQHandle* pQuery; }; +#define VND_TSDB(vnd) ((vnd)->pTsdb) +#define VND_RSMA0(vnd) ((vnd)->pTsdb) +#define VND_RSMA1(vnd) ((vnd)->pRSma1) +#define VND_RSMA2(vnd) ((vnd)->pRSma2) + struct STbUidStore { tb_uid_t suid; SArray* tbUids; @@ -162,7 +187,11 @@ struct STbUidStore { #define TD_VID(PVNODE) (PVNODE)->config.vgId -typedef struct STbDdlH STbDdlH; + +static FORCE_INLINE bool tsdbIsRollup(SVnode* pVnode) { + SRetention* pRetention = &(pVnode->config.tsdbCfg.retentions[0]); + return (pRetention->freq > 0 && pRetention->keep > 0); +} // sma void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index e65f5229af604c98daff563624b66abc94c14930..85a49ffabd81499bd39d86b836fb0850d62b2abe 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -47,66 +47,66 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) { // open env ret = tdbEnvOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv); if (ret < 0) { - metaError("vgId: %d failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pTbDb ret = tdbDbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb); if (ret < 0) { - metaError("vgId: %d failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pSkmDb ret = tdbDbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb); if (ret < 0) { - metaError("vgId: %d failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pUidIdx ret = tdbDbOpen("uid.idx", sizeof(tb_uid_t), sizeof(int64_t), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx); if (ret < 0) { - metaError("vgId: %d failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pNameIdx ret = tdbDbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx); if (ret < 0) { - metaError("vgId: %d failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pCtbIdx ret = tdbDbOpen("ctb.idx", sizeof(SCtbIdxKey), 0, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx); if (ret < 0) { - metaError("vgId: %d failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pTagIdx ret = tdbDbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx); if (ret < 0) { - metaError("vgId: %d failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open pTtlIdx ret = tdbDbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx); if (ret < 0) { - metaError("vgId: %d failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open index if (metaOpenIdx(pMeta) < 0) { - metaError("vgId: %d failed to open meta index since %s", TD_VID(pVnode), tstrerror(terrno)); + metaError("vgId:%d failed to open meta index since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } - metaDebug("vgId: %d meta is opened", TD_VID(pVnode)); + metaDebug("vgId:%d meta is opened", TD_VID(pVnode)); *ppMeta = pMeta; return 0; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 46a39e72f91b392f1a84fd13bedcccc799b05eda..60c844e394a6990d41d7eadbc5e6e15fa7c62f60 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -23,7 +23,7 @@ void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags) { void metaReaderClear(SMetaReader *pReader) { tCoderClear(&pReader->coder); - TDB_FREE(pReader->pBuf); + tdbFree(pReader->pBuf); } int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) { @@ -96,15 +96,17 @@ SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { metaReaderInit(&pTbCur->mr, pMeta, 0); - tdbDbcOpen(pMeta->pUidIdx, &pTbCur->pDbc); + tdbDbcOpen(pMeta->pUidIdx, &pTbCur->pDbc, NULL); + + tdbDbcMoveToFirst(pTbCur->pDbc); return pTbCur; } void metaCloseTbCursor(SMTbCursor *pTbCur) { if (pTbCur) { - TDB_FREE(pTbCur->pKey); - TDB_FREE(pTbCur->pVal); + tdbFree(pTbCur->pKey); + tdbFree(pTbCur->pVal); metaReaderClear(&pTbCur->mr); if (pTbCur->pDbc) { tdbDbcClose(pTbCur->pDbc); @@ -119,7 +121,7 @@ int metaTbCursorNext(SMTbCursor *pTbCur) { STbCfg tbCfg; for (;;) { - ret = tdbDbNext(pTbCur->pDbc, &pTbCur->pKey, &pTbCur->kLen, &pTbCur->pVal, &pTbCur->vLen); + ret = tdbDbcNext(pTbCur->pDbc, &pTbCur->pKey, &pTbCur->kLen, &pTbCur->pVal, &pTbCur->vLen); if (ret < 0) { return -1; } @@ -159,7 +161,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo // decode pBuf = pVal; - pSW = taosMemoryMalloc(sizeof(pSW)); + pSW = taosMemoryMalloc(sizeof(SSchemaWrapper)); tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_DECODER); tDecodeSSchemaWrapper(&coder, pSW); @@ -169,7 +171,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo pSW->pSchema = pSchema; - TDB_FREE(pVal); + tdbFree(pVal); return pSW; } @@ -185,7 +187,9 @@ struct SMCtbCursor { SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { SMCtbCursor *pCtbCur = NULL; + SCtbIdxKey ctbIdxKey; int ret; + int c; pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur)); if (pCtbCur == NULL) { @@ -193,12 +197,20 @@ SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { } pCtbCur->suid = uid; - ret = tdbDbcOpen(pMeta->pCtbIdx, &pCtbCur->pCur); + ret = tdbDbcOpen(pMeta->pCtbIdx, &pCtbCur->pCur, NULL); if (ret < 0) { taosMemoryFree(pCtbCur); return NULL; } + // move to the suid + ctbIdxKey.suid = uid; + ctbIdxKey.uid = INT64_MIN; + tdbDbcMoveTo(pCtbCur->pCur, &ctbIdxKey, sizeof(ctbIdxKey), &c); + if (c > 0) { + tdbDbcMoveToNext(pCtbCur->pCur); + } + return pCtbCur; } @@ -207,8 +219,8 @@ void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) { if (pCtbCur->pCur) { tdbDbcClose(pCtbCur->pCur); - TDB_FREE(pCtbCur->pKey); - TDB_FREE(pCtbCur->pVal); + tdbFree(pCtbCur->pKey); + tdbFree(pCtbCur->pVal); } taosMemoryFree(pCtbCur); @@ -219,12 +231,15 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) { int ret; SCtbIdxKey *pCtbIdxKey; - ret = tdbDbNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen); + ret = tdbDbcNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen); if (ret < 0) { return 0; } pCtbIdxKey = pCtbCur->pKey; + if (pCtbIdxKey->suid > pCtbCur->suid) { + return 0; + } return pCtbIdxKey->uid; } @@ -283,7 +298,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { while (true) { // TODO: lock during iterate? - if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { + if (tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { pSmaIdxKey = pCur->pKey; ASSERT(pSmaIdxKey != NULL); @@ -297,7 +312,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { ++pSW->number; STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma)); if (tptr == NULL) { - TDB_FREE(pSmaVal); + tdbFree(pSmaVal); metaCloseSmaCursor(pCur); tdDestroyTSmaWrapper(pSW); taosMemoryFreeClear(pSW); @@ -306,13 +321,13 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { pSW->tSma = tptr; pBuf = pSmaVal; if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) { - TDB_FREE(pSmaVal); + tdbFree(pSmaVal); metaCloseSmaCursor(pCur); tdDestroyTSmaWrapper(pSW); taosMemoryFreeClear(pSW); return NULL; } - TDB_FREE(pSmaVal); + tdbFree(pSmaVal); continue; } break; @@ -354,7 +369,7 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) { tb_uid_t uid = 0; while (true) { // TODO: lock during iterate? - if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { + if (tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { ASSERT(pSmaIdxKey != NULL); pSmaIdxKey = pCur->pKey; @@ -425,15 +440,15 @@ void *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid, bool isDecode) { if (tDecodeTSma(pBuf, pCfg) == NULL) { tdDestroyTSma(pCfg); taosMemoryFree(pCfg); - TDB_FREE(pVal); + tdbFree(pVal); return NULL; } - TDB_FREE(pVal); + tdbFree(pVal); return pCfg; #endif #endif return NULL; } -#endif \ No newline at end of file +#endif diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index fd5f679d0b4efbfcb6800dc05af0a61d9499f0ec..bba707076c0767e3075d5ea06452ab6180051931 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -289,7 +289,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { pVal = pBuf = buf; metaEncodeTbInfo(&pBuf, pTbCfg); vLen = POINTER_DISTANCE(pBuf, buf); - ret = tdbDbInsert(pMetaDb->pTbDB, pKey, kLen, pVal, vLen, &pMetaDb->txn); + ret = tdbDbPut(pMetaDb->pTbDB, pKey, kLen, pVal, vLen, &pMetaDb->txn); if (ret < 0) { return -1; } @@ -311,7 +311,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { pVal = pBuf = buf; metaEncodeSchemaEx(&pBuf, &schemaWrapper); vLen = POINTER_DISTANCE(pBuf, buf); - ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen, &pMeta->pDB->txn); + ret = tdbDbPut(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen, &pMeta->pDB->txn); if (ret < 0) { return -1; } @@ -325,7 +325,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { kLen = nameLen + 1 + sizeof(uid); pVal = NULL; vLen = 0; - ret = tdbDbInsert(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); + ret = tdbDbPut(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); if (ret < 0) { return -1; } @@ -336,7 +336,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { kLen = sizeof(uid); pVal = NULL; vLen = 0; - ret = tdbDbInsert(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); + ret = tdbDbPut(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); if (ret < 0) { return -1; } @@ -347,7 +347,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { kLen = sizeof(ctbIdxKey); pVal = NULL; vLen = 0; - ret = tdbDbInsert(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); + ret = tdbDbPut(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); if (ret < 0) { return -1; } @@ -362,7 +362,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { kLen = sizeof(uid); pVal = NULL; vLen = 0; - ret = tdbDbInsert(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); + ret = tdbDbPut(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn); if (ret < 0) { return -1; } @@ -407,7 +407,7 @@ static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_ pSchemaWrapper = taosMemoryMalloc(sizeof(*pSchemaWrapper)); metaDecodeSchemaEx(pBuf, pSchemaWrapper, isGetEx); - TDB_FREE(pVal); + tdbFree(pVal); return pSchemaWrapper; } @@ -438,7 +438,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { while (true) { // TODO: lock during iterate? - if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { + if (tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { pSmaIdxKey = pCur->pKey; ASSERT(pSmaIdxKey != NULL); @@ -450,7 +450,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { } if ((pSW == NULL) && ((pSW = taosMemoryCalloc(1, sizeof(*pSW))) == NULL)) { - TDB_FREE(pSmaVal); + tdbFree(pSmaVal); metaCloseSmaCursor(pCur); return NULL; } @@ -458,7 +458,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { ++pSW->number; STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma)); if (tptr == NULL) { - TDB_FREE(pSmaVal); + tdbFree(pSmaVal); metaCloseSmaCursor(pCur); tdDestroyTSmaWrapper(pSW); taosMemoryFreeClear(pSW); @@ -467,13 +467,13 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { pSW->tSma = tptr; pBuf = pSmaVal; if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) { - TDB_FREE(pSmaVal); + tdbFree(pSmaVal); metaCloseSmaCursor(pCur); tdDestroyTSmaWrapper(pSW); taosMemoryFreeClear(pSW); return NULL; } - TDB_FREE(pSmaVal); + tdbFree(pSmaVal); continue; } break; @@ -530,7 +530,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { int32_t kLen = sizeof(pSmaCfg->indexUid); int32_t vLen = POINTER_DISTANCE(qBuf, pBuf); - ret = tdbDbInsert(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn); + ret = tdbDbPut(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn); if (ret < 0) { taosMemoryFreeClear(pBuf); return -1; @@ -545,7 +545,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { val = NULL; vLen = 0; - ret = tdbDbInsert(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn); + ret = tdbDbPut(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn); if (ret < 0) { taosMemoryFreeClear(pBuf); return -1; @@ -613,7 +613,7 @@ int64_t metaSmaCursorNext(SMSmaCursor *pCur) { void *pBuf; SSmaIdxKey *smaIdxKey; - ret = tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, &pCur->pVal, &pCur->vLen); + ret = tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, &pCur->pVal, &pCur->vLen); if (ret < 0) { return 0; } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 3e70bbb4797c459e2af51207092e5fdb3dc9b73e..cb0b3dc81c6e10d6621bc0c5ba143262b2cd8904 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -61,19 +61,58 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { if (metaHandleEntry(pMeta, &me) < 0) goto _err; - metaDebug("vgId: %d super table is created, name:%s uid: %" PRId64, TD_VID(pMeta->pVnode), pReq->name, pReq->suid); + metaDebug("vgId:%d super table is created, name:%s uid: %" PRId64, TD_VID(pMeta->pVnode), pReq->name, pReq->suid); return 0; _err: - metaError("vgId: %d failed to create super table: %s uid: %" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + metaError("vgId:%d failed to create super table: %s uid: %" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, tstrerror(terrno)); return -1; } int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) { - // TODO + SMetaReader mr = {0}; + + // validate req + metaReaderInit(&mr, pMeta, 0); + if (metaGetTableEntryByUid(&mr, pReq->suid) < 0) { + terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + goto _err; + } + + // do drop + // drop from pTbDb + // drop from pSkmDb + // drop from pUidIdx + // drop from pNameIdx + // { + // TDBC *pDbc1 = NULL; + // void *pKey = NULL; + // void *pVal = NULL; + // int kLen = 0; + // int vLen = 0; + // int ret = 0; + + // // drop from pCtbIdx + // ret = tdbDbcOpen(pMeta->pCtbIdx, &pDbc1); + // tdbDbcMoveTo(pDbc1, &pReq->suid, sizeof(pReq->suid), NULL /*cmpr*/, 0 /*TDB_FORWARD_SEARCH*/); + // tdbDbcGet(pDbc1, &pKey, &kLen, &pVal, vLen); + // tdbDbcDrop(pDbc1); + // // drop from pTagIdx + // // drop from pTtlIdx + // } + + // clear and return + metaReaderClear(&mr); + metaError("vgId:%d super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid); return 0; + +_err: + metaReaderClear(&mr); + metaError("vgId:%d failed to drop super table %s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, + pReq->suid, tstrerror(terrno)); + return -1; } int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) { @@ -179,7 +218,7 @@ static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) { tCoderClear(&coder); // write to table.db - if (tdbDbInsert(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) { + if (tdbDbPut(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) { goto _err; } @@ -192,11 +231,11 @@ _err: } static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) { - return tdbDbInsert(pMeta->pUidIdx, &pME->uid, sizeof(tb_uid_t), &pME->version, sizeof(int64_t), &pMeta->txn); + return tdbDbPut(pMeta->pUidIdx, &pME->uid, sizeof(tb_uid_t), &pME->version, sizeof(int64_t), &pMeta->txn); } static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) { - return tdbDbInsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), &pMeta->txn); + return tdbDbPut(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), &pMeta->txn); } static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { @@ -219,12 +258,12 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { ttlKey.dtime = ctime + ttlDays * 24 * 60 * 60; ttlKey.uid = pME->uid; - return tdbDbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn); + return tdbDbPut(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn); } static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) { SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid}; - return tdbDbInsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), NULL, 0, &pMeta->txn); + return tdbDbPut(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), NULL, 0, &pMeta->txn); } static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pME) { @@ -265,7 +304,7 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) { tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_ENCODER); tEncodeSSchemaWrapper(&coder, pSW); - if (tdbDbInsert(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) { + if (tdbDbPut(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) { rcode = -1; goto _exit; } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 7cee82f660d92ce0b64e3c6e491ae13da7030c78..411d5c451c92cd45f56d491f3c994eb1ef5bfc09 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -58,6 +58,48 @@ void tqClose(STQ* pTq) { // TODO } +static void tdSRowDemo() { +#define DEMO_N_COLS 3 + + int16_t schemaVersion = 0; + int32_t numOfCols = DEMO_N_COLS; // ts + int + SRowBuilder rb = {0}; + + SSchema schema[DEMO_N_COLS] = { + {.type = TSDB_DATA_TYPE_TIMESTAMP, .colId = 1, .name = "ts", .bytes = 8, .flags = SCHEMA_SMA_ON}, + {.type = TSDB_DATA_TYPE_INT, .colId = 2, .name = "c1", .bytes = 4, .flags = SCHEMA_SMA_ON}, + {.type = TSDB_DATA_TYPE_INT, .colId = 3, .name = "c2", .bytes = 4, .flags = SCHEMA_SMA_ON}}; + + SSchema* pSchema = schema; + STSchema* pTSChema = tdGetSTSChemaFromSSChema(&pSchema, numOfCols); + + tdSRowInit(&rb, schemaVersion); + tdSRowSetTpInfo(&rb, numOfCols, pTSChema->flen); + int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSChema); + void* row = taosMemoryCalloc(1, maxLen); // make sure the buffer is enough + + // set row buf + tdSRowResetBuf(&rb, row); + + for (int32_t idx = 0; idx < pTSChema->numOfCols; ++idx) { + STColumn* pColumn = pTSChema->columns + idx; + if (idx == 0) { + int64_t tsKey = 1651234567; + tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, &tsKey, true, pColumn->offset, idx); + } else if (idx == 1) { + int32_t val1 = 10; + tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, &val1, true, pColumn->offset, idx); + } else { + tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, true, pColumn->offset, idx); + } + } + + // print + tdSRowPrint(row, pTSChema, __func__); + + taosMemoryFree(pTSChema); +} + int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) { if (msgType != TDMT_VND_SUBMIT) return 0; void* pIter = NULL; @@ -864,7 +906,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { } int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { - SStreamTask* pTask = taosMemoryMalloc(sizeof(SStreamTask)); + SStreamTask* pTask = taosMemoryCalloc(1, sizeof(SStreamTask)); if (pTask == NULL) { return -1; } diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index cf1154071dbc14ac48ebdae04427de083b9e1857..89ec55cca122791469ecf1a2bd7fe3dc1c5f509e 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -91,16 +91,8 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p int32_t sversion = 0; if (pHandle->sver != sversion) { pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion); -#if 0 - tb_uid_t quid; - STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->msgIter.uid); - if (pTbCfg->type == META_CHILD_TABLE) { - quid = pTbCfg->ctbCfg.suid; - } else { - quid = pHandle->msgIter.uid; - } - pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, quid, sversion, true); -#endif + + // this interface use suid instead of uid pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.suid, sversion, true); pHandle->sver = sversion; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 8bcb848516890e917e0c1b91293a2017df853217..fc235342470e34c1e0aa3bc4f06f429d696d65ae 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -55,7 +55,7 @@ typedef struct { #define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh)) #define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh)) #define TSDB_COMMIT_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh)) -#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->config.maxRows) +#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->pVnode->config.tsdbCfg.maxRows) #define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch))) static void tsdbStartCommit(STsdb *pRepo); @@ -922,7 +922,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF STColumn *pColumn = pSchema->columns + ncol; SDataCol *pDataCol = pDataCols->cols + ncol; SBlockCol *pBlockCol = pBlockData->cols + nColsNotAllNull; - SAggrBlkCol *pAggrBlkCol = (SAggrBlkCol *)pAggrBlkData + nColsNotAllNull; + SAggrBlkCol *pAggrBlkCol = (SAggrBlkCol *)pAggrBlkData + nColsOfBlockSma; if (isAllRowsNull(pDataCol)) { // all data to commit are NULL, just ignore it continue; @@ -935,7 +935,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF pBlockCol->type = pDataCol->type; pAggrBlkCol->colId = pDataCol->colId; - if (isSuper && pColumn->sma && tDataTypes[pDataCol->type].statisFunc) { + if (isSuper && IS_BSMA_ON(pColumn) && tDataTypes[pDataCol->type].statisFunc) { #if 0 (*tDataTypes[pDataCol->type].statisFunc)(pDataCol->pData, rowsToWrite, &(pBlockCol->min), &(pBlockCol->max), &(pBlockCol->sum), &(pBlockCol->minIndex), &(pBlockCol->maxIndex), @@ -951,6 +951,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF } else { TD_SET_COL_ROWS_MISC(pBlockCol); } + ++nColsOfBlockSma; } else if (tdIsBitmapBlkNorm(pDataCol->pBitmap, rowsToWrite, pDataCols->bitmapMode)) { // check if all rows normal TD_SET_COL_ROWS_NORM(pBlockCol); @@ -959,10 +960,6 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF } ++nColsNotAllNull; - - if (isSuper && pColumn->sma) { - ++nColsOfBlockSma; - } } ASSERT(nColsNotAllNull >= 0 && nColsNotAllNull <= pDataCols->numOfCols); diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index e5b25184154401897c6d16fe4eee9540e8d96483..0827ba6eab183ea4f314dbef1e6b6b020a1a894c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -15,12 +15,34 @@ #include "tsdb.h" -int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb) { +static int tsdbOpenImpl(SVnode *pVnode, int8_t type, STsdb **ppTsdb, const char *dir); + +int tsdbOpen(SVnode *pVnode, int8_t type) { + switch (type) { + case TSDB_TYPE_TSDB: + return tsdbOpenImpl(pVnode, type, &VND_TSDB(pVnode), VNODE_TSDB_DIR); + case TSDB_TYPE_TSMA: + ASSERT(0); + break; + case TSDB_TYPE_RSMA_L0: + return tsdbOpenImpl(pVnode, type, &VND_RSMA0(pVnode), VNODE_TSDB_DIR); + case TSDB_TYPE_RSMA_L1: + return tsdbOpenImpl(pVnode, type, &VND_RSMA1(pVnode), VNODE_RSMA1_DIR); + case TSDB_TYPE_RSMA_L2: + return tsdbOpenImpl(pVnode, type, &VND_RSMA2(pVnode), VNODE_RSMA2_DIR); + default: + ASSERT(0); + break; + } + return 0; +} + +int tsdbOpenImpl(SVnode *pVnode, int8_t type, STsdb **ppTsdb, const char *dir) { STsdb *pTsdb = NULL; int slen = 0; *ppTsdb = NULL; - slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_TSDB_DIR) + 3; + slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(dir) + 3; // create handle pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(*pTsdb) + slen); @@ -31,12 +53,11 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb) { pTsdb->path = (char *)&pTsdb[1]; sprintf(pTsdb->path, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, - VNODE_TSDB_DIR); + dir); pTsdb->pVnode = pVnode; pTsdb->repoLocked = false; - tdbMutexInit(&pTsdb->mutex, NULL); - pTsdb->config = pVnode->config.tsdbCfg; - pTsdb->fs = tsdbNewFS(&pTsdb->config); + taosThreadMutexInit(&pTsdb->mutex, NULL); + pTsdb->fs = tsdbNewFS(REPO_CFG(pTsdb)); // create dir (TODO: use tfsMkdir) taosMkDir(pTsdb->path); @@ -46,7 +67,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb) { goto _err; } - tsdbDebug("vgId: %d tsdb is opened", TD_VID(pVnode)); + tsdbDebug("vgId: %d tsdb is opened for %s", TD_VID(pVnode), pTsdb->path); *ppTsdb = pTsdb; return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 1b23d12c2f6a42279376f79f1c9e0f3bcc364d8d..7d3f7cadc9b8ebdcac031b4acd17387f910f7ea7 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -97,12 +97,20 @@ typedef struct SIOCostSummary { int64_t headFileLoadTime; } SIOCostSummary; +typedef struct SBlockLoadSuppInfo { + SColumnDataAgg *pstatis; + SColumnDataAgg **plist; + SArray *defaultLoadColumn; // default load column + int32_t *slotIds; // colId to slotId +} SBlockLoadSuppInfo; + typedef struct STsdbReadHandle { STsdb* pTsdb; SQueryFilePos cur; // current position int16_t order; STimeWindow window; // the primary query time window that applies to all queries - SColumnDataAgg* statis; // query level statistics, only one table block statistics info exists at any time +// SColumnDataAgg* statis; // query level statistics, only one table block statistics info exists at any time +// SColumnDataAgg** pstatis;// the ptr array list to return to caller int32_t numOfBlocks; SArray* pColumns; // column list, SColumnInfoData array list bool locateStart; @@ -123,13 +131,13 @@ typedef struct STsdbReadHandle { STableBlockInfo* pDataBlockInfo; SDataCols* pDataCols; // in order to hold current file data block int32_t allocSize; // allocated data block size - SArray* defaultLoadColumn; // default load column SDataBlockLoadInfo dataBlockLoadInfo; /* record current block load information */ SLoadCompBlockInfo compBlockLoadInfo; /* record current compblock information in SQueryAttr */ - + SBlockLoadSuppInfo suppInfo; SArray* prev; // previous row which is before than time window SArray* next; // next row which is after the query time window SIOCostSummary cost; + STSchema* pSchema; } STsdbReadHandle; typedef struct STableGroupSupporter { @@ -311,7 +319,7 @@ static bool emptyQueryTimewindow(STsdbReadHandle* pTsdbReadHandle) { // Update the query time window according to the data time to live(TTL) information, in order to avoid to return // the expired data to client, even it is queried already. static int64_t getEarliestValidTimestamp(STsdb* pTsdb) { - STsdbCfg* pCfg = &pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pTsdb); int64_t now = taosGetTimestamp(pCfg->precision); return now - (tsTickPerDay[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick @@ -343,14 +351,14 @@ static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, SQueryTableData } } -static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, SQueryTableDataCond* pCond, uint64_t qId, uint64_t taskId) { +static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond* pCond, uint64_t qId, uint64_t taskId) { STsdbReadHandle* pReadHandle = taosMemoryCalloc(1, sizeof(STsdbReadHandle)); if (pReadHandle == NULL) { goto _end; } pReadHandle->order = pCond->order; - pReadHandle->pTsdb = tsdb; + pReadHandle->pTsdb = pVnode->pTsdb; pReadHandle->type = TSDB_QUERY_TYPE_ALL; pReadHandle->cur.fid = INT32_MIN; pReadHandle->cur.win = TSWINDOW_INITIALIZER; @@ -368,7 +376,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, SQueryTableDataCond* pC snprintf(buf, tListLen(buf), "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, qId); pReadHandle->idStr = strdup(buf); - if (tsdbInitReadH(&pReadHandle->rhelper, (STsdb*)tsdb) != 0) { + if (tsdbInitReadH(&pReadHandle->rhelper, (STsdb*)pVnode->pTsdb) != 0) { goto _end; } @@ -377,8 +385,8 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, SQueryTableDataCond* pC if (pCond->numOfCols > 0) { // allocate buffer in order to load data blocks from file - pReadHandle->statis = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnDataAgg)); - if (pReadHandle->statis == NULL) { + pReadHandle->suppInfo.pstatis = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnDataAgg)); + if (pReadHandle->suppInfo.pstatis == NULL) { goto _end; } @@ -398,13 +406,14 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, SQueryTableDataCond* pC } taosArrayPush(pReadHandle->pColumns, &colInfo); - pReadHandle->statis[i].colId = colInfo.info.colId; } - pReadHandle->defaultLoadColumn = getDefaultLoadColumns(pReadHandle, true); + pReadHandle->suppInfo.defaultLoadColumn = getDefaultLoadColumns(pReadHandle, true); + pReadHandle->suppInfo.slotIds = taosMemoryMalloc(sizeof(int32_t) * taosArrayGetSize(pReadHandle->suppInfo.defaultLoadColumn)); + pReadHandle->suppInfo.plist = taosMemoryCalloc(taosArrayGetSize(pReadHandle->suppInfo.defaultLoadColumn), POINTER_BYTES); } - pReadHandle->pDataCols = tdNewDataCols(1000, pReadHandle->pTsdb->config.maxRows); + pReadHandle->pDataCols = tdNewDataCols(1000, pReadHandle->pTsdb->pVnode->config.tsdbCfg.maxRows); if (pReadHandle->pDataCols == NULL) { tsdbError("%p failed to malloc buf for pDataCols, %s", pReadHandle, pReadHandle->idStr); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -422,9 +431,10 @@ _end: return NULL; } -tsdbReaderT* tsdbQueryTables(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, +tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { - STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(tsdb, pCond, qId, taskId); + + STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(pVnode, pCond, qId, taskId); if (pTsdbReadHandle == NULL) { return NULL; } @@ -441,6 +451,29 @@ tsdbReaderT* tsdbQueryTables(STsdb* tsdb, SQueryTableDataCond* pCond, STableGrou return NULL; } + STableCheckInfo *pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, 0); + + pTsdbReadHandle->pSchema = metaGetTbTSchema(pVnode->pMeta, pCheckInfo->tableId, 0); + int32_t numOfCols = taosArrayGetSize(pTsdbReadHandle->suppInfo.defaultLoadColumn); + int16_t* ids = pTsdbReadHandle->suppInfo.defaultLoadColumn->pData; + + STSchema* pSchema = pTsdbReadHandle->pSchema; + + int32_t i = 0, j = 0; + while(i < numOfCols && j < pSchema->numOfCols) { + if (ids[i] == pSchema->columns[j].colId) { + pTsdbReadHandle->suppInfo.slotIds[i] = j; + i++; + j++; + } else if (ids[i] > pSchema->columns[j].colId) { + j++; + } else { + // tsdbCleanupReadHandle(pTsdbReadHandle); + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } + } + tsdbDebug("%p total numOfTable:%" PRIzu " in this query, group %" PRIzu " %s", pTsdbReadHandle, taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), taosArrayGetSize(groupList->pGroupList), pTsdbReadHandle->idStr); @@ -477,7 +510,8 @@ void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond* pCond) { } // allocate buffer in order to load data blocks from file - memset(pTsdbReadHandle->statis, 0, sizeof(SColumnDataAgg)); + memset(pTsdbReadHandle->suppInfo.pstatis, 0, sizeof(SColumnDataAgg)); + memset(pTsdbReadHandle->suppInfo.plist, 0, POINTER_BYTES); tsdbInitDataBlockLoadInfo(&pTsdbReadHandle->dataBlockLoadInfo); tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo); @@ -505,7 +539,8 @@ void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, SQueryTableDataCon } // allocate buffer in order to load data blocks from file - memset(pTsdbReadHandle->statis, 0, sizeof(SColumnDataAgg)); + memset(pTsdbReadHandle->suppInfo.pstatis, 0, sizeof(SColumnDataAgg)); + memset(pTsdbReadHandle->suppInfo.plist, 0, POINTER_BYTES); tsdbInitDataBlockLoadInfo(&pTsdbReadHandle->dataBlockLoadInfo); tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo); @@ -526,7 +561,7 @@ void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, SQueryTableDataCon // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); } -tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, +tsdbReaderT tsdbQueryLastRow(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { pCond->twindow = updateLastrowForEachGroup(groupList); @@ -535,7 +570,7 @@ tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGrou return NULL; } - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(tsdb, pCond, groupList, qId, taskId); + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(pVnode, pCond, groupList, qId, taskId); if (pTsdbReadHandle == NULL) { return NULL; } @@ -555,8 +590,8 @@ tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGrou } #if 0 -tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, STsdbMemTable* pMemRef) { - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, pMemRef); +tsdbReaderT tsdbQueryCacheLastT(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, STsdbMemTable* pMemRef) { + STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTablesT(tsdb, pCond, groupList, qId, pMemRef); if (pTsdbReadHandle == NULL) { return NULL; } @@ -618,7 +653,7 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr return pNew; } -tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, +tsdbReaderT tsdbQueryRowsInExternalWindow(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList); @@ -634,7 +669,7 @@ tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, SQueryTableDataCond* pCon } } - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(tsdb, pCond, pNew, qId, taskId); + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(pVnode, pCond, pNew, qId, taskId); pTsdbReadHandle->loadExternalRow = true; pTsdbReadHandle->currentLoadExternalRows = true; @@ -889,7 +924,7 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { } static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { - STsdbCfg* pCfg = &pHandle->pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pHandle->pTsdb); size_t size = taosArrayGetSize(pHandle->pTableCheckInfo); assert(pHandle->activeIndex < size && pHandle->activeIndex >= 0 && size >= 1); pHandle->cur.fid = INT32_MIN; @@ -986,7 +1021,7 @@ static int32_t loadBlockInfo(STsdbReadHandle* pTsdbReadHandle, int32_t index, in pCheckInfo->numOfBlocks = 0; STable table = {.uid = pCheckInfo->tableId, .tid = pCheckInfo->tableId}; - table.pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, 0); + table.pSchema = pTsdbReadHandle->pSchema; if (tsdbSetReadTable(&pTsdbReadHandle->rhelper, &table) != TSDB_CODE_SUCCESS) { code = terrno; @@ -1091,29 +1126,28 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl int32_t slotIndex) { int64_t st = taosGetTimestampUs(); - STSchema* pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, 0); - int32_t code = tdInitDataCols(pTsdbReadHandle->pDataCols, pSchema); + int32_t code = tdInitDataCols(pTsdbReadHandle->pDataCols, pTsdbReadHandle->pSchema); if (code != TSDB_CODE_SUCCESS) { tsdbError("%p failed to malloc buf for pDataCols, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _error; } - code = tdInitDataCols(pTsdbReadHandle->rhelper.pDCols[0], pSchema); + code = tdInitDataCols(pTsdbReadHandle->rhelper.pDCols[0], pTsdbReadHandle->pSchema); if (code != TSDB_CODE_SUCCESS) { tsdbError("%p failed to malloc buf for rhelper.pDataCols[0], %s", pTsdbReadHandle, pTsdbReadHandle->idStr); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _error; } - code = tdInitDataCols(pTsdbReadHandle->rhelper.pDCols[1], pSchema); + code = tdInitDataCols(pTsdbReadHandle->rhelper.pDCols[1], pTsdbReadHandle->pSchema); if (code != TSDB_CODE_SUCCESS) { tsdbError("%p failed to malloc buf for rhelper.pDataCols[1], %s", pTsdbReadHandle, pTsdbReadHandle->idStr); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _error; } - int16_t* colIds = pTsdbReadHandle->defaultLoadColumn->pData; + int16_t* colIds = pTsdbReadHandle->suppInfo.defaultLoadColumn->pData; int32_t ret = tsdbLoadBlockDataCols(&(pTsdbReadHandle->rhelper), pBlock, pCheckInfo->pCompInfo, colIds, (int)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)), true); @@ -1169,7 +1203,7 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo) { SQueryFilePos* cur = &pTsdbReadHandle->cur; - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); TSKEY key; int32_t code = TSDB_CODE_SUCCESS; @@ -1490,6 +1524,10 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit pSchema1 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row1)); } +#ifdef TD_DEBUG_PRINT_ROW + tdSRowPrint(row1, pSchema1, __func__); +#endif + if (isRow1DataRow) { numOfColsOfRow1 = schemaNCols(pSchema1); } else { @@ -1519,8 +1557,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit } else if (isRow1DataRow) { colIdOfRow1 = pSchema1->columns[j].colId; } else { - SKvRowIdx* pColIdx = tdKvRowColIdxAt(row1, j); - colIdOfRow1 = pColIdx->colId; + colIdOfRow1 = tdKvRowColIdAt(row1, j); } int32_t colIdOfRow2; @@ -1529,8 +1566,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit } else if (isRow2DataRow) { colIdOfRow2 = pSchema2->columns[k].colId; } else { - SKvRowIdx* pColIdx = tdKvRowColIdxAt(row2, k); - colIdOfRow2 = pColIdx->colId; + colIdOfRow2 = tdKvRowColIdAt(row2, k); } if (colIdOfRow1 == colIdOfRow2) { @@ -1754,7 +1790,7 @@ int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* p static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock) { SQueryFilePos* cur = &pTsdbReadHandle->cur; SDataBlockInfo blockInfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); initTableMemIterator(pTsdbReadHandle, pCheckInfo); @@ -2198,7 +2234,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi int32_t numOfBlocks = 0; int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); STimeWindow win = TSWINDOW_INITIALIZER; while (true) { @@ -2304,7 +2340,7 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* // find the start data block in file pTsdbReadHandle->locateStart = true; - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); int32_t fid = getFileIdFromKey(pTsdbReadHandle->window.skey, pCfg->days, pCfg->precision); tsdbRLockFS(pFileHandle); @@ -2405,7 +2441,7 @@ static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exis // find the start data block in file if (!pTsdbReadHandle->locateStart) { pTsdbReadHandle->locateStart = true; - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); int32_t fid = getFileIdFromKey(pTsdbReadHandle->window.skey, pCfg->days, pCfg->precision); tsdbRLockFS(pFileHandle); @@ -2496,7 +2532,7 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int STsdbReadHandle* pTsdbReadHandle) { int numOfRows = 0; int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); win->skey = TSKEY_INITIAL_VAL; int64_t st = taosGetTimestampUs(); @@ -3237,8 +3273,9 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa /* * return null for mixed data block, if not a complete file data block, the statistics value will always return NULL */ -int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SColumnDataAgg** pBlockStatis) { +int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SColumnDataAgg*** pBlockStatis, bool* allHave) { STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; + *allHave = false; SQueryFilePos* c = &pHandle->cur; if (c->mixBlock) { @@ -3267,35 +3304,47 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SColumnDat tsdbDebug("vgId:%d succeed to load block statis part for uid %" PRIu64, REPO_ID(pHandle->pTsdb), TSDB_READ_TABLE_UID(&pHandle->rhelper)); - int16_t* colIds = pHandle->defaultLoadColumn->pData; + int16_t* colIds = pHandle->suppInfo.defaultLoadColumn->pData; size_t numOfCols = QH_GET_NUM_OF_COLS(pHandle); - memset(pHandle->statis, 0, numOfCols * sizeof(SColumnDataAgg)); + memset(pHandle->suppInfo.plist, 0, numOfCols * POINTER_BYTES); + memset(pHandle->suppInfo.pstatis, 0, numOfCols * sizeof(SColumnDataAgg)); + for (int32_t i = 0; i < numOfCols; ++i) { - pHandle->statis[i].colId = colIds[i]; + pHandle->suppInfo.pstatis[i].colId = colIds[i]; } - tsdbGetBlockStatis(&pHandle->rhelper, pHandle->statis, (int)numOfCols, pBlockInfo->compBlock); + *allHave = true; + tsdbGetBlockStatis(&pHandle->rhelper, pHandle->suppInfo.pstatis, (int)numOfCols, pBlockInfo->compBlock); // always load the first primary timestamp column data - SColumnDataAgg* pPrimaryColStatis = &pHandle->statis[0]; + SColumnDataAgg* pPrimaryColStatis = &pHandle->suppInfo.pstatis[0]; assert(pPrimaryColStatis->colId == PRIMARYKEY_TIMESTAMP_COL_ID); pPrimaryColStatis->numOfNull = 0; pPrimaryColStatis->min = pBlockInfo->compBlock->keyFirst; pPrimaryColStatis->max = pBlockInfo->compBlock->keyLast; + pHandle->suppInfo.plist[0] = &pHandle->suppInfo.pstatis[0]; // update the number of NULL data rows + int32_t* slotIds = pHandle->suppInfo.slotIds; for (int32_t i = 1; i < numOfCols; ++i) { - if (pHandle->statis[i].numOfNull == -1) { // set the column data are all NULL - pHandle->statis[i].numOfNull = pBlockInfo->compBlock->numOfRows; + ASSERT(colIds[i] == pHandle->pSchema->columns[slotIds[i]].colId); + if (IS_BSMA_ON(&(pHandle->pSchema->columns[slotIds[i]]))) { + if (pHandle->suppInfo.pstatis[i].numOfNull == -1) { // set the column data are all NULL + pHandle->suppInfo.pstatis[i].numOfNull = pBlockInfo->compBlock->numOfRows; + } else { + pHandle->suppInfo.plist[i] = &pHandle->suppInfo.pstatis[i]; + } + } else { + *allHave = false; } } int64_t elapsed = taosGetTimestampUs() - stime; pHandle->cost.statisInfoLoadTime += elapsed; - *pBlockStatis = pHandle->statis; + *pBlockStatis = pHandle->suppInfo.plist; return TSDB_CODE_SUCCESS; } @@ -3715,7 +3764,7 @@ _error: } #if 0 -int32_t tsdbGetTableGroupFromIdList(STsdb* tsdb, SArray* pTableIdList, STableGroupInfo* pGroupInfo) { +int32_t tsdbGetTableGroupFromIdListT(STsdb* tsdb, SArray* pTableIdList, STableGroupInfo* pGroupInfo) { if (tsdbRLockRepoMeta(tsdb) < 0) { return terrno; } @@ -3797,9 +3846,10 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { pTsdbReadHandle->pColumns = doFreeColumnInfoData(pTsdbReadHandle->pColumns); - taosArrayDestroy(pTsdbReadHandle->defaultLoadColumn); + taosArrayDestroy(pTsdbReadHandle->suppInfo.defaultLoadColumn); taosMemoryFreeClear(pTsdbReadHandle->pDataBlockInfo); - taosMemoryFreeClear(pTsdbReadHandle->statis); + taosMemoryFreeClear(pTsdbReadHandle->suppInfo.pstatis); + taosMemoryFreeClear(pTsdbReadHandle->suppInfo.plist); if (!emptyQueryTimewindow(pTsdbReadHandle)) { // tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index c39780372b98a83b60285d4530f397be16726fd6..d7c9a70c183786cce37129cb714d36186eacdf29 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -248,7 +248,8 @@ int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget) { int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) { ASSERT(pBlock->numOfSubBlocks > 0); - int8_t update = pReadh->pRepo->config.update; + STsdbCfg *pCfg = REPO_CFG(pReadh->pRepo); + int8_t update = pCfg->update; SBlock *iBlock = pBlock; if (pBlock->numOfSubBlocks > 1) { @@ -279,7 +280,7 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) { int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, int numOfColsIds, bool mergeBitmap) { ASSERT(pBlock->numOfSubBlocks > 0); - int8_t update = pReadh->pRepo->config.update; + int8_t update = pReadh->pRepo->pVnode->config.tsdbCfg.update; SBlock *iBlock = pBlock; if (pBlock->numOfSubBlocks > 1) { @@ -471,7 +472,7 @@ void tsdbGetBlockStatis(SReadH *pReadh, SColumnDataAgg *pStatis, int numOfCols, SAggrBlkData *pAggrBlkData = pReadh->pAggrBlkData; for (int i = 0, j = 0; i < numOfCols;) { - if (j >= pBlock->numOfCols) { + if (j >= pBlock->numOfBSma) { pStatis[i].numOfNull = -1; ++i; continue; diff --git a/source/dnode/vnode/src/tsdb/tsdbScan.c b/source/dnode/vnode/src/tsdb/tsdbScan.c deleted file mode 100644 index cc6fb473d00c299475c7140e57d6471649915328..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/tsdb/tsdbScan.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#if 0 -#include "tsdb.h" -#ifndef _TSDB_PLUGINS - -int tsdbScanFGroup(STsdbScanHandle* pScanHandle, char* rootDir, int fid) { return 0; } - -STsdbScanHandle* tsdbNewScanHandle() { return NULL; } - -void tsdbSetScanLogStream(STsdbScanHandle* pScanHandle, FILE* fLogStream) {} - -int tsdbSetAndOpenScanFile(STsdbScanHandle* pScanHandle, char* rootDir, int fid) { return 0; } - -int tsdbScanSBlockIdx(STsdbScanHandle* pScanHandle) { return 0; } - -int tsdbScanSBlock(STsdbScanHandle* pScanHandle, int idx) { return 0; } - -int tsdbCloseScanFile(STsdbScanHandle* pScanHandle) { return 0; } - -void tsdbFreeScanHandle(STsdbScanHandle* pScanHandle) {} - -#endif -#endif \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index c9e33cefc7c87f6601e53026252c89a0a629c5a1..d131cef8a2ac719320aae70636e48cd90e9a8185 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -103,10 +103,9 @@ typedef struct { STSma *pSma; // cache schema } SSmaStatItem; -#define RSMA_MAX_LEVEL 2 #define RSMA_TASK_INFO_HASH_SLOT 8 struct SRSmaInfo { - void *taskInfo[RSMA_MAX_LEVEL]; // qTaskInfo_t + void *taskInfo[TSDB_RSMA_RETENTION_2]; // qTaskInfo_t }; struct SSmaStat { @@ -128,7 +127,7 @@ static FORCE_INLINE void tsdbFreeTaskHandle(qTaskInfo_t *taskHandle) { } static FORCE_INLINE void *tsdbFreeRSmaInfo(SRSmaInfo *pInfo) { - for (int32_t i = 0; i < RSMA_MAX_LEVEL; ++i) { + for (int32_t i = 0; i < TSDB_RSMA_RETENTION_MAX; ++i) { if (pInfo->taskInfo[i]) { tsdbFreeTaskHandle(pInfo->taskInfo[i]); } @@ -173,6 +172,7 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg); static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg); +static FORCE_INLINE int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid); static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids); // mgmt interface static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid); @@ -223,7 +223,7 @@ static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) { } static SPoolMem *openPool() { - SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool)); + SPoolMem *pPool = (SPoolMem *)taosMemoryMalloc(sizeof(*pPool)); pPool->prev = pPool->next = pPool; pPool->size = 0; @@ -245,7 +245,7 @@ static void clearPool(SPoolMem *pPool) { pMem->prev->next = pMem->next; pPool->size -= pMem->size; - tdbOsFree(pMem); + taosMemoryFree(pMem); } while (1); assert(pPool->size == 0); @@ -254,7 +254,7 @@ static void clearPool(SPoolMem *pPool) { static void closePool(SPoolMem *pPool) { if (pPool) { clearPool(pPool); - tdbOsFree(pPool); + taosMemoryFree(pPool); } } @@ -263,7 +263,7 @@ static void *poolMalloc(void *arg, size_t size) { SPoolMem *pPool = (SPoolMem *)arg; SPoolMem *pMem; - pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size); + pMem = (SPoolMem *)taosMemoryMalloc(sizeof(*pMem) + size); if (!pMem) { assert(0); } @@ -290,7 +290,7 @@ static void poolFree(void *arg, void *ptr) { pMem->prev->next = pMem->next; pPool->size -= pMem->size; - tdbOsFree(pMem); + taosMemoryFree(pMem); } int32_t tsdbInitSma(STsdb *pTsdb) { @@ -1692,18 +1692,16 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) { * @param pReq * @return int32_t */ -int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) { -#if 0 - SRSmaParam *param = pReq->stbCfg.pRSmaParam; - - if (!param) { - tsdbDebug("vgId:%d return directly since no rollup for stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, - pReq->stbCfg.suid); +int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateStbReq *pReq) { + if (!pReq->rollup) { + tsdbDebug("vgId:%d return directly since no rollup for stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->suid); return TSDB_CODE_SUCCESS; } + SRSmaParam *param = &pReq->pRSmaParam; + if ((param->qmsg1Len == 0) && (param->qmsg2Len == 0)) { - tsdbWarn("vgId:%d no qmsg1/qmsg2 for rollup stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid); + tsdbWarn("vgId:%d no qmsg1/qmsg2 for rollup stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->suid); return TSDB_CODE_SUCCESS; } @@ -1716,9 +1714,9 @@ int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) { SSmaStat *pStat = SMA_ENV_STAT(pEnv); SRSmaInfo *pRSmaInfo = NULL; - pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t)); + pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t)); if (pRSmaInfo) { - tsdbWarn("vgId:%d rsma info already exists for stb: %s, %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid); + tsdbWarn("vgId:%d rsma info already exists for stb: %s, %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->suid); return TSDB_CODE_SUCCESS; } @@ -1758,14 +1756,13 @@ int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) { } } - if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) != + if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) != TSDB_CODE_SUCCESS) { return TSDB_CODE_FAILED; } else { - tsdbDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, REPO_ID(pTsdb), pReq->stbCfg.suid); + tsdbDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, REPO_ID(pTsdb), pReq->suid); } -#endif return TSDB_CODE_SUCCESS; } @@ -1777,7 +1774,7 @@ int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) { * @param uid * @return int32_t */ -int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) { +static int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) { // prefer to store suid/uids in array if ((suid == pStore->suid) || (pStore->suid == 0)) { if (pStore->suid == 0) { @@ -1833,6 +1830,7 @@ void tsdbUidStoreDestory(STbUidStore *pStore) { if (pStore) { if (pStore->uidHash) { if (pStore->tbUids) { + // When pStore->tbUids not NULL, the pStore->uidHash has k/v; otherwise pStore->uidHash only has keys. void *pIter = taosHashIterate(pStore->uidHash, NULL); while (pIter) { SArray *arr = *(SArray **)pIter; @@ -1847,8 +1845,10 @@ void tsdbUidStoreDestory(STbUidStore *pStore) { } void *tsdbUidStoreFree(STbUidStore *pStore) { - tsdbUidStoreDestory(pStore); - taosMemoryFree(pStore); + if (pStore) { + tsdbUidStoreDestory(pStore); + taosMemoryFree(pStore); + } return NULL; } @@ -1861,7 +1861,7 @@ void *tsdbUidStoreFree(STbUidStore *pStore) { * @param uid * @return int32_t */ -int32_t tsdbFetchTbUidList(void *pTsdb, void **ppStore, void *suid, void *uid) { +int32_t tsdbFetchTbUidList(STsdb *pTsdb, STbUidStore **ppStore, tb_uid_t suid, tb_uid_t uid) { SSmaEnv *pEnv = REPO_RSMA_ENV((STsdb *)pTsdb); // only applicable to rollup SMA ctables @@ -1877,7 +1877,7 @@ int32_t tsdbFetchTbUidList(void *pTsdb, void **ppStore, void *suid, void *uid) { } // info cached when create rsma stable and return directly for non-rsma ctables - if (!taosHashGet(infoHash, suid, sizeof(tb_uid_t))) { + if (!taosHashGet(infoHash, &suid, sizeof(tb_uid_t))) { return TSDB_CODE_SUCCESS; } @@ -1887,7 +1887,7 @@ int32_t tsdbFetchTbUidList(void *pTsdb, void **ppStore, void *suid, void *uid) { } } - if (tsdbUidStorePut(*ppStore, *(tb_uid_t *)suid, (tb_uid_t *)uid) != 0) { + if (tsdbUidStorePut(*ppStore, suid, &uid) != 0) { *ppStore = tsdbUidStoreFree(*ppStore); return TSDB_CODE_FAILED; } @@ -1935,12 +1935,10 @@ static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pStore) { if (!pStore || (taosArrayGetSize(pStore->tbUids) == 0)) { tsdbDebug("vgId:%d no need to update tbUids since empty uidStore", REPO_ID(pTsdb)); - tsdbUidStoreFree(pStore); return TSDB_CODE_SUCCESS; } if (tsdbUpdateTbUidListImpl(pTsdb, &pStore->suid, pStore->tbUids) != TSDB_CODE_SUCCESS) { - tsdbUidStoreFree(pStore); return TSDB_CODE_FAILED; } @@ -1951,15 +1949,11 @@ int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pStore) { if (tsdbUpdateTbUidListImpl(pTsdb, pTbSuid, pTbUids) != TSDB_CODE_SUCCESS) { taosHashCancelIterate(pStore->uidHash, pIter); - tsdbUidStoreFree(pStore); return TSDB_CODE_FAILED; } pIter = taosHashIterate(pStore->uidHash, pIter); } - - tsdbUidStoreFree(pStore); - return TSDB_CODE_SUCCESS; } @@ -1971,8 +1965,6 @@ static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) { STSRow *row = NULL; terrno = TSDB_CODE_SUCCESS; - // pMsg->length = htonl(pMsg->length); - // pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); if (tInitSubmitMsgIterEx(pMsg, &msgIter) < 0) return -1; while (true) { diff --git a/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c index ac3baf8c3af5eed608206ba187f0e5a795419a0c..74878e817f4df5d9fb239d9eb3d371eaa9d3dfbe 100644 --- a/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c @@ -55,12 +55,12 @@ static inline int tsdbSmaKeyCmpr(const void *arg1, int len1, const void *arg2, i } static int32_t tsdbOpenDBDb(TDB **ppDB, TENV *pEnv, const char *pFName) { - int ret; - FKeyComparator compFunc; + int ret; + tdb_cmpr_fn_t compFunc; // Create a database compFunc = tsdbSmaKeyCmpr; - ret = tdbDbOpen(pFName, TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, ppDB); + ret = tdbDbOpen(pFName, -1, -1, compFunc, pEnv, ppDB); return 0; } @@ -97,7 +97,7 @@ int32_t tsdbCloseDBF(SDBFile *pDBF) { int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, int32_t valLen, TXN *txn) { int32_t ret; - ret = tdbDbInsert(pDBF->pDB, pKey, keyLen, pVal, valLen, txn); + ret = tdbDbPut(pDBF->pDB, pKey, keyLen, pVal, valLen, txn); if (ret < 0) { tsdbError("Failed to create insert sma data into db, ret = %d", ret); return -1; diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index 82fa6b9ae5772276ad5623c6b37fc69b541ed600..9fb6aad47279ff0cb1b8645db2d68c008148a051 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -60,9 +60,10 @@ static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) { SSubmitBlk *pBlock = NULL; SSubmitBlkIter blkIter = {0}; STSRow *row = NULL; - TSKEY now = taosGetTimestamp(pTsdb->config.precision); - TSKEY minKey = now - tsTickPerDay[pTsdb->config.precision] * pTsdb->config.keep2; - TSKEY maxKey = now + tsTickPerDay[pTsdb->config.precision] * pTsdb->config.days; + STsdbCfg *pCfg = REPO_CFG(pTsdb); + TSKEY now = taosGetTimestamp(pCfg->precision); + TSKEY minKey = now - tsTickPerDay[pCfg->precision] * pCfg->keep2; + TSKEY maxKey = now + tsTickPerDay[pCfg->precision] * pCfg->days; terrno = TSDB_CODE_SUCCESS; pMsg->length = htonl(pMsg->length); diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 0e55113dc3f1600ac3ed6a041b43f9d934d5d440..8130a00e04f83f97d6f7618070e43af52a949f22 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -23,7 +23,6 @@ const SVnodeCfg vnodeCfgDefault = { .szCache = 256, .szBuf = 96 * 1024 * 1024, .isHeap = false, - .streamMode = 0, .isWeak = 0, .tsdbCfg = {.precision = TSDB_TIME_PRECISION_MILLI, .update = 0, @@ -56,7 +55,6 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { if (tjsonAddIntegerToObject(pJson, "szCache", pCfg->szCache) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "szBuf", pCfg->szBuf) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "isHeap", pCfg->isHeap) < 0) return -1; - if (tjsonAddIntegerToObject(pJson, "streamMode", pCfg->streamMode) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "isWeak", pCfg->isWeak) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "precision", pCfg->tsdbCfg.precision) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "update", pCfg->tsdbCfg.update) < 0) return -1; @@ -68,6 +66,28 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { if (tjsonAddIntegerToObject(pJson, "keep0", pCfg->tsdbCfg.keep0) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "keep1", pCfg->tsdbCfg.keep1) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "keep2", pCfg->tsdbCfg.keep2) < 0) return -1; +#ifdef TSDB_VNODE_SMA_DEBUG + if (pCfg->tsdbCfg.retentions[0].freq > 0) { + int32_t nRetention = 1; + if (pCfg->tsdbCfg.retentions[1].freq > 0) { + ++nRetention; + if (pCfg->tsdbCfg.retentions[2].freq > 0) { + ++nRetention; + } + } + SJson *pNodeRetentions = tjsonCreateArray(); + tjsonAddItemToObject(pJson, "retentions", pNodeRetentions); + for (int32_t i = 0; i < nRetention; ++i) { + SJson *pNodeRetention = tjsonCreateObject(); + const SRetention *pRetention = pCfg->tsdbCfg.retentions + i; + tjsonAddIntegerToObject(pNodeRetention, "freq", pRetention->freq); + tjsonAddIntegerToObject(pNodeRetention, "freqUnit", pRetention->freqUnit); + tjsonAddIntegerToObject(pNodeRetention, "keep", pRetention->keep); + tjsonAddIntegerToObject(pNodeRetention, "keepUnit", pRetention->keepUnit); + tjsonAddItemToArray(pNodeRetentions, pNodeRetention); + } + } +#endif if (tjsonAddIntegerToObject(pJson, "wal.vgId", pCfg->walCfg.vgId) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod) < 0) return -1; @@ -104,7 +124,6 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (tjsonGetNumberValue(pJson, "szCache", pCfg->szCache) < 0) return -1; if (tjsonGetNumberValue(pJson, "szBuf", pCfg->szBuf) < 0) return -1; if (tjsonGetNumberValue(pJson, "isHeap", pCfg->isHeap) < 0) return -1; - if (tjsonGetNumberValue(pJson, "streamMode", pCfg->streamMode) < 0) return -1; if (tjsonGetNumberValue(pJson, "isWeak", pCfg->isWeak) < 0) return -1; if (tjsonGetNumberValue(pJson, "precision", pCfg->tsdbCfg.precision) < 0) return -1; if (tjsonGetNumberValue(pJson, "update", pCfg->tsdbCfg.update) < 0) return -1; @@ -116,6 +135,20 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (tjsonGetNumberValue(pJson, "keep0", pCfg->tsdbCfg.keep0) < 0) return -1; if (tjsonGetNumberValue(pJson, "keep1", pCfg->tsdbCfg.keep1) < 0) return -1; if (tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2) < 0) return -1; +#ifdef TSDB_VNODE_SMA_DEBUG + SJson *pNodeRetentions = tjsonGetObjectItem(pJson, "retentions"); + int nRetention = tjsonGetArraySize(pNodeRetentions); + ASSERT(nRetention <= TSDB_RSMA_RETENTION_MAX); + + for (int32_t i = 0; i < nRetention; ++i) { + SJson *pNodeRetention = tjsonGetArrayItem(pNodeRetentions, i); + ASSERT(pNodeRetention != NULL); + tjsonGetNumberValue(pNodeRetention, "freq", (pCfg->tsdbCfg.retentions)[i].freq); + tjsonGetNumberValue(pNodeRetention, "freqUnit", (pCfg->tsdbCfg.retentions)[i].freqUnit); + tjsonGetNumberValue(pNodeRetention, "keep", (pCfg->tsdbCfg.retentions)[i].keep); + tjsonGetNumberValue(pNodeRetention, "keepUnit", (pCfg->tsdbCfg.retentions)[i].keepUnit); + } +#endif if (tjsonGetNumberValue(pJson, "wal.vgId", pCfg->walCfg.vgId) < 0) return -1; if (tjsonGetNumberValue(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod) < 0) return -1; if (tjsonGetNumberValue(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod) < 0) return -1; diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 1c0e65aa95a8a0aa543b101ef92f21444b2fef52..7026673231a4b07865d009215dd3826b99e3d119 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -42,13 +42,13 @@ int vnodeBegin(SVnode *pVnode) { // begin meta if (metaBegin(pVnode->pMeta) < 0) { - vError("vgId: %d failed to begin meta since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to begin meta since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } // begin tsdb if (tsdbBegin(pVnode->pTsdb) < 0) { - vError("vgId: %d failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } @@ -93,7 +93,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { // free info binary taosMemoryFree(data); - vInfo("vgId: %d vnode info is saved, fname: %s", pInfo->config.vgId, fname); + vInfo("vgId:%d vnode info is saved, fname: %s", pInfo->config.vgId, fname); return 0; @@ -115,7 +115,7 @@ int vnodeCommitInfo(const char *dir, const SVnodeInfo *pInfo) { return -1; } - vInfo("vgId: %d vnode info is committed", pInfo->config.vgId); + vInfo("vgId:%d vnode info is committed", pInfo->config.vgId); return 0; } @@ -190,7 +190,7 @@ int vnodeSyncCommit(SVnode *pVnode) { } int vnodeCommit(SVnode *pVnode) { - SVnodeInfo info; + SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN]; vInfo("vgId:%d start to commit, version: %" PRId64, TD_VID(pVnode), pVnode->state.applied); diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index ee64976df972e65a9af2865cf6fb2dc7d780acc0..3737bcfe3b3515a2d1eb18a49981c47163d91fc0 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -23,13 +23,13 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { // check config if (vnodeCheckCfg(pCfg) < 0) { - vError("vgId: %d failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno)); + vError("vgId:%d failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno)); return -1; } // create vnode env if (tfsMkdir(pTfs, path) < 0) { - vError("vgId: %d failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno)); + vError("vgId:%d failed to create vnode since: %s", pCfg->vgId, tstrerror(terrno)); return -1; } @@ -39,11 +39,11 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { info.state.applied = -1; if (vnodeSaveInfo(dir, &info) < 0 || vnodeCommitInfo(dir, &info) < 0) { - vError("vgId: %d failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno)); + vError("vgId:%d failed to save vnode config since %s", pCfg->vgId, tstrerror(terrno)); return -1; } - vInfo("vgId: %d vnode is created", pCfg->vgId); + vInfo("vgId:%d vnode is created", pCfg->vgId); return 0; } @@ -70,7 +70,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1); if (pVnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - vError("vgId: %d failed to open vnode since %s", info.config.vgId, tstrerror(terrno)); + vError("vgId:%d failed to open vnode since %s", info.config.vgId, tstrerror(terrno)); return NULL; } @@ -85,27 +85,44 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { // open buffer pool if (vnodeOpenBufPool(pVnode, pVnode->config.isHeap ? 0 : pVnode->config.szBuf / 3) < 0) { - vError("vgId: %d failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open meta if (metaOpen(pVnode, &pVnode->pMeta) < 0) { - vError("vgId: %d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open tsdb - if (tsdbOpen(pVnode, &pVnode->pTsdb) < 0) { - vError("vgId: %d failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); - goto _err; + if (tsdbIsRollup(pVnode)) { + if (tsdbOpen(pVnode, TSDB_TYPE_RSMA_L0) < 0) { + vError("vgId: %d failed to open vnode rsma0 since %s", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } + + if (tsdbOpen(pVnode, TSDB_TYPE_RSMA_L1) < 0) { + vError("vgId: %d failed to open vnode rsma1 since %s", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } + + if (tsdbOpen(pVnode, TSDB_TYPE_RSMA_L2) < 0) { + vError("vgId: %d failed to open vnode rsma2 since %s", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } + } else { + if (tsdbOpen(pVnode, TSDB_TYPE_TSDB) < 0) { + vError("vgId: %d failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); + goto _err; + } } // open wal sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR); 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)); + vError("vgId:%d failed to open vnode wal since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } @@ -113,25 +130,25 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_TQ_DIR); pVnode->pTq = tqOpen(tdir, pVnode, pVnode->pWal); if (pVnode->pTq == NULL) { - vError("vgId: %d failed to open vnode tq since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to open vnode tq since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open query if (vnodeQueryOpen(pVnode)) { - vError("vgId: %d failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // vnode begin if (vnodeBegin(pVnode) < 0) { - vError("vgId: %d failed to begin since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to begin since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } // open sync if (vnodeSyncOpen(pVnode, dir)) { - vError("vgId: %d failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } @@ -143,6 +160,8 @@ _err: if (pVnode->pWal) walClose(pVnode->pWal); if (pVnode->pTsdb) tsdbClose(pVnode->pTsdb); if (pVnode->pMeta) metaClose(pVnode->pMeta); + tsdbClose(VND_RSMA1(pVnode)); + tsdbClose(VND_RSMA2(pVnode)); tsem_destroy(&(pVnode->canCommit)); taosMemoryFree(pVnode); return NULL; @@ -155,7 +174,9 @@ void vnodeClose(SVnode *pVnode) { vnodeQueryClose(pVnode); walClose(pVnode->pWal); tqClose(pVnode->pTq); - tsdbClose(pVnode->pTsdb); + tsdbClose(VND_TSDB(pVnode)); + tsdbClose(VND_RSMA1(pVnode)); + tsdbClose(VND_RSMA2(pVnode)); metaClose(pVnode->pMeta); vnodeCloseBufPool(pVnode); // destroy handle diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 605185c9d940f7eb1d0a42f142433c9ff12103ba..7e80eacf8f8026f594998bda2a079c59d21f7145 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -147,4 +147,19 @@ void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) { if (vgId) { *vgId = TD_VID(pVnode); } +} + +// wrapper of tsdb read interface +tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, + void *pMemRef) { +#if 0 + return tsdbQueryCacheLastT(pVnode->pTsdb, pCond, groupList, qId, pMemRef); +#endif + return 0; +} +int32_t tsdbGetTableGroupFromIdList(SVnode *pVnode, SArray *pTableIdList, STableGroupInfo *pGroupInfo) { +#if 0 + return tsdbGetTableGroupFromIdListT(pVnode->pTsdb, pTableIdList, pGroupInfo); +#endif + return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 4a5be466983bbe564bf28a04a59a67bbe63c69be..4eeba06027f18e19b1bec9c79a9a26ac406d590c 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -17,10 +17,10 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, int len, SRpcMsg *pRsp); static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp); -static int vnodeProcessDropStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp); +static int vnodeProcessDropStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq, int len, SRpcMsg *pRsp); static int vnodeProcessAlterTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp); -static int vnodeProcessDropTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp); +static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); int vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs, int64_t *version) { @@ -52,7 +52,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg int len; int ret; - vTrace("vgId: %d start to process write request %s, version %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), + vTrace("vgId:%d start to process write request %s, version %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); pVnode->state.applied = version; @@ -61,9 +61,8 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); len = pMsg->contLen - sizeof(SMsgHead); - // todo: change the interface here if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, version) < 0) { - vError("vgId: %d failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno)); + vError("vgId:%d failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno)); return -1; } @@ -76,7 +75,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg if (vnodeProcessAlterStbReq(pVnode, pReq, len, pRsp) < 0) goto _err; break; case TDMT_VND_DROP_STB: - if (vnodeProcessDropStbReq(pVnode, pReq, len, pRsp) < 0) goto _err; + if (vnodeProcessDropStbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; break; case TDMT_VND_CREATE_TABLE: if (vnodeProcessCreateTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; @@ -85,7 +84,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg if (vnodeProcessAlterTbReq(pVnode, pReq, len, pRsp) < 0) goto _err; break; case TDMT_VND_DROP_TABLE: - if (vnodeProcessDropTbReq(pVnode, pReq, len, pRsp) < 0) goto _err; + if (vnodeProcessDropTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; break; case TDMT_VND_CREATE_SMA: { // timeRangeSMA if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { @@ -120,7 +119,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg break; } - vDebug("vgId: %d process %s request success, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); + vDebug("vgId:%d process %s request success, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); // commit if need if (vnodeShouldCommit(pVnode)) { @@ -135,15 +134,17 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg return 0; _err: - vDebug("vgId: %d process %s request failed since %s, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), + vDebug("vgId:%d process %s request failed since %s, version: %" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), tstrerror(terrno), version); return -1; } int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { vTrace("message in vnode query queue is processing"); +#if 0 SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode}; - +#endif + SReadHandle handle = {.meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode}; switch (pMsg->msgType) { case TDMT_VND_QUERY: return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg); @@ -300,13 +301,13 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, goto _err; } - // tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &vCreateTbReq); - if (metaCreateSTable(pVnode->pMeta, version, &req) < 0) { pRsp->code = terrno; goto _err; } + tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &req); + tCoderClear(&coder); return 0; @@ -323,6 +324,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq, SVCreateTbBatchRsp rsp = {0}; SVCreateTbRsp cRsp = {0}; char tbName[TSDB_TABLE_FNAME_LEN]; + STbUidStore *pStore = NULL; pRsp->msgType = TDMT_VND_CREATE_TABLE_RSP; pRsp->code = TSDB_CODE_SUCCESS; @@ -361,6 +363,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq, cRsp.code = terrno; } else { cRsp.code = TSDB_CODE_SUCCESS; + tsdbFetchTbUidList(pVnode->pTsdb, &pStore, pCreateReq->ctb.suid, pCreateReq->uid); } taosArrayPush(rsp.pArray, &cRsp); @@ -368,6 +371,9 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq, tCoderClear(&coder); + tsdbUpdateTbUidList(pVnode->pTsdb, pStore); + tsdbUidStoreFree(pStore); + // prepare rsp int32_t ret = 0; tEncodeSize(tEncodeSVCreateTbBatchRsp, &rsp, pRsp->contLen, ret); @@ -403,9 +409,32 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpc return 0; } -static int vnodeProcessDropStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) { - // TODO - // ASSERT(0); +static int vnodeProcessDropStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { + SVDropStbReq req = {0}; + int rcode = TSDB_CODE_SUCCESS; + SCoder coder = {0}; + + pRsp->msgType = TDMT_VND_CREATE_STB_RSP; + pRsp->pCont = NULL; + pRsp->contLen = 0; + + // decode request + tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER); + if (tDecodeSVDropStbReq(&coder, &req) < 0) { + rcode = TSDB_CODE_INVALID_MSG; + goto _exit; + } + + // process request + // if (metaDropSTable(pVnode->pMeta, version, &req) < 0) { + // rcode = terrno; + // goto _exit; + // } + + // return rsp +_exit: + pRsp->code = rcode; + tCoderClear(&coder); return 0; } @@ -415,9 +444,15 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcM return 0; } -static int vnodeProcessDropTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) { - // TODO - ASSERT(0); +static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { + SVDropTbReq req = {0}; + SVDropTbReq rsp = {0}; + + // decode req + + // process req + + // return rsp return 0; } @@ -426,7 +461,7 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in SSubmitRsp rsp = {0}; pRsp->code = 0; - + tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, pReq, STREAM_DATA_TYPE_SUBMIT_BLOCK); // handle the request if (tsdbInsertData(pVnode->pTsdb, version, pSubmitReq, &rsp) < 0) { pRsp->code = terrno; @@ -435,7 +470,7 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in // pRsp->msgType = TDMT_VND_SUBMIT_RSP; // vnodeProcessSubmitReq(pVnode, ptr, pRsp); - // tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, ptr, STREAM_DATA_TYPE_SUBMIT_BLOCK); + // tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, pReq, STREAM_DATA_TYPE_SUBMIT_BLOCK); // encode the response (TODO) pRsp->pCont = rpcMallocCont(sizeof(SSubmitRsp)); diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 272c370ca3943c65d6163e9d1a169d19c9b80a82..6f1f34a57b2fe56f45be909ff6a42b19726a79f6 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -17,6 +17,7 @@ #include "query.h" #include "tname.h" #include "catalogInt.h" +#include "systable.h" int32_t ctgActUpdateVg(SCtgMetaAction *action); int32_t ctgActUpdateTbl(SCtgMetaAction *action); diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 1045acbe939417ed94a1a13f15c561797702146c..cff0087d6ccc7dbab5f690ffe1cecc27ec4813b7 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -97,24 +97,22 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { SCreateDbReq createReq = {0}; strcpy(createReq.db, "1.db1"); createReq.numOfVgroups = 2; - createReq.cacheBlockSize = 16; - createReq.totalBlocks = 10; + createReq.buffer = -1; + createReq.pageSize = -1; + createReq.pages = -1; createReq.daysPerFile = 10; createReq.daysToKeep0 = 3650; createReq.daysToKeep1 = 3650; createReq.daysToKeep2 = 3650; createReq.minRows = 100; createReq.maxRows = 4096; - createReq.commitTime = 3600; createReq.fsyncPeriod = 3000; createReq.walLevel = 1; createReq.precision = 0; createReq.compression = 2; createReq.replications = 1; createReq.strict = 1; - createReq.update = 0; createReq.cacheLastRow = 0; - createReq.ttl = 1; createReq.ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq); @@ -254,7 +252,6 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) { rspMsg->numOfColumns = ctgTestColNum; rspMsg->precision = 1 + 1; rspMsg->tableType = TSDB_SUPER_TABLE; - rspMsg->update = 1 + 1; rspMsg->sversion = ctgTestSVersion + 1; rspMsg->tversion = ctgTestTVersion + 1; rspMsg->suid = ctgTestSuid + 1; @@ -333,7 +330,6 @@ void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg * metaRsp.numOfColumns = ctgTestColNum; metaRsp.precision = 1; metaRsp.tableType = TSDB_NORMAL_TABLE; - metaRsp.update = 1; metaRsp.sversion = ctgTestSVersion; metaRsp.tversion = ctgTestTVersion; metaRsp.suid = 0; @@ -379,7 +375,6 @@ void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg metaRsp.numOfColumns = ctgTestColNum; metaRsp.precision = 1; metaRsp.tableType = TSDB_CHILD_TABLE; - metaRsp.update = 1; metaRsp.sversion = ctgTestSVersion; metaRsp.tversion = ctgTestTVersion; metaRsp.suid = 0x0000000000000002; @@ -426,7 +421,6 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg metaRsp.numOfColumns = ctgTestColNum; metaRsp.precision = 1; metaRsp.tableType = TSDB_SUPER_TABLE; - metaRsp.update = 1; metaRsp.sversion = ctgTestSVersion; metaRsp.tversion = ctgTestTVersion; metaRsp.suid = ctgTestSuid; @@ -475,7 +469,6 @@ void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRp metaRsp.numOfColumns = ctgTestColNum; metaRsp.precision = 1; metaRsp.tableType = TSDB_SUPER_TABLE; - metaRsp.update = 1; metaRsp.sversion = ctgTestSVersion; metaRsp.tversion = ctgTestTVersion; metaRsp.suid = ctgTestSuid + idx; diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index 452804ac91c8a92527b3fc596d8aa631ca184c33..775dee28a4e2528cbf8509cb5955d567b658a5dd 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -56,10 +56,9 @@ extern "C" { #define EXPLAIN_ROWS_FORMAT "rows=%" PRIu64 #define EXPLAIN_COLUMNS_FORMAT "columns=%d" #define EXPLAIN_WIDTH_FORMAT "width=%d" +#define EXPLAIN_TABLE_SCAN_FORMAT "order=[asc|%d desc|%d]" #define EXPLAIN_GROUPS_FORMAT "groups=%d" #define EXPLAIN_WIDTH_FORMAT "width=%d" -#define EXPLAIN_LOOPS_FORMAT "loops=%d" -#define EXPLAIN_REVERSE_FORMAT "reverse=%d" #define EXPLAIN_FUNCTIONS_FORMAT "functions=%d" #define EXPLAIN_EXECINFO_FORMAT "cost=%" PRIu64 "..%" PRIu64 " rows=%" PRIu64 diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index d17a5a59a444776c8465dac0487c6d73a2a29506..2aae4303eb3ada4bfc39bde55bfd2e4e3084e960 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -379,6 +379,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pTblScanNode->scan.node.pOutputDataBlockDesc->totalRowSize); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); + EXPLAIN_ROW_APPEND(EXPLAIN_TABLE_SCAN_FORMAT, pTblScanNode->scanSeq[0], pTblScanNode->scanSeq[1]); EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 7a6432a06cadf7195448f730c3b7dd66e285a0f5..ee8cdc6b1bbeb6d87edad5c98a69882961fe85df 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -375,6 +375,7 @@ typedef struct SStreamBlockScanInfo { uint64_t numOfExec; // execution times void* readerHandle; // stream block reader handle SArray* pColMatchInfo; // + SNode* pCondition; } SStreamBlockScanInfo; typedef struct SSysTableScanInfo { @@ -640,6 +641,7 @@ int32_t getTableScanOrder(SOperatorInfo* pOperator); void doSetOperatorCompleted(SOperatorInfo* pOperator); void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock); SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset); +void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols); SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); @@ -671,7 +673,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo); SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, - SArray* pTableIdList, SExecTaskInfo* pTaskInfo); + SArray* pTableIdList, SExecTaskInfo* pTaskInfo, SNode* pConditions); SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock, int32_t fillType, char* fillVal, @@ -694,7 +696,7 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim SExprInfo* pExpr, int32_t numOfOutput); #endif -void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, +int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList); void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order, bool createDummyCol); diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index a5ce01dba28c07b0354d6e69c595048da511cd99..a217701471c07b1b2b86b25de7bc89ac9f400a45 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -31,6 +31,7 @@ typedef struct SDataDispatchBuf { typedef struct SDataCacheEntry { int32_t dataLen; int32_t numOfRows; + int32_t numOfCols; int8_t compressed; char data[]; } SDataCacheEntry; @@ -76,6 +77,7 @@ static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputDat SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData; pEntry->compressed = (int8_t)needCompress(pInput->pData, numOfCols); pEntry->numOfRows = pInput->pData->info.rows; + pEntry->numOfCols = pInput->pData->info.numOfCols; pEntry->dataLen = 0; pBuf->useSize = sizeof(SRetrieveTableRsp); @@ -169,6 +171,7 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDispatcher->nextOutput.pData); memcpy(pOutput->pData, pEntry->data, pEntry->dataLen); pOutput->numOfRows = pEntry->numOfRows; + pOutput->numOfCols = pEntry->numOfCols; pOutput->compressed = pEntry->compressed; taosMemoryFreeClear(pDispatcher->nextOutput.pData); // todo persistent pOutput->bufStatus = updateStatus(pDispatcher); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index cee84c65d0d3a5f6ee90faf69f07b13ed6bf80c1..d8e69c4b707a8a3c2c08e217689799d75296abf8 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -227,8 +227,8 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) { } SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn, - __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_encode_fn_t encode, - __optr_decode_fn_t decode, __optr_get_explain_fn_t explain) { + __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_encode_fn_t encode, + __optr_decode_fn_t decode, __optr_get_explain_fn_t explain) { SOperatorFpSet fpSet = { ._openFn = openFn, .getNextFn = nextFn, @@ -441,8 +441,8 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, * +----------+---------------+ */ static SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, int64_t uid, - char* pData, int16_t bytes, bool masterscan, uint64_t groupId, - SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup) { + char* pData, int16_t bytes, bool masterscan, uint64_t groupId, + SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup) { SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId); SResultRowPosition* p1 = @@ -463,9 +463,9 @@ static SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowI } } - // 1. close current opened time window + // 1. close current opened time window if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId && - pResult->offset != pResultRowInfo->cur.offset))) { + pResult->offset != pResultRowInfo->cur.offset))) { // todo extract function SResultRowPosition pos = pResultRowInfo->cur; SFilePage* pPage = getBufPage(pResultBuf, pos.pageId); @@ -482,7 +482,8 @@ static SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowI // add a new result set for a new group SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset}; - taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, sizeof(SResultRowPosition)); + taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, + sizeof(SResultRowPosition)); } // 2. set the new time window to be the new active time window @@ -646,7 +647,7 @@ static int32_t setResultOutputBufByKey_rv(SResultRowInfo* pResultRowInfo, int64_ SExecTaskInfo* pTaskInfo) { assert(win->skey <= win->ekey); SResultRow* pResultRow = doSetResultOutBufByKey(pAggSup->pResultBuf, pResultRowInfo, id, (char*)&win->skey, - TSDB_KEYSIZE, masterscan, tableGroupId, pTaskInfo, true, pAggSup); + TSDB_KEYSIZE, masterscan, tableGroupId, pTaskInfo, true, pAggSup); if (pResultRow == NULL) { *pResult = NULL; @@ -1034,8 +1035,8 @@ void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlo } } -static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, - int32_t paramIndex, int32_t numOfRows) { +static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex, + int32_t numOfRows) { SColumnInfoData* pColInfo = NULL; if (pInput->pData[paramIndex] == NULL) { pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData)); @@ -1066,9 +1067,9 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc colDataAppendDouble(pColInfo, i, &v); } } else if (type == TSDB_DATA_TYPE_VARCHAR) { - char *tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE); + char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE); STR_WITH_SIZE_TO_VARSTR(tmp, pFuncParam->param.pz, pFuncParam->param.nLen); - for(int32_t i = 0; i < numOfRows; ++i) { + for (int32_t i = 0; i < numOfRows; ++i) { colDataAppend(pColInfo, i, tmp, false); } } @@ -1081,9 +1082,9 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt int32_t code = TSDB_CODE_SUCCESS; for (int32_t i = 0; i < pOperator->numOfOutput; ++i) { - pCtx[i].order = order; - pCtx[i].size = pBlock->info.rows; - pCtx[i].pSrcBlock = pBlock; + pCtx[i].order = order; + pCtx[i].size = pBlock->info.rows; + pCtx[i].pSrcBlock = pBlock; pCtx[i].currentStage = MAIN_SCAN; SInputColumnInfoData* pInput = &pCtx[i].input; @@ -1177,7 +1178,7 @@ static void setPseudoOutputColInfo(SSDataBlock* pResult, SqlFunctionCtx* pCtx, S } } -void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, +int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList) { setPseudoOutputColInfo(pResult, pCtx, pPseudoList); pResult->info.groupId = pSrcBlock->info.groupId; @@ -1217,7 +1218,7 @@ void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* taosArrayPush(pBlockList, &pSrcBlock); SColumnInfoData* pResColData = taosArrayGet(pResult->pDataBlock, outputSlotId); - SColumnInfoData idata = {.info = pResColData->info}; + SColumnInfoData idata = {.info = pResColData->info, .hasNull = true}; SScalarParam dest = {.columnData = &idata}; scalarCalculate(pExpr[k].pExpr->_optrRoot.pRootNode, pBlockList, &dest); @@ -1254,10 +1255,14 @@ void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* taosArrayPush(pBlockList, &pSrcBlock); SColumnInfoData* pResColData = taosArrayGet(pResult->pDataBlock, outputSlotId); - SColumnInfoData idata = {.info = pResColData->info}; + SColumnInfoData idata = {.info = pResColData->info, .hasNull = true}; SScalarParam dest = {.columnData = &idata}; - scalarCalculate((SNode*)pExpr[k].pExpr->_function.pFunctNode, pBlockList, &dest); + int32_t code = scalarCalculate((SNode*)pExpr[k].pExpr->_function.pFunctNode, pBlockList, &dest); + if (code != TSDB_CODE_SUCCESS) { + taosArrayDestroy(pBlockList); + return code; + } int32_t startOffset = createNewColModel ? 0 : pResult->info.rows; colDataMergeCol(pResColData, startOffset, &idata, dest.numOfRows); @@ -1273,6 +1278,8 @@ void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* if (!createNewColModel) { pResult->info.rows += numOfRows; } + + return TSDB_CODE_SUCCESS; } void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, SArray* pDataBlock, TSKEY prevTs, @@ -1421,7 +1428,7 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc if (!done) { // it is not interpolated, now start to generated the interpolated value int32_t startRowIndex = startPos; bool interp = setTimeWindowInterpolationStartTs(pOperatorInfo, pCtx, startRowIndex, pBlock->info.rows, - pBlock->pDataBlock, tsCols, win); + pBlock->pDataBlock, tsCols, win); if (interp) { setResultRowInterpo(pResult, RESULT_ROW_START_INTERP); } @@ -1482,8 +1489,8 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe SResultRow* pResult = NULL; int32_t ret = setResultOutputBufByKey_rv(pResultRowInfo, pSDataBlock->info.uid, &win, masterScan, &pResult, - tableGroupId, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, - &pInfo->aggSup, pTaskInfo); + tableGroupId, pInfo->binfo.pCtx, numOfOutput, pInfo->binfo.rowCellInfoOffset, + &pInfo->aggSup, pTaskInfo); if (ret != TSDB_CODE_SUCCESS || pResult == NULL) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -1491,8 +1498,8 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) { SResKeyPos* pos = taosMemoryMalloc(sizeof(SResKeyPos) + sizeof(uint64_t)); pos->groupId = tableGroupId; - pos->pos = (SResultRowPosition) {.pageId = pResult->pageId, .offset = pResult->offset}; - *(int64_t*) pos->key = pResult->win.skey; + pos->pos = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; + *(int64_t*)pos->key = pResult->win.skey; taosArrayPush(pUpdated, &pos); } @@ -1569,8 +1576,8 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) { SResKeyPos* pos = taosMemoryMalloc(sizeof(SResKeyPos) + sizeof(uint64_t)); pos->groupId = tableGroupId; - pos->pos = (SResultRowPosition) {.pageId = pResult->pageId, .offset = pResult->offset}; - *(int64_t*) pos->key = pResult->win.skey; + pos->pos = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; + *(int64_t*)pos->key = pResult->win.skey; taosArrayPush(pUpdated, &pos); } @@ -1706,7 +1713,7 @@ int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* SqlFunctionCtx* pCtx = binfo->pCtx; SResultRow* pResultRow = doSetResultOutBufByKey(pBuf, pResultRowInfo, groupId, (char*)pData, bytes, true, groupId, - pTaskInfo, false, pAggSup); + pTaskInfo, false, pAggSup); assert(pResultRow != NULL); setResultRowKey(pResultRow, pData, type); @@ -1812,7 +1819,10 @@ void setBlockStatisInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) { int32_t slotId = pFuncParam->pCol->slotId; - pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId]; + pInput->pColumnDataAgg[j] = pBlock->pBlockAgg[slotId]; + if (pInput->pColumnDataAgg[j] == NULL) { + pInput->colDataAggIsSet = false; + } // Here we set the column info data since the data type for each column data is required, but // the data in the corresponding SColumnInfoData will not be used. @@ -1890,14 +1900,21 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, pCtx->functionId = -1; pCtx->curBufPage = -1; - pCtx->pExpr = pExpr; + pCtx->pExpr = pExpr; if (pExpr->pExpr->nodeType == QUERY_NODE_FUNCTION) { SFuncExecEnv env = {0}; pCtx->functionId = pExpr->pExpr->_function.pFunctNode->funcId; if (fmIsAggFunc(pCtx->functionId) || fmIsNonstandardSQLFunc(pCtx->functionId)) { - fmGetFuncExecFuncs(pCtx->functionId, &pCtx->fpSet); + bool isUdaf = fmIsUserDefinedFunc(pCtx->functionId); + if (!isUdaf) { + fmGetFuncExecFuncs(pCtx->functionId, &pCtx->fpSet); + } else { + char* udfName = pExpr->pExpr->_function.pFunctNode->functionName; + strncpy(pCtx->udfName, udfName, strlen(udfName)); + fmGetUdafExecFuncs(pCtx->functionId, &pCtx->fpSet); + } pCtx->fpSet.getEnv(pExpr->pExpr->_function.pFunctNode, &env); } else { fmGetScalarFuncExecFuncs(pCtx->functionId, &pCtx->sfp); @@ -1919,9 +1936,9 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, pCtx->pTsOutput = NULL; pCtx->resDataInfo.bytes = pFunct->resSchema.bytes; pCtx->resDataInfo.type = pFunct->resSchema.type; - pCtx->order = TSDB_ORDER_ASC; + pCtx->order = TSDB_ORDER_ASC; pCtx->start.key = INT64_MIN; - pCtx->end.key = INT64_MIN; + pCtx->end.key = INT64_MIN; pCtx->numOfParams = pExpr->base.numOfParams; pCtx->param = pFunct->pParam; @@ -2712,7 +2729,7 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t int64_t tid = 0; int64_t groupId = 0; SResultRow* pRow = doSetResultOutBufByKey(pSup->pResultBuf, pResultRowInfo, tid, (char*)&tid, sizeof(tid), true, - groupId, pTaskInfo, false, pSup); + groupId, pTaskInfo, false, pSup); for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { struct SResultRowEntryInfo* pEntry = getResultCell(pRow, i, rowCellInfoOffset); @@ -2859,24 +2876,24 @@ void finalizeUpdatedResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbased size_t num = taosArrayGetSize(pUpdateList); for (int32_t i = 0; i < num; ++i) { - SResKeyPos * pPos = taosArrayGetP(pUpdateList, i); + SResKeyPos* pPos = taosArrayGetP(pUpdateList, i); SFilePage* bufPage = getBufPage(pBuf, pPos->pos.pageId); SResultRow* pRow = (SResultRow*)((char*)bufPage + pPos->pos.offset); -// + // for (int32_t j = 0; j < numOfOutput; ++j) { pCtx[j].resultInfo = getResultCell(pRow, j, rowCellInfoOffset); -// + // struct SResultRowEntryInfo* pResInfo = pCtx[j].resultInfo; -// if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) { -// continue; -// } -// -// if (pCtx[j].fpSet.process) { // TODO set the dummy function. -//// pCtx[j].fpSet.finalize(&pCtx[j]); -// pResInfo->initialized = true; -// } -// + // if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) { + // continue; + // } + // + // if (pCtx[j].fpSet.process) { // TODO set the dummy function. + //// pCtx[j].fpSet.finalize(&pCtx[j]); + // pResInfo->initialized = true; + // } + // if (pRow->numOfRows < pResInfo->numOfRes) { pRow->numOfRows = pResInfo->numOfRes; } @@ -2998,9 +3015,8 @@ void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, u SqlFunctionCtx* pCtx = pAggInfo->binfo.pCtx; int32_t* rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset; - SResultRow* pResultRow = - doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, uid, (char*)&groupId, sizeof(groupId), - true, groupId, pTaskInfo, false, &pAggInfo->aggSup); + SResultRow* pResultRow = doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, uid, (char*)&groupId, + sizeof(groupId), true, groupId, pTaskInfo, false, &pAggInfo->aggSup); assert(pResultRow != NULL); /* @@ -3098,8 +3114,8 @@ int32_t doCopyToSDataBlock(SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbased } for (int32_t i = start; (i < numOfRows) && (i >= 0); i += step) { - SResKeyPos *pPos = taosArrayGetP(pGroupResInfo->pRows, i); - SFilePage* page = getBufPage(pBuf, pPos->pos.pageId); + SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i); + SFilePage* page = getBufPage(pBuf, pPos->pos.pageId); SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset); if (pRow->numOfRows == 0) { @@ -3661,6 +3677,7 @@ int32_t loadRemoteDataCallback(void* param, const SDataBuf* pMsg, int32_t code) SRetrieveTableRsp* pRsp = pSourceDataInfo->pRsp; pRsp->numOfRows = htonl(pRsp->numOfRows); pRsp->compLen = htonl(pRsp->compLen); + pRsp->numOfCols = htonl(pRsp->numOfCols); pRsp->useconds = htobe64(pRsp->useconds); } else { pSourceDataInfo->code = code; @@ -3739,12 +3756,12 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf } // NOTE: sources columns are more than the destination SSDatablock columns. -static void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols) { +void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols) { size_t numOfSrcCols = taosArrayGetSize(pCols); ASSERT(numOfSrcCols >= pBlock->info.numOfCols); int32_t i = 0, j = 0; - while(i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) { + while (i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) { SColumnInfoData* p = taosArrayGet(pCols, i); SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, j); if (!pmInfo->output) { @@ -3770,10 +3787,10 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI blockDataEnsureCapacity(pRes, numOfRows); if (pColList == NULL) { // data from other sources - int32_t dataLen = *(int32_t*) pData; + int32_t dataLen = *(int32_t*)pData; pData += sizeof(int32_t); - pRes->info.groupId = *(uint64_t*) pData; + pRes->info.groupId = *(uint64_t*)pData; pData += sizeof(uint64_t); int32_t* colLen = (int32_t*)pData; @@ -3803,8 +3820,8 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI memcpy(pColInfoData->pData, pStart, colLen[i]); } - //TODO setting this flag to true temporarily so aggregate function on stable will - //examine NULL value for non-primary key column + // TODO setting this flag to true temporarily so aggregate function on stable will + // examine NULL value for non-primary key column pColInfoData->hasNull = true; pStart += colLen[i]; } @@ -3840,11 +3857,11 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI blockDataEnsureCapacity(&block, numOfRows); - int32_t dataLen = *(int32_t*) pStart; - uint64_t groupId = *(uint64_t*) (pStart + sizeof(int32_t)); + int32_t dataLen = *(int32_t*)pStart; + uint64_t groupId = *(uint64_t*)(pStart + sizeof(int32_t)); pStart += sizeof(int32_t) + sizeof(uint64_t); - int32_t* colLen = (int32_t*) (pStart); + int32_t* colLen = (int32_t*)(pStart); pStart += sizeof(int32_t) * numOfCols; for (int32_t i = 0; i < numOfCols; ++i) { @@ -3870,7 +3887,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI } // data from mnode - relocateColumnData(pRes, pColList, block.pDataBlock); + relocateColumnData(pRes, pColList, block.pDataBlock); } pRes->info.rows = numOfRows; @@ -3944,7 +3961,7 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SEx SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; code = setSDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, - pTableRsp->compLen, pOperator->numOfOutput, startTs, &pDataInfo->totalRows, NULL); + pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); if (code != 0) { goto _error; } @@ -4079,7 +4096,7 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo* pOperator) { SRetrieveTableRsp* pTableRsp = pDataInfo->pRsp; int32_t code = setSDataBlockFromFetchRsp(pExchangeInfo->pResult, pLoadInfo, pTableRsp->numOfRows, pTableRsp->data, - pTableRsp->compLen, pOperator->numOfOutput, startTs, &pDataInfo->totalRows, NULL); + pTableRsp->compLen, pTableRsp->numOfCols, startTs, &pDataInfo->totalRows, NULL); if (pRsp->completed == 1) { qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, rowsOfSource:%" PRIu64 @@ -4219,8 +4236,8 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock pOperator->numOfOutput = pBlock->info.numOfCols; pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, destroyExchangeOperatorInfo, - NULL, NULL, NULL); + pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, + destroyExchangeOperatorInfo, NULL, NULL, NULL); #if 1 { // todo refactor @@ -4709,8 +4726,8 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSort, NULL, NULL, destroyOrderOperatorInfo, - NULL, NULL, NULL); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, NULL); int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -4764,8 +4781,12 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { // there is an scalar expression that needs to be calculated before apply the group aggregation. if (pAggInfo->pScalarExprInfo != NULL) { - projectApplyFunctions(pAggInfo->pScalarExprInfo, pBlock, pBlock, pAggInfo->pScalarCtx, pAggInfo->numOfScalarExpr, + int32_t code = projectApplyFunctions(pAggInfo->pScalarExprInfo, pBlock, pBlock, pAggInfo->pScalarCtx, pAggInfo->numOfScalarExpr, NULL); + if (code != TSDB_CODE_SUCCESS) { + pTaskInfo->code = code; + longjmp(pTaskInfo->env, pTaskInfo->code); + } } // the pDataBlock are always the same one, no need to call this again @@ -4926,8 +4947,8 @@ bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter* pSup, SOptrBasi initResultRow(resultRow); prepareResultListBuffer(&pInfo->resultRowInfo, pOperator->pTaskInfo->env); // pInfo->resultRowInfo.cur = pInfo->resultRowInfo.size; -// pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = -// (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset}; + // pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = + // (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset}; pInfo->resultRowInfo.cur = (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset}; } @@ -4939,13 +4960,13 @@ bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter* pSup, SOptrBasi enum { PROJECT_RETRIEVE_CONTINUE = 0x1, - PROJECT_RETRIEVE_DONE = 0x2, + PROJECT_RETRIEVE_DONE = 0x2, }; static int32_t handleLimitOffset(SOperatorInfo* pOperator, SSDataBlock* pBlock) { SProjectOperatorInfo* pProjectInfo = pOperator->info; SOptrBasicInfo* pInfo = &pProjectInfo->binfo; - SSDataBlock* pRes = pInfo->pRes; + SSDataBlock* pRes = pInfo->pRes; if (pProjectInfo->curSOffset > 0) { if (pProjectInfo->groupId == 0) { // it is the first group @@ -5005,11 +5026,13 @@ static int32_t handleLimitOffset(SOperatorInfo* pOperator, SSDataBlock* pBlock) return PROJECT_RETRIEVE_DONE; } + // todo optimize performance // If there are slimit/soffset value exists, multi-round result can not be packed into one group, since the // they may not belong to the same group the limit/offset value is not valid in this case. - if (pRes->info.rows >= pOperator->resultInfo.threshold || pProjectInfo->slimit.offset != -1 || pProjectInfo->slimit.limit != -1) { + if (pRes->info.rows >= pOperator->resultInfo.threshold || pProjectInfo->slimit.offset != -1 || + pProjectInfo->slimit.limit != -1) { return PROJECT_RETRIEVE_DONE; - } else { // not full enough, continue to accumulate the output data in the buffer. + } else { // not full enough, continue to accumulate the output data in the buffer. return PROJECT_RETRIEVE_CONTINUE; } } @@ -5093,7 +5116,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) int32_t status = handleLimitOffset(pOperator, pBlock); if (status == PROJECT_RETRIEVE_CONTINUE) { continue; - } else if (status == PROJECT_RETRIEVE_DONE) { + } else if (status == PROJECT_RETRIEVE_DONE) { break; } } @@ -5283,7 +5306,7 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); // finalizeQueryResult(pSliceInfo->binfo.pCtx, pOperator->numOfOutput); -// initGroupedResultInfo(&pSliceInfo->groupResInfo, &pSliceInfo->binfo.resultRowInfo); + // initGroupedResultInfo(&pSliceInfo->groupResInfo, &pSliceInfo->binfo.resultRowInfo); // doBuildResultDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pSliceInfo->pRes); if (pSliceInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pSliceInfo->groupResInfo)) { @@ -5334,7 +5357,7 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset); -// initGroupedResultInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo); + // initGroupedResultInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo); OPTR_SET_OPENED(pOperator); blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); @@ -5368,7 +5391,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI pRowSup->numOfRows = 0; for (int32_t j = 0; j < pBlock->info.rows; ++j) { - if (colDataIsNull(pStateColInfoData, pBlock->info.rows, j, pBlock->pBlockAgg)) { + if (colDataIsNull(pStateColInfoData, pBlock->info.rows, j, pBlock->pBlockAgg[pInfo->colIndex])) { continue; } @@ -5676,8 +5699,8 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput); pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t)); pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK); -// pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); -// pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell)); + // pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); + // pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell)); if (pAggSup->keyBuf == NULL /*|| pAggSup->pResultRowArrayList == NULL || pAggSup->pResultRowListSet == NULL*/ || pAggSup->pResultRowHashTable == NULL) { @@ -5695,8 +5718,8 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n static void cleanupAggSup(SAggSupporter* pAggSup) { taosMemoryFreeClear(pAggSup->keyBuf); taosHashCleanup(pAggSup->pResultRowHashTable); -// taosHashCleanup(pAggSup->pResultRowListSet); -// taosArrayDestroy(pAggSup->pResultRowArrayList); + // taosHashCleanup(pAggSup->pResultRowListSet); + // taosArrayDestroy(pAggSup->pResultRowArrayList); destroyDiskbasedBuf(pAggSup->pResultBuf); } @@ -5707,7 +5730,7 @@ int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInf doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, keyBufSize, pkey); - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { pBasicInfo->pCtx[i].pBuf = pAggSup->pResultBuf; } @@ -5724,6 +5747,10 @@ void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows) { } static STableQueryInfo* initTableQueryInfo(const STableGroupInfo* pTableGroupInfo) { + if (pTableGroupInfo->numOfTables == 0) { + return NULL; + } + STableQueryInfo* pTableQueryInfo = taosMemoryCalloc(pTableGroupInfo->numOfTables, sizeof(STableQueryInfo)); if (pTableQueryInfo == NULL) { return NULL; @@ -5749,7 +5776,8 @@ static STableQueryInfo* initTableQueryInfo(const STableGroupInfo* pTableGroupInf SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo, - int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { + int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, + const STableGroupInfo* pTableGroupInfo) { SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -5763,7 +5791,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, pResultBlock, keyBufSize, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); - if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { + if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -5918,8 +5946,8 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p pOperator->pExpr = pExprInfo; pOperator->numOfOutput = num; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL, destroyProjectOperatorInfo, - NULL, NULL, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL, + destroyProjectOperatorInfo, NULL, NULL, NULL); pOperator->pTaskInfo = pTaskInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); @@ -5944,12 +5972,12 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* goto _error; } - pInfo->order = TSDB_ORDER_ASC; - pInfo->interval = *pInterval; -// pInfo->execModel = OPTR_EXEC_MODEL_STREAM; - pInfo->execModel = pTaskInfo->execModel; - pInfo->win = pTaskInfo->window; - pInfo->twAggSup = *pTwAggSupp; + pInfo->order = TSDB_ORDER_ASC; + pInfo->interval = *pInterval; + // pInfo->execModel = OPTR_EXEC_MODEL_STREAM; + pInfo->execModel = pTaskInfo->execModel; + pInfo->win = pTaskInfo->window; + pInfo->twAggSup = *pTwAggSupp; pInfo->primaryTsIndex = primaryTsSlotId; int32_t numOfRows = 4096; @@ -5976,8 +6004,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, doStreamIntervalAgg, NULL, destroyIntervalOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, doStreamIntervalAgg, NULL, + destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -5996,18 +6024,19 @@ _error: SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlotId, - STimeWindowAggSupp *pTwAggSupp, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { + STimeWindowAggSupp* pTwAggSupp, const STableGroupInfo* pTableGroupInfo, + SExecTaskInfo* pTaskInfo) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->order = TSDB_ORDER_ASC; - pInfo->interval = *pInterval; - pInfo->execModel = OPTR_EXEC_MODEL_STREAM; - pInfo->win = pTaskInfo->window; - pInfo->twAggSup = *pTwAggSupp; + pInfo->order = TSDB_ORDER_ASC; + pInfo->interval = *pInterval; + pInfo->execModel = OPTR_EXEC_MODEL_STREAM; + pInfo->win = pTaskInfo->window; + pInfo->twAggSup = *pTwAggSupp; pInfo->primaryTsIndex = primaryTsSlotId; int32_t numOfRows = 4096; @@ -6034,8 +6063,8 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExpr pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doStreamIntervalAgg, doStreamIntervalAgg, NULL, destroyIntervalOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doStreamIntervalAgg, doStreamIntervalAgg, NULL, + destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -6044,13 +6073,12 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExpr return pOperator; - _error: +_error: destroyIntervalOperatorInfo(pInfo, numOfCols); taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; - } SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, @@ -6114,8 +6142,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf pOperator->pTaskInfo = pTaskInfo; pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStateWindowAgg, NULL, NULL, destroyStateWindowOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStateWindowAgg, NULL, NULL, + destroyStateWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -6160,8 +6188,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, NULL, destroySWindowOperatorInfo, - aggEncodeResultRow, aggDecodeResultRow, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, NULL, + destroySWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); @@ -6249,8 +6277,8 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExp pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroySFillOperatorInfo, - NULL, NULL, NULL); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroySFillOperatorInfo, NULL, NULL, NULL); pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -6261,7 +6289,6 @@ _error: return NULL; } - static int32_t getColumnIndexInSource(SQueriedTableInfo* pTableInfo, SExprBasicInfo* pExpr, SColumnInfo* pTagCols) { int32_t j = 0; @@ -6459,11 +6486,11 @@ static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableSc static SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode) { SInterval interval = { - .interval = pTableScanNode->interval, - .sliding = pTableScanNode->sliding, + .interval = pTableScanNode->interval, + .sliding = pTableScanNode->sliding, .intervalUnit = pTableScanNode->intervalUnit, - .slidingUnit = pTableScanNode->slidingUnit, - .offset = pTableScanNode->offset, + .slidingUnit = pTableScanNode->slidingUnit, + .offset = pTableScanNode->offset, }; return interval; @@ -6478,7 +6505,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode; - int32_t numOfCols = 0; + int32_t numOfCols = 0; tsdbReaderT pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); if (pDataReader == NULL && terrno != 0) { return NULL; @@ -6489,14 +6516,15 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SSDataBlock* pResBlock = createResDataBlock(pScanPhyNode->node.pOutputDataBlockDesc); SQueryTableDataCond cond = {0}; - int32_t code = initQueryTableDataCond(&cond, pTableScanNode); + int32_t code = initQueryTableDataCond(&cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { return NULL; } SInterval interval = extractIntervalInfo(pTableScanNode); - return createTableScanOperatorInfo(pDataReader, &cond, numOfCols, pTableScanNode->dataRequired, pTableScanNode->scanSeq, pColList, - pResBlock, pScanPhyNode->node.pConditions, &interval, pTableScanNode->ratio, pTaskInfo); + return createTableScanOperatorInfo(pDataReader, &cond, numOfCols, pTableScanNode->dataRequired, + pTableScanNode->scanSeq, pColList, pResBlock, pScanPhyNode->node.pConditions, + &interval, pTableScanNode->ratio, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) { SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode; SSDataBlock* pResBlock = createResDataBlock(pExchange->node.pOutputDataBlockDesc); @@ -6504,27 +6532,30 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) { SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table. - int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, queryId, taskId); + int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, + queryId, taskId); SArray* tableIdList = extractTableIdList(pTableGroupInfo); SSDataBlock* pResBlock = createResDataBlock(pScanPhyNode->node.pOutputDataBlockDesc); int32_t numOfCols = 0; SArray* pCols = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); - SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pResBlock, pCols, tableIdList, pTaskInfo); + SOperatorInfo* pOperator = + createStreamScanOperatorInfo(pHandle->reader, pResBlock, pCols, tableIdList, pTaskInfo, pScanPhyNode->node.pConditions); taosArrayDestroy(tableIdList); return pOperator; } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) { SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode; - SScanPhysiNode* pScanNode = &pSysScanPhyNode->scan; + SScanPhysiNode* pScanNode = &pSysScanPhyNode->scan; SSDataBlock* pResBlock = createResDataBlock(pScanNode->node.pOutputDataBlockDesc); int32_t numOfOutputCols = 0; - SArray* colList = extractColMatchInfo(pScanNode->pScanCols, pScanNode->node.pOutputDataBlockDesc, &numOfOutputCols); + SArray* colList = + extractColMatchInfo(pScanNode->pScanCols, pScanNode->node.pOutputDataBlockDesc, &numOfOutputCols); SOperatorInfo* pOperator = createSysTableScanOperatorInfo( - pHandle, pResBlock, &pScanNode->tableName, pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, - colList, pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId); + pHandle, pResBlock, &pScanNode->tableName, pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, colList, + pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId); return pOperator; } else { ASSERT(0); @@ -6641,8 +6672,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return pOptr; } - -static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode) { +static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode) { pCond->loadExternalRows = false; pCond->order = pTableScanNode->scanSeq[0] > 0 ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; @@ -6656,7 +6686,7 @@ static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableS pCond->twindow = pTableScanNode->scanRange; #if 1 - //todo work around a problem, remove it later + // todo work around a problem, remove it later if ((pCond->order == TSDB_ORDER_ASC && pCond->twindow.skey > pCond->twindow.ekey) || (pCond->order == TSDB_ORDER_DESC && pCond->twindow.skey < pCond->twindow.ekey)) { TSWAP(pCond->twindow.skey, pCond->twindow.ekey); @@ -6700,22 +6730,22 @@ SArray* extractColumnInfo(SNodeList* pNodeList) { // todo extract method SColumn c = {0}; - c.slotId = pColNode->slotId; - c.colId = pColNode->colId; - c.type = pColNode->node.resType.type; - c.bytes = pColNode->node.resType.bytes; - c.scale = pColNode->node.resType.scale; + c.slotId = pColNode->slotId; + c.colId = pColNode->colId; + c.type = pColNode->node.resType.type; + c.bytes = pColNode->node.resType.bytes; + c.scale = pColNode->node.resType.scale; c.precision = pColNode->node.resType.precision; taosArrayPush(pList, &c); } else if (nodeType(pNode->pExpr) == QUERY_NODE_VALUE) { - SValueNode* pValNode = (SValueNode*) pNode->pExpr; - SColumn c = {0}; + SValueNode* pValNode = (SValueNode*)pNode->pExpr; + SColumn c = {0}; c.slotId = pNode->slotId; - c.colId = pNode->slotId; - c.type = pValNode->node.type; - c.bytes = pValNode->node.resType.bytes; - c.scale = pValNode->node.resType.scale; + c.colId = pNode->slotId; + c.type = pValNode->node.type; + c.bytes = pValNode->node.resType.bytes; + c.scale = pValNode->node.resType.scale; c.precision = pValNode->node.resType.precision; taosArrayPush(pList, &c); @@ -6897,9 +6927,11 @@ tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* code = initQueryTableDataCond(&cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { goto _error; - } - + } +#if 0 return tsdbQueryTables(pHandle->reader, &cond, pTableGroupInfo, queryId, taskId); +#endif + return tsdbQueryTables(pHandle->vnode, &cond, pTableGroupInfo, queryId, taskId); _error: terrno = code; @@ -6917,7 +6949,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead goto _complete; } - (*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &(*pTaskInfo)->tableqinfoGroupInfo); + (*pTaskInfo)->pRoot = + createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &(*pTaskInfo)->tableqinfoGroupInfo); if (NULL == (*pTaskInfo)->pRoot) { code = terrno; goto _complete; @@ -7255,8 +7288,8 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOf pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyBasicOperatorInfo, - NULL, NULL, NULL); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyBasicOperatorInfo, NULL, NULL, NULL); int32_t code = appendDownstream(pOperator, pDownstream, numOfDownstream); return pOperator; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index beee11ec189680adaf5388d44e56bc523e5ca91a..dd9cd52870c1cc4ad7beb322e8998c6047367ce1 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -77,7 +77,7 @@ static bool groupKeyCompare(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlo SColumn* pCol = taosArrayGet(pGroupCols, i); SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pCol->slotId); if (pBlock->pBlockAgg != NULL) { - pColAgg = &pBlock->pBlockAgg[pCol->slotId]; // TODO is agg data matched? + pColAgg = pBlock->pBlockAgg[pCol->slotId]; // TODO is agg data matched? } bool isNull = colDataIsNull(pColInfoData, pBlock->info.rows, rowIndex, pColAgg); @@ -118,7 +118,7 @@ static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSData SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pCol->slotId); if (pBlock->pBlockAgg != NULL) { - pColAgg = &pBlock->pBlockAgg[pCol->slotId]; // TODO is agg data matched? + pColAgg = pBlock->pBlockAgg[pCol->slotId]; // TODO is agg data matched? } SGroupKeys* pkey = taosArrayGet(pGroupColVals, i); diff --git a/source/libs/executor/src/indexoperator.c b/source/libs/executor/src/indexoperator.c index 34b04c04decc50c77720e6d34af39f3e61df843a..1f8e73b80a43a98543928d3fcf6def4aa603ffa0 100644 --- a/source/libs/executor/src/indexoperator.c +++ b/source/libs/executor/src/indexoperator.c @@ -54,7 +54,9 @@ typedef struct SIFParam { typedef int32_t (*sif_func_t)(SNode *left, SNode *rigth, SIFParam *output); // construct tag filter operator later -static void destroyTagFilterOperatorInfo(void *param) { STagFilterOperatorInfo *pInfo = (STagFilterOperatorInfo *)param; } +static void destroyTagFilterOperatorInfo(void *param) { + STagFilterOperatorInfo *pInfo = (STagFilterOperatorInfo *)param; +} static void sifFreeParam(SIFParam *param) { if (param == NULL) return; @@ -62,8 +64,9 @@ static void sifFreeParam(SIFParam *param) { } static int32_t sifGetOperParamNum(EOperatorType ty) { - if (OP_TYPE_IS_NULL == ty || OP_TYPE_IS_NOT_NULL == ty || OP_TYPE_IS_TRUE == ty || OP_TYPE_IS_NOT_TRUE == ty || OP_TYPE_IS_FALSE == ty || - OP_TYPE_IS_NOT_FALSE == ty || OP_TYPE_IS_UNKNOWN == ty || OP_TYPE_IS_NOT_UNKNOWN == ty || OP_TYPE_MINUS == ty) { + if (OP_TYPE_IS_NULL == ty || OP_TYPE_IS_NOT_NULL == ty || OP_TYPE_IS_TRUE == ty || OP_TYPE_IS_NOT_TRUE == ty || + OP_TYPE_IS_FALSE == ty || OP_TYPE_IS_NOT_FALSE == ty || OP_TYPE_IS_UNKNOWN == ty || + OP_TYPE_IS_NOT_UNKNOWN == ty || OP_TYPE_MINUS == ty) { return 1; } return 2; @@ -267,7 +270,8 @@ _return: static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *output) { if (NULL == node->pParameterList || node->pParameterList->length <= 0) { - qError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); + qError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, + node->pParameterList ? node->pParameterList->length : 0); return TSDB_CODE_QRY_INVALID_INPUT; } @@ -341,7 +345,8 @@ static EDealRes sifWalkOper(SNode *pNode, void *context) { } EDealRes sifCalcWalker(SNode *node, void *context) { - if (QUERY_NODE_VALUE == nodeType(node) || QUERY_NODE_NODE_LIST == nodeType(node) || QUERY_NODE_COLUMN == nodeType(node)) { + if (QUERY_NODE_VALUE == nodeType(node) || QUERY_NODE_NODE_LIST == nodeType(node) || + QUERY_NODE_COLUMN == nodeType(node)) { return DEAL_RES_CONTINUE; } SIFCtx *ctx = (SIFCtx *)context; @@ -383,21 +388,20 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } nodesWalkExprPostOrder(pNode, sifCalcWalker, &ctx); - if (ctx.code != TSDB_CODE_SUCCESS) { - return ctx.code; - } + SIF_ERR_RET(ctx.code); + if (pDst) { SIFParam *res = (SIFParam *)taosHashGet(ctx.pRes, (void *)&pNode, POINTER_BYTES); if (res == NULL) { qError("no valid res in hash, node:(%p), type(%d)", (void *)&pNode, nodeType(pNode)); - return TSDB_CODE_QRY_APP_ERROR; + SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } taosArrayAddAll(pDst->result, res->result); sifFreeParam(res); taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); } - return TSDB_CODE_SUCCESS; + SIF_RET(code); } int32_t doFilterTag(const SNode *pFilterNode, SArray *result) { @@ -407,22 +411,14 @@ int32_t doFilterTag(const SNode *pFilterNode, SArray *result) { SFilterInfo *filter = NULL; // todo move to the initialization function - int32_t code = filterInitFromNode((SNode *)pFilterNode, &filter, 0); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0)); SIFParam param = {0}; - code = sifCalculate((SNode *)pFilterNode, ¶m); - - if (code != TSDB_CODE_SUCCESS) { - return code; - } + SIF_ERR_RET(sifCalculate((SNode *)pFilterNode, ¶m)); taosArrayAddAll(result, param.result); sifFreeParam(¶m); - - return code; + SIF_RET(TSDB_CODE_SUCCESS); } SIdxFltStatus idxGetFltStatus(SNode *pFilterNode) { diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 8291826e69aa1bf99639ec0e0e1649c011b95b75..c2a101e0125b03020ac00441a8e4b851f6e38d9c 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include +#include "common/ttime.h" #include "filter.h" #include "function.h" #include "functionMgt.h" @@ -21,7 +21,7 @@ #include "querynodes.h" #include "tglobal.h" #include "tname.h" -#include "vnode.h" +#include "systable.h" #include "tdatablock.h" #include "tmsg.h" @@ -36,6 +36,9 @@ #define SET_REVERSE_SCAN_FLAG(_info) ((_info)->scanFlag = REVERSE_SCAN) #define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) +int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo); + +int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName); void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { for (int32_t i = 0; i < numOfOutput; ++i) { SWITCH_ORDER(pCtx[i].order); @@ -65,21 +68,6 @@ static void setupQueryRangeForReverseScan(STableScanInfo* pTableScanInfo) { #endif } -// relocated the column data according to the slotId -static void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols) { - int32_t numOfCols = pBlock->info.numOfCols; - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* p = taosArrayGet(pCols, i); - SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i); - if (!pmInfo->output) { - continue; - } - - ASSERT(pmInfo->colId == p->info.colId); - taosArraySet(pBlock->pDataBlock, pmInfo->targetSlotId, p); - } -} - static void getNextTimeWindow(SInterval* pInterval, STimeWindow* tw, int32_t order) { int32_t factor = GET_FORWARD_DIRECTION_FACTOR(order); if (pInterval->intervalUnit != 'n' && pInterval->intervalUnit != 'y') { @@ -200,14 +188,18 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, } else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) { pCost->loadBlockStatis += 1; - SColumnDataAgg* pColAgg = NULL; - tsdbRetrieveDataBlockStatisInfo(pTableScanInfo->dataReader, &pColAgg); + bool allHave = true; + SColumnDataAgg** pColAgg = NULL; + tsdbRetrieveDataBlockStatisInfo(pTableScanInfo->dataReader, &pColAgg, &allHave); - if (pColAgg != NULL) { + if (allHave == true) { int32_t numOfCols = pBlock->info.numOfCols; // todo create this buffer during creating operator - pBlock->pBlockAgg = taosMemoryCalloc(numOfCols, sizeof(SColumnDataAgg)); + if (pBlock->pBlockAgg == NULL) { + pBlock->pBlockAgg = taosMemoryCalloc(numOfCols, POINTER_BYTES); + } + for (int32_t i = 0; i < numOfCols; ++i) { SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i); if (!pColMatchInfo->output) { @@ -244,11 +236,6 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, } relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols); - - // reset the block to be 0 by default, this blockId is assigned by physical plan and is used by direct upstream - // operator. - pBlock->info.blockId = 0; - doFilter(pTableScanInfo->pFilterNode, pBlock); if (pBlock->info.rows == 0) { pCost->filterOutBlocks += 1; @@ -531,6 +518,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) // NOTE: this operator does never check if current status is done or not SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStreamBlockScanInfo* pInfo = pOperator->info; + int32_t rows = 0; pTaskInfo->code = pOperator->fpSet._openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS || pOperator->status == OP_EXEC_DONE) { @@ -597,6 +585,8 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) pTaskInfo->code = terrno; return NULL; } + rows = pBlockInfo->rows; + doFilter(pInfo->pCondition, pInfo->pRes); break; } @@ -605,16 +595,16 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) pInfo->numOfExec++; pInfo->numOfRows += pBlockInfo->rows; - if (pBlockInfo->rows == 0) { + if (rows == 0) { pOperator->status = OP_EXEC_DONE; } - return (pBlockInfo->rows == 0) ? NULL : pInfo->pRes; + return (rows == 0) ? NULL : pInfo->pRes; } } SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, - SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { + SArray* pTableIdList, SExecTaskInfo* pTaskInfo, SNode* pCondition) { SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -652,6 +642,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pInfo->readerHandle = streamReadHandle; pInfo->pRes = pResBlock; + pInfo->pCondition = pCondition; pOperator->name = "StreamBlockScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; @@ -788,7 +779,12 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { continue; } - colDataAppend(pDest, numOfRow, colDataGetData(pSrc, j), false); + if (colDataIsNull_s(pSrc, j)) { + colDataAppendNULL(pDest, numOfRow); + } else { + colDataAppend(pDest, numOfRow, colDataGetData(pSrc, j), false); + } + numOfRow += 1; } } else { @@ -802,6 +798,67 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; } +static SSDataBlock* buildSysTableMetaBlock() { + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + pBlock->info.numOfCols = 10; + pBlock->info.hasVarCol = true; + + pBlock->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData)); + + SColumnInfoData colInfoData = {0}; + colInfoData.info.colId = 1; + colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR; + colInfoData.info.bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 2; + colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR; + colInfoData.info.bytes = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 3; + colInfoData.info.type = TSDB_DATA_TYPE_TIMESTAMP; + colInfoData.info.bytes = 8; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 4; + colInfoData.info.type = TSDB_DATA_TYPE_INT; + colInfoData.info.bytes = 4; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 5; + colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR; + colInfoData.info.bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 6; + colInfoData.info.type = TSDB_DATA_TYPE_BIGINT; + colInfoData.info.bytes = 8; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 7; + colInfoData.info.type = TSDB_DATA_TYPE_INT; + colInfoData.info.bytes = 4; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 8; + colInfoData.info.type = TSDB_DATA_TYPE_INT; + colInfoData.info.bytes = 4; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 9; + colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR; + colInfoData.info.bytes = 512 + VARSTR_HEADER_SIZE; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + colInfoData.info.colId = 10; + colInfoData.info.type = TSDB_DATA_TYPE_VARCHAR; + colInfoData.info.bytes = 20 + VARSTR_HEADER_SIZE; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + + return pBlock; +} + static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { // build message and send to mnode to fetch the content of system tables. SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -810,115 +867,135 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { // retrieve local table list info from vnode const char* name = tNameGetTableName(&pInfo->name); if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) { - if (pInfo->pCur == NULL) { - pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta); - } - - blockDataCleanup(pInfo->pRes); - - int32_t tableNameSlotId = 1; - SColumnInfoData* pTableNameCol = taosArrayGet(pInfo->pRes->pDataBlock, tableNameSlotId); - - int32_t numOfRows = 0; - - const char* db = NULL; - int32_t vgId = 0; - vnodeGetInfo(pInfo->readHandle.vnode, &db, &vgId); - - SName sn = {0}; - char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; - tNameFromString(&sn, db, T_NAME_ACCT|T_NAME_DB); + // the retrieve is executed on the mnode, so return tables that belongs to the information schema database. + if (pInfo->readHandle.mnd != NULL) { + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } - tNameGetDbName(&sn, varDataVal(dbname)); - varDataSetLen(dbname, strlen(varDataVal(dbname))); + buildSysDbTableInfo(pInfo); - char n[TSDB_TABLE_NAME_LEN] = {0}; - while (metaTbCursorNext(pInfo->pCur) == 0) { - STR_TO_VARSTR(n, pInfo->pCur->mr.me.name); - colDataAppend(pTableNameCol, numOfRows, n, false); + doFilterResult(pInfo); + pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; - int32_t tableType = pInfo->pCur->mr.me.type; + pOperator->status = OP_EXEC_DONE; + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; + } else { + if (pInfo->pCur == NULL) { + pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta); + } - // database name - SColumnInfoData* pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 0); - colDataAppend(pColInfoData, numOfRows, dbname, false); + blockDataCleanup(pInfo->pRes); - // vgId - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 6); - colDataAppend(pColInfoData, numOfRows, (char*) &vgId, false); + int32_t numOfRows = 0; - // table comment - // todo: set the correct comment - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 8); - colDataAppendNULL(pColInfoData, numOfRows); + const char* db = NULL; + int32_t vgId = 0; + vnodeGetInfo(pInfo->readHandle.vnode, &db, &vgId); - char str[256] = {0}; - if (tableType == TSDB_CHILD_TABLE) { - SMetaReader mr = {0}; - metaReaderInit(&mr, pInfo->readHandle.meta, 0); - metaGetTableEntryByUid(&mr, pInfo->pCur->mr.me.ctbEntry.suid); + SName sn = {0}; + char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB); - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 3); - colDataAppend(pColInfoData, numOfRows, (char*) &mr.me.stbEntry.schema.nCols, false); + tNameGetDbName(&sn, varDataVal(dbname)); + varDataSetLen(dbname, strlen(varDataVal(dbname))); - // create time - int64_t ts = pInfo->pCur->mr.me.ctbEntry.ctime; - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 2); - colDataAppend(pColInfoData, numOfRows, (char*) &ts, false); + SSDataBlock* p = buildSysTableMetaBlock(); + blockDataEnsureCapacity(p, pInfo->capacity); - // super table name - STR_TO_VARSTR(str, mr.me.name); - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 4); - colDataAppend(pColInfoData, numOfRows, str, false); - metaReaderClear(&mr); + char n[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + while (metaTbCursorNext(pInfo->pCur) == 0) { + STR_TO_VARSTR(n, pInfo->pCur->mr.me.name); - // uid - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 5); - colDataAppend(pColInfoData, numOfRows, (char*) &pInfo->pCur->mr.me.uid, false); + // table name + SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, 0); + colDataAppend(pColInfoData, numOfRows, n, false); - // ttl - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 7); - colDataAppend(pColInfoData, numOfRows, (char*) &pInfo->pCur->mr.me.ctbEntry.ttlDays, false); + // database name + pColInfoData = taosArrayGet(p->pDataBlock, 1); + colDataAppend(pColInfoData, numOfRows, dbname, false); - STR_TO_VARSTR(str, "CHILD_TABLE"); - } else if (tableType == TSDB_NORMAL_TABLE) { - // create time - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 2); - colDataAppend(pColInfoData, numOfRows, (char*) &pInfo->pCur->mr.me.ntbEntry.ctime, false); + // vgId + pColInfoData = taosArrayGet(p->pDataBlock, 6); + colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false); - // number of columns - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 3); - colDataAppend(pColInfoData, numOfRows, (char*) &pInfo->pCur->mr.me.ntbEntry.schema.nCols, false); - - // super table name - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 4); + // table comment + // todo: set the correct comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); colDataAppendNULL(pColInfoData, numOfRows); - // uid - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 5); - colDataAppend(pColInfoData, numOfRows, (char*) &pInfo->pCur->mr.me.uid, false); + char str[256] = {0}; + int32_t tableType = pInfo->pCur->mr.me.type; + if (tableType == TSDB_CHILD_TABLE) { + // create time + int64_t ts = pInfo->pCur->mr.me.ctbEntry.ctime; + pColInfoData = taosArrayGet(p->pDataBlock, 2); + colDataAppend(pColInfoData, numOfRows, (char*)&ts, false); + + SMetaReader mr = {0}; + metaReaderInit(&mr, pInfo->readHandle.meta, 0); + metaGetTableEntryByUid(&mr, pInfo->pCur->mr.me.ctbEntry.suid); + + // number of columns + pColInfoData = taosArrayGet(p->pDataBlock, 3); + colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schema.nCols, false); + + // super table name + STR_TO_VARSTR(str, mr.me.name); + pColInfoData = taosArrayGet(p->pDataBlock, 4); + colDataAppend(pColInfoData, numOfRows, str, false); + metaReaderClear(&mr); + + // uid + pColInfoData = taosArrayGet(p->pDataBlock, 5); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); + + // ttl + pColInfoData = taosArrayGet(p->pDataBlock, 7); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false); + + STR_TO_VARSTR(str, "CHILD_TABLE"); + } else if (tableType == TSDB_NORMAL_TABLE) { + // create time + pColInfoData = taosArrayGet(p->pDataBlock, 2); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ctime, false); + + // number of columns + pColInfoData = taosArrayGet(p->pDataBlock, 3); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.schema.nCols, false); + + // super table name + pColInfoData = taosArrayGet(p->pDataBlock, 4); + colDataAppendNULL(pColInfoData, numOfRows); + + // uid + pColInfoData = taosArrayGet(p->pDataBlock, 5); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); + + // ttl + pColInfoData = taosArrayGet(p->pDataBlock, 7); + colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false); + + STR_TO_VARSTR(str, "NORMAL_TABLE"); + } - // ttl - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 7); - colDataAppend(pColInfoData, numOfRows, (char*) &pInfo->pCur->mr.me.ntbEntry.ttlDays, false); + pColInfoData = taosArrayGet(p->pDataBlock, 9); + colDataAppend(pColInfoData, numOfRows, str, false); - STR_TO_VARSTR(str, "NORMAL_TABLE"); + if (++numOfRows >= pInfo->capacity) { + break; + } } - pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, 9); - colDataAppend(pColInfoData, numOfRows, str, false); - - if (++numOfRows >= pInfo->capacity) { - break; - } - } + p->info.rows = numOfRows; + pInfo->pRes->info.rows = numOfRows; - pInfo->loadInfo.totalRows += numOfRows; - pInfo->pRes->info.rows = numOfRows; + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock); + doFilterResult(pInfo); - // pInfo->elapsedTime; - // pInfo->totalBytes; - return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; + pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; + } } else { // load the meta from mnode of the given epset if (pOperator->status == OP_EXEC_DONE) { return NULL; @@ -988,6 +1065,67 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { } } +int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo) { + SSDataBlock* p = buildSysTableMetaBlock(); + blockDataEnsureCapacity(p, pInfo->capacity); + + size_t size = 0; + const SSysTableMeta* pSysDbTableMeta = NULL; + + getInfosDbMeta(&pSysDbTableMeta, &size); + p->info.rows = buildDbTableInfoBlock(p, pSysDbTableMeta, size, TSDB_INFORMATION_SCHEMA_DB); + + getPerfDbMeta(&pSysDbTableMeta, &size); + p->info.rows = buildDbTableInfoBlock(p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB); + + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock); +// blockDataDestroy(p); todo handle memory leak + + pInfo->pRes->info.rows = p->info.rows; + return p->info.rows; +} + +int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName) { + char n[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + int32_t numOfRows = p->info.rows; + + for(int32_t i = 0; i < size; ++i) { + const SSysTableMeta* pm = &pSysDbTableMeta[i]; + + SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, 0); + + STR_TO_VARSTR(n, pm->name); + colDataAppend(pColInfoData, numOfRows, n, false); + + // database name + STR_TO_VARSTR(n, dbName); + pColInfoData = taosArrayGet(p->pDataBlock, 1); + colDataAppend(pColInfoData, numOfRows, n, false); + + // create time + pColInfoData = taosArrayGet(p->pDataBlock, 2); + colDataAppendNULL(pColInfoData, numOfRows); + + // number of columns + pColInfoData = taosArrayGet(p->pDataBlock, 3); + colDataAppend(pColInfoData, numOfRows, (char*)&pm->colNum, false); + + for(int32_t j = 4; j <= 8; ++j) { + pColInfoData = taosArrayGet(p->pDataBlock, j); + colDataAppendNULL(pColInfoData, numOfRows); + } + + STR_TO_VARSTR(n, "SYSTEM_TABLE"); + + pColInfoData = taosArrayGet(p->pDataBlock, 9); + colDataAppend(pColInfoData, numOfRows, n, false); + + numOfRows += 1; + } + + return numOfRows; +} + SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pResBlock, const SName* pName, SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId) { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 2ac28200e79d3b365fc75d055f785e0a99963355..46fc8da00caf938ed6ad287b74b1120e87ce3b11 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -374,18 +374,17 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { for(int32_t i = 0; i < pInfo->size; ++i) { SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i); - SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->slotId); bool leftNull = false; if (pLeftColInfoData->hasNull) { - leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg); + leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg[pOrder->slotId]); } SColumnInfoData* pRightColInfoData = TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); bool rightNull = false; if (pRightColInfoData->hasNull) { - rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg); + rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg[pOrder->slotId]); } if (leftNull && rightNull) { diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index efa0581fd0b09893054c09a9429cb589411d3e91..e646387856e66b147b5fb369b8d522b155f5d04c 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -164,13 +164,13 @@ int32_t docomp(const void* p1, const void* p2, void* param) { bool leftNull = false; if (pLeftColInfoData->hasNull) { - leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg); + leftNull = colDataIsNull(pLeftColInfoData, pLeftBlock->info.rows, pLeftSource->src.rowIndex, pLeftBlock->pBlockAgg[pOrder->slotId]); } SColumnInfoData* pRightColInfoData = (SColumnInfoData*) TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); bool rightNull = false; if (pRightColInfoData->hasNull) { - rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg); + rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, pRightBlock->pBlockAgg[pOrder->slotId]); } if (leftNull && rightNull) { diff --git a/source/libs/function/CMakeLists.txt b/source/libs/function/CMakeLists.txt index 98f1209ad921ce9e86887a6972b4246ad7483d3a..15813b3cb05cc796594dd7be27ad10a0557359b7 100644 --- a/source/libs/function/CMakeLists.txt +++ b/source/libs/function/CMakeLists.txt @@ -51,6 +51,21 @@ target_link_libraries( udf1 PUBLIC os ) +add_library(udf2 MODULE test/udf2.c) +target_include_directories( + udf2 + PUBLIC + "${TD_SOURCE_DIR}/include/libs/function" + "${TD_SOURCE_DIR}/include/util" + "${TD_SOURCE_DIR}/include/common" + "${TD_SOURCE_DIR}/include/client" + "${TD_SOURCE_DIR}/include/os" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + udf2 PUBLIC os +) + #SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin) add_executable(udfd src/udfd.c) target_include_directories( diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 0ad3730b5a44185e1da652c7b31404f911b7e95d..87cd3e24a8eb43162524ab0e3baa9591f38bd78a 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -25,6 +25,7 @@ extern "C" { bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, char* finalResult); EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); @@ -67,6 +68,11 @@ bool getTopBotFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv); int32_t topFunction(SqlFunctionCtx *pCtx); int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +bool getSpreadFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool spreadFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); +int32_t spreadFunction(SqlFunctionCtx* pCtx); +int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); + #ifdef __cplusplus } #endif diff --git a/source/libs/function/inc/tudfInt.h b/source/libs/function/inc/tudfInt.h index 4e7178f7fd0a67e53552ae9d0e73f3357edb8430..8aedd59c335f2876a5fc4c6a9f958f4ea81dc464 100644 --- a/source/libs/function/inc/tudfInt.h +++ b/source/libs/function/inc/tudfInt.h @@ -43,6 +43,9 @@ typedef struct SUdfSetupRequest { typedef struct SUdfSetupResponse { int64_t udfHandle; + int8_t outputType; + int32_t outputLen; + int32_t bufSize; } SUdfSetupResponse; typedef struct SUdfCallRequest { diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 45cfbae1ad13d348b92d8225af797f9db400fe78..8f3c88900dc194d1e432d041c403e624e52e0892 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -212,7 +212,16 @@ static int32_t translateBottom(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } static int32_t translateSpread(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - // todo + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(paraType) && TSDB_DATA_TYPE_TIMESTAMP != paraType) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } @@ -247,8 +256,7 @@ static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = - (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } @@ -430,436 +438,544 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return TSDB_CODE_SUCCESS; } +// clang-format off const SBuiltinFuncDefinition funcMgtBuiltins[] = { - {.name = "count", - .type = FUNCTION_TYPE_COUNT, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateCount, - .dataRequiredFunc = countDataRequired, - .getEnvFunc = getCountFuncEnv, - .initFunc = functionSetup, - .processFunc = countFunction, - .finalizeFunc = functionFinalize}, - {.name = "sum", - .type = FUNCTION_TYPE_SUM, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateSum, - .dataRequiredFunc = statisDataRequired, - .getEnvFunc = getSumFuncEnv, - .initFunc = functionSetup, - .processFunc = sumFunction, - .finalizeFunc = functionFinalize}, - {.name = "min", - .type = FUNCTION_TYPE_MIN, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateInOutNum, - .dataRequiredFunc = statisDataRequired, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = minFunctionSetup, - .processFunc = minFunction, - .finalizeFunc = functionFinalize}, - {.name = "max", - .type = FUNCTION_TYPE_MAX, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .translateFunc = translateInOutNum, - .dataRequiredFunc = statisDataRequired, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize}, - {.name = "stddev", - .type = FUNCTION_TYPE_STDDEV, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = getStddevFuncEnv, - .initFunc = stddevFunctionSetup, - .processFunc = stddevFunction, - .finalizeFunc = stddevFinalize}, - {.name = "avg", - .type = FUNCTION_TYPE_AVG, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = getAvgFuncEnv, - .initFunc = avgFunctionSetup, - .processFunc = avgFunction, - .finalizeFunc = avgFinalize}, - {.name = "percentile", - .type = FUNCTION_TYPE_PERCENTILE, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translatePercentile, - .getEnvFunc = getPercentileFuncEnv, - .initFunc = percentileFunctionSetup, - .processFunc = percentileFunction, - .finalizeFunc = percentileFinalize}, - {.name = "apercentile", - .type = FUNCTION_TYPE_APERCENTILE, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateApercentile, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize}, - { - .name = "top", - .type = FUNCTION_TYPE_TOP, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateTop, - .getEnvFunc = getTopBotFuncEnv, - .initFunc = functionSetup, - .processFunc = topFunction, - .finalizeFunc = topBotFinalize, - }, - {.name = "bottom", - .type = FUNCTION_TYPE_BOTTOM, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateBottom, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize}, - {.name = "spread", - .type = FUNCTION_TYPE_SPREAD, - .classification = FUNC_MGT_AGG_FUNC, - .translateFunc = translateSpread, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize}, - {.name = "last_row", - .type = FUNCTION_TYPE_LAST_ROW, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, - .translateFunc = translateLastRow, - .getEnvFunc = getMinmaxFuncEnv, - .initFunc = maxFunctionSetup, - .processFunc = maxFunction, - .finalizeFunc = functionFinalize}, - {.name = "first", - .type = FUNCTION_TYPE_FIRST, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, - .translateFunc = translateFirstLast, - .getEnvFunc = getFirstLastFuncEnv, - .initFunc = functionSetup, - .processFunc = firstFunction, - .finalizeFunc = functionFinalize}, - {.name = "last", - .type = FUNCTION_TYPE_LAST, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, - .translateFunc = translateFirstLast, - .getEnvFunc = getFirstLastFuncEnv, - .initFunc = functionSetup, - .processFunc = lastFunction, - .finalizeFunc = functionFinalize}, - {.name = "diff", - .type = FUNCTION_TYPE_DIFF, - .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = getDiffFuncEnv, - .initFunc = diffFunctionSetup, - .processFunc = diffFunction, - .finalizeFunc = functionFinalize}, - {.name = "abs", - .type = FUNCTION_TYPE_ABS, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = absFunction, - .finalizeFunc = NULL}, - {.name = "log", - .type = FUNCTION_TYPE_LOG, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateIn2NumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = logFunction, - .finalizeFunc = NULL}, - {.name = "pow", - .type = FUNCTION_TYPE_POW, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateIn2NumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = powFunction, - .finalizeFunc = NULL}, - {.name = "sqrt", - .type = FUNCTION_TYPE_SQRT, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = sqrtFunction, - .finalizeFunc = NULL}, - {.name = "ceil", - .type = FUNCTION_TYPE_CEIL, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = ceilFunction, - .finalizeFunc = NULL}, - {.name = "floor", - .type = FUNCTION_TYPE_FLOOR, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = floorFunction, - .finalizeFunc = NULL}, - {.name = "round", - .type = FUNCTION_TYPE_ROUND, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInOutNum, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = roundFunction, - .finalizeFunc = NULL}, - {.name = "sin", - .type = FUNCTION_TYPE_SIN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = sinFunction, - .finalizeFunc = NULL}, - {.name = "cos", - .type = FUNCTION_TYPE_COS, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = cosFunction, - .finalizeFunc = NULL}, - {.name = "tan", - .type = FUNCTION_TYPE_TAN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = tanFunction, - .finalizeFunc = NULL}, - {.name = "asin", - .type = FUNCTION_TYPE_ASIN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = asinFunction, - .finalizeFunc = NULL}, - {.name = "acos", - .type = FUNCTION_TYPE_ACOS, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = acosFunction, - .finalizeFunc = NULL}, - {.name = "atan", - .type = FUNCTION_TYPE_ATAN, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateInNumOutDou, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = atanFunction, - .finalizeFunc = NULL}, - {.name = "length", - .type = FUNCTION_TYPE_LENGTH, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateLength, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = lengthFunction, - .finalizeFunc = NULL}, - {.name = "char_length", - .type = FUNCTION_TYPE_CHAR_LENGTH, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateLength, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = charLengthFunction, - .finalizeFunc = NULL}, - {.name = "concat", - .type = FUNCTION_TYPE_CONCAT, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateConcat, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = concatFunction, - .finalizeFunc = NULL}, - {.name = "concat_ws", - .type = FUNCTION_TYPE_CONCAT_WS, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateConcatWs, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = concatWsFunction, - .finalizeFunc = NULL}, - {.name = "lower", - .type = FUNCTION_TYPE_LOWER, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = lowerFunction, - .finalizeFunc = NULL}, - {.name = "upper", - .type = FUNCTION_TYPE_UPPER, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = upperFunction, - .finalizeFunc = NULL}, - {.name = "ltrim", - .type = FUNCTION_TYPE_LTRIM, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = ltrimFunction, - .finalizeFunc = NULL}, - {.name = "rtrim", - .type = FUNCTION_TYPE_RTRIM, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateInOutStr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = rtrimFunction, - .finalizeFunc = NULL}, - {.name = "substr", - .type = FUNCTION_TYPE_SUBSTR, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .translateFunc = translateSubstr, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = substrFunction, - .finalizeFunc = NULL}, - {.name = "cast", - .type = FUNCTION_TYPE_CAST, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateCast, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = castFunction, - .finalizeFunc = NULL}, - {.name = "to_iso8601", - .type = FUNCTION_TYPE_TO_ISO8601, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateToIso8601, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = toISO8601Function, - .finalizeFunc = NULL}, - {.name = "to_unixtimestamp", - .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateToUnixtimestamp, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = toUnixtimestampFunction, - .finalizeFunc = NULL}, - {.name = "timetruncate", - .type = FUNCTION_TYPE_TIMETRUNCATE, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateTimeTruncate, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = timeTruncateFunction, - .finalizeFunc = NULL}, - {.name = "timediff", - .type = FUNCTION_TYPE_TIMEDIFF, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateTimeDiff, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = timeDiffFunction, - .finalizeFunc = NULL}, - {.name = "now", - .type = FUNCTION_TYPE_NOW, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = nowFunction, - .finalizeFunc = NULL}, - {.name = "today", - .type = FUNCTION_TYPE_TODAY, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = todayFunction, - .finalizeFunc = NULL}, - {.name = "timezone", - .type = FUNCTION_TYPE_TIMEZONE, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateTimezone, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = timezoneFunction, - .finalizeFunc = NULL}, - {.name = "_rowts", - .type = FUNCTION_TYPE_ROWTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = NULL, - .finalizeFunc = NULL}, - {.name = "tbname", - .type = FUNCTION_TYPE_TBNAME, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_SCAN_PC_FUNC, - .translateFunc = translateTbnameColumn, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = NULL, - .finalizeFunc = NULL}, - {.name = "_qstartts", - .type = FUNCTION_TYPE_QSTARTTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = qStartTsFunction, - .finalizeFunc = NULL}, - {.name = "_qendts", - .type = FUNCTION_TYPE_QENDTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = qEndTsFunction, - .finalizeFunc = NULL}, - {.name = "_wstartts", - .type = FUNCTION_TYPE_WSTARTTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = winStartTsFunction, - .finalizeFunc = NULL}, - {.name = "_wendts", - .type = FUNCTION_TYPE_WENDTS, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateTimePseudoColumn, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = winEndTsFunction, - .finalizeFunc = NULL}, - {.name = "_wduration", - .type = FUNCTION_TYPE_WDURATION, - .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .translateFunc = translateWduration, - .getEnvFunc = getTimePseudoFuncEnv, - .initFunc = NULL, - .sprocessFunc = winDurFunction, - .finalizeFunc = NULL}, - {.name = "to_json", - .type = FUNCTION_TYPE_TO_JSON, - .classification = FUNC_MGT_SCALAR_FUNC, - .translateFunc = translateToJson, - .getEnvFunc = NULL, - .initFunc = NULL, - .sprocessFunc = toJsonFunction, - .finalizeFunc = NULL}}; + { + .name = "count", + .type = FUNCTION_TYPE_COUNT, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateCount, + .dataRequiredFunc = countDataRequired, + .getEnvFunc = getCountFuncEnv, + .initFunc = functionSetup, + .processFunc = countFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "sum", + .type = FUNCTION_TYPE_SUM, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateSum, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getSumFuncEnv, + .initFunc = functionSetup, + .processFunc = sumFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "min", + .type = FUNCTION_TYPE_MIN, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateInOutNum, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = minFunctionSetup, + .processFunc = minFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "max", + .type = FUNCTION_TYPE_MAX, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateInOutNum, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "stddev", + .type = FUNCTION_TYPE_STDDEV, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = getStddevFuncEnv, + .initFunc = stddevFunctionSetup, + .processFunc = stddevFunction, + .finalizeFunc = stddevFinalize + }, + { + .name = "avg", + .type = FUNCTION_TYPE_AVG, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = getAvgFuncEnv, + .initFunc = avgFunctionSetup, + .processFunc = avgFunction, + .finalizeFunc = avgFinalize + }, + { + .name = "percentile", + .type = FUNCTION_TYPE_PERCENTILE, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translatePercentile, + .getEnvFunc = getPercentileFuncEnv, + .initFunc = percentileFunctionSetup, + .processFunc = percentileFunction, + .finalizeFunc = percentileFinalize + }, + { + .name = "apercentile", + .type = FUNCTION_TYPE_APERCENTILE, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateApercentile, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "top", + .type = FUNCTION_TYPE_TOP, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateTop, + .getEnvFunc = getTopBotFuncEnv, + .initFunc = functionSetup, + .processFunc = topFunction, + .finalizeFunc = topBotFinalize, + }, + { + .name = "bottom", + .type = FUNCTION_TYPE_BOTTOM, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateBottom, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "spread", + .type = FUNCTION_TYPE_SPREAD, + .classification = FUNC_MGT_AGG_FUNC, + .translateFunc = translateSpread, + .dataRequiredFunc = statisDataRequired, + .getEnvFunc = getSpreadFuncEnv, + .initFunc = spreadFunctionSetup, + .processFunc = spreadFunction, + .finalizeFunc = spreadFinalize + }, + { + .name = "last_row", + .type = FUNCTION_TYPE_LAST_ROW, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, + .translateFunc = translateLastRow, + .getEnvFunc = getMinmaxFuncEnv, + .initFunc = maxFunctionSetup, + .processFunc = maxFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "first", + .type = FUNCTION_TYPE_FIRST, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC, + .translateFunc = translateFirstLast, + .getEnvFunc = getFirstLastFuncEnv, + .initFunc = functionSetup, + .processFunc = firstFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "last", + .type = FUNCTION_TYPE_LAST, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC, + .translateFunc = translateFirstLast, + .getEnvFunc = getFirstLastFuncEnv, + .initFunc = functionSetup, + .processFunc = lastFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "diff", + .type = FUNCTION_TYPE_DIFF, + .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC | FUNC_MGT_TIMELINE_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = getDiffFuncEnv, + .initFunc = diffFunctionSetup, + .processFunc = diffFunction, + .finalizeFunc = functionFinalize + }, + { + .name = "abs", + .type = FUNCTION_TYPE_ABS, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = absFunction, + .finalizeFunc = NULL + }, + { + .name = "log", + .type = FUNCTION_TYPE_LOG, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateIn2NumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = logFunction, + .finalizeFunc = NULL + }, + { + .name = "pow", + .type = FUNCTION_TYPE_POW, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateIn2NumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = powFunction, + .finalizeFunc = NULL + }, + { + .name = "sqrt", + .type = FUNCTION_TYPE_SQRT, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = sqrtFunction, + .finalizeFunc = NULL + }, + { + .name = "ceil", + .type = FUNCTION_TYPE_CEIL, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = ceilFunction, + .finalizeFunc = NULL + }, + { + .name = "floor", + .type = FUNCTION_TYPE_FLOOR, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = floorFunction, + .finalizeFunc = NULL + }, + { + .name = "round", + .type = FUNCTION_TYPE_ROUND, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInOutNum, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = roundFunction, + .finalizeFunc = NULL + }, + { + .name = "sin", + .type = FUNCTION_TYPE_SIN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = sinFunction, + .finalizeFunc = NULL + }, + { + .name = "cos", + .type = FUNCTION_TYPE_COS, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = cosFunction, + .finalizeFunc = NULL + }, + { + .name = "tan", + .type = FUNCTION_TYPE_TAN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = tanFunction, + .finalizeFunc = NULL + }, + { + .name = "asin", + .type = FUNCTION_TYPE_ASIN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = asinFunction, + .finalizeFunc = NULL + }, + { + .name = "acos", + .type = FUNCTION_TYPE_ACOS, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = acosFunction, + .finalizeFunc = NULL + }, + { + .name = "atan", + .type = FUNCTION_TYPE_ATAN, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateInNumOutDou, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = atanFunction, + .finalizeFunc = NULL + }, + { + .name = "length", + .type = FUNCTION_TYPE_LENGTH, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateLength, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = lengthFunction, + .finalizeFunc = NULL + }, + { + .name = "char_length", + .type = FUNCTION_TYPE_CHAR_LENGTH, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateLength, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = charLengthFunction, + .finalizeFunc = NULL + }, + { + .name = "concat", + .type = FUNCTION_TYPE_CONCAT, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateConcat, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = concatFunction, + .finalizeFunc = NULL + }, + { + .name = "concat_ws", + .type = FUNCTION_TYPE_CONCAT_WS, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateConcatWs, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = concatWsFunction, + .finalizeFunc = NULL + }, + { + .name = "lower", + .type = FUNCTION_TYPE_LOWER, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = lowerFunction, + .finalizeFunc = NULL + }, + { + .name = "upper", + .type = FUNCTION_TYPE_UPPER, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = upperFunction, + .finalizeFunc = NULL + }, + { + .name = "ltrim", + .type = FUNCTION_TYPE_LTRIM, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = ltrimFunction, + .finalizeFunc = NULL + }, + { + .name = "rtrim", + .type = FUNCTION_TYPE_RTRIM, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateInOutStr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = rtrimFunction, + .finalizeFunc = NULL + }, + { + .name = "substr", + .type = FUNCTION_TYPE_SUBSTR, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, + .translateFunc = translateSubstr, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = substrFunction, + .finalizeFunc = NULL + }, + { + .name = "cast", + .type = FUNCTION_TYPE_CAST, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateCast, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = castFunction, + .finalizeFunc = NULL + }, + { + .name = "to_iso8601", + .type = FUNCTION_TYPE_TO_ISO8601, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToIso8601, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toISO8601Function, + .finalizeFunc = NULL + }, + { + .name = "to_unixtimestamp", + .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToUnixtimestamp, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toUnixtimestampFunction, + .finalizeFunc = NULL + }, + { + .name = "timetruncate", + .type = FUNCTION_TYPE_TIMETRUNCATE, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimeTruncate, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeTruncateFunction, + .finalizeFunc = NULL + }, + { + .name = "timediff", + .type = FUNCTION_TYPE_TIMEDIFF, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimeDiff, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeDiffFunction, + .finalizeFunc = NULL + }, + { + .name = "now", + .type = FUNCTION_TYPE_NOW, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = nowFunction, + .finalizeFunc = NULL + }, + { + .name = "today", + .type = FUNCTION_TYPE_TODAY, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = todayFunction, + .finalizeFunc = NULL + }, + { + .name = "timezone", + .type = FUNCTION_TYPE_TIMEZONE, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimezone, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timezoneFunction, + .finalizeFunc = NULL + }, + { + .name = "_rowts", + .type = FUNCTION_TYPE_ROWTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "tbname", + .type = FUNCTION_TYPE_TBNAME, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, + .translateFunc = translateTbnameColumn, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = NULL, + .finalizeFunc = NULL + }, + { + .name = "_qstartts", + .type = FUNCTION_TYPE_QSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = qStartTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_qendts", + .type = FUNCTION_TYPE_QENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = qEndTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_wstartts", + .type = FUNCTION_TYPE_WSTARTTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winStartTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_wendts", + .type = FUNCTION_TYPE_WENDTS, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateTimePseudoColumn, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winEndTsFunction, + .finalizeFunc = NULL + }, + { + .name = "_wduration", + .type = FUNCTION_TYPE_WDURATION, + .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, + .translateFunc = translateWduration, + .getEnvFunc = getTimePseudoFuncEnv, + .initFunc = NULL, + .sprocessFunc = winDurFunction, + .finalizeFunc = NULL + }, + { + .name = "to_json", + .type = FUNCTION_TYPE_TO_JSON, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToJson, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toJsonFunction, + .finalizeFunc = NULL + } +}; +// clang-format on const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 0b9765ef15036c7744fe9693249a915812f23541..bb01af420da855be5c4d89cf48b1d31a58f800cd 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -36,27 +36,33 @@ typedef struct SAvgRes { typedef struct STopBotResItem { SVariant v; - uint64_t uid; // it is a table uid, used to extract tag data during building of the final result for the tag data + uint64_t uid; // it is a table uid, used to extract tag data during building of the final result for the tag data struct { - int32_t pageId; - int32_t offset; - } tuplePos; // tuple data of this chosen row + int32_t pageId; + int32_t offset; + } tuplePos; // tuple data of this chosen row } STopBotResItem; typedef struct STopBotRes { - STopBotResItem *pItems; + STopBotResItem* pItems; } STopBotRes; typedef struct SStddevRes { double result; int64_t count; - union {double quadraticDSum; int64_t quadraticISum;}; - union {double dsum; int64_t isum;}; + union { + double quadraticDSum; + int64_t quadraticISum; + }; + union { + double dsum; + int64_t isum; + }; } SStddevRes; typedef struct SPercentileInfo { double result; - tMemBucket *pMemBucket; + tMemBucket* pMemBucket; int32_t stage; double minval; double maxval; @@ -64,19 +70,29 @@ typedef struct SPercentileInfo { } SPercentileInfo; typedef struct SDiffInfo { - bool hasPrev; - bool includeNull; - bool ignoreNegative; - bool firstOutput; - union { int64_t i64; double d64;} prev; + bool hasPrev; + bool includeNull; + bool ignoreNegative; + bool firstOutput; + union { + int64_t i64; + double d64; + } prev; } SDiffInfo; -#define SET_VAL(_info, numOfElem, res) \ - do { \ - if ((numOfElem) <= 0) { \ - break; \ - } \ - (_info)->numOfRes = (res); \ +typedef struct SSpreadInfo { + double result; + bool hasResult; + double min; + double max; +} SSpreadInfo; + +#define SET_VAL(_info, numOfElem, res) \ + do { \ + if ((numOfElem) <= 0) { \ + break; \ + } \ + (_info)->numOfRes = (res); \ } while (0) #define GET_TS_LIST(x) ((TSKEY*)((x)->ptsList)) @@ -85,7 +101,7 @@ typedef struct SDiffInfo { #define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \ do { \ for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \ - SqlFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[_i]; \ + SqlFunctionCtx* __ctx = (ctx)->tagInfo.pTagCtxList[_i]; \ __ctx->fpSet.process(__ctx); \ } \ } while (0); @@ -101,7 +117,7 @@ typedef struct SDiffInfo { #define LOOPCHECK_N(val, _col, ctx, _t, _nrow, _start, sign, num) \ do { \ - _t *d = (_t *)((_col)->pData); \ + _t* d = (_t*)((_col)->pData); \ for (int32_t i = (_start); i < (_nrow) + (_start); ++i) { \ if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \ continue; \ @@ -111,8 +127,7 @@ typedef struct SDiffInfo { } \ } while (0) - -bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { +bool functionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (pResultInfo->initialized) { return false; } @@ -126,12 +141,12 @@ bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { } int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { - int32_t slotId = pCtx->pExpr->base.resSchema.slotId; + int32_t slotId = pCtx->pExpr->base.resSchema.slotId; SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - pResInfo->isNullRes = (pResInfo->numOfRes == 0)? 1:0; - cleanupResultRowEntry(pResInfo); + pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; + /*cleanupResultRowEntry(pResInfo);*/ char* in = GET_ROWCELL_INTERBUF(pResInfo); colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes); @@ -139,6 +154,20 @@ int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return pResInfo->numOfRes; } +int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, char* finalResult) { + int32_t slotId = pCtx->pExpr->base.resSchema.slotId; + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); + + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; + cleanupResultRowEntry(pResInfo); + + char* in = finalResult; + colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes); + + return pResInfo->numOfRes; +} + EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); if (QUERY_NODE_COLUMN == nodeType(pParam) && PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pParam)->colId) { @@ -156,7 +185,7 @@ bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { * count function does need the finalize, if data is missing, the default value, which is 0, is used * count function does not use the pCtx->interResBuf to keep the intermediate buffer */ -int32_t countFunction(SqlFunctionCtx *pCtx) { +int32_t countFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; /* @@ -165,7 +194,7 @@ int32_t countFunction(SqlFunctionCtx *pCtx) { * 3. for primary key column, pInputCol->hasNull always be false, pInput->colDataAggIsSet == false; */ SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pInputCol = pInput->pData[0]; + SColumnInfoData* pInputCol = pInput->pData[0]; if (pInput->colDataAggIsSet && pInput->totalRows == pInput->numOfRows) { numOfElem = pInput->numOfRows - pInput->pColumnDataAgg[0]->numOfNull; ASSERT(numOfElem >= 0); @@ -178,14 +207,15 @@ int32_t countFunction(SqlFunctionCtx *pCtx) { numOfElem += 1; } } else { - //when counting on the primary time stamp column and no statistics data is presented, use the size value directly. + // when counting on the primary time stamp column and no statistics data is presented, use the size value + // directly. numOfElem = pInput->numOfRows; } } SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - char* buf = GET_ROWCELL_INTERBUF(pResInfo); - *((int64_t *)buf) += numOfElem; + char* buf = GET_ROWCELL_INTERBUF(pResInfo); + *((int64_t*)buf) += numOfElem; SET_VAL(pResInfo, numOfElem, 1); return TSDB_CODE_SUCCESS; @@ -193,7 +223,7 @@ int32_t countFunction(SqlFunctionCtx *pCtx) { #define LIST_ADD_N(_res, _col, _start, _rows, _t, numOfElem) \ do { \ - _t *d = (_t *)(_col->pData); \ + _t* d = (_t*)(_col->pData); \ for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \ if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \ continue; \ @@ -203,13 +233,13 @@ int32_t countFunction(SqlFunctionCtx *pCtx) { } \ } while (0) -int32_t sumFunction(SqlFunctionCtx *pCtx) { +int32_t sumFunction(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; // Only the pre-computing information loaded and actual data does not loaded SInputColumnInfoData* pInput = &pCtx->input; - SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0]; - int32_t type = pInput->pData[0]->info.type; + SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0]; + int32_t type = pInput->pData[0]->info.type; SSumRes* pSumRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); @@ -227,7 +257,7 @@ int32_t sumFunction(SqlFunctionCtx *pCtx) { } else { // computing based on the true data block SColumnInfoData* pCol = pInput->pData[0]; - int32_t start = pInput->startRowIndex; + int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { @@ -272,7 +302,7 @@ bool getAvgFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { return true; } -bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { +bool avgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; } @@ -299,21 +329,21 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { switch (type) { case TSDB_DATA_TYPE_TINYINT: { - int8_t* plist = (int8_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; - pAvgRes->sum.isum += plist[i]; + int8_t* plist = (int8_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; } - break; + numOfElem += 1; + pAvgRes->count += 1; + pAvgRes->sum.isum += plist[i]; } - case TSDB_DATA_TYPE_SMALLINT: { + break; + } + + case TSDB_DATA_TYPE_SMALLINT: { int16_t* plist = (int16_t*)pCol->pData; for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { @@ -395,22 +425,22 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SInputColumnInfoData* pInput = &pCtx->input; - int32_t type = pInput->pData[0]->info.type; - SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + int32_t type = pInput->pData[0]->info.type; + SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); if (IS_INTEGER_TYPE(type)) { - pAvgRes->result = pAvgRes->sum.isum / ((double) pAvgRes->count); + pAvgRes->result = pAvgRes->sum.isum / ((double)pAvgRes->count); } else { - pAvgRes->result = pAvgRes->sum.dsum / ((double) pAvgRes->count); + pAvgRes->result = pAvgRes->sum.dsum / ((double)pAvgRes->count); } return functionFinalize(pCtx, pBlock); } -EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow){ +EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { return FUNC_DATA_REQUIRED_STATIS_LOAD; } -bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { +bool maxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; } @@ -418,34 +448,34 @@ bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { char* buf = GET_ROWCELL_INTERBUF(pResultInfo); switch (pCtx->resDataInfo.type) { case TSDB_DATA_TYPE_INT: - *((int32_t *)buf) = INT32_MIN; + *((int32_t*)buf) = INT32_MIN; break; case TSDB_DATA_TYPE_UINT: - *((uint32_t *)buf) = 0; + *((uint32_t*)buf) = 0; break; case TSDB_DATA_TYPE_FLOAT: - *((float *)buf) = -FLT_MAX; + *((float*)buf) = -FLT_MAX; break; case TSDB_DATA_TYPE_DOUBLE: - SET_DOUBLE_VAL(((double *)buf), -DBL_MAX); + SET_DOUBLE_VAL(((double*)buf), -DBL_MAX); break; case TSDB_DATA_TYPE_BIGINT: - *((int64_t *)buf) = INT64_MIN; + *((int64_t*)buf) = INT64_MIN; break; case TSDB_DATA_TYPE_UBIGINT: - *((uint64_t *)buf) = 0; + *((uint64_t*)buf) = 0; break; case TSDB_DATA_TYPE_SMALLINT: - *((int16_t *)buf) = INT16_MIN; + *((int16_t*)buf) = INT16_MIN; break; case TSDB_DATA_TYPE_USMALLINT: - *((uint16_t *)buf) = 0; + *((uint16_t*)buf) = 0; break; case TSDB_DATA_TYPE_TINYINT: - *((int8_t *)buf) = INT8_MIN; + *((int8_t*)buf) = INT8_MIN; break; case TSDB_DATA_TYPE_UTINYINT: - *((uint8_t *)buf) = 0; + *((uint8_t*)buf) = 0; break; case TSDB_DATA_TYPE_BOOL: *((int8_t*)buf) = 0; @@ -456,7 +486,7 @@ bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { return true; } -bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { +bool minFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; // not initialized since it has been initialized } @@ -464,34 +494,34 @@ bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { char* buf = GET_ROWCELL_INTERBUF(pResultInfo); switch (pCtx->resDataInfo.type) { case TSDB_DATA_TYPE_TINYINT: - *((int8_t *)buf) = INT8_MAX; + *((int8_t*)buf) = INT8_MAX; break; case TSDB_DATA_TYPE_UTINYINT: - *(uint8_t *) buf = UINT8_MAX; + *(uint8_t*)buf = UINT8_MAX; break; case TSDB_DATA_TYPE_SMALLINT: - *((int16_t *)buf) = INT16_MAX; + *((int16_t*)buf) = INT16_MAX; break; case TSDB_DATA_TYPE_USMALLINT: - *((uint16_t *)buf) = UINT16_MAX; + *((uint16_t*)buf) = UINT16_MAX; break; case TSDB_DATA_TYPE_INT: - *((int32_t *)buf) = INT32_MAX; + *((int32_t*)buf) = INT32_MAX; break; case TSDB_DATA_TYPE_UINT: - *((uint32_t *)buf) = UINT32_MAX; + *((uint32_t*)buf) = UINT32_MAX; break; case TSDB_DATA_TYPE_BIGINT: - *((int64_t *)buf) = INT64_MAX; + *((int64_t*)buf) = INT64_MAX; break; case TSDB_DATA_TYPE_UBIGINT: - *((uint64_t *)buf) = UINT64_MAX; + *((uint64_t*)buf) = UINT64_MAX; break; case TSDB_DATA_TYPE_FLOAT: - *((float *)buf) = FLT_MAX; + *((float*)buf) = FLT_MAX; break; case TSDB_DATA_TYPE_DOUBLE: - SET_DOUBLE_VAL(((double *)buf), DBL_MAX); + SET_DOUBLE_VAL(((double*)buf), DBL_MAX); break; case TSDB_DATA_TYPE_BOOL: *((int8_t*)buf) = 1; @@ -514,21 +544,21 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { #define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \ do { \ for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \ - SqlFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[_i]; \ + SqlFunctionCtx* __ctx = (ctx)->tagInfo.pTagCtxList[_i]; \ __ctx->fpSet.process(__ctx); \ } \ } while (0); -#define DO_UPDATE_SUBSID_RES(ctx, ts) \ - do { \ +#define DO_UPDATE_SUBSID_RES(ctx, ts) \ + do { \ for (int32_t _i = 0; _i < (ctx)->subsidiaries.num; ++_i) { \ - SqlFunctionCtx* __ctx = (ctx)->subsidiaries.pCtx[_i]; \ - if (__ctx->functionId == FUNCTION_TS_DUMMY) { \ - __ctx->tag.i = (ts); \ - __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \ - } \ - __ctx->fpSet.process(__ctx); \ - } \ + SqlFunctionCtx* __ctx = (ctx)->subsidiaries.pCtx[_i]; \ + if (__ctx->functionId == FUNCTION_TS_DUMMY) { \ + __ctx->tag.i = (ts); \ + __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \ + } \ + __ctx->fpSet.process(__ctx); \ + } \ } while (0) #define UPDATE_DATA(ctx, left, right, num, sign, _ts) \ @@ -542,7 +572,7 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { #define LOOPCHECK_N(val, _col, ctx, _t, _nrow, _start, sign, num) \ do { \ - _t *d = (_t *)((_col)->pData); \ + _t* d = (_t*)((_col)->pData); \ for (int32_t i = (_start); i < (_nrow) + (_start); ++i) { \ if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \ continue; \ @@ -552,17 +582,17 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { } \ } while (0) -int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { +int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { int32_t numOfElems = 0; SInputColumnInfoData* pInput = &pCtx->input; - SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0]; + SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0]; SColumnInfoData* pCol = pInput->pData[0]; - int32_t type = pCol->info.type; + int32_t type = pCol->info.type; SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - char* buf = GET_ROWCELL_INTERBUF(pResInfo); + char* buf = GET_ROWCELL_INTERBUF(pResInfo); // data in current data block are qualified to the query if (pInput->colDataAggIsSet) { @@ -577,15 +607,15 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { int16_t index = 0; if (isMinFunc) { - tval = &pInput->pColumnDataAgg[0]->min; + tval = &pInput->pColumnDataAgg[0]->min; index = pInput->pColumnDataAgg[0]->minIndex; } else { - tval = &pInput->pColumnDataAgg[0]->max; + tval = &pInput->pColumnDataAgg[0]->max; index = pInput->pColumnDataAgg[0]->maxIndex; } // the index is the original position, not the relative position - TSKEY key = (pCtx->ptsList != NULL)? pCtx->ptsList[index]:TSKEY_INITIAL_VAL; + TSKEY key = (pCtx->ptsList != NULL) ? pCtx->ptsList[index] : TSKEY_INITIAL_VAL; if (IS_SIGNED_NUMERIC_TYPE(type)) { int64_t prev = 0; @@ -593,7 +623,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { int64_t val = GET_INT64_VAL(tval); if ((prev < val) ^ isMinFunc) { - *(int64_t*) buf = val; + *(int64_t*)buf = val; for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) { SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i]; if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor @@ -610,7 +640,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { uint64_t val = GET_UINT64_VAL(tval); if ((prev < val) ^ isMinFunc) { - *(uint64_t*) buf = val; + *(uint64_t*)buf = val; for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) { SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i]; if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor @@ -622,11 +652,11 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { } } } else if (type == TSDB_DATA_TYPE_DOUBLE) { - double val = GET_DOUBLE_VAL(tval); - UPDATE_DATA(pCtx, *(double*) buf, val, numOfElems, isMinFunc, key); + double val = GET_DOUBLE_VAL(tval); + UPDATE_DATA(pCtx, *(double*)buf, val, numOfElems, isMinFunc, key); } else if (type == TSDB_DATA_TYPE_FLOAT) { double val = GET_DOUBLE_VAL(tval); - UPDATE_DATA(pCtx, *(float*) buf, val, numOfElems, isMinFunc, key); + UPDATE_DATA(pCtx, *(float*)buf, val, numOfElems, isMinFunc, key); } return numOfElems; @@ -639,10 +669,10 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) { LOOPCHECK_N(*(int8_t*)buf, pCol, pCtx, int8_t, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_SMALLINT) { - LOOPCHECK_N(*(int16_t*) buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(int16_t*)buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_INT) { - int32_t *pData = (int32_t*)pCol->pData; - int32_t *val = (int32_t*) buf; + int32_t* pData = (int32_t*)pCol->pData; + int32_t* val = (int32_t*)buf; for (int32_t i = start; i < start + numOfRows; ++i) { if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) { @@ -651,7 +681,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { if ((*val < pData[i]) ^ isMinFunc) { *val = pData[i]; - TSKEY ts = (pCtx->ptsList != NULL)? GET_TS_DATA(pCtx, i) : 0; + TSKEY ts = (pCtx->ptsList != NULL) ? GET_TS_DATA(pCtx, i) : 0; DO_UPDATE_SUBSID_RES(pCtx, ts); } @@ -662,34 +692,34 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { qDebug("max value updated:%d", *retVal); #endif } else if (type == TSDB_DATA_TYPE_BIGINT) { - LOOPCHECK_N(*(int64_t*) buf, pCol, pCtx, int64_t, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(int64_t*)buf, pCol, pCtx, int64_t, numOfRows, start, isMinFunc, numOfElems); } } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { if (type == TSDB_DATA_TYPE_UTINYINT) { - LOOPCHECK_N(*(uint8_t*) buf, pCol, pCtx, uint8_t, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(uint8_t*)buf, pCol, pCtx, uint8_t, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_USMALLINT) { - LOOPCHECK_N(*(uint16_t*) buf, pCol, pCtx, uint16_t, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(uint16_t*)buf, pCol, pCtx, uint16_t, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_UINT) { - LOOPCHECK_N(*(uint32_t*) buf, pCol, pCtx, uint32_t, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(uint32_t*)buf, pCol, pCtx, uint32_t, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_UBIGINT) { - LOOPCHECK_N(*(uint64_t*) buf, pCol, pCtx, uint64_t, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(uint64_t*)buf, pCol, pCtx, uint64_t, numOfRows, start, isMinFunc, numOfElems); } } else if (type == TSDB_DATA_TYPE_DOUBLE) { - LOOPCHECK_N(*(double*) buf, pCol, pCtx, double, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(double*)buf, pCol, pCtx, double, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_FLOAT) { - LOOPCHECK_N(*(float*) buf, pCol, pCtx, float, numOfRows, start, isMinFunc, numOfElems); + LOOPCHECK_N(*(float*)buf, pCol, pCtx, float, numOfRows, start, isMinFunc, numOfElems); } return numOfElems; } -int32_t minFunction(SqlFunctionCtx *pCtx) { +int32_t minFunction(SqlFunctionCtx* pCtx) { int32_t numOfElems = doMinMaxHelper(pCtx, 1); SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); return TSDB_CODE_SUCCESS; } -int32_t maxFunction(SqlFunctionCtx *pCtx) { +int32_t maxFunction(SqlFunctionCtx* pCtx) { int32_t numOfElems = doMinMaxHelper(pCtx, 0); SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); return TSDB_CODE_SUCCESS; @@ -700,7 +730,7 @@ bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { return true; } -bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { +bool stddevFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; } @@ -727,22 +757,22 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { switch (type) { case TSDB_DATA_TYPE_TINYINT: { - int8_t* plist = (int8_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; - pStddevRes->isum += plist[i]; - pStddevRes->quadraticISum += plist[i] * plist[i]; + int8_t* plist = (int8_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + start; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; } - break; + numOfElem += 1; + pStddevRes->count += 1; + pStddevRes->isum += plist[i]; + pStddevRes->quadraticISum += plist[i] * plist[i]; } - case TSDB_DATA_TYPE_SMALLINT: { + break; + } + + case TSDB_DATA_TYPE_SMALLINT: { int16_t* plist = (int16_t*)pCol->pData; for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { @@ -829,15 +859,15 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SInputColumnInfoData* pInput = &pCtx->input; - int32_t type = pInput->pData[0]->info.type; - SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - double avg; + int32_t type = pInput->pData[0]->info.type; + SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + double avg; if (IS_INTEGER_TYPE(type)) { - avg = pStddevRes->isum / ((double) pStddevRes->count); - pStddevRes->result = sqrt(pStddevRes->quadraticISum/((double)pStddevRes->count) - avg*avg); + avg = pStddevRes->isum / ((double)pStddevRes->count); + pStddevRes->result = sqrt(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg); } else { - avg = pStddevRes->dsum / ((double) pStddevRes->count); - pStddevRes->result = sqrt(pStddevRes->quadraticDSum/((double)pStddevRes->count) - avg*avg); + avg = pStddevRes->dsum / ((double)pStddevRes->count); + pStddevRes->result = sqrt(pStddevRes->quadraticDSum / ((double)pStddevRes->count) - avg * avg); } return functionFinalize(pCtx, pBlock); @@ -848,13 +878,13 @@ bool getPercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { return true; } -bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { +bool percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; } // in the first round, get the min-max value of all involved data - SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResultInfo); + SPercentileInfo* pInfo = GET_ROWCELL_INTERBUF(pResultInfo); SET_DOUBLE_VAL(&pInfo->minval, DBL_MAX); SET_DOUBLE_VAL(&pInfo->maxval, -DBL_MAX); pInfo->numOfElems = 0; @@ -862,17 +892,17 @@ bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultI return true; } -int32_t percentileFunction(SqlFunctionCtx *pCtx) { - int32_t notNullElems = 0; - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); +int32_t percentileFunction(SqlFunctionCtx* pCtx) { + int32_t notNullElems = 0; + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); SInputColumnInfoData* pInput = &pCtx->input; - SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0]; + SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0]; - SColumnInfoData *pCol = pInput->pData[0]; - int32_t type = pCol->info.type; + SColumnInfoData* pCol = pInput->pData[0]; + int32_t type = pCol->info.type; - SPercentileInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo); + SPercentileInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo); if (pCtx->currentStage == REPEAT_SCAN && pInfo->stage == 0) { pInfo->stage += 1; @@ -917,7 +947,7 @@ int32_t percentileFunction(SqlFunctionCtx *pCtx) { continue; } - char *data = colDataGetData(pCol, i); + char* data = colDataGetData(pCol, i); double v = 0; GET_TYPED_DATA(v, double, pCtx->inputType, data); @@ -943,7 +973,7 @@ int32_t percentileFunction(SqlFunctionCtx *pCtx) { continue; } - char *data = colDataGetData(pCol, i); + char* data = colDataGetData(pCol, i); notNullElems += 1; tMemBucketPut(pInfo->pMemBucket, data, 1); @@ -955,12 +985,12 @@ int32_t percentileFunction(SqlFunctionCtx *pCtx) { int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SVariant* pVal = &pCtx->param[1].param; - double v = pVal->nType == TSDB_DATA_TYPE_INT ? pVal->i : pVal->d; + double v = pVal->nType == TSDB_DATA_TYPE_INT ? pVal->i : pVal->d; - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - SPercentileInfo* ppInfo = (SPercentileInfo *) GET_ROWCELL_INTERBUF(pResInfo); + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SPercentileInfo* ppInfo = (SPercentileInfo*)GET_ROWCELL_INTERBUF(pResInfo); - tMemBucket * pMemBucket = ppInfo->pMemBucket; + tMemBucket* pMemBucket = ppInfo->pMemBucket; if (pMemBucket != NULL && pMemBucket->total > 0) { // check for null SET_DOUBLE_VAL(&ppInfo->result, getPercentile(pMemBucket, v)); } @@ -980,19 +1010,19 @@ static FORCE_INLINE TSKEY getRowPTs(SColumnInfoData* pTsColInfo, int32_t rowInde return 0; } - return *(TSKEY*) colDataGetData(pTsColInfo, rowIndex); + return *(TSKEY*)colDataGetData(pTsColInfo, rowIndex); } // This ordinary first function does not care if current scan is ascending order or descending order scan // the OPTIMIZED version of first function will only handle the ascending order scan -int32_t firstFunction(SqlFunctionCtx *pCtx) { +int32_t firstFunction(SqlFunctionCtx* pCtx) { int32_t numOfElems = 0; - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - char* buf = GET_ROWCELL_INTERBUF(pResInfo); + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + char* buf = GET_ROWCELL_INTERBUF(pResInfo); SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pInputCol = pInput->pData[0]; + SColumnInfoData* pInputCol = pInput->pData[0]; int32_t bytes = pInputCol->info.bytes; @@ -1002,12 +1032,12 @@ int32_t firstFunction(SqlFunctionCtx *pCtx) { return 0; } - SColumnDataAgg* pColAgg = (pInput->colDataAggIsSet)? pInput->pColumnDataAgg[0]:NULL; + SColumnDataAgg* pColAgg = (pInput->colDataAggIsSet) ? pInput->pColumnDataAgg[0] : NULL; TSKEY startKey = getRowPTs(pInput->pPTS, 0); TSKEY endKey = getRowPTs(pInput->pPTS, pInput->totalRows - 1); - int32_t blockDataOrder = (startKey <= endKey)? TSDB_ORDER_ASC:TSDB_ORDER_DESC; + int32_t blockDataOrder = (startKey <= endKey) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; if (blockDataOrder == TSDB_ORDER_ASC) { // filter according to current result firstly @@ -1031,7 +1061,7 @@ int32_t firstFunction(SqlFunctionCtx *pCtx) { if (pResInfo->numOfRes == 0 || *(TSKEY*)(buf + bytes) > cts) { memcpy(buf, data, bytes); *(TSKEY*)(buf + bytes) = cts; -// DO_UPDATE_TAG_COLUMNS(pCtx, ts); + // DO_UPDATE_TAG_COLUMNS(pCtx, ts); pResInfo->numOfRes = 1; break; @@ -1060,7 +1090,7 @@ int32_t firstFunction(SqlFunctionCtx *pCtx) { if (pResInfo->numOfRes == 0 || *(TSKEY*)(buf + bytes) > cts) { memcpy(buf, data, bytes); *(TSKEY*)(buf + bytes) = cts; -// DO_UPDATE_TAG_COLUMNS(pCtx, ts); + // DO_UPDATE_TAG_COLUMNS(pCtx, ts); pResInfo->numOfRes = 1; break; } @@ -1071,14 +1101,14 @@ int32_t firstFunction(SqlFunctionCtx *pCtx) { return TSDB_CODE_SUCCESS; } -int32_t lastFunction(SqlFunctionCtx *pCtx) { +int32_t lastFunction(SqlFunctionCtx* pCtx) { int32_t numOfElems = 0; - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - char* buf = GET_ROWCELL_INTERBUF(pResInfo); + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + char* buf = GET_ROWCELL_INTERBUF(pResInfo); SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pInputCol = pInput->pData[0]; + SColumnInfoData* pInputCol = pInput->pData[0]; int32_t bytes = pInputCol->info.bytes; @@ -1088,12 +1118,12 @@ int32_t lastFunction(SqlFunctionCtx *pCtx) { return 0; } - SColumnDataAgg* pColAgg = (pInput->colDataAggIsSet)? pInput->pColumnDataAgg[0]:NULL; + SColumnDataAgg* pColAgg = (pInput->colDataAggIsSet) ? pInput->pColumnDataAgg[0] : NULL; TSKEY startKey = getRowPTs(pInput->pPTS, 0); TSKEY endKey = getRowPTs(pInput->pPTS, pInput->totalRows - 1); - int32_t blockDataOrder = (startKey <= endKey)? TSDB_ORDER_ASC:TSDB_ORDER_DESC; + int32_t blockDataOrder = (startKey <= endKey) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; if (blockDataOrder == TSDB_ORDER_ASC) { for (int32_t i = pInput->numOfRows + pInput->startRowIndex - 1; i >= pInput->startRowIndex; --i) { @@ -1127,7 +1157,7 @@ int32_t lastFunction(SqlFunctionCtx *pCtx) { memcpy(buf, data, bytes); *(TSKEY*)(buf + bytes) = cts; pResInfo->numOfRes = 1; -// DO_UPDATE_TAG_COLUMNS(pCtx, ts); + // DO_UPDATE_TAG_COLUMNS(pCtx, ts); } break; } @@ -1142,43 +1172,42 @@ bool getDiffFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { return true; } -bool diffFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo) { +bool diffFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { if (!functionSetup(pCtx, pResInfo)) { return false; } SDiffInfo* pDiffInfo = GET_ROWCELL_INTERBUF(pResInfo); - pDiffInfo->hasPrev = false; + pDiffInfo->hasPrev = false; pDiffInfo->prev.i64 = 0; - pDiffInfo->ignoreNegative = false; // TODO set correct param + pDiffInfo->ignoreNegative = false; // TODO set correct param pDiffInfo->includeNull = false; pDiffInfo->firstOutput = false; return true; } -int32_t diffFunction(SqlFunctionCtx *pCtx) { - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - SDiffInfo *pDiffInfo = GET_ROWCELL_INTERBUF(pResInfo); +int32_t diffFunction(SqlFunctionCtx* pCtx) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SDiffInfo* pDiffInfo = GET_ROWCELL_INTERBUF(pResInfo); SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pInputCol = pInput->pData[0]; + SColumnInfoData* pInputCol = pInput->pData[0]; - bool isFirstBlock = (pDiffInfo->hasPrev == false); + bool isFirstBlock = (pDiffInfo->hasPrev == false); int32_t numOfElems = 0; int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order); -// int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1; + // int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1; SColumnInfoData* pTsOutput = pCtx->pTsOutput; - TSKEY* tsList = (int64_t*)pInput->pPTS->pData; + TSKEY* tsList = (int64_t*)pInput->pPTS->pData; int32_t startOffset = pCtx->offset; switch (pInputCol->info.type) { case TSDB_DATA_TYPE_INT: { - SColumnInfoData *pOutput = (SColumnInfoData *)pCtx->pOutput; + SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput; for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += step) { - - int32_t pos = startOffset + (isFirstBlock? (numOfElems-1):numOfElems); + int32_t pos = startOffset + (isFirstBlock ? (numOfElems - 1) : numOfElems); if (colDataIsNull_f(pInputCol->nullbitmap, i)) { if (pDiffInfo->includeNull) { colDataSetNull_f(pOutput->nullbitmap, pos); @@ -1191,7 +1220,7 @@ int32_t diffFunction(SqlFunctionCtx *pCtx) { continue; } - int32_t v = *(int32_t*) colDataGetData(pInputCol, i); + int32_t v = *(int32_t*)colDataGetData(pInputCol, i); if (pDiffInfo->hasPrev) { int32_t delta = (int32_t)(v - pDiffInfo->prev.i64); // direct previous may be null if (delta < 0 && pDiffInfo->ignoreNegative) { @@ -1206,14 +1235,14 @@ int32_t diffFunction(SqlFunctionCtx *pCtx) { } pDiffInfo->prev.i64 = v; - pDiffInfo->hasPrev = true; + pDiffInfo->hasPrev = true; numOfElems++; } break; } case TSDB_DATA_TYPE_BIGINT: { - SColumnInfoData *pOutput = (SColumnInfoData *)pCtx->pOutput; + SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput; for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += step) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; @@ -1221,17 +1250,17 @@ int32_t diffFunction(SqlFunctionCtx *pCtx) { int32_t v = 0; if (pDiffInfo->hasPrev) { - v = *(int64_t*) colDataGetData(pInputCol, i); + v = *(int64_t*)colDataGetData(pInputCol, i); int64_t delta = (int64_t)(v - pDiffInfo->prev.i64); // direct previous may be null if (pDiffInfo->ignoreNegative) { continue; } -// *(pOutput++) = delta; -// *pTimestamp = (tsList != NULL)? tsList[i]:0; -// -// pOutput += 1; -// pTimestamp += 1; + // *(pOutput++) = delta; + // *pTimestamp = (tsList != NULL)? tsList[i]:0; + // + // pOutput += 1; + // pTimestamp += 1; } pDiffInfo->prev.i64 = v; @@ -1345,7 +1374,7 @@ int32_t diffFunction(SqlFunctionCtx *pCtx) { #endif default: break; -// qError("error input type"); + // qError("error input type"); } // initial value is not set yet @@ -1357,12 +1386,12 @@ int32_t diffFunction(SqlFunctionCtx *pCtx) { assert(pCtx->hasNull); return 0; } else { -// for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) { -// SqlFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t]; -// if (tagCtx->functionId == TSDB_FUNC_TAG_DUMMY) { -// aAggs[TSDB_FUNC_TAGPRJ].xFunction(tagCtx); -// } -// } + // for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) { + // SqlFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t]; + // if (tagCtx->functionId == TSDB_FUNC_TAG_DUMMY) { + // aAggs[TSDB_FUNC_TAGPRJ].xFunction(tagCtx); + // } + // } int32_t forwardStep = (isFirstBlock) ? numOfElems - 1 : numOfElems; return forwardStep; @@ -1370,35 +1399,35 @@ int32_t diffFunction(SqlFunctionCtx *pCtx) { } bool getTopBotFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { - SValueNode* pkNode = (SValueNode*) nodesListGetNode(pFunc->pParameterList, 1); + SValueNode* pkNode = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 1); pEnv->calcMemSize = sizeof(STopBotRes) + pkNode->datum.i * sizeof(STopBotResItem); return true; } -static STopBotRes *getTopBotOutputInfo(SqlFunctionCtx *pCtx) { - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); - STopBotRes* pRes = GET_ROWCELL_INTERBUF(pResInfo); - pRes->pItems = (STopBotResItem*)((char*) pRes + sizeof(STopBotRes)); +static STopBotRes* getTopBotOutputInfo(SqlFunctionCtx* pCtx) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + STopBotRes* pRes = GET_ROWCELL_INTERBUF(pResInfo); + pRes->pItems = (STopBotResItem*)((char*)pRes + sizeof(STopBotRes)); return pRes; } -static void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock, - uint16_t type, uint64_t uid, SResultRowEntryInfo* pEntryInfo); +static void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock, uint16_t type, + uint64_t uid, SResultRowEntryInfo* pEntryInfo); static void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem); static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem); -int32_t topFunction(SqlFunctionCtx *pCtx) { - int32_t numOfElems = 0; - SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); +int32_t topFunction(SqlFunctionCtx* pCtx) { + int32_t numOfElems = 0; + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); -// if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotRes) + POINTER_BYTES * pCtx->param[0].i)) { -// buildTopBotStruct(pRes, pCtx); -// } + // if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotRes) + POINTER_BYTES * pCtx->param[0].i)) { + // buildTopBotStruct(pRes, pCtx); + // } SInputColumnInfoData* pInput = &pCtx->input; - SColumnInfoData* pCol = pInput->pData[0]; + SColumnInfoData* pCol = pInput->pData[0]; int32_t type = pInput->pData[0]->info.type; @@ -1418,11 +1447,11 @@ int32_t topFunction(SqlFunctionCtx *pCtx) { return TSDB_CODE_SUCCESS; } -static int32_t topBotResComparFn(const void *p1, const void *p2, const void *param) { - uint16_t type = *(uint16_t *) param; +static int32_t topBotResComparFn(const void* p1, const void* p2, const void* param) { + uint16_t type = *(uint16_t*)param; - STopBotResItem *val1 = (STopBotResItem *) p1; - STopBotResItem *val2 = (STopBotResItem *) p2; + STopBotResItem* val1 = (STopBotResItem*)p1; + STopBotResItem* val2 = (STopBotResItem*)p2; if (IS_SIGNED_NUMERIC_TYPE(type)) { if (val1->v.i == val2->v.i) { @@ -1447,19 +1476,19 @@ static int32_t topBotResComparFn(const void *p1, const void *p2, const void *par void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock, uint16_t type, uint64_t uid, SResultRowEntryInfo* pEntryInfo) { - STopBotRes *pRes = getTopBotOutputInfo(pCtx); - int32_t maxSize = pCtx->param[1].param.i; + STopBotRes* pRes = getTopBotOutputInfo(pCtx); + int32_t maxSize = pCtx->param[1].param.i; SVariant val = {0}; taosVariantCreateFromBinary(&val, pData, tDataTypes[type].bytes, type); - STopBotResItem *pItems = pRes->pItems; + STopBotResItem* pItems = pRes->pItems; assert(pItems != NULL); // not full yet if (pEntryInfo->numOfRes < maxSize) { STopBotResItem* pItem = &pItems[pEntryInfo->numOfRes]; - pItem->v = val; + pItem->v = val; pItem->uid = uid; // save the data of this tuple @@ -1467,20 +1496,21 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData // allocate the buffer and keep the data of this row into the new allocated buffer pEntryInfo->numOfRes++; - taosheapsort((void *) pItems, sizeof(STopBotResItem), pEntryInfo->numOfRes, (const void *) &type, topBotResComparFn, false); - } else { // replace the minimum value in the result + taosheapsort((void*)pItems, sizeof(STopBotResItem), pEntryInfo->numOfRes, (const void*)&type, topBotResComparFn, + false); + } else { // replace the minimum value in the result if ((IS_SIGNED_NUMERIC_TYPE(type) && val.i > pItems[0].v.i) || - (IS_UNSIGNED_NUMERIC_TYPE(type) && val.u > pItems[0].v.u) || - (IS_FLOAT_TYPE(type) && val.d > pItems[0].v.d)) { + (IS_UNSIGNED_NUMERIC_TYPE(type) && val.u > pItems[0].v.u) || (IS_FLOAT_TYPE(type) && val.d > pItems[0].v.d)) { // replace the old data and the coresponding tuple data STopBotResItem* pItem = &pItems[0]; - pItem->v = val; + pItem->v = val; pItem->uid = uid; // save the data of this tuple by over writing the old data copyTupleData(pCtx, rowIndex, pSrcBlock, pItem); - taosheapadjust((void *) pItems, sizeof(STopBotResItem), 0, pEntryInfo->numOfRes - 1, (const void *) &type, topBotResComparFn, NULL, false); + taosheapadjust((void*)pItems, sizeof(STopBotResItem), 0, pEntryInfo->numOfRes - 1, (const void*)&type, + topBotResComparFn, NULL, false); } } } @@ -1539,7 +1569,7 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS char* pStart = (char*)(nullList + pSrcBlock->info.numOfCols * sizeof(bool)); int32_t offset = 0; - for(int32_t i = 0; i < pSrcBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < pSrcBlock->info.numOfCols; ++i) { SColumnInfoData* pCol = taosArrayGet(pSrcBlock->pDataBlock, i); if ((nullList[i] = colDataIsNull_s(pCol, rowIndex)) == true) { continue; @@ -1560,17 +1590,17 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS } int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { - SResultRowEntryInfo *pEntryInfo = GET_RES_INFO(pCtx); - STopBotRes* pRes = GET_ROWCELL_INTERBUF(pEntryInfo); + SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx); + STopBotRes* pRes = GET_ROWCELL_INTERBUF(pEntryInfo); pEntryInfo->complete = true; - int32_t type = pCtx->input.pData[0]->info.type; - int32_t slotId = pCtx->pExpr->base.resSchema.slotId; + int32_t type = pCtx->input.pData[0]->info.type; + int32_t slotId = pCtx->pExpr->base.resSchema.slotId; SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); // todo assign the tag value and the corresponding row data int32_t currentRow = pBlock->info.rows; - switch(type) { + switch (type) { case TSDB_DATA_TYPE_INT: { for (int32_t i = 0; i < pEntryInfo->numOfRes; ++i) { STopBotResItem* pItem = &pRes->pItems[i]; @@ -1588,12 +1618,12 @@ int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { for (int32_t j = 0; j < pCtx->subsidiaries.num; ++j) { SqlFunctionCtx* pc = pCtx->subsidiaries.pCtx[j]; - SFunctParam *pFuncParam = &pc->pExpr->base.pParam[0]; - int32_t srcSlotId = pFuncParam->pCol->slotId; - int32_t dstSlotId = pCtx->pExpr->base.resSchema.slotId; + SFunctParam* pFuncParam = &pc->pExpr->base.pParam[0]; + int32_t srcSlotId = pFuncParam->pCol->slotId; + int32_t dstSlotId = pCtx->pExpr->base.resSchema.slotId; int32_t ps = 0; - for(int32_t k = 0; k < srcSlotId; ++k) { + for (int32_t k = 0; k < srcSlotId; ++k) { SColumnInfoData* pSrcCol = taosArrayGet(pCtx->pSrcBlock->pDataBlock, k); ps += pSrcCol->info.bytes; } @@ -1616,3 +1646,101 @@ int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return pEntryInfo->numOfRes; } + +bool getSpreadFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { + pEnv->calcMemSize = sizeof(SSpreadInfo); + return true; +} + +bool spreadFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { + if (!functionSetup(pCtx, pResultInfo)) { + return false; + } + + SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(pResultInfo); + SET_DOUBLE_VAL(&pInfo->min, DBL_MAX); + SET_DOUBLE_VAL(&pInfo->max, -DBL_MAX); + pInfo->hasResult = false; + return true; +} + +int32_t spreadFunction(SqlFunctionCtx *pCtx) { + int32_t numOfElems = 0; + + // Only the pre-computing information loaded and actual data does not loaded + SInputColumnInfoData* pInput = &pCtx->input; + SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0]; + int32_t type = pInput->pData[0]->info.type; + + SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + + if (pInput->colDataAggIsSet) { + numOfElems = pInput->numOfRows - pAgg->numOfNull; + if (numOfElems == 0) { + goto _spread_over; + } + double tmin = 0.0, tmax = 0.0; + if (IS_SIGNED_NUMERIC_TYPE(type)) { + tmin = (double)GET_INT64_VAL(&pAgg->min); + tmax = (double)GET_INT64_VAL(&pAgg->max); + } else if (IS_FLOAT_TYPE(type)) { + tmin = GET_DOUBLE_VAL(&pAgg->min); + tmax = GET_DOUBLE_VAL(&pAgg->max); + } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { + tmin = (double)GET_UINT64_VAL(&pAgg->min); + tmax = (double)GET_UINT64_VAL(&pAgg->max); + } + + if (GET_DOUBLE_VAL(&pInfo->min) > tmin) { + SET_DOUBLE_VAL(&pInfo->min, tmin); + } + + if (GET_DOUBLE_VAL(&pInfo->max) < tmax) { + SET_DOUBLE_VAL(&pInfo->max, tmax); + } + + } else { // computing based on the true data block + SColumnInfoData* pCol = pInput->pData[0]; + + int32_t start = pInput->startRowIndex; + int32_t numOfRows = pInput->numOfRows; + + // check the valid data one by one + for (int32_t i = start; i < pInput->numOfRows + start; ++i) { + if (colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + char *data = colDataGetData(pCol, i); + + double v = 0; + GET_TYPED_DATA(v, double, type, data); + if (v < GET_DOUBLE_VAL(&pInfo->min)) { + SET_DOUBLE_VAL(&pInfo->min, v); + } + + if (v > GET_DOUBLE_VAL(&pInfo->max)) { + SET_DOUBLE_VAL(&pInfo->max, v); + } + + numOfElems += 1; + } + } + +_spread_over: + // data in the check operation are all null, not output + SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); + if (numOfElems > 0) { + pInfo->hasResult = true; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t spreadFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { + SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + if (pInfo->hasResult == true) { + SET_DOUBLE_VAL(&pInfo->result, pInfo->max - pInfo->min); + } + return functionFinalize(pCtx, pBlock); +} diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 72c7175c6d54070881e99af3a4226077bb6a885f..b505f2e8ec94922447364ef2dae6c17762ffb58f 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -21,6 +21,7 @@ #include "taos.h" #include "taoserror.h" #include "thash.h" +#include "tudf.h" typedef struct SFuncMgtService { SHashObj* pFuncNameHashTable; @@ -120,6 +121,17 @@ int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) { return TSDB_CODE_SUCCESS; } +int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) { + if (!fmIsUserDefinedFunc(funcId)) { + return TSDB_CODE_FAILED; + } + pFpSet->getEnv = udfAggGetEnv; + pFpSet->init = udfAggInit; + pFpSet->process = udfAggProcess; + pFpSet->finalize = udfAggFinalize; + return TSDB_CODE_SUCCESS; +} + int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet) { if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) { return TSDB_CODE_FAILED; @@ -133,6 +145,8 @@ bool fmIsAggFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MG bool fmIsScalarFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); } +bool fmIsTimelineFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_TIMELINE_FUNC); } + bool fmIsPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PSEUDO_COLUMN_FUNC); } bool fmIsScanPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCAN_PC_FUNC); } diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index f4a724afa375691be6ec2fba8487d74bc5966721..9aac2bfe0cce2587f3c45ed9957afac40ed746dd 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -19,6 +19,9 @@ #include "tudfInt.h" #include "tarray.h" #include "tdatablock.h" +#include "querynodes.h" +#include "builtinsimpl.h" +#include "functionMgt.h" //TODO: network error processing. //TODO: add unit test @@ -147,6 +150,10 @@ typedef struct SUdfUvSession { SUdfdProxy *udfc; int64_t severHandle; uv_pipe_t *udfSvcPipe; + + int8_t outputType; + int32_t outputLen; + int32_t bufSize; } SUdfUvSession; typedef struct SClientUvTaskNode { @@ -235,12 +242,14 @@ void* decodeUdfSetupRequest(const void* buf, SUdfSetupRequest *request) { int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf* state) { int32_t len = 0; + len += taosEncodeFixedI8(buf, state->numOfResult); len += taosEncodeFixedI32(buf, state->bufLen); len += taosEncodeBinary(buf, state->buf, state->bufLen); return len; } void* decodeUdfInterBuf(const void* buf, SUdfInterBuf* state) { + buf = taosDecodeFixedI8(buf, &state->numOfResult); buf = taosDecodeFixedI32(buf, &state->bufLen); buf = taosDecodeBinary(buf, (void**)&state->buf, state->bufLen); return (void*)buf; @@ -342,11 +351,17 @@ void* decodeUdfRequest(const void* buf, SUdfRequest* request) { int32_t encodeUdfSetupResponse(void **buf, const SUdfSetupResponse *setupRsp) { int32_t len = 0; len += taosEncodeFixedI64(buf, setupRsp->udfHandle); + len += taosEncodeFixedI8(buf, setupRsp->outputType); + len += taosEncodeFixedI32(buf, setupRsp->outputLen); + len += taosEncodeFixedI32(buf, setupRsp->bufSize); return len; } void* decodeUdfSetupResponse(const void* buf, SUdfSetupResponse* setupRsp) { buf = taosDecodeFixedI64(buf, &setupRsp->udfHandle); + buf = taosDecodeFixedI8(buf, &setupRsp->outputType); + buf = taosDecodeFixedI32(buf, &setupRsp->outputLen); + buf = taosDecodeFixedI32(buf, &setupRsp->bufSize); return (void*)buf; } @@ -1049,6 +1064,9 @@ int32_t setupUdf(char udfName[], UdfcFuncHandle *funcHandle) { SUdfSetupResponse *rsp = &task->_setup.rsp; task->session->severHandle = rsp->udfHandle; + task->session->outputType = rsp->outputType; + task->session->outputLen = rsp->outputLen; + task->session->bufSize = rsp->bufSize; if (task->errCode != 0) { fnError("failed to setup udf. err: %d", task->errCode) } else { @@ -1158,7 +1176,7 @@ int32_t callUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInte // input: interBuf // output: resultData int32_t callUdfAggFinalize(UdfcFuncHandle handle, SUdfInterBuf *interBuf, SUdfInterBuf *resultData) { - int8_t callType = TSDB_UDF_CALL_AGG_PROC; + int8_t callType = TSDB_UDF_CALL_AGG_FIN; int32_t err = callUdf(handle, callType, NULL, interBuf, NULL, NULL, resultData); return err; } @@ -1197,3 +1215,123 @@ int32_t teardownUdf(UdfcFuncHandle handle) { return err; } + +//memory layout |---SUdfAggRes----|-----final result-----|---inter result----| +typedef struct SUdfAggRes { + SUdfUvSession *session; + int8_t finalResNum; + int8_t interResNum; + char* finalResBuf; + char* interResBuf; +} SUdfAggRes; + +bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { + if (fmIsScalarFunc(pFunc->funcId)) { + return false; + } + pEnv->calcMemSize = sizeof(SUdfAggRes) + pFunc->node.resType.bytes + pFunc->udfBufSize; + return true; +} + +bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo) { + if (functionSetup(pCtx, pResultCellInfo) != true) { + return false; + } + UdfcFuncHandle handle; + if (setupUdf((char*)pCtx->udfName, &handle) != 0) { + return false; + } + SUdfUvSession *session = (SUdfUvSession *)handle; + SUdfAggRes *udfRes = (SUdfAggRes*)GET_ROWCELL_INTERBUF(pResultCellInfo); + int32_t envSize = sizeof(SUdfAggRes) + session->outputLen + session->bufSize; + memset(udfRes, 0, envSize); + + udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes); + udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen; + + udfRes->session = (SUdfUvSession *)handle; + SUdfInterBuf buf = {0}; + if (callUdfAggInit(handle, &buf) != 0) { + return false; + } + udfRes->interResNum = buf.numOfResult; + memcpy(udfRes->interResBuf, buf.buf, buf.bufLen); + return true; +} + +int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { + SInputColumnInfoData* pInput = &pCtx->input; + int32_t numOfCols = pInput->numOfInputCols; + + SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + SUdfUvSession *session = udfRes->session; + udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes); + udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen; + + int32_t start = pInput->startRowIndex; + int32_t numOfRows = pInput->numOfRows; + + + SSDataBlock tempBlock = {0}; + tempBlock.info.numOfCols = numOfCols; + tempBlock.info.rows = numOfRows; + tempBlock.info.uid = pInput->uid; + bool hasVarCol = false; + tempBlock.pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); + + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData *col = pInput->pData[i]; + if (IS_VAR_DATA_TYPE(col->info.type)) { + hasVarCol = true; + } + taosArrayPush(tempBlock.pDataBlock, col); + } + tempBlock.info.hasVarCol = hasVarCol; + + SSDataBlock *inputBlock = blockDataExtractBlock(&tempBlock, start, numOfRows); + + SUdfInterBuf state = {.buf = udfRes->interResBuf, + .bufLen = session->bufSize, + .numOfResult = udfRes->interResNum}; + SUdfInterBuf newState = {0}; + + callUdfAggProcess(session, inputBlock, &state, &newState); + + udfRes->interResNum = newState.numOfResult; + memcpy(udfRes->interResBuf, newState.buf, newState.bufLen); + + if (newState.numOfResult == 1 || state.numOfResult == 1) { + GET_RES_INFO(pCtx)->numOfRes = 1; + } + + blockDataDestroy(inputBlock); + + taosArrayDestroy(tempBlock.pDataBlock); + + taosMemoryFree(newState.buf); + return 0; +} + +int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) { + SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + SUdfUvSession *session = udfRes->session; + udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes); + udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen; + + + SUdfInterBuf resultBuf = {0}; + SUdfInterBuf state = {.buf = udfRes->interResBuf, + .bufLen = session->bufSize, + .numOfResult = udfRes->interResNum}; + callUdfAggFinalize(session, &state, &resultBuf); + + udfRes->finalResBuf = resultBuf.buf; + udfRes->finalResNum = resultBuf.numOfResult; + + teardownUdf(session); + + if (resultBuf.numOfResult == 1) { + GET_RES_INFO(pCtx)->numOfRes = 1; + } + return functionFinalizeWithResultBuf(pCtx, pBlock, udfRes->finalResBuf); +} \ No newline at end of file diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 11bbd6442ce8e02906f79b4aef1ab779df3bf006..06fa49e1c2d85b123522efe1fc7a2cf8880a5fa6 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -77,6 +77,10 @@ typedef struct SUdf { uv_lib_t lib; TUdfScalarProcFunc scalarProcFunc; TUdfFreeUdfColumnFunc freeUdfColumn; + + TUdfAggStartFunc aggStartFunc; + TUdfAggProcessFunc aggProcFunc; + TUdfAggFinishFunc aggFinishFunc; } SUdf; // TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix @@ -97,15 +101,32 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) { fnError("can not load library %s. error: %s", udf->path, uv_strerror(err)); return UDFC_CODE_LOAD_UDF_FAILURE; } - // TODO: find all the functions - char normalFuncName[TSDB_FUNC_NAME_LEN] = {0}; - strcpy(normalFuncName, udfName); - uv_dlsym(&udf->lib, normalFuncName, (void **)(&udf->scalarProcFunc)); - char freeFuncName[TSDB_FUNC_NAME_LEN + 6] = {0}; - char *freeSuffix = "_free"; - strncpy(freeFuncName, normalFuncName, strlen(normalFuncName)); - strncat(freeFuncName, freeSuffix, strlen(freeSuffix)); - uv_dlsym(&udf->lib, freeFuncName, (void **)(&udf->freeUdfColumn)); + //TODO: init and destroy function + if (udf->funcType == TSDB_FUNC_TYPE_SCALAR) { + char processFuncName[TSDB_FUNC_NAME_LEN] = {0}; + strcpy(processFuncName, udfName); + uv_dlsym(&udf->lib, processFuncName, (void **)(&udf->scalarProcFunc)); + char freeFuncName[TSDB_FUNC_NAME_LEN + 5] = {0}; + char *freeSuffix = "_free"; + strncpy(freeFuncName, processFuncName, strlen(processFuncName)); + strncat(freeFuncName, freeSuffix, strlen(freeSuffix)); + uv_dlsym(&udf->lib, freeFuncName, (void **)(&udf->freeUdfColumn)); + } else if (udf->funcType == TSDB_FUNC_TYPE_AGGREGATE) { + char processFuncName[TSDB_FUNC_NAME_LEN] = {0}; + strcpy(processFuncName, udfName); + uv_dlsym(&udf->lib, processFuncName, (void **)(&udf->aggProcFunc)); + char startFuncName[TSDB_FUNC_NAME_LEN + 6] = {0}; + char *startSuffix = "_start"; + strncpy(startFuncName, processFuncName, strlen(processFuncName)); + strncat(startFuncName, startSuffix, strlen(startSuffix)); + uv_dlsym(&udf->lib, startFuncName, (void **)(&udf->aggStartFunc)); + char finishFuncName[TSDB_FUNC_NAME_LEN + 7] = {0}; + char *finishSuffix = "_finish"; + strncpy(finishFuncName, processFuncName, strlen(processFuncName)); + strncat(finishFuncName, finishSuffix, strlen(finishSuffix)); + uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggFinishFunc)); + //TODO: merge + } return 0; } @@ -160,6 +181,9 @@ void udfdProcessRequest(uv_work_t *req) { rsp.type = request.type; rsp.code = 0; rsp.setupRsp.udfHandle = (int64_t)(handle); + rsp.setupRsp.outputType = udf->outputType; + rsp.setupRsp.outputLen = udf->outputLen; + rsp.setupRsp.bufSize = udf->bufSize; int32_t len = encodeUdfResponse(NULL, &rsp); rsp.msgLen = len; void *bufBegin = taosMemoryMalloc(len); @@ -178,26 +202,58 @@ void udfdProcessRequest(uv_work_t *req) { call->udfHandle); SUdfcFuncHandle *handle = (SUdfcFuncHandle *)(call->udfHandle); SUdf *udf = handle->udf; - - SUdfDataBlock input = {0}; - convertDataBlockToUdfDataBlock(&call->block, &input); - SUdfColumn output = {0}; - // TODO: call different functions according to call type, for now just calar - if (call->callType == TSDB_UDF_CALL_SCALA_PROC) { - udf->scalarProcFunc(input, &output); - } - SUdfResponse response = {0}; SUdfResponse *rsp = &response; - if (call->callType == TSDB_UDF_CALL_SCALA_PROC) { - rsp->seqNum = request.seqNum; - rsp->type = request.type; - rsp->code = 0; - SUdfCallResponse *subRsp = &rsp->callRsp; - subRsp->callType = call->callType; - convertUdfColumnToDataBlock(&output, &subRsp->resultData); + SUdfCallResponse *subRsp = &rsp->callRsp; + + switch(call->callType) { + case TSDB_UDF_CALL_SCALA_PROC: { + SUdfColumn output = {0}; + + SUdfDataBlock input = {0}; + convertDataBlockToUdfDataBlock(&call->block, &input); + udf->scalarProcFunc(&input, &output); + + convertUdfColumnToDataBlock(&output, &response.callRsp.resultData); + udf->freeUdfColumn(&output); + break; + } + case TSDB_UDF_CALL_AGG_INIT: { + SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize), + .bufLen= udf->bufSize, + .numOfResult = 0}; + udf->aggStartFunc(&outBuf); + subRsp->resultBuf = outBuf; + break; + } + case TSDB_UDF_CALL_AGG_PROC: { + SUdfDataBlock input = {0}; + convertDataBlockToUdfDataBlock(&call->block, &input); + SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize), + .bufLen= udf->bufSize, + .numOfResult = 0}; + udf->aggProcFunc(&input, &call->interBuf, &outBuf); + subRsp->resultBuf = outBuf; + + break; + } + case TSDB_UDF_CALL_AGG_FIN: { + SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize), + .bufLen= udf->bufSize, + .numOfResult = 0}; + udf->aggFinishFunc(&call->interBuf, &outBuf); + subRsp->resultBuf = outBuf; + break; + } + default: + break; } + rsp->seqNum = request.seqNum; + rsp->type = request.type; + rsp->code = 0; + subRsp->callType = call->callType; + int32_t len = encodeUdfResponse(NULL, rsp); rsp->msgLen = len; void *bufBegin = taosMemoryMalloc(len); @@ -205,9 +261,6 @@ void udfdProcessRequest(uv_work_t *req) { encodeUdfResponse(&buf, rsp); uvUdf->output = uv_buf_init(bufBegin, len); - // TODO: free udf column - udf->freeUdfColumn(&output); - taosMemoryFree(uvUdf->input.base); break; } diff --git a/source/libs/function/test/udf1.c b/source/libs/function/test/udf1.c index 94cab9fee96377c170c70d45ec9a85f29a4976e3..b2367313ae2fbada9f3cc4abb30b5d1cca8a3c88 100644 --- a/source/libs/function/test/udf1.c +++ b/source/libs/function/test/udf1.c @@ -9,18 +9,18 @@ #undef free #define free free -int32_t udf1_setup() { +int32_t udf1_init() { return 0; } -int32_t udf1_teardown() { +int32_t udf1_destroy() { return 0; } -int32_t udf1(SUdfDataBlock block, SUdfColumn *resultCol) { +int32_t udf1(SUdfDataBlock* block, SUdfColumn *resultCol) { SUdfColumnData *resultData = &resultCol->colData; - resultData->numOfRows = block.numOfRows; - SUdfColumnData *srcData = &block.udfCols[0]->colData; + resultData->numOfRows = block->numOfRows; + SUdfColumnData *srcData = &block->udfCols[0]->colData; resultData->varLengthColumn = srcData->varLengthColumn; if (resultData->varLengthColumn) { diff --git a/source/libs/function/test/udf2.c b/source/libs/function/test/udf2.c new file mode 100644 index 0000000000000000000000000000000000000000..69ed515d2bc4981c4e5adb6a1f71fae0b259626c --- /dev/null +++ b/source/libs/function/test/udf2.c @@ -0,0 +1,52 @@ +#include +#include +#include + +#include "tudf.h" + +#undef malloc +#define malloc malloc +#undef free +#define free free + +int32_t udf2_init() { + return 0; +} + +int32_t udf2_destroy() { + return 0; +} + +int32_t udf2_start(SUdfInterBuf *buf) { + *(int64_t*)(buf->buf) = 0; + buf->bufLen = sizeof(int64_t); + buf->numOfResult = 0; + return 0; +} + +int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) { + int64_t sumSquares = *(int64_t*)interBuf->buf; + for (int32_t i = 0; i < block->numOfCols; ++i) { + for (int32_t j = 0; j < block->numOfRows; ++j) { + SUdfColumn* col = block->udfCols[i]; + //TODO: check the bitmap for null value + int32_t* rows = (int32_t*)col->colData.fixLenCol.data; + sumSquares += rows[j] * rows[j]; + } + } + + *(int64_t*)(newInterBuf->buf) = sumSquares; + newInterBuf->bufLen = sizeof(int64_t); + //TODO: if all null value, numOfResult = 0; + newInterBuf->numOfResult = 1; + return 0; +} + +int32_t udf2_finish(SUdfInterBuf* buf, SUdfInterBuf *resultData) { + //TODO: check numOfResults; + int64_t sumSquares = *(int64_t*)(buf->buf); + *(double*)(resultData->buf) = sqrt(sumSquares); + resultData->bufLen = sizeof(double); + resultData->numOfResult = 1; + return 0; +} diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index f1fe68c55adaf74a07fa6618f7eb88ce2f42ace7..92da47631934471d83afc7499f06b7a4adff9c93 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -154,6 +154,7 @@ static SNode* logicConditionNodeCopy(const SLogicConditionNode* pSrc, SLogicCond } static SNode* functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) { + COPY_ALL_SCALAR_FIELDS; exprNodeCopy((const SExprNode*)pSrc, (SExprNode*)pDst); COPY_CHAR_ARRAY_FIELD(functionName); COPY_SCALAR_FIELD(funcId); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 0e6ec4f945af8ba7a920e25e3a0a1ffeb6cf387e..6dcd2a0bafda18716731617ae5dbe055474ffbd7 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -588,6 +588,259 @@ static int32_t jsonToLogicSortNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkPartitionLogicPlanPartitionKeys = "PartitionKeys"; + +static int32_t logicPartitionNodeToJson(const void* pObj, SJson* pJson) { + const SPartitionLogicNode* pNode = (const SPartitionLogicNode*)pObj; + + int32_t code = logicPlanNodeToJson(pObj, pJson); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkPartitionLogicPlanPartitionKeys, pNode->pPartitionKeys); + } + + return code; +} + +static int32_t jsonToLogicPartitionNode(const SJson* pJson, void* pObj) { + SPartitionLogicNode* pNode = (SPartitionLogicNode*)pObj; + + int32_t code = jsonToLogicPlanNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkPartitionLogicPlanPartitionKeys, &pNode->pPartitionKeys); + } + + return code; +} + +static const char* jkSubplanIdQueryId = "QueryId"; +static const char* jkSubplanIdGroupId = "GroupId"; +static const char* jkSubplanIdSubplanId = "SubplanId"; + +static int32_t subplanIdToJson(const void* pObj, SJson* pJson) { + const SSubplanId* pNode = (const SSubplanId*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkSubplanIdQueryId, pNode->queryId); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkSubplanIdGroupId, pNode->groupId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkSubplanIdSubplanId, pNode->subplanId); + } + + return code; +} + +static int32_t jsonToSubplanId(const SJson* pJson, void* pObj) { + SSubplanId* pNode = (SSubplanId*)pObj; + + int32_t code = tjsonGetUBigIntValue(pJson, jkSubplanIdQueryId, &pNode->queryId); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkSubplanIdGroupId, &pNode->groupId); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkSubplanIdSubplanId, &pNode->subplanId); + } + + return code; +} + +static const char* jkEndPointFqdn = "Fqdn"; +static const char* jkEndPointPort = "Port"; + +static int32_t epToJson(const void* pObj, SJson* pJson) { + const SEp* pNode = (const SEp*)pObj; + + int32_t code = tjsonAddStringToObject(pJson, jkEndPointFqdn, pNode->fqdn); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkEndPointPort, pNode->port); + } + + return code; +} + +static int32_t jsonToEp(const SJson* pJson, void* pObj) { + SEp* pNode = (SEp*)pObj; + + int32_t code = tjsonGetStringValue(pJson, jkEndPointFqdn, pNode->fqdn); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetSmallIntValue(pJson, jkEndPointPort, &pNode->port); + } + + return code; +} + +static const char* jkEpSetInUse = "InUse"; +static const char* jkEpSetNumOfEps = "NumOfEps"; +static const char* jkEpSetEps = "Eps"; + +static int32_t epSetToJson(const void* pObj, SJson* pJson) { + const SEpSet* pNode = (const SEpSet*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkEpSetInUse, pNode->inUse); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkEpSetNumOfEps, pNode->numOfEps); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddArray(pJson, jkEpSetEps, epToJson, pNode->eps, sizeof(SEp), pNode->numOfEps); + } + + return code; +} + +static int32_t jsonToEpSet(const SJson* pJson, void* pObj) { + SEpSet* pNode = (SEpSet*)pObj; + + int32_t code = tjsonGetTinyIntValue(pJson, jkEpSetInUse, &pNode->inUse); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetTinyIntValue(pJson, jkEpSetNumOfEps, &pNode->numOfEps); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonToArray(pJson, jkEpSetEps, jsonToEp, pNode->eps, sizeof(SEp)); + } + + return code; +} + +static const char* jkVgroupInfoVgId = "VgId"; +static const char* jkVgroupInfoHashBegin = "HashBegin"; +static const char* jkVgroupInfoHashEnd = "HashEnd"; +static const char* jkVgroupInfoEpSet = "EpSet"; +static const char* jkVgroupInfoNumOfTable = "NumOfTable"; + +static int32_t vgroupInfoToJson(const void* pObj, SJson* pJson) { + const SVgroupInfo* pNode = (const SVgroupInfo*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupInfoVgId, pNode->vgId); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashBegin, pNode->hashBegin); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashEnd, pNode->hashEnd); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkVgroupInfoEpSet, epSetToJson, &pNode->epSet); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkVgroupInfoNumOfTable, pNode->numOfTable); + } + + return code; +} + +static int32_t jsonToVgroupInfo(const SJson* pJson, void* pObj) { + SVgroupInfo* pNode = (SVgroupInfo*)pObj; + + int32_t code = tjsonGetIntValue(pJson, jkVgroupInfoVgId, &pNode->vgId); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUIntValue(pJson, jkVgroupInfoHashBegin, &pNode->hashBegin); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUIntValue(pJson, jkVgroupInfoHashEnd, &pNode->hashEnd); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonToObject(pJson, jkVgroupInfoEpSet, jsonToEpSet, &pNode->epSet); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkVgroupInfoNumOfTable, &pNode->numOfTable); + } + + return code; +} + +static const char* jkVgroupsInfoNum = "Num"; +static const char* jkVgroupsInfoVgroups = "Vgroups"; + +static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) { + const SVgroupsInfo* pNode = (const SVgroupsInfo*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), + pNode->numOfVgroups); + } + + return code; +} + +static int32_t jsonToVgroupsInfo(const SJson* pJson, void* pObj) { + SVgroupsInfo* pNode = (SVgroupsInfo*)pObj; + + int32_t code = tjsonGetIntValue(pJson, jkVgroupsInfoNum, &pNode->numOfVgroups); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonToArray(pJson, jkVgroupsInfoVgroups, jsonToVgroupInfo, pNode->vgroups, sizeof(SVgroupInfo)); + } + + return code; +} + +static const char* jkLogicSubplanId = "Id"; +static const char* jkLogicSubplanChildren = "Children"; +static const char* jkLogicSubplanRootNode = "RootNode"; +static const char* jkLogicSubplanType = "SubplanType"; +static const char* jkLogicSubplanVgroupsSize = "VgroupsSize"; +static const char* jkLogicSubplanVgroups = "Vgroups"; +static const char* jkLogicSubplanLevel = "Level"; +static const char* jkLogicSubplanSplitFlag = "SplitFlag"; + +static int32_t logicSubplanToJson(const void* pObj, SJson* pJson) { + const SLogicSubplan* pNode = (const SLogicSubplan*)pObj; + + int32_t code = tjsonAddObject(pJson, jkLogicSubplanId, subplanIdToJson, &pNode->id); + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkLogicSubplanChildren, pNode->pChildren); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkLogicSubplanRootNode, nodeToJson, pNode->pNode); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkLogicSubplanType, pNode->subplanType); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkLogicSubplanVgroupsSize, VGROUPS_INFO_SIZE(pNode->pVgroupList)); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkLogicSubplanVgroups, vgroupsInfoToJson, pNode->pVgroupList); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkLogicSubplanLevel, pNode->level); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkLogicSubplanSplitFlag, pNode->splitFlag); + } + + return code; +} + +static int32_t jsonToLogicSubplan(const SJson* pJson, void* pObj) { + SLogicSubplan* pNode = (SLogicSubplan*)pObj; + + int32_t code = tjsonToObject(pJson, jkLogicSubplanId, jsonToSubplanId, &pNode->id); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkLogicSubplanChildren, &pNode->pChildren); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkLogicSubplanRootNode, (SNode**)&pNode->pNode); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetNumberValue(pJson, jkLogicSubplanType, pNode->subplanType); + } + int32_t objSize = 0; + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkLogicSubplanVgroupsSize, &objSize); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonMakeObject(pJson, jkLogicSubplanVgroups, jsonToVgroupsInfo, (void**)&pNode->pVgroupList, objSize); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkLogicSubplanLevel, &pNode->level); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkLogicSubplanSplitFlag, &pNode->splitFlag); + } + + return code; +} + static const char* jkJoinLogicPlanJoinType = "JoinType"; static const char* jkJoinLogicPlanOnConditions = "OnConditions"; @@ -837,63 +1090,6 @@ static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { retur static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); } -static const char* jkEndPointFqdn = "Fqdn"; -static const char* jkEndPointPort = "Port"; - -static int32_t epToJson(const void* pObj, SJson* pJson) { - const SEp* pNode = (const SEp*)pObj; - - int32_t code = tjsonAddStringToObject(pJson, jkEndPointFqdn, pNode->fqdn); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkEndPointPort, pNode->port); - } - - return code; -} - -static int32_t jsonToEp(const SJson* pJson, void* pObj) { - SEp* pNode = (SEp*)pObj; - - int32_t code = tjsonGetStringValue(pJson, jkEndPointFqdn, pNode->fqdn); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetSmallIntValue(pJson, jkEndPointPort, &pNode->port); - } - - return code; -} - -static const char* jkEpSetInUse = "InUse"; -static const char* jkEpSetNumOfEps = "NumOfEps"; -static const char* jkEpSetEps = "Eps"; - -static int32_t epSetToJson(const void* pObj, SJson* pJson) { - const SEpSet* pNode = (const SEpSet*)pObj; - - int32_t code = tjsonAddIntegerToObject(pJson, jkEpSetInUse, pNode->inUse); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkEpSetNumOfEps, pNode->numOfEps); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddArray(pJson, jkEpSetEps, epToJson, pNode->eps, sizeof(SEp), pNode->numOfEps); - } - - return code; -} - -static int32_t jsonToEpSet(const SJson* pJson, void* pObj) { - SEpSet* pNode = (SEpSet*)pObj; - - int32_t code = tjsonGetTinyIntValue(pJson, jkEpSetInUse, &pNode->inUse); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetTinyIntValue(pJson, jkEpSetNumOfEps, &pNode->numOfEps); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonToArray(pJson, jkEpSetEps, jsonToEp, pNode->eps, sizeof(SEp)); - } - - return code; -} - static const char* jkSysTableScanPhysiPlanMnodeEpSet = "MnodeEpSet"; static const char* jkSysTableScanPhysiPlanShowRewrite = "ShowRewrite"; static const char* jkSysTableScanPhysiPlanAccountId = "AccountId"; @@ -1342,38 +1538,6 @@ static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { return jsonToPhysicDataSinkNode(pJson, pObj); } -static const char* jkSubplanIdQueryId = "QueryId"; -static const char* jkSubplanIdGroupId = "GroupId"; -static const char* jkSubplanIdSubplanId = "SubplanId"; - -static int32_t subplanIdToJson(const void* pObj, SJson* pJson) { - const SSubplanId* pNode = (const SSubplanId*)pObj; - - int32_t code = tjsonAddIntegerToObject(pJson, jkSubplanIdQueryId, pNode->queryId); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkSubplanIdGroupId, pNode->groupId); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkSubplanIdSubplanId, pNode->subplanId); - } - - return code; -} - -static int32_t jsonToSubplanId(const SJson* pJson, void* pObj) { - SSubplanId* pNode = (SSubplanId*)pObj; - - int32_t code = tjsonGetUBigIntValue(pJson, jkSubplanIdQueryId, &pNode->queryId); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetIntValue(pJson, jkSubplanIdGroupId, &pNode->groupId); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetIntValue(pJson, jkSubplanIdSubplanId, &pNode->subplanId); - } - - return code; -} - static const char* jkQueryNodeAddrId = "Id"; static const char* jkQueryNodeAddrInUse = "InUse"; static const char* jkQueryNodeAddrNumOfEps = "NumOfEps"; @@ -1747,23 +1911,51 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) { break; case TSDB_DATA_TYPE_BOOL: code = tjsonGetBoolValue(pJson, jkValueDatum, &pNode->datum.b); + *(bool*)&pNode->typeData = pNode->datum.b; break; case TSDB_DATA_TYPE_TINYINT: + code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i); + *(int8_t*)&pNode->typeData = pNode->datum.i; + break; case TSDB_DATA_TYPE_SMALLINT: + code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i); + *(int16_t*)&pNode->typeData = pNode->datum.i; + break; case TSDB_DATA_TYPE_INT: + code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i); + *(int32_t*)&pNode->typeData = pNode->datum.i; + break; case TSDB_DATA_TYPE_BIGINT: + code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i); + *(int64_t*)&pNode->typeData = pNode->datum.i; + break; case TSDB_DATA_TYPE_TIMESTAMP: code = tjsonGetBigIntValue(pJson, jkValueDatum, &pNode->datum.i); + *(int64_t*)&pNode->typeData = pNode->datum.i; break; case TSDB_DATA_TYPE_UTINYINT: + code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u); + *(uint8_t*)&pNode->typeData = pNode->datum.u; + break; case TSDB_DATA_TYPE_USMALLINT: + code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u); + *(uint16_t*)&pNode->typeData = pNode->datum.u; + break; case TSDB_DATA_TYPE_UINT: + code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u); + *(uint32_t*)&pNode->typeData = pNode->datum.u; + break; case TSDB_DATA_TYPE_UBIGINT: code = tjsonGetUBigIntValue(pJson, jkValueDatum, &pNode->datum.u); + *(uint64_t*)&pNode->typeData = pNode->datum.u; break; case TSDB_DATA_TYPE_FLOAT: + code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d); + *(float*)&pNode->typeData = pNode->datum.d; + break; case TSDB_DATA_TYPE_DOUBLE: code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d); + *(double*)&pNode->typeData = pNode->datum.d; break; case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: @@ -1885,6 +2077,7 @@ static const char* jkFunctionName = "Name"; static const char* jkFunctionId = "Id"; static const char* jkFunctionType = "Type"; static const char* jkFunctionParameter = "Parameters"; +static const char* jkFunctionUdfBufSize = "UdfBufSize"; static int32_t functionNodeToJson(const void* pObj, SJson* pJson) { const SFunctionNode* pNode = (const SFunctionNode*)pObj; @@ -1902,6 +2095,9 @@ static int32_t functionNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkFunctionParameter, pNode->pParameterList); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkFunctionUdfBufSize, pNode->udfBufSize); + } return code; } @@ -1922,6 +2118,9 @@ static int32_t jsonToFunctionNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkFunctionParameter, &pNode->pParameterList); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetIntValue(pJson, jkFunctionUdfBufSize, &pNode->udfBufSize); + } return code; } @@ -1964,78 +2163,6 @@ static int32_t jsonToTableNode(const SJson* pJson, void* pObj) { return code; } -static const char* jkVgroupInfoVgId = "VgId"; -static const char* jkVgroupInfoHashBegin = "HashBegin"; -static const char* jkVgroupInfoHashEnd = "HashEnd"; -static const char* jkVgroupInfoEpSet = "EpSet"; -static const char* jkVgroupInfoNumOfTable = "NumOfTable"; - -static int32_t vgroupInfoToJson(const void* pObj, SJson* pJson) { - const SVgroupInfo* pNode = (const SVgroupInfo*)pObj; - - int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupInfoVgId, pNode->vgId); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashBegin, pNode->hashBegin); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashEnd, pNode->hashEnd); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddObject(pJson, jkVgroupInfoEpSet, epSetToJson, &pNode->epSet); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkVgroupInfoNumOfTable, pNode->numOfTable); - } - - return code; -} - -static int32_t jsonToVgroupInfo(const SJson* pJson, void* pObj) { - SVgroupInfo* pNode = (SVgroupInfo*)pObj; - - int32_t code = tjsonGetIntValue(pJson, jkVgroupInfoVgId, &pNode->vgId); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetUIntValue(pJson, jkVgroupInfoHashBegin, &pNode->hashBegin); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetUIntValue(pJson, jkVgroupInfoHashEnd, &pNode->hashEnd); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonToObject(pJson, jkVgroupInfoEpSet, jsonToEpSet, &pNode->epSet); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetIntValue(pJson, jkVgroupInfoNumOfTable, &pNode->numOfTable); - } - - return code; -} - -static const char* jkVgroupsInfoNum = "Num"; -static const char* jkVgroupsInfoVgroups = "Vgroups"; - -static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) { - const SVgroupsInfo* pNode = (const SVgroupsInfo*)pObj; - - int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), - pNode->numOfVgroups); - } - - return code; -} - -static int32_t jsonToVgroupsInfo(const SJson* pJson, void* pObj) { - SVgroupsInfo* pNode = (SVgroupsInfo*)pObj; - - int32_t code = tjsonGetIntValue(pJson, jkVgroupsInfoNum, &pNode->numOfVgroups); - if (TSDB_CODE_SUCCESS == code) { - code = tjsonToArray(pJson, jkVgroupsInfoVgroups, jsonToVgroupInfo, pNode->vgroups, sizeof(SVgroupInfo)); - } - - return code; -} - static const char* jkRealTableMetaSize = "MetaSize"; static const char* jkRealTableMeta = "Meta"; static const char* jkRealTableVgroupsInfoSize = "VgroupsInfoSize"; @@ -2582,7 +2709,10 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { break; case QUERY_NODE_LOGIC_PLAN_SORT: return logicSortNodeToJson(pObj, pJson); + case QUERY_NODE_LOGIC_PLAN_PARTITION: + return logicPartitionNodeToJson(pObj, pJson); case QUERY_NODE_LOGIC_SUBPLAN: + return logicSubplanToJson(pObj, pJson); case QUERY_NODE_LOGIC_PLAN: break; case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: @@ -2667,6 +2797,10 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToLogicProjectNode(pJson, pObj); case QUERY_NODE_LOGIC_PLAN_SORT: return jsonToLogicSortNode(pJson, pObj); + case QUERY_NODE_LOGIC_PLAN_PARTITION: + return jsonToLogicPartitionNode(pJson, pObj); + case QUERY_NODE_LOGIC_SUBPLAN: + return jsonToLogicSubplan(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: return jsonToPhysiTagScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index 84eccf85325083265025efaa156276f68fece4ff..88f5d914e4998234367ebd03803aa5b75bf47850 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -423,6 +423,9 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk EDealRes res = DEAL_RES_CONTINUE; switch (nodeType(pNode)) { + case QUERY_NODE_NODE_LIST: + res = walkPhysiPlans(((SNodeListNode*)pNode)->pNodeList, order, walker, pContext); + break; case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: res = walkScanPhysi((SScanPhysiNode*)pNode, order, walker, pContext); break; @@ -534,10 +537,7 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk break; case QUERY_NODE_PHYSICAL_SUBPLAN: { SSubplan* pSubplan = (SSubplan*)pNode; - res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pSubplan->pChildren, order, walker, pContext); - } + res = walkPhysiPlans(pSubplan->pChildren, order, walker, pContext); if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkPhysiPlan((SNode*)pSubplan->pNode, order, walker, pContext); } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 351b50133c498d959c4cb86d65c2cb1ca25c7ee5..d7dba107180dffacb64a3c87fb037d11ae7ba3d8 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -389,21 +389,25 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_COLUMN_DEF: // no pointer field case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field break; - case QUERY_NODE_DATABASE_OPTIONS: - nodesDestroyList(((SDatabaseOptions*)pNode)->pRetentions); + case QUERY_NODE_DATABASE_OPTIONS: { + SDatabaseOptions* pOptions = (SDatabaseOptions*)pNode; + nodesDestroyNode(pOptions->pDaysPerFile); + nodesDestroyList(pOptions->pKeep); + nodesDestroyList(pOptions->pRetentions); break; + } case QUERY_NODE_TABLE_OPTIONS: { - STableOptions* pStmt = (STableOptions*)pNode; - nodesDestroyList(pStmt->pSma); - nodesDestroyList(pStmt->pFuncs); + STableOptions* pOptions = (STableOptions*)pNode; + nodesDestroyList(pOptions->pSma); + nodesDestroyList(pOptions->pRollupFuncs); break; } case QUERY_NODE_INDEX_OPTIONS: { - SIndexOptions* pStmt = (SIndexOptions*)pNode; - nodesDestroyList(pStmt->pFuncs); - nodesDestroyNode(pStmt->pInterval); - nodesDestroyNode(pStmt->pOffset); - nodesDestroyNode(pStmt->pSliding); + SIndexOptions* pOptions = (SIndexOptions*)pNode; + nodesDestroyList(pOptions->pFuncs); + nodesDestroyNode(pOptions->pInterval); + nodesDestroyNode(pOptions->pOffset); + nodesDestroyNode(pOptions->pSliding); break; } case QUERY_NODE_SET_OPERATOR: { @@ -867,21 +871,18 @@ void nodesClearList(SNodeList* pList) { void* nodesGetValueFromNode(SValueNode* pNode) { switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_BOOL: - return (void*)&pNode->datum.b; case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: - return (void*)&pNode->datum.i; case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: - return (void*)&pNode->datum.u; case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: - return (void*)&pNode->datum.d; + return (void*)&pNode->typeData; case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: @@ -893,6 +894,68 @@ void* nodesGetValueFromNode(SValueNode* pNode) { return NULL; } +int32_t nodesSetValueNodeValue(SValueNode* pNode, void *value) { + switch (pNode->node.resType.type) { + case TSDB_DATA_TYPE_BOOL: + pNode->datum.b = *(bool*)value; + *(bool*)&pNode->typeData = pNode->datum.b; + break; + case TSDB_DATA_TYPE_TINYINT: + pNode->datum.i = *(int8_t*)value; + *(int8_t*)&pNode->typeData = pNode->datum.i; + break; + case TSDB_DATA_TYPE_SMALLINT: + pNode->datum.i = *(int16_t*)value; + *(int16_t*)&pNode->typeData = pNode->datum.i; + break; + case TSDB_DATA_TYPE_INT: + pNode->datum.i = *(int32_t*)value; + *(int32_t*)&pNode->typeData = pNode->datum.i; + break; + case TSDB_DATA_TYPE_BIGINT: + pNode->datum.i = *(int64_t*)value; + *(int64_t*)&pNode->typeData = pNode->datum.i; + break; + case TSDB_DATA_TYPE_TIMESTAMP: + pNode->datum.i = *(int64_t*)value; + *(int64_t*)&pNode->typeData = pNode->datum.i; + break; + case TSDB_DATA_TYPE_UTINYINT: + pNode->datum.u = *(int8_t*)value; + *(int8_t*)&pNode->typeData = pNode->datum.u; + break; + case TSDB_DATA_TYPE_USMALLINT: + pNode->datum.u = *(int16_t*)value; + *(int16_t*)&pNode->typeData = pNode->datum.u; + break; + case TSDB_DATA_TYPE_UINT: + pNode->datum.u = *(int32_t*)value; + *(int32_t*)&pNode->typeData = pNode->datum.u; + break; + case TSDB_DATA_TYPE_UBIGINT: + pNode->datum.u = *(uint64_t*)value; + *(uint64_t*)&pNode->typeData = pNode->datum.u; + break; + case TSDB_DATA_TYPE_FLOAT: + pNode->datum.d = *(float*)value; + *(float*)&pNode->typeData = pNode->datum.d; + break; + case TSDB_DATA_TYPE_DOUBLE: + pNode->datum.d = *(double*)value; + *(double*)&pNode->typeData = pNode->datum.d; + break; + case TSDB_DATA_TYPE_NCHAR: + case TSDB_DATA_TYPE_VARCHAR: + case TSDB_DATA_TYPE_VARBINARY: + pNode->datum.p = (char*)value; + break; + default: + return TSDB_CODE_QRY_APP_ERROR; + } + + return TSDB_CODE_SUCCESS; +} + char* nodesGetStrValueFromNode(SValueNode* pNode) { switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_BOOL: { @@ -1086,30 +1149,31 @@ static EDealRes collectColumns(SNode* pNode, void* pContext) { int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type, SNodeList** pCols) { if (NULL == pSelect || NULL == pCols) { - return TSDB_CODE_SUCCESS; + return TSDB_CODE_FAILED; } SCollectColumnsCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pTableAlias = pTableAlias, .collectType = type, - .pCols = nodesMakeList(), + .pCols = (NULL == *pCols ? nodesMakeList() : *pCols), .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)}; if (NULL == cxt.pCols || NULL == cxt.pColHash) { return TSDB_CODE_OUT_OF_MEMORY; } - + *pCols = NULL; nodesWalkSelectStmt(pSelect, clause, collectColumns, &cxt); taosHashCleanup(cxt.pColHash); if (TSDB_CODE_SUCCESS != cxt.errCode) { nodesDestroyList(cxt.pCols); return cxt.errCode; } - if (0 == LIST_LENGTH(cxt.pCols)) { + if (LIST_LENGTH(cxt.pCols) > 0) { + *pCols = cxt.pCols; + } else { nodesDestroyList(cxt.pCols); - cxt.pCols = NULL; } - *pCols = cxt.pCols; + return TSDB_CODE_SUCCESS; } @@ -1130,7 +1194,7 @@ static EDealRes collectFuncs(SNode* pNode, void* pContext) { int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNodeList** pFuncs) { if (NULL == pSelect || NULL == pFuncs) { - return TSDB_CODE_SUCCESS; + return TSDB_CODE_FAILED; } SCollectFuncsCxt cxt = { @@ -1153,6 +1217,46 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod return TSDB_CODE_SUCCESS; } +typedef struct SCollectSpecialNodesCxt { + int32_t errCode; + ENodeType type; + SNodeList* pNodes; +} SCollectSpecialNodesCxt; + +static EDealRes collectSpecialNodes(SNode* pNode, void* pContext) { + SCollectSpecialNodesCxt* pCxt = (SCollectSpecialNodesCxt*)pContext; + if (pCxt->type == nodeType(pNode)) { + pCxt->errCode = nodesListStrictAppend(pCxt->pNodes, nodesCloneNode(pNode)); + return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR); + } + return DEAL_RES_CONTINUE; +} + +int32_t nodesCollectSpecialNodes(SSelectStmt* pSelect, ESqlClause clause, ENodeType type, SNodeList** pNodes) { + if (NULL == pSelect || NULL == pNodes) { + return TSDB_CODE_FAILED; + } + + SCollectSpecialNodesCxt cxt = { + .errCode = TSDB_CODE_SUCCESS, .type = type, .pNodes = (NULL == *pNodes ? nodesMakeList() : *pNodes)}; + if (NULL == cxt.pNodes) { + return TSDB_CODE_OUT_OF_MEMORY; + } + *pNodes = NULL; + nodesWalkSelectStmt(pSelect, SQL_CLAUSE_GROUP_BY, collectSpecialNodes, &cxt); + if (TSDB_CODE_SUCCESS != cxt.errCode) { + nodesDestroyList(cxt.pNodes); + return cxt.errCode; + } + if (LIST_LENGTH(cxt.pNodes) > 0) { + *pNodes = cxt.pNodes; + } else { + nodesDestroyList(cxt.pNodes); + } + + return TSDB_CODE_SUCCESS; +} + char* getFillModeString(EFillMode mode) { switch (mode) { case FILL_MODE_NONE: diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index f885508374806fbf38537e125003d14e2b1b9d70..8ecfab72ce3c985eb14a54b0203807ef41f3a658 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -30,14 +30,13 @@ typedef struct SAstCreateContext { SParseContext* pQueryCxt; SMsgBuf msgBuf; bool notSupport; - bool valid; SNode* pRootNode; int16_t placeholderNo; + int32_t errCode; } SAstCreateContext; typedef enum EDatabaseOptionType { - DB_OPTION_BLOCKS = 1, - DB_OPTION_CACHE, + DB_OPTION_BUFFER = 1, DB_OPTION_CACHELAST, DB_OPTION_COMP, DB_OPTION_DAYS, @@ -45,31 +44,30 @@ typedef enum EDatabaseOptionType { DB_OPTION_MAXROWS, DB_OPTION_MINROWS, DB_OPTION_KEEP, + DB_OPTION_PAGES, + DB_OPTION_PAGESIZE, DB_OPTION_PRECISION, - DB_OPTION_QUORUM, DB_OPTION_REPLICA, - DB_OPTION_TTL, + DB_OPTION_STRICT, DB_OPTION_WAL, DB_OPTION_VGROUPS, DB_OPTION_SINGLE_STABLE, - DB_OPTION_STREAM_MODE, - DB_OPTION_STRICT, DB_OPTION_RETENTIONS } EDatabaseOptionType; typedef enum ETableOptionType { - TABLE_OPTION_KEEP = 1, - TABLE_OPTION_TTL, - TABLE_OPTION_COMMENT, - TABLE_OPTION_SMA, + TABLE_OPTION_COMMENT = 1, + TABLE_OPTION_DELAY, TABLE_OPTION_FILE_FACTOR, - TABLE_OPTION_DELAY + TABLE_OPTION_ROLLUP, + TABLE_OPTION_TTL, + TABLE_OPTION_SMA } ETableOptionType; typedef struct SAlterOption { - int32_t type; - SValueNode* pVal; - SNodeList* pList; + int32_t type; + SToken val; + SNodeList* pList; } SAlterOption; extern SToken nil_token; @@ -121,25 +119,29 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit); SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable); SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight); -SNode* createDatabaseOptions(SAstCreateContext* pCxt); -SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); -SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); -SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); -SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); -SNode* createTableOptions(SAstCreateContext* pCxt); -SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); -SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment); SDataType createDataType(uint8_t type); SDataType createVarLenDataType(uint8_t type, const SToken* pLen); -SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, - SNodeList* pTags, SNode* pOptions); + +SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt); +SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt); +SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal); +SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); +SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); +SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); +SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); +SNode* createDefaultTableOptions(SAstCreateContext* pCxt); +SNode* createAlterTableOptions(SAstCreateContext* pCxt); +SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal); +SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment); +SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, + SNodeList* pTags, SNode* pOptions); SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, - SNodeList* pSpecificTags, SNodeList* pValsOfTags); + SNodeList* pSpecificTags, SNodeList* pValsOfTags, SNode* pOptions); SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables); SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables); SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); -SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions); +SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions); SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType); SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 42fd77ac1ac99afbfea9867b05aa268b02217564..30f0d8ed8be55785118a1d41b5078acc9461b71a 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -23,13 +23,12 @@ } %syntax_error { - if (pCxt->valid) { + if (TSDB_CODE_SUCCESS == pCxt->errCode) { if(TOKEN.z) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z); + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z); } else { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL); + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL); } - pCxt->valid = false; } } @@ -42,8 +41,8 @@ %left NK_CONCAT. /************************************************ create/alter account *****************************************/ -cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } -cmd ::= ALTER ACCOUNT NK_ID alter_account_options. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } +cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } +cmd ::= ALTER ACCOUNT NK_ID alter_account_options. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } %type account_options { int32_t } %destructor account_options { } @@ -137,43 +136,41 @@ not_exists_opt(A) ::= . exists_opt(A) ::= IF EXISTS. { A = true; } exists_opt(A) ::= . { A = false; } -db_options(A) ::= . { A = createDatabaseOptions(pCxt); } -db_options(A) ::= db_options(B) BLOCKS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) CACHE NK_INTEGER(C). { ((SDatabaseOptions*)B)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) CACHELAST NK_INTEGER(C). { ((SDatabaseOptions*)B)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) COMP NK_INTEGER(C). { ((SDatabaseOptions*)B)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) DAYS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) DAYS NK_VARIABLE(C). { ((SDatabaseOptions*)B)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &C); A = B; } -db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { ((SDatabaseOptions*)B)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) KEEP integer_list(C). { ((SDatabaseOptions*)B)->pKeep = C; A = B; } -db_options(A) ::= db_options(B) KEEP variable_list(C). { ((SDatabaseOptions*)B)->pKeep = C; A = B; } -db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { ((SDatabaseOptions*)B)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &C); A = B; } -db_options(A) ::= db_options(B) QUORUM NK_INTEGER(C). { ((SDatabaseOptions*)B)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { ((SDatabaseOptions*)B)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) TTL NK_INTEGER(C). { ((SDatabaseOptions*)B)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { ((SDatabaseOptions*)B)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { ((SDatabaseOptions*)B)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { ((SDatabaseOptions*)B)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -db_options(A) ::= db_options(B) RETENTIONS retention_list(C). { ((SDatabaseOptions*)B)->pRetentions = C; A = B; } -db_options(A) ::= db_options(B) STRICT NK_INTEGER(C). { ((SDatabaseOptions*)B)->pStrict = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } - -alter_db_options(A) ::= alter_db_option(B). { A = createDatabaseOptions(pCxt); A = setDatabaseAlterOption(pCxt, A, &B); } -alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseAlterOption(pCxt, B, &C); } +db_options(A) ::= . { A = createDefaultDatabaseOptions(pCxt); } +db_options(A) ::= db_options(B) BUFFER NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_BUFFER, &C); } +db_options(A) ::= db_options(B) CACHELAST NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHELAST, &C); } +db_options(A) ::= db_options(B) COMP NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMP, &C); } +db_options(A) ::= db_options(B) DAYS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DAYS, &C); } +db_options(A) ::= db_options(B) DAYS NK_VARIABLE(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DAYS, &C); } +db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FSYNC, &C); } +db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MAXROWS, &C); } +db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MINROWS, &C); } +db_options(A) ::= db_options(B) KEEP integer_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, C); } +db_options(A) ::= db_options(B) KEEP variable_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, C); } +db_options(A) ::= db_options(B) PAGES NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PAGES, &C); } +db_options(A) ::= db_options(B) PAGESIZE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PAGESIZE, &C); } +db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PRECISION, &C); } +db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_REPLICA, &C); } +db_options(A) ::= db_options(B) STRICT NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STRICT, &C); } +db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL, &C); } +db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); } +db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); } +db_options(A) ::= db_options(B) RETENTIONS retention_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, C); } + +alter_db_options(A) ::= alter_db_option(B). { A = createAlterDatabaseOptions(pCxt); A = setAlterDatabaseOption(pCxt, A, &B); } +alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setAlterDatabaseOption(pCxt, B, &C); } %type alter_db_option { SAlterOption } %destructor alter_db_option { } -alter_db_option(A) ::= BLOCKS NK_INTEGER(B). { A.type = DB_OPTION_BLOCKS; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } -alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } +alter_db_option(A) ::= BUFFER NK_INTEGER(B). { A.type = DB_OPTION_BUFFER; A.val = B; } +alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.val = B; } +alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.val = B; } alter_db_option(A) ::= KEEP integer_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; } alter_db_option(A) ::= KEEP variable_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; } -alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } -alter_db_option(A) ::= QUORUM NK_INTEGER(B). { A.type = DB_OPTION_QUORUM; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } -alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } -alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } -alter_db_option(A) ::= STRICT NK_INTEGER(B). { A.type = DB_OPTION_STRICT; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } +alter_db_option(A) ::= PAGES NK_INTEGER(B). { A.type = DB_OPTION_PAGES; A.val = B; } +alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.val = B; } +alter_db_option(A) ::= STRICT NK_INTEGER(B). { A.type = DB_OPTION_STRICT; A.val = B; } +alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; } %type integer_list { SNodeList* } %destructor integer_list { nodesDestroyList($$); } @@ -204,7 +201,7 @@ cmd ::= DROP STABLE exists_opt(A) full_table_name(B). cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; } cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = A; } -alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableOption(pCxt, B, C); } +alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); } alter_table_clause(A) ::= full_table_name(B) ADD COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D); } alter_table_clause(A) ::= full_table_name(B) DROP COLUMN column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_COLUMN, &C); } @@ -229,7 +226,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C). create_subtable_clause(A) ::= not_exists_opt(B) full_table_name(C) USING full_table_name(D) - specific_tags_opt(E) TAGS NK_LP literal_list(F) NK_RP. { A = createCreateSubTableClause(pCxt, B, C, D, E, F); } + specific_tags_opt(E) TAGS NK_LP literal_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); } %type multi_drop_clause { SNodeList* } %destructor multi_drop_clause { nodesDestroyList($$); } @@ -289,25 +286,21 @@ tags_def_opt(A) ::= tags_def(B). %destructor tags_def { nodesDestroyList($$); } tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; } -table_options(A) ::= . { A = createTableOptions(pCxt); } -table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { ((STableOptions*)B)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &C); A = B; } -table_options(A) ::= table_options(B) KEEP integer_list(C). { ((STableOptions*)B)->pKeep = C; A = B; } -table_options(A) ::= table_options(B) KEEP variable_list(C). { ((STableOptions*)B)->pKeep = C; A = B; } -table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { ((STableOptions*)B)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } -table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { ((STableOptions*)B)->pSma = C; A = B; } -table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { ((STableOptions*)B)->pFuncs = C; A = B; } -table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { ((STableOptions*)B)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &C); A = B; } -table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { ((STableOptions*)B)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } +table_options(A) ::= . { A = createDefaultTableOptions(pCxt); } +table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); } +table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_DELAY, &C); } +table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { A = setTableOption(pCxt, B, TABLE_OPTION_FILE_FACTOR, &C); } +table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableOption(pCxt, B, TABLE_OPTION_ROLLUP, C); } +table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); } +table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableOption(pCxt, B, TABLE_OPTION_SMA, C); } -alter_table_options(A) ::= alter_table_option(B). { A = createTableOptions(pCxt); A = setTableAlterOption(pCxt, A, &B); } -alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableAlterOption(pCxt, B, &C); } +alter_table_options(A) ::= alter_table_option(B). { A = createAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); } +alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableOption(pCxt, B, C.type, &C.val); } %type alter_table_option { SAlterOption } %destructor alter_table_option { } -alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } -alter_table_option(A) ::= KEEP integer_list(B). { A.type = TABLE_OPTION_KEEP; A.pList = B; } -alter_table_option(A) ::= KEEP variable_list(B). { A.type = TABLE_OPTION_KEEP; A.pList = B; } -alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } +alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.val = B; } +alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.val = B; } %type col_name_list { SNodeList* } %destructor col_name_list { nodesDestroyList($$); } @@ -329,7 +322,7 @@ cmd ::= SHOW QNODES. cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, A, B); } cmd ::= SHOW STREAMS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } -cmd ::= SHOW ACCOUNTS. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } +cmd ::= SHOW ACCOUNTS. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } @@ -497,7 +490,7 @@ signed_literal(A) ::= NK_STRING(B). signed_literal(A) ::= NK_BOOL(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B); } signed_literal(A) ::= TIMESTAMP NK_STRING(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); } signed_literal(A) ::= duration_literal(B). { A = releaseRawExprNode(pCxt, B); } -signed_literal(A) ::= NULL. { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } +signed_literal(A) ::= NULL(B). { A = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &B); } signed_literal(A) ::= literal_func(B). { A = releaseRawExprNode(pCxt, B); } %type literal_list { SNodeList* } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4c8c33dd0ab3c13916c5d61f11844f08a1310e88..1701976f8d02eb60453b80bd5e103d5ffa5f6b7c 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -21,7 +21,7 @@ #define CHECK_OUT_OF_MEM(p) \ do { \ if (NULL == (p)) { \ - pCxt->valid = false; \ + pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; \ snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \ return NULL; \ } \ @@ -30,7 +30,7 @@ #define CHECK_RAW_EXPR_NODE(node) \ do { \ if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \ - pCxt->valid = false; \ + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; \ return NULL; \ } \ } while (0) @@ -42,9 +42,15 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { pCxt->msgBuf.buf = pParseCxt->pMsg; pCxt->msgBuf.len = pParseCxt->msgLen; pCxt->notSupport = false; - pCxt->valid = true; pCxt->pRootNode = NULL; - pCxt->placeholderNo = 1; + pCxt->placeholderNo = 0; + pCxt->errCode = TSDB_CODE_SUCCESS; +} + +static void copyStringFormStringToken(SToken* pToken, char* pBuf, int32_t len) { + if (pToken->n > 2) { + strncpy(pBuf, pToken->z + 1, TMIN(pToken->n - 2, len - 1)); + } } static void trimEscape(SToken* pName) { @@ -57,42 +63,38 @@ static void trimEscape(SToken* pName) { static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) { if (NULL == pUserName) { - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; } else { if (pUserName->n >= TSDB_USER_LEN) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); } } - if (pCxt->valid) { + if (TSDB_CODE_SUCCESS == pCxt->errCode) { trimEscape(pUserName); } - return pCxt->valid; + return TSDB_CODE_SUCCESS == pCxt->errCode; } static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, char* pPassword) { if (NULL == pPasswordToken) { - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; } else if (pPasswordToken->n >= (TSDB_USET_PASSWORD_LEN - 2)) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); } else { strncpy(pPassword, pPasswordToken->z, pPasswordToken->n); strdequote(pPassword); if (strtrim(pPassword) <= 0) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY); } } - return pCxt->valid; + return TSDB_CODE_SUCCESS == pCxt->errCode; } static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* pFqdn, int32_t* pPort) { if (NULL == pEp) { - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; } else if (pEp->n >= TSDB_FQDN_LEN + 2 + 6) { // format 'fqdn:port' - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); } else { char ep[TSDB_FQDN_LEN + 2 + 6]; strncpy(ep, pEp->z, pEp->n); @@ -100,66 +102,59 @@ static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, ch strtrim(ep); char* pColon = strchr(ep, ':'); if (NULL == pColon) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENDPOINT); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENDPOINT); } else { strncpy(pFqdn, ep, pColon - ep); *pPort = strtol(pColon + 1, NULL, 10); if (*pPort >= UINT16_MAX || *pPort <= 0) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT); } } } - return pCxt->valid; + return TSDB_CODE_SUCCESS == pCxt->errCode; } static bool checkFqdn(SAstCreateContext* pCxt, const SToken* pFqdn) { if (NULL == pFqdn) { - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; } else { if (pFqdn->n >= TSDB_FQDN_LEN) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG); } } - return pCxt->valid; + return TSDB_CODE_SUCCESS == pCxt->errCode; } static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t* pPort) { if (NULL == pPortToken) { - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; } else { *pPort = strtol(pPortToken->z, NULL, 10); if (*pPort >= UINT16_MAX || *pPort <= 0) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT); } } - return pCxt->valid; + return TSDB_CODE_SUCCESS == pCxt->errCode; } static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool query) { if (NULL == pDbName) { if (query && NULL == pCxt->pQueryCxt->db) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DB_NOT_SPECIFIED); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DB_NOT_SPECIFIED); } } else { trimEscape(pDbName); if (pDbName->n >= TSDB_DB_NAME_LEN) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pDbName->z); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pDbName->z); } } - return pCxt->valid; + return TSDB_CODE_SUCCESS == pCxt->errCode; } static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) { trimEscape(pTableName); if (NULL != pTableName && pTableName->n >= TSDB_TABLE_NAME_LEN) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTableName->z); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTableName->z); return false; } return true; @@ -168,8 +163,7 @@ static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) { static bool checkColumnName(SAstCreateContext* pCxt, SToken* pColumnName) { trimEscape(pColumnName); if (NULL != pColumnName && pColumnName->n >= TSDB_COL_NAME_LEN) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pColumnName->z); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pColumnName->z); return false; } return true; @@ -178,8 +172,7 @@ static bool checkColumnName(SAstCreateContext* pCxt, SToken* pColumnName) { static bool checkIndexName(SAstCreateContext* pCxt, SToken* pIndexName) { trimEscape(pIndexName); if (NULL != pIndexName && pIndexName->n >= TSDB_INDEX_NAME_LEN) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pIndexName->z); - pCxt->valid = false; + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pIndexName->z); return false; } return true; @@ -218,7 +211,7 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { if (NULL == pNode || QUERY_NODE_RAW_EXPR != nodeType(pNode)) { - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; return nil_token; } SRawExprNode* target = (SRawExprNode*)pNode; @@ -229,16 +222,12 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) { SNodeList* list = nodesMakeList(); CHECK_OUT_OF_MEM(list); - if (TSDB_CODE_SUCCESS != nodesListAppend(list, pNode)) { - pCxt->valid = false; - } + pCxt->errCode = nodesListAppend(list, pNode); return list; } SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode) { - if (TSDB_CODE_SUCCESS != nodesListAppend(pList, pNode)) { - pCxt->valid = false; - } + pCxt->errCode = nodesListAppend(pList, pNode); return pList; } @@ -309,7 +298,7 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera CHECK_OUT_OF_MEM(val); val->literal = strndup(pLiteral->z, pLiteral->n); CHECK_OUT_OF_MEM(val->literal); - val->placeholderNo = pCxt->placeholderNo++; + val->placeholderNo = ++pCxt->placeholderNo; return (SNode*)val; } @@ -374,6 +363,11 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d CHECK_OUT_OF_MEM(func); strcpy(func->functionName, "cast"); func->node.resType = dt; + if (TSDB_DATA_TYPE_BINARY == dt.type) { + func->node.resType.bytes += 2; + } else if (TSDB_DATA_TYPE_NCHAR == dt.type) { + func->node.resType.bytes = func->node.resType.bytes * TSDB_NCHAR_SIZE + 2; + } nodesListMakeAppend(&func->pParameterList, pExpr); return (SNode*)func; } @@ -520,7 +514,7 @@ SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) { } SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) { - if (NULL == pNode || !pCxt->valid) { + if (NULL == pNode || TSDB_CODE_SUCCESS != pCxt->errCode) { return pNode; } int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n); @@ -592,6 +586,7 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr select->pProjectionList = pProjectionList; select->pFromTable = pTable; sprintf(select->stmtName, "%p", select); + select->isTimeOrderQuery = true; return (SNode*)select; } @@ -604,64 +599,113 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* return (SNode*)setOp; } -SNode* createDatabaseOptions(SAstCreateContext* pCxt) { +SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) { SDatabaseOptions* pOptions = 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->compressionLevel = TSDB_DEFAULT_COMP_LEVEL; + pOptions->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; + pOptions->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; + pOptions->maxRowsPerBlock = TSDB_DEFAULT_MAXROWS_FBLOCK; + pOptions->minRowsPerBlock = TSDB_DEFAULT_MINROWS_FBLOCK; + pOptions->keep[0] = TSDB_DEFAULT_KEEP; + pOptions->keep[1] = TSDB_DEFAULT_KEEP; + pOptions->keep[2] = TSDB_DEFAULT_KEEP; + pOptions->pages = TSDB_DEFAULT_PAGES_PER_VNODE; + pOptions->pagesize = TSDB_DEFAULT_PAGESIZE_PER_VNODE; + pOptions->precision = TSDB_DEFAULT_PRECISION; + pOptions->replica = TSDB_DEFAULT_DB_REPLICA; + pOptions->strict = TSDB_DEFAULT_DB_STRICT; + pOptions->walLevel = TSDB_DEFAULT_WAL_LEVEL; + pOptions->numOfVgroups = TSDB_DEFAULT_VN_PER_DB; + pOptions->singleStable = TSDB_DEFAULT_DB_SINGLE_STABLE; return (SNode*)pOptions; } -SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { - switch (pAlterOption->type) { - case DB_OPTION_BLOCKS: - ((SDatabaseOptions*)pOptions)->pNumOfBlocks = pAlterOption->pVal; - break; - case DB_OPTION_CACHE: - ((SDatabaseOptions*)pOptions)->pCacheBlockSize = pAlterOption->pVal; +SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) { + SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS); + CHECK_OUT_OF_MEM(pOptions); + pOptions->buffer = -1; + pOptions->cachelast = -1; + pOptions->compressionLevel = -1; + pOptions->daysPerFile = -1; + pOptions->fsyncPeriod = -1; + pOptions->maxRowsPerBlock = -1; + pOptions->minRowsPerBlock = -1; + pOptions->keep[0] = -1; + pOptions->keep[1] = -1; + pOptions->keep[2] = -1; + pOptions->pages = -1; + pOptions->pagesize = -1; + pOptions->precision = -1; + pOptions->replica = -1; + pOptions->strict = -1; + pOptions->walLevel = -1; + pOptions->numOfVgroups = -1; + pOptions->singleStable = -1; + return (SNode*)pOptions; +} + +SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal) { + switch (type) { + case DB_OPTION_BUFFER: + ((SDatabaseOptions*)pOptions)->buffer = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_CACHELAST: - ((SDatabaseOptions*)pOptions)->pCachelast = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->cachelast = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_COMP: - ((SDatabaseOptions*)pOptions)->pCompressionLevel = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->compressionLevel = strtol(((SToken*)pVal)->z, NULL, 10); break; - case DB_OPTION_DAYS: - ((SDatabaseOptions*)pOptions)->pDaysPerFile = pAlterOption->pVal; + case DB_OPTION_DAYS: { + SToken* pToken = pVal; + if (TK_NK_INTEGER == pToken->type) { + ((SDatabaseOptions*)pOptions)->daysPerFile = strtol(pToken->z, NULL, 10); + } else { + ((SDatabaseOptions*)pOptions)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, pToken); + } break; + } case DB_OPTION_FSYNC: - ((SDatabaseOptions*)pOptions)->pFsyncPeriod = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->fsyncPeriod = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_MAXROWS: - ((SDatabaseOptions*)pOptions)->pMaxRowsPerBlock = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->maxRowsPerBlock = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_MINROWS: - ((SDatabaseOptions*)pOptions)->pMinRowsPerBlock = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->minRowsPerBlock = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_KEEP: - ((SDatabaseOptions*)pOptions)->pKeep = pAlterOption->pList; + ((SDatabaseOptions*)pOptions)->pKeep = pVal; + break; + case DB_OPTION_PAGES: + ((SDatabaseOptions*)pOptions)->pages = strtol(((SToken*)pVal)->z, NULL, 10); + break; + case DB_OPTION_PAGESIZE: + ((SDatabaseOptions*)pOptions)->pagesize = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_PRECISION: - ((SDatabaseOptions*)pOptions)->pPrecision = pAlterOption->pVal; + copyStringFormStringToken((SToken*)pVal, ((SDatabaseOptions*)pOptions)->precisionStr, + sizeof(((SDatabaseOptions*)pOptions)->precisionStr)); break; case DB_OPTION_REPLICA: - ((SDatabaseOptions*)pOptions)->pReplica = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->replica = strtol(((SToken*)pVal)->z, NULL, 10); break; - case DB_OPTION_TTL: - ((SDatabaseOptions*)pOptions)->pTtl = pAlterOption->pVal; + case DB_OPTION_STRICT: + ((SDatabaseOptions*)pOptions)->strict = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_WAL: - ((SDatabaseOptions*)pOptions)->pWalLevel = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->walLevel = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_VGROUPS: - ((SDatabaseOptions*)pOptions)->pNumOfVgroups = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->numOfVgroups = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_SINGLE_STABLE: - ((SDatabaseOptions*)pOptions)->pSingleStable = pAlterOption->pVal; - break; - case DB_OPTION_STREAM_MODE: - ((SDatabaseOptions*)pOptions)->pStreamMode = pAlterOption->pVal; + ((SDatabaseOptions*)pOptions)->singleStable = strtol(((SToken*)pVal)->z, NULL, 10); break; case DB_OPTION_RETENTIONS: - ((SDatabaseOptions*)pOptions)->pRetentions = pAlterOption->pList; + ((SDatabaseOptions*)pOptions)->pRetentions = pVal; break; default: break; @@ -669,6 +713,17 @@ SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOp return pOptions; } +SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { + switch (pAlterOption->type) { + case DB_OPTION_KEEP: + case DB_OPTION_RETENTIONS: + return setDatabaseOption(pCxt, pOptions, pAlterOption->type, pAlterOption->pList); + default: + break; + } + return setDatabaseOption(pCxt, pOptions, pAlterOption->type, &pAlterOption->val); +} + SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions) { if (!checkDbName(pCxt, pDbName, false)) { return NULL; @@ -703,31 +758,44 @@ SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* return (SNode*)pStmt; } -SNode* createTableOptions(SAstCreateContext* pCxt) { +SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); CHECK_OUT_OF_MEM(pOptions); + pOptions->delay = TSDB_DEFAULT_ROLLUP_DELAY; + pOptions->filesFactor = TSDB_DEFAULT_ROLLUP_FILE_FACTOR; + pOptions->ttl = TSDB_DEFAULT_TABLE_TTL; return (SNode*)pOptions; } -SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { - switch (pAlterOption->type) { - case TABLE_OPTION_KEEP: - ((STableOptions*)pOptions)->pKeep = pAlterOption->pList; - break; - case TABLE_OPTION_TTL: - ((STableOptions*)pOptions)->pTtl = pAlterOption->pVal; - break; +SNode* createAlterTableOptions(SAstCreateContext* pCxt) { + STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); + CHECK_OUT_OF_MEM(pOptions); + pOptions->delay = -1; + pOptions->filesFactor = -1; + pOptions->ttl = -1; + return (SNode*)pOptions; +} + +SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal) { + switch (type) { case TABLE_OPTION_COMMENT: - ((STableOptions*)pOptions)->pComments = pAlterOption->pVal; + copyStringFormStringToken((SToken*)pVal, ((STableOptions*)pOptions)->comment, + sizeof(((STableOptions*)pOptions)->comment)); break; - case TABLE_OPTION_SMA: - ((STableOptions*)pOptions)->pSma = pAlterOption->pList; + case TABLE_OPTION_DELAY: + ((STableOptions*)pOptions)->delay = strtol(((SToken*)pVal)->z, NULL, 10); break; case TABLE_OPTION_FILE_FACTOR: - ((STableOptions*)pOptions)->pFilesFactor = pAlterOption->pVal; + ((STableOptions*)pOptions)->filesFactor = strtod(((SToken*)pVal)->z, NULL); break; - case TABLE_OPTION_DELAY: - ((STableOptions*)pOptions)->pDelay = pAlterOption->pVal; + case TABLE_OPTION_ROLLUP: + ((STableOptions*)pOptions)->pRollupFuncs = pVal; + break; + case TABLE_OPTION_TTL: + ((STableOptions*)pOptions)->ttl = strtol(((SToken*)pVal)->z, NULL, 10); + break; + case TABLE_OPTION_SMA: + ((STableOptions*)pOptions)->pSma = pVal; break; default: break; @@ -778,7 +846,7 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* } SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, - SNodeList* pSpecificTags, SNodeList* pValsOfTags) { + SNodeList* pSpecificTags, SNodeList* pValsOfTags, SNode* pOptions) { if (NULL == pRealTable) { return NULL; } @@ -833,7 +901,7 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S return (SNode*)pStmt; } -SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) { +SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) { if (NULL == pRealTable) { return NULL; } @@ -911,7 +979,7 @@ static bool needDbShowStmt(ENodeType type) { SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) { if (needDbShowStmt(type) && NULL == pDbName && NULL == pCxt->pQueryCxt->db) { snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "db not specified"); - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; return NULL; } SShowStmt* pStmt = nodesMakeNode(type); @@ -1172,7 +1240,7 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) { SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize) { if (pLibPath->n <= 2) { - pCxt->valid = false; + pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; return NULL; } SCreateFunctionStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_FUNCTION_STMT); diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 723ad577f4e7b439e21a7506ed6e9c74b5fa64a9..ee1a92d8b35248cd315a432dc70f10f21f936f17 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -53,20 +53,20 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) { } case TK_NK_ILLEGAL: { snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unrecognized token: \"%s\"", t0.z); - cxt.valid = false; + cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR; goto abort_parse; } case TK_NK_HEX: case TK_NK_OCT: case TK_NK_BIN: { snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unsupported token: \"%s\"", t0.z); - cxt.valid = false; + cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR; goto abort_parse; } default: Parse(pParser, t0.type, t0, &cxt); // ParseTrace(stdout, ""); - if (!cxt.valid) { + if (TSDB_CODE_SUCCESS != cxt.errCode) { goto abort_parse; } } @@ -74,12 +74,13 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) { abort_parse: ParseFree(pParser, (FFree)taosMemoryFree); - if (cxt.valid) { + if (TSDB_CODE_SUCCESS == cxt.errCode) { *pQuery = taosMemoryCalloc(1, sizeof(SQuery)); if (NULL == *pQuery) { return TSDB_CODE_OUT_OF_MEMORY; } (*pQuery)->pRoot = cxt.pRootNode; + (*pQuery)->placeholderNum = cxt.placeholderNo; } - return cxt.valid ? TSDB_CODE_SUCCESS : TSDB_CODE_FAILED; + return cxt.errCode; } diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index d0e670df6e71cffa8136040fd4e9af81d0e45bc9..9c2bd106863af1d2ac21a2d26aac60fd150f69e2 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -208,6 +208,23 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProject return TSDB_CODE_SUCCESS; } +static int32_t calcConstGroupBy(SCalcConstContext* pCxt, SSelectStmt* pSelect) { + int32_t code = calcConstList(pSelect->pGroupByList); + if (TSDB_CODE_SUCCESS == code) { + SNode* pNode = NULL; + FOREACH(pNode, pSelect->pGroupByList) { + SNode* pGroupPara = NULL; + FOREACH(pGroupPara, ((SGroupingSetNode*)pNode)->pParameterList) { + if (QUERY_NODE_VALUE != nodeType(pGroupPara)) { + return code; + } + } + } + DESTORY_LIST(pSelect->pGroupByList); + } + return code; +} + static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { int32_t code = calcConstProjections(pCxt, pSelect->pProjectionList, subquery); if (TSDB_CODE_SUCCESS == code) { @@ -223,7 +240,7 @@ static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bo code = calcConstNode(&pSelect->pWindow); } if (TSDB_CODE_SUCCESS == code) { - code = calcConstList(pSelect->pGroupByList); + code = calcConstGroupBy(pCxt, pSelect); } if (TSDB_CODE_SUCCESS == code) { code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pHaving); diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 62bb96f1cb0a80961849a464c60a9b819d2f2688..f452838921d629bdbb86dd600adbf52c3ae7d0a6 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -937,6 +937,11 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, } *gotRow = true; +#ifdef TD_DEBUG_PRINT_ROW + STSchema* pSTSchema = tdGetSTSChemaFromSSChema(&schema, spd->numOfCols); + tdSRowPrint(row, pSTSchema, __func__); + taosMemoryFree(pSTSchema); +#endif } // *len = pBuilder->extendedRowSize; @@ -1328,10 +1333,6 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, in for (int c = 0; c < spd->numOfBound; ++c) { SSchema* pColSchema = &pSchema[spd->boundColumns[c] - 1]; - if (bind[c].buffer_type != pColSchema->type) { - return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); - } - if (bind[c].num != rowNum) { return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); } @@ -1346,6 +1347,10 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, in CHECK_CODE(MemRowAppend(&pBuf, NULL, 0, ¶m)); } else { + if (bind[c].buffer_type != pColSchema->type) { + return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); + } + int32_t colLen = pColSchema->bytes; if (IS_VAR_DATA_TYPE(pColSchema->type)) { colLen = bind[c].length[r]; @@ -1359,7 +1364,6 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, in checkTimestamp(pDataBlock, (const char*)&tsKey); } } - // set the null value for the columns that do not assign values if ((spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) { for (int32_t i = 0; i < spd->numOfCols; ++i) { @@ -1369,6 +1373,11 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, in } } } +#ifdef TD_DEBUG_PRINT_ROW + STSchema* pSTSchema = tdGetSTSChemaFromSSChema(&pSchema, spd->numOfCols); + tdSRowPrint(row, pSTSchema, __func__); + taosMemoryFree(pSTSchema); +#endif pDataBlock->size += extendedRowSize; } @@ -1447,6 +1456,14 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBu } } } + +#ifdef TD_DEBUG_PRINT_ROW + if(rowEnd) { + STSchema* pSTSchema = tdGetSTSChemaFromSSChema(&pSchema, spd->numOfCols); + tdSRowPrint(row, pSTSchema, __func__); + taosMemoryFree(pSTSchema); + } +#endif } if (rowEnd) { diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 1338a11f424dacb39ae3c68903669a5db65796f9..ed123d50bd91f8abbefbffa8288fd12bb3acf94f 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -43,10 +43,11 @@ static SKeyword keywordTable[] = { {"BETWEEN", TK_BETWEEN}, {"BINARY", TK_BINARY}, {"BIGINT", TK_BIGINT}, - {"BLOCKS", TK_BLOCKS}, + // {"BLOCKS", TK_BLOCKS}, {"BNODE", TK_BNODE}, {"BNODES", TK_BNODES}, {"BOOL", TK_BOOL}, + {"BUFFER", TK_BUFFER}, {"BUFSIZE", TK_BUFSIZE}, {"BY", TK_BY}, {"CACHE", TK_CACHE}, @@ -132,6 +133,8 @@ static SKeyword keywordTable[] = { {"OUTPUTTYPE", TK_OUTPUTTYPE}, {"PARTITION", TK_PARTITION}, {"PASS", TK_PASS}, + {"PAGES", TK_PAGES}, + {"PAGESIZE", TK_PAGESIZE}, {"PORT", TK_PORT}, {"PPS", TK_PPS}, {"PRECISION", TK_PRECISION}, @@ -142,7 +145,7 @@ static SKeyword keywordTable[] = { {"QTIME", TK_QTIME}, {"QUERIES", TK_QUERIES}, {"QUERY", TK_QUERY}, - {"QUORUM", TK_QUORUM}, + // {"QUORUM", TK_QUORUM}, {"RATIO", TK_RATIO}, {"REPLICA", TK_REPLICA}, {"RESET", TK_RESET}, @@ -169,7 +172,7 @@ static SKeyword keywordTable[] = { {"STORAGE", TK_STORAGE}, {"STREAM", TK_STREAM}, {"STREAMS", TK_STREAMS}, - {"STREAM_MODE", TK_STREAM_MODE}, + // {"STREAM_MODE", TK_STREAM_MODE}, {"STRICT", TK_STRICT}, {"SYNCDB", TK_SYNCDB}, {"TABLE", TK_TABLE}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index cb514e974a93ee5b0077c7cbf80dbb914b7e29f8..2d08342214d7196cbd27cf3dc7c1a417639cf444 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -20,10 +20,12 @@ #include "functionMgt.h" #include "parUtil.h" #include "scalar.h" +#include "systable.h" #include "tglobal.h" #include "ttime.h" -#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : getBigintFromValueNode((SValueNode*)(pVal))) +#define generateDealNodeErrMsg(pCxt, code, ...) \ + (pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, code, ##__VA_ARGS__), DEAL_RES_ERROR) typedef struct STranslateContext { SParseContext* pParseCxt; @@ -50,15 +52,6 @@ static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_B static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; } -enum EDealRes generateDealNodeErrMsg(STranslateContext* pCxt, int32_t code, ...) { - va_list ap; - va_start(ap, code); - generateSyntaxErrMsg(&pCxt->msgBuf, code, ap); - va_end(ap); - pCxt->errCode = code; - return DEAL_RES_ERROR; -} - static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel); if (currTotalLevel > pCxt->currLevel) { @@ -326,7 +319,7 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol pCol->node.resType = pExpr->resType; } -static int32_t createColumnNodeByTable(STranslateContext* pCxt, const STableNode* pTable, SNodeList* pList) { +static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* pTable, SNodeList* pList) { if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta; int32_t nums = @@ -473,27 +466,66 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { break; case TSDB_DATA_TYPE_BOOL: pVal->datum.b = (0 == strcasecmp(pVal->literal, "true")); + *(bool*)&pVal->typeData = pVal->datum.b; + break; + case TSDB_DATA_TYPE_TINYINT:{ + char* endPtr = NULL; + pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + *(int8_t*)&pVal->typeData = pVal->datum.i; break; - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_INT: + } + case TSDB_DATA_TYPE_SMALLINT:{ + char* endPtr = NULL; + pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + *(int16_t*)&pVal->typeData = pVal->datum.i; + break; + } + case TSDB_DATA_TYPE_INT:{ + char* endPtr = NULL; + pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + *(int32_t*)&pVal->typeData = pVal->datum.i; + break; + } case TSDB_DATA_TYPE_BIGINT: { char* endPtr = NULL; pVal->datum.i = strtoll(pVal->literal, &endPtr, 10); + *(int64_t*)&pVal->typeData = pVal->datum.i; + break; + } + case TSDB_DATA_TYPE_UTINYINT:{ + char* endPtr = NULL; + pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + *(uint8_t*)&pVal->typeData = pVal->datum.u; + break; + } + case TSDB_DATA_TYPE_USMALLINT:{ + char* endPtr = NULL; + pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + *(uint16_t*)&pVal->typeData = pVal->datum.u; + break; + } + case TSDB_DATA_TYPE_UINT:{ + char* endPtr = NULL; + pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + *(uint32_t*)&pVal->typeData = pVal->datum.u; break; } - case TSDB_DATA_TYPE_UTINYINT: - case TSDB_DATA_TYPE_USMALLINT: - case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: { char* endPtr = NULL; pVal->datum.u = strtoull(pVal->literal, &endPtr, 10); + *(uint64_t*)&pVal->typeData = pVal->datum.u; + break; + } + case TSDB_DATA_TYPE_FLOAT:{ + char* endPtr = NULL; + pVal->datum.d = strtold(pVal->literal, &endPtr); + *(float*)&pVal->typeData = pVal->datum.d; break; } - case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: { char* endPtr = NULL; pVal->datum.d = strtold(pVal->literal, &endPtr); + *(double*)&pVal->typeData = pVal->datum.d; break; } case TSDB_DATA_TYPE_VARCHAR: @@ -511,6 +543,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { TSDB_CODE_SUCCESS) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); } + *(int64_t*)&pVal->typeData = pVal->datum.i; break; } case TSDB_DATA_TYPE_NCHAR: @@ -548,8 +581,8 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); } if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || - (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && IS_VAR_DATA_TYPE(rdt.type)) || - (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && IS_VAR_DATA_TYPE(ldt.type))) { + (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) || + (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); } @@ -610,6 +643,7 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING); } pCxt->pCurrStmt->hasAggFuncs = true; + pCxt->pCurrStmt->isTimeOrderQuery = false; } return DEAL_RES_CONTINUE; @@ -788,17 +822,17 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea SArray* vgroupList = NULL; if ('\0' != pRealTable->qualDbName[0]) { // todo release after mnode can be processed - // if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) { - code = getDBVgInfo(pCxt, pRealTable->qualDbName, &vgroupList); - // } + if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) { + code = getDBVgInfo(pCxt, pRealTable->qualDbName, &vgroupList); + } } else { code = getDBVgInfoImpl(pCxt, pName, &vgroupList); } // todo release after mnode can be processed - // if (TSDB_CODE_SUCCESS == code) { - // code = addMnodeToVgroupList(&pCxt->pParseCxt->mgmtEpSet, &vgroupList); - // } + if (TSDB_CODE_SUCCESS == code) { + code = addMnodeToVgroupList(&pCxt->pParseCxt->mgmtEpSet, &vgroupList); + } if (TSDB_CODE_SUCCESS == code) { code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList); @@ -906,7 +940,7 @@ static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) { size_t nums = taosArrayGetSize(pTables); for (size_t i = 0; i < nums; ++i) { STableNode* pTable = taosArrayGetP(pTables, i); - int32_t code = createColumnNodeByTable(pCxt, pTable, *pCols); + int32_t code = createColumnsByTable(pCxt, pTable, *pCols); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -978,7 +1012,7 @@ static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SN } } if (TSDB_CODE_SUCCESS == code) { - code = createColumnNodeByTable(pCxt, pTable, *pOutput); + code = createColumnsByTable(pCxt, pTable, *pOutput); } return code; } @@ -1060,52 +1094,33 @@ static int32_t createMultiResFuncsFromStar(STranslateContext* pCxt, SFunctionNod return code; } -static bool isCountStar(SNode* pNode) { - if (QUERY_NODE_FUNCTION != nodeType(pNode) || 1 != LIST_LENGTH(((SFunctionNode*)pNode)->pParameterList)) { - return false; - } - SNode* pPara = nodesListGetNode(((SFunctionNode*)pNode)->pParameterList, 0); - return (QUERY_NODE_COLUMN == nodeType(pPara) && 0 == strcmp(((SColumnNode*)pPara)->colName, "*")); -} - -static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) { - SColumnNode* pCol = nodesListGetNode(pCount->pParameterList, 0); - STableNode* pTable = NULL; - int32_t code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable); - if (TSDB_CODE_SUCCESS == code && QUERY_NODE_REAL_TABLE == nodeType(pTable)) { - setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, false, pCol); - } - return code; -} - static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) { if (NULL == pSelect->pProjectionList) { // select * ... return createAllColumns(pCxt, &pSelect->pProjectionList); } else { SNode* pNode = NULL; WHERE_EACH(pNode, pSelect->pProjectionList) { + int32_t code = TSDB_CODE_SUCCESS; if (isMultiResFunc(pNode)) { SNodeList* pFuncs = NULL; - if (TSDB_CODE_SUCCESS != createMultiResFuncsFromStar(pCxt, (SFunctionNode*)pNode, &pFuncs)) { - return TSDB_CODE_OUT_OF_MEMORY; + code = createMultiResFuncsFromStar(pCxt, (SFunctionNode*)pNode, &pFuncs); + if (TSDB_CODE_SUCCESS == code) { + INSERT_LIST(pSelect->pProjectionList, pFuncs); + ERASE_NODE(pSelect->pProjectionList); + continue; } - INSERT_LIST(pSelect->pProjectionList, pFuncs); - ERASE_NODE(pSelect->pProjectionList); - continue; } else if (isTableStar(pNode)) { SNodeList* pCols = NULL; - if (TSDB_CODE_SUCCESS != createTableAllCols(pCxt, (SColumnNode*)pNode, &pCols)) { - return TSDB_CODE_OUT_OF_MEMORY; - } - INSERT_LIST(pSelect->pProjectionList, pCols); - ERASE_NODE(pSelect->pProjectionList); - continue; - } else if (isCountStar(pNode)) { - int32_t code = rewriteCountStar(pCxt, (SFunctionNode*)pNode); - if (TSDB_CODE_SUCCESS != code) { - return code; + code = createTableAllCols(pCxt, (SColumnNode*)pNode, &pCols); + if (TSDB_CODE_SUCCESS == code) { + INSERT_LIST(pSelect->pProjectionList, pCols); + ERASE_NODE(pSelect->pProjectionList); + continue; } } + if (TSDB_CODE_SUCCESS != code) { + return code; + } WHERE_NEXT; } } @@ -1221,12 +1236,14 @@ static int32_t translateGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) { if (NULL != pSelect->pGroupByList && NULL != pSelect->pWindow) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST); } - pCxt->currClause = SQL_CLAUSE_GROUP_BY; - return translateExprList(pCxt, pSelect->pGroupByList); + if (NULL != pSelect->pGroupByList) { + pCxt->currClause = SQL_CLAUSE_GROUP_BY; + pSelect->isTimeOrderQuery = false; + return translateExprList(pCxt, pSelect->pGroupByList); + } + return TSDB_CODE_SUCCESS; } -static bool isValTimeUnit(char unit) { return ('n' == unit || 'y' == unit); } - static int64_t getMonthsFromTimeVal(int64_t val, int32_t fromPrecision, char unit) { int64_t days = convertTimeFromPrecisionToUnit(val, fromPrecision, 'd'); switch (unit) { @@ -1253,7 +1270,7 @@ static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* uint8_t precision = ((SColumnNode*)pInterval->pCol)->node.resType.precision; SValueNode* pInter = (SValueNode*)pInterval->pInterval; - bool valInter = isValTimeUnit(pInter->unit); + 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); @@ -1267,7 +1284,7 @@ static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* if (pInter->unit == 'n' && pOffset->unit == 'y') { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_OFFSET_UNIT); } - bool fixed = !isValTimeUnit(pOffset->unit) && !valInter; + bool fixed = !TIME_IS_VAR_DURATION(pOffset->unit) && !valInter; if ((fixed && pOffset->datum.i >= pInter->datum.i) || (!fixed && getMonthsFromTimeVal(pOffset->datum.i, precision, pOffset->unit) >= getMonthsFromTimeVal(pInter->datum.i, precision, pInter->unit))) { @@ -1279,7 +1296,7 @@ static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* const static int32_t INTERVAL_SLIDING_FACTOR = 100; SValueNode* pSliding = (SValueNode*)pInterval->pSliding; - if (pInter->unit == 'n' || pInter->unit == 'y') { + if (TIME_IS_VAR_DURATION(pSliding->unit)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SLIDING_UNIT); } if ((pSliding->datum.i < convertTimePrecision(tsMinSlidingTime, TSDB_TIME_PRECISION_MILLI, precision)) || @@ -1386,6 +1403,78 @@ static int32_t checkLimit(STranslateContext* pCxt, SSelectStmt* pSelect) { return TSDB_CODE_SUCCESS; } +static bool isCountStar(SFunctionNode* pFunc) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return false; + } + SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); + return (QUERY_NODE_COLUMN == nodeType(pPara) && 0 == strcmp(((SColumnNode*)pPara)->colName, "*")); +} + +// count(*) is rewritten as count(ts) for scannning optimization +static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) { + SColumnNode* pCol = nodesListGetNode(pCount->pParameterList, 0); + STableNode* pTable = NULL; + int32_t code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable); + if (TSDB_CODE_SUCCESS == code && QUERY_NODE_REAL_TABLE == nodeType(pTable)) { + setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, false, pCol); + } + return code; +} + +static int32_t createPrimaryKeyColByTable(STranslateContext* pCxt, STableNode* pTable, SNode** pPrimaryKey) { + SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN); + if (NULL == pCol) { + return TSDB_CODE_OUT_OF_MEMORY; + } + if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) { + setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, false, pCol); + } else { + // todo + } + *pPrimaryKey = (SNode*)pCol; + return TSDB_CODE_SUCCESS; +} + +static int32_t createPrimaryKeyCol(STranslateContext* pCxt, SNode** pPrimaryKey) { + STableNode* pTable = NULL; + int32_t code = findTable(pCxt, NULL, &pTable); + if (TSDB_CODE_SUCCESS == code) { + code = createPrimaryKeyColByTable(pCxt, pTable, pPrimaryKey); + } + return code; +} + +static int32_t rewriteTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFunc) { + SNode* pPrimaryKey = NULL; + int32_t code = createPrimaryKeyCol(pCxt, &pPrimaryKey); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListMakeStrictAppend(&pFunc->pParameterList, pPrimaryKey); + } + return code; +} + +EDealRes rewriteFuncForSelectImpl(SNode* pNode, void* pContext) { + if (QUERY_NODE_FUNCTION == nodeType(pNode)) { + STranslateContext* pCxt = pContext; + SFunctionNode* pFunc = (SFunctionNode*)pNode; + if (isCountStar(pFunc)) { + pCxt->errCode = rewriteCountStar(pCxt, pFunc); + } else if (fmIsTimelineFunc(pFunc->funcId)) { + pCxt->errCode = rewriteTimelineFunc(pCxt, pFunc); + } + if (TSDB_CODE_SUCCESS != pCxt->errCode) { + return DEAL_RES_ERROR; + } + } + return DEAL_RES_CONTINUE; +} + +static int32_t rewriteFuncForSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { + nodesWalkSelectStmt(pSelect, SQL_CLAUSE_FROM, rewriteFuncForSelectImpl, pCxt); + return pCxt->errCode; +} + static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { pCxt->pCurrStmt = pSelect; int32_t code = translateFrom(pCxt, pSelect); @@ -1416,6 +1505,9 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { if (TSDB_CODE_SUCCESS == code) { code = checkLimit(pCxt, pSelect); } + if (TSDB_CODE_SUCCESS == code) { + code = rewriteFuncForSelect(pCxt, pSelect); + } return code; } @@ -1546,157 +1638,118 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS SName name = {0}; tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameGetFullDbName(&name, pReq->db); - pReq->numOfVgroups = GET_OPTION_VAL(pStmt->pOptions->pNumOfVgroups, TSDB_DEFAULT_VN_PER_DB); - pReq->cacheBlockSize = GET_OPTION_VAL(pStmt->pOptions->pCacheBlockSize, TSDB_DEFAULT_CACHE_BLOCK_SIZE); - pReq->totalBlocks = GET_OPTION_VAL(pStmt->pOptions->pNumOfBlocks, TSDB_DEFAULT_TOTAL_BLOCKS); - pReq->daysPerFile = GET_OPTION_VAL(pStmt->pOptions->pDaysPerFile, TSDB_DEFAULT_DAYS_PER_FILE); - pReq->daysToKeep0 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 0), TSDB_DEFAULT_KEEP); - pReq->daysToKeep1 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 1), TSDB_DEFAULT_KEEP); - pReq->daysToKeep2 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 2), TSDB_DEFAULT_KEEP); - pReq->minRows = GET_OPTION_VAL(pStmt->pOptions->pMinRowsPerBlock, TSDB_DEFAULT_MINROWS_FBLOCK); - pReq->maxRows = GET_OPTION_VAL(pStmt->pOptions->pMaxRowsPerBlock, TSDB_DEFAULT_MAXROWS_FBLOCK); - pReq->commitTime = -1; - pReq->fsyncPeriod = GET_OPTION_VAL(pStmt->pOptions->pFsyncPeriod, TSDB_DEFAULT_FSYNC_PERIOD); - pReq->walLevel = GET_OPTION_VAL(pStmt->pOptions->pWalLevel, TSDB_DEFAULT_WAL_LEVEL); - pReq->precision = GET_OPTION_VAL(pStmt->pOptions->pPrecision, TSDB_TIME_PRECISION_MILLI); - pReq->compression = GET_OPTION_VAL(pStmt->pOptions->pCompressionLevel, TSDB_DEFAULT_COMP_LEVEL); - pReq->replications = GET_OPTION_VAL(pStmt->pOptions->pReplica, TSDB_DEFAULT_DB_REPLICA); - pReq->update = -1; - pReq->cacheLastRow = GET_OPTION_VAL(pStmt->pOptions->pCachelast, TSDB_DEFAULT_CACHE_LAST_ROW); + pReq->numOfVgroups = pStmt->pOptions->numOfVgroups; + pReq->numOfStables = pStmt->pOptions->singleStable; + pReq->buffer = pStmt->pOptions->buffer; + pReq->pageSize = pStmt->pOptions->pagesize; + pReq->pages = pStmt->pOptions->pages; + pReq->daysPerFile = pStmt->pOptions->daysPerFile; + pReq->daysToKeep0 = pStmt->pOptions->keep[0]; + pReq->daysToKeep1 = pStmt->pOptions->keep[1]; + pReq->daysToKeep2 = pStmt->pOptions->keep[2]; + pReq->minRows = pStmt->pOptions->minRowsPerBlock; + pReq->maxRows = pStmt->pOptions->maxRowsPerBlock; + pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod; + pReq->walLevel = pStmt->pOptions->walLevel; + pReq->precision = pStmt->pOptions->precision; + pReq->compression = pStmt->pOptions->compressionLevel; + pReq->replications = pStmt->pOptions->replica; + pReq->strict = pStmt->pOptions->strict; + pReq->cacheLastRow = pStmt->pOptions->cachelast; pReq->ignoreExist = pStmt->ignoreExists; - pReq->streamMode = GET_OPTION_VAL(pStmt->pOptions->pStreamMode, TSDB_DEFAULT_DB_STREAM_MODE); - pReq->ttl = GET_OPTION_VAL(pStmt->pOptions->pTtl, TSDB_DEFAULT_DB_TTL); - pReq->singleSTable = GET_OPTION_VAL(pStmt->pOptions->pSingleStable, TSDB_DEFAULT_DB_SINGLE_STABLE); - pReq->strict = GET_OPTION_VAL(pStmt->pOptions->pStrict, TSDB_DEFAULT_DB_STRICT); - return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq); } -static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, SValueNode* pVal, int32_t minVal, +static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, int32_t val, int32_t minVal, int32_t maxVal) { - if (NULL != pVal) { - if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { - return pCxt->errCode; - } - if (pVal->isDuration && - (TIME_UNIT_MINUTE != pVal->unit && TIME_UNIT_HOUR != pVal->unit && TIME_UNIT_DAY != pVal->unit)) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_OPTION_UNIT, pName, pVal->unit); - } - int64_t val = getBigintFromValueNode(pVal); - if (val < minVal || val > maxVal) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_RANGE_OPTION, pName, val, minVal, maxVal); - } + if (val >= 0 && (val < minVal || val > maxVal)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_RANGE_OPTION, pName, val, minVal, maxVal); } return TSDB_CODE_SUCCESS; } -static void convertValueFromStrToInt(SValueNode* pVal, int64_t val) { - taosMemoryFreeClear(pVal->datum.p); - pVal->datum.i = val; - pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT; - pVal->node.resType.bytes = tDataTypes[pVal->node.resType.type].bytes; -} - -static int32_t checkDbPrecisionOption(STranslateContext* pCxt, SValueNode* pVal) { - if (NULL != pVal) { - if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { +static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) { + if (NULL != pOptions->pDaysPerFile) { + if (DEAL_RES_ERROR == translateValue(pCxt, pOptions->pDaysPerFile)) { return pCxt->errCode; } - char* pRrecision = varDataVal(pVal->datum.p); - if (0 == strcmp(pRrecision, TSDB_TIME_PRECISION_MILLI_STR)) { - convertValueFromStrToInt(pVal, TSDB_TIME_PRECISION_MILLI); - } else if (0 == strcmp(pRrecision, TSDB_TIME_PRECISION_MICRO_STR)) { - convertValueFromStrToInt(pVal, TSDB_TIME_PRECISION_MICRO); - } else if (0 == strcmp(pRrecision, TSDB_TIME_PRECISION_NANO_STR)) { - convertValueFromStrToInt(pVal, TSDB_TIME_PRECISION_NANO); - } else { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STR_OPTION, "precision", pVal->datum.p); + if (TIME_UNIT_MINUTE != pOptions->pDaysPerFile->unit && TIME_UNIT_HOUR != pOptions->pDaysPerFile->unit && + TIME_UNIT_DAY != pOptions->pDaysPerFile->unit) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_OPTION_UNIT, "daysPerFile", + pOptions->pDaysPerFile->unit); } + pOptions->daysPerFile = getBigintFromValueNode(pOptions->pDaysPerFile); } - return TSDB_CODE_SUCCESS; -} - -static int32_t checkDbEnumOption(STranslateContext* pCxt, const char* pName, SValueNode* pVal, int32_t v1, int32_t v2) { - if (NULL != pVal) { - if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { - return pCxt->errCode; - } - int64_t val = pVal->datum.i; - if (val != v1 && val != v2) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENUM_OPTION, pName, val, v1, v2); - } - } - return TSDB_CODE_SUCCESS; + return checkRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); } -static int32_t checkTtlOption(STranslateContext* pCxt, SValueNode* pVal) { - if (NULL != pVal) { - if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { - return pCxt->errCode; - } - int64_t val = pVal->datum.i; - if (val < TSDB_MIN_DB_TTL) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TTL_OPTION, val, TSDB_MIN_DB_TTL); - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t checkKeepOption(STranslateContext* pCxt, SNodeList* pKeep) { - if (NULL == pKeep) { +static int32_t checkDbKeepOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) { + if (NULL == pOptions->pKeep) { return TSDB_CODE_SUCCESS; } - int32_t numOfKeep = LIST_LENGTH(pKeep); + int32_t numOfKeep = LIST_LENGTH(pOptions->pKeep); if (numOfKeep > 3 || numOfKeep < 1) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_NUM); } SNode* pNode = NULL; - FOREACH(pNode, pKeep) { - if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode)) { + FOREACH(pNode, pOptions->pKeep) { + SValueNode* pVal = (SValueNode*)pNode; + if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { return pCxt->errCode; } + if (pVal->isDuration && TIME_UNIT_MINUTE != pVal->unit && TIME_UNIT_HOUR != pVal->unit && + TIME_UNIT_DAY != pVal->unit) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_UNIT, pVal->unit); + } } - if (1 == numOfKeep) { - if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pKeep, nodesCloneNode(nodesListGetNode(pKeep, 0)))) { - return TSDB_CODE_OUT_OF_MEMORY; - } - ++numOfKeep; + pOptions->keep[0] = getBigintFromValueNode((SValueNode*)nodesListGetNode(pOptions->pKeep, 0)); + + if (numOfKeep < 2) { + pOptions->keep[1] = pOptions->keep[0]; + } else { + pOptions->keep[1] = getBigintFromValueNode((SValueNode*)nodesListGetNode(pOptions->pKeep, 1)); } - if (2 == numOfKeep) { - if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pKeep, nodesCloneNode(nodesListGetNode(pKeep, 1)))) { - return TSDB_CODE_OUT_OF_MEMORY; - } + if (numOfKeep < 3) { + pOptions->keep[2] = pOptions->keep[1]; + } else { + pOptions->keep[2] = getBigintFromValueNode((SValueNode*)nodesListGetNode(pOptions->pKeep, 2)); } - SValueNode* pKeep0 = (SValueNode*)nodesListGetNode(pKeep, 0); - SValueNode* pKeep1 = (SValueNode*)nodesListGetNode(pKeep, 1); - SValueNode* pKeep2 = (SValueNode*)nodesListGetNode(pKeep, 2); - if ((pKeep0->isDuration && - (TIME_UNIT_MINUTE != pKeep0->unit && TIME_UNIT_HOUR != pKeep0->unit && TIME_UNIT_DAY != pKeep0->unit)) || - (pKeep1->isDuration && - (TIME_UNIT_MINUTE != pKeep1->unit && TIME_UNIT_HOUR != pKeep1->unit && TIME_UNIT_DAY != pKeep1->unit)) || - (pKeep2->isDuration && - (TIME_UNIT_MINUTE != pKeep2->unit && TIME_UNIT_HOUR != pKeep2->unit && TIME_UNIT_DAY != pKeep2->unit))) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_UNIT, pKeep0->unit, pKeep1->unit, - pKeep2->unit); + if (pOptions->keep[0] < TSDB_MIN_KEEP || pOptions->keep[1] < TSDB_MIN_KEEP || pOptions->keep[2] < TSDB_MIN_KEEP || + pOptions->keep[0] > TSDB_MAX_KEEP || pOptions->keep[1] > TSDB_MAX_KEEP || pOptions->keep[2] > TSDB_MAX_KEEP) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_VALUE, pOptions->keep[0], pOptions->keep[1], + pOptions->keep[2], TSDB_MIN_KEEP, TSDB_MAX_KEEP); } - int32_t daysToKeep0 = getBigintFromValueNode(pKeep0); - int32_t daysToKeep1 = getBigintFromValueNode(pKeep1); - int32_t daysToKeep2 = getBigintFromValueNode(pKeep2); - if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP || - daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_VALUE, daysToKeep0, daysToKeep1, daysToKeep2, - TSDB_MIN_KEEP, TSDB_MAX_KEEP); + if (!((pOptions->keep[0] <= pOptions->keep[1]) && (pOptions->keep[1] <= pOptions->keep[2]))) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_ORDER); } - if (!((daysToKeep0 <= daysToKeep1) && (daysToKeep1 <= daysToKeep2))) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_ORDER); + return TSDB_CODE_SUCCESS; +} + +static int32_t checkDbPrecisionOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) { + if ('\0' != pOptions->precisionStr[0]) { + if (0 == strcmp(pOptions->precisionStr, TSDB_TIME_PRECISION_MILLI_STR)) { + pOptions->precision = TSDB_TIME_PRECISION_MILLI; + } else if (0 == strcmp(pOptions->precisionStr, TSDB_TIME_PRECISION_MICRO_STR)) { + pOptions->precision = TSDB_TIME_PRECISION_MICRO; + } else if (0 == strcmp(pOptions->precisionStr, TSDB_TIME_PRECISION_NANO_STR)) { + pOptions->precision = TSDB_TIME_PRECISION_NANO; + } else { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STR_OPTION, "precision", pOptions->precisionStr); + } } + return TSDB_CODE_SUCCESS; +} +static int32_t checkDbEnumOption(STranslateContext* pCxt, const char* pName, int32_t val, int32_t v1, int32_t v2) { + if (val >= 0 && val != v1 && val != v2) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENUM_OPTION, pName, val, v1, v2); + } return TSDB_CODE_SUCCESS; } @@ -1709,34 +1762,36 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION); } - SNode* pNode = NULL; - FOREACH(pNode, pRetentions) { - SNode* pVal = NULL; - FOREACH(pVal, ((SNodeListNode*)pNode)->pNodeList) { - if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pVal)) { + SNode* pRetention = NULL; + FOREACH(pRetention, pRetentions) { + SNode* pNode = NULL; + FOREACH(pNode, ((SNodeListNode*)pRetention)->pNodeList) { + SValueNode* pVal = (SValueNode*)pNode; + if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { return pCxt->errCode; } + if (!TIME_IS_VAR_DURATION(pVal->unit)) { + pVal->datum.i = convertTimeFromPrecisionToUnit(pVal->datum.i, pVal->node.resType.precision, pVal->unit); + } } } return TSDB_CODE_SUCCESS; } -static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions, - bool alter) { - if (NULL == pOptions->pDaysPerFile && NULL == pOptions->pKeep) { +static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) { + int32_t daysPerFile = pOptions->daysPerFile; + int32_t daysToKeep0 = pOptions->keep[0]; + if (-1 == daysPerFile && -1 == daysToKeep0) { return TSDB_CODE_SUCCESS; - } - int64_t daysPerFile = GET_OPTION_VAL(pOptions->pDaysPerFile, alter ? -1 : TSDB_DEFAULT_DAYS_PER_FILE); - int64_t daysToKeep0 = GET_OPTION_VAL(nodesListGetNode(pOptions->pKeep, 0), alter ? -1 : TSDB_DEFAULT_KEEP); - if (alter && (-1 == daysPerFile || -1 == daysToKeep0)) { + } else if (-1 == daysPerFile || -1 == daysToKeep0) { SDbCfgInfo dbCfg; int32_t code = getDBCfg(pCxt, pDbName, &dbCfg); if (TSDB_CODE_SUCCESS != code) { return code; } daysPerFile = (-1 == daysPerFile ? dbCfg.daysPerFile : daysPerFile); - daysToKeep0 = (-1 == daysPerFile ? dbCfg.daysToKeep0 : daysToKeep0); + daysToKeep0 = (-1 == daysToKeep0 ? dbCfg.daysToKeep0 : daysToKeep0); } if (daysPerFile > daysToKeep0) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DAYS_VALUE); @@ -1744,76 +1799,70 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa return TSDB_CODE_SUCCESS; } -static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions, - bool alter) { +static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) { int32_t code = - checkRangeOption(pCxt, "totalBlocks", pOptions->pNumOfBlocks, TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); + checkRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE); if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "cacheBlockSize", pOptions->pCacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE, - TSDB_MAX_CACHE_BLOCK_SIZE); - } - if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "cacheLast", pOptions->pCachelast, TSDB_MIN_DB_CACHE_LAST_ROW, + code = checkRangeOption(pCxt, "cacheLast", pOptions->cachelast, TSDB_MIN_DB_CACHE_LAST_ROW, TSDB_MAX_DB_CACHE_LAST_ROW); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "compression", pOptions->pCompressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); + code = checkRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); } if (TSDB_CODE_SUCCESS == code) { - code = - checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); + code = checkDbDaysOption(pCxt, pOptions); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "fsyncPeriod", pOptions->pFsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); + code = checkRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "maxRowsPerBlock", pOptions->pMaxRowsPerBlock, TSDB_MIN_MAXROWS_FBLOCK, + code = checkRangeOption(pCxt, "maxRowsPerBlock", pOptions->maxRowsPerBlock, TSDB_MIN_MAXROWS_FBLOCK, TSDB_MAX_MAXROWS_FBLOCK); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "minRowsPerBlock", pOptions->pMinRowsPerBlock, TSDB_MIN_MINROWS_FBLOCK, + code = checkRangeOption(pCxt, "minRowsPerBlock", pOptions->minRowsPerBlock, TSDB_MIN_MINROWS_FBLOCK, TSDB_MAX_MINROWS_FBLOCK); } if (TSDB_CODE_SUCCESS == code) { - code = checkKeepOption(pCxt, pOptions->pKeep); + code = checkDbKeepOption(pCxt, pOptions); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbPrecisionOption(pCxt, pOptions->pPrecision); + code = checkRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, TSDB_MAX_PAGES_PER_VNODE); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbEnumOption(pCxt, "replications", pOptions->pReplica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA); + code = checkRangeOption(pCxt, "pagesize", pOptions->pagesize, TSDB_MIN_PAGESIZE_PER_VNODE, + TSDB_MAX_PAGESIZE_PER_VNODE); } if (TSDB_CODE_SUCCESS == code) { - code = checkTtlOption(pCxt, pOptions->pTtl); + code = checkDbPrecisionOption(pCxt, pOptions); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbEnumOption(pCxt, "walLevel", pOptions->pWalLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL); + code = checkDbEnumOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "vgroups", pOptions->pNumOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB); + code = checkDbEnumOption(pCxt, "strict", pOptions->strict, TSDB_DB_STRICT_OFF, TSDB_DB_STRICT_ON); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbEnumOption(pCxt, "singleStable", pOptions->pSingleStable, TSDB_DB_SINGLE_STABLE_ON, - TSDB_DB_SINGLE_STABLE_OFF); + code = checkDbEnumOption(pCxt, "walLevel", pOptions->walLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL); } if (TSDB_CODE_SUCCESS == code) { - code = - checkDbEnumOption(pCxt, "streamMode", pOptions->pStreamMode, TSDB_DB_STREAM_MODE_OFF, TSDB_DB_STREAM_MODE_ON); + code = checkRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbRetentionsOption(pCxt, pOptions->pRetentions); + code = checkDbEnumOption(pCxt, "singleStable", pOptions->singleStable, TSDB_DB_SINGLE_STABLE_ON, + TSDB_DB_SINGLE_STABLE_OFF); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbEnumOption(pCxt, "strict", pOptions->pStrict, TSDB_DB_STRICT_OFF, TSDB_DB_STRICT_ON); + code = checkDbRetentionsOption(pCxt, pOptions->pRetentions); } if (TSDB_CODE_SUCCESS == code) { - code = checkOptionsDependency(pCxt, pDbName, pOptions, alter); + code = checkOptionsDependency(pCxt, pDbName, pOptions); } return code; } static int32_t checkCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { - return checkDatabaseOptions(pCxt, pStmt->dbName, pStmt->pOptions, false); + return checkDatabaseOptions(pCxt, pStmt->dbName, pStmt->pOptions); } typedef int32_t (*FSerializeFunc)(void* pBuf, int32_t bufLen, void* pReq); @@ -1864,20 +1913,23 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, SName name = {0}; tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameGetFullDbName(&name, pReq->db); - pReq->totalBlocks = GET_OPTION_VAL(pStmt->pOptions->pNumOfBlocks, -1); - pReq->daysToKeep0 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 0), -1); - pReq->daysToKeep1 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 1), -1); - pReq->daysToKeep2 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 2), -1); - pReq->fsyncPeriod = GET_OPTION_VAL(pStmt->pOptions->pFsyncPeriod, -1); - pReq->walLevel = GET_OPTION_VAL(pStmt->pOptions->pWalLevel, -1); - pReq->strict = GET_OPTION_VAL(pStmt->pOptions->pQuorum, -1); - pReq->cacheLastRow = GET_OPTION_VAL(pStmt->pOptions->pCachelast, -1); - pReq->replications = GET_OPTION_VAL(pStmt->pOptions->pReplica, -1); + pReq->buffer = pStmt->pOptions->buffer; + pReq->pageSize = -1; + pReq->pages = pStmt->pOptions->pages; + pReq->daysPerFile = -1; + pReq->daysToKeep0 = pStmt->pOptions->keep[0]; + pReq->daysToKeep1 = pStmt->pOptions->keep[1]; + pReq->daysToKeep2 = pStmt->pOptions->keep[2]; + pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod; + pReq->walLevel = pStmt->pOptions->walLevel; + pReq->strict = pStmt->pOptions->strict; + pReq->cacheLastRow = pStmt->pOptions->cachelast; + pReq->replications = pStmt->pOptions->replica; return; } static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt) { - int32_t code = checkDatabaseOptions(pCxt, pStmt->dbName, pStmt->pOptions, true); + int32_t code = checkDatabaseOptions(pCxt, pStmt->dbName, pStmt->pOptions); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -1923,27 +1975,10 @@ static SColumnDefNode* findColDef(SNodeList* pCols, const SColumnNode* pCol) { return NULL; } -static int32_t checkTableCommentOption(STranslateContext* pCxt, SValueNode* pVal) { - if (NULL != pVal) { - if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { - return pCxt->errCode; - } - if (pVal->node.resType.bytes >= TSDB_STB_COMMENT_LEN) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COMMENT_OPTION, TSDB_STB_COMMENT_LEN - 1); - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t checTableFactorOption(STranslateContext* pCxt, SValueNode* pVal) { - if (NULL != pVal) { - if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { - return pCxt->errCode; - } - if (pVal->datum.d < TSDB_MIN_DB_FILE_FACTOR || pVal->datum.d > TSDB_MAX_DB_FILE_FACTOR) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_F_RANGE_OPTION, "file_factor", pVal->datum.d, - TSDB_MIN_DB_FILE_FACTOR, TSDB_MAX_DB_FILE_FACTOR); - } +static int32_t checTableFactorOption(STranslateContext* pCxt, float val) { + if (val < TSDB_MIN_ROLLUP_FILE_FACTOR || val > TSDB_MAX_ROLLUP_FILE_FACTOR) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_F_RANGE_OPTION, "file_factor", val, + TSDB_MIN_ROLLUP_FILE_FACTOR, TSDB_MAX_ROLLUP_FILE_FACTOR); } return TSDB_CODE_SUCCESS; } @@ -1988,24 +2023,18 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs } static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { - int32_t code = checkKeepOption(pCxt, pStmt->pOptions->pKeep); + int32_t code = checkRangeOption(pCxt, "delay", pStmt->pOptions->delay, TSDB_MIN_ROLLUP_DELAY, TSDB_MAX_ROLLUP_DELAY); if (TSDB_CODE_SUCCESS == code) { - code = checkTtlOption(pCxt, pStmt->pOptions->pTtl); - } - if (TSDB_CODE_SUCCESS == code) { - code = checkTableCommentOption(pCxt, pStmt->pOptions->pComments); - } - if (TSDB_CODE_SUCCESS == code) { - code = checkTableSmaOption(pCxt, pStmt); + code = checTableFactorOption(pCxt, pStmt->pOptions->filesFactor); } if (TSDB_CODE_SUCCESS == code) { - code = checkTableRollupOption(pCxt, pStmt->pOptions->pFuncs); + code = checkTableRollupOption(pCxt, pStmt->pOptions->pRollupFuncs); } if (TSDB_CODE_SUCCESS == code) { - code = checTableFactorOption(pCxt, pStmt->pOptions->pFilesFactor); + code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX); } if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "delay", pStmt->pOptions->pDelay, TSDB_MIN_DB_DELAY, TSDB_MAX_DB_DELAY); + code = checkTableSmaOption(pCxt, pStmt); } if (TSDB_CODE_SUCCESS == code) { code = checkTableTags(pCxt, pStmt); @@ -2143,7 +2172,7 @@ static SNodeList* createRollupFuncs(SCreateTableStmt* pStmt) { } SNode* pFunc = NULL; - FOREACH(pFunc, pStmt->pOptions->pFuncs) { + FOREACH(pFunc, pStmt->pOptions->pRollupFuncs) { SNode* pCol = NULL; bool primaryKey = true; FOREACH(pCol, pStmt->pCols) { @@ -2234,8 +2263,8 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt, static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) { pReq->igExists = pStmt->ignoreExists; - pReq->xFilesFactor = GET_OPTION_VAL(pStmt->pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR); - pReq->delay = GET_OPTION_VAL(pStmt->pOptions->pDelay, TSDB_DEFAULT_DB_DELAY); + pReq->xFilesFactor = pStmt->pOptions->filesFactor; + pReq->delay = pStmt->pOptions->delay; columnDefNodeToField(pStmt->pCols, &pReq->pColumns); columnDefNodeToField(pStmt->pTags, &pReq->pTags); pReq->numOfColumns = LIST_LENGTH(pStmt->pCols); @@ -2734,7 +2763,7 @@ static int32_t translateCreateStream(STranslateContext* pCxt, SCreateStreamStmt* if ('\0' != pStmt->targetTabName[0]) { strcpy(name.dbname, pStmt->targetDbName); strcpy(name.tname, pStmt->targetTabName); - tNameExtractFullName(&name, createReq.outputSTbName); + tNameExtractFullName(&name, createReq.targetStbFullName); } int32_t code = translateQuery(pCxt, pStmt->pQuery); @@ -3210,36 +3239,19 @@ static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) { return code; } -typedef struct SVgroupTablesBatch { +typedef struct SVgroupCreateTableBatch { SVCreateTbBatchReq req; SVgroupInfo info; char dbName[TSDB_DB_NAME_LEN]; -} SVgroupTablesBatch; +} SVgroupCreateTableBatch; static void destroyCreateTbReq(SVCreateTbReq* pReq) { taosMemoryFreeClear(pReq->name); taosMemoryFreeClear(pReq->ntb.schema.pSchema); } -static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) { - if (0 == LIST_LENGTH(pOptions->pFuncs)) { - return TSDB_CODE_SUCCESS; - } - -#if 0 - pReq->ntbCfg.pRSmaParam = taosMemoryCalloc(1, sizeof(SRSmaParam)); - if (NULL == pReq->ntbCfg.pRSmaParam) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pReq->ntbCfg.pRSmaParam->delay = GET_OPTION_VAL(pOptions->pDelay, TSDB_DEFAULT_DB_DELAY); - pReq->ntbCfg.pRSmaParam->xFilesFactor = GET_OPTION_VAL(pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR); -#endif - - return TSDB_CODE_SUCCESS; -} - static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pVgroupInfo, - SVgroupTablesBatch* pBatch) { + SVgroupCreateTableBatch* pBatch) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId}; strcpy(name.dbname, pStmt->dbName); @@ -3261,11 +3273,6 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* toSchema((SColumnDefNode*)pCol, index + 1, req.ntb.schema.pSchema + index); ++index; } - if (TSDB_CODE_SUCCESS != buildSmaParam(pStmt->pOptions, &req)) { - destroyCreateTbReq(&req); - return TSDB_CODE_OUT_OF_MEMORY; - } - pBatch->info = *pVgroupInfo; strcpy(pBatch->dbName, pStmt->dbName); pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq)); @@ -3278,13 +3285,13 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* return TSDB_CODE_SUCCESS; } -static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) { +static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch, SArray* pBufArray) { int tlen; SCoder coder = {0}; int32_t ret = 0; tEncodeSize(tEncodeSVCreateTbBatchReq, &pTbBatch->req, tlen, ret); - tlen += sizeof(SMsgHead); //+ tSerializeSVCreateTbBatchReq(NULL, &(pTbBatch->req)); + tlen += sizeof(SMsgHead); void* buf = taosMemoryMalloc(tlen); if (NULL == buf) { return TSDB_CODE_OUT_OF_MEMORY; @@ -3310,7 +3317,7 @@ static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* return TSDB_CODE_SUCCESS; } -static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { +static void destroyCreateTbReqBatch(SVgroupCreateTableBatch* pTbBatch) { size_t size = taosArrayGetSize(pTbBatch->req.pArray); for (int32_t i = 0; i < size; ++i) { SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i); @@ -3355,10 +3362,10 @@ static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt* return TSDB_CODE_OUT_OF_MEMORY; } - SVgroupTablesBatch tbatch = {0}; - int32_t code = buildNormalTableBatchReq(acctId, pStmt, pInfo, &tbatch); + SVgroupCreateTableBatch tbatch = {0}; + int32_t code = buildNormalTableBatchReq(acctId, pStmt, pInfo, &tbatch); if (TSDB_CODE_SUCCESS == code) { - code = serializeVgroupTablesBatch(&tbatch, *pBufArray); + code = serializeVgroupCreateTableBatch(&tbatch, *pBufArray); } destroyCreateTbReqBatch(&tbatch); @@ -3403,9 +3410,9 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, c req.ctb.suid = suid; req.ctb.pTag = row; - SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId)); + SVgroupCreateTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId)); if (pTableBatch == NULL) { - SVgroupTablesBatch tBatch = {0}; + SVgroupCreateTableBatch tBatch = {0}; tBatch.info = *pVgInfo; strcpy(tBatch.dbName, pDbName); @@ -3578,21 +3585,21 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla return code; } -static SArray* serializeVgroupsTablesBatch(int32_t acctId, SHashObj* pVgroupHashmap) { +static SArray* serializeVgroupsCreateTableBatch(int32_t acctId, SHashObj* pVgroupHashmap) { SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); if (NULL == pBufArray) { return NULL; } - int32_t code = TSDB_CODE_SUCCESS; - SVgroupTablesBatch* pTbBatch = NULL; + int32_t code = TSDB_CODE_SUCCESS; + SVgroupCreateTableBatch* pTbBatch = NULL; do { pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch); if (pTbBatch == NULL) { break; } - serializeVgroupTablesBatch(pTbBatch, pBufArray); + serializeVgroupCreateTableBatch(pTbBatch, pBufArray); destroyCreateTbReqBatch(pTbBatch); } while (true); @@ -3617,7 +3624,143 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) } } - SArray* pBufArray = serializeVgroupsTablesBatch(pCxt->pParseCxt->acctId, pVgroupHashmap); + SArray* pBufArray = serializeVgroupsCreateTableBatch(pCxt->pParseCxt->acctId, pVgroupHashmap); + taosHashCleanup(pVgroupHashmap); + if (NULL == pBufArray) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + return rewriteToVnodeModifOpStmt(pQuery, pBufArray); +} + +typedef struct SVgroupDropTableBatch { + SVDropTbBatchReq req; + SVgroupInfo info; + char dbName[TSDB_DB_NAME_LEN]; +} SVgroupDropTableBatch; + +static void addDropTbReqIntoVgroup(SHashObj* pVgroupHashmap, SDropTableClause* pClause, SVgroupInfo* pVgInfo) { + SVDropTbReq req = {.name = pClause->tableName, .igNotExists = pClause->ignoreNotExists}; + SVgroupDropTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId)); + if (NULL == pTableBatch) { + SVgroupDropTableBatch tBatch = {0}; + tBatch.info = *pVgInfo; + tBatch.req.pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq)); + taosArrayPush(tBatch.req.pArray, &req); + + taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); + } else { // add to the correct vgroup + taosArrayPush(pTableBatch->req.pArray, &req); + } +} + +static int32_t buildDropTableVgroupHashmap(STranslateContext* pCxt, SDropTableClause* pClause, bool* pIsSuperTable, + SHashObj* pVgroupHashmap) { + STableMeta* pTableMeta = NULL; + int32_t code = getTableMeta(pCxt, pClause->dbName, pClause->tableName, &pTableMeta); + + if (TSDB_CODE_SUCCESS == code && TSDB_SUPER_TABLE == pTableMeta->tableType) { + *pIsSuperTable = true; + goto over; + } + + *pIsSuperTable = false; + + SVgroupInfo info = {0}; + if (TSDB_CODE_SUCCESS == code) { + code = getTableHashVgroup(pCxt, pClause->dbName, pClause->tableName, &info); + } + if (TSDB_CODE_SUCCESS == code) { + addDropTbReqIntoVgroup(pVgroupHashmap, pClause, &info); + } + +over: + taosMemoryFreeClear(pTableMeta); + return code; +} + +static void destroyDropTbReqBatch(SVgroupDropTableBatch* pTbBatch) { taosArrayDestroy(pTbBatch->req.pArray); } + +static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SArray* pBufArray) { + int tlen; + SCoder coder = {0}; + + int32_t ret = 0; + tEncodeSize(tEncodeSVDropTbBatchReq, &pTbBatch->req, tlen, ret); + tlen += sizeof(SMsgHead); + void* buf = taosMemoryMalloc(tlen); + if (NULL == buf) { + return TSDB_CODE_OUT_OF_MEMORY; + } + ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); + ((SMsgHead*)buf)->contLen = htonl(tlen); + void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + + tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, tlen - sizeof(SMsgHead), TD_ENCODER); + tEncodeSVDropTbBatchReq(&coder, &pTbBatch->req); + tCoderClear(&coder); + + SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); + if (NULL == pVgData) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pVgData->vg = pTbBatch->info; + pVgData->pData = buf; + pVgData->size = tlen; + pVgData->numOfTables = (int32_t)taosArrayGetSize(pTbBatch->req.pArray); + taosArrayPush(pBufArray, &pVgData); + + return TSDB_CODE_SUCCESS; +} + +static SArray* serializeVgroupsDropTableBatch(int32_t acctId, SHashObj* pVgroupHashmap) { + SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); + if (NULL == pBufArray) { + return NULL; + } + + int32_t code = TSDB_CODE_SUCCESS; + SVgroupDropTableBatch* pTbBatch = NULL; + do { + pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch); + if (pTbBatch == NULL) { + break; + } + + serializeVgroupDropTableBatch(pTbBatch, pBufArray); + destroyDropTbReqBatch(pTbBatch); + } while (true); + + return pBufArray; +} + +static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { + SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot; + + SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (NULL == pVgroupHashmap) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + bool isSuperTable = false; + SNode* pNode; + FOREACH(pNode, pStmt->pTables) { + int32_t code = buildDropTableVgroupHashmap(pCxt, (SDropTableClause*)pNode, &isSuperTable, pVgroupHashmap); + if (TSDB_CODE_SUCCESS != code) { + taosHashCleanup(pVgroupHashmap); + return code; + } + if (isSuperTable && LIST_LENGTH(pStmt->pTables) > 1) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DROP_STABLE); + } + } + + if (isSuperTable) { + taosHashCleanup(pVgroupHashmap); + return TSDB_CODE_SUCCESS; + } + + SArray* pBufArray = serializeVgroupsDropTableBatch(pCxt->pParseCxt->acctId, pVgroupHashmap); taosHashCleanup(pVgroupHashmap); if (NULL == pBufArray) { return TSDB_CODE_OUT_OF_MEMORY; @@ -3663,6 +3806,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_CREATE_MULTI_TABLE_STMT: code = rewriteCreateMultiTable(pCxt, pQuery); break; + case QUERY_NODE_DROP_TABLE_STMT: + code = rewriteDropTable(pCxt, pQuery); + break; case QUERY_NODE_ALTER_TABLE_STMT: if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == ((SAlterTableStmt*)pQuery->pRoot)->alterType) { code = rewriteAlterTable(pCxt, pQuery); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 3ffdaad3e6443df4dea09504421ebe867da2f15d..2bf4071d3395d8bf29e9a3b9aedde76ec595b072 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -68,8 +68,6 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "Invalid option %s: %s"; case TSDB_CODE_PAR_INVALID_ENUM_OPTION: return "Invalid option %s: %" PRId64 ", only %d, %d allowed"; - case TSDB_CODE_PAR_INVALID_TTL_OPTION: - return "Invalid option ttl: %" PRId64 ", should be greater than or equal to %d"; case TSDB_CODE_PAR_INVALID_KEEP_NUM: return "Invalid number of keep options"; case TSDB_CODE_PAR_INVALID_KEEP_ORDER: @@ -89,7 +87,7 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_INVALID_OPTION_UNIT: return "Invalid option %s unit: %c, only m, h, d allowed"; case TSDB_CODE_PAR_INVALID_KEEP_UNIT: - return "Invalid option keep unit: %c, %c, %c, only m, h, d allowed"; + return "Invalid option keep unit: %c, only m, h, d allowed"; case TSDB_CODE_PAR_AGG_FUNC_NESTING: return "Aggregate functions do not support nesting"; case TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE: @@ -128,6 +126,8 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "slimit/soffset only available for PARTITION BY query"; case TSDB_CODE_PAR_INVALID_TOPIC_QUERY: return "Invalid topic query"; + case TSDB_CODE_PAR_INVALID_DROP_STABLE: + return "Cannot drop super table in batch"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 18f0809dfd2d24cbf82e145b24a89367dd030b05..4d06024c68440dd6fa451997ad72720d66dbf0d1 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -133,17 +133,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 575 -#define YYNRULE 444 +#define YYNSTATE 569 +#define YYNRULE 438 #define YYNTOKEN 231 -#define YY_MAX_SHIFT 574 -#define YY_MIN_SHIFTREDUCE 857 -#define YY_MAX_SHIFTREDUCE 1300 -#define YY_ERROR_ACTION 1301 -#define YY_ACCEPT_ACTION 1302 -#define YY_NO_ACTION 1303 -#define YY_MIN_REDUCE 1304 -#define YY_MAX_REDUCE 1747 +#define YY_MAX_SHIFT 568 +#define YY_MIN_SHIFTREDUCE 848 +#define YY_MAX_SHIFTREDUCE 1285 +#define YY_ERROR_ACTION 1286 +#define YY_ACCEPT_ACTION 1287 +#define YY_NO_ACTION 1288 +#define YY_MIN_REDUCE 1289 +#define YY_MAX_REDUCE 1726 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -210,573 +210,579 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2021) +#define YY_ACTTAB_COUNT (2054) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 273, 124, 485, 1316, 1596, 485, 485, 322, 128, 1581, - /* 10 */ 472, 78, 33, 31, 78, 326, 1520, 1581, 386, 1467, - /* 20 */ 282, 393, 1117, 447, 1577, 1585, 1583, 1426, 1612, 484, - /* 30 */ 1426, 1426, 1577, 1584, 1583, 469, 488, 485, 1115, 34, - /* 40 */ 32, 30, 29, 28, 488, 468, 327, 1726, 105, 1567, - /* 50 */ 12, 33, 31, 1242, 484, 451, 484, 1123, 59, 282, - /* 60 */ 137, 1117, 1426, 125, 1723, 1726, 1624, 1383, 1726, 73, - /* 70 */ 1597, 471, 1599, 1600, 467, 1, 488, 1115, 1725, 1664, - /* 80 */ 22, 1724, 1723, 253, 1660, 1723, 103, 328, 485, 12, - /* 90 */ 34, 32, 30, 29, 28, 1726, 1123, 336, 571, 1353, - /* 100 */ 449, 133, 1671, 1672, 365, 1676, 26, 205, 137, 36, - /* 110 */ 1116, 36, 1723, 1426, 1, 1305, 454, 251, 985, 511, - /* 120 */ 510, 509, 989, 508, 991, 992, 507, 994, 504, 947, - /* 130 */ 1000, 501, 1002, 1003, 498, 495, 89, 571, 1141, 88, - /* 140 */ 87, 86, 85, 84, 83, 82, 81, 80, 949, 1116, - /* 150 */ 1118, 547, 546, 545, 544, 297, 441, 543, 542, 541, - /* 160 */ 108, 536, 535, 534, 533, 532, 531, 530, 529, 115, - /* 170 */ 525, 1121, 1122, 1139, 1167, 1168, 1169, 1170, 1171, 1172, - /* 180 */ 1173, 464, 486, 1181, 1182, 1183, 1184, 1185, 1186, 1118, - /* 190 */ 30, 29, 28, 402, 416, 396, 69, 1475, 321, 401, - /* 200 */ 320, 138, 102, 272, 397, 395, 65, 398, 1473, 54, - /* 210 */ 1121, 1122, 394, 1167, 1168, 1169, 1170, 1171, 1172, 1173, - /* 220 */ 464, 486, 1181, 1182, 1183, 1184, 1185, 1186, 33, 31, - /* 230 */ 1422, 447, 63, 1596, 1726, 138, 282, 250, 1117, 1139, - /* 240 */ 34, 32, 30, 29, 28, 447, 344, 137, 54, 356, - /* 250 */ 138, 1723, 1079, 1419, 1115, 138, 105, 1612, 357, 472, - /* 260 */ 1081, 100, 285, 455, 466, 1519, 12, 33, 31, 1421, - /* 270 */ 105, 485, 485, 1123, 468, 282, 451, 1117, 1567, 89, - /* 280 */ 337, 364, 88, 87, 86, 85, 84, 83, 82, 81, - /* 290 */ 80, 1, 1142, 1115, 103, 1624, 1426, 1426, 248, 1597, - /* 300 */ 471, 1599, 1600, 467, 465, 488, 462, 1636, 103, 198, - /* 310 */ 1671, 446, 1123, 445, 571, 1356, 1726, 1140, 56, 270, - /* 320 */ 1080, 1612, 175, 134, 1671, 1672, 1116, 1676, 469, 137, - /* 330 */ 7, 1304, 355, 1723, 138, 350, 349, 348, 347, 346, - /* 340 */ 1404, 343, 342, 341, 340, 339, 335, 334, 333, 332, - /* 350 */ 331, 330, 329, 571, 138, 98, 97, 96, 95, 94, - /* 360 */ 93, 92, 91, 90, 440, 1116, 1118, 402, 1507, 396, - /* 370 */ 1143, 1297, 524, 401, 1475, 146, 102, 514, 397, 395, - /* 380 */ 287, 398, 1266, 567, 566, 1473, 394, 1121, 1122, 365, - /* 390 */ 1167, 1168, 1169, 1170, 1171, 1172, 1173, 464, 486, 1181, - /* 400 */ 1182, 1183, 1184, 1185, 1186, 1118, 34, 32, 30, 29, - /* 410 */ 28, 293, 286, 34, 32, 30, 29, 28, 1510, 1512, - /* 420 */ 122, 434, 1264, 1265, 1267, 1268, 1121, 1122, 1428, 1167, - /* 430 */ 1168, 1169, 1170, 1171, 1172, 1173, 464, 486, 1181, 1182, - /* 440 */ 1183, 1184, 1185, 1186, 33, 31, 1187, 1475, 391, 390, - /* 450 */ 1296, 254, 282, 294, 1117, 485, 138, 1596, 1473, 48, - /* 460 */ 161, 70, 290, 131, 1423, 527, 894, 485, 893, 382, - /* 470 */ 1115, 378, 374, 370, 160, 106, 1548, 1154, 485, 1581, - /* 480 */ 1426, 1612, 1418, 33, 31, 1204, 895, 482, 450, 1123, - /* 490 */ 200, 282, 1426, 1117, 1577, 1584, 1583, 122, 468, 1417, - /* 500 */ 351, 55, 1567, 1426, 158, 1429, 488, 7, 485, 1115, - /* 510 */ 1415, 34, 32, 30, 29, 28, 101, 483, 437, 1624, - /* 520 */ 389, 1206, 74, 1597, 471, 1599, 1600, 467, 1123, 488, - /* 530 */ 571, 1402, 1664, 1426, 121, 1205, 275, 1660, 132, 424, - /* 540 */ 485, 1211, 1116, 392, 1567, 292, 7, 148, 147, 219, - /* 550 */ 201, 295, 1411, 122, 485, 1210, 430, 1691, 1144, 122, - /* 560 */ 24, 1428, 157, 296, 152, 1426, 154, 1428, 1302, 571, - /* 570 */ 34, 32, 30, 29, 28, 1256, 23, 1475, 1327, 1426, - /* 580 */ 524, 1116, 1118, 1413, 425, 151, 442, 438, 1474, 893, - /* 590 */ 25, 280, 1199, 1200, 1201, 1202, 1203, 1207, 1208, 1209, - /* 600 */ 1409, 9, 8, 1121, 1122, 384, 1167, 1168, 1169, 1170, - /* 610 */ 1171, 1172, 1173, 464, 486, 1181, 1182, 1183, 1184, 1185, - /* 620 */ 1186, 1118, 298, 1567, 1726, 34, 32, 30, 29, 28, - /* 630 */ 34, 32, 30, 29, 28, 6, 1326, 137, 1325, 447, - /* 640 */ 1324, 1723, 1121, 1122, 144, 1167, 1168, 1169, 1170, 1171, - /* 650 */ 1172, 1173, 464, 486, 1181, 1182, 1183, 1184, 1185, 1186, - /* 660 */ 33, 31, 1726, 254, 105, 400, 399, 1678, 282, 1596, - /* 670 */ 1117, 52, 1678, 453, 51, 137, 1218, 1323, 186, 1723, - /* 680 */ 1678, 1567, 1322, 1567, 178, 1567, 1115, 1321, 1320, 521, - /* 690 */ 520, 1675, 1241, 1612, 1154, 1319, 1674, 1204, 1318, 539, - /* 700 */ 450, 463, 103, 316, 1673, 1123, 1315, 1314, 1313, 1312, - /* 710 */ 468, 528, 1311, 1398, 1567, 1310, 1309, 135, 1671, 1672, - /* 720 */ 1308, 1676, 1567, 1, 540, 538, 1307, 1567, 457, 264, - /* 730 */ 1403, 1624, 1567, 1567, 74, 1597, 471, 1599, 1600, 467, - /* 740 */ 1567, 488, 228, 1567, 1664, 1456, 571, 1205, 275, 1660, - /* 750 */ 132, 1567, 1567, 1567, 1567, 101, 1401, 1567, 1116, 389, - /* 760 */ 1567, 1567, 1511, 1512, 1249, 1567, 313, 1210, 513, 1692, - /* 770 */ 1141, 1567, 265, 461, 263, 262, 1556, 388, 1683, 1237, - /* 780 */ 1192, 919, 392, 423, 166, 315, 1141, 164, 414, 1317, - /* 790 */ 168, 107, 1237, 167, 170, 519, 172, 169, 1118, 171, - /* 800 */ 920, 412, 25, 280, 1199, 1200, 1201, 1202, 1203, 1207, - /* 810 */ 1208, 1209, 305, 1103, 1104, 1384, 1596, 107, 522, 1121, - /* 820 */ 1122, 519, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 464, - /* 830 */ 486, 1181, 1182, 1183, 1184, 1185, 1186, 518, 517, 516, - /* 840 */ 1612, 515, 113, 202, 522, 1468, 426, 469, 1596, 1343, - /* 850 */ 43, 252, 42, 9, 8, 189, 1263, 468, 35, 191, - /* 860 */ 435, 1567, 1212, 518, 517, 516, 35, 515, 1299, 1300, - /* 870 */ 1174, 403, 1612, 417, 195, 383, 1694, 458, 1624, 469, - /* 880 */ 1596, 74, 1597, 471, 1599, 1600, 467, 1338, 488, 468, - /* 890 */ 1240, 1664, 448, 1567, 1196, 275, 1660, 1738, 35, 208, - /* 900 */ 1589, 110, 1074, 210, 1612, 477, 1698, 1613, 1139, 405, - /* 910 */ 1624, 469, 1587, 74, 1597, 471, 1599, 1600, 467, 1336, - /* 920 */ 488, 468, 111, 1664, 1126, 1567, 216, 275, 1660, 1738, - /* 930 */ 204, 113, 1596, 2, 123, 978, 1125, 300, 1721, 234, - /* 940 */ 42, 408, 1624, 407, 973, 74, 1597, 471, 1599, 1600, - /* 950 */ 467, 232, 488, 304, 259, 1664, 1612, 261, 415, 275, - /* 960 */ 1660, 1738, 493, 469, 149, 947, 1006, 111, 1087, 224, - /* 970 */ 1682, 1010, 174, 468, 112, 410, 338, 1567, 1017, 1117, - /* 980 */ 404, 1596, 1509, 451, 113, 111, 173, 145, 1016, 114, - /* 990 */ 353, 345, 352, 354, 1624, 1115, 1129, 241, 1597, 471, - /* 1000 */ 1599, 1600, 467, 358, 488, 1612, 1148, 150, 1128, 359, - /* 1010 */ 360, 1147, 469, 46, 1123, 361, 45, 153, 362, 1146, - /* 1020 */ 363, 156, 468, 1726, 53, 366, 1567, 1145, 72, 159, - /* 1030 */ 387, 385, 1416, 1596, 1123, 163, 137, 79, 269, 1412, - /* 1040 */ 1723, 1552, 165, 1624, 225, 176, 126, 1597, 471, 1599, - /* 1050 */ 1600, 467, 179, 488, 116, 571, 117, 1612, 1414, 50, - /* 1060 */ 49, 325, 1410, 143, 469, 1596, 118, 1116, 319, 119, - /* 1070 */ 427, 418, 226, 181, 468, 184, 422, 419, 1567, 428, - /* 1080 */ 260, 1144, 311, 436, 307, 303, 140, 1705, 1695, 1612, - /* 1090 */ 452, 1739, 475, 1704, 187, 1624, 469, 433, 75, 1597, - /* 1100 */ 471, 1599, 1600, 467, 190, 488, 468, 1118, 1664, 274, - /* 1110 */ 1567, 439, 1663, 1660, 444, 1596, 5, 138, 1237, 432, - /* 1120 */ 104, 130, 1143, 1685, 194, 4, 37, 1624, 1121, 1122, - /* 1130 */ 75, 1597, 471, 1599, 1600, 467, 1679, 488, 196, 1612, - /* 1140 */ 1664, 456, 16, 276, 460, 1660, 469, 574, 459, 197, - /* 1150 */ 1722, 1518, 203, 1741, 1645, 1596, 468, 473, 474, 284, - /* 1160 */ 1567, 223, 1517, 478, 99, 214, 479, 480, 212, 62, - /* 1170 */ 563, 1427, 559, 555, 551, 222, 64, 1624, 227, 1612, - /* 1180 */ 75, 1597, 471, 1599, 1600, 467, 469, 488, 1399, 229, - /* 1190 */ 1664, 221, 491, 271, 570, 1661, 468, 44, 129, 235, - /* 1200 */ 1567, 231, 71, 431, 233, 217, 236, 1561, 1596, 1560, - /* 1210 */ 299, 1557, 301, 302, 1111, 1112, 141, 1624, 306, 1555, - /* 1220 */ 249, 1597, 471, 1599, 1600, 467, 308, 488, 309, 310, - /* 1230 */ 1554, 312, 1612, 1553, 314, 481, 1538, 142, 317, 469, - /* 1240 */ 318, 1090, 1089, 1532, 1531, 323, 324, 1530, 1529, 468, - /* 1250 */ 1057, 1502, 1501, 1567, 1500, 1499, 1498, 1596, 109, 1485, - /* 1260 */ 1484, 1483, 1482, 1481, 429, 1497, 1496, 182, 1596, 1495, - /* 1270 */ 1624, 1494, 1493, 244, 1597, 471, 1599, 1600, 467, 1492, - /* 1280 */ 488, 1612, 1491, 1490, 1095, 1489, 177, 1488, 469, 1487, - /* 1290 */ 1486, 1480, 1612, 1479, 1478, 1059, 1477, 1476, 468, 469, - /* 1300 */ 1355, 1546, 1567, 1540, 1524, 1515, 1405, 155, 912, 468, - /* 1310 */ 1354, 443, 1352, 1567, 367, 1596, 279, 368, 369, 1624, - /* 1320 */ 1350, 373, 126, 1597, 471, 1599, 1600, 467, 372, 488, - /* 1330 */ 1624, 1596, 162, 249, 1597, 471, 1599, 1600, 467, 1612, - /* 1340 */ 488, 1348, 377, 1346, 376, 371, 466, 1596, 1335, 375, - /* 1350 */ 1334, 379, 380, 1331, 1407, 1612, 468, 1025, 381, 1022, - /* 1360 */ 1567, 77, 469, 1406, 946, 945, 944, 1740, 943, 942, - /* 1370 */ 537, 1612, 468, 939, 539, 1344, 1567, 1624, 469, 281, - /* 1380 */ 248, 1597, 471, 1599, 1600, 467, 266, 488, 468, 1637, - /* 1390 */ 938, 1339, 1567, 1624, 267, 283, 249, 1597, 471, 1599, - /* 1400 */ 1600, 467, 1337, 488, 406, 1596, 268, 409, 1330, 1624, - /* 1410 */ 411, 1329, 249, 1597, 471, 1599, 1600, 467, 1596, 488, - /* 1420 */ 413, 76, 1545, 1097, 47, 1539, 420, 1523, 421, 1612, - /* 1430 */ 1522, 1514, 180, 57, 3, 120, 469, 1596, 183, 35, - /* 1440 */ 13, 127, 1612, 192, 185, 40, 468, 188, 1587, 469, - /* 1450 */ 1567, 14, 1262, 20, 193, 1255, 58, 199, 21, 468, - /* 1460 */ 1162, 1612, 1285, 1567, 39, 1234, 1233, 1624, 469, 38, - /* 1470 */ 237, 1597, 471, 1599, 1600, 467, 1290, 488, 468, 15, - /* 1480 */ 1624, 136, 1567, 243, 1597, 471, 1599, 1600, 467, 1284, - /* 1490 */ 488, 11, 1596, 277, 1289, 1288, 278, 8, 17, 1624, - /* 1500 */ 1197, 139, 245, 1597, 471, 1599, 1600, 467, 1596, 488, - /* 1510 */ 1176, 27, 470, 1175, 10, 18, 1612, 19, 476, 206, - /* 1520 */ 207, 1260, 209, 469, 211, 60, 1513, 213, 215, 61, - /* 1530 */ 1133, 65, 1612, 468, 1627, 1586, 1178, 1567, 487, 469, - /* 1540 */ 218, 41, 492, 1007, 291, 494, 497, 490, 1596, 468, - /* 1550 */ 1004, 496, 1001, 1567, 1624, 499, 500, 238, 1597, 471, - /* 1560 */ 1599, 1600, 467, 995, 488, 502, 1596, 503, 505, 993, - /* 1570 */ 1624, 506, 1612, 246, 1597, 471, 1599, 1600, 467, 469, - /* 1580 */ 488, 1596, 999, 998, 984, 997, 996, 512, 1019, 468, - /* 1590 */ 1612, 66, 1015, 1567, 67, 68, 1012, 469, 1018, 910, - /* 1600 */ 953, 523, 935, 933, 526, 1612, 220, 468, 932, 931, - /* 1610 */ 1624, 1567, 469, 239, 1597, 471, 1599, 1600, 467, 930, - /* 1620 */ 488, 929, 468, 928, 927, 926, 1567, 948, 1624, 950, - /* 1630 */ 1596, 247, 1597, 471, 1599, 1600, 467, 923, 488, 922, - /* 1640 */ 921, 1351, 918, 1624, 917, 916, 240, 1597, 471, 1599, - /* 1650 */ 1600, 467, 915, 488, 1612, 548, 549, 1349, 550, 552, - /* 1660 */ 553, 469, 554, 1347, 556, 557, 558, 1345, 560, 561, - /* 1670 */ 562, 468, 1333, 564, 565, 1567, 1332, 1596, 1328, 573, - /* 1680 */ 568, 569, 1303, 1119, 230, 572, 1303, 1303, 1303, 1303, - /* 1690 */ 1303, 1303, 1624, 1303, 1303, 1608, 1597, 471, 1599, 1600, - /* 1700 */ 467, 1612, 488, 1303, 1303, 1303, 1303, 1596, 469, 1303, - /* 1710 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 468, 1303, - /* 1720 */ 1303, 1303, 1567, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1730 */ 1303, 1612, 1303, 1303, 1303, 1303, 1303, 1596, 469, 1624, - /* 1740 */ 1303, 1303, 1607, 1597, 471, 1599, 1600, 467, 468, 488, - /* 1750 */ 1303, 1303, 1567, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1760 */ 1303, 1612, 1303, 1303, 1303, 1303, 1303, 1596, 469, 1624, - /* 1770 */ 1303, 1303, 1606, 1597, 471, 1599, 1600, 467, 468, 488, - /* 1780 */ 1303, 1303, 1567, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1790 */ 1303, 1612, 1303, 1303, 1303, 1303, 1303, 1596, 469, 1624, - /* 1800 */ 1303, 1303, 257, 1597, 471, 1599, 1600, 467, 468, 488, - /* 1810 */ 1303, 1303, 1567, 1303, 1303, 1303, 1596, 1303, 1303, 1303, - /* 1820 */ 1303, 1612, 1303, 1303, 1303, 1303, 1303, 1303, 469, 1624, - /* 1830 */ 1303, 1303, 256, 1597, 471, 1599, 1600, 467, 468, 488, - /* 1840 */ 1612, 1303, 1567, 1303, 1303, 1303, 1596, 469, 289, 288, - /* 1850 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 468, 1131, 1624, - /* 1860 */ 1303, 1567, 258, 1597, 471, 1599, 1600, 467, 1303, 488, - /* 1870 */ 1612, 1303, 1303, 1303, 1124, 1303, 1303, 469, 1624, 1303, - /* 1880 */ 1303, 255, 1597, 471, 1599, 1600, 467, 468, 488, 1303, - /* 1890 */ 1303, 1567, 1303, 1123, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1900 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1624, 1303, - /* 1910 */ 1303, 242, 1597, 471, 1599, 1600, 467, 1303, 488, 1303, - /* 1920 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1930 */ 1303, 1303, 1303, 1303, 489, 1303, 1303, 1303, 1303, 1303, - /* 1940 */ 1303, 1303, 1303, 1303, 1303, 1303, 1127, 1303, 1303, 1303, - /* 1950 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1960 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1970 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 1980 */ 1303, 1303, 1303, 1303, 1303, 1303, 1132, 1303, 1303, 1303, - /* 1990 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, - /* 2000 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1135, 1303, 1303, - /* 2010 */ 1303, 1303, 1303, 1303, 1303, 1303, 1303, 1303, 486, 1181, - /* 2020 */ 1182, + /* 0 */ 1575, 1560, 1705, 470, 1591, 483, 285, 26, 203, 1498, + /* 10 */ 273, 467, 33, 31, 326, 1704, 1556, 1564, 1562, 1702, + /* 20 */ 282, 445, 1102, 22, 1591, 123, 1400, 1560, 486, 1366, + /* 30 */ 1409, 467, 482, 34, 32, 30, 29, 28, 1100, 483, + /* 40 */ 1287, 466, 1556, 1563, 1562, 1546, 104, 438, 98, 1124, + /* 50 */ 12, 33, 31, 1227, 486, 386, 1108, 1575, 1386, 282, + /* 60 */ 482, 1102, 1603, 365, 1409, 75, 1576, 469, 1578, 1579, + /* 70 */ 465, 1546, 486, 1, 351, 1643, 1454, 1100, 294, 1642, + /* 80 */ 1639, 1591, 272, 1126, 102, 1489, 1491, 1452, 467, 12, + /* 90 */ 1128, 885, 1705, 884, 298, 1108, 565, 59, 466, 132, + /* 100 */ 1650, 1651, 1546, 1655, 24, 1703, 439, 1101, 449, 1702, + /* 110 */ 1127, 886, 1, 36, 34, 32, 30, 29, 28, 1603, + /* 120 */ 146, 145, 73, 1576, 469, 1578, 1579, 465, 1290, 486, + /* 130 */ 520, 122, 1643, 1301, 1705, 565, 253, 1639, 1657, 34, + /* 140 */ 32, 30, 29, 28, 518, 1125, 1101, 135, 1705, 88, + /* 150 */ 1103, 1702, 87, 86, 85, 84, 83, 82, 81, 80, + /* 160 */ 79, 135, 1654, 517, 516, 1702, 515, 514, 513, 56, + /* 170 */ 270, 1106, 1107, 173, 1152, 1153, 1154, 1155, 1156, 1157, + /* 180 */ 1158, 462, 484, 1166, 1167, 1168, 1169, 1170, 1171, 1103, + /* 190 */ 974, 509, 508, 507, 978, 506, 980, 981, 505, 983, + /* 200 */ 502, 136, 989, 499, 991, 992, 496, 493, 482, 198, + /* 210 */ 1106, 1107, 264, 1152, 1153, 1154, 1155, 1156, 1157, 1158, + /* 220 */ 462, 484, 1166, 1167, 1168, 1169, 1170, 1171, 33, 31, + /* 230 */ 136, 322, 328, 1575, 1384, 523, 282, 1381, 1102, 88, + /* 240 */ 1251, 136, 87, 86, 85, 84, 83, 82, 81, 80, + /* 250 */ 79, 1312, 1191, 265, 1100, 263, 262, 1591, 388, 1454, + /* 260 */ 435, 36, 251, 390, 464, 287, 12, 33, 31, 1282, + /* 270 */ 1452, 1705, 1108, 1196, 466, 282, 422, 1102, 1546, 432, + /* 280 */ 1249, 1250, 1252, 1253, 135, 321, 389, 320, 1702, 1, + /* 290 */ 30, 29, 28, 1100, 136, 1603, 1546, 136, 248, 1576, + /* 300 */ 469, 1578, 1579, 465, 463, 486, 460, 1615, 23, 1311, + /* 310 */ 390, 1108, 565, 1310, 1575, 34, 32, 30, 29, 28, + /* 320 */ 518, 423, 483, 1101, 33, 31, 1172, 483, 7, 440, + /* 330 */ 436, 327, 282, 389, 1102, 1454, 296, 136, 1591, 517, + /* 340 */ 516, 293, 515, 514, 513, 467, 1452, 1409, 1657, 1281, + /* 350 */ 1100, 565, 1409, 1568, 1546, 466, 129, 512, 1546, 1546, + /* 360 */ 1387, 1705, 1101, 33, 31, 1566, 1103, 1448, 1108, 561, + /* 370 */ 560, 282, 1653, 1102, 135, 1309, 1603, 1241, 1702, 244, + /* 380 */ 1576, 469, 1578, 1579, 465, 7, 486, 1106, 1107, 1100, + /* 390 */ 1152, 1153, 1154, 1155, 1156, 1157, 1158, 462, 484, 1166, + /* 400 */ 1167, 1168, 1169, 1170, 1171, 1103, 1308, 1108, 565, 365, + /* 410 */ 34, 32, 30, 29, 28, 397, 396, 441, 1307, 1101, + /* 420 */ 1546, 522, 535, 533, 7, 1306, 1106, 1107, 54, 1152, + /* 430 */ 1153, 1154, 1155, 1156, 1157, 1158, 462, 484, 1166, 1167, + /* 440 */ 1168, 1169, 1170, 1171, 9, 8, 54, 565, 142, 1405, + /* 450 */ 421, 1546, 400, 399, 568, 1398, 136, 398, 1101, 100, + /* 460 */ 101, 395, 1103, 1546, 394, 393, 392, 1404, 221, 1394, + /* 470 */ 1546, 99, 1139, 52, 1305, 1304, 51, 557, 1486, 553, + /* 480 */ 549, 545, 220, 1106, 1107, 144, 1152, 1153, 1154, 1155, + /* 490 */ 1156, 1157, 1158, 462, 484, 1166, 1167, 1168, 1169, 1170, + /* 500 */ 1171, 1103, 34, 32, 30, 29, 28, 71, 286, 48, + /* 510 */ 215, 34, 32, 30, 29, 28, 120, 1203, 445, 1546, + /* 520 */ 1546, 1226, 1106, 1107, 1411, 1152, 1153, 1154, 1155, 1156, + /* 530 */ 1157, 1158, 462, 484, 1166, 1167, 1168, 1169, 1170, 1171, + /* 540 */ 33, 31, 250, 104, 1124, 479, 63, 1575, 282, 1064, + /* 550 */ 1102, 344, 1088, 1089, 356, 483, 470, 1066, 70, 936, + /* 560 */ 483, 1385, 1499, 357, 336, 483, 1100, 1402, 414, 98, + /* 570 */ 427, 1591, 105, 180, 337, 1303, 391, 938, 467, 1401, + /* 580 */ 1409, 102, 1396, 518, 1108, 1409, 1300, 1299, 466, 1298, + /* 590 */ 1409, 1080, 1546, 175, 6, 447, 131, 1650, 1651, 1657, + /* 600 */ 1655, 1, 517, 516, 445, 515, 514, 513, 1705, 1603, + /* 610 */ 520, 1302, 74, 1576, 469, 1578, 1579, 465, 1065, 486, + /* 620 */ 1546, 135, 1643, 1652, 565, 1702, 275, 1639, 1717, 104, + /* 630 */ 227, 1546, 1546, 1439, 1546, 1101, 355, 1677, 119, 350, + /* 640 */ 349, 348, 347, 346, 1289, 343, 342, 341, 340, 339, + /* 650 */ 335, 334, 333, 332, 331, 330, 329, 120, 34, 32, + /* 660 */ 30, 29, 28, 1490, 1491, 1412, 1454, 102, 97, 96, + /* 670 */ 95, 94, 93, 92, 91, 90, 89, 1453, 1103, 1662, + /* 680 */ 1222, 292, 133, 1650, 1651, 1535, 1655, 1129, 1392, 120, + /* 690 */ 459, 1297, 1234, 1575, 1296, 1295, 254, 1411, 1126, 1106, + /* 700 */ 1107, 1294, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 462, + /* 710 */ 484, 1166, 1167, 1168, 1169, 1170, 1171, 1591, 483, 1225, + /* 720 */ 1139, 305, 313, 451, 448, 445, 1293, 364, 1189, 34, + /* 730 */ 32, 30, 29, 28, 466, 1292, 1546, 295, 1546, 1546, + /* 740 */ 1546, 1177, 315, 1409, 534, 120, 1546, 1126, 316, 200, + /* 750 */ 104, 1222, 121, 1411, 455, 1603, 1367, 233, 74, 1576, + /* 760 */ 469, 1578, 1579, 465, 290, 486, 483, 254, 1643, 231, + /* 770 */ 449, 1546, 275, 1639, 130, 1406, 483, 1111, 884, 1190, + /* 780 */ 1546, 1560, 147, 452, 164, 1527, 199, 162, 102, 1575, + /* 790 */ 176, 1409, 428, 1670, 384, 415, 1556, 1563, 1562, 1189, + /* 800 */ 1195, 1409, 461, 196, 1650, 444, 184, 443, 486, 166, + /* 810 */ 1705, 1181, 165, 1591, 168, 170, 412, 167, 169, 511, + /* 820 */ 448, 43, 252, 135, 483, 1328, 1323, 1702, 110, 410, + /* 830 */ 466, 1341, 424, 480, 1546, 25, 280, 1184, 1185, 1186, + /* 840 */ 1187, 1188, 1192, 1193, 1194, 72, 1114, 401, 403, 1409, + /* 850 */ 1190, 1603, 9, 8, 74, 1576, 469, 1578, 1579, 465, + /* 860 */ 1321, 486, 42, 187, 1643, 483, 1248, 189, 275, 1639, + /* 870 */ 130, 1195, 1284, 1285, 481, 35, 50, 49, 325, 1197, + /* 880 */ 1110, 141, 406, 400, 399, 433, 319, 193, 398, 1671, + /* 890 */ 1409, 101, 395, 1575, 383, 394, 393, 392, 260, 1449, + /* 900 */ 311, 1673, 307, 303, 138, 456, 25, 280, 1184, 1185, + /* 910 */ 1186, 1187, 1188, 1192, 1193, 1194, 483, 1591, 35, 35, + /* 920 */ 446, 1592, 1159, 1059, 467, 217, 206, 108, 202, 109, + /* 930 */ 208, 475, 453, 214, 466, 136, 2, 1124, 1546, 110, + /* 940 */ 1575, 1409, 42, 967, 491, 300, 226, 109, 995, 1113, + /* 950 */ 110, 999, 111, 109, 1006, 1603, 1004, 112, 74, 1576, + /* 960 */ 469, 1578, 1579, 465, 1591, 486, 69, 936, 1643, 909, + /* 970 */ 304, 467, 275, 1639, 1717, 261, 65, 1072, 222, 353, + /* 980 */ 259, 466, 1338, 1700, 338, 1546, 1488, 910, 143, 345, + /* 990 */ 352, 354, 358, 1133, 359, 148, 360, 1132, 361, 151, + /* 1000 */ 362, 1131, 1603, 154, 363, 74, 1576, 469, 1578, 1579, + /* 1010 */ 465, 53, 486, 366, 157, 1643, 1130, 385, 387, 275, + /* 1020 */ 1639, 1717, 1399, 161, 1395, 163, 114, 78, 1575, 115, + /* 1030 */ 1661, 1108, 1397, 1393, 541, 540, 539, 297, 116, 538, + /* 1040 */ 537, 536, 106, 531, 530, 529, 528, 527, 526, 525, + /* 1050 */ 524, 113, 1591, 269, 117, 1531, 416, 174, 420, 467, + /* 1060 */ 223, 177, 224, 179, 425, 426, 417, 182, 1129, 466, + /* 1070 */ 434, 1684, 473, 1546, 5, 1575, 1674, 185, 1683, 449, + /* 1080 */ 431, 1664, 188, 274, 127, 437, 442, 194, 430, 4, + /* 1090 */ 1603, 1222, 103, 240, 1576, 469, 1578, 1579, 465, 1591, + /* 1100 */ 486, 1128, 195, 1701, 1658, 37, 467, 457, 276, 1720, + /* 1110 */ 454, 16, 1624, 192, 1497, 471, 466, 472, 284, 1705, + /* 1120 */ 1546, 477, 476, 1496, 201, 64, 478, 210, 1575, 212, + /* 1130 */ 225, 1410, 135, 564, 62, 219, 1702, 1603, 126, 1575, + /* 1140 */ 75, 1576, 469, 1578, 1579, 465, 1382, 486, 228, 489, + /* 1150 */ 1643, 271, 1591, 234, 458, 1639, 241, 44, 235, 467, + /* 1160 */ 230, 1540, 232, 1591, 1539, 299, 1536, 302, 301, 466, + /* 1170 */ 467, 1096, 1097, 1546, 139, 306, 1534, 308, 310, 309, + /* 1180 */ 466, 1533, 312, 1532, 1546, 314, 1517, 140, 317, 318, + /* 1190 */ 1603, 1075, 1074, 124, 1576, 469, 1578, 1579, 465, 1575, + /* 1200 */ 486, 1603, 1511, 1510, 75, 1576, 469, 1578, 1579, 465, + /* 1210 */ 323, 486, 324, 1509, 1643, 107, 1042, 1575, 1508, 1640, + /* 1220 */ 1481, 1480, 1479, 1591, 1478, 1477, 1476, 1475, 1474, 1473, + /* 1230 */ 467, 1472, 1471, 1470, 1469, 1468, 1467, 450, 1718, 1466, + /* 1240 */ 466, 1591, 1465, 1464, 1546, 1463, 1462, 429, 467, 1461, + /* 1250 */ 1575, 1460, 1459, 1458, 1457, 1456, 1455, 1340, 466, 1044, + /* 1260 */ 1525, 1603, 1546, 1519, 249, 1576, 469, 1578, 1579, 465, + /* 1270 */ 1503, 486, 1494, 153, 1591, 77, 367, 1335, 371, 1603, + /* 1280 */ 1575, 467, 124, 1576, 469, 1578, 1579, 465, 1388, 486, + /* 1290 */ 369, 466, 903, 1339, 405, 1546, 1337, 368, 279, 1333, + /* 1300 */ 372, 373, 376, 375, 1591, 377, 1331, 379, 1320, 413, + /* 1310 */ 1575, 464, 1603, 1319, 380, 249, 1576, 469, 1578, 1579, + /* 1320 */ 465, 466, 486, 172, 381, 1546, 408, 1719, 1316, 1390, + /* 1330 */ 160, 402, 1010, 1009, 1591, 935, 934, 171, 1389, 933, + /* 1340 */ 932, 467, 1603, 532, 534, 248, 1576, 469, 1578, 1579, + /* 1350 */ 465, 466, 486, 929, 1616, 1546, 928, 927, 281, 1329, + /* 1360 */ 1324, 266, 46, 1575, 267, 45, 404, 1322, 268, 407, + /* 1370 */ 1315, 409, 1603, 1314, 1575, 249, 1576, 469, 1578, 1579, + /* 1380 */ 465, 1524, 486, 411, 76, 1082, 1518, 1591, 418, 1502, + /* 1390 */ 1501, 1493, 3, 57, 467, 178, 181, 13, 1591, 118, + /* 1400 */ 35, 1566, 40, 191, 466, 467, 47, 419, 1546, 125, + /* 1410 */ 183, 283, 14, 38, 186, 466, 11, 1247, 190, 1546, + /* 1420 */ 1270, 20, 21, 1269, 1240, 1603, 197, 58, 249, 1576, + /* 1430 */ 469, 1578, 1579, 465, 1575, 486, 1603, 1219, 39, 236, + /* 1440 */ 1576, 469, 1578, 1579, 465, 1218, 486, 134, 1275, 1575, + /* 1450 */ 15, 277, 1274, 1273, 278, 8, 1182, 17, 1591, 1147, + /* 1460 */ 137, 204, 468, 474, 1492, 467, 1161, 27, 211, 1160, + /* 1470 */ 10, 18, 1118, 1591, 19, 466, 205, 1245, 207, 1546, + /* 1480 */ 467, 209, 60, 61, 1606, 213, 1163, 65, 973, 490, + /* 1490 */ 466, 1565, 216, 485, 1546, 41, 1603, 996, 291, 243, + /* 1500 */ 1576, 469, 1578, 1579, 465, 488, 486, 492, 494, 1575, + /* 1510 */ 993, 1603, 495, 497, 245, 1576, 469, 1578, 1579, 465, + /* 1520 */ 1575, 486, 990, 984, 500, 498, 503, 501, 988, 982, + /* 1530 */ 504, 987, 510, 1591, 66, 67, 986, 1005, 985, 1575, + /* 1540 */ 467, 68, 1003, 1002, 1591, 1001, 901, 519, 942, 521, + /* 1550 */ 466, 467, 218, 923, 1546, 922, 921, 920, 919, 918, + /* 1560 */ 917, 466, 916, 1591, 939, 1546, 937, 913, 912, 1575, + /* 1570 */ 467, 1603, 1336, 911, 237, 1576, 469, 1578, 1579, 465, + /* 1580 */ 466, 486, 1603, 543, 1546, 246, 1576, 469, 1578, 1579, + /* 1590 */ 465, 908, 486, 1591, 907, 906, 542, 544, 1334, 546, + /* 1600 */ 467, 1603, 547, 548, 238, 1576, 469, 1578, 1579, 465, + /* 1610 */ 466, 486, 1332, 550, 1546, 551, 552, 1330, 554, 555, + /* 1620 */ 556, 1318, 1575, 558, 559, 1317, 1313, 562, 563, 567, + /* 1630 */ 1104, 1603, 229, 1575, 247, 1576, 469, 1578, 1579, 465, + /* 1640 */ 566, 486, 1288, 1288, 1288, 1288, 1591, 1288, 1288, 1288, + /* 1650 */ 1288, 1288, 1288, 467, 1288, 1288, 1288, 1591, 1288, 1288, + /* 1660 */ 1288, 1288, 1288, 466, 467, 1288, 1288, 1546, 1288, 1288, + /* 1670 */ 1288, 1288, 1288, 1288, 466, 1288, 1288, 1288, 1546, 1288, + /* 1680 */ 1288, 1288, 1288, 1288, 1603, 1288, 1288, 239, 1576, 469, + /* 1690 */ 1578, 1579, 465, 1575, 486, 1603, 1288, 1288, 1587, 1576, + /* 1700 */ 469, 1578, 1579, 465, 1288, 486, 1288, 1288, 1575, 1288, + /* 1710 */ 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1591, 1288, 1288, + /* 1720 */ 1288, 1288, 1288, 1288, 467, 1288, 1288, 1288, 1288, 1288, + /* 1730 */ 1288, 1288, 1591, 1288, 466, 1288, 1288, 1288, 1546, 467, + /* 1740 */ 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 466, + /* 1750 */ 1288, 1288, 1288, 1546, 1288, 1603, 1288, 1288, 1586, 1576, + /* 1760 */ 469, 1578, 1579, 465, 1288, 486, 1288, 1288, 1575, 1288, + /* 1770 */ 1603, 1288, 1288, 1585, 1576, 469, 1578, 1579, 465, 1575, + /* 1780 */ 486, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, + /* 1790 */ 1288, 1288, 1591, 1288, 1288, 1288, 1288, 1288, 1575, 467, + /* 1800 */ 1288, 1288, 1288, 1591, 1288, 1288, 1288, 1288, 1288, 466, + /* 1810 */ 467, 1288, 1288, 1546, 1288, 1288, 1288, 1288, 1288, 1288, + /* 1820 */ 466, 1288, 1591, 1288, 1546, 1288, 1288, 1288, 1575, 467, + /* 1830 */ 1603, 1288, 1288, 257, 1576, 469, 1578, 1579, 465, 466, + /* 1840 */ 486, 1603, 1288, 1546, 256, 1576, 469, 1578, 1579, 465, + /* 1850 */ 1288, 486, 1591, 1288, 1288, 1288, 1288, 1288, 1288, 467, + /* 1860 */ 1603, 1288, 1288, 258, 1576, 469, 1578, 1579, 465, 466, + /* 1870 */ 486, 159, 1288, 1546, 128, 1288, 289, 288, 1288, 1288, + /* 1880 */ 382, 1575, 378, 374, 370, 158, 1116, 1288, 1288, 1288, + /* 1890 */ 1603, 1288, 1288, 255, 1576, 469, 1578, 1579, 465, 1288, + /* 1900 */ 486, 1288, 1109, 1102, 1288, 1591, 1288, 1288, 1288, 1288, + /* 1910 */ 55, 1288, 467, 156, 1288, 1288, 1288, 1288, 1288, 1100, + /* 1920 */ 1108, 1288, 466, 1288, 1288, 1288, 1546, 1288, 1288, 1288, + /* 1930 */ 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1108, 1288, 1288, + /* 1940 */ 1288, 1288, 1288, 1603, 1288, 1288, 242, 1576, 469, 1578, + /* 1950 */ 1579, 465, 1288, 486, 1288, 1288, 1288, 1288, 1288, 1288, + /* 1960 */ 487, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, + /* 1970 */ 1288, 1112, 155, 1288, 150, 1288, 152, 565, 1288, 1288, + /* 1980 */ 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1101, 1288, + /* 1990 */ 1288, 1288, 1288, 1288, 1288, 1288, 149, 1288, 1288, 1288, + /* 2000 */ 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, + /* 2010 */ 1288, 1288, 1288, 1288, 1117, 1288, 1288, 1288, 1288, 1288, + /* 2020 */ 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, 1288, + /* 2030 */ 1288, 1103, 1288, 1288, 1288, 1120, 1288, 1288, 1288, 1288, + /* 2040 */ 1288, 1288, 1288, 1288, 1288, 1288, 484, 1166, 1167, 1288, + /* 2050 */ 1288, 1288, 1106, 1107, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 262, 233, 240, 235, 234, 240, 240, 285, 257, 279, - /* 10 */ 275, 249, 12, 13, 249, 249, 281, 279, 256, 268, - /* 20 */ 20, 256, 22, 240, 294, 295, 296, 265, 258, 20, - /* 30 */ 265, 265, 294, 295, 296, 265, 306, 240, 38, 12, - /* 40 */ 13, 14, 15, 16, 306, 275, 249, 325, 265, 279, - /* 50 */ 50, 12, 13, 14, 20, 285, 20, 57, 4, 20, - /* 60 */ 338, 22, 265, 243, 342, 325, 296, 247, 325, 299, - /* 70 */ 300, 301, 302, 303, 304, 75, 306, 38, 338, 309, - /* 80 */ 2, 338, 342, 313, 314, 342, 303, 240, 240, 50, - /* 90 */ 12, 13, 14, 15, 16, 325, 57, 249, 98, 0, - /* 100 */ 317, 318, 319, 320, 49, 322, 310, 311, 338, 75, - /* 110 */ 110, 75, 342, 265, 75, 0, 72, 270, 89, 90, - /* 120 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 38, - /* 130 */ 101, 102, 103, 104, 105, 106, 21, 98, 20, 24, - /* 140 */ 25, 26, 27, 28, 29, 30, 31, 32, 57, 110, - /* 150 */ 150, 52, 53, 54, 55, 56, 20, 58, 59, 60, - /* 160 */ 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - /* 170 */ 71, 171, 172, 20, 174, 175, 176, 177, 178, 179, + /* 0 */ 234, 279, 325, 275, 258, 240, 278, 310, 311, 281, + /* 10 */ 262, 265, 12, 13, 249, 338, 294, 295, 296, 342, + /* 20 */ 20, 240, 22, 2, 258, 243, 234, 279, 306, 247, + /* 30 */ 265, 265, 20, 12, 13, 14, 15, 16, 38, 240, + /* 40 */ 231, 275, 294, 295, 296, 279, 265, 301, 249, 20, + /* 50 */ 50, 12, 13, 14, 306, 256, 56, 234, 0, 20, + /* 60 */ 20, 22, 296, 49, 265, 299, 300, 301, 302, 303, + /* 70 */ 304, 279, 306, 73, 67, 309, 258, 38, 267, 313, + /* 80 */ 314, 258, 264, 20, 303, 274, 275, 269, 265, 50, + /* 90 */ 20, 20, 325, 22, 285, 56, 96, 4, 275, 318, + /* 100 */ 319, 320, 279, 322, 2, 338, 20, 107, 285, 342, + /* 110 */ 20, 40, 73, 73, 12, 13, 14, 15, 16, 296, + /* 120 */ 113, 114, 299, 300, 301, 302, 303, 304, 0, 306, + /* 130 */ 49, 233, 309, 235, 325, 96, 313, 314, 297, 12, + /* 140 */ 13, 14, 15, 16, 86, 20, 107, 338, 325, 21, + /* 150 */ 150, 342, 24, 25, 26, 27, 28, 29, 30, 31, + /* 160 */ 32, 338, 321, 105, 106, 342, 108, 109, 110, 159, + /* 170 */ 160, 171, 172, 163, 174, 175, 176, 177, 178, 179, /* 180 */ 180, 181, 182, 183, 184, 185, 186, 187, 188, 150, - /* 190 */ 14, 15, 16, 52, 285, 54, 75, 258, 149, 58, - /* 200 */ 151, 201, 61, 264, 63, 64, 85, 66, 269, 242, - /* 210 */ 171, 172, 71, 174, 175, 176, 177, 178, 179, 180, + /* 190 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + /* 200 */ 97, 201, 99, 100, 101, 102, 103, 104, 20, 139, + /* 210 */ 171, 172, 35, 174, 175, 176, 177, 178, 179, 180, /* 220 */ 181, 182, 183, 184, 185, 186, 187, 188, 12, 13, - /* 230 */ 263, 240, 239, 234, 325, 201, 20, 18, 22, 20, - /* 240 */ 12, 13, 14, 15, 16, 240, 27, 338, 242, 30, - /* 250 */ 201, 342, 74, 260, 38, 201, 265, 258, 39, 275, - /* 260 */ 82, 255, 278, 219, 265, 281, 50, 12, 13, 263, - /* 270 */ 265, 240, 240, 57, 275, 20, 285, 22, 279, 21, - /* 280 */ 249, 249, 24, 25, 26, 27, 28, 29, 30, 31, - /* 290 */ 32, 75, 20, 38, 303, 296, 265, 265, 299, 300, - /* 300 */ 301, 302, 303, 304, 305, 306, 307, 308, 303, 318, - /* 310 */ 319, 320, 57, 322, 98, 0, 325, 20, 159, 160, - /* 320 */ 142, 258, 163, 318, 319, 320, 110, 322, 265, 338, - /* 330 */ 75, 0, 113, 342, 201, 116, 117, 118, 119, 120, - /* 340 */ 0, 122, 123, 124, 125, 126, 127, 128, 129, 130, - /* 350 */ 131, 132, 133, 98, 201, 24, 25, 26, 27, 28, - /* 360 */ 29, 30, 31, 32, 301, 110, 150, 52, 265, 54, - /* 370 */ 20, 143, 49, 58, 258, 272, 61, 86, 63, 64, - /* 380 */ 264, 66, 171, 237, 238, 269, 71, 171, 172, 49, + /* 230 */ 201, 285, 240, 234, 0, 246, 20, 248, 22, 21, + /* 240 */ 171, 201, 24, 25, 26, 27, 28, 29, 30, 31, + /* 250 */ 32, 234, 133, 76, 38, 78, 79, 258, 81, 258, + /* 260 */ 137, 73, 270, 86, 265, 264, 50, 12, 13, 142, + /* 270 */ 269, 325, 56, 154, 275, 20, 240, 22, 279, 210, + /* 280 */ 211, 212, 213, 214, 338, 149, 109, 151, 342, 73, + /* 290 */ 14, 15, 16, 38, 201, 296, 279, 201, 299, 300, + /* 300 */ 301, 302, 303, 304, 305, 306, 307, 308, 189, 234, + /* 310 */ 86, 56, 96, 234, 234, 12, 13, 14, 15, 16, + /* 320 */ 86, 285, 240, 107, 12, 13, 14, 240, 73, 206, + /* 330 */ 207, 249, 20, 109, 22, 258, 249, 201, 258, 105, + /* 340 */ 106, 264, 108, 109, 110, 265, 269, 265, 297, 222, + /* 350 */ 38, 96, 265, 73, 279, 275, 257, 84, 279, 279, + /* 360 */ 0, 325, 107, 12, 13, 85, 150, 268, 56, 237, + /* 370 */ 238, 20, 321, 22, 338, 234, 296, 74, 342, 299, + /* 380 */ 300, 301, 302, 303, 304, 73, 306, 171, 172, 38, /* 390 */ 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, - /* 400 */ 184, 185, 186, 187, 188, 150, 12, 13, 14, 15, - /* 410 */ 16, 267, 250, 12, 13, 14, 15, 16, 274, 275, - /* 420 */ 258, 210, 211, 212, 213, 214, 171, 172, 266, 174, + /* 400 */ 184, 185, 186, 187, 188, 150, 234, 56, 96, 49, + /* 410 */ 12, 13, 14, 15, 16, 244, 245, 337, 234, 107, + /* 420 */ 279, 56, 244, 245, 73, 234, 171, 172, 242, 174, /* 430 */ 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, - /* 440 */ 185, 186, 187, 188, 12, 13, 14, 258, 244, 245, - /* 450 */ 222, 50, 20, 264, 22, 240, 201, 234, 269, 3, - /* 460 */ 33, 239, 262, 36, 249, 57, 20, 240, 22, 42, - /* 470 */ 38, 44, 45, 46, 47, 253, 249, 76, 240, 279, - /* 480 */ 265, 258, 260, 12, 13, 84, 40, 249, 265, 57, - /* 490 */ 140, 20, 265, 22, 294, 295, 296, 258, 275, 234, - /* 500 */ 67, 74, 279, 265, 77, 266, 306, 75, 240, 38, - /* 510 */ 259, 12, 13, 14, 15, 16, 61, 249, 138, 296, - /* 520 */ 65, 134, 299, 300, 301, 302, 303, 304, 57, 306, - /* 530 */ 98, 0, 309, 265, 140, 134, 313, 314, 315, 240, - /* 540 */ 240, 154, 110, 88, 279, 250, 75, 114, 115, 249, - /* 550 */ 327, 250, 259, 258, 240, 154, 333, 334, 20, 258, - /* 560 */ 2, 266, 135, 249, 137, 265, 139, 266, 231, 98, - /* 570 */ 12, 13, 14, 15, 16, 76, 189, 258, 234, 265, - /* 580 */ 49, 110, 150, 259, 285, 158, 206, 207, 269, 22, - /* 590 */ 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - /* 600 */ 259, 1, 2, 171, 172, 38, 174, 175, 176, 177, - /* 610 */ 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, - /* 620 */ 188, 150, 285, 279, 325, 12, 13, 14, 15, 16, - /* 630 */ 12, 13, 14, 15, 16, 43, 234, 338, 234, 240, - /* 640 */ 234, 342, 171, 172, 47, 174, 175, 176, 177, 178, - /* 650 */ 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, - /* 660 */ 12, 13, 325, 50, 265, 244, 245, 297, 20, 234, - /* 670 */ 22, 74, 297, 217, 77, 338, 76, 234, 140, 342, - /* 680 */ 297, 279, 234, 279, 259, 279, 38, 234, 234, 244, - /* 690 */ 245, 321, 4, 258, 76, 234, 321, 84, 234, 72, - /* 700 */ 265, 259, 303, 76, 321, 57, 234, 234, 234, 234, - /* 710 */ 275, 246, 234, 248, 279, 234, 234, 318, 319, 320, - /* 720 */ 234, 322, 279, 75, 244, 245, 234, 279, 72, 35, - /* 730 */ 0, 296, 279, 279, 299, 300, 301, 302, 303, 304, - /* 740 */ 279, 306, 251, 279, 309, 254, 98, 134, 313, 314, - /* 750 */ 315, 279, 279, 279, 279, 61, 0, 279, 110, 65, - /* 760 */ 279, 279, 274, 275, 14, 279, 146, 154, 259, 334, - /* 770 */ 20, 279, 78, 50, 80, 81, 0, 83, 199, 200, - /* 780 */ 14, 38, 88, 288, 79, 165, 20, 82, 21, 235, - /* 790 */ 79, 61, 200, 82, 79, 65, 79, 82, 150, 82, - /* 800 */ 57, 34, 189, 190, 191, 192, 193, 194, 195, 196, - /* 810 */ 197, 198, 36, 161, 162, 247, 234, 61, 88, 171, - /* 820 */ 172, 65, 174, 175, 176, 177, 178, 179, 180, 181, - /* 830 */ 182, 183, 184, 185, 186, 187, 188, 107, 108, 109, - /* 840 */ 258, 111, 72, 345, 88, 268, 76, 265, 234, 0, - /* 850 */ 140, 141, 72, 1, 2, 72, 76, 275, 72, 76, - /* 860 */ 336, 279, 76, 107, 108, 109, 72, 111, 186, 187, - /* 870 */ 76, 22, 258, 292, 330, 237, 298, 221, 296, 265, - /* 880 */ 234, 299, 300, 301, 302, 303, 304, 0, 306, 275, - /* 890 */ 202, 309, 323, 279, 171, 313, 314, 315, 72, 72, - /* 900 */ 75, 72, 76, 76, 258, 76, 324, 258, 20, 22, - /* 910 */ 296, 265, 87, 299, 300, 301, 302, 303, 304, 0, - /* 920 */ 306, 275, 72, 309, 38, 279, 76, 313, 314, 315, - /* 930 */ 339, 72, 234, 326, 18, 76, 38, 240, 324, 23, - /* 940 */ 72, 22, 296, 4, 76, 299, 300, 301, 302, 303, - /* 950 */ 304, 35, 306, 36, 293, 309, 258, 244, 19, 313, - /* 960 */ 314, 315, 72, 265, 48, 38, 76, 72, 148, 286, - /* 970 */ 324, 76, 33, 275, 72, 36, 240, 279, 76, 22, - /* 980 */ 41, 234, 240, 285, 72, 72, 47, 121, 76, 76, - /* 990 */ 134, 273, 271, 271, 296, 38, 110, 299, 300, 301, - /* 1000 */ 302, 303, 304, 240, 306, 258, 20, 242, 110, 290, - /* 1010 */ 275, 20, 265, 74, 57, 283, 77, 242, 265, 20, - /* 1020 */ 276, 242, 275, 325, 242, 240, 279, 20, 112, 242, - /* 1030 */ 258, 236, 258, 234, 57, 258, 338, 240, 236, 258, - /* 1040 */ 342, 279, 258, 296, 290, 239, 299, 300, 301, 302, - /* 1050 */ 303, 304, 239, 306, 258, 98, 258, 258, 258, 143, - /* 1060 */ 144, 145, 258, 147, 265, 234, 258, 110, 152, 258, - /* 1070 */ 265, 157, 283, 239, 275, 239, 275, 289, 279, 276, - /* 1080 */ 164, 20, 166, 209, 168, 169, 170, 335, 298, 258, - /* 1090 */ 343, 344, 208, 335, 280, 296, 265, 279, 299, 300, - /* 1100 */ 301, 302, 303, 304, 280, 306, 275, 150, 309, 279, - /* 1110 */ 279, 279, 313, 314, 215, 234, 216, 201, 200, 204, - /* 1120 */ 265, 329, 20, 332, 331, 203, 121, 296, 171, 172, - /* 1130 */ 299, 300, 301, 302, 303, 304, 297, 306, 328, 258, - /* 1140 */ 309, 218, 75, 223, 313, 314, 265, 19, 220, 316, - /* 1150 */ 341, 280, 340, 346, 312, 234, 275, 279, 279, 279, - /* 1160 */ 279, 33, 280, 137, 36, 239, 277, 276, 265, 239, - /* 1170 */ 42, 265, 44, 45, 46, 47, 75, 296, 254, 258, - /* 1180 */ 299, 300, 301, 302, 303, 304, 265, 306, 248, 240, - /* 1190 */ 309, 239, 261, 284, 236, 314, 275, 287, 291, 252, - /* 1200 */ 279, 241, 74, 282, 232, 77, 252, 0, 234, 0, - /* 1210 */ 64, 0, 38, 167, 38, 38, 38, 296, 167, 0, - /* 1220 */ 299, 300, 301, 302, 303, 304, 38, 306, 38, 167, - /* 1230 */ 0, 38, 258, 0, 38, 107, 0, 75, 154, 265, - /* 1240 */ 153, 110, 150, 0, 0, 53, 146, 0, 0, 275, - /* 1250 */ 87, 0, 0, 279, 0, 0, 0, 234, 121, 0, - /* 1260 */ 0, 0, 0, 0, 136, 0, 0, 139, 234, 0, - /* 1270 */ 296, 0, 0, 299, 300, 301, 302, 303, 304, 0, - /* 1280 */ 306, 258, 0, 0, 156, 0, 158, 0, 265, 0, - /* 1290 */ 0, 0, 258, 0, 0, 22, 0, 0, 275, 265, - /* 1300 */ 0, 0, 279, 0, 0, 0, 0, 43, 51, 275, - /* 1310 */ 0, 337, 0, 279, 38, 234, 282, 36, 43, 296, - /* 1320 */ 0, 43, 299, 300, 301, 302, 303, 304, 36, 306, - /* 1330 */ 296, 234, 82, 299, 300, 301, 302, 303, 304, 258, - /* 1340 */ 306, 0, 43, 0, 36, 38, 265, 234, 0, 38, - /* 1350 */ 0, 38, 36, 0, 0, 258, 275, 38, 43, 22, - /* 1360 */ 279, 84, 265, 0, 38, 38, 38, 344, 38, 38, - /* 1370 */ 72, 258, 275, 38, 72, 0, 279, 296, 265, 282, - /* 1380 */ 299, 300, 301, 302, 303, 304, 22, 306, 275, 308, - /* 1390 */ 38, 0, 279, 296, 22, 282, 299, 300, 301, 302, - /* 1400 */ 303, 304, 0, 306, 39, 234, 22, 38, 0, 296, - /* 1410 */ 22, 0, 299, 300, 301, 302, 303, 304, 234, 306, - /* 1420 */ 22, 20, 0, 38, 140, 0, 22, 0, 140, 258, - /* 1430 */ 0, 0, 137, 75, 72, 155, 265, 234, 43, 72, - /* 1440 */ 205, 75, 258, 75, 135, 72, 275, 76, 87, 265, - /* 1450 */ 279, 205, 76, 75, 72, 76, 75, 87, 72, 275, - /* 1460 */ 22, 258, 38, 279, 72, 76, 76, 296, 265, 199, - /* 1470 */ 299, 300, 301, 302, 303, 304, 76, 306, 275, 72, - /* 1480 */ 296, 87, 279, 299, 300, 301, 302, 303, 304, 38, - /* 1490 */ 306, 205, 234, 38, 38, 38, 38, 2, 72, 296, - /* 1500 */ 171, 87, 299, 300, 301, 302, 303, 304, 234, 306, - /* 1510 */ 76, 75, 173, 76, 75, 75, 258, 75, 138, 87, - /* 1520 */ 76, 76, 75, 265, 75, 75, 0, 43, 135, 75, - /* 1530 */ 22, 85, 258, 275, 75, 87, 76, 279, 75, 265, - /* 1540 */ 87, 75, 38, 76, 38, 75, 75, 86, 234, 275, - /* 1550 */ 76, 38, 76, 279, 296, 38, 75, 299, 300, 301, - /* 1560 */ 302, 303, 304, 76, 306, 38, 234, 75, 38, 76, - /* 1570 */ 296, 75, 258, 299, 300, 301, 302, 303, 304, 265, - /* 1580 */ 306, 234, 100, 100, 22, 100, 100, 88, 38, 275, - /* 1590 */ 258, 75, 38, 279, 75, 75, 22, 265, 110, 51, - /* 1600 */ 57, 50, 38, 38, 73, 258, 72, 275, 38, 38, - /* 1610 */ 296, 279, 265, 299, 300, 301, 302, 303, 304, 38, - /* 1620 */ 306, 38, 275, 38, 38, 22, 279, 38, 296, 57, - /* 1630 */ 234, 299, 300, 301, 302, 303, 304, 38, 306, 38, - /* 1640 */ 38, 0, 38, 296, 38, 38, 299, 300, 301, 302, - /* 1650 */ 303, 304, 38, 306, 258, 38, 36, 0, 43, 38, - /* 1660 */ 36, 265, 43, 0, 38, 36, 43, 0, 38, 36, - /* 1670 */ 43, 275, 0, 38, 37, 279, 0, 234, 0, 20, - /* 1680 */ 22, 21, 347, 22, 22, 21, 347, 347, 347, 347, - /* 1690 */ 347, 347, 296, 347, 347, 299, 300, 301, 302, 303, - /* 1700 */ 304, 258, 306, 347, 347, 347, 347, 234, 265, 347, - /* 1710 */ 347, 347, 347, 347, 347, 347, 347, 347, 275, 347, - /* 1720 */ 347, 347, 279, 347, 347, 347, 347, 347, 347, 347, - /* 1730 */ 347, 258, 347, 347, 347, 347, 347, 234, 265, 296, - /* 1740 */ 347, 347, 299, 300, 301, 302, 303, 304, 275, 306, - /* 1750 */ 347, 347, 279, 347, 347, 347, 347, 347, 347, 347, - /* 1760 */ 347, 258, 347, 347, 347, 347, 347, 234, 265, 296, - /* 1770 */ 347, 347, 299, 300, 301, 302, 303, 304, 275, 306, - /* 1780 */ 347, 347, 279, 347, 347, 347, 347, 347, 347, 347, - /* 1790 */ 347, 258, 347, 347, 347, 347, 347, 234, 265, 296, - /* 1800 */ 347, 347, 299, 300, 301, 302, 303, 304, 275, 306, - /* 1810 */ 347, 347, 279, 347, 347, 347, 234, 347, 347, 347, - /* 1820 */ 347, 258, 347, 347, 347, 347, 347, 347, 265, 296, - /* 1830 */ 347, 347, 299, 300, 301, 302, 303, 304, 275, 306, - /* 1840 */ 258, 347, 279, 347, 347, 347, 234, 265, 12, 13, - /* 1850 */ 347, 347, 347, 347, 347, 347, 347, 275, 22, 296, - /* 1860 */ 347, 279, 299, 300, 301, 302, 303, 304, 347, 306, - /* 1870 */ 258, 347, 347, 347, 38, 347, 347, 265, 296, 347, - /* 1880 */ 347, 299, 300, 301, 302, 303, 304, 275, 306, 347, - /* 1890 */ 347, 279, 347, 57, 347, 347, 347, 347, 347, 347, - /* 1900 */ 347, 347, 347, 347, 347, 347, 347, 347, 296, 347, - /* 1910 */ 347, 299, 300, 301, 302, 303, 304, 347, 306, 347, - /* 1920 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 1930 */ 347, 347, 347, 347, 98, 347, 347, 347, 347, 347, - /* 1940 */ 347, 347, 347, 347, 347, 347, 110, 347, 347, 347, - /* 1950 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 1960 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 1970 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 1980 */ 347, 347, 347, 347, 347, 347, 150, 347, 347, 347, - /* 1990 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 2000 */ 347, 347, 347, 347, 347, 347, 347, 171, 347, 347, - /* 2010 */ 347, 347, 347, 347, 347, 347, 347, 347, 182, 183, - /* 2020 */ 184, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 2030 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 2040 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, - /* 2050 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 440 */ 185, 186, 187, 188, 1, 2, 242, 96, 47, 263, + /* 450 */ 288, 279, 52, 53, 19, 259, 201, 57, 107, 255, + /* 460 */ 60, 61, 150, 279, 64, 65, 66, 263, 33, 259, + /* 470 */ 279, 36, 74, 72, 234, 234, 75, 42, 265, 44, + /* 480 */ 45, 46, 47, 171, 172, 272, 174, 175, 176, 177, + /* 490 */ 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, + /* 500 */ 188, 150, 12, 13, 14, 15, 16, 72, 250, 3, + /* 510 */ 75, 12, 13, 14, 15, 16, 258, 74, 240, 279, + /* 520 */ 279, 4, 171, 172, 266, 174, 175, 176, 177, 178, + /* 530 */ 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + /* 540 */ 12, 13, 18, 265, 20, 110, 239, 234, 20, 72, + /* 550 */ 22, 27, 161, 162, 30, 240, 275, 80, 239, 38, + /* 560 */ 240, 0, 281, 39, 249, 240, 38, 260, 285, 249, + /* 570 */ 135, 258, 253, 138, 249, 234, 256, 56, 265, 260, + /* 580 */ 265, 303, 259, 86, 56, 265, 234, 234, 275, 234, + /* 590 */ 265, 156, 279, 158, 43, 317, 318, 319, 320, 297, + /* 600 */ 322, 73, 105, 106, 240, 108, 109, 110, 325, 296, + /* 610 */ 49, 235, 299, 300, 301, 302, 303, 304, 141, 306, + /* 620 */ 279, 338, 309, 321, 96, 342, 313, 314, 315, 265, + /* 630 */ 251, 279, 279, 254, 279, 107, 112, 324, 139, 115, + /* 640 */ 116, 117, 118, 119, 0, 121, 122, 123, 124, 125, + /* 650 */ 126, 127, 128, 129, 130, 131, 132, 258, 12, 13, + /* 660 */ 14, 15, 16, 274, 275, 266, 258, 303, 24, 25, + /* 670 */ 26, 27, 28, 29, 30, 31, 32, 269, 150, 199, + /* 680 */ 200, 250, 318, 319, 320, 0, 322, 20, 259, 258, + /* 690 */ 50, 234, 14, 234, 234, 234, 50, 266, 20, 171, + /* 700 */ 172, 234, 174, 175, 176, 177, 178, 179, 180, 181, + /* 710 */ 182, 183, 184, 185, 186, 187, 188, 258, 240, 202, + /* 720 */ 74, 36, 145, 217, 265, 240, 234, 249, 82, 12, + /* 730 */ 13, 14, 15, 16, 275, 234, 279, 250, 279, 279, + /* 740 */ 279, 14, 165, 265, 70, 258, 279, 20, 74, 345, + /* 750 */ 265, 200, 18, 266, 70, 296, 247, 23, 299, 300, + /* 760 */ 301, 302, 303, 304, 262, 306, 240, 50, 309, 35, + /* 770 */ 285, 279, 313, 314, 315, 249, 240, 38, 22, 133, + /* 780 */ 279, 279, 48, 70, 77, 249, 327, 80, 303, 234, + /* 790 */ 259, 265, 333, 334, 38, 292, 294, 295, 296, 82, + /* 800 */ 154, 265, 259, 318, 319, 320, 139, 322, 306, 77, + /* 810 */ 325, 171, 80, 258, 77, 77, 21, 80, 80, 259, + /* 820 */ 265, 139, 140, 338, 240, 0, 0, 342, 70, 34, + /* 830 */ 275, 0, 74, 249, 279, 189, 190, 191, 192, 193, + /* 840 */ 194, 195, 196, 197, 198, 111, 107, 22, 22, 265, + /* 850 */ 133, 296, 1, 2, 299, 300, 301, 302, 303, 304, + /* 860 */ 0, 306, 70, 70, 309, 240, 74, 74, 313, 314, + /* 870 */ 315, 154, 186, 187, 249, 70, 142, 143, 144, 74, + /* 880 */ 38, 147, 22, 52, 53, 336, 152, 330, 57, 334, + /* 890 */ 265, 60, 61, 234, 237, 64, 65, 66, 164, 268, + /* 900 */ 166, 298, 168, 169, 170, 221, 189, 190, 191, 192, + /* 910 */ 193, 194, 195, 196, 197, 198, 240, 258, 70, 70, + /* 920 */ 323, 258, 74, 74, 265, 249, 70, 70, 339, 70, + /* 930 */ 74, 74, 219, 74, 275, 201, 326, 20, 279, 70, + /* 940 */ 234, 265, 70, 74, 70, 240, 74, 70, 74, 107, + /* 950 */ 70, 74, 70, 70, 74, 296, 74, 74, 299, 300, + /* 960 */ 301, 302, 303, 304, 258, 306, 73, 38, 309, 38, + /* 970 */ 36, 265, 313, 314, 315, 244, 83, 148, 286, 133, + /* 980 */ 293, 275, 0, 324, 240, 279, 240, 56, 120, 273, + /* 990 */ 271, 271, 240, 20, 290, 242, 275, 20, 283, 242, + /* 1000 */ 265, 20, 296, 242, 276, 299, 300, 301, 302, 303, + /* 1010 */ 304, 242, 306, 240, 242, 309, 20, 236, 258, 313, + /* 1020 */ 314, 315, 258, 258, 258, 258, 258, 240, 234, 258, + /* 1030 */ 324, 56, 258, 258, 52, 53, 54, 55, 258, 57, + /* 1040 */ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + /* 1050 */ 68, 69, 258, 236, 258, 279, 157, 239, 275, 265, + /* 1060 */ 290, 239, 283, 239, 265, 276, 289, 239, 20, 275, + /* 1070 */ 209, 335, 208, 279, 216, 234, 298, 280, 335, 285, + /* 1080 */ 279, 332, 280, 279, 329, 279, 215, 328, 204, 203, + /* 1090 */ 296, 200, 265, 299, 300, 301, 302, 303, 304, 258, + /* 1100 */ 306, 20, 316, 341, 297, 120, 265, 220, 223, 346, + /* 1110 */ 218, 73, 312, 331, 280, 279, 275, 279, 279, 325, + /* 1120 */ 279, 277, 136, 280, 340, 73, 276, 265, 234, 239, + /* 1130 */ 254, 265, 338, 236, 239, 239, 342, 296, 291, 234, + /* 1140 */ 299, 300, 301, 302, 303, 304, 248, 306, 240, 261, + /* 1150 */ 309, 284, 258, 252, 313, 314, 252, 287, 252, 265, + /* 1160 */ 241, 0, 232, 258, 0, 64, 0, 167, 38, 275, + /* 1170 */ 265, 38, 38, 279, 38, 167, 0, 38, 167, 38, + /* 1180 */ 275, 0, 38, 0, 279, 38, 0, 73, 154, 153, + /* 1190 */ 296, 107, 150, 299, 300, 301, 302, 303, 304, 234, + /* 1200 */ 306, 296, 0, 0, 299, 300, 301, 302, 303, 304, + /* 1210 */ 146, 306, 145, 0, 309, 120, 85, 234, 0, 314, + /* 1220 */ 0, 0, 0, 258, 0, 0, 0, 0, 0, 0, + /* 1230 */ 265, 0, 0, 0, 0, 0, 0, 343, 344, 0, + /* 1240 */ 275, 258, 0, 0, 279, 0, 0, 282, 265, 0, + /* 1250 */ 234, 0, 0, 0, 0, 0, 0, 0, 275, 22, + /* 1260 */ 0, 296, 279, 0, 299, 300, 301, 302, 303, 304, + /* 1270 */ 0, 306, 0, 43, 258, 82, 38, 0, 38, 296, + /* 1280 */ 234, 265, 299, 300, 301, 302, 303, 304, 0, 306, + /* 1290 */ 43, 275, 51, 0, 4, 279, 0, 36, 282, 0, + /* 1300 */ 36, 43, 36, 38, 258, 43, 0, 38, 0, 19, + /* 1310 */ 234, 265, 296, 0, 36, 299, 300, 301, 302, 303, + /* 1320 */ 304, 275, 306, 33, 43, 279, 36, 344, 0, 0, + /* 1330 */ 80, 41, 38, 22, 258, 38, 38, 47, 0, 38, + /* 1340 */ 38, 265, 296, 70, 70, 299, 300, 301, 302, 303, + /* 1350 */ 304, 275, 306, 38, 308, 279, 38, 38, 282, 0, + /* 1360 */ 0, 22, 72, 234, 22, 75, 39, 0, 22, 38, + /* 1370 */ 0, 22, 296, 0, 234, 299, 300, 301, 302, 303, + /* 1380 */ 304, 0, 306, 22, 20, 38, 0, 258, 22, 0, + /* 1390 */ 0, 0, 70, 73, 265, 136, 43, 205, 258, 155, + /* 1400 */ 70, 85, 70, 70, 275, 265, 139, 139, 279, 73, + /* 1410 */ 134, 282, 205, 199, 74, 275, 205, 74, 73, 279, + /* 1420 */ 38, 73, 70, 38, 74, 296, 85, 73, 299, 300, + /* 1430 */ 301, 302, 303, 304, 234, 306, 296, 74, 70, 299, + /* 1440 */ 300, 301, 302, 303, 304, 74, 306, 85, 74, 234, + /* 1450 */ 70, 38, 38, 38, 38, 2, 171, 70, 258, 22, + /* 1460 */ 85, 85, 173, 137, 0, 265, 74, 73, 43, 74, + /* 1470 */ 73, 73, 22, 258, 73, 275, 74, 74, 73, 279, + /* 1480 */ 265, 73, 73, 73, 73, 134, 74, 83, 22, 38, + /* 1490 */ 275, 85, 85, 73, 279, 73, 296, 74, 38, 299, + /* 1500 */ 300, 301, 302, 303, 304, 84, 306, 73, 38, 234, + /* 1510 */ 74, 296, 73, 38, 299, 300, 301, 302, 303, 304, + /* 1520 */ 234, 306, 74, 74, 38, 73, 38, 73, 98, 74, + /* 1530 */ 73, 98, 86, 258, 73, 73, 98, 38, 98, 234, + /* 1540 */ 265, 73, 107, 38, 258, 22, 51, 50, 56, 71, + /* 1550 */ 275, 265, 70, 38, 279, 38, 38, 38, 38, 22, + /* 1560 */ 38, 275, 38, 258, 56, 279, 38, 38, 38, 234, + /* 1570 */ 265, 296, 0, 38, 299, 300, 301, 302, 303, 304, + /* 1580 */ 275, 306, 296, 36, 279, 299, 300, 301, 302, 303, + /* 1590 */ 304, 38, 306, 258, 38, 38, 38, 43, 0, 38, + /* 1600 */ 265, 296, 36, 43, 299, 300, 301, 302, 303, 304, + /* 1610 */ 275, 306, 0, 38, 279, 36, 43, 0, 38, 36, + /* 1620 */ 43, 0, 234, 38, 37, 0, 0, 22, 21, 20, + /* 1630 */ 22, 296, 22, 234, 299, 300, 301, 302, 303, 304, + /* 1640 */ 21, 306, 347, 347, 347, 347, 258, 347, 347, 347, + /* 1650 */ 347, 347, 347, 265, 347, 347, 347, 258, 347, 347, + /* 1660 */ 347, 347, 347, 275, 265, 347, 347, 279, 347, 347, + /* 1670 */ 347, 347, 347, 347, 275, 347, 347, 347, 279, 347, + /* 1680 */ 347, 347, 347, 347, 296, 347, 347, 299, 300, 301, + /* 1690 */ 302, 303, 304, 234, 306, 296, 347, 347, 299, 300, + /* 1700 */ 301, 302, 303, 304, 347, 306, 347, 347, 234, 347, + /* 1710 */ 347, 347, 347, 347, 347, 347, 347, 258, 347, 347, + /* 1720 */ 347, 347, 347, 347, 265, 347, 347, 347, 347, 347, + /* 1730 */ 347, 347, 258, 347, 275, 347, 347, 347, 279, 265, + /* 1740 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 275, + /* 1750 */ 347, 347, 347, 279, 347, 296, 347, 347, 299, 300, + /* 1760 */ 301, 302, 303, 304, 347, 306, 347, 347, 234, 347, + /* 1770 */ 296, 347, 347, 299, 300, 301, 302, 303, 304, 234, + /* 1780 */ 306, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 1790 */ 347, 347, 258, 347, 347, 347, 347, 347, 234, 265, + /* 1800 */ 347, 347, 347, 258, 347, 347, 347, 347, 347, 275, + /* 1810 */ 265, 347, 347, 279, 347, 347, 347, 347, 347, 347, + /* 1820 */ 275, 347, 258, 347, 279, 347, 347, 347, 234, 265, + /* 1830 */ 296, 347, 347, 299, 300, 301, 302, 303, 304, 275, + /* 1840 */ 306, 296, 347, 279, 299, 300, 301, 302, 303, 304, + /* 1850 */ 347, 306, 258, 347, 347, 347, 347, 347, 347, 265, + /* 1860 */ 296, 347, 347, 299, 300, 301, 302, 303, 304, 275, + /* 1870 */ 306, 33, 347, 279, 36, 347, 12, 13, 347, 347, + /* 1880 */ 42, 234, 44, 45, 46, 47, 22, 347, 347, 347, + /* 1890 */ 296, 347, 347, 299, 300, 301, 302, 303, 304, 347, + /* 1900 */ 306, 347, 38, 22, 347, 258, 347, 347, 347, 347, + /* 1910 */ 72, 347, 265, 75, 347, 347, 347, 347, 347, 38, + /* 1920 */ 56, 347, 275, 347, 347, 347, 279, 347, 347, 347, + /* 1930 */ 347, 347, 347, 347, 347, 347, 347, 56, 347, 347, + /* 1940 */ 347, 347, 347, 296, 347, 347, 299, 300, 301, 302, + /* 1950 */ 303, 304, 347, 306, 347, 347, 347, 347, 347, 347, + /* 1960 */ 96, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 1970 */ 347, 107, 134, 347, 136, 347, 138, 96, 347, 347, + /* 1980 */ 347, 347, 347, 347, 347, 347, 347, 347, 107, 347, + /* 1990 */ 347, 347, 347, 347, 347, 347, 158, 347, 347, 347, + /* 2000 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2010 */ 347, 347, 347, 347, 150, 347, 347, 347, 347, 347, + /* 2020 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2030 */ 347, 150, 347, 347, 347, 171, 347, 347, 347, 347, + /* 2040 */ 347, 347, 347, 347, 347, 347, 182, 183, 184, 347, + /* 2050 */ 347, 347, 171, 172, 347, 347, 347, 347, 347, 347, /* 2060 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, /* 2070 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2080 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2090 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2100 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2110 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2120 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2130 */ 347, 347, 347, 347, 347, }; -#define YY_SHIFT_COUNT (574) +#define YY_SHIFT_COUNT (568) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1836) +#define YY_SHIFT_MAX (1881) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 916, 0, 39, 216, 216, 216, 216, 255, 216, 216, - /* 10 */ 432, 471, 648, 471, 471, 471, 471, 471, 471, 471, - /* 20 */ 471, 471, 471, 471, 471, 471, 471, 471, 471, 471, - /* 30 */ 471, 471, 471, 471, 471, 471, 34, 36, 36, 36, - /* 40 */ 1836, 1836, 1836, 153, 49, 9, 9, 133, 54, 9, - /* 50 */ 9, 9, 9, 9, 9, 55, 9, 118, 136, 133, - /* 60 */ 272, 118, 9, 9, 118, 9, 118, 272, 118, 118, - /* 70 */ 9, 323, 219, 401, 613, 613, 258, 957, 694, 141, - /* 80 */ 957, 957, 957, 957, 957, 957, 957, 957, 957, 957, - /* 90 */ 957, 957, 957, 957, 957, 957, 957, 957, 957, 446, - /* 100 */ 340, 91, 91, 350, 350, 350, 531, 91, 91, 297, - /* 110 */ 272, 118, 272, 118, 291, 408, 29, 29, 29, 29, - /* 120 */ 29, 29, 29, 1128, 115, 315, 228, 211, 455, 159, - /* 130 */ 380, 567, 538, 579, 592, 579, 750, 456, 688, 766, - /* 140 */ 888, 917, 927, 820, 888, 888, 866, 856, 856, 888, - /* 150 */ 986, 55, 272, 991, 55, 297, 999, 55, 55, 888, - /* 160 */ 55, 1007, 118, 118, 118, 118, 118, 118, 118, 118, - /* 170 */ 118, 118, 118, 888, 1007, 977, 986, 323, 914, 272, - /* 180 */ 323, 991, 323, 297, 999, 323, 1061, 874, 884, 977, - /* 190 */ 874, 884, 977, 977, 900, 899, 915, 922, 918, 297, - /* 200 */ 1102, 1005, 920, 928, 923, 1067, 118, 884, 977, 977, - /* 210 */ 884, 977, 1026, 297, 999, 323, 291, 323, 297, 1101, - /* 220 */ 408, 888, 323, 1007, 2021, 2021, 2021, 2021, 2021, 2021, - /* 230 */ 2021, 99, 427, 331, 939, 730, 756, 499, 78, 558, - /* 240 */ 394, 618, 27, 27, 27, 27, 27, 27, 27, 27, - /* 250 */ 597, 433, 178, 600, 387, 176, 176, 176, 176, 776, - /* 260 */ 620, 627, 705, 711, 715, 717, 849, 887, 919, 767, - /* 270 */ 652, 710, 770, 780, 783, 852, 682, 44, 656, 786, - /* 280 */ 723, 794, 825, 826, 827, 829, 850, 859, 886, 898, - /* 290 */ 868, 890, 895, 902, 912, 913, 121, 743, 1207, 1209, - /* 300 */ 1146, 1211, 1174, 1046, 1176, 1177, 1178, 1051, 1219, 1188, - /* 310 */ 1190, 1062, 1230, 1193, 1233, 1196, 1236, 1162, 1084, 1087, - /* 320 */ 1131, 1092, 1243, 1244, 1192, 1100, 1247, 1248, 1163, 1251, - /* 330 */ 1252, 1254, 1255, 1256, 1265, 1266, 1269, 1271, 1272, 1279, - /* 340 */ 1282, 1283, 1285, 1287, 1289, 1290, 1137, 1259, 1260, 1261, - /* 350 */ 1262, 1263, 1291, 1273, 1293, 1294, 1296, 1297, 1300, 1301, - /* 360 */ 1303, 1304, 1305, 1264, 1306, 1257, 1310, 1312, 1276, 1281, - /* 370 */ 1275, 1320, 1307, 1292, 1278, 1341, 1311, 1308, 1299, 1343, - /* 380 */ 1313, 1316, 1315, 1348, 1350, 1353, 1354, 1277, 1250, 1319, - /* 390 */ 1298, 1302, 1337, 1363, 1326, 1327, 1328, 1330, 1331, 1298, - /* 400 */ 1302, 1335, 1352, 1375, 1364, 1391, 1372, 1365, 1402, 1384, - /* 410 */ 1369, 1408, 1388, 1411, 1398, 1401, 1422, 1284, 1385, 1425, - /* 420 */ 1280, 1404, 1288, 1295, 1427, 1430, 1431, 1358, 1395, 1309, - /* 430 */ 1362, 1367, 1235, 1371, 1373, 1376, 1366, 1368, 1378, 1379, - /* 440 */ 1382, 1361, 1381, 1386, 1246, 1389, 1390, 1370, 1270, 1392, - /* 450 */ 1394, 1400, 1407, 1286, 1424, 1451, 1455, 1456, 1457, 1458, - /* 460 */ 1495, 1329, 1426, 1434, 1436, 1437, 1414, 1439, 1440, 1432, - /* 470 */ 1438, 1339, 1442, 1444, 1445, 1447, 1449, 1380, 1450, 1526, - /* 480 */ 1484, 1393, 1454, 1446, 1448, 1453, 1459, 1460, 1463, 1508, - /* 490 */ 1466, 1461, 1467, 1504, 1506, 1470, 1474, 1513, 1471, 1476, - /* 500 */ 1517, 1481, 1487, 1527, 1492, 1493, 1530, 1496, 1482, 1483, - /* 510 */ 1485, 1486, 1562, 1499, 1516, 1550, 1488, 1519, 1520, 1554, - /* 520 */ 1298, 1302, 1574, 1548, 1551, 1564, 1543, 1531, 1534, 1565, - /* 530 */ 1570, 1571, 1581, 1583, 1585, 1586, 1603, 1572, 1298, 1589, - /* 540 */ 1302, 1599, 1601, 1602, 1604, 1606, 1607, 1614, 1641, 1617, - /* 550 */ 1620, 1615, 1657, 1621, 1624, 1619, 1663, 1626, 1629, 1623, - /* 560 */ 1667, 1630, 1633, 1627, 1672, 1635, 1637, 1676, 1678, 1658, - /* 570 */ 1660, 1661, 1662, 1664, 1659, + /* 0 */ 734, 0, 39, 216, 216, 216, 216, 255, 216, 216, + /* 10 */ 312, 351, 528, 351, 351, 351, 351, 351, 351, 351, + /* 20 */ 351, 351, 351, 351, 351, 351, 351, 351, 351, 351, + /* 30 */ 351, 351, 351, 351, 351, 351, 40, 188, 188, 188, + /* 40 */ 1864, 1864, 1864, 29, 136, 12, 12, 96, 93, 12, + /* 50 */ 12, 12, 12, 12, 12, 14, 12, 63, 86, 96, + /* 60 */ 90, 63, 12, 12, 63, 12, 63, 63, 90, 63, + /* 70 */ 12, 81, 524, 646, 717, 717, 218, 1881, 400, 1881, + /* 80 */ 1881, 1881, 1881, 1881, 1881, 1881, 1881, 1881, 1881, 1881, + /* 90 */ 1881, 1881, 1881, 1881, 1881, 1881, 1881, 1881, 177, 71, + /* 100 */ 360, 521, 70, 70, 70, 561, 521, 125, 90, 63, + /* 110 */ 63, 90, 273, 365, 103, 103, 103, 103, 103, 103, + /* 120 */ 103, 435, 128, 831, 127, 69, 10, 123, 756, 224, + /* 130 */ 667, 480, 551, 480, 678, 506, 517, 727, 917, 934, + /* 140 */ 929, 829, 917, 917, 868, 846, 846, 917, 973, 14, + /* 150 */ 90, 977, 14, 125, 981, 14, 14, 917, 14, 996, + /* 160 */ 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + /* 170 */ 63, 917, 996, 975, 973, 81, 899, 90, 81, 977, + /* 180 */ 81, 125, 981, 81, 1048, 861, 864, 975, 861, 864, + /* 190 */ 975, 975, 858, 871, 884, 886, 891, 125, 1081, 985, + /* 200 */ 885, 887, 892, 1038, 63, 864, 975, 975, 864, 975, + /* 210 */ 986, 125, 981, 81, 273, 81, 125, 1052, 365, 917, + /* 220 */ 81, 996, 2054, 2054, 2054, 2054, 2054, 2054, 2054, 2054, + /* 230 */ 982, 1838, 644, 1290, 58, 234, 303, 21, 102, 499, + /* 240 */ 398, 497, 490, 490, 490, 490, 490, 490, 490, 490, + /* 250 */ 401, 7, 477, 443, 119, 276, 276, 276, 276, 685, + /* 260 */ 577, 674, 707, 732, 737, 738, 825, 826, 860, 795, + /* 270 */ 391, 682, 758, 792, 793, 851, 686, 713, 684, 805, + /* 280 */ 640, 848, 280, 849, 856, 857, 859, 869, 739, 842, + /* 290 */ 872, 874, 877, 880, 882, 883, 893, 931, 1161, 1164, + /* 300 */ 1101, 1166, 1130, 1000, 1133, 1134, 1136, 1008, 1176, 1139, + /* 310 */ 1141, 1011, 1181, 1144, 1183, 1147, 1186, 1114, 1034, 1036, + /* 320 */ 1084, 1042, 1202, 1203, 1064, 1067, 1213, 1218, 1131, 1220, + /* 330 */ 1221, 1222, 1224, 1225, 1226, 1227, 1228, 1229, 1231, 1232, + /* 340 */ 1233, 1234, 1235, 1236, 1239, 1242, 1095, 1243, 1245, 1246, + /* 350 */ 1249, 1251, 1252, 1237, 1253, 1254, 1255, 1256, 1257, 1260, + /* 360 */ 1263, 1270, 1272, 1230, 1288, 1241, 1293, 1296, 1238, 1261, + /* 370 */ 1247, 1277, 1240, 1264, 1258, 1299, 1265, 1266, 1262, 1306, + /* 380 */ 1269, 1278, 1281, 1308, 1313, 1328, 1329, 1193, 1250, 1294, + /* 390 */ 1311, 1338, 1297, 1298, 1301, 1302, 1273, 1274, 1315, 1318, + /* 400 */ 1319, 1359, 1339, 1360, 1342, 1327, 1367, 1346, 1331, 1370, + /* 410 */ 1349, 1373, 1361, 1364, 1381, 1267, 1347, 1386, 1244, 1366, + /* 420 */ 1268, 1259, 1389, 1390, 1391, 1320, 1353, 1276, 1322, 1330, + /* 430 */ 1192, 1340, 1332, 1343, 1336, 1345, 1348, 1350, 1333, 1316, + /* 440 */ 1354, 1352, 1207, 1363, 1371, 1341, 1214, 1368, 1362, 1374, + /* 450 */ 1380, 1211, 1382, 1385, 1413, 1414, 1415, 1416, 1453, 1285, + /* 460 */ 1387, 1392, 1394, 1395, 1375, 1397, 1398, 1376, 1437, 1289, + /* 470 */ 1401, 1402, 1403, 1405, 1408, 1326, 1409, 1464, 1425, 1351, + /* 480 */ 1410, 1404, 1406, 1407, 1411, 1412, 1420, 1450, 1422, 1421, + /* 490 */ 1423, 1451, 1460, 1434, 1436, 1470, 1439, 1448, 1475, 1452, + /* 500 */ 1449, 1486, 1454, 1455, 1488, 1457, 1430, 1433, 1438, 1440, + /* 510 */ 1466, 1446, 1461, 1462, 1499, 1468, 1435, 1505, 1523, 1495, + /* 520 */ 1497, 1492, 1478, 1482, 1515, 1517, 1518, 1519, 1520, 1537, + /* 530 */ 1522, 1524, 1508, 1273, 1528, 1274, 1529, 1530, 1535, 1553, + /* 540 */ 1556, 1557, 1572, 1558, 1547, 1554, 1598, 1561, 1566, 1560, + /* 550 */ 1612, 1575, 1579, 1573, 1617, 1580, 1583, 1577, 1621, 1585, + /* 560 */ 1587, 1625, 1626, 1605, 1607, 1608, 1610, 1619, 1609, }; -#define YY_REDUCE_COUNT (230) -#define YY_REDUCE_MIN (-278) -#define YY_REDUCE_MAX (1612) +#define YY_REDUCE_COUNT (229) +#define YY_REDUCE_MIN (-323) +#define YY_REDUCE_MAX (1647) static const short yy_reduce_ofst[] = { - /* 0 */ 337, -230, 223, 435, 582, 614, 646, 698, 799, 831, - /* 10 */ -1, 747, 881, 921, 974, 1023, 1034, 1081, 1097, 1113, - /* 20 */ 1171, 1184, 1203, 1258, 1274, 1314, 1332, 1347, 1396, 1443, - /* 30 */ 1473, 1503, 1533, 1563, 1582, 1612, -9, -217, 5, 399, - /* 40 */ -262, 200, -270, 299, -278, -238, -235, -91, -260, -234, - /* 50 */ -203, -152, 31, 32, 215, 6, 227, -61, 63, -257, - /* 60 */ -16, 162, 238, 268, 116, 300, 295, 144, 189, 301, - /* 70 */ 314, 222, -153, -204, -204, -204, -232, 265, -249, -180, - /* 80 */ 344, 402, 404, 406, 443, 448, 453, 454, 461, 464, - /* 90 */ 472, 473, 474, 475, 478, 481, 482, 486, 492, 146, - /* 100 */ -33, 204, 421, 370, 375, 383, -7, 445, 480, 103, - /* 110 */ -265, 239, 488, 319, 491, 465, 251, 293, 324, 341, - /* 120 */ 425, 442, 509, 495, 554, 568, 498, 524, 577, 581, - /* 130 */ 544, 638, 578, 569, 569, 569, 649, 591, 607, 649, - /* 140 */ 697, 661, 713, 683, 736, 742, 718, 721, 722, 763, - /* 150 */ 719, 765, 735, 732, 775, 753, 744, 779, 782, 785, - /* 160 */ 787, 795, 772, 774, 777, 781, 784, 796, 798, 800, - /* 170 */ 804, 808, 811, 797, 802, 762, 754, 806, 788, 801, - /* 180 */ 813, 789, 834, 805, 803, 836, 790, 752, 814, 818, - /* 190 */ 758, 824, 830, 832, 791, 793, 792, 810, 569, 855, - /* 200 */ 839, 833, 807, 809, 812, 842, 649, 871, 878, 879, - /* 210 */ 882, 880, 889, 903, 891, 926, 924, 930, 906, 931, - /* 220 */ 940, 949, 952, 958, 910, 907, 909, 947, 954, 960, - /* 230 */ 972, + /* 0 */ -191, -177, 459, 555, 313, 659, 706, 794, -234, 841, + /* 10 */ -1, 894, 905, 965, 80, 983, 1016, 1046, 1076, 1129, + /* 20 */ 1140, 1200, 1215, 1275, 1286, 1305, 1335, 1388, 1399, 1459, + /* 30 */ 1474, 1534, 1545, 1564, 1594, 1647, 485, 278, -219, 364, + /* 40 */ -252, 502, -278, 36, -54, -201, 320, 283, -323, -235, + /* 50 */ 82, 315, 325, 478, 526, 204, 536, -182, -254, -233, + /* 60 */ -272, 258, 584, 625, 1, 676, 431, 77, -189, 487, + /* 70 */ 87, 319, -8, -303, -303, -303, -102, -208, -218, 17, + /* 80 */ 75, 79, 141, 172, 184, 191, 240, 241, 341, 352, + /* 90 */ 353, 355, 457, 460, 461, 467, 492, 501, 99, 132, + /* 100 */ 186, 171, -159, 51, 302, 307, 178, 213, 281, 399, + /* 110 */ 408, 389, 379, -11, 196, 210, 323, 429, 531, 543, + /* 120 */ 560, 162, 376, 509, 404, 549, 503, 557, 657, 631, + /* 130 */ 603, 597, 597, 597, 663, 589, 610, 663, 705, 687, + /* 140 */ 731, 692, 744, 746, 716, 719, 720, 752, 704, 753, + /* 150 */ 721, 715, 757, 735, 728, 761, 769, 773, 772, 781, + /* 160 */ 760, 764, 765, 766, 767, 768, 771, 774, 775, 780, + /* 170 */ 796, 787, 817, 776, 770, 818, 777, 783, 822, 779, + /* 180 */ 824, 799, 789, 828, 778, 736, 797, 801, 743, 802, + /* 190 */ 804, 806, 749, 782, 755, 759, 597, 827, 807, 786, + /* 200 */ 763, 762, 784, 800, 663, 834, 836, 838, 843, 839, + /* 210 */ 844, 862, 850, 890, 876, 895, 866, 888, 898, 908, + /* 220 */ 896, 897, 870, 847, 867, 901, 904, 906, 919, 930, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 10 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 20 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 30 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 40 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 50 */ 1301, 1301, 1301, 1301, 1301, 1360, 1301, 1301, 1301, 1301, - /* 60 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 70 */ 1301, 1358, 1503, 1301, 1666, 1301, 1301, 1301, 1301, 1301, - /* 80 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 90 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 100 */ 1360, 1301, 1301, 1677, 1677, 1677, 1358, 1301, 1301, 1301, - /* 110 */ 1301, 1301, 1301, 1301, 1455, 1301, 1301, 1301, 1301, 1301, - /* 120 */ 1301, 1301, 1301, 1541, 1301, 1301, 1742, 1301, 1408, 1547, - /* 130 */ 1701, 1301, 1693, 1669, 1683, 1670, 1301, 1727, 1686, 1301, - /* 140 */ 1301, 1301, 1301, 1533, 1301, 1301, 1508, 1505, 1505, 1301, - /* 150 */ 1301, 1360, 1301, 1301, 1360, 1301, 1301, 1360, 1360, 1301, - /* 160 */ 1360, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 170 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1358, 1543, 1301, - /* 180 */ 1358, 1301, 1358, 1301, 1301, 1358, 1301, 1708, 1706, 1301, - /* 190 */ 1708, 1706, 1301, 1301, 1720, 1716, 1699, 1697, 1683, 1301, - /* 200 */ 1301, 1301, 1745, 1733, 1729, 1301, 1301, 1706, 1301, 1301, - /* 210 */ 1706, 1301, 1516, 1301, 1301, 1358, 1301, 1358, 1301, 1424, - /* 220 */ 1301, 1301, 1358, 1301, 1535, 1549, 1525, 1458, 1458, 1361, - /* 230 */ 1306, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 240 */ 1301, 1301, 1611, 1719, 1718, 1642, 1641, 1640, 1638, 1610, - /* 250 */ 1301, 1301, 1301, 1301, 1301, 1604, 1605, 1603, 1602, 1301, - /* 260 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 270 */ 1301, 1301, 1301, 1301, 1301, 1667, 1301, 1730, 1734, 1301, - /* 280 */ 1301, 1301, 1588, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 290 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 300 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 310 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 320 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 330 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 340 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 350 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 360 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 370 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 380 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 390 */ 1471, 1470, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1388, - /* 400 */ 1387, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 410 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 420 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 430 */ 1690, 1700, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 440 */ 1301, 1588, 1301, 1717, 1301, 1676, 1672, 1301, 1301, 1668, - /* 450 */ 1301, 1301, 1728, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 460 */ 1662, 1301, 1635, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 470 */ 1301, 1598, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 480 */ 1301, 1301, 1301, 1301, 1587, 1301, 1626, 1301, 1301, 1301, - /* 490 */ 1301, 1301, 1301, 1301, 1301, 1452, 1301, 1301, 1301, 1301, - /* 500 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1437, 1435, - /* 510 */ 1434, 1433, 1301, 1430, 1301, 1301, 1301, 1301, 1301, 1301, - /* 520 */ 1461, 1460, 1301, 1301, 1301, 1301, 1301, 1301, 1381, 1301, - /* 530 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1372, 1301, - /* 540 */ 1371, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 550 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 560 */ 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, 1301, - /* 570 */ 1301, 1301, 1301, 1301, 1301, + /* 0 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 10 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 20 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 30 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 40 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 50 */ 1286, 1286, 1286, 1286, 1286, 1345, 1286, 1286, 1286, 1286, + /* 60 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 70 */ 1286, 1343, 1482, 1286, 1645, 1286, 1286, 1286, 1286, 1286, + /* 80 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 90 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 100 */ 1345, 1286, 1656, 1656, 1656, 1343, 1286, 1286, 1286, 1286, + /* 110 */ 1286, 1286, 1438, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 120 */ 1286, 1520, 1286, 1286, 1721, 1286, 1526, 1680, 1286, 1391, + /* 130 */ 1672, 1648, 1662, 1649, 1286, 1706, 1665, 1286, 1286, 1286, + /* 140 */ 1286, 1512, 1286, 1286, 1487, 1484, 1484, 1286, 1286, 1345, + /* 150 */ 1286, 1286, 1345, 1286, 1286, 1345, 1345, 1286, 1345, 1286, + /* 160 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 170 */ 1286, 1286, 1286, 1286, 1286, 1343, 1522, 1286, 1343, 1286, + /* 180 */ 1343, 1286, 1286, 1343, 1286, 1687, 1685, 1286, 1687, 1685, + /* 190 */ 1286, 1286, 1699, 1695, 1678, 1676, 1662, 1286, 1286, 1286, + /* 200 */ 1724, 1712, 1708, 1286, 1286, 1685, 1286, 1286, 1685, 1286, + /* 210 */ 1495, 1286, 1286, 1343, 1286, 1343, 1286, 1407, 1286, 1286, + /* 220 */ 1343, 1286, 1514, 1528, 1504, 1441, 1441, 1441, 1346, 1291, + /* 230 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 240 */ 1286, 1403, 1590, 1698, 1697, 1621, 1620, 1619, 1617, 1589, + /* 250 */ 1286, 1286, 1286, 1286, 1286, 1583, 1584, 1582, 1581, 1286, + /* 260 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 270 */ 1286, 1286, 1286, 1286, 1286, 1646, 1286, 1709, 1713, 1286, + /* 280 */ 1286, 1286, 1567, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 290 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 300 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 310 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 320 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 330 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 340 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 350 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 360 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 370 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 380 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 390 */ 1286, 1286, 1286, 1286, 1286, 1286, 1372, 1371, 1286, 1286, + /* 400 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 410 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 420 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1669, 1679, + /* 430 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1567, + /* 440 */ 1286, 1696, 1286, 1655, 1651, 1286, 1286, 1647, 1286, 1286, + /* 450 */ 1707, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1641, 1286, + /* 460 */ 1614, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1577, + /* 470 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 480 */ 1286, 1286, 1566, 1286, 1605, 1286, 1286, 1286, 1286, 1286, + /* 490 */ 1286, 1286, 1286, 1435, 1286, 1286, 1286, 1286, 1286, 1286, + /* 500 */ 1286, 1286, 1286, 1286, 1286, 1286, 1420, 1418, 1417, 1416, + /* 510 */ 1286, 1413, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 520 */ 1286, 1286, 1286, 1365, 1286, 1286, 1286, 1286, 1286, 1286, + /* 530 */ 1286, 1286, 1286, 1356, 1286, 1355, 1286, 1286, 1286, 1286, + /* 540 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 550 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, + /* 560 */ 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, 1286, }; /********** End of lemon-generated parsing tables *****************************/ @@ -848,8 +854,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* IF => nothing */ 0, /* NOT => nothing */ 0, /* EXISTS => nothing */ - 0, /* BLOCKS => nothing */ - 0, /* CACHE => nothing */ + 0, /* BUFFER => nothing */ 0, /* CACHELAST => nothing */ 0, /* COMP => nothing */ 0, /* DAYS => nothing */ @@ -858,16 +863,15 @@ static const YYCODETYPE yyFallback[] = { 0, /* MAXROWS => nothing */ 0, /* MINROWS => nothing */ 0, /* KEEP => nothing */ + 0, /* PAGES => nothing */ + 0, /* PAGESIZE => nothing */ 0, /* PRECISION => nothing */ - 0, /* QUORUM => nothing */ 0, /* REPLICA => nothing */ - 0, /* TTL => nothing */ + 0, /* STRICT => nothing */ 0, /* WAL => nothing */ 0, /* VGROUPS => nothing */ 0, /* SINGLE_STABLE => nothing */ - 0, /* STREAM_MODE => nothing */ 0, /* RETENTIONS => nothing */ - 0, /* STRICT => nothing */ 0, /* NK_COMMA => nothing */ 0, /* NK_COLON => nothing */ 0, /* TABLE => nothing */ @@ -903,11 +907,12 @@ static const YYCODETYPE yyFallback[] = { 0, /* BLOB => nothing */ 0, /* VARBINARY => nothing */ 0, /* DECIMAL => nothing */ - 0, /* SMA => nothing */ - 0, /* ROLLUP => nothing */ + 0, /* DELAY => nothing */ 0, /* FILE_FACTOR => nothing */ 0, /* NK_FLOAT => nothing */ - 0, /* DELAY => nothing */ + 0, /* ROLLUP => nothing */ + 0, /* TTL => nothing */ + 0, /* SMA => nothing */ 0, /* SHOW => nothing */ 0, /* DATABASES => nothing */ 0, /* TABLES => nothing */ @@ -943,6 +948,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* DESCRIBE => nothing */ 0, /* RESET => nothing */ 0, /* QUERY => nothing */ + 0, /* CACHE => nothing */ 0, /* EXPLAIN => nothing */ 0, /* ANALYZE => nothing */ 0, /* VERBOSE => nothing */ @@ -1166,101 +1172,101 @@ static const char *const yyTokenName[] = { /* 49 */ "IF", /* 50 */ "NOT", /* 51 */ "EXISTS", - /* 52 */ "BLOCKS", - /* 53 */ "CACHE", - /* 54 */ "CACHELAST", - /* 55 */ "COMP", - /* 56 */ "DAYS", - /* 57 */ "NK_VARIABLE", - /* 58 */ "FSYNC", - /* 59 */ "MAXROWS", - /* 60 */ "MINROWS", - /* 61 */ "KEEP", - /* 62 */ "PRECISION", - /* 63 */ "QUORUM", + /* 52 */ "BUFFER", + /* 53 */ "CACHELAST", + /* 54 */ "COMP", + /* 55 */ "DAYS", + /* 56 */ "NK_VARIABLE", + /* 57 */ "FSYNC", + /* 58 */ "MAXROWS", + /* 59 */ "MINROWS", + /* 60 */ "KEEP", + /* 61 */ "PAGES", + /* 62 */ "PAGESIZE", + /* 63 */ "PRECISION", /* 64 */ "REPLICA", - /* 65 */ "TTL", + /* 65 */ "STRICT", /* 66 */ "WAL", /* 67 */ "VGROUPS", /* 68 */ "SINGLE_STABLE", - /* 69 */ "STREAM_MODE", - /* 70 */ "RETENTIONS", - /* 71 */ "STRICT", - /* 72 */ "NK_COMMA", - /* 73 */ "NK_COLON", - /* 74 */ "TABLE", - /* 75 */ "NK_LP", - /* 76 */ "NK_RP", - /* 77 */ "STABLE", - /* 78 */ "ADD", - /* 79 */ "COLUMN", - /* 80 */ "MODIFY", - /* 81 */ "RENAME", - /* 82 */ "TAG", - /* 83 */ "SET", - /* 84 */ "NK_EQ", - /* 85 */ "USING", - /* 86 */ "TAGS", - /* 87 */ "NK_DOT", - /* 88 */ "COMMENT", - /* 89 */ "BOOL", - /* 90 */ "TINYINT", - /* 91 */ "SMALLINT", - /* 92 */ "INT", - /* 93 */ "INTEGER", - /* 94 */ "BIGINT", - /* 95 */ "FLOAT", - /* 96 */ "DOUBLE", - /* 97 */ "BINARY", - /* 98 */ "TIMESTAMP", - /* 99 */ "NCHAR", - /* 100 */ "UNSIGNED", - /* 101 */ "JSON", - /* 102 */ "VARCHAR", - /* 103 */ "MEDIUMBLOB", - /* 104 */ "BLOB", - /* 105 */ "VARBINARY", - /* 106 */ "DECIMAL", - /* 107 */ "SMA", + /* 69 */ "RETENTIONS", + /* 70 */ "NK_COMMA", + /* 71 */ "NK_COLON", + /* 72 */ "TABLE", + /* 73 */ "NK_LP", + /* 74 */ "NK_RP", + /* 75 */ "STABLE", + /* 76 */ "ADD", + /* 77 */ "COLUMN", + /* 78 */ "MODIFY", + /* 79 */ "RENAME", + /* 80 */ "TAG", + /* 81 */ "SET", + /* 82 */ "NK_EQ", + /* 83 */ "USING", + /* 84 */ "TAGS", + /* 85 */ "NK_DOT", + /* 86 */ "COMMENT", + /* 87 */ "BOOL", + /* 88 */ "TINYINT", + /* 89 */ "SMALLINT", + /* 90 */ "INT", + /* 91 */ "INTEGER", + /* 92 */ "BIGINT", + /* 93 */ "FLOAT", + /* 94 */ "DOUBLE", + /* 95 */ "BINARY", + /* 96 */ "TIMESTAMP", + /* 97 */ "NCHAR", + /* 98 */ "UNSIGNED", + /* 99 */ "JSON", + /* 100 */ "VARCHAR", + /* 101 */ "MEDIUMBLOB", + /* 102 */ "BLOB", + /* 103 */ "VARBINARY", + /* 104 */ "DECIMAL", + /* 105 */ "DELAY", + /* 106 */ "FILE_FACTOR", + /* 107 */ "NK_FLOAT", /* 108 */ "ROLLUP", - /* 109 */ "FILE_FACTOR", - /* 110 */ "NK_FLOAT", - /* 111 */ "DELAY", - /* 112 */ "SHOW", - /* 113 */ "DATABASES", - /* 114 */ "TABLES", - /* 115 */ "STABLES", - /* 116 */ "MNODES", - /* 117 */ "MODULES", - /* 118 */ "QNODES", - /* 119 */ "FUNCTIONS", - /* 120 */ "INDEXES", - /* 121 */ "FROM", - /* 122 */ "ACCOUNTS", - /* 123 */ "APPS", - /* 124 */ "CONNECTIONS", - /* 125 */ "LICENCE", - /* 126 */ "GRANTS", - /* 127 */ "QUERIES", - /* 128 */ "SCORES", - /* 129 */ "TOPICS", - /* 130 */ "VARIABLES", - /* 131 */ "BNODES", - /* 132 */ "SNODES", - /* 133 */ "CLUSTER", - /* 134 */ "LIKE", - /* 135 */ "INDEX", - /* 136 */ "FULLTEXT", - /* 137 */ "FUNCTION", - /* 138 */ "INTERVAL", - /* 139 */ "TOPIC", - /* 140 */ "AS", - /* 141 */ "WITH", - /* 142 */ "SCHEMA", - /* 143 */ "DESC", - /* 144 */ "DESCRIBE", - /* 145 */ "RESET", - /* 146 */ "QUERY", + /* 109 */ "TTL", + /* 110 */ "SMA", + /* 111 */ "SHOW", + /* 112 */ "DATABASES", + /* 113 */ "TABLES", + /* 114 */ "STABLES", + /* 115 */ "MNODES", + /* 116 */ "MODULES", + /* 117 */ "QNODES", + /* 118 */ "FUNCTIONS", + /* 119 */ "INDEXES", + /* 120 */ "FROM", + /* 121 */ "ACCOUNTS", + /* 122 */ "APPS", + /* 123 */ "CONNECTIONS", + /* 124 */ "LICENCE", + /* 125 */ "GRANTS", + /* 126 */ "QUERIES", + /* 127 */ "SCORES", + /* 128 */ "TOPICS", + /* 129 */ "VARIABLES", + /* 130 */ "BNODES", + /* 131 */ "SNODES", + /* 132 */ "CLUSTER", + /* 133 */ "LIKE", + /* 134 */ "INDEX", + /* 135 */ "FULLTEXT", + /* 136 */ "FUNCTION", + /* 137 */ "INTERVAL", + /* 138 */ "TOPIC", + /* 139 */ "AS", + /* 140 */ "WITH", + /* 141 */ "SCHEMA", + /* 142 */ "DESC", + /* 143 */ "DESCRIBE", + /* 144 */ "RESET", + /* 145 */ "QUERY", + /* 146 */ "CACHE", /* 147 */ "EXPLAIN", /* 148 */ "ANALYZE", /* 149 */ "VERBOSE", @@ -1526,392 +1532,386 @@ static const char *const yyRuleName[] = { /* 55 */ "exists_opt ::= IF EXISTS", /* 56 */ "exists_opt ::=", /* 57 */ "db_options ::=", - /* 58 */ "db_options ::= db_options BLOCKS NK_INTEGER", - /* 59 */ "db_options ::= db_options CACHE NK_INTEGER", - /* 60 */ "db_options ::= db_options CACHELAST NK_INTEGER", - /* 61 */ "db_options ::= db_options COMP NK_INTEGER", - /* 62 */ "db_options ::= db_options DAYS NK_INTEGER", - /* 63 */ "db_options ::= db_options DAYS NK_VARIABLE", - /* 64 */ "db_options ::= db_options FSYNC NK_INTEGER", - /* 65 */ "db_options ::= db_options MAXROWS NK_INTEGER", - /* 66 */ "db_options ::= db_options MINROWS NK_INTEGER", - /* 67 */ "db_options ::= db_options KEEP integer_list", - /* 68 */ "db_options ::= db_options KEEP variable_list", - /* 69 */ "db_options ::= db_options PRECISION NK_STRING", - /* 70 */ "db_options ::= db_options QUORUM NK_INTEGER", + /* 58 */ "db_options ::= db_options BUFFER NK_INTEGER", + /* 59 */ "db_options ::= db_options CACHELAST NK_INTEGER", + /* 60 */ "db_options ::= db_options COMP NK_INTEGER", + /* 61 */ "db_options ::= db_options DAYS NK_INTEGER", + /* 62 */ "db_options ::= db_options DAYS NK_VARIABLE", + /* 63 */ "db_options ::= db_options FSYNC NK_INTEGER", + /* 64 */ "db_options ::= db_options MAXROWS NK_INTEGER", + /* 65 */ "db_options ::= db_options MINROWS NK_INTEGER", + /* 66 */ "db_options ::= db_options KEEP integer_list", + /* 67 */ "db_options ::= db_options KEEP variable_list", + /* 68 */ "db_options ::= db_options PAGES NK_INTEGER", + /* 69 */ "db_options ::= db_options PAGESIZE NK_INTEGER", + /* 70 */ "db_options ::= db_options PRECISION NK_STRING", /* 71 */ "db_options ::= db_options REPLICA NK_INTEGER", - /* 72 */ "db_options ::= db_options TTL NK_INTEGER", + /* 72 */ "db_options ::= db_options STRICT NK_INTEGER", /* 73 */ "db_options ::= db_options WAL NK_INTEGER", /* 74 */ "db_options ::= db_options VGROUPS NK_INTEGER", /* 75 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", - /* 76 */ "db_options ::= db_options STREAM_MODE NK_INTEGER", - /* 77 */ "db_options ::= db_options RETENTIONS retention_list", - /* 78 */ "db_options ::= db_options STRICT NK_INTEGER", - /* 79 */ "alter_db_options ::= alter_db_option", - /* 80 */ "alter_db_options ::= alter_db_options alter_db_option", - /* 81 */ "alter_db_option ::= BLOCKS NK_INTEGER", - /* 82 */ "alter_db_option ::= FSYNC NK_INTEGER", - /* 83 */ "alter_db_option ::= KEEP integer_list", - /* 84 */ "alter_db_option ::= KEEP variable_list", - /* 85 */ "alter_db_option ::= WAL NK_INTEGER", - /* 86 */ "alter_db_option ::= QUORUM NK_INTEGER", - /* 87 */ "alter_db_option ::= CACHELAST NK_INTEGER", - /* 88 */ "alter_db_option ::= REPLICA NK_INTEGER", - /* 89 */ "alter_db_option ::= STRICT NK_INTEGER", - /* 90 */ "integer_list ::= NK_INTEGER", - /* 91 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", - /* 92 */ "variable_list ::= NK_VARIABLE", - /* 93 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", - /* 94 */ "retention_list ::= retention", - /* 95 */ "retention_list ::= retention_list NK_COMMA retention", - /* 96 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", - /* 97 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 98 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 99 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 100 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 101 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 102 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 103 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 104 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 105 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 106 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 107 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 108 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 109 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 110 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 111 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 112 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 113 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", - /* 114 */ "multi_create_clause ::= create_subtable_clause", - /* 115 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 116 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP", - /* 117 */ "multi_drop_clause ::= drop_table_clause", - /* 118 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 119 */ "drop_table_clause ::= exists_opt full_table_name", - /* 120 */ "specific_tags_opt ::=", - /* 121 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", - /* 122 */ "full_table_name ::= table_name", - /* 123 */ "full_table_name ::= db_name NK_DOT table_name", - /* 124 */ "column_def_list ::= column_def", - /* 125 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 126 */ "column_def ::= column_name type_name", - /* 127 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 128 */ "type_name ::= BOOL", - /* 129 */ "type_name ::= TINYINT", - /* 130 */ "type_name ::= SMALLINT", - /* 131 */ "type_name ::= INT", - /* 132 */ "type_name ::= INTEGER", - /* 133 */ "type_name ::= BIGINT", - /* 134 */ "type_name ::= FLOAT", - /* 135 */ "type_name ::= DOUBLE", - /* 136 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 137 */ "type_name ::= TIMESTAMP", - /* 138 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 139 */ "type_name ::= TINYINT UNSIGNED", - /* 140 */ "type_name ::= SMALLINT UNSIGNED", - /* 141 */ "type_name ::= INT UNSIGNED", - /* 142 */ "type_name ::= BIGINT UNSIGNED", - /* 143 */ "type_name ::= JSON", - /* 144 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 145 */ "type_name ::= MEDIUMBLOB", - /* 146 */ "type_name ::= BLOB", - /* 147 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 148 */ "type_name ::= DECIMAL", - /* 149 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 150 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 151 */ "tags_def_opt ::=", - /* 152 */ "tags_def_opt ::= tags_def", - /* 153 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 154 */ "table_options ::=", - /* 155 */ "table_options ::= table_options COMMENT NK_STRING", - /* 156 */ "table_options ::= table_options KEEP integer_list", - /* 157 */ "table_options ::= table_options KEEP variable_list", - /* 158 */ "table_options ::= table_options TTL NK_INTEGER", - /* 159 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 160 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", - /* 161 */ "table_options ::= table_options FILE_FACTOR NK_FLOAT", - /* 162 */ "table_options ::= table_options DELAY NK_INTEGER", - /* 163 */ "alter_table_options ::= alter_table_option", - /* 164 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 165 */ "alter_table_option ::= COMMENT NK_STRING", - /* 166 */ "alter_table_option ::= KEEP integer_list", - /* 167 */ "alter_table_option ::= KEEP variable_list", - /* 168 */ "alter_table_option ::= TTL NK_INTEGER", - /* 169 */ "col_name_list ::= col_name", - /* 170 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 171 */ "col_name ::= column_name", - /* 172 */ "cmd ::= SHOW DNODES", - /* 173 */ "cmd ::= SHOW USERS", - /* 174 */ "cmd ::= SHOW DATABASES", - /* 175 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 176 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 177 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 178 */ "cmd ::= SHOW MNODES", - /* 179 */ "cmd ::= SHOW MODULES", - /* 180 */ "cmd ::= SHOW QNODES", - /* 181 */ "cmd ::= SHOW FUNCTIONS", - /* 182 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 183 */ "cmd ::= SHOW STREAMS", - /* 184 */ "cmd ::= SHOW ACCOUNTS", - /* 185 */ "cmd ::= SHOW APPS", - /* 186 */ "cmd ::= SHOW CONNECTIONS", - /* 187 */ "cmd ::= SHOW LICENCE", - /* 188 */ "cmd ::= SHOW GRANTS", - /* 189 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 190 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 191 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 192 */ "cmd ::= SHOW QUERIES", - /* 193 */ "cmd ::= SHOW SCORES", - /* 194 */ "cmd ::= SHOW TOPICS", - /* 195 */ "cmd ::= SHOW VARIABLES", - /* 196 */ "cmd ::= SHOW BNODES", - /* 197 */ "cmd ::= SHOW SNODES", - /* 198 */ "cmd ::= SHOW CLUSTER", - /* 199 */ "db_name_cond_opt ::=", - /* 200 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 201 */ "like_pattern_opt ::=", - /* 202 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 203 */ "table_name_cond ::= table_name", - /* 204 */ "from_db_opt ::=", - /* 205 */ "from_db_opt ::= FROM db_name", - /* 206 */ "func_name_list ::= func_name", - /* 207 */ "func_name_list ::= func_name_list NK_COMMA func_name", - /* 208 */ "func_name ::= function_name", - /* 209 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 210 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 211 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 212 */ "index_options ::=", - /* 213 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 214 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 215 */ "func_list ::= func", - /* 216 */ "func_list ::= func_list NK_COMMA func", - /* 217 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 218 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS query_expression", - /* 219 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS db_name", - /* 220 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 221 */ "topic_options ::=", - /* 222 */ "topic_options ::= topic_options WITH TABLE", - /* 223 */ "topic_options ::= topic_options WITH SCHEMA", - /* 224 */ "topic_options ::= topic_options WITH TAG", - /* 225 */ "cmd ::= DESC full_table_name", - /* 226 */ "cmd ::= DESCRIBE full_table_name", - /* 227 */ "cmd ::= RESET QUERY CACHE", - /* 228 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 229 */ "analyze_opt ::=", - /* 230 */ "analyze_opt ::= ANALYZE", - /* 231 */ "explain_options ::=", - /* 232 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 233 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 234 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 235 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 236 */ "cmd ::= DROP FUNCTION function_name", - /* 237 */ "agg_func_opt ::=", - /* 238 */ "agg_func_opt ::= AGGREGATE", - /* 239 */ "bufsize_opt ::=", - /* 240 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 241 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", - /* 242 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 243 */ "into_opt ::=", - /* 244 */ "into_opt ::= INTO full_table_name", - /* 245 */ "stream_options ::=", - /* 246 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 247 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 248 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 249 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 250 */ "cmd ::= KILL QUERY NK_INTEGER", - /* 251 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 252 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 253 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 254 */ "dnode_list ::= DNODE NK_INTEGER", - /* 255 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 256 */ "cmd ::= SYNCDB db_name REPLICA", - /* 257 */ "cmd ::= query_expression", - /* 258 */ "literal ::= NK_INTEGER", - /* 259 */ "literal ::= NK_FLOAT", - /* 260 */ "literal ::= NK_STRING", - /* 261 */ "literal ::= NK_BOOL", - /* 262 */ "literal ::= TIMESTAMP NK_STRING", - /* 263 */ "literal ::= duration_literal", - /* 264 */ "literal ::= NULL", - /* 265 */ "literal ::= NK_QUESTION", - /* 266 */ "duration_literal ::= NK_VARIABLE", - /* 267 */ "signed ::= NK_INTEGER", - /* 268 */ "signed ::= NK_PLUS NK_INTEGER", - /* 269 */ "signed ::= NK_MINUS NK_INTEGER", - /* 270 */ "signed ::= NK_FLOAT", - /* 271 */ "signed ::= NK_PLUS NK_FLOAT", - /* 272 */ "signed ::= NK_MINUS NK_FLOAT", - /* 273 */ "signed_literal ::= signed", - /* 274 */ "signed_literal ::= NK_STRING", - /* 275 */ "signed_literal ::= NK_BOOL", - /* 276 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 277 */ "signed_literal ::= duration_literal", - /* 278 */ "signed_literal ::= NULL", - /* 279 */ "signed_literal ::= literal_func", - /* 280 */ "literal_list ::= signed_literal", - /* 281 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 282 */ "db_name ::= NK_ID", - /* 283 */ "table_name ::= NK_ID", - /* 284 */ "column_name ::= NK_ID", - /* 285 */ "function_name ::= NK_ID", - /* 286 */ "table_alias ::= NK_ID", - /* 287 */ "column_alias ::= NK_ID", - /* 288 */ "user_name ::= NK_ID", - /* 289 */ "index_name ::= NK_ID", - /* 290 */ "topic_name ::= NK_ID", - /* 291 */ "stream_name ::= NK_ID", - /* 292 */ "expression ::= literal", - /* 293 */ "expression ::= pseudo_column", - /* 294 */ "expression ::= column_reference", - /* 295 */ "expression ::= function_expression", - /* 296 */ "expression ::= subquery", - /* 297 */ "expression ::= NK_LP expression NK_RP", - /* 298 */ "expression ::= NK_PLUS expression", - /* 299 */ "expression ::= NK_MINUS expression", - /* 300 */ "expression ::= expression NK_PLUS expression", - /* 301 */ "expression ::= expression NK_MINUS expression", - /* 302 */ "expression ::= expression NK_STAR expression", - /* 303 */ "expression ::= expression NK_SLASH expression", - /* 304 */ "expression ::= expression NK_REM expression", - /* 305 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 306 */ "expression_list ::= expression", - /* 307 */ "expression_list ::= expression_list NK_COMMA expression", - /* 308 */ "column_reference ::= column_name", - /* 309 */ "column_reference ::= table_name NK_DOT column_name", - /* 310 */ "pseudo_column ::= ROWTS", - /* 311 */ "pseudo_column ::= TBNAME", - /* 312 */ "pseudo_column ::= QSTARTTS", - /* 313 */ "pseudo_column ::= QENDTS", - /* 314 */ "pseudo_column ::= WSTARTTS", - /* 315 */ "pseudo_column ::= WENDTS", - /* 316 */ "pseudo_column ::= WDURATION", - /* 317 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 318 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 319 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 320 */ "function_expression ::= literal_func", - /* 321 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 322 */ "literal_func ::= NOW", - /* 323 */ "noarg_func ::= NOW", - /* 324 */ "noarg_func ::= TODAY", - /* 325 */ "noarg_func ::= TIMEZONE", - /* 326 */ "star_func ::= COUNT", - /* 327 */ "star_func ::= FIRST", - /* 328 */ "star_func ::= LAST", - /* 329 */ "star_func ::= LAST_ROW", - /* 330 */ "star_func_para_list ::= NK_STAR", - /* 331 */ "star_func_para_list ::= other_para_list", - /* 332 */ "other_para_list ::= star_func_para", - /* 333 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 334 */ "star_func_para ::= expression", - /* 335 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 336 */ "predicate ::= expression compare_op expression", - /* 337 */ "predicate ::= expression BETWEEN expression AND expression", - /* 338 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 339 */ "predicate ::= expression IS NULL", - /* 340 */ "predicate ::= expression IS NOT NULL", - /* 341 */ "predicate ::= expression in_op in_predicate_value", - /* 342 */ "compare_op ::= NK_LT", - /* 343 */ "compare_op ::= NK_GT", - /* 344 */ "compare_op ::= NK_LE", - /* 345 */ "compare_op ::= NK_GE", - /* 346 */ "compare_op ::= NK_NE", - /* 347 */ "compare_op ::= NK_EQ", - /* 348 */ "compare_op ::= LIKE", - /* 349 */ "compare_op ::= NOT LIKE", - /* 350 */ "compare_op ::= MATCH", - /* 351 */ "compare_op ::= NMATCH", - /* 352 */ "compare_op ::= CONTAINS", - /* 353 */ "in_op ::= IN", - /* 354 */ "in_op ::= NOT IN", - /* 355 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 356 */ "boolean_value_expression ::= boolean_primary", - /* 357 */ "boolean_value_expression ::= NOT boolean_primary", - /* 358 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 359 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 360 */ "boolean_primary ::= predicate", - /* 361 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 362 */ "common_expression ::= expression", - /* 363 */ "common_expression ::= boolean_value_expression", - /* 364 */ "from_clause ::= FROM table_reference_list", - /* 365 */ "table_reference_list ::= table_reference", - /* 366 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 367 */ "table_reference ::= table_primary", - /* 368 */ "table_reference ::= joined_table", - /* 369 */ "table_primary ::= table_name alias_opt", - /* 370 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 371 */ "table_primary ::= subquery alias_opt", - /* 372 */ "table_primary ::= parenthesized_joined_table", - /* 373 */ "alias_opt ::=", - /* 374 */ "alias_opt ::= table_alias", - /* 375 */ "alias_opt ::= AS table_alias", - /* 376 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 377 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 378 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 379 */ "join_type ::=", - /* 380 */ "join_type ::= INNER", - /* 381 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 382 */ "set_quantifier_opt ::=", - /* 383 */ "set_quantifier_opt ::= DISTINCT", - /* 384 */ "set_quantifier_opt ::= ALL", - /* 385 */ "select_list ::= NK_STAR", - /* 386 */ "select_list ::= select_sublist", - /* 387 */ "select_sublist ::= select_item", - /* 388 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 389 */ "select_item ::= common_expression", - /* 390 */ "select_item ::= common_expression column_alias", - /* 391 */ "select_item ::= common_expression AS column_alias", - /* 392 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 393 */ "where_clause_opt ::=", - /* 394 */ "where_clause_opt ::= WHERE search_condition", - /* 395 */ "partition_by_clause_opt ::=", - /* 396 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 397 */ "twindow_clause_opt ::=", - /* 398 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 399 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 400 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 401 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 402 */ "sliding_opt ::=", - /* 403 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 404 */ "fill_opt ::=", - /* 405 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 406 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 407 */ "fill_mode ::= NONE", - /* 408 */ "fill_mode ::= PREV", - /* 409 */ "fill_mode ::= NULL", - /* 410 */ "fill_mode ::= LINEAR", - /* 411 */ "fill_mode ::= NEXT", - /* 412 */ "group_by_clause_opt ::=", - /* 413 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 414 */ "group_by_list ::= expression", - /* 415 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 416 */ "having_clause_opt ::=", - /* 417 */ "having_clause_opt ::= HAVING search_condition", - /* 418 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 419 */ "query_expression_body ::= query_primary", - /* 420 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 421 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 422 */ "query_primary ::= query_specification", - /* 423 */ "order_by_clause_opt ::=", - /* 424 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 425 */ "slimit_clause_opt ::=", - /* 426 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 427 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 428 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 429 */ "limit_clause_opt ::=", - /* 430 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 431 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 432 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 433 */ "subquery ::= NK_LP query_expression NK_RP", - /* 434 */ "search_condition ::= common_expression", - /* 435 */ "sort_specification_list ::= sort_specification", - /* 436 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 437 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 438 */ "ordering_specification_opt ::=", - /* 439 */ "ordering_specification_opt ::= ASC", - /* 440 */ "ordering_specification_opt ::= DESC", - /* 441 */ "null_ordering_opt ::=", - /* 442 */ "null_ordering_opt ::= NULLS FIRST", - /* 443 */ "null_ordering_opt ::= NULLS LAST", + /* 76 */ "db_options ::= db_options RETENTIONS retention_list", + /* 77 */ "alter_db_options ::= alter_db_option", + /* 78 */ "alter_db_options ::= alter_db_options alter_db_option", + /* 79 */ "alter_db_option ::= BUFFER NK_INTEGER", + /* 80 */ "alter_db_option ::= CACHELAST NK_INTEGER", + /* 81 */ "alter_db_option ::= FSYNC NK_INTEGER", + /* 82 */ "alter_db_option ::= KEEP integer_list", + /* 83 */ "alter_db_option ::= KEEP variable_list", + /* 84 */ "alter_db_option ::= PAGES NK_INTEGER", + /* 85 */ "alter_db_option ::= REPLICA NK_INTEGER", + /* 86 */ "alter_db_option ::= STRICT NK_INTEGER", + /* 87 */ "alter_db_option ::= WAL NK_INTEGER", + /* 88 */ "integer_list ::= NK_INTEGER", + /* 89 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", + /* 90 */ "variable_list ::= NK_VARIABLE", + /* 91 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", + /* 92 */ "retention_list ::= retention", + /* 93 */ "retention_list ::= retention_list NK_COMMA retention", + /* 94 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", + /* 95 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 96 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 97 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 98 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 99 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 100 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 101 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 102 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 103 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 104 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 105 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 106 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 107 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 108 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 109 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 110 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 111 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal", + /* 112 */ "multi_create_clause ::= create_subtable_clause", + /* 113 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 114 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options", + /* 115 */ "multi_drop_clause ::= drop_table_clause", + /* 116 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 117 */ "drop_table_clause ::= exists_opt full_table_name", + /* 118 */ "specific_tags_opt ::=", + /* 119 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", + /* 120 */ "full_table_name ::= table_name", + /* 121 */ "full_table_name ::= db_name NK_DOT table_name", + /* 122 */ "column_def_list ::= column_def", + /* 123 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 124 */ "column_def ::= column_name type_name", + /* 125 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 126 */ "type_name ::= BOOL", + /* 127 */ "type_name ::= TINYINT", + /* 128 */ "type_name ::= SMALLINT", + /* 129 */ "type_name ::= INT", + /* 130 */ "type_name ::= INTEGER", + /* 131 */ "type_name ::= BIGINT", + /* 132 */ "type_name ::= FLOAT", + /* 133 */ "type_name ::= DOUBLE", + /* 134 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 135 */ "type_name ::= TIMESTAMP", + /* 136 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 137 */ "type_name ::= TINYINT UNSIGNED", + /* 138 */ "type_name ::= SMALLINT UNSIGNED", + /* 139 */ "type_name ::= INT UNSIGNED", + /* 140 */ "type_name ::= BIGINT UNSIGNED", + /* 141 */ "type_name ::= JSON", + /* 142 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 143 */ "type_name ::= MEDIUMBLOB", + /* 144 */ "type_name ::= BLOB", + /* 145 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 146 */ "type_name ::= DECIMAL", + /* 147 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 148 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 149 */ "tags_def_opt ::=", + /* 150 */ "tags_def_opt ::= tags_def", + /* 151 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 152 */ "table_options ::=", + /* 153 */ "table_options ::= table_options COMMENT NK_STRING", + /* 154 */ "table_options ::= table_options DELAY NK_INTEGER", + /* 155 */ "table_options ::= table_options FILE_FACTOR NK_FLOAT", + /* 156 */ "table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP", + /* 157 */ "table_options ::= table_options TTL NK_INTEGER", + /* 158 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 159 */ "alter_table_options ::= alter_table_option", + /* 160 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 161 */ "alter_table_option ::= COMMENT NK_STRING", + /* 162 */ "alter_table_option ::= TTL NK_INTEGER", + /* 163 */ "col_name_list ::= col_name", + /* 164 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 165 */ "col_name ::= column_name", + /* 166 */ "cmd ::= SHOW DNODES", + /* 167 */ "cmd ::= SHOW USERS", + /* 168 */ "cmd ::= SHOW DATABASES", + /* 169 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 170 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 171 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 172 */ "cmd ::= SHOW MNODES", + /* 173 */ "cmd ::= SHOW MODULES", + /* 174 */ "cmd ::= SHOW QNODES", + /* 175 */ "cmd ::= SHOW FUNCTIONS", + /* 176 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 177 */ "cmd ::= SHOW STREAMS", + /* 178 */ "cmd ::= SHOW ACCOUNTS", + /* 179 */ "cmd ::= SHOW APPS", + /* 180 */ "cmd ::= SHOW CONNECTIONS", + /* 181 */ "cmd ::= SHOW LICENCE", + /* 182 */ "cmd ::= SHOW GRANTS", + /* 183 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 184 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 185 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 186 */ "cmd ::= SHOW QUERIES", + /* 187 */ "cmd ::= SHOW SCORES", + /* 188 */ "cmd ::= SHOW TOPICS", + /* 189 */ "cmd ::= SHOW VARIABLES", + /* 190 */ "cmd ::= SHOW BNODES", + /* 191 */ "cmd ::= SHOW SNODES", + /* 192 */ "cmd ::= SHOW CLUSTER", + /* 193 */ "db_name_cond_opt ::=", + /* 194 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 195 */ "like_pattern_opt ::=", + /* 196 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 197 */ "table_name_cond ::= table_name", + /* 198 */ "from_db_opt ::=", + /* 199 */ "from_db_opt ::= FROM db_name", + /* 200 */ "func_name_list ::= func_name", + /* 201 */ "func_name_list ::= func_name_list NK_COMMA func_name", + /* 202 */ "func_name ::= function_name", + /* 203 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 204 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 205 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 206 */ "index_options ::=", + /* 207 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 208 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 209 */ "func_list ::= func", + /* 210 */ "func_list ::= func_list NK_COMMA func", + /* 211 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 212 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS query_expression", + /* 213 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS db_name", + /* 214 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 215 */ "topic_options ::=", + /* 216 */ "topic_options ::= topic_options WITH TABLE", + /* 217 */ "topic_options ::= topic_options WITH SCHEMA", + /* 218 */ "topic_options ::= topic_options WITH TAG", + /* 219 */ "cmd ::= DESC full_table_name", + /* 220 */ "cmd ::= DESCRIBE full_table_name", + /* 221 */ "cmd ::= RESET QUERY CACHE", + /* 222 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 223 */ "analyze_opt ::=", + /* 224 */ "analyze_opt ::= ANALYZE", + /* 225 */ "explain_options ::=", + /* 226 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 227 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 228 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 229 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 230 */ "cmd ::= DROP FUNCTION function_name", + /* 231 */ "agg_func_opt ::=", + /* 232 */ "agg_func_opt ::= AGGREGATE", + /* 233 */ "bufsize_opt ::=", + /* 234 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 235 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", + /* 236 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 237 */ "into_opt ::=", + /* 238 */ "into_opt ::= INTO full_table_name", + /* 239 */ "stream_options ::=", + /* 240 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 241 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 242 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 243 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 244 */ "cmd ::= KILL QUERY NK_INTEGER", + /* 245 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 246 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 247 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 248 */ "dnode_list ::= DNODE NK_INTEGER", + /* 249 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 250 */ "cmd ::= SYNCDB db_name REPLICA", + /* 251 */ "cmd ::= query_expression", + /* 252 */ "literal ::= NK_INTEGER", + /* 253 */ "literal ::= NK_FLOAT", + /* 254 */ "literal ::= NK_STRING", + /* 255 */ "literal ::= NK_BOOL", + /* 256 */ "literal ::= TIMESTAMP NK_STRING", + /* 257 */ "literal ::= duration_literal", + /* 258 */ "literal ::= NULL", + /* 259 */ "literal ::= NK_QUESTION", + /* 260 */ "duration_literal ::= NK_VARIABLE", + /* 261 */ "signed ::= NK_INTEGER", + /* 262 */ "signed ::= NK_PLUS NK_INTEGER", + /* 263 */ "signed ::= NK_MINUS NK_INTEGER", + /* 264 */ "signed ::= NK_FLOAT", + /* 265 */ "signed ::= NK_PLUS NK_FLOAT", + /* 266 */ "signed ::= NK_MINUS NK_FLOAT", + /* 267 */ "signed_literal ::= signed", + /* 268 */ "signed_literal ::= NK_STRING", + /* 269 */ "signed_literal ::= NK_BOOL", + /* 270 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 271 */ "signed_literal ::= duration_literal", + /* 272 */ "signed_literal ::= NULL", + /* 273 */ "signed_literal ::= literal_func", + /* 274 */ "literal_list ::= signed_literal", + /* 275 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 276 */ "db_name ::= NK_ID", + /* 277 */ "table_name ::= NK_ID", + /* 278 */ "column_name ::= NK_ID", + /* 279 */ "function_name ::= NK_ID", + /* 280 */ "table_alias ::= NK_ID", + /* 281 */ "column_alias ::= NK_ID", + /* 282 */ "user_name ::= NK_ID", + /* 283 */ "index_name ::= NK_ID", + /* 284 */ "topic_name ::= NK_ID", + /* 285 */ "stream_name ::= NK_ID", + /* 286 */ "expression ::= literal", + /* 287 */ "expression ::= pseudo_column", + /* 288 */ "expression ::= column_reference", + /* 289 */ "expression ::= function_expression", + /* 290 */ "expression ::= subquery", + /* 291 */ "expression ::= NK_LP expression NK_RP", + /* 292 */ "expression ::= NK_PLUS expression", + /* 293 */ "expression ::= NK_MINUS expression", + /* 294 */ "expression ::= expression NK_PLUS expression", + /* 295 */ "expression ::= expression NK_MINUS expression", + /* 296 */ "expression ::= expression NK_STAR expression", + /* 297 */ "expression ::= expression NK_SLASH expression", + /* 298 */ "expression ::= expression NK_REM expression", + /* 299 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 300 */ "expression_list ::= expression", + /* 301 */ "expression_list ::= expression_list NK_COMMA expression", + /* 302 */ "column_reference ::= column_name", + /* 303 */ "column_reference ::= table_name NK_DOT column_name", + /* 304 */ "pseudo_column ::= ROWTS", + /* 305 */ "pseudo_column ::= TBNAME", + /* 306 */ "pseudo_column ::= QSTARTTS", + /* 307 */ "pseudo_column ::= QENDTS", + /* 308 */ "pseudo_column ::= WSTARTTS", + /* 309 */ "pseudo_column ::= WENDTS", + /* 310 */ "pseudo_column ::= WDURATION", + /* 311 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 312 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 313 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 314 */ "function_expression ::= literal_func", + /* 315 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 316 */ "literal_func ::= NOW", + /* 317 */ "noarg_func ::= NOW", + /* 318 */ "noarg_func ::= TODAY", + /* 319 */ "noarg_func ::= TIMEZONE", + /* 320 */ "star_func ::= COUNT", + /* 321 */ "star_func ::= FIRST", + /* 322 */ "star_func ::= LAST", + /* 323 */ "star_func ::= LAST_ROW", + /* 324 */ "star_func_para_list ::= NK_STAR", + /* 325 */ "star_func_para_list ::= other_para_list", + /* 326 */ "other_para_list ::= star_func_para", + /* 327 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 328 */ "star_func_para ::= expression", + /* 329 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 330 */ "predicate ::= expression compare_op expression", + /* 331 */ "predicate ::= expression BETWEEN expression AND expression", + /* 332 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 333 */ "predicate ::= expression IS NULL", + /* 334 */ "predicate ::= expression IS NOT NULL", + /* 335 */ "predicate ::= expression in_op in_predicate_value", + /* 336 */ "compare_op ::= NK_LT", + /* 337 */ "compare_op ::= NK_GT", + /* 338 */ "compare_op ::= NK_LE", + /* 339 */ "compare_op ::= NK_GE", + /* 340 */ "compare_op ::= NK_NE", + /* 341 */ "compare_op ::= NK_EQ", + /* 342 */ "compare_op ::= LIKE", + /* 343 */ "compare_op ::= NOT LIKE", + /* 344 */ "compare_op ::= MATCH", + /* 345 */ "compare_op ::= NMATCH", + /* 346 */ "compare_op ::= CONTAINS", + /* 347 */ "in_op ::= IN", + /* 348 */ "in_op ::= NOT IN", + /* 349 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 350 */ "boolean_value_expression ::= boolean_primary", + /* 351 */ "boolean_value_expression ::= NOT boolean_primary", + /* 352 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 353 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 354 */ "boolean_primary ::= predicate", + /* 355 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 356 */ "common_expression ::= expression", + /* 357 */ "common_expression ::= boolean_value_expression", + /* 358 */ "from_clause ::= FROM table_reference_list", + /* 359 */ "table_reference_list ::= table_reference", + /* 360 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 361 */ "table_reference ::= table_primary", + /* 362 */ "table_reference ::= joined_table", + /* 363 */ "table_primary ::= table_name alias_opt", + /* 364 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 365 */ "table_primary ::= subquery alias_opt", + /* 366 */ "table_primary ::= parenthesized_joined_table", + /* 367 */ "alias_opt ::=", + /* 368 */ "alias_opt ::= table_alias", + /* 369 */ "alias_opt ::= AS table_alias", + /* 370 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 371 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 372 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 373 */ "join_type ::=", + /* 374 */ "join_type ::= INNER", + /* 375 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 376 */ "set_quantifier_opt ::=", + /* 377 */ "set_quantifier_opt ::= DISTINCT", + /* 378 */ "set_quantifier_opt ::= ALL", + /* 379 */ "select_list ::= NK_STAR", + /* 380 */ "select_list ::= select_sublist", + /* 381 */ "select_sublist ::= select_item", + /* 382 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 383 */ "select_item ::= common_expression", + /* 384 */ "select_item ::= common_expression column_alias", + /* 385 */ "select_item ::= common_expression AS column_alias", + /* 386 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 387 */ "where_clause_opt ::=", + /* 388 */ "where_clause_opt ::= WHERE search_condition", + /* 389 */ "partition_by_clause_opt ::=", + /* 390 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 391 */ "twindow_clause_opt ::=", + /* 392 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 393 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 394 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 395 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 396 */ "sliding_opt ::=", + /* 397 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 398 */ "fill_opt ::=", + /* 399 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 400 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 401 */ "fill_mode ::= NONE", + /* 402 */ "fill_mode ::= PREV", + /* 403 */ "fill_mode ::= NULL", + /* 404 */ "fill_mode ::= LINEAR", + /* 405 */ "fill_mode ::= NEXT", + /* 406 */ "group_by_clause_opt ::=", + /* 407 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 408 */ "group_by_list ::= expression", + /* 409 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 410 */ "having_clause_opt ::=", + /* 411 */ "having_clause_opt ::= HAVING search_condition", + /* 412 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 413 */ "query_expression_body ::= query_primary", + /* 414 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 415 */ "query_expression_body ::= query_expression_body UNION query_expression_body", + /* 416 */ "query_primary ::= query_specification", + /* 417 */ "order_by_clause_opt ::=", + /* 418 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 419 */ "slimit_clause_opt ::=", + /* 420 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 421 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 422 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 423 */ "limit_clause_opt ::=", + /* 424 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 425 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 426 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 427 */ "subquery ::= NK_LP query_expression NK_RP", + /* 428 */ "search_condition ::= common_expression", + /* 429 */ "sort_specification_list ::= sort_specification", + /* 430 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 431 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 432 */ "ordering_specification_opt ::=", + /* 433 */ "ordering_specification_opt ::= ASC", + /* 434 */ "ordering_specification_opt ::= DESC", + /* 435 */ "null_ordering_opt ::=", + /* 436 */ "null_ordering_opt ::= NULLS FIRST", + /* 437 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -2554,392 +2554,386 @@ static const struct { { 242, -2 }, /* (55) exists_opt ::= IF EXISTS */ { 242, 0 }, /* (56) exists_opt ::= */ { 241, 0 }, /* (57) db_options ::= */ - { 241, -3 }, /* (58) db_options ::= db_options BLOCKS NK_INTEGER */ - { 241, -3 }, /* (59) db_options ::= db_options CACHE NK_INTEGER */ - { 241, -3 }, /* (60) db_options ::= db_options CACHELAST NK_INTEGER */ - { 241, -3 }, /* (61) db_options ::= db_options COMP NK_INTEGER */ - { 241, -3 }, /* (62) db_options ::= db_options DAYS NK_INTEGER */ - { 241, -3 }, /* (63) db_options ::= db_options DAYS NK_VARIABLE */ - { 241, -3 }, /* (64) db_options ::= db_options FSYNC NK_INTEGER */ - { 241, -3 }, /* (65) db_options ::= db_options MAXROWS NK_INTEGER */ - { 241, -3 }, /* (66) db_options ::= db_options MINROWS NK_INTEGER */ - { 241, -3 }, /* (67) db_options ::= db_options KEEP integer_list */ - { 241, -3 }, /* (68) db_options ::= db_options KEEP variable_list */ - { 241, -3 }, /* (69) db_options ::= db_options PRECISION NK_STRING */ - { 241, -3 }, /* (70) db_options ::= db_options QUORUM NK_INTEGER */ + { 241, -3 }, /* (58) db_options ::= db_options BUFFER NK_INTEGER */ + { 241, -3 }, /* (59) db_options ::= db_options CACHELAST NK_INTEGER */ + { 241, -3 }, /* (60) db_options ::= db_options COMP NK_INTEGER */ + { 241, -3 }, /* (61) db_options ::= db_options DAYS NK_INTEGER */ + { 241, -3 }, /* (62) db_options ::= db_options DAYS NK_VARIABLE */ + { 241, -3 }, /* (63) db_options ::= db_options FSYNC NK_INTEGER */ + { 241, -3 }, /* (64) db_options ::= db_options MAXROWS NK_INTEGER */ + { 241, -3 }, /* (65) db_options ::= db_options MINROWS NK_INTEGER */ + { 241, -3 }, /* (66) db_options ::= db_options KEEP integer_list */ + { 241, -3 }, /* (67) db_options ::= db_options KEEP variable_list */ + { 241, -3 }, /* (68) db_options ::= db_options PAGES NK_INTEGER */ + { 241, -3 }, /* (69) db_options ::= db_options PAGESIZE NK_INTEGER */ + { 241, -3 }, /* (70) db_options ::= db_options PRECISION NK_STRING */ { 241, -3 }, /* (71) db_options ::= db_options REPLICA NK_INTEGER */ - { 241, -3 }, /* (72) db_options ::= db_options TTL NK_INTEGER */ + { 241, -3 }, /* (72) db_options ::= db_options STRICT NK_INTEGER */ { 241, -3 }, /* (73) db_options ::= db_options WAL NK_INTEGER */ { 241, -3 }, /* (74) db_options ::= db_options VGROUPS NK_INTEGER */ { 241, -3 }, /* (75) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 241, -3 }, /* (76) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 241, -3 }, /* (77) db_options ::= db_options RETENTIONS retention_list */ - { 241, -3 }, /* (78) db_options ::= db_options STRICT NK_INTEGER */ - { 243, -1 }, /* (79) alter_db_options ::= alter_db_option */ - { 243, -2 }, /* (80) alter_db_options ::= alter_db_options alter_db_option */ - { 247, -2 }, /* (81) alter_db_option ::= BLOCKS NK_INTEGER */ - { 247, -2 }, /* (82) alter_db_option ::= FSYNC NK_INTEGER */ - { 247, -2 }, /* (83) alter_db_option ::= KEEP integer_list */ - { 247, -2 }, /* (84) alter_db_option ::= KEEP variable_list */ - { 247, -2 }, /* (85) alter_db_option ::= WAL NK_INTEGER */ - { 247, -2 }, /* (86) alter_db_option ::= QUORUM NK_INTEGER */ - { 247, -2 }, /* (87) alter_db_option ::= CACHELAST NK_INTEGER */ - { 247, -2 }, /* (88) alter_db_option ::= REPLICA NK_INTEGER */ - { 247, -2 }, /* (89) alter_db_option ::= STRICT NK_INTEGER */ - { 244, -1 }, /* (90) integer_list ::= NK_INTEGER */ - { 244, -3 }, /* (91) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 245, -1 }, /* (92) variable_list ::= NK_VARIABLE */ - { 245, -3 }, /* (93) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 246, -1 }, /* (94) retention_list ::= retention */ - { 246, -3 }, /* (95) retention_list ::= retention_list NK_COMMA retention */ - { 248, -3 }, /* (96) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 231, -9 }, /* (97) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 231, -3 }, /* (98) cmd ::= CREATE TABLE multi_create_clause */ - { 231, -9 }, /* (99) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 231, -3 }, /* (100) cmd ::= DROP TABLE multi_drop_clause */ - { 231, -4 }, /* (101) cmd ::= DROP STABLE exists_opt full_table_name */ - { 231, -3 }, /* (102) cmd ::= ALTER TABLE alter_table_clause */ - { 231, -3 }, /* (103) cmd ::= ALTER STABLE alter_table_clause */ - { 256, -2 }, /* (104) alter_table_clause ::= full_table_name alter_table_options */ - { 256, -5 }, /* (105) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 256, -4 }, /* (106) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 256, -5 }, /* (107) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 256, -5 }, /* (108) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 256, -5 }, /* (109) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 256, -4 }, /* (110) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 256, -5 }, /* (111) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 256, -5 }, /* (112) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 256, -6 }, /* (113) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 253, -1 }, /* (114) multi_create_clause ::= create_subtable_clause */ - { 253, -2 }, /* (115) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 260, -9 }, /* (116) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 255, -1 }, /* (117) multi_drop_clause ::= drop_table_clause */ - { 255, -2 }, /* (118) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 263, -2 }, /* (119) drop_table_clause ::= exists_opt full_table_name */ - { 261, 0 }, /* (120) specific_tags_opt ::= */ - { 261, -3 }, /* (121) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 249, -1 }, /* (122) full_table_name ::= table_name */ - { 249, -3 }, /* (123) full_table_name ::= db_name NK_DOT table_name */ - { 250, -1 }, /* (124) column_def_list ::= column_def */ - { 250, -3 }, /* (125) column_def_list ::= column_def_list NK_COMMA column_def */ - { 266, -2 }, /* (126) column_def ::= column_name type_name */ - { 266, -4 }, /* (127) column_def ::= column_name type_name COMMENT NK_STRING */ - { 259, -1 }, /* (128) type_name ::= BOOL */ - { 259, -1 }, /* (129) type_name ::= TINYINT */ - { 259, -1 }, /* (130) type_name ::= SMALLINT */ - { 259, -1 }, /* (131) type_name ::= INT */ - { 259, -1 }, /* (132) type_name ::= INTEGER */ - { 259, -1 }, /* (133) type_name ::= BIGINT */ - { 259, -1 }, /* (134) type_name ::= FLOAT */ - { 259, -1 }, /* (135) type_name ::= DOUBLE */ - { 259, -4 }, /* (136) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 259, -1 }, /* (137) type_name ::= TIMESTAMP */ - { 259, -4 }, /* (138) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 259, -2 }, /* (139) type_name ::= TINYINT UNSIGNED */ - { 259, -2 }, /* (140) type_name ::= SMALLINT UNSIGNED */ - { 259, -2 }, /* (141) type_name ::= INT UNSIGNED */ - { 259, -2 }, /* (142) type_name ::= BIGINT UNSIGNED */ - { 259, -1 }, /* (143) type_name ::= JSON */ - { 259, -4 }, /* (144) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 259, -1 }, /* (145) type_name ::= MEDIUMBLOB */ - { 259, -1 }, /* (146) type_name ::= BLOB */ - { 259, -4 }, /* (147) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 259, -1 }, /* (148) type_name ::= DECIMAL */ - { 259, -4 }, /* (149) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 259, -6 }, /* (150) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 251, 0 }, /* (151) tags_def_opt ::= */ - { 251, -1 }, /* (152) tags_def_opt ::= tags_def */ - { 254, -4 }, /* (153) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 252, 0 }, /* (154) table_options ::= */ - { 252, -3 }, /* (155) table_options ::= table_options COMMENT NK_STRING */ - { 252, -3 }, /* (156) table_options ::= table_options KEEP integer_list */ - { 252, -3 }, /* (157) table_options ::= table_options KEEP variable_list */ - { 252, -3 }, /* (158) table_options ::= table_options TTL NK_INTEGER */ - { 252, -5 }, /* (159) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 252, -5 }, /* (160) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 252, -3 }, /* (161) table_options ::= table_options FILE_FACTOR NK_FLOAT */ - { 252, -3 }, /* (162) table_options ::= table_options DELAY NK_INTEGER */ - { 257, -1 }, /* (163) alter_table_options ::= alter_table_option */ - { 257, -2 }, /* (164) alter_table_options ::= alter_table_options alter_table_option */ - { 268, -2 }, /* (165) alter_table_option ::= COMMENT NK_STRING */ - { 268, -2 }, /* (166) alter_table_option ::= KEEP integer_list */ - { 268, -2 }, /* (167) alter_table_option ::= KEEP variable_list */ - { 268, -2 }, /* (168) alter_table_option ::= TTL NK_INTEGER */ - { 264, -1 }, /* (169) col_name_list ::= col_name */ - { 264, -3 }, /* (170) col_name_list ::= col_name_list NK_COMMA col_name */ - { 269, -1 }, /* (171) col_name ::= column_name */ - { 231, -2 }, /* (172) cmd ::= SHOW DNODES */ - { 231, -2 }, /* (173) cmd ::= SHOW USERS */ - { 231, -2 }, /* (174) cmd ::= SHOW DATABASES */ - { 231, -4 }, /* (175) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 231, -4 }, /* (176) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 231, -3 }, /* (177) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 231, -2 }, /* (178) cmd ::= SHOW MNODES */ - { 231, -2 }, /* (179) cmd ::= SHOW MODULES */ - { 231, -2 }, /* (180) cmd ::= SHOW QNODES */ - { 231, -2 }, /* (181) cmd ::= SHOW FUNCTIONS */ - { 231, -5 }, /* (182) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 231, -2 }, /* (183) cmd ::= SHOW STREAMS */ - { 231, -2 }, /* (184) cmd ::= SHOW ACCOUNTS */ - { 231, -2 }, /* (185) cmd ::= SHOW APPS */ - { 231, -2 }, /* (186) cmd ::= SHOW CONNECTIONS */ - { 231, -2 }, /* (187) cmd ::= SHOW LICENCE */ - { 231, -2 }, /* (188) cmd ::= SHOW GRANTS */ - { 231, -4 }, /* (189) cmd ::= SHOW CREATE DATABASE db_name */ - { 231, -4 }, /* (190) cmd ::= SHOW CREATE TABLE full_table_name */ - { 231, -4 }, /* (191) cmd ::= SHOW CREATE STABLE full_table_name */ - { 231, -2 }, /* (192) cmd ::= SHOW QUERIES */ - { 231, -2 }, /* (193) cmd ::= SHOW SCORES */ - { 231, -2 }, /* (194) cmd ::= SHOW TOPICS */ - { 231, -2 }, /* (195) cmd ::= SHOW VARIABLES */ - { 231, -2 }, /* (196) cmd ::= SHOW BNODES */ - { 231, -2 }, /* (197) cmd ::= SHOW SNODES */ - { 231, -2 }, /* (198) cmd ::= SHOW CLUSTER */ - { 270, 0 }, /* (199) db_name_cond_opt ::= */ - { 270, -2 }, /* (200) db_name_cond_opt ::= db_name NK_DOT */ - { 271, 0 }, /* (201) like_pattern_opt ::= */ - { 271, -2 }, /* (202) like_pattern_opt ::= LIKE NK_STRING */ - { 272, -1 }, /* (203) table_name_cond ::= table_name */ - { 273, 0 }, /* (204) from_db_opt ::= */ - { 273, -2 }, /* (205) from_db_opt ::= FROM db_name */ - { 267, -1 }, /* (206) func_name_list ::= func_name */ - { 267, -3 }, /* (207) func_name_list ::= func_name_list NK_COMMA func_name */ - { 274, -1 }, /* (208) func_name ::= function_name */ - { 231, -8 }, /* (209) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 231, -10 }, /* (210) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 231, -6 }, /* (211) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 277, 0 }, /* (212) index_options ::= */ - { 277, -9 }, /* (213) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 277, -11 }, /* (214) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 278, -1 }, /* (215) func_list ::= func */ - { 278, -3 }, /* (216) func_list ::= func_list NK_COMMA func */ - { 281, -4 }, /* (217) func ::= function_name NK_LP expression_list NK_RP */ - { 231, -7 }, /* (218) cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS query_expression */ - { 231, -7 }, /* (219) cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS db_name */ - { 231, -4 }, /* (220) cmd ::= DROP TOPIC exists_opt topic_name */ - { 284, 0 }, /* (221) topic_options ::= */ - { 284, -3 }, /* (222) topic_options ::= topic_options WITH TABLE */ - { 284, -3 }, /* (223) topic_options ::= topic_options WITH SCHEMA */ - { 284, -3 }, /* (224) topic_options ::= topic_options WITH TAG */ - { 231, -2 }, /* (225) cmd ::= DESC full_table_name */ - { 231, -2 }, /* (226) cmd ::= DESCRIBE full_table_name */ - { 231, -3 }, /* (227) cmd ::= RESET QUERY CACHE */ - { 231, -4 }, /* (228) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ - { 286, 0 }, /* (229) analyze_opt ::= */ - { 286, -1 }, /* (230) analyze_opt ::= ANALYZE */ - { 287, 0 }, /* (231) explain_options ::= */ - { 287, -3 }, /* (232) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 287, -3 }, /* (233) explain_options ::= explain_options RATIO NK_FLOAT */ - { 231, -6 }, /* (234) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ - { 231, -10 }, /* (235) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 231, -3 }, /* (236) cmd ::= DROP FUNCTION function_name */ - { 288, 0 }, /* (237) agg_func_opt ::= */ - { 288, -1 }, /* (238) agg_func_opt ::= AGGREGATE */ - { 289, 0 }, /* (239) bufsize_opt ::= */ - { 289, -2 }, /* (240) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 231, -8 }, /* (241) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ - { 231, -4 }, /* (242) cmd ::= DROP STREAM exists_opt stream_name */ - { 292, 0 }, /* (243) into_opt ::= */ - { 292, -2 }, /* (244) into_opt ::= INTO full_table_name */ - { 291, 0 }, /* (245) stream_options ::= */ - { 291, -3 }, /* (246) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 291, -3 }, /* (247) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 291, -3 }, /* (248) stream_options ::= stream_options WATERMARK duration_literal */ - { 231, -3 }, /* (249) cmd ::= KILL CONNECTION NK_INTEGER */ - { 231, -3 }, /* (250) cmd ::= KILL QUERY NK_INTEGER */ - { 231, -4 }, /* (251) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 231, -4 }, /* (252) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 231, -3 }, /* (253) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 293, -2 }, /* (254) dnode_list ::= DNODE NK_INTEGER */ - { 293, -3 }, /* (255) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 231, -3 }, /* (256) cmd ::= SYNCDB db_name REPLICA */ - { 231, -1 }, /* (257) cmd ::= query_expression */ - { 234, -1 }, /* (258) literal ::= NK_INTEGER */ - { 234, -1 }, /* (259) literal ::= NK_FLOAT */ - { 234, -1 }, /* (260) literal ::= NK_STRING */ - { 234, -1 }, /* (261) literal ::= NK_BOOL */ - { 234, -2 }, /* (262) literal ::= TIMESTAMP NK_STRING */ - { 234, -1 }, /* (263) literal ::= duration_literal */ - { 234, -1 }, /* (264) literal ::= NULL */ - { 234, -1 }, /* (265) literal ::= NK_QUESTION */ - { 279, -1 }, /* (266) duration_literal ::= NK_VARIABLE */ - { 294, -1 }, /* (267) signed ::= NK_INTEGER */ - { 294, -2 }, /* (268) signed ::= NK_PLUS NK_INTEGER */ - { 294, -2 }, /* (269) signed ::= NK_MINUS NK_INTEGER */ - { 294, -1 }, /* (270) signed ::= NK_FLOAT */ - { 294, -2 }, /* (271) signed ::= NK_PLUS NK_FLOAT */ - { 294, -2 }, /* (272) signed ::= NK_MINUS NK_FLOAT */ - { 295, -1 }, /* (273) signed_literal ::= signed */ - { 295, -1 }, /* (274) signed_literal ::= NK_STRING */ - { 295, -1 }, /* (275) signed_literal ::= NK_BOOL */ - { 295, -2 }, /* (276) signed_literal ::= TIMESTAMP NK_STRING */ - { 295, -1 }, /* (277) signed_literal ::= duration_literal */ - { 295, -1 }, /* (278) signed_literal ::= NULL */ - { 295, -1 }, /* (279) signed_literal ::= literal_func */ - { 262, -1 }, /* (280) literal_list ::= signed_literal */ - { 262, -3 }, /* (281) literal_list ::= literal_list NK_COMMA signed_literal */ - { 240, -1 }, /* (282) db_name ::= NK_ID */ - { 265, -1 }, /* (283) table_name ::= NK_ID */ - { 258, -1 }, /* (284) column_name ::= NK_ID */ - { 275, -1 }, /* (285) function_name ::= NK_ID */ - { 297, -1 }, /* (286) table_alias ::= NK_ID */ - { 298, -1 }, /* (287) column_alias ::= NK_ID */ - { 236, -1 }, /* (288) user_name ::= NK_ID */ - { 276, -1 }, /* (289) index_name ::= NK_ID */ - { 283, -1 }, /* (290) topic_name ::= NK_ID */ - { 290, -1 }, /* (291) stream_name ::= NK_ID */ - { 299, -1 }, /* (292) expression ::= literal */ - { 299, -1 }, /* (293) expression ::= pseudo_column */ - { 299, -1 }, /* (294) expression ::= column_reference */ - { 299, -1 }, /* (295) expression ::= function_expression */ - { 299, -1 }, /* (296) expression ::= subquery */ - { 299, -3 }, /* (297) expression ::= NK_LP expression NK_RP */ - { 299, -2 }, /* (298) expression ::= NK_PLUS expression */ - { 299, -2 }, /* (299) expression ::= NK_MINUS expression */ - { 299, -3 }, /* (300) expression ::= expression NK_PLUS expression */ - { 299, -3 }, /* (301) expression ::= expression NK_MINUS expression */ - { 299, -3 }, /* (302) expression ::= expression NK_STAR expression */ - { 299, -3 }, /* (303) expression ::= expression NK_SLASH expression */ - { 299, -3 }, /* (304) expression ::= expression NK_REM expression */ - { 299, -3 }, /* (305) expression ::= column_reference NK_ARROW NK_STRING */ - { 282, -1 }, /* (306) expression_list ::= expression */ - { 282, -3 }, /* (307) expression_list ::= expression_list NK_COMMA expression */ - { 301, -1 }, /* (308) column_reference ::= column_name */ - { 301, -3 }, /* (309) column_reference ::= table_name NK_DOT column_name */ - { 300, -1 }, /* (310) pseudo_column ::= ROWTS */ - { 300, -1 }, /* (311) pseudo_column ::= TBNAME */ - { 300, -1 }, /* (312) pseudo_column ::= QSTARTTS */ - { 300, -1 }, /* (313) pseudo_column ::= QENDTS */ - { 300, -1 }, /* (314) pseudo_column ::= WSTARTTS */ - { 300, -1 }, /* (315) pseudo_column ::= WENDTS */ - { 300, -1 }, /* (316) pseudo_column ::= WDURATION */ - { 302, -4 }, /* (317) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 302, -4 }, /* (318) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 302, -6 }, /* (319) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 302, -1 }, /* (320) function_expression ::= literal_func */ - { 296, -3 }, /* (321) literal_func ::= noarg_func NK_LP NK_RP */ - { 296, -1 }, /* (322) literal_func ::= NOW */ - { 306, -1 }, /* (323) noarg_func ::= NOW */ - { 306, -1 }, /* (324) noarg_func ::= TODAY */ - { 306, -1 }, /* (325) noarg_func ::= TIMEZONE */ - { 304, -1 }, /* (326) star_func ::= COUNT */ - { 304, -1 }, /* (327) star_func ::= FIRST */ - { 304, -1 }, /* (328) star_func ::= LAST */ - { 304, -1 }, /* (329) star_func ::= LAST_ROW */ - { 305, -1 }, /* (330) star_func_para_list ::= NK_STAR */ - { 305, -1 }, /* (331) star_func_para_list ::= other_para_list */ - { 307, -1 }, /* (332) other_para_list ::= star_func_para */ - { 307, -3 }, /* (333) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 308, -1 }, /* (334) star_func_para ::= expression */ - { 308, -3 }, /* (335) star_func_para ::= table_name NK_DOT NK_STAR */ - { 309, -3 }, /* (336) predicate ::= expression compare_op expression */ - { 309, -5 }, /* (337) predicate ::= expression BETWEEN expression AND expression */ - { 309, -6 }, /* (338) predicate ::= expression NOT BETWEEN expression AND expression */ - { 309, -3 }, /* (339) predicate ::= expression IS NULL */ - { 309, -4 }, /* (340) predicate ::= expression IS NOT NULL */ - { 309, -3 }, /* (341) predicate ::= expression in_op in_predicate_value */ - { 310, -1 }, /* (342) compare_op ::= NK_LT */ - { 310, -1 }, /* (343) compare_op ::= NK_GT */ - { 310, -1 }, /* (344) compare_op ::= NK_LE */ - { 310, -1 }, /* (345) compare_op ::= NK_GE */ - { 310, -1 }, /* (346) compare_op ::= NK_NE */ - { 310, -1 }, /* (347) compare_op ::= NK_EQ */ - { 310, -1 }, /* (348) compare_op ::= LIKE */ - { 310, -2 }, /* (349) compare_op ::= NOT LIKE */ - { 310, -1 }, /* (350) compare_op ::= MATCH */ - { 310, -1 }, /* (351) compare_op ::= NMATCH */ - { 310, -1 }, /* (352) compare_op ::= CONTAINS */ - { 311, -1 }, /* (353) in_op ::= IN */ - { 311, -2 }, /* (354) in_op ::= NOT IN */ - { 312, -3 }, /* (355) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 313, -1 }, /* (356) boolean_value_expression ::= boolean_primary */ - { 313, -2 }, /* (357) boolean_value_expression ::= NOT boolean_primary */ - { 313, -3 }, /* (358) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 313, -3 }, /* (359) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 314, -1 }, /* (360) boolean_primary ::= predicate */ - { 314, -3 }, /* (361) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 315, -1 }, /* (362) common_expression ::= expression */ - { 315, -1 }, /* (363) common_expression ::= boolean_value_expression */ - { 316, -2 }, /* (364) from_clause ::= FROM table_reference_list */ - { 317, -1 }, /* (365) table_reference_list ::= table_reference */ - { 317, -3 }, /* (366) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 318, -1 }, /* (367) table_reference ::= table_primary */ - { 318, -1 }, /* (368) table_reference ::= joined_table */ - { 319, -2 }, /* (369) table_primary ::= table_name alias_opt */ - { 319, -4 }, /* (370) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 319, -2 }, /* (371) table_primary ::= subquery alias_opt */ - { 319, -1 }, /* (372) table_primary ::= parenthesized_joined_table */ - { 321, 0 }, /* (373) alias_opt ::= */ - { 321, -1 }, /* (374) alias_opt ::= table_alias */ - { 321, -2 }, /* (375) alias_opt ::= AS table_alias */ - { 322, -3 }, /* (376) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 322, -3 }, /* (377) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 320, -6 }, /* (378) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 323, 0 }, /* (379) join_type ::= */ - { 323, -1 }, /* (380) join_type ::= INNER */ - { 325, -9 }, /* (381) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 326, 0 }, /* (382) set_quantifier_opt ::= */ - { 326, -1 }, /* (383) set_quantifier_opt ::= DISTINCT */ - { 326, -1 }, /* (384) set_quantifier_opt ::= ALL */ - { 327, -1 }, /* (385) select_list ::= NK_STAR */ - { 327, -1 }, /* (386) select_list ::= select_sublist */ - { 333, -1 }, /* (387) select_sublist ::= select_item */ - { 333, -3 }, /* (388) select_sublist ::= select_sublist NK_COMMA select_item */ - { 334, -1 }, /* (389) select_item ::= common_expression */ - { 334, -2 }, /* (390) select_item ::= common_expression column_alias */ - { 334, -3 }, /* (391) select_item ::= common_expression AS column_alias */ - { 334, -3 }, /* (392) select_item ::= table_name NK_DOT NK_STAR */ - { 328, 0 }, /* (393) where_clause_opt ::= */ - { 328, -2 }, /* (394) where_clause_opt ::= WHERE search_condition */ - { 329, 0 }, /* (395) partition_by_clause_opt ::= */ - { 329, -3 }, /* (396) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 330, 0 }, /* (397) twindow_clause_opt ::= */ - { 330, -6 }, /* (398) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 330, -4 }, /* (399) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 330, -6 }, /* (400) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 330, -8 }, /* (401) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 280, 0 }, /* (402) sliding_opt ::= */ - { 280, -4 }, /* (403) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 335, 0 }, /* (404) fill_opt ::= */ - { 335, -4 }, /* (405) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 335, -6 }, /* (406) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 336, -1 }, /* (407) fill_mode ::= NONE */ - { 336, -1 }, /* (408) fill_mode ::= PREV */ - { 336, -1 }, /* (409) fill_mode ::= NULL */ - { 336, -1 }, /* (410) fill_mode ::= LINEAR */ - { 336, -1 }, /* (411) fill_mode ::= NEXT */ - { 331, 0 }, /* (412) group_by_clause_opt ::= */ - { 331, -3 }, /* (413) group_by_clause_opt ::= GROUP BY group_by_list */ - { 337, -1 }, /* (414) group_by_list ::= expression */ - { 337, -3 }, /* (415) group_by_list ::= group_by_list NK_COMMA expression */ - { 332, 0 }, /* (416) having_clause_opt ::= */ - { 332, -2 }, /* (417) having_clause_opt ::= HAVING search_condition */ - { 285, -4 }, /* (418) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 338, -1 }, /* (419) query_expression_body ::= query_primary */ - { 338, -4 }, /* (420) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 338, -3 }, /* (421) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 342, -1 }, /* (422) query_primary ::= query_specification */ - { 339, 0 }, /* (423) order_by_clause_opt ::= */ - { 339, -3 }, /* (424) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 340, 0 }, /* (425) slimit_clause_opt ::= */ - { 340, -2 }, /* (426) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 340, -4 }, /* (427) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 340, -4 }, /* (428) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 341, 0 }, /* (429) limit_clause_opt ::= */ - { 341, -2 }, /* (430) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 341, -4 }, /* (431) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 341, -4 }, /* (432) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 303, -3 }, /* (433) subquery ::= NK_LP query_expression NK_RP */ - { 324, -1 }, /* (434) search_condition ::= common_expression */ - { 343, -1 }, /* (435) sort_specification_list ::= sort_specification */ - { 343, -3 }, /* (436) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 344, -3 }, /* (437) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 345, 0 }, /* (438) ordering_specification_opt ::= */ - { 345, -1 }, /* (439) ordering_specification_opt ::= ASC */ - { 345, -1 }, /* (440) ordering_specification_opt ::= DESC */ - { 346, 0 }, /* (441) null_ordering_opt ::= */ - { 346, -2 }, /* (442) null_ordering_opt ::= NULLS FIRST */ - { 346, -2 }, /* (443) null_ordering_opt ::= NULLS LAST */ + { 241, -3 }, /* (76) db_options ::= db_options RETENTIONS retention_list */ + { 243, -1 }, /* (77) alter_db_options ::= alter_db_option */ + { 243, -2 }, /* (78) alter_db_options ::= alter_db_options alter_db_option */ + { 247, -2 }, /* (79) alter_db_option ::= BUFFER NK_INTEGER */ + { 247, -2 }, /* (80) alter_db_option ::= CACHELAST NK_INTEGER */ + { 247, -2 }, /* (81) alter_db_option ::= FSYNC NK_INTEGER */ + { 247, -2 }, /* (82) alter_db_option ::= KEEP integer_list */ + { 247, -2 }, /* (83) alter_db_option ::= KEEP variable_list */ + { 247, -2 }, /* (84) alter_db_option ::= PAGES NK_INTEGER */ + { 247, -2 }, /* (85) alter_db_option ::= REPLICA NK_INTEGER */ + { 247, -2 }, /* (86) alter_db_option ::= STRICT NK_INTEGER */ + { 247, -2 }, /* (87) alter_db_option ::= WAL NK_INTEGER */ + { 244, -1 }, /* (88) integer_list ::= NK_INTEGER */ + { 244, -3 }, /* (89) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 245, -1 }, /* (90) variable_list ::= NK_VARIABLE */ + { 245, -3 }, /* (91) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 246, -1 }, /* (92) retention_list ::= retention */ + { 246, -3 }, /* (93) retention_list ::= retention_list NK_COMMA retention */ + { 248, -3 }, /* (94) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 231, -9 }, /* (95) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 231, -3 }, /* (96) cmd ::= CREATE TABLE multi_create_clause */ + { 231, -9 }, /* (97) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 231, -3 }, /* (98) cmd ::= DROP TABLE multi_drop_clause */ + { 231, -4 }, /* (99) cmd ::= DROP STABLE exists_opt full_table_name */ + { 231, -3 }, /* (100) cmd ::= ALTER TABLE alter_table_clause */ + { 231, -3 }, /* (101) cmd ::= ALTER STABLE alter_table_clause */ + { 256, -2 }, /* (102) alter_table_clause ::= full_table_name alter_table_options */ + { 256, -5 }, /* (103) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 256, -4 }, /* (104) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 256, -5 }, /* (105) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 256, -5 }, /* (106) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 256, -5 }, /* (107) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 256, -4 }, /* (108) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 256, -5 }, /* (109) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 256, -5 }, /* (110) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 256, -6 }, /* (111) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + { 253, -1 }, /* (112) multi_create_clause ::= create_subtable_clause */ + { 253, -2 }, /* (113) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 260, -10 }, /* (114) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ + { 255, -1 }, /* (115) multi_drop_clause ::= drop_table_clause */ + { 255, -2 }, /* (116) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 263, -2 }, /* (117) drop_table_clause ::= exists_opt full_table_name */ + { 261, 0 }, /* (118) specific_tags_opt ::= */ + { 261, -3 }, /* (119) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 249, -1 }, /* (120) full_table_name ::= table_name */ + { 249, -3 }, /* (121) full_table_name ::= db_name NK_DOT table_name */ + { 250, -1 }, /* (122) column_def_list ::= column_def */ + { 250, -3 }, /* (123) column_def_list ::= column_def_list NK_COMMA column_def */ + { 266, -2 }, /* (124) column_def ::= column_name type_name */ + { 266, -4 }, /* (125) column_def ::= column_name type_name COMMENT NK_STRING */ + { 259, -1 }, /* (126) type_name ::= BOOL */ + { 259, -1 }, /* (127) type_name ::= TINYINT */ + { 259, -1 }, /* (128) type_name ::= SMALLINT */ + { 259, -1 }, /* (129) type_name ::= INT */ + { 259, -1 }, /* (130) type_name ::= INTEGER */ + { 259, -1 }, /* (131) type_name ::= BIGINT */ + { 259, -1 }, /* (132) type_name ::= FLOAT */ + { 259, -1 }, /* (133) type_name ::= DOUBLE */ + { 259, -4 }, /* (134) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 259, -1 }, /* (135) type_name ::= TIMESTAMP */ + { 259, -4 }, /* (136) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 259, -2 }, /* (137) type_name ::= TINYINT UNSIGNED */ + { 259, -2 }, /* (138) type_name ::= SMALLINT UNSIGNED */ + { 259, -2 }, /* (139) type_name ::= INT UNSIGNED */ + { 259, -2 }, /* (140) type_name ::= BIGINT UNSIGNED */ + { 259, -1 }, /* (141) type_name ::= JSON */ + { 259, -4 }, /* (142) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 259, -1 }, /* (143) type_name ::= MEDIUMBLOB */ + { 259, -1 }, /* (144) type_name ::= BLOB */ + { 259, -4 }, /* (145) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 259, -1 }, /* (146) type_name ::= DECIMAL */ + { 259, -4 }, /* (147) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 259, -6 }, /* (148) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 251, 0 }, /* (149) tags_def_opt ::= */ + { 251, -1 }, /* (150) tags_def_opt ::= tags_def */ + { 254, -4 }, /* (151) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 252, 0 }, /* (152) table_options ::= */ + { 252, -3 }, /* (153) table_options ::= table_options COMMENT NK_STRING */ + { 252, -3 }, /* (154) table_options ::= table_options DELAY NK_INTEGER */ + { 252, -3 }, /* (155) table_options ::= table_options FILE_FACTOR NK_FLOAT */ + { 252, -5 }, /* (156) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ + { 252, -3 }, /* (157) table_options ::= table_options TTL NK_INTEGER */ + { 252, -5 }, /* (158) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 257, -1 }, /* (159) alter_table_options ::= alter_table_option */ + { 257, -2 }, /* (160) alter_table_options ::= alter_table_options alter_table_option */ + { 268, -2 }, /* (161) alter_table_option ::= COMMENT NK_STRING */ + { 268, -2 }, /* (162) alter_table_option ::= TTL NK_INTEGER */ + { 264, -1 }, /* (163) col_name_list ::= col_name */ + { 264, -3 }, /* (164) col_name_list ::= col_name_list NK_COMMA col_name */ + { 269, -1 }, /* (165) col_name ::= column_name */ + { 231, -2 }, /* (166) cmd ::= SHOW DNODES */ + { 231, -2 }, /* (167) cmd ::= SHOW USERS */ + { 231, -2 }, /* (168) cmd ::= SHOW DATABASES */ + { 231, -4 }, /* (169) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 231, -4 }, /* (170) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 231, -3 }, /* (171) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 231, -2 }, /* (172) cmd ::= SHOW MNODES */ + { 231, -2 }, /* (173) cmd ::= SHOW MODULES */ + { 231, -2 }, /* (174) cmd ::= SHOW QNODES */ + { 231, -2 }, /* (175) cmd ::= SHOW FUNCTIONS */ + { 231, -5 }, /* (176) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 231, -2 }, /* (177) cmd ::= SHOW STREAMS */ + { 231, -2 }, /* (178) cmd ::= SHOW ACCOUNTS */ + { 231, -2 }, /* (179) cmd ::= SHOW APPS */ + { 231, -2 }, /* (180) cmd ::= SHOW CONNECTIONS */ + { 231, -2 }, /* (181) cmd ::= SHOW LICENCE */ + { 231, -2 }, /* (182) cmd ::= SHOW GRANTS */ + { 231, -4 }, /* (183) cmd ::= SHOW CREATE DATABASE db_name */ + { 231, -4 }, /* (184) cmd ::= SHOW CREATE TABLE full_table_name */ + { 231, -4 }, /* (185) cmd ::= SHOW CREATE STABLE full_table_name */ + { 231, -2 }, /* (186) cmd ::= SHOW QUERIES */ + { 231, -2 }, /* (187) cmd ::= SHOW SCORES */ + { 231, -2 }, /* (188) cmd ::= SHOW TOPICS */ + { 231, -2 }, /* (189) cmd ::= SHOW VARIABLES */ + { 231, -2 }, /* (190) cmd ::= SHOW BNODES */ + { 231, -2 }, /* (191) cmd ::= SHOW SNODES */ + { 231, -2 }, /* (192) cmd ::= SHOW CLUSTER */ + { 270, 0 }, /* (193) db_name_cond_opt ::= */ + { 270, -2 }, /* (194) db_name_cond_opt ::= db_name NK_DOT */ + { 271, 0 }, /* (195) like_pattern_opt ::= */ + { 271, -2 }, /* (196) like_pattern_opt ::= LIKE NK_STRING */ + { 272, -1 }, /* (197) table_name_cond ::= table_name */ + { 273, 0 }, /* (198) from_db_opt ::= */ + { 273, -2 }, /* (199) from_db_opt ::= FROM db_name */ + { 267, -1 }, /* (200) func_name_list ::= func_name */ + { 267, -3 }, /* (201) func_name_list ::= func_name_list NK_COMMA func_name */ + { 274, -1 }, /* (202) func_name ::= function_name */ + { 231, -8 }, /* (203) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 231, -10 }, /* (204) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 231, -6 }, /* (205) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 277, 0 }, /* (206) index_options ::= */ + { 277, -9 }, /* (207) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 277, -11 }, /* (208) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 278, -1 }, /* (209) func_list ::= func */ + { 278, -3 }, /* (210) func_list ::= func_list NK_COMMA func */ + { 281, -4 }, /* (211) func ::= function_name NK_LP expression_list NK_RP */ + { 231, -7 }, /* (212) cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS query_expression */ + { 231, -7 }, /* (213) cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS db_name */ + { 231, -4 }, /* (214) cmd ::= DROP TOPIC exists_opt topic_name */ + { 284, 0 }, /* (215) topic_options ::= */ + { 284, -3 }, /* (216) topic_options ::= topic_options WITH TABLE */ + { 284, -3 }, /* (217) topic_options ::= topic_options WITH SCHEMA */ + { 284, -3 }, /* (218) topic_options ::= topic_options WITH TAG */ + { 231, -2 }, /* (219) cmd ::= DESC full_table_name */ + { 231, -2 }, /* (220) cmd ::= DESCRIBE full_table_name */ + { 231, -3 }, /* (221) cmd ::= RESET QUERY CACHE */ + { 231, -4 }, /* (222) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 286, 0 }, /* (223) analyze_opt ::= */ + { 286, -1 }, /* (224) analyze_opt ::= ANALYZE */ + { 287, 0 }, /* (225) explain_options ::= */ + { 287, -3 }, /* (226) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 287, -3 }, /* (227) explain_options ::= explain_options RATIO NK_FLOAT */ + { 231, -6 }, /* (228) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + { 231, -10 }, /* (229) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 231, -3 }, /* (230) cmd ::= DROP FUNCTION function_name */ + { 288, 0 }, /* (231) agg_func_opt ::= */ + { 288, -1 }, /* (232) agg_func_opt ::= AGGREGATE */ + { 289, 0 }, /* (233) bufsize_opt ::= */ + { 289, -2 }, /* (234) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 231, -8 }, /* (235) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ + { 231, -4 }, /* (236) cmd ::= DROP STREAM exists_opt stream_name */ + { 292, 0 }, /* (237) into_opt ::= */ + { 292, -2 }, /* (238) into_opt ::= INTO full_table_name */ + { 291, 0 }, /* (239) stream_options ::= */ + { 291, -3 }, /* (240) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 291, -3 }, /* (241) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 291, -3 }, /* (242) stream_options ::= stream_options WATERMARK duration_literal */ + { 231, -3 }, /* (243) cmd ::= KILL CONNECTION NK_INTEGER */ + { 231, -3 }, /* (244) cmd ::= KILL QUERY NK_INTEGER */ + { 231, -4 }, /* (245) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 231, -4 }, /* (246) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 231, -3 }, /* (247) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 293, -2 }, /* (248) dnode_list ::= DNODE NK_INTEGER */ + { 293, -3 }, /* (249) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 231, -3 }, /* (250) cmd ::= SYNCDB db_name REPLICA */ + { 231, -1 }, /* (251) cmd ::= query_expression */ + { 234, -1 }, /* (252) literal ::= NK_INTEGER */ + { 234, -1 }, /* (253) literal ::= NK_FLOAT */ + { 234, -1 }, /* (254) literal ::= NK_STRING */ + { 234, -1 }, /* (255) literal ::= NK_BOOL */ + { 234, -2 }, /* (256) literal ::= TIMESTAMP NK_STRING */ + { 234, -1 }, /* (257) literal ::= duration_literal */ + { 234, -1 }, /* (258) literal ::= NULL */ + { 234, -1 }, /* (259) literal ::= NK_QUESTION */ + { 279, -1 }, /* (260) duration_literal ::= NK_VARIABLE */ + { 294, -1 }, /* (261) signed ::= NK_INTEGER */ + { 294, -2 }, /* (262) signed ::= NK_PLUS NK_INTEGER */ + { 294, -2 }, /* (263) signed ::= NK_MINUS NK_INTEGER */ + { 294, -1 }, /* (264) signed ::= NK_FLOAT */ + { 294, -2 }, /* (265) signed ::= NK_PLUS NK_FLOAT */ + { 294, -2 }, /* (266) signed ::= NK_MINUS NK_FLOAT */ + { 295, -1 }, /* (267) signed_literal ::= signed */ + { 295, -1 }, /* (268) signed_literal ::= NK_STRING */ + { 295, -1 }, /* (269) signed_literal ::= NK_BOOL */ + { 295, -2 }, /* (270) signed_literal ::= TIMESTAMP NK_STRING */ + { 295, -1 }, /* (271) signed_literal ::= duration_literal */ + { 295, -1 }, /* (272) signed_literal ::= NULL */ + { 295, -1 }, /* (273) signed_literal ::= literal_func */ + { 262, -1 }, /* (274) literal_list ::= signed_literal */ + { 262, -3 }, /* (275) literal_list ::= literal_list NK_COMMA signed_literal */ + { 240, -1 }, /* (276) db_name ::= NK_ID */ + { 265, -1 }, /* (277) table_name ::= NK_ID */ + { 258, -1 }, /* (278) column_name ::= NK_ID */ + { 275, -1 }, /* (279) function_name ::= NK_ID */ + { 297, -1 }, /* (280) table_alias ::= NK_ID */ + { 298, -1 }, /* (281) column_alias ::= NK_ID */ + { 236, -1 }, /* (282) user_name ::= NK_ID */ + { 276, -1 }, /* (283) index_name ::= NK_ID */ + { 283, -1 }, /* (284) topic_name ::= NK_ID */ + { 290, -1 }, /* (285) stream_name ::= NK_ID */ + { 299, -1 }, /* (286) expression ::= literal */ + { 299, -1 }, /* (287) expression ::= pseudo_column */ + { 299, -1 }, /* (288) expression ::= column_reference */ + { 299, -1 }, /* (289) expression ::= function_expression */ + { 299, -1 }, /* (290) expression ::= subquery */ + { 299, -3 }, /* (291) expression ::= NK_LP expression NK_RP */ + { 299, -2 }, /* (292) expression ::= NK_PLUS expression */ + { 299, -2 }, /* (293) expression ::= NK_MINUS expression */ + { 299, -3 }, /* (294) expression ::= expression NK_PLUS expression */ + { 299, -3 }, /* (295) expression ::= expression NK_MINUS expression */ + { 299, -3 }, /* (296) expression ::= expression NK_STAR expression */ + { 299, -3 }, /* (297) expression ::= expression NK_SLASH expression */ + { 299, -3 }, /* (298) expression ::= expression NK_REM expression */ + { 299, -3 }, /* (299) expression ::= column_reference NK_ARROW NK_STRING */ + { 282, -1 }, /* (300) expression_list ::= expression */ + { 282, -3 }, /* (301) expression_list ::= expression_list NK_COMMA expression */ + { 301, -1 }, /* (302) column_reference ::= column_name */ + { 301, -3 }, /* (303) column_reference ::= table_name NK_DOT column_name */ + { 300, -1 }, /* (304) pseudo_column ::= ROWTS */ + { 300, -1 }, /* (305) pseudo_column ::= TBNAME */ + { 300, -1 }, /* (306) pseudo_column ::= QSTARTTS */ + { 300, -1 }, /* (307) pseudo_column ::= QENDTS */ + { 300, -1 }, /* (308) pseudo_column ::= WSTARTTS */ + { 300, -1 }, /* (309) pseudo_column ::= WENDTS */ + { 300, -1 }, /* (310) pseudo_column ::= WDURATION */ + { 302, -4 }, /* (311) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 302, -4 }, /* (312) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 302, -6 }, /* (313) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + { 302, -1 }, /* (314) function_expression ::= literal_func */ + { 296, -3 }, /* (315) literal_func ::= noarg_func NK_LP NK_RP */ + { 296, -1 }, /* (316) literal_func ::= NOW */ + { 306, -1 }, /* (317) noarg_func ::= NOW */ + { 306, -1 }, /* (318) noarg_func ::= TODAY */ + { 306, -1 }, /* (319) noarg_func ::= TIMEZONE */ + { 304, -1 }, /* (320) star_func ::= COUNT */ + { 304, -1 }, /* (321) star_func ::= FIRST */ + { 304, -1 }, /* (322) star_func ::= LAST */ + { 304, -1 }, /* (323) star_func ::= LAST_ROW */ + { 305, -1 }, /* (324) star_func_para_list ::= NK_STAR */ + { 305, -1 }, /* (325) star_func_para_list ::= other_para_list */ + { 307, -1 }, /* (326) other_para_list ::= star_func_para */ + { 307, -3 }, /* (327) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 308, -1 }, /* (328) star_func_para ::= expression */ + { 308, -3 }, /* (329) star_func_para ::= table_name NK_DOT NK_STAR */ + { 309, -3 }, /* (330) predicate ::= expression compare_op expression */ + { 309, -5 }, /* (331) predicate ::= expression BETWEEN expression AND expression */ + { 309, -6 }, /* (332) predicate ::= expression NOT BETWEEN expression AND expression */ + { 309, -3 }, /* (333) predicate ::= expression IS NULL */ + { 309, -4 }, /* (334) predicate ::= expression IS NOT NULL */ + { 309, -3 }, /* (335) predicate ::= expression in_op in_predicate_value */ + { 310, -1 }, /* (336) compare_op ::= NK_LT */ + { 310, -1 }, /* (337) compare_op ::= NK_GT */ + { 310, -1 }, /* (338) compare_op ::= NK_LE */ + { 310, -1 }, /* (339) compare_op ::= NK_GE */ + { 310, -1 }, /* (340) compare_op ::= NK_NE */ + { 310, -1 }, /* (341) compare_op ::= NK_EQ */ + { 310, -1 }, /* (342) compare_op ::= LIKE */ + { 310, -2 }, /* (343) compare_op ::= NOT LIKE */ + { 310, -1 }, /* (344) compare_op ::= MATCH */ + { 310, -1 }, /* (345) compare_op ::= NMATCH */ + { 310, -1 }, /* (346) compare_op ::= CONTAINS */ + { 311, -1 }, /* (347) in_op ::= IN */ + { 311, -2 }, /* (348) in_op ::= NOT IN */ + { 312, -3 }, /* (349) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 313, -1 }, /* (350) boolean_value_expression ::= boolean_primary */ + { 313, -2 }, /* (351) boolean_value_expression ::= NOT boolean_primary */ + { 313, -3 }, /* (352) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 313, -3 }, /* (353) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 314, -1 }, /* (354) boolean_primary ::= predicate */ + { 314, -3 }, /* (355) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 315, -1 }, /* (356) common_expression ::= expression */ + { 315, -1 }, /* (357) common_expression ::= boolean_value_expression */ + { 316, -2 }, /* (358) from_clause ::= FROM table_reference_list */ + { 317, -1 }, /* (359) table_reference_list ::= table_reference */ + { 317, -3 }, /* (360) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 318, -1 }, /* (361) table_reference ::= table_primary */ + { 318, -1 }, /* (362) table_reference ::= joined_table */ + { 319, -2 }, /* (363) table_primary ::= table_name alias_opt */ + { 319, -4 }, /* (364) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 319, -2 }, /* (365) table_primary ::= subquery alias_opt */ + { 319, -1 }, /* (366) table_primary ::= parenthesized_joined_table */ + { 321, 0 }, /* (367) alias_opt ::= */ + { 321, -1 }, /* (368) alias_opt ::= table_alias */ + { 321, -2 }, /* (369) alias_opt ::= AS table_alias */ + { 322, -3 }, /* (370) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 322, -3 }, /* (371) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 320, -6 }, /* (372) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 323, 0 }, /* (373) join_type ::= */ + { 323, -1 }, /* (374) join_type ::= INNER */ + { 325, -9 }, /* (375) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 326, 0 }, /* (376) set_quantifier_opt ::= */ + { 326, -1 }, /* (377) set_quantifier_opt ::= DISTINCT */ + { 326, -1 }, /* (378) set_quantifier_opt ::= ALL */ + { 327, -1 }, /* (379) select_list ::= NK_STAR */ + { 327, -1 }, /* (380) select_list ::= select_sublist */ + { 333, -1 }, /* (381) select_sublist ::= select_item */ + { 333, -3 }, /* (382) select_sublist ::= select_sublist NK_COMMA select_item */ + { 334, -1 }, /* (383) select_item ::= common_expression */ + { 334, -2 }, /* (384) select_item ::= common_expression column_alias */ + { 334, -3 }, /* (385) select_item ::= common_expression AS column_alias */ + { 334, -3 }, /* (386) select_item ::= table_name NK_DOT NK_STAR */ + { 328, 0 }, /* (387) where_clause_opt ::= */ + { 328, -2 }, /* (388) where_clause_opt ::= WHERE search_condition */ + { 329, 0 }, /* (389) partition_by_clause_opt ::= */ + { 329, -3 }, /* (390) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 330, 0 }, /* (391) twindow_clause_opt ::= */ + { 330, -6 }, /* (392) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 330, -4 }, /* (393) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + { 330, -6 }, /* (394) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 330, -8 }, /* (395) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 280, 0 }, /* (396) sliding_opt ::= */ + { 280, -4 }, /* (397) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 335, 0 }, /* (398) fill_opt ::= */ + { 335, -4 }, /* (399) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 335, -6 }, /* (400) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 336, -1 }, /* (401) fill_mode ::= NONE */ + { 336, -1 }, /* (402) fill_mode ::= PREV */ + { 336, -1 }, /* (403) fill_mode ::= NULL */ + { 336, -1 }, /* (404) fill_mode ::= LINEAR */ + { 336, -1 }, /* (405) fill_mode ::= NEXT */ + { 331, 0 }, /* (406) group_by_clause_opt ::= */ + { 331, -3 }, /* (407) group_by_clause_opt ::= GROUP BY group_by_list */ + { 337, -1 }, /* (408) group_by_list ::= expression */ + { 337, -3 }, /* (409) group_by_list ::= group_by_list NK_COMMA expression */ + { 332, 0 }, /* (410) having_clause_opt ::= */ + { 332, -2 }, /* (411) having_clause_opt ::= HAVING search_condition */ + { 285, -4 }, /* (412) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 338, -1 }, /* (413) query_expression_body ::= query_primary */ + { 338, -4 }, /* (414) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 338, -3 }, /* (415) query_expression_body ::= query_expression_body UNION query_expression_body */ + { 342, -1 }, /* (416) query_primary ::= query_specification */ + { 339, 0 }, /* (417) order_by_clause_opt ::= */ + { 339, -3 }, /* (418) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 340, 0 }, /* (419) slimit_clause_opt ::= */ + { 340, -2 }, /* (420) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 340, -4 }, /* (421) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 340, -4 }, /* (422) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 341, 0 }, /* (423) limit_clause_opt ::= */ + { 341, -2 }, /* (424) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 341, -4 }, /* (425) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 341, -4 }, /* (426) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 303, -3 }, /* (427) subquery ::= NK_LP query_expression NK_RP */ + { 324, -1 }, /* (428) search_condition ::= common_expression */ + { 343, -1 }, /* (429) sort_specification_list ::= sort_specification */ + { 343, -3 }, /* (430) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 344, -3 }, /* (431) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 345, 0 }, /* (432) ordering_specification_opt ::= */ + { 345, -1 }, /* (433) ordering_specification_opt ::= ASC */ + { 345, -1 }, /* (434) ordering_specification_opt ::= DESC */ + { 346, 0 }, /* (435) null_ordering_opt ::= */ + { 346, -2 }, /* (436) null_ordering_opt ::= NULLS FIRST */ + { 346, -2 }, /* (437) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3027,11 +3021,11 @@ static YYACTIONTYPE yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ -{ pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } +{ pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } yy_destructor(yypParser,232,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ -{ pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } +{ pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } yy_destructor(yypParser,233,&yymsp[0].minor); break; case 2: /* account_options ::= */ @@ -3114,23 +3108,23 @@ static YYACTIONTYPE yy_reduce( case 36: /* dnode_endpoint ::= NK_STRING */ case 37: /* dnode_host_name ::= NK_ID */ yytestcase(yyruleno==37); case 38: /* dnode_host_name ::= NK_IPTOKEN */ yytestcase(yyruleno==38); - case 282: /* db_name ::= NK_ID */ yytestcase(yyruleno==282); - case 283: /* table_name ::= NK_ID */ yytestcase(yyruleno==283); - case 284: /* column_name ::= NK_ID */ yytestcase(yyruleno==284); - case 285: /* function_name ::= NK_ID */ yytestcase(yyruleno==285); - case 286: /* table_alias ::= NK_ID */ yytestcase(yyruleno==286); - case 287: /* column_alias ::= NK_ID */ yytestcase(yyruleno==287); - case 288: /* user_name ::= NK_ID */ yytestcase(yyruleno==288); - case 289: /* index_name ::= NK_ID */ yytestcase(yyruleno==289); - case 290: /* topic_name ::= NK_ID */ yytestcase(yyruleno==290); - case 291: /* stream_name ::= NK_ID */ yytestcase(yyruleno==291); - case 323: /* noarg_func ::= NOW */ yytestcase(yyruleno==323); - case 324: /* noarg_func ::= TODAY */ yytestcase(yyruleno==324); - case 325: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==325); - case 326: /* star_func ::= COUNT */ yytestcase(yyruleno==326); - case 327: /* star_func ::= FIRST */ yytestcase(yyruleno==327); - case 328: /* star_func ::= LAST */ yytestcase(yyruleno==328); - case 329: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==329); + case 276: /* db_name ::= NK_ID */ yytestcase(yyruleno==276); + case 277: /* table_name ::= NK_ID */ yytestcase(yyruleno==277); + case 278: /* column_name ::= NK_ID */ yytestcase(yyruleno==278); + case 279: /* function_name ::= NK_ID */ yytestcase(yyruleno==279); + case 280: /* table_alias ::= NK_ID */ yytestcase(yyruleno==280); + case 281: /* column_alias ::= NK_ID */ yytestcase(yyruleno==281); + case 282: /* user_name ::= NK_ID */ yytestcase(yyruleno==282); + case 283: /* index_name ::= NK_ID */ yytestcase(yyruleno==283); + case 284: /* topic_name ::= NK_ID */ yytestcase(yyruleno==284); + case 285: /* stream_name ::= NK_ID */ yytestcase(yyruleno==285); + case 317: /* noarg_func ::= NOW */ yytestcase(yyruleno==317); + case 318: /* noarg_func ::= TODAY */ yytestcase(yyruleno==318); + case 319: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==319); + case 320: /* star_func ::= COUNT */ yytestcase(yyruleno==320); + case 321: /* star_func ::= FIRST */ yytestcase(yyruleno==321); + case 322: /* star_func ::= LAST */ yytestcase(yyruleno==322); + case 323: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==323); { yylhsminor.yy555 = yymsp[0].minor.yy0; } yymsp[0].minor.yy555 = yylhsminor.yy555; break; @@ -3181,711 +3175,691 @@ static YYACTIONTYPE yy_reduce( break; case 54: /* not_exists_opt ::= */ case 56: /* exists_opt ::= */ yytestcase(yyruleno==56); - case 229: /* analyze_opt ::= */ yytestcase(yyruleno==229); - case 237: /* agg_func_opt ::= */ yytestcase(yyruleno==237); - case 382: /* set_quantifier_opt ::= */ yytestcase(yyruleno==382); + case 223: /* analyze_opt ::= */ yytestcase(yyruleno==223); + case 231: /* agg_func_opt ::= */ yytestcase(yyruleno==231); + case 376: /* set_quantifier_opt ::= */ yytestcase(yyruleno==376); { yymsp[1].minor.yy617 = false; } break; case 55: /* exists_opt ::= IF EXISTS */ { yymsp[-1].minor.yy617 = true; } break; case 57: /* db_options ::= */ -{ yymsp[1].minor.yy662 = createDatabaseOptions(pCxt); } - break; - case 58: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } - yymsp[-2].minor.yy662 = yylhsminor.yy662; +{ yymsp[1].minor.yy662 = createDefaultDatabaseOptions(pCxt); } break; - case 59: /* db_options ::= db_options CACHE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 58: /* db_options ::= db_options BUFFER NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 60: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 59: /* db_options ::= db_options CACHELAST NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 61: /* db_options ::= db_options COMP NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 60: /* db_options ::= db_options COMP NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_COMP, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 62: /* db_options ::= db_options DAYS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 61: /* db_options ::= db_options DAYS NK_INTEGER */ + case 62: /* db_options ::= db_options DAYS NK_VARIABLE */ yytestcase(yyruleno==62); +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 63: /* db_options ::= db_options DAYS NK_VARIABLE */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 63: /* db_options ::= db_options FSYNC NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 64: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 64: /* db_options ::= db_options MAXROWS NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 65: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 65: /* db_options ::= db_options MINROWS NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 66: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 66: /* db_options ::= db_options KEEP integer_list */ + case 67: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==67); +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_KEEP, yymsp[0].minor.yy568); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 67: /* db_options ::= db_options KEEP integer_list */ - case 68: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==68); -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pKeep = yymsp[0].minor.yy568; yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 68: /* db_options ::= db_options PAGES NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 69: /* db_options ::= db_options PRECISION NK_STRING */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 69: /* db_options ::= db_options PAGESIZE NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 70: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 70: /* db_options ::= db_options PRECISION NK_STRING */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 71: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 72: /* db_options ::= db_options TTL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 72: /* db_options ::= db_options STRICT NK_INTEGER */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 73: /* db_options ::= db_options WAL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_WAL, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 74: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 75: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } - yymsp[-2].minor.yy662 = yylhsminor.yy662; - break; - case 76: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 77: /* db_options ::= db_options RETENTIONS retention_list */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pRetentions = yymsp[0].minor.yy568; yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 76: /* db_options ::= db_options RETENTIONS retention_list */ +{ yylhsminor.yy662 = setDatabaseOption(pCxt, yymsp[-2].minor.yy662, DB_OPTION_RETENTIONS, yymsp[0].minor.yy568); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 78: /* db_options ::= db_options STRICT NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pStrict = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } - yymsp[-2].minor.yy662 = yylhsminor.yy662; - break; - case 79: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy662 = createDatabaseOptions(pCxt); yylhsminor.yy662 = setDatabaseAlterOption(pCxt, yylhsminor.yy662, &yymsp[0].minor.yy475); } + case 77: /* alter_db_options ::= alter_db_option */ +{ yylhsminor.yy662 = createAlterDatabaseOptions(pCxt); yylhsminor.yy662 = setAlterDatabaseOption(pCxt, yylhsminor.yy662, &yymsp[0].minor.yy475); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 80: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy662 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy662, &yymsp[0].minor.yy475); } + case 78: /* alter_db_options ::= alter_db_options alter_db_option */ +{ yylhsminor.yy662 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy662, &yymsp[0].minor.yy475); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 81: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 79: /* alter_db_option ::= BUFFER NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 82: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 80: /* alter_db_option ::= CACHELAST NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 83: /* alter_db_option ::= KEEP integer_list */ - case 84: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==84); -{ yymsp[-1].minor.yy475.type = DB_OPTION_KEEP; yymsp[-1].minor.yy475.pList = yymsp[0].minor.yy568; } + case 81: /* alter_db_option ::= FSYNC NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 85: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = DB_OPTION_WAL; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 82: /* alter_db_option ::= KEEP integer_list */ + case 83: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==83); +{ yymsp[-1].minor.yy475.type = DB_OPTION_KEEP; yymsp[-1].minor.yy475.pList = yymsp[0].minor.yy568; } break; - case 86: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 84: /* alter_db_option ::= PAGES NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = DB_OPTION_PAGES; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 87: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 85: /* alter_db_option ::= REPLICA NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 88: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 86: /* alter_db_option ::= STRICT NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = DB_OPTION_STRICT; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 89: /* alter_db_option ::= STRICT NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = DB_OPTION_STRICT; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 87: /* alter_db_option ::= WAL NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = DB_OPTION_WAL; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 90: /* integer_list ::= NK_INTEGER */ + case 88: /* integer_list ::= NK_INTEGER */ { yylhsminor.yy568 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 91: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 255: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==255); + case 89: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ + case 249: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==249); { yylhsminor.yy568 = addNodeToList(pCxt, yymsp[-2].minor.yy568, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } yymsp[-2].minor.yy568 = yylhsminor.yy568; break; - case 92: /* variable_list ::= NK_VARIABLE */ + case 90: /* variable_list ::= NK_VARIABLE */ { yylhsminor.yy568 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 93: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + case 91: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ { yylhsminor.yy568 = addNodeToList(pCxt, yymsp[-2].minor.yy568, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[-2].minor.yy568 = yylhsminor.yy568; break; - case 94: /* retention_list ::= retention */ - case 114: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==114); - case 117: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==117); - case 124: /* column_def_list ::= column_def */ yytestcase(yyruleno==124); - case 169: /* col_name_list ::= col_name */ yytestcase(yyruleno==169); - case 206: /* func_name_list ::= func_name */ yytestcase(yyruleno==206); - case 215: /* func_list ::= func */ yytestcase(yyruleno==215); - case 280: /* literal_list ::= signed_literal */ yytestcase(yyruleno==280); - case 332: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==332); - case 387: /* select_sublist ::= select_item */ yytestcase(yyruleno==387); - case 435: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==435); + case 92: /* retention_list ::= retention */ + case 112: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==112); + case 115: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==115); + case 122: /* column_def_list ::= column_def */ yytestcase(yyruleno==122); + case 163: /* col_name_list ::= col_name */ yytestcase(yyruleno==163); + case 200: /* func_name_list ::= func_name */ yytestcase(yyruleno==200); + case 209: /* func_list ::= func */ yytestcase(yyruleno==209); + case 274: /* literal_list ::= signed_literal */ yytestcase(yyruleno==274); + case 326: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==326); + case 381: /* select_sublist ::= select_item */ yytestcase(yyruleno==381); + case 429: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==429); { yylhsminor.yy568 = createNodeList(pCxt, yymsp[0].minor.yy662); } yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 95: /* retention_list ::= retention_list NK_COMMA retention */ - case 125: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==125); - case 170: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==170); - case 207: /* func_name_list ::= func_name_list NK_COMMA func_name */ yytestcase(yyruleno==207); - case 216: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==216); - case 281: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==281); - case 333: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==333); - case 388: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==388); - case 436: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==436); + case 93: /* retention_list ::= retention_list NK_COMMA retention */ + case 123: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==123); + case 164: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==164); + case 201: /* func_name_list ::= func_name_list NK_COMMA func_name */ yytestcase(yyruleno==201); + case 210: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==210); + case 275: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==275); + case 327: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==327); + case 382: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==382); + case 430: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==430); { yylhsminor.yy568 = addNodeToList(pCxt, yymsp[-2].minor.yy568, yymsp[0].minor.yy662); } yymsp[-2].minor.yy568 = yylhsminor.yy568; break; - case 96: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + case 94: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ { yylhsminor.yy662 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 97: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 99: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==99); + case 95: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 97: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==97); { pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy617, yymsp[-5].minor.yy662, yymsp[-3].minor.yy568, yymsp[-1].minor.yy568, yymsp[0].minor.yy662); } break; - case 98: /* cmd ::= CREATE TABLE multi_create_clause */ + case 96: /* cmd ::= CREATE TABLE multi_create_clause */ { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy568); } break; - case 100: /* cmd ::= DROP TABLE multi_drop_clause */ + case 98: /* cmd ::= DROP TABLE multi_drop_clause */ { pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy568); } break; - case 101: /* cmd ::= DROP STABLE exists_opt full_table_name */ + case 99: /* cmd ::= DROP STABLE exists_opt full_table_name */ { pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy617, yymsp[0].minor.yy662); } break; - case 102: /* cmd ::= ALTER TABLE alter_table_clause */ - case 103: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==103); - case 257: /* cmd ::= query_expression */ yytestcase(yyruleno==257); + case 100: /* cmd ::= ALTER TABLE alter_table_clause */ + case 101: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==101); + case 251: /* cmd ::= query_expression */ yytestcase(yyruleno==251); { pCxt->pRootNode = yymsp[0].minor.yy662; } break; - case 104: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy662 = createAlterTableOption(pCxt, yymsp[-1].minor.yy662, yymsp[0].minor.yy662); } + case 102: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy662 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy662, yymsp[0].minor.yy662); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 105: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + case 103: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ { yylhsminor.yy662 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy662, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy555, yymsp[0].minor.yy156); } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 106: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ + case 104: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ { yylhsminor.yy662 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy662, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy555); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 107: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + case 105: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ { yylhsminor.yy662 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy662, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy555, yymsp[0].minor.yy156); } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 108: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + case 106: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ { yylhsminor.yy662 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy662, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy555, &yymsp[0].minor.yy555); } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 109: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + case 107: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ { yylhsminor.yy662 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy662, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy555, yymsp[0].minor.yy156); } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 110: /* alter_table_clause ::= full_table_name DROP TAG column_name */ + case 108: /* alter_table_clause ::= full_table_name DROP TAG column_name */ { yylhsminor.yy662 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy662, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy555); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 111: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + case 109: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ { yylhsminor.yy662 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy662, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy555, yymsp[0].minor.yy156); } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 112: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + case 110: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ { yylhsminor.yy662 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy662, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy555, &yymsp[0].minor.yy555); } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 113: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + case 111: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ { yylhsminor.yy662 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy662, &yymsp[-2].minor.yy555, yymsp[0].minor.yy662); } yymsp[-5].minor.yy662 = yylhsminor.yy662; break; - case 115: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 118: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==118); + case 113: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 116: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==116); { yylhsminor.yy568 = addNodeToList(pCxt, yymsp[-1].minor.yy568, yymsp[0].minor.yy662); } yymsp[-1].minor.yy568 = yylhsminor.yy568; break; - case 116: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy662 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy617, yymsp[-7].minor.yy662, yymsp[-5].minor.yy662, yymsp[-4].minor.yy568, yymsp[-1].minor.yy568); } - yymsp[-8].minor.yy662 = yylhsminor.yy662; + case 114: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ +{ yylhsminor.yy662 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy617, yymsp[-8].minor.yy662, yymsp[-6].minor.yy662, yymsp[-5].minor.yy568, yymsp[-2].minor.yy568, yymsp[0].minor.yy662); } + yymsp[-9].minor.yy662 = yylhsminor.yy662; break; - case 119: /* drop_table_clause ::= exists_opt full_table_name */ + case 117: /* drop_table_clause ::= exists_opt full_table_name */ { yylhsminor.yy662 = createDropTableClause(pCxt, yymsp[-1].minor.yy617, yymsp[0].minor.yy662); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 120: /* specific_tags_opt ::= */ - case 151: /* tags_def_opt ::= */ yytestcase(yyruleno==151); - case 395: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==395); - case 412: /* group_by_clause_opt ::= */ yytestcase(yyruleno==412); - case 423: /* order_by_clause_opt ::= */ yytestcase(yyruleno==423); + case 118: /* specific_tags_opt ::= */ + case 149: /* tags_def_opt ::= */ yytestcase(yyruleno==149); + case 389: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==389); + case 406: /* group_by_clause_opt ::= */ yytestcase(yyruleno==406); + case 417: /* order_by_clause_opt ::= */ yytestcase(yyruleno==417); { yymsp[1].minor.yy568 = NULL; } break; - case 121: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ + case 119: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ { yymsp[-2].minor.yy568 = yymsp[-1].minor.yy568; } break; - case 122: /* full_table_name ::= table_name */ + case 120: /* full_table_name ::= table_name */ { yylhsminor.yy662 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy555, NULL); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 123: /* full_table_name ::= db_name NK_DOT table_name */ + case 121: /* full_table_name ::= db_name NK_DOT table_name */ { yylhsminor.yy662 = createRealTableNode(pCxt, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy555, NULL); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 126: /* column_def ::= column_name type_name */ + case 124: /* column_def ::= column_name type_name */ { yylhsminor.yy662 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy555, yymsp[0].minor.yy156, NULL); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 127: /* column_def ::= column_name type_name COMMENT NK_STRING */ + case 125: /* column_def ::= column_name type_name COMMENT NK_STRING */ { yylhsminor.yy662 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy555, yymsp[-2].minor.yy156, &yymsp[0].minor.yy0); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 128: /* type_name ::= BOOL */ + case 126: /* type_name ::= BOOL */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 129: /* type_name ::= TINYINT */ + case 127: /* type_name ::= TINYINT */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 130: /* type_name ::= SMALLINT */ + case 128: /* type_name ::= SMALLINT */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 131: /* type_name ::= INT */ - case 132: /* type_name ::= INTEGER */ yytestcase(yyruleno==132); + case 129: /* type_name ::= INT */ + case 130: /* type_name ::= INTEGER */ yytestcase(yyruleno==130); { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 133: /* type_name ::= BIGINT */ + case 131: /* type_name ::= BIGINT */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 134: /* type_name ::= FLOAT */ + case 132: /* type_name ::= FLOAT */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 135: /* type_name ::= DOUBLE */ + case 133: /* type_name ::= DOUBLE */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 136: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + case 134: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 137: /* type_name ::= TIMESTAMP */ + case 135: /* type_name ::= TIMESTAMP */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 138: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + case 136: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 139: /* type_name ::= TINYINT UNSIGNED */ + case 137: /* type_name ::= TINYINT UNSIGNED */ { yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 140: /* type_name ::= SMALLINT UNSIGNED */ + case 138: /* type_name ::= SMALLINT UNSIGNED */ { yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 141: /* type_name ::= INT UNSIGNED */ + case 139: /* type_name ::= INT UNSIGNED */ { yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 142: /* type_name ::= BIGINT UNSIGNED */ + case 140: /* type_name ::= BIGINT UNSIGNED */ { yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 143: /* type_name ::= JSON */ + case 141: /* type_name ::= JSON */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 144: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + case 142: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 145: /* type_name ::= MEDIUMBLOB */ + case 143: /* type_name ::= MEDIUMBLOB */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 146: /* type_name ::= BLOB */ + case 144: /* type_name ::= BLOB */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 147: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + case 145: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 148: /* type_name ::= DECIMAL */ + case 146: /* type_name ::= DECIMAL */ { yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 149: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + case 147: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ { yymsp[-3].minor.yy156 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 150: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + case 148: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ { yymsp[-5].minor.yy156 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 152: /* tags_def_opt ::= tags_def */ - case 331: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==331); - case 386: /* select_list ::= select_sublist */ yytestcase(yyruleno==386); + case 150: /* tags_def_opt ::= tags_def */ + case 325: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==325); + case 380: /* select_list ::= select_sublist */ yytestcase(yyruleno==380); { yylhsminor.yy568 = yymsp[0].minor.yy568; } yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 153: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ + case 151: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ { yymsp[-3].minor.yy568 = yymsp[-1].minor.yy568; } break; - case 154: /* table_options ::= */ -{ yymsp[1].minor.yy662 = createTableOptions(pCxt); } + case 152: /* table_options ::= */ +{ yymsp[1].minor.yy662 = createDefaultTableOptions(pCxt); } break; - case 155: /* table_options ::= table_options COMMENT NK_STRING */ -{ ((STableOptions*)yymsp[-2].minor.yy662)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 153: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy662 = setTableOption(pCxt, yymsp[-2].minor.yy662, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 156: /* table_options ::= table_options KEEP integer_list */ - case 157: /* table_options ::= table_options KEEP variable_list */ yytestcase(yyruleno==157); -{ ((STableOptions*)yymsp[-2].minor.yy662)->pKeep = yymsp[0].minor.yy568; yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 154: /* table_options ::= table_options DELAY NK_INTEGER */ +{ yylhsminor.yy662 = setTableOption(pCxt, yymsp[-2].minor.yy662, TABLE_OPTION_DELAY, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 158: /* table_options ::= table_options TTL NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy662)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 155: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ +{ yylhsminor.yy662 = setTableOption(pCxt, yymsp[-2].minor.yy662, TABLE_OPTION_FILE_FACTOR, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 159: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy662)->pSma = yymsp[-1].minor.yy568; yylhsminor.yy662 = yymsp[-4].minor.yy662; } + case 156: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ +{ yylhsminor.yy662 = setTableOption(pCxt, yymsp[-4].minor.yy662, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy568); } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 160: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy662)->pFuncs = yymsp[-1].minor.yy568; yylhsminor.yy662 = yymsp[-4].minor.yy662; } - yymsp[-4].minor.yy662 = yylhsminor.yy662; - break; - case 161: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ ((STableOptions*)yymsp[-2].minor.yy662)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + case 157: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy662 = setTableOption(pCxt, yymsp[-2].minor.yy662, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 162: /* table_options ::= table_options DELAY NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy662)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } - yymsp[-2].minor.yy662 = yylhsminor.yy662; + case 158: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy662 = setTableOption(pCxt, yymsp[-4].minor.yy662, TABLE_OPTION_SMA, yymsp[-1].minor.yy568); } + yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 163: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy662 = createTableOptions(pCxt); yylhsminor.yy662 = setTableAlterOption(pCxt, yylhsminor.yy662, &yymsp[0].minor.yy475); } + case 159: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy662 = createAlterTableOptions(pCxt); yylhsminor.yy662 = setTableOption(pCxt, yylhsminor.yy662, yymsp[0].minor.yy475.type, &yymsp[0].minor.yy475.val); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 164: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy662 = setTableAlterOption(pCxt, yymsp[-1].minor.yy662, &yymsp[0].minor.yy475); } + case 160: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy662 = setTableOption(pCxt, yymsp[-1].minor.yy662, yymsp[0].minor.yy475.type, &yymsp[0].minor.yy475.val); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 165: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy475.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - break; - case 166: /* alter_table_option ::= KEEP integer_list */ - case 167: /* alter_table_option ::= KEEP variable_list */ yytestcase(yyruleno==167); -{ yymsp[-1].minor.yy475.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy475.pList = yymsp[0].minor.yy568; } + case 161: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy475.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 168: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy475.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 162: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy475.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy475.val = yymsp[0].minor.yy0; } break; - case 171: /* col_name ::= column_name */ + case 165: /* col_name ::= column_name */ { yylhsminor.yy662 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy555); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 172: /* cmd ::= SHOW DNODES */ + case 166: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } break; - case 173: /* cmd ::= SHOW USERS */ + case 167: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL, NULL); } break; - case 174: /* cmd ::= SHOW DATABASES */ + case 168: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; - case 175: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + case 169: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy662, yymsp[0].minor.yy662); } break; - case 176: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + case 170: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy662, yymsp[0].minor.yy662); } break; - case 177: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ + case 171: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy662, NULL); } break; - case 178: /* cmd ::= SHOW MNODES */ + case 172: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } break; - case 179: /* cmd ::= SHOW MODULES */ + case 173: /* cmd ::= SHOW MODULES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT, NULL, NULL); } break; - case 180: /* cmd ::= SHOW QNODES */ + case 174: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL, NULL); } break; - case 181: /* cmd ::= SHOW FUNCTIONS */ + case 175: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; - case 182: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + case 176: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy662, yymsp[0].minor.yy662); } break; - case 183: /* cmd ::= SHOW STREAMS */ + case 177: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } break; - case 184: /* cmd ::= SHOW ACCOUNTS */ -{ pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } + case 178: /* cmd ::= SHOW ACCOUNTS */ +{ pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; - case 185: /* cmd ::= SHOW APPS */ + case 179: /* cmd ::= SHOW APPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } break; - case 186: /* cmd ::= SHOW CONNECTIONS */ + case 180: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } break; - case 187: /* cmd ::= SHOW LICENCE */ - case 188: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==188); + case 181: /* cmd ::= SHOW LICENCE */ + case 182: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==182); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } break; - case 189: /* cmd ::= SHOW CREATE DATABASE db_name */ + case 183: /* cmd ::= SHOW CREATE DATABASE db_name */ { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy555); } break; - case 190: /* cmd ::= SHOW CREATE TABLE full_table_name */ + case 184: /* cmd ::= SHOW CREATE TABLE full_table_name */ { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy662); } break; - case 191: /* cmd ::= SHOW CREATE STABLE full_table_name */ + case 185: /* cmd ::= SHOW CREATE STABLE full_table_name */ { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy662); } break; - case 192: /* cmd ::= SHOW QUERIES */ + case 186: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } break; - case 193: /* cmd ::= SHOW SCORES */ + case 187: /* cmd ::= SHOW SCORES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } break; - case 194: /* cmd ::= SHOW TOPICS */ + case 188: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } break; - case 195: /* cmd ::= SHOW VARIABLES */ + case 189: /* cmd ::= SHOW VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } break; - case 196: /* cmd ::= SHOW BNODES */ + case 190: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT, NULL, NULL); } break; - case 197: /* cmd ::= SHOW SNODES */ + case 191: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT, NULL, NULL); } break; - case 198: /* cmd ::= SHOW CLUSTER */ + case 192: /* cmd ::= SHOW CLUSTER */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT, NULL, NULL); } break; - case 199: /* db_name_cond_opt ::= */ - case 204: /* from_db_opt ::= */ yytestcase(yyruleno==204); + case 193: /* db_name_cond_opt ::= */ + case 198: /* from_db_opt ::= */ yytestcase(yyruleno==198); { yymsp[1].minor.yy662 = createDefaultDatabaseCondValue(pCxt); } break; - case 200: /* db_name_cond_opt ::= db_name NK_DOT */ + case 194: /* db_name_cond_opt ::= db_name NK_DOT */ { yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy555); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 201: /* like_pattern_opt ::= */ - case 212: /* index_options ::= */ yytestcase(yyruleno==212); - case 243: /* into_opt ::= */ yytestcase(yyruleno==243); - case 393: /* where_clause_opt ::= */ yytestcase(yyruleno==393); - case 397: /* twindow_clause_opt ::= */ yytestcase(yyruleno==397); - case 402: /* sliding_opt ::= */ yytestcase(yyruleno==402); - case 404: /* fill_opt ::= */ yytestcase(yyruleno==404); - case 416: /* having_clause_opt ::= */ yytestcase(yyruleno==416); - case 425: /* slimit_clause_opt ::= */ yytestcase(yyruleno==425); - case 429: /* limit_clause_opt ::= */ yytestcase(yyruleno==429); + case 195: /* like_pattern_opt ::= */ + case 206: /* index_options ::= */ yytestcase(yyruleno==206); + case 237: /* into_opt ::= */ yytestcase(yyruleno==237); + case 387: /* where_clause_opt ::= */ yytestcase(yyruleno==387); + case 391: /* twindow_clause_opt ::= */ yytestcase(yyruleno==391); + case 396: /* sliding_opt ::= */ yytestcase(yyruleno==396); + case 398: /* fill_opt ::= */ yytestcase(yyruleno==398); + case 410: /* having_clause_opt ::= */ yytestcase(yyruleno==410); + case 419: /* slimit_clause_opt ::= */ yytestcase(yyruleno==419); + case 423: /* limit_clause_opt ::= */ yytestcase(yyruleno==423); { yymsp[1].minor.yy662 = NULL; } break; - case 202: /* like_pattern_opt ::= LIKE NK_STRING */ + case 196: /* like_pattern_opt ::= LIKE NK_STRING */ { yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 203: /* table_name_cond ::= table_name */ + case 197: /* table_name_cond ::= table_name */ { yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy555); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 205: /* from_db_opt ::= FROM db_name */ + case 199: /* from_db_opt ::= FROM db_name */ { yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy555); } break; - case 208: /* func_name ::= function_name */ + case 202: /* func_name ::= function_name */ { yylhsminor.yy662 = createFunctionNode(pCxt, &yymsp[0].minor.yy555, NULL); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 209: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + case 203: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy617, &yymsp[-3].minor.yy555, &yymsp[-1].minor.yy555, NULL, yymsp[0].minor.yy662); } break; - case 210: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + case 204: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy617, &yymsp[-5].minor.yy555, &yymsp[-3].minor.yy555, yymsp[-1].minor.yy568, NULL); } break; - case 211: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ + case 205: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ { pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy617, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy555); } break; - case 213: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + case 207: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ { yymsp[-8].minor.yy662 = createIndexOption(pCxt, yymsp[-6].minor.yy568, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), NULL, yymsp[0].minor.yy662); } break; - case 214: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + case 208: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ { yymsp[-10].minor.yy662 = createIndexOption(pCxt, yymsp[-8].minor.yy568, releaseRawExprNode(pCxt, yymsp[-4].minor.yy662), releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), yymsp[0].minor.yy662); } break; - case 217: /* func ::= function_name NK_LP expression_list NK_RP */ + case 211: /* func ::= function_name NK_LP expression_list NK_RP */ { yylhsminor.yy662 = createFunctionNode(pCxt, &yymsp[-3].minor.yy555, yymsp[-1].minor.yy568); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 218: /* cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS query_expression */ + case 212: /* cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS query_expression */ { pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy617, &yymsp[-3].minor.yy555, yymsp[0].minor.yy662, NULL, yymsp[-2].minor.yy662); } break; - case 219: /* cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS db_name */ + case 213: /* cmd ::= CREATE TOPIC not_exists_opt topic_name topic_options AS db_name */ { pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy617, &yymsp[-3].minor.yy555, NULL, &yymsp[0].minor.yy555, yymsp[-2].minor.yy662); } break; - case 220: /* cmd ::= DROP TOPIC exists_opt topic_name */ + case 214: /* cmd ::= DROP TOPIC exists_opt topic_name */ { pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy617, &yymsp[0].minor.yy555); } break; - case 221: /* topic_options ::= */ + case 215: /* topic_options ::= */ { yymsp[1].minor.yy662 = createTopicOptions(pCxt); } break; - case 222: /* topic_options ::= topic_options WITH TABLE */ + case 216: /* topic_options ::= topic_options WITH TABLE */ { ((STopicOptions*)yymsp[-2].minor.yy662)->withTable = true; yylhsminor.yy662 = yymsp[-2].minor.yy662; } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 223: /* topic_options ::= topic_options WITH SCHEMA */ + case 217: /* topic_options ::= topic_options WITH SCHEMA */ { ((STopicOptions*)yymsp[-2].minor.yy662)->withSchema = true; yylhsminor.yy662 = yymsp[-2].minor.yy662; } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 224: /* topic_options ::= topic_options WITH TAG */ + case 218: /* topic_options ::= topic_options WITH TAG */ { ((STopicOptions*)yymsp[-2].minor.yy662)->withTag = true; yylhsminor.yy662 = yymsp[-2].minor.yy662; } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 225: /* cmd ::= DESC full_table_name */ - case 226: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==226); + case 219: /* cmd ::= DESC full_table_name */ + case 220: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==220); { pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy662); } break; - case 227: /* cmd ::= RESET QUERY CACHE */ + case 221: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 228: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + case 222: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ { pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy617, yymsp[-1].minor.yy662, yymsp[0].minor.yy662); } break; - case 230: /* analyze_opt ::= ANALYZE */ - case 238: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==238); - case 383: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==383); + case 224: /* analyze_opt ::= ANALYZE */ + case 232: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==232); + case 377: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==377); { yymsp[0].minor.yy617 = true; } break; - case 231: /* explain_options ::= */ + case 225: /* explain_options ::= */ { yymsp[1].minor.yy662 = createDefaultExplainOptions(pCxt); } break; - case 232: /* explain_options ::= explain_options VERBOSE NK_BOOL */ + case 226: /* explain_options ::= explain_options VERBOSE NK_BOOL */ { yylhsminor.yy662 = setExplainVerbose(pCxt, yymsp[-2].minor.yy662, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 233: /* explain_options ::= explain_options RATIO NK_FLOAT */ + case 227: /* explain_options ::= explain_options RATIO NK_FLOAT */ { yylhsminor.yy662 = setExplainRatio(pCxt, yymsp[-2].minor.yy662, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 234: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + case 228: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ { pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy568); } break; - case 235: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + case 229: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ { pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy617, yymsp[-8].minor.yy617, &yymsp[-5].minor.yy555, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy156, yymsp[0].minor.yy610); } break; - case 236: /* cmd ::= DROP FUNCTION function_name */ + case 230: /* cmd ::= DROP FUNCTION function_name */ { pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy555); } break; - case 239: /* bufsize_opt ::= */ + case 233: /* bufsize_opt ::= */ { yymsp[1].minor.yy610 = 0; } break; - case 240: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ + case 234: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ { yymsp[-1].minor.yy610 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 241: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ + case 235: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ { pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy617, &yymsp[-4].minor.yy555, yymsp[-2].minor.yy662, yymsp[-3].minor.yy662, yymsp[0].minor.yy662); } break; - case 242: /* cmd ::= DROP STREAM exists_opt stream_name */ + case 236: /* cmd ::= DROP STREAM exists_opt stream_name */ { pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy617, &yymsp[0].minor.yy555); } break; - case 244: /* into_opt ::= INTO full_table_name */ - case 364: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==364); - case 394: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==394); - case 417: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==417); + case 238: /* into_opt ::= INTO full_table_name */ + case 358: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==358); + case 388: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==388); + case 411: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==411); { yymsp[-1].minor.yy662 = yymsp[0].minor.yy662; } break; - case 245: /* stream_options ::= */ + case 239: /* stream_options ::= */ { yymsp[1].minor.yy662 = createStreamOptions(pCxt); } break; - case 246: /* stream_options ::= stream_options TRIGGER AT_ONCE */ + case 240: /* stream_options ::= stream_options TRIGGER AT_ONCE */ { ((SStreamOptions*)yymsp[-2].minor.yy662)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy662 = yymsp[-2].minor.yy662; } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 247: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + case 241: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ { ((SStreamOptions*)yymsp[-2].minor.yy662)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy662 = yymsp[-2].minor.yy662; } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 248: /* stream_options ::= stream_options WATERMARK duration_literal */ + case 242: /* stream_options ::= stream_options WATERMARK duration_literal */ { ((SStreamOptions*)yymsp[-2].minor.yy662)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy662); yylhsminor.yy662 = yymsp[-2].minor.yy662; } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 249: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 243: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 250: /* cmd ::= KILL QUERY NK_INTEGER */ + case 244: /* cmd ::= KILL QUERY NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_QUERY_STMT, &yymsp[0].minor.yy0); } break; - case 251: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 245: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 252: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + case 246: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy568); } break; - case 253: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 247: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 254: /* dnode_list ::= DNODE NK_INTEGER */ + case 248: /* dnode_list ::= DNODE NK_INTEGER */ { yymsp[-1].minor.yy568 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; - case 256: /* cmd ::= SYNCDB db_name REPLICA */ + case 250: /* cmd ::= SYNCDB db_name REPLICA */ { pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy555); } break; - case 258: /* literal ::= NK_INTEGER */ + case 252: /* literal ::= NK_INTEGER */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 259: /* literal ::= NK_FLOAT */ + case 253: /* literal ::= NK_FLOAT */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 260: /* literal ::= NK_STRING */ + case 254: /* literal ::= NK_STRING */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 261: /* literal ::= NK_BOOL */ + case 255: /* literal ::= NK_BOOL */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 262: /* literal ::= TIMESTAMP NK_STRING */ + case 256: /* literal ::= TIMESTAMP NK_STRING */ { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 263: /* literal ::= duration_literal */ - case 273: /* signed_literal ::= signed */ yytestcase(yyruleno==273); - case 292: /* expression ::= literal */ yytestcase(yyruleno==292); - case 293: /* expression ::= pseudo_column */ yytestcase(yyruleno==293); - case 294: /* expression ::= column_reference */ yytestcase(yyruleno==294); - case 295: /* expression ::= function_expression */ yytestcase(yyruleno==295); - case 296: /* expression ::= subquery */ yytestcase(yyruleno==296); - case 320: /* function_expression ::= literal_func */ yytestcase(yyruleno==320); - case 356: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==356); - case 360: /* boolean_primary ::= predicate */ yytestcase(yyruleno==360); - case 362: /* common_expression ::= expression */ yytestcase(yyruleno==362); - case 363: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==363); - case 365: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==365); - case 367: /* table_reference ::= table_primary */ yytestcase(yyruleno==367); - case 368: /* table_reference ::= joined_table */ yytestcase(yyruleno==368); - case 372: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==372); - case 419: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==419); - case 422: /* query_primary ::= query_specification */ yytestcase(yyruleno==422); + case 257: /* literal ::= duration_literal */ + case 267: /* signed_literal ::= signed */ yytestcase(yyruleno==267); + case 286: /* expression ::= literal */ yytestcase(yyruleno==286); + case 287: /* expression ::= pseudo_column */ yytestcase(yyruleno==287); + case 288: /* expression ::= column_reference */ yytestcase(yyruleno==288); + case 289: /* expression ::= function_expression */ yytestcase(yyruleno==289); + case 290: /* expression ::= subquery */ yytestcase(yyruleno==290); + case 314: /* function_expression ::= literal_func */ yytestcase(yyruleno==314); + case 350: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==350); + case 354: /* boolean_primary ::= predicate */ yytestcase(yyruleno==354); + case 356: /* common_expression ::= expression */ yytestcase(yyruleno==356); + case 357: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==357); + case 359: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==359); + case 361: /* table_reference ::= table_primary */ yytestcase(yyruleno==361); + case 362: /* table_reference ::= joined_table */ yytestcase(yyruleno==362); + case 366: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==366); + case 413: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==413); + case 416: /* query_primary ::= query_specification */ yytestcase(yyruleno==416); { yylhsminor.yy662 = yymsp[0].minor.yy662; } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 264: /* literal ::= NULL */ + case 258: /* literal ::= NULL */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 265: /* literal ::= NK_QUESTION */ + case 259: /* literal ::= NK_QUESTION */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 266: /* duration_literal ::= NK_VARIABLE */ + case 260: /* duration_literal ::= NK_VARIABLE */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 267: /* signed ::= NK_INTEGER */ + case 261: /* signed ::= NK_INTEGER */ { yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 268: /* signed ::= NK_PLUS NK_INTEGER */ + case 262: /* signed ::= NK_PLUS NK_INTEGER */ { yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 269: /* signed ::= NK_MINUS NK_INTEGER */ + case 263: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; @@ -3893,14 +3867,14 @@ static YYACTIONTYPE yy_reduce( } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 270: /* signed ::= NK_FLOAT */ + case 264: /* signed ::= NK_FLOAT */ { yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 271: /* signed ::= NK_PLUS NK_FLOAT */ + case 265: /* signed ::= NK_PLUS NK_FLOAT */ { yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 272: /* signed ::= NK_MINUS NK_FLOAT */ + case 266: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; @@ -3908,48 +3882,49 @@ static YYACTIONTYPE yy_reduce( } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 274: /* signed_literal ::= NK_STRING */ + case 268: /* signed_literal ::= NK_STRING */ { yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 275: /* signed_literal ::= NK_BOOL */ + case 269: /* signed_literal ::= NK_BOOL */ { yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 276: /* signed_literal ::= TIMESTAMP NK_STRING */ + case 270: /* signed_literal ::= TIMESTAMP NK_STRING */ { yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 277: /* signed_literal ::= duration_literal */ - case 279: /* signed_literal ::= literal_func */ yytestcase(yyruleno==279); - case 334: /* star_func_para ::= expression */ yytestcase(yyruleno==334); - case 389: /* select_item ::= common_expression */ yytestcase(yyruleno==389); - case 434: /* search_condition ::= common_expression */ yytestcase(yyruleno==434); + case 271: /* signed_literal ::= duration_literal */ + case 273: /* signed_literal ::= literal_func */ yytestcase(yyruleno==273); + case 328: /* star_func_para ::= expression */ yytestcase(yyruleno==328); + case 383: /* select_item ::= common_expression */ yytestcase(yyruleno==383); + case 428: /* search_condition ::= common_expression */ yytestcase(yyruleno==428); { yylhsminor.yy662 = releaseRawExprNode(pCxt, yymsp[0].minor.yy662); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 278: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } + case 272: /* signed_literal ::= NULL */ +{ yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 297: /* expression ::= NK_LP expression NK_RP */ - case 361: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==361); + case 291: /* expression ::= NK_LP expression NK_RP */ + case 355: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==355); { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy662)); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 298: /* expression ::= NK_PLUS expression */ + case 292: /* expression ::= NK_PLUS expression */ { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy662)); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 299: /* expression ::= NK_MINUS expression */ + case 293: /* expression ::= NK_MINUS expression */ { SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy662), NULL)); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 300: /* expression ::= expression NK_PLUS expression */ + case 294: /* expression ::= expression NK_PLUS expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -3957,7 +3932,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 301: /* expression ::= expression NK_MINUS expression */ + case 295: /* expression ::= expression NK_MINUS expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -3965,7 +3940,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 302: /* expression ::= expression NK_STAR expression */ + case 296: /* expression ::= expression NK_STAR expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -3973,7 +3948,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 303: /* expression ::= expression NK_SLASH expression */ + case 297: /* expression ::= expression NK_SLASH expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -3981,7 +3956,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 304: /* expression ::= expression NK_REM expression */ + case 298: /* expression ::= expression NK_REM expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -3989,64 +3964,64 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 305: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 299: /* expression ::= column_reference NK_ARROW NK_STRING */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 306: /* expression_list ::= expression */ + case 300: /* expression_list ::= expression */ { yylhsminor.yy568 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy662)); } yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 307: /* expression_list ::= expression_list NK_COMMA expression */ + case 301: /* expression_list ::= expression_list NK_COMMA expression */ { yylhsminor.yy568 = addNodeToList(pCxt, yymsp[-2].minor.yy568, releaseRawExprNode(pCxt, yymsp[0].minor.yy662)); } yymsp[-2].minor.yy568 = yylhsminor.yy568; break; - case 308: /* column_reference ::= column_name */ + case 302: /* column_reference ::= column_name */ { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy555, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy555)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 309: /* column_reference ::= table_name NK_DOT column_name */ + case 303: /* column_reference ::= table_name NK_DOT column_name */ { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy555, createColumnNode(pCxt, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy555)); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 310: /* pseudo_column ::= ROWTS */ - case 311: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==311); - case 312: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==312); - case 313: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==313); - case 314: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==314); - case 315: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==315); - case 316: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==316); - case 322: /* literal_func ::= NOW */ yytestcase(yyruleno==322); + case 304: /* pseudo_column ::= ROWTS */ + case 305: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==305); + case 306: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==306); + case 307: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==307); + case 308: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==308); + case 309: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==309); + case 310: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==310); + case 316: /* literal_func ::= NOW */ yytestcase(yyruleno==316); { yylhsminor.yy662 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } yymsp[0].minor.yy662 = yylhsminor.yy662; break; - case 317: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 318: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==318); + case 311: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 312: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==312); { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy555, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy555, yymsp[-1].minor.yy568)); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 319: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + case 313: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy662), yymsp[-1].minor.yy156)); } yymsp[-5].minor.yy662 = yylhsminor.yy662; break; - case 321: /* literal_func ::= noarg_func NK_LP NK_RP */ + case 315: /* literal_func ::= noarg_func NK_LP NK_RP */ { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy555, NULL)); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 330: /* star_func_para_list ::= NK_STAR */ + case 324: /* star_func_para_list ::= NK_STAR */ { yylhsminor.yy568 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 335: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 392: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==392); + case 329: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 386: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==386); { yylhsminor.yy662 = createColumnNode(pCxt, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 336: /* predicate ::= expression compare_op expression */ - case 341: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==341); + case 330: /* predicate ::= expression compare_op expression */ + case 335: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==335); { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -4054,7 +4029,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 337: /* predicate ::= expression BETWEEN expression AND expression */ + case 331: /* predicate ::= expression BETWEEN expression AND expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -4062,7 +4037,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 338: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 332: /* predicate ::= expression NOT BETWEEN expression AND expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -4070,71 +4045,71 @@ static YYACTIONTYPE yy_reduce( } yymsp[-5].minor.yy662 = yylhsminor.yy662; break; - case 339: /* predicate ::= expression IS NULL */ + case 333: /* predicate ::= expression IS NULL */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), NULL)); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 340: /* predicate ::= expression IS NOT NULL */ + case 334: /* predicate ::= expression IS NOT NULL */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy662); yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy662), NULL)); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 342: /* compare_op ::= NK_LT */ + case 336: /* compare_op ::= NK_LT */ { yymsp[0].minor.yy304 = OP_TYPE_LOWER_THAN; } break; - case 343: /* compare_op ::= NK_GT */ + case 337: /* compare_op ::= NK_GT */ { yymsp[0].minor.yy304 = OP_TYPE_GREATER_THAN; } break; - case 344: /* compare_op ::= NK_LE */ + case 338: /* compare_op ::= NK_LE */ { yymsp[0].minor.yy304 = OP_TYPE_LOWER_EQUAL; } break; - case 345: /* compare_op ::= NK_GE */ + case 339: /* compare_op ::= NK_GE */ { yymsp[0].minor.yy304 = OP_TYPE_GREATER_EQUAL; } break; - case 346: /* compare_op ::= NK_NE */ + case 340: /* compare_op ::= NK_NE */ { yymsp[0].minor.yy304 = OP_TYPE_NOT_EQUAL; } break; - case 347: /* compare_op ::= NK_EQ */ + case 341: /* compare_op ::= NK_EQ */ { yymsp[0].minor.yy304 = OP_TYPE_EQUAL; } break; - case 348: /* compare_op ::= LIKE */ + case 342: /* compare_op ::= LIKE */ { yymsp[0].minor.yy304 = OP_TYPE_LIKE; } break; - case 349: /* compare_op ::= NOT LIKE */ + case 343: /* compare_op ::= NOT LIKE */ { yymsp[-1].minor.yy304 = OP_TYPE_NOT_LIKE; } break; - case 350: /* compare_op ::= MATCH */ + case 344: /* compare_op ::= MATCH */ { yymsp[0].minor.yy304 = OP_TYPE_MATCH; } break; - case 351: /* compare_op ::= NMATCH */ + case 345: /* compare_op ::= NMATCH */ { yymsp[0].minor.yy304 = OP_TYPE_NMATCH; } break; - case 352: /* compare_op ::= CONTAINS */ + case 346: /* compare_op ::= CONTAINS */ { yymsp[0].minor.yy304 = OP_TYPE_JSON_CONTAINS; } break; - case 353: /* in_op ::= IN */ + case 347: /* in_op ::= IN */ { yymsp[0].minor.yy304 = OP_TYPE_IN; } break; - case 354: /* in_op ::= NOT IN */ + case 348: /* in_op ::= NOT IN */ { yymsp[-1].minor.yy304 = OP_TYPE_NOT_IN; } break; - case 355: /* in_predicate_value ::= NK_LP expression_list NK_RP */ + case 349: /* in_predicate_value ::= NK_LP expression_list NK_RP */ { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy568)); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 357: /* boolean_value_expression ::= NOT boolean_primary */ + case 351: /* boolean_value_expression ::= NOT boolean_primary */ { SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy662), NULL)); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 358: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 352: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -4142,7 +4117,7 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 359: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 353: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); @@ -4150,47 +4125,47 @@ static YYACTIONTYPE yy_reduce( } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 366: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ + case 360: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ { yylhsminor.yy662 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy662, yymsp[0].minor.yy662, NULL); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 369: /* table_primary ::= table_name alias_opt */ + case 363: /* table_primary ::= table_name alias_opt */ { yylhsminor.yy662 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy555, &yymsp[0].minor.yy555); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 370: /* table_primary ::= db_name NK_DOT table_name alias_opt */ + case 364: /* table_primary ::= db_name NK_DOT table_name alias_opt */ { yylhsminor.yy662 = createRealTableNode(pCxt, &yymsp[-3].minor.yy555, &yymsp[-1].minor.yy555, &yymsp[0].minor.yy555); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 371: /* table_primary ::= subquery alias_opt */ + case 365: /* table_primary ::= subquery alias_opt */ { yylhsminor.yy662 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy662), &yymsp[0].minor.yy555); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 373: /* alias_opt ::= */ + case 367: /* alias_opt ::= */ { yymsp[1].minor.yy555 = nil_token; } break; - case 374: /* alias_opt ::= table_alias */ + case 368: /* alias_opt ::= table_alias */ { yylhsminor.yy555 = yymsp[0].minor.yy555; } yymsp[0].minor.yy555 = yylhsminor.yy555; break; - case 375: /* alias_opt ::= AS table_alias */ + case 369: /* alias_opt ::= AS table_alias */ { yymsp[-1].minor.yy555 = yymsp[0].minor.yy555; } break; - case 376: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 377: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==377); + case 370: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 371: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==371); { yymsp[-2].minor.yy662 = yymsp[-1].minor.yy662; } break; - case 378: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + case 372: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ { yylhsminor.yy662 = createJoinTableNode(pCxt, yymsp[-4].minor.yy84, yymsp[-5].minor.yy662, yymsp[-2].minor.yy662, yymsp[0].minor.yy662); } yymsp[-5].minor.yy662 = yylhsminor.yy662; break; - case 379: /* join_type ::= */ + case 373: /* join_type ::= */ { yymsp[1].minor.yy84 = JOIN_TYPE_INNER; } break; - case 380: /* join_type ::= INNER */ + case 374: /* join_type ::= INNER */ { yymsp[0].minor.yy84 = JOIN_TYPE_INNER; } break; - case 381: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 375: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { yymsp[-8].minor.yy662 = createSelectStmt(pCxt, yymsp[-7].minor.yy617, yymsp[-6].minor.yy568, yymsp[-5].minor.yy662); yymsp[-8].minor.yy662 = addWhereClause(pCxt, yymsp[-8].minor.yy662, yymsp[-4].minor.yy662); @@ -4200,70 +4175,70 @@ static YYACTIONTYPE yy_reduce( yymsp[-8].minor.yy662 = addHavingClause(pCxt, yymsp[-8].minor.yy662, yymsp[0].minor.yy662); } break; - case 384: /* set_quantifier_opt ::= ALL */ + case 378: /* set_quantifier_opt ::= ALL */ { yymsp[0].minor.yy617 = false; } break; - case 385: /* select_list ::= NK_STAR */ + case 379: /* select_list ::= NK_STAR */ { yymsp[0].minor.yy568 = NULL; } break; - case 390: /* select_item ::= common_expression column_alias */ + case 384: /* select_item ::= common_expression column_alias */ { yylhsminor.yy662 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy662), &yymsp[0].minor.yy555); } yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 391: /* select_item ::= common_expression AS column_alias */ + case 385: /* select_item ::= common_expression AS column_alias */ { yylhsminor.yy662 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), &yymsp[0].minor.yy555); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 396: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 413: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==413); - case 424: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==424); + case 390: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 407: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==407); + case 418: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==418); { yymsp[-2].minor.yy568 = yymsp[0].minor.yy568; } break; - case 398: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + case 392: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ { yymsp[-5].minor.yy662 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy662), releaseRawExprNode(pCxt, yymsp[-1].minor.yy662)); } break; - case 399: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + case 393: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ { yymsp[-3].minor.yy662 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy662)); } break; - case 400: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + case 394: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ { yymsp[-5].minor.yy662 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy662), NULL, yymsp[-1].minor.yy662, yymsp[0].minor.yy662); } break; - case 401: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + case 395: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ { yymsp[-7].minor.yy662 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy662), releaseRawExprNode(pCxt, yymsp[-3].minor.yy662), yymsp[-1].minor.yy662, yymsp[0].minor.yy662); } break; - case 403: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + case 397: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ { yymsp[-3].minor.yy662 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy662); } break; - case 405: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ + case 399: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ { yymsp[-3].minor.yy662 = createFillNode(pCxt, yymsp[-1].minor.yy284, NULL); } break; - case 406: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + case 400: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ { yymsp[-5].minor.yy662 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy568)); } break; - case 407: /* fill_mode ::= NONE */ + case 401: /* fill_mode ::= NONE */ { yymsp[0].minor.yy284 = FILL_MODE_NONE; } break; - case 408: /* fill_mode ::= PREV */ + case 402: /* fill_mode ::= PREV */ { yymsp[0].minor.yy284 = FILL_MODE_PREV; } break; - case 409: /* fill_mode ::= NULL */ + case 403: /* fill_mode ::= NULL */ { yymsp[0].minor.yy284 = FILL_MODE_NULL; } break; - case 410: /* fill_mode ::= LINEAR */ + case 404: /* fill_mode ::= LINEAR */ { yymsp[0].minor.yy284 = FILL_MODE_LINEAR; } break; - case 411: /* fill_mode ::= NEXT */ + case 405: /* fill_mode ::= NEXT */ { yymsp[0].minor.yy284 = FILL_MODE_NEXT; } break; - case 414: /* group_by_list ::= expression */ + case 408: /* group_by_list ::= expression */ { yylhsminor.yy568 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 415: /* group_by_list ::= group_by_list NK_COMMA expression */ + case 409: /* group_by_list ::= group_by_list NK_COMMA expression */ { yylhsminor.yy568 = addNodeToList(pCxt, yymsp[-2].minor.yy568, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } yymsp[-2].minor.yy568 = yylhsminor.yy568; break; - case 418: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 412: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { yylhsminor.yy662 = addOrderByClause(pCxt, yymsp[-3].minor.yy662, yymsp[-2].minor.yy568); yylhsminor.yy662 = addSlimitClause(pCxt, yylhsminor.yy662, yymsp[-1].minor.yy662); @@ -4271,50 +4246,50 @@ static YYACTIONTYPE yy_reduce( } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 420: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + case 414: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ { yylhsminor.yy662 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy662, yymsp[0].minor.yy662); } yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 421: /* query_expression_body ::= query_expression_body UNION query_expression_body */ + case 415: /* query_expression_body ::= query_expression_body UNION query_expression_body */ { yylhsminor.yy662 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy662, yymsp[0].minor.yy662); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 426: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 430: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==430); + case 420: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 424: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==424); { yymsp[-1].minor.yy662 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 427: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 431: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==431); + case 421: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 425: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==425); { yymsp[-3].minor.yy662 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 428: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 432: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==432); + case 422: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 426: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==426); { yymsp[-3].minor.yy662 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 433: /* subquery ::= NK_LP query_expression NK_RP */ + case 427: /* subquery ::= NK_LP query_expression NK_RP */ { yylhsminor.yy662 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy662); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 437: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + case 431: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ { yylhsminor.yy662 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), yymsp[-1].minor.yy272, yymsp[0].minor.yy181); } yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 438: /* ordering_specification_opt ::= */ + case 432: /* ordering_specification_opt ::= */ { yymsp[1].minor.yy272 = ORDER_ASC; } break; - case 439: /* ordering_specification_opt ::= ASC */ + case 433: /* ordering_specification_opt ::= ASC */ { yymsp[0].minor.yy272 = ORDER_ASC; } break; - case 440: /* ordering_specification_opt ::= DESC */ + case 434: /* ordering_specification_opt ::= DESC */ { yymsp[0].minor.yy272 = ORDER_DESC; } break; - case 441: /* null_ordering_opt ::= */ + case 435: /* null_ordering_opt ::= */ { yymsp[1].minor.yy181 = NULL_ORDER_DEFAULT; } break; - case 442: /* null_ordering_opt ::= NULLS FIRST */ + case 436: /* null_ordering_opt ::= NULLS FIRST */ { yymsp[-1].minor.yy181 = NULL_ORDER_FIRST; } break; - case 443: /* null_ordering_opt ::= NULLS LAST */ + case 437: /* null_ordering_opt ::= NULLS LAST */ { yymsp[-1].minor.yy181 = NULL_ORDER_LAST; } break; default: @@ -4378,13 +4353,12 @@ static void yy_syntax_error( #define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ - if (pCxt->valid) { + if (TSDB_CODE_SUCCESS == pCxt->errCode) { if(TOKEN.z) { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z); + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z); } else { - generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL); + pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL); } - pCxt->valid = false; } /************ End %syntax_error code ******************************************/ ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ diff --git a/source/libs/parser/test/CMakeLists.txt b/source/libs/parser/test/CMakeLists.txt index 96de3fb7356a6cf3acb4df828e3284c472f4ef07..0e8adb978dd0e9fca5a67e9999ce7c5faa877cc0 100644 --- a/source/libs/parser/test/CMakeLists.txt +++ b/source/libs/parser/test/CMakeLists.txt @@ -24,4 +24,9 @@ if(${BUILD_WINGETOPT}) PUBLIC "${TD_SOURCE_DIR}/contrib/wingetopt/src" ) target_link_libraries(parserTest PUBLIC wingetopt) -endif() \ No newline at end of file +endif() + +add_test( + NAME parserTest + COMMAND parserTest +) diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 289888c71b3d6ff8063215e13d12e859f0d9e9fe..ab02ff9558f1d20308f82b8fb29fe7143566d9b7 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -155,16 +155,22 @@ int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, return 0; } +int32_t __catalogGetDBCfg(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* dbFName, SDbCfgInfo* pDbCfg) { + return 0; +} + void initMetaDataEnv() { mockCatalogService.reset(new MockCatalogService()); static Stub stub; stub.set(catalogGetHandle, __catalogGetHandle); stub.set(catalogGetTableMeta, __catalogGetTableMeta); + stub.set(catalogGetSTableMeta, __catalogGetTableMeta); stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup); stub.set(catalogGetTableDistVgInfo, __catalogGetTableDistVgInfo); stub.set(catalogGetDBVgVersion, __catalogGetDBVgVersion); stub.set(catalogGetDBVgInfo, __catalogGetDBVgInfo); + stub.set(catalogGetDBCfg, __catalogGetDBCfg); // { // AddrAny any("libcatalog.so"); // std::map result; diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index ef989e919051c4e9f5565e7963796d8d8d46a0e5..2c85bfdf2e5f71674cf329c478572fec4f0119b4 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -111,9 +111,8 @@ class MockCatalogServiceImpl { } int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const { - char db[TSDB_DB_NAME_LEN] = {0}; - tNameGetDbName(pTableName, db); - return copyTableVgroup(db, tNameGetTableName(pTableName), vgInfo); + vgInfo->vgId = 1; + return TSDB_CODE_SUCCESS; } int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** vgList) const { diff --git a/source/libs/parser/test/parExplainToSyncdbTest.cpp b/source/libs/parser/test/parExplainToSyncdbTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c12912ef337519585524a2d3f5c2d485bc661885 --- /dev/null +++ b/source/libs/parser/test/parExplainToSyncdbTest.cpp @@ -0,0 +1,42 @@ +/* + * 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 "parTestUtil.h" + +using namespace std; + +namespace ParserTest { + +class ParserExplainToSyncdbTest : public ParserTestBase {}; + +TEST_F(ParserExplainToSyncdbTest, explain) { + useDb("root", "test"); + + run("explain SELECT * FROM t1"); + + run("explain analyze SELECT * FROM t1"); + + run("explain analyze verbose true ratio 0.01 SELECT * FROM t1"); +} + +// todo kill connection +// todo kill query +// todo kill stream +// todo merge vgroup +// todo redistribute vgroup +// todo reset query cache +// todo syncdb + +} // namespace ParserTest diff --git a/source/libs/parser/test/parInitialATest.cpp b/source/libs/parser/test/parInitialATest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e58f50f52aeedfe6767b02b44d0c0d0d84037b0a --- /dev/null +++ b/source/libs/parser/test/parInitialATest.cpp @@ -0,0 +1,62 @@ +/* + * 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 "parTestUtil.h" + +using namespace std; + +namespace ParserTest { + +class ParserInitialATest : public ParserTestBase {}; + +TEST_F(ParserInitialATest, alterAccount) { + useDb("root", "test"); + + run("alter account ac_wxy pass '123456'", TSDB_CODE_PAR_EXPRIE_STATEMENT); +} + +TEST_F(ParserInitialATest, alterDnode) { + useDb("root", "test"); + + run("alter dnode 1 'resetLog'"); + + run("alter dnode 1 'debugFlag' '134'"); +} + +TEST_F(ParserInitialATest, alterDatabase) { + useDb("root", "test"); + + run("alter database wxy_db cachelast 1 fsync 200 wal 1"); +} + +// todo alter local +// todo alter stable +// todo alter table + +TEST_F(ParserInitialATest, alterUser) { + useDb("root", "test"); + + run("alter user wxy pass '123456'"); + + run("alter user wxy privilege 'write'"); +} + +TEST_F(ParserInitialATest, bug001) { + useDb("root", "test"); + + run("alter database db wal 0 # td-14436", TSDB_CODE_PAR_SYNTAX_ERROR); +} + +} // namespace ParserTest \ No newline at end of file diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..540560fcd72a3c4fa0e579dfab69fa72937a63c2 --- /dev/null +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -0,0 +1,180 @@ +/* + * 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 "parTestUtil.h" + +using namespace std; + +namespace ParserTest { + +class ParserInitialCTest : public ParserTestBase {}; + +// todo compact + +TEST_F(ParserInitialCTest, createAccount) { + useDb("root", "test"); + + run("create account ac_wxy pass '123456'", TSDB_CODE_PAR_EXPRIE_STATEMENT); +} + +TEST_F(ParserInitialCTest, createBnode) { + useDb("root", "test"); + + run("create bnode on dnode 1"); +} + +TEST_F(ParserInitialCTest, createDatabase) { + useDb("root", "test"); + + run("create database wxy_db"); + + run("create database if not exists wxy_db " + "cachelast 2 " + "comp 1 " + "days 100 " + "fsync 100 " + "maxrows 1000 " + "minrows 100 " + "keep 1440 " + "precision 'ms' " + "replica 3 " + "wal 2 " + "vgroups 100 " + "single_stable 0 " + "retentions 15s:7d,1m:21d,15m:5y"); + + run("create database if not exists wxy_db " + "days 100m " + "keep 1440m,300h,400d "); +} + +TEST_F(ParserInitialCTest, createDnode) { + useDb("root", "test"); + + run("create dnode abc1 port 7000"); + + run("create dnode 1.1.1.1 port 9000"); +} + +// todo create function + +TEST_F(ParserInitialCTest, createIndexSma) { + useDb("root", "test"); + + run("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)"); +} + +TEST_F(ParserInitialCTest, createMnode) { + useDb("root", "test"); + + run("create mnode on dnode 1"); +} + +TEST_F(ParserInitialCTest, createQnode) { + useDb("root", "test"); + + run("create qnode on dnode 1"); +} + +TEST_F(ParserInitialCTest, createSnode) { + useDb("root", "test"); + + run("create snode on dnode 1"); +} + +TEST_F(ParserInitialCTest, createStable) { + useDb("root", "test"); + + run("create stable t1(ts timestamp, c1 int) TAGS(id int)"); + + run("create stable if not exists test.t1(" + "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " + "SMALLINT, " + "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), " + "c15 VARCHAR(50)) " + "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 " + "BINARY(20), a8 SMALLINT, " + "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), " + "a15 VARCHAR(50)) " + "TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"); +} + +TEST_F(ParserInitialCTest, createStream) { + useDb("root", "test"); + + run("create stream s1 as select * from t1"); + + run("create stream if not exists s1 as select * from t1"); + + run("create stream s1 into st1 as select * from t1"); + + run("create stream if not exists s1 trigger window_close watermark 10s into st1 as select * from t1"); +} + +TEST_F(ParserInitialCTest, createTable) { + useDb("root", "test"); + + run("create table t1(ts timestamp, c1 int)"); + + run("create table if not exists test.t1(" + "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " + "SMALLINT, " + "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 " + "NCHAR(30), " + "c15 VARCHAR(50)) " + "TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"); + + run("create table if not exists test.t1(" + "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " + "SMALLINT, " + "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 " + "NCHAR(30), " + "c15 VARCHAR(50)) " + "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, " + "a5 FLOAT, a6 DOUBLE, a7 " + "BINARY(20), a8 SMALLINT, " + "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 " + "TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), " + "a15 VARCHAR(50)) " + "TTL 100 COMMENT 'test create " + "table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"); + + run("create table if not exists t1 using st1 tags(1, 'wxy')"); + + run("create table " + "if not exists test.t1 using test.st1 (tag1, tag2) tags(1, 'abc') " + "if not exists test.t2 using test.st1 (tag1, tag2) tags(2, 'abc') " + "if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc') "); +} + +TEST_F(ParserInitialCTest, createTopic) { + useDb("root", "test"); + + run("create topic tp1 as select * from t1"); + + run("create topic if not exists tp1 as select * from t1"); + + run("create topic tp1 as test"); + + run("create topic if not exists tp1 as test"); +} + +TEST_F(ParserInitialCTest, createUser) { + useDb("root", "test"); + + run("create user wxy pass '123456'"); +} + +} // namespace ParserTest diff --git a/source/libs/parser/test/parInitialDTest.cpp b/source/libs/parser/test/parInitialDTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1153b238b1feb1be8167c91acb0bf7f7267a391f --- /dev/null +++ b/source/libs/parser/test/parInitialDTest.cpp @@ -0,0 +1,81 @@ +/* + * 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 "parTestUtil.h" + +using namespace std; + +namespace ParserTest { + +class ParserInitialDTest : public ParserTestBase {}; + +// todo delete +// todo desc +// todo describe +// todo drop account + +TEST_F(ParserInitialDTest, dropBnode) { + useDb("root", "test"); + + run("drop bnode on dnode 1"); +} + +// todo drop database +// todo drop dnode +// todo drop function + +TEST_F(ParserInitialDTest, dropIndex) { + useDb("root", "test"); + + run("drop index index1 on t1"); +} + +TEST_F(ParserInitialDTest, dropMnode) { + useDb("root", "test"); + + run("drop mnode on dnode 1"); +} + +TEST_F(ParserInitialDTest, dropQnode) { + useDb("root", "test"); + + run("drop qnode on dnode 1"); +} + +TEST_F(ParserInitialDTest, dropSnode) { + useDb("root", "test"); + + run("drop snode on dnode 1"); +} + +// todo drop stable +// todo drop stream +// todo drop table + +TEST_F(ParserInitialDTest, dropTopic) { + useDb("root", "test"); + + run("drop topic tp1"); + + run("drop topic if exists tp1"); +} + +TEST_F(ParserInitialDTest, dropUser) { + useDb("root", "test"); + + run("drop user wxy"); +} + +} // namespace ParserTest diff --git a/source/libs/parser/test/parserInsertTest.cpp b/source/libs/parser/test/parInsertTest.cpp similarity index 99% rename from source/libs/parser/test/parserInsertTest.cpp rename to source/libs/parser/test/parInsertTest.cpp index 308152bf3ea12255ac41640b367a20c96dd50fa7..7fafec88824111ef8b170ba25f3b092fd7ba1f1a 100644 --- a/source/libs/parser/test/parserInsertTest.cpp +++ b/source/libs/parser/test/parInsertTest.cpp @@ -111,6 +111,7 @@ class InsertTest : public Test { cxt_.pMsg = errMagBuf_; cxt_.msgLen = max_err_len; code_ = TSDB_CODE_SUCCESS; + res_ = nullptr; } SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) { return (SVnodeModifOpStmt*)pQuery->pRoot; } diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c3a4e8ab9a06e71ab9051c8288bd95fec588b39 --- /dev/null +++ b/source/libs/parser/test/parSelectTest.cpp @@ -0,0 +1,194 @@ +/* + * 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 "parTestUtil.h" + +using namespace std; + +namespace ParserTest { + +class ParserSelectTest : public ParserTestBase {}; + +TEST_F(ParserSelectTest, basic) { + useDb("root", "test"); + + run("select * from t1"); + + run("select * from test.t1"); + + run("select ts, c1 from t1"); + + run("select ts, t.c1 from (select * from t1) t"); + + run("select * from t1 tt1, t1 tt2 where tt1.c1 = tt2.c1"); +} + +TEST_F(ParserSelectTest, constant) { + useDb("root", "test"); + + run("select 123, 20.4, 'abc', \"wxy\", timestamp '2022-02-09 17:30:20', true, false, 10s from t1"); + + run("select 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", " + "timestamp '2022-02-09 17:30:20', true, false, 15s from t1"); + + run("select 123 + 45 from t1 where 2 - 1"); +} + +TEST_F(ParserSelectTest, expression) { + useDb("root", "test"); + + run("select ts + 10s, c1 + 10, concat(c2, 'abc') from t1"); + + run("select ts > 0, c1 < 20 and c2 = 'qaz' from t1"); + + run("select ts > 0, c1 between 10 and 20 and c2 = 'qaz' from t1"); +} + +TEST_F(ParserSelectTest, condition) { + useDb("root", "test"); + + run("select c1 from t1 where ts in (true, false)"); + + run("select * from t1 where c1 > 10 and c1 is not null"); +} + +TEST_F(ParserSelectTest, pseudoColumn) { + useDb("root", "test"); + + run("select _wstartts, _wendts, count(*) from t1 interval(10s)"); +} + +TEST_F(ParserSelectTest, multiResFunc) { + useDb("root", "test"); + + run("select last(*), first(*), last_row(*) from t1"); + + run("select last(c1, c2), first(t1.*), last_row(c3) from t1"); + + run("select last(t2.*), first(t1.c1, t2.*), last_row(t1.*, t2.*) from st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); +} + +TEST_F(ParserSelectTest, timelineFunc) { + useDb("root", "test"); + + run("select last(*), first(*) from t1"); + + run("select last(*), first(*) from t1 group by c1"); + + run("select last(*), first(*) from t1 interval(10s)"); + + run("select diff(c1) from t1"); +} + +TEST_F(ParserSelectTest, clause) { + useDb("root", "test"); + + // group by clause + run("select count(*) cnt from t1 where c1 > 0"); + + run("select count(*), c2 cnt from t1 where c1 > 0 group by c2"); + + run("select count(*) cnt from t1 where c1 > 0 group by c2 having count(c1) > 10"); + + run("select count(*), c1, c2 + 10, c1 + c2 cnt from t1 where c1 > 0 group by c2, c1"); + + run("select count(*), c1 + 10, c2 cnt from t1 where c1 > 0 group by c1 + 10, c2"); + + // order by clause + run("select count(*) cnt from t1 where c1 > 0 group by c2 order by cnt"); + + run("select count(*) cnt from t1 where c1 > 0 group by c2 order by 1"); + + // distinct clause + // run("select distinct c1, c2 from t1 where c1 > 0 order by c1"); + + // run("select distinct c1 + 10, c2 from t1 where c1 > 0 order by c1 + 10, c2"); + + // run("select distinct c1 + 10 cc1, c2 cc2 from t1 where c1 > 0 order by cc1, c2"); + + // run("select distinct count(c2) from t1 where c1 > 0 group by c1 order by count(c2)"); +} + +TEST_F(ParserSelectTest, window) { + useDb("root", "test"); + + run("select count(*) from t1 interval(10s)"); +} + +TEST_F(ParserSelectTest, semanticError) { + useDb("root", "test"); + + // TSDB_CODE_PAR_INVALID_COLUMN + run("select c1, cc1 from t1", TSDB_CODE_PAR_INVALID_COLUMN, PARSER_STAGE_TRANSLATE); + + run("select t1.c1, t1.cc1 from t1", TSDB_CODE_PAR_INVALID_COLUMN, PARSER_STAGE_TRANSLATE); + + // TSDB_CODE_PAR_TABLE_NOT_EXIST + run("select * from t10", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + + run("select * from test.t10", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + + run("select t2.c1 from t1", TSDB_CODE_PAR_TABLE_NOT_EXIST, PARSER_STAGE_TRANSLATE); + + // 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); + + // TSDB_CODE_PAR_WRONG_VALUE_TYPE + run("select timestamp '2010' from t1", TSDB_CODE_PAR_WRONG_VALUE_TYPE, PARSER_STAGE_TRANSLATE); + + // 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 where count(*) > 0", 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, PARSER_STAGE_TRANSLATE); + + // 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 2", TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT, PARSER_STAGE_TRANSLATE); + + // 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 group by c2 having c1 > 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, + PARSER_STAGE_TRANSLATE); + + run("select count(*) cnt from t1 group by c2 having c2 > 0 order by c1", TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION, + PARSER_STAGE_TRANSLATE); + + // TSDB_CODE_PAR_NOT_SINGLE_GROUP + run("select count(*), c1 from t1", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + + run("select count(*) from t1 order by c1", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + + run("select c1 from t1 order by count(*)", TSDB_CODE_PAR_NOT_SINGLE_GROUP, PARSER_STAGE_TRANSLATE); + + // 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 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, + PARSER_STAGE_TRANSLATE); +} + +} // namespace ParserTest diff --git a/source/libs/parser/test/parShowToUse.cpp b/source/libs/parser/test/parShowToUse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37d5d87a88d2e91ecfddf70cd8bc23e17d891cba --- /dev/null +++ b/source/libs/parser/test/parShowToUse.cpp @@ -0,0 +1,138 @@ +/* + * 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 "parTestUtil.h" + +using namespace std; + +namespace ParserTest { + +class ParserShowToUseTest : public ParserTestBase {}; + +// todo show accounts +// todo show apps +// todo show connections +// todo show create database +// todo show create stable +// todo show create table + +TEST_F(ParserShowToUseTest, showDatabases) { + useDb("root", "test"); + + run("show databases"); +} + +TEST_F(ParserShowToUseTest, showDnodes) { + useDb("root", "test"); + + run("show dnodes"); +} + +TEST_F(ParserShowToUseTest, showFunctions) { + useDb("root", "test"); + + run("show functions"); +} + +// todo show licence + +TEST_F(ParserShowToUseTest, showIndexes) { + useDb("root", "test"); + + run("show indexes from t1"); + + run("show indexes from t1 from test"); +} + +TEST_F(ParserShowToUseTest, showMnodes) { + useDb("root", "test"); + + run("show mnodes"); +} + +TEST_F(ParserShowToUseTest, showModules) { + useDb("root", "test"); + + run("show modules"); +} + +TEST_F(ParserShowToUseTest, showQnodes) { + useDb("root", "test"); + + run("show qnodes"); +} + +// todo show queries +// todo show scores + +TEST_F(ParserShowToUseTest, showStables) { + useDb("root", "test"); + + run("show stables"); + + run("show test.stables"); + + run("show stables like 'c%'"); + + run("show test.stables like 'c%'"); +} + +TEST_F(ParserShowToUseTest, showStreams) { + useDb("root", "test"); + + run("show streams"); +} + +TEST_F(ParserShowToUseTest, showTables) { + useDb("root", "test"); + + run("show tables"); + + run("show test.tables"); + + run("show tables like 'c%'"); + + run("show test.tables like 'c%'"); +} + +// todo show topics + +TEST_F(ParserShowToUseTest, showUsers) { + useDb("root", "test"); + + run("show users"); +} + +// todo show variables + +TEST_F(ParserShowToUseTest, showVgroups) { + useDb("root", "test"); + + run("show vgroups"); + + run("show test.vgroups"); +} + +// todo show vnodes + +// todo split vgroup + +TEST_F(ParserShowToUseTest, useDatabase) { + useDb("root", "test"); + + run("use wxy_db"); +} + +} // namespace ParserTest diff --git a/source/libs/parser/test/parserTestMain.cpp b/source/libs/parser/test/parTestMain.cpp similarity index 90% rename from source/libs/parser/test/parserTestMain.cpp rename to source/libs/parser/test/parTestMain.cpp index 62b092251cf143f12da5a619c1b1b8fac7fee07a..ebc83fb21981e56666b82ec6a5a08a63cd7f0c87 100644 --- a/source/libs/parser/test/parserTestMain.cpp +++ b/source/libs/parser/test/parTestMain.cpp @@ -13,23 +13,24 @@ * along with this program. If not, see . */ +#include #include #include #include -#include #include #ifdef WINDOWS #define TD_USE_WINSOCK #endif + #include "functionMgt.h" #include "mockCatalog.h" #include "os.h" +#include "parTestUtil.h" #include "parToken.h" -#include "parserTestUtil.h" -bool g_isDump = false; +namespace ParserTest { class ParserEnv : public testing::Environment { public: @@ -63,9 +64,11 @@ static void parseArg(int argc, char* argv[]) { } } +} // namespace ParserTest + int main(int argc, char* argv[]) { - testing::AddGlobalTestEnvironment(new ParserEnv()); + testing::AddGlobalTestEnvironment(new ParserTest::ParserEnv()); testing::InitGoogleTest(&argc, argv); - parseArg(argc, argv); + ParserTest::parseArg(argc, argv); return RUN_ALL_TESTS(); } diff --git a/source/libs/parser/test/parTestUtil.cpp b/source/libs/parser/test/parTestUtil.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9ff756a95699e8e8f4fb89c0bf734976fa75bf3 --- /dev/null +++ b/source/libs/parser/test/parTestUtil.cpp @@ -0,0 +1,196 @@ +/* + * 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 "parTestUtil.h" + +#include +#include + +#include "parInt.h" + +using namespace std; +using namespace testing; + +namespace ParserTest { + +#define DO_WITH_THROW(func, ...) \ + do { \ + int32_t code__ = func(__VA_ARGS__); \ + if (!checkResultCode(#func, code__)) { \ + if (TSDB_CODE_SUCCESS != code__) { \ + throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + \ + ", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \ + } else { \ + throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " expect " + to_string(stmtEnv_.expect_) + \ + " actual " + to_string(code__)); \ + } \ + } else if (TSDB_CODE_SUCCESS != code__) { \ + throw TerminateFlag(); \ + } \ + } while (0); + +bool g_isDump = false; + +struct TerminateFlag : public exception { + const char* what() const throw() { return "success and terminate"; } +}; + +class ParserTestBaseImpl { + public: + void useDb(const string& acctId, const string& db) { + caseEnv_.acctId_ = acctId; + caseEnv_.db_ = db; + } + + void run(const string& sql, int32_t expect, ParserStage checkStage) { + reset(expect, checkStage); + try { + SParseContext cxt = {0}; + setParseContext(sql, &cxt); + + SQuery* pQuery = nullptr; + doParse(&cxt, &pQuery); + + doTranslate(&cxt, pQuery); + + doCalculateConstant(&cxt, pQuery); + + if (g_isDump) { + dump(); + } + } catch (const TerminateFlag& e) { + // success and terminate + return; + } catch (...) { + dump(); + throw; + } + } + + private: + struct caseEnv { + string acctId_; + string db_; + }; + + struct stmtEnv { + string sql_; + array msgBuf_; + int32_t expect_; + string checkFunc_; + }; + + struct stmtRes { + string parsedAst_; + string translatedAst_; + string calcConstAst_; + }; + + bool checkResultCode(const string& pFunc, int32_t resultCode) { + return !(stmtEnv_.checkFunc_.empty()) + ? (("*" == stmtEnv_.checkFunc_ || stmtEnv_.checkFunc_ == pFunc) ? stmtEnv_.expect_ == resultCode + : TSDB_CODE_SUCCESS == resultCode) + : true; + } + + string stageFunc(ParserStage stage) { + switch (stage) { + case PARSER_STAGE_PARSE: + return "parse"; + case PARSER_STAGE_TRANSLATE: + return "translate"; + case PARSER_STAGE_CALC_CONST: + return "calculateConstant"; + case PARSER_STAGE_ALL: + return "*"; + default: + break; + } + return "unknown"; + } + + void reset(int32_t expect, ParserStage checkStage) { + stmtEnv_.sql_.clear(); + stmtEnv_.msgBuf_.fill(0); + stmtEnv_.expect_ = expect; + stmtEnv_.checkFunc_ = stageFunc(checkStage); + + res_.parsedAst_.clear(); + res_.translatedAst_.clear(); + res_.calcConstAst_.clear(); + } + + void dump() { + cout << "==========================================sql : [" << stmtEnv_.sql_ << "]" << endl; + cout << "raw syntax tree : " << endl; + cout << res_.parsedAst_ << endl; + cout << "translated syntax tree : " << endl; + cout << res_.translatedAst_ << endl; + cout << "optimized syntax tree : " << endl; + cout << res_.calcConstAst_ << endl; + } + + void setParseContext(const string& sql, SParseContext* pCxt) { + stmtEnv_.sql_ = sql; + transform(stmtEnv_.sql_.begin(), stmtEnv_.sql_.end(), stmtEnv_.sql_.begin(), ::tolower); + + pCxt->acctId = atoi(caseEnv_.acctId_.c_str()); + pCxt->db = caseEnv_.db_.c_str(); + pCxt->pSql = stmtEnv_.sql_.c_str(); + pCxt->sqlLen = stmtEnv_.sql_.length(); + pCxt->pMsg = stmtEnv_.msgBuf_.data(); + pCxt->msgLen = stmtEnv_.msgBuf_.max_size(); + } + + void doParse(SParseContext* pCxt, SQuery** pQuery) { + DO_WITH_THROW(parse, pCxt, pQuery); + res_.parsedAst_ = toString((*pQuery)->pRoot); + } + + void doTranslate(SParseContext* pCxt, SQuery* pQuery) { + DO_WITH_THROW(translate, pCxt, pQuery); + res_.translatedAst_ = toString(pQuery->pRoot); + } + + void doCalculateConstant(SParseContext* pCxt, SQuery* pQuery) { + DO_WITH_THROW(calculateConstant, pCxt, pQuery); + res_.calcConstAst_ = toString(pQuery->pRoot); + } + + string toString(const SNode* pRoot) { + char* pStr = NULL; + int32_t len = 0; + DO_WITH_THROW(nodesNodeToString, pRoot, false, &pStr, &len) + string str(pStr); + taosMemoryFreeClear(pStr); + return str; + } + + caseEnv caseEnv_; + stmtEnv stmtEnv_; + stmtRes res_; +}; + +ParserTestBase::ParserTestBase() : impl_(new ParserTestBaseImpl()) {} + +ParserTestBase::~ParserTestBase() {} + +void ParserTestBase::useDb(const std::string& acctId, const std::string& db) { impl_->useDb(acctId, db); } + +void ParserTestBase::run(const std::string& sql, int32_t expect, ParserStage checkStage) { + return impl_->run(sql, expect, checkStage); +} + +} // namespace ParserTest diff --git a/source/libs/parser/test/parTestUtil.h b/source/libs/parser/test/parTestUtil.h new file mode 100644 index 0000000000000000000000000000000000000000..0e8703b2c82fa85772e5bf8650ef1b3be78dd3f3 --- /dev/null +++ b/source/libs/parser/test/parTestUtil.h @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +#ifndef PARSER_TEST_UTIL_H +#define PARSER_TEST_UTIL_H + +#include + +#include "taoserror.h" + +namespace ParserTest { + +class ParserTestBaseImpl; + +enum ParserStage { PARSER_STAGE_PARSE, PARSER_STAGE_TRANSLATE, PARSER_STAGE_CALC_CONST, PARSER_STAGE_ALL }; + +class ParserTestBase : public testing::Test { + public: + ParserTestBase(); + virtual ~ParserTestBase(); + + void useDb(const std::string& acctId, const std::string& db); + void run(const std::string& sql, int32_t expect = TSDB_CODE_SUCCESS, ParserStage checkStage = PARSER_STAGE_ALL); + + private: + std::unique_ptr impl_; +}; + +extern bool g_isDump; + +} // namespace ParserTest + +#endif // PARSER_TEST_UTIL_H diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp deleted file mode 100644 index 3cfc16600fb3b10ee5dc78460670ae079cd60759..0000000000000000000000000000000000000000 --- a/source/libs/parser/test/parserAstTest.cpp +++ /dev/null @@ -1,782 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include - -#include "parInt.h" -#include "parserTestUtil.h" - -using namespace std; -using namespace testing; - -class ParserTest : public Test { - protected: - void setDatabase(const string& acctId, const string& db) { - acctId_ = acctId; - db_ = db; - } - - void bind(const char* sql) { - reset(); - cxt_.acctId = atoi(acctId_.c_str()); - cxt_.db = db_.c_str(); - sqlBuf_ = string(sql); - transform(sqlBuf_.begin(), sqlBuf_.end(), sqlBuf_.begin(), ::tolower); - cxt_.sqlLen = strlen(sql); - cxt_.pSql = sqlBuf_.c_str(); - } - - bool run(int32_t parseCode = TSDB_CODE_SUCCESS, int32_t translateCode = TSDB_CODE_SUCCESS) { - query_ = nullptr; - bool res = runImpl(parseCode, translateCode); - qDestroyQuery(query_); - if (!res || g_isDump) { - dump(); - } - return res; - } - - private: - static const int max_err_len = 1024; - - bool runImpl(int32_t parseCode, int32_t translateCode) { - int32_t code = parse(&cxt_, &query_); - if (code != TSDB_CODE_SUCCESS) { - parseErrStr_ = string("code:") + tstrerror(code) + string(", msg:") + errMagBuf_; - return (code == parseCode); - } - if (TSDB_CODE_SUCCESS != parseCode) { - return false; - } - parsedAstStr_ = toString(query_->pRoot); - code = translate(&cxt_, query_); - if (code != TSDB_CODE_SUCCESS) { - translateErrStr_ = string("code:") + tstrerror(code) + string(", msg:") + errMagBuf_; - return (code == translateCode); - } - translatedAstStr_ = toString(query_->pRoot); - code = calculateConstant(&cxt_, query_); - if (code != TSDB_CODE_SUCCESS) { - calcConstErrStr_ = string("code:") + tstrerror(code) + string(", msg:") + errMagBuf_; - return false; - } - calcConstAstStr_ = toString(query_->pRoot); - return (TSDB_CODE_SUCCESS == translateCode); - } - - void dump() { - cout << "input sql : [" << cxt_.pSql << "]" << endl; - if (!parseErrStr_.empty()) { - cout << "parse error: " << parseErrStr_ << endl; - } - if (!parsedAstStr_.empty()) { - cout << "parse output: " << endl; - cout << parsedAstStr_ << endl; - } - if (!translateErrStr_.empty()) { - cout << "translate error: " << translateErrStr_ << endl; - } - if (!translatedAstStr_.empty()) { - cout << "translate output: " << endl; - cout << translatedAstStr_ << endl; - } - if (!calcConstErrStr_.empty()) { - cout << "calculateConstant error: " << calcConstErrStr_ << endl; - } - if (!calcConstAstStr_.empty()) { - cout << "calculateConstant output: " << endl; - cout << calcConstAstStr_ << endl; - } - } - - string toString(const SNode* pRoot, bool format = false) { - char* pStr = NULL; - int32_t len = 0; - int32_t code = nodesNodeToString(pRoot, format, &pStr, &len); - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] toString code:" << code << ", strerror:" << tstrerror(code) << endl; - throw "nodesNodeToString failed!"; - } - string str(pStr); - taosMemoryFreeClear(pStr); - return str; - } - - void reset() { - memset(&cxt_, 0, sizeof(cxt_)); - memset(errMagBuf_, 0, max_err_len); - cxt_.pMsg = errMagBuf_; - cxt_.msgLen = max_err_len; - parseErrStr_.clear(); - parsedAstStr_.clear(); - translateErrStr_.clear(); - translatedAstStr_.clear(); - calcConstErrStr_.clear(); - calcConstAstStr_.clear(); - } - - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - string sqlBuf_; - SParseContext cxt_; - SQuery* query_; - string parseErrStr_; - string parsedAstStr_; - string translateErrStr_; - string translatedAstStr_; - string calcConstErrStr_; - string calcConstAstStr_; -}; - -TEST_F(ParserTest, createAccount) { - setDatabase("root", "test"); - - bind("create account ac_wxy pass '123456'"); - ASSERT_TRUE(run(TSDB_CODE_PAR_EXPRIE_STATEMENT)); -} - -TEST_F(ParserTest, alterAccount) { - setDatabase("root", "test"); - - bind("alter account ac_wxy pass '123456'"); - ASSERT_TRUE(run(TSDB_CODE_PAR_EXPRIE_STATEMENT)); -} - -TEST_F(ParserTest, createUser) { - setDatabase("root", "test"); - - bind("create user wxy pass '123456'"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, alterUser) { - setDatabase("root", "test"); - - bind("alter user wxy pass '123456'"); - ASSERT_TRUE(run()); - - bind("alter user wxy privilege 'write'"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, dropUser) { - setDatabase("root", "test"); - - bind("drop user wxy"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectSimple) { - setDatabase("root", "test"); - - bind("SELECT * FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM test.t1"); - ASSERT_TRUE(run()); - - bind("SELECT ts, c1 FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT ts, t.c1 FROM (SELECT * FROM t1) t"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectConstant) { - setDatabase("root", "test"); - - bind("SELECT 123, 20.4, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 10s FROM t1"); - ASSERT_TRUE(run()); - - bind( - "SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", " - "TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT 123 + 45 FROM t1 where 2 - 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectExpression) { - setDatabase("root", "test"); - - bind("SELECT ts + 10s, c1 + 10, concat(c2, 'abc') FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT ts > 0, c1 < 20 AND c2 = 'qaz' FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT ts > 0, c1 BETWEEN 10 AND 20 AND c2 = 'qaz' FROM t1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectCondition) { - setDatabase("root", "test"); - - bind("SELECT c1 FROM t1 where ts in (true, false)"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 where c1 > 10 and c1 is not null"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectPseudoColumn) { - setDatabase("root", "test"); - - bind("SELECT _wstartts, _wendts, count(*) FROM t1 interval(10s)"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectMultiResFunc) { - setDatabase("root", "test"); - - // bind("SELECT last(*), first(*), last_row(*) FROM t1"); - // ASSERT_TRUE(run()); - - bind("SELECT last(c1, c2), first(t1.*), last_row(c3) FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT last(t2.*), first(t1.c1, t2.*), last_row(t1.*, t2.*) FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectClause) { - setDatabase("root", "test"); - - // GROUP BY clause - bind("SELECT count(*) cnt FROM t1 WHERE c1 > 0"); - ASSERT_TRUE(run()); - - bind("SELECT count(*), c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c2"); - ASSERT_TRUE(run()); - - bind("SELECT count(*) cnt FROM t1 WHERE c1 > 0 GROUP BY c2 HAVING count(c1) > 10"); - ASSERT_TRUE(run()); - - bind("SELECT count(*), c1, c2 + 10, c1 + c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c2, c1"); - ASSERT_TRUE(run()); - - bind("SELECT count(*), c1 + 10, c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c1 + 10, c2"); - ASSERT_TRUE(run()); - - // ORDER BY clause - bind("SELECT count(*) cnt FROM t1 WHERE c1 > 0 GROUP BY c2 ORDER BY cnt"); - ASSERT_TRUE(run()); - - bind("SELECT count(*) cnt FROM t1 WHERE c1 > 0 GROUP BY c2 ORDER BY 1"); - ASSERT_TRUE(run()); - - // DISTINCT clause - bind("SELECT DISTINCT c1, c2 FROM t1 WHERE c1 > 0 ORDER BY c1"); - ASSERT_TRUE(run()); - - bind("SELECT DISTINCT c1 + 10, c2 FROM t1 WHERE c1 > 0 ORDER BY c1 + 10, c2"); - ASSERT_TRUE(run()); - - bind("SELECT DISTINCT c1 + 10 cc1, c2 cc2 FROM t1 WHERE c1 > 0 ORDER BY cc1, c2"); - ASSERT_TRUE(run()); - - bind("SELECT DISTINCT count(c2) FROM t1 WHERE c1 > 0 GROUP BY c1 ORDER BY count(c2)"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectWindow) { - setDatabase("root", "test"); - - bind("SELECT count(*) FROM t1 interval(10s)"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, selectSyntaxError) { - setDatabase("root", "test"); - - bind("SELECTT * FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_FAILED)); - - bind("SELECT *"); - ASSERT_TRUE(run(TSDB_CODE_FAILED)); - - bind("SELECT *, * FROM test.t1"); - ASSERT_TRUE(run(TSDB_CODE_FAILED)); - - bind("SELECT * FROM test.t1 t WHER"); - ASSERT_TRUE(run(TSDB_CODE_FAILED)); -} - -TEST_F(ParserTest, selectSemanticError) { - setDatabase("root", "test"); - - // TSDB_CODE_PAR_INVALID_COLUMN - bind("SELECT c1, cc1 FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_COLUMN)); - - bind("SELECT t1.c1, t1.cc1 FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_COLUMN)); - - // TSDB_CODE_PAR_TABLE_NOT_EXIST - bind("SELECT * FROM t10"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_TABLE_NOT_EXIST)); - - bind("SELECT * FROM test.t10"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_TABLE_NOT_EXIST)); - - bind("SELECT t2.c1 FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_TABLE_NOT_EXIST)); - - // TSDB_CODE_PAR_AMBIGUOUS_COLUMN - bind("SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_AMBIGUOUS_COLUMN)); - - // TSDB_CODE_PAR_WRONG_VALUE_TYPE - bind("SELECT 10n FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_WRONG_VALUE_TYPE)); - - bind("SELECT TIMESTAMP '2010' FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_WRONG_VALUE_TYPE)); - - // TSDB_CODE_PAR_INVALID_FUNTION - bind("SELECT cnt(*) FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_FUNC_INVALID_FUNTION)); - - // TSDB_CODE_PAR_FUNTION_PARA_NUM - // TSDB_CODE_PAR_FUNTION_PARA_TYPE - - // TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION - bind("SELECT c2 FROM t1 tt1 JOIN t1 tt2 ON count(*) > 0"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION)); - - bind("SELECT c2 FROM t1 where count(*) > 0"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION)); - - bind("SELECT c2 FROM t1 GROUP BY count(*)"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION)); - - // TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT - bind("SELECT c2 FROM t1 ORDER BY 0"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT)); - - bind("SELECT c2 FROM t1 ORDER BY 2"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT)); - - // TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION - bind("SELECT count(*) cnt FROM t1 HAVING c1 > 0"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION)); - - bind("SELECT count(*) cnt FROM t1 GROUP BY c2 HAVING c1 > 0"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION)); - - bind("SELECT count(*), c1 cnt FROM t1 GROUP BY c2 HAVING c2 > 0"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION)); - - bind("SELECT count(*) cnt FROM t1 GROUP BY c2 HAVING c2 > 0 ORDER BY c1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION)); - - // TSDB_CODE_PAR_NOT_SINGLE_GROUP - bind("SELECT count(*), c1 FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_NOT_SINGLE_GROUP)); - - bind("SELECT count(*) FROM t1 ORDER BY c1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_NOT_SINGLE_GROUP)); - - bind("SELECT c1 FROM t1 ORDER BY count(*)"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_NOT_SINGLE_GROUP)); - - // TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION - bind("SELECT DISTINCT c1, c2 FROM t1 WHERE c1 > 0 ORDER BY ts"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION)); - - bind("SELECT DISTINCT c1 FROM t1 WHERE c1 > 0 ORDER BY count(c2)"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION)); - - bind("SELECT DISTINCT c2 FROM t1 WHERE c1 > 0 ORDER BY count(c2)"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION)); -} - -TEST_F(ParserTest, showUsers) { - setDatabase("root", "test"); - - bind("show users"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createDnode) { - setDatabase("root", "test"); - - bind("create dnode abc1 port 7000"); - ASSERT_TRUE(run()); - - bind("create dnode 1.1.1.1 port 9000"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showDnodes) { - setDatabase("root", "test"); - - bind("show dnodes"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, alterDnode) { - setDatabase("root", "test"); - - bind("alter dnode 1 'resetLog'"); - ASSERT_TRUE(run()); - - bind("alter dnode 1 'debugFlag' '134'"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createDatabase) { - setDatabase("root", "test"); - - bind("create database wxy_db"); - ASSERT_TRUE(run()); - - bind( - "create database if not exists wxy_db " - "BLOCKS 100 " - "CACHE 100 " - "CACHELAST 2 " - "COMP 1 " - "DAYS 100 " - "FSYNC 100 " - "MAXROWS 1000 " - "MINROWS 100 " - "KEEP 100 " - "PRECISION 'ms' " - "QUORUM 1 " - "REPLICA 3 " - "TTL 100 " - "WAL 2 " - "VGROUPS 100 " - "SINGLE_STABLE 0 " - "STREAM_MODE 1 " - "RETENTIONS '15s:7d,1m:21d,15m:5y'"); - ASSERT_TRUE(run()); - - bind( - "create database if not exists wxy_db " - "DAYS 100m " - "KEEP 200m,300h,400d "); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, alterDatabase) { - setDatabase("root", "test"); - - bind("alter database wxy_db BLOCKS 200"); - ASSERT_TRUE(run()); - - bind( - "alter database wxy_db " - "BLOCKS 200 " - "CACHELAST 1 " - "FSYNC 200 " - "KEEP 200 " - "QUORUM 2 " - "WAL 1 "); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showDatabase) { - setDatabase("root", "test"); - - bind("show databases"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, useDatabase) { - setDatabase("root", "test"); - - bind("use wxy_db"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createTable) { - setDatabase("root", "test"); - - bind("create table t1(ts timestamp, c1 int)"); - ASSERT_TRUE(run()); - - bind( - "create table if not exists test.t1(" - "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " - "SMALLINT, " - "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), " - "c14 JSON, c15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"); - ASSERT_TRUE(run()); - - bind( - "create table if not exists test.t1(" - "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " - "SMALLINT, " - "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), " - "c14 JSON, c15 VARCHAR(50)) " - "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 " - "BINARY(20), a8 SMALLINT, " - "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), " - "a14 JSON, a15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"); - ASSERT_TRUE(run()); - - bind("create table if not exists t1 using st1 tags(1, 'wxy')"); - ASSERT_TRUE(run()); - - bind( - "create table " - "if not exists test.t1 using test.st1 (tag1, tag2) tags(1, 'abc') " - "if not exists test.t2 using test.st1 (tag1, tag2) tags(2, 'abc') " - "if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc') " - "if not exists test.t4 using test.st1 (tag1, tag2) tags(3, null) " - "if not exists test.t5 using test.st1 (tag1, tag2) tags(null, 'abc') " - "if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)"); - ASSERT_TRUE(run()); - - bind("create stable t1(ts timestamp, c1 int) TAGS(id int)"); - ASSERT_TRUE(run()); - - bind( - "create stable if not exists test.t1(" - "ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 " - "SMALLINT, " - "c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), " - "c14 JSON, c15 VARCHAR(50)) " - "TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 " - "BINARY(20), a8 SMALLINT, " - "a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), " - "a14 JSON, a15 VARCHAR(50)) " - "KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showTables) { - setDatabase("root", "test"); - - bind("show tables"); - ASSERT_TRUE(run()); - - bind("show test.tables"); - ASSERT_TRUE(run()); - - bind("show tables like 'c%'"); - ASSERT_TRUE(run()); - - bind("show test.tables like 'c%'"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showStables) { - setDatabase("root", "test"); - - bind("show stables"); - ASSERT_TRUE(run()); - - bind("show test.stables"); - ASSERT_TRUE(run()); - - bind("show stables like 'c%'"); - ASSERT_TRUE(run()); - - bind("show test.stables like 'c%'"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showVgroups) { - setDatabase("root", "test"); - - bind("show vgroups"); - ASSERT_TRUE(run()); - - bind("show test.vgroups"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showMnodes) { - setDatabase("root", "test"); - - bind("show mnodes"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showModules) { - setDatabase("root", "test"); - - bind("show modules"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showQnodes) { - setDatabase("root", "test"); - - bind("show qnodes"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showFunctions) { - setDatabase("root", "test"); - - bind("show functions"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showIndexes) { - setDatabase("root", "test"); - - bind("show indexes from t1"); - ASSERT_TRUE(run()); - - bind("show indexes from t1 from test"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, showStreams) { - setDatabase("root", "test"); - - bind("show streams"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createSmaIndex) { - setDatabase("root", "test"); - - bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, dropIndex) { - setDatabase("root", "test"); - - bind("drop index index1 on t1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createQnode) { - setDatabase("root", "test"); - - bind("create qnode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, dropQnode) { - setDatabase("root", "test"); - - bind("drop qnode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createBnode) { - setDatabase("root", "test"); - - bind("create bnode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, dropBnode) { - setDatabase("root", "test"); - - bind("drop bnode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createSnode) { - setDatabase("root", "test"); - - bind("create snode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, dropSnode) { - setDatabase("root", "test"); - - bind("drop snode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createMnode) { - setDatabase("root", "test"); - - bind("create mnode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, dropMnode) { - setDatabase("root", "test"); - - bind("drop mnode on dnode 1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createTopic) { - setDatabase("root", "test"); - - bind("create topic tp1 as select * from t1"); - ASSERT_TRUE(run()); - - bind("create topic if not exists tp1 as select * from t1"); - ASSERT_TRUE(run()); - - bind("create topic tp1 as test"); - ASSERT_TRUE(run()); - - bind("create topic if not exists tp1 as test"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, dropTopic) { - setDatabase("root", "test"); - - bind("drop topic tp1"); - ASSERT_TRUE(run()); - - bind("drop topic if exists tp1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, createStream) { - setDatabase("root", "test"); - - bind("create stream s1 as select * from t1"); - ASSERT_TRUE(run()); - - bind("create stream if not exists s1 as select * from t1"); - ASSERT_TRUE(run()); - - bind("create stream s1 into st1 as select * from t1"); - ASSERT_TRUE(run()); - - bind("create stream if not exists s1 trigger window_close watermark 10s into st1 as select * from t1"); - ASSERT_TRUE(run()); -} - -TEST_F(ParserTest, explain) { - setDatabase("root", "test"); - - bind("explain SELECT * FROM t1"); - ASSERT_TRUE(run()); - - bind("explain analyze SELECT * FROM t1"); - ASSERT_TRUE(run()); - - bind("explain analyze verbose true ratio 0.01 SELECT * FROM t1"); - ASSERT_TRUE(run()); -} diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 18e59859accdcc9cb2efc0df20842ef43a5844f5..00f28082941ee45483898ee905f428458d4b1afc 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -748,10 +748,10 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele SLogicNode* pRoot = NULL; int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot); if (TSDB_CODE_SUCCESS == code) { - code = createChildLogicNode(pCxt, pSelect, createWindowLogicNode, &pRoot); + code = createChildLogicNode(pCxt, pSelect, createPartitionLogicNode, &pRoot); } if (TSDB_CODE_SUCCESS == code) { - code = createChildLogicNode(pCxt, pSelect, createPartitionLogicNode, &pRoot); + code = createChildLogicNode(pCxt, pSelect, createWindowLogicNode, &pRoot); } if (TSDB_CODE_SUCCESS == code) { code = createChildLogicNode(pCxt, pSelect, createAggLogicNode, &pRoot); @@ -944,9 +944,16 @@ static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* } static int32_t getMsgType(ENodeType sqlType) { - return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) - ? TDMT_VND_CREATE_TABLE - : TDMT_VND_SUBMIT; + switch (sqlType) { + case QUERY_NODE_CREATE_TABLE_STMT: + case QUERY_NODE_CREATE_MULTI_TABLE_STMT: + return TDMT_VND_CREATE_TABLE; + case QUERY_NODE_DROP_TABLE_STMT: + return TDMT_VND_DROP_TABLE; + default: + break; + } + return TDMT_VND_SUBMIT; } static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) { diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 042b914927732edb7b8214f2976a230c1f883e8f..47dcd9ce86299f7d97aa3e807c2998d3c89fb7a8 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -206,6 +206,8 @@ static int32_t cpdMergeCond(SNode** pDst, SNode** pSrc) { if (NULL == pLogicCond) { return TSDB_CODE_OUT_OF_MEMORY; } + pLogicCond->node.resType.type = TSDB_DATA_TYPE_BOOL; + pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; pLogicCond->condType = LOGIC_COND_TYPE_AND; int32_t code = nodesListMakeAppend(&pLogicCond->pParameterList, *pSrc); if (TSDB_CODE_SUCCESS == code) { @@ -520,6 +522,7 @@ static int32_t cpdPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SN default: break; } + planError("cpdPushCondToChild failed, invalid logic plan node %s", nodesNodeName(nodeType(pChild))); return TSDB_CODE_PLAN_INTERNAL_ERROR; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 548957ab8e2db71da3ef0b1644afd760ef6eb8d4..901afce7186402aed191fa6f23ed44c49c252816 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -18,6 +18,7 @@ #include "catalog.h" #include "functionMgt.h" #include "tglobal.h" +#include "systable.h" typedef struct SSlotIdInfo { int16_t slotId; @@ -271,6 +272,7 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { } // pIndex is definitely not NULL, otherwise it is a bug if (NULL == pIndex) { + planError("doSetSlotId failed, invalid slot name %s", name); pCxt->errCode = TSDB_CODE_PLAN_INTERNAL_ERROR; return DEAL_RES_ERROR; } @@ -434,12 +436,15 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd pNodeAddr->epSet = vg->epSet; } -static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { +static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode( pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); if (NULL == pTagScan) { return TSDB_CODE_OUT_OF_MEMORY; } + vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); + taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode); return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTagScan, pPhyNode); } @@ -513,7 +518,7 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SPhysiNode** pPhyNode) { switch (pScanLogicNode->scanType) { case SCAN_TYPE_TAG: - return createTagScanPhysiNode(pCxt, pScanLogicNode, pPhyNode); + return createTagScanPhysiNode(pCxt, pSubplan, pScanLogicNode, pPhyNode); case SCAN_TYPE_TABLE: return createTableScanPhysiNode(pCxt, pSubplan, pScanLogicNode, pPhyNode); case SCAN_TYPE_SYSTEM_TABLE: diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 4d4670379e6460ebe5df840e2e52ef71366571a4..6336377279716b0d60947cc1b3f637dfd4eebebb 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -19,26 +19,23 @@ typedef struct SCollectPlaceholderValuesCxt { int32_t errCode; - SNodeList* pValues; + SArray* pValues; } SCollectPlaceholderValuesCxt; static EDealRes collectPlaceholderValuesImpl(SNode* pNode, void* pContext) { if (QUERY_NODE_VALUE == nodeType(pNode) && ((SValueNode*)pNode)->placeholderNo > 0) { SCollectPlaceholderValuesCxt* pCxt = pContext; - pCxt->errCode = nodesListMakeAppend(&pCxt->pValues, pNode); + taosArrayInsert(pCxt->pValues, ((SValueNode*)pNode)->placeholderNo - 1, &pNode); return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR; } return DEAL_RES_CONTINUE; } static int32_t collectPlaceholderValues(SPlanContext* pCxt, SQueryPlan* pPlan) { - SCollectPlaceholderValuesCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pValues = NULL}; + pPlan->pPlaceholderValues = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); + + SCollectPlaceholderValuesCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pValues = pPlan->pPlaceholderValues}; nodesWalkPhysiPlan((SNode*)pPlan, collectPlaceholderValuesImpl, &cxt); - if (TSDB_CODE_SUCCESS == cxt.errCode) { - pPlan->pPlaceholderValues = cxt.pValues; - } else { - nodesDestroyList(cxt.pValues); - } return cxt.errCode; } @@ -60,7 +57,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo if (TSDB_CODE_SUCCESS == code) { code = createPhysiPlan(pCxt, pLogicPlan, pPlan, pExecNodeList); } - if (TSDB_CODE_SUCCESS == code && pCxt->isStmtQuery) { + if (TSDB_CODE_SUCCESS == code && pCxt->placeholderNum > 0) { code = collectPlaceholderValues(pCxt, *pPlan); } @@ -107,8 +104,9 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes; return TSDB_CODE_SUCCESS; } + int32_t inputSize = (NULL != pParam->length ? *(pParam->length) : tDataTypes[pParam->buffer_type].bytes); pVal->node.resType.type = pParam->buffer_type; - pVal->node.resType.bytes = *(pParam->length); + pVal->node.resType.bytes = inputSize; switch (pParam->buffer_type) { case TSDB_DATA_TYPE_BOOL: pVal->datum.b = *((bool*)pParam->buffer); @@ -140,6 +138,21 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { varDataSetLen(pVal->datum.p, pVal->node.resType.bytes); strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes); break; + case TSDB_DATA_TYPE_NCHAR: { + pVal->node.resType.bytes *= TSDB_NCHAR_SIZE; + pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); + if (NULL == pVal->datum.p) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int32_t output = 0; + if (!taosMbsToUcs4(pParam->buffer, inputSize, (TdUcs4*)varDataVal(pVal->datum.p), pVal->node.resType.bytes, &output)) { + return errno; + } + varDataSetLen(pVal->datum.p, output); + pVal->node.resType.bytes = output; + break; + } case TSDB_DATA_TYPE_TIMESTAMP: pVal->datum.i = *((int64_t*)pParam->buffer); break; @@ -155,7 +168,6 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { case TSDB_DATA_TYPE_UBIGINT: pVal->datum.u = *((uint64_t*)pParam->buffer); break; - case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_JSON: case TSDB_DATA_TYPE_DECIMAL: case TSDB_DATA_TYPE_BLOB: @@ -168,18 +180,42 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) { return TSDB_CODE_SUCCESS; } -int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_MULTI_BIND* pParams, int32_t colIdx) { - if (colIdx < 0) { - int32_t index = 0; - SNode* pNode = NULL; +static EDealRes updatePlanQueryId(SNode* pNode, void* pContext) { + int64_t queryId = *(uint64_t *)pContext; + + if (QUERY_NODE_PHYSICAL_PLAN == nodeType(pNode)) { + SQueryPlan* planNode = (SQueryPlan*)pNode; + planNode->queryId = queryId; + } else if (QUERY_NODE_PHYSICAL_SUBPLAN == nodeType(pNode)) { + SSubplan* subplanNode = (SSubplan*)pNode; + subplanNode->id.queryId = queryId; + } + + return DEAL_RES_CONTINUE; +} - FOREACH(pNode, pPlan->pPlaceholderValues) { - setValueByBindParam((SValueNode*)pNode, pParams + index); - ++index; +int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_MULTI_BIND* pParams, int32_t colIdx, uint64_t queryId) { + int32_t size = taosArrayGetSize(pPlan->pPlaceholderValues); + int32_t code = 0; + + if (colIdx < 0) { + for (int32_t i = 0; i < size; ++i) { + code = setValueByBindParam((SValueNode*)taosArrayGetP(pPlan->pPlaceholderValues, i), pParams + i); + if (code) { + return code; + } } } else { - setValueByBindParam((SValueNode*)nodesListGetNode(pPlan->pPlaceholderValues, colIdx), pParams); + code = setValueByBindParam((SValueNode*)taosArrayGetP(pPlan->pPlaceholderValues, colIdx), pParams); + if (code) { + return code; + } + } + + if (colIdx < 0 || ((colIdx + 1) == size)) { + nodesWalkPhysiPlan((SNode*)pPlan, updatePlanQueryId, &queryId); } + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/test/CMakeLists.txt b/source/libs/planner/test/CMakeLists.txt index f0c59b969f0827a3c1a24c424819d097c71891ba..a21b36fef6b3eecc51bdbe4abbb7fff3dc065098 100644 --- a/source/libs/planner/test/CMakeLists.txt +++ b/source/libs/planner/test/CMakeLists.txt @@ -30,4 +30,9 @@ if(${BUILD_WINGETOPT}) PUBLIC "${TD_SOURCE_DIR}/contrib/wingetopt/src" ) target_link_libraries(plannerTest PUBLIC wingetopt) -endif() \ No newline at end of file +endif() + +add_test( + NAME plannerTest + COMMAND plannerTest +) diff --git a/source/libs/planner/test/planBasicTest.cpp b/source/libs/planner/test/planBasicTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..05a009d79d1b2cc7ac09b2a49ac5e3947671c951 --- /dev/null +++ b/source/libs/planner/test/planBasicTest.cpp @@ -0,0 +1,49 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanBasicTest : public PlannerTestBase {}; + +TEST_F(PlanBasicTest, select) { + useDb("root", "test"); + + run("select * from t1"); + run("select 1 from t1"); + run("select * from st1"); + run("select 1 from st1"); +} + +TEST_F(PlanBasicTest, where) { + useDb("root", "test"); + + run("select * from t1 where c1 > 10"); +} + +TEST_F(PlanBasicTest, join) { + useDb("root", "test"); + + run("select t1.c1, t2.c2 from st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + run("select t1.c1, t2.c2 from st1s1 t1 join st1s2 t2 on t1.ts = t2.ts"); +} + +TEST_F(PlanBasicTest, func) { + useDb("root", "test"); + + run("select diff(c1) from t1"); +} diff --git a/source/libs/planner/test/planDistinctTest.cpp b/source/libs/planner/test/planDistinctTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..58473dcff27839654fe8ea4f33c9d408c2c4b24f --- /dev/null +++ b/source/libs/planner/test/planDistinctTest.cpp @@ -0,0 +1,42 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanDistinctTest : public PlannerTestBase {}; + +TEST_F(PlanDistinctTest, basic) { + useDb("root", "test"); + + // distinct single col + run("select distinct c1 from t1"); + // distinct col list + run("select distinct c1, c2 from t1"); +} + +TEST_F(PlanDistinctTest, expr) { + useDb("root", "test"); + + run("select distinct c1, c2 + 10 from t1"); +} + +TEST_F(PlanDistinctTest, withOrderBy) { + useDb("root", "test"); + + run("select distinct c1 + 10 a from t1 order by a"); +} diff --git a/source/libs/planner/test/planGroupByTest.cpp b/source/libs/planner/test/planGroupByTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..05ffe41fe7cc69b916dba37059bc71c754b722ad --- /dev/null +++ b/source/libs/planner/test/planGroupByTest.cpp @@ -0,0 +1,52 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanGroupByTest : public PlannerTestBase {}; + +TEST_F(PlanGroupByTest, basic) { + useDb("root", "test"); + + run("select count(*) from t1"); + + run("select c1, max(c3), min(c3), count(*) from t1 group by c1"); + + run("select c1 + c3, c1 + count(*) from t1 where c2 = 'abc' group by c1, c3"); + + run("select c1 + c3, sum(c4 * c5) from t1 where concat(c2, 'wwww') = 'abcwww' group by c1 + c3"); + + run("select sum(ceil(c1)) from t1 group by ceil(c1)"); +} + +TEST_F(PlanGroupByTest, withOrderBy) { + useDb("root", "test"); + + // order by aggfunc + run("select count(*), sum(c1) from t1 order by sum(c1)"); + // order by alias of aggfunc + // run("select count(*), sum(c1) a from t1 order by a"); +} + +TEST_F(PlanGroupByTest, aggFunc) { + useDb("root", "test"); + + run("select last(*), first(*) from t1"); + + run("select last(*), first(*) from t1 group by c1"); +} diff --git a/source/libs/planner/test/planIntervalTest.cpp b/source/libs/planner/test/planIntervalTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6cc67a34461783290d30420bc25579323a2bcf6f --- /dev/null +++ b/source/libs/planner/test/planIntervalTest.cpp @@ -0,0 +1,41 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanIntervalTest : public PlannerTestBase {}; + +TEST_F(PlanIntervalTest, basic) { + useDb("root", "test"); + + run("select count(*) from t1 interval(10s)"); +} + +TEST_F(PlanIntervalTest, pseudoCol) { + useDb("root", "test"); + + run("select _wstartts, _wduration, _wendts, count(*) from t1 interval(10s)"); +} + +TEST_F(PlanIntervalTest, fill) { + useDb("root", "test"); + + run("select count(*) from t1 interval(10s) fill(linear)"); + + run("select count(*), sum(c1) from t1 interval(10s) fill(value, 10, 20)"); +} diff --git a/source/libs/planner/test/planJoinTest.cpp b/source/libs/planner/test/planJoinTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4098d383f8edc2461613cfb8ab9102035185b4b9 --- /dev/null +++ b/source/libs/planner/test/planJoinTest.cpp @@ -0,0 +1,32 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanJoinTest : public PlannerTestBase {}; + +TEST_F(PlanJoinTest, basic) { + useDb("root", "test"); + + run("select t1.c1, t2.c2 from st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + + run("select t1.*, t2.* from st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + + // run("select t1.c1, t2.c1 from st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and " + // "t2.c2 = 'qwe'"); +} diff --git a/source/libs/planner/test/planLimitTest.cpp b/source/libs/planner/test/planLimitTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b8b3180bdd3b873736ba65ef362b6985ec60c0d --- /dev/null +++ b/source/libs/planner/test/planLimitTest.cpp @@ -0,0 +1,41 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanLimitTest : public PlannerTestBase {}; + +TEST_F(PlanLimitTest, limit) { + useDb("root", "test"); + + run("select * from t1 limit 2"); + + run("select * from t1 limit 5 offset 2"); + + run("select * from t1 limit 2, 5"); +} + +TEST_F(PlanLimitTest, slimit) { + useDb("root", "test"); + + run("select * from t1 partition by c1 slimit 2"); + + run("select * from t1 partition by c1 slimit 5 soffset 2"); + + run("select * from t1 partition by c1 slimit 2, 5"); +} diff --git a/source/libs/planner/test/planOptTest.cpp b/source/libs/planner/test/planOptimizeTest.cpp similarity index 100% rename from source/libs/planner/test/planOptTest.cpp rename to source/libs/planner/test/planOptimizeTest.cpp diff --git a/source/libs/planner/test/planOrderByTest.cpp b/source/libs/planner/test/planOrderByTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d95d1bdf1d429d9ea6c5e62c5a280dbb5c6de477 --- /dev/null +++ b/source/libs/planner/test/planOrderByTest.cpp @@ -0,0 +1,42 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanOrderByTest : public PlannerTestBase {}; + +TEST_F(PlanOrderByTest, basic) { + useDb("root", "test"); + + // order by key is in the projection list + run("select c1 from t1 order by c1"); + // order by key is not in the projection list + run("select c1 from t1 order by c2"); +} + +TEST_F(PlanOrderByTest, expr) { + useDb("root", "test"); + + run("select * from t1 order by c1 + 10, c2"); +} + +TEST_F(PlanOrderByTest, nullsOrder) { + useDb("root", "test"); + + run("select * from t1 order by c1 desc nulls first"); +} diff --git a/source/libs/planner/test/planOtherTest.cpp b/source/libs/planner/test/planOtherTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b70cb4d19ae99de436914d95e4192cf297b2435d --- /dev/null +++ b/source/libs/planner/test/planOtherTest.cpp @@ -0,0 +1,50 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanOtherTest : public PlannerTestBase {}; + +TEST_F(PlanOtherTest, createTopic) { + useDb("root", "test"); + + run("create topic tp as SELECT * FROM st1"); +} + +TEST_F(PlanOtherTest, createStream) { + useDb("root", "test"); + + run("create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 " + "interval(10s)"); +} + +TEST_F(PlanOtherTest, createSmaIndex) { + useDb("root", "test"); + + run("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) interval(10s)"); +} + +TEST_F(PlanOtherTest, explain) { + useDb("root", "test"); + + run("explain SELECT * FROM t1"); + + run("explain analyze SELECT * FROM t1"); + + run("explain analyze verbose true ratio 0.01 SELECT * FROM t1"); +} \ No newline at end of file diff --git a/source/libs/planner/test/planPartByTest.cpp b/source/libs/planner/test/planPartByTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..230500e70266053684b2a3ee94876cd3e42efd68 --- /dev/null +++ b/source/libs/planner/test/planPartByTest.cpp @@ -0,0 +1,48 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanPartitionByTest : public PlannerTestBase {}; + +TEST_F(PlanPartitionByTest, basic) { + useDb("root", "test"); + + run("select * from t1 partition by c1"); +} + +TEST_F(PlanPartitionByTest, withAggFunc) { + useDb("root", "test"); + + run("select count(*) from t1 partition by c1"); +} + +TEST_F(PlanPartitionByTest, withInterval) { + useDb("root", "test"); + + // normal/child table + run("select count(*) from t1 partition by c1 interval(10s)"); + // super table + run("select count(*) from st1 partition by tag1, tag2 interval(10s)"); +} + +TEST_F(PlanPartitionByTest, withGroupBy) { + useDb("root", "test"); + + run("select count(*) from t1 partition by c1 group by c2"); +} diff --git a/source/libs/parser/test/parserTestUtil.h b/source/libs/planner/test/planSessionTest.cpp similarity index 73% rename from source/libs/parser/test/parserTestUtil.h rename to source/libs/planner/test/planSessionTest.cpp index 6db229df7fe58eac1326651150bd855c3af1155b..3ec9c4c387a2e0b21ed731e2ae2ba0d0a38e20f3 100644 --- a/source/libs/parser/test/parserTestUtil.h +++ b/source/libs/planner/test/planSessionTest.cpp @@ -13,9 +13,15 @@ * along with this program. If not, see . */ -#ifndef PARSER_TEST_UTIL_H -#define PARSER_TEST_UTIL_H +#include "planTestUtil.h" +#include "planner.h" -extern bool g_isDump; +using namespace std; -#endif // PARSER_TEST_UTIL_H +class PlanSessionTest : public PlannerTestBase {}; + +TEST_F(PlanSessionTest, basic) { + useDb("root", "test"); + + run("select count(*) from t1 session(ts, 10s)"); +} diff --git a/source/dnode/vnode/src/vnd/vnodeInt.c b/source/libs/planner/test/planStateTest.cpp similarity index 64% rename from source/dnode/vnode/src/vnd/vnodeInt.c rename to source/libs/planner/test/planStateTest.cpp index 14dfc75cedcf5ddda581214f7ecf77442aef7060..46988d67066659ea284610858ef3662d7c6d6a3b 100644 --- a/source/dnode/vnode/src/vnd/vnodeInt.c +++ b/source/libs/planner/test/planStateTest.cpp @@ -13,12 +13,21 @@ * along with this program. If not, see . */ -#define _DEFAULT_SOURCE -#include "vnd.h" -// #include "vnodeInt.h" +#include "planTestUtil.h" +#include "planner.h" -int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; } +using namespace std; -int32_t vnodeCompact(SVnode *pVnode) { return 0; } +class PlanStateTest : public PlannerTestBase {}; -int32_t vnodeSync(SVnode *pVnode) { return 0; } \ No newline at end of file +TEST_F(PlanStateTest, basic) { + useDb("root", "test"); + + run("select count(*) from t1 state_window(c1)"); +} + +TEST_F(PlanStateTest, stateExpr) { + useDb("root", "test"); + + run("select count(*) from t1 state_window(c1 + 10)"); +} diff --git a/source/libs/planner/test/planStmtTest.cpp b/source/libs/planner/test/planStmtTest.cpp index edf1990704a59e5cd08f64adc3543322e98b8102..6d56a3419e40c5d62684272aa1e54b252713f7cc 100644 --- a/source/libs/planner/test/planStmtTest.cpp +++ b/source/libs/planner/test/planStmtTest.cpp @@ -42,13 +42,13 @@ class PlanStmtTest : public PlannerTestBase { // todo } -private: + private: TAOS_MULTI_BIND* pBindParams_; - int32_t paramNo_; + int32_t paramNo_; }; TEST_F(PlanStmtTest, stmt) { useDb("root", "test"); - run("SELECT * FROM t1 where c1 = ?"); + run("select * from t1 where c1 = ?"); } diff --git a/source/libs/planner/test/planSubqueryTest.cpp b/source/libs/planner/test/planSubqueryTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..185f55db10e87d23c77425d000f91cf9b8b63ac6 --- /dev/null +++ b/source/libs/planner/test/planSubqueryTest.cpp @@ -0,0 +1,34 @@ +/* + * 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 "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanSubqeuryTest : public PlannerTestBase {}; + +TEST_F(PlanSubqeuryTest, basic) { + useDb("root", "test"); + + run("select * from (select * from t1)"); +} + +TEST_F(PlanSubqeuryTest, doubleGroupBy) { + useDb("root", "test"); + + run("select count(*) from (select c1 + c3 a, c1 + count(*) b from t1 where c2 = 'abc' group by c1, c3) where a > 100 " + "group by b"); +} diff --git a/source/libs/tdb/src/inc/tdbTxn.h b/source/libs/planner/test/planSysTbTest.cpp similarity index 65% rename from source/libs/tdb/src/inc/tdbTxn.h rename to source/libs/planner/test/planSysTbTest.cpp index ed9784614cf83850bb2f7deae8dead0b70671cc1..fff6bfcca437887b28e70d59327a6873de13730d 100644 --- a/source/libs/tdb/src/inc/tdbTxn.h +++ b/source/libs/planner/test/planSysTbTest.cpp @@ -13,19 +13,22 @@ * along with this program. If not, see . */ -#ifndef _TDB_TXN_H_ -#define _TDB_TXN_H_ +#include "planTestUtil.h" +#include "planner.h" -#ifdef __cplusplus -extern "C" { -#endif +using namespace std; -int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg, - int flags); -int tdbTxnClose(TXN *pTxn); +class PlanSysTableTest : public PlannerTestBase {}; -#ifdef __cplusplus +TEST_F(PlanSysTableTest, show) { + useDb("root", "test"); + + run("show tables"); + run("show stables"); } -#endif -#endif /*_TDB_TXN_H_*/ \ No newline at end of file +TEST_F(PlanSysTableTest, information) { + useDb("root", "information_schema"); + + run("show tables"); +} diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index c619e9b405cdd3661fc8d87df9e0e505f42cfb8b..9ddf2a4959516b58561dddcbc7c05becec7384f0 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -14,9 +14,9 @@ */ #include "planTestUtil.h" -#include #include +#include #include "cmdnodes.h" #include "parser.h" @@ -106,6 +106,7 @@ class PlannerTestBaseImpl { res_.splitLogicPlan_.clear(); res_.scaledLogicPlan_.clear(); res_.physiPlan_.clear(); + res_.physiSubplans_.clear(); } void dump() { diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp deleted file mode 100644 index 11280768237d225aaa8a51bdc1d0b7ad558060e0..0000000000000000000000000000000000000000 --- a/source/libs/planner/test/plannerTest.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include - -#include - -#include "cmdnodes.h" -#include "parser.h" -#include "planInt.h" - -using namespace std; -using namespace testing; - -class PlannerTest : public Test { - protected: - void setDatabase(const string& acctId, const string& db) { - acctId_ = acctId; - db_ = db; - } - - void bind(const char* sql) { - reset(); - cxt_.acctId = atoi(acctId_.c_str()); - cxt_.db = db_.c_str(); - sqlBuf_ = string(sql); - transform(sqlBuf_.begin(), sqlBuf_.end(), sqlBuf_.begin(), ::tolower); - cxt_.sqlLen = strlen(sql); - cxt_.pSql = sqlBuf_.c_str(); - } - - bool run(bool streamQuery = false) { - int32_t code = qParseQuerySql(&cxt_, &query_); - - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code) - << ", msg:" << errMagBuf_ << endl; - return false; - } - - const string syntaxTreeStr = toString(query_->pRoot, false); - - SLogicNode* pLogicNode = nullptr; - SPlanContext cxt = {0}; - cxt.queryId = 1; - cxt.acctId = 0; - cxt.streamQuery = streamQuery; - - setPlanContext(query_, &cxt); - code = createLogicPlan(&cxt, &pLogicNode); - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] createLogicPlan code:" << code << ", strerror:" << tstrerror(code) << endl; - return false; - } - - cout << "====================sql : [" << cxt_.pSql << "]" << endl; - cout << "syntax tree : " << endl; - cout << syntaxTreeStr << endl; - cout << "unformatted logic plan : " << endl; - cout << toString((const SNode*)pLogicNode, false) << endl; - - code = optimizeLogicPlan(&cxt, pLogicNode); - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] optimizeLogicPlan code:" << code << ", strerror:" << tstrerror(code) << endl; - return false; - } - - SLogicSubplan* pLogicSubplan = nullptr; - code = splitLogicPlan(&cxt, pLogicNode, &pLogicSubplan); - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] splitLogicPlan code:" << code << ", strerror:" << tstrerror(code) << endl; - return false; - } - - SQueryLogicPlan* pLogicPlan = NULL; - code = scaleOutLogicPlan(&cxt, pLogicSubplan, &pLogicPlan); - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] createPhysiPlan code:" << code << ", strerror:" << tstrerror(code) << endl; - return false; - } - - SArray* pExecNodeList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SQueryNodeAddr)); - code = createPhysiPlan(&cxt, pLogicPlan, &plan_, pExecNodeList); - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] createPhysiPlan code:" << code << ", strerror:" << tstrerror(code) << endl; - return false; - } - - cout << "unformatted physical plan : " << endl; - cout << toString((const SNode*)plan_, false) << endl; - SNode* pNode; - FOREACH(pNode, plan_->pSubplans) { - SNode* pSubplan; - FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { - cout << "unformatted physical subplan : " << endl; - cout << toString(pSubplan, false) << endl; - } - } - - return true; - } - - private: - static const int max_err_len = 1024; - - void setPlanContext(SQuery* pQuery, SPlanContext* pCxt) { - if (QUERY_NODE_CREATE_TOPIC_STMT == nodeType(pQuery->pRoot)) { - pCxt->pAstRoot = ((SCreateTopicStmt*)pQuery->pRoot)->pQuery; - pCxt->topicQuery = true; - } else if (QUERY_NODE_CREATE_INDEX_STMT == nodeType(pQuery->pRoot)) { - SMCreateSmaReq req = {0}; - tDeserializeSMCreateSmaReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req); - nodesStringToNode(req.ast, &pCxt->pAstRoot); - pCxt->streamQuery = true; - } else if (QUERY_NODE_CREATE_STREAM_STMT == nodeType(pQuery->pRoot)) { - SCreateStreamStmt* pStmt = (SCreateStreamStmt*)pQuery->pRoot; - pCxt->pAstRoot = pStmt->pQuery; - pCxt->streamQuery = true; - pCxt->triggerType = pStmt->pOptions->triggerType; - pCxt->watermark = (NULL != pStmt->pOptions->pWatermark ? ((SValueNode*)pStmt->pOptions->pWatermark)->datum.i : 0); - } else { - pCxt->pAstRoot = pQuery->pRoot; - } - } - - void reset() { - memset(&cxt_, 0, sizeof(cxt_)); - memset(errMagBuf_, 0, max_err_len); - cxt_.pMsg = errMagBuf_; - cxt_.msgLen = max_err_len; - } - - string toString(const SNode* pRoot, bool format = true) { - char* pStr = NULL; - int32_t len = 0; - int32_t code = nodesNodeToString(pRoot, format, &pStr, &len); - if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] toString code:" << code << ", strerror:" << tstrerror(code) << endl; - return string(); - } - string str(pStr); - taosMemoryFreeClear(pStr); - return str; - } - - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - string sqlBuf_; - SParseContext cxt_; - SQuery* query_; - SQueryPlan* plan_; -}; - -TEST_F(PlannerTest, selectBasic) { - setDatabase("root", "test"); - - bind("SELECT * FROM t1"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectConstant) { - setDatabase("root", "test"); - - bind("SELECT 2-1 FROM t1"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectStableBasic) { - setDatabase("root", "test"); - - bind("SELECT * FROM st1"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectJoin) { - setDatabase("root", "test"); - - bind("SELECT t1.c1, t2.c2 FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); - ASSERT_TRUE(run()); - - bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); - ASSERT_TRUE(run()); - - bind( - "SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and " - "t2.c2 = 'qwe'"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectGroupBy) { - setDatabase("root", "test"); - - bind("SELECT count(*) FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT c1, max(c3), min(c3), count(*) FROM t1 GROUP BY c1"); - ASSERT_TRUE(run()); - - bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3"); - ASSERT_TRUE(run()); - - bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3"); - ASSERT_TRUE(run()); - - bind("SELECT sum(ceil(c1)) FROM t1 GROUP BY ceil(c1)"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectSubquery) { - setDatabase("root", "test"); - - bind( - "SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 " - "group by b"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectInterval) { - setDatabase("root", "test"); - - bind("SELECT count(*) FROM t1 interval(10s)"); - ASSERT_TRUE(run()); - - bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); - ASSERT_TRUE(run()); - - bind("SELECT count(*) FROM t1 interval(10s) fill(linear)"); - ASSERT_TRUE(run()); - - bind("SELECT count(*), sum(c1) FROM t1 interval(10s) fill(value, 10, 20)"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectSessionWindow) { - setDatabase("root", "test"); - - bind("SELECT count(*) FROM t1 session(ts, 10s)"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectStateWindow) { - setDatabase("root", "test"); - - bind("SELECT count(*) FROM t1 state_window(c1)"); - ASSERT_TRUE(run()); - - bind("SELECT count(*) FROM t1 state_window(c1 + 10)"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectPartitionBy) { - setDatabase("root", "test"); - - bind("SELECT * FROM t1 partition by c1"); - ASSERT_TRUE(run()); - - bind("SELECT count(*) FROM t1 partition by c1"); - ASSERT_TRUE(run()); - - bind("SELECT count(*) FROM t1 partition by c1 group by c2"); - ASSERT_TRUE(run()); - - bind("SELECT count(*) FROM st1 partition by tag1, tag2 interval(10s)"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectOrderBy) { - setDatabase("root", "test"); - - bind("SELECT c1 FROM t1 order by c1"); - ASSERT_TRUE(run()); - - bind("SELECT c1 FROM t1 order by c2"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 order by c1 + 10, c2"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 order by c1 desc nulls first"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectGroupByOrderBy) { - setDatabase("root", "test"); - - bind("select count(*), sum(c1) from t1 order by sum(c1)"); - ASSERT_TRUE(run()); - - bind("select count(*), sum(c1) a from t1 order by a"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectDistinct) { - setDatabase("root", "test"); - - bind("SELECT distinct c1 FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT distinct c1, c2 + 10 FROM t1"); - ASSERT_TRUE(run()); - - bind("SELECT distinct c1 + 10 a FROM t1 order by a"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectLimit) { - setDatabase("root", "test"); - - bind("SELECT * FROM t1 limit 2"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 limit 5 offset 2"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 limit 2, 5"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, selectSlimit) { - setDatabase("root", "test"); - - bind("SELECT * FROM t1 partition by c1 slimit 2"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 partition by c1 slimit 5 soffset 2"); - ASSERT_TRUE(run()); - - bind("SELECT * FROM t1 partition by c1 slimit 2, 5"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, showTables) { - setDatabase("root", "test"); - - bind("show tables"); - ASSERT_TRUE(run()); - - setDatabase("root", "information_schema"); - - bind("show tables"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, showStables) { - setDatabase("root", "test"); - - bind("show stables"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, createTopic) { - setDatabase("root", "test"); - - bind("create topic tp as SELECT * FROM st1"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, createStream) { - setDatabase("root", "test"); - - bind( - "create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 " - "interval(10s)"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, createSmaIndex) { - setDatabase("root", "test"); - - bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)"); - ASSERT_TRUE(run()); -} - -TEST_F(PlannerTest, explain) { - setDatabase("root", "test"); - - bind("explain SELECT * FROM t1"); - ASSERT_TRUE(run()); - - bind("explain analyze SELECT * FROM t1"); - ASSERT_TRUE(run()); - - bind("explain analyze verbose true ratio 0.01 SELECT * FROM t1"); - ASSERT_TRUE(run()); -} diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index fd7c831399901a5c8d9922e011213e4267d748cd..286e7d3d44d5c1f2d406b417e3846a0414f97988 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -17,6 +17,7 @@ #include "queryInt.h" #include "query.h" #include "trpc.h" +#include "systable.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" diff --git a/source/libs/qworker/inc/qworkerInt.h b/source/libs/qworker/inc/qworkerInt.h index de73f1db0b496fa6fe865831177e150464ef916e..ca471262ff747b2466159a93571ac77120b3b9ac 100644 --- a/source/libs/qworker/inc/qworkerInt.h +++ b/source/libs/qworker/inc/qworkerInt.h @@ -20,9 +20,11 @@ extern "C" { #endif +#include "osDef.h" #include "qworker.h" #include "tlockfree.h" #include "ttimer.h" +#include "tref.h" #define QW_DEFAULT_SCHEDULER_NUMBER 10000 #define QW_DEFAULT_TASK_NUMBER 10000 @@ -85,6 +87,12 @@ typedef struct SQWMsg { SQWConnInfo connInfo; } SQWMsg; +typedef struct SQWHbParam { + bool inUse; + int32_t qwrId; + int64_t refId; +} SQWHbParam; + typedef struct SQWHbInfo { SSchedulerHbRsp rsp; SQWConnInfo connInfo; @@ -137,7 +145,8 @@ typedef struct SQWSchStatus { } SQWSchStatus; // Qnode/Vnode level task management -typedef struct SQWorkerMgmt { +typedef struct SQWorker { + int64_t refId; SQWorkerCfg cfg; int8_t nodeType; int32_t nodeId; @@ -148,9 +157,17 @@ typedef struct SQWorkerMgmt { SHashObj *schHash; // key: schedulerId, value: SQWSchStatus SHashObj *ctxHash; // key: queryId+taskId, value: SQWTaskCtx SMsgCb msgCb; +} SQWorker; + +typedef struct SQWorkerMgmt { + SRWLatch lock; + int32_t qwRef; + int32_t qwNum; + SQWHbParam param[1024]; + int32_t paramIdx; } SQWorkerMgmt; -#define QW_FPARAMS_DEF SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId +#define QW_FPARAMS_DEF SQWorker *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId #define QW_IDS() sId, qId, tId, rId #define QW_FPARAMS() mgmt, QW_IDS() @@ -209,13 +226,13 @@ typedef struct SQWorkerMgmt { } \ } while (0) -#define QW_ELOG(param, ...) qError("QW:%p " param, mgmt, __VA_ARGS__) -#define QW_DLOG(param, ...) qDebug("QW:%p " param, mgmt, __VA_ARGS__) +#define QW_ELOG(_param, ...) qError("QW:%p " _param, mgmt, __VA_ARGS__) +#define QW_DLOG(_param, ...) qDebug("QW:%p " _param, mgmt, __VA_ARGS__) -#define QW_DUMP(param, ...) \ +#define QW_DUMP(_param, ...) \ do { \ if (gQWDebug.dumpEnable) { \ - qDebug("QW:%p " param, mgmt, __VA_ARGS__); \ + qDebug("QW:%p " _param, mgmt, __VA_ARGS__); \ } \ } while (0) @@ -282,6 +299,14 @@ typedef struct SQWorkerMgmt { } \ } while (0) + +extern SQWorkerMgmt gQwMgmt; + +static FORCE_INLINE SQWorker *qwAcquire(int64_t refId) { return (SQWorker *)taosAcquireRef(atomic_load_32(&gQwMgmt.qwRef), refId); } + +static FORCE_INLINE int32_t qwRelease(int64_t refId) { return taosReleaseRef(gQwMgmt.qwRef, refId); } + + #ifdef __cplusplus } #endif diff --git a/source/libs/qworker/inc/qworkerMsg.h b/source/libs/qworker/inc/qworkerMsg.h index fb1950d16bb6dafcbf8c44537e94a33d51b58cf3..fbd9ce91bc96369ef6d21f63b0094efe05a33b93 100644 --- a/source/libs/qworker/inc/qworkerMsg.h +++ b/source/libs/qworker/inc/qworkerMsg.h @@ -28,7 +28,7 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessReady(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg); int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg); -int32_t qwProcessHb(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req); +int32_t qwProcessHb(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req); int32_t qwBuildAndSendDropRsp(SQWConnInfo *pConn, int32_t code); int32_t qwBuildAndSendCancelRsp(SQWConnInfo *pConn, int32_t code); @@ -41,10 +41,10 @@ int32_t qwBuildAndSendQueryRsp(SQWConnInfo *pConn, int32_t code); int32_t qwBuildAndSendExplainRsp(SQWConnInfo *pConn, SExplainExecInfo *execInfo, int32_t num); void qwFreeFetchRsp(void *msg); int32_t qwMallocFetchRsp(int32_t length, SRetrieveTableRsp **rsp); -int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp); +int32_t qwGetSchTasksStatus(SQWorker *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp); int32_t qwBuildAndSendHbRsp(SQWConnInfo *pConn, SSchedulerHbRsp *rsp, int32_t code); int32_t qwRegisterQueryBrokenLinkArg(QW_FPARAMS_DEF, SQWConnInfo *pConn); -int32_t qwRegisterHbBrokenLinkArg(SQWorkerMgmt *mgmt, uint64_t sId, SQWConnInfo *pConn); +int32_t qwRegisterHbBrokenLinkArg(SQWorker *mgmt, uint64_t sId, SQWConnInfo *pConn); #ifdef __cplusplus } diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index b51bc5083e826eeeda453f6a5eb2fd7de51aec84..e84f387dbea4cb24ae79248a731bdd1f54ba6b15 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -10,6 +10,11 @@ #include "tname.h" SQWDebug gQWDebug = {.statusEnable = true, .dumpEnable = true}; +SQWorkerMgmt gQwMgmt = { + .lock = 0, + .qwRef = -1, + .qwNum = 0, +}; int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore) { if (!gQWDebug.statusEnable) { @@ -98,7 +103,7 @@ _return: void qwDbgDumpSchInfo(SQWSchStatus *sch, int32_t i) {} -void qwDbgDumpMgmtInfo(SQWorkerMgmt *mgmt) { +void qwDbgDumpMgmtInfo(SQWorker *mgmt) { if (!gQWDebug.dumpEnable) { return; } @@ -186,7 +191,7 @@ int32_t qwSetTaskStatus(QW_FPARAMS_DEF, SQWTaskStatus *task, int8_t status) { return TSDB_CODE_SUCCESS; } -int32_t qwAddSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType) { +int32_t qwAddSchedulerImpl(SQWorker *mgmt, uint64_t sId, int32_t rwType) { SQWSchStatus newSch = {0}; newSch.tasksHash = taosHashInit(mgmt->cfg.maxSchTaskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); @@ -213,7 +218,7 @@ int32_t qwAddSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType) { return TSDB_CODE_SUCCESS; } -int32_t qwAcquireSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch, int32_t nOpt) { +int32_t qwAcquireSchedulerImpl(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch, int32_t nOpt) { while (true) { QW_LOCK(rwType, &mgmt->schLock); *sch = taosHashGet(mgmt->schHash, &sId, sizeof(sId)); @@ -240,15 +245,15 @@ int32_t qwAcquireSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType, return TSDB_CODE_SUCCESS; } -int32_t qwAcquireAddScheduler(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch) { +int32_t qwAcquireAddScheduler(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch) { return qwAcquireSchedulerImpl(mgmt, sId, rwType, sch, QW_NOT_EXIST_ADD); } -int32_t qwAcquireScheduler(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch) { +int32_t qwAcquireScheduler(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch) { return qwAcquireSchedulerImpl(mgmt, sId, rwType, sch, QW_NOT_EXIST_RET_ERR); } -void qwReleaseScheduler(int32_t rwType, SQWorkerMgmt *mgmt) { QW_UNLOCK(rwType, &mgmt->schLock); } +void qwReleaseScheduler(int32_t rwType, SQWorker *mgmt) { QW_UNLOCK(rwType, &mgmt->schLock); } int32_t qwAcquireTaskStatus(QW_FPARAMS_DEF, int32_t rwType, SQWSchStatus *sch, SQWTaskStatus **task) { char id[sizeof(qId) + sizeof(tId)] = {0}; @@ -384,7 +389,7 @@ int32_t qwAddTaskCtx(QW_FPARAMS_DEF) { QW_RET(qwAddTaskCtxImpl(QW_FPARAMS(), fal int32_t qwAddAcquireTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx) { return qwAddTaskCtxImpl(QW_FPARAMS(), true, ctx); } -void qwReleaseTaskCtx(SQWorkerMgmt *mgmt, void *ctx) { taosHashRelease(mgmt->ctxHash, ctx); } +void qwReleaseTaskCtx(SQWorker *mgmt, void *ctx) { taosHashRelease(mgmt->ctxHash, ctx); } void qwFreeTaskHandle(QW_FPARAMS_DEF, qTaskInfo_t *taskHandle) { // Note: free/kill may in RC @@ -606,7 +611,7 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryEnd) { QW_RET(code); } -int32_t qwGenerateSchHbRsp(SQWorkerMgmt *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo) { +int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo) { int32_t taskNum = 0; hbInfo->connInfo = sch->hbConnInfo; @@ -1262,7 +1267,7 @@ _return: QW_RET(TSDB_CODE_SUCCESS); } -int32_t qwProcessHbLinkBroken(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) { +int32_t qwProcessHbLinkBroken(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) { int32_t code = 0; SSchedulerHbRsp rsp = {0}; SQWSchStatus * sch = NULL; @@ -1288,7 +1293,7 @@ int32_t qwProcessHbLinkBroken(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq QW_RET(TSDB_CODE_SUCCESS); } -int32_t qwProcessHb(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) { +int32_t qwProcessHb(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) { int32_t code = 0; SSchedulerHbRsp rsp = {0}; SQWSchStatus * sch = NULL; @@ -1333,7 +1338,19 @@ _return: } void qwProcessHbTimerEvent(void *param, void *tmrId) { - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)param; + SQWHbParam* hbParam = (SQWHbParam*)param; + if (hbParam->qwrId != atomic_load_32(&gQwMgmt.qwRef)) { + return; + } + + int64_t refId = hbParam->refId; + SQWorker *mgmt = qwAcquire(refId); + if (NULL == mgmt) { + QW_DLOG("qwAcquire %" PRIx64 "failed", refId); + taosMemoryFree(param); + return; + } + SQWSchStatus *sch = NULL; int32_t taskNum = 0; SQWHbInfo * rspList = NULL; @@ -1347,6 +1364,7 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) { if (schNum <= 0) { QW_UNLOCK(QW_READ, &mgmt->schLock); taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); + qwRelease(refId); return; } @@ -1355,6 +1373,7 @@ void qwProcessHbTimerEvent(void *param, void *tmrId) { QW_UNLOCK(QW_READ, &mgmt->schLock); QW_ELOG("calloc %d SQWHbInfo failed", schNum); taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); + qwRelease(refId); return; } @@ -1396,6 +1415,74 @@ _return: taosMemoryFreeClear(rspList); taosTmrReset(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, param, mgmt->timer, &mgmt->hbTimer); + qwRelease(refId); +} + +void qwCloseRef(void) { + taosWLockLatch(&gQwMgmt.lock); + if (atomic_load_32(&gQwMgmt.qwNum) <= 0 && gQwMgmt.qwRef >= 0) { + taosCloseRef(gQwMgmt.qwRef); + gQwMgmt.qwRef= -1; + } + taosWUnLockLatch(&gQwMgmt.lock); +} + +void qwDestroyImpl(void *pMgmt) { + SQWorker *mgmt = (SQWorker *)pMgmt; + + taosTmrStopA(&mgmt->hbTimer); + taosTmrCleanUp(mgmt->timer); + + // TODO STOP ALL QUERY + + // TODO FREE ALL + + taosHashCleanup(mgmt->ctxHash); + taosHashCleanup(mgmt->schHash); + + taosMemoryFree(mgmt); + + atomic_sub_fetch_32(&gQwMgmt.qwNum, 1); + + qwCloseRef(); +} + +int32_t qwOpenRef(void) { + taosWLockLatch(&gQwMgmt.lock); + if (gQwMgmt.qwRef < 0) { + gQwMgmt.qwRef= taosOpenRef(100, qwDestroyImpl); + if (gQwMgmt.qwRef < 0) { + taosWUnLockLatch(&gQwMgmt.lock); + qError("init qworker ref failed"); + QW_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + } + taosWUnLockLatch(&gQwMgmt.lock); + + return TSDB_CODE_SUCCESS; +} + +void qwSetHbParam(int64_t refId, SQWHbParam **pParam) { + int32_t paramIdx = 0; + int32_t newParamIdx = 0; + + while (true) { + paramIdx = atomic_load_32(&gQwMgmt.paramIdx); + if (paramIdx == tListLen(gQwMgmt.param)) { + newParamIdx = 0; + } else { + newParamIdx = paramIdx + 1; + } + + if (paramIdx == atomic_val_compare_exchange_32(&gQwMgmt.paramIdx, paramIdx, newParamIdx)) { + break; + } + } + + gQwMgmt.param[paramIdx].qwrId = gQwMgmt.qwRef; + gQwMgmt.param[paramIdx].refId = refId; + + *pParam = &gQwMgmt.param[paramIdx]; } int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qWorkerMgmt, const SMsgCb *pMsgCb) { @@ -1404,10 +1491,21 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qW QW_RET(TSDB_CODE_QRY_INVALID_INPUT); } - int32_t code = 0; - SQWorkerMgmt *mgmt = taosMemoryCalloc(1, sizeof(SQWorkerMgmt)); + int32_t qwNum = atomic_add_fetch_32(&gQwMgmt.qwNum, 1); + if (1 == qwNum) { + memset(gQwMgmt.param, 0, sizeof(gQwMgmt.param)); + } + + int32_t code = qwOpenRef(); + if (code) { + atomic_sub_fetch_32(&gQwMgmt.qwNum, 1); + QW_RET(code); + } + + SQWorker *mgmt = taosMemoryCalloc(1, sizeof(SQWorker)); if (NULL == mgmt) { - qError("calloc %d failed", (int32_t)sizeof(SQWorkerMgmt)); + qError("calloc %d failed", (int32_t)sizeof(SQWorker)); + atomic_sub_fetch_32(&gQwMgmt.qwNum, 1); QW_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -1449,16 +1547,25 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qW QW_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - mgmt->hbTimer = taosTmrStart(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, mgmt, mgmt->timer); - if (NULL == mgmt->hbTimer) { - qError("start hb timer failed"); - QW_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - mgmt->nodeType = nodeType; mgmt->nodeId = nodeId; mgmt->msgCb = *pMsgCb; + mgmt->refId = taosAddRef(gQwMgmt.qwRef, mgmt); + if (mgmt->refId < 0) { + qError("taosAddRef qw failed, error:%s", tstrerror(terrno)); + QW_ERR_JRET(terrno); + } + + SQWHbParam *param = NULL; + qwSetHbParam(mgmt->refId, ¶m); + + mgmt->hbTimer = taosTmrStart(qwProcessHbTimerEvent, QW_DEFAULT_HEARTBEAT_MSEC, (void*)param, mgmt->timer); + if (NULL == mgmt->hbTimer) { + qError("start hb timer failed"); + QW_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + *qWorkerMgmt = mgmt; qDebug("qworker initialized for node, type:%d, id:%d, handle:%p", mgmt->nodeType, mgmt->nodeId, mgmt); @@ -1467,13 +1574,17 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qW _return: - taosHashCleanup(mgmt->schHash); - taosHashCleanup(mgmt->ctxHash); - - taosTmrCleanUp(mgmt->timer); - - taosMemoryFreeClear(mgmt); + if (mgmt->refId >= 0) { + qwRelease(mgmt->refId); + } else { + taosHashCleanup(mgmt->schHash); + taosHashCleanup(mgmt->ctxHash); + taosTmrCleanUp(mgmt->timer); + taosMemoryFreeClear(mgmt); + atomic_sub_fetch_32(&gQwMgmt.qwNum, 1); + } + QW_RET(code); } @@ -1482,22 +1593,14 @@ void qWorkerDestroy(void **qWorkerMgmt) { return; } - SQWorkerMgmt *mgmt = *qWorkerMgmt; + SQWorker *mgmt = *qWorkerMgmt; - taosTmrStopA(&mgmt->hbTimer); - taosTmrCleanUp(mgmt->timer); - - // TODO STOP ALL QUERY - - // TODO FREE ALL - - taosHashCleanup(mgmt->ctxHash); - taosHashCleanup(mgmt->schHash); - - taosMemoryFreeClear(*qWorkerMgmt); + if (taosRemoveRef(gQwMgmt.qwRef, mgmt->refId)) { + qError("remove qw from ref list failed, refId:%" PRIx64, mgmt->refId); + } } -int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp) { +int32_t qwGetSchTasksStatus(SQWorker *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp) { /* SQWSchStatus *sch = NULL; int32_t taskNum = 0; @@ -1544,7 +1647,7 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRs return TSDB_CODE_SUCCESS; } -int32_t qwUpdateSchLastAccess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId) { +int32_t qwUpdateSchLastAccess(SQWorker *mgmt, uint64_t sId, uint64_t qId, uint64_t tId) { SQWSchStatus *sch = NULL; /* @@ -1557,7 +1660,7 @@ int32_t qwUpdateSchLastAccess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, ui return TSDB_CODE_SUCCESS; } -int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int8_t *taskStatus) { +int32_t qwGetTaskStatus(SQWorker *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int8_t *taskStatus) { SQWSchStatus * sch = NULL; SQWTaskStatus *task = NULL; int32_t code = 0; @@ -1584,7 +1687,7 @@ int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t QW_RET(code); } -int32_t qwCancelTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t tId) { +int32_t qwCancelTask(SQWorker *mgmt, uint64_t sId, uint64_t qId, uint64_t tId) { SQWSchStatus * sch = NULL; SQWTaskStatus *task = NULL; int32_t code = 0; diff --git a/source/libs/qworker/src/qworkerMsg.c b/source/libs/qworker/src/qworkerMsg.c index 64df4f02bf7e826589f8b2b3d61f9972328dacd4..d4f6c2fd004f33018a74f9dd6ea779c5d7cfea8c 100644 --- a/source/libs/qworker/src/qworkerMsg.c +++ b/source/libs/qworker/src/qworkerMsg.c @@ -34,6 +34,7 @@ void qwBuildFetchRsp(void *msg, SOutputData *input, int32_t len, bool qComplete) rsp->compressed = input->compressed; rsp->compLen = htonl(len); rsp->numOfRows = htonl(input->numOfRows); + rsp->numOfCols = htonl(input->numOfCols); } void qwFreeFetchRsp(void *msg) { @@ -319,7 +320,7 @@ int32_t qwRegisterQueryBrokenLinkArg(QW_FPARAMS_DEF, SQWConnInfo *pConn) { return TSDB_CODE_SUCCESS; } -int32_t qwRegisterHbBrokenLinkArg(SQWorkerMgmt *mgmt, uint64_t sId, SQWConnInfo *pConn) { +int32_t qwRegisterHbBrokenLinkArg(SQWorker *mgmt, uint64_t sId, SQWConnInfo *pConn) { SSchedulerHbReq req = {0}; req.header.vgId = mgmt->nodeId; req.sId = sId; @@ -362,7 +363,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { int32_t code = 0; SSubQueryMsg *msg = pMsg->pCont; - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; if (NULL == msg || pMsg->contLen <= sizeof(*msg)) { QW_ELOG("invalid query msg, msg:%p, msgLen:%d", msg, pMsg->contLen); @@ -404,7 +405,7 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { SQueryContinueReq *msg = (SQueryContinueReq *)pMsg->pCont; bool needStop = false; SQWTaskCtx *handles = NULL; - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; if (NULL == msg || pMsg->contLen < sizeof(*msg)) { QW_ELOG("invalid cquery msg, msg:%p, msgLen:%d", msg, pMsg->contLen); @@ -435,7 +436,7 @@ int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; } - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; SResReadyReq *msg = pMsg->pCont; if (NULL == msg || pMsg->contLen < sizeof(*msg)) { QW_ELOG("invalid task ready msg, msg:%p, msgLen:%d", msg, pMsg->contLen); @@ -477,7 +478,7 @@ int32_t qWorkerProcessStatusMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; msg->sId = htobe64(msg->sId); uint64_t sId = msg->sId; @@ -498,7 +499,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { } SResFetchReq *msg = pMsg->pCont; - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; if (NULL == msg || pMsg->contLen < sizeof(*msg)) { QW_ELOG("invalid fetch msg, msg:%p, msgLen:%d", msg, pMsg->contLen); @@ -538,7 +539,7 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; } - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; int32_t code = 0; STaskCancelReq *msg = pMsg->pCont; if (NULL == msg || pMsg->contLen < sizeof(*msg)) { @@ -578,7 +579,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { int32_t code = 0; STaskDropReq *msg = pMsg->pCont; - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; if (NULL == msg || pMsg->contLen < sizeof(*msg)) { QW_ELOG("invalid task drop msg, msg:%p, msgLen:%d", msg, pMsg->contLen); @@ -620,7 +621,7 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { int32_t code = 0; SSchedulerHbReq req = {0}; - SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt; + SQWorker *mgmt = (SQWorker *)qWorkerMgmt; if (NULL == pMsg->pCont) { QW_ELOG("invalid hb msg, msg:%p, msgLen:%d", pMsg->pCont, pMsg->contLen); diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 021e0e0f96545085973d49853006bcbe1e362f8d..659d7dcf7e3b3a33d5b741e184da80f7c953c5ec 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -34,7 +34,7 @@ typedef struct SScalarCtx { #define SCL_IS_CONST_NODE(_node) ((NULL == (_node)) || (QUERY_NODE_VALUE == (_node)->type) || (QUERY_NODE_NODE_LIST == (_node)->type)) #define SCL_IS_CONST_CALC(_ctx) (NULL == (_ctx)->pBlockList) -#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type)) +#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type) && (((SValueNode *)_node)->placeholderNo <= 0)) #define sclFatal(...) qFatal(__VA_ARGS__) #define sclError(...) qError(__VA_ARGS__) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 5522bfc6a3d0c133e0a17c3ca1d5507fced5548e..80e5669cc2b5891f1c73d158097d2b4429117f98 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3541,11 +3541,16 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { } if (QUERY_NODE_VALUE == nodeType(*pNode)) { + SValueNode *valueNode = (SValueNode *)*pNode; + if (valueNode->placeholderNo >= 1) { + stat->scalarMode = true; + return DEAL_RES_CONTINUE; + } + if (!FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP)) { return DEAL_RES_CONTINUE; } - SValueNode *valueNode = (SValueNode *)*pNode; if (TSDB_DATA_TYPE_BINARY != valueNode->node.resType.type && TSDB_DATA_TYPE_NCHAR != valueNode->node.resType.type) { return DEAL_RES_CONTINUE; } @@ -3587,7 +3592,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL) { + if (node->opType == OP_TYPE_NOT_IN || node->opType == OP_TYPE_NOT_LIKE || node->opType > OP_TYPE_IS_NOT_NULL || node->opType == OP_TYPE_NOT_EQUAL) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } @@ -3760,6 +3765,7 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) FLT_ERR_JRET(fltReviseNodes(info, &pNode, &stat)); info->scalarMode = stat.scalarMode; + fltDebug("scalar mode: %d", info->scalarMode); if (!info->scalarMode) { FLT_ERR_JRET(fltInitFromNode(pNode, info, options)); diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 34b0cf730dd5d80d2a74f97d96710833e00770ec..f5fab814ffdcb8b585e0171e0880944eda5e2557 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -7,6 +7,7 @@ #include "tcommon.h" #include "tdatablock.h" #include "scalar.h" +#include "tudf.h" int32_t scalarGetOperatorParamNum(EOperatorType type) { if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || OP_TYPE_IS_NOT_TRUE == type @@ -74,7 +75,15 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { if (valueNode->node.resType.type != type) { out.columnData->info.type = type; - out.columnData->info.bytes = tDataTypes[type].bytes; + if (IS_VAR_DATA_TYPE(type)) { + if (IS_VAR_DATA_TYPE(valueNode->node.resType.type)) { + out.columnData->info.bytes = valueNode->node.resType.bytes * TSDB_NCHAR_SIZE; + } else { + out.columnData->info.bytes = 64 * TSDB_NCHAR_SIZE; + } + } else { + out.columnData->info.bytes = tDataTypes[type].bytes; + } code = doConvertDataType(valueNode, &out); if (code != TSDB_CODE_SUCCESS) { @@ -336,14 +345,12 @@ int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outp SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, ¶mNum, &rowNum)); if (fmIsUserDefinedFunc(node->funcId)) { -#if 0 UdfcFuncHandle udfHandle = NULL; SCL_ERR_JRET(setupUdf(node->functionName, &udfHandle)); code = callUdfScalarFunc(udfHandle, params, paramNum, output); teardownUdf(udfHandle); SCL_ERR_JRET(code); -#endif } else { SScalarFuncExecFuncs ffpSet = {0}; code = fmGetScalarFuncExecFuncs(node->funcId, &ffpSet); @@ -505,6 +512,7 @@ EDealRes sclRewriteBasedOnOptr(SNode** pNode, SScalarCtx *ctx, EOperatorType opT } res->node.resType.type = TSDB_DATA_TYPE_BOOL; + res->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; res->datum.b = false; nodesDestroyNode(*pNode); @@ -520,14 +528,14 @@ EDealRes sclRewriteOperatorForNullValue(SNode** pNode, SScalarCtx *ctx) { if (node->pLeft && (QUERY_NODE_VALUE == nodeType(node->pLeft))) { SValueNode *valueNode = (SValueNode *)node->pLeft; - if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { + if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { return sclRewriteBasedOnOptr(pNode, ctx, node->opType); } } if (node->pRight && (QUERY_NODE_VALUE == nodeType(node->pRight))) { SValueNode *valueNode = (SValueNode *)node->pRight; - if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { + if (SCL_IS_NULL_VALUE_NODE(valueNode) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { return sclRewriteBasedOnOptr(pNode, ctx, node->opType); } } @@ -589,13 +597,16 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { if (colDataIsNull_s(output.columnData, 0)) { res->node.resType.type = TSDB_DATA_TYPE_NULL; } else { - res->node.resType = node->node.resType; + res->node.resType.type = output.columnData->info.type; + res->node.resType.bytes = output.columnData->info.bytes; + res->node.resType.scale = output.columnData->info.scale; + res->node.resType.precision = output.columnData->info.precision; int32_t type = output.columnData->info.type; if (IS_VAR_DATA_TYPE(type)) { res->datum.p = taosMemoryCalloc(res->node.resType.bytes + VARSTR_HEADER_SIZE + 1, 1); memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData)); } else { - memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); + nodesSetValueNodeValue(res, output.columnData->pData); } } @@ -635,7 +646,7 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { res->datum.p = output.columnData->pData; output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); + nodesSetValueNodeValue(res, output.columnData->pData); } nodesDestroyNode(*pNode); @@ -677,7 +688,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { res->datum.p = output.columnData->pData; output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); + nodesSetValueNodeValue(res, output.columnData->pData); } } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 28514c360575a76cd5691d768b67c6da98692f89..a507b4134211548b303d4db3167ef6da52ce62ab 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -15,7 +15,15 @@ typedef int16_t (*_len_fn)(char *, int32_t); /** Math functions **/ static double tlog(double v, double base) { - return log(v) / log(base); + double a = log(v); + double b = log(base); + if (isnan(a) || isinf(a)) { + return a; + } else if (isnan(b) || isinf(b)) { + return b; + } else { + return a / b; + } } int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { @@ -133,7 +141,12 @@ static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SS colDataAppendNULL(pOutputData, i); continue; } - out[i] = valFn(getValueFn(pInputData->pData, i)); + double result = valFn(getValueFn(pInputData->pData, i)); + if (isinf(result) || isnan(result)) { + colDataAppendNULL(pOutputData, i); + } else { + out[i] = result; + } } pOutput->numOfRows = pInput->numOfRows; @@ -155,17 +168,64 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S } double *out = (double *)pOutputData->pData; + double result; + + int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows); + if (pInput[0].numOfRows == pInput[1].numOfRows) { + for (int32_t i = 0; i < numOfRows; ++i) { + if (colDataIsNull_s(pInputData[0], i) || + colDataIsNull_s(pInputData[1], i)) { + colDataAppendNULL(pOutputData, i); + continue; + } + result = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, i)); + if (isinf(result) || isnan(result)) { + colDataAppendNULL(pOutputData, i); + } else { + out[i] = result; + } + } + } else if (pInput[0].numOfRows == 1) { //left operand is constant + if (colDataIsNull_s(pInputData[0], 0)) { + colDataAppendNNULL(pOutputData, 0, pInput[1].numOfRows); + } else { + for (int32_t i = 0; i < numOfRows; ++i) { + if (colDataIsNull_s(pInputData[1], i)) { + colDataAppendNULL(pOutputData, i); + continue; + } - for (int32_t i = 0; i < pInput->numOfRows; ++i) { - if (colDataIsNull_s(pInputData[0], i) || - colDataIsNull_s(pInputData[1], 0)) { - colDataAppendNULL(pOutputData, i); - continue; + result = valFn(getValueFn[0](pInputData[0]->pData, 0), getValueFn[1](pInputData[1]->pData, i)); + if (isinf(result) || isnan(result)) { + colDataAppendNULL(pOutputData, i); + continue; + } + + out[i] = result; + } + } + } else if (pInput[1].numOfRows == 1) { + if (colDataIsNull_s(pInputData[1], 0)) { + colDataAppendNNULL(pOutputData, 0, pInput[0].numOfRows); + } else { + for (int32_t i = 0; i < numOfRows; ++i) { + if (colDataIsNull_s(pInputData[0], i)) { + colDataAppendNULL(pOutputData, i); + continue; + } + + result = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, 0)); + if (isinf(result) || isnan(result)) { + colDataAppendNULL(pOutputData, i); + continue; + } + + out[i] = result; + } } - out[i] = valFn(getValueFn[0](pInputData[0]->pData, i), getValueFn[1](pInputData[1]->pData, 0)); } - pOutput->numOfRows = pInput->numOfRows; + pOutput->numOfRows = numOfRows; return TSDB_CODE_SUCCESS; } @@ -297,7 +357,8 @@ static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarP SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - int16_t *out = (int16_t *)pOutputData->pData; + ASSERT(pOutputData->info.type == TSDB_DATA_TYPE_BIGINT); + int64_t *out = (int64_t *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { @@ -648,11 +709,6 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp int16_t outputType = GET_PARAM_TYPE(&pOutput[0]); int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]); - if (IS_VAR_DATA_TYPE(outputType)) { - int32_t factor = (TSDB_DATA_TYPE_NCHAR == outputType) ? TSDB_NCHAR_SIZE : 1; - outputLen = outputLen * factor + VARSTR_HEADER_SIZE; - } - char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows, 1); char *output = outputBuf; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 4fcebedc98d64c58de4ce2aea659806a4668b4d9..a75b2521bdded3737b11a6fc931762fef8cb4cb8 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1058,36 +1058,36 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); double *output = (double *)pOutputCol->pData; - if (pLeft->numOfRows == pRight->numOfRows) { // check for the 0 value + if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i) || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { //divide by 0 check colDataAppendNULL(pOutputCol, i); - continue; // TODO set null or ignore + continue; } *output = getVectorDoubleValueFnLeft(LEFT_COL, i) - /getVectorDoubleValueFnRight(RIGHT_COL, i); + / getVectorDoubleValueFnRight(RIGHT_COL, i); } } else if (pLeft->numOfRows == 1) { if (colDataIsNull_s(pLeftCol, 0)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows); } else { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { - if (colDataIsNull_s(pRightCol, i)) { + if (colDataIsNull_s(pRightCol, i) || (getVectorDoubleValueFnRight(RIGHT_COL, i) == 0)) { // divide by 0 check colDataAppendNULL(pOutputCol, i); - continue; // TODO set null or ignore + continue; } *output = getVectorDoubleValueFnLeft(LEFT_COL, 0) / getVectorDoubleValueFnRight(RIGHT_COL, i); } } } else if (pRight->numOfRows == 1) { - if (colDataIsNull_s(pRightCol, 0)) { // Set pLeft->numOfRows NULL value + if (colDataIsNull_s(pRightCol, 0) || (getVectorDoubleValueFnRight(RIGHT_COL, 0) == 0)) { // Set pLeft->numOfRows NULL value (divde by 0 check) colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows); } else { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { if (colDataIsNull_s(pLeftCol, i)) { colDataAppendNULL(pOutputCol, i); - continue; // TODO set null or ignore + continue; } *output = getVectorDoubleValueFnLeft(LEFT_COL, i) / getVectorDoubleValueFnRight(RIGHT_COL, 0); @@ -1195,9 +1195,10 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO for (; i < pLeft->numOfRows && i >= 0; i += step, output += 1) { if (colDataIsNull_s(pLeft->columnData, i)) { colDataAppendNULL(pOutputCol, i); - continue; // TODO set null or ignore + continue; } - *output = - getVectorDoubleValueFnLeft(LEFT_COL, i); + double result = getVectorDoubleValueFnLeft(LEFT_COL, i); + *output = (result == 0) ? 0 : -result; } doReleaseVec(pLeftCol, leftConvert); diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index 0f6961018ce4cbbba9e4129bed2e42a8e3e0d64e..5906ee8970f7725fb10139522eab3d276ef3f7f0 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -85,7 +85,10 @@ typedef struct SSchedulerMgmt { uint64_t taskId; // sequential taksId uint64_t sId; // schedulerId SSchedulerCfg cfg; + SRWLatch lock; + bool exit; int32_t jobRef; + int32_t jobNum; SSchedulerStat stat; SHashObj *hbConnections; } SSchedulerMgmt; diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 31d2da93802e18ed00306b909daba44665cc622e..a70d366e9b41e41e84b6a42e2c0a5311c3de6512 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -21,7 +21,9 @@ #include "tref.h" #include "trpc.h" -SSchedulerMgmt schMgmt = {0}; +SSchedulerMgmt schMgmt = { + .jobRef = -1, +}; FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) { return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId); } @@ -70,6 +72,7 @@ int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel * int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *transport, SArray *pNodeList, const char *sql, int64_t startTs, bool syncSchedule) { int32_t code = 0; + int64_t refId = -1; SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob)); if (NULL == pJob) { qError("QID:%" PRIx64 " calloc %d failed", pDag->queryId, (int32_t)sizeof(SSchJob)); @@ -114,15 +117,17 @@ int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *transport, SArray tsem_init(&pJob->rspSem, 0, 0); - int64_t refId = taosAddRef(schMgmt.jobRef, pJob); + refId = taosAddRef(schMgmt.jobRef, pJob); if (refId < 0) { SCH_JOB_ELOG("taosAddRef job failed, error:%s", tstrerror(terrno)); SCH_ERR_JRET(terrno); } + atomic_add_fetch_32(&schMgmt.jobNum, 1); + if (NULL == schAcquireJob(refId)) { SCH_JOB_ELOG("schAcquireJob job failed, refId:%" PRIx64, refId); - SCH_RET(TSDB_CODE_SCH_STATUS_ERROR); + SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR); } pJob->refId = refId; @@ -137,7 +142,11 @@ int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *transport, SArray _return: - schFreeJobImpl(pJob); + if (refId < 0) { + schFreeJobImpl(pJob); + } else { + taosRemoveRef(schMgmt.jobRef, refId); + } SCH_RET(code); } @@ -245,6 +254,7 @@ int32_t schValidateTaskReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t m SCH_SET_TASK_LASTMSG_TYPE(pTask, -1); return TSDB_CODE_SUCCESS; case TDMT_VND_CREATE_TABLE_RSP: + case TDMT_VND_DROP_TABLE_RSP: case TDMT_VND_SUBMIT_RSP: break; default: @@ -369,7 +379,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { } for (int32_t n = 0; n < childNum; ++n) { - SSubplan * child = (SSubplan *)nodesListGetNode(pPlan->pChildren, n); + SSubplan *child = (SSubplan *)nodesListGetNode(pPlan->pChildren, n); SSchTask **childTask = taosHashGet(planToTask, &child, POINTER_BYTES); if (NULL == childTask || NULL == *childTask) { SCH_TASK_ELOG("subplan children relationship error, level:%d, taskIdx:%d, childIdx:%d", i, m, n); @@ -401,7 +411,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { } for (int32_t n = 0; n < parentNum; ++n) { - SSubplan * parent = (SSubplan *)nodesListGetNode(pPlan->pParents, n); + SSubplan *parent = (SSubplan *)nodesListGetNode(pPlan->pParents, n); SSchTask **parentTask = taosHashGet(planToTask, &parent, POINTER_BYTES); if (NULL == parentTask || NULL == *parentTask) { SCH_TASK_ELOG("subplan parent relationship error, level:%d, taskIdx:%d, childIdx:%d", i, m, n); @@ -491,7 +501,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { SSchLevel level = {0}; SNodeListNode *plans = NULL; int32_t taskNum = 0; - SSchLevel * pLevel = NULL; + SSchLevel *pLevel = NULL; level.status = JOB_TASK_STATUS_NOT_START; @@ -1094,6 +1104,30 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; } + case TDMT_VND_DROP_TABLE_RSP: { + SVDropTbBatchRsp batchRsp = {0}; + if (msg) { + SCoder coder = {0}; + tCoderInit(&coder, TD_LITTLE_ENDIAN, msg, msgSize, TD_DECODER); + code = tDecodeSVDropTbBatchRsp(&coder, &batchRsp); + if (TSDB_CODE_SUCCESS == code && batchRsp.pArray) { + int32_t num = taosArrayGetSize(batchRsp.pArray); + for (int32_t i = 0; i < num; ++i) { + SVDropTbRsp *rsp = taosArrayGet(batchRsp.pArray, i); + if (NEED_CLIENT_HANDLE_ERROR(rsp->code)) { + tCoderClear(&coder); + SCH_ERR_JRET(rsp->code); + } + } + } + tCoderClear(&coder); + SCH_ERR_JRET(code); + } + + SCH_ERR_JRET(rspCode); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); + break; + } case TDMT_VND_SUBMIT_RSP: { if (msg) { SSubmitRsp *rsp = (SSubmitRsp *)msg; @@ -1267,7 +1301,7 @@ int32_t schUpdateTaskExecNodeHandle(SSchTask *pTask, void *handle, int32_t rspCo int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, int32_t rspCode) { int32_t code = 0; SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; - SSchTask * pTask = NULL; + SSchTask *pTask = NULL; SSchJob *pJob = schAcquireJob(pParam->refId); if (NULL == pJob) { @@ -1316,6 +1350,10 @@ int32_t schHandleCreateTableCallback(void *param, const SDataBuf *pMsg, int32_t return schHandleCallback(param, pMsg, TDMT_VND_CREATE_TABLE_RSP, code); } +int32_t schHandleDropTableCallback(void *param, const SDataBuf *pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_DROP_TABLE_RSP, code); +} + int32_t schHandleQueryCallback(void *param, const SDataBuf *pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code); } @@ -1412,6 +1450,9 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { case TDMT_VND_CREATE_TABLE: *fp = schHandleCreateTableCallback; break; + case TDMT_VND_DROP_TABLE: + *fp = schHandleDropTableCallback; + break; case TDMT_VND_SUBMIT: *fp = schHandleSubmitCallback; break; @@ -1617,8 +1658,8 @@ _return: int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { int32_t code = 0; SSchHbCallbackParam *param = NULL; - SMsgSendInfo * pMsgSendInfo = NULL; - SQueryNodeAddr * addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); + SMsgSendInfo *pMsgSendInfo = NULL; + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); SQueryNodeEpId epId = {0}; epId.nodeId = addr->nodeId; @@ -1759,10 +1800,10 @@ int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) { } SRpcCtxVal dst = {0}; - void * pIter = taosHashIterate(pSrc->args, NULL); + void *pIter = taosHashIterate(pSrc->args, NULL); while (pIter) { SRpcCtxVal *pVal = (SRpcCtxVal *)pIter; - int32_t * msgType = taosHashGetKey(pIter, NULL); + int32_t *msgType = taosHashGetKey(pIter, NULL); dst = *pVal; dst.val = NULL; @@ -1916,7 +1957,7 @@ _return: int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t msgType) { uint32_t msgSize = 0; - void * msg = NULL; + void *msg = NULL; int32_t code = 0; bool isCandidateAddr = false; bool persistHandle = false; @@ -1931,6 +1972,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, switch (msgType) { case TDMT_VND_CREATE_TABLE: + case TDMT_VND_DROP_TABLE: case TDMT_VND_SUBMIT: { msgSize = pTask->msgLen; msg = taosMemoryCalloc(1, msgSize); @@ -2239,6 +2281,19 @@ int32_t schCancelJob(SSchJob *pJob) { // TODO MOVE ALL TASKS FROM EXEC LIST TO FAIL LIST } +void schCloseJobRef(void) { + if (!atomic_load_8((int8_t*)&schMgmt.exit)) { + return; + } + + SCH_LOCK(SCH_WRITE, &schMgmt.lock); + if (atomic_load_32(&schMgmt.jobNum) <= 0 && schMgmt.jobRef >= 0) { + taosCloseRef(schMgmt.jobRef); + schMgmt.jobRef = -1; + } + SCH_UNLOCK(SCH_WRITE, &schMgmt.lock); +} + void schFreeJobImpl(void *job) { if (NULL == job) { return; @@ -2284,6 +2339,10 @@ void schFreeJobImpl(void *job) { taosMemoryFreeClear(pJob); qDebug("QID:0x%" PRIx64 " job freed, refId:%" PRIx64 ", pointer:%p", queryId, refId, pJob); + + atomic_sub_fetch_32(&schMgmt.jobNum, 1); + + schCloseJobRef(); } static int32_t schExecJobImpl(void *transport, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql, @@ -2368,7 +2427,7 @@ _return: } int32_t schedulerInit(SSchedulerCfg *cfg) { - if (schMgmt.jobRef) { + if (schMgmt.jobRef >= 0) { qError("scheduler already initialized"); return TSDB_CODE_QRY_INVALID_INPUT; } @@ -2673,7 +2732,7 @@ int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub) { SSchLevel *pLevel = taosArrayGet(pJob->levels, i); for (int32_t m = 0; m < pLevel->taskNum; ++m) { - SSchTask * pTask = taosArrayGet(pLevel->subTasks, m); + SSchTask *pTask = taosArrayGet(pLevel->subTasks, m); SQuerySubDesc subDesc = {.tid = pTask->taskId, .status = pTask->status}; taosArrayPush(pSub, &subDesc); @@ -2732,7 +2791,9 @@ void schedulerFreeTaskList(SArray *taskList) { } void schedulerDestroy(void) { - if (schMgmt.jobRef) { + atomic_store_8((int8_t*)&schMgmt.exit, 1); + + if (schMgmt.jobRef >= 0) { SSchJob *pJob = taosIterateRef(schMgmt.jobRef, 0); int64_t refId = 0; @@ -2745,9 +2806,6 @@ void schedulerDestroy(void) { pJob = taosIterateRef(schMgmt.jobRef, refId); } - - taosCloseRef(schMgmt.jobRef); - schMgmt.jobRef = 0; } if (schMgmt.hbConnections) { diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 8aaaa414ca265f31f09f26f877b2ec3dea7ce5b3..cf3cd162aa1b365704e02377f9731b1420a8d950 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -28,6 +28,7 @@ static int32_t streamBuildDispatchMsg(SStreamTask* pTask, SArray* data, SRpcMsg* if (buf == NULL) { return -1; } + if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { ((SMsgHead*)buf)->vgId = 0; req.taskId = pTask->inplaceDispatcher.taskId; @@ -158,8 +159,6 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in // } else if (pTask->sinkType == TASK_SINK__FETCH) { // - } else if (pTask->sinkType == TASK_SINK__SHOW) { - blockDebugShowData(pRes); } else { ASSERT(pTask->sinkType == TASK_SINK__NONE); } @@ -280,8 +279,6 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI64(pEncoder, pTask->smaSink.smaId) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__FETCH) { if (tEncodeI8(pEncoder, pTask->fetchSink.reserved) < 0) return -1; - } else if (pTask->sinkType == TASK_SINK__SHOW) { - if (tEncodeI8(pEncoder, pTask->showSink.reserved) < 0) return -1; } else { ASSERT(pTask->sinkType == TASK_SINK__NONE); } @@ -326,8 +323,6 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { if (tDecodeI64(pDecoder, &pTask->smaSink.smaId) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__FETCH) { if (tDecodeI8(pDecoder, &pTask->fetchSink.reserved) < 0) return -1; - } else if (pTask->sinkType == TASK_SINK__SHOW) { - if (tDecodeI8(pDecoder, &pTask->showSink.reserved) < 0) return -1; } else { ASSERT(pTask->sinkType == TASK_SINK__NONE); } diff --git a/source/libs/stream/src/tstreamUpdate.c b/source/libs/stream/src/tstreamUpdate.c new file mode 100644 index 0000000000000000000000000000000000000000..850a17b6dd465565fb92ce8a02292d37aea5165e --- /dev/null +++ b/source/libs/stream/src/tstreamUpdate.c @@ -0,0 +1,180 @@ +/* + * 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 "tstreamUpdate.h" +#include "ttime.h" + +#define DEFAULT_FALSE_POSITIVE 0.01 +#define DEFAULT_BUCKET_SIZE 1024 +#define ROWS_PER_MILLISECOND 1 +#define MAX_NUM_SCALABLE_BF 120 +#define MIN_NUM_SCALABLE_BF 10 +#define DEFAULT_PREADD_BUCKET 1 +#define MAX_INTERVAL MILLISECOND_PER_MINUTE +#define MIN_INTERVAL (MILLISECOND_PER_SECOND * 10) + +static void windowSBfAdd(SUpdateInfo *pInfo, uint64_t count) { + if (pInfo->numSBFs < count ) { + count = pInfo->numSBFs; + } + for (uint64_t i = 0; i < count; ++i) { + SScalableBf *tsSBF = tScalableBfInit(pInfo->interval * ROWS_PER_MILLISECOND, + DEFAULT_FALSE_POSITIVE); + taosArrayPush(pInfo->pTsSBFs, &tsSBF); + } +} + +static void windowSBfDelete(SUpdateInfo *pInfo, uint64_t count) { + if (count < pInfo->numSBFs - 1) { + for (uint64_t i = 0; i < count; ++i) { + SScalableBf *pTsSBFs = taosArrayGetP(pInfo->pTsSBFs, i); + tScalableBfDestroy(pTsSBFs); + taosArrayRemove(pInfo->pTsSBFs, i); + } + } else { + taosArrayClearP(pInfo->pTsSBFs, (FDelete)tScalableBfDestroy); + } + pInfo->minTS += pInfo->interval * count; +} + +static int64_t adjustInterval(int64_t interval, int32_t precision) { + int64_t val = interval; + if (precision != TSDB_TIME_PRECISION_MILLI) { + val = convertTimePrecision(interval, precision, TSDB_TIME_PRECISION_MILLI); + } + + if (val <= 0 || val > MAX_INTERVAL) { + val = MAX_INTERVAL; + } else if (val < MIN_INTERVAL) { + val = MIN_INTERVAL; + } + + if (precision != TSDB_TIME_PRECISION_MILLI) { + val = convertTimePrecision(val, TSDB_TIME_PRECISION_MILLI, precision); + } + return val; +} + +static int64_t adjustWatermark(int64_t interval, int32_t watermark) { + if (watermark <= 0 || watermark > MAX_NUM_SCALABLE_BF * interval) { + watermark = MAX_NUM_SCALABLE_BF * interval; + } else if (watermark < MIN_NUM_SCALABLE_BF * interval) { + watermark = MIN_NUM_SCALABLE_BF * interval; + } + return watermark; +} + +SUpdateInfo *updateInfoInitP(SInterval* pInterval, int64_t watermark) { + return updateInfoInit(pInterval->interval, pInterval->precision, watermark); +} + +SUpdateInfo *updateInfoInit(int64_t interval, int32_t precision, int64_t watermark) { + SUpdateInfo *pInfo = taosMemoryCalloc(1, sizeof(SUpdateInfo)); + if (pInfo == NULL) { + return NULL; + } + pInfo->pTsBuckets = NULL; + pInfo->pTsSBFs = NULL; + pInfo->minTS = -1; + pInfo->interval = adjustInterval(interval, precision); + pInfo->watermark = adjustWatermark(pInfo->interval, watermark); + + uint64_t bfSize = (uint64_t)(pInfo->watermark / pInfo->interval); + + pInfo->pTsSBFs = taosArrayInit(bfSize, sizeof(SScalableBf)); + if (pInfo->pTsSBFs == NULL) { + updateInfoDestroy(pInfo); + return NULL; + } + pInfo->numSBFs = bfSize; + windowSBfAdd(pInfo, bfSize); + + pInfo->pTsBuckets = taosArrayInit(DEFAULT_BUCKET_SIZE, sizeof(TSKEY)); + if (pInfo->pTsBuckets == NULL) { + updateInfoDestroy(pInfo); + return NULL; + } + + TSKEY dumy = 0; + for(uint64_t i=0; i < DEFAULT_BUCKET_SIZE; ++i) { + taosArrayPush(pInfo->pTsBuckets, &dumy); + } + pInfo->numBuckets = DEFAULT_BUCKET_SIZE; + return pInfo; +} + +static SScalableBf* getSBf(SUpdateInfo *pInfo, TSKEY ts) { + if (ts <= 0) { + return NULL; + } + if (pInfo->minTS < 0) { + pInfo->minTS = (TSKEY)(ts / pInfo->interval * pInfo->interval); + } + uint64_t index = (uint64_t)((ts - pInfo->minTS) / pInfo->interval); + if (index >= pInfo->numSBFs) { + uint64_t count = index + 1 - pInfo->numSBFs; + windowSBfDelete(pInfo, count); + windowSBfAdd(pInfo, count); + index = pInfo->numSBFs - 1; + } + SScalableBf *res = taosArrayGetP(pInfo->pTsSBFs, index); + if (res == NULL) { + res = tScalableBfInit(pInfo->interval * ROWS_PER_MILLISECOND, + DEFAULT_FALSE_POSITIVE); + taosArrayPush(pInfo->pTsSBFs, &res); + } + return res; +} + +bool isUpdated(SUpdateInfo *pInfo, tb_uid_t tableId, TSKEY ts) { + int32_t res = TSDB_CODE_FAILED; + uint64_t index = ((uint64_t)tableId) % pInfo->numBuckets; + SScalableBf* pSBf = getSBf(pInfo, ts); + // pSBf may be a null pointer + if (pSBf) { + res = tScalableBfPut(pSBf, &ts, sizeof(TSKEY)); + } + + TSKEY maxTs = *(TSKEY *)taosArrayGet(pInfo->pTsBuckets, index); + if (maxTs < ts ) { + taosArraySet(pInfo->pTsBuckets, index, &ts); + return false; + } + + if (ts < pInfo->minTS) { + return true; + } else if (res == TSDB_CODE_SUCCESS) { + return false; + } + + //check from tsdb api + return true; +} + +void updateInfoDestroy(SUpdateInfo *pInfo) { + if (pInfo == NULL) { + return; + } + taosArrayDestroy(pInfo->pTsBuckets); + + uint64_t size = taosArrayGetSize(pInfo->pTsSBFs); + for (uint64_t i = 0; i < size; i++) { + SScalableBf *pSBF = taosArrayGetP(pInfo->pTsSBFs, i); + tScalableBfDestroy(pSBF); + } + + taosArrayDestroy(pInfo->pTsSBFs); + taosMemoryFree(pInfo); +} \ No newline at end of file diff --git a/source/libs/stream/test/CMakeLists.txt b/source/libs/stream/test/CMakeLists.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..96209f681259da0ac8369a30327dcb868729b177 100644 --- a/source/libs/stream/test/CMakeLists.txt +++ b/source/libs/stream/test/CMakeLists.txt @@ -0,0 +1,20 @@ + +MESSAGE(STATUS "build stream unit test") + +# GoogleTest requires at least C++11 +SET(CMAKE_CXX_STANDARD 11) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + +# bloomFilterTest +ADD_EXECUTABLE(streamUpdateTest "tstreamUpdateTest.cpp") + +TARGET_LINK_LIBRARIES( + streamUpdateTest + PUBLIC os util common gtest stream +) + +TARGET_INCLUDE_DIRECTORIES( + streamUpdateTest + PUBLIC "${TD_SOURCE_DIR}/include/libs/stream/" + PRIVATE "${TD_SOURCE_DIR}/source/libs/stream/inc" +) \ No newline at end of file diff --git a/source/libs/stream/test/tstreamUpdateTest.cpp b/source/libs/stream/test/tstreamUpdateTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..32ed974f727827b7bd7cd1dbe0e81c0acbb6214c --- /dev/null +++ b/source/libs/stream/test/tstreamUpdateTest.cpp @@ -0,0 +1,113 @@ +#include + +#include "tstreamUpdate.h" +#include "ttime.h" + +using namespace std; + +TEST(TD_STREAM_UPDATE_TEST, update) { + int64_t interval = 20 * 1000; + int64_t watermark = 10 * 60 * 1000; + SUpdateInfo *pSU = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); + GTEST_ASSERT_EQ(isUpdated(pSU,1, 0), true); + GTEST_ASSERT_EQ(isUpdated(pSU,1, -1), true); + + for(int i=0; i < 1024; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU,i, 1), false); + } + for(int i=0; i < 1024; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU,i, 1), true); + } + + for(int i=0; i < 1024; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU,i, 2), false); + } + for(int i=0; i < 1024; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU,i, 2), true); + } + + for(int i=0; i < 1024; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU,i, 1), true); + } + + for(int i=3; i < 1024; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU,0, i), false); + } + GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU->pTsBuckets,0), 1023); + + for(int i=3; i < 1024; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU,0, i), true); + } + GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU->pTsBuckets,0), 1023); + + SUpdateInfo *pSU1 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); + for(int i=1; i <= watermark / interval; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU1, 1, i * interval + 5), false); + GTEST_ASSERT_EQ(pSU1->minTS, interval); + GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval); + } + for(int i=0; i < pSU1->numSBFs; i++) { + SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, i); + SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0); + GTEST_ASSERT_EQ(pBF->size, 1); + } + + for(int i= watermark / interval + 1, j = 2 ; i <= watermark / interval + 10; i++,j++) { + GTEST_ASSERT_EQ(isUpdated(pSU1, 1, i * interval + 5), false); + GTEST_ASSERT_EQ(pSU1->minTS, interval*j); + GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval); + SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU1->pTsSBFs, pSU1->numSBFs - 1); + SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0); + GTEST_ASSERT_EQ(pBF->size, 1); + } + + for(int i= watermark / interval * 100, j = 0; j < 10; i+= (watermark / interval * 2), j++) { + GTEST_ASSERT_EQ(isUpdated(pSU1, 1, i * interval + 5), false); + GTEST_ASSERT_EQ(pSU1->minTS, (i-(pSU1->numSBFs-1))*interval); + GTEST_ASSERT_EQ(pSU1->numSBFs, watermark / interval); + } + + SUpdateInfo *pSU2 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); + GTEST_ASSERT_EQ(isUpdated(pSU2, 1, 1 * interval + 5), false); + GTEST_ASSERT_EQ(pSU2->minTS, interval); + for(int i= watermark / interval * 100, j = 0; j < 10; i+= (watermark / interval * 10), j++) { + GTEST_ASSERT_EQ(isUpdated(pSU2, 1, i * interval + 5), false); + GTEST_ASSERT_EQ(pSU2->minTS, (i-(pSU2->numSBFs-1))*interval); + GTEST_ASSERT_EQ(pSU2->numSBFs, watermark / interval); + GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU2->pTsBuckets,1), i * interval + 5); + } + + SUpdateInfo *pSU3 = updateInfoInit(interval, TSDB_TIME_PRECISION_MILLI, watermark); + for(int j = 1; j < 100; j++) { + for(int i = 0; i < pSU3->numSBFs; i++) { + GTEST_ASSERT_EQ(isUpdated(pSU3, i, i * interval + 5 * j), false); + GTEST_ASSERT_EQ(pSU3->minTS, 0); + GTEST_ASSERT_EQ(pSU3->numSBFs, watermark / interval); + GTEST_ASSERT_EQ(*(int64_t*)taosArrayGet(pSU3->pTsBuckets, i), i * interval + 5 * j); + SScalableBf *pSBF = (SScalableBf *)taosArrayGetP(pSU3->pTsSBFs, i); + SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF->bfArray, 0); + GTEST_ASSERT_EQ(pBF->size, j); + } + } + + SUpdateInfo *pSU4 = updateInfoInit(-1, TSDB_TIME_PRECISION_MILLI, -1); + GTEST_ASSERT_EQ(pSU4->watermark, 120 * pSU4->interval); + GTEST_ASSERT_EQ(pSU4->interval, MILLISECOND_PER_MINUTE); + + SUpdateInfo *pSU5 = updateInfoInit(0, TSDB_TIME_PRECISION_MILLI, 0); + GTEST_ASSERT_EQ(pSU5->watermark, 120 * pSU4->interval); + GTEST_ASSERT_EQ(pSU5->interval, MILLISECOND_PER_MINUTE); + + + updateInfoDestroy(pSU); + updateInfoDestroy(pSU1); + updateInfoDestroy(pSU2); + updateInfoDestroy(pSU3); + updateInfoDestroy(pSU4); + updateInfoDestroy(pSU5); +} + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 71ac3d97ed87eea6b81b7a16ecddb206a66b0cb0..49da6fd8ed78059e0a06f8d79ae951379874f01f 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -22,6 +22,65 @@ extern "C" { #endif +typedef int (*tdb_cmpr_fn_t)(const void *pKey1, int kLen1, const void *pKey2, int kLen2); + +// exposed types +typedef struct STEnv TENV; +typedef struct STDB TDB; +typedef struct STDBC TDBC; +typedef struct STxn TXN; + +// TENV +int tdbEnvOpen(const char *rootDir, int szPage, int pages, TENV **ppEnv); +int tdbEnvClose(TENV *pEnv); +int tdbBegin(TENV *pEnv, TXN *pTxn); +int tdbCommit(TENV *pEnv, TXN *pTxn); + +// TDB +int tdbDbOpen(const char *fname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TENV *pEnv, TDB **ppDb); +int tdbDbClose(TDB *pDb); +int tdbDbDrop(TDB *pDb); +int tdbDbPut(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn); +int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); +int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen); + +// TDBC +int tdbDbcOpen(TDB *pDb, TDBC **ppDbc, TXN *pTxn); +int tdbDbcClose(TDBC *pDbc); +int tdbDbcMoveTo(TDBC *pDbc, const void *pKey, int kLen, int *c); +int tdbDbcMoveToFirst(TDBC *pDbc); +int tdbDbcMoveToLast(TDBC *pDbc); +int tdbDbcMoveToNext(TDBC *pDbc); +int tdbDbcMoveToPrev(TDBC *pDbc); +int tdbDbcGet(TDBC *pDbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen); + +int tdbDbcPut(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen); +int tdbDbcUpdate(TDBC *pDbc, const void *pKey, int kLen, const void *pVal, int vLen); +int tdbDbcDrop(TDBC *pDbc); +int tdbDbcNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); + +// TXN +#define TDB_TXN_WRITE 0x1 +#define TDB_TXN_READ_UNCOMMITTED 0x2 + +int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg, + int flags); +int tdbTxnClose(TXN *pTxn); + +// other +void tdbFree(void *); + +struct STxn { + int flags; + int64_t txnId; + void *(*xMalloc)(void *, size_t); + void (*xFree)(void *, void *); + void *xArg; +}; + +// error code +enum { TDB_CODE_SUCCESS = 0, TDB_CODE_MAX }; + #ifdef __cplusplus } #endif diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 0cee494ae8e3fa6be5c1f2607dfd0b1066c3d568..2665dd1cf6ed423d44a9eb9470f635b55165036b 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -19,17 +19,17 @@ #define TDB_BTREE_LEAF 0x2 struct SBTree { - SPgno root; - int keyLen; - int valLen; - SPager *pPager; - FKeyComparator kcmpr; - int pageSize; - int maxLocal; - int minLocal; - int maxLeaf; - int minLeaf; - void *pBuf; + SPgno root; + int keyLen; + int valLen; + SPager *pPager; + tdb_cmpr_fn_t kcmpr; + int pageSize; + int maxLocal; + int minLocal; + int maxLeaf; + int minLeaf; + void *pBuf; }; #define TDB_BTREE_PAGE_COMMON_HDR u8 flags; @@ -58,16 +58,6 @@ typedef struct { SBTree *pBt; } SBtreeInitPageArg; -typedef struct { - int kLen; - const u8 *pKey; - int vLen; - const u8 *pVal; - SPgno pgno; - u8 *pBuf; -} SCellDecoder; - -static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst); static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeInitPage(SPage *pPage, void *arg, int init); @@ -76,11 +66,10 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); static int tdbBtreeBalance(SBTC *pBtc); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); -static int tdbBtcMoveToNext(SBTC *pBtc); static int tdbBtcMoveDownward(SBTC *pBtc); static int tdbBtcMoveUpward(SBTC *pBtc); -int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { +int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, tdb_cmpr_fn_t kcmpr, SBTree **ppBt) { SBTree *pBt; int ret; @@ -165,7 +154,7 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in // make sure enough space to hold the cell szBuf = kLen + vLen + 14; - pBuf = TDB_REALLOC(pBt->pBuf, pBt->pageSize > szBuf ? szBuf : pBt->pageSize); + pBuf = tdbRealloc(pBt->pBuf, pBt->pageSize > szBuf ? szBuf : pBt->pageSize); if (pBuf == NULL) { tdbBtcClose(&btc); ASSERT(0); @@ -243,7 +232,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL tdbBtreeDecodeCell(btc.pPage, pCell, &cd); if (ppKey) { - pTKey = TDB_REALLOC(*ppKey, cd.kLen); + pTKey = tdbRealloc(*ppKey, cd.kLen); if (pTKey == NULL) { tdbBtcClose(&btc); ASSERT(0); @@ -255,7 +244,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL } if (ppVal) { - pTVal = TDB_REALLOC(*ppVal, cd.vLen); + pTVal = tdbRealloc(*ppVal, cd.vLen); if (pTVal == NULL) { tdbBtcClose(&btc); ASSERT(0); @@ -1018,6 +1007,7 @@ int tdbBtcOpen(SBTC *pBtc, SBTree *pBt, TXN *pTxn) { pBtc->iPage = -1; pBtc->pPage = NULL; pBtc->idx = -1; + memset(&pBtc->coder, 0, sizeof(SCellDecoder)); if (pTxn == NULL) { pBtc->pTxn = &pBtc->txn; @@ -1060,6 +1050,8 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { return 0; } } else { + ASSERT(0); +#if 0 // move from a position int iPage = 0; @@ -1077,6 +1069,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) { tdbBtcMoveUpward(pBtc); } +#endif } // move downward @@ -1125,6 +1118,8 @@ int tdbBtcMoveToLast(SBTC *pBtc) { return 0; } } else { + ASSERT(0); +#if 0 int iPage = 0; // downward search @@ -1147,6 +1142,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) { tdbBtcMoveUpward(pBtc); } +#endif } // move downward @@ -1185,7 +1181,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd); - pKey = TDB_REALLOC(*ppKey, cd.kLen); + pKey = tdbRealloc(*ppKey, cd.kLen); if (pKey == NULL) { return -1; } @@ -1196,9 +1192,9 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { if (ppVal) { // TODO: vLen may be zero - pVal = TDB_REALLOC(*ppVal, cd.vLen); + pVal = tdbRealloc(*ppVal, cd.vLen); if (pVal == NULL) { - TDB_FREE(pKey); + tdbFree(pKey); return -1; } @@ -1216,7 +1212,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return 0; } -static int tdbBtcMoveToNext(SBTC *pBtc) { +int tdbBtcMoveToNext(SBTC *pBtc) { int nCells; int ret; SCell *pCell; @@ -1262,6 +1258,43 @@ static int tdbBtcMoveToNext(SBTC *pBtc) { return 0; } +int tdbBtcMoveToPrev(SBTC *pBtc) { + if (pBtc->idx < 0) return -1; + + pBtc->idx--; + if (pBtc->idx >= 0) { + return 0; + } + + // move upward + for (;;) { + if (pBtc->iPage == 0) { + pBtc->idx = -1; + return 0; + } + + tdbBtcMoveUpward(pBtc); + pBtc->idx--; + if (pBtc->idx >= 0) { + break; + } + } + + // move downward + for (;;) { + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break; + + tdbBtcMoveDownward(pBtc); + if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) { + pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1; + } else { + pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage); + } + } + + return 0; +} + static int tdbBtcMoveDownward(SBTC *pBtc) { int ret; SPgno pgno; @@ -1307,17 +1340,38 @@ static int tdbBtcMoveUpward(SBTC *pBtc) { return 0; } -static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { - int ret; - int nCells; - int c; - SBTree *pBt; - SCell *pCell; - SPager *pPager; - SCellDecoder cd = {0}; +int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen) { + SCell *pCell; - pBt = pBtc->pBt; - pPager = pBt->pPager; + if (pBtc->idx < 0 || pBtc->idx >= TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) { + return -1; + } + + pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); + tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder); + + if (ppKey) { + *ppKey = (void *)pBtc->coder.pKey; + *kLen = pBtc->coder.kLen; + } + + if (ppVal) { + *ppVal = (void *)pBtc->coder.pVal; + *kLen = pBtc->coder.vLen; + } + + return 0; +} + +int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { + int ret; + int nCells; + int c; + SCell *pCell; + SBTree *pBt = pBtc->pBt; + SPager *pPager = pBt->pPager; + const void *pTKey; + int tkLen; if (pBtc->iPage < 0) { // move from a clear cursor @@ -1334,6 +1388,8 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { // for empty tree, just return with an invalid position if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) return 0; } else { + ASSERT(0); +#if 0 SPage *pPage; int idx; int iPage = 0; @@ -1368,11 +1424,12 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { if (pBtc->iPage == iPage) break; tdbBtcMoveUpward(pBtc); } +#endif } // search downward to the leaf for (;;) { - int lidx, ridx, midx; + int lidx, ridx; SPage *pPage; pPage = pBtc->pPage; @@ -1381,13 +1438,11 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { ridx = nCells - 1; ASSERT(nCells > 0); - ASSERT(pBtc->idx == -1); // compare first cell - midx = lidx; - pCell = tdbPageGetCell(pPage, midx); - tdbBtreeDecodeCell(pPage, pCell, &cd); - c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + pBtc->idx = lidx; + tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); + c = pBt->kcmpr(pKey, kLen, pTKey, tkLen); if (c <= 0) { ridx = lidx - 1; } else { @@ -1396,10 +1451,9 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { // compare last cell if (lidx <= ridx) { - midx = ridx; - pCell = tdbPageGetCell(pPage, midx); - tdbBtreeDecodeCell(pPage, pCell, &cd); - c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + pBtc->idx = ridx; + tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); + c = pBt->kcmpr(pKey, kLen, pTKey, tkLen); if (c >= 0) { lidx = ridx + 1; } else { @@ -1411,24 +1465,15 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { for (;;) { if (lidx > ridx) break; - midx = (lidx + ridx) >> 1; - - pCell = tdbPageGetCell(pPage, midx); - ret = tdbBtreeDecodeCell(pPage, pCell, &cd); - if (ret < 0) { - // TODO: handle error - ASSERT(0); - return -1; - } - - // Compare the key values - c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); + pBtc->idx = (lidx + ridx) >> 1; + tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); + c = pBt->kcmpr(pKey, kLen, pTKey, tkLen); if (c < 0) { // pKey < cd.pKey - ridx = midx - 1; + ridx = pBtc->idx - 1; } else if (c > 0) { // pKey > cd.pKey - lidx = midx + 1; + lidx = pBtc->idx + 1; } else { // pKey == cd.pKey break; @@ -1437,14 +1482,11 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { // keep search downward or break if (TDB_BTREE_PAGE_IS_LEAF(pPage)) { - pBtc->idx = midx; *pCRst = c; break; } else { - if (c <= 0) { - pBtc->idx = midx; - } else { - pBtc->idx = midx + 1; + if (c > 0) { + pBtc->idx += 1; } tdbBtcMoveDownward(pBtc); } diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index f4468e7e827da8b8455db921df2b027e0b778d3a..aadb9238b0ebe896aa3a61cdd435b8934be3e2da 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -24,7 +24,7 @@ struct STDBC { SBTC btc; }; -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb) { +int tdbDbOpen(const char *fname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TENV *pEnv, TDB **ppDb) { TDB *pDb; SPager *pPager; int ret; @@ -75,7 +75,7 @@ int tdbDbDrop(TDB *pDb) { return 0; } -int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn) { +int tdbDbPut(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn) { return tdbBtreeInsert(pDb->pBt, pKey, keyLen, pVal, valLen, pTxn); } @@ -87,7 +87,7 @@ int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, vo return tdbBtreePGet(pDb->pBt, pKey, kLen, ppKey, pkLen, ppVal, vLen); } -int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) { +int tdbDbcOpen(TDB *pDb, TDBC **ppDbc, TXN *pTxn) { int ret; TDBC *pDbc = NULL; @@ -97,34 +97,53 @@ int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) { return -1; } - tdbBtcOpen(&pDbc->btc, pDb->pBt, NULL); - - // TODO: move to first now, we can move to any key-value - // and in any direction, design new APIs. - ret = tdbBtcMoveToFirst(&pDbc->btc); - if (ret < 0) { - ASSERT(0); - return -1; - } + tdbBtcOpen(&pDbc->btc, pDb->pBt, pTxn); *ppDbc = pDbc; return 0; } -int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { +int tdbDbcMoveTo(TDBC *pDbc, const void *pKey, int kLen, int *c) { return tdbBtcMoveTo(&pDbc->btc, pKey, kLen, c); } + +int tdbDbcMoveToFirst(TDBC *pDbc) { return tdbBtcMoveToFirst(&pDbc->btc); } + +int tdbDbcMoveToLast(TDBC *pDbc) { return tdbBtcMoveToLast(&pDbc->btc); } + +int tdbDbcMoveToNext(TDBC *pDbc) { return tdbBtcMoveToNext(&pDbc->btc); } + +int tdbDbcMoveToPrev(TDBC *pDbc) { return tdbBtcMoveToPrev(&pDbc->btc); } + +int tdbDbcGet(TDBC *pDbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen) { + return tdbBtcGet(&pDbc->btc, ppKey, pkLen, ppVal, pvLen); +} + +int tdbDbcPut(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen) { + // TODO + ASSERT(0); + return 0; +} + +int tdbDbcUpdate(TDBC *pDbc, const void *pKey, int kLen, const void *pVal, int vLen) { + // TODO + ASSERT(0); + return 0; +} + +int tdbDbcDrop(TDBC *pDbc) { + // TODO + ASSERT(0); + return 0; +} + +int tdbDbcNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen); } int tdbDbcClose(TDBC *pDbc) { if (pDbc) { + tdbBtcClose(&pDbc->btc); tdbOsFree(pDbc); } return 0; } - -int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen) { - // TODO - ASSERT(0); - return 0; -} \ No newline at end of file diff --git a/source/libs/tdb/src/db/tdbEnv.c b/source/libs/tdb/src/db/tdbEnv.c index 779435861e312a590613c2db61abb90468e5f7f3..d64b31234e170fc60c7b24d86905404c2c044fbd 100644 --- a/source/libs/tdb/src/db/tdbEnv.c +++ b/source/libs/tdb/src/db/tdbEnv.c @@ -15,7 +15,7 @@ #include "tdbInt.h" -int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) { +int tdbEnvOpen(const char *rootDir, int szPage, int pages, TENV **ppEnv) { TENV *pEnv; int dsize; int zsize; @@ -49,14 +49,14 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) { pEnv->jfd = -1; - ret = tdbPCacheOpen(pageSize, cacheSize, &(pEnv->pCache)); + ret = tdbPCacheOpen(szPage, pages, &(pEnv->pCache)); if (ret < 0) { return -1; } pEnv->nPgrHash = 8; tsize = sizeof(SPager *) * pEnv->nPgrHash; - pEnv->pgrHash = TDB_REALLOC(pEnv->pgrHash, tsize); + pEnv->pgrHash = tdbRealloc(pEnv->pgrHash, tsize); if (pEnv->pgrHash == NULL) { return -1; } @@ -103,11 +103,6 @@ int tdbCommit(TENV *pEnv, TXN *pTxn) { return 0; } -int tdbRollback(TENV *pEnv, TXN *pTxn) { - ASSERT(0); - return 0; -} - SPager *tdbEnvGetPager(TENV *pEnv, const char *fname) { u32 hash; SPager **ppPager; diff --git a/source/libs/tdb/src/db/tdbOs.c b/source/libs/tdb/src/db/tdbOs.c index 5ca3578985e96715cd6facbc88499282b802eefa..a2fce8925b8072658df78953b9c0876597299b22 100644 --- a/source/libs/tdb/src/db/tdbOs.c +++ b/source/libs/tdb/src/db/tdbOs.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tdbInt.h" +#include "tdbOs.h" #ifndef TDB_FOR_TDENGINE diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 0ccf7f5f92ccd406f93a30a96e094cc1f312b306..646b83298ead54fe1d262d93f867e5c21198f27c 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -135,7 +135,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) // 1. Search the hash table pPage = pCache->pgHash[tdbPCachePageHash(pPgid) % pCache->nHash]; while (pPage) { - if (TDB_IS_SAME_PAGE(&(pPage->pgid), pPgid)) break; + if (memcmp(pPage->pgid.fileid, pPgid->fileid, TDB_FILE_ID_LEN) == 0 && pPage->pgid.pgno == pPgid->pgno) break; pPage = pPage->pHashNext; } diff --git a/source/libs/tdb/src/db/tdbUtil.c b/source/libs/tdb/src/db/tdbUtil.c index 09e126772b1c46e2adfb29b4323a561df6c770a1..3746d9358f8eacbbe2a572c079f510e2e84e277d 100644 --- a/source/libs/tdb/src/db/tdbUtil.c +++ b/source/libs/tdb/src/db/tdbUtil.c @@ -15,6 +15,26 @@ #include "tdbInt.h" +void *tdbRealloc(void *ptr, size_t size) { + void *nPtr; + if ((ptr) == NULL || ((int *)(ptr))[-1] < (size)) { + nPtr = tdbOsRealloc((ptr) ? (char *)(ptr) - sizeof(int) : NULL, (size) + sizeof(int)); + if (nPtr) { + ((int *)nPtr)[0] = (size); + nPtr = (char *)nPtr + sizeof(int); + } + } else { + nPtr = (ptr); + } + return nPtr; +} + +void tdbFree(void *p) { + if (p) { + tdbOsFree((char *)(p) - sizeof(int)); + } +} + int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { int64_t stDev = 0, stIno = 0; diff --git a/source/libs/tdb/src/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h deleted file mode 100644 index 2a9e8533d2487673e86e65b47b1aa79d30447bb8..0000000000000000000000000000000000000000 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_BTREE_H_ -#define _TD_BTREE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct SBTree SBTree; -typedef struct SBTC SBTC; -typedef struct SBtInfo { - SPgno root; - int nLevel; - int nData; -} SBtInfo; - -struct SBTC { - SBTree *pBt; - i8 iPage; - SPage *pPage; - int idx; - int idxStack[BTREE_MAX_DEPTH + 1]; - SPage *pgStack[BTREE_MAX_DEPTH + 1]; - TXN *pTxn; - TXN txn; -}; - -// SBTree -int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt); -int tdbBtreeClose(SBTree *pBt); -int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn); -int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); -int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen); - -// SBTC -int tdbBtcOpen(SBTC *pBtc, SBTree *pBt, TXN *pTxn); -int tdbBtcMoveToFirst(SBTC *pBtc); -int tdbBtcMoveToLast(SBTC *pBtc); -int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); -int tdbBtcClose(SBTC *pBtc); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_BTREE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbDb.h b/source/libs/tdb/src/inc/tdbDb.h deleted file mode 100644 index f9ff3786337249e612c13423c8764db73caad270..0000000000000000000000000000000000000000 --- a/source/libs/tdb/src/inc/tdbDb.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TDB_DB_H_ -#define _TD_TDB_DB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct STDB TDB; -typedef struct STDBC TDBC; - -// TDB -int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb); -int tdbDbClose(TDB *pDb); -int tdbDbDrop(TDB *pDb); -int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn); -int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); -int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen); - -// TDBC -int tdbDbcOpen(TDB *pDb, TDBC **ppDbc); -int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); -int tdbDbcClose(TDBC *pDbc); -int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TDB_DB_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index b85b7174bcdb68417bac6c16c40549ab538275c9..4c19dee03ec29b23793e0aae2379043d92f309b8 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -31,6 +31,12 @@ typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; +// SPgno +typedef u32 SPgno; + +#include "tdbOs.h" +#include "tdbUtil.h" + // p must be u8 * #define TDB_GET_U24(p) ((p)[0] * 65536 + *(u16 *)((p) + 1)) #define TDB_PUT_U24(p, v) \ @@ -41,10 +47,6 @@ typedef uint64_t u64; (p)[0] = (tv >> 16) & 0xff; \ } while (0) -// SPgno -typedef u32 SPgno; -#define TDB_IVLD_PGNO ((pgno_t)0) - // fileid #define TDB_FILE_ID_LEN 24 @@ -54,51 +56,21 @@ typedef struct { SPgno pgno; } SPgid; -#define TDB_IVLD_PGID (SPgid){0, TDB_IVLD_PGNO}; - -static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { - SPgid *pgid1 = (SPgid *)p1; - SPgid *pgid2 = (SPgid *)p2; - int rcode; - - rcode = memcmp(pgid1->fileid, pgid2->fileid, TDB_FILE_ID_LEN); - if (rcode) { - return rcode; - } else { - if (pgid1->pgno > pgid2->pgno) { - return 1; - } else if (pgid1->pgno < pgid2->pgno) { - return -1; - } else { - return 0; - } - } -} - -#define TDB_IS_SAME_PAGE(pPgid1, pPgid2) (tdbCmprPgId(pPgid1, pPgid2) == 0) - // pgsz_t #define TDB_MIN_PGSIZE 512 // 512B #define TDB_MAX_PGSIZE 16777216 // 16M #define TDB_DEFAULT_PGSIZE 4096 #define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE)) -// cache -#define TDB_DEFAULT_CACHE_SIZE (256 * 4096) // 1M - // dbname #define TDB_MAX_DBNAME_LEN 24 #define TDB_VARIANT_LEN ((int)-1) -typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2); - #define TDB_JOURNAL_NAME "tdb.journal" #define TDB_FILENAME_LEN 128 -#define TDB_DEFAULT_FANOUT 6 - #define BTREE_MAX_DEPTH 20 #define TDB_FLAG_IS(flags, flag) ((flags) == (flag)) @@ -112,37 +84,253 @@ typedef struct SPCache SPCache; typedef struct SPage SPage; // transaction -#define TDB_TXN_WRITE 0x1 -#define TDB_TXN_READ_UNCOMMITTED 0x2 -typedef struct STxn { - int flags; - i64 txnId; - void *(*xMalloc)(void *, size_t); - void (*xFree)(void *, void *); - void *xArg; -} TXN; #define TDB_TXN_IS_WRITE(PTXN) ((PTXN)->flags & TDB_TXN_WRITE) #define TDB_TXN_IS_READ(PTXN) (!TDB_TXN_IS_WRITE(PTXN)) #define TDB_TXN_IS_READ_UNCOMMITTED(PTXN) ((PTXN)->flags & TDB_TXN_READ_UNCOMMITTED) -#include "tdbOs.h" - -#include "tdbUtil.h" - -#include "tdbPCache.h" +// tdbEnv.c ==================================== +void tdbEnvAddPager(TENV *pEnv, SPager *pPager); +void tdbEnvRemovePager(TENV *pEnv, SPager *pPager); +SPager *tdbEnvGetPager(TENV *pEnv, const char *fname); -#include "tdbPager.h" +// tdbBtree.c ==================================== +typedef struct SBTree SBTree; +typedef struct SBTC SBTC; +typedef struct SBtInfo { + SPgno root; + int nLevel; + int nData; +} SBtInfo; -#include "tdbBtree.h" +typedef struct { + int kLen; + const u8 *pKey; + int vLen; + const u8 *pVal; + SPgno pgno; + u8 *pBuf; +} SCellDecoder; + +struct SBTC { + SBTree *pBt; + i8 iPage; + SPage *pPage; + int idx; + int idxStack[BTREE_MAX_DEPTH + 1]; + SPage *pgStack[BTREE_MAX_DEPTH + 1]; + SCellDecoder coder; + TXN *pTxn; + TXN txn; +}; + +// SBTree +int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, tdb_cmpr_fn_t kcmpr, SBTree **ppBt); +int tdbBtreeClose(SBTree *pBt); +int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn); +int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen); +int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen); + +// SBTC +int tdbBtcOpen(SBTC *pBtc, SBTree *pBt, TXN *pTxn); +int tdbBtcClose(SBTC *pBtc); +int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst); +int tdbBtcMoveToFirst(SBTC *pBtc); +int tdbBtcMoveToLast(SBTC *pBtc); +int tdbBtcMoveToNext(SBTC *pBtc); +int tdbBtcMoveToPrev(SBTC *pBtc); +int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen); + +// tdbPager.c ==================================== + +int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager); +int tdbPagerClose(SPager *pPager); +int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate); +int tdbPagerWrite(SPager *pPager, SPage *pPage); +int tdbPagerBegin(SPager *pPager, TXN *pTxn); +int tdbPagerCommit(SPager *pPager, TXN *pTxn); +int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg, + TXN *pTxn); +void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn); +int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno); + +// tdbPCache.c ==================================== +#define TDB_PCACHE_PAGE \ + u8 isAnchor; \ + u8 isLocal; \ + u8 isDirty; \ + i32 nRef; \ + SPage *pCacheNext; \ + SPage *pFreeNext; \ + SPage *pHashNext; \ + SPage *pLruNext; \ + SPage *pLruPrev; \ + SPage *pDirtyNext; \ + SPager *pPager; \ + SPgid pgid; + +// For page ref +#define TDB_INIT_PAGE_REF(pPage) ((pPage)->nRef = 0) +#define TDB_REF_PAGE(pPage) atomic_add_fetch_32(&((pPage)->nRef), 1) +#define TDB_UNREF_PAGE(pPage) atomic_sub_fetch_32(&((pPage)->nRef), 1) +#define TDB_GET_PAGE_REF(pPage) atomic_load_32(&((pPage)->nRef)) + +int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache); +int tdbPCacheClose(SPCache *pCache); +SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn); +void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn); +int tdbPCacheGetPageSize(SPCache *pCache); + +// tdbPage.c ==================================== +typedef u8 SCell; + +// PAGE APIS implemented +typedef struct { + int szOffset; + int szPageHdr; + int szFreeCell; + // cell number + int (*getCellNum)(SPage *); + void (*setCellNum)(SPage *, int); + // cell content offset + int (*getCellBody)(SPage *); + void (*setCellBody)(SPage *, int); + // first free cell offset (0 means no free cells) + int (*getCellFree)(SPage *); + void (*setCellFree)(SPage *, int); + // total free bytes + int (*getFreeBytes)(SPage *); + void (*setFreeBytes)(SPage *, int); + // cell offset at idx + int (*getCellOffset)(SPage *, int); + void (*setCellOffset)(SPage *, int, int); + // free cell info + void (*getFreeCellInfo)(SCell *pCell, int *szCell, int *nxOffset); + void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset); +} SPageMethods; + +#pragma pack(push, 1) + +// Page footer +typedef struct { + u8 cksm[4]; +} SPageFtr; +#pragma pack(pop) + +struct SPage { + tdb_spinlock_t lock; + int pageSize; + u8 *pData; + SPageMethods *pPageMethods; + // Fields below used by pager and am + u8 *pPageHdr; + u8 *pCellIdx; + u8 *pFreeStart; + u8 *pFreeEnd; + SPageFtr *pPageFtr; + int nOverflow; + SCell *apOvfl[4]; + int aiOvfl[4]; + int kLen; // key length of the page, -1 for unknown + int vLen; // value length of the page, -1 for unknown + int maxLocal; + int minLocal; + int (*xCellSize)(const SPage *, SCell *); + // Fields used by SPCache + TDB_PCACHE_PAGE +}; + +// For page lock +#define P_LOCK_SUCC 0 +#define P_LOCK_BUSY 1 +#define P_LOCK_FAIL -1 + +static inline int tdbTryLockPage(tdb_spinlock_t *pLock) { + int ret; + if (tdbSpinlockTrylock(pLock) == 0) { + ret = P_LOCK_SUCC; + } else if (errno == EBUSY) { + ret = P_LOCK_BUSY; + } else { + ret = P_LOCK_FAIL; + } + return ret; +} -#include "tdbEnv.h" +#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0) +#define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock)) +#define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock)) +#define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock)) +#define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock)) + +// APIs +#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) +#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) +#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage) +#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno) +#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) +#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) + +int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); +int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); +void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); +void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); +int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl); +int tdbPageDropCell(SPage *pPage, int idx); +void tdbPageCopy(SPage *pFromPage, SPage *pToPage); +int tdbPageCapacity(int pageSize, int amHdrSize); + +static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { + SCell *pCell; + int iOvfl; + int lidx; + + ASSERT(idx >= 0 && idx < TDB_PAGE_TOTAL_CELLS(pPage)); + + iOvfl = 0; + for (; iOvfl < pPage->nOverflow; iOvfl++) { + if (pPage->aiOvfl[iOvfl] == idx) { + pCell = pPage->apOvfl[iOvfl]; + return pCell; + } else if (pPage->aiOvfl[iOvfl] > idx) { + break; + } + } -#include "tdbDb.h" + lidx = idx - iOvfl; + ASSERT(lidx >= 0 && lidx < pPage->pPageMethods->getCellNum(pPage)); + pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx); -#include "tdbPage.h" + return pCell; +} -#include "tdbTxn.h" +struct STEnv { + char *rootDir; + char *jfname; + int jfd; + SPCache *pCache; + SPager *pgrList; + int nPager; + int nPgrHash; + SPager **pgrHash; +}; + +struct SPager { + char *dbFileName; + char *jFileName; + int pageSize; + uint8_t fid[TDB_FILE_ID_LEN]; + tdb_fd_t fd; + tdb_fd_t jfd; + SPCache *pCache; + SPgno dbFileSize; + SPgno dbOrigSize; + SPage *pDirty; + u8 inTran; + SPager *pNext; // used by TENV + SPager *pHashNext; // used by TENV +}; #ifdef __cplusplus } diff --git a/source/libs/tdb/src/inc/tdbPCache.h b/source/libs/tdb/src/inc/tdbPCache.h deleted file mode 100644 index a77cf6248cf2cac87f9e7b75f122ed88221c21cf..0000000000000000000000000000000000000000 --- a/source/libs/tdb/src/inc/tdbPCache.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_PAGE_CACHE_H_ -#define _TD_PAGE_CACHE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#define TDB_PCACHE_PAGE \ - u8 isAnchor; \ - u8 isLocal; \ - u8 isDirty; \ - i32 nRef; \ - SPage *pCacheNext; \ - SPage *pFreeNext; \ - SPage *pHashNext; \ - SPage *pLruNext; \ - SPage *pLruPrev; \ - SPage *pDirtyNext; \ - SPager *pPager; \ - SPgid pgid; - -// For page ref -#define TDB_INIT_PAGE_REF(pPage) ((pPage)->nRef = 0) -#if 0 -#define TDB_REF_PAGE(pPage) (++(pPage)->nRef) -#define TDB_UNREF_PAGE(pPage) (--(pPage)->nRef) -#define TDB_GET_PAGE_REF(pPage) ((pPage)->nRef) -#else -#define TDB_REF_PAGE(pPage) atomic_add_fetch_32(&((pPage)->nRef), 1) -#define TDB_UNREF_PAGE(pPage) atomic_sub_fetch_32(&((pPage)->nRef), 1) -#define TDB_GET_PAGE_REF(pPage) atomic_load_32(&((pPage)->nRef)) -#endif - -int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache); -int tdbPCacheClose(SPCache *pCache); -SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn); -void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn); -int tdbPCacheGetPageSize(SPCache *pCache); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_PAGE_CACHE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h deleted file mode 100644 index 3707a922ee84d46849d57647a6bb6f3853a508d2..0000000000000000000000000000000000000000 --- a/source/libs/tdb/src/inc/tdbPage.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TDB_PAGE_H_ -#define _TDB_PAGE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef u8 SCell; - -// PAGE APIS implemented -typedef struct { - int szOffset; - int szPageHdr; - int szFreeCell; - // cell number - int (*getCellNum)(SPage *); - void (*setCellNum)(SPage *, int); - // cell content offset - int (*getCellBody)(SPage *); - void (*setCellBody)(SPage *, int); - // first free cell offset (0 means no free cells) - int (*getCellFree)(SPage *); - void (*setCellFree)(SPage *, int); - // total free bytes - int (*getFreeBytes)(SPage *); - void (*setFreeBytes)(SPage *, int); - // cell offset at idx - int (*getCellOffset)(SPage *, int); - void (*setCellOffset)(SPage *, int, int); - // free cell info - void (*getFreeCellInfo)(SCell *pCell, int *szCell, int *nxOffset); - void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset); -} SPageMethods; - -#pragma pack(push,1) - -// Page footer -typedef struct { - u8 cksm[4]; -} SPageFtr; -#pragma pack(pop) - -struct SPage { - tdb_spinlock_t lock; - int pageSize; - u8 *pData; - SPageMethods *pPageMethods; - // Fields below used by pager and am - u8 *pPageHdr; - u8 *pCellIdx; - u8 *pFreeStart; - u8 *pFreeEnd; - SPageFtr *pPageFtr; - int nOverflow; - SCell *apOvfl[4]; - int aiOvfl[4]; - int kLen; // key length of the page, -1 for unknown - int vLen; // value length of the page, -1 for unknown - int maxLocal; - int minLocal; - int (*xCellSize)(const SPage *, SCell *); - // Fields used by SPCache - TDB_PCACHE_PAGE -}; - -// For page lock -#define P_LOCK_SUCC 0 -#define P_LOCK_BUSY 1 -#define P_LOCK_FAIL -1 - -static inline int tdbTryLockPage(tdb_spinlock_t *pLock) { - int ret; - if (tdbSpinlockTrylock(pLock) == 0) { - ret = P_LOCK_SUCC; - } else if (errno == EBUSY) { - ret = P_LOCK_BUSY; - } else { - ret = P_LOCK_FAIL; - } - return ret; -} - -#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0) -#define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock)) -#define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock)) -#define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock)) -#define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock)) - -// APIs -#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage)) -#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx) -#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage) -#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno) -#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset) -#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset) - -int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg); -int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg); -void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); -void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *)); -int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl); -int tdbPageDropCell(SPage *pPage, int idx); -void tdbPageCopy(SPage *pFromPage, SPage *pToPage); -int tdbPageCapacity(int pageSize, int amHdrSize); - -static inline SCell *tdbPageGetCell(SPage *pPage, int idx) { - SCell *pCell; - int iOvfl; - int lidx; - - ASSERT(idx >= 0 && idx < TDB_PAGE_TOTAL_CELLS(pPage)); - - iOvfl = 0; - for (; iOvfl < pPage->nOverflow; iOvfl++) { - if (pPage->aiOvfl[iOvfl] == idx) { - pCell = pPage->apOvfl[iOvfl]; - return pCell; - } else if (pPage->aiOvfl[iOvfl] > idx) { - break; - } - } - - lidx = idx - iOvfl; - ASSERT(lidx >= 0 && lidx < pPage->pPageMethods->getCellNum(pPage)); - pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx); - - return pCell; -} - -#ifdef __cplusplus -} -#endif - -#endif /*_TDB_PAGE_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbPager.h b/source/libs/tdb/src/inc/tdbPager.h deleted file mode 100644 index c39f833c738ecd9a1ad63628d2ae1a371bd37bf0..0000000000000000000000000000000000000000 --- a/source/libs/tdb/src/inc/tdbPager.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TDB_PAGER_H_ -#define _TDB_PAGER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -struct SPager { - char *dbFileName; - char *jFileName; - int pageSize; - uint8_t fid[TDB_FILE_ID_LEN]; - tdb_fd_t fd; - tdb_fd_t jfd; - SPCache *pCache; - SPgno dbFileSize; - SPgno dbOrigSize; - SPage *pDirty; - u8 inTran; - SPager *pNext; // used by TENV - SPager *pHashNext; // used by TENV -}; - -int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager); -int tdbPagerClose(SPager *pPager); -int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate); -int tdbPagerWrite(SPager *pPager, SPage *pPage); -int tdbPagerBegin(SPager *pPager, TXN *pTxn); -int tdbPagerCommit(SPager *pPager, TXN *pTxn); -int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg, - TXN *pTxn); -void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn); -int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno); - -#ifdef __cplusplus -} -#endif - -#endif /*_TDB_PAGER_H_*/ \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbUtil.h b/source/libs/tdb/src/inc/tdbUtil.h index cffd3f27469598c58a31513e11d9b72b8539fc5f..29a505fa783e848e9603dc1c7dfd12c1b01bd622 100644 --- a/source/libs/tdb/src/inc/tdbUtil.h +++ b/source/libs/tdb/src/inc/tdbUtil.h @@ -31,27 +31,7 @@ extern "C" { int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); int tdbGetFileSize(tdb_fd_t fd, int szPage, SPgno *size); -static inline void *tdbRealloc(void *ptr, size_t size) { - void *nPtr; - if ((ptr) == NULL || ((int *)(ptr))[-1] < (size)) { - nPtr = tdbOsRealloc((ptr) ? (char *)(ptr) - sizeof(int) : NULL, (size) + sizeof(int)); - if (nPtr) { - ((int *)nPtr)[0] = (size); - nPtr = (char *)nPtr + sizeof(int); - } - } else { - nPtr = (ptr); - } - return nPtr; -} -#define TDB_REALLOC(PTR, SIZE) tdbRealloc(PTR, SIZE) - -#define TDB_FREE(PTR) \ - do { \ - if (PTR) { \ - tdbOsFree((char *)(PTR) - sizeof(int)); \ - } \ - } while (0) +void *tdbRealloc(void *ptr, size_t size); static inline void *tdbDefaultMalloc(void *arg, size_t size) { void *ptr; diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 49763ae937d252e3289ab964f3c2c868bb82ea20..1f6f28261f8cd5ae4bff0fab8f415b5144b809d3 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -1,7 +1,7 @@ #include #include "os.h" -#include "tdbInt.h" +#include "tdb.h" #include @@ -12,7 +12,7 @@ typedef struct SPoolMem { } SPoolMem; static SPoolMem *openPool() { - SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool)); + SPoolMem *pPool = (SPoolMem *)taosMemoryMalloc(sizeof(*pPool)); pPool->prev = pPool->next = pPool; pPool->size = 0; @@ -32,7 +32,7 @@ static void clearPool(SPoolMem *pPool) { pMem->prev->next = pMem->next; pPool->size -= pMem->size; - tdbOsFree(pMem); + taosMemoryFree(pMem); } while (1); assert(pPool->size == 0); @@ -40,7 +40,7 @@ static void clearPool(SPoolMem *pPool) { static void closePool(SPoolMem *pPool) { clearPool(pPool); - tdbOsFree(pPool); + taosMemoryFree(pPool); } static void *poolMalloc(void *arg, size_t size) { @@ -48,7 +48,7 @@ static void *poolMalloc(void *arg, size_t size) { SPoolMem *pPool = (SPoolMem *)arg; SPoolMem *pMem; - pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size); + pMem = (SPoolMem *)taosMemoryMalloc(sizeof(*pMem) + size); if (pMem == NULL) { assert(0); } @@ -75,7 +75,7 @@ static void poolFree(void *arg, void *ptr) { pMem->prev->next = pMem->next; pPool->size -= pMem->size; - tdbOsFree(pMem); + taosMemoryFree(pMem); } static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { @@ -116,12 +116,12 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in } TEST(tdb_test, simple_test) { - int ret; - TENV *pEnv; - TDB *pDb; - FKeyComparator compFunc; - int nData = 10000000; - TXN txn; + int ret; + TENV *pEnv; + TDB *pDb; + tdb_cmpr_fn_t compFunc; + int nData = 10000000; + TXN txn; taosRemoveDir("tdb"); @@ -131,7 +131,7 @@ TEST(tdb_test, simple_test) { // Create a database compFunc = tKeyCmpr; - ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, &pDb); + ret = tdbDbOpen("db.db", -1, -1, compFunc, pEnv, &pDb); GTEST_ASSERT_EQ(ret, 0); { @@ -152,7 +152,7 @@ TEST(tdb_test, simple_test) { for (int iData = 1; iData <= nData; iData++) { sprintf(key, "key%d", iData); sprintf(val, "value%d", iData); - ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val), &txn); + ret = tdbDbPut(pDb, key, strlen(key), val, strlen(val), &txn); GTEST_ASSERT_EQ(ret, 0); // if pool is full, commit the transaction and start a new one @@ -189,7 +189,7 @@ TEST(tdb_test, simple_test) { GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0); } - TDB_FREE(pVal); + tdbFree(pVal); } { // Iterate to query the DB data @@ -199,11 +199,11 @@ TEST(tdb_test, simple_test) { int vLen, kLen; int count = 0; - ret = tdbDbcOpen(pDb, &pDBC); + ret = tdbDbcOpen(pDb, &pDBC, NULL); GTEST_ASSERT_EQ(ret, 0); for (;;) { - ret = tdbDbNext(pDBC, &pKey, &kLen, &pVal, &vLen); + ret = tdbDbcNext(pDBC, &pKey, &kLen, &pVal, &vLen); if (ret < 0) break; // std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " "; @@ -217,8 +217,8 @@ TEST(tdb_test, simple_test) { tdbDbcClose(pDBC); - TDB_FREE(pKey); - TDB_FREE(pVal); + tdbFree(pKey); + tdbFree(pVal); } } @@ -234,12 +234,12 @@ TEST(tdb_test, simple_test) { } TEST(tdb_test, simple_test2) { - int ret; - TENV *pEnv; - TDB *pDb; - FKeyComparator compFunc; - int nData = 1000000; - TXN txn; + int ret; + TENV *pEnv; + TDB *pDb; + tdb_cmpr_fn_t compFunc; + int nData = 1000000; + TXN txn; taosRemoveDir("tdb"); @@ -249,7 +249,7 @@ TEST(tdb_test, simple_test2) { // Create a database compFunc = tDefaultKeyCmpr; - ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, &pDb); + ret = tdbDbOpen("db.db", -1, -1, compFunc, pEnv, &pDb); GTEST_ASSERT_EQ(ret, 0); { @@ -269,7 +269,7 @@ TEST(tdb_test, simple_test2) { for (int iData = 1; iData <= nData; iData++) { sprintf(key, "key%d", iData); sprintf(val, "value%d", iData); - ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val), &txn); + ret = tdbDbPut(pDb, key, strlen(key), val, strlen(val), &txn); GTEST_ASSERT_EQ(ret, 0); } @@ -280,11 +280,11 @@ TEST(tdb_test, simple_test2) { int vLen, kLen; int count = 0; - ret = tdbDbcOpen(pDb, &pDBC); + ret = tdbDbcOpen(pDb, &pDBC, NULL); GTEST_ASSERT_EQ(ret, 0); for (;;) { - ret = tdbDbNext(pDBC, &pKey, &kLen, &pVal, &vLen); + ret = tdbDbcNext(pDBC, &pKey, &kLen, &pVal, &vLen); if (ret < 0) break; std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " "; @@ -298,8 +298,8 @@ TEST(tdb_test, simple_test2) { tdbDbcClose(pDBC); - TDB_FREE(pKey); - TDB_FREE(pVal); + tdbFree(pKey); + tdbFree(pVal); } } diff --git a/source/libs/tdb/test/tdbUtilTest.cpp b/source/libs/tdb/test/tdbUtilTest.cpp index 5fd45daa3e59780927616b2155310cf339d527ca..57372995cc8b4ece29c6fab95cdbf0363d12a759 100644 --- a/source/libs/tdb/test/tdbUtilTest.cpp +++ b/source/libs/tdb/test/tdbUtilTest.cpp @@ -1,20 +1,20 @@ #include -#include "tdbInt.h" +#include "tdb.h" #include TEST(tdb_util_test, simple_test) { - int vEncode = 5000; - int vDecode; - int nEncode; - int nDecode; - u8 buffer[128]; + // int vEncode = 5000; + // int vDecode; + // int nEncode; + // int nDecode; + // uint8_t buffer[128]; - nEncode = tdbPutVarInt(buffer, vEncode); + // nEncode = tdbPutVarInt(buffer, vEncode); - nDecode = tdbGetVarInt(buffer, &vDecode); + // nDecode = tdbGetVarInt(buffer, &vDecode); - GTEST_ASSERT_EQ(nEncode, nDecode); - GTEST_ASSERT_EQ(vEncode, vDecode); + // GTEST_ASSERT_EQ(nEncode, nDecode); + // GTEST_ASSERT_EQ(vEncode, vDecode); } \ No newline at end of file diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 37f21e2511905cc8af755fb2b0d762099f601821..21af35e8f768748c5ea7609d70f89fc2d9896f03 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -28,6 +28,7 @@ extern "C" { #include "taoserror.h" #include "tglobal.h" #include "thash.h" +#include "theap.h" #include "tidpool.h" #include "tmd5.h" #include "tmempool.h" @@ -328,10 +329,38 @@ void transQueueClear(STransQueue* queue); */ void transQueueDestroy(STransQueue* queue); +/* + * delay queue based on uv loop and uv timer, and only used in retry + */ +typedef struct STaskArg { + void* param1; + void* param2; +} STaskArg; + +typedef struct SDelayTask { + void (*func)(void* arg); + void* arg; + uint64_t execTime; + HeapNode node; +} SDelayTask; + +typedef struct SDelayQueue { + uv_timer_t* timer; + Heap* heap; + uv_loop_t* loop; +} SDelayQueue; + +int transDQCreate(uv_loop_t* loop, SDelayQueue** queue); + +void transDQDestroy(SDelayQueue* queue); + +int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs); + /* * init global func */ void transThreadOnce(); + #ifdef __cplusplus } #endif diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index fecb5d927951a2b98ea8ff716b26a4cab1391fc9..f776fb3764b0ed0db51fc54dc1e95e0ef4564098 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -101,18 +101,8 @@ void* rpcReallocCont(void* ptr, int contLen) { } void rpcSendRedirectRsp(void* thandle, const SEpSet* pEpSet) { - SRpcMsg rpcMsg; - memset(&rpcMsg, 0, sizeof(rpcMsg)); - - SMEpSet msg = {.epSet = *pEpSet}; - int32_t len = tSerializeSMEpSet(NULL, 0, &msg); - rpcMsg.pCont = rpcMallocCont(len); - tSerializeSMEpSet(rpcMsg.pCont, len, &msg); - - rpcMsg.code = TSDB_CODE_RPC_REDIRECT; - rpcMsg.handle = thandle; - - rpcSendResponse(&rpcMsg); + // deprecated api + assert(0); } int rpcReportProgress(void* pConn, char* pCont, int contLen) { return -1; } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 20406763deed764f157a6c89c326f438ba18c815..80b5d88a9040623b2e86eea2dce2445d5e60f0fc 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -60,10 +60,10 @@ typedef struct SCliThrdObj { // msg queue queue msg; TdThreadMutex msgMtx; - - uint64_t nextTimeout; // next timeout - void* pTransInst; // - bool quit; + SDelayQueue* delayQueue; + uint64_t nextTimeout; // next timeout + void* pTransInst; // + bool quit; } SCliThrdObj; typedef struct SCliObj { @@ -161,8 +161,7 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); transUnrefCliHandle(conn); \ } \ if (T_REF_VAL_GET(conn) == 1) { \ - SCliThrdObj* thrd = conn->hostThrd; \ - addConnToPool(thrd->pool, conn); \ + transUnrefCliHandle(conn); \ } \ destroyCmsg(pMsg); \ return; \ @@ -838,12 +837,13 @@ static SCliThrdObj* createThrdObj() { uv_loop_init(pThrd->loop); pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 5, pThrd, cliAsyncCb); - uv_timer_init(pThrd->loop, &pThrd->timer); pThrd->timer.data = pThrd; pThrd->pool = createConnPool(4); + transDQCreate(pThrd->loop, &pThrd->delayQueue); + pThrd->quit = false; return pThrd; } @@ -851,12 +851,13 @@ static void destroyThrdObj(SCliThrdObj* pThrd) { if (pThrd == NULL) { return; } + taosThreadJoin(pThrd->thread, NULL); CLI_RELEASE_UV(pThrd->loop); taosThreadMutexDestroy(&pThrd->msgMtx); transDestroyAsyncPool(pThrd->asyncPool); - uv_timer_stop(&pThrd->timer); + transDQDestroy(pThrd->delayQueue); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); } @@ -885,6 +886,16 @@ int cliRBChoseIdx(STrans* pTransInst) { } return index % pTransInst->numOfThreads; } +static void doDelayTask(void* param) { + STaskArg* arg = param; + + SCliMsg* pMsg = arg->param1; + SCliThrdObj* pThrd = arg->param2; + + cliHandleReq(pMsg, pThrd); + + taosMemoryFree(arg); +} int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { SCliThrdObj* pThrd = pConn->hostThrd; STrans* pTransInst = pThrd->pTransInst; @@ -903,26 +914,37 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { tmsg_t msgType = pCtx->msgType; if ((pTransInst->retry != NULL && (pTransInst->retry(pResp->code))) || ((pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) && msgType == TDMT_MND_CONNECT)) { - pCtx->retryCount += 1; + pMsg->sent = 0; pMsg->st = taosGetTimestampUs(); + pCtx->retryCount += 1; if (msgType == TDMT_MND_CONNECT && pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { if (pCtx->retryCount < pEpSet->numOfEps) { pEpSet->inUse = (++pEpSet->inUse) % pEpSet->numOfEps; - cliHandleReq(pMsg, pThrd); + + STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + arg->param1 = pMsg; + arg->param2 = pThrd; + transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL); + cliDestroy((uv_handle_t*)pConn->stream); return -1; } } else if (pCtx->retryCount < TRANS_RETRY_COUNT_LIMIT) { if (pResp->contLen == 0) { - pEpSet->inUse = (pEpSet->inUse++) % pEpSet->numOfEps; + pEpSet->inUse = (++pEpSet->inUse) % pEpSet->numOfEps; } else { SMEpSet emsg = {0}; tDeserializeSMEpSet(pResp->pCont, pResp->contLen, &emsg); pCtx->epSet = emsg.epSet; } - cliHandleReq(pMsg, pThrd); - // release pConn addConnToPool(pThrd, pConn); + tTrace("use remote epset, current in use: %d, retry count%d, try limit: %d", pEpSet->inUse, pCtx->retryCount + 1, + TRANS_RETRY_COUNT_LIMIT); + + STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + arg->param1 = pMsg; + arg->param2 = pThrd; + transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL); return -1; } } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index eb42029090dadb5618457661f5c26b1f4885cc9c..01a20a466ac7419c6b803fa4b171ecd9f5e8daea 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -358,4 +358,81 @@ void transQueueDestroy(STransQueue* queue) { transQueueClear(queue); taosArrayDestroy(queue->q); } + +static int32_t timeCompare(const HeapNode* a, const HeapNode* b) { + SDelayTask* arg1 = container_of(a, SDelayTask, node); + SDelayTask* arg2 = container_of(b, SDelayTask, node); + if (arg1->execTime > arg2->execTime) { + return 0; + } else { + return 1; + } +} + +static void transDQTimeout(uv_timer_t* timer) { + SDelayQueue* queue = timer->data; + tTrace("timer %p timeout", timer); + uint64_t timeout = 0; + do { + HeapNode* minNode = heapMin(queue->heap); + if (minNode == NULL) break; + SDelayTask* task = container_of(minNode, SDelayTask, node); + if (task->execTime <= taosGetTimestampMs()) { + heapRemove(queue->heap, minNode); + task->func(task->arg); + taosMemoryFree(task); + timeout = 0; + } else { + timeout = task->execTime - taosGetTimestampMs(); + break; + } + } while (1); + if (timeout != 0) { + uv_timer_start(queue->timer, transDQTimeout, timeout, 0); + } +} +int transDQCreate(uv_loop_t* loop, SDelayQueue** queue) { + uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); + uv_timer_init(loop, timer); + + Heap* heap = heapCreate(timeCompare); + + SDelayQueue* q = taosMemoryCalloc(1, sizeof(SDelayQueue)); + q->heap = heap; + q->timer = timer; + q->loop = loop; + q->timer->data = q; + + *queue = q; + return 0; +} + +void transDQDestroy(SDelayQueue* queue) { + taosMemoryFree(queue->timer); + + while (heapSize(queue->heap) > 0) { + HeapNode* minNode = heapMin(queue->heap); + if (minNode == NULL) { + return; + } + heapRemove(queue->heap, minNode); + + SDelayTask* task = container_of(minNode, SDelayTask, node); + taosMemoryFree(task); + } + heapDestroy(queue->heap); + taosMemoryFree(queue); +} + +int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs) { + SDelayTask* task = taosMemoryCalloc(1, sizeof(SDelayTask)); + task->func = func; + task->arg = arg; + task->execTime = taosGetTimestampMs() + timeoutMs; + + tTrace("timer %p put task into queue, timeoutMs: %" PRIu64 "", queue->timer, timeoutMs); + heapInsert(queue->heap, &task->node); + uv_timer_start(queue->timer, transDQTimeout, timeoutMs, 0); + return 0; +} #endif diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index b78edf6cd0b78df00fb148ec32f015eddc15f9da..916bcb886258b550d4270166f0538baa52b7ba70 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -207,7 +207,7 @@ static bool addHandleToAcceptloop(void* arg); SExHandle* exh2 = uvAcquireExHandle(refId); \ if (exh2 == NULL || refId != exh2->refId) { \ tTrace("server handle %p except, may already freed, ignore msg, ref1: %" PRIu64 ", ref2 : %" PRIu64 "", exh1, \ - exh1->refId, refId); \ + exh2 ? exh2->refId : 0, refId); \ goto _return1; \ } \ } else if (refId == 0) { \ @@ -765,8 +765,10 @@ static void destroyConn(SSrvConn* conn, bool clear) { transDestroyBuffer(&conn->readBuf); if (clear) { tTrace("server conn %p to be destroyed", conn); - uv_shutdown_t* req = taosMemoryMalloc(sizeof(uv_shutdown_t)); - uv_shutdown(req, (uv_stream_t*)conn->pTcp, uvShutDownCb); + // uv_shutdown_t* req = taosMemoryMalloc(sizeof(uv_shutdown_t)); + uv_close((uv_handle_t*)conn->pTcp, uvDestroyConn); + // uv_close(conn->pTcp) + // uv_shutdown(req, (uv_stream_t*)conn->pTcp, uvShutDownCb); } } static void uvDestroyConn(uv_handle_t* handle) { @@ -810,16 +812,17 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, SWorkThrdObj* thrd = (SWorkThrdObj*)taosMemoryCalloc(1, sizeof(SWorkThrdObj)); thrd->quit = false; srv->pThreadObj[i] = thrd; + thrd->pTransInst = shandle; srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); - int fds[2]; - if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) { + + uv_os_sock_t fds[2]; + if (uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) { goto End; } uv_pipe_init(srv->loop, &(srv->pipe[i][0]), 1); uv_pipe_open(&(srv->pipe[i][0]), fds[1]); // init write - thrd->pTransInst = shandle; thrd->fd = fds[0]; thrd->pipe = &(srv->pipe[i][1]); // init read diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 46fa2ecd3aed5c5e99b1241f5736b04b8f50c12f..6d90773d1b0d04b803011adb97896ece705814ed 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -40,11 +40,11 @@ int wordexp(char *words, wordexp_t *pwordexp, int flags) { memset(pwordexp->wordPos, 0, 1025); if (_fullpath(pwordexp->wordPos, words, 1024) == NULL) { pwordexp->we_wordv[0] = words; - printf("failed to parse relative path:%s to abs path", words); + printf("failed to parse relative path:%s to abs path\n", words); return -1; } - printf("parse relative path:%s to abs path:%s", words, pwordexp->wordPos); + printf("parse relative path:%s to abs path:%s\n", words, pwordexp->wordPos); return 0; } @@ -72,8 +72,8 @@ void taosRemoveDir(const char *dirname) { while ((de = taosReadDir(pDir)) != NULL) { if (strcmp(taosGetDirEntryName(de), ".") == 0 || strcmp(taosGetDirEntryName(de), "..") == 0) continue; - char filename[1024]; - snprintf(filename, sizeof(filename), "%s/%s", dirname, taosGetDirEntryName(de)); + char filename[1024] = {0}; + snprintf(filename, sizeof(filename), "%s%s%s", dirname, TD_DIRSEP, taosGetDirEntryName(de)); if (taosDirEntryIsDir(de)) { taosRemoveDir(filename); } else { diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 786e58a6d261fb5eca7f4d0ecedaf9336e5f6bb1..d378b5234aedb6d8e520a7ca6781a17826def3bc 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -22,20 +22,6 @@ #define W_OK 2 #define R_OK 4 -#if defined(_MSDOS) -#define open _open -#endif - -#if defined(_WIN32) -extern int openA(const char *, int, ...); /* MsvcLibX ANSI version of open */ -extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */ -#if defined(_UTF8_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define open openU -#else /* _ANSI_SOURCE */ -#define open openA -#endif /* defined(_UTF8_SOURCE) */ -#endif /* defined(_WIN32) */ - #define _SEND_FILE_STEP_ 1000 #else @@ -228,9 +214,6 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) { void autoDelFileListAdd(const char *path) { return; } TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { -#ifdef WINDOWS - return NULL; -#else int fd = -1; FILE *fp = NULL; if (tdFileOptions & TD_FILE_STREAM) { @@ -263,7 +246,11 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { access |= (tdFileOptions & TD_FILE_APPEND) ? O_APPEND : 0; access |= (tdFileOptions & TD_FILE_TEXT) ? O_TEXT : 0; access |= (tdFileOptions & TD_FILE_EXCL) ? O_EXCL : 0; + #ifdef WINDOWS + fd = _open(path, access, _S_IREAD|_S_IWRITE); + #else fd = open(path, access, S_IRWXU | S_IRWXG | S_IRWXO); + #endif if (fd == -1) { return NULL; } @@ -286,7 +273,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { pFile->fp = fp; pFile->refId = 0; return pFile; -#endif } int64_t taosCloseFile(TdFilePtr *ppFile) { diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index ccc302e6467770f946e8a9031c63d330d185b73e..3c3612854c8a6bf8f943e55261fd61aeff340394 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -866,6 +866,16 @@ void taosSetCoreDump(bool enable) { SysNameInfo taosGetSysNameInfo() { #ifdef WINDOWS + SysNameInfo info = {0}; + DWORD dwVersion = GetVersion(); + + tstrncpy(info.sysname, getenv("OS"), sizeof(info.sysname)); + tstrncpy(info.nodename, getenv("COMPUTERNAME"), sizeof(info.nodename)); + sprintf_s(info.release, sizeof(info.release), "%d", dwVersion & 0x0F); + sprintf_s(info.version, sizeof(info.release), "%d", (dwVersion >> 8) & 0x0F); + tstrncpy(info.machine, getenv("PROCESSOR_ARCHITECTURE"), sizeof(info.machine)); + + return info; #elif defined(_TD_DARWIN_64) SysNameInfo info = {0}; diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index 18bc8831435d86ecbe5aa1be226d99403d46ffe3..a34b332b9daa9876cae89fc35b4613f597979153 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -318,6 +318,20 @@ void taosArrayClearEx(SArray* pArray, void (*fp)(void*)) { pArray->size = 0; } +void taosArrayClearP(SArray* pArray, FDelete fp) { + if (pArray == NULL) return; + if (fp == NULL) { + pArray->size = 0; + return; + } + + for (int32_t i = 0; i < pArray->size; ++i) { + fp(*(void**)TARRAY_GET_ELEM(pArray, i)); + } + + pArray->size = 0; +} + void* taosArrayDestroy(SArray* pArray) { if (pArray) { taosMemoryFree(pArray->pData); diff --git a/source/util/src/tbloomfilter.c b/source/util/src/tbloomfilter.c new file mode 100644 index 0000000000000000000000000000000000000000..52c541ae2e6b66f20f15642a92e7f4b8b57c5986 --- /dev/null +++ b/source/util/src/tbloomfilter.c @@ -0,0 +1,117 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE + +#include "tbloomfilter.h" +#include "taos.h" +#include "taoserror.h" + +#define UNIT_NUM_BITS 64 +#define UNIT_ADDR_NUM_BITS 6 + +static FORCE_INLINE bool setBit(uint64_t *buf, uint64_t index) { + uint64_t unitIndex = index >> UNIT_ADDR_NUM_BITS; + uint64_t mask = 1 << (index % UNIT_NUM_BITS); + uint64_t old = buf[unitIndex]; + buf[unitIndex] |= mask; + return buf[unitIndex] != old; +} + +static FORCE_INLINE bool getBit(uint64_t *buf, uint64_t index) { + uint64_t unitIndex = index >> UNIT_ADDR_NUM_BITS; + uint64_t mask = 1 << (index % UNIT_NUM_BITS); + return buf[unitIndex] & mask; +} + +SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate) { + if (expectedEntries < 1 || errorRate <= 0 || errorRate >= 1.0) { + return NULL; + } + SBloomFilter *pBF = taosMemoryCalloc(1, sizeof(SBloomFilter)); + if (pBF == NULL) { + return NULL; + } + pBF->expectedEntries = expectedEntries; + pBF->errorRate = errorRate; + + double lnRate = fabs(log(errorRate)); + // ln(2)^2 = 0.480453013918201 + // m = - n * ln(P) / ( ln(2) )^2 + // m is the size of bloom filter, n is expected entries, P is false positive probability + pBF->numUnits = (uint64_t) ceil(expectedEntries * lnRate / 0.480453013918201 / UNIT_NUM_BITS); + pBF->numBits = pBF->numUnits * 64; + pBF->size = 0; + + // ln(2) = 0.693147180559945 + pBF->hashFunctions = (uint32_t) ceil(lnRate / 0.693147180559945); + pBF->hashFn1 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP); + pBF->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR); + pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t)); + if (pBF->buffer == NULL) { + tBloomFilterDestroy(pBF); + return NULL; + } + return pBF; +} + +int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len) { + ASSERT(!tBloomFilterIsFull(pBF)); + uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len); + uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len); + bool hasChange = false; + const register uint64_t size = pBF->numBits; + uint64_t cbHash = h1; + for (uint64_t i = 0; i < pBF->hashFunctions; ++i) { + hasChange |= setBit(pBF->buffer, cbHash % size); + cbHash += h2; + } + if (hasChange) { + pBF->size++; + return TSDB_CODE_SUCCESS; + } + return TSDB_CODE_FAILED; +} + +int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf, + uint32_t len) { + uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len); + uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len); + const register uint64_t size = pBF->numBits; + uint64_t cbHash = h1; + for (uint64_t i = 0; i < pBF->hashFunctions; ++i) { + if (!getBit(pBF->buffer, cbHash % size)) { + return TSDB_CODE_SUCCESS; + } + cbHash += h2; + } + return TSDB_CODE_FAILED; +} + +void tBloomFilterDestroy(SBloomFilter *pBF) { + if (pBF == NULL) { + return; + } + taosMemoryFree(pBF->buffer); + taosMemoryFree(pBF); +} + +void tBloomFilterDump(const struct SBloomFilter *pBF) { +// ToDo +} + +bool tBloomFilterIsFull(const SBloomFilter *pBF) { + return pBF->size >= pBF->expectedEntries; +} \ No newline at end of file diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index cb9ef8770125988d5e5e7101be4375576f166fae..8f48e0585e79294dd65649a37a12a2fbcb17beb4 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -687,13 +687,13 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { const char *filepath = ".env"; if (envFile != NULL && strlen(envFile)>0) { if (!taosCheckExistFile(envFile)) { - uError("fial to load env file: %s", envFile); + uError("failed to load env file: %s", envFile); return -1; } filepath = envFile; }else { if (!taosCheckExistFile(filepath)) { - uInfo("fial to load env file: %s", filepath); + uInfo("failed to load env file: %s", filepath); return 0; } } @@ -826,7 +826,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { if (strncmp(url, "jsonFile", 8) == 0) { char *filepath = p; if (!taosCheckExistFile(filepath)) { - uError("fial to load json file: %s", filepath); + uError("failed to load json file: %s", filepath); return -1; } @@ -957,13 +957,13 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl const char *filepath = ".env"; if (envFile != NULL && strlen(envFile)>0) { if (!taosCheckExistFile(envFile)) { - uError("fial to load env file: %s", envFile); + uError("failed to load env file: %s", envFile); return -1; } filepath = envFile; }else { if (!taosCheckExistFile(filepath)) { - uInfo("fial to load env file: %s", filepath); + uInfo("failed to load env file: %s", filepath); return 0; } } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 8f2ba2dcc446941c884fb66e177bc4904baf2647..709efa312589409e9033c3565ab105a4a2006d0e 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -93,6 +93,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_OPS_NOT_SUPPORT, "Operation not support TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed") TAOS_DEFINE_ERROR(TSDB_CODE_CFG_NOT_FOUND, "Config not found") TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization") +TAOS_DEFINE_ERROR(TSDB_CODE_DUP_KEY, "Cannot add duplicate keys to hash") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") @@ -250,6 +251,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, "Tag does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_COLUMNS, "Too many columns") TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_ALREADY_EXIST, "Column already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_NOT_EXIST, "Column does not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SINGLE_STB_MODE_DB, "Database is single stable mode") // mnode-infoSchema TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SYS_TABLENAME, "Invalid system table name") @@ -316,6 +318,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_TSDB_STATE, "Invalid tsdb state") TAOS_DEFINE_ERROR(TSDB_CODE_VND_TB_NOT_EXIST, "Table not exists") TAOS_DEFINE_ERROR(TSDB_CODE_VND_SMA_NOT_EXIST, "SMA not exists") TAOS_DEFINE_ERROR(TSDB_CODE_VND_HASH_MISMATCH, "Hash value mismatch") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_TABLE_NOT_EXIST, "Table does not exists") // tsdb TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, "Invalid table ID") diff --git a/source/util/src/thash.c b/source/util/src/thash.c index d2b07875a36357d33309ea07d0b527de7bbd9ec4..4bbf6ccf450ae4c11685d5012d4acdf2348b551e 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -310,6 +310,7 @@ int32_t taosHashGetSize(const SHashObj *pHashObj) { int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const void *data, size_t size) { if (pHashObj == NULL || key == NULL || keyLen == 0) { + terrno = TSDB_CODE_INVALID_PTR; return -1; } @@ -378,6 +379,8 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo } doUpdateHashNode(pHashObj, pe, prev, pNode, pNewNode); + } else { + terrno = TSDB_CODE_DUP_KEY; } taosHashEntryWUnlock(pHashObj, pe); diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index d8343bc427875cffa4b64698c6e71b5e36eddd2e..8963a4f94eb23799374a355f9a44a24a6962e2e5 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -175,7 +175,6 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char if (handle != 0 && ftype == PROC_FUNC_REQ) { if (taosHashPut(pProc->hash, &handle, sizeof(int64_t), &handleRef, sizeof(int64_t)) != 0) { taosThreadMutexUnlock(&pQueue->mutex); - terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } } @@ -227,8 +226,8 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char taosThreadMutexUnlock(&pQueue->mutex); tsem_post(&pQueue->sem); - uTrace("proc:%s, push msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype, - pQueue->items, headLen, pHead, bodyLen, pBody); + uTrace("proc:%s, push msg at pos:%d ftype:%d remain:%d handle:%p ref:%" PRId64 ", head:%d %p body:%d %p", + pQueue->name, pos, ftype, pQueue->items, (void *)handle, handleRef, headLen, pHead, bodyLen, pBody); return 0; } @@ -455,25 +454,28 @@ void taosProcCleanup(SProcObj *pProc) { } int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - void *handle, int64_t handleRef, EProcFuncType ftype) { + void *handle, int64_t ref, EProcFuncType ftype) { if (ftype != PROC_FUNC_REQ) { terrno = TSDB_CODE_INVALID_PARA; return -1; } - return taosProcQueuePush(pProc, pProc->pChildQueue, pHead, headLen, pBody, bodyLen, (int64_t)handle, handleRef, - ftype); + return taosProcQueuePush(pProc, pProc->pChildQueue, pHead, headLen, pBody, bodyLen, (int64_t)handle, ref, ftype); } int64_t taosProcRemoveHandle(SProcObj *pProc, void *handle) { int64_t h = (int64_t)handle; taosThreadMutexLock(&pProc->pChildQueue->mutex); - int64_t *handleRef = taosHashGet(pProc->hash, &h, sizeof(int64_t)); + int64_t *pRef = taosHashGet(pProc->hash, &h, sizeof(int64_t)); + int64_t ref = 0; + if (pRef != NULL) { + ref = *pRef; + } + taosHashRemove(pProc->hash, &h, sizeof(int64_t)); taosThreadMutexUnlock(&pProc->pChildQueue->mutex); - if (handleRef == NULL) return 0; - return *handleRef; + return ref; } void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)) { diff --git a/source/util/src/tscalablebf.c b/source/util/src/tscalablebf.c new file mode 100644 index 0000000000000000000000000000000000000000..9ddac44e201905237fdc5a1f06950d24c699246a --- /dev/null +++ b/source/util/src/tscalablebf.c @@ -0,0 +1,106 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE + +#include "tscalablebf.h" +#include "taoserror.h" + +#define DEFAULT_GROWTH 2 +#define DEFAULT_TIGHTENING_RATIO 0.5 + +static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, + double errorRate); + +SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) { + const uint32_t defaultSize = 8; + if (expectedEntries < 1 || errorRate <= 0 || errorRate >= 1.0) { + return NULL; + } + SScalableBf *pSBf = taosMemoryCalloc(1, sizeof(SScalableBf)); + if (pSBf == NULL) { + return NULL; + } + pSBf->numBits = 0; + pSBf->bfArray = taosArrayInit(defaultSize, sizeof(void *)); + if (tScalableBfAddFilter(pSBf, expectedEntries, errorRate * DEFAULT_TIGHTENING_RATIO) == NULL ) { + tScalableBfDestroy(pSBf); + return NULL; + } + pSBf->growth = DEFAULT_GROWTH; + return pSBf; +} + +int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) { + int32_t size = taosArrayGetSize(pSBf->bfArray); + for (int32_t i = size - 2; i >= 0; --i) { + if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), + keyBuf, len) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_FAILED; + } + } + + SBloomFilter *pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1); + ASSERT(pNormalBf); + if (tBloomFilterIsFull(pNormalBf)) { + pNormalBf = tScalableBfAddFilter(pSBf, + pNormalBf->expectedEntries * pSBf->growth, + pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO); + if (pNormalBf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + return tBloomFilterPut(pNormalBf, keyBuf, len); +} + +int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf, + uint32_t len) { + int32_t size = taosArrayGetSize(pSBf->bfArray); + for (int32_t i = size - 1; i >= 0; --i) { + if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), + keyBuf, len) != TSDB_CODE_SUCCESS) { + return TSDB_CODE_FAILED; + } + } + return TSDB_CODE_SUCCESS; +} + +static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, + double errorRate) { + SBloomFilter *pNormalBf = tBloomFilterInit(expectedEntries, errorRate); + if (pNormalBf == NULL) { + return NULL; + } + if(taosArrayPush(pSBf->bfArray, &pNormalBf) == NULL) { + tBloomFilterDestroy(pNormalBf); + return NULL; + } + pSBf->numBits += pNormalBf->numBits; + return pNormalBf; +} + +void tScalableBfDestroy(SScalableBf *pSBf) { + if (pSBf == NULL) { + return; + } + if (pSBf->bfArray != NULL) { + taosArrayDestroyP(pSBf->bfArray, (FDelete)tBloomFilterDestroy); + } + taosMemoryFree(pSBf); +} + +void tScalableBfDump(const SScalableBf *pSBf) { + // Todo; +} \ No newline at end of file diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index 3c52d52d504852528874716a2237ad671e27cef4..582618ef5c78ca2390be00881a6b023b15620d2e 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -59,4 +59,12 @@ target_link_libraries(cfgTest os util gtest_main) add_test( NAME cfgTest COMMAND cfgTest +) + +# bloomFilterTest +add_executable(bloomFilterTest "bloomFilterTest.cpp") +target_link_libraries(bloomFilterTest os util gtest_main) +add_test( + NAME bloomFilterTest + COMMAND bloomFilterTest ) \ No newline at end of file diff --git a/source/util/test/bloomFilterTest.cpp b/source/util/test/bloomFilterTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fcb1b4f0aef180bc509a75b9de3cb45303789529 --- /dev/null +++ b/source/util/test/bloomFilterTest.cpp @@ -0,0 +1,140 @@ +#include + +#include "tscalablebf.h" +#include "taoserror.h" + +using namespace std; + +TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) { + int64_t ts1 = 1650803518000; + + GTEST_ASSERT_EQ(NULL, tBloomFilterInit(100, 0)); + GTEST_ASSERT_EQ(NULL, tBloomFilterInit(100, 1)); + GTEST_ASSERT_EQ(NULL, tBloomFilterInit(100, -0.1)); + GTEST_ASSERT_EQ(NULL, tBloomFilterInit(0, 0.01)); + + SBloomFilter *pBF1 = tBloomFilterInit(100, 0.005); + GTEST_ASSERT_EQ(pBF1->numBits, 1152); + GTEST_ASSERT_EQ(pBF1->numUnits, 1152/64); + int64_t count = 0; + for(int64_t i = 0; count < 100; i++) { + int64_t ts = i + ts1; + if(tBloomFilterPut(pBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { + count++; + } + } + ASSERT_TRUE(tBloomFilterIsFull(pBF1)); + + SBloomFilter *pBF2 = tBloomFilterInit(1000*10000, 0.1); + GTEST_ASSERT_EQ(pBF2->numBits, 47925312); + GTEST_ASSERT_EQ(pBF2->numUnits, 47925312/64); + + SBloomFilter *pBF3 = tBloomFilterInit(10000*10000, 0.001); + GTEST_ASSERT_EQ(pBF3->numBits, 1437758784); + GTEST_ASSERT_EQ(pBF3->numUnits, 1437758784/64); + + int64_t size = 10000; + SBloomFilter *pBF4 = tBloomFilterInit(size, 0.001); + for(int64_t i = 0; i < 1000; i++) { + int64_t ts = i + ts1; + GTEST_ASSERT_EQ(tBloomFilterPut(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); + } + ASSERT_TRUE(!tBloomFilterIsFull(pBF4)); + + for(int64_t i = 0; i < 1000; i++) { + int64_t ts = i + ts1; + GTEST_ASSERT_EQ(tBloomFilterNoContain(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_FAILED); + } + + for(int64_t i = 2000; i < 3000; i++) { + int64_t ts = i + ts1; + GTEST_ASSERT_EQ(tBloomFilterNoContain(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); + } + + tBloomFilterDestroy(pBF1); + tBloomFilterDestroy(pBF2); + tBloomFilterDestroy(pBF3); + tBloomFilterDestroy(pBF4); + +} + +TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) { + int64_t ts1 = 1650803518000; + + GTEST_ASSERT_EQ(NULL, tScalableBfInit(100, 0)); + GTEST_ASSERT_EQ(NULL, tScalableBfInit(100, 1)); + GTEST_ASSERT_EQ(NULL, tScalableBfInit(100, -0.1)); + GTEST_ASSERT_EQ(NULL, tScalableBfInit(0, 0.01)); + + SScalableBf *pSBF1 = tScalableBfInit(100, 0.01); + GTEST_ASSERT_EQ(pSBF1->numBits, 1152); + int64_t count = 0; + int64_t index = 0; + for( ; count < 100; index++) { + int64_t ts = index + ts1; + if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { + count++; + } + } + GTEST_ASSERT_EQ(pSBF1->numBits, 1152); + + for( ; count < 300; index++) { + int64_t ts = index + ts1; + if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { + count++; + } + } + GTEST_ASSERT_EQ(pSBF1->numBits, 1152+2496); + + for( ; count < 700; index++) { + int64_t ts = index + ts1; + if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { + count++; + } + } + GTEST_ASSERT_EQ(pSBF1->numBits, 1152+2496+5568); + + for( ; count < 1500; index++) { + int64_t ts = index + ts1; + if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { + count++; + } + } + GTEST_ASSERT_EQ(pSBF1->numBits, 1152+2496+5568+12288); + + int32_t aSize = taosArrayGetSize(pSBF1->bfArray); + int64_t totalBits = 0; + for(int64_t i = 0; i < aSize; i++) { + SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF1->bfArray, i); + ASSERT_TRUE(tBloomFilterIsFull(pBF)); + totalBits += pBF->numBits; + } + GTEST_ASSERT_EQ(pSBF1->numBits, totalBits); + + for(int64_t i = 0; i < index; i++) { + int64_t ts = i + ts1; + GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF1, &ts, sizeof(int64_t)), TSDB_CODE_FAILED); + } + + + int64_t size = 10000; + SScalableBf *pSBF4 = tScalableBfInit(size, 0.001); + for(int64_t i = 0; i < 1000; i++) { + int64_t ts = i + ts1; + GTEST_ASSERT_EQ(tScalableBfPut(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); + } + + for(int64_t i = 0; i < 1000; i++) { + int64_t ts = i + ts1; + GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_FAILED); + } + + for(int64_t i = 2000; i < 3000; i++) { + int64_t ts = i + ts1; + GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); + } + + tScalableBfDestroy(pSBF1); + tScalableBfDestroy(pSBF4); + +} \ No newline at end of file diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 4a3ccff08adeff8b50734028f2d15ac56d43eb0a..19a5d3ecc1e314cbbb52f7c5249afd62c3303928 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -16,6 +16,7 @@ import os import time import datetime import inspect +import traceback import psutil import shutil import pandas as pd @@ -88,6 +89,7 @@ class TDSql: caller = inspect.getframeinfo(inspect.stack()[1][0]) args = (caller.filename, caller.lineno, sql, repr(e)) tdLog.notice("%s(%d) failed: sql:%s, %s" % args) + traceback.print_exc() raise Exception(repr(e)) if row_tag: return self.queryResult diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 8fd3272055f08a8316123abd07da7656c213a5ee..f14885b72e4ed13cfb80bb747fe7dc0080187b78 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -11,7 +11,40 @@ int32_t shortColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT}; int32_t fullColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_TINYINT, TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_USMALLINT, TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_UINT, TSDB_DATA_TYPE_BIGINT, TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_BINARY, TSDB_DATA_TYPE_NCHAR}; -int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_NCHAR}; +int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_NCHAR, TSDB_DATA_TYPE_BOOL}; +int32_t optrIdxList[] = {2, 11, 6}; + +typedef struct { + char* oper; + int32_t paramNum; + bool enclose; +} OperInfo; + +OperInfo operInfo[] = { + {">", 2, false}, + {">=", 2, false}, + {"<", 2, false}, + {"<=", 2, false}, + {"=", 2, false}, + {"<>", 2, false}, + {"in", 2, true}, + {"not in", 2, true}, + + {"like", 2, false}, + {"not like", 2, false}, + {"match", 2, false}, + {"nmatch", 2, false}, +}; + +int32_t operatorList[] = {0, 1, 2, 3, 4, 5, 6, 7}; +int32_t varoperatorList[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + +char *bpStbPrefix = "st"; +char *bpTbPrefix = "t"; + + +//char *operatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in"}; +//char *varoperatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in", "like", "not like", "match", "nmatch"}; #define tListLen(x) (sizeof(x) / sizeof((x)[0])) @@ -43,62 +76,72 @@ int32_t gVarCharLen = 5; int32_t gExecLoopTimes = 1; // no change int32_t gFullColNum = tListLen(fullColList); -int insertMBSETest1(TAOS_STMT *stmt); -int insertMBSETest2(TAOS_STMT *stmt); -int insertMBMETest1(TAOS_STMT *stmt); -int insertMBMETest2(TAOS_STMT *stmt); -int insertMBMETest3(TAOS_STMT *stmt); -int insertMBMETest4(TAOS_STMT *stmt); -int insertMPMETest1(TAOS_STMT *stmt); - - - +int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos); +int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos); +int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos); +int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos); +int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos); +int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos); +int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos); +int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos); + +enum { + TTYPE_INSERT = 1, + TTYPE_QUERY, +}; typedef struct { char caseDesc[128]; int32_t colNum; int32_t *colList; // full table column list - bool autoCreate; + int32_t testType; + bool prepareStb; bool fullCol; - int32_t (*runFn)(TAOS_STMT*); + int32_t (*runFn)(TAOS_STMT*, TAOS*); int32_t tblNum; int32_t rowNum; int32_t bindRowNum; int32_t bindColNum; // equal colNum in full column case int32_t bindNullNum; int32_t runTimes; + int32_t preCaseIdx; } CaseCfg; CaseCfg gCase[] = { - {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, false, true, insertMBSETest1, 1, 10, 10, 0, 0, 1}, - {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 1}, + {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 1, 10, 10, 0, 0, 1, -1}, + {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 1, -1}, + + {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 1, -1}, + {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 1, -1}, + {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 1, -1}, + + {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 1, -1}, + {"insert:MBSE2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 1, -1}, + {"insert:MBSE2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 1, -1}, - {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 1}, - {"insert:MBSE1-C012", tListLen(fullColList), fullColList, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 1}, - {"insert:MBSE1-C002", tListLen(fullColList), fullColList, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 1}, + {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 1, -1}, + {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 1, -1}, + {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 1, -1}, - {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 1}, - {"insert:MBSE2-C012", tListLen(fullColList), fullColList, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 1}, - {"insert:MBSE2-C002", tListLen(fullColList), fullColList, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 1}, + // 11 + {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 1, -1}, + {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 1, -1}, + {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 1, -1}, - {"insert:MBME1-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 1}, - {"insert:MBME1-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 1}, - {"insert:MBME1-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 1}, + {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 1, -1}, + {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 1, -1}, + {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 1, -1}, - {"insert:MBME2-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 1}, - {"insert:MBME2-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 1}, - {"insert:MBME2-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 1}, + {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 1, -1}, + {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 1, -1}, + {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 1, -1}, - {"insert:MBME3-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 1}, - {"insert:MBME3-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 1}, - {"insert:MBME3-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 1}, + {"insert:MPME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMPMETest1, 10, 10, 2, 0, 0, 1, -1}, + {"insert:MPME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMPMETest1, 10, 10, 2, 12, 0, 1, -1}, - {"insert:MBME4-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 1}, - {"insert:MBME4-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 1}, - {"insert:MBME4-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 1}, + // 22 + {"query:SUBT-FULL", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, querySUBTTest1, 10, 10, 1, 3, 0, 1, 2}, - {"insert:MPME1-FULL", tListLen(fullColList), fullColList, false, true, insertMPMETest1, 10, 10, 2, 0, 0, 1}, - {"insert:MPME1-C012", tListLen(fullColList), fullColList, false, false, insertMPMETest1, 10, 10, 2, 12, 0, 1}, }; CaseCfg *gCurCase = NULL; @@ -106,38 +149,81 @@ CaseCfg *gCurCase = NULL; typedef struct { char caseCatalog[255]; int32_t bindNullNum; - bool autoCreate; + bool prepareStb; bool checkParamNum; bool printRes; bool printCreateTblSql; - bool printInsertSql; + bool printQuerySql; + bool printStmtSql; int32_t rowNum; //row num for one table int32_t bindColNum; int32_t bindRowNum; //row num for once bind int32_t bindColTypeNum; int32_t* bindColTypeList; + int32_t optrIdxListNum; + int32_t* optrIdxList; int32_t runTimes; - int32_t caseIdx; - int32_t caseRunNum; + int32_t caseIdx; // static case idx + int32_t caseNum; // num in static case list + int32_t caseRunIdx; // runtime case idx + int32_t caseRunNum; // total run case num } CaseCtrl; +#if 1 CaseCtrl gCaseCtrl = { .bindNullNum = 0, - .autoCreate = false, + .prepareStb = false, .printCreateTblSql = false, - .printInsertSql = true, + .printQuerySql = true, + .printStmtSql = true, .rowNum = 0, .bindColNum = 0, .bindRowNum = 0, .bindColTypeNum = 0, .bindColTypeList = NULL, + .optrIdxListNum = 0, + .optrIdxList = NULL, + .checkParamNum = false, + .printRes = true, + .runTimes = 0, +// .caseIdx = -1, +// .caseNum = -1, + .caseRunIdx = -1, +// .caseRunNum = -1, + + +// .optrIdxListNum = tListLen(optrIdxList), +// .optrIdxList = optrIdxList, +// .bindColTypeNum = tListLen(bindColTypeList), +// .bindColTypeList = bindColTypeList, + .caseIdx = 22, + .caseNum = 1, + .caseRunNum = 1, + +}; +#else +CaseCtrl gCaseCtrl = { + .bindNullNum = 0, + .prepareStb = false, + .printCreateTblSql = false, + .printQuerySql = true, + .printStmtSql = true, + .rowNum = 0, + .bindColNum = 0, + .bindRowNum = 0, + .bindColTypeNum = tListLen(bindColTypeList), + .bindColTypeList = bindColTypeList, .checkParamNum = false, .printRes = true, .runTimes = 0, - .caseIdx = -1, - .caseRunNum = -1, + .caseIdx = 2, + .caseNum = 1, + .caseRunIdx = -1, + .caseRunNum = 1, }; +#endif + int32_t taosGetTimeOfDay(struct timeval *tv) { return gettimeofday(tv, NULL); } @@ -182,7 +268,12 @@ bool colExists(TAOS_MULTI_BIND* pBind, int32_t dataType) { } void generateInsertSQL(BindData *data) { - int32_t len = sprintf(data->sql, "insert into %s ", (gCurCase->tblNum > 1 ? "? " : "t0 ")); + int32_t len = 0; + if (gCurCase->tblNum > 1) { + len = sprintf(data->sql, "insert into ? "); + } else { + len = sprintf(data->sql, "insert into %s0 ", bpTbPrefix); + } if (!gCurCase->fullCol) { len += sprintf(data->sql + len, "("); for (int c = 0; c < gCurCase->bindColNum; ++c) { @@ -233,7 +324,7 @@ void generateInsertSQL(BindData *data) { len += sprintf(data->sql + len, "ubigdata"); break; default: - printf("invalid col type:%d", data->pBind[c].buffer_type); + printf("!!!invalid col type:%d", data->pBind[c].buffer_type); exit(1); } } @@ -250,11 +341,103 @@ void generateInsertSQL(BindData *data) { } len += sprintf(data->sql + len, ")"); - if (gCaseCtrl.printInsertSql) { - printf("SQL: %s\n", data->sql); + if (gCaseCtrl.printStmtSql) { + printf("\tSQL: %s\n", data->sql); } } +void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) { + OperInfo *pInfo = NULL; + + if (gCaseCtrl.optrIdxListNum > 0) { + pInfo = &operInfo[gCaseCtrl.optrIdxList[idx]]; + } else { + if (TSDB_DATA_TYPE_VARCHAR == dataType || TSDB_DATA_TYPE_NCHAR == dataType) { + pInfo = &operInfo[varoperatorList[rand() % tListLen(varoperatorList)]]; + } else { + pInfo = &operInfo[operatorList[rand() % tListLen(operatorList)]]; + } + } + + switch (pInfo->paramNum) { + case 2: + if (pInfo->enclose) { + *len += sprintf(data->sql + *len, " %s (?)", pInfo->oper); + } else { + *len += sprintf(data->sql + *len, " %s ?", pInfo->oper); + } + break; + default: + printf("!!!invalid paramNum:%d\n", pInfo->paramNum); + exit(1); + } +} + +void generateQuerySQL(BindData *data, int32_t tblIdx) { + int32_t len = sprintf(data->sql, "select * from %s%d where ", bpTbPrefix, tblIdx); + if (!gCurCase->fullCol) { + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, " and "); + } + switch (data->pBind[c].buffer_type) { + case TSDB_DATA_TYPE_BOOL: + len += sprintf(data->sql + len, "booldata"); + break; + case TSDB_DATA_TYPE_TINYINT: + len += sprintf(data->sql + len, "tinydata"); + break; + case TSDB_DATA_TYPE_SMALLINT: + len += sprintf(data->sql + len, "smalldata"); + break; + case TSDB_DATA_TYPE_INT: + len += sprintf(data->sql + len, "intdata"); + break; + case TSDB_DATA_TYPE_BIGINT: + len += sprintf(data->sql + len, "bigdata"); + break; + case TSDB_DATA_TYPE_FLOAT: + len += sprintf(data->sql + len, "floatdata"); + break; + case TSDB_DATA_TYPE_DOUBLE: + len += sprintf(data->sql + len, "doubledata"); + break; + case TSDB_DATA_TYPE_VARCHAR: + len += sprintf(data->sql + len, "binarydata"); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + len += sprintf(data->sql + len, "ts"); + break; + case TSDB_DATA_TYPE_NCHAR: + len += sprintf(data->sql + len, "nchardata"); + break; + case TSDB_DATA_TYPE_UTINYINT: + len += sprintf(data->sql + len, "utinydata"); + break; + case TSDB_DATA_TYPE_USMALLINT: + len += sprintf(data->sql + len, "usmalldata"); + break; + case TSDB_DATA_TYPE_UINT: + len += sprintf(data->sql + len, "uintdata"); + break; + case TSDB_DATA_TYPE_UBIGINT: + len += sprintf(data->sql + len, "ubigdata"); + break; + default: + printf("!!!invalid col type:%d", data->pBind[c].buffer_type); + exit(1); + } + + bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c); + } + } + + if (gCaseCtrl.printStmtSql) { + printf("\tSTMT SQL: %s\n", data->sql); + } +} + + void generateDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) { if (bindIdx < gCurCase->bindColNum) { if (gCaseCtrl.bindColTypeNum) { @@ -378,7 +561,7 @@ int32_t prepareColData(BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; break; default: - printf("invalid col type:%d", dataType); + printf("!!!invalid col type:%d", dataType); exit(1); } @@ -389,7 +572,7 @@ int32_t prepareColData(BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t } -int32_t prepareData(BindData *data) { +int32_t prepareInsertData(BindData *data) { static int64_t tsData = 1591060628000; uint64_t allRowNum = gCurCase->rowNum * gCurCase->tblNum; @@ -417,17 +600,17 @@ int32_t prepareData(BindData *data) { for (int32_t i = 0; i < allRowNum; ++i) { data->tsData[i] = tsData++; - data->boolData[i] = i % 2; - data->tinyData[i] = i; - data->utinyData[i] = i+1; - data->smallData[i] = i; - data->usmallData[i] = i+1; - data->intData[i] = i; - data->uintData[i] = i+1; - data->bigData[i] = i; - data->ubigData[i] = i+1; - data->floatData[i] = i; - data->doubleData[i] = i+1; + data->boolData[i] = (bool)(i % 2); + data->tinyData[i] = (int8_t)i; + data->utinyData[i] = (uint8_t)(i+1); + data->smallData[i] = (int16_t)i; + data->usmallData[i] = (uint16_t)(i+1); + data->intData[i] = (int32_t)i; + data->uintData[i] = (uint32_t)(i+1); + data->bigData[i] = (int64_t)i; + data->ubigData[i] = (uint64_t)(i+1); + data->floatData[i] = (float)i; + data->doubleData[i] = (double)(i+1); memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen); if (gCurCase->bindNullNum) { data->isNull[i] = i % 2; @@ -446,6 +629,64 @@ int32_t prepareData(BindData *data) { return 0; } +int32_t prepareQueryData(BindData *data, int32_t tblIdx) { + static int64_t tsData = 1591060628000; + uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum; + + data->colNum = 0; + data->colTypes = taosMemoryCalloc(30, sizeof(int32_t)); + data->sql = taosMemoryCalloc(1, 1024); + data->pBind = taosMemoryCalloc(bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND)); + data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t)); + data->boolData = taosMemoryMalloc(bindNum * sizeof(bool)); + data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t)); + data->utinyData = taosMemoryMalloc(bindNum * sizeof(uint8_t)); + data->smallData = taosMemoryMalloc(bindNum * sizeof(int16_t)); + data->usmallData = taosMemoryMalloc(bindNum * sizeof(uint16_t)); + data->intData = taosMemoryMalloc(bindNum * sizeof(int32_t)); + data->uintData = taosMemoryMalloc(bindNum * sizeof(uint32_t)); + data->bigData = taosMemoryMalloc(bindNum * sizeof(int64_t)); + data->ubigData = taosMemoryMalloc(bindNum * sizeof(uint64_t)); + data->floatData = taosMemoryMalloc(bindNum * sizeof(float)); + data->doubleData = taosMemoryMalloc(bindNum * sizeof(double)); + data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize); + data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t)); + if (gCurCase->bindNullNum) { + data->isNull = taosMemoryCalloc(bindNum, sizeof(char)); + } + + for (int32_t i = 0; i < bindNum; ++i) { + data->tsData[i] = tsData + tblIdx*gCurCase->rowNum + rand()%gCurCase->rowNum; + data->boolData[i] = (bool)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->tinyData[i] = (int8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->utinyData[i] = (uint8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->smallData[i] = (int16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->usmallData[i] = (uint16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->intData[i] = (int32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->uintData[i] = (uint32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->bigData[i] = (int64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->ubigData[i] = (uint64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->floatData[i] = (float)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + data->doubleData[i] = (double)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum); + memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen); + if (gCurCase->bindNullNum) { + data->isNull[i] = i % 2; + } + data->binaryLen[i] = gVarCharLen; + } + + for (int b = 0; b < bindNum; b++) { + for (int c = 0; c < gCurCase->bindColNum; ++c) { + prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); + } + } + + generateQuerySQL(data, tblIdx); + + return 0; +} + + void destroyData(BindData *data) { taosMemoryFree(data->tsData); taosMemoryFree(data->boolData); @@ -466,42 +707,149 @@ void destroyData(BindData *data) { taosMemoryFree(data->colTypes); } +void bpFetchRows(TAOS_RES *result, bool printr, int32_t *rows) { + TAOS_ROW row; + int num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + char temp[256]; + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + (*rows)++; + if (printr) { + memset(temp, 0, sizeof(temp)); + taos_print_row(temp, row, fields, num_fields); + printf("\t[%s]\n", temp); + } + } +} + +void bpExecQuery(TAOS * taos, char* sql, bool printr, int32_t *rows) { + TAOS_RES *result = taos_query(taos, sql); + int code = taos_errno(result); + if (code != 0) { + printf("!!!failed to query table, reason:%s\n", taos_errstr(result)); + taos_free_result(result); + exit(1); + } + + bpFetchRows(result, printr, rows); + + taos_free_result(result); +} + + +int32_t bpAppendValueString(char *buf, int type, void *value, int32_t valueLen, int32_t *len) { + switch (type) { + case TSDB_DATA_TYPE_NULL: + *len += sprintf(buf + *len, "null"); + break; + + case TSDB_DATA_TYPE_BOOL: + *len += sprintf(buf + *len, (*(bool*)value) ? "true" : "false"); + break; + + case TSDB_DATA_TYPE_TINYINT: + *len += sprintf(buf + *len, "%d", *(int8_t*)value); + break; + + case TSDB_DATA_TYPE_SMALLINT: + *len += sprintf(buf + *len, "%d", *(int16_t*)value); + break; + + case TSDB_DATA_TYPE_INT: + *len += sprintf(buf + *len, "%d", *(int32_t*)value); + break; + + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TIMESTAMP: + *len += sprintf(buf + *len, "%ld", *(int64_t*)value); + break; + + case TSDB_DATA_TYPE_FLOAT: + *len += sprintf(buf + *len, "%e", *(float*)value); + break; + + case TSDB_DATA_TYPE_DOUBLE: + *len += sprintf(buf + *len, "%e", *(double*)value); + break; + + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + buf[*len] = '\''; + ++(*len); + memcpy(buf + *len, value, valueLen); + *len += valueLen; + buf[*len] = '\''; + ++(*len); + break; + + case TSDB_DATA_TYPE_UTINYINT: + *len += sprintf(buf + *len, "%d", *(uint8_t*)value); + break; + + case TSDB_DATA_TYPE_USMALLINT: + *len += sprintf(buf + *len, "%d", *(uint16_t*)value); + break; + + case TSDB_DATA_TYPE_UINT: + *len += sprintf(buf + *len, "%u", *(uint32_t*)value); + break; + + case TSDB_DATA_TYPE_UBIGINT: + *len += sprintf(buf + *len, "%lu", *(uint64_t*)value); + break; + + default: + printf("!!!invalid data type:%d\n", type); + exit(1); + } +} + + int32_t bpBindParam(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { static int32_t n = 0; if (gCurCase->bindRowNum > 1) { if (0 == (n++%2)) { if (taos_stmt_bind_param_batch(stmt, bind)) { - printf("taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } else { for (int32_t i = 0; i < gCurCase->bindColNum; ++i) { if (taos_stmt_bind_single_param_batch(stmt, bind++, i)) { - printf("taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } } } else { - if (taos_stmt_bind_param(stmt, bind)) { - printf("taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt)); - exit(1); + if (0 == (n++%2)) { + if (taos_stmt_bind_param_batch(stmt, bind)) { + printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } else { + if (taos_stmt_bind_param(stmt, bind)) { + printf("!!!taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } } } return 0; } -void bpCheckIsInsert(TAOS_STMT *stmt) { +void bpCheckIsInsert(TAOS_STMT *stmt, int32_t insert) { int32_t isInsert = 0; if (taos_stmt_is_insert(stmt, &isInsert)) { - printf("taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - if (0 == isInsert) { - printf("is insert failed\n"); + if (insert != isInsert) { + printf("!!!is insert failed\n"); exit(1); } } @@ -509,12 +857,12 @@ void bpCheckIsInsert(TAOS_STMT *stmt) { void bpCheckParamNum(TAOS_STMT *stmt) { int32_t num = 0; if (taos_stmt_num_params(stmt, &num)) { - printf("taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt)); exit(1); } if (gCurCase->bindColNum != num) { - printf("is insert failed\n"); + printf("!!!is insert failed\n"); exit(1); } } @@ -523,24 +871,73 @@ void bpCheckAffectedRows(TAOS_STMT *stmt, int32_t times) { int32_t rows = taos_stmt_affected_rows(stmt); int32_t insertNum = gCurCase->rowNum * gCurCase->tblNum * times; if (insertNum != rows) { - printf("affected rows %d mis-match with insert num %d\n", rows, insertNum); + printf("!!!affected rows %d mis-match with insert num %d\n", rows, insertNum); + exit(1); + } +} + +void bpCheckAffectedRowsOnce(TAOS_STMT *stmt, int32_t expectedNum) { + int32_t rows = taos_stmt_affected_rows_once(stmt); + if (expectedNum != rows) { + printf("!!!affected rows %d mis-match with expected num %d\n", rows, expectedNum); exit(1); } } +void bpCheckQueryResult(TAOS_STMT *stmt, TAOS *taos, char *stmtSql, TAOS_MULTI_BIND* bind) { + TAOS_RES* res = taos_stmt_use_result(stmt); + int32_t sqlResNum = 0; + int32_t stmtResNum = 0; + bpFetchRows(res, gCaseCtrl.printRes, &stmtResNum); + + char sql[1024]; + int32_t len = 0; + char* p = stmtSql; + char* s = NULL; + + for (int32_t i = 0; true; ++i, p=s+1) { + s = strchr(p, '?'); + if (NULL == s) { + strcpy(&sql[len], p); + break; + } + + memcpy(&sql[len], p, (int64_t)s - (int64_t)p); + len += (int64_t)s - (int64_t)p; + + if (bind[i].is_null && bind[i].is_null[0]) { + bpAppendValueString(sql, TSDB_DATA_TYPE_NULL, NULL, 0, &len); + continue; + } + + bpAppendValueString(sql, bind[i].buffer_type, bind[i].buffer, (bind[i].length ? bind[i].length[0] : 0), &len); + } + + if (gCaseCtrl.printQuerySql) { + printf("\tQuery SQL: %s\n", sql); + } + + bpExecQuery(taos, sql, gCaseCtrl.printRes, &sqlResNum); + if (sqlResNum != stmtResNum) { + printf("!!!sql res num %d mis-match stmt res num %d\n", sqlResNum, stmtResNum); + exit(1); + } + + printf("***sql res num match stmt res num %d\n", stmtResNum); +} /* prepare [settbname [bind add]] exec */ -int insertMBSETest1(TAOS_STMT *stmt) { +int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; - prepareData(&data); + prepareInsertData(&data); int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; for (int32_t t = 0; t< gCurCase->tblNum; ++t) { @@ -549,7 +946,7 @@ int insertMBSETest1(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -564,18 +961,18 @@ int insertMBSETest1(TAOS_STMT *stmt) { } if (taos_stmt_add_batch(stmt)) { - printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } } if (taos_stmt_execute(stmt) != 0) { - printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); bpCheckAffectedRows(stmt, 1); destroyData(&data); @@ -585,17 +982,17 @@ int insertMBSETest1(TAOS_STMT *stmt) { /* prepare [settbname bind add] exec */ -int insertMBSETest2(TAOS_STMT *stmt) { +int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; - prepareData(&data); + prepareInsertData(&data); int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; @@ -606,7 +1003,7 @@ int insertMBSETest2(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -620,18 +1017,18 @@ int insertMBSETest2(TAOS_STMT *stmt) { } if (taos_stmt_add_batch(stmt)) { - printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } } if (taos_stmt_execute(stmt) != 0) { - printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); bpCheckAffectedRows(stmt, 1); destroyData(&data); @@ -640,17 +1037,17 @@ int insertMBSETest2(TAOS_STMT *stmt) { } /* prepare [settbname [bind add] exec] */ -int insertMBMETest1(TAOS_STMT *stmt) { +int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; - prepareData(&data); + prepareInsertData(&data); int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; for (int32_t t = 0; t< gCurCase->tblNum; ++t) { @@ -659,7 +1056,7 @@ int insertMBMETest1(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -674,18 +1071,18 @@ int insertMBMETest1(TAOS_STMT *stmt) { } if (taos_stmt_add_batch(stmt)) { - printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } if (taos_stmt_execute(stmt) != 0) { - printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); bpCheckAffectedRows(stmt, 1); destroyData(&data); @@ -694,17 +1091,17 @@ int insertMBMETest1(TAOS_STMT *stmt) { } /* prepare [settbname [bind add exec]] */ -int insertMBMETest2(TAOS_STMT *stmt) { +int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; - prepareData(&data); + prepareInsertData(&data); int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; for (int32_t t = 0; t< gCurCase->tblNum; ++t) { @@ -713,7 +1110,7 @@ int insertMBMETest2(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -728,18 +1125,18 @@ int insertMBMETest2(TAOS_STMT *stmt) { } if (taos_stmt_add_batch(stmt)) { - printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } if (taos_stmt_execute(stmt) != 0) { - printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); bpCheckAffectedRows(stmt, 1); destroyData(&data); @@ -748,17 +1145,17 @@ int insertMBMETest2(TAOS_STMT *stmt) { } /* prepare [settbname [settbname bind add exec]] */ -int insertMBMETest3(TAOS_STMT *stmt) { +int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; - prepareData(&data); + prepareInsertData(&data); int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; for (int32_t t = 0; t< gCurCase->tblNum; ++t) { @@ -767,7 +1164,7 @@ int insertMBMETest3(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -782,7 +1179,7 @@ int insertMBMETest3(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -792,18 +1189,18 @@ int insertMBMETest3(TAOS_STMT *stmt) { } if (taos_stmt_add_batch(stmt)) { - printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } if (taos_stmt_execute(stmt) != 0) { - printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); bpCheckAffectedRows(stmt, 1); destroyData(&data); @@ -813,17 +1210,17 @@ int insertMBMETest3(TAOS_STMT *stmt) { /* prepare [settbname bind add exec] */ -int insertMBMETest4(TAOS_STMT *stmt) { +int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) { BindData data = {0}; - prepareData(&data); + prepareInsertData(&data); int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; @@ -834,7 +1231,7 @@ int insertMBMETest4(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -848,18 +1245,18 @@ int insertMBMETest4(TAOS_STMT *stmt) { } if (taos_stmt_add_batch(stmt)) { - printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } if (taos_stmt_execute(stmt) != 0) { - printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); bpCheckAffectedRows(stmt, 1); destroyData(&data); @@ -868,20 +1265,20 @@ int insertMBMETest4(TAOS_STMT *stmt) { } /* [prepare [settbname [bind add] exec]] */ -int insertMPMETest1(TAOS_STMT *stmt) { +int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) { int32_t loop = 0; while (gCurCase->bindColNum >= 2) { BindData data = {0}; - prepareData(&data); + prepareInsertData(&data); int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; for (int32_t t = 0; t< gCurCase->tblNum; ++t) { @@ -890,7 +1287,7 @@ int insertMPMETest1(TAOS_STMT *stmt) { sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } @@ -905,18 +1302,18 @@ int insertMPMETest1(TAOS_STMT *stmt) { } if (taos_stmt_add_batch(stmt)) { - printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } if (taos_stmt_execute(stmt) != 0) { - printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); exit(1); } } - bpCheckIsInsert(stmt); + bpCheckIsInsert(stmt, 1); destroyData(&data); @@ -932,6 +1329,51 @@ int insertMPMETest1(TAOS_STMT *stmt) { return 0; } +int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos) { + BindData data = {0}; + + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + memset(&data, 0, sizeof(data)); + prepareQueryData(&data, t); + + int code = taos_stmt_prepare(stmt, data.sql, 0); + if (code != 0){ + printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + for (int32_t n = 0; n< (gCurCase->rowNum/gCurCase->bindRowNum); ++n) { + bpCheckIsInsert(stmt, 0); + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum)) { + exit(1); + } + + if (taos_stmt_add_batch(stmt)) { + printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + bpCheckQueryResult(stmt, taos, data.sql, data.pBind + n * gCurCase->bindColNum); + } + + bpCheckIsInsert(stmt, 0); + + destroyData(&data); + } + + return 0; +} + #if 0 @@ -3807,59 +4249,35 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) { } #endif -void prepareCheckResultImpl(TAOS *taos, char *tname, bool printr, int expected) { - char sql[255] = "SELECT * FROM "; - TAOS_RES *result; +void prepareCheckResultImpl(TAOS * taos, char *tname, bool printr, int expected, bool silent) { + char sql[255] = "SELECT * FROM "; + int32_t rows = 0; + strcat(sql, tname); - - result = taos_query(taos, sql); - int code = taos_errno(result); - if (code != 0) { - printf("failed to query table, reason:%s\n", taos_errstr(result)); - taos_free_result(result); - exit(1); - } - - - TAOS_ROW row; - int rows = 0; - int num_fields = taos_num_fields(result); - TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; - - // fetch the records row by row - while ((row = taos_fetch_row(result))) { - rows++; - if (printr) { - memset(temp, 0, sizeof(temp)); - taos_print_row(temp, row, fields, num_fields); - printf("[%s]\n", temp); - } - } + bpExecQuery(taos, sql, printr, &rows); if (rows == expected) { - printf("%d rows are fetched as expected from %s\n", rows, tname); + if (!silent) { + printf("***%d rows are fetched as expected from %s\n", rows, tname); + } } else { - printf("!!!expect %d rows, but %d rows are fetched from %s\n", expected, rows, tname); + printf("!!!expect rows %d mis-match rows %d fetched from %s\n", expected, rows, tname); exit(1); } - - taos_free_result(result); - } -void prepareCheckResult(TAOS *taos) { +void prepareCheckResult(TAOS *taos, bool silent) { char buf[32]; for (int32_t t = 0; t< gCurCase->tblNum; ++t) { if (gCurCase->tblNum > 1) { - sprintf(buf, "t%d", t); + sprintf(buf, "%s%d", bpTbPrefix, t); } else { - sprintf(buf, "t%d", 0); + sprintf(buf, "%s%d", bpTbPrefix, 0); } - prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes); + prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes, silent); } gExecLoopTimes = 1; @@ -3894,7 +4312,7 @@ int sql_perf1(TAOS *taos) { result = taos_query(taos, sql[i]); int code = taos_errno(result); if (code != 0) { - printf("failed to query table, reason:%s\n", taos_errstr(result)); + printf("%d failed to query table, reason:%s\n", taos_errstr(result)); taos_free_result(result); exit(1); } @@ -4013,7 +4431,7 @@ int sql_s_perf1(TAOS *taos) { void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) { int32_t blen = 0; - blen = sprintf(buf, "create table %s%d ", (stable ? "st" : "t"), tblIdx); + blen = sprintf(buf, "create table %s%d ", (stable ? bpStbPrefix : bpTbPrefix), tblIdx); if (stable) { blen += sprintf(buf + blen, "tags ("); for (int c = 0; c < colNum; ++c) { @@ -4131,11 +4549,11 @@ void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t * blen += sprintf(buf + blen, ")"); if (gCaseCtrl.printCreateTblSql) { - printf("Create Table SQL:%s\n", buf); + printf("\tCreate Table SQL:%s\n", buf); } } -void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int autoCreate) { +void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int prepareStb) { TAOS_RES *result; int code; @@ -4145,7 +4563,7 @@ void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int autoCreate) { result = taos_query(taos, "create database demo keep 36500"); code = taos_errno(result); if (code != 0) { - printf("failed to create database, reason:%s\n", taos_errstr(result)); + printf("!!!failed to create database, reason:%s\n", taos_errstr(result)); taos_free_result(result); exit(1); } @@ -4154,7 +4572,7 @@ void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int autoCreate) { result = taos_query(taos, "use demo"); taos_free_result(result); - if (!autoCreate) { + if (!prepareStb) { // create table for (int i = 0 ; i < 10; i++) { char buf[1024]; @@ -4162,7 +4580,7 @@ void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int autoCreate) { result = taos_query(taos, buf); code = taos_errno(result); if (code != 0) { - printf("failed to create table, reason:%s\n", taos_errstr(result)); + printf("!!!failed to create table, reason:%s\n", taos_errstr(result)); taos_free_result(result); exit(1); } @@ -4175,7 +4593,7 @@ void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int autoCreate) { result = taos_query(taos, buf); code = taos_errno(result); if (code != 0) { - printf("failed to create table, reason:%s\n", taos_errstr(result)); + printf("!!!failed to create table, reason:%s\n", taos_errstr(result)); taos_free_result(result); exit(1); } @@ -4184,82 +4602,115 @@ void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int autoCreate) { } -void* runcase(TAOS *taos) { +int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) { TAOS_STMT *stmt = NULL; - static int32_t caseIdx = 0; - static int32_t caseRunNum = 0; - int64_t beginUs, endUs, totalUs; - - for (int32_t i = 0; i < sizeof(gCase)/sizeof(gCase[0]); ++i) { - if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) { - break; - } + int64_t beginUs, endUs, totalUs; + CaseCfg cfg = gCase[caseIdx]; + gCurCase = &cfg; + + if ((gCaseCtrl.bindColTypeNum || gCaseCtrl.bindColNum) && (gCurCase->colNum != gFullColNum)) { + return 1; + } + + if (gCurCase->preCaseIdx >= 0) { + bool printRes = gCaseCtrl.printRes; + bool printStmtSql = gCaseCtrl.printStmtSql; + gCaseCtrl.printRes = false; + gCaseCtrl.printStmtSql = false; + runCase(taos, gCurCase->preCaseIdx, caseRunIdx, true); + gCaseCtrl.printRes = printRes; + gCaseCtrl.printStmtSql = printStmtSql; - CaseCfg cfg = gCase[i]; gCurCase = &cfg; + } + + if (gCaseCtrl.runTimes) { + gCurCase->runTimes = gCaseCtrl.runTimes; + } + + if (gCaseCtrl.rowNum) { + gCurCase->rowNum = gCaseCtrl.rowNum; + } + + if (gCurCase->fullCol) { + gCurCase->bindColNum = gCurCase->colNum; + } + + gCurCase->bindNullNum = gCaseCtrl.bindNullNum; + gCurCase->prepareStb = gCaseCtrl.prepareStb; + if (gCaseCtrl.bindColNum) { + gCurCase->bindColNum = gCaseCtrl.bindColNum; + gCurCase->fullCol = false; + } + if (gCaseCtrl.bindRowNum) { + gCurCase->bindRowNum = gCaseCtrl.bindRowNum; + } + if (gCaseCtrl.bindColTypeNum) { + gCurCase->bindColNum = gCaseCtrl.bindColTypeNum; + gCurCase->fullCol = false; + } - if ((gCaseCtrl.bindColTypeNum || gCaseCtrl.bindColNum) && (gCurCase->colNum != gFullColNum)) { - continue; - } - - if (gCaseCtrl.caseIdx >= 0 && caseIdx < gCaseCtrl.caseIdx) { - caseIdx++; - continue; - } - - if (gCaseCtrl.runTimes) { - gCurCase->runTimes = gCaseCtrl.runTimes; - } - - if (gCaseCtrl.rowNum) { - gCurCase->rowNum = gCaseCtrl.rowNum; + if (!silent) { + printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc); + } + + totalUs = 0; + for (int32_t n = 0; n < gCurCase->runTimes; ++n) { + if (gCurCase->preCaseIdx < 0) { + prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->prepareStb); } - if (gCurCase->fullCol) { - gCurCase->bindColNum = gCurCase->colNum; - } - - gCurCase->bindNullNum = gCaseCtrl.bindNullNum; - gCurCase->autoCreate = gCaseCtrl.autoCreate; - if (gCaseCtrl.bindColNum) { - gCurCase->bindColNum = gCaseCtrl.bindColNum; - gCurCase->fullCol = false; - } - if (gCaseCtrl.bindRowNum) { - gCurCase->bindRowNum = gCaseCtrl.bindRowNum; - } - if (gCaseCtrl.bindColTypeNum) { - gCurCase->bindColNum = gCaseCtrl.bindColTypeNum; - gCurCase->fullCol = false; + beginUs = taosGetTimestampUs(); + + stmt = taos_stmt_init(taos); + if (NULL == stmt) { + printf("!!!taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } + + (*gCurCase->runFn)(stmt, taos); + + taos_stmt_close(stmt); + + endUs = taosGetTimestampUs(); + totalUs += (endUs - beginUs); - printf("* Case %d - [%s]%s Begin *\n", caseIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc); + prepareCheckResult(taos, silent); + } - totalUs = 0; - for (int32_t n = 0; n < gCurCase->runTimes; ++n) { - prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->autoCreate); + if (!silent) { + printf("* Case %d - [%s]%s [AvgTime:%.3fms] End *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc, ((double)totalUs)/1000/gCurCase->runTimes); + } + + return 0; +} - beginUs = taosGetTimestampUs(); - - stmt = taos_stmt_init(taos); - if (NULL == stmt) { - printf("taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt)); - exit(1); - } +void* runCaseList(TAOS *taos) { + static int32_t caseRunIdx = 0; + static int32_t caseRunNum = 0; + int32_t caseNum = 0; + int32_t caseIdx = (gCaseCtrl.caseIdx >= 0) ? gCaseCtrl.caseIdx : 0; - (*gCurCase->runFn)(stmt); + for (int32_t i = caseIdx; i < sizeof(gCase)/sizeof(gCase[0]); ++i) { + if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) { + break; + } - taos_stmt_close(stmt); + if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) { + break; + } - endUs = taosGetTimestampUs(); - totalUs += (endUs - beginUs); + if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) { + caseRunIdx++; + continue; + } - prepareCheckResult(taos); + if (runCase(taos, i, caseRunIdx, false)) { + continue; } - - printf("* Case %d - [%s]%s [AvgTime:%.3fms] End *\n", caseIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc, ((double)totalUs)/1000/gCurCase->runTimes); - caseIdx++; + caseRunIdx++; + caseNum++; caseRunNum++; } @@ -4269,51 +4720,51 @@ void* runcase(TAOS *taos) { void runAll(TAOS *taos) { strcpy(gCaseCtrl.caseCatalog, "Normal Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); - runcase(taos); + runCaseList(taos); strcpy(gCaseCtrl.caseCatalog, "Null Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.bindNullNum = 1; - runcase(taos); + runCaseList(taos); gCaseCtrl.bindNullNum = 0; strcpy(gCaseCtrl.caseCatalog, "Bind Row Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.bindRowNum = 1; - runcase(taos); + runCaseList(taos); gCaseCtrl.bindRowNum = 0; strcpy(gCaseCtrl.caseCatalog, "Row Num Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.rowNum = 1000; gCaseCtrl.printRes = false; - runcase(taos); + runCaseList(taos); gCaseCtrl.rowNum = 0; gCaseCtrl.printRes = true; strcpy(gCaseCtrl.caseCatalog, "Runtimes Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.runTimes = 2; - runcase(taos); + runCaseList(taos); gCaseCtrl.runTimes = 0; strcpy(gCaseCtrl.caseCatalog, "Check Param Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.checkParamNum = true; - runcase(taos); + runCaseList(taos); gCaseCtrl.checkParamNum = false; strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.bindColNum = 6; - runcase(taos); + runCaseList(taos); gCaseCtrl.bindColNum = 0; strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList); gCaseCtrl.bindColTypeList = bindColTypeList; - runcase(taos); + runCaseList(taos); printf("All Test End\n"); } diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index ba4296f9bf8ee76f293ab8e03632b909e3ada747..d1c5e8397554ffa97ff45d4435f894da894405b8 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -69,7 +69,7 @@ ./test.sh -f tsim/stable/dnode3.sim ./test.sh -f tsim/stable/metrics.sim ./test.sh -f tsim/stable/refcount.sim -# ./test.sh -f tsim/stable/show.sim +#./test.sh -f tsim/stable/show.sim ./test.sh -f tsim/stable/values.sim ./test.sh -f tsim/stable/vnode3.sim @@ -81,7 +81,7 @@ ./test.sh -f tsim/insert/backquote.sim -m ./test.sh -f tsim/parser/fourArithmetic-basic.sim -m ./test.sh -f tsim/query/interval-offset.sim -m -#./test.sh -f tsim/tmq/basic1.sim -m +./test.sh -f tsim/tmq/basic3.sim -m ./test.sh -f tsim/stable/vnode3.sim -m ./test.sh -f tsim/qnode/basic1.sim -m ./test.sh -f tsim/mnode/basic1.sim -m diff --git a/tests/script/tsim/db/alter_option.sim b/tests/script/tsim/db/alter_option.sim index 1f0c2043e8ecd51cf9e1bea1a32d9237ae510e51..417e53daff1f703a5a109c96fe39e2199a75063c 100644 --- a/tests/script/tsim/db/alter_option.sim +++ b/tests/script/tsim/db/alter_option.sim @@ -58,15 +58,15 @@ endi print ============= create database #database_option: { -# BLOCKS value [3~1000, default: 6] +# | BUFFER value [3~16384, default: 96] +# | PAGES value [64~16384, default: 256] # | CACHELAST value [0, 1, 2, 3] # | FSYNC value [0 ~ 180000 ms] # | KEEP value [days, 365000] -# | QUORUM value [1 | 2] # | REPLICA value [1 | 3] # | WAL value [1 | 2] -sql create database db BLOCKS 7 CACHE 3 CACHELAST 3 COMP 0 DAYS 345600 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1440000 PRECISION 'ns' REPLICA 1 TTL 7 WAL 2 VGROUPS 6 SINGLE_STABLE 1 STREAM_MODE 1 +sql create database db CACHELAST 3 COMP 0 DAYS 345600 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1440000 PRECISION 'ns' REPLICA 1 WAL 2 VGROUPS 6 SINGLE_STABLE 1 sql show databases print rows: $rows print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 @@ -98,31 +98,34 @@ endi if $data7_db != 1440000,1440000,1440000 then # keep return -1 endi -if $data8_db != 3 then # cache +if $data8_db != 96 then # buffer return -1 endi -if $data9_db != 7 then # blocks +if $data9_db != 4 then # pagesize return -1 endi -if $data10_db != 10 then # minrows +if $data10_db != 256 then # pages return -1 endi -if $data11_db != 8000 then # maxrows +if $data11_db != 10 then # minrows return -1 endi -if $data12_db != 2 then # wal +if $data12_db != 8000 then # maxrows return -1 endi -if $data13_db != 1000 then # fsync +if $data13_db != 2 then # wal return -1 endi -if $data14_db != 0 then # comp +if $data14_db != 1000 then # fsync return -1 endi -if $data15_db != 3 then # cachelast +if $data15_db != 0 then # comp return -1 endi -if $data16_db != ns then # precision +if $data16_db != 3 then # cachelast + return -1 +endi +if $data17_db != ns then # precision return -1 endi @@ -250,41 +253,41 @@ sql_error alter database db keep 0 sql_error alter database db keep -1 #sql_error alter database db keep 365001 -print ============== modify cache -sql_error alter database db cache 12 -sql_error alter database db cache 1 -sql_error alter database db cache 60 -sql_error alter database db cache 50 -sql_error alter database db cache 20 -sql_error alter database db cache 3 -sql_error alter database db cache 129 -sql_error alter database db cache 300 -sql_error alter database db cache 0 -sql_error alter database db cache -1 +#print ============== modify cache +#sql_error alter database db cache 12 +#sql_error alter database db cache 1 +#sql_error alter database db cache 60 +#sql_error alter database db cache 50 +#sql_error alter database db cache 20 +#sql_error alter database db cache 3 +#sql_error alter database db cache 129 +#sql_error alter database db cache 300 +#sql_error alter database db cache 0 +#sql_error alter database db cache -1 -print ============== modify blocks -sql alter database db blocks 3 -sql show databases -print blocks $data9_db -if $data9_db != 3 then - return -1 -endi -sql alter database db blocks 11 -sql show databases -print blocks $data9_db -if $data9_db != 11 then - return -1 -endi +#print ============== modify blocks +#sql alter database db blocks 3 +#sql show databases +#print blocks $data9_db +#if $data9_db != 3 then +# return -1 +#endi +#sql alter database db blocks 11 +#sql show databases +#print blocks $data9_db +#if $data9_db != 11 then +# return -1 +#endi -sql alter database db blocks 40 -sql alter database db blocks 30 -sql alter database db blocks 20 -sql alter database db blocks 10 -sql_error alter database db blocks 2 -sql_error alter database db blocks 1 -sql_error alter database db blocks 0 -sql_error alter database db blocks -1 -sql_error alter database db blocks 10001 +#sql alter database db blocks 40 +#sql alter database db blocks 30 +#sql alter database db blocks 20 +#sql alter database db blocks 10 +#sql_error alter database db blocks 2 +#sql_error alter database db blocks 1 +#sql_error alter database db blocks 0 +#sql_error alter database db blocks -1 +#sql_error alter database db blocks 10001 print ============== modify minrows sql_error alter database db minrows 8 @@ -302,14 +305,14 @@ sql_error alter database db maxrows 10 # little than minrows print ============== step wal sql alter database db wal 1 sql show databases -print wal $data12_db -if $data12_db != 1 then +print wal $data13_db +if $data13_db != 1 then return -1 endi sql alter database db wal 2 sql show databases -print wal $data12_db -if $data12_db != 2 then +print wal $data13_db +if $data13_db != 2 then return -1 endi @@ -321,20 +324,20 @@ sql_error alter database db wal -1 print ============== modify fsync sql alter database db fsync 2000 sql show databases -print fsync $data13_db -if $data13_db != 2000 then +print fsync $data14_db +if $data14_db != 2000 then return -1 endi sql alter database db fsync 500 sql show databases -print fsync $data13_db -if $data13_db != 500 then +print fsync $data14_db +if $data14_db != 500 then return -1 endi sql alter database db fsync 0 sql show databases -print fsync $data13_db -if $data13_db != 0 then +print fsync $data14_db +if $data14_db != 0 then return -1 endi sql_error alter database db fsync 180001 @@ -353,32 +356,32 @@ sql_error alter database db comp -1 print ============== modify cachelast [0, 1, 2, 3] sql alter database db cachelast 2 sql show databases -print cachelast $data15_db -if $data15_db != 2 then +print cachelast $data16_db +if $data16_db != 2 then return -1 endi sql alter database db cachelast 1 sql show databases -print cachelast $data15_db -if $data15_db != 1 then +print cachelast $data16_db +if $data16_db != 1 then return -1 endi sql alter database db cachelast 0 sql show databases -print cachelast $data15_db -if $data15_db != 0 then +print cachelast $data16_db +if $data16_db != 0 then return -1 endi sql alter database db cachelast 2 sql show databases -print cachelast $data15_db -if $data15_db != 2 then +print cachelast $data16_db +if $data16_db != 2 then return -1 endi sql alter database db cachelast 3 sql show databases -print cachelast $data15_db -if $data15_db != 3 then +print cachelast $data16_db +if $data16_db != 3 then return -1 endi diff --git a/tests/script/tsim/db/basic6.sim b/tests/script/tsim/db/basic6.sim index f682dcc8162d6db4049c241ee4b6ba6abe336865..8075e54f9ee053c288787c546e16f9734f470ee9 100644 --- a/tests/script/tsim/db/basic6.sim +++ b/tests/script/tsim/db/basic6.sim @@ -15,7 +15,8 @@ $tb = $tbPrefix . $i print =============== step1 # quorum presicion -sql create database $db vgroups 8 replica 1 days 2880 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us' +#sql create database $db vgroups 8 replica 1 days 2880 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us' +sql create database $db vgroups 8 replica 1 days 2880 keep 3650 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us' sql show databases print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 @@ -40,12 +41,12 @@ endi if $data27 != 3650,3650,3650 then return -1 endi -if $data28 != 32 then - return -1 -endi -if $data29 != 12 then - return -1 -endi +#if $data28 != 32 then +# return -1 +#endi +#if $data29 != 12 then +# return -1 +#endi print =============== step2 sql_error create database $db diff --git a/tests/script/tsim/db/create_all_options.sim b/tests/script/tsim/db/create_all_options.sim index cd6a7ee28b442fb7507be11cb68cd1cd308f2ca0..d7d72c4a1df1116d563c2f9283994e9807eac9d7 100644 --- a/tests/script/tsim/db/create_all_options.sim +++ b/tests/script/tsim/db/create_all_options.sim @@ -58,8 +58,9 @@ endi print ============= create database with all options #database_option: { -# | BLOCKS value [3~1000, default: 6] -# | CACHE value [default: 16] +# | BUFFER value [3~16384, default: 96] +# | PAGES value [64~16384, default: 256] +# | PAGESIZE value [1~16384, default: 4] # | CACHELAST value [0, 1, 2, 3, default: 0] # | COMP [0 | 1 | 2, default: 2] # | DAYS value [60m ~ min(3650d,keep), default: 10d, unit may be minut/hour/day] @@ -68,24 +69,18 @@ print ============= create database with all options # | MINROWS value [10~1000, default: 100] # | KEEP value [max(1d ~ 365000d), default: 1d, unit may be minut/hour/day] # | PRECISION ['ms' | 'us' | 'ns', default: ms] -# | QUORUM value [1 | 2, default: 1] # | REPLICA value [1 | 3, default: 1] -# | TTL value [1d ~ , default: 1] # | WAL value [1 | 2, default: 1] # | VGROUPS value [default: 2] # | SINGLE_STABLE [0 | 1, default: ] -# | STREAM_MODE [0 | 1, default: ] # #$data0_db : name #$data1_db : create_time #$data2_db : vgroups #$data3_db : ntables #$data4_db : replica -#$data5_db : quorum #$data6_db : days #$data7_db : keep -#$data8_db : cache -#$data9_db : blocks #$data10_db : minrows #$data11_db : maxrows #$data12_db : wal @@ -124,77 +119,80 @@ endi if $data7_db != 5256000,5256000,5256000 then # keep return -1 endi -if $data8_db != 16 then # cache +if $data8_db != 96 then # buffer return -1 endi -if $data9_db != 6 then # blocks +if $data9_db != 4 then # pagesize return -1 endi -if $data10_db != 100 then # minrows +if $data10_db != 256 then # pages return -1 endi -if $data11_db != 4096 then # maxrows +if $data11_db != 100 then # minrows return -1 endi -if $data12_db != 1 then # wal +if $data12_db != 4096 then # maxrows return -1 endi -if $data13_db != 3000 then # fsync +if $data13_db != 1 then # wal return -1 endi -if $data14_db != 2 then # comp +if $data14_db != 3000 then # fsync return -1 endi -if $data15_db != 0 then # cachelast +if $data15_db != 2 then # comp return -1 endi -if $data16_db != ms then # precision +if $data16_db != 0 then # cachelast return -1 endi -sql drop database db - -print ====> BLOCKS value [3~1000, default: 6] -sql create database db BLOCKS 3 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data9_db != 3 then +if $data17_db != ms then # precision return -1 endi sql drop database db -sql create database db BLOCKS 1000 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data9_db != 1000 then - return -1 -endi -sql drop database db -sql_error create database db BLOCKS 2 -sql_error create database db BLOCKS 0 -sql_error create database db BLOCKS -1 +#print ====> BLOCKS value [3~1000, default: 6] +#sql create database db BLOCKS 3 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data9_db != 3 then +# return -1 +#endi +#sql drop database db -print ====> CACHE value [default: 16] -sql create database db CACHE 1 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data8_db != 1 then - return -1 -endi -sql drop database db +#sql create database db BLOCKS 1000 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data9_db != 1000 then +# return -1 +#endi +#sql drop database db +#sql_error create database db BLOCKS 2 +#sql_error create database db BLOCKS 0 +#sql_error create database db BLOCKS -1 -sql create database db CACHE 128 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data8_db != 128 then - return -1 -endi -sql drop database db +#print ====> CACHE value [default: 16] +#sql create database db CACHE 1 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data8_db != 1 then +# return -1 +#endi +#sql drop database db + +#sql create database db CACHE 128 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#if $data8_db != 128 then +# return -1 +#endi +#sql drop database db print ====> CACHELAST value [0, 1, 2, 3, default: 0] sql create database db CACHELAST 1 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data15_db != 1 then +if $data16_db != 1 then return -1 endi sql drop database db @@ -202,7 +200,7 @@ sql drop database db sql create database db CACHELAST 2 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data15_db != 2 then +if $data16_db != 2 then return -1 endi sql drop database db @@ -210,7 +208,7 @@ sql drop database db sql create database db CACHELAST 3 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data15_db != 3 then +if $data16_db != 3 then return -1 endi sql drop database db @@ -221,7 +219,7 @@ print ====> COMP [0 | 1 | 2, default: 2] sql create database db COMP 1 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data14_db != 1 then +if $data15_db != 1 then return -1 endi sql drop database db @@ -229,7 +227,7 @@ sql drop database db sql create database db COMP 0 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data14_db != 0 then +if $data15_db != 0 then return -1 endi sql drop database db @@ -280,7 +278,7 @@ print ====> FSYNC value [0 ~ 180000 ms, default: 3000] sql create database db FSYNC 0 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data13_db != 0 then +if $data14_db != 0 then return -1 endi sql drop database db @@ -288,7 +286,7 @@ sql drop database db sql create database db FSYNC 180000 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data13_db != 180000 then +if $data14_db != 180000 then return -1 endi sql drop database db @@ -299,10 +297,10 @@ print ====> MAXROWS value [200~10000, default: 4096], MINROWS value [10~1000, de sql create database db MAXROWS 10000 MINROWS 1000 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data10_db != 1000 then +if $data11_db != 1000 then return -1 endi -if $data11_db != 10000 then +if $data12_db != 10000 then return -1 endi sql drop database db @@ -310,10 +308,10 @@ sql drop database db sql create database db MAXROWS 200 MINROWS 10 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data10_db != 10 then +if $data11_db != 10 then return -1 endi -if $data11_db != 200 then +if $data12_db != 200 then return -1 endi sql drop database db @@ -331,7 +329,7 @@ print ====> PRECISION ['ms' | 'us' | 'ns', default: ms] sql create database db PRECISION 'us' sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data16_db != us then +if $data17_db != us then return -1 endi sql drop database db @@ -339,15 +337,15 @@ sql drop database db sql create database db PRECISION 'ns' sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data16_db != ns then +if $data17_db != ns then return -1 endi sql drop database db sql_error create database db PRECISION 'as' sql_error create database db PRECISION -1 -print ====> QUORUM value [1 | 2, default: 1] -#sql create database db QUORUM 2 +print ====> QUORUM value [1 | 2, default: 1] 3.0 not support this item +#sql_error create database db QUORUM 2 #sql show databases #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #if $data5_db != 2 then @@ -362,9 +360,11 @@ print ====> QUORUM value [1 | 2, default: 1] # return -1 #endi #sql drop database db -#sql_error create database db QUORUM 3 -#sql_error create database db QUORUM 0 -#sql_error create database db QUORUM -1 +sql_error create database db QUORUM 1 +sql_error create database db QUORUM 2 +sql_error create database db QUORUM 3 +sql_error create database db QUORUM 0 +sql_error create database db QUORUM -1 print ====> REPLICA value [1 | 3, default: 1] sql create database db REPLICA 3 @@ -387,30 +387,30 @@ sql_error create database db REPLICA 0 sql_error create database db REPLICA -1 sql_error create database db REPLICA 4 -print ====> TTL value [1d ~ , default: 1] -sql create database db TTL 1 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#print ====> TTL value [1d ~ , default: 1] +#sql create database db TTL 1 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #if $dataXX_db != 1 then # return -1 #endi -sql drop database db +#sql drop database db -sql create database db TTL 10 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#sql create database db TTL 10 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #if $dataXX_db != 10 then # return -1 #endi -sql drop database db -sql_error create database db TTL 0 -sql_error create database db TTL -1 +#sql drop database db +#sql_error create database db TTL 0 +#sql_error create database db TTL -1 print ====> WAL value [1 | 2, default: 1] sql create database db WAL 2 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data12_db != 2 then +if $data13_db != 2 then return -1 endi sql drop database db @@ -418,7 +418,7 @@ sql drop database db sql create database db WAL 1 sql show databases print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $data12_db != 1 then +if $data13_db != 1 then return -1 endi sql drop database db @@ -465,24 +465,24 @@ sql drop database db sql_error create database db SINGLE_STABLE 2 sql_error create database db SINGLE_STABLE -1 -print ====> STREAM_MODE [0 | 1, default: ] -sql create database db STREAM_MODE 1 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#print ====> STREAM_MODE [0 | 1, default: ] +#sql create database db STREAM_MODE 1 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #if $dataXXX_db != 1 then # return -1 #endi -sql drop database db +#sql drop database db -sql create database db STREAM_MODE 0 -sql show databases -print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db +#sql create database db STREAM_MODE 0 +#sql show databases +#print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #if $dataXXX_db != 0 then # return -1 #endi -sql drop database db -sql_error create database db STREAM_MODE 2 -sql_error create database db STREAM_MODE -1 +#sql drop database db +#sql_error create database db STREAM_MODE 2 +#sql_error create database db STREAM_MODE -1 system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT diff --git a/tests/script/tsim/parser/fourArithmetic-basic.sim b/tests/script/tsim/parser/fourArithmetic-basic.sim index dde451279d1c3d783a1077e20f1e3304b4e084c3..bd01813c61716c80b7fbd5bb9b6474090cd43cb2 100644 --- a/tests/script/tsim/parser/fourArithmetic-basic.sim +++ b/tests/script/tsim/parser/fourArithmetic-basic.sim @@ -94,7 +94,7 @@ endi if $data01 != 10.000000000 then return -1 endi -if $data02 != -nan then +if $data02 != NULL then return -1 endi if $data03 != -10.000000000 then diff --git a/tests/script/tsim/query/complex_having.sim b/tests/script/tsim/query/complex_having.sim index 86d4f7d4ca109035f1f9420debf449d18a5f89b9..ef58228f342f7f38460ebced4e9867dced0c9b44 100644 --- a/tests/script/tsim/query/complex_having.sim +++ b/tests/script/tsim/query/complex_having.sim @@ -215,6 +215,7 @@ sql select count(c1) from stb1 print ====> sql : select count(c1) from stb1 print ====> rows: $data00 if $data00 != 20 then + print expect 20, actual: $data00 return -1 endi diff --git a/tests/script/tsim/show/basic.sim b/tests/script/tsim/show/basic.sim index ca6cd1c11a7af848172c8e3c7f4e5e3947b897d8..e171d1abb9e3249c5b93ae01899b596e6238a4c4 100644 --- a/tests/script/tsim/show/basic.sim +++ b/tests/script/tsim/show/basic.sim @@ -3,9 +3,6 @@ system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode2 -i 2 system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode2 -s start - -# after mnode support, del sleep 2000, and check dnode status -sleep 2000 sql connect #$loop_cnt = 0 @@ -101,7 +98,7 @@ if $rows != 1 then endi #sql select * from information_schema.user_streams sql select * from information_schema.user_tables -if $rows != 1 then +if $rows != 28 then return -1 endi #sql select * from information_schema.user_table_distributed @@ -199,7 +196,7 @@ if $rows != 1 then endi #sql select * from information_schema.user_streams sql select * from information_schema.user_tables -if $rows != 1 then +if $rows != 28 then return -1 endi #sql select * from information_schema.user_table_distributed diff --git a/tests/script/tsim/sync/oneReplica1VgElect.sim b/tests/script/tsim/sync/oneReplica1VgElect.sim index 8e99bc4b2eaee0c1343c29f0335ee2e46f51db64..bb9b3f449640818d888137721350b0cea90eebae 100644 --- a/tests/script/tsim/sync/oneReplica1VgElect.sim +++ b/tests/script/tsim/sync/oneReplica1VgElect.sim @@ -83,7 +83,7 @@ print $data(db)[13] $data(db)[14] $data(db)[15] $data(db)[16] $data(db)[17] $dat if $rows != 3 then return -1 endi -if $data(db)[20] != ready then +if $data(db)[19] != ready then goto check_db_ready endi diff --git a/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim b/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim index e85d5ea4373d2e27ee219a6918fd859468c3d5da..7ceeb2806b320014c2b35ea5c640063e44793063 100644 --- a/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim +++ b/tests/script/tsim/sync/oneReplica1VgElectWithInsert.sim @@ -83,7 +83,7 @@ print $data(db)[13] $data(db)[14] $data(db)[15] $data(db)[16] $data(db)[17] $dat if $rows != 3 then return -1 endi -if $data(db)[20] != ready then +if $data(db)[19] != ready then goto check_db_ready endi diff --git a/tests/script/tsim/sync/threeReplica1VgElect.sim b/tests/script/tsim/sync/threeReplica1VgElect.sim index e06bd86daa0b8927db25d6dd706423a6385184e1..7f8c8339cbb44de39cb0da9dca12c19159209d3f 100644 --- a/tests/script/tsim/sync/threeReplica1VgElect.sim +++ b/tests/script/tsim/sync/threeReplica1VgElect.sim @@ -83,7 +83,7 @@ print $data(db)[13] $data(db)[14] $data(db)[15] $data(db)[16] $data(db)[17] $dat if $rows != 3 then return -1 endi -if $data(db)[20] != ready then +if $data(db)[19] != ready then goto check_db_ready endi diff --git a/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim b/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim index 797baea811ab9519d3310c8a0be2bb9708bcceb5..1e12e8565feedc200151b64d37bc6663b4e09b53 100644 --- a/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim +++ b/tests/script/tsim/sync/threeReplica1VgElectWihtInsert.sim @@ -83,7 +83,7 @@ print $data(db)[13] $data(db)[14] $data(db)[15] $data(db)[16] $data(db)[17] $dat if $rows != 3 then return -1 endi -if $data(db)[20] != ready then +if $data(db)[19] != ready then goto check_db_ready endi diff --git a/tests/script/tsim/tmq/prepareBasicEnv-1vgrp.sim b/tests/script/tsim/tmq/prepareBasicEnv-1vgrp.sim index db56bcf743dfa2cb10e1f3c8dca5213c6cc0d09a..e32a1df8025f1105ffcaee8e0f081149cb756f91 100644 --- a/tests/script/tsim/tmq/prepareBasicEnv-1vgrp.sim +++ b/tests/script/tsim/tmq/prepareBasicEnv-1vgrp.sim @@ -39,7 +39,7 @@ sql show databases print ==> rows: $rows print ==> $data(db)[0] $data(db)[1] $data(db)[2] $data(db)[3] $data(db)[4] $data(db)[5] $data(db)[6] $data(db)[7] $data(db)[8] $data(db)[9] $data(db)[10] $data(db)[11] $data(db)[12] print $data(db)[13] $data(db)[14] $data(db)[15] $data(db)[16] $data(db)[17] $data(db)[18] $data(db)[19] $data(db)[20] -if $data(db)[20] != nostrict then +if $data(db)[19] != nostrict then sleep 100 $loop_cnt = $loop_cnt + 1 goto check_db_ready diff --git a/tests/script/tsim/tmq/prepareBasicEnv-4vgrp.sim b/tests/script/tsim/tmq/prepareBasicEnv-4vgrp.sim index d7fa58558f97ae82ce4e643cbb259fbe815e9ccf..4750aab214e074408f3076cdd0533315fa436ea5 100644 --- a/tests/script/tsim/tmq/prepareBasicEnv-4vgrp.sim +++ b/tests/script/tsim/tmq/prepareBasicEnv-4vgrp.sim @@ -39,7 +39,7 @@ sql show databases print ==> rows: $rows print ==> $data(db)[0] $data(db)[1] $data(db)[2] $data(db)[3] $data(db)[4] $data(db)[5] $data(db)[6] $data(db)[7] $data(db)[8] $data(db)[9] $data(db)[10] $data(db)[11] $data(db)[12] print $data(db)[13] $data(db)[14] $data(db)[15] $data(db)[16] $data(db)[17] $data(db)[18] $data(db)[19] $data(db)[20] -if $data(db)[20] != nostrict then +if $data(db)[19] != nostrict then sleep 100 $loop_cnt = $loop_cnt + 1 goto check_db_ready diff --git a/tests/system-test/0-others/taosShell.py b/tests/system-test/0-others/taosShell.py index 3c3508a5c302a9eb44a787720fa87f30848f83d4..f6dfe3f75c795ab8bd8eefc7b9d043d75854dc2e 100644 --- a/tests/system-test/0-others/taosShell.py +++ b/tests/system-test/0-others/taosShell.py @@ -11,13 +11,15 @@ from util.sql import * from util.cases import * from util.dnodes import * -def taos_command (key, value, expectString, cfgDir, sqlString='', key1='', value1=''): +def taos_command (buildPath, key, value, expectString, cfgDir, sqlString='', key1='', value1=''): if len(key) == 0: tdLog.exit("taos test key is null!") - + + taosCmd = buildPath + '/build/bin/taos ' if len(cfgDir) != 0: - taosCmd = 'taos -c ' + cfgDir + ' -' + key + taosCmd = taosCmd + '-c ' + cfgDir + taosCmd = taosCmd + ' -' + key if len(value) != 0: if key == 'p': taosCmd = taosCmd + value @@ -55,12 +57,12 @@ def taos_command (key, value, expectString, cfgDir, sqlString='', key1='', value else: return "TAOS_FAIL" else: - if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C': + if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C' or key == 'V' or key1 == 'V': return "TAOS_OK", retResult else: return "TAOS_OK" else: - if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C': + if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C' or key == 'V' or key1 == 'V': return "TAOS_OK", retResult else: return "TAOS_FAIL" @@ -70,17 +72,20 @@ class TDTestCase: # 'serverPort': 7080, 'firstEp': 'trd02:7080'} hostname = socket.gethostname() serverPort = '7080' - clientCfgDict = {'serverPort': '', 'firstEp': '', 'secondEp':''} - clientCfgDict["serverPort"] = serverPort - clientCfgDict["firstEp"] = hostname + ':' + serverPort - clientCfgDict["secondEp"] = hostname + ':' + serverPort - - - updatecfgDict = {'clientCfg': {}, 'serverPort': '', 'firstEp': '', 'secondEp':''} + rpcDebugFlagVal = '143' + clientCfgDict = {'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} + clientCfgDict["serverPort"] = serverPort + clientCfgDict["firstEp"] = hostname + ':' + serverPort + clientCfgDict["secondEp"] = hostname + ':' + serverPort + clientCfgDict["rpcDebugFlag"] = rpcDebugFlagVal + clientCfgDict["fqdn"] = hostname + + updatecfgDict = {'clientCfg': {}, 'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} updatecfgDict["clientCfg"] = clientCfgDict updatecfgDict["serverPort"] = serverPort updatecfgDict["firstEp"] = hostname + ':' + serverPort updatecfgDict["secondEp"] = hostname + ':' + serverPort + updatecfgDict["fqdn"] = hostname print ("===================: ", updatecfgDict) @@ -109,8 +114,8 @@ class TDTestCase: # time.sleep(2) tdSql.query("create user testpy pass 'testpy'") - hostname = socket.gethostname() - tdLog.info ("hostname: %s" % hostname) + #hostname = socket.gethostname() + #tdLog.info ("hostname: %s" % hostname) buildPath = self.getBuildPath() if (buildPath == ""): @@ -126,13 +131,14 @@ class TDTestCase: keyDict = {'h':'', 'P':'6030', 'p':'testpy', 'u':'testpy', 'a':'', 'A':'', 'c':'', 'C':'', 's':'', 'r':'', 'f':'', \ 'k':'', 't':'', 'n':'', 'l':'1024', 'N':'100', 'V':'', 'd':'db', 'w':'30', '-help':'', '-usage':'', '?':''} - keyDict['h'] = hostname + keyDict['h'] = self.hostname keyDict['c'] = cfgPath + keyDict['P'] = self.serverPort tdLog.printNoPrefix("================================ parameter: -h") newDbName="dbh" sqlString = 'create database ' + newDbName + ';' - retCode = taos_command("h", keyDict['h'], "taos>", keyDict['c'], sqlString) + retCode = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], sqlString) if retCode != "TAOS_OK": tdLog.exit("taos -h %s fail"%keyDict['h']) else: @@ -155,7 +161,7 @@ class TDTestCase: #keyDict['P'] = 6030 newDbName = "dbpp" sqlString = 'create database ' + newDbName + ';' - retCode = taos_command("P", keyDict['P'], "taos>", keyDict['c'], sqlString) + retCode = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], sqlString) if retCode != "TAOS_OK": tdLog.exit("taos -P %s fail"%keyDict['P']) else: @@ -171,7 +177,7 @@ class TDTestCase: tdLog.printNoPrefix("================================ parameter: -u") newDbName="dbu" sqlString = 'create database ' + newDbName + ';' - retCode = taos_command("u", keyDict['u'], "taos>", keyDict['c'], sqlString, "p", keyDict['p']) + retCode = taos_command(buildPath, "u", keyDict['u'], "taos>", keyDict['c'], sqlString, "p", keyDict['p']) if retCode != "TAOS_OK": tdLog.exit("taos -u %s -p%s fail"%(keyDict['u'], keyDict['p'])) else: @@ -186,12 +192,12 @@ class TDTestCase: tdLog.printNoPrefix("================================ parameter: -A") newDbName="dbaa" - retCode, retVal = taos_command("p", keyDict['p'], "taos>", keyDict['c'], '', "A", '') + retCode, retVal = taos_command(buildPath, "p", keyDict['p'], "taos>", keyDict['c'], '', "A", '') if retCode != "TAOS_OK": tdLog.exit("taos -A fail") sqlString = 'create database ' + newDbName + ';' - retCode = taos_command("u", keyDict['u'], "taos>", keyDict['c'], sqlString, 'a', retVal) + retCode = taos_command(buildPath, "u", keyDict['u'], "taos>", keyDict['c'], sqlString, 'a', retVal) if retCode != "TAOS_OK": tdLog.exit("taos -u %s -a %s"%(keyDict['u'], retVal)) @@ -207,7 +213,7 @@ class TDTestCase: tdLog.printNoPrefix("================================ parameter: -s") newDbName="dbss" keyDict['s'] = "\"create database " + newDbName + "\"" - retCode = taos_command("s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') if retCode != "TAOS_OK": tdLog.exit("taos -s fail") @@ -220,17 +226,17 @@ class TDTestCase: tdLog.exit("create db fail after taos -s %s fail"%(keyDict['s'])) keyDict['s'] = "\"create table " + newDbName + ".stb (ts timestamp, c int) tags (t int)\"" - retCode = taos_command("s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') if retCode != "TAOS_OK": tdLog.exit("taos -s create table fail") keyDict['s'] = "\"create table " + newDbName + ".ctb0 using " + newDbName + ".stb tags (0) " + newDbName + ".ctb1 using " + newDbName + ".stb tags (1)\"" - retCode = taos_command("s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') if retCode != "TAOS_OK": tdLog.exit("taos -s create table fail") keyDict['s'] = "\"insert into " + newDbName + ".ctb0 values('2021-04-01 08:00:00.000', 10)('2021-04-01 08:00:01.000', 20) " + newDbName + ".ctb1 values('2021-04-01 08:00:00.000', 11)('2021-04-01 08:00:01.000', 21)\"" - retCode = taos_command("s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') if retCode != "TAOS_OK": tdLog.exit("taos -s insert data fail") @@ -248,18 +254,18 @@ class TDTestCase: tdSql.checkData(1, 1, 21) keyDict['s'] = "\"select * from " + newDbName + ".ctb0\"" - retCode = taos_command("s", keyDict['s'], "2021-04-01 08:00:01.000", keyDict['c'], '', '', '') + retCode = taos_command(buildPath, "s", keyDict['s'], "2021-04-01 08:00:01.000", keyDict['c'], '', '', '') if retCode != "TAOS_OK": tdLog.exit("taos -r show fail") tdLog.printNoPrefix("================================ parameter: -r") keyDict['s'] = "\"select * from " + newDbName + ".ctb0\"" - retCode = taos_command("s", keyDict['s'], "1617235200000", keyDict['c'], '', 'r', '') + retCode = taos_command(buildPath, "s", keyDict['s'], "1617235200000", keyDict['c'], '', 'r', '') if retCode != "TAOS_OK": tdLog.exit("taos -r show fail") keyDict['s'] = "\"select * from " + newDbName + ".ctb1\"" - retCode = taos_command("s", keyDict['s'], "1617235201000", keyDict['c'], '', 'r', '') + retCode = taos_command(buildPath, "s", keyDict['s'], "1617235201000", keyDict['c'], '', 'r', '') if retCode != "TAOS_OK": tdLog.exit("taos -r show fail") @@ -281,10 +287,10 @@ class TDTestCase: os.system(sql5) keyDict['f'] = pwd + "/0-others/sql.txt" - retCode = taos_command("f", keyDict['f'], 'performance_schema', keyDict['c'], '', '', '') + retCode = taos_command(buildPath, "f", keyDict['f'], 'performance_schema', keyDict['c'], '', '', '') print("============ ret code: ", retCode) if retCode != "TAOS_OK": - tdLog.exit("taos -s fail") + tdLog.exit("taos -f fail") print ("========== check new db ==========") tdSql.query("show databases") @@ -307,14 +313,110 @@ class TDTestCase: tdSql.query('drop database %s'%newDbName) tdLog.printNoPrefix("================================ parameter: -C") - newDbName="dbcc" - retCode, retVal = taos_command("C", keyDict['C'], "buildinfo", keyDict['c'], '', '', '') + #newDbName="dbcc" + retCode, retVal = taos_command(buildPath, "C", keyDict['C'], "buildinfo", keyDict['c'], '', '', '') if retCode != "TAOS_OK": tdLog.exit("taos -C fail") - print ("-C return content:\n ", retVal) + + #print ("-C return content:\n ", retVal) + totalCfgItem = {"firstEp":['', '', ''], } + for line in retVal.splitlines(): + strList = line.split() + if (len(strList) > 2): + totalCfgItem[strList[1]] = strList + + #print ("dict content:\n ", totalCfgItem) + firstEp = keyDict["h"] + ':' + keyDict['P'] + if (totalCfgItem["firstEp"][2] != firstEp) and (totalCfgItem["firstEp"][0] != 'cfg_file'): + tdLog.exit("taos -C return firstEp error!") + + if (totalCfgItem["rpcDebugFlag"][2] != self.rpcDebugFlagVal) and (totalCfgItem["rpcDebugFlag"][0] != 'cfg_file'): + tdLog.exit("taos -C return rpcDebugFlag error!") + count = os.cpu_count() + if (totalCfgItem["numOfCores"][2] != count) and (totalCfgItem["numOfCores"][0] != 'default'): + tdLog.exit("taos -C return numOfCores error!") + + version = totalCfgItem["version"][2] + + tdLog.printNoPrefix("================================ parameter: -V") + #newDbName="dbvv" + retCode, retVal = taos_command(buildPath, "V", keyDict['V'], "", keyDict['c'], '', '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -V fail") + + version = 'version: ' + version + retVal = retVal.replace("\n", "") + retVal = retVal.replace("\r", "") + if retVal != version: + print ("return version: [%s]"%retVal) + print ("dict version: [%s]"%version) + tdLog.exit("taos -V version not match") + + tdLog.printNoPrefix("================================ parameter: -d") + newDbName="dbd" + sqlString = 'create database ' + newDbName + ';' + retCode = taos_command(buildPath, "d", keyDict['d'], "taos>", keyDict['c'], sqlString, '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -d %s fail"%(keyDict['d'])) + else: + tdSql.query("show databases") + for i in range(tdSql.queryRows): + if tdSql.getData(i, 0) == newDbName: + break + else: + tdLog.exit("create db fail after taos -d %s fail"%(keyDict['d'])) + + tdSql.query('drop database %s'%newDbName) + + retCode = taos_command(buildPath, "d", 'dbno', "taos>", keyDict['c'], sqlString, '', '') + if retCode != "TAOS_FAIL": + tdLog.exit("taos -d dbno fail") + + tdLog.printNoPrefix("================================ parameter: -w") + newDbName="dbw" + keyDict['s'] = "\"create database " + newDbName + "\"" + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -w fail") + keyDict['s'] = "\"create table " + newDbName + ".ntb (ts timestamp, c binary(128))\"" + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -w create table fail") + + keyDict['s'] = "\"insert into " + newDbName + ".ntb values('2021-04-01 08:00:00.001', 'abcd0123456789')('2021-04-01 08:00:00.002', 'abcd012345678901234567890123456789') \"" + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -w insert data fail") + + keyDict['s'] = "\"insert into " + newDbName + ".ntb values('2021-04-01 08:00:00.003', 'aaaaaaaaaaaaaaaaaaaa')('2021-04-01 08:00:01.004', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb') \"" + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -w insert data fail") + + keyDict['s'] = "\"insert into " + newDbName + ".ntb values('2021-04-01 08:00:00.005', 'cccccccccccccccccccc')('2021-04-01 08:00:01.006', 'dddddddddddddddddddddddddddddddddddddddd') \"" + retCode = taos_command(buildPath, "s", keyDict['s'], "Query OK", keyDict['c'], '', '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -w insert data fail") + + keyDict['s'] = "\"select * from " + newDbName + ".ntb \"" + retCode = taos_command(buildPath, "s", keyDict['s'], "aaaaaaaaaaaaaaaaaaaa", keyDict['c'], '', '', '') + if retCode != "TAOS_OK": + tdLog.exit("taos -w insert data fail") + + keyDict['s'] = "\"select * from " + newDbName + ".ntb \"" + retCode = taos_command(buildPath, "s", keyDict['s'], "dddddddddddddddddddddddddddddddddddddddd", keyDict['c'], '', '', '') + if retCode != "TAOS_FAIL": + tdLog.exit("taos -w insert data fail") + + keyDict['s'] = "\"select * from " + newDbName + ".ntb \"" + retCode = taos_command(buildPath, "s", keyDict['s'], "dddddddddddddddddddddddddddddddddddddddd", keyDict['c'], '', 'w', '60') + if retCode != "TAOS_OK": + tdLog.exit("taos -w insert data fail") + + tdSql.query('drop database %s'%newDbName) def stop(self): tdSql.close() diff --git a/tests/system-test/0-others/taosShellError.py b/tests/system-test/0-others/taosShellError.py new file mode 100644 index 0000000000000000000000000000000000000000..5f2f79982a58fe33e361f7c05926fc7c276f84d7 --- /dev/null +++ b/tests/system-test/0-others/taosShellError.py @@ -0,0 +1,282 @@ + +import taos +import sys +import time +import socket +import pexpect +import os + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + +def taos_command (buildPath, key, value, expectString, cfgDir, sqlString='', key1='', value1=''): + if len(key) == 0: + tdLog.exit("taos test key is null!") + + taosCmd = buildPath + '/build/bin/taos ' + if len(cfgDir) != 0: + taosCmd = taosCmd + '-c ' + cfgDir + + taosCmd = taosCmd + ' -' + key + if len(value) != 0: + if key == 'p': + taosCmd = taosCmd + value + else: + taosCmd = taosCmd + ' ' + value + + if len(key1) != 0: + taosCmd = taosCmd + ' -' + key1 + if key1 == 'p': + taosCmd = taosCmd + value1 + else: + if len(value1) != 0: + taosCmd = taosCmd + ' ' + value1 + + tdLog.info ("taos cmd: %s" % taosCmd) + + child = pexpect.spawn(taosCmd, timeout=3) + #output = child.readline() + #print (output.decode()) + if len(expectString) != 0: + i = child.expect([expectString, pexpect.TIMEOUT, pexpect.EOF], timeout=6) + else: + i = child.expect([pexpect.TIMEOUT, pexpect.EOF], timeout=6) + + retResult = child.before.decode() + print("cmd return result:\n%s\n"%retResult) + #print(child.after.decode()) + if i == 0: + print ('taos login success! Here can run sql, taos> ') + if len(sqlString) != 0: + child.sendline (sqlString) + w = child.expect(["Query OK", pexpect.TIMEOUT, pexpect.EOF], timeout=1) + retResult = child.before.decode() + if w == 0: + return "TAOS_OK", retResult + else: + return "TAOS_FAIL", retResult + else: + if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C' or key == 'V' or key1 == 'V': + return "TAOS_OK", retResult + else: + return "TAOS_OK", retResult + else: + if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C' or key == 'V' or key1 == 'V': + return "TAOS_OK", retResult + else: + return "TAOS_FAIL", retResult + +class TDTestCase: + #updatecfgDict = {'clientCfg': {'serverPort': 7080, 'firstEp': 'trd02:7080', 'secondEp':'trd02:7080'},\ + # 'serverPort': 7080, 'firstEp': 'trd02:7080'} + hostname = socket.gethostname() + serverPort = '7080' + rpcDebugFlagVal = '143' + clientCfgDict = {'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} + clientCfgDict["serverPort"] = serverPort + clientCfgDict["firstEp"] = hostname + ':' + serverPort + clientCfgDict["secondEp"] = hostname + ':' + serverPort + clientCfgDict["rpcDebugFlag"] = rpcDebugFlagVal + clientCfgDict["fqdn"] = hostname + + updatecfgDict = {'clientCfg': {}, 'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} + updatecfgDict["clientCfg"] = clientCfgDict + updatecfgDict["serverPort"] = serverPort + updatecfgDict["firstEp"] = hostname + ':' + serverPort + updatecfgDict["secondEp"] = hostname + ':' + serverPort + updatecfgDict["fqdn"] = hostname + + print ("===================: ", updatecfgDict) + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring + tdSql.prepare() + # time.sleep(2) + tdSql.query("create user testpy pass 'testpy'") + + #hostname = socket.gethostname() + #tdLog.info ("hostname: %s" % hostname) + + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + cfgPath = buildPath + "/../sim/psim/cfg" + tdLog.info("cfgPath: %s" % cfgPath) + + checkNetworkStatus = ['0: unavailable', '1: network ok', '2: service ok', '3: service degraded', '4: exiting'] + netrole = ['client', 'server'] + + keyDict = {'h':'', 'P':'6030', 'p':'testpy', 'u':'testpy', 'a':'', 'A':'', 'c':'', 'C':'', 's':'', 'r':'', 'f':'', \ + 'k':'', 't':'', 'n':'', 'l':'1024', 'N':'100', 'V':'', 'd':'db', 'w':'30', '-help':'', '-usage':'', '?':''} + + keyDict['h'] = self.hostname + keyDict['c'] = cfgPath + keyDict['P'] = self.serverPort + + tdLog.printNoPrefix("================================ parameter: -h wiht error value") + #newDbName="dbh" + #sqlString = 'create database ' + newDbName + ';' + keyDict['h'] = 'abc' + retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -h %s test suceess"%keyDict['h']) + else: + tdLog.exit("taos -h %s fail"%keyDict['h']) + + keyDict['h'] = '\'abc\'' + retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -h %s test suceess"%keyDict['h']) + else: + tdLog.exit("taos -h %s fail"%keyDict['h']) + + keyDict['h'] = '3' + retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -h %s test suceess"%keyDict['h']) + else: + tdLog.exit("taos -h %s fail"%keyDict['h']) + + keyDict['h'] = '\'3\'' + retCode, retVal = taos_command(buildPath, "h", keyDict['h'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -h %s test suceess"%keyDict['h']) + else: + tdLog.exit("taos -h %s fail"%keyDict['h']) + + tdLog.printNoPrefix("================================ parameter: -P wiht error value") + #newDbName="dbh" + #sqlString = 'create database ' + newDbName + ';' + keyDict['P'] = 'abc' + retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Invalid port" in retVal): + tdLog.info("taos -P %s test suceess"%keyDict['P']) + else: + tdLog.exit("taos -P %s fail"%keyDict['P']) + + keyDict['P'] = '\'abc\'' + retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Invalid port" in retVal): + tdLog.info("taos -P %s test suceess"%keyDict['P']) + else: + tdLog.exit("taos -P %s fail"%keyDict['P']) + + keyDict['P'] = '3' + retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -P %s test suceess"%keyDict['P']) + else: + tdLog.exit("taos -P %s fail"%keyDict['P']) + + keyDict['P'] = '\'3\'' + retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -P %s test suceess"%keyDict['P']) + else: + tdLog.exit("taos -P %s fail"%keyDict['P']) + + keyDict['P'] = '12ab' + retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -P %s test suceess"%keyDict['P']) + else: + tdLog.exit("taos -P %s fail"%keyDict['P']) + + keyDict['P'] = '\'12ab\'' + retCode, retVal = taos_command(buildPath, "P", keyDict['P'], "taos>", keyDict['c'], '') + if (retCode == "TAOS_FAIL") and ("Unable to establish connection" in retVal): + tdLog.info("taos -P %s test suceess"%keyDict['P']) + else: + tdLog.exit("taos -P %s fail"%keyDict['P']) + + tdLog.printNoPrefix("================================ parameter: -f with error sql ") + pwd=os.getcwd() + newDbName="dbf" + sqlFile = pwd + "/0-others/sql.txt" + sql1 = "echo 'create database " + newDbName + "' > " + sqlFile + sql2 = "echo 'use " + newDbName + "' >> " + sqlFile + sql3 = "echo 'create table ntbf (ts timestamp, c binary(40)) no this item' >> " + sqlFile + sql4 = "echo 'insert into ntbf values (\"2021-04-01 08:00:00.000\", \"test taos -f1\")(\"2021-04-01 08:00:01.000\", \"test taos -f2\")' >> " + sqlFile + sql5 = "echo 'show databases' >> " + sqlFile + os.system(sql1) + os.system(sql2) + os.system(sql3) + os.system(sql4) + os.system(sql5) + + keyDict['f'] = pwd + "/0-others/sql.txt" + retCode, retVal = taos_command(buildPath, "f", keyDict['f'], 'performance_schema', keyDict['c'], '', '', '') + #print("============ ret code: ", retCode) + if retCode != "TAOS_OK": + tdLog.exit("taos -f fail") + + print ("========== check new db ==========") + tdSql.query("show databases") + for i in range(tdSql.queryRows): + #print ("dbseq: %d, dbname: %s"%(i, tdSql.getData(i, 0))) + if tdSql.getData(i, 0) == newDbName: + break + else: + tdLog.exit("create db fail after taos -f fail") + + sqlString = "select * from " + newDbName + ".ntbf" + tdSql.error(sqlString) + + shellCmd = "rm -f " + sqlFile + os.system(shellCmd) + + keyDict['f'] = pwd + "/0-others/noexistfile.txt" + retCode, retVal = taos_command(buildPath, "f", keyDict['f'], 'failed to open file', keyDict['c'], '', '', '') + #print("============ ret code: ", retCode) + if retCode != "TAOS_OK": + tdLog.exit("taos -f fail") + + tdSql.query('drop database %s'%newDbName) + + tdLog.printNoPrefix("================================ parameter: -a with error value") + #newDbName="dba" + errorPassword = 'errorPassword' + sqlString = 'create database ' + newDbName + ';' + retCode, retVal = taos_command(buildPath, "u", keyDict['u'], "taos>", keyDict['c'], sqlString, 'a', errorPassword) + if retCode != "TAOS_FAIL": + tdLog.exit("taos -u %s -a %s"%(keyDict['u'], errorPassword)) + + tdLog.printNoPrefix("================================ parameter: -p with error value") + #newDbName="dba" + keyDict['p'] = 'errorPassword' + retCode, retVal = taos_command(buildPath, "u", keyDict['u'], "taos>", keyDict['c'], sqlString, 'p', keyDict['p']) + if retCode == "TAOS_FAIL" and "Authentication failure" in retVal: + tdLog.info("taos -p %s test suceess"%keyDict['p']) + else: + tdLog.exit("taos -u %s -p %s"%(keyDict['u'], keyDict['p'])) + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/0-others/taosShellNetChk.py b/tests/system-test/0-others/taosShellNetChk.py new file mode 100644 index 0000000000000000000000000000000000000000..524268101afcca88e06bdbed4da0bdd55e6633b5 --- /dev/null +++ b/tests/system-test/0-others/taosShellNetChk.py @@ -0,0 +1,202 @@ + +import taos +import sys +import time +import socket +import pexpect +import os + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + +def taos_command (buildPath, key, value, expectString, cfgDir, sqlString='', key1='', value1=''): + if len(key) == 0: + tdLog.exit("taos test key is null!") + + taosCmd = buildPath + '/build/bin/taos ' + if len(cfgDir) != 0: + taosCmd = taosCmd + '-c ' + cfgDir + + taosCmd = taosCmd + ' -' + key + if len(value) != 0: + if key == 'p': + taosCmd = taosCmd + value + else: + taosCmd = taosCmd + ' ' + value + + if len(key1) != 0: + taosCmd = taosCmd + ' -' + key1 + if key1 == 'p': + taosCmd = taosCmd + value1 + else: + if len(value1) != 0: + taosCmd = taosCmd + ' ' + value1 + + tdLog.info ("taos cmd: %s" % taosCmd) + + child = pexpect.spawn(taosCmd, timeout=3) + #output = child.readline() + #print (output.decode()) + if len(expectString) != 0: + i = child.expect([expectString, pexpect.TIMEOUT, pexpect.EOF], timeout=6) + else: + i = child.expect([pexpect.TIMEOUT, pexpect.EOF], timeout=6) + + retResult = child.before.decode() + print("expect() return code: %d, content:\n %s\n"%(i, retResult)) + #print(child.after.decode()) + if i == 0: + print ('taos login success! Here can run sql, taos> ') + if len(sqlString) != 0: + child.sendline (sqlString) + w = child.expect(["Query OK", pexpect.TIMEOUT, pexpect.EOF], timeout=1) + retResult = child.before.decode() + if w == 0: + return "TAOS_OK", retResult + else: + return "TAOS_FAIL", retResult + else: + if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C' or key == 'V' or key1 == 'V': + return "TAOS_OK", retResult + else: + return "TAOS_OK", retResult + else: + if key == 'A' or key1 == 'A' or key == 'C' or key1 == 'C' or key == 'V' or key1 == 'V': + return "TAOS_OK", retResult + else: + return "TAOS_FAIL", retResult + +class TDTestCase: + #updatecfgDict = {'clientCfg': {'serverPort': 7080, 'firstEp': 'trd02:7080', 'secondEp':'trd02:7080'},\ + # 'serverPort': 7080, 'firstEp': 'trd02:7080'} + hostname = socket.gethostname() + serverPort = '7080' + rpcDebugFlagVal = '143' + clientCfgDict = {'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} + clientCfgDict["serverPort"] = serverPort + clientCfgDict["firstEp"] = hostname + ':' + serverPort + clientCfgDict["secondEp"] = hostname + ':' + serverPort + clientCfgDict["rpcDebugFlag"] = rpcDebugFlagVal + clientCfgDict["fqdn"] = hostname + + updatecfgDict = {'clientCfg': {}, 'serverPort': '', 'firstEp': '', 'secondEp':'', 'rpcDebugFlag':'135', 'fqdn':''} + updatecfgDict["clientCfg"] = clientCfgDict + updatecfgDict["serverPort"] = serverPort + updatecfgDict["firstEp"] = hostname + ':' + serverPort + updatecfgDict["secondEp"] = hostname + ':' + serverPort + updatecfgDict["fqdn"] = hostname + + print ("===================: ", updatecfgDict) + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring + tdSql.prepare() + tdSql.query("create user testpy pass 'testpy'") + + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + cfgPath = buildPath + "/../sim/psim/cfg" + tdLog.info("cfgPath: %s" % cfgPath) + + checkNetworkStatus = ['0: unavailable', '1: network ok', '2: service ok', '3: service degraded', '4: exiting'] + netrole = ['client', 'server'] + + keyDict = {'h':'', 'P':'6030', 'p':'testpy', 'u':'testpy', 'a':'', 'A':'', 'c':'', 'C':'', 's':'', 'r':'', 'f':'', \ + 'k':'', 't':'', 'n':'', 'l':'1024', 'N':'100', 'V':'', 'd':'db', 'w':'30', '-help':'', '-usage':'', '?':''} + + keyDict['h'] = self.hostname + keyDict['c'] = cfgPath + keyDict['P'] = self.serverPort + + tdLog.printNoPrefix("================================ parameter: -k") + sqlString = '' + retCode, retVal = taos_command(buildPath, "k", '', "", keyDict['c'], sqlString) + if "2: service ok" in retVal: + tdLog.info("taos -k success") + else: + tdLog.exit("taos -k fail") + + # stop taosd + tdDnodes.stop(1) + #sleep(10) + #tdDnodes.start(1) + #sleep(5) + retCode, retVal = taos_command(buildPath, "k", '', "", keyDict['c'], sqlString) + if "0: unavailable" in retVal: + tdLog.info("taos -k success") + else: + tdLog.exit("taos -k fail") + + # restart taosd + tdDnodes.start(1) + #sleep(5) + retCode, retVal = taos_command(buildPath, "k", '', "", keyDict['c'], sqlString) + if "2: service ok" in retVal: + tdLog.info("taos -k success") + else: + tdLog.exit("taos -k fail") + + tdLog.printNoPrefix("================================ parameter: -n") + # stop taosd + tdDnodes.stop(1) + + role = 'server' + taosCmd = 'nohup ' + buildPath + '/build/bin/taos -c ' + keyDict['c'] + taosCmd = taosCmd + ' -n ' + role + ' > /dev/null 2>&1 &' + print (taosCmd) + os.system(taosCmd) + + pktLen = '2000' + pktNum = '10' + role = 'client' + taosCmd = buildPath + '/build/bin/taos -c ' + keyDict['c'] + taosCmd = taosCmd + ' -n ' + role + ' -l ' + pktLen + ' -N ' + pktNum + print (taosCmd) + child = pexpect.spawn(taosCmd, timeout=3) + i = child.expect([pexpect.TIMEOUT, pexpect.EOF], timeout=6) + + retResult = child.before.decode() + print("expect() return code: %d, content:\n %s\n"%(i, retResult)) + #print(child.after.decode()) + if i == 0: + tdLog.exit('taos -n server fail!') + + expectString1 = 'response is received, size:' + pktLen + expectSTring2 = pktNum + '/' + pktNum + if expectString1 in retResult and expectSTring2 in retResult: + tdLog.info("taos -n client success") + else: + tdLog.exit('taos -n client fail!') + + os.system('pkill taos') + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/Now.py b/tests/system-test/2-query/Now.py index 7f0e17343996c709a44fbf84c7b2d0694dc67f90..99fca2e88d4bc10591861a800580312ae7689ab5 100644 --- a/tests/system-test/2-query/Now.py +++ b/tests/system-test/2-query/Now.py @@ -1,5 +1,4 @@ - from util.dnodes import * from util.log import * from util.sql import * @@ -111,21 +110,72 @@ class TDTestCase: tdSql.query("select * from ntb where ts=now()") tdSql.checkRows(0) + tdSql.query("select * from db.ntb where ts>=now()") + tdSql.checkRows(0) tdSql.query("select * from ntb where ts>now()") tdSql.checkRows(0) + tdSql.query("select * from db.ntb where ts>now()") + tdSql.checkRows(0) tdSql.query("select now() from ntb where ts=today()") tdSql.checkRows(1) + tdSql.query("select now() from db.ntb where ts=today()") + tdSql.checkRows(1) + tdSql.query("select now()+1 from ntb") + tdSql.checkRows(3) + tdSql.query("select now()+1 from db.ntb") + tdSql.checkRows(3) + # tdSql.query("select now()+9223372036854775807 from ntb") + # tdSql.checkRows(3) + tdSql.error("select now()+1.5 from ntb") + tdSql.error("select now()+1.5 from db.ntb") + tdSql.error("select now()+'abc' from ntb") + tdSql.error("select now()+'abc' from db.ntb") + tdSql.error("select now()+abc from ntb") + tdSql.error("select now()+abc from db.ntb") + tdSql.error("select now()+! from ntb") + tdSql.error("select now()+! from db.ntb") + + tdSql.query("select now()+null from ntb") + tdSql.checkData(0,0,None) + tdSql.query("select now()+null from db.ntb") + tdSql.checkData(0,0,None) + tdSql.query("select now()-null from ntb") + tdSql.checkData(0,0,None) + tdSql.query("select now()-null from db.ntb") + tdSql.checkData(0,0,None) + tdSql.query("select now()*null from ntb") + tdSql.checkData(0,0,None) + tdSql.query("select now()*null from db.ntb") + tdSql.checkData(0,0,None) + tdSql.query("select now()/null from ntb") + tdSql.checkData(0,0,None) + tdSql.query("select now()/null from db.ntb") + tdSql.checkData(0,0,None) + + tdSql.error("select now() +today() from ntb") + tdSql.error("select now() +today() from db.ntb") + # stable tdSql.query("select now() from stb") tdSql.checkRows(3) + tdSql.query("select now() from db.stb") + tdSql.checkRows(3) tdSql.query("select now() +1w from stb") tdSql.checkRows(3) tdSql.query("select now() +1w from db.stb") @@ -198,16 +248,52 @@ class TDTestCase: # tdSql.checkData(2,1,1) tdSql.query("select c1 from stb where ts=now()") tdSql.checkRows(0) + tdSql.query("select c1 from db.stb where ts=now()") + tdSql.checkRows(0) # tdSql.query("select * from stb where ts>=now()") # tdSql.checkRows(0) # tdSql.query("select * from stb where ts>now()") # tdSql.checkRows(0) tdSql.query("select now() from stb where ts=today()") tdSql.checkRows(1) + tdSql.query("select now() from db.stb where ts=today()") + tdSql.checkRows(1) + tdSql.query("select now() +1 from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1 from db.stb") + tdSql.checkRows(3) + + tdSql.error("select now() +'abc' from stb") + tdSql.error("select now() +'abc' from db.stb") + tdSql.error("select now() + ! from stb") + tdSql.error("select now() + ! from db.stb") + tdSql.error("select now() + today() from stb") + tdSql.error("select now() + today() from db.stb") + tdSql.error("select now() -today() from stb") + tdSql.error("select now() - today() from db.stb") + + tdSql.query("select now()+null from stb") + tdSql.checkData(0,0,None) + tdSql.query("select now()+null from db.stb") + tdSql.checkData(0,0,None) + tdSql.query("select now()-null from stb") + tdSql.checkData(0,0,None) + tdSql.query("select now()-null from db.stb") + tdSql.checkData(0,0,None) + tdSql.query("select now()*null from stb") + tdSql.checkData(0,0,None) + tdSql.query("select now()*null from db.stb") + tdSql.checkData(0,0,None) + tdSql.query("select now()/null from stb") + tdSql.checkData(0,0,None) + tdSql.query("select now()/null from db.stb") + tdSql.checkData(0,0,None) # table tdSql.query("select now() from stb_1") tdSql.checkRows(3) + tdSql.query("select now() from db.stb_1") + tdSql.checkRows(3) tdSql.query("select now() +1w from stb_1") tdSql.checkRows(3) tdSql.query("select now() +1w from db.stb_1") @@ -275,15 +361,27 @@ class TDTestCase: tdSql.query("select * from stb_1 where ts=now()") tdSql.checkRows(0) + tdSql.query("select * from db.stb_1 where ts>=now()") + tdSql.checkRows(0) tdSql.query("select * from stb_1 where ts>now()") tdSql.checkRows(0) + tdSql.query("select * from db.stb_1 where ts>now()") + tdSql.checkRows(0) # tdSql.query("select * from stb_1 where ts=0: + elem = elem + else: + elem = -elem + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + for row_index , row in enumerate(abs_result): + for col_index , elem in enumerate(row): + if auto_result[row_index][col_index] != elem: + check_status = False + if not check_status: + tdLog.notice("abs function value has not as expected , sql is \"%s\" "%abs_query ) + sys.exit(1) + else: + tdLog.info("abs value check pass , it work as expected ,sql is \"%s\" "%abs_query ) + + def test_errors(self): + error_sql_lists = [ + "select abs from t1", + # "select abs(-+--+c1) from t1", + # "select +-abs(c1) from t1", + # "select ++-abs(c1) from t1", + # "select ++--abs(c1) from t1", + # "select - -abs(c1)*0 from t1", + # "select abs(tbname+1) from t1 ", + "select abs(123--123)==1 from t1", + "select abs(c1) as 'd1' from t1", + "select abs(c1 ,c2 ) from t1", + "select abs(c1 ,NULL) from t1", + "select abs(,) from t1;", + "select abs(abs(c1) ab from t1)", + "select abs(c1) as int from t1", + "select abs from stb1", + # "select abs(-+--+c1) from stb1", + # "select +-abs(c1) from stb1", + # "select ++-abs(c1) from stb1", + # "select ++--abs(c1) from stb1", + # "select - -abs(c1)*0 from stb1", + # "select abs(tbname+1) from stb1 ", + "select abs(123--123)==1 from stb1", + "select abs(c1) as 'd1' from stb1", + "select abs(c1 ,c2 ) from stb1", + "select abs(c1 ,NULL) from stb1", + "select abs(,) from stb1;", + "select abs(abs(c1) ab from stb1)", + "select abs(c1) as int from stb1" + ] + for error_sql in error_sql_lists: + tdSql.error(error_sql) + + def support_types(self): + type_error_sql_lists = [ + "select abs(ts) from t1" , + "select abs(c7) from t1", + "select abs(c8) from t1", + "select abs(c9) from t1", + "select abs(ts) from ct1" , + "select abs(c7) from ct1", + "select abs(c8) from ct1", + "select abs(c9) from ct1", + "select abs(ts) from ct3" , + "select abs(c7) from ct3", + "select abs(c8) from ct3", + "select abs(c9) from ct3", + "select abs(ts) from ct4" , + "select abs(c7) from ct4", + "select abs(c8) from ct4", + "select abs(c9) from ct4", + "select abs(ts) from stb1" , + "select abs(c7) from stb1", + "select abs(c8) from stb1", + "select abs(c9) from stb1" , + + "select abs(ts) from stbbb1" , + "select abs(c7) from stbbb1", + + "select abs(ts) from tbname", + "select abs(c9) from tbname" + + ] + + for type_sql in type_error_sql_lists: + tdSql.error(type_sql) + + + type_sql_lists = [ + "select abs(c1) from t1", + "select abs(c2) from t1", + "select abs(c3) from t1", + "select abs(c4) from t1", + "select abs(c5) from t1", + "select abs(c6) from t1", + + "select abs(c1) from ct1", + "select abs(c2) from ct1", + "select abs(c3) from ct1", + "select abs(c4) from ct1", + "select abs(c5) from ct1", + "select abs(c6) from ct1", + + "select abs(c1) from ct3", + "select abs(c2) from ct3", + "select abs(c3) from ct3", + "select abs(c4) from ct3", + "select abs(c5) from ct3", + "select abs(c6) from ct3", + + "select abs(c1) from stb1", + "select abs(c2) from stb1", + "select abs(c3) from stb1", + "select abs(c4) from stb1", + "select abs(c5) from stb1", + "select abs(c6) from stb1", + + "select abs(c6) as alisb from stb1", + "select abs(c6) alisb from stb1", + ] + + for type_sql in type_sql_lists: + tdSql.query(type_sql) + + def basic_abs_function(self): + + # basic query + tdSql.query("select c1 from ct3") + tdSql.checkRows(0) + tdSql.query("select c1 from t1") + tdSql.checkRows(12) + tdSql.query("select c1 from stb1") + tdSql.checkRows(25) + + # used for empty table , ct3 is empty + tdSql.query("select abs(c1) from ct3") + tdSql.checkRows(0) + tdSql.query("select abs(c2) from ct3") + tdSql.checkRows(0) + tdSql.query("select abs(c3) from ct3") + tdSql.checkRows(0) + tdSql.query("select abs(c4) from ct3") + tdSql.checkRows(0) + tdSql.query("select abs(c5) from ct3") + tdSql.checkRows(0) + tdSql.query("select abs(c6) from ct3") + + # used for regular table + tdSql.query("select abs(c1) from t1") + tdSql.checkData(0, 0, None) + tdSql.checkData(1 , 0, 1) + tdSql.checkData(3 , 0, 3) + tdSql.checkData(5 , 0, None) + + tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 4, 1.11000) + tdSql.checkData(3, 3, 33) + tdSql.checkData(5, 4, None) + tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 5, 1.11000) + tdSql.checkData(3, 4, 33) + tdSql.checkData(5, 5, None) + + self.check_result_auto( "select c1, c2, c3 , c4, c5 from t1", "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from t1") + + # used for sub table + tdSql.query("select abs(c1) from ct1") + tdSql.checkData(0, 0, 8) + tdSql.checkData(1 , 0, 7) + tdSql.checkData(3 , 0, 5) + tdSql.checkData(5 , 0, 4) + + tdSql.query("select abs(c1) from ct1") + self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct1", "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct1") + self.check_result_auto("select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct1;","select c1 from ct1" ) + + # used for stable table + + tdSql.query("select abs(c1) from stb1") + tdSql.checkRows(25) + self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct4 ", "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct4") + self.check_result_auto("select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct4;" , "select c1 from ct4" ) + + + # used for not exists table + tdSql.error("select abs(c1) from stbbb1") + tdSql.error("select abs(c1) from tbname") + tdSql.error("select abs(c1) from ct5") + + # mix with common col + tdSql.query("select c1, abs(c1) from ct1") + tdSql.checkData(0 , 0 ,8) + tdSql.checkData(0 , 1 ,8) + tdSql.checkData(4 , 0 ,0) + tdSql.checkData(4 , 1 ,0) + tdSql.query("select c1, abs(c1) from ct4") + tdSql.checkData(0 , 0 , None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + tdSql.checkData(5 , 0 ,None) + tdSql.checkData(5 , 1 ,None) + tdSql.query("select c1, abs(c1) from ct4 ") + tdSql.checkData(0 , 0 ,None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + + # mix with common functions + tdSql.query("select c1, abs(c1),c5, floor(c5) from ct4 ") + tdSql.checkData(0 , 0 ,None) + 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) + tdSql.checkData(3 , 3 ,6.00000) + + tdSql.query("select c1, abs(c1),c5, floor(c5) from stb1 ") + + # mix with agg functions , not support + tdSql.error("select c1, abs(c1),c5, count(c5) from stb1 ") + tdSql.error("select c1, abs(c1),c5, count(c5) from ct1 ") + tdSql.error("select abs(c1), count(c5) from stb1 ") + tdSql.error("select abs(c1), count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from stb1 ") + + # agg functions mix with agg functions + + 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) + tdSql.query("select count(*) from ct4 ") + tdSql.checkData(0,0,12) + tdSql.query("select count(c1) from stb1 ") + tdSql.checkData(0,0,22) + tdSql.query("select count(*) from stb1 ") + tdSql.checkData(0,0,25) + + # 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) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 8.000000000) + + tdSql.query(" select c1, abs(c1) -0 ,ceil(c1-0.1)-0.1 from ct4") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 7.900000000) + + + + def abs_func_filter(self): + tdSql.execute("use db") + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + tdSql.checkRows(3) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,8.000000000) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,7.900000000) + tdSql.checkData(0,4,3.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,88888) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,8.000000000) + tdSql.checkData(0,4,7.900000000) + tdSql.checkData(0,5,3.000000000) + + + def abs_Arithmetic(self): + pass + + def check_boundary_values(self): + + tdSql.execute("drop database if exists bound_test") + tdSql.execute("create database if not exists bound_test") + time.sleep(3) + tdSql.execute("use bound_test") + tdSql.execute( + "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + ) + tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+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 abs(c1), abs(c2) ,abs(c3), abs(c4), abs(c5) ,abs(c6) from sub1_bound") + self.check_result_auto( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select abs(c1), abs(c2) ,abs(c3), abs(c3), abs(c2) ,abs(c1) from sub1_bound") + self.check_result_auto("select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from sub1_bound;" , "select abs(c1) from sub1_bound" ) + + # check basic elem for table per row + tdSql.query("select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from sub1_bound ") + tdSql.checkData(0,0,2147483647) + tdSql.checkData(0,1,9223372036854775807) + tdSql.checkData(0,2,32767) + tdSql.checkData(0,3,127) + tdSql.checkData(0,4,339999995214436424907732413799364296704.00000) + tdSql.checkData(0,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(1,0,2147483647) + tdSql.checkData(1,1,9223372036854775807) + tdSql.checkData(1,2,32767) + tdSql.checkData(1,3,127) + tdSql.checkData(1,4,339999995214436424907732413799364296704.00000) + tdSql.checkData(1,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(3,0,2147483646) + tdSql.checkData(3,1,9223372036854775806) + tdSql.checkData(3,2,32766) + tdSql.checkData(3,3,126) + tdSql.checkData(3,4,339999995214436424907732413799364296704.00000) + tdSql.checkData(3,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + + # check + - * / in functions + tdSql.query("select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") + tdSql.checkData(0,0,2147483648.000000000) + tdSql.checkData(0,1,9223372036854775807) + tdSql.checkData(0,2,32767.000000000) + tdSql.checkData(0,3,63.500000000) + tdSql.checkData(0,4,169999997607218212453866206899682148352.000000000) + tdSql.checkData(0,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + + + tdSql.checkData(1,0,2147483646.000000000) + tdSql.checkData(1,1,9223372036854775808.000000000) + tdSql.checkData(1,2,32767.000000000) + tdSql.checkData(1,3,63.500000000) + tdSql.checkData(1,4,169999997607218212453866206899682148352.000000000) + + self.check_result_auto("select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from sub1_bound" ,"select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") + + + 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 ==============") + + self.test_errors() + + tdLog.printNoPrefix("==========step3:support types ============") + + self.support_types() + + tdLog.printNoPrefix("==========step4: abs basic query ============") + + self.basic_abs_function() + + tdLog.printNoPrefix("==========step5: abs boundary query ============") + + self.check_boundary_values() + + tdLog.printNoPrefix("==========step6: abs filter query ============") + + self.abs_func_filter() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index fb0f22eaf8ba20b5229ec6f885c7af1202a85b0b..0e849410b7b6ca29a739c4309d6123d5c9508ede 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -35,9 +35,7 @@ class TDTestCase: for i in range(len(tdSql.queryRows)): if data_tb_col[i] is None: tdSql.checkData( i, 0 , None ) - if (col_name == "c2" or col_name == "double" ) and tbname == "t1" and i == 10: - continue - else: + if col_name not in ["c2", "double"] or tbname != "t1" or i != 10: utc_zone = datetime.timezone.utc utc_8 = datetime.timezone(datetime.timedelta(hours=8)) date_init_stamp = datetime.datetime.utcfromtimestamp(data_tb_col[i]/1000) @@ -597,7 +595,41 @@ class TDTestCase: time2str = str(int(datetime.datetime.timestamp(data_t1_c10[i])*1000)) tdSql.checkData( i, 0, time2str ) - + tdLog.printNoPrefix("==========step39: cast constant operation to bigint, expect change to int ") + tdSql.query("select cast(12121.23323131 as bigint) as b from ct4") + ( tdSql.checkData(i, 0, 12121) for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 as binary(16)) as b from ct4") + ( tdSql.checkData(i, 0, '12121.233231') for i in range(len(tdSql.queryRows)) ) + tdSql.query("select cast(12121.23323131 as binary(2)) as b from ct4") + ( tdSql.checkData(i, 0, '12') for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 as nchar(16)) as b from ct4") + ( tdSql.checkData(i, 0, '12121.233231') for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 as nchar(2)) as b from ct4") + ( tdSql.checkData(i, 0, '12') for i in range(len(tdSql.queryRows) ) ) + + tdSql.query("select cast(12121.23323131 + 321.876897998 as bigint) as b from ct4") + ( tdSql.checkData(i, 0, 12443) for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 + 321.876897998 as binary(16)) as b from ct4") + ( tdSql.checkData(i, 0, '12443.110129') for i in range(len(tdSql.queryRows)) ) + tdSql.query("select cast(12121.23323131 + 321.876897998 as binary(3)) as b from ct4") + ( tdSql.checkData(i, 0, '124') for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 + 321.876897998 as nchar(16)) as b from ct4") + ( tdSql.checkData(i, 0, '12443.110129') for i in range(len(tdSql.queryRows)) ) + tdSql.query("select cast(12121.23323131 + 321.876897998 as nchar(3)) as b from ct4") + ( tdSql.checkData(i, 0, '124') for i in range(len(tdSql.queryRows) ) ) + + tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as bigint) as b from ct4") + ( tdSql.checkData(i, 0, 12121) for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as binary(16)) as b from ct4") + ( tdSql.checkData(i, 0, '12121.233231') for i in range(len(tdSql.queryRows)) ) + tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as binary(2)) as b from ct4") + ( tdSql.checkData(i, 0, '12') for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as nchar(16)) as b from ct4") + ( tdSql.checkData(i, 0, '12121.233231') for i in range(len(tdSql.queryRows) ) ) + tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as nchar(2)) as b from ct4") + ( tdSql.checkData(i, 0, '12') for i in range(len(tdSql.queryRows) ) ) + + tdLog.printNoPrefix("==========step40: error cast condition, should return error ") tdSql.error("select cast(c1 as int) as b from ct4") tdSql.error("select cast(c1 as bool) as b from ct4") tdSql.error("select cast(c1 as tinyint) as b from ct4") diff --git a/tests/system-test/2-query/ceil.py b/tests/system-test/2-query/ceil.py new file mode 100644 index 0000000000000000000000000000000000000000..4196a5a8ce858bbc2d2f680e143cfb2488953dca --- /dev/null +++ b/tests/system-test/2-query/ceil.py @@ -0,0 +1,463 @@ +from math import ceil +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * + +class TDTestCase: + 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 ,"fnDebugFlag":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 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + for i in range(9): + tdSql.execute( + f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into t1 values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '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: + if elem == None: + elem = None + else: + elem = ceil(elem) + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + 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 + 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", + # "select ceil(-+--+c1) from t1", + # "select +-ceil(c1) from t1", + # "select ++-ceil(c1) from t1", + # "select ++--ceil(c1) from t1", + # "select - -ceil(c1)*0 from t1", + # "select ceil(tbname+1) from t1 ", + "select ceil(123--123)==1 from t1", + "select ceil(c1) as 'd1' from t1", + "select ceil(c1 ,c2 ) from t1", + "select ceil(c1 ,NULL) from t1", + "select ceil(,) from t1;", + "select ceil(ceil(c1) ab from t1)", + "select ceil(c1) as int from t1", + "select ceil from stb1", + # "select ceil(-+--+c1) from stb1", + # "select +-ceil(c1) from stb1", + # "select ++-ceil(c1) from stb1", + # "select ++--ceil(c1) from stb1", + # "select - -ceil(c1)*0 from stb1", + # "select ceil(tbname+1) from stb1 ", + "select ceil(123--123)==1 from stb1", + "select ceil(c1) as 'd1' from stb1", + "select ceil(c1 ,c2 ) from stb1", + "select ceil(c1 ,NULL) from stb1", + "select ceil(,) from stb1;", + "select ceil(ceil(c1) ab from stb1)", + "select ceil(c1) as int from stb1" + ] + 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(c7) from t1", + "select ceil(c8) from t1", + "select ceil(c9) from t1", + "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(c7) from ct3", + "select ceil(c8) from ct3", + "select ceil(c9) from ct3", + "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(c7) from stb1", + "select ceil(c8) from stb1", + "select ceil(c9) from stb1" , + + "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", + "select ceil(c3) from t1", + "select ceil(c4) from t1", + "select ceil(c5) from t1", + "select ceil(c6) from t1", + + "select ceil(c1) from ct1", + "select ceil(c2) from ct1", + "select ceil(c3) from ct1", + "select ceil(c4) from ct1", + "select ceil(c5) from ct1", + "select ceil(c6) from ct1", + + "select ceil(c1) from ct3", + "select ceil(c2) from ct3", + "select ceil(c3) from ct3", + "select ceil(c4) from ct3", + "select ceil(c5) from ct3", + "select ceil(c6) from ct3", + + "select ceil(c1) from stb1", + "select ceil(c2) from stb1", + "select ceil(c3) from stb1", + "select ceil(c4) from stb1", + "select ceil(c5) from stb1", + "select ceil(c6) 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 + tdSql.query("select c1 from ct3") + tdSql.checkRows(0) + tdSql.query("select c1 from t1") + tdSql.checkRows(12) + tdSql.query("select c1 from stb1") + tdSql.checkRows(25) + + # used for empty table , ct3 is empty + tdSql.query("select ceil(c1) from ct3") + tdSql.checkRows(0) + tdSql.query("select ceil(c2) from ct3") + tdSql.checkRows(0) + tdSql.query("select ceil(c3) from ct3") + tdSql.checkRows(0) + tdSql.query("select ceil(c4) from ct3") + tdSql.checkRows(0) + 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) + tdSql.checkData(1 , 0, 1) + tdSql.checkData(3 , 0, 3) + tdSql.checkData(5 , 0, None) + + tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 4, 1.11000) + tdSql.checkData(3, 3, 33) + tdSql.checkData(5, 4, None) + tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 5, 1.11000) + tdSql.checkData(3, 4, 33) + 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) + tdSql.checkData(1 , 0, 7) + tdSql.checkData(3 , 0, 5) + tdSql.checkData(5 , 0, 4) + + tdSql.query("select ceil(c1) from ct1") + 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 + + 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 + tdSql.query("select c1, ceil(c1) from ct1") + tdSql.checkData(0 , 0 ,8) + tdSql.checkData(0 , 1 ,8) + tdSql.checkData(4 , 0 ,0) + tdSql.checkData(4 , 1 ,0) + tdSql.query("select c1, ceil(c1) from ct4") + tdSql.checkData(0 , 0 , None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + tdSql.checkData(5 , 0 ,None) + tdSql.checkData(5 , 1 ,None) + tdSql.query("select c1, ceil(c1) from ct4 ") + tdSql.checkData(0 , 0 ,None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + + # mix with common functions + tdSql.query("select c1, ceil(c1),c5, ceil(c5) from ct4 ") + tdSql.checkData(0 , 0 ,None) + 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) + tdSql.checkData(3 , 3 ,7.00000) + + tdSql.query("select c1, ceil(c1),c5, floor(c5) from stb1 ") + + # mix with agg functions , not support + tdSql.error("select c1, ceil(c1),c5, count(c5) from stb1 ") + tdSql.error("select c1, ceil(c1),c5, count(c5) from ct1 ") + tdSql.error("select ceil(c1), count(c5) from stb1 ") + tdSql.error("select ceil(c1), count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from stb1 ") + + # agg functions mix with agg functions + + 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) + tdSql.query("select count(*) from ct4 ") + tdSql.checkData(0,0,12) + tdSql.query("select count(c1) from stb1 ") + tdSql.checkData(0,0,22) + tdSql.query("select count(*) from stb1 ") + tdSql.checkData(0,0,25) + + # 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) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 8.000000000) + + tdSql.query(" select c1, abs(c1) -0 ,ceil(c1-0.1)-0.1 from ct4") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 7.900000000) + + def abs_func_filter(self): + tdSql.execute("use db") + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + tdSql.checkRows(3) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,8.000000000) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,7.900000000) + tdSql.checkData(0,4,3.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,88888) + tdSql.checkData(0,2,8.000000000) + 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") + tdSql.execute("create database if not exists bound_test") + time.sleep(3) + tdSql.execute("use bound_test") + tdSql.execute( + "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + ) + tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + + tdSql.execute( + f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + + 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.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) + tdSql.checkData(0, 2, 32768.000000000) + tdSql.checkData(0, 3, 127.000000000) + tdSql.checkData(0, 4, 169999997607218212453866206899682148352.000000000) + + tdSql.checkData(4, 0, -2147483642.000000000) + tdSql.checkData(4, 2, -32762.000000000) + tdSql.checkData(4, 3, -123.000000000) + 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 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 ==============") + + self.test_errors() + + tdLog.printNoPrefix("==========step3:support types ============") + + self.support_types() + + tdLog.printNoPrefix("==========step4: ceil basic query ============") + + self.basic_ceil_function() + + tdLog.printNoPrefix("==========step5: ceil boundary query ============") + + self.check_boundary_values() + + tdLog.printNoPrefix("==========step6: ceil filter query ============") + + self.abs_func_filter() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/char_length.py b/tests/system-test/2-query/char_length.py new file mode 100644 index 0000000000000000000000000000000000000000..e78db3b8b010a08329545af0e927fc946bb9ae33 --- /dev/null +++ b/tests/system-test/2-query/char_length.py @@ -0,0 +1,248 @@ +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + +INT_COL = "c1" +BINT_COL = "c2" +SINT_COL = "c3" +TINT_COL = "c4" +FLOAT_COL = "c5" +DOUBLE_COL = "c6" +BOOL_COL = "c7" + +BINARY_COL = "c8" +NCHAR_COL = "c9" +TS_COL = "c10" + +UN_CHAR_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL, ] +CHAR_COL = [ BINARY_COL, NCHAR_COL, ] +TS_TYPE_COL = [TS_COL] + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def __char_length_condition(self): + char_length_condition = [] + for char_col in CHAR_COL: + char_length_condition.extend( + ( + char_col, + f"upper( {char_col} )", + ) + ) + char_length_condition.extend( f"cast( {un_char_col} as binary(16) ) " for un_char_col in UN_CHAR_COL) + char_length_condition.extend( f"cast( {char_col} + {char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + char_length_condition.extend( f"cast( {char_col} + {un_char_col} as binary(32) ) " for un_char_col in UN_CHAR_COL ) + + char_length_condition.append('''"test1234!@#$%^&*():'> 0 " + return "" + + def __group_condition(self, col, having = ""): + return f" group by {col} having {having}" if having else f" group by {col} " + + def __char_length_current_check(self, tbname): + char_length_condition = self.__char_length_condition() + for condition in char_length_condition: + where_condition = self.__where_condition(condition) + group_having = self.__group_condition(condition, having=f"{condition} is not null " ) + group_no_having= self.__group_condition(condition ) + groups = ["", group_having, group_no_having] + + for group_condition in groups: + tdSql.query(f"select {condition}, char_length( {condition} ) from {tbname} {where_condition} {group_condition} ") + for i in range(tdSql.queryRows): + if not tdSql.getData(i,1): + tdSql.checkData(i, 1, None) + # elif "as nchar" in condition or (NCHAR_COL in condition and "as binary" not in condition): + # tdSql.checkData(i, 1, len(str(tdSql.getData(i,0) ) ) * 4 ) + else: + tdSql.checkData(i, 1, len(str(tdSql.getData(i,0) ) ) ) + + def __char_length_err_check(self,tbname): + sqls = [] + + for un_char_col in UN_CHAR_COL: + sqls.extend( + ( + f"select char_length( {un_char_col} ) from {tbname} ", + f"select char_length(ceil( {un_char_col} )) from {tbname} ", + f"select {un_char_col} from {tbname} group by char_length( {un_char_col} ) ", + ) + ) + + sqls.extend( f"select char_length( {un_char_col} + {un_char_col_2} ) from {tbname} " for un_char_col_2 in UN_CHAR_COL ) + sqls.extend( f"select char_length( {un_char_col} + {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + + sqls.extend( f"select {char_col} from {tbname} group by char_length( {char_col} ) " for char_col in CHAR_COL) + sqls.extend( f"select char_length( {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + sqls.extend( f"select char_length( {char_col} + {ts_col} ) from {tbname} " for char_col in UN_CHAR_COL for ts_col in TS_TYPE_COL) + sqls.extend( f"select char_length( {char_col} + {char_col_2} ) from {tbname} " for char_col in CHAR_COL for char_col_2 in CHAR_COL ) + sqls.extend( f"select upper({char_col}, 11) from {tbname} " for char_col in CHAR_COL ) + sqls.extend( f"select upper({char_col}) from {tbname} interval(2d) sliding(1d)" for char_col in CHAR_COL ) + sqls.extend( + ( + f"select char_length() from {tbname} ", + f"select char_length(*) from {tbname} ", + f"select char_length(ccccccc) from {tbname} ", + f"select char_length(111) from {tbname} ", + f"select char_length(c8, 11) from {tbname} ", + ) + ) + + return sqls + + def __test_current(self): + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + for tb in tbname: + self.__char_length_current_check(tb) + tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") + + def __test_error(self): + tdLog.printNoPrefix("==========err sql condition check , must return error==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + + for tb in tbname: + for errsql in self.__char_length_err_check(tb): + tdSql.error(sql=errsql) + tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") + + + def all_test(self): + self.__test_current() + self.__test_error() + + + def __create_tb(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + create_stb_sql = f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) tags (t1 int) + ''' + create_ntb_sql = f'''create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + def __insert_data(self, rows): + now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + for i in range(rows): + tdSql.execute( + f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f'''insert into ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) + ''' + ) + + tdSql.execute( + f'''insert into ct4 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} + ) + ( + { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} + ) + ''' + ) + + tdSql.execute( + f'''insert into ct2 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + for i in range(rows): + insert_data = f'''insert into t1 values + ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) + ''' + tdSql.execute(insert_data) + tdSql.execute( + f'''insert into t1 values + ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.__insert_data(10) + + tdLog.printNoPrefix("==========step3:all check") + self.all_test() + + # tdDnodes.stop(1) + # tdDnodes.start(1) + + # tdSql.execute("use db") + + # tdLog.printNoPrefix("==========step4:after wal, all check again ") + # self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/floor.py b/tests/system-test/2-query/floor.py new file mode 100644 index 0000000000000000000000000000000000000000..c955c24e05c37f51856a45956b3befd6552ac812 --- /dev/null +++ b/tests/system-test/2-query/floor.py @@ -0,0 +1,462 @@ +from math import floor +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * + +class TDTestCase: + 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 ,"fnDebugFlag":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 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + for i in range(9): + tdSql.execute( + f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into t1 values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '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: + if elem == None: + elem = None + else: + elem = floor(elem) + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + 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 + 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", + # "select floor(-+--+c1) from t1", + # "select +-floor(c1) from t1", + # "select ++-floor(c1) from t1", + # "select ++--floor(c1) from t1", + # "select - -floor(c1)*0 from t1", + # "select floor(tbname+1) from t1 ", + "select floor(123--123)==1 from t1", + "select floor(c1) as 'd1' from t1", + "select floor(c1 ,c2 ) from t1", + "select floor(c1 ,NULL) from t1", + "select floor(,) from t1;", + "select floor(floor(c1) ab from t1)", + "select floor(c1) as int from t1", + "select floor from stb1", + # "select floor(-+--+c1) from stb1", + # "select +-floor(c1) from stb1", + # "select ++-floor(c1) from stb1", + # "select ++--floor(c1) from stb1", + # "select - -floor(c1)*0 from stb1", + # "select floor(tbname+1) from stb1 ", + "select floor(123--123)==1 from stb1", + "select floor(c1) as 'd1' from stb1", + "select floor(c1 ,c2 ) from stb1", + "select floor(c1 ,NULL) from stb1", + "select floor(,) from stb1;", + "select floor(floor(c1) ab from stb1)", + "select floor(c1) as int from stb1" + ] + 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(c7) from t1", + "select floor(c8) from t1", + "select floor(c9) from t1", + "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(c7) from ct3", + "select floor(c8) from ct3", + "select floor(c9) from ct3", + "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(c7) from stb1", + "select floor(c8) from stb1", + "select floor(c9) from stb1" , + + "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", + "select floor(c3) from t1", + "select floor(c4) from t1", + "select floor(c5) from t1", + "select floor(c6) from t1", + + "select floor(c1) from ct1", + "select floor(c2) from ct1", + "select floor(c3) from ct1", + "select floor(c4) from ct1", + "select floor(c5) from ct1", + "select floor(c6) from ct1", + + "select floor(c1) from ct3", + "select floor(c2) from ct3", + "select floor(c3) from ct3", + "select floor(c4) from ct3", + "select floor(c5) from ct3", + "select floor(c6) from ct3", + + "select floor(c1) from stb1", + "select floor(c2) from stb1", + "select floor(c3) from stb1", + "select floor(c4) from stb1", + "select floor(c5) from stb1", + "select floor(c6) 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 + tdSql.query("select c1 from ct3") + tdSql.checkRows(0) + tdSql.query("select c1 from t1") + tdSql.checkRows(12) + tdSql.query("select c1 from stb1") + tdSql.checkRows(25) + + # used for empty table , ct3 is empty + tdSql.query("select floor(c1) from ct3") + tdSql.checkRows(0) + tdSql.query("select floor(c2) from ct3") + tdSql.checkRows(0) + tdSql.query("select floor(c3) from ct3") + tdSql.checkRows(0) + tdSql.query("select floor(c4) from ct3") + tdSql.checkRows(0) + 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) + tdSql.checkData(1 , 0, 1) + tdSql.checkData(3 , 0, 3) + tdSql.checkData(5 , 0, None) + + tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 4, 1.11000) + tdSql.checkData(3, 3, 33) + tdSql.checkData(5, 4, None) + tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 5, 1.11000) + tdSql.checkData(3, 4, 33) + 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) + tdSql.checkData(1 , 0, 7) + tdSql.checkData(3 , 0, 5) + tdSql.checkData(5 , 0, 4) + + tdSql.query("select floor(c1) from ct1") + 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 + + 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 + tdSql.query("select c1, floor(c1) from ct1") + tdSql.checkData(0 , 0 ,8) + tdSql.checkData(0 , 1 ,8) + tdSql.checkData(4 , 0 ,0) + tdSql.checkData(4 , 1 ,0) + tdSql.query("select c1, floor(c1) from ct4") + tdSql.checkData(0 , 0 , None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + tdSql.checkData(5 , 0 ,None) + tdSql.checkData(5 , 1 ,None) + tdSql.query("select c1, floor(c1) from ct4 ") + tdSql.checkData(0 , 0 ,None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + + # mix with common functions + tdSql.query("select c1, floor(c1),c5, floor(c5) from ct4 ") + tdSql.checkData(0 , 0 ,None) + 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) + tdSql.checkData(3 , 3 ,6.00000) + + tdSql.query("select c1, floor(c1),c5, floor(c5) from stb1 ") + + # mix with agg functions , not support + tdSql.error("select c1, floor(c1),c5, count(c5) from stb1 ") + tdSql.error("select c1, floor(c1),c5, count(c5) from ct1 ") + tdSql.error("select floor(c1), count(c5) from stb1 ") + tdSql.error("select floor(c1), count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from stb1 ") + + # agg functions mix with agg functions + + 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) + tdSql.query("select count(*) from ct4 ") + tdSql.checkData(0,0,12) + tdSql.query("select count(c1) from stb1 ") + tdSql.checkData(0,0,22) + tdSql.query("select count(*) from stb1 ") + tdSql.checkData(0,0,25) + + # 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) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 8.000000000) + + tdSql.query(" select c1, abs(c1) -0 ,floor(c1-0.1)-0.1 from ct4") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 6.900000000) + + def abs_func_filter(self): + tdSql.execute("use db") + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + tdSql.checkRows(3) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,8.000000000) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,7.900000000) + tdSql.checkData(0,4,3.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,88888) + tdSql.checkData(0,2,8.000000000) + 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") + tdSql.execute("create database if not exists bound_test") + time.sleep(3) + tdSql.execute("use bound_test") + tdSql.execute( + "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + ) + tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + + tdSql.execute( + f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + + 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.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) + tdSql.checkData(0, 2, 32767.000000000) + tdSql.checkData(0, 3, 126.000000000) + tdSql.checkData(0, 4, 169999997607218212453866206899682148352.000000000) + + tdSql.checkData(4, 0, -2147483643.000000000) + tdSql.checkData(4, 2, -32763.000000000) + tdSql.checkData(4, 3, -124.000000000) + 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 floor(c1+1) ,floor(c2) , floor(c3*1) , floor(c4/2), floor(c5)/2, floor(c6) from sub1_bound ") + + 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 ==============") + + self.test_errors() + + tdLog.printNoPrefix("==========step3:support types ============") + + self.support_types() + + tdLog.printNoPrefix("==========step4: floor basic query ============") + + self.basic_floor_function() + + tdLog.printNoPrefix("==========step5: floor boundary query ============") + + self.check_boundary_values() + + tdLog.printNoPrefix("==========step6: floor filter query ============") + + self.abs_func_filter() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/join.py b/tests/system-test/2-query/join.py new file mode 100644 index 0000000000000000000000000000000000000000..b4878e42c9b5bb710bb4ec90752c2e7b766a7ec4 --- /dev/null +++ b/tests/system-test/2-query/join.py @@ -0,0 +1,249 @@ +import datetime + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + +INT_COL = "c1" +BINT_COL = "c2" +SINT_COL = "c3" +TINT_COL = "c4" +FLOAT_COL = "c5" +DOUBLE_COL = "c6" +BOOL_COL = "c7" + +BINARY_COL = "c8" +NCHAR_COL = "c9" +TS_COL = "c10" + +UN_CHAR_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL, ] +CHAR_COL = [ BINARY_COL, NCHAR_COL, ] +TS_TYPE_COL = [TS_COL] + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def __length_condition(self): + length_condition = [] + for char_col in CHAR_COL: + length_condition.extend( + ( + char_col, + f"upper( {char_col} )", + ) + ) + length_condition.extend( f"cast( {un_char_col} as binary(16) ) " for un_char_col in UN_CHAR_COL) + length_condition.extend( f"cast( {char_col} + {char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + length_condition.extend( f"cast( {char_col} + {un_char_col} as binary(32) ) " for un_char_col in UN_CHAR_COL ) + + length_condition.append('''"test1234!@#$%^&*():'> 0 " + return "" + + def __group_condition(self, col, having = ""): + return f" group by {col} having {having}" if having else f" group by {col} " + + def __length_current_check(self, tbname): + length_condition = self.__length_condition() + for condition in length_condition: + where_condition = self.__where_condition(condition) + group_having = self.__group_condition(condition, having=f"{condition} is not null " ) + group_no_having= self.__group_condition(condition ) + groups = ["", group_having, group_no_having] + + for group_condition in groups: + tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + length_data = [ len(str(data)) if data else None for data in datas ] + tdSql.query(f"select length( {condition} ) from {tbname} {where_condition} {group_condition}") + for i in range(len(length_data)): + tdSql.checkData(i, 0, length_data[i] ) if length_data[i] else tdSql.checkData(i, 0, None) + + def __length_err_check(self,tbname): + sqls = [] + + for un_char_col in UN_CHAR_COL: + sqls.extend( + ( + f"select length( {un_char_col} ) from {tbname} ", + f"select length(ceil( {un_char_col} )) from {tbname} ", + f"select {un_char_col} from {tbname} group by length( {un_char_col} ) ", + ) + ) + + sqls.extend( f"select length( {un_char_col} + {un_char_col_2} ) from {tbname} " for un_char_col_2 in UN_CHAR_COL ) + sqls.extend( f"select length( {un_char_col} + {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + + sqls.extend( f"select {char_col} from {tbname} group by length( {char_col} ) " for char_col in CHAR_COL) + sqls.extend( f"select length( {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + sqls.extend( f"select length( {char_col} + {ts_col} ) from {tbname} " for char_col in UN_CHAR_COL for ts_col in TS_TYPE_COL) + sqls.extend( f"select length( {char_col} + {char_col_2} ) from {tbname} " for char_col in CHAR_COL for char_col_2 in CHAR_COL ) + sqls.extend( f"select upper({char_col}, 11) from {tbname} " for char_col in CHAR_COL ) + sqls.extend( f"select upper({char_col}) from {tbname} interval(2d) sliding(1d)" for char_col in CHAR_COL ) + sqls.extend( + ( + f"select length() from {tbname} ", + f"select length(*) from {tbname} ", + f"select length(ccccccc) from {tbname} ", + f"select length(111) from {tbname} ", + f"select length(c8, 11) from {tbname} ", + ) + ) + + return sqls + + def __test_current(self): + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tbname = ["ct1", "ct2", "ct4", "t1"] + for tb in tbname: + self.__length_current_check(tb) + tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") + + def __test_error(self): + tdLog.printNoPrefix("==========err sql condition check , must return error==========") + tbname = ["ct1", "ct2", "ct4", "t1"] + + for tb in tbname: + for errsql in self.__length_err_check(tb): + tdSql.error(sql=errsql) + tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") + + + def all_test(self): + self.__test_current() + self.__test_error() + + + def __create_tb(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + create_stb_sql = f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) tags (t1 int) + ''' + create_ntb_sql = f'''create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2} + + def __insert_data(self, rows): + now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + for i in range(rows): + tdSql.execute( + f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f'''insert into ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) + ''' + ) + + tdSql.execute( + f'''insert into ct4 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} + ) + ( + { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} + ) + ''' + ) + + tdSql.execute( + f'''insert into ct2 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + for i in range(rows): + insert_data = f'''insert into t1 values + ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) + ''' + tdSql.execute(insert_data) + tdSql.execute( + f'''insert into t1 values + ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.__insert_data(10) + + tdLog.printNoPrefix("==========step3:all check") + self.all_test() + + # tdDnodes.stop(1) + # tdDnodes.start(1) + + # tdSql.execute("use db") + + # tdLog.printNoPrefix("==========step4:after wal, all check again ") + # self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/length.py b/tests/system-test/2-query/length.py new file mode 100644 index 0000000000000000000000000000000000000000..083bc62c9a8d0411b0db394f991e5fd01ad0474f --- /dev/null +++ b/tests/system-test/2-query/length.py @@ -0,0 +1,249 @@ +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + +INT_COL = "c1" +BINT_COL = "c2" +SINT_COL = "c3" +TINT_COL = "c4" +FLOAT_COL = "c5" +DOUBLE_COL = "c6" +BOOL_COL = "c7" + +BINARY_COL = "c8" +NCHAR_COL = "c9" +TS_COL = "c10" + +UN_CHAR_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL, ] +CHAR_COL = [ BINARY_COL, NCHAR_COL, ] +TS_TYPE_COL = [TS_COL] + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def __length_condition(self): + length_condition = [] + for char_col in CHAR_COL: + length_condition.extend( + ( + char_col, + f"upper( {char_col} )", + ) + ) + length_condition.extend( f"cast( {un_char_col} as binary(16) ) " for un_char_col in UN_CHAR_COL) + length_condition.extend( f"cast( {char_col} + {char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + length_condition.extend( f"cast( {char_col} + {un_char_col} as binary(32) ) " for un_char_col in UN_CHAR_COL ) + + length_condition.append('''"test1234!@#$%^&*():'> 0 " + return "" + + def __group_condition(self, col, having = ""): + return f" group by {col} having {having}" if having else f" group by {col} " + + def __length_current_check(self, tbname): + length_condition = self.__length_condition() + for condition in length_condition: + where_condition = self.__where_condition(condition) + group_having = self.__group_condition(condition, having=f"{condition} is not null " ) + group_no_having= self.__group_condition(condition ) + groups = ["", group_having, group_no_having] + + for group_condition in groups: + tdSql.query(f"select {condition}, length( {condition} ) from {tbname} {where_condition} {group_condition} ") + for i in range(tdSql.queryRows): + if not tdSql.getData(i,1): + tdSql.checkData(i, 1, None) + elif "as nchar" in condition or (NCHAR_COL in condition and "as binary" not in condition): + tdSql.checkData(i, 1, len(str(tdSql.getData(i,0) ) ) * 4 ) + else: + tdSql.checkData(i, 1, len(str(tdSql.getData(i,0) ) ) ) + + + def __length_err_check(self,tbname): + sqls = [] + + for un_char_col in UN_CHAR_COL: + sqls.extend( + ( + f"select length( {un_char_col} ) from {tbname} ", + f"select length(ceil( {un_char_col} )) from {tbname} ", + f"select {un_char_col} from {tbname} group by length( {un_char_col} ) ", + ) + ) + + sqls.extend( f"select length( {un_char_col} + {un_char_col_2} ) from {tbname} " for un_char_col_2 in UN_CHAR_COL ) + sqls.extend( f"select length( {un_char_col} + {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + + sqls.extend( f"select {char_col} from {tbname} group by length( {char_col} ) " for char_col in CHAR_COL) + sqls.extend( f"select length( {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + sqls.extend( f"select length( {char_col} + {ts_col} ) from {tbname} " for char_col in UN_CHAR_COL for ts_col in TS_TYPE_COL) + sqls.extend( f"select length( {char_col} + {char_col_2} ) from {tbname} " for char_col in CHAR_COL for char_col_2 in CHAR_COL ) + sqls.extend( f"select upper({char_col}, 11) from {tbname} " for char_col in CHAR_COL ) + sqls.extend( f"select upper({char_col}) from {tbname} interval(2d) sliding(1d)" for char_col in CHAR_COL ) + sqls.extend( + ( + f"select length() from {tbname} ", + f"select length(*) from {tbname} ", + f"select length(ccccccc) from {tbname} ", + f"select length(111) from {tbname} ", + f"select length(c8, 11) from {tbname} ", + ) + ) + + return sqls + + def __test_current(self): + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + for tb in tbname: + self.__length_current_check(tb) + tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") + + def __test_error(self): + tdLog.printNoPrefix("==========err sql condition check , must return error==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + + for tb in tbname: + for errsql in self.__length_err_check(tb): + tdSql.error(sql=errsql) + tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") + + + def all_test(self): + self.__test_current() + self.__test_error() + + + def __create_tb(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + create_stb_sql = f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) tags (t1 int) + ''' + create_ntb_sql = f'''create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + def __insert_data(self, rows): + now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + for i in range(rows): + tdSql.execute( + f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f'''insert into ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) + ''' + ) + + tdSql.execute( + f'''insert into ct4 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} + ) + ( + { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} + ) + ''' + ) + + tdSql.execute( + f'''insert into ct2 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + for i in range(rows): + insert_data = f'''insert into t1 values + ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) + ''' + tdSql.execute(insert_data) + tdSql.execute( + f'''insert into t1 values + ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.__insert_data(10) + + tdLog.printNoPrefix("==========step3:all check") + self.all_test() + + # tdDnodes.stop(1) + # tdDnodes.start(1) + + # tdSql.execute("use db") + + # tdLog.printNoPrefix("==========step4:after wal, all check again ") + # self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/log.py b/tests/system-test/2-query/log.py new file mode 100644 index 0000000000000000000000000000000000000000..e6762b2d61205119b39f7c21ddca9e81a5f7c9a3 --- /dev/null +++ b/tests/system-test/2-query/log.py @@ -0,0 +1,652 @@ +import taos +import sys +import datetime +import inspect +import math +from util.log import * +from util.sql import * +from util.cases import * + + + +class TDTestCase: + 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 ,"fnDebugFlag":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 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + for i in range(9): + tdSql.execute( + f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into t1 values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ''' + ) + + def check_result_auto_log2(self ,origin_query , log_query): + + log_result = tdSql.getResult(log_query) + origin_result = tdSql.getResult(origin_query) + + auto_result =[] + + for row in origin_result: + row_check = [] + for elem in row: + if elem == None: + elem = None + elif elem >0: + elem = math.log(elem,2) + elif elem <=0: + elem = None + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + for row_index , row in enumerate(log_result): + for col_index , elem in enumerate(row): + if auto_result[row_index][col_index] != elem: + check_status = False + if not check_status: + tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query ) + sys.exit(1) + else: + tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query ) + + def check_result_auto_log1(self ,origin_query , log_query): + log_result = tdSql.getResult(log_query) + origin_result = tdSql.getResult(origin_query) + + auto_result =[] + + for row in origin_result: + row_check = [] + for elem in row: + if elem == None: + elem = None + elif elem >0: + elem = None + elif elem <=0: + elem = None + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + for row_index , row in enumerate(log_result): + for col_index , elem in enumerate(row): + if auto_result[row_index][col_index] != elem: + check_status = False + if not check_status: + tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query ) + sys.exit(1) + else: + tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query ) + def check_result_auto_log__10(self ,origin_query , log_query): + log_result = tdSql.getResult(log_query) + origin_result = tdSql.getResult(origin_query) + + auto_result =[] + + for row in origin_result: + row_check = [] + for elem in row: + if elem == None: + elem = None + elif elem >0: + elem = None + elif elem <=0: + elem = None + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + for row_index , row in enumerate(log_result): + for col_index , elem in enumerate(row): + if auto_result[row_index][col_index] != elem: + check_status = False + if not check_status: + tdLog.notice("log function value has not as expected , sql is \"%s\" "%log_query ) + sys.exit(1) + else: + tdLog.info("log value check pass , it work as expected ,sql is \"%s\" "%log_query ) + + def test_errors(self): + error_sql_lists = [ + "select log from t1", + # "select log(-+--+c1 ,2) from t1", + # "select +-log(c1,2) from t1", + # "select ++-log(c1,2) from t1", + # "select ++--log(c1,2) from t1", + # "select - -log(c1,2)*0 from t1", + # "select log(tbname+1,2) from t1 ", + "select log(123--123,2)==1 from t1", + "select log(c1,2) as 'd1' from t1", + "select log(c1 ,c2 ,2) from t1", + "select log(c1 ,NULL ,2) from t1", + "select log(, 2) from t1;", + "select log(log(c1, 2) ab from t1)", + "select log(c1 ,2 ) as int from t1", + "select log from stb1", + # "select log(-+--+c1) from stb1", + # "select +-log(c1) from stb1", + # "select ++-log(c1) from stb1", + # "select ++--log(c1) from stb1", + # "select - -log(c1)*0 from stb1", + # "select log(tbname+1) from stb1 ", + "select log(123--123 ,2)==1 from stb1", + "select log(c1 ,2) as 'd1' from stb1", + "select log(c1 ,c2 ,2 ) from stb1", + "select log(c1 ,NULL,2) from stb1", + "select log(,) from stb1;", + "select log(log(c1 , 2) ab from stb1)", + "select log(c1 , 2) as int from stb1" + ] + for error_sql in error_sql_lists: + tdSql.error(error_sql) + + def support_types(self): + type_error_sql_lists = [ + "select log(ts ,2 ) from t1" , + "select log(c7,2 ) from t1", + "select log(c8,2 ) from t1", + "select log(c9,2 ) from t1", + "select log(ts,2 ) from ct1" , + "select log(c7,2 ) from ct1", + "select log(c8,2 ) from ct1", + "select log(c9,2 ) from ct1", + "select log(ts,2 ) from ct3" , + "select log(c7,2 ) from ct3", + "select log(c8,2 ) from ct3", + "select log(c9,2 ) from ct3", + "select log(ts,2 ) from ct4" , + "select log(c7,2 ) from ct4", + "select log(c8,2 ) from ct4", + "select log(c9,2 ) from ct4", + "select log(ts,2 ) from stb1" , + "select log(c7,2 ) from stb1", + "select log(c8,2 ) from stb1", + "select log(c9,2 ) from stb1" , + + "select log(ts,2 ) from stbbb1" , + "select log(c7,2 ) from stbbb1", + + "select log(ts,2 ) from tbname", + "select log(c9,2 ) from tbname" + + ] + + for type_sql in type_error_sql_lists: + tdSql.error(type_sql) + + + type_sql_lists = [ + "select log(c1,2 ) from t1", + "select log(c2,2 ) from t1", + "select log(c3,2 ) from t1", + "select log(c4,2 ) from t1", + "select log(c5,2 ) from t1", + "select log(c6,2 ) from t1", + + "select log(c1,2 ) from ct1", + "select log(c2,2 ) from ct1", + "select log(c3,2 ) from ct1", + "select log(c4,2 ) from ct1", + "select log(c5,2 ) from ct1", + "select log(c6,2 ) from ct1", + + "select log(c1,2 ) from ct3", + "select log(c2,2 ) from ct3", + "select log(c3,2 ) from ct3", + "select log(c4,2 ) from ct3", + "select log(c5,2 ) from ct3", + "select log(c6,2 ) from ct3", + + "select log(c1,2 ) from stb1", + "select log(c2,2 ) from stb1", + "select log(c3,2 ) from stb1", + "select log(c4,2 ) from stb1", + "select log(c5,2 ) from stb1", + "select log(c6,2 ) from stb1", + + "select log(c6,2) as alisb from stb1", + "select log(c6,2) alisb from stb1", + ] + + for type_sql in type_sql_lists: + tdSql.query(type_sql) + + def basic_log_function(self): + + # basic query + tdSql.query("select c1 from ct3") + tdSql.checkRows(0) + tdSql.query("select c1 from t1") + tdSql.checkRows(12) + tdSql.query("select c1 from stb1") + tdSql.checkRows(25) + + # used for empty table , ct3 is empty + tdSql.query("select log(c1 ,2) from ct3") + tdSql.checkRows(0) + tdSql.query("select log(c2 ,2) from ct3") + tdSql.checkRows(0) + tdSql.query("select log(c3 ,2) from ct3") + tdSql.checkRows(0) + tdSql.query("select log(c4 ,2) from ct3") + tdSql.checkRows(0) + tdSql.query("select log(c5 ,2) from ct3") + tdSql.checkRows(0) + tdSql.query("select log(c6 ,2) from ct3") + tdSql.checkRows(0) + + + # # used for regular table + tdSql.query("select log(c1 ,2) from t1") + tdSql.checkData(0, 0, None) + tdSql.checkData(1 , 0, 0.000000000) + tdSql.checkData(3 , 0, 1.584962501) + tdSql.checkData(5 , 0, None) + + tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 4, 1.11000) + tdSql.checkData(3, 3, 33) + tdSql.checkData(5, 4, None) + + tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 5, 1.11000) + tdSql.checkData(3, 4, 33) + tdSql.checkData(5, 5, None) + + self.check_result_auto_log2( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,2), log(c2 ,2) ,log(c3, 2), log(c4 ,2), log(c5 ,2) from t1") + self.check_result_auto_log1( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,1), log(c2 ,1) ,log(c3, 1), log(c4 ,1), log(c5 ,1) from t1") + self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 from t1", "select log(c1 ,-10), log(c2 ,-10) ,log(c3, -10), log(c4 ,-10), log(c5 ,-10) from t1") + + # used for sub table + tdSql.query("select c1 ,log(c1 ,3) from ct1") + tdSql.checkData(0, 1, 1.892789261) + tdSql.checkData(1 , 1, 1.771243749) + tdSql.checkData(3 , 1, 1.464973521) + tdSql.checkData(4 , 1, None) + + # test bug fix for log(c1,c2) + + tdSql.query("select c1, c2 ,log(c1,c2) from ct1") + tdSql.checkData(0 , 2, 0.182485070) + tdSql.checkData(1 , 2, 0.172791608) + tdSql.checkData(2 , 2, 0.161311499) + tdSql.checkData(3 , 2, 0.147315235) + tdSql.checkData(4 , 2, None) + + + self.check_result_auto_log2( "select c1, c2, c3 , c4, c5 from ct1", "select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) from ct1") + self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 from ct1", "select log(c1,-10), log(c2,-10) ,log(c3,-10), log(c4,-10), log(c5,-10) from ct1") + + # nest query for log functions + tdSql.query("select c1 , log(c1,3) ,log(log(c1,3),3) , log(log(log(c1,3),3),3) from ct1;") + tdSql.checkData(0 , 0 , 8) + tdSql.checkData(0 , 1 , 1.892789261) + tdSql.checkData(0 , 2 , 0.580779541) + tdSql.checkData(0 , 3 , -0.494609470) + + tdSql.checkData(1 , 0 , 7) + tdSql.checkData(1 , 1 , 1.771243749) + tdSql.checkData(1 , 2 , 0.520367366) + tdSql.checkData(1 , 3 , -0.594586689) + + tdSql.checkData(4 , 0 , 0) + tdSql.checkData(4 , 1 , None) + tdSql.checkData(4 , 2 , None) + tdSql.checkData(4 , 3 , None) + + # # used for stable table + + tdSql.query("select log(c1, 2) from stb1") + tdSql.checkRows(25) + + + # used for not exists table + tdSql.error("select log(c1, 2) from stbbb1") + tdSql.error("select log(c1, 2) from tbname") + tdSql.error("select log(c1, 2) from ct5") + + # mix with common col + tdSql.query("select c1, log(c1 ,2) from ct1") + tdSql.checkData(0 , 0 ,8) + tdSql.checkData(0 , 1 ,3.000000000) + tdSql.checkData(4 , 0 ,0) + tdSql.checkData(4 , 1 ,None) + tdSql.query("select c1, log(c1,2) from ct4") + tdSql.checkData(0 , 0 , None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,2.321928095) + tdSql.checkData(5 , 0 ,None) + tdSql.checkData(5 , 1 ,None) + tdSql.query("select c1, log(c1 ,2 ) from ct4 ") + tdSql.checkData(0 , 0 ,None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,2.321928095) + + # mix with common functions + tdSql.query("select c1, log(c1 ,2),c5, log(c5 ,2) from ct4 ") + tdSql.checkData(0 , 0 ,None) + 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.584962501) + tdSql.checkData(3 , 2 ,6.66000) + tdSql.checkData(3 , 3 ,2.735522144) + + tdSql.query("select c1, log(c1,1),c5, floor(c5 ) from stb1 ") + + # # mix with agg functions , not support + tdSql.error("select c1, log(c1 ,2),c5, count(c5) from stb1 ") + tdSql.error("select c1, log(c1 ,2),c5, count(c5) from ct1 ") + tdSql.error("select log(c1 ,2), count(c5) from stb1 ") + tdSql.error("select log(c1 ,2), count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from stb1 ") + + # agg functions mix with agg functions + + 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) + tdSql.query("select count(*) from ct4 ") + tdSql.checkData(0,0,12) + tdSql.query("select count(c1) from stb1 ") + tdSql.checkData(0,0,22) + tdSql.query("select count(*) from stb1 ") + tdSql.checkData(0,0,25) + + # # bug fix for compute + tdSql.query("select c1, log(c1 ,2) -0 ,log(c1-4 ,2)-0 from ct4 ") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 3.000000000) + tdSql.checkData(1, 2, 2.000000000) + + tdSql.query(" select c1, log(c1 ,2) -0 ,log(c1-0.1 ,2)-0.1 from ct4") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 3.000000000) + tdSql.checkData(1, 2, 2.881852653) + + tdSql.query("select c1, log(c1, -10), c2, log(c2, -10), c3, log(c3, -10) from ct1") + + def test_big_number(self): + + tdSql.query("select c1, log(c1, 100000000) from ct1") # bigint to double data overflow + tdSql.checkData(0, 1, 0.112886248) + tdSql.checkData(1, 1, 0.105637255) + tdSql.checkData(4, 1, None) + + + tdSql.query("select c1, log(c1, 10000000000000) from ct1") # bigint to double data overflow + tdSql.checkData(0, 1, 0.069468461) + tdSql.checkData(1, 1, 0.065007542) + tdSql.checkData(4, 1, None) + + tdSql.query("select c1, log(c1, 10000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query("select c1, log(c1, 10000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.checkData(0, 1, 0.036123599) + tdSql.checkData(1, 1, 0.033803922) + tdSql.checkData(4, 1, None) + + tdSql.query("select c1, log(c1, 10000000000000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query("select c1, log(c1, 10000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.checkData(0, 1, 0.026561470) + tdSql.checkData(1, 1, 0.024855825) + tdSql.checkData(4, 1, None) + + tdSql.query("select c1, log(c1, 10000000000000000000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query("select c1, log(c1, 10000000000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.checkData(0, 1, 0.022577250) + tdSql.checkData(1, 1, 0.021127451) + tdSql.checkData(4, 1, None) + + tdSql.query("select c1, log(c1, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1") # bigint to double data overflow + + def log_base_test(self): + + # base is an regular number ,int or double + tdSql.query("select c1, log(c1, 2) from ct1") + tdSql.checkData(0, 1,3.000000000) + tdSql.query("select c1, log(c1, 2.0) from ct1") + tdSql.checkData(0, 1, 3.000000000) + + tdSql.query("select c1, log(1, 2.0) from ct1") + tdSql.checkData(0, 1, 0.000000000) + tdSql.checkRows(13) + + + # # bug for compute in functions + # tdSql.query("select c1, abs(1/0) from ct1") + # tdSql.checkData(0, 0, 8) + # tdSql.checkData(0, 1, 1) + + tdSql.query("select c1, log(1, 2.0) from ct1") + tdSql.checkData(0, 1, 0.000000000) + tdSql.checkRows(13) + + # two cols start log(x,y) + tdSql.query("select c1,c2, log(c1,c2) from ct1") + tdSql.checkData(0, 2, 0.182485070) + tdSql.checkData(1, 2, 0.172791608) + tdSql.checkData(4, 2, None) + + tdSql.query("select c1,c2, log(c2,c1) from ct1") + tdSql.checkData(0, 2, 5.479900349) + tdSql.checkData(1, 2, 5.787318105) + tdSql.checkData(4, 2, None) + + tdSql.query("select c1, log(2.0 , c1) from ct1") + tdSql.checkData(0, 1, 0.333333333) + tdSql.checkData(1, 1, 0.356207187) + tdSql.checkData(4, 1, None) + + tdSql.query("select c1, log(2.0 , ceil(abs(c1))) from ct1") + tdSql.checkData(0, 1, 0.333333333) + tdSql.checkData(1, 1, 0.356207187) + tdSql.checkData(4, 1, None) + + + def abs_func_filter(self): + tdSql.execute("use db") + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + tdSql.checkRows(3) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,8.000000000) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,7.900000000) + tdSql.checkData(0,4,3.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,88888) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,8.000000000) + tdSql.checkData(0,4,7.900000000) + tdSql.checkData(0,5,3.000000000) + + def log_Arithmetic(self): + pass + + def check_boundary_values(self): + + tdSql.execute("drop database if exists bound_test") + tdSql.execute("create database if not exists bound_test") + time.sleep(3) + tdSql.execute("use bound_test") + tdSql.execute( + "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + ) + tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+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_log2( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1,2), log(c2,2) ,log(c3,2), log(c4,2), log(c5,2) ,log(c6,2) from sub1_bound") + self.check_result_auto_log__10( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select log(c1,-10), log(c2,-10) ,log(c3,-10), log(c4,-10), log(c5,-10) ,log(c6,-10) from sub1_bound") + + self.check_result_auto_log2( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select log(c1,2), log(c2,2) ,log(c3,2), log(c3,2), log(c2,2) ,log(c1,2) from sub1_bound") + + + self.check_result_auto_log2("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select log(abs(c1) ,2) from sub1_bound" ) + + # check basic elem for table per row + tdSql.query("select log(abs(c1),2) ,log(abs(c2),2) , log(abs(c3),2) , log(abs(c4),2), log(abs(c5),2), log(abs(c6),2) from sub1_bound ") + tdSql.checkData(0,0,math.log(2147483647,2)) + tdSql.checkData(0,1,math.log(9223372036854775807 ,2)) + tdSql.checkData(0,2,math.log(32767,2)) + tdSql.checkData(0,3,math.log(127 ,2)) + tdSql.checkData(0,4,math.log(339999995214436424907732413799364296704.00000,2)) + tdSql.checkData(0,5,math.log(169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000 ,2)) + tdSql.checkData(1,0,math.log(2147483647 ,2)) + tdSql.checkData(1,1,math.log(9223372036854775807 ,2)) + tdSql.checkData(1,2,math.log(32767 ,2)) + tdSql.checkData(1,3,math.log(127,2)) + tdSql.checkData(1,4,math.log(339999995214436424907732413799364296704.00000 ,2)) + tdSql.checkData(1,5,math.log(169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000 ,2)) + tdSql.checkData(3,0,math.log(2147483646,2)) + tdSql.checkData(3,1,math.log(9223372036854775806,2)) + tdSql.checkData(3,2,math.log(32766,2)) + tdSql.checkData(3,3,math.log(126 ,2)) + tdSql.checkData(3,4,math.log(339999995214436424907732413799364296704.00000,2)) + tdSql.checkData(3,5,math.log(169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000,2)) + + # check + - * / in functions + tdSql.query("select log(abs(c1+1) ,2) ,log(abs(c2),2) , log(abs(c3*1),2) , log(abs(c4/2),2), log(abs(c5) ,2)/2, log(abs(c6) ,2) from sub1_bound ") + tdSql.checkData(0,0,math.log(2147483648.000000000,2)) + tdSql.checkData(0,1,math.log(9223372036854775807,2)) + tdSql.checkData(0,2,math.log(32767.000000000,2)) + tdSql.checkData(0,3,math.log(63.500000000,2)) + tdSql.checkData(0,4,63.999401166) + + + 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 ==============") + + self.test_errors() + + tdLog.printNoPrefix("==========step3:support types ============") + + self.support_types() + + tdLog.printNoPrefix("==========step4: log basic query ============") + + self.basic_log_function() + + tdLog.printNoPrefix("==========step5: big number log query ============") + + self.test_big_number() + + tdLog.printNoPrefix("==========step6: base number for log query ============") + + self.log_base_test() + + tdLog.printNoPrefix("==========step7: log boundary query ============") + + self.check_boundary_values() + + tdLog.printNoPrefix("==========step8: log filter query ============") + + self.abs_func_filter() + + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/lower.py b/tests/system-test/2-query/lower.py new file mode 100644 index 0000000000000000000000000000000000000000..5445c37b8a0b5e08998371585f0e293c36378320 --- /dev/null +++ b/tests/system-test/2-query/lower.py @@ -0,0 +1,246 @@ +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + +INT_COL = "c1" +BINT_COL = "c2" +SINT_COL = "c3" +TINT_COL = "c4" +FLOAT_COL = "c5" +DOUBLE_COL = "c6" +BOOL_COL = "c7" + +BINARY_COL = "c8" +NCHAR_COL = "c9" +TS_COL = "c10" + +UN_CHAR_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL, ] +CHAR_COL = [ BINARY_COL, NCHAR_COL, ] +TS_TYPE_COL = [TS_COL] + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def __lower_condition(self): + lower_condition = [] + for char_col in CHAR_COL: + lower_condition.extend( + ( + char_col, + f"upper( {char_col} )", + ) + ) + lower_condition.extend(f"cast( {un_char_col} as binary(16) ) " for un_char_col in UN_CHAR_COL) + lower_condition.extend( f"cast( {char_col} + {char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + lower_condition.extend( f"cast( {char_col} + {un_char_col} as binary(32) ) " for un_char_col in UN_CHAR_COL ) + + lower_condition.append('''"test1234!@#$%^&*():'> 0 " + return "" + + def __group_condition(self, col, having = ""): + return f" group by {col} having {having}" if having else f" group by {col} " + + def __lower_current_check(self, tbname): + lower_condition = self.__lower_condition() + for condition in lower_condition: + where_condition = self.__where_condition(condition) + group_having = self.__group_condition(condition, having=f"{condition} is not null " ) + group_no_having= self.__group_condition(condition ) + groups = ["", group_having, group_no_having] + + for group_condition in groups: + tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + lower_data = [ str(data).lower() if data else None for data in datas ] + tdSql.query(f"select lower( {condition} ) from {tbname} {where_condition} {group_condition}") + for i in range(len(lower_data)): + tdSql.checkData(i, 0, lower_data[i] ) if lower_data[i] else tdSql.checkData(i, 0, None) + + def __lower_err_check(self,tbname): + sqls = [] + + for un_char_col in UN_CHAR_COL: + sqls.extend( + ( + f"select lower( {un_char_col} ) from {tbname} ", + f"select lower(ceil( {un_char_col} )) from {tbname} ", + f"select {un_char_col} from {tbname} group by lower( {un_char_col} ) ", + ) + ) + + sqls.extend( f"select lower( {un_char_col} + {un_char_col_2} ) from {tbname} " for un_char_col_2 in UN_CHAR_COL ) + sqls.extend( f"select lower( {un_char_col} + {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + + sqls.extend( f"select {char_col} from {tbname} group by lower( {char_col} ) " for char_col in CHAR_COL) + sqls.extend( f"select lower( {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + sqls.extend( f"select lower( {char_col} + {ts_col} ) from {tbname} " for char_col in UN_CHAR_COL for ts_col in TS_TYPE_COL) + sqls.extend( f"select lower( {char_col} + {char_col_2} ) from {tbname} " for char_col in CHAR_COL for char_col_2 in CHAR_COL ) + sqls.extend( f"select upper({char_col}, 11) from {tbname} " for char_col in CHAR_COL ) + sqls.extend( f"select upper({char_col}) from {tbname} interval(2d) sliding(1d)" for char_col in CHAR_COL ) + sqls.extend( + ( + f"select lower() from {tbname} ", + f"select lower(*) from {tbname} ", + f"select lower(ccccccc) from {tbname} ", + f"select lower(111) from {tbname} ", + f"select lower(c8, 11) from {tbname} ", + ) + ) + + return sqls + + def __test_current(self): + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + for tb in tbname: + self.__lower_current_check(tb) + tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") + + def __test_error(self): + tdLog.printNoPrefix("==========err sql condition check , must return error==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + + for tb in tbname: + for errsql in self.__lower_err_check(tb): + tdSql.error(sql=errsql) + tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") + + + def all_test(self): + self.__test_current() + self.__test_error() + + + def __create_tb(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + create_stb_sql = f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) tags (t1 int) + ''' + create_ntb_sql = f'''create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + def __insert_data(self, rows): + now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + for i in range(rows): + tdSql.execute( + f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f'''insert into ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) + ''' + ) + + tdSql.execute( + f'''insert into ct4 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} + ) + ( + { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} + ) + ''' + ) + + tdSql.execute( + f'''insert into ct2 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + for i in range(rows): + insert_data = f'''insert into t1 values + ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) + ''' + tdSql.execute(insert_data) + tdSql.execute( + f'''insert into t1 values + ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.__insert_data(10) + + tdLog.printNoPrefix("==========step3:all check") + self.all_test() + + # tdDnodes.stop(1) + # tdDnodes.start(1) + + # tdSql.execute("use db") + + # tdLog.printNoPrefix("==========step4:after wal, all check again ") + # self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/round.py b/tests/system-test/2-query/round.py new file mode 100644 index 0000000000000000000000000000000000000000..223e56bce65de91d8a0ff5c677bc6e17993579c7 --- /dev/null +++ b/tests/system-test/2-query/round.py @@ -0,0 +1,467 @@ +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * + +class TDTestCase: + 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 ,"fnDebugFlag":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 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + + tdSql.execute( + ''' + create table t1 + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + for i in range(9): + tdSql.execute( + f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute( + f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + ) + tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into t1 values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '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: + if elem == None: + elem = None + else: + elem = round(elem) + row_check.append(elem) + auto_result.append(row_check) + + check_status = True + 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 + 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", + # "select round(-+--+c1) from t1", + # "select +-round(c1) from t1", + # "select ++-round(c1) from t1", + # "select ++--round(c1) from t1", + # "select - -round(c1)*0 from t1", + # "select round(tbname+1) from t1 ", + "select round(123--123)==1 from t1", + "select round(c1) as 'd1' from t1", + "select round(c1 ,c2 ) from t1", + "select round(c1 ,NULL) from t1", + "select round(,) from t1;", + "select round(round(c1) ab from t1)", + "select round(c1) as int from t1", + "select round from stb1", + # "select round(-+--+c1) from stb1", + # "select +-round(c1) from stb1", + # "select ++-round(c1) from stb1", + # "select ++--round(c1) from stb1", + # "select - -round(c1)*0 from stb1", + # "select round(tbname+1) from stb1 ", + "select round(123--123)==1 from stb1", + "select round(c1) as 'd1' from stb1", + "select round(c1 ,c2 ) from stb1", + "select round(c1 ,NULL) from stb1", + "select round(,) from stb1;", + "select round(round(c1) ab from stb1)", + "select round(c1) as int from stb1" + ] + 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(c7) from t1", + "select round(c8) from t1", + "select round(c9) from t1", + "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(c7) from ct3", + "select round(c8) from ct3", + "select round(c9) from ct3", + "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(c7) from stb1", + "select round(c8) from stb1", + "select round(c9) from stb1" , + + "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", + "select round(c3) from t1", + "select round(c4) from t1", + "select round(c5) from t1", + "select round(c6) from t1", + + "select round(c1) from ct1", + "select round(c2) from ct1", + "select round(c3) from ct1", + "select round(c4) from ct1", + "select round(c5) from ct1", + "select round(c6) from ct1", + + "select round(c1) from ct3", + "select round(c2) from ct3", + "select round(c3) from ct3", + "select round(c4) from ct3", + "select round(c5) from ct3", + "select round(c6) from ct3", + + "select round(c1) from stb1", + "select round(c2) from stb1", + "select round(c3) from stb1", + "select round(c4) from stb1", + "select round(c5) from stb1", + "select round(c6) 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 + tdSql.query("select c1 from ct3") + tdSql.checkRows(0) + tdSql.query("select c1 from t1") + tdSql.checkRows(12) + tdSql.query("select c1 from stb1") + tdSql.checkRows(25) + + # used for empty table , ct3 is empty + tdSql.query("select round(c1) from ct3") + tdSql.checkRows(0) + tdSql.query("select round(c2) from ct3") + tdSql.checkRows(0) + tdSql.query("select round(c3) from ct3") + tdSql.checkRows(0) + tdSql.query("select round(c4) from ct3") + tdSql.checkRows(0) + 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) + tdSql.checkData(1 , 0, 1) + tdSql.checkData(3 , 0, 3) + tdSql.checkData(5 , 0, None) + + tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 4, 1.11000) + tdSql.checkData(3, 3, 33) + tdSql.checkData(5, 4, None) + tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.checkData(1, 5, 1.11000) + tdSql.checkData(3, 4, 33) + 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) + tdSql.checkData(1 , 0, 7) + tdSql.checkData(3 , 0, 5) + tdSql.checkData(5 , 0, 4) + + tdSql.query("select round(c1) from ct1") + 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 + + 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 + tdSql.query("select c1, round(c1) from ct1") + tdSql.checkData(0 , 0 ,8) + tdSql.checkData(0 , 1 ,8) + tdSql.checkData(4 , 0 ,0) + tdSql.checkData(4 , 1 ,0) + tdSql.query("select c1, round(c1) from ct4") + tdSql.checkData(0 , 0 , None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + tdSql.checkData(5 , 0 ,None) + tdSql.checkData(5 , 1 ,None) + tdSql.query("select c1, round(c1) from ct4 ") + tdSql.checkData(0 , 0 ,None) + tdSql.checkData(0 , 1 ,None) + tdSql.checkData(4 , 0 ,5) + tdSql.checkData(4 , 1 ,5) + + # mix with common functions + tdSql.query("select c1, round(c1),c5, round(c5) from ct4 ") + tdSql.checkData(0 , 0 ,None) + 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) + tdSql.checkData(3 , 3 ,7.00000) + + tdSql.checkData(6 , 0 , 4) + tdSql.checkData(6 , 1 , 4) + tdSql.checkData(6 , 2 ,4.44000) + tdSql.checkData(6 , 3 ,4.00000) + + tdSql.query("select c1, round(c1),c5, round(c5) from stb1 ") + + # mix with agg functions , not support + tdSql.error("select c1, round(c1),c5, count(c5) from stb1 ") + tdSql.error("select c1, round(c1),c5, count(c5) from ct1 ") + tdSql.error("select round(c1), count(c5) from stb1 ") + tdSql.error("select round(c1), count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from ct1 ") + tdSql.error("select c1, count(c5) from stb1 ") + + # agg functions mix with agg functions + + 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) + tdSql.query("select count(*) from ct4 ") + tdSql.checkData(0,0,12) + tdSql.query("select count(c1) from stb1 ") + tdSql.checkData(0,0,22) + tdSql.query("select count(*) from stb1 ") + tdSql.checkData(0,0,25) + + # 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) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 8.000000000) + + tdSql.query(" select c1, abs(c1) -0 ,round(c1-0.1)-0.1 from ct4") + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 0, 8) + tdSql.checkData(1, 1, 8.000000000) + tdSql.checkData(1, 2, 7.900000000) + + def abs_func_filter(self): + tdSql.execute("use db") + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + tdSql.checkRows(3) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,8.000000000) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,7.900000000) + tdSql.checkData(0,4,3.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,5) + tdSql.checkData(0,1,5.000000000) + tdSql.checkData(0,2,5.000000000) + tdSql.checkData(0,3,4.900000000) + tdSql.checkData(0,4,2.000000000) + + tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) , round(abs(c1))-0.5 from ct4 where c1>log(c1,2) limit 1 ") + tdSql.checkRows(1) + tdSql.checkData(0,0,8) + tdSql.checkData(0,1,88888) + tdSql.checkData(0,2,8.000000000) + tdSql.checkData(0,3,8.000000000) + 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") + tdSql.execute("create database if not exists bound_test") + time.sleep(3) + tdSql.execute("use bound_test") + tdSql.execute( + "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + ) + tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute( + f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + tdSql.execute( + f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + + tdSql.execute( + f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + + 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.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) + tdSql.checkData(0, 2, 32767.000000000) + tdSql.checkData(0, 3, 127.000000000) + tdSql.checkData(0, 4, 169999997607218212453866206899682148352.000000000) + + tdSql.checkData(4, 0, -2147483643.000000000) + tdSql.checkData(4, 2, -32763.000000000) + tdSql.checkData(4, 3, -123.000000000) + 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 round(c1+1) ,round(c2) , round(c3*1) , round(c4/2), round(c5)/2, round(c6) from sub1_bound ") + + 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 ==============") + + self.test_errors() + + tdLog.printNoPrefix("==========step3:support types ============") + + self.support_types() + + tdLog.printNoPrefix("==========step4: round basic query ============") + + self.basic_round_function() + + tdLog.printNoPrefix("==========step5: round boundary query ============") + + self.check_boundary_values() + + tdLog.printNoPrefix("==========step6: round filter query ============") + + self.abs_func_filter() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 757f5c3c90a072bbc5589a20768b7836c549bf80..9521b005ddcfebedc08c4b618c936726ec4e3c85 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -61,6 +61,7 @@ class TDTestCase: tdSql.checkData(0, 0, sum_data) tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} {group_condition} ") def __sum_err_check(self,tbanme): sqls = [] @@ -131,74 +132,75 @@ class TDTestCase: tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') def __insert_data(self, rows): - for i in range(9): + now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + for i in range(rows): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( now()-{i*90}d, {-1*i}, {-11111*i}, {-111*i}, {-11*i}, {-1.11*i}, {-11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - '''insert into ct1 values - ( now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a ) - ( now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a ) + f'''insert into ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) ''' ) tdSql.execute( f'''insert into ct4 values - ( now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( - now()+{rows * 9-10}d, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d + { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} ) ( - now()+{rows * 9-20}d, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nachar_limit-2", now()-2d + { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} ) ''' ) tdSql.execute( f'''insert into ct2 values - ( now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now()+{rows * 9}d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( - now()+{rows * 9-10}d, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, - { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nachar_limit-1", now()-1d + { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } ) ( - now()+{rows * 9-20}d, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, - { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nachar_limit-2", now()-2d + { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } ) ''' ) for i in range(rows): insert_data = f'''insert into t1 values - ( now()-{i}h, {i}, {i}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, - "binary_{i}", "nchar_{i}", now()-{i}s ) + ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( f'''insert into t1 values - ( now() + 3h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now()-{ ( rows // 2 ) * 60 + 30 }m, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now()-{rows}h, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( now() + 2h, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, - "binary_limit-1", "nachar_limit-1", now()-1d + "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } ) ( - now() + 1h , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, - "binary_limit-2", "nachar_limit-2", now()-2d + "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } ) ''' ) @@ -211,7 +213,7 @@ class TDTestCase: self.__create_tb() tdLog.printNoPrefix("==========step2:insert data") - self.__insert_data(100) + self.__insert_data(10) tdLog.printNoPrefix("==========step3:all check") self.all_test() diff --git a/tests/system-test/2-query/timezone.py b/tests/system-test/2-query/timezone.py index a273b1c0f8ba10936cd1adf29f490979604fc8c5..1f3dac90c6a3e45669510b3a5f208df318e39be7 100644 --- a/tests/system-test/2-query/timezone.py +++ b/tests/system-test/2-query/timezone.py @@ -45,20 +45,15 @@ class TDTestCase: tdSql.query("select timezone() from ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, time_zone) - - - tdSql.query("select timezone() from db.ntb") tdSql.checkRows(2) tdSql.checkData(0, 0, time_zone) - tdSql.query("select timezone() from stb") tdSql.checkRows(2) tdSql.checkData(0, 0, time_zone) tdSql.query("select timezone() from db.stb") tdSql.checkRows(2) tdSql.checkData(0, 0, time_zone) - tdSql.query("select timezone() from stb_1") tdSql.checkRows(2) tdSql.checkData(0, 0, time_zone) @@ -66,14 +61,78 @@ class TDTestCase: tdSql.checkRows(2) tdSql.checkData(0, 0, time_zone) + tdSql.error("select timezone(1) from stb") + tdSql.error("select timezone(1) from db.stb") tdSql.error("select timezone(1) from ntb") + tdSql.error("select timezone(1) from db.ntb") + tdSql.error("select timezone(1) from stb_1") + tdSql.error("select timezone(1) from db.stb_1") tdSql.error("select timezone(now()) from stb") + tdSql.error("select timezone(now()) from db.stb") tdSql.query(f"select * from ntb where timezone()='{time_zone}'") tdSql.checkRows(2) tdSql.query("select timezone()+1 from ntb") tdSql.checkRows(2) + tdSql.query("select timezone()+1 from db.ntb") + tdSql.checkRows(2) + tdSql.query("select timezone()+1 from stb") + tdSql.checkRows(2) + tdSql.query("select timezone()+1 from db.stb") + tdSql.checkRows(2) + tdSql.query("select timezone()+1 from stb_1") + tdSql.checkRows(2) + tdSql.query("select timezone()+1 from db.stb_1") + tdSql.checkRows(2) + tdSql.query("select timezone()+1.5 from ntb") + tdSql.checkRows(2) + tdSql.query("select timezone()+1.5 from db.ntb") + tdSql.checkRows(2) + tdSql.query("select timezone()-100 from ntb") + tdSql.checkRows(2) + tdSql.query("select timezone()*100 from ntb") + tdSql.checkRows(2) + tdSql.query("select timezone()/10 from ntb") + # tdSql.query("select timezone()/0 from ntb") + + tdSql.query("select timezone()+null from ntb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()-null from ntb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()*null from ntb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()/null from ntb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + # tdSql.query("select timezone()") + tdSql.query("select timezone()+null from stb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()-null from stb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()*null from stb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()/null from stb") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()+null from stb_1") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()-null from stb_1") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()*null from stb_1") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) + tdSql.query("select timezone()/null from stb_1") + tdSql.checkRows(2) + tdSql.checkData(0,0,None) def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/system-test/2-query/upper.py b/tests/system-test/2-query/upper.py new file mode 100644 index 0000000000000000000000000000000000000000..3c3fddfb45b29dbc23ceabacae62717ee1155a52 --- /dev/null +++ b/tests/system-test/2-query/upper.py @@ -0,0 +1,245 @@ +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + +INT_COL = "c1" +BINT_COL = "c2" +SINT_COL = "c3" +TINT_COL = "c4" +FLOAT_COL = "c5" +DOUBLE_COL = "c6" +BOOL_COL = "c7" + +BINARY_COL = "c8" +NCHAR_COL = "c9" +TS_COL = "c10" + +UN_CHAR_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL, ] +CHAR_COL = [ BINARY_COL, NCHAR_COL, ] +TS_TYPE_COL = [TS_COL] + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def __upper_condition(self): + upper_condition = [] + for char_col in CHAR_COL: + upper_condition.extend( + ( + char_col, + f"lower( {char_col} )", + ) + ) + upper_condition.extend(f"cast( {un_char_col} as binary(16) ) " for un_char_col in UN_CHAR_COL) + upper_condition.extend( f"cast( {char_col} + {char_col_2} as binary(32) ) " for char_col_2 in CHAR_COL ) + upper_condition.extend( f"cast( {char_col} + {un_char_col} as binary(32) ) " for un_char_col in UN_CHAR_COL ) + + upper_condition.append('''"test1234!@#$%^&*():'> 0 " + return "" + + def __group_condition(self, col, having = ""): + return f" group by {col} having {having}" if having else f" group by {col} " + + def __upper_current_check(self, tbname): + upper_condition = self.__upper_condition() + for condition in upper_condition: + where_condition = self.__where_condition(condition) + group_having = self.__group_condition(condition, having=f"{condition} is not null " ) + group_no_having= self.__group_condition(condition ) + groups = ["", group_having, group_no_having] + + for group_condition in groups: + tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") + datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + upper_data = [ str(data).upper() if data else None for data in datas ] + tdSql.query(f"select upper( {condition} ) from {tbname} {where_condition} {group_condition}") + for i in range(len(upper_data)): + tdSql.checkData(i, 0, upper_data[i] ) if upper_data[i] else tdSql.checkData(i, 0, None) + + def __upper_err_check(self,tbname): + sqls = [] + + for un_char_col in UN_CHAR_COL: + sqls.extend( + ( + f"select upper( {un_char_col} ) from {tbname} ", + f"select upper(ceil( {un_char_col} )) from {tbname} ", + f"select {un_char_col} from {tbname} group by upper( {un_char_col} ) ", + ) + ) + + sqls.extend( f"select upper( {un_char_col} + {un_char_col_2} ) from {tbname} " for un_char_col_2 in UN_CHAR_COL ) + sqls.extend( f"select upper( {un_char_col} + {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + + sqls.extend( f"select {char_col} from {tbname} group by upper( {char_col} ) " for char_col in CHAR_COL) + sqls.extend( f"select upper( {ts_col} ) from {tbname} " for ts_col in TS_TYPE_COL ) + sqls.extend( f"select upper( {char_col} + {ts_col} ) from {tbname} " for char_col in UN_CHAR_COL for ts_col in TS_TYPE_COL) + sqls.extend( f"select upper( {char_col} + {char_col_2} ) from {tbname} " for char_col in CHAR_COL for char_col_2 in CHAR_COL ) + sqls.extend( f"select upper({char_col}, 11) from {tbname} " for char_col in CHAR_COL ) + sqls.extend( f"select upper({char_col}) from {tbname} interval(2d) sliding(1d)" for char_col in CHAR_COL ) + sqls.extend( + ( + f"select upper() from {tbname} ", + f"select upper(*) from {tbname} ", + f"select upper(ccccccc) from {tbname} ", + f"select upper(111) from {tbname} ", + ) + ) + + return sqls + + def __test_current(self): + tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + for tb in tbname: + self.__upper_current_check(tb) + tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") + + def __test_error(self): + tdLog.printNoPrefix("==========err sql condition check , must return error==========") + tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + + for tb in tbname: + for errsql in self.__upper_err_check(tb): + tdSql.error(sql=errsql) + tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") + + + def all_test(self): + self.__test_current() + self.__test_error() + + + def __create_tb(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + create_stb_sql = f'''create table stb1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) tags (t1 int) + ''' + create_ntb_sql = f'''create table t1( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp + ) + ''' + tdSql.execute(create_stb_sql) + tdSql.execute(create_ntb_sql) + + for i in range(4): + tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + + def __insert_data(self, rows): + now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + for i in range(rows): + tdSql.execute( + f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + ) + tdSql.execute( + f'''insert into ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) + ''' + ) + + tdSql.execute( + f'''insert into ct4 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} + ) + ( + { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} + ) + ''' + ) + + tdSql.execute( + f'''insert into ct2 values + ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( + { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + for i in range(rows): + insert_data = f'''insert into t1 values + ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, + "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) + ''' + tdSql.execute(insert_data) + tdSql.execute( + f'''insert into t1 values + ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, + "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + ) + ( + { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, + "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + ) + ''' + ) + + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + self.__create_tb() + + tdLog.printNoPrefix("==========step2:insert data") + self.__insert_data(10) + + tdLog.printNoPrefix("==========step3:all check") + self.all_test() + + # tdDnodes.stop(1) + # tdDnodes.start(1) + + # tdSql.execute("use db") + + # tdLog.printNoPrefix("==========step4:after wal, all check again ") + # self.all_test() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 30477722ab31ee168f060f9eba2916d4f1303504..0b7a71bbe4dc7ccbecb0235802690cf7c8ab4e34 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -1,8 +1,14 @@ #!/bin/bash set -e +set -x + +python3 ./test.py -f 0-others/taosShell.py +python3 ./test.py -f 0-others/taosShellError.py +python3 ./test.py -f 0-others/taosShellNetChk.py + #python3 ./test.py -f 2-query/between.py -#python3 ./test.py -f 2-query/distinct.py +python3 ./test.py -f 2-query/distinct.py python3 ./test.py -f 2-query/varchar.py #python3 ./test.py -f 2-query/timezone.py @@ -11,3 +17,9 @@ python3 ./test.py -f 2-query/Today.py #python3 ./test.py -f 2-query/cast.py + +python3 ./test.py -f 2-query/abs.py +python3 ./test.py -f 2-query/ceil.py +python3 ./test.py -f 2-query/floor.py +python3 ./test.py -f 2-query/round.py +python3 ./test.py -f 2-query/log.py \ No newline at end of file diff --git a/tests/test-all.sh b/tests/test-all.sh index ff9905e2097a41f11875cda7c34a6dcd2c28f69c..67bf66ee40892aadcff1e26f494bb0650657dd5e 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -93,6 +93,7 @@ function runSimCaseOneByOnefq { if [[ $line =~ ^./test.sh* ]] || [[ $line =~ ^run* ]]; then #case=`echo $line | grep sim$ |awk '{print $NF}'` case=`echo $line | grep -o ".*\.sim" |awk '{print $NF}'` + echo "$line running ..." start_time=`date +%s` date +%F\ %T | tee -a out.log diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index db01b84d0e57766f170e8c805804caf9358a85c6..73cdf7f59ce9333f41e9dd2cfd1b7347949790de 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -29,49 +29,49 @@ #define NC "\033[0m" #define min(a, b) (((a) < (b)) ? (a) : (b)) -#define MAX_SQL_STR_LEN (1024 * 1024) -#define MAX_ROW_STR_LEN (16 * 1024) -#define MAX_CONSUMER_THREAD_CNT (16) +#define MAX_SQL_STR_LEN (1024 * 1024) +#define MAX_ROW_STR_LEN (16 * 1024) +#define MAX_CONSUMER_THREAD_CNT (16) typedef struct { - TdThread thread; - int32_t consumerId; + TdThread thread; + int32_t consumerId; - int32_t ifCheckData; - int64_t expectMsgCnt; - - int64_t consumeMsgCnt; - int64_t consumeRowCnt; - int32_t checkresult; + int32_t ifCheckData; + int64_t expectMsgCnt; - char topicString[1024]; - char keyString[1024]; + int64_t consumeMsgCnt; + int64_t consumeRowCnt; + int32_t checkresult; - int32_t numOfTopic; - char topics[32][64]; + char topicString[1024]; + char keyString[1024]; - int32_t numOfKey; - char key[32][64]; - char value[32][64]; + int32_t numOfTopic; + char topics[32][64]; + + int32_t numOfKey; + char key[32][64]; + char value[32][64]; tmq_t* tmq; tmq_list_t* topicList; - + } SThreadInfo; typedef struct { // input from argvs - char cdbName[32]; - char dbName[32]; - int32_t showMsgFlag; - int32_t showRowFlag; - int32_t consumeDelay; // unit s - int32_t numOfThread; - SThreadInfo stThreads[MAX_CONSUMER_THREAD_CNT]; + char cdbName[32]; + char dbName[32]; + int32_t showMsgFlag; + int32_t showRowFlag; + int32_t consumeDelay; // unit s + int32_t numOfThread; + SThreadInfo stThreads[MAX_CONSUMER_THREAD_CNT]; } SConfInfo; static SConfInfo g_stConfInfo; -TdFilePtr g_fp = NULL; +TdFilePtr g_fp = NULL; // char* g_pRowValue = NULL; // TdFilePtr g_fp = NULL; @@ -93,7 +93,6 @@ static void printHelp() { exit(EXIT_SUCCESS); } - void initLogFile() { // FILE *fp = fopen(g_stConfInfo.resultFileName, "a"); char file[256]; @@ -106,36 +105,35 @@ void initLogFile() { g_fp = pFile; } - void saveConfigToLogFile() { time_t tTime = taosGetTimestampSec(); struct tm tm = *taosLocalTime(&tTime, NULL); taosFprintfFile(g_fp, "###################################################################\n"); - taosFprintfFile(g_fp, "# configDir: %s\n", configDir); - taosFprintfFile(g_fp, "# dbName: %s\n", g_stConfInfo.dbName); - taosFprintfFile(g_fp, "# cdbName: %s\n", g_stConfInfo.cdbName); - taosFprintfFile(g_fp, "# showMsgFlag: %d\n", g_stConfInfo.showMsgFlag); - taosFprintfFile(g_fp, "# showRowFlag: %d\n", g_stConfInfo.showRowFlag); - taosFprintfFile(g_fp, "# consumeDelay: %d\n", g_stConfInfo.consumeDelay); - taosFprintfFile(g_fp, "# numOfThread: %d\n", g_stConfInfo.numOfThread); - - for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { + taosFprintfFile(g_fp, "# configDir: %s\n", configDir); + taosFprintfFile(g_fp, "# dbName: %s\n", g_stConfInfo.dbName); + taosFprintfFile(g_fp, "# cdbName: %s\n", g_stConfInfo.cdbName); + taosFprintfFile(g_fp, "# showMsgFlag: %d\n", g_stConfInfo.showMsgFlag); + taosFprintfFile(g_fp, "# showRowFlag: %d\n", g_stConfInfo.showRowFlag); + taosFprintfFile(g_fp, "# consumeDelay: %d\n", g_stConfInfo.consumeDelay); + taosFprintfFile(g_fp, "# numOfThread: %d\n", g_stConfInfo.numOfThread); + + for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { taosFprintfFile(g_fp, "# consumer %d info:\n", g_stConfInfo.stThreads[i].consumerId); - taosFprintfFile(g_fp, " Topics: "); - for (int j = 0 ; j < g_stConfInfo.stThreads[i].numOfTopic; j++) { - taosFprintfFile(g_fp, "%s, ", g_stConfInfo.stThreads[i].topics[j]); + taosFprintfFile(g_fp, " Topics: "); + for (int j = 0; j < g_stConfInfo.stThreads[i].numOfTopic; j++) { + taosFprintfFile(g_fp, "%s, ", g_stConfInfo.stThreads[i].topics[j]); } - taosFprintfFile(g_fp, "\n"); + taosFprintfFile(g_fp, "\n"); taosFprintfFile(g_fp, " Key: "); - for (int k = 0 ; k < g_stConfInfo.stThreads[i].numOfKey; k++) { - taosFprintfFile(g_fp, "%s:%s, ", g_stConfInfo.stThreads[i].key[k], g_stConfInfo.stThreads[i].value[k]); + for (int k = 0; k < g_stConfInfo.stThreads[i].numOfKey; k++) { + taosFprintfFile(g_fp, "%s:%s, ", g_stConfInfo.stThreads[i].key[k], g_stConfInfo.stThreads[i].value[k]); } taosFprintfFile(g_fp, "\n"); } - + taosFprintfFile(g_fp, "# Test time: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, - tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); taosFprintfFile(g_fp, "###################################################################\n"); } @@ -168,7 +166,7 @@ void parseArgument(int32_t argc, char* argv[]) { } initLogFile(); - + taosFprintfFile(g_fp, "====parseArgument() success\n"); #if 1 @@ -203,26 +201,26 @@ void ltrim(char* str) { // return str; } -static int running = 1; +static int running = 1; static int32_t msg_process(TAOS_RES* msg, int64_t msgIndex, int32_t threadLable) { - char buf[1024]; + char buf[1024]; int32_t totalRows = 0; - //printf("topic: %s\n", tmq_get_topic_name(msg)); - //printf("vg:%d\n", tmq_get_vgroup_id(msg)); - taosFprintfFile(g_fp, "msg index:%" PRId64 ", threadLable: %d\n", msgIndex, threadLable); - taosFprintfFile(g_fp, "topic: %s, vgroupId: %d\n", tmq_get_topic_name(msg), tmq_get_vgroup_id(msg)); - + // printf("topic: %s\n", tmq_get_topic_name(msg)); + // printf("vg:%d\n", tmq_get_vgroup_id(msg)); + taosFprintfFile(g_fp, "msg index:%" PRId64 ", threadLable: %d\n", msgIndex, threadLable); + taosFprintfFile(g_fp, "topic: %s, vgroupId: %d\n", tmq_get_topic_name(msg), tmq_get_vgroup_id(msg)); + while (1) { TAOS_ROW row = taos_fetch_row(msg); if (row == NULL) break; - if (0 != g_stConfInfo.showRowFlag) { - TAOS_FIELD* fields = taos_fetch_fields(msg); + if (0 != g_stConfInfo.showRowFlag) { + TAOS_FIELD* fields = taos_fetch_fields(msg); int32_t numOfFields = taos_field_count(msg); taos_print_row(buf, row, fields, numOfFields); - taosFprintfFile(g_fp, "rows[%d]: %s\n", totalRows, buf); - } - totalRows++; + taosFprintfFile(g_fp, "rows[%d]: %s\n", totalRows, buf); + } + totalRows++; } return totalRows; @@ -241,43 +239,43 @@ int queryDB(TAOS* taos, char* command) { return 0; } -static void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets) { +static void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets, void* param) { printf("tmq_commit_cb_print() commit %d\n", resp); } -void build_consumer(SThreadInfo *pInfo) { +void build_consumer(SThreadInfo* pInfo) { tmq_conf_t* conf = tmq_conf_new(); - //tmq_conf_set(conf, "td.connect.ip", "localhost"); - //tmq_conf_set(conf, "td.connect.port", "6030"); + // tmq_conf_set(conf, "td.connect.ip", "localhost"); + // tmq_conf_set(conf, "td.connect.port", "6030"); tmq_conf_set(conf, "td.connect.user", "root"); tmq_conf_set(conf, "td.connect.pass", "taosdata"); tmq_conf_set(conf, "td.connect.db", g_stConfInfo.dbName); - tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print); + tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print, NULL); // tmq_conf_set(conf, "group.id", "cgrp1"); for (int32_t i = 0; i < pInfo->numOfKey; i++) { tmq_conf_set(conf, pInfo->key[i], pInfo->value[i]); } - //tmq_conf_set(conf, "client.id", "c-001"); + // tmq_conf_set(conf, "client.id", "c-001"); + + // tmq_conf_set(conf, "enable.auto.commit", "true"); + // tmq_conf_set(conf, "enable.auto.commit", "false"); + + // tmq_conf_set(conf, "auto.commit.interval.ms", "1000"); - //tmq_conf_set(conf, "enable.auto.commit", "true"); - //tmq_conf_set(conf, "enable.auto.commit", "false"); + // tmq_conf_set(conf, "auto.offset.reset", "none"); + // tmq_conf_set(conf, "auto.offset.reset", "earliest"); + // tmq_conf_set(conf, "auto.offset.reset", "latest"); - //tmq_conf_set(conf, "auto.commit.interval.ms", "1000"); - - //tmq_conf_set(conf, "auto.offset.reset", "none"); - //tmq_conf_set(conf, "auto.offset.reset", "earliest"); - //tmq_conf_set(conf, "auto.offset.reset", "latest"); - pInfo->tmq = tmq_consumer_new(conf, NULL, 0); return; } -void build_topic_list(SThreadInfo *pInfo) { +void build_topic_list(SThreadInfo* pInfo) { pInfo->topicList = tmq_list_new(); // tmq_list_append(topic_list, "test_stb_topic_1"); for (int32_t i = 0; i < pInfo->numOfTopic; i++) { @@ -286,41 +284,37 @@ void build_topic_list(SThreadInfo *pInfo) { return; } -int32_t saveConsumeResult(SThreadInfo *pInfo) { +int32_t saveConsumeResult(SThreadInfo* pInfo) { char sqlStr[1024] = {0}; - + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); assert(pConn != NULL); - + // schema: ts timestamp, consumerid int, consummsgcnt bigint, checkresult int - sprintf(sqlStr, "insert into %s.consumeresult values (now, %d, %" PRId64 ", %" PRId64 ", %d)", - g_stConfInfo.cdbName, - pInfo->consumerId, - pInfo->consumeMsgCnt, - pInfo->consumeRowCnt, - pInfo->checkresult); - + sprintf(sqlStr, "insert into %s.consumeresult values (now, %d, %" PRId64 ", %" PRId64 ", %d)", g_stConfInfo.cdbName, + pInfo->consumerId, pInfo->consumeMsgCnt, pInfo->consumeRowCnt, pInfo->checkresult); + TAOS_RES* pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { printf("error in save consumeinfo, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); exit(-1); } - + taos_free_result(pRes); return 0; } -void loop_consume(SThreadInfo *pInfo) { +void loop_consume(SThreadInfo* pInfo) { tmq_resp_err_t err; - + int64_t totalMsgs = 0; int64_t totalRows = 0; while (running) { TAOS_RES* tmqMsg = tmq_consumer_poll(pInfo->tmq, g_stConfInfo.consumeDelay * 1000); - if (tmqMsg) { + if (tmqMsg) { if (0 != g_stConfInfo.showMsgFlag) { totalRows += msg_process(tmqMsg, totalMsgs, pInfo->consumerId); } @@ -328,7 +322,7 @@ void loop_consume(SThreadInfo *pInfo) { taos_free_result(tmqMsg); totalMsgs++; - + if (totalMsgs >= pInfo->expectMsgCnt) { break; } @@ -336,7 +330,7 @@ void loop_consume(SThreadInfo *pInfo) { break; } } - + err = tmq_consumer_close(pInfo->tmq); if (err) { printf("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); @@ -346,27 +340,27 @@ void loop_consume(SThreadInfo *pInfo) { pInfo->consumeMsgCnt = totalMsgs; pInfo->consumeRowCnt = totalRows; - taosFprintfFile(g_fp, "==== consumerId: %d, consumeMsgCnt: %"PRId64", consumeRowCnt: %"PRId64"\n", pInfo->consumerId, pInfo->consumeMsgCnt, pInfo->consumeRowCnt); - + taosFprintfFile(g_fp, "==== consumerId: %d, consumeMsgCnt: %" PRId64 ", consumeRowCnt: %" PRId64 "\n", + pInfo->consumerId, pInfo->consumeMsgCnt, pInfo->consumeRowCnt); } -void *consumeThreadFunc(void *param) { +void* consumeThreadFunc(void* param) { int32_t totalMsgs = 0; - SThreadInfo *pInfo = (SThreadInfo *)param; + SThreadInfo* pInfo = (SThreadInfo*)param; build_consumer(pInfo); build_topic_list(pInfo); - if ((NULL == pInfo->tmq) || (NULL == pInfo->topicList)){ + if ((NULL == pInfo->tmq) || (NULL == pInfo->topicList)) { return NULL; } - + tmq_resp_err_t err = tmq_subscribe(pInfo->tmq, pInfo->topicList); if (err) { printf("tmq_subscribe() fail, reason: %s\n", tmq_err2str(err)); exit(-1); } - + loop_consume(pInfo); tmq_commit(pInfo->tmq, NULL, 0); @@ -374,10 +368,10 @@ void *consumeThreadFunc(void *param) { err = tmq_unsubscribe(pInfo->tmq); if (err) { printf("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); - pInfo->consumeMsgCnt = -1; + pInfo->consumeMsgCnt = -1; return NULL; - } - + } + // save consume result into consumeresult table saveConsumeResult(pInfo); @@ -389,7 +383,7 @@ void parseConsumeInfo() { const char delim[2] = ","; const char ch = ':'; - for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { + for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { token = strtok(g_stConfInfo.stThreads[i].topicString, delim); while (token != NULL) { // printf("%s\n", token ); @@ -397,10 +391,10 @@ void parseConsumeInfo() { ltrim(g_stConfInfo.stThreads[i].topics[g_stConfInfo.stThreads[i].numOfTopic]); // printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]); g_stConfInfo.stThreads[i].numOfTopic++; - + token = strtok(NULL, delim); } - + token = strtok(g_stConfInfo.stThreads[i].keyString, delim); while (token != NULL) { // printf("%s\n", token ); @@ -414,7 +408,7 @@ void parseConsumeInfo() { // g_stConfInfo.value[g_stConfInfo.numOfKey]); g_stConfInfo.stThreads[i].numOfKey++; } - + token = strtok(NULL, delim); } } @@ -422,48 +416,49 @@ void parseConsumeInfo() { int32_t getConsumeInfo() { char sqlStr[1024] = {0}; - + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); assert(pConn != NULL); - + sprintf(sqlStr, "select * from %s.consumeinfo", g_stConfInfo.cdbName); TAOS_RES* pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { printf("error in get consumeinfo, reason:%s\n", taos_errstr(pRes)); taosFprintfFile(g_fp, "error in get consumeinfo, reason:%s\n", taos_errstr(pRes)); - taosCloseFile(&g_fp); + taosCloseFile(&g_fp); taos_free_result(pRes); exit(-1); - } - - TAOS_ROW row = NULL; - int num_fields = taos_num_fields(pRes); - TAOS_FIELD* fields = taos_fetch_fields(pRes); - - // schema: ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int - + } + + TAOS_ROW row = NULL; + int num_fields = taos_num_fields(pRes); + TAOS_FIELD* fields = taos_fetch_fields(pRes); + + // schema: ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, + // ifcheckdata int + int32_t numOfThread = 0; while ((row = taos_fetch_row(pRes))) { - int32_t* lengths = taos_fetch_lengths(pRes); - - for (int i = 0; i < num_fields; ++i) { + int32_t* lengths = taos_fetch_lengths(pRes); + + for (int i = 0; i < num_fields; ++i) { if (row[i] == NULL || 0 == i) { continue; } - + if ((1 == i) && (fields[i].type == TSDB_DATA_TYPE_INT)) { - g_stConfInfo.stThreads[numOfThread].consumerId = *((int32_t *)row[i]); + g_stConfInfo.stThreads[numOfThread].consumerId = *((int32_t*)row[i]); } else if ((2 == i) && (fields[i].type == TSDB_DATA_TYPE_BINARY)) { memcpy(g_stConfInfo.stThreads[numOfThread].topicString, row[i], lengths[i]); } else if ((3 == i) && (fields[i].type == TSDB_DATA_TYPE_BINARY)) { memcpy(g_stConfInfo.stThreads[numOfThread].keyString, row[i], lengths[i]); } else if ((4 == i) && (fields[i].type == TSDB_DATA_TYPE_BIGINT)) { - g_stConfInfo.stThreads[numOfThread].expectMsgCnt = *((int64_t *)row[i]); + g_stConfInfo.stThreads[numOfThread].expectMsgCnt = *((int64_t*)row[i]); } else if ((5 == i) && (fields[i].type == TSDB_DATA_TYPE_INT)) { - g_stConfInfo.stThreads[numOfThread].ifCheckData = *((int32_t *)row[i]); + g_stConfInfo.stThreads[numOfThread].ifCheckData = *((int32_t*)row[i]); } } - numOfThread ++; + numOfThread++; } g_stConfInfo.numOfThread = numOfThread; @@ -474,7 +469,6 @@ int32_t getConsumeInfo() { return 0; } - int main(int32_t argc, char* argv[]) { parseArgument(argc, argv); getConsumeInfo(); @@ -485,20 +479,21 @@ int main(int32_t argc, char* argv[]) { taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); // pthread_create one thread to consume - taosFprintfFile(g_fp, "==== create %d consume thread ====\n", g_stConfInfo.numOfThread); + taosFprintfFile(g_fp, "==== create %d consume thread ====\n", g_stConfInfo.numOfThread); for (int32_t i = 0; i < g_stConfInfo.numOfThread; ++i) { - taosThreadCreate(&(g_stConfInfo.stThreads[i].thread), &thattr, consumeThreadFunc, (void *)(&(g_stConfInfo.stThreads[i]))); + taosThreadCreate(&(g_stConfInfo.stThreads[i].thread), &thattr, consumeThreadFunc, + (void*)(&(g_stConfInfo.stThreads[i]))); } for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { taosThreadJoin(g_stConfInfo.stThreads[i].thread, NULL); } - //printf("consumer: %d, cosumer1: %d\n", totalMsgs, pInfo->consumeMsgCnt); - - taosFprintfFile(g_fp, "==== close tmqlog ====\n"); - taosCloseFile(&g_fp); - + // printf("consumer: %d, cosumer1: %d\n", totalMsgs, pInfo->consumeMsgCnt); + + taosFprintfFile(g_fp, "==== close tmqlog ====\n"); + taosCloseFile(&g_fp); + return 0; } diff --git a/tools/shell/inc/shellInt.h b/tools/shell/inc/shellInt.h index 382009905c8774b0ff462bcf67f2baa9dd2bbfc2..825866e16361b35ca86abeac62ff5f765ce67a10 100644 --- a/tools/shell/inc/shellInt.h +++ b/tools/shell/inc/shellInt.h @@ -62,7 +62,7 @@ typedef struct { bool is_check; bool is_startup; bool is_help; - uint16_t port; + int32_t port; int32_t pktLen; int32_t pktNum; int32_t displayWidth; diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index 8ccfde4b16dd591a9535e618f0738e28c68d6332..13f8cde3e3bc43635f92d2c52978a35fef519bbb 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -99,6 +99,7 @@ static int32_t shellParseSingleOpt(int32_t key, char *arg) { break; case 'P': pArgs->port = atoi(arg); + if (pArgs->port == 0) pArgs->port = -1; break; case 'u': pArgs->user = arg; @@ -304,6 +305,11 @@ static int32_t shellCheckArgs() { return -1; } + if (pArgs->port < 0 || pArgs->port > 65535) { + printf("Invalid port\n"); + return -1; + } + if (pArgs->pktLen < SHELL_MIN_PKG_LEN || pArgs->pktLen > SHELL_MAX_PKG_LEN) { printf("Invalid pktLen:%d, range:[%d, %d]\n", pArgs->pktLen, SHELL_MIN_PKG_LEN, SHELL_MAX_PKG_LEN); return -1;