diff --git a/CMakeLists.txt b/CMakeLists.txt index e1fbd54be337eb625fa1c1a95dead88c83887c50..0436f5b25923927edaa7568ba57c7b948446f8b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project( ) if (NOT DEFINED TD_SOURCE_DIR) - set( TD_SOURCE_DIR ${CMAKE_SOURCE_DIR} ) + set( TD_SOURCE_DIR ${PROJECT_SOURCE_DIR} ) endif() set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake") diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 1ddc765c5c5a93dd4b8a6001ebede7c3bde22a59..19923a5ad63bc6ec584324116956ea272b3df52b 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -14,9 +14,24 @@ if(${BUILD_PTHREAD}) cat("${TD_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) endif() -# gnu regex -if(${BUILD_GNUREGEX}) - cat("${TD_SUPPORT_DIR}/gnuregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +# iconv +if(${BUILD_WITH_ICONV}) + cat("${TD_SUPPORT_DIR}/iconv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +endif() + +# msvc regex +if(${BUILD_MSVCREGEX}) + cat("${TD_SUPPORT_DIR}/msvcregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +endif() + +# wcwidth +if(${BUILD_WCWIDTH}) + cat("${TD_SUPPORT_DIR}/wcwidth_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +endif() + +# wingetopt +if(${BUILD_WINGETOPT}) + cat("${TD_SUPPORT_DIR}/wingetopt_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) endif() # googletest @@ -99,8 +114,27 @@ if(${BUILD_TEST}) target_include_directories( gtest PUBLIC $ - PUBLIC $ ) + if(${TD_WINDOWS}) + target_include_directories( + gtest + PUBLIC $ + ) + endif(${TD_WINDOWS}) + if(${TD_LINUX}) + target_include_directories( + gtest + PUBLIC $ + ) + endif(${TD_LINUX}) + if(${TD_DARWIN}) + target_include_directories( + gtest + PUBLIC $ + ) + endif(${TD_DARWIN}) + + endif(${BUILD_TEST}) # cJson @@ -182,6 +216,53 @@ if(${BUILD_WITH_NURAFT}) add_subdirectory(nuraft) endif(${BUILD_WITH_NURAFT}) +# pthread +if(${BUILD_PTHREAD}) + set(CMAKE_BUILD_TYPE release) + add_definitions(-DPTW32_STATIC_LIB) + add_subdirectory(pthread) + set_target_properties(libpthreadVC3 PROPERTIES OUTPUT_NAME pthread) + add_library(pthread STATIC IMPORTED GLOBAL) + SET_PROPERTY(TARGET pthread PROPERTY IMPORTED_LOCATION ${LIBRARY_OUTPUT_PATH}/pthread.lib) +endif() + +# iconv +if(${BUILD_WITH_ICONV}) + add_subdirectory(iconv) +endif(${BUILD_WITH_ICONV}) + +# wingetopt +if(${BUILD_WINGETOPT}) + add_subdirectory(wingetopt) +endif(${BUILD_WINGETOPT}) + +# msvcregex +if(${BUILD_MSVCREGEX}) + add_library(msvcregex STATIC "") + target_sources(msvcregex + PRIVATE "msvcregex/regex.c" + ) + target_include_directories(msvcregex + PRIVATE "msvcregex" + ) + target_link_libraries(msvcregex + INTERFACE Shell32 + ) + SET_TARGET_PROPERTIES(msvcregex PROPERTIES OUTPUT_NAME msvcregex) +endif(${BUILD_MSVCREGEX}) + +# msvcregex +if(${BUILD_WCWIDTH}) + add_library(wcwidth STATIC "") + target_sources(wcwidth + PRIVATE "wcwidth/wcwidth.c" + ) + target_include_directories(wcwidth + PRIVATE "wcwidth" + ) + SET_TARGET_PROPERTIES(wcwidth PROPERTIES OUTPUT_NAME wcwidth) +endif(${BUILD_WCWIDTH}) + # CRAFT if(${BUILD_WITH_CRAFT}) add_library(craft STATIC IMPORTED GLOBAL) @@ -238,8 +319,12 @@ if(${BUILD_WITH_SQLITE}) target_link_libraries(sqlite INTERFACE m INTERFACE pthread - INTERFACE dl ) + if(NOT TD_WINDOWS) + target_link_libraries(sqlite + INTERFACE dl + ) + endif(NOT TD_WINDOWS) endif(${BUILD_WITH_SQLITE}) # pthread diff --git a/contrib/test/craft/CMakeLists.txt b/contrib/test/craft/CMakeLists.txt index e0f6ae64bd3e9c998db15c1006cebf1b15702f5b..ec8b44b67395a481ed2970f19cb5d0e1290f6d6b 100644 --- a/contrib/test/craft/CMakeLists.txt +++ b/contrib/test/craft/CMakeLists.txt @@ -1,2 +1,9 @@ add_executable(simulate_vnode "simulate_vnode.c") -target_link_libraries(simulate_vnode PUBLIC craft lz4 uv_a) \ No newline at end of file +target_link_libraries(simulate_vnode PUBLIC craft lz4 uv_a) +if(${BUILD_WINGETOPT}) + target_link_libraries(simulate_vnode PUBLIC wingetopt) + target_include_directories( + simulate_vnode + PUBLIC "${TD_SOURCE_DIR}/contrib/wingetopt/src" + ) +endif() \ No newline at end of file diff --git a/contrib/test/tdev/src/main.c b/contrib/test/tdev/src/main.c index 5e1de83e88a2a76d2381726ded0c28fe00ab67a6..e40040ce9762e39ca3b23380f4470352a96c921b 100644 --- a/contrib/test/tdev/src/main.c +++ b/contrib/test/tdev/src/main.c @@ -6,43 +6,39 @@ #define POINTER_SHIFT(ptr, s) ((void *)(((char *)ptr) + (s))) #define POINTER_DISTANCE(pa, pb) ((char *)(pb) - (char *)(pa)) -#define tPutA(buf, val) \ - ({ \ - memcpy(buf, &val, sizeof(val)); \ - POINTER_SHIFT(buf, sizeof(val)); \ - }) +static inline void tPutA(void **buf, uint64_t val) { + memcpy(buf, &val, sizeof(val)); + *buf = POINTER_SHIFT(buf, sizeof(val)); +} -#define tPutB(buf, val) \ - ({ \ - ((uint8_t *)buf)[7] = ((val) >> 56) & 0xff; \ - ((uint8_t *)buf)[6] = ((val) >> 48) & 0xff; \ - ((uint8_t *)buf)[5] = ((val) >> 40) & 0xff; \ - ((uint8_t *)buf)[4] = ((val) >> 32) & 0xff; \ - ((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \ - ((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \ - ((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \ - ((uint8_t *)buf)[0] = (val)&0xff; \ - POINTER_SHIFT(buf, sizeof(val)); \ - }) +static inline void tPutB(void **buf, uint64_t val) { + ((uint8_t *)buf)[7] = ((val) >> 56) & 0xff; + ((uint8_t *)buf)[6] = ((val) >> 48) & 0xff; + ((uint8_t *)buf)[5] = ((val) >> 40) & 0xff; + ((uint8_t *)buf)[4] = ((val) >> 32) & 0xff; + ((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; + ((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; + ((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; + ((uint8_t *)buf)[0] = (val)&0xff; + *buf = POINTER_SHIFT(buf, sizeof(val)); +} -#define tPutC(buf, val) \ - ({ \ - if (buf) { \ - ((uint64_t *)buf)[0] = (val); \ - POINTER_SHIFT(buf, sizeof(val)); \ - } \ - NULL; \ - }) +static inline void tPutC(void **buf, uint64_t val) { + if (buf) { + ((uint64_t *)buf)[0] = (val); + POINTER_SHIFT(buf, sizeof(val)); + } + *buf = NULL; +} -#define tPutD(buf, val) \ - ({ \ - uint64_t tmp = val; \ - for (size_t i = 0; i < sizeof(val); i++) { \ - ((uint8_t *)buf)[i] = tmp & 0xff; \ - tmp >>= 8; \ - } \ - POINTER_SHIFT(buf, sizeof(val)); \ - }) +static inline void tPutD(void **buf, uint64_t val) { + uint64_t tmp = val; + for (size_t i = 0; i < sizeof(val); i++) { + ((uint8_t *)buf)[i] = tmp & 0xff; + tmp >>= 8; + } + *buf = POINTER_SHIFT(buf, sizeof(val)); +} static inline void tPutE(void **buf, uint64_t val) { if (buf) { @@ -61,7 +57,7 @@ static void func(T t) { switch (t) { case A: for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { - pBuf = tPutA(pBuf, val); + tPutA(pBuf, val); if (POINTER_DISTANCE(buf, pBuf) == 1024) { pBuf = buf; } @@ -69,7 +65,7 @@ static void func(T t) { break; case B: for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { - pBuf = tPutB(pBuf, val); + tPutB(pBuf, val); if (POINTER_DISTANCE(buf, pBuf) == 1024) { pBuf = buf; } @@ -77,7 +73,7 @@ static void func(T t) { break; case C: for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { - pBuf = tPutC(pBuf, val); + tPutC(pBuf, val); if (POINTER_DISTANCE(buf, pBuf) == 1024) { pBuf = buf; } @@ -85,7 +81,7 @@ static void func(T t) { break; case D: for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) { - pBuf = tPutD(pBuf, val); + tPutD(pBuf, val); if (POINTER_DISTANCE(buf, pBuf) == 1024) { pBuf = buf; } diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 80059dde4d1017b8fa1c71b3dd74271f4927187d..365b1b7172f394111c5e75b113a9ce1e1ce8822b 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -30,6 +30,7 @@ target_link_libraries(demoapi ) target_include_directories(tmq + PUBLIC "${TD_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) diff --git a/example/src/tmq.c b/example/src/tmq.c index b2cbf856c01340c05d4db113933a241067234ab3..21f60ada5d985bb694d4ea608a0a0ebd691a6b01 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -17,8 +17,8 @@ #include #include #include -#include #include "taos.h" +#include "osSleep.h" static int running = 1; static void msg_process(TAOS_RES* msg) { @@ -48,7 +48,6 @@ int32_t init_env() { return -1; } taos_free_result(pRes); - sleep(1); pRes = taos_query(pConn, "use abc1"); if (taos_errno(pRes) != 0) { @@ -60,7 +59,6 @@ int32_t init_env() { pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags(t1 int)"); if (taos_errno(pRes) != 0) { - assert(0); printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); return -1; } @@ -104,8 +102,8 @@ int32_t create_topic() { } taos_free_result(pRes); - /*pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");*/ - pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1"); + pRes = taos_query(pConn, "create topic topic_ctb_column as abc1"); + /*pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");*/ if (taos_errno(pRes) != 0) { printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes)); return -1; @@ -163,9 +161,10 @@ tmq_t* build_consumer() { tmq_conf_set(conf, "group.id", "tg2"); 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(conf, "td.connect.db", "abc1");*/ tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); + assert(tmq); return tmq; } diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index e94de3cbca574de71c8bcefc4b52173922c05a98..17a9257c499c6a1efd24fb23b47a9e9835ad7ade 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -1,7 +1,7 @@ PROJECT(TDengine) IF (TD_LINUX) - INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) + INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc) AUX_SOURCE_DIRECTORY(. SRC) ADD_EXECUTABLE(demo apitest.c) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread ) @@ -13,7 +13,7 @@ IF (TD_LINUX) TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua) ENDIF () IF (TD_DARWIN) - INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) + INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc) AUX_SOURCE_DIRECTORY(. SRC) ADD_EXECUTABLE(demo demo.c) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua) diff --git a/include/client/taos.h b/include/client/taos.h index 6afbcee6f150e460eb751228130df2c0f71a568b..6ff55aef19dc5d166abf8472885e477966c6f557 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -27,10 +27,7 @@ typedef void TAOS; typedef void TAOS_STMT; typedef void TAOS_RES; typedef void **TAOS_ROW; -#if 0 -typedef void TAOS_STREAM; -#endif -typedef void TAOS_SUB; +typedef void TAOS_SUB; // Data type definition #define TSDB_DATA_TYPE_NULL 0 // 1 bytes @@ -88,17 +85,21 @@ typedef struct taosField { int32_t bytes; } TAOS_FIELD; -#define DLL_EXPORT +#ifdef WINDOWS + #define DLL_EXPORT __declspec(dllexport) +#else + #define DLL_EXPORT +#endif typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code); typedef struct TAOS_BIND_v2 { - int buffer_type; - void *buffer; - int32_t buffer_length; - int32_t *length; - char *is_null; - int num; + int buffer_type; + void *buffer; + int32_t buffer_length; + int32_t *length; + char *is_null; + int num; } TAOS_BIND_v2; typedef enum { @@ -128,35 +129,35 @@ 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_BIND_v2 *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_BIND_v2 *bind); -DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind); -DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *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_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_BIND_v2 *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_BIND_v2 *bind); +DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind); +DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *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); @@ -192,12 +193,6 @@ DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub); DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress); #endif -#if 0 -DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), - int64_t stime, void *param, void (*callback)(void *)); -DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr); -#endif - DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); @@ -234,15 +229,11 @@ DLL_EXPORT tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errst DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); /* ------------------------TMQ CONSUMER INTERFACE------------------------ */ -DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, tmq_list_t *topic_list); +DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list); DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq); DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics); -DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t blocking_time); +DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t wait_time); DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq); -#if 0 -DLL_EXPORT tmq_resp_err_t tmq_assign(tmq_t* tmq, const tmq_topic_vgroup_list_t* vgroups); -DLL_EXPORT tmq_resp_err_t tmq_assignment(tmq_t* tmq, tmq_topic_vgroup_list_t** vgroups); -#endif DLL_EXPORT tmq_resp_err_t tmq_commit(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, int32_t async); #if 0 DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async); @@ -269,7 +260,7 @@ DLL_EXPORT 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_block_table_name(TAOS_RES *res); +DLL_EXPORT char *tmq_get_table_name(TAOS_RES *res); #endif #if 0 diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 7c308f9354ff38f7e4bd699de3aa61e0bbc786a8..00f9e39c7ac5941fc928160baa243774281ae905 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -99,6 +99,15 @@ typedef struct SColumnInfoData { }; } SColumnInfoData; +typedef struct SQueryTableDataCond { + STimeWindow twindow; + int32_t order; // desc|asc order to iterate the data block + int32_t numOfCols; + SColumnInfo *colList; + bool loadExternalRows; // load external rows or not + int32_t type; // data block load type: +} SQueryTableDataCond; + void* blockDataDestroy(SSDataBlock* pBlock); int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock); void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock); @@ -229,7 +238,6 @@ typedef struct SResSchame { char name[TSDB_COL_NAME_LEN]; } SResSchema; -// TODO move away to executor.h typedef struct SExprBasicInfo { SResSchema resSchema; int16_t numOfParams; // argument value of each function diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 72f67665ba066b46057c8a0f3195f49f89e9a794..fc3d575317a5e8e68657d967b6d2e2afa3458d13 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[]; #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) -int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, - const char *apolloUrl, SArray *pArgs, bool tsc); -int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc); +int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, + char *apolloUrl, SArray *pArgs, bool tsc); +int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc); void taosCleanupCfg(); void taosCfgDynamicOptions(const char *option, const char *value); void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 5a2dd502c1c909a1c1248981e71d940deb450210..26cbd35e904e19c7d2e89cf9591dc86bc96854c4 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -227,8 +227,16 @@ typedef struct { } SSubmitBlkIter; typedef struct { - int32_t totalLen; - int32_t len; + int32_t totalLen; + int32_t len; + // head of SSubmitBlk + int64_t uid; // table unique id + int64_t suid; // stable id + int32_t sversion; // data schema version + int32_t dataLen; // data part length, not including the SSubmitBlk head + int32_t schemaLen; // schema length, if length is 0, no schema exists + int16_t numOfRows; // total number of rows in current submit block + // head of SSubmitBlk const void* pMsg; } SSubmitMsgIter; @@ -237,6 +245,15 @@ int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock); int32_t tInitSubmitBlkIter(SSubmitBlk* pBlock, SSubmitBlkIter* pIter); STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter); +// TODO: KEEP one suite of iterator API finally. +// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts +// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later +// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter +int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter); +int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock); +int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter); +STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter); + typedef struct { int32_t index; // index of failed block in submit blocks int32_t vnode; // vnode index of failed block @@ -275,7 +292,6 @@ typedef struct { char name[TSDB_TABLE_FNAME_LEN]; int8_t igExists; float xFilesFactor; - int32_t aggregationMethod; int32_t delay; int32_t ttl; int32_t numOfColumns; @@ -1316,7 +1332,7 @@ typedef struct { typedef struct { int64_t consumerId; char cgroup[TSDB_CGROUP_LEN]; - SArray* topicNames; // SArray + SArray* topicNames; // SArray } SCMSubscribeReq; static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) { @@ -1495,10 +1511,8 @@ typedef struct { int32_t delay; int32_t qmsg1Len; int32_t qmsg2Len; - func_id_t* pFuncIds; - char* qmsg1; // not null: pAst1:qmsg1:SRetention1 => trigger aggr task1 - char* qmsg2; // not null: pAst2:qmsg2:SRetention2 => trigger aggr task2 - int8_t nFuncIds; + char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1 + char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2 } SRSmaParam; typedef struct SVCreateTbReq { @@ -2052,80 +2066,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) { return buf; } -typedef struct { - int64_t leftForVer; - int32_t vgId; - int32_t epoch; - int64_t consumerId; - char topicName[TSDB_TOPIC_FNAME_LEN]; -} SMqCancelConnReq; - -static FORCE_INLINE int32_t tEncodeSMqCancelConnReq(void** buf, const SMqCancelConnReq* pReq) { - int32_t tlen = 0; - tlen += taosEncodeFixedI64(buf, pReq->leftForVer); - tlen += taosEncodeFixedI32(buf, pReq->vgId); - tlen += taosEncodeFixedI32(buf, pReq->epoch); - tlen += taosEncodeFixedI64(buf, pReq->consumerId); - tlen += taosEncodeString(buf, pReq->topicName); - return tlen; -} - -static FORCE_INLINE void* tDecodeSMqCancelConnReq(void* buf, SMqCancelConnReq* pReq) { - buf = taosDecodeFixedI64(buf, &pReq->leftForVer); - buf = taosDecodeFixedI32(buf, &pReq->vgId); - buf = taosDecodeFixedI32(buf, &pReq->epoch); - buf = taosDecodeFixedI64(buf, &pReq->consumerId); - buf = taosDecodeStringTo(buf, pReq->topicName); - return buf; -} - -typedef struct { - int8_t reserved; -} SMqCancelConnRsp; - -typedef struct { - int64_t leftForVer; - int32_t vgId; - int64_t oldConsumerId; - int64_t newConsumerId; - char* topic; -} SMqMVRebReq; - -static FORCE_INLINE int32_t tEncodeSMqMVRebReq(void** buf, const SMqMVRebReq* pReq) { - int32_t tlen = 0; - tlen += taosEncodeFixedI64(buf, pReq->leftForVer); - tlen += taosEncodeFixedI32(buf, pReq->vgId); - tlen += taosEncodeFixedI64(buf, pReq->oldConsumerId); - tlen += taosEncodeFixedI64(buf, pReq->newConsumerId); - tlen += taosEncodeString(buf, pReq->topic); - return tlen; -} - -static FORCE_INLINE void* tDecodeSMqMVRebReq(void* buf, SMqMVRebReq* pReq) { - buf = taosDecodeFixedI64(buf, &pReq->leftForVer); - buf = taosDecodeFixedI32(buf, &pReq->vgId); - buf = taosDecodeFixedI64(buf, &pReq->oldConsumerId); - buf = taosDecodeFixedI64(buf, &pReq->newConsumerId); - buf = taosDecodeString(buf, &pReq->topic); - return buf; -} - -typedef struct { - SMsgHead header; - int32_t vgId; - int64_t consumerId; - char topicName[TSDB_TOPIC_FNAME_LEN]; - char cgroup[TSDB_CGROUP_LEN]; -} SMqSetCVgRsp; - -typedef struct { - SMsgHead header; - int32_t vgId; - int64_t consumerId; - char topicName[TSDB_TOPIC_FNAME_LEN]; - char cgroup[TSDB_CGROUP_LEN]; -} SMqMVRebRsp; - typedef struct { int32_t vgId; int64_t offset; @@ -2152,6 +2092,24 @@ typedef struct { SSchema* pSchema; } SSchemaWrapper; +static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) { + SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper)); + if (pSW == NULL) return pSW; + pSW->nCols = pSchemaWrapper->nCols; + pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema)); + if (pSW->pSchema == NULL) { + taosMemoryFree(pSW); + return NULL; + } + memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema)); + return pSW; +} + +static FORCE_INLINE void tDeleteSSchemaWrapper(SSchemaWrapper* pSchemaWrapper) { + taosMemoryFree(pSchemaWrapper->pSchema); + taosMemoryFree(pSchemaWrapper); +} + static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) { int32_t tlen = 0; tlen += taosEncodeFixedI8(buf, pSchema->type); @@ -2162,13 +2120,13 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema return tlen; } -static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) { +static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) { buf = taosDecodeFixedI8(buf, &pSchema->type); buf = taosDecodeFixedI8(buf, &pSchema->flags); buf = taosDecodeFixedI32(buf, &pSchema->bytes); buf = taosDecodeFixedI16(buf, &pSchema->colId); buf = taosDecodeStringTo(buf, pSchema->name); - return buf; + return (void*)buf; } static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) { @@ -2198,7 +2156,7 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr return tlen; } -static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) { +static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) { buf = taosDecodeFixedU32(buf, &pSW->nCols); pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema)); if (pSW->pSchema == NULL) { @@ -2208,7 +2166,7 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pS for (int32_t i = 0; i < pSW->nCols; i++) { buf = taosDecodeSSchema(buf, &pSW->pSchema[i]); } - return buf; + return (void*)buf; } static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) { @@ -2615,6 +2573,10 @@ static FORCE_INLINE int32_t tEncodeSMqDataBlkRsp(void** buf, const SMqDataBlkRsp void* data = taosArrayGetP(pRsp->blockData, i); tlen += taosEncodeFixedI32(buf, bLen); tlen += taosEncodeBinary(buf, data, bLen); + if (pRsp->withSchema) { + SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pRsp->blockSchema, i); + tlen += taosEncodeSSchemaWrapper(buf, pSW); + } } } return tlen; @@ -2627,6 +2589,7 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p buf = taosDecodeFixedI32(buf, &pRsp->blockNum); pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void*)); pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(void*)); + pRsp->blockSchema = taosArrayInit(pRsp->blockNum, sizeof(void*)); if (pRsp->blockNum != 0) { buf = taosDecodeFixedI8(buf, &pRsp->withTbName); buf = taosDecodeFixedI8(buf, &pRsp->withSchema); @@ -2639,6 +2602,11 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p buf = taosDecodeBinary(buf, &data, bLen); taosArrayPush(pRsp->blockDataLen, &bLen); taosArrayPush(pRsp->blockData, &data); + if (pRsp->withSchema) { + SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper)); + buf = taosDecodeSSchemaWrapper(buf, pSW); + taosArrayPush(pRsp->blockSchema, &pSW); + } } } return (void*)buf; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 691d491eb053962045ee66a40e28818f87a022de..97ee66a2daeaf2fd95678b55c27cd0821a73d657 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -145,7 +145,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp) - TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-get-sub-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp) + TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-mq-ask-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp) TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq) TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mnode-mq-consumer-lost", SMTimerReq, SMTimerReq) TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg) diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 46e78d5c22dc53d9969cc89887984e24049860b4..0580f3acba9e2563af70dcdc92a9cdb08fb5557b 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -202,7 +202,7 @@ typedef struct SqlFunctionCtx { SPoint1 end; SFuncExecFuncs fpSet; SScalarFuncExecFuncs sfp; - SExprInfo *pExpr; + struct SExprInfo *pExpr; struct SDiskbasedBuf *pBuf; struct SSDataBlock *pSrcBlock; int32_t curBufPage; diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 2fff819f5496327b8b5264b30a23558331a8cbed..56e25d49c12216f8f8a0c785a8400dd83320dfb5 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -125,15 +125,15 @@ typedef struct SFmGetFuncInfoParam { struct SCatalog* pCtg; void *pRpc; const SEpSet* pMgmtEps; + char* pErrBuf; + int32_t errBufLen; } SFmGetFuncInfoParam; int32_t fmFuncMgtInit(); void fmFuncMgtDestroy(); -int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType); - -int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len); +int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc); bool fmIsAggFunc(int32_t funcId); bool fmIsScalarFunc(int32_t funcId); diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index e68cfc4708126981a2f68a3dd97c41ff4f2a7767..1605fe8ac8c9ad1f8a15337d4d72fc5b7ddeedc3 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -25,14 +25,16 @@ extern "C" { #include "tvariant.h" #define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags) -#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema))) -#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo))) +#define TABLE_META_SIZE(pMeta) \ + (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema))) +#define VGROUPS_INFO_SIZE(pInfo) \ + (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo))) typedef struct SRawExprNode { ENodeType nodeType; - char* p; - uint32_t n; - SNode* pNode; + char* p; + uint32_t n; + SNode* pNode; } SRawExprNode; typedef struct SDataType { @@ -45,173 +47,155 @@ typedef struct SDataType { typedef struct SExprNode { ENodeType type; SDataType resType; - char aliasName[TSDB_COL_NAME_LEN]; - SNodeList* pAssociationList; + char aliasName[TSDB_COL_NAME_LEN]; + SArray* pAssociation; } SExprNode; -typedef enum EColumnType { - COLUMN_TYPE_COLUMN = 1, - COLUMN_TYPE_TAG -} EColumnType; +typedef enum EColumnType { COLUMN_TYPE_COLUMN = 1, COLUMN_TYPE_TAG } EColumnType; typedef struct SColumnNode { - SExprNode node; // QUERY_NODE_COLUMN - uint64_t tableId; - int8_t tableType; - col_id_t colId; - EColumnType colType; // column or tag - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - char tableAlias[TSDB_TABLE_NAME_LEN]; - char colName[TSDB_COL_NAME_LEN]; - SNode* pProjectRef; - int16_t dataBlockId; - int16_t slotId; + SExprNode node; // QUERY_NODE_COLUMN + uint64_t tableId; + int8_t tableType; + col_id_t colId; + EColumnType colType; // column or tag + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + char tableAlias[TSDB_TABLE_NAME_LEN]; + char colName[TSDB_COL_NAME_LEN]; + SNode* pProjectRef; + int16_t dataBlockId; + int16_t slotId; } SColumnNode; typedef struct STargetNode { ENodeType type; - int16_t dataBlockId; - int16_t slotId; - SNode* pExpr; + int16_t dataBlockId; + int16_t slotId; + SNode* pExpr; } STargetNode; typedef struct SValueNode { - SExprNode node; // QUERY_NODE_VALUE - char* literal; - bool isDuration; - bool translate; - bool genByCalc; - int16_t placeholderNo; + SExprNode node; // QUERY_NODE_VALUE + char* literal; + bool isDuration; + bool translate; + int16_t placeholderNo; union { - bool b; - int64_t i; + bool b; + int64_t i; uint64_t u; - double d; - char* p; + double d; + char* p; } datum; char unit; } SValueNode; typedef struct SOperatorNode { - SExprNode node; // QUERY_NODE_OPERATOR + SExprNode node; // QUERY_NODE_OPERATOR EOperatorType opType; - SNode* pLeft; - SNode* pRight; + SNode* pLeft; + SNode* pRight; } SOperatorNode; - typedef struct SLogicConditionNode { - SExprNode node; // QUERY_NODE_LOGIC_CONDITION + SExprNode node; // QUERY_NODE_LOGIC_CONDITION ELogicConditionType condType; - SNodeList* pParameterList; + SNodeList* pParameterList; } SLogicConditionNode; typedef struct SNodeListNode { - ENodeType type; // QUERY_NODE_NODE_LIST - SDataType dataType; + ENodeType type; // QUERY_NODE_NODE_LIST + SDataType dataType; SNodeList* pNodeList; } SNodeListNode; typedef struct SFunctionNode { - SExprNode node; // QUERY_NODE_FUNCTION - char functionName[TSDB_FUNC_NAME_LEN]; - int32_t funcId; - int32_t funcType; + SExprNode node; // QUERY_NODE_FUNCTION + char functionName[TSDB_FUNC_NAME_LEN]; + int32_t funcId; + int32_t funcType; SNodeList* pParameterList; - - int8_t udfFuncType; //TODO: fill by parser/planner - int32_t bufSize; //TODO: fill by parser/planner + int32_t udfBufSize; } SFunctionNode; typedef struct STableNode { SExprNode node; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - char tableAlias[TSDB_TABLE_NAME_LEN]; - uint8_t precision; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + char tableAlias[TSDB_TABLE_NAME_LEN]; + uint8_t precision; } STableNode; struct STableMeta; typedef struct SRealTableNode { - STableNode table; // QUERY_NODE_REAL_TABLE + STableNode table; // QUERY_NODE_REAL_TABLE struct STableMeta* pMeta; - SVgroupsInfo* pVgroupList; - char useDbName[TSDB_DB_NAME_LEN]; - double ratio; + SVgroupsInfo* pVgroupList; + char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES + double ratio; } SRealTableNode; typedef struct STempTableNode { - STableNode table; // QUERY_NODE_TEMP_TABLE - SNode* pSubquery; + STableNode table; // QUERY_NODE_TEMP_TABLE + SNode* pSubquery; } STempTableNode; -typedef enum EJoinType { - JOIN_TYPE_INNER = 1 -} EJoinType; +typedef enum EJoinType { JOIN_TYPE_INNER = 1 } EJoinType; typedef struct SJoinTableNode { - STableNode table; // QUERY_NODE_JOIN_TABLE - EJoinType joinType; - SNode* pLeft; - SNode* pRight; - SNode* pOnCond; + STableNode table; // QUERY_NODE_JOIN_TABLE + EJoinType joinType; + SNode* pLeft; + SNode* pRight; + SNode* pOnCond; } SJoinTableNode; -typedef enum EGroupingSetType { - GP_TYPE_NORMAL = 1 -} EGroupingSetType; +typedef enum EGroupingSetType { GP_TYPE_NORMAL = 1 } EGroupingSetType; typedef struct SGroupingSetNode { - ENodeType type; // QUERY_NODE_GROUPING_SET + ENodeType type; // QUERY_NODE_GROUPING_SET EGroupingSetType groupingSetType; - SNodeList* pParameterList; + SNodeList* pParameterList; } SGroupingSetNode; -typedef enum EOrder { - ORDER_ASC = 1, - ORDER_DESC -} EOrder; +typedef enum EOrder { ORDER_ASC = 1, ORDER_DESC } EOrder; -typedef enum ENullOrder { - NULL_ORDER_DEFAULT = 1, - NULL_ORDER_FIRST, - NULL_ORDER_LAST -} ENullOrder; +typedef enum ENullOrder { NULL_ORDER_DEFAULT = 1, NULL_ORDER_FIRST, NULL_ORDER_LAST } ENullOrder; typedef struct SOrderByExprNode { - ENodeType type; // QUERY_NODE_ORDER_BY_EXPR - SNode* pExpr; - EOrder order; + ENodeType type; // QUERY_NODE_ORDER_BY_EXPR + SNode* pExpr; + EOrder order; ENullOrder nullOrder; } SOrderByExprNode; typedef struct SLimitNode { - ENodeType type; // QUERY_NODE_LIMIT - int64_t limit; - int64_t offset; + ENodeType type; // QUERY_NODE_LIMIT + int64_t limit; + int64_t offset; } SLimitNode; typedef struct SStateWindowNode { - ENodeType type; // QUERY_NODE_STATE_WINDOW - SNode* pCol; // timestamp primary key - SNode* pExpr; + ENodeType type; // QUERY_NODE_STATE_WINDOW + SNode* pCol; // timestamp primary key + SNode* pExpr; } SStateWindowNode; typedef struct SSessionWindowNode { - ENodeType type; // QUERY_NODE_SESSION_WINDOW - SColumnNode* pCol; // timestamp primary key - SValueNode* pGap; // gap between two session window(in microseconds) + ENodeType type; // QUERY_NODE_SESSION_WINDOW + SColumnNode* pCol; // timestamp primary key + SValueNode* pGap; // gap between two session window(in microseconds) } SSessionWindowNode; typedef struct SIntervalWindowNode { - ENodeType type; // QUERY_NODE_INTERVAL_WINDOW - SNode* pCol; // timestamp primary key - SNode* pInterval; // SValueNode - SNode* pOffset; // SValueNode - SNode* pSliding; // SValueNode - SNode* pFill; + ENodeType type; // QUERY_NODE_INTERVAL_WINDOW + SNode* pCol; // timestamp primary key + SNode* pInterval; // SValueNode + SNode* pOffset; // SValueNode + SNode* pSliding; // SValueNode + SNode* pFill; } SIntervalWindowNode; typedef enum EFillMode { @@ -224,42 +208,40 @@ typedef enum EFillMode { } EFillMode; typedef struct SFillNode { - ENodeType type; // QUERY_NODE_FILL + ENodeType type; // QUERY_NODE_FILL EFillMode mode; - SNode* pValues; // SNodeListNode + SNode* pValues; // SNodeListNode } SFillNode; typedef struct SSelectStmt { - ENodeType type; // QUERY_NODE_SELECT_STMT - bool isDistinct; - SNodeList* pProjectionList; - SNode* pFromTable; - SNode* pWhere; - SNodeList* pPartitionByList; - SNode* pWindow; - SNodeList* pGroupByList; // SGroupingSetNode - SNode* pHaving; - SNodeList* pOrderByList; // SOrderByExprNode + ENodeType type; // QUERY_NODE_SELECT_STMT + bool isDistinct; + SNodeList* pProjectionList; + SNode* pFromTable; + SNode* pWhere; + SNodeList* pPartitionByList; + SNode* pWindow; + SNodeList* pGroupByList; // SGroupingSetNode + SNode* pHaving; + SNodeList* pOrderByList; // SOrderByExprNode SLimitNode* pLimit; SLimitNode* pSlimit; - char stmtName[TSDB_TABLE_NAME_LEN]; - uint8_t precision; - bool isEmptyResult; + char stmtName[TSDB_TABLE_NAME_LEN]; + uint8_t precision; + bool isEmptyResult; + bool hasAggFuncs; } SSelectStmt; -typedef enum ESetOperatorType { - SET_OP_TYPE_UNION_ALL = 1, - SET_OP_TYPE_UNION -} ESetOperatorType; +typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType; typedef struct SSetOperator { - ENodeType type; // QUERY_NODE_SET_OPERATOR + ENodeType type; // QUERY_NODE_SET_OPERATOR ESetOperatorType opType; - SNodeList* pProjectionList; - SNode* pLeft; - SNode* pRight; - SNodeList* pOrderByList; // SOrderByExprNode - SNode* pLimit; + SNodeList* pProjectionList; + SNode* pLeft; + SNode* pRight; + SNodeList* pOrderByList; // SOrderByExprNode + SNode* pLimit; } SSetOperator; typedef enum ESqlClause { @@ -274,7 +256,6 @@ typedef enum ESqlClause { SQL_CLAUSE_ORDER_BY } ESqlClause; - typedef enum { PAYLOAD_TYPE_KV = 0, PAYLOAD_TYPE_RAW = 1, @@ -284,29 +265,29 @@ typedef struct SVgDataBlocks { SVgroupInfo vg; int32_t numOfTables; // number of tables in current submit block uint32_t size; - char *pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ... + char* pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ... } SVgDataBlocks; typedef struct SVnodeModifOpStmt { - ENodeType nodeType; - ENodeType sqlNodeType; - SArray* pDataBlocks; // data block for each vgroup, SArray. - uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert - uint32_t insertType; // insert data from [file|sql statement| bound statement] - const char* sql; // current sql statement position + ENodeType nodeType; + ENodeType sqlNodeType; + SArray* pDataBlocks; // data block for each vgroup, SArray. + uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert + uint32_t insertType; // insert data from [file|sql statement| bound statement] + const char* sql; // current sql statement position } SVnodeModifOpStmt; typedef struct SExplainOptions { ENodeType type; - bool verbose; - double ratio; + bool verbose; + double ratio; } SExplainOptions; typedef struct SExplainStmt { - ENodeType type; - bool analyze; + ENodeType type; + bool analyze; SExplainOptions* pOptions; - SNode* pQuery; + SNode* pQuery; } SExplainStmt; void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext); @@ -327,10 +308,10 @@ bool nodesIsJsonOp(const SOperatorNode* pOp); bool nodesIsTimeorderQuery(const SNode* pQuery); bool nodesIsTimelineQuery(const SNode* pQuery); -void* nodesGetValueFromNode(SValueNode *pNode); -char* nodesGetStrValueFromNode(SValueNode *pNode); -char *getFillModeString(EFillMode mode); -void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal); +void* nodesGetValueFromNode(SValueNode* pNode); +char* nodesGetStrValueFromNode(SValueNode* pNode); +char* getFillModeString(EFillMode mode); +void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal); #ifdef __cplusplus } diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 0be27e6d3a65909deea9bbb5b638094cf598190f..ffe435a8b28c3b09007eb12b58b74b00be934db0 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -158,6 +158,8 @@ typedef enum { int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); +bool syncEnvIsStart(); + extern int32_t sDebugFlag; //----------------------------------------- diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 2545b33574be842e734593ee5592cd167682af4b..f0c3cc4b14ec088834c03de32cdc80f941c57177 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -573,7 +573,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602) #define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603) #define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604) -#define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605) #define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608) #define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609) #define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A) @@ -633,6 +632,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801) #define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802) #define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803) +#define TSDB_CODE_FUNC_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2604) #ifdef __cplusplus } diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 012368d9cba4ce62cb11ca4d3bacad8724e574d5..06fa9fd9aaf351f59b761a57cc96a4f3529ecf91 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -30,6 +30,7 @@ typedef enum { CFG_STYPE_CFG_FILE, CFG_STYPE_ENV_FILE, CFG_STYPE_ENV_VAR, + CFG_STYPE_ENV_CMD, CFG_STYPE_APOLLO_URL, CFG_STYPE_ARG_LIST, CFG_STYPE_TAOS_OPTIONS @@ -82,7 +83,7 @@ typedef struct SConfig { } SConfig; SConfig *cfgInit(); -int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); +int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr); int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair void cfgCleanup(SConfig *pCfg); @@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type); void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump); +int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl); + #ifdef __cplusplus } #endif diff --git a/include/util/tenv.h b/include/util/tenv.h new file mode 100644 index 0000000000000000000000000000000000000000..1410e23f9062be06fe45d38dbe5399a7db7bc444 --- /dev/null +++ b/include/util/tenv.h @@ -0,0 +1,33 @@ + +/* + * 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_ENV_H_ +#define _TD_ENV_H_ + +#include "os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen); +int32_t taosEnvToCfg(const char *envStr, char *cfgStr); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_ENV_H_*/ diff --git a/include/util/tjson.h b/include/util/tjson.h index 286a7e65fcd4780a653df5a61fc1d5de21253b62..d23f7b402ea142ea9118f57f6274983d78c5a72a 100644 --- a/include/util/tjson.h +++ b/include/util/tjson.h @@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem); int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem); SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName); +int32_t tjsonGetObjectName(const SJson* pJson, char** pName); +int32_t tjsonGetObjectValueString(const SJson* pJson, char** pStringValue); int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal); int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal); int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal); @@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson); SJson* tjsonParse(const char* pStr); bool tjsonValidateJson(const char* pJson); +const char* tjsonGetError(); #ifdef __cplusplus } diff --git a/include/util/ttimer.h b/include/util/ttimer.h index f2ee825c4e5ae4ab8b48184e78e89b5c99cf6ff6..10222596319f445c980e5a03b9ded91a3ca9ce4e 100644 --- a/include/util/ttimer.h +++ b/include/util/ttimer.h @@ -41,10 +41,6 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void *param, void *han void taosTmrCleanUp(void *handle); -int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms); - -void taosUninitTimer(); - #ifdef __cplusplus } #endif diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index 3ff671d5369ed3324c901302a0a30f0441622c6b..d3adc12df1674c1c4f7ba5d4d03221d6a97256cc 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -1,5 +1,9 @@ aux_source_directory(src CLIENT_SRC) -add_library(taos SHARED ${CLIENT_SRC}) +if(TD_WINDOWS) + add_library(taos SHARED ${CLIENT_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/taos.rc.in) +else() + add_library(taos SHARED ${CLIENT_SRC}) +endif () target_include_directories( taos PUBLIC "${TD_SOURCE_DIR}/include/client" @@ -10,6 +14,13 @@ target_link_libraries( INTERFACE api PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom ) +if(TD_WINDOWS) + set_target_properties(taos + PROPERTIES + LINK_FLAGS + /DEF:${CMAKE_CURRENT_SOURCE_DIR}/src/taos.def + ) +endif () set_target_properties( taos diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 814caf330ab8d938d04b7b4c261bfc4c9c71b5f8..c0237a184aead4f70b28e974370f34ac3f7c279c 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -231,6 +231,10 @@ static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool conver msg->resIter++; if (msg->resIter < msg->rsp.blockNum) { SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(msg->rsp.blockData, msg->resIter); + if (msg->rsp.withSchema) { + SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(msg->rsp.blockSchema, msg->resIter); + setResSchemaInfo(&msg->resInfo, pSW->pSchema, pSW->nCols); + } setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4); return &msg->resInfo; } diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 9a34334466d34cee74115f4735d15979215772ea..596c3d3fbf7fbc1ad975fea4eb88a02cd0ae7ab5 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -254,12 +254,12 @@ void taos_init_imp(void) { deltaToUtcInitOnce(); - if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) { + if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) { tscInitRes = -1; return; } - if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) { tscInitRes = -1; return; } diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 6159da9cb161e6604cbdd4f504114bf4b831b1d3..b11a49fa1aadbd1fd0be04f3e11ad230c150f62e 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -14,9 +14,9 @@ */ #include "catalog.h" -#include "scheduler.h" #include "clientInt.h" #include "clientLog.h" +#include "scheduler.h" #include "trpc.h" static SClientHbMgr clientHbMgr = {0}; @@ -110,7 +110,8 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pRsp->connKey, sizeof(SClientHbKey)); if (NULL == info) { - tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid, pRsp->connKey.connType); + tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid, + pRsp->connKey.connType); return TSDB_CODE_SUCCESS; } @@ -121,7 +122,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { } else { updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet); pTscObj->connId = pRsp->query->connId; - + if (pRsp->query->killRid) { SRequestObj *pRequest = acquireRequest(pRsp->query->killRid); if (NULL == pRequest) { @@ -131,7 +132,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { releaseRequest(pRsp->query->killRid); } } - + if (pRsp->query->killConnection) { taos_close(pTscObj); } @@ -139,7 +140,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { releaseTscObj(pRsp->connKey.tscRid); } } - + int32_t kvNum = pRsp->info ? taosArrayGetSize(pRsp->info) : 0; tscDebug("hb got %d rsp kv", kvNum); @@ -236,24 +237,24 @@ static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code) } int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) { - int64_t now = taosGetTimestampUs(); + int64_t now = taosGetTimestampUs(); SQueryDesc desc = {0}; - int32_t code = 0; + int32_t code = 0; - void *pIter = taosHashIterate(pObj->pRequests, NULL); + void *pIter = taosHashIterate(pObj->pRequests, NULL); while (pIter != NULL) { - int64_t *rid = pIter; + int64_t *rid = pIter; SRequestObj *pRequest = acquireRequest(*rid); if (NULL == pRequest) { continue; } tstrncpy(desc.sql, pRequest->sqlstr, sizeof(desc.sql)); - desc.stime = pRequest->metric.start; - desc.queryId = pRequest->requestId; + desc.stime = pRequest->metric.start; + desc.queryId = pRequest->requestId; desc.useconds = now - pRequest->metric.start; - desc.reqRid = pRequest->self; - desc.pid = hbBasic->pid; + desc.reqRid = pRequest->self; + desc.pid = hbBasic->pid; taosGetFqdn(desc.fqdn); desc.subPlanNum = pRequest->body.pDag ? pRequest->body.pDag->numOfSubplans : 0; @@ -271,9 +272,9 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) { } } - releaseRequest(*rid); + releaseRequest(*rid); taosArrayPush(hbBasic->queryDesc, &desc); - + pIter = taosHashIterate(pObj->pRequests, pIter); } @@ -286,14 +287,14 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid); return TSDB_CODE_QRY_APP_ERROR; } - + int32_t numOfQueries = pTscObj->pRequests ? taosHashGetSize(pTscObj->pRequests) : 0; if (numOfQueries <= 0) { releaseTscObj(connKey->tscRid); tscDebug("no queries on connection"); return TSDB_CODE_QRY_APP_ERROR; } - + SQueryHbReqBasic *hbBasic = (SQueryHbReqBasic *)taosMemoryCalloc(1, sizeof(SQueryHbReqBasic)); if (NULL == hbBasic) { tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic)); @@ -308,7 +309,7 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) { taosMemoryFree(hbBasic); return TSDB_CODE_QRY_OUT_OF_MEMORY; } - + hbBasic->connId = pTscObj->connId; hbBasic->pid = taosGetPId(); taosGetAppName(hbBasic->app, NULL); @@ -405,7 +406,7 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req } hbGetQueryBasicInfo(connKey, req); - + code = hbGetExpiredDBInfo(connKey, pCatalog, req); if (TSDB_CODE_SUCCESS != code) { return code; @@ -471,10 +472,10 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) { pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter); } -// if (code) { -// taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq); -// taosMemoryFreeClear(pBatchReq); -// } + // if (code) { + // taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq); + // taosMemoryFreeClear(pBatchReq); + // } return pBatchReq; } @@ -630,24 +631,23 @@ void appHbMgrCleanup(void) { int sz = taosArrayGetSize(clientHbMgr.appHbMgrs); for (int i = 0; i < sz; i++) { SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i); - - void *pIter = taosHashIterate(pTarget->activeInfo, NULL); + + void *pIter = taosHashIterate(pTarget->activeInfo, NULL); while (pIter != NULL) { SClientHbReq *pOneReq = pIter; hbFreeReq(pOneReq); taosHashCleanup(pOneReq->info); pIter = taosHashIterate(pTarget->activeInfo, pIter); - } + } taosHashCleanup(pTarget->activeInfo); pTarget->activeInfo = NULL; - pIter = taosHashIterate(pTarget->connInfo, NULL); while (pIter != NULL) { SHbConnInfo *info = pIter; taosMemoryFree(info->param); pIter = taosHashIterate(pTarget->connInfo, pIter); - } + } taosHashCleanup(pTarget->connInfo); pTarget->connInfo = NULL; @@ -668,13 +668,13 @@ int hbMgrInit() { hbMgrInitHandle(); // init backgroud thread - //hbCreateThread(); + /*hbCreateThread();*/ return 0; } void hbMgrCleanUp() { - //hbStopThread(); + // hbStopThread(); // destroy all appHbMgr int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0); @@ -747,11 +747,11 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) { taosMemoryFree(info->param); taosHashRemove(pAppHbMgr->connInfo, &connKey, sizeof(SClientHbKey)); } - + if (NULL == pReq || NULL == info) { return; } - + atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1); } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 2ae9a118030f2f3f750c3a5b0ac753c20210eed8..a40edbb65ac683893a364466c3e6cc2395ba7790 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -226,17 +226,15 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) { pRequest->type = pQuery->msgType; - SPlanContext cxt = { - .queryId = pRequest->requestId, - .acctId = pRequest->pTscObj->acctId, - .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), - .pAstRoot = pQuery->pRoot, - .showRewrite = pQuery->showRewrite, - .pTransporter = pRequest->pTscObj->pAppInfo->pTransporter, - .pMsg = pRequest->msgBuf, - .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE - }; - int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog); + SPlanContext cxt = {.queryId = pRequest->requestId, + .acctId = pRequest->pTscObj->acctId, + .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), + .pAstRoot = pQuery->pRoot, + .showRewrite = pQuery->showRewrite, + .pTransporter = pRequest->pTscObj->pAppInfo->pTransporter, + .pMsg = pRequest->msgBuf, + .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE}; + int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog); if (TSDB_CODE_SUCCESS == code) { code = qCreateQueryPlan(&cxt, pPlan, pNodeList); } @@ -247,6 +245,7 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t ASSERT(pSchema != NULL && numOfCols > 0); pResInfo->numOfCols = numOfCols; + // TODO handle memory leak pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD)); pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD)); @@ -282,7 +281,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf}; int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, - pRequest->metric.start, &res); + pRequest->metric.start, &res); if (code != TSDB_CODE_SUCCESS) { if (pRequest->body.queryJob != 0) { schedulerFreeJob(pRequest->body.queryJob); @@ -840,12 +839,12 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 return code; } - char* p = (char*) pResultInfo->pData; + char* p = (char*)pResultInfo->pData; - int32_t dataLen = *(int32_t*) p; + int32_t dataLen = *(int32_t*)p; p += sizeof(int32_t); - uint64_t groupId = *(uint64_t*) p; + uint64_t groupId = *(uint64_t*)p; p += sizeof(uint64_t); int32_t* colLength = (int32_t*)p; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 27efcee76e5af71ed7f5c7b516b00eb262cdaa8d..a9efcced4038fa9bcf5ab5c834b673a90b7a9901 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -120,7 +120,7 @@ const char *taos_errstr(TAOS_RES *res) { return (const char *)tstrerror(terrno); } - if (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) { + if (NULL != pRequest->msgBuf && (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR)) { return pRequest->msgBuf; } else { return (const char *)tstrerror(pRequest->code); diff --git a/source/client/src/taos.def b/source/client/src/taos.def new file mode 100644 index 0000000000000000000000000000000000000000..bc78b241d20a1bffab6747456db80319be25ac46 --- /dev/null +++ b/source/client/src/taos.def @@ -0,0 +1,80 @@ +taos_cleanup +taos_options +taos_set_config +taos_connect +taos_connect_l +taos_connect_auth +taos_close +taos_data_type +taos_stmt_init +taos_stmt_prepare +taos_stmt_set_tbname_tags +taos_stmt_set_tbname +taos_stmt_set_sub_tbname +taos_stmt_is_insert +taos_stmt_num_params +taos_stmt_get_param +taos_stmt_bind_param +taos_stmt_bind_param_batch +taos_stmt_bind_single_param_batch +taos_stmt_add_batch +taos_stmt_execute +taos_stmt_use_result +taos_stmt_close +taos_stmt_errstr +taos_stmt_affected_rows +taos_stmt_affected_rows_once +taos_query +taos_query_l +taos_fetch_row +taos_result_precision +taos_free_result +taos_field_count +taos_num_fields +taos_affected_rows +taos_fetch_fields +taos_select_db +taos_print_row +taos_stop_query +taos_is_null +taos_is_update_query +taos_fetch_block +taos_fetch_block_s +taos_fetch_raw_block +taos_get_column_data_offset +taos_validate_sql +taos_reset_current_db +taos_fetch_lengths +taos_result_block +taos_get_server_info +taos_get_client_info +taos_errstr +taos_errno +taos_query_a +taos_fetch_rows_a +taos_subscribe +taos_consume +taos_unsubscribe +taos_load_table_info +taos_schemaless_insert +tmq_list_new +tmq_list_append +tmq_list_destroy +tmq_list_get_size +tmq_list_to_c_array +tmq_consumer_new +tmq_err2str +tmq_subscribe +tmq_unsubscribe +tmq_subscription +tmq_consumer_poll +tmq_consumer_close +tmq_commit +tmq_conf_new +tmq_conf_set +tmq_conf_destroy +tmq_conf_set_offset_commit_cb +tmq_get_topic_name +tmq_get_vgroup_id +tmq_create_stream +taos_check_server_status \ No newline at end of file diff --git a/source/client/src/taos.rc.in b/source/client/src/taos.rc.in new file mode 100644 index 0000000000000000000000000000000000000000..84a2a7a5b5d8507b7f7b69d6f8b66ba558328c5e --- /dev/null +++ b/source/client/src/taos.rc.in @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION ${TD_VER_NUMBER} + PRODUCTVERSION ${TD_VER_NUMBER} + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "Native C Driver for TDengine" + VALUE "FileVersion", "${TD_VER_NUMBER}" + VALUE "InternalName", "taos.dll(${TD_VER_CPUTYPE})" + VALUE "LegalCopyright", "Copyright (C) 2020 TAOS Data" + VALUE "OriginalFilename", "" + VALUE "ProductName", "taos.dll(${TD_VER_CPUTYPE})" + VALUE "ProductVersion", "${TD_VER_NUMBER}" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END \ No newline at end of file diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index d576f28cb4d4bd004884ab1cf2f832f4245a8ba0..66e10f8c6a029de155b506bf23f0e17cd4ef6d40 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -23,6 +23,9 @@ #include "tmsgtype.h" #include "tqueue.h" #include "tref.h" +#include "ttimer.h" + +int32_t tmqAskEp(tmq_t* tmq, bool sync); typedef struct { int8_t tmqRspType; @@ -53,7 +56,7 @@ struct tmq_conf_t { int8_t autoCommit; int8_t resetOffset; uint16_t port; - uint16_t autoCommitInterval; + int32_t autoCommitInterval; char* ip; char* user; char* pass; @@ -61,29 +64,48 @@ struct tmq_conf_t { tmq_commit_cb* commit_cb; }; +typedef struct { + int8_t inited; + tmr_h timer; +} SMqMgmt; + +static SMqMgmt tmqMgmt = {0}; + struct tmq_t { // conf - char groupId[TSDB_CGROUP_LEN]; - char clientId[256]; - int8_t autoCommit; - /*int8_t inWaiting;*/ - int64_t consumerId; - int32_t epoch; + char groupId[TSDB_CGROUP_LEN]; + char clientId[256]; + int8_t autoCommit; + int32_t autoCommitInterval; int32_t resetOffsetCfg; - int64_t status; - STscObj* pTscObj; + int64_t consumerId; tmq_commit_cb* commit_cb; - /*int32_t nextTopicIdx;*/ + + // status + int8_t status; + int32_t epoch; +#if 0 int8_t epStatus; int32_t epSkipCnt; - /*int32_t waitingRequest;*/ - /*int32_t readyRequest;*/ +#endif + int64_t pollCnt; + + // timer + tmr_h hbTimer; + tmr_h reportTimer; + tmr_h commitTimer; + + // connection + STscObj* pTscObj; + + // container SArray* clientTopics; // SArray - STaosQueue* mqueue; // queue of tmq_message_t + STaosQueue* mqueue; // queue of rsp STaosQall* qall; - tsem_t rspSem; - // stat - int64_t pollCnt; + STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit + + // ctl + tsem_t rspSem; }; enum { @@ -93,9 +115,16 @@ enum { enum { TMQ_CONSUMER_STATUS__INIT = 0, + TMQ_CONSUMER_STATUS__SUBSCRIBED, TMQ_CONSUMER_STATUS__READY, }; +enum { + TMQ_DELAYED_TASK__HB = 1, + TMQ_DELAYED_TASK__REPORT, + TMQ_DELAYED_TASK__COMMIT, +}; + typedef struct { // statistics int64_t pollCnt; @@ -110,13 +139,11 @@ typedef struct { typedef struct { // subscribe info - int32_t sqlLen; - char* sql; - char* topicName; - int64_t topicId; - SArray* vgs; // SArray + char* topicName; + + SArray* vgs; // SArray + int8_t isSchemaAdaptive; - int32_t numOfFields; SSchemaWrapper schema; } SMqClientTopic; @@ -156,7 +183,6 @@ typedef struct { int32_t async; tsem_t rspSem; tmq_resp_err_t rspErr; - /*SMqClientVg* pVg;*/ } SMqCommitCbParam; tmq_conf_t* tmq_conf_new() { @@ -251,13 +277,7 @@ int32_t tmq_list_append(tmq_list_t* list, const char* src) { void tmq_list_destroy(tmq_list_t* list) { SArray* container = &list->container; - /*taosArrayDestroy(container);*/ - int32_t sz = taosArrayGetSize(container); - for (int32_t i = 0; i < sz; i++) { - char* str = taosArrayGetP(container, i); - taosMemoryFree(str); - } - taosArrayDestroy(container); + taosArrayDestroyP(container, taosMemoryFree); } int32_t tmq_list_get_size(const tmq_list_t* list) { @@ -274,6 +294,50 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) { return sprintf(dst, "%s:%d", topicName, vg); } +void tmqAssignDelayedHbTask(void* param, void* tmrId) { + tmq_t* tmq = (tmq_t*)param; + int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t)); + *pTaskType = TMQ_DELAYED_TASK__HB; + taosWriteQitem(tmq->delayedTask, pTaskType); +} + +void tmqAssignDelayedCommitTask(void* param, void* tmrId) { + tmq_t* tmq = (tmq_t*)param; + int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t)); + *pTaskType = TMQ_DELAYED_TASK__COMMIT; + taosWriteQitem(tmq->delayedTask, pTaskType); +} + +void tmqAssignDelayedReportTask(void* param, void* tmrId) { + tmq_t* tmq = (tmq_t*)param; + int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t)); + *pTaskType = TMQ_DELAYED_TASK__REPORT; + taosWriteQitem(tmq->delayedTask, pTaskType); +} + +int32_t tmqHandleAllDelayedTask(tmq_t* tmq) { + STaosQall* qall = taosAllocateQall(); + taosReadAllQitems(tmq->delayedTask, qall); + while (1) { + int8_t* pTaskType = NULL; + taosGetQitem(qall, (void**)&pTaskType); + if (pTaskType == NULL) break; + + if (*pTaskType == TMQ_DELAYED_TASK__HB) { + tmqAskEp(tmq, false); + taosTmrReset(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer, &tmq->hbTimer); + } else if (*pTaskType == TMQ_DELAYED_TASK__COMMIT) { + tmq_commit(tmq, NULL, true); + taosTmrReset(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer, &tmq->commitTimer); + } else if (*pTaskType == TMQ_DELAYED_TASK__REPORT) { + } else { + ASSERT(0); + } + } + taosFreeQall(qall); + return 0; +} + void tmqClearUnhandleMsg(tmq_t* tmq) { SMqRspWrapper* msg = NULL; while (1) { @@ -298,6 +362,8 @@ void tmqClearUnhandleMsg(tmq_t* tmq) { int32_t tmqSubscribeCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqSubscribeCbParam* pParam = (SMqSubscribeCbParam*)param; pParam->rspErr = code; + tmq_t* tmq = pParam->tmq; + atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__SUBSCRIBED); tsem_post(&pParam->rspSem); return 0; } @@ -335,12 +401,9 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs return NULL; } pTmq->pTscObj = (STscObj*)conn; - /*pTmq->inWaiting = 0;*/ pTmq->status = 0; pTmq->pollCnt = 0; pTmq->epoch = 0; - /*pTmq->waitingRequest = 0;*/ - /*pTmq->readyRequest = 0;*/ pTmq->epStatus = 0; pTmq->epSkipCnt = 0; // set conf @@ -367,46 +430,78 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs #endif tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { + // init timer + int8_t inited = atomic_val_compare_exchange_8(&tmqMgmt.inited, 0, 1); + if (inited == 0) { + tmqMgmt.timer = taosTmrInit(1000, 100, 360000, "TMQ"); + if (tmqMgmt.timer == NULL) { + atomic_store_8(&tmqMgmt.inited, 0); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + } + tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t)); if (pTmq == NULL) { return NULL; } + const char* user = conf->user == NULL ? TSDB_DEFAULT_USER : conf->user; const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass; ASSERT(user); ASSERT(pass); - ASSERT(conf->db); ASSERT(conf->groupId[0]); - pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, conf->db, conf->port, CONN_TYPE__TMQ); - if (pTmq->pTscObj == NULL) return NULL; + pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic)); + pTmq->mqueue = taosOpenQueue(); + pTmq->qall = taosAllocateQall(); + pTmq->delayedTask = taosOpenQueue(); + + if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL) { + goto FAIL; + } - pTmq->status = 0; + // init status + pTmq->status = TMQ_CONSUMER_STATUS__INIT; pTmq->pollCnt = 0; pTmq->epoch = 0; - pTmq->epStatus = 0; - pTmq->epSkipCnt = 0; + /*pTmq->epStatus = 0;*/ + /*pTmq->epSkipCnt = 0;*/ + // set conf strcpy(pTmq->clientId, conf->clientId); strcpy(pTmq->groupId, conf->groupId); - pTmq->autoCommit = conf->autoCommit; + /*pTmq->autoCommit = conf->autoCommit;*/ + pTmq->autoCommit = 0; + pTmq->autoCommitInterval = conf->autoCommitInterval; pTmq->commit_cb = conf->commit_cb; pTmq->resetOffsetCfg = conf->resetOffset; + // assign consumerId pTmq->consumerId = tGenIdPI64(); - pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic)); - if (pTmq->clientTopics == NULL) { - taosMemoryFree(pTmq); - return NULL; - } - pTmq->mqueue = taosOpenQueue(); - pTmq->qall = taosAllocateQall(); + // init semaphore + if (tsem_init(&pTmq->rspSem, 0, 0) != 0) { + goto FAIL; + } - tsem_init(&pTmq->rspSem, 0, 0); + // init connection + pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, NULL, conf->port, CONN_TYPE__TMQ); + if (pTmq->pTscObj == NULL) { + tsem_destroy(&pTmq->rspSem); + goto FAIL; + } return pTmq; + +FAIL: + if (pTmq->clientTopics) taosArrayDestroy(pTmq->clientTopics); + if (pTmq->mqueue) taosCloseQueue(pTmq->mqueue); + if (pTmq->delayedTask) taosCloseQueue(pTmq->delayedTask); + if (pTmq->qall) taosFreeQall(pTmq->qall); + taosMemoryFree(pTmq); + return NULL; } tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int32_t async) { @@ -497,86 +592,64 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in return resp; } -tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) { - SRequestObj* pRequest = NULL; - SArray* container = &topic_list->container; - int32_t sz = taosArrayGetSize(container); - // destroy ex - taosArrayDestroy(tmq->clientTopics); - tmq->clientTopics = taosArrayInit(sz, sizeof(SMqClientTopic)); +tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { + const SArray* container = &topic_list->container; + int32_t sz = taosArrayGetSize(container); + void* buf = NULL; + SCMSubscribeReq req = {0}; + int32_t code = -1; - SCMSubscribeReq req; req.consumerId = tmq->consumerId; - strcpy(req.cgroup, tmq->groupId); + tstrncpy(req.cgroup, tmq->groupId, TSDB_CGROUP_LEN); req.topicNames = taosArrayInit(sz, sizeof(void*)); + if (req.topicNames == NULL) goto FAIL; - for (int i = 0; i < sz; i++) { - /*char* topicName = topic_list->elems[i];*/ - char* topicName = taosArrayGetP(container, i); + for (int32_t i = 0; i < sz; i++) { + char* topic = taosArrayGetP(container, i); SName name = {0}; -#if 0 - char* dbName = getDbOfConnection(tmq->pTscObj); - if (dbName == NULL) { - return TMQ_RESP_ERR__FAIL; - } -#endif - tNameSetDbName(&name, tmq->pTscObj->acctId, topicName, strlen(topicName)); -#if 0 - tNameFromString(&name, topicName, T_NAME_TABLE); -#endif + tNameSetDbName(&name, tmq->pTscObj->acctId, topic, strlen(topic)); - char* topicFname = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN); - if (topicFname == NULL) { - goto _return; + char* topicFName = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN); + if (topicFName == NULL) { + goto FAIL; } - tNameExtractFullName(&name, topicFname); - tscDebug("subscribe topic: %s", topicFname); - SMqClientTopic topic = { - .sql = NULL, - .sqlLen = 0, - .topicId = 0, - .topicName = topicFname, - .vgs = NULL, - }; - topic.vgs = taosArrayInit(0, sizeof(SMqClientVg)); - taosArrayPush(tmq->clientTopics, &topic); - taosArrayPush(req.topicNames, &topicFname); -#if 0 - taosMemoryFree(dbName); -#endif - } + tNameExtractFullName(&name, topicFName); - int tlen = tSerializeSCMSubscribeReq(NULL, &req); - void* buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - goto _return; + tscDebug("subscribe topic: %s", topicFName); + + taosArrayPush(req.topicNames, &topicFName); } + int32_t tlen = tSerializeSCMSubscribeReq(NULL, &req); + buf = taosMemoryMalloc(tlen); + if (buf == NULL) goto FAIL; + void* abuf = buf; tSerializeSCMSubscribeReq(&abuf, &req); - /*printf("formatted: %s\n", dagStr);*/ - pRequest = createRequest(tmq->pTscObj, NULL, NULL, TDMT_MND_SUBSCRIBE); - if (pRequest == NULL) { - tscError("failed to malloc request"); - } + SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo)); + if (sendInfo == NULL) goto FAIL; SMqSubscribeCbParam param = { .rspErr = TMQ_RESP_ERR__SUCCESS, .tmq = tmq, }; - tsem_init(¶m.rspSem, 0, 0); - pRequest->body.requestMsg = (SDataBuf){ + if (tsem_init(¶m.rspSem, 0, 0) != 0) goto FAIL; + + sendInfo->msgInfo = (SDataBuf){ .pData = buf, .len = tlen, .handle = NULL, }; - SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest); + sendInfo->requestId = generateRequestId(); + sendInfo->requestObjRefId = 0; sendInfo->param = ¶m; sendInfo->fp = tmqSubscribeCb; + sendInfo->msgType = TDMT_MND_SUBSCRIBE; + SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); int64_t transporterId = 0; @@ -585,15 +658,36 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) { tsem_wait(¶m.rspSem); tsem_destroy(¶m.rspSem); -_return: - /*if (sendInfo != NULL) {*/ - /*destroySendMsgInfo(sendInfo);*/ - /*}*/ + code = param.rspErr; + if (code != 0) goto FAIL; + + // TODO: add max retry cnt + while (TSDB_CODE_MND_CONSUMER_NOT_READY == tmqAskEp(tmq, true)) { + tscDebug("not ready, retry\n"); + taosMsleep(500); + } + + // init hb timer + tmq->hbTimer = taosTmrStart(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer); - return param.rspErr; + // init auto commit timer + if (tmq->autoCommit) { + tmq->commitTimer = taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer); + } + + code = 0; +FAIL: + if (req.topicNames != NULL) taosArrayDestroyP(req.topicNames, taosMemoryFree); + if (code != 0) { + taosMemoryFree(buf); + } + return code; } -void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) { conf->commit_cb = cb; } +void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) { + // + conf->commit_cb = cb; +} TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) { STscObj* pTscObj = (STscObj*)taos; @@ -627,9 +721,6 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa int32_t code = 0; CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); CHECK_CODE_GOTO(parseSql(pRequest, false, &pQueryNode, NULL), _return); - - // todo check for invalid sql statement and return with error code - CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return); /*printf("%s\n", pStr);*/ @@ -653,7 +744,6 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa } tSerializeSCMCreateStreamReq(buf, tlen, &req); - /*printf("formatted: %s\n", dagStr);*/ pRequest->body.requestMsg = (SDataBuf){ .pData = buf, @@ -684,94 +774,6 @@ _return: return pRequest; } -#if 0 -TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) { - STscObj* pTscObj = (STscObj*)taos; - SRequestObj* pRequest = NULL; - SQuery* pQueryNode = NULL; - char* astStr = NULL; - - terrno = TSDB_CODE_SUCCESS; - if (taos == NULL || topicName == NULL || sql == NULL) { - tscError("invalid parameters for creating topic, connObj:%p, topic name:%s, sql:%s", taos, topicName, sql); - terrno = TSDB_CODE_TSC_INVALID_INPUT; - goto _return; - } - - if (strlen(topicName) >= TSDB_TOPIC_NAME_LEN) { - tscError("topic name too long, max length:%d", TSDB_TOPIC_NAME_LEN - 1); - terrno = TSDB_CODE_TSC_INVALID_INPUT; - goto _return; - } - - if (sqlLen > TSDB_MAX_ALLOWED_SQL_LEN) { - tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); - terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; - goto _return; - } - - tscDebug("start to create topic: %s", topicName); - - int32_t code = TSDB_CODE_SUCCESS; - CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); - CHECK_CODE_GOTO(parseSql(pRequest, true, &pQueryNode), _return); - - // todo check for invalid sql statement and return with error code - - CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return); - - /*printf("%s\n", pStr);*/ - - SName name = {.acctId = pTscObj->acctId, .type = TSDB_TABLE_NAME_T}; - strcpy(name.dbname, pRequest->pDb); - strcpy(name.tname, topicName); - - SCMCreateTopicReq req = { - .igExists = 1, - .ast = astStr, - .sql = (char*)sql, - }; - tNameExtractFullName(&name, req.name); - - int tlen = tSerializeSCMCreateTopicReq(NULL, 0, &req); - void* buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - goto _return; - } - - tSerializeSCMCreateTopicReq(buf, tlen, &req); - /*printf("formatted: %s\n", dagStr);*/ - - pRequest->body.requestMsg = (SDataBuf){ - .pData = buf, - .len = tlen, - .handle = NULL, - }; - pRequest->type = TDMT_MND_CREATE_TOPIC; - - SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest); - SEpSet epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); - - int64_t transporterId = 0; - asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); - - tsem_wait(&pRequest->body.rspSem); - -_return: - taosMemoryFreeClear(astStr); - qDestroyQuery(pQueryNode); - /*if (sendInfo != NULL) {*/ - /*destroySendMsgInfo(sendInfo);*/ - /*}*/ - - if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) { - pRequest->code = terrno; - } - - return pRequest; -} -#endif - #if 0 int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) { if (tmq_message == NULL) return 0; @@ -954,7 +956,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { /*printf("rsp epoch %ld sz %ld\n", rsp.epoch, rsp.topics->size);*/ /*printf("tmq epoch %ld sz %ld\n", tmq->epoch, tmq->clientTopics->size);*/ if (tmqUpdateEp(tmq, head->epoch, &rsp)) { - atomic_store_64(&tmq->status, TMQ_CONSUMER_STATUS__READY); + atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__READY); } tDeleteSMqCMGetSubEpRsp(&rsp); } else { @@ -975,7 +977,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { } END: - atomic_store_8(&tmq->epStatus, 0); + /*atomic_store_8(&tmq->epStatus, 0);*/ if (pParam->sync) { tsem_post(&pParam->rspSem); } @@ -984,6 +986,7 @@ END: int32_t tmqAskEp(tmq_t* tmq, bool sync) { int32_t code = 0; +#if 0 int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1); if (epStatus == 1) { int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1); @@ -991,11 +994,12 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { if (epSkipCnt < 5000) return 0; } atomic_store_32(&tmq->epSkipCnt, 0); +#endif int32_t tlen = sizeof(SMqCMGetSubEpReq); SMqCMGetSubEpReq* req = taosMemoryMalloc(tlen); if (req == NULL) { tscError("failed to malloc get subscribe ep buf"); - atomic_store_8(&tmq->epStatus, 0); + /*atomic_store_8(&tmq->epStatus, 0);*/ return -1; } req->consumerId = htobe64(tmq->consumerId); @@ -1006,7 +1010,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { if (pParam == NULL) { tscError("failed to malloc subscribe param"); taosMemoryFree(req); - atomic_store_8(&tmq->epStatus, 0); + /*atomic_store_8(&tmq->epStatus, 0);*/ return -1; } pParam->tmq = tmq; @@ -1018,7 +1022,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { tsem_destroy(&pParam->rspSem); taosMemoryFree(pParam); taosMemoryFree(req); - atomic_store_8(&tmq->epStatus, 0); + /*atomic_store_8(&tmq->epStatus, 0);*/ return -1; } @@ -1118,7 +1122,9 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) { pRspObj->resInfo.totalRows = 0; pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI; - setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols); + if (!pWrapper->msg.withSchema) { + setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols); + } taosFreeQitem(pWrapper); return pRspObj; @@ -1187,7 +1193,6 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { int64_t transporterId = 0; /*printf("send poll\n");*/ - /*atomic_add_fetch_32(&tmq->waitingRequest, 1);*/ tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId, pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId); /*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/ @@ -1266,12 +1271,14 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { SMqRspObj* rspObj; int64_t startTime = taosGetTimestampMs(); - // TODO: put into another thread or delayed queue - int64_t status = atomic_load_64(&tmq->status); - while (0 != tmqAskEp(tmq, status == TMQ_CONSUMER_STATUS__INIT)) { + // TODO: put into delayed queue +#if 0 + int8_t status = atomic_load_8(&tmq->status); + while (0 != tmqAskEp(tmq, status != TMQ_CONSUMER_STATUS__READY)) { tscDebug("not ready, retry\n"); taosSsleep(1); } +#endif rspObj = tmqHandleAllRsp(tmq, blocking_time, false); if (rspObj) { @@ -1279,8 +1286,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { } while (1) { - /*printf("cycle\n");*/ - tmqAskEp(tmq, false); + tmqHandleAllDelayedTask(tmq); tmqPollImpl(tmq, blocking_time); /*tsem_wait(&tmq->rspSem);*/ diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 09452b584d5236f8e1265506d3adcc720c4b97d9..5270bdeb4658d8eaf0e4ddbcfdda7d767b3a03f4 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -79,7 +79,11 @@ int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRo if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { return pColumnInfoData->varmeta.length; } else { - return pColumnInfoData->info.bytes * numOfRows; + if (pColumnInfoData->info.type == TSDB_DATA_TYPE_NULL) { + return 0; + } else { + return pColumnInfoData->info.bytes * numOfRows; + } } } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 33999ea14cc901c579a46e8f8cdddd7046dabfd6..bbf14b2fdc42ac889a9183eb90981ab217590564 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() { return tsCfg; } -static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { +static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) { char cfgDir[PATH_MAX] = {0}; char cfgFile[PATH_MAX + 100] = {0}; @@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e tstrncpy(cfgFile, cfgDir, sizeof(cfgDir)); } + if (apolloUrl == NULL || apolloUrl[0] == '\0') cfgGetApollUrl(envCmd, envFile, apolloUrl); + if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) { uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr()); return -1; @@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e return -1; } + if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) { + uError("failed to load from cmd env variables since %s", terrstr()); + return -1; + } + return 0; } @@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) { if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1; if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1; - if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1; - if (cfgAddInt64(pCfg, "totalMemory(KB)", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "pageSizeKB", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1; + if (cfgAddInt64(pCfg, "totalMemoryKB", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1; if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1; if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1; @@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { return 0; } -int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, - const char *apolloUrl, SArray *pArgs, bool tsc) { +int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, + char *apolloUrl, SArray *pArgs, bool tsc) { osDefaultInit(); SConfig *pCfg = cfgInit(); @@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi if (taosAddServerLogCfg(pCfg) != 0) return -1; } - if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) { + if (taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) { uError("failed to load cfg since %s", terrstr()); cfgCleanup(pCfg); return -1; @@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi return 0; } -int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) { +int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) { if (tsCfg != NULL) return 0; tsCfg = cfgInit(); @@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU } taosAddSystemCfg(tsCfg); - if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) { + if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) { uError("failed to load cfg since %s", terrstr()); cfgCleanup(tsCfg); tsCfg = NULL; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index efd4cbfcecc53176f658c66548523ae1b8f140b1..98d0bae427ae1b5b08769a2f373dbf57cbf0e825 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -94,6 +94,86 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) { } } +// TODO: KEEP one suite of iterator API finally. +// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts +// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later +// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter + +int32_t tInitSubmitMsgIterEx(const SSubmitReq *pMsg, SSubmitMsgIter *pIter) { + if (pMsg == NULL) { + terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP; + return -1; + } + + pIter->totalLen = htonl(pMsg->length); + ASSERT(pIter->totalLen > 0); + pIter->len = 0; + pIter->pMsg = pMsg; + if (pIter->totalLen <= sizeof(SSubmitReq)) { + terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP; + return -1; + } + + return 0; +} + +int32_t tGetSubmitMsgNextEx(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) { + ASSERT(pIter->len >= 0); + + if (pIter->len == 0) { + pIter->len += sizeof(SSubmitReq); + } else { + if (pIter->len >= pIter->totalLen) { + ASSERT(0); + } + + SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len); + pIter->len += (sizeof(SSubmitBlk) + pIter->dataLen + pIter->schemaLen); + ASSERT(pIter->len > 0); + } + + if (pIter->len > pIter->totalLen) { + terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP; + *pPBlock = NULL; + return -1; + } + + if (pIter->len == pIter->totalLen) { + *pPBlock = NULL; + } else { + *pPBlock = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len); + pIter->uid = htobe64((*pPBlock)->uid); + pIter->suid = htobe64((*pPBlock)->suid); + pIter->sversion = htonl((*pPBlock)->sversion); + pIter->dataLen = htonl((*pPBlock)->dataLen); + pIter->schemaLen = htonl((*pPBlock)->schemaLen); + pIter->numOfRows = htons((*pPBlock)->numOfRows); + } + return 0; +} + +int32_t tInitSubmitBlkIterEx(SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkIter *pIter) { + if (pMsgIter->dataLen <= 0) return -1; + pIter->totalLen = pMsgIter->dataLen; + pIter->len = 0; + pIter->row = (STSRow *)(pBlock->data + pMsgIter->schemaLen); + return 0; +} + +STSRow *tGetSubmitBlkNextEx(SSubmitBlkIter *pIter) { + STSRow *row = pIter->row; + + if (pIter->len >= pIter->totalLen) { + return NULL; + } else { + pIter->len += TD_ROW_LEN(row); + if (pIter->len < pIter->totalLen) { + pIter->row = POINTER_SHIFT(row, TD_ROW_LEN(row)); + } + return row; + } +} + int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) { if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1; if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1; @@ -442,10 +522,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { SRSmaParam *param = pReq->stbCfg.pRSmaParam; tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); tlen += taosEncodeFixedI32(buf, param->delay); - tlen += taosEncodeFixedI8(buf, param->nFuncIds); - for (int8_t i = 0; i < param->nFuncIds; ++i) { - tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); - } tlen += taosEncodeFixedI32(buf, param->qmsg1Len); if (param->qmsg1Len > 0) { tlen += taosEncodeString(buf, param->qmsg1); @@ -475,10 +551,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { SRSmaParam *param = pReq->ntbCfg.pRSmaParam; tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); tlen += taosEncodeFixedI32(buf, param->delay); - tlen += taosEncodeFixedI8(buf, param->nFuncIds); - for (int8_t i = 0; i < param->nFuncIds; ++i) { - tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]); - } } break; default: @@ -521,13 +593,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { SRSmaParam *param = pReq->stbCfg.pRSmaParam; buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); buf = taosDecodeFixedI32(buf, ¶m->delay); - buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); - if (param->nFuncIds > 0) { - param->pFuncIds = (func_id_t *)taosMemoryCalloc(param->nFuncIds, sizeof(func_id_t)); - for (int8_t i = 0; i < param->nFuncIds; ++i) { - buf = taosDecodeFixedI32(buf, param->pFuncIds + i); - } - } buf = taosDecodeFixedI32(buf, ¶m->qmsg1Len); if (param->qmsg1Len > 0) { buf = taosDecodeString(buf, ¶m->qmsg1); @@ -561,15 +626,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { SRSmaParam *param = pReq->ntbCfg.pRSmaParam; buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor)); buf = taosDecodeFixedI32(buf, ¶m->delay); - buf = taosDecodeFixedI8(buf, ¶m->nFuncIds); - if (param->nFuncIds > 0) { - param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t)); - for (int8_t i = 0; i < param->nFuncIds; ++i) { - buf = taosDecodeFixedI32(buf, param->pFuncIds + i); - } - } else { - param->pFuncIds = NULL; - } } else { pReq->ntbCfg.pRSmaParam = NULL; } @@ -632,7 +688,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1; - if (tEncodeI32(&encoder, pReq->aggregationMethod) < 0) return -1; if (tEncodeI32(&encoder, pReq->delay) < 0) return -1; if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1; @@ -687,7 +742,6 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1; - if (tDecodeI32(&decoder, &pReq->aggregationMethod) < 0) return -1; if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1; if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 4b01c540f7e6019240aa3eff0ab547705420275e..5983ba92ac9d58324decc2cff958057ee087789f 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -17,13 +17,24 @@ #include "dmImp.h" #include "tconfig.h" +#define DM_APOLLO_URL "The apollo string to use when configuring the server, such as: -a 'jsonFile:./tests/cfg.json', cfg.json text can be '{\"fqdn\":\"td1\"}'." +#define DM_CFG_DIR "Configuration directory." +#define DM_DMP_CFG "Dump configuration." +#define DM_ENV_CMD "The env cmd variable string to use when configuring the server, such as: -e 'TAOS_FQDN=td1'." +#define DM_ENV_FILE "The env variable file path to use when configuring the server, default is './.env', .env text can be 'TAOS_FQDN=td1'." +#define DM_NODE_TYPE "Startup type of the node, default is 0." +#define DM_MACHINE_CODE "Get machine code." +#define DM_VERSION "Print program version." +#define DM_EMAIL "" static struct { bool dumpConfig; bool generateGrant; bool printAuth; bool printVersion; + bool printHelp; char envFile[PATH_MAX]; char apolloUrl[PATH_MAX]; + const char **envCmd; SArray *pArgs; // SConfigPair SDnode *pDnode; EDndNodeType ntype; @@ -56,6 +67,9 @@ static void dmSetSignalHandle() { } static int32_t dmParseArgs(int32_t argc, char const *argv[]) { + int32_t cmdEnvIndex = 0; + global.envCmd = taosMemoryMalloc(argc-1); + memset(global.envCmd, 0, argc-1); for (int32_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { @@ -70,7 +84,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { } } else if (strcmp(argv[i], "-a") == 0) { tstrncpy(global.apolloUrl, argv[++i], PATH_MAX); - } else if (strcmp(argv[i], "-e") == 0) { + } else if (strcmp(argv[i], "-E") == 0) { tstrncpy(global.envFile, argv[++i], PATH_MAX); } else if (strcmp(argv[i], "-n") == 0) { global.ntype = atoi(argv[++i]); @@ -84,6 +98,11 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { global.dumpConfig = true; } else if (strcmp(argv[i], "-V") == 0) { global.printVersion = true; + } else if (strcmp(argv[i], "-e") == 0) { + global.envCmd[cmdEnvIndex] = argv[++i]; + cmdEnvIndex++; + } else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 || strcmp(argv[i], "-?")) { + global.printHelp = true; } else { } } @@ -104,6 +123,21 @@ static void dmPrintVersion() { printf("buildInfo: %s\n", buildinfo); } +static void dmPrintHelp() { + char indent[] = " "; + printf("Usage: taosd [OPTION...] \n\n"); + printf("%s%s%s%s\n", indent, "-a,", indent, DM_APOLLO_URL); + printf("%s%s%s%s\n", indent, "-c,", indent, DM_CFG_DIR); + printf("%s%s%s%s\n", indent, "-C,", indent, DM_DMP_CFG); + printf("%s%s%s%s\n", indent, "-e,", indent, DM_ENV_CMD); + printf("%s%s%s%s\n", indent, "-E,", indent, DM_ENV_FILE); + printf("%s%s%s%s\n", indent, "-n,", indent, DM_NODE_TYPE); + printf("%s%s%s%s\n", indent, "-k,", indent, DM_MACHINE_CODE); + printf("%s%s%s%s\n", indent, "-V,", indent, DM_VERSION); + + printf("\n\nReport bugs to %s.\n", DM_EMAIL); +} + static void dmDumpCfg() { SConfig *pCfg = taosGetCfg(); cfgDumpCfg(pCfg, 0, true); @@ -129,7 +163,7 @@ static SDnodeOpt dmGetOpt() { static int32_t dmInitLog() { char logName[12] = {0}; snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype)); - return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); + return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0); } static void dmSetProcInfo(int32_t argc, char **argv) { @@ -168,6 +202,10 @@ static int32_t dmRunDnode() { return code; } +static void taosCleanupArgs() { + if (global.envCmd != NULL) taosMemoryFree(global.envCmd); +} + int main(int argc, char const *argv[]) { if (!taosCheckSystemIsSmallEnd()) { printf("failed to start since on non-small-end machines\n"); @@ -176,26 +214,37 @@ int main(int argc, char const *argv[]) { if (dmParseArgs(argc, argv) != 0) { printf("failed to start since parse args error\n"); + taosCleanupArgs(); return -1; } if (global.generateGrant) { dmGenerateGrant(); + taosCleanupArgs(); + return 0; + } + + if (global.printHelp) { + dmPrintHelp(); + taosCleanupArgs(); return 0; } if (global.printVersion) { dmPrintVersion(); + taosCleanupArgs(); return 0; } if (dmInitLog() != 0) { - dError("failed to start since init log error"); + printf("failed to start since init log error"); + taosCleanupArgs(); return -1; } - if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { + if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { dError("failed to start since read config error"); + taosCleanupArgs(); return -1; } @@ -203,9 +252,11 @@ int main(int argc, char const *argv[]) { dmDumpCfg(); taosCleanupCfg(); taosCloseLog(); + taosCleanupArgs(); return 0; } dmSetProcInfo(argc, (char **)argv); + taosCleanupArgs(); return dmRunDnode(); } diff --git a/source/dnode/mgmt/interface/src/dmFile.c b/source/dnode/mgmt/interface/src/dmFile.c index e9117939d72ca5c094d7fe6066cb1843d4efaeed..38acf169be47f51c96cbb0339f58b4b964c3d382 100644 --- a/source/dnode/mgmt/interface/src/dmFile.c +++ b/source/dnode/mgmt/interface/src/dmFile.c @@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to lock file:%s since %s", filepath, terrstr()); + dError("failed to open file:%s since %s", filepath, terrstr()); return NULL; } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 4cc1b8527c57f297d93383019d5c847648ec5945..7fc263c93cbf3fd4f4649c5ce7502d957629ed95 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -202,6 +202,17 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return code; } + code = vnodeStart(pImpl); + if (code != 0) { + tFreeSCreateVnodeReq(&createReq); + dError("vgId:%d, failed to start sync since %s", createReq.vgId, terrstr()); + vnodeClose(pImpl); + vnodeDestroy(path, pMgmt->pTfs); + terrno = code; + return code; + } + + code = vmWriteVnodesToFile(pMgmt); if (code != 0) { tFreeSCreateVnodeReq(&createReq); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 687a799c575baeb13603f2d37edcb8e4e6895bd2..3088c5dea40f92b5ef9a8b2b582ef8bfedc66d58 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -74,12 +74,6 @@ int32_t vmOpenVnode(SVnodesMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) { return -1; } - // sync integration - vnodeSyncSetQ(pImpl, NULL); - vnodeSyncSetRpc(pImpl, NULL); - int32_t ret = vnodeSyncStart(pImpl); - assert(ret == 0); - taosWLockLatch(&pMgmt->latch); int32_t code = taosHashPut(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnodeObj *)); taosWUnLockLatch(&pMgmt->latch); @@ -153,6 +147,7 @@ static void *vmOpenVnodeFunc(void *param) { pThread->failed++; } else { vmOpenVnode(pMgmt, pCfg, pImpl); + //vnodeStart(pImpl); dDebug("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex); pThread->opened++; } @@ -364,10 +359,52 @@ static int32_t vmRequire(SMgmtWrapper *pWrapper, bool *required) { return 0; } +static int32_t vmStart(SMgmtWrapper *pWrapper) { + dDebug("vnode-mgmt start to run"); + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + + taosRLockLatch(&pMgmt->latch); + + void *pIter = taosHashIterate(pMgmt->hash, NULL); + while (pIter) { + SVnodeObj **ppVnode = pIter; + if (ppVnode == NULL || *ppVnode == NULL) continue; + + SVnodeObj *pVnode = *ppVnode; + vnodeStart(pVnode->pImpl); + pIter = taosHashIterate(pMgmt->hash, pIter); + } + + taosRUnLockLatch(&pMgmt->latch); + return 0; +} + +static void vmStop(SMgmtWrapper *pWrapper) { +#if 0 + dDebug("vnode-mgmt start to stop"); + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + taosRLockLatch(&pMgmt->latch); + + void *pIter = taosHashIterate(pMgmt->hash, NULL); + while (pIter) { + SVnodeObj **ppVnode = pIter; + if (ppVnode == NULL || *ppVnode == NULL) continue; + + SVnodeObj *pVnode = *ppVnode; + vnodeStop(pVnode->pImpl); + pIter = taosHashIterate(pMgmt->hash, pIter); + } + + taosRUnLockLatch(&pMgmt->latch); +#endif +} + void vmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = vmInit; mgmtFp.closeFp = vmCleanup; + mgmtFp.startFp = vmStart; + mgmtFp.stopFp = vmStop; mgmtFp.requiredFp = vmRequire; vmInitMsgHandle(pWrapper); @@ -396,4 +433,4 @@ void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { } taosRUnLockLatch(&pMgmt->latch); -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index cf1cd58540733eba2a6f3d970d9462414de9c3bd..36a8173adf3abb2efc68a6a37ece55bdef2fea25 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -126,6 +126,8 @@ typedef enum { DND_REASON_OTHERS } EDndReason; +typedef void (*TransCbFp)(SMnode* pMnode, void* param); + typedef struct { int32_t id; ETrnStage stage; @@ -148,6 +150,8 @@ typedef struct { int64_t dbUid; char dbname[TSDB_DB_FNAME_LEN]; char lastError[TSDB_TRANS_ERROR_LEN]; + TransCbFp transCbFp; + void* transCbParam; } STrans; typedef struct { @@ -350,7 +354,6 @@ typedef struct { int32_t version; int32_t nextColId; float xFilesFactor; - int32_t aggregationMethod; int32_t delay; int32_t ttl; int32_t numOfColumns; diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 5c1b0991be803e765637c8f36b3b84cdb1fc7056..2fcc82e861485a2c7f7df957a29642a471275137 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -44,6 +44,7 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw); int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction); int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction); void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen); +void mndTransSetCb(STrans *pTrans, TransCbFp fp, void *param); void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb); int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans); diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index fe8c35004da1b2ced3a7d59c4ac880371c2a416f..f42829eddfffddabf55f96ad7ed830831f28378e 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -30,7 +30,6 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup); int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups); SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup); int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId); -int32_t mndGetGlobalVgroupVersion(int32_t *vgId); void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen); diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 9caadb7e030b7912f7ede818fbbcd8c58f7fad86..15ebcf02dbbeeca55b653d548105d1d8f9122da3 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -234,6 +234,8 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) { return 0; } +static int32_t mndGetGlobalVgroupVersion(SMnode *pMnode) { return sdbGetTableVer(pMnode->pSdb, SDB_VGROUP); } + SDbObj *mndAcquireDb(SMnode *pMnode, const char *db) { SSdb *pSdb = pMnode->pSdb; SDbObj *pDb = sdbAcquire(pSdb, SDB_DB, db); @@ -618,7 +620,7 @@ static int32_t mndSetAlterDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOl SSdbRaw *pRedoRaw = mndDbActionEncode(pOld); 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; } @@ -1191,8 +1193,7 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) { char *p = strchr(usedbReq.db, '.'); if (p && 0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB)) { memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN); - //mndGetGlobalVgroupVersion(); TODO - static int32_t vgVersion = 1; + int32_t vgVersion = mndGetGlobalVgroupVersion(pMnode); if (usedbReq.vgVersion < vgVersion) { usedbRsp.pVgroupInfos = taosArrayInit(10, sizeof(SVgroupInfo)); if (usedbRsp.pVgroupInfos == NULL) { diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 73583058f1fd599dba0608a1eff99d6702cb99cc..3dff65866c996fa3d3a0cbd7ba2480357a938fa1 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -476,32 +476,36 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) { SSdb* pSdb = pMnode->pSdb; SVgObj* pVgroup = NULL; - SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan); - if (pPlan == NULL) { - terrno = TSDB_CODE_QRY_INVALID_INPUT; - return -1; - } + SQueryPlan* pPlan = NULL; + SSubplan* plan = NULL; + if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) { + pPlan = qStringToQueryPlan(pTopic->physicalPlan); + if (pPlan == NULL) { + terrno = TSDB_CODE_QRY_INVALID_INPUT; + return -1; + } - ASSERT(pSub->vgNum == -1); + ASSERT(pSub->vgNum == -1); - pSub->vgNum = 0; + pSub->vgNum = 0; - int32_t levelNum = LIST_LENGTH(pPlan->pSubplans); - if (levelNum != 1) { - qDestroyQueryPlan(pPlan); - terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC; - return -1; - } + int32_t levelNum = LIST_LENGTH(pPlan->pSubplans); + if (levelNum != 1) { + qDestroyQueryPlan(pPlan); + terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC; + return -1; + } - SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0); + SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0); - int32_t opNum = LIST_LENGTH(inner->pNodeList); - if (opNum != 1) { - qDestroyQueryPlan(pPlan); - terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC; - return -1; + int32_t opNum = LIST_LENGTH(inner->pNodeList); + if (opNum != 1) { + qDestroyQueryPlan(pPlan); + terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC; + return -1; + } + plan = nodesListGetNode(inner->pNodeList, 0); } - SSubplan* plan = nodesListGetNode(inner->pNodeList, 0); int64_t unexistKey = -1; SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t)); @@ -519,38 +523,35 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib } pSub->vgNum++; - plan->execNode.nodeId = pVgroup->vgId; - plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup); SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp)); - pVgEp->epSet = plan->execNode.epSet; - pVgEp->vgId = plan->execNode.nodeId; - -#if 0 - SMqConsumerEp consumerEp = {0}; - consumerEp.status = 0; - consumerEp.consumerId = -1; - consumerEp.epSet = plan->execNode.epSet; - consumerEp.vgId = plan->execNode.nodeId; -#endif + pVgEp->epSet = mndGetVgroupEpset(pMnode, pVgroup); + pVgEp->vgId = pVgroup->vgId; + taosArrayPush(pEpInSub->vgs, &pVgEp); mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId); - int32_t msgLen; - if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) { - sdbRelease(pSdb, pVgroup); - qDestroyQueryPlan(pPlan); - terrno = TSDB_CODE_QRY_INVALID_INPUT; - return -1; + if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) { + int32_t msgLen; + + plan->execNode.epSet = pVgEp->epSet; + plan->execNode.nodeId = pVgEp->vgId; + + if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) { + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + terrno = TSDB_CODE_QRY_INVALID_INPUT; + return -1; + } + } else { + pVgEp->qmsg = strdup(""); } - taosArrayPush(pEpInSub->vgs, &pVgEp); ASSERT(taosHashGetSize(pSub->consumerHash) == 1); /*taosArrayPush(pSub->unassignedVg, &consumerEp);*/ } - ASSERT(pEpInSub->vgs->size > 0); pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t)); ASSERT(pEpInSub->vgs->size > 0); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index f304e3153ded7f26c586bffcd7f2f249480662aa..6332ff86620e689b373818b19dd972cc87fee8d4 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -87,7 +87,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { SDB_SET_INT32(pRaw, dataPos, pStb->version, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER) SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER) - SDB_SET_INT32(pRaw, dataPos, pStb->aggregationMethod, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER) @@ -175,7 +174,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { int32_t xFilesFactor = 0; SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER) pStb->xFilesFactor = xFilesFactor / 10000.0f; - SDB_GET_INT32(pRaw, dataPos, &pStb->aggregationMethod, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER) SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER) @@ -404,7 +402,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt req.name = (char *)tNameGetTableName(&name); req.ttl = 0; req.keep = 0; - req.rollup = pStb->aggregationMethod > -1 ? 1 : 0; + req.rollup = pStb->pAst1 > 0 ? 1 : 0; req.type = TD_SUPER_TABLE; req.stbCfg.suid = pStb->uid; req.stbCfg.nCols = pStb->numOfColumns; @@ -433,29 +431,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt pRSmaParam->xFilesFactor = pStb->xFilesFactor; pRSmaParam->delay = pStb->delay; - pRSmaParam->nFuncIds = 1; // only 1 aggregation method supported currently - pRSmaParam->pFuncIds = (func_id_t *)taosMemoryCalloc(pRSmaParam->nFuncIds, sizeof(func_id_t)); - if (pRSmaParam->pFuncIds == NULL) { - taosMemoryFreeClear(req.stbCfg.pRSmaParam); - taosMemoryFreeClear(req.stbCfg.pSchema); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - for (int32_t f = 0; f < pRSmaParam->nFuncIds; ++f) { - *(pRSmaParam->pFuncIds + f) = pStb->aggregationMethod; - } if (pStb->ast1Len > 0) { if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) { - taosMemoryFreeClear(pRSmaParam->pFuncIds); taosMemoryFreeClear(req.stbCfg.pRSmaParam); taosMemoryFreeClear(req.stbCfg.pSchema); return NULL; } } if (pStb->ast2Len > 0) { - int32_t qmsgLen2 = 0; if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) { - taosMemoryFreeClear(pRSmaParam->pFuncIds); taosMemoryFreeClear(pRSmaParam->qmsg1); taosMemoryFreeClear(req.stbCfg.pRSmaParam); taosMemoryFreeClear(req.stbCfg.pSchema); @@ -470,7 +454,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt SMsgHead *pHead = taosMemoryMalloc(contLen); if (pHead == NULL) { if (pRSmaParam) { - taosMemoryFreeClear(pRSmaParam->pFuncIds); taosMemoryFreeClear(pRSmaParam->qmsg1); taosMemoryFreeClear(pRSmaParam->qmsg2); taosMemoryFreeClear(pRSmaParam); @@ -488,7 +471,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt *pContLen = contLen; if (pRSmaParam) { - taosMemoryFreeClear(pRSmaParam->pFuncIds); taosMemoryFreeClear(pRSmaParam->qmsg1); taosMemoryFreeClear(pRSmaParam->qmsg2); taosMemoryFreeClear(pRSmaParam); @@ -706,7 +688,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre stbObj.version = 1; stbObj.nextColId = 1; stbObj.xFilesFactor = pCreate->xFilesFactor; - stbObj.aggregationMethod = pCreate->aggregationMethod; stbObj.delay = pCreate->delay; stbObj.ttl = pCreate->ttl; stbObj.numOfColumns = pCreate->numOfColumns; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 2516c438603915d947279d3cbf758cfd1df1b20d..7c4e51298ffa49347c8fb832580da480f52298cb 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -282,10 +282,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq topicObj.version = 1; topicObj.sql = strdup(pCreate->sql); topicObj.sqlLen = strlen(pCreate->sql) + 1; - topicObj.ast = strdup(pCreate->ast); - topicObj.astLen = strlen(pCreate->ast) + 1; if (pCreate->ast && pCreate->ast[0]) { + topicObj.ast = strdup(pCreate->ast); + topicObj.astLen = strlen(pCreate->ast) + 1; topicObj.subType = TOPIC_SUB_TYPE__TABLE; topicObj.withTbName = 0; topicObj.withSchema = 0; @@ -314,6 +314,9 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq return -1; } } else { + topicObj.ast = strdup(""); + topicObj.astLen = 1; + topicObj.physicalPlan = strdup(""); topicObj.subType = TOPIC_SUB_TYPE__DB; topicObj.withTbName = 1; topicObj.withSchema = 1; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 9e9a8b56c9fc61aa31599921a0fb859276eb3941..6e221fb3dfb7746c0dc5473d08d43db77a91ed39 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -193,9 +193,9 @@ TRANS_ENCODE_OVER: static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_OUT_OF_MEMORY; - SSdbRow * pRow = NULL; - STrans * pTrans = NULL; - char * pData = NULL; + SSdbRow *pRow = NULL; + STrans *pTrans = NULL; + char *pData = NULL; int32_t dataLen = 0; int8_t sver = 0; int32_t redoLogNum = 0; @@ -456,7 +456,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) { } static STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) { - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &transId); if (pTrans == NULL) { terrno = TSDB_CODE_MND_TRANS_NOT_EXIST; @@ -574,6 +574,11 @@ void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen) { pTrans->rpcRspLen = contLen; } +void mndTransSetCb(STrans *pTrans, TransCbFp fp, void *param) { + pTrans->transCbFp = fp; + pTrans->transCbParam = param; +} + void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb) { pTrans->dbUid = pDb->uid; memcpy(pTrans->dbname, pDb->name, TSDB_DB_FNAME_LEN); @@ -626,7 +631,7 @@ static int32_t mndCheckTransCanBeStartedInParallel(SMnode *pMnode, STrans *pNewT if (mndIsBasicTrans(pNewTrans)) return 0; STrans *pTrans = NULL; - void * pIter = NULL; + void *pIter = NULL; int32_t code = 0; while (1) { @@ -707,6 +712,8 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) { pNew->rpcRefId = pTrans->rpcRefId; pNew->rpcRsp = pTrans->rpcRsp; pNew->rpcRspLen = pTrans->rpcRspLen; + pNew->transCbFp = pTrans->transCbFp; + pNew->transCbParam = pTrans->transCbParam; pTrans->rpcRsp = NULL; pTrans->rpcRspLen = 0; @@ -830,7 +837,7 @@ HANDLE_ACTION_RSP_OVER: } static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) { - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; int32_t arraySize = taosArrayGetSize(pArray); if (arraySize == 0) return 0; @@ -1117,6 +1124,11 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) { } mDebug("trans:%d, finished, code:0x%04x, failedTimes:%d", pTrans->id, pTrans->code, pTrans->failedTimes); + + if (pTrans->transCbFp != NULL) { + (*pTrans->transCbFp)(pMnode, pTrans->transCbParam); + } + return continueExec; } @@ -1205,11 +1217,11 @@ static int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) { } static int32_t mndProcessKillTransReq(SNodeMsg *pReq) { - SMnode * pMnode = pReq->pNode; + SMnode *pMnode = pReq->pNode; SKillTransReq killReq = {0}; int32_t code = -1; - SUserObj * pUser = NULL; - STrans * pTrans = NULL; + SUserObj *pUser = NULL; + STrans *pTrans = NULL; if (tDeserializeSKillTransReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &killReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; @@ -1249,7 +1261,7 @@ KILL_OVER: void mndTransPullup(SMnode *pMnode) { STrans *pTrans = NULL; - void * pIter = NULL; + void *pIter = NULL; while (1) { pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans); @@ -1264,11 +1276,11 @@ void mndTransPullup(SMnode *pMnode) { static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; STrans *pTrans = NULL; int32_t cols = 0; - char * pWrite; + char *pWrite; while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_TRANS, pShow->pIter, (void **)&pTrans); diff --git a/source/dnode/mnode/impl/test/db/db.cpp b/source/dnode/mnode/impl/test/db/db.cpp index 1fc1bec650a3dbc3638b33d4da9ec373c971985c..6e72ce89d3512a471b4038a836114866b6d6309d 100644 --- a/source/dnode/mnode/impl/test/db/db.cpp +++ b/source/dnode/mnode/impl/test/db/db.cpp @@ -89,7 +89,6 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { void* pReq = rpcMallocCont(contLen); tSerializeSAlterDbReq(pReq, contLen, &alterdbReq); - taosMsleep(1000); // Wait for the vnode to become the leader SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen); ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); diff --git a/source/dnode/mnode/impl/test/sma/sma.cpp b/source/dnode/mnode/impl/test/sma/sma.cpp index 96c0c8e9530b5196a9c5d60db6e278f6e95914a8..0d41d5de203f36453c1ff168ae226f142ee3c23e 100644 --- a/source/dnode/mnode/impl/test/sma/sma.cpp +++ b/source/dnode/mnode/impl/test/sma/sma.cpp @@ -258,7 +258,6 @@ TEST_F(MndTestSma, 02_Create_Show_Meta_Drop_Restart_BSma) { pReq = BuildCreateDbReq(dbname, &contLen); pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_EQ(pRsp->code, 0); - taosMsleep(1000); // Wait for the vnode to become the leader } { diff --git a/source/dnode/mnode/impl/test/stb/stb.cpp b/source/dnode/mnode/impl/test/stb/stb.cpp index 0c54091aa9b9111947bf0342102566cd8e692ab5..9270d38e1148f925bfb6a7d754041d0f679ea05c 100644 --- a/source/dnode/mnode/impl/test/stb/stb.cpp +++ b/source/dnode/mnode/impl/test/stb/stb.cpp @@ -304,7 +304,6 @@ TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { @@ -439,7 +438,6 @@ TEST_F(MndTestStb, 02_Alter_Stb_AddTag) { SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { @@ -499,7 +497,6 @@ TEST_F(MndTestStb, 03_Alter_Stb_DropTag) { void* pReq = BuildCreateDbReq(dbname, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { @@ -541,7 +538,6 @@ TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) { void* pReq = BuildCreateDbReq(dbname, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { @@ -606,7 +602,6 @@ TEST_F(MndTestStb, 05_Alter_Stb_AlterTagBytes) { void* pReq = BuildCreateDbReq(dbname, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { @@ -660,7 +655,6 @@ TEST_F(MndTestStb, 06_Alter_Stb_AddColumn) { SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { @@ -721,7 +715,6 @@ TEST_F(MndTestStb, 07_Alter_Stb_DropColumn) { void* pReq = BuildCreateDbReq(dbname, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { @@ -782,7 +775,6 @@ TEST_F(MndTestStb, 08_Alter_Stb_AlterTagBytes) { void* pReq = BuildCreateDbReq(dbname, &contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); ASSERT_EQ(pRsp->code, 0); - taosMsleep(2000); // Wait for the vnode to become the leader } { diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index f4975c183e26da5f7a198451e1df134fea6e657b..833cdfdf002d5d95895283c0cfab8e2158aa39d1 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -61,6 +61,9 @@ int32_t vnodeSync(SVnode *pVnode); int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName); +int32_t vnodeStart(SVnode *pVnode); +void vnodeStop(SVnode *pVnode); + int64_t vnodeGetSyncHandle(SVnode *pVnode); void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot); @@ -77,16 +80,15 @@ char *metaTbCursorNext(SMTbCursor *pTbCur); // tsdb typedef struct STsdb STsdb; -typedef struct STsdbQueryCond STsdbQueryCond; 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, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, +tsdbReaderT *tsdbQueryTables(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, uint64_t taskId); -tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, +tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, void *pMemRef); int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo); bool isTsdbCacheLastRow(tsdbReaderT *pReader); @@ -98,6 +100,7 @@ bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle); void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo); int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg **pBlockStatis); 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); @@ -157,25 +160,11 @@ struct SVnodeCfg { int8_t hashMethod; }; -struct STsdbQueryCond { - STimeWindow twindow; - int32_t order; // desc|asc order to iterate the data block - int32_t numOfCols; - SColumnInfo *colList; - bool loadExternalRows; // load external rows or not - int32_t type; // data block load type: -}; - typedef struct { TSKEY lastKey; uint64_t uid; } STableKeyInfo; -// sync integration -void vnodeSyncSetQ(SVnode *pVnode, void *qHandle); -void vnodeSyncSetRpc(SVnode *pVnode, void *rpcHandle); -int32_t vnodeSyncStart(SVnode *pVnode); - #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index fb875a46e0a0d0f785b5b2df0977398e59573604..764792924624b6d2ba2fdc0153406506d770417a 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -51,7 +51,7 @@ static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64() #define META_CHILD_TABLE TD_CHILD_TABLE #define META_NORMAL_TABLE TD_NORMAL_TABLE -int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg); +int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle); int metaDropTable(SMeta* pMeta, tb_uid_t uid); int metaCommit(SMeta* pMeta); int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg); @@ -74,7 +74,7 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur); // SMetaDB int metaOpenDB(SMeta* pMeta); void metaCloseDB(SMeta* pMeta); -int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg); +int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle); int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid); int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg); int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index a84776abfd76df66348c2a9d1885a403b2352076..8af3068b8d5846de4158af32001f70b2d8734381 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -56,8 +56,6 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); void tsdbCleanupReadHandle(tsdbReaderT queryHandle); -int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); - typedef enum { TSDB_FILE_HEAD = 0, // .head TSDB_FILE_DATA, // .data diff --git a/source/dnode/vnode/src/inc/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h new file mode 100644 index 0000000000000000000000000000000000000000..e20d2989b9419c1af2d16e3270029ad0d28639f4 --- /dev/null +++ b/source/dnode/vnode/src/inc/tsdbSma.h @@ -0,0 +1,64 @@ +/* + * 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_VNODE_TSDB_SMA_H_ +#define _TD_VNODE_TSDB_SMA_H_ + +#include "os.h" +#include "thash.h" +#include "tmsg.h" + +#ifdef __cplusplus +extern "C" { +#endif + +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; +}; + +typedef struct { + tb_uid_t suid; + SArray *tbUids; + SHashObj *uidHash; +} STbUidStore; + +static FORCE_INLINE int32_t tsdbUidStoreInit(STbUidStore **pStore) { + ASSERT(*pStore == NULL); + *pStore = taosMemoryCalloc(1, sizeof(STbUidStore)); + if (*pStore == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + 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 +} +#endif + +#endif /*_TD_VNODE_TSDB_SMA_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 0027424829e8f8a42653c06ec3471c6d6f75ee95..0f354401bf6d6b84953c04bae64b9185a28da943 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -103,6 +103,8 @@ struct SVnode { #define TD_VID(PVNODE) (PVNODE)->config.vgId +typedef struct STbDdlH STbDdlH; + // sma void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data); @@ -116,6 +118,8 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data); #include "vnodeSync.h" +#include "tsdbSma.h" + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index 8389286596007c779f2b225f896eec9dee660368..d61d3346a2c31840d2822a82b36722d9729a3f28 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -250,7 +250,7 @@ void metaCloseDB(SMeta *pMeta) { } } -int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { +int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { tb_uid_t uid; SMetaDB *pMetaDb; void *pKey; @@ -349,6 +349,12 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { if (ret < 0) { return -1; } + // child table handle for rsma + if (pHandle && pHandle->fp) { + if (((*pHandle->fp)(pHandle->ahandle, &pHandle->result, &ctbIdxKey.suid, &uid)) < 0) { + return -1; + }; + } } else if (pTbCfg->type == META_NORMAL_TABLE) { pKey = &uid; kLen = sizeof(uid); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 7f06ba88553b0e211db7f79f0e09d87dc2958277..7f8ec3a6564d3148dc8c1d120a4065d9fdff9bc3 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -15,7 +15,7 @@ #include "vnodeInt.h" -int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { +int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) { // Validate the tbOptions // if (metaValidateTbCfg(pMeta, pTbCfg) < 0) { // // TODO: handle error @@ -24,7 +24,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { // TODO: add atomicity - if (metaSaveTableToDB(pMeta, pTbCfg) < 0) { + if (metaSaveTableToDB(pMeta, pTbCfg, pHandle) < 0) { // TODO: handle error return -1; } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 434c5bc5bb997973f544c7d74eb29b35b6594873..8cabada5113c330161e96a5f5fe008b8656bcda7 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -197,10 +197,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) } memcpy(data, msg, msgLen); - if (msgType == TDMT_VND_SUBMIT) { - if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) { - return -1; - } + // make sure msgType == TDMT_VND_SUBMIT + if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) { + return -1; } SRpcMsg req = { @@ -411,8 +410,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { SMqDataBlkRsp rsp = {0}; rsp.reqOffset = pReq->currentOffset; + rsp.withSchema = pExec->withSchema; rsp.blockData = taosArrayInit(0, sizeof(void*)); rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t)); + rsp.blockSchema = taosArrayInit(0, sizeof(void*)); while (1) { consumerEpoch = atomic_load_32(&pExec->epoch); @@ -512,6 +513,12 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { ASSERT(actualLen <= dataStrLen); taosArrayPush(rsp.blockDataLen, &actualLen); taosArrayPush(rsp.blockData, &buf); + + if (pExec->withSchema) { + SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper); + taosArrayPush(rsp.blockSchema, &pSW); + } + rsp.blockNum++; } // db subscribe @@ -540,6 +547,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { ASSERT(actualLen <= dataStrLen); taosArrayPush(rsp.blockDataLen, &actualLen); taosArrayPush(rsp.blockData, &buf); + + SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper); + taosArrayPush(rsp.blockSchema, &pSW); + rsp.blockNum++; } } else { @@ -586,6 +597,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { // TODO destroy taosArrayDestroy(rsp.blockData); taosArrayDestroy(rsp.blockDataLen); + taosArrayDestroyP(rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper); + return 0; } @@ -827,12 +840,16 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { pExec->pWalReader = walOpenReadHandle(pTq->pVnode->pWal); for (int32_t i = 0; i < 5; i++) { pExec->pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); - SReadHandle handle = { - .reader = pExec->pExecReader[i], - .meta = pTq->pVnode->pMeta, - }; - pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle); - ASSERT(pExec->task[i]); + if (pExec->subType == TOPIC_SUB_TYPE__TABLE) { + SReadHandle handle = { + .reader = pExec->pExecReader[i], + .meta = pTq->pVnode->pMeta, + }; + pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle); + ASSERT(pExec->task[i]); + } else { + pExec->task[i] = NULL; + } } taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec)); return 0; diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index eb45577e0a491ab4ebeb02752f5c07edc3d3bcde..aeb9f27eab4e7fd4b0d7c307eed88d73127e7c5d 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -33,24 +33,24 @@ STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) { int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t ver) { pReadHandle->pMsg = pMsg; - pMsg->length = htonl(pMsg->length); - pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); + // pMsg->length = htonl(pMsg->length); + // pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); // iterate and convert - if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1; + if (tInitSubmitMsgIterEx(pMsg, &pReadHandle->msgIter) < 0) return -1; while (true) { - if (tGetSubmitMsgNext(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1; + if (tGetSubmitMsgNextEx(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1; if (pReadHandle->pBlock == NULL) break; - pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid); - pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid); - pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion); - pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen); - pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen); - pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows); + // pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid); + // pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid); + // pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion); + // pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen); + // pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen); + // pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows); } - if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1; + if (tInitSubmitMsgIterEx(pMsg, &pReadHandle->msgIter) < 0) return -1; pReadHandle->ver = ver; memset(&pReadHandle->blkIter, 0, sizeof(SSubmitBlkIter)); return 0; @@ -58,15 +58,17 @@ int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t bool tqNextDataBlock(STqReadHandle* pHandle) { while (1) { - if (tGetSubmitMsgNext(&pHandle->msgIter, &pHandle->pBlock) < 0) { + if (tGetSubmitMsgNextEx(&pHandle->msgIter, &pHandle->pBlock) < 0) { return false; } if (pHandle->pBlock == NULL) return false; /*pHandle->pBlock->uid = htobe64(pHandle->pBlock->uid);*/ /*if (pHandle->tbUid == pHandle->pBlock->uid) {*/ - ASSERT(pHandle->tbIdHash); - void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->pBlock->uid, sizeof(int64_t)); + if (pHandle->tbIdHash == NULL) { + return true; + } + void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->msgIter.uid, sizeof(int64_t)); if (ret != NULL) { /*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/ /*pHandle->pBlock->tid = htonl(pHandle->pBlock->tid);*/ @@ -88,45 +90,36 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p // TODO set to real sversion int32_t sversion = 0; if (pHandle->sver != sversion) { - pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->pBlock->uid, sversion); - + pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion); +#if 0 tb_uid_t quid; - STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->pBlock->uid); + STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->msgIter.uid); if (pTbCfg->type == META_CHILD_TABLE) { quid = pTbCfg->ctbCfg.suid; } else { - quid = pHandle->pBlock->uid; + quid = pHandle->msgIter.uid; } pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, quid, sversion, true); +#endif + pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.suid, sversion, true); pHandle->sver = sversion; } STSchema* pTschema = pHandle->pSchema; SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper; - *pNumOfRows = pHandle->pBlock->numOfRows; + *pNumOfRows = pHandle->msgIter.numOfRows; int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList); - if (colNumNeed > pSchemaWrapper->nCols) { - colNumNeed = pSchemaWrapper->nCols; - } - - *ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData)); - if (*ppCols == NULL) { - return -1; - } + if (colNumNeed == 0) { + *ppCols = taosArrayInit(pSchemaWrapper->nCols, sizeof(SColumnInfoData)); + if (*ppCols == NULL) { + return -1; + } - int32_t colMeta = 0; - int32_t colNeed = 0; - while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) { - SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta]; - col_id_t colIdSchema = pColSchema->colId; - col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pHandle->pColIdList, colNeed); - if (colIdSchema < colIdNeed) { - colMeta++; - } else if (colIdSchema > colIdNeed) { - colNeed++; - } else { + int32_t colMeta = 0; + while (colMeta < pSchemaWrapper->nCols) { + SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta]; SColumnInfoData colInfo = {0}; colInfo.info.bytes = pColSchema->bytes; colInfo.info.colId = pColSchema->colId; @@ -137,7 +130,40 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p } taosArrayPush(*ppCols, &colInfo); colMeta++; - colNeed++; + } + } else { + if (colNumNeed > pSchemaWrapper->nCols) { + colNumNeed = pSchemaWrapper->nCols; + } + + *ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData)); + if (*ppCols == NULL) { + return -1; + } + + int32_t colMeta = 0; + int32_t colNeed = 0; + while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) { + SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta]; + col_id_t colIdSchema = pColSchema->colId; + col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pHandle->pColIdList, colNeed); + if (colIdSchema < colIdNeed) { + colMeta++; + } else if (colIdSchema > colIdNeed) { + colNeed++; + } else { + SColumnInfoData colInfo = {0}; + colInfo.info.bytes = pColSchema->bytes; + colInfo.info.colId = pColSchema->colId; + colInfo.info.type = pColSchema->type; + + if (colInfoDataEnsureCapacity(&colInfo, 0, *pNumOfRows) < 0) { + goto FAIL; + } + taosArrayPush(*ppCols, &colInfo); + colMeta++; + colNeed++; + } } } @@ -151,8 +177,8 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p tdSTSRowIterInit(&iter, pTschema); STSRow* row; int32_t curRow = 0; - tInitSubmitBlkIter(pHandle->pBlock, &pHandle->blkIter); - while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) { + tInitSubmitBlkIterEx(&pHandle->msgIter, pHandle->pBlock, &pHandle->blkIter); + while ((row = tGetSubmitBlkNextEx(&pHandle->blkIter)) != NULL) { tdSTSRowIterReset(&iter, row); // get all wanted col of that block for (int32_t i = 0; i < colActual; i++) { diff --git a/source/dnode/vnode/src/tsdb/tsdbMain.c b/source/dnode/vnode/src/tsdb/tsdbMain.c index 2753579e9e887919212100d85fc5ef5c3f51e137..8691920c8ff257788501a4889f492e1c4a8e399f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMain.c +++ b/source/dnode/vnode/src/tsdb/tsdbMain.c @@ -81,8 +81,8 @@ static STsdb *tsdbNew(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg static void tsdbFree(STsdb *pTsdb) { if (pTsdb) { - // tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb)); - // tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb)); + tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb)); + tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb)); tsdbFreeFS(pTsdb->fs); taosMemoryFreeClear(pTsdb->path); taosMemoryFree(pTsdb); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 098b86975b7869aa59b61abf8129ffcbe7581b35..f01629cef9ad99f74a828677ab7fcf962afa8193 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -254,7 +254,7 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S assert(info.lastKey >= pTsdbReadHandle->window.skey && info.lastKey <= pTsdbReadHandle->window.ekey); } else { - assert(info.lastKey >= pTsdbReadHandle->window.ekey && info.lastKey <= pTsdbReadHandle->window.skey); + info.lastKey = pTsdbReadHandle->window.skey; } taosArrayPush(pTableCheckInfo, &info); @@ -317,7 +317,7 @@ static int64_t getEarliestValidTimestamp(STsdb* pTsdb) { return now - (tsTickPerDay[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick } -static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, STsdbQueryCond* pCond) { +static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, SQueryTableDataCond* pCond) { pTsdbReadHandle->window = pCond->twindow; bool updateTs = false; @@ -343,7 +343,7 @@ static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, STsdbQueryCond* } } -static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, uint64_t qId, uint64_t taskId) { +static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, SQueryTableDataCond* pCond, uint64_t qId, uint64_t taskId) { STsdbReadHandle* pReadHandle = taosMemoryCalloc(1, sizeof(STsdbReadHandle)); if (pReadHandle == NULL) { goto _end; @@ -422,7 +422,7 @@ _end: return NULL; } -tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, +tsdbReaderT* tsdbQueryTables(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(tsdb, pCond, qId, taskId); if (pTsdbReadHandle == NULL) { @@ -448,7 +448,7 @@ tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo return (tsdbReaderT)pTsdbReadHandle; } -void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) { +void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond* pCond) { STsdbReadHandle* pTsdbReadHandle = queryHandle; if (emptyQueryTimewindow(pTsdbReadHandle)) { @@ -460,9 +460,9 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) { return; } - pTsdbReadHandle->order = pCond->order; - pTsdbReadHandle->window = pCond->twindow; - pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; + pTsdbReadHandle->order = pCond->order; + pTsdbReadHandle->window = pCond->twindow; + pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; pTsdbReadHandle->cur.fid = -1; pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; pTsdbReadHandle->checkFiles = true; @@ -485,7 +485,7 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) { resetCheckInfo(pTsdbReadHandle); } -void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond* pCond, STableGroupInfo* groupList) { +void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, SQueryTableDataCond* pCond, STableGroupInfo* groupList) { STsdbReadHandle* pTsdbReadHandle = queryHandle; pTsdbReadHandle->order = pCond->order; @@ -526,7 +526,7 @@ void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond* pC // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); } -tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, +tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { pCond->twindow = updateLastrowForEachGroup(groupList); @@ -555,7 +555,7 @@ tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo } #if 0 -tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, STsdbMemTable* pMemRef) { +tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, STsdbMemTable* pMemRef) { STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, pMemRef); if (pTsdbReadHandle == NULL) { return NULL; @@ -618,7 +618,7 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr return pNew; } -tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, +tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList); @@ -1185,10 +1185,11 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* tsdbDebug("%p no data in mem, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); } - if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || - (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) { - if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) || - (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey))) { + bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + + if ((ascScan && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || (!ascScan && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) { + + if ((ascScan && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) || (!ascScan && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey))) { // do not load file block into buffer int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; @@ -1225,8 +1226,7 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* assert(pTsdbReadHandle->outputCapacity >= binfo.rows); int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &binfo); - if ((cur->pos == 0 && endPos == binfo.rows - 1 && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || - (cur->pos == (binfo.rows - 1) && endPos == 0 && (!ASCENDING_TRAVERSE(pTsdbReadHandle->order)))) { + if ((cur->pos == 0 && endPos == binfo.rows - 1 && ascScan) || (cur->pos == (binfo.rows - 1) && endPos == 0 && (!ascScan))) { pTsdbReadHandle->realNumOfRows = binfo.rows; cur->rows = binfo.rows; @@ -1234,7 +1234,7 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* cur->mixBlock = false; cur->blockCompleted = true; - if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { + if (ascScan) { cur->lastKey = binfo.window.ekey + 1; cur->pos = binfo.rows; } else { @@ -1382,8 +1382,6 @@ static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) { static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, int32_t start, int32_t end) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; TSKEY* tsArray = pCols->cols[0].pData; @@ -1394,6 +1392,11 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t return numOfRows; } + bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + int32_t trueStart = ascScan ? start : end; + int32_t trueEnd = ascScan ? end : start; + int32_t step = ascScan ? 1 : -1; + int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); // data in buffer has greater timestamp, copy data in file block @@ -1411,7 +1414,7 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance // memmove(pData, (char*)src->pData + bytes * start, bytes * num); int32_t rowIndex = numOfRows; - for (int32_t k = start; k <= end; ++k, ++rowIndex) { + for (int32_t k = trueStart; ((ascScan && k <= trueEnd) || (!ascScan && k >= trueEnd)); k += step, ++rowIndex) { SCellVal sVal = {0}; if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { TASSERT(0); @@ -1427,7 +1430,7 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t int32_t rowIndex = numOfRows; // todo refactor, only copy one-by-one - for (int32_t k = start; k < num + start; ++k, ++rowIndex) { + for (int32_t k = trueStart; ((ascScan && k <= trueEnd) || (!ascScan && k >= trueEnd)); k += step, ++rowIndex) { SCellVal sVal = {0}; if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { TASSERT(0); @@ -1444,26 +1447,19 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t j++; i++; } else { // pColInfo->info.colId < src->colId, it is a NULL data - int32_t rowIndex = numOfRows; - for (int32_t k = start; k < num + start; ++k, ++rowIndex) { // TODO opt performance - colDataAppend(pColInfo, rowIndex, NULL, true); - } + colDataAppendNNULL(pColInfo, numOfRows, num); i++; } } while (i < requiredNumOfCols) { // the remain columns are all null data SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - int32_t rowIndex = numOfRows; - - for (int32_t k = start; k < num + start; ++k, ++rowIndex) { - colDataAppend(pColInfo, rowIndex, NULL, true); // TODO add a fast version to set a number of consecutive NULL value. - } + colDataAppendNNULL(pColInfo, numOfRows, num); i++; } - pTsdbReadHandle->cur.win.ekey = tsArray[end]; - pTsdbReadHandle->cur.lastKey = tsArray[end] + step; + pTsdbReadHandle->cur.win.ekey = tsArray[trueEnd]; + pTsdbReadHandle->cur.lastKey = tsArray[trueEnd] + step; return numOfRows + num; } @@ -2966,7 +2962,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // } // // // load the previous row -// STsdbQueryCond cond = {.numOfCols = numOfCols, .loadExternalRows = false, .type = BLOCK_LOAD_OFFSET_SEQ_ORDER}; +// SQueryTableDataCond cond = {.numOfCols = numOfCols, .loadExternalRows = false, .type = BLOCK_LOAD_OFFSET_SEQ_ORDER}; // if (type == TSDB_PREV_ROW) { // cond.order = TSDB_ORDER_DESC; // cond.twindow = (STimeWindow){pTsdbReadHandle->window.skey, INT64_MIN}; @@ -3330,21 +3326,7 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) { return NULL; } - // todo refactor int32_t numOfRows = doCopyRowsFromFileBlock(pHandle, pHandle->outputCapacity, 0, 0, pBlock->numOfRows - 1); - - // if the buffer is not full in case of descending order query, move the data in the front of the buffer - if (!ASCENDING_TRAVERSE(pHandle->order) && numOfRows < pHandle->outputCapacity) { - int32_t emptySize = pHandle->outputCapacity - numOfRows; - int32_t reqNumOfCols = (int32_t)taosArrayGetSize(pHandle->pColumns); - - for (int32_t i = 0; i < reqNumOfCols; ++i) { - SColumnInfoData* pColInfo = taosArrayGet(pHandle->pColumns, i); - memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, - numOfRows * pColInfo->info.bytes); - } - } - return pHandle->pColumns; } } @@ -3636,6 +3618,8 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; goto _error; + } else { + tsdbDebug("%p succeed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); } if (pTbCfg->type != META_SUPER_TABLE) { diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index bc9fe46c0f34f1b9b293af212c221064752b7602..806512f07d458a0f9cfd1e603678d671d277d2fa 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -33,6 +33,8 @@ static const char *TSDB_SMA_DNAME[] = { #define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test #define SMA_TEST_INDEX_UID 2000000001 // TODO: just for test + +typedef struct SRSmaInfo SRSmaInfo; typedef enum { SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f200.tsma SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma @@ -46,6 +48,7 @@ typedef struct SPoolMem { struct SSmaEnv { TdThreadRwlock lock; + int8_t type; TXN txn; SPoolMem *pPool; SDiskID did; @@ -55,6 +58,7 @@ struct SSmaEnv { }; #define SMA_ENV_LOCK(env) ((env)->lock) +#define SMA_ENV_TYPE(env) ((env)->type) #define SMA_ENV_DID(env) ((env)->did) #define SMA_ENV_ENV(env) ((env)->dbEnv) #define SMA_ENV_PATH(env) ((env)->path) @@ -91,16 +95,45 @@ typedef struct { * - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open, * without information about its previous state. * - TSDB_SMA_STAT_DROPPED: 1)sma dropped + * N.B. only applicable to tsma */ int8_t state; // ETsdbSmaStat SHashObj *expiredWindows; // key: skey of time window, value: N/A 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 +}; + struct SSmaStat { - SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem + union { + SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem for tsma + SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo; + }; T_REF_DECLARE() }; +#define SMA_STAT_ITEMS(s) ((s)->smaStatItems) +#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash) + +static FORCE_INLINE void tsdbFreeTaskHandle(qTaskInfo_t *taskHandle) { + // Note: free/kill may in RC + qTaskInfo_t otaskHandle = atomic_load_ptr(taskHandle); + if (otaskHandle && atomic_val_compare_exchange_ptr(taskHandle, otaskHandle, NULL)) { + qDestroyTask(otaskHandle); + } +} + +static FORCE_INLINE void *tsdbFreeRSmaInfo(SRSmaInfo *pInfo) { + for (int32_t i = 0; i < RSMA_MAX_LEVEL; ++i) { + if (pInfo->taskInfo[i]) { + tsdbFreeTaskHandle(pInfo->taskInfo[i]); + } + } + return NULL; +} // declaration of static functions @@ -108,11 +141,11 @@ struct SSmaStat { static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version); static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey, int64_t version); -static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat); +static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType); static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem); -static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat); -static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did); -static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv); +static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType); +static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did); +static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv); static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey); static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat); static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat); @@ -139,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 tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids); // mgmt interface static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid); @@ -229,7 +263,7 @@ static void *poolMalloc(void *arg, size_t size) { SPoolMem *pMem; pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size); - if (pMem == NULL) { + if (!pMem) { assert(0); } @@ -317,15 +351,17 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) { snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TSDB_SMA_DNAME[smaType]); } -static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) { +static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did) { SSmaEnv *pEnv = NULL; pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv)); - if (pEnv == NULL) { + if (!pEnv) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + SMA_ENV_TYPE(pEnv) = smaType; + int code = taosThreadRwlockInit(&(pEnv->lock), NULL); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -334,15 +370,15 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) } ASSERT(path && (strlen(path) > 0)); - pEnv->path = strdup(path); - if (pEnv->path == NULL) { + SMA_ENV_PATH(pEnv) = strdup(path); + if (!SMA_ENV_PATH(pEnv)) { tsdbFreeSmaEnv(pEnv); return NULL; } - pEnv->did = did; + SMA_ENV_DID(pEnv) = did; - if (tsdbInitSmaStat(&pEnv->pStat) != TSDB_CODE_SUCCESS) { + if (tsdbInitSmaStat(&SMA_ENV_STAT(pEnv), smaType) != TSDB_CODE_SUCCESS) { tsdbFreeSmaEnv(pEnv); return NULL; } @@ -354,7 +390,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) return NULL; } - if ((pEnv->pPool = openPool()) == NULL) { + if (!(pEnv->pPool = openPool())) { tsdbFreeSmaEnv(pEnv); return NULL; } @@ -362,14 +398,14 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) return pEnv; } -static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv) { +static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv) { if (!pEnv) { terrno = TSDB_CODE_INVALID_PTR; return TSDB_CODE_FAILED; } - if (*pEnv == NULL) { - if ((*pEnv = tsdbNewSmaEnv(pTsdb, path, did)) == NULL) { + if (!(*pEnv)) { + if (!(*pEnv = tsdbNewSmaEnv(pTsdb, smaType, path, did))) { return TSDB_CODE_FAILED; } } @@ -385,7 +421,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaE */ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) { if (pSmaEnv) { - tsdbDestroySmaState(pSmaEnv->pStat); + tsdbDestroySmaState(pSmaEnv->pStat, SMA_ENV_TYPE(pSmaEnv)); taosMemoryFreeClear(pSmaEnv->pStat); taosMemoryFreeClear(pSmaEnv->path); taosThreadRwlockDestroy(&(pSmaEnv->lock)); @@ -401,7 +437,7 @@ void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv) { } static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) { - if (pStat == NULL) return 0; + if (!pStat) return 0; int ref = T_REF_INC(pStat); tsdbDebug("vgId:%d ref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref); @@ -409,17 +445,17 @@ static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) { } static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) { - if (pStat == NULL) return 0; + if (!pStat) return 0; int ref = T_REF_DEC(pStat); tsdbDebug("vgId:%d unref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref); return 0; } -static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) { +static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) { ASSERT(pSmaStat != NULL); - if (*pSmaStat != NULL) { // no lock + if (*pSmaStat) { // no lock return TSDB_CODE_SUCCESS; } @@ -428,19 +464,31 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) { * 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if * tsdbInitSmaStat invoked in other multithread environment later. */ - if (*pSmaStat == NULL) { + if (!(*pSmaStat)) { *pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat)); - if (*pSmaStat == NULL) { + if (!(*pSmaStat)) { terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } - (*pSmaStat)->smaStatItems = - taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + if (smaType == TSDB_SMA_TYPE_ROLLUP) { + SMA_STAT_INFO_HASH(*pSmaStat) = taosHashInit( + RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); - if ((*pSmaStat)->smaStatItems == NULL) { - taosMemoryFreeClear(*pSmaStat); - return TSDB_CODE_FAILED; + if (!SMA_STAT_INFO_HASH(*pSmaStat)) { + taosMemoryFreeClear(*pSmaStat); + return TSDB_CODE_FAILED; + } + } else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { + SMA_STAT_ITEMS(*pSmaStat) = + taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + + if (!SMA_STAT_ITEMS(*pSmaStat)) { + taosMemoryFreeClear(*pSmaStat); + return TSDB_CODE_FAILED; + } + } else { + ASSERT(0); } } return TSDB_CODE_SUCCESS; @@ -462,7 +510,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) { } static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) { - if (pSmaStatItem != NULL) { + if (pSmaStatItem) { tdDestroyTSma(pSmaStatItem->pSma); taosMemoryFreeClear(pSmaStatItem->pSma); taosHashCleanup(pSmaStatItem->expiredWindows); @@ -477,16 +525,28 @@ static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) { * @param pSmaStat * @return int32_t */ -int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) { +int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) { if (pSmaStat) { // TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready. - void *item = taosHashIterate(pSmaStat->smaStatItems, NULL); - while (item != NULL) { - SSmaStatItem *pItem = *(SSmaStatItem **)item; - tsdbFreeSmaStatItem(pItem); - item = taosHashIterate(pSmaStat->smaStatItems, item); + if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { + void *item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), NULL); + while (item) { + SSmaStatItem *pItem = *(SSmaStatItem **)item; + tsdbFreeSmaStatItem(pItem); + item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), item); + } + taosHashCleanup(SMA_STAT_ITEMS(pSmaStat)); + } else if (smaType == TSDB_SMA_TYPE_ROLLUP) { + void *infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), NULL); + while (infoHash) { + SRSmaInfo *pInfoHash = *(SRSmaInfo **)infoHash; + tsdbFreeRSmaInfo(pInfoHash); + infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), infoHash); + } + taosHashCleanup(SMA_STAT_INFO_HASH(pSmaStat)); + } else { + ASSERT(0); } - taosHashCleanup(pSmaStat->smaStatItems); } return TSDB_CODE_SUCCESS; } @@ -497,12 +557,12 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { // return if already init switch (smaType) { case TSDB_SMA_TYPE_TIME_RANGE: - if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))) != NULL) { + if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb)))) { return TSDB_CODE_SUCCESS; } break; case TSDB_SMA_TYPE_ROLLUP: - if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb))) != NULL) { + if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb)))) { return TSDB_CODE_SUCCESS; } break; @@ -515,7 +575,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { tsdbLockRepo(pTsdb); pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&REPO_TSMA_ENV(pTsdb)) : atomic_load_ptr(&REPO_RSMA_ENV(pTsdb)); - if (pEnv == NULL) { + if (!pEnv) { char rname[TSDB_FILENAME_LEN] = {0}; SDiskID did = {0}; @@ -531,7 +591,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { return TSDB_CODE_FAILED; } - if (tsdbInitSmaEnv(pTsdb, rname, did, &pEnv) != TSDB_CODE_SUCCESS) { + if (tsdbInitSmaEnv(pTsdb, smaType, rname, did, &pEnv) != TSDB_CODE_SUCCESS) { tsdbUnlockRepo(pTsdb); return TSDB_CODE_FAILED; } @@ -547,10 +607,10 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey, int64_t version) { SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid)); - if (pItem == NULL) { + if (!pItem) { // TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_OK); // TODO use the real state - if (pItem == NULL) { + if (!pItem) { // Response to stream computing: OOM // For query, if the indexUid not found, the TSDB should tell query module to query raw TS data. return TSDB_CODE_FAILED; @@ -558,7 +618,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t // cache smaMeta STSma *pSma = metaGetSmaInfoByIndex(REPO_META(pTsdb), indexUid, true); - if (pSma == NULL) { + if (!pSma) { terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META; taosHashCleanup(pItem->expiredWindows); taosMemoryFree(pItem); @@ -574,7 +634,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t taosMemoryFree(pItem); return TSDB_CODE_FAILED; } - } else if ((pItem = *(SSmaStatItem **)pItem) == NULL) { + } else if (!(pItem = *(SSmaStatItem **)pItem)) { terrno = TSDB_CODE_INVALID_PTR; return TSDB_CODE_FAILED; } @@ -618,9 +678,6 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers return TSDB_CODE_FAILED; } - if (tdScanAndConvertSubmitMsg(pMsg) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_FAILED; - } if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_TDB_INIT_FAILED; @@ -634,7 +691,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers SSmaStat *pStat = SMA_ENV_STAT(pEnv); SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv); - TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL); + TASSERT(pEnv && pStat && pItemsHash); // basic procedure // TODO: optimization @@ -645,26 +702,26 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers SInterval interval = {0}; TSKEY lastWinSKey = INT64_MIN; - if (tInitSubmitMsgIter(pMsg, &msgIter) != TSDB_CODE_SUCCESS) { + if (tInitSubmitMsgIterEx(pMsg, &msgIter) != TSDB_CODE_SUCCESS) { return TSDB_CODE_FAILED; } while (true) { - tGetSubmitMsgNext(&msgIter, &pBlock); - if (pBlock == NULL) break; + tGetSubmitMsgNextEx(&msgIter, &pBlock); + if (!pBlock) break; STSmaWrapper *pSW = NULL; STSma *pTSma = NULL; SSubmitBlkIter blkIter = {0}; - if (tInitSubmitBlkIter(pBlock, &blkIter) != TSDB_CODE_SUCCESS) { + if (tInitSubmitBlkIterEx(&msgIter, pBlock, &blkIter) != TSDB_CODE_SUCCESS) { pSW = tdFreeTSmaWrapper(pSW); break; } while (true) { - STSRow *row = tGetSubmitBlkNext(&blkIter); - if (row == NULL) { + STSRow *row = tGetSubmitBlkNextEx(&blkIter); + if (!row) { tdFreeTSmaWrapper(pSW); break; } @@ -672,10 +729,10 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers if (pSW) { pSW = tdFreeTSmaWrapper(pSW); } - if ((pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) { + if (!(pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid))) { break; } - if ((pSW->number) <= 0 || (pSW->tSma == NULL)) { + if ((pSW->number) <= 0 || !pSW->tSma) { pSW = tdFreeTSmaWrapper(pSW); break; } @@ -721,10 +778,10 @@ static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t ind tsdbRefSmaStat(pTsdb, pStat); - if (pStat && pStat->smaStatItems) { - pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid)); + if (pStat && SMA_STAT_ITEMS(pStat)) { + pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid)); } - if ((pItem != NULL) && ((pItem = *(SSmaStatItem **)pItem) != NULL)) { + if ((pItem) && ((pItem = *(SSmaStatItem **)pItem))) { // pItem resides in hash buffer all the time unless drop sma index // TODO: multithread protect if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) { @@ -934,7 +991,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) { static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) { STsdb *pTsdb = pSmaH->pTsdb; - ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL); + ASSERT(!pSmaH->dFile.path && !pSmaH->dFile.pDB); pSmaH->dFile.fid = fid; char tSmaFile[TSDB_FILENAME_LEN] = {0}; @@ -1004,6 +1061,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char STsdbCfg *pCfg = REPO_CFG(pTsdb); const SArray *pDataBlocks = (const SArray *)msg; + // TODO: destroy SSDataBlocks(msg) + // For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus // the sma data would arrive ahead of the update-expired-window msg. if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) { @@ -1011,7 +1070,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char return TSDB_CODE_FAILED; } - if (pDataBlocks == NULL) { + if (!pDataBlocks) { terrno = TSDB_CODE_INVALID_PTR; tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb)); return terrno; @@ -1029,11 +1088,11 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char tsdbRefSmaStat(pTsdb, pStat); - if (pStat && pStat->smaStatItems) { - pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid)); + if (pStat && SMA_STAT_ITEMS(pStat)) { + pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid)); } - if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) { + if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) { terrno = TSDB_CODE_TDB_INVALID_SMA_STAT; tsdbUnRefSmaStat(pTsdb, pStat); return TSDB_CODE_FAILED; @@ -1061,9 +1120,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit); int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel); - // key: skey + groupId - char smaKey[SMA_KEY_LEN] = {0}; - char dataBuf[512] = {0}; + char smaKey[SMA_KEY_LEN] = {0}; // key: skey + groupId + char dataBuf[512] = {0}; // val: aggr data // TODO: handle 512 buffer? void *pDataBuf = NULL; int32_t sz = taosArrayGetSize(pDataBlocks); for (int32_t i = 0; i < sz; ++i) { @@ -1228,7 +1286,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) { tsdbDebug("vgId:%d drop tSma local cache for %" PRIi64, REPO_ID(pTsdb), indexUid); SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid)); - if ((pItem != NULL) || ((pItem = *(SSmaStatItem **)pItem) != NULL)) { + if ((pItem) || ((pItem = *(SSmaStatItem **)pItem))) { if (tsdbSmaStatIsDropped(pItem)) { tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid); return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode @@ -1284,19 +1342,13 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) { SSmaEnv *pEnv = atomic_load_ptr(&REPO_RSMA_ENV(pTsdb)); int64_t indexUid = SMA_TEST_INDEX_UID; - if (pEnv == NULL) { - terrno = TSDB_CODE_INVALID_PTR; - tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); - return terrno; - } - - if (pEnv == NULL) { + if (!pEnv) { terrno = TSDB_CODE_INVALID_PTR; tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); return terrno; } - if (pDataBlocks == NULL) { + if (!pDataBlocks) { terrno = TSDB_CODE_INVALID_PTR; tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb)); return terrno; @@ -1313,11 +1365,11 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) { tsdbRefSmaStat(pTsdb, pStat); - if (pStat && pStat->smaStatItems) { - pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid)); + if (pStat && SMA_STAT_ITEMS(pStat)) { + pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid)); } - if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) { + if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) { terrno = TSDB_CODE_TDB_INVALID_SMA_STAT; tsdbUnRefSmaStat(pTsdb, pStat); return TSDB_CODE_FAILED; @@ -1438,7 +1490,7 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) { ++pReadH->smaFsIter.iter; } - if (pReadH->pDFile != NULL) { + if (pReadH->pDFile) { tsdbDebug("vg%d: smaFile %s matched", REPO_ID(pReadH->pTsdb), "[pSmaFile dir]"); return true; } @@ -1471,7 +1523,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, tsdbRefSmaStat(pTsdb, pStat); SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid)); - if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL)) { + if (!pItem || !(pItem = *(SSmaStatItem **)pItem)) { // Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if // it's NULL. tsdbUnRefSmaStat(pTsdb, pStat); @@ -1484,7 +1536,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, int32_t nQueryWin = taosArrayGetSize(pQuerySKey); for (int32_t n = 0; n < nQueryWin; ++n) { TSKEY skey = taosArrayGet(pQuerySKey, n); - if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY)) != NULL) { + if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY))) { // TODO: mark this window as expired. } } @@ -1500,7 +1552,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, return TSDB_CODE_FAILED; } - if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY)) != NULL) { + if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY))) { // TODO: mark this window as expired. tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb), querySKey, indexUid); @@ -1534,7 +1586,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, void *result = NULL; int32_t valueSize = 0; - if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) { + if (!(result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize))) { tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s", REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno)); tsdbCloseDBF(&tReadH.dFile); @@ -1578,7 +1630,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) { SSmaCfg vCreateSmaReq = {0}; - if (tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq) == NULL) { + if (!tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq)) { terrno = TSDB_CODE_OUT_OF_MEMORY; tsdbWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno)); return -1; @@ -1604,7 +1656,7 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) { int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) { SVDropTSmaReq vDropSmaReq = {0}; - if (tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq) == NULL) { + if (!tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq)) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -1632,6 +1684,401 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) { return TSDB_CODE_SUCCESS; } +/** + * @brief Check and init qTaskInfo_t, only applicable to stable with SRSmaParam. + * + * @param pTsdb + * @param pMeta + * @param pReq + * @return int32_t + */ +int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) { + 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); + return TSDB_CODE_SUCCESS; + } + + 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); + return TSDB_CODE_SUCCESS; + } + + if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_ROLLUP) != TSDB_CODE_SUCCESS) { + terrno = TSDB_CODE_TDB_INIT_FAILED; + return TSDB_CODE_FAILED; + } + + SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb); + SSmaStat *pStat = SMA_ENV_STAT(pEnv); + SRSmaInfo *pRSmaInfo = NULL; + + pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.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); + return TSDB_CODE_SUCCESS; + } + + pRSmaInfo = (SRSmaInfo *)taosMemoryCalloc(1, sizeof(SRSmaInfo)); + if (!pRSmaInfo) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + + STqReadHandle *pReadHandle = tqInitSubmitMsgScanner(pMeta); + if (!pReadHandle) { + taosMemoryFree(pRSmaInfo); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + + SReadHandle handle = { + .reader = pReadHandle, + .meta = pMeta, + }; + + if (param->qmsg1) { + pRSmaInfo->taskInfo[0] = qCreateStreamExecTaskInfo(param->qmsg1, &handle); + if (!pRSmaInfo->taskInfo[0]) { + taosMemoryFree(pRSmaInfo); + taosMemoryFree(pReadHandle); + return TSDB_CODE_FAILED; + } + } + + if (param->qmsg2) { + pRSmaInfo->taskInfo[1] = qCreateStreamExecTaskInfo(param->qmsg2, &handle); + if (!pRSmaInfo->taskInfo[1]) { + taosMemoryFree(pRSmaInfo); + taosMemoryFree(pReadHandle); + return TSDB_CODE_FAILED; + } + } + + if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.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); + } + + return TSDB_CODE_SUCCESS; +} + +/** + * @brief store suid/[uids], prefer to use array and then hash + * + * @param pStore + * @param suid + * @param uid + * @return int32_t + */ +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) { + pStore->suid = suid; + } + if (uid) { + if (!pStore->tbUids) { + if (!(pStore->tbUids = taosArrayInit(1, sizeof(tb_uid_t)))) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + } + if (!taosArrayPush(pStore->tbUids, uid)) { + return TSDB_CODE_FAILED; + } + } + } else { + // store other suid/uids in hash when multiple stable/table included in 1 batch of request + if (!pStore->uidHash) { + pStore->uidHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); + if (!pStore->uidHash) { + return TSDB_CODE_FAILED; + } + } + if (uid) { + SArray *uidArray = taosHashGet(pStore->uidHash, &suid, sizeof(tb_uid_t)); + if (uidArray && ((uidArray = *(SArray **)uidArray))) { + taosArrayPush(uidArray, uid); + } else { + SArray *pUidArray = taosArrayInit(1, sizeof(tb_uid_t)); + if (!pUidArray) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + if (!taosArrayPush(pUidArray, uid)) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) != 0) { + return TSDB_CODE_FAILED; + } + } + } else { + if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) != 0) { + return TSDB_CODE_FAILED; + } + } + } + return TSDB_CODE_SUCCESS; +} + +void tsdbUidStoreDestory(STbUidStore *pStore) { + if (pStore) { + if (pStore->uidHash) { + if (pStore->tbUids) { + void *pIter = taosHashIterate(pStore->uidHash, NULL); + while (pIter) { + SArray *arr = *(SArray **)pIter; + taosArrayDestroy(arr); + pIter = taosHashIterate(pStore->uidHash, pIter); + } + } + taosHashCleanup(pStore->uidHash); + } + taosArrayDestroy(pStore->tbUids); + } +} + +void *tsdbUidStoreFree(STbUidStore *pStore) { + tsdbUidStoreDestory(pStore); + taosMemoryFree(pStore); + return NULL; +} + +/** + * @brief fetch suid/uids when create child tables of rollup SMA + * + * @param pTsdb + * @param ppStore + * @param suid + * @param uid + * @return int32_t + */ +int32_t tsdbFetchTbUidList(void *pTsdb, void **ppStore, void *suid, void *uid) { + SSmaEnv *pEnv = REPO_RSMA_ENV((STsdb *)pTsdb); + + // only applicable to rollup SMA ctables + if (!pEnv) { + return TSDB_CODE_SUCCESS; + } + + SSmaStat *pStat = SMA_ENV_STAT(pEnv); + SHashObj *infoHash = NULL; + if (!pStat || !(infoHash = SMA_STAT_INFO_HASH(pStat))) { + terrno = TSDB_CODE_TDB_INVALID_SMA_STAT; + return TSDB_CODE_FAILED; + } + + // info cached when create rsma stable and return directly for non-rsma ctables + if (!taosHashGet(infoHash, suid, sizeof(tb_uid_t))) { + return TSDB_CODE_SUCCESS; + } + + if (!(*ppStore)) { + if (tsdbUidStoreInit((STbUidStore **)ppStore) != 0) { + return TSDB_CODE_FAILED; + } + } + + if (tsdbUidStorePut(*ppStore, *(tb_uid_t *)suid, (tb_uid_t *)uid) != 0) { + *ppStore = tsdbUidStoreFree(*ppStore); + return TSDB_CODE_FAILED; + } + + return TSDB_CODE_SUCCESS; +} + +static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids) { + SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb); + SSmaStat *pStat = SMA_ENV_STAT(pEnv); + SRSmaInfo *pRSmaInfo = NULL; + + if (!suid || !tbUids) { + terrno = TSDB_CODE_INVALID_PTR; + tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno)); + return TSDB_CODE_FAILED; + } + + pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t)); + if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { + tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64, REPO_ID(pTsdb), *suid); + terrno = TSDB_CODE_TDB_INVALID_SMA_STAT; + return TSDB_CODE_FAILED; + } + + if (pRSmaInfo->taskInfo[0] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[0], tbUids, true) != 0)) { + tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno)); + return TSDB_CODE_FAILED; + } else { + tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb), + pRSmaInfo->taskInfo[0], *suid, *(int64_t *)taosArrayGet(tbUids, 0)); + } + + if (pRSmaInfo->taskInfo[1] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[1], tbUids, true) != 0)) { + tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno)); + return TSDB_CODE_FAILED; + } else { + tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb), + pRSmaInfo->taskInfo[1], *suid, *(int64_t *)taosArrayGet(tbUids, 0)); + } + + return TSDB_CODE_SUCCESS; +} + +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; + } + + void *pIter = taosHashIterate(pStore->uidHash, NULL); + while (pIter) { + tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL); + SArray *pTbUids = *(SArray **)pIter; + + 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; +} + +static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) { + ASSERT(pMsg != NULL); + SSubmitMsgIter msgIter = {0}; + SSubmitBlk *pBlock = NULL; + SSubmitBlkIter blkIter = {0}; + 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) { + if (tGetSubmitMsgNextEx(&msgIter, &pBlock) < 0) return -1; + + if (!pBlock) break; + tsdbUidStorePut(pStore, msgIter.suid, NULL); + } + + if (terrno != TSDB_CODE_SUCCESS) return -1; + return 0; +} + +int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t inputType, tb_uid_t *suid) { + SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb); + if (!pEnv) { + // only applicable when rsma env exists + return TSDB_CODE_SUCCESS; + } + + SSmaStat *pStat = SMA_ENV_STAT(pEnv); + SRSmaInfo *pRSmaInfo = NULL; + + pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t)); + + if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { + tsdbDebug("vgId:%d no rsma info for suid:%" PRIu64, REPO_ID(pTsdb), *suid); + return TSDB_CODE_SUCCESS; + } + + SArray *pResult = NULL; + + pResult = taosArrayInit(0, sizeof(SSDataBlock)); + if (!pResult) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) { + if (pRSmaInfo->taskInfo[0]) { + tsdbDebug("vgId:%d execute rsma task for qTaskInfo:%p suid:%" PRIu64, REPO_ID(pTsdb), pRSmaInfo->taskInfo[0], + *suid); + qSetStreamInput(pRSmaInfo->taskInfo[0], pMsg, inputType); + while (1) { + SSDataBlock *output; + uint64_t ts; + if (qExecTask(pRSmaInfo->taskInfo[0], &output, &ts) < 0) { + ASSERT(false); + } + if (!output) { + break; + } + taosArrayPush(pResult, output); + } + if (taosArrayGetSize(pResult) > 0) { + blockDebugShowData(pResult); + } else { + tsdbWarn("vgId:%d no sma data generated since %s", REPO_ID(pTsdb), tstrerror(terrno)); + } + } + + // if (pRSmaInfo->taskInfo[1]) { + // qSetStreamInput(pRSmaInfo->taskInfo[1], pMsg, inputType); + // while (1) { + // SSDataBlock *output; + // uint64_t ts; + // if (qExecTask(pRSmaInfo->taskInfo[1], &output, &ts) < 0) { + // ASSERT(false); + // } + // if (!output) { + // break; + // } + // taosArrayPush(pResult, output); + // } + // blockDebugShowData(pResult); + // } + } + + return TSDB_CODE_SUCCESS; +} + +int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType) { + SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb); + if (!pEnv) { + // only applicable when rsma env exists + return TSDB_CODE_SUCCESS; + } + + if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) { + STbUidStore uidStore = {0}; + tsdbFetchSubmitReqSuids(pMsg, &uidStore); + + if (uidStore.suid != 0) { + tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, &uidStore.suid); + + void *pIter = taosHashIterate(uidStore.uidHash, NULL); + while (pIter) { + tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL); + tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, pTbSuid); + pIter = taosHashIterate(uidStore.uidHash, pIter); + } + + tsdbUidStoreDestory(&uidStore); + } + } + return TSDB_CODE_SUCCESS; +} + #if 0 /** * @brief Get the start TS key of the last data block of one interval/sliding. @@ -1674,6 +2121,7 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) { if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) { tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); } + // TODO: destroy SSDataBlocks(msg) return code; } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 2b10afa5ed9548b2f6397d6d3bd3487072b82c3a..11136bc7bad5f8982bdf3ec493171b49287a2d2c 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -14,6 +14,7 @@ */ #include "vnodeInt.h" +#include "vnodeSync.h" int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { SVnodeInfo info = {0}; @@ -171,6 +172,16 @@ void vnodeClose(SVnode *pVnode) { } } +// start the sync timer after the queue is ready +int32_t vnodeStart(SVnode *pVnode) { + vnodeSyncSetQ(pVnode, NULL); + vnodeSyncSetRpc(pVnode, NULL); + vnodeSyncStart(pVnode); + return 0; +} + +void vnodeStop(SVnode *pVnode) {} + int64_t vnodeGetSyncHandle(SVnode *pVnode) { return pVnode->sync; } void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot) { pSnapshot->lastApplyIndex = pVnode->state.committed; } \ 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 e3c504c93d9195eec1111965fc65c05119d3f853..76c8e366050a1b2130320bcdf7c40eb71a73983a 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -81,6 +81,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg case TDMT_VND_DROP_TABLE: break; case TDMT_VND_SUBMIT: + tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, ptr, STREAM_DATA_TYPE_SUBMIT_BLOCK); pRsp->msgType = TDMT_VND_SUBMIT_RSP; vnodeProcessSubmitReq(pVnode, ptr, pRsp); break; @@ -101,7 +102,6 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg } } break; case TDMT_VND_CREATE_SMA: { // timeRangeSMA - if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { // TODO } @@ -193,108 +193,105 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { // sync integration int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); - assert(pSyncNode != NULL); - ESyncState state = syncGetMyRole(pVnode->sync); - SyncTerm currentTerm = syncGetMyTerm(pVnode->sync); + if (syncEnvIsStart()) { - SMsgHead *pHead = pMsg->pCont; + SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); + assert(pSyncNode != NULL); - char logBuf[512]; - char *syncNodeStr = sync2SimpleStr(pVnode->sync); - snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr); - syncRpcMsgLog2(logBuf, pMsg); - taosMemoryFree(syncNodeStr); + ESyncState state = syncGetMyRole(pVnode->sync); + SyncTerm currentTerm = syncGetMyTerm(pVnode->sync); - SRpcMsg *pRpcMsg = pMsg; + SMsgHead *pHead = pMsg->pCont; - if (pRpcMsg->msgType == TDMT_VND_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + char logBuf[512]; + char *syncNodeStr = sync2SimpleStr(pVnode->sync); + snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr); + syncRpcMsgLog2(logBuf, pMsg); + taosMemoryFree(syncNodeStr); - syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); + SRpcMsg *pRpcMsg = pMsg; - } else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + if (pRpcMsg->msgType == TDMT_VND_SYNC_TIMEOUT) { + SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); + syncNodeOnTimeoutCb(pSyncNode, pSyncMsg); + syncTimeoutDestroy(pSyncMsg); - } else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + } else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING) { + SyncPing *pSyncMsg = syncPingFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); + syncNodeOnPingCb(pSyncNode, pSyncMsg); + syncPingDestroy(pSyncMsg); - } else if (pRpcMsg->msgType == TDMT_VND_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + } else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING_REPLY) { + SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeOnClientRequestCb(pSyncNode, pSyncMsg); - syncClientRequestDestroy(pSyncMsg); + syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); + syncPingReplyDestroy(pSyncMsg); - } else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + } else if (pRpcMsg->msgType == TDMT_VND_SYNC_CLIENT_REQUEST) { + SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); + syncNodeOnClientRequestCb(pSyncNode, pSyncMsg); + syncClientRequestDestroy(pSyncMsg); - } else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + } else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE) { + SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); + syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg); + syncRequestVoteDestroy(pSyncMsg); - } else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES) { - SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + } else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE_REPLY) { + SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); + syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg); + syncRequestVoteReplyDestroy(pSyncMsg); - } else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg); - assert(pSyncMsg != NULL); + } else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES) { + SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); + syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg); + syncAppendEntriesDestroy(pSyncMsg); - } else { - vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType); - } + } else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES_REPLY) { + SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg); + assert(pSyncMsg != NULL); - syncNodeRelease(pSyncNode); + syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg); + syncAppendEntriesReplyDestroy(pSyncMsg); + + } else { + vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType); + } + syncNodeRelease(pSyncNode); + } else { + vError("==vnodeProcessSyncReq== error syncEnv stop"); + } return 0; } static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) { SVCreateTbReq vCreateTbReq = {0}; tDeserializeSVCreateTbReq(pReq, &vCreateTbReq); - if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { + if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq), NULL) < 0) { // TODO return -1; } - // TODO: remove the debug log - SRSmaParam *param = vCreateTbReq.stbCfg.pRSmaParam; - if (param) { - printf("qmsg1 len = %d, body = %s\n", param->qmsg1 ? (int32_t)strlen(param->qmsg1) : 0, - param->qmsg1 ? param->qmsg1 : ""); - printf("qmsg1 len = %d, body = %s\n", param->qmsg2 ? (int32_t)strlen(param->qmsg2) : 0, - param->qmsg2 ? param->qmsg2 : ""); - } + tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &vCreateTbReq); taosMemoryFree(vCreateTbReq.stbCfg.pSchema); taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); if (vCreateTbReq.stbCfg.pRSmaParam) { - taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg1); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg2); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); @@ -309,6 +306,13 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR SVCreateTbBatchRsp vCreateTbBatchRsp = {0}; tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq); int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray); + + STbDdlH ddlHandle = { + .ahandle = pVnode->pTsdb, + .result = NULL, + .fp = tsdbFetchTbUidList, + }; + for (int i = 0; i < reqNum; i++) { SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i); @@ -324,7 +328,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR taosArrayPush(vCreateTbBatchRsp.rspList, &rsp); } - if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { + if (metaCreateTable(pVnode->pMeta, pCreateTbReq, &ddlHandle) < 0) { // TODO: handle error vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name); } @@ -334,7 +338,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR taosMemoryFree(pCreateTbReq->stbCfg.pSchema); taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); if (pCreateTbReq->stbCfg.pRSmaParam) { - taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds); taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); } } else if (pCreateTbReq->type == TD_CHILD_TABLE) { @@ -342,12 +345,13 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR } else { taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); if (pCreateTbReq->ntbCfg.pRSmaParam) { - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds); taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); } } } + tsdbUpdateTbUidList(pVnode->pTsdb, ddlHandle.result); + vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray)); taosArrayDestroy(vCreateTbBatchReq.pArray); if (vCreateTbBatchRsp.rspList) { @@ -371,7 +375,6 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) { taosMemoryFree(vAlterTbReq.stbCfg.pSchema); taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); if (vAlterTbReq.stbCfg.pRSmaParam) { - taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds); taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); } taosMemoryFree(vAlterTbReq.name); diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index b0217a046280abb37065005d90d4cb5d70806fba..ab617cb18660bc6663b500d7ef9da60a5c2d9fa5 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -407,7 +407,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { } } - EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS); + // EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS); EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg, 0), 0); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index db0dd1ffbb8e099f0743dc2e5ab55dd37a2cec02..4a7461c00f08a5a41c87769a585f0fb1ac3e84b0 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -319,27 +319,32 @@ typedef struct SColMatchInfo { bool output; } SColMatchInfo; +typedef struct SScanInfo { + int32_t numOfAsc; + int32_t numOfDesc; +} SScanInfo; + typedef struct STableScanInfo { void* dataReader; + int32_t numOfBlocks; // extract basic running information. int32_t numOfSkipped; int32_t numOfBlockStatis; int64_t numOfRows; - int32_t order; // scan order - int32_t times; // repeat counts + int64_t elapsedTime; + int32_t prevGroupId; // previous table group id + SScanInfo scanInfo; int32_t current; - int32_t reverseTimes; // 0 by default - SNode* pFilterNode; // filter operator info - SqlFunctionCtx* pCtx; // next operator query context + SNode* pFilterNode; // filter operator info + SqlFunctionCtx* pCtx; // next operator query context SResultRowInfo* pResultRowInfo; int32_t* rowCellInfoOffset; SExprInfo* pExpr; SSDataBlock* pResBlock; SArray* pColMatchInfo; int32_t numOfOutput; - int64_t elapsedTime; - int32_t prevGroupId; // previous table group id + SQueryTableDataCond cond; int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan int32_t dataBlockLoadFlag; double sampleRatio; // data block sample ratio, 1 by default @@ -399,8 +404,8 @@ typedef struct SOptrBasicInfo { // TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset typedef struct SAggSupporter { SHashObj* pResultRowHashTable; // quick locate the window object for each result - SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not - SArray* pResultRowArrayList; // The array list that contains the Result rows +// SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not +// SArray* pResultRowArrayList; // The array list that contains the Result rows char* keyBuf; // window key buffer SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row @@ -620,6 +625,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList); void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win); +int32_t getTableScanOrder(SOperatorInfo* pOperator); void doSetOperatorCompleted(SOperatorInfo* pOperator); void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock); @@ -627,9 +633,9 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createTableScanOperatorInfo(void* pReaderHandle, int32_t order, int32_t numOfCols, int32_t dataLoadFlag, int32_t repeatTime, - int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, - SInterval* pInterval, double ratio, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCond* pCond, int32_t numOfOutput, int32_t dataLoadFlag, const uint8_t* scanInfo, + SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo); + SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index c3fa777779c979799e281761816a48698aebfc56..3283ae2b55326972a15bf6d34fcb036223117749 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -221,7 +221,7 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, boo p->groupId = *(uint64_t*) key; p->pos = *(SResultRowPosition*) pData; - memcpy(p->key, key + sizeof(uint64_t), keyLen - sizeof(uint64_t)); + memcpy(p->key, (char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t)); taosArrayPush(pGroupResInfo->pRows, &p); } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 6a5f5b2dc348545f4c350932b55a0b143b201696..35410130154e5904f13d122e0c74f6050af68511 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -191,7 +191,7 @@ static SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutpu static int32_t setTimestampListJoinInfo(STaskRuntimeEnv* pRuntimeEnv, SVariant* pTag, STableQueryInfo* pTableQueryInfo); static void releaseQueryBuf(size_t numOfTables); static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); -// static STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win); +// static SQueryTableDataCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win); static STableIdInfo createTableIdInfo(STableQueryInfo* pTableQueryInfo); static int32_t getNumOfScanTimes(STaskAttr* pQueryAttr); @@ -207,7 +207,6 @@ static void destroyAggOperatorInfo(void* param, int32_t numOfOutput); static void destroyIntervalOperatorInfo(void* param, int32_t numOfOutput); static void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput); -static void destroyConditionOperatorInfo(void* param, int32_t numOfOutput); static void destroyOperatorInfo(SOperatorInfo* pOperator); static void destroySysTableScannerOperatorInfo(void* param, int32_t numOfOutput); @@ -268,7 +267,6 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { int32_t numOfCols = LIST_LENGTH(pNode->pSlots); SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->info.numOfCols = numOfCols; pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); pBlock->info.blockId = pNode->dataBlockId; @@ -294,6 +292,7 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { taosArrayPush(pBlock->pDataBlock, &idata); } + pBlock->info.numOfCols = taosArrayGetSize(pBlock->pDataBlock); return pBlock; } @@ -324,11 +323,16 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) newCapacity = (int64_t)(pResultRowInfo->capacity * 1.5); } - if (newCapacity == pResultRowInfo->capacity) { + if (newCapacity <= pResultRowInfo->capacity) { newCapacity += 4; } - pResultRowInfo->pPosition = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition)); + char* p = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition)); + if (p == NULL) { + longjmp(env, TSDB_CODE_OUT_OF_MEMORY); + } + + pResultRowInfo->pPosition = (SResultRowPosition*)p; int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity; memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition) * inc); @@ -419,88 +423,56 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, * | 8 bytes | actual length | * +----------+---------------+ */ -static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, int64_t uid, +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) { - bool existInCurrentResusltRowInfo = false; SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId); SResultRowPosition* p1 = (SResultRowPosition*)taosHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); + SResultRow* pResult = NULL; + // in case of repeat scan/reverse scan, no new time window added. if (isIntervalQuery) { - if (!masterscan) { // the *p1 may be NULL in case of sliding+offset exists. - if (p1 != NULL) { - return getResultRowByPos(pResultBuf, p1); - } else { - return NULL; - } - } - - if (p1 != NULL) { - if (pResultRowInfo->size == 0) { - existInCurrentResusltRowInfo = - false; // this time window created by other timestamp that does not belongs to current table. - } else if (pResultRowInfo->size == 1) { - SResultRowPosition* p = &pResultRowInfo->pPosition[0]; - existInCurrentResusltRowInfo = (p->pageId == p1->pageId && p->offset == p1->offset); - } else { // check if current pResultRowInfo contains the existInCurrentResusltRowInfo pResultRow - SET_RES_EXT_WINDOW_KEY(pSup->keyBuf, pData, bytes, uid, pResultRowInfo); - int64_t* index = taosHashGet(pSup->pResultRowListSet, pSup->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes)); - if (index != NULL) { - // TODO check the scan order for current opened time window - existInCurrentResusltRowInfo = true; - } else { - existInCurrentResusltRowInfo = false; - } - } + if (masterscan && p1 != NULL) { // the *p1 may be NULL in case of sliding+offset exists. + pResult = getResultRowByPos(pResultBuf, p1); } } else { // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the // pResultRowInfo object. if (p1 != NULL) { - return getResultRowByPos(pResultBuf, p1); + pResult = getResultRowByPos(pResultBuf, p1); } } - SResultRow* pResult = NULL; - if (!existInCurrentResusltRowInfo) { // 1. close current opened time window - if (pResultRowInfo->cur.pageId != -1) { // todo extract function - SResultRowPosition pos = pResultRowInfo->cur; - SFilePage* pPage = getBufPage(pResultBuf, pos.pageId); - SResultRow* pRow = (SResultRow*)((char*)pPage + pos.offset); - closeResultRow(pRow); - releaseBufPage(pResultBuf, pPage); - } - - prepareResultListBuffer(pResultRowInfo, pTaskInfo->env); - if (p1 == NULL) { - pResult = getNewResultRow_rv(pResultBuf, groupId, pSup->resultRowSize); - initResultRow(pResult); - - // 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)); - SResultRowCell cell = {.groupId = groupId, .pos = pos}; - taosArrayPush(pSup->pResultRowArrayList, &cell); - } else { - pResult = getResultRowByPos(pResultBuf, p1); - } + if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId && + pResult->offset != pResultRowInfo->cur.offset))) { + // todo extract function + SResultRowPosition pos = pResultRowInfo->cur; + SFilePage* pPage = getBufPage(pResultBuf, pos.pageId); + SResultRow* pRow = (SResultRow*)((char*)pPage + pos.offset); + closeResultRow(pRow); + releaseBufPage(pResultBuf, pPage); + } + + // allocate a new buffer page + prepareResultListBuffer(pResultRowInfo, pTaskInfo->env); + if (pResult == NULL) { + pResult = getNewResultRow_rv(pResultBuf, groupId, pSup->resultRowSize); + initResultRow(pResult); - // 2. set the new time window to be the new active time window - pResultRowInfo->pPosition[pResultRowInfo->size++] = - (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; - pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; - SET_RES_EXT_WINDOW_KEY(pSup->keyBuf, pData, bytes, uid, pResultRowInfo); - taosHashPut(pSup->pResultRowListSet, pSup->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes), &pResultRowInfo->cur, - POINTER_BYTES); - } else { - pResult = getResultRowByPos(pResultBuf, p1); + // 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)); } + // 2. set the new time window to be the new active time window + pResultRowInfo->pPosition[pResultRowInfo->size++] = + (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; + pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset}; + // too many time window in query if (pResultRowInfo->size > MAX_INTERVAL_TIME_WINDOW) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW); @@ -656,7 +628,7 @@ static int32_t setResultOutputBufByKey_rv(SResultRowInfo* pResultRowInfo, int64_ int32_t numOfOutput, int32_t* rowCellInfoOffset, SAggSupporter* pAggSup, SExecTaskInfo* pTaskInfo) { assert(win->skey <= win->ekey); - SResultRow* pResultRow = doSetResultOutBufByKey_rv(pAggSup->pResultBuf, pResultRowInfo, id, (char*)&win->skey, + SResultRow* pResultRow = doSetResultOutBufByKey(pAggSup->pResultBuf, pResultRowInfo, id, (char*)&win->skey, TSDB_KEYSIZE, masterscan, tableGroupId, pTaskInfo, true, pAggSup); if (pResultRow == NULL) { @@ -1059,6 +1031,8 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc pColInfo->info.bytes = tDataTypes[type].bytes; pInput->pData[paramIndex] = pColInfo; + } else { + pColInfo = pInput->pData[paramIndex]; } ASSERT(!IS_VAR_DATA_TYPE(type)); @@ -1091,6 +1065,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt SInputColumnInfoData* pInput = &pCtx[i].input; pInput->uid = pBlock->info.uid; + pInput->colDataAggIsSet = false; SExprInfo* pOneExpr = &pOperator->pExpr[i]; for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) { @@ -1707,7 +1682,7 @@ int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo; SqlFunctionCtx* pCtx = binfo->pCtx; - SResultRow* pResultRow = doSetResultOutBufByKey_rv(pBuf, pResultRowInfo, groupId, (char*)pData, bytes, true, groupId, + SResultRow* pResultRow = doSetResultOutBufByKey(pBuf, pResultRowInfo, groupId, (char*)pData, bytes, true, groupId, pTaskInfo, false, pAggSup); assert(pResultRow != NULL); @@ -2713,7 +2688,7 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t int64_t tid = 0; int64_t groupId = 0; - SResultRow* pRow = doSetResultOutBufByKey_rv(pSup->pResultBuf, pResultRowInfo, tid, (char*)&tid, sizeof(tid), true, + SResultRow* pRow = doSetResultOutBufByKey(pSup->pResultBuf, pResultRowInfo, tid, (char*)&tid, sizeof(tid), true, groupId, pTaskInfo, false, pSup); for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { @@ -3001,7 +2976,7 @@ void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, u int32_t* rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset; SResultRow* pResultRow = - doSetResultOutBufByKey_rv(pAggInfo->aggSup.pResultBuf, pResultRowInfo, uid, (char*)&groupId, sizeof(groupId), + doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, uid, (char*)&groupId, sizeof(groupId), true, groupId, pTaskInfo, false, &pAggInfo->aggSup); assert(pResultRow != NULL); @@ -3612,8 +3587,8 @@ static void doTableQueryInfoTimeWindowCheck(SExecTaskInfo* pTaskInfo, STableQuer #endif } -// STsdbQueryCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win) { -// STsdbQueryCond cond = { +// SQueryTableDataCond createTsdbQueryCond(STaskAttr* pQueryAttr, STimeWindow* win) { +// SQueryTableDataCond cond = { // .colList = pQueryAttr->tableCols, // .order = pQueryAttr->order.order, // .numOfCols = pQueryAttr->numOfCols, @@ -3775,6 +3750,9 @@ 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 + pColInfoData->hasNull = true; pStart += colLen[i]; } } else { // extract data according to pColList @@ -4702,7 +4680,18 @@ _error: return NULL; } -static int32_t getTableScanOrder(STableScanInfo* pTableScanInfo) { return pTableScanInfo->order; } +int32_t getTableScanOrder(SOperatorInfo* pOperator) { + if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) { + if (pOperator->pDownstream == NULL || pOperator->pDownstream[0] == NULL) { + return TSDB_ORDER_ASC; + } else { + return getTableScanOrder(pOperator->pDownstream[0]); + } + } + + STableScanInfo* pTableScanInfo = pOperator->info; + return pTableScanInfo->cond.order; +} // this is a blocking operator static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { @@ -4895,8 +4884,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}; } @@ -4906,6 +4895,76 @@ bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter* pSup, SOptrBasi return true; } +enum { + PROJECT_RETRIEVE_CONTINUE = 0x1, + PROJECT_RETRIEVE_DONE = 0x2, +}; + +static int32_t handleLimitOffset(SOperatorInfo* pOperator, SSDataBlock* pBlock) { + SProjectOperatorInfo* pProjectInfo = pOperator->info; + SOptrBasicInfo* pInfo = &pProjectInfo->binfo; + SSDataBlock* pRes = pInfo->pRes; + + if (pProjectInfo->curSOffset > 0) { + if (pProjectInfo->groupId == 0) { // it is the first group + pProjectInfo->groupId = pBlock->info.groupId; + blockDataCleanup(pInfo->pRes); + return PROJECT_RETRIEVE_CONTINUE; + } else if (pProjectInfo->groupId != pBlock->info.groupId) { + pProjectInfo->curSOffset -= 1; + + // ignore data block in current group + if (pProjectInfo->curSOffset > 0) { + blockDataCleanup(pInfo->pRes); + return PROJECT_RETRIEVE_CONTINUE; + } + } + + // set current group id of the project operator + pProjectInfo->groupId = pBlock->info.groupId; + } + + if (pProjectInfo->groupId != 0 && pProjectInfo->groupId != pBlock->info.groupId) { + pProjectInfo->curGroupOutput += 1; + if ((pProjectInfo->slimit.limit > 0) && (pProjectInfo->slimit.limit <= pProjectInfo->curGroupOutput)) { + pOperator->status = OP_EXEC_DONE; + blockDataCleanup(pRes); + + return PROJECT_RETRIEVE_DONE; + } + + // reset the value for a new group data + pProjectInfo->curOffset = 0; + pProjectInfo->curOutput = 0; + } + + // here we reach the start position, according to the limit/offset requirements. + + // set current group id + pProjectInfo->groupId = pBlock->info.groupId; + + if (pProjectInfo->curOffset >= pRes->info.rows) { + pProjectInfo->curOffset -= pRes->info.rows; + blockDataCleanup(pRes); + return PROJECT_RETRIEVE_CONTINUE; + } else if (pProjectInfo->curOffset < pRes->info.rows && pProjectInfo->curOffset > 0) { + blockDataTrimFirstNRows(pRes, pProjectInfo->curOffset); + pProjectInfo->curOffset = 0; + } + + if (pRes->info.rows >= pOperator->resultInfo.threshold) { + + // check for the limitation in each group + if (pProjectInfo->limit.limit > 0 && pProjectInfo->curOutput + pRes->info.rows >= pProjectInfo->limit.limit) { + pRes->info.rows = (int32_t)(pProjectInfo->limit.limit - pProjectInfo->curOutput); + } + + return PROJECT_RETRIEVE_DONE; + } else { // not full enough, continue to accumulate the output data in the buffer. + return PROJECT_RETRIEVE_CONTINUE; + } +} + static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) { SProjectOperatorInfo* pProjectInfo = pOperator->info; SOptrBasicInfo* pInfo = &pProjectInfo->binfo; @@ -4974,63 +5033,22 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) // } // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC, false); + int32_t order = getTableScanOrder(pOperator->pDownstream[0]); + + setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order, false); blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput, pProjectInfo->pPseudoColInfo); - if (pProjectInfo->curSOffset > 0) { - if (pProjectInfo->groupId == 0) { // it is the first group - pProjectInfo->groupId = pBlock->info.groupId; - blockDataCleanup(pInfo->pRes); - continue; - } else if (pProjectInfo->groupId != pBlock->info.groupId) { - pProjectInfo->curSOffset -= 1; - - // ignore data block in current group - if (pProjectInfo->curSOffset > 0) { - blockDataCleanup(pInfo->pRes); - continue; - } - } - - pProjectInfo->groupId = pBlock->info.groupId; - } - - if (pProjectInfo->groupId != 0 && pProjectInfo->groupId != pBlock->info.groupId) { - pProjectInfo->curGroupOutput += 1; - if ((pProjectInfo->slimit.limit > 0) && (pProjectInfo->slimit.limit <= pProjectInfo->curGroupOutput)) { - pOperator->status = OP_EXEC_DONE; - return NULL; - } - - // reset the value for a new group data - pProjectInfo->curOffset = 0; - pProjectInfo->curOutput = 0; - } - - pProjectInfo->groupId = pBlock->info.groupId; - - // todo extract method - if (pProjectInfo->curOffset < pInfo->pRes->info.rows && pProjectInfo->curOffset > 0) { - blockDataTrimFirstNRows(pInfo->pRes, pProjectInfo->curOffset); - pProjectInfo->curOffset = 0; - } else if (pProjectInfo->curOffset >= pInfo->pRes->info.rows) { - pProjectInfo->curOffset -= pInfo->pRes->info.rows; - blockDataCleanup(pInfo->pRes); + int32_t status = handleLimitOffset(pOperator, pBlock); + if (status == PROJECT_RETRIEVE_CONTINUE) { continue; - } - - if (pRes->info.rows >= pOperator->resultInfo.threshold) { + } else if (status == PROJECT_RETRIEVE_DONE) { break; } } - if (pProjectInfo->limit.limit > 0 && pProjectInfo->curOutput + pInfo->pRes->info.rows >= pProjectInfo->limit.limit) { - pInfo->pRes->info.rows = (int32_t)(pProjectInfo->limit.limit - pProjectInfo->curOutput); - } - pProjectInfo->curOutput += pInfo->pRes->info.rows; // copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); @@ -5609,10 +5627,10 @@ 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 || + if (pAggSup->keyBuf == NULL /*|| pAggSup->pResultRowArrayList == NULL || pAggSup->pResultRowListSet == NULL*/ || pAggSup->pResultRowHashTable == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -5628,8 +5646,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); } @@ -5682,8 +5700,7 @@ 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) { @@ -6340,6 +6357,19 @@ static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOu static SArray* createSortInfo(SNodeList* pNodeList, SNodeList* pNodeListTarget); static SArray* createIndexMap(SNodeList* pNodeList); static SArray* extractPartitionColInfo(SNodeList* pNodeList); +static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode); + +static SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode) { + SInterval interval = { + .interval = pTableScanNode->interval, + .sliding = pTableScanNode->sliding, + .intervalUnit = pTableScanNode->intervalUnit, + .slidingUnit = pTableScanNode->slidingUnit, + .offset = pTableScanNode->offset, + }; + + return interval; +} SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId, STableGroupInfo* pTableGroupInfo) { @@ -6350,9 +6380,9 @@ 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) { + if (pDataReader == NULL && terrno != 0) { return NULL; } @@ -6360,16 +6390,14 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); SSDataBlock* pResBlock = createResDataBlock(pScanPhyNode->node.pOutputDataBlockDesc); - SInterval interval = { - .interval = pTableScanNode->interval, - .sliding = pTableScanNode->sliding, - .intervalUnit = pTableScanNode->intervalUnit, - .slidingUnit = pTableScanNode->slidingUnit, - .offset = pTableScanNode->offset, - }; + SQueryTableDataCond cond = {0}; + int32_t code = initQueryTableDataCond(&cond, pTableScanNode); + if (code != TSDB_CODE_SUCCESS) { + return NULL; + } - return createTableScanOperatorInfo(pDataReader, pTableScanNode->scanSeq[0] > 0 ? TSDB_ORDER_ASC : TSDB_ORDER_DESC, - numOfCols, pTableScanNode->dataRequired, pTableScanNode->scanSeq[0], pTableScanNode->scanSeq[1], pColList, + SInterval interval = extractIntervalInfo(pTableScanNode); + 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; @@ -6390,10 +6418,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return pOperator; } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) { SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode; - SSDataBlock* pResBlock = createResDataBlock(pSysScanPhyNode->scan.node.pOutputDataBlockDesc); + SScanPhysiNode* pScanNode = &pSysScanPhyNode->scan; - struct SScanPhysiNode* pScanNode = &pSysScanPhyNode->scan; - SArray* colList = extractScanColumnId(pScanNode->pScanCols); + SSDataBlock* pResBlock = createResDataBlock(pScanNode->node.pOutputDataBlockDesc); + SArray* colList = extractScanColumnId(pScanNode->pScanCols); SOperatorInfo* pOperator = createSysTableScanOperatorInfo( pHandle->meta, pResBlock, &pScanNode->tableName, pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, @@ -6514,38 +6542,47 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return pOptr; } -static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STableGroupInfo* pGroupInfo, - void* readHandle, uint64_t queryId, uint64_t taskId) { - STsdbQueryCond cond = {.loadExternalRows = false}; - cond.order = pTableScanNode->scanSeq[0] > 0 ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; - cond.numOfCols = LIST_LENGTH(pTableScanNode->scan.pScanCols); - cond.colList = taosMemoryCalloc(cond.numOfCols, sizeof(SColumnInfo)); - if (cond.colList == NULL) { +static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode) { + pCond->loadExternalRows = false; + + pCond->order = pTableScanNode->scanSeq[0] > 0 ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; + pCond->numOfCols = LIST_LENGTH(pTableScanNode->scan.pScanCols); + pCond->colList = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnInfo)); + if (pCond->colList == NULL) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; - return NULL; + return terrno; } - cond.twindow = pTableScanNode->scanRange; - cond.type = BLOCK_LOAD_OFFSET_SEQ_ORDER; - // cond.type = pTableScanNode->scanFlag; + pCond->twindow = pTableScanNode->scanRange; + +#if 1 + //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, int64_t); + } +#endif + + pCond->type = BLOCK_LOAD_OFFSET_SEQ_ORDER; + // pCond->type = pTableScanNode->scanFlag; int32_t j = 0; - for (int32_t i = 0; i < cond.numOfCols; ++i) { + for (int32_t i = 0; i < pCond->numOfCols; ++i) { STargetNode* pNode = (STargetNode*)nodesListGetNode(pTableScanNode->scan.pScanCols, i); SColumnNode* pColNode = (SColumnNode*)pNode->pExpr; if (pColNode->colType == COLUMN_TYPE_TAG) { continue; } - cond.colList[j].type = pColNode->node.resType.type; - cond.colList[j].bytes = pColNode->node.resType.bytes; - cond.colList[j].colId = pColNode->colId; + pCond->colList[j].type = pColNode->node.resType.type; + pCond->colList[j].bytes = pColNode->node.resType.bytes; + pCond->colList[j].colId = pColNode->colId; j += 1; } - cond.numOfCols = j; - return tsdbQueryTables(readHandle, &cond, pGroupInfo, queryId, taskId); + pCond->numOfCols = j; + return TSDB_CODE_SUCCESS; } SArray* extractScanColumnId(SNodeList* pNodeList) { @@ -6763,7 +6800,13 @@ tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* goto _error; } - return createDataReaderImpl(pTableScanNode, pTableGroupInfo, pHandle->reader, queryId, taskId); + SQueryTableDataCond cond = {0}; + code = initQueryTableDataCond(&cond, pTableScanNode); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + return tsdbQueryTables(pHandle->reader, &cond, pTableGroupInfo, queryId, taskId); _error: terrno = code; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index a70e40287159134edaa5addf186790a5a3755633..fa7c3a365ad4bfbe88ed8fdd6122a23734f00f68 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -245,6 +245,9 @@ 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; @@ -255,17 +258,15 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, return TSDB_CODE_SUCCESS; } -static void setupEnvForReverseScan(STableScanInfo* pTableScanInfo, SqlFunctionCtx* pCtx, int32_t numOfOutput) { - // reverse order time range +static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunctionCtx* pCtx, int32_t numOfOutput) { SET_REVERSE_SCAN_FLAG(pTableScanInfo); switchCtxOrder(pCtx, numOfOutput); - SWITCH_ORDER(pTableScanInfo->order); - setupQueryRangeForReverseScan(pTableScanInfo); +// setupQueryRangeForReverseScan(pTableScanInfo); - pTableScanInfo->times = 1; - pTableScanInfo->current = 0; - pTableScanInfo->reverseTimes = 0; + STimeWindow* pTWindow = &pTableScanInfo->cond.twindow; + TSWAP(pTWindow->skey, pTWindow->ekey, int64_t); + pTableScanInfo->cond.order = TSDB_ORDER_DESC; } static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { @@ -294,8 +295,6 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { continue; } - // 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; return pBlock; } @@ -311,63 +310,67 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { return NULL; } - SResultRowInfo* pResultRowInfo = pTableScanInfo->pResultRowInfo; *newgroup = false; - while (pTableScanInfo->current < pTableScanInfo->times) { + while (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) { SSDataBlock* p = doTableScanImpl(pOperator, newgroup); if (p != NULL) { return p; } - if (++pTableScanInfo->current >= pTableScanInfo->times) { - if (pTableScanInfo->reverseTimes <= 0 /* || isTsdbCacheLastRow(pTableScanInfo->pTsdbReadHandle)*/) { - return NULL; - } else { - break; - } + pTableScanInfo->current += 1; + + if (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) { + setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); + pTableScanInfo->scanFlag = REPEAT_SCAN; + + STimeWindow* pWin = &pTableScanInfo->cond.twindow; + qDebug("%s start to repeat ascending order scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64, + GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); + + // do prepare for the next round table scan operation + tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond); } + } - // do prepare for the next round table scan operation - // STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window); - // tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond); + int32_t total = pTableScanInfo->scanInfo.numOfAsc + pTableScanInfo->scanInfo.numOfDesc; + if (pTableScanInfo->current < total) { + if (pTableScanInfo->cond.order == TSDB_ORDER_ASC) { + prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, pTableScanInfo->numOfOutput); + tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond); + } - setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); - pTableScanInfo->scanFlag = REPEAT_SCAN; + STimeWindow* pWin = &pTableScanInfo->cond.twindow; + qDebug("%s start to descending order scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64, + GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey); - // if (pResultRowInfo->size > 0) { - // pResultRowInfo->curPos = 0; - // } + while (pTableScanInfo->current < total) { + SSDataBlock* p = doTableScanImpl(pOperator, newgroup); + if (p != NULL) { + return p; + } - qDebug("%s start to repeat scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64, - GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); - } + pTableScanInfo->current += 1; - SSDataBlock* p = NULL; - // todo refactor - if (pTableScanInfo->reverseTimes > 0) { - setupEnvForReverseScan(pTableScanInfo, pTableScanInfo->pCtx, pTableScanInfo->numOfOutput); - // STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window); - // tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond); + if (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) { + setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); + pTableScanInfo->scanFlag = REPEAT_SCAN; - qDebug("%s start to reverse scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64, - GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); + qDebug("%s start to repeat descending order scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64, + GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); - if (pResultRowInfo->size > 0) { - // pResultRowInfo->curPos = pResultRowInfo->size - 1; + // do prepare for the next round table scan operation + tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond); + } } - - p = doTableScanImpl(pOperator, newgroup); } - return p; + setTaskStatus(pTaskInfo, TASK_COMPLETED); + return NULL; } -SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, int32_t order, int32_t numOfOutput, int32_t dataLoadFlag, - int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, - SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo) { - assert(repeatTime > 0); - +SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCond* pCond, int32_t numOfOutput, int32_t dataLoadFlag, const uint8_t* scanInfo, + SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -378,18 +381,19 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, int32_t order, int return NULL; } + pInfo->cond = *pCond; + pInfo->scanInfo = (SScanInfo) {.numOfAsc = scanInfo[0], .numOfDesc = scanInfo[1]}; + pInfo->interval = *pInterval; pInfo->sampleRatio = sampleRatio; pInfo->dataBlockLoadFlag= dataLoadFlag; pInfo->pResBlock = pResBlock; pInfo->pFilterNode = pCondition; pInfo->dataReader = pDataReader; - pInfo->times = repeatTime; - pInfo->reverseTimes = reverseTime; - pInfo->order = order; pInfo->current = 0; pInfo->scanFlag = MAIN_SCAN; pInfo->pColMatchInfo = pColMatchInfo; + pOperator->name = "TableScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; pOperator->blockingOptr = false; @@ -410,19 +414,17 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, int32_t order, int SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); - pInfo->dataReader = pTsdbReadHandle; - pInfo->times = 1; - pInfo->reverseTimes = 0; - pInfo->current = 0; + pInfo->dataReader = pTsdbReadHandle; + pInfo->current = 0; pInfo->prevGroupId = -1; SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pOperator->name = "TableSeqScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; - pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->getNextFn = doTableScanImpl; + pOperator->name = "TableSeqScanOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; + pOperator->blockingOptr = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->getNextFn = doTableScanImpl; return pOperator; } diff --git a/source/libs/function/inc/functionMgtInt.h b/source/libs/function/inc/functionMgtInt.h index 39287f08ee62a535265147855c1f611b7ab90d10..af4c8a7bdb7baf37135060402112ecc70525b091 100644 --- a/source/libs/function/inc/functionMgtInt.h +++ b/source/libs/function/inc/functionMgtInt.h @@ -41,7 +41,9 @@ extern "C" { #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) -#define FUNC_UDF_ID_START_OFFSET_VAL 5000 +#define FUNC_UDF_ID_START 5000 +#define FUNC_AGGREGATE_UDF_ID 5001 +#define FUNC_SCALAR_UDF_ID 5002 extern const int funcMgtUdfNum; diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index a52e39bd4f58343c0166145a9c444e7c366c0101..805df08f2736dd4df279c7b12db3a758c2a4e210 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -50,7 +50,7 @@ static int32_t translateInOutNum(SFunctionNode* pFunc, char* pErrBuf, int32_t le return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[paraType].bytes, .type = paraType}; return TSDB_CODE_SUCCESS; } @@ -65,7 +65,7 @@ static int32_t translateInNumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_t return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } @@ -81,7 +81,7 @@ static int32_t translateIn2NumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_ return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } @@ -96,7 +96,7 @@ static int32_t translateInOutStr(SFunctionNode* pFunc, char* pErrBuf, int32_t le return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type}; return TSDB_CODE_SUCCESS; } @@ -126,7 +126,7 @@ static int32_t translateSum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { } else if (IS_FLOAT_TYPE(paraType)) { resType = TSDB_DATA_TYPE_DOUBLE; } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[resType].bytes, .type = resType}; return TSDB_CODE_SUCCESS; } @@ -143,9 +143,7 @@ static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in } static int32_t translateTimezone(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type}; - //pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY}; + pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY}; return TSDB_CODE_SUCCESS; } @@ -156,11 +154,11 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if (!IS_NUMERIC_TYPE(para1Type) || (!IS_SIGNED_NUMERIC_TYPE(para2Type) && !IS_UNSIGNED_NUMERIC_TYPE(para2Type))) { + if (!IS_NUMERIC_TYPE(para1Type) || (!IS_SIGNED_NUMERIC_TYPE(para2Type) && !IS_UNSIGNED_NUMERIC_TYPE(para2Type))) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } @@ -168,7 +166,8 @@ static bool validAperventileAlgo(const SValueNode* pVal) { if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) { return false; } - return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest")); + return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || + 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest")); } static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { @@ -185,17 +184,19 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t if (3 == paraNum) { SNode* pPara3 = nodesListGetNode(pFunc->pParameterList, 2); if (QUERY_NODE_VALUE != nodeType(pPara3) || !validAperventileAlgo((SValueNode*)pPara3)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Third parameter algorithm of apercentile must be 'default' or 't-digest'"); + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "Third parameter algorithm of apercentile must be 'default' or 't-digest'"); } } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; } static int32_t translateTbnameColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { // pseudo column do not need to check parameters - pFunc->node.resType = (SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}; + pFunc->node.resType = + (SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}; return TSDB_CODE_SUCCESS; } @@ -228,11 +229,12 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); if (QUERY_NODE_COLUMN != nodeType(pPara)) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "The parameters of first/last can only be columns"); + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "The parameters of first/last can only be columns"); } uint8_t paraType = ((SExprNode*)pPara)->resType.type; - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[paraType].bytes, .type = paraType}; return TSDB_CODE_SUCCESS; } @@ -245,11 +247,13 @@ 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_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT}; return TSDB_CODE_SUCCESS; } -static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, bool hasSep) { +static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, + int32_t maxParaNum, bool hasSep) { int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); if (paraNum < minParaNum || paraNum > maxParaNum) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); @@ -261,7 +265,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t /* For concat/concat_ws function, if params have NCHAR type, promote the final result to NCHAR */ for (int32_t i = 0; i < paraNum; ++i) { - SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); + SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); uint8_t paraType = ((SExprNode*)pPara)->resType.type; if (!IS_VAR_DATA_TYPE(paraType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); @@ -272,7 +276,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t } for (int32_t i = 0; i < paraNum; ++i) { - SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); + SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); uint8_t paraType = ((SExprNode*)pPara)->resType.type; int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes; int32_t factor = 1; @@ -290,7 +294,7 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t resultBytes += sepBytes * (paraNum - 3); } - pFunc->node.resType = (SDataType) { .bytes = resultBytes, .type = resultType }; + pFunc->node.resType = (SDataType){.bytes = resultBytes, .type = resultType}; return TSDB_CODE_SUCCESS; } @@ -309,7 +313,7 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); - uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; if (!IS_VAR_DATA_TYPE(pPara1->resType.type) || !IS_INTEGER_TYPE(para2Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -320,7 +324,7 @@ static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) } } - pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type}; return TSDB_CODE_SUCCESS; } @@ -339,7 +343,7 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } int32_t para2Bytes = pFunc->node.resType.bytes; - if (para2Bytes <= 0 || para2Bytes > 1000) { //cast dst var type length limits to 1000 + if (para2Bytes <= 0 || para2Bytes > 1000) { // cast dst var type length limits to 1000 return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); } return TSDB_CODE_SUCCESS; @@ -355,7 +359,7 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = 24, .type = TSDB_DATA_TYPE_BINARY}; + pFunc->node.resType = (SDataType){.bytes = 64, .type = TSDB_DATA_TYPE_BINARY}; return TSDB_CODE_SUCCESS; } @@ -368,7 +372,7 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } @@ -379,11 +383,13 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_ uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || !IS_INTEGER_TYPE(para2Type)) { + if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || + !IS_INTEGER_TYPE(para2Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; + pFunc->node.resType = + (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; return TSDB_CODE_SUCCESS; } @@ -406,7 +412,7 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le } } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; } @@ -420,545 +426,440 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BINARY].bytes, .type = TSDB_DATA_TYPE_BINARY}; + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BINARY].bytes, .type = TSDB_DATA_TYPE_BINARY}; return TSDB_CODE_SUCCESS; } 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, - .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, + .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, + .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}}; const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 06b30dd1233906cc1c0b6dd0de56f048f9e05ebf..73736fbad3cafdf8abd7e8efb3e89d6215762a83 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -25,7 +25,6 @@ typedef struct SFuncMgtService { SHashObj* pFuncNameHashTable; - SArray* pUdfTable; // SUdfInfo } SFuncMgtService; typedef struct SUdfInfo { @@ -50,18 +49,12 @@ static void doInitFunctionTable() { return; } } - - gFunMgtService.pUdfTable = NULL; -} - -static int8_t getUdfType(int32_t funcId) { - SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1); - return pUdf->funcType; } static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) { if (fmIsUserDefinedFunc(funcId)) { - return getUdfType(funcId); + return FUNC_MGT_AGG_FUNC == classification ? FUNC_AGGREGATE_UDF_ID == funcId : + (FUNC_MGT_SCALAR_FUNC == classification ? FUNC_SCALAR_UDF_ID == funcId : false); } if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { return false; @@ -69,33 +62,23 @@ static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) { return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification); } -static int32_t getUdfId(SFmGetFuncInfoParam* pParam, const char* pFuncName) { +static int32_t getUdfInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) { SFuncInfo* pInfo = NULL; - int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFuncName, &pInfo); - if (TSDB_CODE_SUCCESS != code || NULL == pInfo) { - return -1; - } - if (NULL == gFunMgtService.pUdfTable) { - gFunMgtService.pUdfTable = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SUdfInfo)); - } - SUdfInfo info = { .outputDt.type = pInfo->outputType, .outputDt.bytes = pInfo->outputLen, .funcType = pInfo->funcType }; - taosArrayPush(gFunMgtService.pUdfTable, &info); + int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFunc->functionName, &pInfo); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + if (NULL == pInfo) { + snprintf(pParam->pErrBuf, pParam->errBufLen, "Invalid function name: %s", pFunc->functionName); + return TSDB_CODE_FUNC_INVALID_FUNTION; + } + pFunc->funcType = FUNCTION_TYPE_UDF; + pFunc->funcId = TSDB_FUNC_TYPE_AGGREGATE == pInfo->funcType ? FUNC_AGGREGATE_UDF_ID : FUNC_SCALAR_UDF_ID; + pFunc->node.resType.type = pInfo->outputType; + pFunc->node.resType.bytes = pInfo->outputLen; + pFunc->udfBufSize = pInfo->bufSize; tFreeSFuncInfo(pInfo); taosMemoryFree(pInfo); - return taosArrayGetSize(gFunMgtService.pUdfTable) + FUNC_UDF_ID_START_OFFSET_VAL; -} - -static int32_t getFuncId(SFmGetFuncInfoParam* pParam, const char* pFuncName) { - void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFuncName, strlen(pFuncName)); - if (NULL == pVal) { - return getUdfId(pParam, pFuncName); - } - return *(int32_t*)pVal; -} - -static int32_t getUdfResultType(SFunctionNode* pFunc) { - SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, pFunc->funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1); - pFunc->node.resType = pUdf->outputDt; return TSDB_CODE_SUCCESS; } @@ -104,28 +87,14 @@ int32_t fmFuncMgtInit() { return initFunctionCode; } -int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) { - *pFuncId = getFuncId(pParam, pFuncName); - if (*pFuncId < 0) { - return TSDB_CODE_FAILED; - } - if (fmIsUserDefinedFunc(*pFuncId)) { - *pFuncType = FUNCTION_TYPE_UDF; - } else { - *pFuncType = funcMgtBuiltins[*pFuncId].type; - } - return TSDB_CODE_SUCCESS; -} - -int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { - if (fmIsUserDefinedFunc(pFunc->funcId)) { - return getUdfResultType(pFunc); - } - - if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) { - return TSDB_CODE_FAILED; +int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) { + void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName)); + if (NULL != pVal) { + pFunc->funcId = *(int32_t*)pVal; + pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type; + return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pParam->pErrBuf, pParam->errBufLen); } - return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pErrBuf, len); + return getUdfInfo(pParam, pFunc); } EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { @@ -203,7 +172,7 @@ bool fmIsMultiResFunc(int32_t funcId) { } bool fmIsUserDefinedFunc(int32_t funcId) { - return funcId > FUNC_UDF_ID_START_OFFSET_VAL; + return funcId > FUNC_UDF_ID_START; } void fmFuncMgtDestroy() { diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index d4e7c9b8253679944c3b9c072729c05b635ba931..6c68adda4e2963a0f7ffb41ca57f7235b7cca8aa 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -551,7 +551,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) { static int32_t udfdInitLog() { char logName[12] = {0}; snprintf(logName, sizeof(logName), "%slog", "udfd"); - return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0); + return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0); } void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { @@ -659,7 +659,7 @@ int main(int argc, char *argv[]) { return -1; } - if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) { fnError("failed to start since read config error"); return -1; } diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index 8e5eac538e9bac83534e3ad5143482e008f51d91..a8d6fbd7152a76f13d06fea6ef42e13acc57e25c 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -31,13 +31,13 @@ static int32_t parseArgs(int32_t argc, char *argv[]) { static int32_t initLog() { char logName[12] = {0}; snprintf(logName, sizeof(logName), "%slog", "udfc"); - return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0); + return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0); } int main(int argc, char *argv[]) { parseArgs(argc, argv); initLog(); - if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) { fnError("failed to start since read config error"); return -1; } diff --git a/source/libs/nodes/inc/nodesUtil.h b/source/libs/nodes/inc/nodesUtil.h index c6233ba9808439f3e0132e0904140638051307fe..e092c18834b7159deb4ec5a76496a82e7f7b03db 100644 --- a/source/libs/nodes/inc/nodesUtil.h +++ b/source/libs/nodes/inc/nodesUtil.h @@ -20,17 +20,39 @@ extern "C" { #endif -#define nodesFatal(...) qFatal("NODES: " __VA_ARGS__) -#define nodesError(...) qError("NODES: " __VA_ARGS__) -#define nodesWarn(...) qWarn("NODES: " __VA_ARGS__) -#define nodesInfo(...) qInfo("NODES: " __VA_ARGS__) -#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__) -#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__) +#define nodesFatal(...) qFatal("NODES: " __VA_ARGS__) +#define nodesError(...) qError("NODES: " __VA_ARGS__) +#define nodesWarn(...) qWarn("NODES: " __VA_ARGS__) +#define nodesInfo(...) qInfo("NODES: " __VA_ARGS__) +#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__) +#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__) -#define NODES_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) -#define NODES_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) -#define NODES_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +#define NODES_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define NODES_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) + +#define NODES_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ + } while (0) #ifdef __cplusplus } diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 975036575de0a57ac3e038812599a3308e9df940..89cacf9298f854ab31c7edc84769339572189678 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -19,71 +19,71 @@ #include "taos.h" #include "taoserror.h" -#define COPY_ALL_SCALAR_FIELDS \ - do { \ +#define COPY_ALL_SCALAR_FIELDS \ + do { \ memcpy((pDst), (pSrc), sizeof(*pSrc)); \ - } while (0) + } while (0) -#define COPY_SCALAR_FIELD(fldname) \ - do { \ +#define COPY_SCALAR_FIELD(fldname) \ + do { \ (pDst)->fldname = (pSrc)->fldname; \ - } while (0) + } while (0) -#define COPY_CHAR_ARRAY_FIELD(fldname) \ - do { \ +#define COPY_CHAR_ARRAY_FIELD(fldname) \ + do { \ strcpy((pDst)->fldname, (pSrc)->fldname); \ - } while (0) + } while (0) -#define COPY_CHAR_POINT_FIELD(fldname) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ +#define COPY_CHAR_POINT_FIELD(fldname) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = strdup((pSrc)->fldname); \ - } while (0) + } while (0) -#define CLONE_NODE_FIELD(fldname) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ +#define CLONE_NODE_FIELD(fldname) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = nodesCloneNode((pSrc)->fldname); \ - if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)(pDst)); \ - return NULL; \ - } \ - } while (0) - -#define CLONE_NODE_LIST_FIELD(fldname) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ + if (NULL == (pDst)->fldname) { \ + nodesDestroyNode((SNode*)(pDst)); \ + return NULL; \ + } \ + } while (0) + +#define CLONE_NODE_LIST_FIELD(fldname) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = nodesCloneList((pSrc)->fldname); \ - if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)(pDst)); \ - return NULL; \ - } \ - } while (0) - -#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \ - do { \ - if (NULL == (pSrc)->fldname) { \ - break; \ - } \ + if (NULL == (pDst)->fldname) { \ + nodesDestroyNode((SNode*)(pDst)); \ + return NULL; \ + } \ + } while (0) + +#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \ + do { \ + if (NULL == (pSrc)->fldname) { \ + break; \ + } \ (pDst)->fldname = cloneFunc((pSrc)->fldname); \ - if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)(pDst)); \ - return NULL; \ - } \ - } while (0) - -#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \ - do { \ + if (NULL == (pDst)->fldname) { \ + nodesDestroyNode((SNode*)(pDst)); \ + return NULL; \ + } \ + } while (0) + +#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \ + do { \ if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \ - return NULL; \ - } \ - } while (0) + return NULL; \ + } \ + } while (0) static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) { COPY_SCALAR_FIELD(type); @@ -201,7 +201,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) { } static STableMeta* tableMetaClone(const STableMeta* pSrc) { - int32_t len = TABLE_META_SIZE(pSrc); + int32_t len = TABLE_META_SIZE(pSrc); STableMeta* pDst = taosMemoryMalloc(len); if (NULL == pDst) { return NULL; @@ -211,7 +211,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) { } static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) { - int32_t len = VGROUPS_INFO_SIZE(pSrc); + int32_t len = VGROUPS_INFO_SIZE(pSrc); SVgroupsInfo* pDst = taosMemoryMalloc(len); if (NULL == pDst) { return NULL; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 046a5368d967b17902b6aba5d3623992097e9cb9..f8a56109ee67621e9187356342385a4b4703cdd6 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -16,8 +16,8 @@ #include "cmdnodes.h" #include "nodesUtil.h" #include "plannodes.h" -#include "querynodes.h" #include "query.h" +#include "querynodes.h" #include "taoserror.h" #include "tjson.h" @@ -29,7 +29,7 @@ static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode); const char* nodesNodeName(ENodeType type) { switch (type) { case QUERY_NODE_COLUMN: - return "Column"; + return "Column"; case QUERY_NODE_VALUE: return "Value"; case QUERY_NODE_OPERATOR: @@ -306,7 +306,7 @@ static int32_t tableComInfoToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkTableComInfoRowSize, pNode->rowSize); } - + return code; } @@ -323,7 +323,7 @@ static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetNumberValue(pJson, jkTableComInfoRowSize, pNode->rowSize); } - + return code; } @@ -345,7 +345,7 @@ static int32_t schemaToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddStringToObject(pJson, jkSchemaName, pNode->name); } - + return code; } @@ -362,7 +362,7 @@ static int32_t jsonToSchema(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetStringValue(pJson, jkSchemaName, pNode->name); } - + return code; } @@ -398,7 +398,8 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) { code = tjsonAddObject(pJson, jkTableMetaComInfo, tableComInfoToJson, &pNode->tableInfo); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema), TABLE_TOTAL_COL_NUM(pNode)); + code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema), + TABLE_TOTAL_COL_NUM(pNode)); } return code; @@ -713,13 +714,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) { return code; } -static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) { - return physiScanNodeToJson(pObj, pJson); -} +static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); } -static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { - return jsonToPhysiScanNode(pJson, pObj); -} +static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); } static const char* jkTableScanPhysiPlanScanCount = "ScanCount"; static const char* jkTableScanPhysiPlanReverseScanCount = "ReverseScanCount"; @@ -732,7 +729,7 @@ static const char* jkTableScanPhysiPlanInterval = "Interval"; static const char* jkTableScanPhysiPlanOffset = "Offset"; static const char* jkTableScanPhysiPlanSliding = "Sliding"; static const char* jkTableScanPhysiPlanIntervalUnit = "intervalUnit"; -static const char* jkTableScanPhysiPlanSlidingUnit = "slidingUnit"; +static const char* jkTableScanPhysiPlanSlidingUnit = "slidingUnit"; static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) { const STableScanPhysiNode* pNode = (const STableScanPhysiNode*)pObj; @@ -822,13 +819,9 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) { return code; } -static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { - return physiScanNodeToJson(pObj, pJson); -} +static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); } -static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { - return jsonToPhysiScanNode(pJson, pObj); -} +static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); } static const char* jkEndPointFqdn = "Fqdn"; static const char* jkEndPointPort = "Port"; @@ -1178,7 +1171,7 @@ static const char* jkIntervalPhysiPlanInterval = "Interval"; static const char* jkIntervalPhysiPlanOffset = "Offset"; static const char* jkIntervalPhysiPlanSliding = "Sliding"; static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit"; -static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; +static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; static const char* jkIntervalPhysiPlanFill = "Fill"; static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { @@ -1331,13 +1324,9 @@ static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) { return jsonToNodeObject(pJson, jkDataSinkInputDataBlockDesc, (SNode**)&pNode->pInputDataBlockDesc); } -static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { - return physicDataSinkNodeToJson(pObj, pJson); -} +static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return physicDataSinkNodeToJson(pObj, pJson); } -static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { - return jsonToPhysicDataSinkNode(pJson, pObj); -} +static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { return jsonToPhysicDataSinkNode(pJson, pObj); } static const char* jkSubplanIdQueryId = "QueryId"; static const char* jkSubplanIdGroupId = "GroupId"; @@ -1663,7 +1652,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) { return code; } -static const char* jkValueGenByCalc = "GenByCalc"; +static const char* jkValueLiteralSize = "LiteralSize"; static const char* jkValueLiteral = "Literal"; static const char* jkValueDuration = "Duration"; static const char* jkValueTranslate = "Translate"; @@ -1709,7 +1698,7 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) { break; } - return code ; + return code; } static int32_t valueNodeToJson(const void* pObj, SJson* pJson) { @@ -1717,9 +1706,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) { int32_t code = exprNodeToJson(pObj, pJson); if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddBoolToObject(pJson, jkValueGenByCalc, pNode->genByCalc); + code = tjsonAddIntegerToObject(pJson, jkValueLiteralSize, NULL != pNode->literal ? strlen(pNode->literal) : 0); } - if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) { + if (TSDB_CODE_SUCCESS == code && NULL != pNode->literal) { code = tjsonAddStringToObject(pJson, jkValueLiteral, pNode->literal); } if (TSDB_CODE_SUCCESS == code) { @@ -1789,10 +1778,11 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) { SValueNode* pNode = (SValueNode*)pObj; int32_t code = jsonToExprNode(pJson, pObj); + int32_t literalSize = 0; if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBoolValue(pJson, jkValueGenByCalc, &pNode->genByCalc); + code = tjsonGetIntValue(pJson, jkValueLiteralSize, &literalSize); } - if (TSDB_CODE_SUCCESS == code && !pNode->genByCalc) { + if (TSDB_CODE_SUCCESS == code && literalSize > 0) { code = tjsonDupStringValue(pJson, jkValueLiteral, &pNode->literal); } if (TSDB_CODE_SUCCESS == code) { @@ -2014,7 +2004,8 @@ static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) { int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups); if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), pNode->numOfVgroups); + code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), + pNode->numOfVgroups); } return code; @@ -2380,6 +2371,7 @@ static const char* jkSelectStmtOrderBy = "OrderBy"; static const char* jkSelectStmtLimit = "Limit"; static const char* jkSelectStmtSlimit = "Slimit"; static const char* jkSelectStmtStmtName = "StmtName"; +static const char* jkSelectStmtHasAggFuncs = "HasAggFuncs"; static int32_t selectStmtTojson(const void* pObj, SJson* pJson) { const SSelectStmt* pNode = (const SSelectStmt*)pObj; @@ -2418,6 +2410,9 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddBoolToObject(pJson, jkSelectStmtHasAggFuncs, pNode->hasAggFuncs); + } return code; } @@ -2459,6 +2454,9 @@ static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBoolValue(pJson, jkSelectStmtHasAggFuncs, &pNode->hasAggFuncs); + } return code; } @@ -2659,10 +2657,10 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToPhysiTagScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: return jsonToPhysiTableScanNode(pJson, pObj); - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: return jsonToPhysiStreamScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: - return jsonToPhysiSysTableScanNode(pJson, pObj); + return jsonToPhysiSysTableScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return jsonToPhysiProjectNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_JOIN: diff --git a/source/libs/nodes/src/nodesEqualFuncs.c b/source/libs/nodes/src/nodesEqualFuncs.c index 4185754355ddfd98fc9c7243ab961ed727a8d4d4..bd1662db4c9984d1961071fd6ef6342afff142f9 100644 --- a/source/libs/nodes/src/nodesEqualFuncs.c +++ b/source/libs/nodes/src/nodesEqualFuncs.c @@ -15,32 +15,27 @@ #include "querynodes.h" -#define COMPARE_SCALAR_FIELD(fldname) \ - do { \ - if (a->fldname != b->fldname) \ - return false; \ - } while (0) - -#define COMPARE_STRING(a, b) \ - (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b)) - -#define COMPARE_STRING_FIELD(fldname) \ - do { \ - if (!COMPARE_STRING(a->fldname, b->fldname)) \ - return false; \ - } while (0) - -#define COMPARE_NODE_FIELD(fldname) \ - do { \ - if (!nodesEqualNode(a->fldname, b->fldname)) \ - return false; \ - } while (0) - -#define COMPARE_NODE_LIST_FIELD(fldname) \ - do { \ - if (!nodeNodeListEqual(a->fldname, b->fldname)) \ - return false; \ - } while (0) +#define COMPARE_SCALAR_FIELD(fldname) \ + do { \ + if (a->fldname != b->fldname) return false; \ + } while (0) + +#define COMPARE_STRING(a, b) (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b)) + +#define COMPARE_STRING_FIELD(fldname) \ + do { \ + if (!COMPARE_STRING(a->fldname, b->fldname)) return false; \ + } while (0) + +#define COMPARE_NODE_FIELD(fldname) \ + do { \ + if (!nodesEqualNode(a->fldname, b->fldname)) return false; \ + } while (0) + +#define COMPARE_NODE_LIST_FIELD(fldname) \ + do { \ + if (!nodeNodeListEqual(a->fldname, b->fldname)) return false; \ + } while (0) static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) { if (a == b) { @@ -55,7 +50,7 @@ static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) { return false; } - SNode* na, *nb; + SNode *na, *nb; FORBOTH(na, a, nb, b) { if (!nodesEqualNode(na, nb)) { return false; @@ -125,7 +120,7 @@ bool nodesEqualNode(const SNodeptr a, const SNodeptr b) { case QUERY_NODE_GROUPING_SET: case QUERY_NODE_ORDER_BY_EXPR: case QUERY_NODE_LIMIT: - return false; // todo + return false; // todo default: break; } diff --git a/source/libs/nodes/src/nodesToSQLFuncs.c b/source/libs/nodes/src/nodesToSQLFuncs.c index aa1336b59d849436e3dbac4072b462a8afb8a74d..3b129740e81b4743dbae25dd82da36ac2a49407e 100644 --- a/source/libs/nodes/src/nodesToSQLFuncs.c +++ b/source/libs/nodes/src/nodesToSQLFuncs.c @@ -21,9 +21,35 @@ #include "taoserror.h" #include "thash.h" -char *gOperatorStr[] = {NULL, "+", "-", "*", "/", "%", "-", "&", "|", ">", ">=", "<", "<=", "=", "<>", - "IN", "NOT IN", "LIKE", "NOT LIKE", "MATCH", "NMATCH", "IS NULL", "IS NOT NULL", - "IS TRUE", "IS FALSE", "IS UNKNOWN", "IS NOT TRUE", "IS NOT FALSE", "IS NOT UNKNOWN"}; +char *gOperatorStr[] = {NULL, + "+", + "-", + "*", + "/", + "%", + "-", + "&", + "|", + ">", + ">=", + "<", + "<=", + "=", + "<>", + "IN", + "NOT IN", + "LIKE", + "NOT LIKE", + "MATCH", + "NMATCH", + "IS NULL", + "IS NOT NULL", + "IS TRUE", + "IS FALSE", + "IS UNKNOWN", + "IS NOT TRUE", + "IS NOT FALSE", + "IS NOT UNKNOWN"}; char *gLogicConditionStr[] = {"AND", "OR", "NOT"}; int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { @@ -33,36 +59,36 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { if (colNode->dbName[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->dbName); } - + if (colNode->tableAlias[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableAlias); } else if (colNode->tableName[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`.", colNode->tableName); } - + if (colNode->tableAlias[0]) { *len += snprintf(buf + *len, bufSize - *len, "`%s`", colNode->colName); } else { *len += snprintf(buf + *len, bufSize - *len, "%s", colNode->colName); } - + return TSDB_CODE_SUCCESS; } - case QUERY_NODE_VALUE:{ + case QUERY_NODE_VALUE: { SValueNode *colNode = (SValueNode *)pNode; - char *t = nodesGetStrValueFromNode(colNode); + char *t = nodesGetStrValueFromNode(colNode); if (NULL == t) { nodesError("fail to get str value from valueNode"); NODES_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - + *len += snprintf(buf + *len, bufSize - *len, "%s", t); taosMemoryFree(t); - + return TSDB_CODE_SUCCESS; } case QUERY_NODE_OPERATOR: { - SOperatorNode* pOpNode = (SOperatorNode*)pNode; + SOperatorNode *pOpNode = (SOperatorNode *)pNode; *len += snprintf(buf + *len, bufSize - *len, "("); if (pOpNode->pLeft) { NODES_ERR_RET(nodesNodeToSQL(pOpNode->pLeft, buf, bufSize, len)); @@ -72,24 +98,24 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { nodesError("unknown operation type:%d", pOpNode->opType); NODES_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - + *len += snprintf(buf + *len, bufSize - *len, " %s ", gOperatorStr[pOpNode->opType]); if (pOpNode->pRight) { NODES_ERR_RET(nodesNodeToSQL(pOpNode->pRight, buf, bufSize, len)); - } + } *len += snprintf(buf + *len, bufSize - *len, ")"); return TSDB_CODE_SUCCESS; } - case QUERY_NODE_LOGIC_CONDITION:{ - SLogicConditionNode* pLogicNode = (SLogicConditionNode*)pNode; - SNode* node = NULL; - bool first = true; - + case QUERY_NODE_LOGIC_CONDITION: { + SLogicConditionNode *pLogicNode = (SLogicConditionNode *)pNode; + SNode *node = NULL; + bool first = true; + *len += snprintf(buf + *len, bufSize - *len, "("); - + FOREACH(node, pLogicNode->pParameterList) { if (!first) { *len += snprintf(buf + *len, bufSize - *len, " %s ", gLogicConditionStr[pLogicNode->condType]); @@ -102,13 +128,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { return TSDB_CODE_SUCCESS; } - case QUERY_NODE_FUNCTION:{ - SFunctionNode* pFuncNode = (SFunctionNode*)pNode; - SNode* node = NULL; - bool first = true; - + case QUERY_NODE_FUNCTION: { + SFunctionNode *pFuncNode = (SFunctionNode *)pNode; + SNode *node = NULL; + bool first = true; + *len += snprintf(buf + *len, bufSize - *len, "%s(", pFuncNode->functionName); - + FOREACH(node, pFuncNode->pParameterList) { if (!first) { *len += snprintf(buf + *len, bufSize - *len, ", "); @@ -121,13 +147,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { return TSDB_CODE_SUCCESS; } - case QUERY_NODE_NODE_LIST:{ - SNodeListNode* pListNode = (SNodeListNode *)pNode; - SNode* node = NULL; - bool first = true; - + case QUERY_NODE_NODE_LIST: { + SNodeListNode *pListNode = (SNodeListNode *)pNode; + SNode *node = NULL; + bool first = true; + *len += snprintf(buf + *len, bufSize - *len, "("); - + FOREACH(node, pListNode->pNodeList) { if (!first) { *len += snprintf(buf + *len, bufSize - *len, ", "); @@ -135,7 +161,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { NODES_ERR_RET(nodesNodeToSQL(node, buf, bufSize, len)); first = false; } - + *len += snprintf(buf + *len, bufSize - *len, ")"); return TSDB_CODE_SUCCESS; @@ -143,7 +169,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) { default: break; } - + nodesError("nodesNodeToSQL unknown node = %s", nodesNodeName(pNode->type)); NODES_RET(TSDB_CODE_QRY_APP_ERROR); } diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index e74ecfd0f4563f904ca73cba7b2681b41c45e548..84eccf85325083265025efaa156276f68fece4ff 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include "querynodes.h" #include "plannodes.h" +#include "querynodes.h" typedef enum ETraversalOrder { TRAVERSAL_PREORDER = 1, @@ -29,7 +29,8 @@ static EDealRes walkExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeWalk static EDealRes walkPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext); static EDealRes walkPhysiPlans(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext); -static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext, FNodeDispatcher dispatcher) { +static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext, + FNodeDispatcher dispatcher) { if (NULL == pNode) { return DEAL_RES_CONTINUE; } @@ -77,7 +78,7 @@ static EDealRes dispatchExpr(SNode* pNode, ETraversalOrder order, FNodeWalker wa break; case QUERY_NODE_REAL_TABLE: case QUERY_NODE_TEMP_TABLE: - break; // todo + break; // todo case QUERY_NODE_JOIN_TABLE: { SJoinTableNode* pJoinTableNode = (SJoinTableNode*)pNode; res = walkExpr(pJoinTableNode->pLeft, order, walker, pContext); @@ -217,7 +218,7 @@ static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewrit break; case QUERY_NODE_REAL_TABLE: case QUERY_NODE_TEMP_TABLE: - break; // todo + break; // todo case QUERY_NODE_JOIN_TABLE: { SJoinTableNode* pJoinTableNode = (SJoinTableNode*)pNode; res = rewriteExpr(&(pJoinTableNode->pLeft), order, rewriter, pContext); @@ -339,7 +340,7 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa case SQL_CLAUSE_DISTINCT: nodesWalkExprs(pSelect->pOrderByList, walker, pContext); case SQL_CLAUSE_ORDER_BY: - nodesWalkExprs(pSelect->pProjectionList, walker, pContext); + nodesWalkExprs(pSelect->pProjectionList, walker, pContext); default: break; } @@ -368,7 +369,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit case SQL_CLAUSE_DISTINCT: nodesRewriteExprs(pSelect->pOrderByList, rewriter, pContext); case SQL_CLAUSE_ORDER_BY: - nodesRewriteExprs(pSelect->pProjectionList, rewriter, pContext); + nodesRewriteExprs(pSelect->pProjectionList, rewriter, pContext); default: break; } @@ -395,7 +396,8 @@ static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNod return res; } -static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, void* pContext) { +static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, + void* pContext) { EDealRes res = walkScanPhysi((SScanPhysiNode*)pScan, order, walker, pContext); if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkPhysiPlans(pScan->pDynamicScanFuncs, order, walker, pContext); diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 6415c16db587754e77b29c193b23fca7280ef7a7..092d0f435d144e15eaf6f17c8b0f8c7baa3eb867 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -97,7 +97,7 @@ SNodeptr nodesMakeNode(ENodeType type) { case QUERY_NODE_CREATE_DATABASE_STMT: return makeNode(type, sizeof(SCreateDatabaseStmt)); case QUERY_NODE_DROP_DATABASE_STMT: - return makeNode(type, sizeof(SDropDatabaseStmt)); + return makeNode(type, sizeof(SDropDatabaseStmt)); case QUERY_NODE_ALTER_DATABASE_STMT: return makeNode(type, sizeof(SAlterDatabaseStmt)); case QUERY_NODE_CREATE_TABLE_STMT: @@ -298,9 +298,7 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) { nodesDestroyList(pNode->pScanCols); } -static void destroyDataSinkNode(SDataSinkNode* pNode) { - nodesDestroyNode(pNode->pInputDataBlockDesc); -} +static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode(pNode->pInputDataBlockDesc); } void nodesDestroyNode(SNodeptr pNode) { if (NULL == pNode) { @@ -308,7 +306,7 @@ void nodesDestroyNode(SNodeptr pNode) { } switch (nodeType(pNode)) { - case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release + case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release break; case QUERY_NODE_VALUE: { SValueNode* pValue = (SValueNode*)pNode; @@ -352,7 +350,7 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_ORDER_BY_EXPR: nodesDestroyNode(((SOrderByExprNode*)pNode)->pExpr); break; - case QUERY_NODE_LIMIT: // no pointer field + case QUERY_NODE_LIMIT: // no pointer field break; case QUERY_NODE_STATE_WINDOW: nodesDestroyNode(((SStateWindowNode*)pNode)->pExpr); @@ -387,9 +385,9 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_DATABLOCK_DESC: nodesDestroyList(((SDataBlockDescNode*)pNode)->pSlots); break; - case QUERY_NODE_SLOT_DESC: // no pointer field - case QUERY_NODE_COLUMN_DEF: // no pointer field - case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field + case QUERY_NODE_SLOT_DESC: // no pointer field + 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); @@ -436,7 +434,7 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_CREATE_DATABASE_STMT: nodesDestroyNode(((SCreateDatabaseStmt*)pNode)->pOptions); break; - case QUERY_NODE_DROP_DATABASE_STMT: // no pointer field + case QUERY_NODE_DROP_DATABASE_STMT: // no pointer field break; case QUERY_NODE_ALTER_DATABASE_STMT: nodesDestroyNode(((SAlterDatabaseStmt*)pNode)->pOptions); @@ -457,12 +455,12 @@ void nodesDestroyNode(SNodeptr pNode) { case QUERY_NODE_CREATE_MULTI_TABLE_STMT: nodesDestroyList(((SCreateMultiTableStmt*)pNode)->pSubTables); break; - case QUERY_NODE_DROP_TABLE_CLAUSE: // no pointer field + case QUERY_NODE_DROP_TABLE_CLAUSE: // no pointer field break; case QUERY_NODE_DROP_TABLE_STMT: nodesDestroyNode(((SDropTableStmt*)pNode)->pTables); break; - case QUERY_NODE_DROP_SUPER_TABLE_STMT: // no pointer field + case QUERY_NODE_DROP_SUPER_TABLE_STMT: // no pointer field break; case QUERY_NODE_ALTER_TABLE_STMT: { SAlterTableStmt* pStmt = (SAlterTableStmt*)pNode; @@ -470,13 +468,13 @@ void nodesDestroyNode(SNodeptr pNode) { nodesDestroyNode(pStmt->pVal); break; } - case QUERY_NODE_CREATE_USER_STMT: // no pointer field - case QUERY_NODE_ALTER_USER_STMT: // no pointer field - case QUERY_NODE_DROP_USER_STMT: // no pointer field - case QUERY_NODE_USE_DATABASE_STMT: // no pointer field - case QUERY_NODE_CREATE_DNODE_STMT: // no pointer field - case QUERY_NODE_DROP_DNODE_STMT: // no pointer field - case QUERY_NODE_ALTER_DNODE_STMT: // no pointer field + case QUERY_NODE_CREATE_USER_STMT: // no pointer field + case QUERY_NODE_ALTER_USER_STMT: // no pointer field + case QUERY_NODE_DROP_USER_STMT: // no pointer field + case QUERY_NODE_USE_DATABASE_STMT: // no pointer field + case QUERY_NODE_CREATE_DNODE_STMT: // no pointer field + case QUERY_NODE_DROP_DNODE_STMT: // no pointer field + case QUERY_NODE_ALTER_DNODE_STMT: // no pointer field break; case QUERY_NODE_CREATE_INDEX_STMT: { SCreateIndexStmt* pStmt = (SCreateIndexStmt*)pNode; @@ -484,15 +482,15 @@ void nodesDestroyNode(SNodeptr pNode) { nodesDestroyList(pStmt->pCols); break; } - case QUERY_NODE_DROP_INDEX_STMT: // no pointer field - case QUERY_NODE_CREATE_QNODE_STMT: // no pointer field - case QUERY_NODE_DROP_QNODE_STMT: // no pointer field + case QUERY_NODE_DROP_INDEX_STMT: // no pointer field + case QUERY_NODE_CREATE_QNODE_STMT: // no pointer field + case QUERY_NODE_DROP_QNODE_STMT: // no pointer field break; case QUERY_NODE_CREATE_TOPIC_STMT: nodesDestroyNode(((SCreateTopicStmt*)pNode)->pQuery); break; - case QUERY_NODE_DROP_TOPIC_STMT: // no pointer field - case QUERY_NODE_ALTER_LOCAL_STMT: // no pointer field + case QUERY_NODE_DROP_TOPIC_STMT: // no pointer field + case QUERY_NODE_ALTER_LOCAL_STMT: // no pointer field break; case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_TABLES_STMT: @@ -658,7 +656,7 @@ void nodesDestroyNode(SNodeptr pNode) { SQueryPlan* pPlan = (SQueryPlan*)pNode; if (NULL != pPlan->pSubplans) { // only need to destroy the top-level subplans, because they will recurse to all the subplans below - bool first = true; + bool first = true; SNode* pElement = NULL; FOREACH(pElement, pPlan->pSubplans) { if (first) { @@ -866,7 +864,7 @@ void nodesClearList(SNodeList* pList) { taosMemoryFreeClear(pList); } -void* nodesGetValueFromNode(SValueNode *pNode) { +void* nodesGetValueFromNode(SValueNode* pNode) { switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_BOOL: return (void*)&pNode->datum.b; @@ -895,10 +893,10 @@ void* nodesGetValueFromNode(SValueNode *pNode) { return NULL; } -char* nodesGetStrValueFromNode(SValueNode *pNode) { +char* nodesGetStrValueFromNode(SValueNode* pNode) { switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_BOOL: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -911,7 +909,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -923,7 +921,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -933,7 +931,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { } case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: { - void *buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); + void* buf = taosMemoryMalloc(MAX_NUM_STR_SIZE); if (NULL == buf) { return NULL; } @@ -945,7 +943,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: { int32_t bufSize = varDataLen(pNode->datum.p) + 2 + 1; - void *buf = taosMemoryMalloc(bufSize); + void* buf = taosMemoryMalloc(bufSize); if (NULL == buf) { return NULL; } @@ -962,7 +960,8 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) { bool nodesIsExprNode(const SNode* pNode) { ENodeType type = nodeType(pNode); - return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || QUERY_NODE_FUNCTION == type); + return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || + QUERY_NODE_FUNCTION == type); } bool nodesIsUnaryOp(const SOperatorNode* pOp) { @@ -1037,23 +1036,19 @@ bool nodesIsJsonOp(const SOperatorNode* pOp) { return false; } -bool nodesIsTimeorderQuery(const SNode* pQuery) { - return false; -} +bool nodesIsTimeorderQuery(const SNode* pQuery) { return false; } -bool nodesIsTimelineQuery(const SNode* pQuery) { - return false; -} +bool nodesIsTimelineQuery(const SNode* pQuery) { return false; } typedef struct SCollectColumnsCxt { - int32_t errCode; + int32_t errCode; const char* pTableAlias; - SNodeList* pCols; - SHashObj* pColHash; + SNodeList* pCols; + SHashObj* pColHash; } SCollectColumnsCxt; static EDealRes doCollect(SCollectColumnsCxt* pCxt, SColumnNode* pCol, SNode* pNode) { - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; int32_t len = 0; if ('\0' == pCol->tableAlias[0]) { len = sprintf(name, "%s", pCol->colName); @@ -1086,11 +1081,10 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* } SCollectColumnsCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .pTableAlias = pTableAlias, - .pCols = nodesMakeList(), - .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK) - }; + .errCode = TSDB_CODE_SUCCESS, + .pTableAlias = pTableAlias, + .pCols = nodesMakeList(), + .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; } @@ -1110,9 +1104,9 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* } typedef struct SCollectFuncsCxt { - int32_t errCode; + int32_t errCode; FFuncClassifier classifier; - SNodeList* pFuncs; + SNodeList* pFuncs; } SCollectFuncsCxt; static EDealRes collectFuncs(SNode* pNode, void* pContext) { @@ -1129,11 +1123,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod return TSDB_CODE_SUCCESS; } - SCollectFuncsCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .classifier = classifier, - .pFuncs = nodesMakeList() - }; + SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .classifier = classifier, .pFuncs = nodesMakeList()}; if (NULL == cxt.pFuncs) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1148,12 +1138,11 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod nodesDestroyList(cxt.pFuncs); *pFuncs = NULL; } - + return TSDB_CODE_SUCCESS; } - -char *getFillModeString(EFillMode mode) { +char* getFillModeString(EFillMode mode) { switch (mode) { case FILL_MODE_NONE: return "none"; @@ -1172,12 +1161,12 @@ char *getFillModeString(EFillMode mode) { } } -char *nodesGetNameFromColumnNode(SNode *pNode) { +char* nodesGetNameFromColumnNode(SNode* pNode) { if (NULL == pNode || QUERY_NODE_COLUMN != pNode->type) { return "NULL"; } - - return ((SColumnNode *)pNode)->colName; + + return ((SColumnNode*)pNode)->colName; } int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) { @@ -1185,14 +1174,14 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) { return 0; } - SNode* pNode = NULL; + SNode* pNode = NULL; int32_t num = 0; FOREACH(pNode, pSlots) { if (QUERY_NODE_SLOT_DESC != pNode->type) { continue; } - SSlotDescNode *descNode = (SSlotDescNode *)pNode; + SSlotDescNode* descNode = (SSlotDescNode*)pNode; if (descNode->output) { ++num; } @@ -1201,13 +1190,12 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) { return num; } - void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) { pVal->nType = pNode->node.resType.type; pVal->nLen = pNode->node.resType.bytes; switch (pNode->node.resType.type) { case TSDB_DATA_TYPE_NULL: - break; + break; case TSDB_DATA_TYPE_BOOL: pVal->i = pNode->datum.b; break; @@ -1241,6 +1229,3 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) { break; } } - - - diff --git a/source/libs/nodes/test/nodesTest.cpp b/source/libs/nodes/test/nodesTest.cpp index fdfb9522dbed5a38759962b0640fa320bda783d2..0515e8bbc0ae1319042f868b4d70315cc1e31b9c 100644 --- a/source/libs/nodes/test/nodesTest.cpp +++ b/source/libs/nodes/test/nodesTest.cpp @@ -20,42 +20,42 @@ using namespace std; static EDealRes rewriterTest(SNode** pNode, void* pContext) { - EDealRes* pRes = (EDealRes*)pContext; - if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { - SOperatorNode* pOp = (SOperatorNode*)(*pNode); - if (QUERY_NODE_VALUE != nodeType(pOp->pLeft) || QUERY_NODE_VALUE != nodeType(pOp->pRight)) { - *pRes = DEAL_RES_ERROR; - } - SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); - string tmp = to_string(stoi(((SValueNode*)(pOp->pLeft))->literal) + stoi(((SValueNode*)(pOp->pRight))->literal)); - pVal->literal = strdup(tmp.c_str()); - nodesDestroyNode(*pNode); - *pNode = (SNode*)pVal; - } - return DEAL_RES_CONTINUE; + EDealRes* pRes = (EDealRes*)pContext; + if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { + SOperatorNode* pOp = (SOperatorNode*)(*pNode); + if (QUERY_NODE_VALUE != nodeType(pOp->pLeft) || QUERY_NODE_VALUE != nodeType(pOp->pRight)) { + *pRes = DEAL_RES_ERROR; + } + SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + string tmp = to_string(stoi(((SValueNode*)(pOp->pLeft))->literal) + stoi(((SValueNode*)(pOp->pRight))->literal)); + pVal->literal = strdup(tmp.c_str()); + nodesDestroyNode(*pNode); + *pNode = (SNode*)pVal; + } + return DEAL_RES_CONTINUE; } TEST(NodesTest, traverseTest) { - SNode* pRoot = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); - SOperatorNode* pOp = (SOperatorNode*)pRoot; - SOperatorNode* pLeft = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR); - pLeft->pLeft = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); - ((SValueNode*)(pLeft->pLeft))->literal = strdup("10"); - pLeft->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); - ((SValueNode*)(pLeft->pRight))->literal = strdup("5"); - pOp->pLeft = (SNode*)pLeft; - pOp->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); - ((SValueNode*)(pOp->pRight))->literal = strdup("3"); + SNode* pRoot = (SNode*)nodesMakeNode(QUERY_NODE_OPERATOR); + SOperatorNode* pOp = (SOperatorNode*)pRoot; + SOperatorNode* pLeft = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR); + pLeft->pLeft = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); + ((SValueNode*)(pLeft->pLeft))->literal = strdup("10"); + pLeft->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); + ((SValueNode*)(pLeft->pRight))->literal = strdup("5"); + pOp->pLeft = (SNode*)pLeft; + pOp->pRight = (SNode*)nodesMakeNode(QUERY_NODE_VALUE); + ((SValueNode*)(pOp->pRight))->literal = strdup("3"); - EXPECT_EQ(nodeType(pRoot), QUERY_NODE_OPERATOR); - EDealRes res = DEAL_RES_CONTINUE; - nodesRewriteExprPostOrder(&pRoot, rewriterTest, &res); - EXPECT_EQ(res, DEAL_RES_CONTINUE); - EXPECT_EQ(nodeType(pRoot), QUERY_NODE_VALUE); - EXPECT_EQ(string(((SValueNode*)pRoot)->literal), "18"); + EXPECT_EQ(nodeType(pRoot), QUERY_NODE_OPERATOR); + EDealRes res = DEAL_RES_CONTINUE; + nodesRewriteExprPostOrder(&pRoot, rewriterTest, &res); + EXPECT_EQ(res, DEAL_RES_CONTINUE); + EXPECT_EQ(nodeType(pRoot), QUERY_NODE_VALUE); + EXPECT_EQ(string(((SValueNode*)pRoot)->literal), "18"); } int main(int argc, char* argv[]) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index f4e206af9df7981a5e5c9bddec5cb8927c0c0ae7..f885508374806fbf38537e125003d14e2b1b9d70 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -21,18 +21,18 @@ extern "C" { #endif #include "cmdnodes.h" -#include "parser.h" #include "parToken.h" #include "parUtil.h" +#include "parser.h" #include "querynodes.h" typedef struct SAstCreateContext { SParseContext* pQueryCxt; - SMsgBuf msgBuf; - bool notSupport; - bool valid; - SNode* pRootNode; - int16_t placeholderNo; + SMsgBuf msgBuf; + bool notSupport; + bool valid; + SNode* pRootNode; + int16_t placeholderNo; } SAstCreateContext; typedef enum EDatabaseOptionType { @@ -67,9 +67,9 @@ typedef enum ETableOptionType { } ETableOptionType; typedef struct SAlterOption { - int32_t type; + int32_t type; SValueNode* pVal; - SNodeList* pList; + SNodeList* pList; } SAlterOption; extern SToken nil_token; @@ -95,7 +95,6 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList); -SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName); SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt); SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList); SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2); @@ -106,7 +105,8 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder); SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap); SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr); -SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill); +SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, + SNode* pFill); SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues); SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode); @@ -121,26 +121,30 @@ 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); +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* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags); +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); 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* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType); +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); -SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName); +SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, + const SToken* pOldColName, const SToken* pNewColName); SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern); @@ -152,13 +156,15 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName); SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort); SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode); SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue); -SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions); +SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, + SToken* pTableName, SNodeList* pCols, SNode* pOptions); SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding); SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName); SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId); SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId); SNode* createTopicOptions(SAstCreateContext* pCxt); -SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions); +SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, + const SToken* pSubscribeDbName, SNode* pOptions); SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName); SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue); SNode* createDefaultExplainOptions(SAstCreateContext* pCxt); @@ -168,10 +174,12 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable); SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt); 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); +SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, + const SToken* pLibPath, SDataType dataType, int32_t bufSize); SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName); SNode* createStreamOptions(SAstCreateContext* pCxt); -SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery); +SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, + SNode* pOptions, SNode* pQuery); SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName); SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId); SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2); diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index ed7267655c61f9cf3cec9297d0f3bd33b1a67eaf..02be32a49e1ad41ee5314db20da302e661f8bf6d 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -18,8 +18,8 @@ #include "catalog.h" #include "os.h" -#include "ttypes.h" #include "tname.h" +#include "ttypes.h" #define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED) @@ -52,8 +52,8 @@ typedef struct SParsedDataColInfo { uint16_t flen; // TODO: get from STSchema uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow) uint16_t extendedVarLen; - uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part) - col_id_t *boundColumns; // bound column idx according to schema + uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part) + col_id_t *boundColumns; // bound column idx according to schema SBoundColumn *cols; SBoundIdxInfo *colIdxInfo; int8_t orderStatus; // bound columns @@ -72,12 +72,13 @@ typedef struct STableDataBlocks { int32_t numOfTables; // number of tables in current submit block int32_t rowSize; // row size for current table uint32_t nAllocSize; - uint32_t headerSize; // header for table info (uid, tid, submit metadata) + uint32_t headerSize; // header for table info (uid, tid, submit metadata) uint32_t size; - STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache - char *pData; - bool cloned; - int32_t createTbReqLen; + STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to + // avoid to be removed from cache + char *pData; + bool cloned; + int32_t createTbReqLen; SParsedDataColInfo boundColumnInfo; SRowBuilder rowBuilder; } STableDataBlocks; @@ -89,8 +90,8 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) { (int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1); } -static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, - int32_t *toffset, col_id_t *colIdx) { +static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset, + col_id_t *colIdx) { col_id_t schemaIdx = 0; if (IS_DATA_COL_ORDERED(spd)) { schemaIdx = spd->boundColumns[idx] - PRIMARYKEY_TIMESTAMP_COL_ID; @@ -114,8 +115,9 @@ static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo } } -static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks* dataBuf, int32_t numOfRows) { - pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid); +static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows) { + pBlocks->suid = + (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid); pBlocks->uid = dataBuf->pTableMeta->uid; pBlocks->sversion = dataBuf->pTableMeta->sversion; pBlocks->schemaLen = dataBuf->createTbReqLen; @@ -131,14 +133,15 @@ static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks* int32_t schemaIdxCompar(const void *lhs, const void *rhs); int32_t boundIdxCompar(const void *lhs, const void *rhs); void setBoundColumnInfo(SParsedDataColInfo *pColList, SSchema *pSchema, col_id_t numOfCols); -void destroyBlockArrayList(SArray* pDataBlockList); -void destroyBlockHashmap(SHashObj* pDataBlockHash); -int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo); -int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t * numOfRows); -int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq); -int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** pVgDataBlocks); -int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq); +void destroyBlockArrayList(SArray *pDataBlockList); +void destroyBlockHashmap(SHashObj *pDataBlockHash); +int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo); +int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t *numOfRows); +int32_t getDataBlockFromList(SHashObj *pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, + const STableMeta *pTableMeta, STableDataBlocks **dataBlocks, SArray *pBlockList, + SVCreateTbReq *pCreateTbReq); +int32_t mergeTableDataBlocks(SHashObj *pHashObj, uint8_t payloadType, SArray **pVgDataBlocks); +int32_t buildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq); int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize); #endif // TDENGINE_DATABLOCKMGT_H diff --git a/source/libs/parser/inc/parInt.h b/source/libs/parser/inc/parInt.h index 87348e292ebb1cc92a2fed126e4976ebd9e4da9b..7641b6951eb53f56fa200f7e673ff96068c2efae 100644 --- a/source/libs/parser/inc/parInt.h +++ b/source/libs/parser/inc/parInt.h @@ -20,9 +20,9 @@ extern "C" { #endif -#include "parser.h" #include "parToken.h" #include "parUtil.h" +#include "parser.h" int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery); diff --git a/source/libs/parser/inc/parToken.h b/source/libs/parser/inc/parToken.h index d8a2c22fd8a29cd00673f8a71277dab58a430aa9..787abf287e3bcf4f42e505d40bea0b7230cfc7e7 100644 --- a/source/libs/parser/inc/parToken.h +++ b/source/libs/parser/inc/parToken.h @@ -20,6 +20,8 @@ extern "C" { #endif +#include "os.h" + #include "ttokendef.h" // used to denote the minimum unite in sql parsing @@ -35,7 +37,7 @@ typedef struct SToken { * @return */ #define isNumber(tk) \ -((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_NK_HEX || (tk)->type == TK_NK_BIN) + ((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_NK_HEX || (tk)->type == TK_NK_BIN) /** * tokenizer for sql string @@ -68,12 +70,12 @@ bool taosIsKeyWordToken(const char *z, int32_t len); * @param pToken * @return token type, if it is not a number, TK_NK_ILLEGAL will return */ -static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { - const char* z = pToken->z; - int32_t type = TK_NK_ILLEGAL; +static FORCE_INLINE int32_t tGetNumericStringType(const SToken *pToken) { + const char *z = pToken->z; + int32_t type = TK_NK_ILLEGAL; uint32_t i = 0; - for(; i < pToken->n; ++i) { + for (; i < pToken->n; ++i) { switch (z[i]) { case '+': case '-': { @@ -86,7 +88,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { * .123 * .123e4 */ - if (!isdigit(z[i+1])) { + if (!isdigit(z[i + 1])) { return TK_NK_ILLEGAL; } @@ -107,13 +109,13 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { case '0': { char next = z[i + 1]; - if (next == 'b') { // bin number + if (next == 'b') { // bin number type = TK_NK_BIN; for (i += 2; (z[i] == '0' || z[i] == '1'); ++i) { } goto _end; - } else if (next == 'x') { //hex number + } else if (next == 'x') { // hex number type = TK_NK_HEX; for (i += 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) { } @@ -167,15 +169,15 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) { } } - _end: - return (i < pToken->n)? TK_NK_ILLEGAL:type; +_end: + return (i < pToken->n) ? TK_NK_ILLEGAL : type; } void taosCleanupKeywordsTable(); -SToken tscReplaceStrToken(char **str, SToken *token, const char* newToken); +SToken tscReplaceStrToken(char **str, SToken *token, const char *newToken); -SToken taosTokenDup(SToken* pToken, char* buf, int32_t len); +SToken taosTokenDup(SToken *pToken, char *buf, int32_t len); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/parUtil.h b/source/libs/parser/inc/parUtil.h index 460a089802a2629f38abbb56100d95298c6ac6f1..62d197d61169f89de73eb73346b3e756e9839931 100644 --- a/source/libs/parser/inc/parUtil.h +++ b/source/libs/parser/inc/parUtil.h @@ -23,31 +23,31 @@ extern "C" { #include "os.h" #include "query.h" -#define parserFatal(param, ...) qFatal("PARSER: " param, __VA_ARGS__) -#define parserError(param, ...) qError("PARSER: " param, __VA_ARGS__) -#define parserWarn(param, ...) qWarn("PARSER: " param, __VA_ARGS__) -#define parserInfo(param, ...) qInfo("PARSER: " param, __VA_ARGS__) -#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__) -#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__) +#define parserFatal(param, ...) qFatal("PARSER: " param, __VA_ARGS__) +#define parserError(param, ...) qError("PARSER: " param, __VA_ARGS__) +#define parserWarn(param, ...) qWarn("PARSER: " param, __VA_ARGS__) +#define parserInfo(param, ...) qInfo("PARSER: " param, __VA_ARGS__) +#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__) +#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__) #define PK_TS_COL_INTERNAL_NAME "_rowts" typedef struct SMsgBuf { int32_t len; - char *buf; + char* buf; } SMsgBuf; int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...); int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg); -int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr); +int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr); -STableMeta* tableMetaDup(const STableMeta* pTableMeta); -SSchema *getTableColumnSchema(const STableMeta *pTableMeta); -SSchema *getTableTagSchema(const STableMeta* pTableMeta); -int32_t getNumOfColumns(const STableMeta* pTableMeta); -int32_t getNumOfTags(const STableMeta* pTableMeta); +STableMeta* tableMetaDup(const STableMeta* pTableMeta); +SSchema* getTableColumnSchema(const STableMeta* pTableMeta); +SSchema* getTableTagSchema(const STableMeta* pTableMeta); +int32_t getNumOfColumns(const STableMeta* pTableMeta); +int32_t getNumOfTags(const STableMeta* pTableMeta); STableComInfo getTableInfo(const STableMeta* pTableMeta); -int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* errMsg, int16_t startColId); +int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* errMsg, int16_t startColId); int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 20e470bd1dbe1fcba1e72fc50d9f76025a4fad80..42fd77ac1ac99afbfea9867b05aa268b02217564 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -498,6 +498,7 @@ signed_literal(A) ::= NK_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) ::= literal_func(B). { A = releaseRawExprNode(pCxt, B); } %type literal_list { SNodeList* } %destructor literal_list { nodesDestroyList($$); } @@ -610,8 +611,10 @@ pseudo_column(A) ::= WDURATION(B). function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } function_expression(A) ::= star_func(B) NK_LP star_func_para_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } function_expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); } -function_expression(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNodeNoArg(pCxt, &B)); } -//function_expression(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +function_expression(A) ::= literal_func(B). { A = B; } + +literal_func(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNode(pCxt, &B, NULL)); } +literal_func(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } %type noarg_func { SToken } %destructor noarg_func { } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index cbd57595bb89b80a2e64081d3b3f33a10c5e96a8..4c8c33dd0ab3c13916c5d61f11844f08a1310e88 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -18,24 +18,24 @@ #include "parUtil.h" #include "ttime.h" -#define CHECK_OUT_OF_MEM(p) \ - do { \ - if (NULL == (p)) { \ - pCxt->valid = false; \ +#define CHECK_OUT_OF_MEM(p) \ + do { \ + if (NULL == (p)) { \ + pCxt->valid = false; \ snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \ - return NULL; \ - } \ + return NULL; \ + } \ } while (0) -#define CHECK_RAW_EXPR_NODE(node) \ - do { \ +#define CHECK_RAW_EXPR_NODE(node) \ + do { \ if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \ - pCxt->valid = false; \ - return NULL; \ - } \ + pCxt->valid = false; \ + return NULL; \ + } \ } while (0) -SToken nil_token = { .type = TK_NK_NIL, .n = 0, .z = NULL }; +SToken nil_token = {.type = TK_NK_NIL, .n = 0, .z = NULL}; void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { pCxt->pQueryCxt = pParseCxt; @@ -90,7 +90,7 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* pFqdn, int32_t* pPort) { if (NULL == pEp) { pCxt->valid = false; - } else if (pEp->n >= TSDB_FQDN_LEN + 2 + 6) { // format 'fqdn:port' + } 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; } else { @@ -206,7 +206,7 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { CHECK_RAW_EXPR_NODE(pNode); SRawExprNode* pRawExpr = (SRawExprNode*)pNode; - SNode* pExpr = pRawExpr->pNode; + SNode* pExpr = pRawExpr->pNode; if (nodesIsExprNode(pExpr)) { int32_t len = TMIN(sizeof(((SExprNode*)pExpr)->aliasName) - 1, pRawExpr->n); strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, len); @@ -222,7 +222,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { return nil_token; } SRawExprNode* target = (SRawExprNode*)pNode; - SToken t = { .type = 0, .z = target->p, .n = target->n}; + SToken t = {.type = 0, .z = target->p, .n = target->n}; return t; } @@ -352,12 +352,13 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) { return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, - createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight)); + createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), + createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight)); } SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) { - return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, - createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight)); + return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), + createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight)); } SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) { @@ -368,39 +369,6 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod return (SNode*)func; } -SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName) { - SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); - CHECK_OUT_OF_MEM(func); - char buf[64] = {0}; - - int32_t dataType; - switch (pFuncName->type) { - case TK_NOW: { - int64_t ts = taosGetTimestamp(TSDB_TIME_PRECISION_MILLI); - snprintf(buf, sizeof(buf), "%"PRId64, ts); - dataType = TSDB_DATA_TYPE_BIGINT; - break; - } - case TK_TODAY: { - int64_t ts = taosGetTimestampToday(TSDB_TIME_PRECISION_MILLI); - snprintf(buf, sizeof(buf), "%"PRId64, ts); - dataType = TSDB_DATA_TYPE_BIGINT; - break; - } - case TK_TIMEZONE: { - strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr)); - dataType = TSDB_DATA_TYPE_BINARY; - break; - } - } - SToken token = {.type = pFuncName->type, .n = strlen(buf), .z = buf}; - - SNodeList *pParameterList = createNodeList(pCxt, createValueNode(pCxt, dataType, &token)); - strncpy(func->functionName, pFuncName->z, pFuncName->n); - func->pParameterList = pParameterList; - return (SNode*)func; -} - SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) { SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); CHECK_OUT_OF_MEM(func); @@ -444,9 +412,6 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa strncpy(realTable->table.tableAlias, pTableName->z, pTableName->n); } strncpy(realTable->table.tableName, pTableName->z, pTableName->n); - if (NULL != pCxt->pQueryCxt->db) { - strcpy(realTable->useDbName, pCxt->pQueryCxt->db); - } return (SNode*)realTable; } @@ -519,7 +484,8 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) { return (SNode*)state; } -SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill) { +SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, + SNode* pFill) { SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW); CHECK_OUT_OF_MEM(interval); interval->pCol = nodesMakeNode(QUERY_NODE_COLUMN); @@ -785,17 +751,17 @@ SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType } SDataType createDataType(uint8_t type) { - SDataType dt = { .type = type, .precision = 0, .scale = 0, .bytes = tDataTypes[type].bytes }; + SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = tDataTypes[type].bytes}; return dt; } SDataType createVarLenDataType(uint8_t type, const SToken* pLen) { - SDataType dt = { .type = type, .precision = 0, .scale = 0, .bytes = strtol(pLen->z, NULL, 10) }; + SDataType dt = {.type = type, .precision = 0, .scale = 0, .bytes = strtol(pLen->z, NULL, 10)}; return dt; } -SNode* createCreateTableStmt(SAstCreateContext* pCxt, - bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions) { +SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, + SNodeList* pTags, SNode* pOptions) { if (NULL == pRealTable) { return NULL; } @@ -811,8 +777,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, return (SNode*)pStmt; } -SNode* createCreateSubTableClause(SAstCreateContext* pCxt, - bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags) { +SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, + SNodeList* pSpecificTags, SNodeList* pValsOfTags) { if (NULL == pRealTable) { return NULL; } @@ -878,7 +844,8 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* return (SNode*)pStmt; } -SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType) { +SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, + const SToken* pColName, SDataType dataType) { if (NULL == pRealTable) { return NULL; } @@ -901,7 +868,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_ return (SNode*)pStmt; } -SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName) { +SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, + const SToken* pOldColName, const SToken* pNewColName) { if (NULL == pRealTable) { return NULL; } @@ -936,7 +904,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) { } static bool needDbShowStmt(ENodeType type) { - return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type || QUERY_NODE_SHOW_VGROUPS_STMT == type; + return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type || + QUERY_NODE_SHOW_VGROUPS_STMT == type; } SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) { @@ -945,7 +914,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S pCxt->valid = false; return NULL; } - SShowStmt* pStmt = nodesMakeNode(type);; + SShowStmt* pStmt = nodesMakeNode(type); + ; CHECK_OUT_OF_MEM(pStmt); pStmt->pDbName = pDbName; pStmt->pTbNamePattern = pTbNamePattern; @@ -1007,7 +977,7 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) { SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort) { int32_t port = 0; - char fqdn[TSDB_FQDN_LEN] = {0}; + char fqdn[TSDB_FQDN_LEN] = {0}; if (NULL == pPort) { if (!checkAndSplitEndpoint(pCxt, pFqdn, fqdn, &port)) { return NULL; @@ -1040,7 +1010,8 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) { return (SNode*)pStmt; } -SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue) { +SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, + const SToken* pValue) { SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->dnodeId = strtol(pDnode->z, NULL, 10); @@ -1051,7 +1022,8 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const return (SNode*)pStmt; } -SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions) { +SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, + SToken* pTableName, SNodeList* pCols, SNode* pOptions) { if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) { return NULL; } @@ -1066,7 +1038,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno return (SNode*)pStmt; } -SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding) { +SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, + SNode* pSliding) { SIndexOptions* pOptions = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS); CHECK_OUT_OF_MEM(pOptions); pOptions->pFuncs = pFuncs; @@ -1091,14 +1064,16 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) { SCreateComponentNodeStmt* pStmt = nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); - pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);; + pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10); + ; return (SNode*)pStmt; } SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) { SDropComponentNodeStmt* pStmt = nodesMakeNode(type); CHECK_OUT_OF_MEM(pStmt); - pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);; + pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10); + ; return (SNode*)pStmt; } @@ -1111,8 +1086,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) { return (SNode*)pOptions; } -SNode* createCreateTopicStmt(SAstCreateContext* pCxt, - bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions) { +SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, + const SToken* pSubscribeDbName, SNode* pOptions) { SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT); CHECK_OUT_OF_MEM(pStmt); strncpy(pStmt->topicName, pTopicName->z, pTopicName->n); @@ -1194,8 +1169,8 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) { return pStmt; } -SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, - bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize) { +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; return NULL; @@ -1224,7 +1199,8 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) { return (SNode*)pOptions; } -SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery) { +SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, + SNode* pOptions, SNode* pQuery) { SCreateStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT); CHECK_OUT_OF_MEM(pStmt); strncpy(pStmt->streamName, pStreamName->z, pStreamName->n); diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index fcc15b197f238d268a4789903ace235eab5fc001..723ad577f4e7b439e21a7506ed6e9c74b5fa64a9 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -23,14 +23,14 @@ typedef void* (*FMalloc)(size_t); typedef void (*FFree)(void*); extern void* ParseAlloc(FMalloc); -extern void Parse(void*, int, SToken, void*); -extern void ParseFree(void*, FFree); -extern void ParseTrace(FILE*, char*); +extern void Parse(void*, int, SToken, void*); +extern void ParseFree(void*, FFree); +extern void ParseTrace(FILE*, char*); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) { SAstCreateContext cxt; initAstCreateContext(pParseCxt, &cxt); - void *pParser = ParseAlloc((FMalloc)taosMemoryMalloc); + void* pParser = ParseAlloc((FMalloc)taosMemoryMalloc); int32_t i = 0; while (1) { SToken t0 = {0}; @@ -38,8 +38,8 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) { Parse(pParser, 0, t0, &cxt); goto abort_parse; } - t0.n = tGetToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type); - t0.z = (char *)(cxt.pQueryCxt->pSql + i); + t0.n = tGetToken((char*)&cxt.pQueryCxt->pSql[i], &t0.type); + t0.z = (char*)(cxt.pQueryCxt->pSql + i); i += t0.n; switch (t0.type) { diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 51e0daf4adfeeb273112d3e88bcd31d43daf1408..d0e670df6e71cffa8136040fd4e9af81d0e45bc9 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -20,113 +20,41 @@ typedef struct SCalcConstContext { SParseContext* pParseCxt; - SMsgBuf msgBuf; - int32_t code; + SMsgBuf msgBuf; + int32_t code; } SCalcConstContext; -static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt); +static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery); -static EDealRes doCalcConst(SNode** pNode, SCalcConstContext* pCxt) { - SNode* pNew = NULL; - pCxt->code = scalarCalculateConstants(*pNode, &pNew); - if (TSDB_CODE_SUCCESS != pCxt->code) { - return DEAL_RES_ERROR; - } - ((SValueNode*)pNew)->genByCalc = true; - ((SValueNode*)pNew)->translate = true; - *pNode = pNew; - return DEAL_RES_CONTINUE; -} - -static bool isTimestampCol(SNode* pNode) { - if (NULL == pNode) { - return false; - } - return (QUERY_NODE_COLUMN == nodeType(pNode) && TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode*)pNode)->resType.type); +static int32_t calcConstSubquery(SCalcConstContext* pCxt, STempTableNode* pTempTable) { + return calcConstQuery(pCxt, pTempTable->pSubquery, true); } -static EDealRes stringToTimestamp(SCalcConstContext* pCxt, uint8_t precision, SValueNode* pVal) { - switch (pVal->node.resType.type) { - case TSDB_DATA_TYPE_VARCHAR: - case TSDB_DATA_TYPE_NCHAR: - case TSDB_DATA_TYPE_VARBINARY: { - int64_t val = 0; - if (TSDB_CODE_SUCCESS != convertStringToTimestamp(pVal->node.resType.type, pVal->datum.p, precision, &val)) { - pCxt->code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCORRECT_TIMESTAMP_VAL, varDataVal(pVal->datum.p)); - return DEAL_RES_ERROR; - } - pVal->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP; - pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; - taosMemoryFreeClear(pVal->datum.p); - pVal->datum.i = val; - break; - } - default: - break; - } - return DEAL_RES_CONTINUE; -} - -static EDealRes calcConstOperator(SOperatorNode** pNode, void* pContext) { - SCalcConstContext* pCxt = pContext; - SOperatorNode* pOp = *pNode; - if (QUERY_NODE_VALUE == nodeType(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) { - return doCalcConst((SNode**)pNode, pCxt); - } - if (isTimestampCol(pOp->pLeft) && (NULL == pOp->pRight || QUERY_NODE_VALUE == nodeType(pOp->pRight))) { - return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pLeft)->node.resType.precision, (SValueNode*)pOp->pRight); - } else if (isTimestampCol(pOp->pRight) && QUERY_NODE_VALUE == nodeType(pOp->pLeft)) { - return stringToTimestamp(pCxt, ((SColumnNode*)pOp->pRight)->node.resType.precision, (SValueNode*)pOp->pLeft); +static int32_t calcConstNode(SNode** pNode) { + if (NULL == *pNode) { + return TSDB_CODE_SUCCESS; } - return DEAL_RES_CONTINUE; -} -static EDealRes calcConstFunction(SFunctionNode** pNode, void* pContext) { - SFunctionNode* pFunc = *pNode; - if (!fmIsScalarFunc(pFunc->funcId) || fmIsUserDefinedFunc(pFunc->funcId)) { - return DEAL_RES_CONTINUE; - } - SNode* pParam = NULL; - FOREACH(pParam, pFunc->pParameterList) { - if (QUERY_NODE_VALUE != nodeType(pParam)) { - return DEAL_RES_CONTINUE; - } + SNode* pNew = NULL; + int32_t code = scalarCalculateConstants(*pNode, &pNew); + if (TSDB_CODE_SUCCESS == code) { + *pNode = pNew; } - return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext); + return code; } -static EDealRes calcConstLogicCond(SLogicConditionNode** pNode, void* pContext) { - SLogicConditionNode* pCond = *pNode; - SNode* pParam = NULL; - FOREACH(pParam, pCond->pParameterList) { - // todo calc "true and c1 > 10" - if (QUERY_NODE_VALUE != nodeType(pParam)) { - return DEAL_RES_CONTINUE; +static int32_t calcConstList(SNodeList* pList) { + SNode* pNode = NULL; + FOREACH(pNode, pList) { + SNode* pNew = NULL; + int32_t code = scalarCalculateConstants(pNode, &pNew); + if (TSDB_CODE_SUCCESS == code) { + REPLACE_NODE(pNew); + } else { + return code; } } - return doCalcConst((SNode**)pNode, (SCalcConstContext*)pContext); -} - -static EDealRes calcConstSubquery(STempTableNode** pNode, void* pContext) { - SCalcConstContext* pCxt = pContext; - pCxt->code = calcConstQuery(pCxt, (*pNode)->pSubquery); - return (TSDB_CODE_SUCCESS == pCxt->code ? DEAL_RES_CONTINUE : DEAL_RES_ERROR); -} - -static EDealRes calcConst(SNode** pNode, void* pContext) { - switch (nodeType(*pNode)) { - case QUERY_NODE_OPERATOR: - return calcConstOperator((SOperatorNode**)pNode, pContext); - case QUERY_NODE_FUNCTION: - return calcConstFunction((SFunctionNode**)pNode, pContext); - case QUERY_NODE_LOGIC_CONDITION: - return calcConstLogicCond((SLogicConditionNode**)pNode, pContext); - case QUERY_NODE_TEMP_TABLE: - return calcConstSubquery((STempTableNode**)pNode, pContext); - default: - break; - } - return DEAL_RES_CONTINUE; + return TSDB_CODE_SUCCESS; } static bool isCondition(const SNode* pNode) { @@ -174,18 +102,41 @@ static int32_t rewriteCondition(SCalcConstContext* pCxt, SNode** pNode) { return pCxt->code; } +static int32_t calcConstCondition(SCalcConstContext* pCxt, SNode** pNode) { + int32_t code = rewriteCondition(pCxt, pNode); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstNode(pNode); + } + return code; +} + static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTable) { - if (QUERY_NODE_JOIN_TABLE == nodeType(pTable)) { - SJoinTableNode* pJoin = (SJoinTableNode*)pTable; - pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pLeft); - if (TSDB_CODE_SUCCESS == pCxt->code) { - pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pRight); + int32_t code = TSDB_CODE_SUCCESS; + switch (nodeType(pTable)) { + case QUERY_NODE_TEMP_TABLE: { + code = calcConstSubquery(pCxt, (STempTableNode*)pTable); + break; } - if (TSDB_CODE_SUCCESS == pCxt->code && NULL != pJoin->pOnCond) { - pCxt->code = rewriteCondition(pCxt, &pJoin->pOnCond); + case QUERY_NODE_JOIN_TABLE: { + SJoinTableNode* pJoin = (SJoinTableNode*)pTable; + code = rewriteConditionForFromTable(pCxt, pJoin->pLeft); + if (TSDB_CODE_SUCCESS == code) { + code = rewriteConditionForFromTable(pCxt, pJoin->pRight); + } + if (TSDB_CODE_SUCCESS == code && NULL != pJoin->pOnCond) { + code = calcConstCondition(pCxt, &pJoin->pOnCond); + } + // todo empty table + break; } + default: + break; } - return pCxt->code; + return code; +} + +static int32_t calcConstFromTable(SCalcConstContext* pCxt, SSelectStmt* pSelect) { + return rewriteConditionForFromTable(pCxt, pSelect->pFromTable); } static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) { @@ -200,89 +151,143 @@ static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) { } } -static int32_t calcConstFromTable(SCalcConstContext* pCxt, SSelectStmt* pSelect) { - pCxt->code = rewriteConditionForFromTable(pCxt, pSelect->pFromTable); - if (TSDB_CODE_SUCCESS == pCxt->code) { - nodesRewriteExprPostOrder(&pSelect->pFromTable, calcConst, pCxt); - } - return pCxt->code; -} - -static int32_t calcConstCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) { +static int32_t calcConstSelectCondition(SCalcConstContext* pCxt, SSelectStmt* pSelect, SNode** pCond) { if (NULL == *pCond) { return TSDB_CODE_SUCCESS; } - pCxt->code = rewriteCondition(pCxt, pCond); - if (TSDB_CODE_SUCCESS == pCxt->code) { - nodesRewriteExprPostOrder(pCond, calcConst, pCxt); + int32_t code = rewriteCondition(pCxt, pCond); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstNode(pCond); } - if (TSDB_CODE_SUCCESS == pCxt->code) { + if (TSDB_CODE_SUCCESS == code) { rewriteConstCondition(pSelect, pCond); } - return pCxt->code; + return code; +} + +static int32_t calcConstProject(SNode* pProject, SNode** pNew) { + SArray* pAssociation = NULL; + if (NULL != ((SExprNode*)pProject)->pAssociation) { + pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation); + if (NULL == pAssociation) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + int32_t code = scalarCalculateConstants(pProject, pNew); + if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE == nodeType(pNew) && NULL != pAssociation) { + int32_t size = taosArrayGetSize(pAssociation); + for (int32_t i = 0; i < size; ++i) { + SNode** pCol = taosArrayGet(pAssociation, i); + *pCol = nodesCloneNode(pNew); + if (NULL == *pCol) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + } + return code; +} + +static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProjections, bool subquery) { + SNode* pProj = NULL; + WHERE_EACH(pProj, pProjections) { + if (subquery && NULL == ((SExprNode*)pProj)->pAssociation) { + ERASE_NODE(pProjections); + continue; + } + SNode* pNew = NULL; + int32_t code = calcConstProject(pProj, &pNew); + if (TSDB_CODE_SUCCESS == code) { + REPLACE_NODE(pNew); + } else { + return code; + } + WHERE_NEXT; + } + return TSDB_CODE_SUCCESS; } -static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect) { - nodesRewriteExprsPostOrder(pSelect->pProjectionList, calcConst, pCxt); - if (TSDB_CODE_SUCCESS == pCxt->code) { - pCxt->code = calcConstFromTable(pCxt, pSelect); +static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { + int32_t code = calcConstProjections(pCxt, pSelect->pProjectionList, subquery); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstFromTable(pCxt, pSelect); } - if (TSDB_CODE_SUCCESS == pCxt->code) { - pCxt->code = calcConstCondition(pCxt, pSelect, &pSelect->pWhere); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pWhere); } - if (TSDB_CODE_SUCCESS == pCxt->code) { - nodesRewriteExprsPostOrder(pSelect->pPartitionByList, calcConst, pCxt); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstList(pSelect->pPartitionByList); } - if (TSDB_CODE_SUCCESS == pCxt->code) { - nodesRewriteExprPostOrder(&pSelect->pWindow, calcConst, pCxt); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstNode(&pSelect->pWindow); } - if (TSDB_CODE_SUCCESS == pCxt->code) { - nodesRewriteExprsPostOrder(pSelect->pGroupByList, calcConst, pCxt); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstList(pSelect->pGroupByList); } - if (TSDB_CODE_SUCCESS == pCxt->code) { - pCxt->code = calcConstCondition(pCxt, pSelect, &pSelect->pHaving); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pHaving); } - if (TSDB_CODE_SUCCESS == pCxt->code) { - nodesRewriteExprsPostOrder(pSelect->pOrderByList, calcConst, pCxt); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstList(pSelect->pOrderByList); } - return pCxt->code; + return code; } -static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt) { +static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery) { + int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pStmt)) { case QUERY_NODE_SELECT_STMT: - return calcConstSelect(pCxt, (SSelectStmt*)pStmt); + code = calcConstSelect(pCxt, (SSelectStmt*)pStmt, subquery); + break; case QUERY_NODE_EXPLAIN_STMT: - return calcConstQuery(pCxt, ((SExplainStmt*)pStmt)->pQuery); + code = calcConstQuery(pCxt, ((SExplainStmt*)pStmt)->pQuery, subquery); + break; + case QUERY_NODE_SET_OPERATOR: { + SSetOperator* pSetOp = (SSetOperator*)pStmt; + code = calcConstQuery(pCxt, pSetOp->pLeft, subquery); + if (TSDB_CODE_SUCCESS == code) { + code = calcConstQuery(pCxt, pSetOp->pRight, subquery); + } + break; + } default: break; } - return TSDB_CODE_SUCCESS; + return code; } static bool isEmptyResultQuery(SNode* pStmt) { + bool isEmptyResult = false; switch (nodeType(pStmt)) { case QUERY_NODE_SELECT_STMT: - return ((SSelectStmt*)pStmt)->isEmptyResult; + isEmptyResult = ((SSelectStmt*)pStmt)->isEmptyResult; + break; case QUERY_NODE_EXPLAIN_STMT: - return isEmptyResultQuery(((SExplainStmt*)pStmt)->pQuery); + isEmptyResult = isEmptyResultQuery(((SExplainStmt*)pStmt)->pQuery); + break; + case QUERY_NODE_SET_OPERATOR: { + SSetOperator* pSetOp = (SSetOperator*)pStmt; + isEmptyResult = isEmptyResultQuery(pSetOp->pLeft); + if (isEmptyResult) { + isEmptyResult = isEmptyResultQuery(pSetOp->pRight); + } + break; + } default: break; } - return false; + return isEmptyResult; } int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) { - SCalcConstContext cxt = { - .pParseCxt = pParseCxt, - .msgBuf.buf = pParseCxt->pMsg, - .msgBuf.len = pParseCxt->msgLen, - .code = TSDB_CODE_SUCCESS - }; - int32_t code = calcConstQuery(&cxt, pQuery->pRoot); - if (TSDB_CODE_SUCCESS == code) { - pQuery->execMode = isEmptyResultQuery(pQuery->pRoot) ? QUERY_EXEC_MODE_EMPTY_RESULT : pQuery->execMode; + SCalcConstContext cxt = {.pParseCxt = pParseCxt, + .msgBuf.buf = pParseCxt->pMsg, + .msgBuf.len = pParseCxt->msgLen, + .code = TSDB_CODE_SUCCESS}; + int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false); + if (TSDB_CODE_SUCCESS == code && isEmptyResultQuery(pQuery->pRoot)) { + pQuery->execMode = QUERY_EXEC_MODE_EMPTY_RESULT; } return code; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index f69a3830056933b866c402f6cc3963a290edafb7..5a93c5cef5e0f01d64023ac5ca5c11b1dd2aabfa 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -42,20 +42,20 @@ } while (0) typedef struct SInsertParseContext { - SParseContext* pComCxt; // input - char *pSql; // input - SMsgBuf msg; // input - STableMeta* pTableMeta; // each table - SParsedDataColInfo tags; // each table - SKVRowBuilder tagsBuilder; // each table - SVCreateTbReq createTblReq; // each table - SHashObj* pVgroupsHashObj; // global - SHashObj* pTableBlockHashObj; // global - SHashObj* pSubTableHashObj; // global - SArray* pVgDataBlocks; // global - int32_t totalNum; + SParseContext* pComCxt; // input + char* pSql; // input + SMsgBuf msg; // input + STableMeta* pTableMeta; // each table + SParsedDataColInfo tags; // each table + SKVRowBuilder tagsBuilder; // each table + SVCreateTbReq createTblReq; // each table + SHashObj* pVgroupsHashObj; // global + SHashObj* pTableBlockHashObj; // global + SHashObj* pSubTableHashObj; // global + SArray* pVgDataBlocks; // global + int32_t totalNum; SVnodeModifOpStmt* pOutput; - SStmtCallback* pStmtCb; + SStmtCallback* pStmtCb; } SInsertParseContext; typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param); @@ -64,8 +64,8 @@ static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; typedef struct SKvParam { - SKVRowBuilder *builder; - SSchema *schema; + SKVRowBuilder* builder; + SSchema* schema; char buf[TSDB_MAX_TAGS_LEN]; } SKvParam; @@ -76,16 +76,14 @@ typedef struct SMemParam { col_id_t colIdx; } SMemParam; - -#define CHECK_CODE(expr) \ - do { \ - int32_t code = expr; \ +#define CHECK_CODE(expr) \ + do { \ + int32_t code = expr; \ if (TSDB_CODE_SUCCESS != code) { \ - return code; \ - } \ + return code; \ + } \ } while (0) - static int32_t skipInsertInto(SInsertParseContext* pCxt) { SToken sToken; NEXT_TOKEN(pCxt->pSql, sToken); @@ -179,7 +177,6 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD return TSDB_CODE_SUCCESS; } - static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) { const char* msg1 = "name too long"; const char* msg2 = "invalid database name"; @@ -242,8 +239,8 @@ static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, con static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool isStb) { SParseContext* pBasicCtx = pCxt->pComCxt; - SName name = {0}; - createSName(&name, pTname, pBasicCtx->acctId, pBasicCtx->db, &pCxt->msg); + SName name = {0}; + createSName(&name, pTname, pBasicCtx->acctId, pBasicCtx->db, &pCxt->msg); if (isStb) { CHECK_CODE(catalogGetSTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &pCxt->pTableMeta)); @@ -316,7 +313,7 @@ static int32_t buildOutput(SInsertParseContext* pCxt) { return TSDB_CODE_SUCCESS; } -int32_t checkTimestamp(STableDataBlocks *pDataBlocks, const char *start) { +int32_t checkTimestamp(STableDataBlocks* pDataBlocks, const char* start) { // once the data block is disordered, we do NOT keep previous timestamp any more if (!pDataBlocks->ordered) { return TSDB_CODE_SUCCESS; @@ -601,7 +598,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } case TSDB_DATA_TYPE_JSON: { - if(pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE){ + if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { return buildSyntaxErrMsg(pMsgBuf, "json string too long than 4095", pToken->z); } return func(pMsgBuf, pToken->z, pToken->n, param); @@ -720,7 +717,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* qsort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar); } - if(pColList->numOfCols > pColList->numOfBound){ + if (pColList->numOfCols > pColList->numOfBound) { memset(&pColList->boundColumns[pColList->numOfBound], 0, sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound)); } @@ -728,18 +725,19 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* return TSDB_CODE_SUCCESS; } -static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, void *param) { - SKvParam* pa = (SKvParam*) param; +static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) { + SKvParam* pa = (SKvParam*)param; int8_t type = pa->schema->type; int16_t colId = pa->schema->colId; - if(TSDB_DATA_TYPE_JSON == type){ + if (TSDB_DATA_TYPE_JSON == type) { return parseJsontoTagData(value, pa->builder, pMsgBuf, colId); } if (value == NULL) { // it is a null data - // tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx); + // tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, + // pa->colIdx); return TSDB_CODE_SUCCESS; } @@ -764,7 +762,7 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, voi return TSDB_CODE_SUCCESS; } -static int32_t buildCreateTbReq(SVCreateTbReq *pTbReq, const SName* pName, SKVRow row, int64_t suid) { +static int32_t buildCreateTbReq(SVCreateTbReq* pTbReq, const SName* pName, SKVRow row, int64_t suid) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(pName, dbFName); pTbReq->type = TD_CHILD_TABLE; @@ -782,9 +780,9 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint } SKvParam param = {.builder = &pCxt->tagsBuilder}; - SToken sToken; - bool isParseBindParam = false; - char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" + SToken sToken; + bool isParseBindParam = false; + char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" for (int i = 0; i < pCxt->tags.numOfBound; ++i) { NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); @@ -800,8 +798,8 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint if (isParseBindParam) { return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and tag values"); } - - SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i] - 1]; // colId starts with 1 + + SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i] - 1]; // colId starts with 1 param.schema = pTagSchema; CHECK_CODE( parseValueToken(&pCxt->pSql, &sToken, pTagSchema, precision, tmpTokenBuf, KvRowAppend, ¶m, &pCxt->msg)); @@ -886,7 +884,8 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken) return TSDB_CODE_SUCCESS; } -static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow, char* tmpTokenBuf) { +static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow, + char* tmpTokenBuf) { SParsedDataColInfo* spd = &pDataBlocks->boundColumnInfo; SRowBuilder* pBuilder = &pDataBlocks->rowBuilder; STSRow* row = (STSRow*)(pDataBlocks->pData + pDataBlocks->size); // skip the SSubmitBlk header @@ -914,7 +913,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, if (isParseBindParam) { return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and values"); } - + param.schema = pSchema; getSTSRowAppendInfo(pBuilder->rowType, spd, i, ¶m.toffset, ¶m.colIdx); CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, timePrec, tmpTokenBuf, MemRowAppend, ¶m, &pCxt->msg)); @@ -970,7 +969,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo bool gotRow = false; CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf)); if (gotRow) { - pDataBlock->size += extendedRowSize; //len; + pDataBlock->size += extendedRowSize; // len; } NEXT_TOKEN(pCxt->pSql, sToken); @@ -984,7 +983,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo } if (0 == (*numOfRows) && (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT))) { - return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); + return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); } return TSDB_CODE_SUCCESS; } @@ -1050,11 +1049,11 @@ static void destroyInsertParseContext(SInsertParseContext* pCxt) { // [...]; static int32_t parseInsertBody(SInsertParseContext* pCxt) { int32_t tbNum = 0; - + // for each table while (1) { SToken sToken; - char *tbName = NULL; + char* tbName = NULL; // pSql -> tb_name ... NEXT_TOKEN(pCxt->pSql, sToken); @@ -1068,7 +1067,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { } if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && tbNum > 0) { - return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt");; + return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt"); + ; } destroyInsertParseContextForTable(pCxt); @@ -1076,14 +1076,14 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { if (TK_NK_QUESTION == sToken.type) { if (pCxt->pStmtCb) { CHECK_CODE((*pCxt->pStmtCb->getTbNameFn)(pCxt->pStmtCb->pStmt, &tbName)); - + sToken.z = tbName; sToken.n = strlen(tbName); } else { return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z); } } - + SToken tbnameToken = sToken; NEXT_TOKEN(pCxt->pSql, sToken); @@ -1131,9 +1131,9 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", sToken.z); } - + if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) { - SParsedDataColInfo *tags = taosMemoryMalloc(sizeof(pCxt->tags)); + SParsedDataColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags)); if (NULL == tags) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1144,10 +1144,10 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { (*pCxt->pStmtCb->setExecInfoFn)(pCxt->pStmtCb->pStmt, pCxt->pVgroupsHashObj, pCxt->pTableBlockHashObj); pCxt->pVgroupsHashObj = NULL; pCxt->pTableBlockHashObj = NULL; - + return TSDB_CODE_SUCCESS; } - + // merge according to vgId if (taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { CHECK_CODE(mergeTableDataBlocks(pCxt->pTableBlockHashObj, pCxt->pOutput->payloadType, &pCxt->pVgDataBlocks)); @@ -1163,25 +1163,25 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { // [...]; int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { SInsertParseContext context = { - .pComCxt = pContext, - .pSql = (char*) pContext->pSql, - .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, - .pTableMeta = NULL, - .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false), - .totalNum = 0, - .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT), - .pStmtCb = pContext->pStmtCb - }; + .pComCxt = pContext, + .pSql = (char*)pContext->pSql, + .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, + .pTableMeta = NULL, + .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false), + .totalNum = 0, + .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT), + .pStmtCb = pContext->pStmtCb}; if (pContext->pStmtCb && *pQuery) { - (*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj, &context.pTableBlockHashObj); + (*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj, + &context.pTableBlockHashObj); } else { context.pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false); context.pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); } - - if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || - NULL == context.pSubTableHashObj || NULL == context.pOutput) { + + if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pSubTableHashObj || + NULL == context.pOutput) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1199,7 +1199,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { (*pQuery)->msgType = TDMT_VND_SUBMIT; (*pQuery)->pRoot = (SNode*)context.pOutput; } - + context.pOutput->payloadType = PAYLOAD_TYPE_KV; int32_t code = skipInsertInto(&context); @@ -1210,15 +1210,15 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { return code; } - -int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen) { - SMsgBuf msg = {.buf = msgBuf, .len =msgBufLen}; - SToken sToken; +int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf, + int32_t msgBufLen) { + SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen}; + SToken sToken; int32_t code = 0; - char *tbName = NULL; - + char* tbName = NULL; + NEXT_TOKEN(pTableName, sToken); - + if (sToken.n == 0) { return buildInvalidOperationMsg(&msg, "empty table name"); } @@ -1237,16 +1237,15 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* return TSDB_CODE_SUCCESS; } - int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) { - SVnodeModifOpStmt *modifyNode = (SVnodeModifOpStmt *)pQuery->pRoot; - int32_t code = 0; + SVnodeModifOpStmt* modifyNode = (SVnodeModifOpStmt*)pQuery->pRoot; + int32_t code = 0; SInsertParseContext insertCtx = { - .pVgroupsHashObj = pVgHash, - .pTableBlockHashObj = pBlockHash, - .pOutput = (SVnodeModifOpStmt*)pQuery->pRoot, + .pVgroupsHashObj = pVgHash, + .pTableBlockHashObj = pBlockHash, + .pOutput = (SVnodeModifOpStmt*)pQuery->pRoot, }; - + // merge according to vgId if (taosHashGetSize(insertCtx.pTableBlockHashObj) > 0) { CHECK_CODE(mergeTableDataBlocks(insertCtx.pTableBlockHashObj, modifyNode->payloadType, &insertCtx.pVgDataBlocks)); @@ -1257,9 +1256,10 @@ int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash return TSDB_CODE_SUCCESS; } -int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen){ - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; +int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, SName* pName, TAOS_BIND_v2* bind, char* msgBuf, + int32_t msgBufLen) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags; if (NULL == tags) { return TSDB_CODE_QRY_APP_ERROR; @@ -1278,16 +1278,16 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p KvRowAppend(&pBuf, NULL, 0, ¶m); continue; } - - SSchema* pTagSchema = &pSchema[tags->boundColumns[c] - 1]; // colId starts with 1 + + SSchema* pTagSchema = &pSchema[tags->boundColumns[c] - 1]; // colId starts with 1 param.schema = pTagSchema; int32_t colLen = pTagSchema->bytes; if (IS_VAR_DATA_TYPE(pTagSchema->type)) { colLen = bind[c].length[0]; } - - CHECK_CODE(KvRowAppend(&pBuf, (char *)bind[c].buffer, colLen, ¶m)); + + CHECK_CODE(KvRowAppend(&pBuf, (char*)bind[c].buffer, colLen, ¶m)); } SKVRow row = tdGetKVRowFromBuilder(&tagBuilder); @@ -1307,25 +1307,24 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p return TSDB_CODE_SUCCESS; } - -int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); - int32_t extendedRowSize = getExtendedRowSize(pDataBlock); +int32_t qBindStmtColsValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); + int32_t extendedRowSize = getExtendedRowSize(pDataBlock); SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo; SRowBuilder* pBuilder = &pDataBlock->rowBuilder; - SMemParam param = {.rb = pBuilder}; - SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; - int32_t rowNum = bind->num; - + SMemParam param = {.rb = pBuilder}; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + int32_t rowNum = bind->num; + CHECK_CODE(initRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo)); CHECK_CODE(allocateMemForSize(pDataBlock, extendedRowSize * bind->num)); - + for (int32_t r = 0; r < bind->num; ++r) { STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header tdSRowResetBuf(pBuilder, row); - + for (int c = 0; c < spd->numOfBound; ++c) { SSchema* pColSchema = &pSchema[spd->boundColumns[c] - 1]; @@ -1336,7 +1335,7 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 if (bind[c].num != rowNum) { return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); } - + param.schema = pColSchema; getSTSRowAppendInfo(pBuilder->rowType, spd, c, ¶m.toffset, ¶m.colIdx); @@ -1344,23 +1343,23 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL"); } - + CHECK_CODE(MemRowAppend(&pBuf, NULL, 0, ¶m)); } else { int32_t colLen = pColSchema->bytes; if (IS_VAR_DATA_TYPE(pColSchema->type)) { colLen = bind[c].length[r]; } - - CHECK_CODE(MemRowAppend(&pBuf, (char *)bind[c].buffer + bind[c].buffer_length * r, colLen, ¶m)); + + CHECK_CODE(MemRowAppend(&pBuf, (char*)bind[c].buffer + bind[c].buffer_length * r, colLen, ¶m)); } - + if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) { TSKEY tsKey = TD_ROW_KEY(row); - checkTimestamp(pDataBlock, (const char *)&tsKey); + 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) { @@ -1370,11 +1369,11 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 } } } - + pDataBlock->size += extendedRowSize; } - SSubmitBlk *pBlocks = (SSubmitBlk *)(pDataBlock->pData); + SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData); if (TSDB_CODE_SUCCESS != setBlockInfo(pBlocks, pDataBlock, bind->num)) { return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than 32767"); } @@ -1382,22 +1381,23 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32 return TSDB_CODE_SUCCESS; } -int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); - int32_t extendedRowSize = getExtendedRowSize(pDataBlock); +int32_t qBindStmtSingleColValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx, + int32_t rowNum) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); + int32_t extendedRowSize = getExtendedRowSize(pDataBlock); SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo; SRowBuilder* pBuilder = &pDataBlock->rowBuilder; - SMemParam param = {.rb = pBuilder}; - SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; - bool rowStart = (0 == colIdx); - bool rowEnd = ((colIdx + 1) == spd->numOfBound); + SMemParam param = {.rb = pBuilder}; + SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen}; + bool rowStart = (0 == colIdx); + bool rowEnd = ((colIdx + 1) == spd->numOfBound); if (rowStart) { CHECK_CODE(initRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo)); CHECK_CODE(allocateMemForSize(pDataBlock, extendedRowSize * bind->num)); } - + for (int32_t r = 0; r < bind->num; ++r) { STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size + extendedRowSize * r); // skip the SSubmitBlk header if (rowStart) { @@ -1405,13 +1405,13 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, } else { tdSRowGetBuf(pBuilder, row); } - + SSchema* pColSchema = &pSchema[spd->boundColumns[colIdx] - 1]; - + if (bind->num != rowNum) { return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); } - + param.schema = pColSchema; getSTSRowAppendInfo(pBuilder->rowType, spd, colIdx, ¶m.toffset, ¶m.colIdx); @@ -1419,7 +1419,7 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL"); } - + CHECK_CODE(MemRowAppend(&pBuf, NULL, 0, ¶m)); } else { if (bind->buffer_type != pColSchema->type) { @@ -1430,15 +1430,15 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, if (IS_VAR_DATA_TYPE(pColSchema->type)) { colLen = bind->length[r]; } - - CHECK_CODE(MemRowAppend(&pBuf, (char *)bind->buffer + bind->buffer_length * r, colLen, ¶m)); + + CHECK_CODE(MemRowAppend(&pBuf, (char*)bind->buffer + bind->buffer_length * r, colLen, ¶m)); } - + if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) { TSKEY tsKey = TD_ROW_KEY(row); - checkTimestamp(pDataBlock, (const char *)&tsKey); + checkTimestamp(pDataBlock, (const char*)&tsKey); } - + // set the null value for the columns that do not assign values if (rowEnd && (spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) { for (int32_t i = 0; i < spd->numOfCols; ++i) { @@ -1447,13 +1447,13 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, spd->cols[i].toffset); } } - } + } } if (rowEnd) { pDataBlock->size += extendedRowSize * bind->num; - SSubmitBlk *pBlocks = (SSubmitBlk *)(pDataBlock->pData); + SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData); if (TSDB_CODE_SUCCESS != setBlockInfo(pBlocks, pDataBlock, bind->num)) { return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than 32767"); } @@ -1462,8 +1462,7 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, return TSDB_CODE_SUCCESS; } - -int32_t buildBoundFields(SParsedDataColInfo *boundInfo, SSchema *pSchema, int32_t *fieldNum, TAOS_FIELD** fields) { +int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD** fields) { if (fields) { *fields = taosMemoryCalloc(boundInfo->numOfBound, sizeof(TAOS_FIELD)); if (NULL == *fields) { @@ -1483,15 +1482,14 @@ int32_t buildBoundFields(SParsedDataColInfo *boundInfo, SSchema *pSchema, int32_ return TSDB_CODE_SUCCESS; } - -int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TAOS_FIELD** fields) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; +int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags; if (NULL == tags) { return TSDB_CODE_QRY_APP_ERROR; } - - SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta); + + SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta); if (tags->numOfBound <= 0) { *fieldNum = 0; *fields = NULL; @@ -1500,13 +1498,13 @@ int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TA } CHECK_CODE(buildBoundFields(tags, pSchema, fieldNum, fields)); - + return TSDB_CODE_SUCCESS; } -int32_t qBuildStmtColFields(void *pBlock, int32_t *fieldNum, TAOS_FIELD** fields) { - STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock; - SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); +int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD** fields) { + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta); if (pDataBlock->boundColumnInfo.numOfBound <= 0) { *fieldNum = 0; if (fields) { @@ -1517,9 +1515,6 @@ int32_t qBuildStmtColFields(void *pBlock, int32_t *fieldNum, TAOS_FIELD** fields } CHECK_CODE(buildBoundFields(&pDataBlock->boundColumnInfo, pSchema, fieldNum, fields)); - + return TSDB_CODE_SUCCESS; } - - - diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index bf30915fcbdbfff64abee067f419f887d6018e16..42dde12bff586be5114129442a9a3f87bd427a13 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -16,9 +16,9 @@ #include "parInsertData.h" #include "catalog.h" +#include "parInt.h" #include "parUtil.h" #include "querynodes.h" -#include "parInt.h" #define IS_RAW_PAYLOAD(t) \ (((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert @@ -33,9 +33,9 @@ typedef struct SBlockKeyInfo { SBlockKeyTuple* pKeyTuple; } SBlockKeyInfo; -static int32_t rowDataCompar(const void *lhs, const void *rhs) { - TSKEY left = *(TSKEY *)lhs; - TSKEY right = *(TSKEY *)rhs; +static int32_t rowDataCompar(const void* lhs, const void* rhs) { + TSKEY left = *(TSKEY*)lhs; + TSKEY right = *(TSKEY*)rhs; if (left == right) { return 0; @@ -81,9 +81,9 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t pColList->extendedVarLen = (uint16_t)(nVar * sizeof(VarDataOffsetT)); } -int32_t schemaIdxCompar(const void *lhs, const void *rhs) { - uint16_t left = *(uint16_t *)lhs; - uint16_t right = *(uint16_t *)rhs; +int32_t schemaIdxCompar(const void* lhs, const void* rhs) { + uint16_t left = *(uint16_t*)lhs; + uint16_t right = *(uint16_t*)rhs; if (left == right) { return 0; @@ -92,9 +92,9 @@ int32_t schemaIdxCompar(const void *lhs, const void *rhs) { } } -int32_t boundIdxCompar(const void *lhs, const void *rhs) { - uint16_t left = *(uint16_t *)POINTER_SHIFT(lhs, sizeof(uint16_t)); - uint16_t right = *(uint16_t *)POINTER_SHIFT(rhs, sizeof(uint16_t)); +int32_t boundIdxCompar(const void* lhs, const void* rhs) { + uint16_t left = *(uint16_t*)POINTER_SHIFT(lhs, sizeof(uint16_t)); + uint16_t right = *(uint16_t*)POINTER_SHIFT(rhs, sizeof(uint16_t)); if (left == right) { return 0; @@ -109,14 +109,14 @@ void destroyBoundColumnInfo(void* pBoundInfo) { } SParsedDataColInfo* pColList = (SParsedDataColInfo*)pBoundInfo; - + taosMemoryFreeClear(pColList->boundColumns); taosMemoryFreeClear(pColList->cols); taosMemoryFreeClear(pColList->colIdxInfo); } -static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks) { +static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, const STableMeta* pTableMeta, + STableDataBlocks** dataBlocks) { STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks)); if (dataBuf == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -137,18 +137,18 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star } memset(dataBuf->pData, 0, sizeof(SSubmitBlk)); - //Here we keep the tableMeta to avoid it to be remove by other threads. + // Here we keep the tableMeta to avoid it to be remove by other threads. dataBuf->pTableMeta = tableMetaDup(pTableMeta); SParsedDataColInfo* pColInfo = &dataBuf->boundColumnInfo; - SSchema* pSchema = getTableColumnSchema(dataBuf->pTableMeta); + SSchema* pSchema = getTableColumnSchema(dataBuf->pTableMeta); setBoundColumnInfo(pColInfo, pSchema, dataBuf->pTableMeta->tableInfo.numOfColumns); - dataBuf->ordered = true; - dataBuf->prevTS = INT64_MIN; - dataBuf->rowSize = rowSize; - dataBuf->size = startOffset; - dataBuf->vgId = dataBuf->pTableMeta->vgId; + dataBuf->ordered = true; + dataBuf->prevTS = INT64_MIN; + dataBuf->rowSize = rowSize; + dataBuf->size = startOffset; + dataBuf->vgId = dataBuf->pTableMeta->vgId; assert(defaultSize > 0 && pTableMeta != NULL && dataBuf->pTableMeta != NULL); @@ -177,7 +177,8 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) } int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize, - const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq) { + const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, + SVCreateTbReq* pCreateTbReq) { *dataBlocks = NULL; STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id)); if (t1 != NULL) { @@ -267,14 +268,14 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash) { } // data block is disordered, sort it in ascending order -void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) { - SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData; +void sortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf) { + SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; // size is less than the total size, since duplicated rows may be removed yet. assert(pBlocks->numOfRows * dataBuf->rowSize + sizeof(SSubmitBlk) == dataBuf->size); if (!dataBuf->ordered) { - char *pBlockData = pBlocks->data; + char* pBlockData = pBlocks->data; qsort(pBlockData, pBlocks->numOfRows, dataBuf->rowSize, rowDataCompar); int32_t i = 0; @@ -282,8 +283,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) { // delete rows with timestamp conflicts while (j < pBlocks->numOfRows) { - TSKEY ti = *(TSKEY *)(pBlockData + dataBuf->rowSize * i); - TSKEY tj = *(TSKEY *)(pBlockData + dataBuf->rowSize * j); + TSKEY ti = *(TSKEY*)(pBlockData + dataBuf->rowSize * i); + TSKEY tj = *(TSKEY*)(pBlockData + dataBuf->rowSize * j); if (ti == tj) { ++j; @@ -308,8 +309,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) { } // data block is disordered, sort it in ascending order -int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKeyInfo) { - SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData; +int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo) { + SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; int16_t nRows = pBlocks->numOfRows; // size is less than the total size, since duplicated rows may be removed yet. @@ -317,21 +318,21 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey // allocate memory size_t nAlloc = nRows * sizeof(SBlockKeyTuple); if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { - char *tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc); + char* tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc); if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple *)tmp; + pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple*)tmp; pBlkKeyInfo->maxBytesAlloc = (int32_t)nAlloc; } memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc); int32_t extendedRowSize = getExtendedRowSize(dataBuf); - SBlockKeyTuple *pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; - char * pBlockData = pBlocks->data + pBlocks->schemaLen; + SBlockKeyTuple* pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + char* pBlockData = pBlocks->data + pBlocks->schemaLen; int n = 0; while (n < nRows) { - pBlkKeyTuple->skey = TD_ROW_KEY((STSRow *)pBlockData); + pBlkKeyTuple->skey = TD_ROW_KEY((STSRow*)pBlockData); pBlkKeyTuple->payloadAddr = pBlockData; // next loop @@ -374,13 +375,14 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey } // Erase the empty space reserved for binary data -static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, bool isRawPayload) { +static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, + bool isRawPayload) { // TODO: optimize this function, handle the case while binary is not presented - STableMeta* pTableMeta = pTableDataBlock->pTableMeta; - STableComInfo tinfo = getTableInfo(pTableMeta); - SSchema* pSchema = getTableColumnSchema(pTableMeta); + STableMeta* pTableMeta = pTableDataBlock->pTableMeta; + STableComInfo tinfo = getTableInfo(pTableMeta); + SSchema* pSchema = getTableColumnSchema(pTableMeta); - int32_t nonDataLen = sizeof(SSubmitBlk) + pTableDataBlock->createTbReqLen; + int32_t nonDataLen = sizeof(SSubmitBlk) + pTableDataBlock->createTbReqLen; SSubmitBlk* pBlock = pDataBlock; memcpy(pDataBlock, pTableDataBlock->pData, nonDataLen); pDataBlock = (char*)pDataBlock + nonDataLen; @@ -399,7 +401,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB if (isRawPayload) { SRowBuilder builder = {0}; - + tdSRowInit(&builder, pTableMeta->sversion); tdSRowSetInfo(&builder, getNumOfColumns(pTableMeta), -1, flen); @@ -419,8 +421,8 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB } } else { for (int32_t i = 0; i < numOfRows; ++i) { - char* payload = (blkKeyTuple + i)->payloadAddr; - TDRowLenT rowTLen = TD_ROW_LEN((STSRow*)payload); + char* payload = (blkKeyTuple + i)->payloadAddr; + TDRowLenT rowTLen = TD_ROW_LEN((STSRow*)payload); memcpy(pDataBlock, payload, rowTLen); pDataBlock = POINTER_SHIFT(pDataBlock, rowTLen); pBlock->dataLen += rowTLen; @@ -438,14 +440,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES); STableDataBlocks** p = taosHashIterate(pHashObj, NULL); - STableDataBlocks* pOneTableBlock = *p; - SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock + STableDataBlocks* pOneTableBlock = *p; + SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock while (pOneTableBlock) { - SSubmitBlk* pBlocks = (SSubmitBlk*) pOneTableBlock->pData; + SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData; if (pBlocks->numOfRows > 0) { STableDataBlocks* dataBuf = NULL; - int32_t ret = getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE, - INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL); + int32_t ret = + getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0, + pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL); if (ret != TSDB_CODE_SUCCESS) { taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); @@ -490,7 +493,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta); // erase the empty space reserved for binary data - int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload); + int32_t finalLen = + trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload); assert(finalLen <= len); dataBuf->size += (finalLen + sizeof(SSubmitBlk)); @@ -513,15 +517,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p return TSDB_CODE_SUCCESS; } -int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize) { - size_t remain = pDataBlock->nAllocSize - pDataBlock->size; +int32_t allocateMemForSize(STableDataBlocks* pDataBlock, int32_t allSize) { + size_t remain = pDataBlock->nAllocSize - pDataBlock->size; uint32_t nAllocSizeOld = pDataBlock->nAllocSize; - + // expand the allocated size if (remain < allSize) { pDataBlock->nAllocSize = (pDataBlock->size + allSize) * 1.5; - char *tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); + char* tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); if (tmp != NULL) { pDataBlock->pData = tmp; memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size); @@ -535,11 +539,11 @@ int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize) { return TSDB_CODE_SUCCESS; } -int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t * numOfRows) { +int32_t allocateMemIfNeed(STableDataBlocks* pDataBlock, int32_t rowSize, int32_t* numOfRows) { size_t remain = pDataBlock->nAllocSize - pDataBlock->size; const int factor = 5; - uint32_t nAllocSizeOld = pDataBlock->nAllocSize; - + uint32_t nAllocSizeOld = pDataBlock->nAllocSize; + // expand the allocated size if (remain < rowSize * factor) { while (remain < rowSize * factor) { @@ -547,7 +551,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t remain = pDataBlock->nAllocSize - pDataBlock->size; } - char *tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); + char* tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize); if (tmp != NULL) { pDataBlock->pData = tmp; memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size); @@ -563,7 +567,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t return TSDB_CODE_SUCCESS; } -int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo) { +int initRowBuilder(SRowBuilder* pBuilder, int16_t schemaVer, SParsedDataColInfo* pColInfo) { ASSERT(pColInfo->numOfCols > 0 && (pColInfo->numOfBound <= pColInfo->numOfCols)); tdSRowInit(pBuilder, schemaVer); tdSRowSetExtendedInfo(pBuilder, pColInfo->numOfCols, pColInfo->numOfBound, pColInfo->flen, pColInfo->allNullLen, @@ -571,7 +575,6 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo return TSDB_CODE_SUCCESS; } - int32_t qResetStmtDataBlock(void* block, bool keepBuf) { STableDataBlocks* pBlock = (STableDataBlocks*)block; @@ -583,32 +586,31 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) { } memset(pBlock->pData, 0, sizeof(SSubmitBlk)); } else { - pBlock->pData = NULL; + pBlock->pData = NULL; } - - pBlock->ordered = true; - pBlock->prevTS = INT64_MIN; - pBlock->size = sizeof(SSubmitBlk); + + pBlock->ordered = true; + pBlock->prevTS = INT64_MIN; + pBlock->size = sizeof(SSubmitBlk); pBlock->tsSource = -1; pBlock->numOfTables = 1; pBlock->nAllocSize = TSDB_PAYLOAD_SIZE; pBlock->headerSize = pBlock->size; - + memset(&pBlock->rowBuilder, 0, sizeof(pBlock->rowBuilder)); return TSDB_CODE_SUCCESS; } - int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) { *pDst = taosMemoryMalloc(sizeof(STableDataBlocks)); if (NULL == *pDst) { return TSDB_CODE_OUT_OF_MEMORY; } - + memcpy(*pDst, pSrc, sizeof(STableDataBlocks)); ((STableDataBlocks*)(*pDst))->cloned = true; - + return qResetStmtDataBlock(*pDst, false); } @@ -618,7 +620,7 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) { return code; } - STableDataBlocks *pBlock = (STableDataBlocks*)*pDst; + STableDataBlocks* pBlock = (STableDataBlocks*)*pDst; pBlock->pData = taosMemoryMalloc(pBlock->nAllocSize); if (NULL == pBlock->pData) { qFreeStmtDataBlock(pBlock); @@ -630,7 +632,6 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) { return TSDB_CODE_SUCCESS; } - void qFreeStmtDataBlock(void* pDataBlock) { if (pDataBlock == NULL) { return; @@ -650,4 +651,3 @@ void qDestroyStmtDataBlock(void* pBlock) { pDataBlock->cloned = false; destroyDataBlock(pDataBlock); } - diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index fe7835d355bc1a1cea4906ecca124ef1791dd4f8..1338a11f424dacb39ae3c68903669a5db65796f9 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -15,8 +15,8 @@ #include "os.h" #include "parToken.h" -#include "thash.h" #include "taosdef.h" +#include "thash.h" #include "ttokendef.h" // All the keywords of the SQL language are stored in a hash table @@ -28,188 +28,188 @@ typedef struct SKeyword { // keywords in sql string static SKeyword keywordTable[] = { - {"ACCOUNT", TK_ACCOUNT}, - {"ACCOUNTS", TK_ACCOUNTS}, - {"ADD", TK_ADD}, - {"AGGREGATE", TK_AGGREGATE}, - {"ALL", TK_ALL}, - {"ALTER", TK_ALTER}, - {"ANALYZE", TK_ANALYZE}, - {"AND", TK_AND}, - {"APPS", TK_APPS}, - {"AS", TK_AS}, - {"ASC", TK_ASC}, - {"AT_ONCE", TK_AT_ONCE}, - {"BETWEEN", TK_BETWEEN}, - {"BINARY", TK_BINARY}, - {"BIGINT", TK_BIGINT}, - {"BLOCKS", TK_BLOCKS}, - {"BNODE", TK_BNODE}, - {"BNODES", TK_BNODES}, - {"BOOL", TK_BOOL}, - {"BUFSIZE", TK_BUFSIZE}, - {"BY", TK_BY}, - {"CACHE", TK_CACHE}, - {"CACHELAST", TK_CACHELAST}, - {"CAST", TK_CAST}, - {"CLUSTER", TK_CLUSTER}, - {"COLUMN", TK_COLUMN}, - {"COMMENT", TK_COMMENT}, - {"COMP", TK_COMP}, - {"COMPACT", TK_COMPACT}, - {"CONNS", TK_CONNS}, - {"CONNECTION", TK_CONNECTION}, - {"CONNECTIONS", TK_CONNECTIONS}, - {"COUNT", TK_COUNT}, - {"CREATE", TK_CREATE}, - {"DATABASE", TK_DATABASE}, - {"DATABASES", TK_DATABASES}, - {"DAYS", TK_DAYS}, - {"DBS", TK_DBS}, - {"DELAY", TK_DELAY}, - {"DESC", TK_DESC}, - {"DESCRIBE", TK_DESCRIBE}, - {"DISTINCT", TK_DISTINCT}, - {"DNODE", TK_DNODE}, - {"DNODES", TK_DNODES}, - {"DOUBLE", TK_DOUBLE}, - {"DROP", TK_DROP}, - {"EXISTS", TK_EXISTS}, - {"EXPLAIN", TK_EXPLAIN}, - {"FILE_FACTOR", TK_FILE_FACTOR}, - {"FILL", TK_FILL}, - {"FIRST", TK_FIRST}, - {"FLOAT", TK_FLOAT}, - {"FROM", TK_FROM}, - {"FSYNC", TK_FSYNC}, - {"FUNCTION", TK_FUNCTION}, - {"FUNCTIONS", TK_FUNCTIONS}, - {"GRANTS", TK_GRANTS}, - {"GROUP", TK_GROUP}, - {"HAVING", TK_HAVING}, - {"IF", TK_IF}, - {"IMPORT", TK_IMPORT}, - {"IN", TK_IN}, - {"INDEX", TK_INDEX}, - {"INDEXES", TK_INDEXES}, - {"INNER", TK_INNER}, - {"INT", TK_INT}, - {"INSERT", TK_INSERT}, - {"INTEGER", TK_INTEGER}, - {"INTERVAL", TK_INTERVAL}, - {"INTO", TK_INTO}, - {"IS", TK_IS}, - {"JOIN", TK_JOIN}, - {"JSON", TK_JSON}, - {"KEEP", TK_KEEP}, - {"KILL", TK_KILL}, - {"LAST", TK_LAST}, - {"LAST_ROW", TK_LAST_ROW}, - {"LICENCE", TK_LICENCE}, - {"LIKE", TK_LIKE}, - {"LIMIT", TK_LIMIT}, - {"LINEAR", TK_LINEAR}, - {"LOCAL", TK_LOCAL}, - {"MATCH", TK_MATCH}, - {"MAXROWS", TK_MAXROWS}, - {"MINROWS", TK_MINROWS}, - {"MINUS", TK_MINUS}, - {"MNODE", TK_MNODE}, - {"MNODES", TK_MNODES}, - {"MODIFY", TK_MODIFY}, - {"MODULES", TK_MODULES}, - {"NCHAR", TK_NCHAR}, - {"NMATCH", TK_NMATCH}, - {"NONE", TK_NONE}, - {"NOT", TK_NOT}, - {"NOW", TK_NOW}, - {"NULL", TK_NULL}, - {"NULLS", TK_NULLS}, - {"OFFSET", TK_OFFSET}, - {"ON", TK_ON}, - {"OR", TK_OR}, - {"ORDER", TK_ORDER}, - {"OUTPUTTYPE", TK_OUTPUTTYPE}, - {"PARTITION", TK_PARTITION}, - {"PASS", TK_PASS}, - {"PORT", TK_PORT}, - {"PPS", TK_PPS}, - {"PRECISION", TK_PRECISION}, - {"PRIVILEGE", TK_PRIVILEGE}, - {"PREV", TK_PREV}, - {"QNODE", TK_QNODE}, - {"QNODES", TK_QNODES}, - {"QTIME", TK_QTIME}, - {"QUERIES", TK_QUERIES}, - {"QUERY", TK_QUERY}, - {"QUORUM", TK_QUORUM}, - {"RATIO", TK_RATIO}, - {"REPLICA", TK_REPLICA}, - {"RESET", TK_RESET}, - {"RETENTIONS", TK_RETENTIONS}, - {"ROLLUP", TK_ROLLUP}, - {"SCHEMA", TK_SCHEMA}, - {"SCORES", TK_SCORES}, - {"SELECT", TK_SELECT}, - {"SESSION", TK_SESSION}, - {"SET", TK_SET}, - {"SHOW", TK_SHOW}, + {"ACCOUNT", TK_ACCOUNT}, + {"ACCOUNTS", TK_ACCOUNTS}, + {"ADD", TK_ADD}, + {"AGGREGATE", TK_AGGREGATE}, + {"ALL", TK_ALL}, + {"ALTER", TK_ALTER}, + {"ANALYZE", TK_ANALYZE}, + {"AND", TK_AND}, + {"APPS", TK_APPS}, + {"AS", TK_AS}, + {"ASC", TK_ASC}, + {"AT_ONCE", TK_AT_ONCE}, + {"BETWEEN", TK_BETWEEN}, + {"BINARY", TK_BINARY}, + {"BIGINT", TK_BIGINT}, + {"BLOCKS", TK_BLOCKS}, + {"BNODE", TK_BNODE}, + {"BNODES", TK_BNODES}, + {"BOOL", TK_BOOL}, + {"BUFSIZE", TK_BUFSIZE}, + {"BY", TK_BY}, + {"CACHE", TK_CACHE}, + {"CACHELAST", TK_CACHELAST}, + {"CAST", TK_CAST}, + {"CLUSTER", TK_CLUSTER}, + {"COLUMN", TK_COLUMN}, + {"COMMENT", TK_COMMENT}, + {"COMP", TK_COMP}, + {"COMPACT", TK_COMPACT}, + {"CONNS", TK_CONNS}, + {"CONNECTION", TK_CONNECTION}, + {"CONNECTIONS", TK_CONNECTIONS}, + {"COUNT", TK_COUNT}, + {"CREATE", TK_CREATE}, + {"DATABASE", TK_DATABASE}, + {"DATABASES", TK_DATABASES}, + {"DAYS", TK_DAYS}, + {"DBS", TK_DBS}, + {"DELAY", TK_DELAY}, + {"DESC", TK_DESC}, + {"DESCRIBE", TK_DESCRIBE}, + {"DISTINCT", TK_DISTINCT}, + {"DNODE", TK_DNODE}, + {"DNODES", TK_DNODES}, + {"DOUBLE", TK_DOUBLE}, + {"DROP", TK_DROP}, + {"EXISTS", TK_EXISTS}, + {"EXPLAIN", TK_EXPLAIN}, + {"FILE_FACTOR", TK_FILE_FACTOR}, + {"FILL", TK_FILL}, + {"FIRST", TK_FIRST}, + {"FLOAT", TK_FLOAT}, + {"FROM", TK_FROM}, + {"FSYNC", TK_FSYNC}, + {"FUNCTION", TK_FUNCTION}, + {"FUNCTIONS", TK_FUNCTIONS}, + {"GRANTS", TK_GRANTS}, + {"GROUP", TK_GROUP}, + {"HAVING", TK_HAVING}, + {"IF", TK_IF}, + {"IMPORT", TK_IMPORT}, + {"IN", TK_IN}, + {"INDEX", TK_INDEX}, + {"INDEXES", TK_INDEXES}, + {"INNER", TK_INNER}, + {"INT", TK_INT}, + {"INSERT", TK_INSERT}, + {"INTEGER", TK_INTEGER}, + {"INTERVAL", TK_INTERVAL}, + {"INTO", TK_INTO}, + {"IS", TK_IS}, + {"JOIN", TK_JOIN}, + {"JSON", TK_JSON}, + {"KEEP", TK_KEEP}, + {"KILL", TK_KILL}, + {"LAST", TK_LAST}, + {"LAST_ROW", TK_LAST_ROW}, + {"LICENCE", TK_LICENCE}, + {"LIKE", TK_LIKE}, + {"LIMIT", TK_LIMIT}, + {"LINEAR", TK_LINEAR}, + {"LOCAL", TK_LOCAL}, + {"MATCH", TK_MATCH}, + {"MAXROWS", TK_MAXROWS}, + {"MINROWS", TK_MINROWS}, + {"MINUS", TK_MINUS}, + {"MNODE", TK_MNODE}, + {"MNODES", TK_MNODES}, + {"MODIFY", TK_MODIFY}, + {"MODULES", TK_MODULES}, + {"NCHAR", TK_NCHAR}, + {"NMATCH", TK_NMATCH}, + {"NONE", TK_NONE}, + {"NOT", TK_NOT}, + {"NOW", TK_NOW}, + {"NULL", TK_NULL}, + {"NULLS", TK_NULLS}, + {"OFFSET", TK_OFFSET}, + {"ON", TK_ON}, + {"OR", TK_OR}, + {"ORDER", TK_ORDER}, + {"OUTPUTTYPE", TK_OUTPUTTYPE}, + {"PARTITION", TK_PARTITION}, + {"PASS", TK_PASS}, + {"PORT", TK_PORT}, + {"PPS", TK_PPS}, + {"PRECISION", TK_PRECISION}, + {"PRIVILEGE", TK_PRIVILEGE}, + {"PREV", TK_PREV}, + {"QNODE", TK_QNODE}, + {"QNODES", TK_QNODES}, + {"QTIME", TK_QTIME}, + {"QUERIES", TK_QUERIES}, + {"QUERY", TK_QUERY}, + {"QUORUM", TK_QUORUM}, + {"RATIO", TK_RATIO}, + {"REPLICA", TK_REPLICA}, + {"RESET", TK_RESET}, + {"RETENTIONS", TK_RETENTIONS}, + {"ROLLUP", TK_ROLLUP}, + {"SCHEMA", TK_SCHEMA}, + {"SCORES", TK_SCORES}, + {"SELECT", TK_SELECT}, + {"SESSION", TK_SESSION}, + {"SET", TK_SET}, + {"SHOW", TK_SHOW}, {"SINGLE_STABLE", TK_SINGLE_STABLE}, - {"SLIDING", TK_SLIDING}, - {"SLIMIT", TK_SLIMIT}, - {"SMA", TK_SMA}, - {"SMALLINT", TK_SMALLINT}, - {"SNODE", TK_SNODE}, - {"SNODES", TK_SNODES}, - {"SOFFSET", TK_SOFFSET}, - {"STABLE", TK_STABLE}, - {"STABLES", TK_STABLES}, - {"STATE", TK_STATE}, - {"STATE_WINDOW", TK_STATE_WINDOW}, - {"STORAGE", TK_STORAGE}, - {"STREAM", TK_STREAM}, - {"STREAMS", TK_STREAMS}, - {"STREAM_MODE", TK_STREAM_MODE}, - {"STRICT", TK_STRICT}, - {"SYNCDB", TK_SYNCDB}, - {"TABLE", TK_TABLE}, - {"TABLES", TK_TABLES}, - {"TAG", TK_TAG}, - {"TAGS", TK_TAGS}, - {"TBNAME", TK_TBNAME}, - {"TIMESTAMP", TK_TIMESTAMP}, - {"TIMEZONE", TK_TIMEZONE}, - {"TINYINT", TK_TINYINT}, - {"TODAY", TK_TODAY}, - {"TOPIC", TK_TOPIC}, - {"TOPICS", TK_TOPICS}, - {"TRIGGER", TK_TRIGGER}, - {"TSERIES", TK_TSERIES}, - {"TTL", TK_TTL}, - {"UNION", TK_UNION}, - {"UNSIGNED", TK_UNSIGNED}, - {"USE", TK_USE}, - {"USER", TK_USER}, - {"USERS", TK_USERS}, - {"USING", TK_USING}, - {"VALUE", TK_VALUE}, - {"VALUES", TK_VALUES}, - {"VARCHAR", TK_VARCHAR}, - {"VARIABLES", TK_VARIABLES}, - {"VERBOSE", TK_VERBOSE}, - {"VGROUPS", TK_VGROUPS}, - {"VNODES", TK_VNODES}, - {"WAL", TK_WAL}, - {"WATERMARK", TK_WATERMARK}, - {"WHERE", TK_WHERE}, - {"WINDOW_CLOSE", TK_WINDOW_CLOSE}, - {"WITH", TK_WITH}, - {"_QENDTS", TK_QENDTS}, - {"_QSTARTTS", TK_QSTARTTS}, - {"_ROWTS", TK_ROWTS}, - {"_WDURATION", TK_WDURATION}, - {"_WENDTS", TK_WENDTS}, - {"_WSTARTTS", TK_WSTARTTS}, + {"SLIDING", TK_SLIDING}, + {"SLIMIT", TK_SLIMIT}, + {"SMA", TK_SMA}, + {"SMALLINT", TK_SMALLINT}, + {"SNODE", TK_SNODE}, + {"SNODES", TK_SNODES}, + {"SOFFSET", TK_SOFFSET}, + {"STABLE", TK_STABLE}, + {"STABLES", TK_STABLES}, + {"STATE", TK_STATE}, + {"STATE_WINDOW", TK_STATE_WINDOW}, + {"STORAGE", TK_STORAGE}, + {"STREAM", TK_STREAM}, + {"STREAMS", TK_STREAMS}, + {"STREAM_MODE", TK_STREAM_MODE}, + {"STRICT", TK_STRICT}, + {"SYNCDB", TK_SYNCDB}, + {"TABLE", TK_TABLE}, + {"TABLES", TK_TABLES}, + {"TAG", TK_TAG}, + {"TAGS", TK_TAGS}, + {"TBNAME", TK_TBNAME}, + {"TIMESTAMP", TK_TIMESTAMP}, + {"TIMEZONE", TK_TIMEZONE}, + {"TINYINT", TK_TINYINT}, + {"TODAY", TK_TODAY}, + {"TOPIC", TK_TOPIC}, + {"TOPICS", TK_TOPICS}, + {"TRIGGER", TK_TRIGGER}, + {"TSERIES", TK_TSERIES}, + {"TTL", TK_TTL}, + {"UNION", TK_UNION}, + {"UNSIGNED", TK_UNSIGNED}, + {"USE", TK_USE}, + {"USER", TK_USER}, + {"USERS", TK_USERS}, + {"USING", TK_USING}, + {"VALUE", TK_VALUE}, + {"VALUES", TK_VALUES}, + {"VARCHAR", TK_VARCHAR}, + {"VARIABLES", TK_VARIABLES}, + {"VERBOSE", TK_VERBOSE}, + {"VGROUPS", TK_VGROUPS}, + {"VNODES", TK_VNODES}, + {"WAL", TK_WAL}, + {"WATERMARK", TK_WATERMARK}, + {"WHERE", TK_WHERE}, + {"WINDOW_CLOSE", TK_WINDOW_CLOSE}, + {"WITH", TK_WITH}, + {"_QENDTS", TK_QENDTS}, + {"_QSTARTTS", TK_QSTARTTS}, + {"_ROWTS", TK_ROWTS}, + {"_WDURATION", TK_WDURATION}, + {"_WENDTS", TK_WENDTS}, + {"_WSTARTTS", TK_WSTARTTS}, // {"ID", TK_ID}, // {"STRING", TK_STRING}, // {"EQ", TK_EQ}, @@ -293,7 +293,7 @@ static void* keywordHashTable = NULL; static void doInitKeywordsTable(void) { int numOfEntries = tListLen(keywordTable); - + keywordHashTable = taosHashInit(numOfEntries, MurmurHash3_32, true, false); for (int32_t i = 0; i < numOfEntries; i++) { keywordTable[i].len = (uint8_t)strlen(keywordTable[i].name); @@ -306,12 +306,12 @@ static TdThreadOnce keywordsHashTableInit = PTHREAD_ONCE_INIT; static int32_t tKeywordCode(const char* z, int n) { taosThreadOnce(&keywordsHashTableInit, doInitKeywordsTable); - + char key[512] = {0}; - if (n > tListLen(key)) { // too long token, can not be any other token type + if (n > tListLen(key)) { // too long token, can not be any other token type return TK_NK_ID; } - + for (int32_t j = 0; j < n; ++j) { if (z[j] >= 'a' && z[j] <= 'z') { key[j] = (char)(z[j] & 0xDF); // to uppercase and set the null-terminated @@ -325,7 +325,7 @@ static int32_t tKeywordCode(const char* z, int n) { } SKeyword** pKey = (SKeyword**)taosHashGet(keywordHashTable, key, n); - return (pKey != NULL)? (*pKey)->type:TK_NK_ID; + return (pKey != NULL) ? (*pKey)->type : TK_NK_ID; } /* @@ -468,11 +468,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { int delim = z[0]; bool strEnd = false; for (i = 1; z[i]; i++) { - if (z[i] == '\\') { // ignore the escaped character that follows this backslash + if (z[i] == '\\') { // ignore the escaped character that follows this backslash i++; continue; } - + if (z[i] == delim) { if (z[i + 1] == delim) { i++; @@ -482,11 +482,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } } } - + if (z[i]) i++; if (strEnd) { - *tokenId = (delim == '`')? TK_NK_ID:TK_NK_STRING; + *tokenId = (delim == '`') ? TK_NK_ID : TK_NK_STRING; return i; } @@ -521,7 +521,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { case '0': { char next = z[1]; - if (next == 'b') { // bin number + if (next == 'b') { // bin number *tokenId = TK_NK_BIN; for (i = 2; (z[i] == '0' || z[i] == '1'); ++i) { } @@ -531,7 +531,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } return i; - } else if (next == 'x') { //hex number + } else if (next == 'x') { // hex number *tokenId = TK_NK_HEX; for (i = 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) { } @@ -557,10 +557,9 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } /* here is the 1u/1a/2s/3m/9y */ - if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || - z[i] == 'y' || z[i] == 'w' || - z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || - z[i] == 'Y' || z[i] == 'W') && + if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || + z[i] == 'n' || z[i] == 'y' || z[i] == 'w' || z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || + z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'Y' || z[i] == 'W') && (isIdChar[(uint8_t)z[i + 1]] == 0)) { *tokenId = TK_NK_VARIABLE; i += 1; @@ -602,7 +601,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { case 't': case 'F': case 'f': { - for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) { + for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t)z[i]]; i++) { } if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) { @@ -611,10 +610,10 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { } } default: { - if (((*z & 0x80) != 0) || !isIdChar[(uint8_t) *z]) { + if (((*z & 0x80) != 0) || !isIdChar[(uint8_t)*z]) { break; } - for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) { + for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t)z[i]]; i++) { } *tokenId = tKeywordCode(z, i); return i; @@ -625,12 +624,12 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) { return 0; } -SToken tscReplaceStrToken(char **str, SToken *token, const char* newToken) { - char *src = *str; - size_t nsize = strlen(newToken); +SToken tscReplaceStrToken(char** str, SToken* token, const char* newToken) { + char* src = *str; + size_t nsize = strlen(newToken); int32_t size = (int32_t)strlen(*str) - token->n + (int32_t)nsize + 1; int32_t bsize = (int32_t)((uint64_t)token->z - (uint64_t)src); - SToken ntoken; + SToken ntoken; *str = taosMemoryCalloc(1, size); @@ -660,13 +659,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) { *i += t0.n; int32_t numOfComma = 0; - char t = str[*i]; + char t = str[*i]; while (t == ' ' || t == '\n' || t == '\r' || t == '\t' || t == '\f' || t == ',') { if (t == ',' && (++numOfComma > 1)) { // comma only allowed once t0.n = 0; return t0; } - + t = str[++(*i)]; } @@ -722,15 +721,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) { } } - t0.z = (char*) str + (*i); + t0.z = (char*)str + (*i); *i += t0.n; return t0; } -bool taosIsKeyWordToken(const char* z, int32_t len) { - return (tKeywordCode((char*)z, len) != TK_NK_ID); -} +bool taosIsKeyWordToken(const char* z, int32_t len) { return (tKeywordCode((char*)z, len) != TK_NK_ID); } void taosCleanupKeywordsTable() { void* m = keywordHashTable; @@ -741,7 +738,7 @@ void taosCleanupKeywordsTable() { SToken taosTokenDup(SToken* pToken, char* buf, int32_t len) { assert(pToken != NULL && buf != NULL && len > pToken->n); - + strncpy(buf, pToken->z, pToken->n); buf[pToken->n] = 0; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index e74a5ad6a9d111fcae0a84dee88455f57ff6ac1c..5bb82449b3238a7afb2d80b22946fde2d6bd9448 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -19,6 +19,7 @@ #include "cmdnodes.h" #include "functionMgt.h" #include "parUtil.h" +#include "scalar.h" #include "tglobal.h" #include "ttime.h" @@ -305,7 +306,10 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) { pCol->pProjectRef = (SNode*)pExpr; - nodesListAppend(pExpr->pAssociationList, (SNode*)pCol); + if (NULL == pExpr->pAssociation) { + pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); + } + taosArrayPush(pExpr->pAssociation, &pCol); if (NULL != pTable) { strcpy(pCol->tableAlias, pTable->tableAlias); } else if (QUERY_NODE_COLUMN == nodeType(pExpr)) { @@ -589,22 +593,25 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) { static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) { SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog, .pRpc = pCxt->pParseCxt->pTransporter, - .pMgmtEps = &pCxt->pParseCxt->mgmtEpSet}; - if (TSDB_CODE_SUCCESS != fmGetFuncInfo(¶m, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName); - } - pCxt->errCode = fmGetFuncResultType(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len); + .pMgmtEps = &pCxt->pParseCxt->mgmtEpSet, + .pErrBuf = pCxt->msgBuf.buf, + .errBufLen = pCxt->msgBuf.len}; + pCxt->errCode = fmGetFuncInfo(¶m, pFunc); if (TSDB_CODE_SUCCESS != pCxt->errCode) { return DEAL_RES_ERROR; } - if (fmIsAggFunc(pFunc->funcId) && beforeHaving(pCxt->currClause)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); - } - bool haveAggFunc = false; - nodesWalkExprs(pFunc->pParameterList, haveAggFunction, &haveAggFunc); - if (haveAggFunc) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING); + if (fmIsAggFunc(pFunc->funcId)) { + if (beforeHaving(pCxt->currClause)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); + } + bool haveAggFunc = false; + nodesWalkExprs(pFunc->pParameterList, haveAggFunction, &haveAggFunc); + if (haveAggFunc) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING); + } + pCxt->pCurrStmt->hasAggFuncs = true; } + return DEAL_RES_CONTINUE; } @@ -759,6 +766,19 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) { return TSDB_CODE_SUCCESS; } +static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) { + if (NULL == *pVgroupList) { + *pVgroupList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVgroupInfo)); + if (NULL == *pVgroupList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + SVgroupInfo vg = {.vgId = MNODE_HANDLE}; + memcpy(&vg.epSet, pEpSet, sizeof(SEpSet)); + taosArrayPush(*pVgroupList, &vg); + return TSDB_CODE_SUCCESS; +} + static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) { if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) { return TSDB_CODE_SUCCESS; @@ -766,12 +786,20 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea int32_t code = TSDB_CODE_SUCCESS; SArray* vgroupList = NULL; - if ('\0' != pRealTable->useDbName[0]) { - code = getDBVgInfo(pCxt, pRealTable->useDbName, &vgroupList); + 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); + // } } 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 = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList); } @@ -1965,13 +1993,6 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs if (1 != LIST_LENGTH(pFuncs)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROLLUP_OPTION); } - SFunctionNode* pFunc = nodesListGetNode(pFuncs, 0); - SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog, - .pRpc = pCxt->pParseCxt->pTransporter, - .pMgmtEps = &pCxt->pParseCxt->mgmtEpSet}; - if (TSDB_CODE_SUCCESS != fmGetFuncInfo(¶m, pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName); - } return TSDB_CODE_SUCCESS; } @@ -2001,13 +2022,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt return code; } -static int32_t getAggregationMethod(SNodeList* pFuncs) { - if (NULL == pFuncs) { - return -1; - } - return ((SFunctionNode*)nodesListGetNode(pFuncs, 0))->funcId; -} - static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchema) { int8_t flags = 0; if (pCol->sma) { @@ -2229,7 +2243,6 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt, static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) { pReq->igExists = pStmt->ignoreExists; - pReq->aggregationMethod = getAggregationMethod(pStmt->pOptions->pFuncs); 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); columnDefNodeToField(pStmt->pCols, &pReq->pColumns); @@ -3193,7 +3206,7 @@ static int32_t createShowCondition(const SShowStmt* pShow, SSelectStmt* pSelect) } if (NULL != pShow->pDbName) { - strcpy(((SRealTableNode*)pSelect->pFromTable)->useDbName, ((SValueNode*)pShow->pDbName)->literal); + strcpy(((SRealTableNode*)pSelect->pFromTable)->qualDbName, ((SValueNode*)pShow->pDbName)->literal); } return TSDB_CODE_SUCCESS; @@ -3235,14 +3248,6 @@ static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) { } 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); - pReq->ntbCfg.pRSmaParam->nFuncIds = LIST_LENGTH(pOptions->pFuncs); - pReq->ntbCfg.pRSmaParam->pFuncIds = taosMemoryCalloc(pReq->ntbCfg.pRSmaParam->nFuncIds, sizeof(func_id_t)); - if (NULL == pReq->ntbCfg.pRSmaParam->pFuncIds) { - return TSDB_CODE_OUT_OF_MEMORY; - } - int32_t index = 0; - SNode* pFunc = NULL; - FOREACH(pFunc, pOptions->pFuncs) { pReq->ntbCfg.pRSmaParam->pFuncIds[index++] = ((SFunctionNode*)pFunc)->funcId; } return TSDB_CODE_SUCCESS; } @@ -3428,10 +3433,6 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId); } - if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { - return pCxt->errCode; - } - if (pVal->node.resType.type == TSDB_DATA_TYPE_NULL) { // todo } else { @@ -3442,6 +3443,23 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS return TSDB_CODE_SUCCESS; } +static int32_t createValueFromFunction(STranslateContext* pCxt, SFunctionNode* pFunc, SValueNode** pVal) { + if (DEAL_RES_ERROR == translateFunction(pCxt, pFunc)) { + return pCxt->errCode; + } + return scalarCalculateConstants((SNode*)pFunc, (SNode**)pVal); +} + +static int32_t translateTagVal(STranslateContext* pCxt, SNode* pNode, SValueNode** pVal) { + if (QUERY_NODE_FUNCTION == nodeType(pNode)) { + return createValueFromFunction(pCxt, (SFunctionNode*)pNode, pVal); + } else if (QUERY_NODE_VALUE == nodeType(pNode)) { + return (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode) ? pCxt->errCode : TSDB_CODE_SUCCESS); + } else { + return TSDB_CODE_FAILED; + } +} + static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta, SKVRowBuilder* pBuilder) { int32_t numOfTags = getNumOfTags(pSuperTableMeta); @@ -3451,8 +3469,8 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla } SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); - SNode * pTag, *pVal; - FORBOTH(pTag, pStmt->pSpecificTags, pVal, pStmt->pValsOfTags) { + SNode * pTag, *pNode; + FORBOTH(pTag, pStmt->pSpecificTags, pNode, pStmt->pValsOfTags) { SColumnNode* pCol = (SColumnNode*)pTag; SSchema* pSchema = NULL; for (int32_t i = 0; i < numOfTags; ++i) { @@ -3464,7 +3482,18 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla if (NULL == pSchema) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName); } - int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pSchema, pBuilder); + SValueNode* pVal = NULL; + int32_t code = translateTagVal(pCxt, pNode, &pVal); + if (TSDB_CODE_SUCCESS == code) { + if (NULL == pVal) { + pVal = (SValueNode*)pNode; + } else { + REPLACE_LIST2_NODE(pVal); + } + } + if (TSDB_CODE_SUCCESS == code) { + code = addValToKVRow(pCxt, pVal, pSchema, pBuilder); + } if (TSDB_CODE_SUCCESS != code) { return code; } @@ -3480,10 +3509,21 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau } SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); - SNode* pVal; + SNode* pNode; int32_t index = 0; - FOREACH(pVal, pStmt->pValsOfTags) { - int32_t code = addValToKVRow(pCxt, (SValueNode*)pVal, pTagSchema + index++, pBuilder); + FOREACH(pNode, pStmt->pValsOfTags) { + SValueNode* pVal = NULL; + int32_t code = translateTagVal(pCxt, pNode, &pVal); + if (TSDB_CODE_SUCCESS == code) { + if (NULL == pVal) { + pVal = (SValueNode*)pNode; + } else { + REPLACE_NODE(pVal); + } + } + if (TSDB_CODE_SUCCESS == code) { + code = addValToKVRow(pCxt, pVal, pTagSchema + index++, pBuilder); + } if (TSDB_CODE_SUCCESS != code) { return code; } diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index fd700f8d461ff2dd38541d40856102c82acd87a1..3ffdaad3e6443df4dea09504421ebe867da2f15d 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -30,8 +30,6 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "Column ambiguously defined: %s"; case TSDB_CODE_PAR_WRONG_VALUE_TYPE: return "Invalid value type: %s"; - case TSDB_CODE_PAR_INVALID_FUNTION: - return "Invalid function name: %s"; case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION: return "There mustn't be aggregation"; case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT: @@ -65,13 +63,13 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR: return "Corresponding super table not in this db"; case TSDB_CODE_PAR_INVALID_RANGE_OPTION: - return "Invalid option %s: %"PRId64" valid range: [%d, %d]"; + return "Invalid option %s: %" PRId64 " valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_STR_OPTION: return "Invalid option %s: %s"; case TSDB_CODE_PAR_INVALID_ENUM_OPTION: - return "Invalid option %s: %"PRId64", only %d, %d allowed"; + 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"; + 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: @@ -196,20 +194,22 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) { return p; } -SSchema *getTableColumnSchema(const STableMeta *pTableMeta) { +SSchema* getTableColumnSchema(const STableMeta* pTableMeta) { assert(pTableMeta != NULL); - return (SSchema*) pTableMeta->schema; + return (SSchema*)pTableMeta->schema; } static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) { - assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta))); + assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && + colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta))); - SSchema* pSchema = (SSchema*) pTableMeta->schema; + SSchema* pSchema = (SSchema*)pTableMeta->schema; return &pSchema[colIndex]; } SSchema* getTableTagSchema(const STableMeta* pTableMeta) { - assert(pTableMeta != NULL && (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE)); + assert(pTableMeta != NULL && + (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE)); return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns); } @@ -230,40 +230,40 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta) { } int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) { - if (len <=0 || dlen <= 0) return 0; + if (len <= 0 || dlen <= 0) return 0; - char delim = src[0]; + char delim = src[0]; int32_t j = 0; for (uint32_t k = 1; k < len - 1; ++k) { if (j >= dlen) { dst[j - 1] = '\0'; return j; } - if (src[k] == delim && src[k + 1] == delim) { // deal with "", '' + if (src[k] == delim && src[k + 1] == delim) { // deal with "", '' dst[j] = src[k + 1]; j++; k++; continue; } - if (src[k] == '\\') { // deal with escape character - if(src[k+1] == 'n'){ + if (src[k] == '\\') { // deal with escape character + if (src[k + 1] == 'n') { dst[j] = '\n'; - }else if(src[k+1] == 'r'){ + } else if (src[k + 1] == 'r') { dst[j] = '\r'; - }else if(src[k+1] == 't'){ + } else if (src[k + 1] == 't') { dst[j] = '\t'; - }else if(src[k+1] == '\\'){ + } else if (src[k + 1] == '\\') { dst[j] = '\\'; - }else if(src[k+1] == '\''){ + } else if (src[k + 1] == '\'') { dst[j] = '\''; - }else if(src[k+1] == '"'){ + } else if (src[k + 1] == '"') { dst[j] = '"'; - }else if(src[k+1] == '%' || src[k+1] == '_'){ + } else if (src[k + 1] == '%' || src[k + 1] == '_') { dst[j++] = src[k]; - dst[j] = src[k+1]; - }else{ - dst[j] = src[k+1]; + dst[j] = src[k + 1]; + } else { + dst[j] = src[k + 1]; } j++; k++; @@ -277,7 +277,7 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) { return j; } -static bool isValidateTag(char *input) { +static bool isValidateTag(char* input) { if (!input) return false; for (size_t i = 0; i < strlen(input); ++i) { if (isprint(input[i]) == 0) return false; @@ -285,30 +285,30 @@ static bool isValidateTag(char *input) { return true; } -int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* pMsgBuf, int16_t startColId){ +int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* pMsgBuf, int16_t startColId) { // set json NULL data uint8_t jsonNULL = TSDB_DATA_TYPE_NULL; - int jsonIndex = startColId + 1; - if (!json || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0){ + int jsonIndex = startColId + 1; + if (!json || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0) { tdAddColToKVRow(kvRowBuilder, jsonIndex, &jsonNULL, CHAR_BYTES); return TSDB_CODE_SUCCESS; } // set json real data - cJSON *root = cJSON_Parse(json); - if (root == NULL){ + cJSON* root = cJSON_Parse(json); + if (root == NULL) { return buildSyntaxErrMsg(pMsgBuf, "json parse error", json); } int size = cJSON_GetArraySize(root); - if(!cJSON_IsObject(root)){ + if (!cJSON_IsObject(root)) { return buildSyntaxErrMsg(pMsgBuf, "json error invalide value", json); } - int retCode = 0; - char *tagKV = NULL; + int retCode = 0; + char* tagKV = NULL; SHashObj* keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { cJSON* item = cJSON_GetArrayItem(root, i); if (!item) { qError("json inner error:%d", i); @@ -316,40 +316,41 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p goto end; } - char *jsonKey = item->string; - if(!isValidateTag(jsonKey)){ + char* jsonKey = item->string; + if (!isValidateTag(jsonKey)) { retCode = buildSyntaxErrMsg(pMsgBuf, "json key not validate", jsonKey); goto end; } -// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){ -// tscError("json key too long error"); -// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL); -// goto end; -// } + // if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){ + // tscError("json key too long error"); + // retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL); + // goto end; + // } size_t keyLen = strlen(jsonKey); - if(keyLen == 0 || taosHashGet(keyHash, jsonKey, keyLen) != NULL){ + if (keyLen == 0 || taosHashGet(keyHash, jsonKey, keyLen) != NULL) { continue; } // key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: LONG_BYTES tagKV = taosMemoryCalloc(keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES, 1); - if(!tagKV) { + if (!tagKV) { retCode = TSDB_CODE_TSC_OUT_OF_MEMORY; goto end; } strncpy(varDataVal(tagKV), jsonKey, keyLen); varDataSetLen(tagKV, keyLen); - if(taosHashGetSize(keyHash) == 0){ + if (taosHashGetSize(keyHash) == 0) { uint8_t jsonNotNULL = TSDB_DATA_TYPE_JSON; - tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNotNULL, CHAR_BYTES); // add json type + tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNotNULL, CHAR_BYTES); // add json type } - taosHashPut(keyHash, jsonKey, keyLen, &keyLen, CHAR_BYTES); // add key to hash to remove dumplicate, value is useless + taosHashPut(keyHash, jsonKey, keyLen, &keyLen, + CHAR_BYTES); // add key to hash to remove dumplicate, value is useless - if(item->type == cJSON_String){ // add json value format: type|data - char *jsonValue = item->valuestring; + if (item->type == cJSON_String) { // add json value format: type|data + char* jsonValue = item->valuestring; int32_t valLen = (int32_t)strlen(jsonValue); int32_t totalLen = keyLen + VARSTR_HEADER_SIZE + valLen * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE + CHAR_BYTES; - char *tmp = taosMemoryRealloc(tagKV, totalLen); - if(!tmp) { + char* tmp = taosMemoryRealloc(tagKV, totalLen); + if (!tmp) { retCode = TSDB_CODE_TSC_OUT_OF_MEMORY; goto end; } @@ -358,44 +359,47 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); *valueType = TSDB_DATA_TYPE_NCHAR; if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)varDataVal(valueData), - (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) { - qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, strerror(errno)); + (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) { + qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, + strerror(errno)); retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue); goto end; } varDataSetLen(valueData, valLen); tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, totalLen); - }else if(item->type == cJSON_Number){ - if(!isfinite(item->valuedouble)){ + } else if (item->type == cJSON_Number) { + if (!isfinite(item->valuedouble)) { qError("json value is invalidate"); - retCode = buildSyntaxErrMsg(pMsgBuf, "json value number is illegal", json); + retCode = buildSyntaxErrMsg(pMsgBuf, "json value number is illegal", json); goto end; } char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE); char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); - *valueType = (item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE; - if(*valueType== TSDB_DATA_TYPE_DOUBLE) *((double *)valueData) = item->valuedouble; - else if(*valueType == TSDB_DATA_TYPE_BIGINT) *((int64_t *)valueData) = item->valueint; - tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES +LONG_BYTES); - }else if(item->type == cJSON_True || item->type == cJSON_False){ + *valueType = + (item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE; + if (*valueType == TSDB_DATA_TYPE_DOUBLE) + *((double*)valueData) = item->valuedouble; + else if (*valueType == TSDB_DATA_TYPE_BIGINT) + *((int64_t*)valueData) = item->valueint; + tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES); + } else if (item->type == cJSON_True || item->type == cJSON_False) { char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE); char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); *valueType = TSDB_DATA_TYPE_BOOL; *valueData = (char)(item->valueint); tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + CHAR_BYTES); - }else if(item->type == cJSON_NULL){ + } else if (item->type == cJSON_NULL) { char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE); *valueType = TSDB_DATA_TYPE_NULL; tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES); - } - else{ + } else { retCode = buildSyntaxErrMsg(pMsgBuf, "invalidate json value", json); goto end; } } - if(taosHashGetSize(keyHash) == 0){ // set json NULL true + if (taosHashGetSize(keyHash) == 0) { // set json NULL true tdAddColToKVRow(kvRowBuilder, jsonIndex, &jsonNULL, CHAR_BYTES); } diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index f17322063adc8a176fd0e61115ef81dc39a5121f..09ef130bc1e2c8288f887d214e837281f6eafaa9 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include "os.h" #include "parser.h" +#include "os.h" #include "parInt.h" #include "parToken.h" @@ -23,11 +23,11 @@ bool isInsertSql(const char* pStr, size_t length) { if (NULL == pStr) { return false; } - + int32_t index = 0; do { - SToken t0 = tStrGetToken((char*) pStr, &index, false); + SToken t0 = tStrGetToken((char*)pStr, &index, false); if (t0.type != TK_NK_LP) { return t0.type == TK_INSERT || t0.type == TK_IMPORT; } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 97f718c1518d1fe9cacff97bf14b9a34f6f7b6c2..18f0809dfd2d24cbf82e145b24a89367dd030b05 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -32,7 +32,6 @@ #include #include -#include "os.h" #include "functionMgt.h" #include "nodes.h" #include "parToken.h" @@ -101,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 346 +#define YYNOCODE 347 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SAlterOption yy145; - EOrder yy250; - EOperatorType yy348; - int32_t yy376; - SDataType yy380; - SNode* yy456; - SToken yy517; - EFillMode yy534; - ENullOrder yy645; - SNodeList* yy652; - bool yy673; - EJoinType yy684; + EJoinType yy84; + SDataType yy156; + ENullOrder yy181; + EOrder yy272; + EFillMode yy284; + EOperatorType yy304; + SAlterOption yy475; + SToken yy555; + SNodeList* yy568; + int32_t yy610; + bool yy617; + SNode* yy662; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -134,17 +133,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 574 -#define YYNRULE 441 +#define YYNSTATE 575 +#define YYNRULE 444 #define YYNTOKEN 231 -#define YY_MAX_SHIFT 573 -#define YY_MIN_SHIFTREDUCE 855 -#define YY_MAX_SHIFTREDUCE 1295 -#define YY_ERROR_ACTION 1296 -#define YY_ACCEPT_ACTION 1297 -#define YY_NO_ACTION 1298 -#define YY_MIN_REDUCE 1299 -#define YY_MAX_REDUCE 1739 +#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 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -211,544 +210,573 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1906) +#define YY_ACTTAB_COUNT (2021) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 487, 1718, 1590, 1502, 273, 474, 322, 290, 285, 78, - /* 10 */ 146, 1514, 33, 31, 1717, 1410, 386, 407, 1715, 487, - /* 20 */ 282, 1576, 1115, 1470, 1576, 1421, 1606, 125, 78, 272, - /* 30 */ 447, 1378, 415, 450, 1468, 393, 1572, 1578, 1113, 1572, - /* 40 */ 1578, 26, 205, 470, 1421, 1718, 174, 1562, 1576, 410, - /* 50 */ 12, 33, 31, 1237, 404, 105, 486, 1121, 137, 282, - /* 60 */ 173, 1115, 1715, 1572, 1579, 54, 74, 1591, 473, 1593, - /* 70 */ 1594, 469, 486, 464, 59, 1, 1656, 1113, 100, 487, - /* 80 */ 275, 1652, 132, 30, 29, 28, 1416, 45, 326, 12, - /* 90 */ 44, 54, 103, 486, 201, 293, 1121, 286, 570, 1348, - /* 100 */ 430, 1683, 1505, 1507, 1421, 122, 449, 133, 1663, 1664, - /* 110 */ 1114, 1668, 1417, 1423, 1, 1300, 983, 510, 509, 508, - /* 120 */ 987, 507, 989, 990, 506, 992, 503, 36, 998, 500, - /* 130 */ 1000, 1001, 497, 494, 9, 8, 89, 570, 1136, 88, - /* 140 */ 87, 86, 85, 84, 83, 82, 81, 80, 36, 1114, - /* 150 */ 1116, 546, 545, 544, 543, 297, 365, 542, 541, 540, - /* 160 */ 108, 535, 534, 533, 532, 531, 530, 529, 528, 115, - /* 170 */ 524, 1119, 1120, 63, 1164, 1165, 1166, 1167, 1168, 1169, - /* 180 */ 1170, 466, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1116, - /* 190 */ 891, 1606, 292, 402, 1414, 396, 416, 1297, 471, 401, - /* 200 */ 122, 138, 102, 1140, 397, 395, 384, 398, 1423, 1213, - /* 210 */ 1119, 1120, 394, 1164, 1165, 1166, 1167, 1168, 1169, 1170, - /* 220 */ 466, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 33, 31, - /* 230 */ 101, 1590, 414, 440, 389, 1718, 282, 250, 1115, 1136, - /* 240 */ 34, 32, 30, 29, 28, 412, 344, 1718, 137, 356, - /* 250 */ 1670, 298, 1715, 138, 1113, 1606, 1299, 392, 357, 1470, - /* 260 */ 1716, 321, 471, 320, 1715, 287, 12, 33, 31, 487, - /* 270 */ 1468, 138, 470, 1121, 1667, 282, 1562, 1115, 327, 138, - /* 280 */ 98, 97, 96, 95, 94, 93, 92, 91, 90, 1412, - /* 290 */ 1718, 1, 1138, 1113, 1421, 74, 1591, 473, 1593, 1594, - /* 300 */ 469, 328, 464, 137, 1251, 1656, 128, 1715, 69, 275, - /* 310 */ 1652, 1730, 1121, 138, 570, 1261, 1470, 1462, 65, 138, - /* 320 */ 1690, 1077, 294, 200, 56, 270, 1114, 1468, 175, 1079, - /* 330 */ 7, 251, 355, 264, 1562, 350, 349, 348, 347, 346, - /* 340 */ 6, 343, 342, 341, 340, 339, 335, 334, 333, 332, - /* 350 */ 331, 330, 329, 570, 434, 1259, 1260, 1262, 1263, 101, - /* 360 */ 892, 441, 891, 389, 89, 1114, 1116, 88, 87, 86, - /* 370 */ 85, 84, 83, 82, 81, 80, 265, 1322, 263, 262, - /* 380 */ 893, 388, 437, 124, 48, 1311, 392, 1119, 1120, 1078, - /* 390 */ 1164, 1165, 1166, 1167, 1168, 1169, 1170, 466, 1175, 1176, - /* 400 */ 1177, 1178, 1179, 1180, 1181, 1116, 1398, 22, 295, 34, - /* 410 */ 32, 30, 29, 28, 1351, 523, 122, 34, 32, 30, - /* 420 */ 29, 28, 1562, 1141, 1423, 228, 1119, 1120, 1451, 1164, - /* 430 */ 1165, 1166, 1167, 1168, 1169, 1170, 466, 1175, 1176, 1177, - /* 440 */ 1178, 1179, 1180, 1181, 33, 31, 1182, 254, 24, 1201, - /* 450 */ 442, 438, 282, 424, 1115, 1590, 138, 945, 34, 32, - /* 460 */ 30, 29, 28, 566, 565, 487, 402, 107, 396, 1206, - /* 470 */ 1113, 518, 401, 1151, 336, 102, 947, 397, 395, 1606, - /* 480 */ 398, 1199, 313, 33, 31, 394, 471, 391, 390, 1121, - /* 490 */ 1421, 282, 1139, 1115, 521, 1321, 470, 1232, 425, 474, - /* 500 */ 1562, 315, 487, 1320, 23, 1515, 451, 7, 1590, 1113, - /* 510 */ 1137, 337, 1319, 517, 516, 515, 487, 514, 1318, 73, - /* 520 */ 1591, 473, 1593, 1594, 469, 364, 464, 1421, 1121, 1656, - /* 530 */ 570, 1200, 1606, 253, 1652, 487, 351, 1718, 70, 471, - /* 540 */ 1562, 1421, 1114, 186, 1418, 1718, 7, 122, 1562, 470, - /* 550 */ 137, 1205, 106, 1562, 1715, 1424, 431, 1562, 137, 1413, - /* 560 */ 1421, 513, 1715, 1562, 34, 32, 30, 29, 28, 570, - /* 570 */ 144, 487, 249, 1591, 473, 1593, 1594, 469, 1317, 464, - /* 580 */ 1543, 1114, 1116, 148, 147, 1316, 25, 280, 1194, 1195, - /* 590 */ 1196, 1197, 1198, 1202, 1203, 1204, 1421, 52, 453, 1315, - /* 600 */ 51, 400, 399, 1119, 1120, 526, 1164, 1165, 1166, 1167, - /* 610 */ 1168, 1169, 1170, 466, 1175, 1176, 1177, 1178, 1179, 1180, - /* 620 */ 1181, 1116, 1314, 1562, 1313, 34, 32, 30, 29, 28, - /* 630 */ 1562, 457, 1310, 34, 32, 30, 29, 28, 1399, 520, - /* 640 */ 519, 1236, 1119, 1120, 1562, 1164, 1165, 1166, 1167, 1168, - /* 650 */ 1169, 1170, 466, 1175, 1176, 1177, 1178, 1179, 1180, 1181, - /* 660 */ 33, 31, 1309, 254, 1670, 1590, 1670, 1562, 282, 1562, - /* 670 */ 1115, 34, 32, 30, 29, 28, 447, 1562, 34, 32, - /* 680 */ 30, 29, 28, 289, 288, 1406, 1113, 365, 1666, 1606, - /* 690 */ 1665, 1397, 1583, 1129, 487, 1292, 450, 1199, 527, 487, - /* 700 */ 1393, 105, 487, 484, 1581, 1121, 470, 1562, 485, 1122, - /* 710 */ 1562, 219, 539, 537, 1506, 1507, 487, 1408, 1590, 1421, - /* 720 */ 1308, 451, 1404, 1, 1421, 296, 1307, 1421, 1121, 74, - /* 730 */ 1591, 473, 1593, 1594, 469, 1151, 464, 178, 103, 1656, - /* 740 */ 523, 1421, 1606, 275, 1652, 132, 570, 1200, 1306, 471, - /* 750 */ 1305, 1101, 1102, 198, 1663, 446, 1304, 445, 1114, 470, - /* 760 */ 1718, 121, 538, 1562, 1684, 1562, 316, 1205, 1303, 488, - /* 770 */ 1302, 1562, 1244, 137, 1291, 1675, 1232, 1715, 1138, 1470, - /* 780 */ 458, 1125, 75, 1591, 473, 1593, 1594, 469, 1187, 464, - /* 790 */ 1469, 454, 1656, 1562, 1138, 1562, 1655, 1652, 1116, 9, - /* 800 */ 8, 1562, 25, 280, 1194, 1195, 1196, 1197, 1198, 1202, - /* 810 */ 1203, 1204, 465, 1562, 1551, 1562, 1590, 40, 252, 1119, - /* 820 */ 1120, 1130, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 466, - /* 830 */ 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1396, 123, 1235, - /* 840 */ 1606, 166, 1133, 234, 164, 1338, 168, 471, 1590, 167, - /* 850 */ 305, 170, 1333, 1115, 169, 232, 172, 470, 113, 171, - /* 860 */ 47, 1562, 426, 512, 1258, 1294, 1295, 403, 149, 1113, - /* 870 */ 1331, 189, 1606, 35, 405, 191, 461, 1207, 1312, 471, - /* 880 */ 74, 1591, 473, 1593, 1594, 469, 423, 464, 1121, 470, - /* 890 */ 1656, 1379, 408, 1562, 275, 1652, 1730, 35, 107, 35, - /* 900 */ 208, 1171, 518, 1072, 210, 1713, 110, 111, 202, 435, - /* 910 */ 479, 216, 74, 1591, 473, 1593, 1594, 469, 1463, 464, - /* 920 */ 113, 1124, 1656, 1123, 976, 521, 275, 1652, 1730, 570, - /* 930 */ 195, 47, 72, 417, 383, 971, 917, 1674, 455, 492, - /* 940 */ 448, 1114, 1686, 1004, 517, 516, 515, 111, 514, 112, - /* 950 */ 447, 1008, 113, 1015, 111, 918, 1014, 1607, 114, 2, - /* 960 */ 204, 1136, 300, 50, 49, 325, 304, 143, 1590, 259, - /* 970 */ 945, 261, 319, 224, 145, 105, 338, 1590, 1085, 1504, - /* 980 */ 345, 1116, 352, 353, 260, 354, 311, 358, 307, 303, - /* 990 */ 140, 1145, 1606, 1127, 359, 1126, 150, 1191, 360, 471, - /* 1000 */ 1144, 1606, 1119, 1120, 361, 153, 362, 1143, 471, 470, - /* 1010 */ 156, 363, 103, 1562, 1142, 53, 366, 159, 470, 451, - /* 1020 */ 385, 138, 1562, 387, 1411, 79, 269, 134, 1663, 1664, - /* 1030 */ 1121, 1668, 241, 1591, 473, 1593, 1594, 469, 1590, 464, - /* 1040 */ 163, 75, 1591, 473, 1593, 1594, 469, 1407, 464, 165, - /* 1050 */ 116, 1656, 117, 1409, 1405, 460, 1652, 1547, 1718, 573, - /* 1060 */ 118, 119, 1606, 428, 447, 418, 1141, 1687, 176, 468, - /* 1070 */ 225, 137, 419, 223, 427, 1715, 99, 179, 181, 470, - /* 1080 */ 422, 184, 562, 1562, 558, 554, 550, 222, 436, 105, - /* 1090 */ 226, 1697, 1590, 187, 477, 433, 444, 190, 1696, 194, - /* 1100 */ 274, 439, 248, 1591, 473, 1593, 1594, 469, 467, 464, - /* 1110 */ 462, 1628, 5, 432, 71, 4, 1606, 217, 1232, 104, - /* 1120 */ 1140, 130, 37, 471, 1590, 197, 103, 196, 1677, 1671, - /* 1130 */ 276, 459, 456, 470, 16, 1513, 475, 1562, 481, 476, - /* 1140 */ 1590, 135, 1663, 1664, 1512, 1668, 480, 483, 1606, 212, - /* 1150 */ 203, 1733, 1714, 284, 1637, 471, 126, 1591, 473, 1593, - /* 1160 */ 1594, 469, 214, 464, 1606, 470, 62, 482, 1422, 1562, - /* 1170 */ 227, 471, 64, 1394, 490, 229, 429, 221, 569, 182, - /* 1180 */ 43, 470, 233, 129, 271, 1562, 235, 231, 244, 1591, - /* 1190 */ 473, 1593, 1594, 469, 1556, 464, 1093, 236, 177, 1590, - /* 1200 */ 452, 1731, 1555, 299, 75, 1591, 473, 1593, 1594, 469, - /* 1210 */ 301, 464, 1590, 1552, 1656, 302, 1109, 1110, 141, 1653, - /* 1220 */ 306, 1550, 308, 1606, 309, 310, 443, 1549, 312, 1548, - /* 1230 */ 471, 314, 1533, 142, 317, 318, 1606, 1088, 1087, 1527, - /* 1240 */ 470, 1526, 323, 471, 1562, 324, 1525, 1524, 1055, 1497, - /* 1250 */ 1496, 1495, 1494, 470, 1493, 1492, 1491, 1562, 109, 1480, - /* 1260 */ 279, 1490, 1489, 126, 1591, 473, 1593, 1594, 469, 1590, - /* 1270 */ 464, 155, 1400, 910, 1349, 1057, 249, 1591, 473, 1593, - /* 1280 */ 1594, 469, 1488, 464, 1487, 1486, 1485, 1484, 1483, 1482, - /* 1290 */ 1481, 1479, 1478, 1606, 1477, 1476, 1475, 1474, 1473, 1472, - /* 1300 */ 468, 1471, 1350, 1541, 1535, 1519, 1510, 1347, 1732, 369, - /* 1310 */ 470, 367, 368, 1345, 1562, 371, 372, 1590, 373, 1343, - /* 1320 */ 1341, 375, 377, 1330, 381, 1329, 1326, 1402, 77, 376, - /* 1330 */ 162, 1401, 536, 248, 1591, 473, 1593, 1594, 469, 538, - /* 1340 */ 464, 1606, 1629, 1020, 380, 1339, 1590, 379, 471, 1023, - /* 1350 */ 944, 266, 943, 942, 941, 940, 937, 1334, 470, 267, - /* 1360 */ 936, 1332, 1562, 406, 268, 281, 409, 1325, 411, 1324, - /* 1370 */ 1606, 413, 76, 1540, 46, 1534, 1095, 471, 120, 180, - /* 1380 */ 420, 249, 1591, 473, 1593, 1594, 469, 470, 464, 1518, - /* 1390 */ 1517, 1562, 161, 183, 283, 131, 1590, 421, 1509, 185, - /* 1400 */ 13, 382, 3, 378, 374, 370, 160, 57, 35, 188, - /* 1410 */ 249, 1591, 473, 1593, 1594, 469, 41, 464, 38, 14, - /* 1420 */ 1606, 11, 1581, 1257, 1250, 1280, 127, 471, 192, 20, - /* 1430 */ 58, 8, 193, 55, 21, 1590, 158, 470, 39, 1229, - /* 1440 */ 1228, 1562, 1279, 199, 1590, 277, 1285, 1284, 15, 1283, - /* 1450 */ 278, 17, 136, 1174, 1173, 463, 27, 1159, 139, 1606, - /* 1460 */ 237, 1591, 473, 1593, 1594, 469, 471, 464, 1606, 1508, - /* 1470 */ 1172, 1192, 10, 206, 18, 471, 470, 19, 478, 207, - /* 1480 */ 1562, 1255, 213, 472, 1131, 470, 65, 1580, 209, 1562, - /* 1490 */ 211, 60, 1590, 61, 157, 218, 152, 42, 154, 243, - /* 1500 */ 1591, 473, 1593, 1594, 469, 1590, 464, 215, 245, 1591, - /* 1510 */ 473, 1593, 1594, 469, 489, 464, 1606, 151, 491, 1005, - /* 1520 */ 291, 493, 495, 471, 1002, 496, 498, 999, 499, 1606, - /* 1530 */ 993, 501, 502, 470, 991, 504, 471, 1562, 505, 982, - /* 1540 */ 997, 996, 66, 511, 995, 994, 470, 1017, 1016, 67, - /* 1550 */ 1562, 68, 1013, 1010, 908, 522, 238, 1591, 473, 1593, - /* 1560 */ 1594, 469, 933, 464, 951, 525, 220, 931, 1590, 246, - /* 1570 */ 1591, 473, 1593, 1594, 469, 930, 464, 1590, 929, 928, - /* 1580 */ 927, 926, 925, 924, 948, 946, 921, 920, 919, 1346, - /* 1590 */ 916, 915, 1606, 914, 913, 547, 548, 549, 1344, 471, - /* 1600 */ 551, 1606, 552, 1342, 556, 555, 553, 557, 471, 470, - /* 1610 */ 1340, 559, 560, 1562, 561, 1328, 1590, 563, 470, 564, - /* 1620 */ 1327, 1323, 1562, 567, 1117, 568, 571, 1590, 230, 572, - /* 1630 */ 1298, 1298, 239, 1591, 473, 1593, 1594, 469, 1298, 464, - /* 1640 */ 1606, 247, 1591, 473, 1593, 1594, 469, 471, 464, 1298, - /* 1650 */ 1298, 1606, 1298, 1298, 1298, 1298, 1298, 470, 471, 1298, - /* 1660 */ 1298, 1562, 1298, 1298, 1298, 1298, 1298, 1298, 470, 1298, - /* 1670 */ 1298, 1298, 1562, 1298, 1298, 1298, 1590, 1298, 1298, 1298, - /* 1680 */ 240, 1591, 473, 1593, 1594, 469, 1298, 464, 1298, 1298, - /* 1690 */ 1298, 1602, 1591, 473, 1593, 1594, 469, 1298, 464, 1298, - /* 1700 */ 1606, 1298, 1298, 1298, 1298, 1298, 1298, 471, 1298, 1298, - /* 1710 */ 1298, 1298, 1298, 1298, 1298, 1590, 1298, 470, 1298, 1298, - /* 1720 */ 1298, 1562, 1298, 1298, 1590, 1298, 1298, 1298, 1298, 1298, - /* 1730 */ 1298, 1298, 1298, 1590, 1298, 1298, 1298, 1298, 1298, 1606, - /* 1740 */ 1601, 1591, 473, 1593, 1594, 469, 471, 464, 1606, 1298, - /* 1750 */ 1298, 1298, 1298, 1298, 1298, 471, 470, 1606, 1298, 1298, - /* 1760 */ 1562, 1298, 1298, 1298, 471, 470, 1298, 1298, 1298, 1562, - /* 1770 */ 1298, 1298, 1590, 1298, 470, 1298, 1298, 1298, 1562, 1600, - /* 1780 */ 1591, 473, 1593, 1594, 469, 1590, 464, 1298, 257, 1591, - /* 1790 */ 473, 1593, 1594, 469, 1298, 464, 1606, 256, 1591, 473, - /* 1800 */ 1593, 1594, 469, 471, 464, 1298, 1298, 1298, 1298, 1606, - /* 1810 */ 1298, 1298, 1298, 470, 1298, 1298, 471, 1562, 1298, 1298, - /* 1820 */ 1298, 1298, 1298, 1298, 1298, 1298, 470, 1298, 1298, 1298, - /* 1830 */ 1562, 1298, 1298, 1298, 1590, 1298, 258, 1591, 473, 1593, - /* 1840 */ 1594, 469, 1298, 464, 1298, 1298, 1298, 1298, 1298, 255, - /* 1850 */ 1591, 473, 1593, 1594, 469, 1298, 464, 1298, 1606, 1298, - /* 1860 */ 1298, 1298, 1298, 1298, 1298, 471, 1298, 1298, 1298, 1298, - /* 1870 */ 1298, 1298, 1298, 1298, 1298, 470, 1298, 1298, 1298, 1562, - /* 1880 */ 1298, 1298, 1298, 1298, 1298, 1298, 1298, 1298, 1298, 1298, - /* 1890 */ 1298, 1298, 1298, 1298, 1298, 1298, 1298, 1298, 242, 1591, - /* 1900 */ 473, 1593, 1594, 469, 1298, 464, + /* 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, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 240, 324, 234, 265, 262, 275, 285, 262, 278, 249, - /* 10 */ 272, 281, 12, 13, 337, 259, 256, 4, 341, 240, - /* 20 */ 20, 279, 22, 258, 279, 265, 258, 243, 249, 264, - /* 30 */ 240, 247, 19, 265, 269, 256, 294, 295, 38, 294, - /* 40 */ 295, 309, 310, 275, 265, 324, 33, 279, 279, 36, - /* 50 */ 50, 12, 13, 14, 41, 265, 20, 57, 337, 20, - /* 60 */ 47, 22, 341, 294, 295, 242, 298, 299, 300, 301, - /* 70 */ 302, 303, 20, 305, 4, 75, 308, 38, 255, 240, - /* 80 */ 312, 313, 314, 14, 15, 16, 263, 74, 249, 50, - /* 90 */ 77, 242, 302, 20, 326, 267, 57, 250, 98, 0, - /* 100 */ 332, 333, 274, 275, 265, 258, 316, 317, 318, 319, - /* 110 */ 110, 321, 263, 266, 75, 0, 89, 90, 91, 92, - /* 120 */ 93, 94, 95, 96, 97, 98, 99, 75, 101, 102, - /* 130 */ 103, 104, 105, 106, 1, 2, 21, 98, 20, 24, - /* 140 */ 25, 26, 27, 28, 29, 30, 31, 32, 75, 110, - /* 150 */ 150, 52, 53, 54, 55, 56, 49, 58, 59, 60, + /* 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, 239, 174, 175, 176, 177, 178, 179, + /* 170 */ 71, 171, 172, 20, 174, 175, 176, 177, 178, 179, /* 180 */ 180, 181, 182, 183, 184, 185, 186, 187, 188, 150, - /* 190 */ 22, 258, 250, 52, 260, 54, 285, 231, 265, 58, - /* 200 */ 258, 201, 61, 20, 63, 64, 38, 66, 266, 76, + /* 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, /* 220 */ 181, 182, 183, 184, 185, 186, 187, 188, 12, 13, - /* 230 */ 61, 234, 21, 300, 65, 324, 20, 18, 22, 20, - /* 240 */ 12, 13, 14, 15, 16, 34, 27, 324, 337, 30, - /* 250 */ 296, 285, 341, 201, 38, 258, 0, 88, 39, 258, - /* 260 */ 337, 149, 265, 151, 341, 264, 50, 12, 13, 240, - /* 270 */ 269, 201, 275, 57, 320, 20, 279, 22, 249, 201, - /* 280 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 234, - /* 290 */ 324, 75, 20, 38, 265, 298, 299, 300, 301, 302, - /* 300 */ 303, 240, 305, 337, 76, 308, 257, 341, 75, 312, - /* 310 */ 313, 314, 57, 201, 98, 171, 258, 268, 85, 201, - /* 320 */ 323, 74, 264, 140, 159, 160, 110, 269, 163, 82, - /* 330 */ 75, 270, 113, 35, 279, 116, 117, 118, 119, 120, - /* 340 */ 43, 122, 123, 124, 125, 126, 127, 128, 129, 130, - /* 350 */ 131, 132, 133, 98, 210, 211, 212, 213, 214, 61, - /* 360 */ 20, 20, 22, 65, 21, 110, 150, 24, 25, 26, - /* 370 */ 27, 28, 29, 30, 31, 32, 78, 234, 80, 81, - /* 380 */ 40, 83, 138, 233, 3, 235, 88, 171, 172, 142, + /* 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, /* 390 */ 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, - /* 400 */ 184, 185, 186, 187, 188, 150, 0, 2, 250, 12, - /* 410 */ 13, 14, 15, 16, 0, 49, 258, 12, 13, 14, - /* 420 */ 15, 16, 279, 20, 266, 251, 171, 172, 254, 174, + /* 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, /* 430 */ 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, - /* 440 */ 185, 186, 187, 188, 12, 13, 14, 50, 2, 134, - /* 450 */ 206, 207, 20, 240, 22, 234, 201, 38, 12, 13, - /* 460 */ 14, 15, 16, 237, 238, 240, 52, 61, 54, 154, - /* 470 */ 38, 65, 58, 76, 249, 61, 57, 63, 64, 258, - /* 480 */ 66, 84, 146, 12, 13, 71, 265, 244, 245, 57, - /* 490 */ 265, 20, 20, 22, 88, 234, 275, 200, 285, 275, - /* 500 */ 279, 165, 240, 234, 189, 281, 285, 75, 234, 38, - /* 510 */ 20, 249, 234, 107, 108, 109, 240, 111, 234, 298, - /* 520 */ 299, 300, 301, 302, 303, 249, 305, 265, 57, 308, - /* 530 */ 98, 134, 258, 312, 313, 240, 67, 324, 239, 265, - /* 540 */ 279, 265, 110, 140, 249, 324, 75, 258, 279, 275, - /* 550 */ 337, 154, 253, 279, 341, 266, 282, 279, 337, 260, - /* 560 */ 265, 86, 341, 279, 12, 13, 14, 15, 16, 98, - /* 570 */ 47, 240, 298, 299, 300, 301, 302, 303, 234, 305, - /* 580 */ 249, 110, 150, 114, 115, 234, 189, 190, 191, 192, - /* 590 */ 193, 194, 195, 196, 197, 198, 265, 74, 217, 234, - /* 600 */ 77, 244, 245, 171, 172, 57, 174, 175, 176, 177, + /* 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, 234, 279, 234, 12, 13, 14, 15, 16, - /* 630 */ 279, 72, 234, 12, 13, 14, 15, 16, 0, 244, - /* 640 */ 245, 4, 171, 172, 279, 174, 175, 176, 177, 178, + /* 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, 234, 50, 296, 234, 296, 279, 20, 279, - /* 670 */ 22, 12, 13, 14, 15, 16, 240, 279, 12, 13, - /* 680 */ 14, 15, 16, 12, 13, 259, 38, 49, 320, 258, - /* 690 */ 320, 0, 75, 22, 240, 143, 265, 84, 246, 240, - /* 700 */ 248, 265, 240, 249, 87, 57, 275, 279, 249, 38, - /* 710 */ 279, 249, 244, 245, 274, 275, 240, 259, 234, 265, - /* 720 */ 234, 285, 259, 75, 265, 249, 234, 265, 57, 298, - /* 730 */ 299, 300, 301, 302, 303, 76, 305, 259, 302, 308, - /* 740 */ 49, 265, 258, 312, 313, 314, 98, 134, 234, 265, - /* 750 */ 234, 161, 162, 317, 318, 319, 234, 321, 110, 275, - /* 760 */ 324, 140, 72, 279, 333, 279, 76, 154, 234, 98, - /* 770 */ 234, 279, 14, 337, 222, 199, 200, 341, 20, 258, - /* 780 */ 221, 110, 298, 299, 300, 301, 302, 303, 14, 305, - /* 790 */ 269, 72, 308, 279, 20, 279, 312, 313, 150, 1, - /* 800 */ 2, 279, 189, 190, 191, 192, 193, 194, 195, 196, - /* 810 */ 197, 198, 259, 279, 0, 279, 234, 140, 141, 171, - /* 820 */ 172, 150, 174, 175, 176, 177, 178, 179, 180, 181, - /* 830 */ 182, 183, 184, 185, 186, 187, 188, 0, 18, 202, - /* 840 */ 258, 79, 171, 23, 82, 0, 79, 265, 234, 82, - /* 850 */ 36, 79, 0, 22, 82, 35, 79, 275, 72, 82, - /* 860 */ 72, 279, 76, 259, 76, 186, 187, 22, 48, 38, - /* 870 */ 0, 72, 258, 72, 22, 76, 50, 76, 235, 265, - /* 880 */ 298, 299, 300, 301, 302, 303, 288, 305, 57, 275, - /* 890 */ 308, 247, 22, 279, 312, 313, 314, 72, 61, 72, - /* 900 */ 72, 76, 65, 76, 76, 323, 72, 72, 344, 335, - /* 910 */ 76, 76, 298, 299, 300, 301, 302, 303, 268, 305, - /* 920 */ 72, 38, 308, 38, 76, 88, 312, 313, 314, 98, - /* 930 */ 329, 72, 112, 292, 237, 76, 38, 323, 219, 72, - /* 940 */ 322, 110, 297, 76, 107, 108, 109, 72, 111, 72, - /* 950 */ 240, 76, 72, 76, 72, 57, 76, 258, 76, 325, - /* 960 */ 338, 20, 240, 143, 144, 145, 36, 147, 234, 293, - /* 970 */ 38, 244, 152, 286, 121, 265, 240, 234, 148, 240, - /* 980 */ 273, 150, 271, 134, 164, 271, 166, 240, 168, 169, - /* 990 */ 170, 20, 258, 110, 290, 110, 242, 171, 275, 265, - /* 1000 */ 20, 258, 171, 172, 283, 242, 265, 20, 265, 275, - /* 1010 */ 242, 276, 302, 279, 20, 242, 240, 242, 275, 285, - /* 1020 */ 236, 201, 279, 258, 258, 240, 236, 317, 318, 319, - /* 1030 */ 57, 321, 298, 299, 300, 301, 302, 303, 234, 305, - /* 1040 */ 258, 298, 299, 300, 301, 302, 303, 258, 305, 258, - /* 1050 */ 258, 308, 258, 258, 258, 312, 313, 279, 324, 19, - /* 1060 */ 258, 258, 258, 276, 240, 157, 20, 297, 239, 265, - /* 1070 */ 290, 337, 289, 33, 265, 341, 36, 239, 239, 275, - /* 1080 */ 275, 239, 42, 279, 44, 45, 46, 47, 209, 265, - /* 1090 */ 283, 334, 234, 280, 208, 279, 215, 280, 334, 330, - /* 1100 */ 279, 279, 298, 299, 300, 301, 302, 303, 304, 305, - /* 1110 */ 306, 307, 216, 204, 74, 203, 258, 77, 200, 265, - /* 1120 */ 20, 328, 121, 265, 234, 315, 302, 327, 331, 296, - /* 1130 */ 223, 220, 218, 275, 75, 280, 279, 279, 277, 279, - /* 1140 */ 234, 317, 318, 319, 280, 321, 137, 107, 258, 265, - /* 1150 */ 339, 345, 340, 279, 311, 265, 298, 299, 300, 301, - /* 1160 */ 302, 303, 239, 305, 258, 275, 239, 276, 265, 279, - /* 1170 */ 254, 265, 75, 248, 261, 240, 136, 239, 236, 139, - /* 1180 */ 287, 275, 232, 291, 284, 279, 252, 241, 298, 299, - /* 1190 */ 300, 301, 302, 303, 0, 305, 156, 252, 158, 234, - /* 1200 */ 342, 343, 0, 64, 298, 299, 300, 301, 302, 303, - /* 1210 */ 38, 305, 234, 0, 308, 167, 38, 38, 38, 313, - /* 1220 */ 167, 0, 38, 258, 38, 167, 336, 0, 38, 0, - /* 1230 */ 265, 38, 0, 75, 154, 153, 258, 110, 150, 0, - /* 1240 */ 275, 0, 53, 265, 279, 146, 0, 0, 87, 0, - /* 1250 */ 0, 0, 0, 275, 0, 0, 0, 279, 121, 0, - /* 1260 */ 282, 0, 0, 298, 299, 300, 301, 302, 303, 234, - /* 1270 */ 305, 43, 0, 51, 0, 22, 298, 299, 300, 301, - /* 1280 */ 302, 303, 0, 305, 0, 0, 0, 0, 0, 0, - /* 1290 */ 0, 0, 0, 258, 0, 0, 0, 0, 0, 0, - /* 1300 */ 265, 0, 0, 0, 0, 0, 0, 0, 343, 43, - /* 1310 */ 275, 38, 36, 0, 279, 38, 36, 234, 43, 0, - /* 1320 */ 0, 38, 43, 0, 43, 0, 0, 0, 84, 36, - /* 1330 */ 82, 0, 72, 298, 299, 300, 301, 302, 303, 72, - /* 1340 */ 305, 258, 307, 22, 36, 0, 234, 38, 265, 38, - /* 1350 */ 38, 22, 38, 38, 38, 38, 38, 0, 275, 22, - /* 1360 */ 38, 0, 279, 39, 22, 282, 38, 0, 22, 0, - /* 1370 */ 258, 22, 20, 0, 140, 0, 38, 265, 155, 137, - /* 1380 */ 22, 298, 299, 300, 301, 302, 303, 275, 305, 0, - /* 1390 */ 0, 279, 33, 43, 282, 36, 234, 140, 0, 135, - /* 1400 */ 205, 42, 72, 44, 45, 46, 47, 75, 72, 76, - /* 1410 */ 298, 299, 300, 301, 302, 303, 72, 305, 199, 205, - /* 1420 */ 258, 205, 87, 76, 76, 38, 75, 265, 75, 75, - /* 1430 */ 75, 2, 72, 74, 72, 234, 77, 275, 72, 76, - /* 1440 */ 76, 279, 38, 87, 234, 38, 76, 38, 72, 38, - /* 1450 */ 38, 72, 87, 76, 76, 75, 75, 22, 87, 258, - /* 1460 */ 298, 299, 300, 301, 302, 303, 265, 305, 258, 0, - /* 1470 */ 76, 171, 75, 87, 75, 265, 275, 75, 138, 76, - /* 1480 */ 279, 76, 43, 173, 22, 275, 85, 87, 75, 279, - /* 1490 */ 75, 75, 234, 75, 135, 87, 137, 75, 139, 298, - /* 1500 */ 299, 300, 301, 302, 303, 234, 305, 135, 298, 299, - /* 1510 */ 300, 301, 302, 303, 86, 305, 258, 158, 38, 76, - /* 1520 */ 38, 75, 38, 265, 76, 75, 38, 76, 75, 258, - /* 1530 */ 76, 38, 75, 275, 76, 38, 265, 279, 75, 22, - /* 1540 */ 100, 100, 75, 88, 100, 100, 275, 38, 110, 75, - /* 1550 */ 279, 75, 38, 22, 51, 50, 298, 299, 300, 301, - /* 1560 */ 302, 303, 38, 305, 57, 73, 72, 38, 234, 298, - /* 1570 */ 299, 300, 301, 302, 303, 38, 305, 234, 38, 38, - /* 1580 */ 38, 38, 38, 22, 57, 38, 38, 38, 38, 0, - /* 1590 */ 38, 38, 258, 38, 38, 38, 36, 43, 0, 265, - /* 1600 */ 38, 258, 36, 0, 36, 38, 43, 43, 265, 275, - /* 1610 */ 0, 38, 36, 279, 43, 0, 234, 38, 275, 37, - /* 1620 */ 0, 0, 279, 22, 22, 21, 21, 234, 22, 20, - /* 1630 */ 346, 346, 298, 299, 300, 301, 302, 303, 346, 305, - /* 1640 */ 258, 298, 299, 300, 301, 302, 303, 265, 305, 346, - /* 1650 */ 346, 258, 346, 346, 346, 346, 346, 275, 265, 346, - /* 1660 */ 346, 279, 346, 346, 346, 346, 346, 346, 275, 346, - /* 1670 */ 346, 346, 279, 346, 346, 346, 234, 346, 346, 346, - /* 1680 */ 298, 299, 300, 301, 302, 303, 346, 305, 346, 346, - /* 1690 */ 346, 298, 299, 300, 301, 302, 303, 346, 305, 346, - /* 1700 */ 258, 346, 346, 346, 346, 346, 346, 265, 346, 346, - /* 1710 */ 346, 346, 346, 346, 346, 234, 346, 275, 346, 346, - /* 1720 */ 346, 279, 346, 346, 234, 346, 346, 346, 346, 346, - /* 1730 */ 346, 346, 346, 234, 346, 346, 346, 346, 346, 258, - /* 1740 */ 298, 299, 300, 301, 302, 303, 265, 305, 258, 346, - /* 1750 */ 346, 346, 346, 346, 346, 265, 275, 258, 346, 346, - /* 1760 */ 279, 346, 346, 346, 265, 275, 346, 346, 346, 279, - /* 1770 */ 346, 346, 234, 346, 275, 346, 346, 346, 279, 298, - /* 1780 */ 299, 300, 301, 302, 303, 234, 305, 346, 298, 299, - /* 1790 */ 300, 301, 302, 303, 346, 305, 258, 298, 299, 300, - /* 1800 */ 301, 302, 303, 265, 305, 346, 346, 346, 346, 258, - /* 1810 */ 346, 346, 346, 275, 346, 346, 265, 279, 346, 346, - /* 1820 */ 346, 346, 346, 346, 346, 346, 275, 346, 346, 346, - /* 1830 */ 279, 346, 346, 346, 234, 346, 298, 299, 300, 301, - /* 1840 */ 302, 303, 346, 305, 346, 346, 346, 346, 346, 298, - /* 1850 */ 299, 300, 301, 302, 303, 346, 305, 346, 258, 346, - /* 1860 */ 346, 346, 346, 346, 346, 265, 346, 346, 346, 346, - /* 1870 */ 346, 346, 346, 346, 346, 275, 346, 346, 346, 279, - /* 1880 */ 346, 346, 346, 346, 346, 346, 346, 346, 346, 346, - /* 1890 */ 346, 346, 346, 346, 346, 346, 346, 346, 298, 299, - /* 1900 */ 300, 301, 302, 303, 346, 305, + /* 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, + /* 2060 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, + /* 2070 */ 347, 347, 347, 347, 347, 347, 347, 347, 347, 347, }; -#define YY_SHIFT_COUNT (573) +#define YY_SHIFT_COUNT (574) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1621) +#define YY_SHIFT_MAX (1836) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 820, 0, 39, 216, 216, 216, 216, 255, 216, 216, + /* 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, 52, 73, 73, 73, - /* 40 */ 118, 671, 671, 112, 36, 36, 78, 671, 70, 36, - /* 50 */ 36, 36, 36, 36, 36, 107, 36, 272, 341, 78, - /* 60 */ 472, 272, 36, 36, 272, 36, 272, 472, 272, 272, - /* 70 */ 36, 366, 219, 397, 613, 613, 343, 831, 298, 141, - /* 80 */ 831, 831, 831, 831, 831, 831, 831, 831, 831, 831, - /* 90 */ 831, 831, 831, 831, 831, 831, 831, 831, 831, 340, - /* 100 */ 638, 419, 419, 183, 183, 183, 691, 419, 419, 490, - /* 110 */ 472, 272, 472, 272, 475, 548, 27, 27, 27, 27, - /* 120 */ 27, 27, 27, 1040, 115, 414, 552, 144, 169, 165, - /* 130 */ 244, 168, 403, 576, 297, 576, 758, 381, 637, 774, - /* 140 */ 941, 930, 932, 830, 941, 941, 853, 849, 849, 941, - /* 150 */ 971, 107, 472, 980, 107, 490, 987, 107, 107, 941, - /* 160 */ 107, 994, 272, 272, 272, 272, 272, 272, 272, 272, - /* 170 */ 272, 272, 272, 941, 994, 973, 971, 366, 908, 472, - /* 180 */ 366, 980, 366, 490, 987, 366, 1046, 879, 886, 973, - /* 190 */ 879, 886, 973, 973, 896, 881, 909, 912, 918, 490, - /* 200 */ 1100, 1001, 907, 911, 914, 1059, 272, 886, 973, 973, - /* 210 */ 886, 973, 1009, 490, 987, 366, 475, 366, 490, 1097, - /* 220 */ 548, 941, 366, 994, 1906, 1906, 1906, 1906, 1906, 1906, - /* 230 */ 1906, 99, 1359, 256, 13, 406, 837, 228, 405, 446, - /* 240 */ 621, 659, 666, 666, 666, 666, 666, 666, 666, 666, - /* 250 */ 523, 469, 247, 133, 315, 69, 69, 69, 69, 814, - /* 260 */ 336, 690, 762, 767, 772, 777, 845, 852, 870, 211, - /* 270 */ 590, 677, 786, 788, 799, 798, 679, 719, 559, 801, - /* 280 */ 826, 825, 617, 827, 828, 834, 835, 848, 883, 885, - /* 290 */ 859, 867, 875, 877, 880, 882, 233, 898, 1194, 1202, - /* 300 */ 1139, 1213, 1172, 1048, 1178, 1179, 1180, 1053, 1221, 1184, - /* 310 */ 1186, 1058, 1227, 1190, 1229, 1193, 1232, 1158, 1080, 1082, - /* 320 */ 1127, 1088, 1239, 1241, 1189, 1099, 1246, 1247, 1161, 1249, - /* 330 */ 1250, 1251, 1252, 1254, 1255, 1256, 1261, 1262, 1282, 1284, - /* 340 */ 1285, 1286, 1287, 1288, 1289, 1290, 1137, 1259, 1291, 1292, - /* 350 */ 1294, 1295, 1296, 1253, 1297, 1298, 1299, 1301, 1302, 1303, - /* 360 */ 1304, 1305, 1306, 1228, 1272, 1222, 1274, 1307, 1273, 1276, - /* 370 */ 1266, 1313, 1277, 1280, 1275, 1319, 1283, 1293, 1279, 1320, - /* 380 */ 1309, 1308, 1281, 1323, 1325, 1326, 1327, 1244, 1248, 1311, - /* 390 */ 1260, 1267, 1321, 1331, 1312, 1314, 1315, 1316, 1317, 1260, - /* 400 */ 1267, 1318, 1322, 1345, 1329, 1357, 1337, 1324, 1361, 1342, - /* 410 */ 1328, 1367, 1346, 1369, 1349, 1352, 1373, 1234, 1338, 1375, - /* 420 */ 1223, 1358, 1257, 1242, 1389, 1390, 1398, 1332, 1350, 1264, - /* 430 */ 1330, 1336, 1195, 1333, 1344, 1347, 1351, 1353, 1354, 1348, - /* 440 */ 1360, 1335, 1355, 1362, 1214, 1363, 1364, 1356, 1219, 1366, - /* 450 */ 1365, 1370, 1376, 1216, 1387, 1404, 1407, 1409, 1411, 1412, - /* 460 */ 1429, 1300, 1379, 1377, 1380, 1378, 1381, 1394, 1371, 1397, - /* 470 */ 1399, 1386, 1435, 1310, 1402, 1403, 1405, 1413, 1415, 1340, - /* 480 */ 1416, 1469, 1439, 1372, 1418, 1401, 1400, 1408, 1462, 1422, - /* 490 */ 1428, 1443, 1480, 1482, 1446, 1448, 1484, 1450, 1451, 1488, - /* 500 */ 1453, 1454, 1493, 1457, 1458, 1497, 1463, 1440, 1441, 1444, - /* 510 */ 1445, 1517, 1455, 1467, 1509, 1438, 1474, 1476, 1514, 1260, - /* 520 */ 1267, 1531, 1503, 1505, 1524, 1507, 1492, 1494, 1529, 1537, - /* 530 */ 1540, 1541, 1542, 1543, 1544, 1561, 1527, 1260, 1547, 1267, - /* 540 */ 1548, 1549, 1550, 1552, 1553, 1555, 1556, 1589, 1557, 1560, - /* 550 */ 1554, 1598, 1562, 1566, 1563, 1603, 1567, 1568, 1564, 1610, - /* 560 */ 1573, 1576, 1571, 1615, 1579, 1582, 1620, 1621, 1601, 1604, - /* 570 */ 1602, 1606, 1605, 1609, + /* 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, }; #define YY_REDUCE_COUNT (230) -#define YY_REDUCE_MIN (-323) -#define YY_REDUCE_MAX (1600) +#define YY_REDUCE_MIN (-278) +#define YY_REDUCE_MAX (1612) static const short yy_reduce_ofst[] = { - /* 0 */ -34, 221, -232, 431, -3, 582, 614, 734, 484, 743, - /* 10 */ 804, 858, 906, 274, 890, 965, 978, 1035, 1083, 1112, - /* 20 */ 1162, 1201, 1210, 1258, 1271, 1334, 1343, 1382, 1393, 1442, - /* 30 */ 1481, 1490, 1499, 1538, 1551, 1600, 436, -210, 710, 824, - /* 40 */ 213, -258, -255, -279, -240, -221, -89, -231, -323, -161, - /* 50 */ 29, 225, 262, 276, 295, -177, 331, -235, -67, -77, - /* 60 */ -270, -153, 454, 459, 1, 462, -58, -172, 58, 158, - /* 70 */ 476, 299, 61, -268, -268, -268, 150, 55, 49, -216, - /* 80 */ 143, 261, 269, 278, 284, 344, 351, 365, 388, 390, - /* 90 */ 398, 428, 486, 492, 514, 516, 522, 534, 536, 226, - /* 100 */ -151, 243, 357, -46, 368, 370, -66, 395, 468, -262, - /* 110 */ 224, 289, 440, 521, 174, 452, -244, 426, 458, 463, - /* 120 */ 478, 553, 604, 598, 643, 644, 564, 574, 650, 641, - /* 130 */ 601, 697, 645, 618, 618, 618, 699, 622, 634, 699, - /* 140 */ 722, 676, 727, 687, 736, 739, 707, 711, 714, 747, - /* 150 */ 704, 754, 723, 721, 763, 741, 735, 768, 773, 776, - /* 160 */ 775, 784, 765, 766, 782, 789, 791, 792, 794, 795, - /* 170 */ 796, 802, 803, 785, 790, 778, 780, 829, 783, 805, - /* 180 */ 838, 807, 839, 809, 787, 842, 770, 757, 813, 816, - /* 190 */ 764, 817, 821, 822, 797, 769, 793, 800, 618, 854, - /* 200 */ 833, 810, 806, 812, 811, 843, 699, 855, 857, 860, - /* 210 */ 864, 874, 861, 884, 891, 923, 916, 927, 903, 913, - /* 220 */ 925, 935, 938, 942, 893, 892, 900, 934, 945, 946, - /* 230 */ 950, + /* 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, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 10 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 20 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 30 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 40 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 50 */ 1296, 1296, 1296, 1296, 1296, 1355, 1296, 1296, 1296, 1296, - /* 60 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 70 */ 1296, 1353, 1498, 1296, 1658, 1296, 1296, 1296, 1296, 1296, - /* 80 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 90 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 100 */ 1355, 1296, 1296, 1669, 1669, 1669, 1353, 1296, 1296, 1296, - /* 110 */ 1296, 1296, 1296, 1296, 1450, 1296, 1296, 1296, 1296, 1296, - /* 120 */ 1296, 1296, 1296, 1536, 1296, 1296, 1734, 1296, 1403, 1542, - /* 130 */ 1693, 1296, 1685, 1661, 1675, 1662, 1296, 1719, 1678, 1296, - /* 140 */ 1296, 1296, 1296, 1528, 1296, 1296, 1503, 1500, 1500, 1296, - /* 150 */ 1296, 1355, 1296, 1296, 1355, 1296, 1296, 1355, 1355, 1296, - /* 160 */ 1355, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 170 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1353, 1538, 1296, - /* 180 */ 1353, 1296, 1353, 1296, 1296, 1353, 1296, 1700, 1698, 1296, - /* 190 */ 1700, 1698, 1296, 1296, 1712, 1708, 1691, 1689, 1675, 1296, - /* 200 */ 1296, 1296, 1737, 1725, 1721, 1296, 1296, 1698, 1296, 1296, - /* 210 */ 1698, 1296, 1511, 1296, 1296, 1353, 1296, 1353, 1296, 1419, - /* 220 */ 1296, 1296, 1353, 1296, 1530, 1544, 1520, 1453, 1453, 1356, - /* 230 */ 1301, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 240 */ 1296, 1296, 1605, 1711, 1710, 1634, 1633, 1632, 1630, 1604, - /* 250 */ 1296, 1296, 1296, 1296, 1296, 1598, 1599, 1597, 1596, 1296, - /* 260 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 270 */ 1296, 1296, 1296, 1296, 1296, 1659, 1296, 1722, 1726, 1296, - /* 280 */ 1296, 1296, 1582, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 290 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 300 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 310 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 320 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 330 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 340 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 350 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 360 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 370 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 380 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 390 */ 1466, 1465, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1383, - /* 400 */ 1382, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 410 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 420 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 430 */ 1682, 1692, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 440 */ 1296, 1582, 1296, 1709, 1296, 1668, 1664, 1296, 1296, 1660, - /* 450 */ 1296, 1296, 1720, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 460 */ 1654, 1296, 1627, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 470 */ 1296, 1296, 1296, 1592, 1296, 1296, 1296, 1296, 1296, 1296, - /* 480 */ 1296, 1296, 1296, 1296, 1296, 1296, 1581, 1296, 1296, 1296, - /* 490 */ 1296, 1296, 1296, 1296, 1447, 1296, 1296, 1296, 1296, 1296, - /* 500 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1432, 1430, 1429, - /* 510 */ 1428, 1296, 1425, 1296, 1296, 1296, 1296, 1296, 1296, 1456, - /* 520 */ 1455, 1296, 1296, 1296, 1296, 1296, 1296, 1376, 1296, 1296, - /* 530 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1367, 1296, 1366, - /* 540 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 550 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 560 */ 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, 1296, - /* 570 */ 1296, 1296, 1296, 1296, + /* 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, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1382,56 +1410,57 @@ static const char *const yyTokenName[] = { /* 293 */ "dnode_list", /* 294 */ "signed", /* 295 */ "signed_literal", - /* 296 */ "table_alias", - /* 297 */ "column_alias", - /* 298 */ "expression", - /* 299 */ "pseudo_column", - /* 300 */ "column_reference", - /* 301 */ "function_expression", - /* 302 */ "subquery", - /* 303 */ "star_func", - /* 304 */ "star_func_para_list", - /* 305 */ "noarg_func", - /* 306 */ "other_para_list", - /* 307 */ "star_func_para", - /* 308 */ "predicate", - /* 309 */ "compare_op", - /* 310 */ "in_op", - /* 311 */ "in_predicate_value", - /* 312 */ "boolean_value_expression", - /* 313 */ "boolean_primary", - /* 314 */ "common_expression", - /* 315 */ "from_clause", - /* 316 */ "table_reference_list", - /* 317 */ "table_reference", - /* 318 */ "table_primary", - /* 319 */ "joined_table", - /* 320 */ "alias_opt", - /* 321 */ "parenthesized_joined_table", - /* 322 */ "join_type", - /* 323 */ "search_condition", - /* 324 */ "query_specification", - /* 325 */ "set_quantifier_opt", - /* 326 */ "select_list", - /* 327 */ "where_clause_opt", - /* 328 */ "partition_by_clause_opt", - /* 329 */ "twindow_clause_opt", - /* 330 */ "group_by_clause_opt", - /* 331 */ "having_clause_opt", - /* 332 */ "select_sublist", - /* 333 */ "select_item", - /* 334 */ "fill_opt", - /* 335 */ "fill_mode", - /* 336 */ "group_by_list", - /* 337 */ "query_expression_body", - /* 338 */ "order_by_clause_opt", - /* 339 */ "slimit_clause_opt", - /* 340 */ "limit_clause_opt", - /* 341 */ "query_primary", - /* 342 */ "sort_specification_list", - /* 343 */ "sort_specification", - /* 344 */ "ordering_specification_opt", - /* 345 */ "null_ordering_opt", + /* 296 */ "literal_func", + /* 297 */ "table_alias", + /* 298 */ "column_alias", + /* 299 */ "expression", + /* 300 */ "pseudo_column", + /* 301 */ "column_reference", + /* 302 */ "function_expression", + /* 303 */ "subquery", + /* 304 */ "star_func", + /* 305 */ "star_func_para_list", + /* 306 */ "noarg_func", + /* 307 */ "other_para_list", + /* 308 */ "star_func_para", + /* 309 */ "predicate", + /* 310 */ "compare_op", + /* 311 */ "in_op", + /* 312 */ "in_predicate_value", + /* 313 */ "boolean_value_expression", + /* 314 */ "boolean_primary", + /* 315 */ "common_expression", + /* 316 */ "from_clause", + /* 317 */ "table_reference_list", + /* 318 */ "table_reference", + /* 319 */ "table_primary", + /* 320 */ "joined_table", + /* 321 */ "alias_opt", + /* 322 */ "parenthesized_joined_table", + /* 323 */ "join_type", + /* 324 */ "search_condition", + /* 325 */ "query_specification", + /* 326 */ "set_quantifier_opt", + /* 327 */ "select_list", + /* 328 */ "where_clause_opt", + /* 329 */ "partition_by_clause_opt", + /* 330 */ "twindow_clause_opt", + /* 331 */ "group_by_clause_opt", + /* 332 */ "having_clause_opt", + /* 333 */ "select_sublist", + /* 334 */ "select_item", + /* 335 */ "fill_opt", + /* 336 */ "fill_mode", + /* 337 */ "group_by_list", + /* 338 */ "query_expression_body", + /* 339 */ "order_by_clause_opt", + /* 340 */ "slimit_clause_opt", + /* 341 */ "limit_clause_opt", + /* 342 */ "query_primary", + /* 343 */ "sort_specification_list", + /* 344 */ "sort_specification", + /* 345 */ "ordering_specification_opt", + /* 346 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1718,168 +1747,171 @@ static const char *const yyRuleName[] = { /* 276 */ "signed_literal ::= TIMESTAMP NK_STRING", /* 277 */ "signed_literal ::= duration_literal", /* 278 */ "signed_literal ::= NULL", - /* 279 */ "literal_list ::= signed_literal", - /* 280 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 281 */ "db_name ::= NK_ID", - /* 282 */ "table_name ::= NK_ID", - /* 283 */ "column_name ::= NK_ID", - /* 284 */ "function_name ::= NK_ID", - /* 285 */ "table_alias ::= NK_ID", - /* 286 */ "column_alias ::= NK_ID", - /* 287 */ "user_name ::= NK_ID", - /* 288 */ "index_name ::= NK_ID", - /* 289 */ "topic_name ::= NK_ID", - /* 290 */ "stream_name ::= NK_ID", - /* 291 */ "expression ::= literal", - /* 292 */ "expression ::= pseudo_column", - /* 293 */ "expression ::= column_reference", - /* 294 */ "expression ::= function_expression", - /* 295 */ "expression ::= subquery", - /* 296 */ "expression ::= NK_LP expression NK_RP", - /* 297 */ "expression ::= NK_PLUS expression", - /* 298 */ "expression ::= NK_MINUS expression", - /* 299 */ "expression ::= expression NK_PLUS expression", - /* 300 */ "expression ::= expression NK_MINUS expression", - /* 301 */ "expression ::= expression NK_STAR expression", - /* 302 */ "expression ::= expression NK_SLASH expression", - /* 303 */ "expression ::= expression NK_REM expression", - /* 304 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 305 */ "expression_list ::= expression", - /* 306 */ "expression_list ::= expression_list NK_COMMA expression", - /* 307 */ "column_reference ::= column_name", - /* 308 */ "column_reference ::= table_name NK_DOT column_name", - /* 309 */ "pseudo_column ::= ROWTS", - /* 310 */ "pseudo_column ::= TBNAME", - /* 311 */ "pseudo_column ::= QSTARTTS", - /* 312 */ "pseudo_column ::= QENDTS", - /* 313 */ "pseudo_column ::= WSTARTTS", - /* 314 */ "pseudo_column ::= WENDTS", - /* 315 */ "pseudo_column ::= WDURATION", - /* 316 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 317 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 318 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 319 */ "function_expression ::= noarg_func NK_LP NK_RP", - /* 320 */ "noarg_func ::= NOW", - /* 321 */ "noarg_func ::= TODAY", - /* 322 */ "noarg_func ::= TIMEZONE", - /* 323 */ "star_func ::= COUNT", - /* 324 */ "star_func ::= FIRST", - /* 325 */ "star_func ::= LAST", - /* 326 */ "star_func ::= LAST_ROW", - /* 327 */ "star_func_para_list ::= NK_STAR", - /* 328 */ "star_func_para_list ::= other_para_list", - /* 329 */ "other_para_list ::= star_func_para", - /* 330 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 331 */ "star_func_para ::= expression", - /* 332 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 333 */ "predicate ::= expression compare_op expression", - /* 334 */ "predicate ::= expression BETWEEN expression AND expression", - /* 335 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 336 */ "predicate ::= expression IS NULL", - /* 337 */ "predicate ::= expression IS NOT NULL", - /* 338 */ "predicate ::= expression in_op in_predicate_value", - /* 339 */ "compare_op ::= NK_LT", - /* 340 */ "compare_op ::= NK_GT", - /* 341 */ "compare_op ::= NK_LE", - /* 342 */ "compare_op ::= NK_GE", - /* 343 */ "compare_op ::= NK_NE", - /* 344 */ "compare_op ::= NK_EQ", - /* 345 */ "compare_op ::= LIKE", - /* 346 */ "compare_op ::= NOT LIKE", - /* 347 */ "compare_op ::= MATCH", - /* 348 */ "compare_op ::= NMATCH", - /* 349 */ "compare_op ::= CONTAINS", - /* 350 */ "in_op ::= IN", - /* 351 */ "in_op ::= NOT IN", - /* 352 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 353 */ "boolean_value_expression ::= boolean_primary", - /* 354 */ "boolean_value_expression ::= NOT boolean_primary", - /* 355 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 356 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 357 */ "boolean_primary ::= predicate", - /* 358 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 359 */ "common_expression ::= expression", - /* 360 */ "common_expression ::= boolean_value_expression", - /* 361 */ "from_clause ::= FROM table_reference_list", - /* 362 */ "table_reference_list ::= table_reference", - /* 363 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 364 */ "table_reference ::= table_primary", - /* 365 */ "table_reference ::= joined_table", - /* 366 */ "table_primary ::= table_name alias_opt", - /* 367 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 368 */ "table_primary ::= subquery alias_opt", - /* 369 */ "table_primary ::= parenthesized_joined_table", - /* 370 */ "alias_opt ::=", - /* 371 */ "alias_opt ::= table_alias", - /* 372 */ "alias_opt ::= AS table_alias", - /* 373 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 374 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 375 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 376 */ "join_type ::=", - /* 377 */ "join_type ::= INNER", - /* 378 */ "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", - /* 379 */ "set_quantifier_opt ::=", - /* 380 */ "set_quantifier_opt ::= DISTINCT", - /* 381 */ "set_quantifier_opt ::= ALL", - /* 382 */ "select_list ::= NK_STAR", - /* 383 */ "select_list ::= select_sublist", - /* 384 */ "select_sublist ::= select_item", - /* 385 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 386 */ "select_item ::= common_expression", - /* 387 */ "select_item ::= common_expression column_alias", - /* 388 */ "select_item ::= common_expression AS column_alias", - /* 389 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 390 */ "where_clause_opt ::=", - /* 391 */ "where_clause_opt ::= WHERE search_condition", - /* 392 */ "partition_by_clause_opt ::=", - /* 393 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 394 */ "twindow_clause_opt ::=", - /* 395 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 396 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 397 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 398 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 399 */ "sliding_opt ::=", - /* 400 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 401 */ "fill_opt ::=", - /* 402 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 403 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 404 */ "fill_mode ::= NONE", - /* 405 */ "fill_mode ::= PREV", - /* 406 */ "fill_mode ::= NULL", - /* 407 */ "fill_mode ::= LINEAR", - /* 408 */ "fill_mode ::= NEXT", - /* 409 */ "group_by_clause_opt ::=", - /* 410 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 411 */ "group_by_list ::= expression", - /* 412 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 413 */ "having_clause_opt ::=", - /* 414 */ "having_clause_opt ::= HAVING search_condition", - /* 415 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 416 */ "query_expression_body ::= query_primary", - /* 417 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 418 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 419 */ "query_primary ::= query_specification", - /* 420 */ "order_by_clause_opt ::=", - /* 421 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 422 */ "slimit_clause_opt ::=", - /* 423 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 424 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 425 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 426 */ "limit_clause_opt ::=", - /* 427 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 428 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 429 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 430 */ "subquery ::= NK_LP query_expression NK_RP", - /* 431 */ "search_condition ::= common_expression", - /* 432 */ "sort_specification_list ::= sort_specification", - /* 433 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 434 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 435 */ "ordering_specification_opt ::=", - /* 436 */ "ordering_specification_opt ::= ASC", - /* 437 */ "ordering_specification_opt ::= DESC", - /* 438 */ "null_ordering_opt ::=", - /* 439 */ "null_ordering_opt ::= NULLS FIRST", - /* 440 */ "null_ordering_opt ::= NULLS LAST", + /* 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", }; #endif /* NDEBUG */ @@ -2035,37 +2067,38 @@ static void yy_destructor( case 292: /* into_opt */ case 294: /* signed */ case 295: /* signed_literal */ - case 298: /* expression */ - case 299: /* pseudo_column */ - case 300: /* column_reference */ - case 301: /* function_expression */ - case 302: /* subquery */ - case 307: /* star_func_para */ - case 308: /* predicate */ - case 311: /* in_predicate_value */ - case 312: /* boolean_value_expression */ - case 313: /* boolean_primary */ - case 314: /* common_expression */ - case 315: /* from_clause */ - case 316: /* table_reference_list */ - case 317: /* table_reference */ - case 318: /* table_primary */ - case 319: /* joined_table */ - case 321: /* parenthesized_joined_table */ - case 323: /* search_condition */ - case 324: /* query_specification */ - case 327: /* where_clause_opt */ - case 329: /* twindow_clause_opt */ - case 331: /* having_clause_opt */ - case 333: /* select_item */ - case 334: /* fill_opt */ - case 337: /* query_expression_body */ - case 339: /* slimit_clause_opt */ - case 340: /* limit_clause_opt */ - case 341: /* query_primary */ - case 343: /* sort_specification */ + case 296: /* literal_func */ + case 299: /* expression */ + case 300: /* pseudo_column */ + case 301: /* column_reference */ + case 302: /* function_expression */ + case 303: /* subquery */ + case 308: /* star_func_para */ + case 309: /* predicate */ + case 312: /* in_predicate_value */ + case 313: /* boolean_value_expression */ + case 314: /* boolean_primary */ + case 315: /* common_expression */ + case 316: /* from_clause */ + case 317: /* table_reference_list */ + case 318: /* table_reference */ + case 319: /* table_primary */ + case 320: /* joined_table */ + case 322: /* parenthesized_joined_table */ + case 324: /* search_condition */ + case 325: /* query_specification */ + case 328: /* where_clause_opt */ + case 330: /* twindow_clause_opt */ + case 332: /* having_clause_opt */ + case 334: /* select_item */ + case 335: /* fill_opt */ + case 338: /* query_expression_body */ + case 340: /* slimit_clause_opt */ + case 341: /* limit_clause_opt */ + case 342: /* query_primary */ + case 344: /* sort_specification */ { - nodesDestroyNode((yypminor->yy456)); + nodesDestroyNode((yypminor->yy662)); } break; case 232: /* account_options */ @@ -2086,11 +2119,11 @@ static void yy_destructor( case 276: /* index_name */ case 283: /* topic_name */ case 290: /* stream_name */ - case 296: /* table_alias */ - case 297: /* column_alias */ - case 303: /* star_func */ - case 305: /* noarg_func */ - case 320: /* alias_opt */ + case 297: /* table_alias */ + case 298: /* column_alias */ + case 304: /* star_func */ + case 306: /* noarg_func */ + case 321: /* alias_opt */ { } @@ -2099,7 +2132,7 @@ static void yy_destructor( case 242: /* exists_opt */ case 286: /* analyze_opt */ case 288: /* agg_func_opt */ - case 325: /* set_quantifier_opt */ + case 326: /* set_quantifier_opt */ { } @@ -2119,17 +2152,17 @@ static void yy_destructor( case 278: /* func_list */ case 282: /* expression_list */ case 293: /* dnode_list */ - case 304: /* star_func_para_list */ - case 306: /* other_para_list */ - case 326: /* select_list */ - case 328: /* partition_by_clause_opt */ - case 330: /* group_by_clause_opt */ - case 332: /* select_sublist */ - case 336: /* group_by_list */ - case 338: /* order_by_clause_opt */ - case 342: /* sort_specification_list */ + case 305: /* star_func_para_list */ + case 307: /* other_para_list */ + case 327: /* select_list */ + case 329: /* partition_by_clause_opt */ + case 331: /* group_by_clause_opt */ + case 333: /* select_sublist */ + case 337: /* group_by_list */ + case 339: /* order_by_clause_opt */ + case 343: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy652)); + nodesDestroyList((yypminor->yy568)); } break; case 247: /* alter_db_option */ @@ -2143,28 +2176,28 @@ static void yy_destructor( } break; - case 309: /* compare_op */ - case 310: /* in_op */ + case 310: /* compare_op */ + case 311: /* in_op */ { } break; - case 322: /* join_type */ + case 323: /* join_type */ { } break; - case 335: /* fill_mode */ + case 336: /* fill_mode */ { } break; - case 344: /* ordering_specification_opt */ + case 345: /* ordering_specification_opt */ { } break; - case 345: /* null_ordering_opt */ + case 346: /* null_ordering_opt */ { } @@ -2742,168 +2775,171 @@ static const struct { { 295, -2 }, /* (276) signed_literal ::= TIMESTAMP NK_STRING */ { 295, -1 }, /* (277) signed_literal ::= duration_literal */ { 295, -1 }, /* (278) signed_literal ::= NULL */ - { 262, -1 }, /* (279) literal_list ::= signed_literal */ - { 262, -3 }, /* (280) literal_list ::= literal_list NK_COMMA signed_literal */ - { 240, -1 }, /* (281) db_name ::= NK_ID */ - { 265, -1 }, /* (282) table_name ::= NK_ID */ - { 258, -1 }, /* (283) column_name ::= NK_ID */ - { 275, -1 }, /* (284) function_name ::= NK_ID */ - { 296, -1 }, /* (285) table_alias ::= NK_ID */ - { 297, -1 }, /* (286) column_alias ::= NK_ID */ - { 236, -1 }, /* (287) user_name ::= NK_ID */ - { 276, -1 }, /* (288) index_name ::= NK_ID */ - { 283, -1 }, /* (289) topic_name ::= NK_ID */ - { 290, -1 }, /* (290) stream_name ::= NK_ID */ - { 298, -1 }, /* (291) expression ::= literal */ - { 298, -1 }, /* (292) expression ::= pseudo_column */ - { 298, -1 }, /* (293) expression ::= column_reference */ - { 298, -1 }, /* (294) expression ::= function_expression */ - { 298, -1 }, /* (295) expression ::= subquery */ - { 298, -3 }, /* (296) expression ::= NK_LP expression NK_RP */ - { 298, -2 }, /* (297) expression ::= NK_PLUS expression */ - { 298, -2 }, /* (298) expression ::= NK_MINUS expression */ - { 298, -3 }, /* (299) expression ::= expression NK_PLUS expression */ - { 298, -3 }, /* (300) expression ::= expression NK_MINUS expression */ - { 298, -3 }, /* (301) expression ::= expression NK_STAR expression */ - { 298, -3 }, /* (302) expression ::= expression NK_SLASH expression */ - { 298, -3 }, /* (303) expression ::= expression NK_REM expression */ - { 298, -3 }, /* (304) expression ::= column_reference NK_ARROW NK_STRING */ - { 282, -1 }, /* (305) expression_list ::= expression */ - { 282, -3 }, /* (306) expression_list ::= expression_list NK_COMMA expression */ - { 300, -1 }, /* (307) column_reference ::= column_name */ - { 300, -3 }, /* (308) column_reference ::= table_name NK_DOT column_name */ - { 299, -1 }, /* (309) pseudo_column ::= ROWTS */ - { 299, -1 }, /* (310) pseudo_column ::= TBNAME */ - { 299, -1 }, /* (311) pseudo_column ::= QSTARTTS */ - { 299, -1 }, /* (312) pseudo_column ::= QENDTS */ - { 299, -1 }, /* (313) pseudo_column ::= WSTARTTS */ - { 299, -1 }, /* (314) pseudo_column ::= WENDTS */ - { 299, -1 }, /* (315) pseudo_column ::= WDURATION */ - { 301, -4 }, /* (316) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 301, -4 }, /* (317) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 301, -6 }, /* (318) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 301, -3 }, /* (319) function_expression ::= noarg_func NK_LP NK_RP */ - { 305, -1 }, /* (320) noarg_func ::= NOW */ - { 305, -1 }, /* (321) noarg_func ::= TODAY */ - { 305, -1 }, /* (322) noarg_func ::= TIMEZONE */ - { 303, -1 }, /* (323) star_func ::= COUNT */ - { 303, -1 }, /* (324) star_func ::= FIRST */ - { 303, -1 }, /* (325) star_func ::= LAST */ - { 303, -1 }, /* (326) star_func ::= LAST_ROW */ - { 304, -1 }, /* (327) star_func_para_list ::= NK_STAR */ - { 304, -1 }, /* (328) star_func_para_list ::= other_para_list */ - { 306, -1 }, /* (329) other_para_list ::= star_func_para */ - { 306, -3 }, /* (330) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 307, -1 }, /* (331) star_func_para ::= expression */ - { 307, -3 }, /* (332) star_func_para ::= table_name NK_DOT NK_STAR */ - { 308, -3 }, /* (333) predicate ::= expression compare_op expression */ - { 308, -5 }, /* (334) predicate ::= expression BETWEEN expression AND expression */ - { 308, -6 }, /* (335) predicate ::= expression NOT BETWEEN expression AND expression */ - { 308, -3 }, /* (336) predicate ::= expression IS NULL */ - { 308, -4 }, /* (337) predicate ::= expression IS NOT NULL */ - { 308, -3 }, /* (338) predicate ::= expression in_op in_predicate_value */ - { 309, -1 }, /* (339) compare_op ::= NK_LT */ - { 309, -1 }, /* (340) compare_op ::= NK_GT */ - { 309, -1 }, /* (341) compare_op ::= NK_LE */ - { 309, -1 }, /* (342) compare_op ::= NK_GE */ - { 309, -1 }, /* (343) compare_op ::= NK_NE */ - { 309, -1 }, /* (344) compare_op ::= NK_EQ */ - { 309, -1 }, /* (345) compare_op ::= LIKE */ - { 309, -2 }, /* (346) compare_op ::= NOT LIKE */ - { 309, -1 }, /* (347) compare_op ::= MATCH */ - { 309, -1 }, /* (348) compare_op ::= NMATCH */ - { 309, -1 }, /* (349) compare_op ::= CONTAINS */ - { 310, -1 }, /* (350) in_op ::= IN */ - { 310, -2 }, /* (351) in_op ::= NOT IN */ - { 311, -3 }, /* (352) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 312, -1 }, /* (353) boolean_value_expression ::= boolean_primary */ - { 312, -2 }, /* (354) boolean_value_expression ::= NOT boolean_primary */ - { 312, -3 }, /* (355) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 312, -3 }, /* (356) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 313, -1 }, /* (357) boolean_primary ::= predicate */ - { 313, -3 }, /* (358) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 314, -1 }, /* (359) common_expression ::= expression */ - { 314, -1 }, /* (360) common_expression ::= boolean_value_expression */ - { 315, -2 }, /* (361) from_clause ::= FROM table_reference_list */ - { 316, -1 }, /* (362) table_reference_list ::= table_reference */ - { 316, -3 }, /* (363) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 317, -1 }, /* (364) table_reference ::= table_primary */ - { 317, -1 }, /* (365) table_reference ::= joined_table */ - { 318, -2 }, /* (366) table_primary ::= table_name alias_opt */ - { 318, -4 }, /* (367) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 318, -2 }, /* (368) table_primary ::= subquery alias_opt */ - { 318, -1 }, /* (369) table_primary ::= parenthesized_joined_table */ - { 320, 0 }, /* (370) alias_opt ::= */ - { 320, -1 }, /* (371) alias_opt ::= table_alias */ - { 320, -2 }, /* (372) alias_opt ::= AS table_alias */ - { 321, -3 }, /* (373) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 321, -3 }, /* (374) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 319, -6 }, /* (375) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 322, 0 }, /* (376) join_type ::= */ - { 322, -1 }, /* (377) join_type ::= INNER */ - { 324, -9 }, /* (378) 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 */ - { 325, 0 }, /* (379) set_quantifier_opt ::= */ - { 325, -1 }, /* (380) set_quantifier_opt ::= DISTINCT */ - { 325, -1 }, /* (381) set_quantifier_opt ::= ALL */ - { 326, -1 }, /* (382) select_list ::= NK_STAR */ - { 326, -1 }, /* (383) select_list ::= select_sublist */ - { 332, -1 }, /* (384) select_sublist ::= select_item */ - { 332, -3 }, /* (385) select_sublist ::= select_sublist NK_COMMA select_item */ - { 333, -1 }, /* (386) select_item ::= common_expression */ - { 333, -2 }, /* (387) select_item ::= common_expression column_alias */ - { 333, -3 }, /* (388) select_item ::= common_expression AS column_alias */ - { 333, -3 }, /* (389) select_item ::= table_name NK_DOT NK_STAR */ - { 327, 0 }, /* (390) where_clause_opt ::= */ - { 327, -2 }, /* (391) where_clause_opt ::= WHERE search_condition */ - { 328, 0 }, /* (392) partition_by_clause_opt ::= */ - { 328, -3 }, /* (393) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 329, 0 }, /* (394) twindow_clause_opt ::= */ - { 329, -6 }, /* (395) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 329, -4 }, /* (396) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 329, -6 }, /* (397) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 329, -8 }, /* (398) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 280, 0 }, /* (399) sliding_opt ::= */ - { 280, -4 }, /* (400) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 334, 0 }, /* (401) fill_opt ::= */ - { 334, -4 }, /* (402) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 334, -6 }, /* (403) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 335, -1 }, /* (404) fill_mode ::= NONE */ - { 335, -1 }, /* (405) fill_mode ::= PREV */ - { 335, -1 }, /* (406) fill_mode ::= NULL */ - { 335, -1 }, /* (407) fill_mode ::= LINEAR */ - { 335, -1 }, /* (408) fill_mode ::= NEXT */ - { 330, 0 }, /* (409) group_by_clause_opt ::= */ - { 330, -3 }, /* (410) group_by_clause_opt ::= GROUP BY group_by_list */ - { 336, -1 }, /* (411) group_by_list ::= expression */ - { 336, -3 }, /* (412) group_by_list ::= group_by_list NK_COMMA expression */ - { 331, 0 }, /* (413) having_clause_opt ::= */ - { 331, -2 }, /* (414) having_clause_opt ::= HAVING search_condition */ - { 285, -4 }, /* (415) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 337, -1 }, /* (416) query_expression_body ::= query_primary */ - { 337, -4 }, /* (417) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 337, -3 }, /* (418) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 341, -1 }, /* (419) query_primary ::= query_specification */ - { 338, 0 }, /* (420) order_by_clause_opt ::= */ - { 338, -3 }, /* (421) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 339, 0 }, /* (422) slimit_clause_opt ::= */ - { 339, -2 }, /* (423) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 339, -4 }, /* (424) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 339, -4 }, /* (425) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 340, 0 }, /* (426) limit_clause_opt ::= */ - { 340, -2 }, /* (427) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 340, -4 }, /* (428) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 340, -4 }, /* (429) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 302, -3 }, /* (430) subquery ::= NK_LP query_expression NK_RP */ - { 323, -1 }, /* (431) search_condition ::= common_expression */ - { 342, -1 }, /* (432) sort_specification_list ::= sort_specification */ - { 342, -3 }, /* (433) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 343, -3 }, /* (434) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 344, 0 }, /* (435) ordering_specification_opt ::= */ - { 344, -1 }, /* (436) ordering_specification_opt ::= ASC */ - { 344, -1 }, /* (437) ordering_specification_opt ::= DESC */ - { 345, 0 }, /* (438) null_ordering_opt ::= */ - { 345, -2 }, /* (439) null_ordering_opt ::= NULLS FIRST */ - { 345, -2 }, /* (440) null_ordering_opt ::= NULLS LAST */ + { 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 */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3040,28 +3076,28 @@ static YYACTIONTYPE yy_reduce( yy_destructor(yypParser,234,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy517, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy555, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy517, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy555, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy555); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy517, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy555, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy555, &yymsp[0].minor.yy0); } break; case 30: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy555); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3078,25 +3114,25 @@ 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 281: /* db_name ::= NK_ID */ yytestcase(yyruleno==281); - case 282: /* table_name ::= NK_ID */ yytestcase(yyruleno==282); - case 283: /* column_name ::= NK_ID */ yytestcase(yyruleno==283); - case 284: /* function_name ::= NK_ID */ yytestcase(yyruleno==284); - case 285: /* table_alias ::= NK_ID */ yytestcase(yyruleno==285); - case 286: /* column_alias ::= NK_ID */ yytestcase(yyruleno==286); - case 287: /* user_name ::= NK_ID */ yytestcase(yyruleno==287); - case 288: /* index_name ::= NK_ID */ yytestcase(yyruleno==288); - case 289: /* topic_name ::= NK_ID */ yytestcase(yyruleno==289); - case 290: /* stream_name ::= NK_ID */ yytestcase(yyruleno==290); - case 320: /* noarg_func ::= NOW */ yytestcase(yyruleno==320); - case 321: /* noarg_func ::= TODAY */ yytestcase(yyruleno==321); - case 322: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==322); - case 323: /* star_func ::= COUNT */ yytestcase(yyruleno==323); - case 324: /* star_func ::= FIRST */ yytestcase(yyruleno==324); - case 325: /* star_func ::= LAST */ yytestcase(yyruleno==325); - case 326: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==326); -{ yylhsminor.yy517 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy517 = yylhsminor.yy517; + 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); +{ yylhsminor.yy555 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy555 = yylhsminor.yy555; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -3129,163 +3165,163 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; case 49: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy673, &yymsp[-1].minor.yy517, yymsp[0].minor.yy456); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy617, &yymsp[-1].minor.yy555, yymsp[0].minor.yy662); } break; case 50: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy673, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy617, &yymsp[0].minor.yy555); } break; case 51: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy555); } break; case 52: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy517, yymsp[0].minor.yy456); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy555, yymsp[0].minor.yy662); } break; case 53: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy673 = true; } +{ yymsp[-2].minor.yy617 = true; } 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 379: /* set_quantifier_opt ::= */ yytestcase(yyruleno==379); -{ yymsp[1].minor.yy673 = false; } + case 382: /* set_quantifier_opt ::= */ yytestcase(yyruleno==382); +{ yymsp[1].minor.yy617 = false; } break; case 55: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy673 = true; } +{ yymsp[-1].minor.yy617 = true; } break; case 57: /* db_options ::= */ -{ yymsp[1].minor.yy456 = createDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy662 = createDatabaseOptions(pCxt); } break; case 58: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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; break; case 59: /* db_options ::= db_options CACHE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pCacheBlockSize = (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 60: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pCachelast = (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 61: /* db_options ::= db_options COMP NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pCompressionLevel = (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 62: /* db_options ::= db_options DAYS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pDaysPerFile = (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 63: /* db_options ::= db_options DAYS NK_VARIABLE */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 64: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pFsyncPeriod = (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 65: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pMaxRowsPerBlock = (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 66: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pMinRowsPerBlock = (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 67: /* db_options ::= db_options KEEP integer_list */ case 68: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==68); -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pKeep = yymsp[0].minor.yy652; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pKeep = yymsp[0].minor.yy568; yylhsminor.yy662 = yymsp[-2].minor.yy662; } + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 69: /* db_options ::= db_options PRECISION NK_STRING */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 70: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pQuorum = (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 71: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pReplica = (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 72: /* db_options ::= db_options TTL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pTtl = (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 73: /* db_options ::= db_options WAL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pWalLevel = (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 74: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pNumOfVgroups = (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 75: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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.yy456)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pStreamMode = (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 77: /* db_options ::= db_options RETENTIONS retention_list */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pRetentions = yymsp[0].minor.yy652; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy662)->pRetentions = yymsp[0].minor.yy568; yylhsminor.yy662 = yymsp[-2].minor.yy662; } + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 78: /* db_options ::= db_options STRICT NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy456)->pStrict = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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.yy456 = createDatabaseOptions(pCxt); yylhsminor.yy456 = setDatabaseAlterOption(pCxt, yylhsminor.yy456, &yymsp[0].minor.yy145); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ yylhsminor.yy662 = createDatabaseOptions(pCxt); yylhsminor.yy662 = setDatabaseAlterOption(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.yy456 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy456, &yymsp[0].minor.yy145); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; +{ yylhsminor.yy662 = setDatabaseAlterOption(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.yy145.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 82: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy145.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &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.yy145.type = DB_OPTION_KEEP; yymsp[-1].minor.yy145.pList = yymsp[0].minor.yy652; } +{ yymsp[-1].minor.yy475.type = DB_OPTION_KEEP; yymsp[-1].minor.yy475.pList = yymsp[0].minor.yy568; } break; case 85: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy145.type = DB_OPTION_WAL; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = DB_OPTION_WAL; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 86: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy145.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 87: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy145.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 88: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy145.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 89: /* alter_db_option ::= STRICT NK_INTEGER */ -{ yymsp[-1].minor.yy145.type = DB_OPTION_STRICT; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = DB_OPTION_STRICT; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 90: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy652 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; +{ 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); -{ yylhsminor.yy652 = addNodeToList(pCxt, yymsp[-2].minor.yy652, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; +{ 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 */ -{ yylhsminor.yy652 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; +{ 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 */ -{ yylhsminor.yy652 = addNodeToList(pCxt, yymsp[-2].minor.yy652, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; +{ 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); @@ -3294,255 +3330,255 @@ static YYACTIONTYPE yy_reduce( 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 279: /* literal_list ::= signed_literal */ yytestcase(yyruleno==279); - case 329: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==329); - case 384: /* select_sublist ::= select_item */ yytestcase(yyruleno==384); - case 432: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==432); -{ yylhsminor.yy652 = createNodeList(pCxt, yymsp[0].minor.yy456); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + 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); +{ 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 280: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==280); - case 330: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==330); - case 385: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==385); - case 433: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==433); -{ yylhsminor.yy652 = addNodeToList(pCxt, yymsp[-2].minor.yy652, yymsp[0].minor.yy456); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + 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); +{ 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 */ -{ yylhsminor.yy456 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ 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); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy673, yymsp[-5].minor.yy456, yymsp[-3].minor.yy652, yymsp[-1].minor.yy652, yymsp[0].minor.yy456); } +{ 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 */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy652); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy568); } break; case 100: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy652); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy568); } break; case 101: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy673, yymsp[0].minor.yy456); } +{ 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); -{ pCxt->pRootNode = yymsp[0].minor.yy456; } +{ pCxt->pRootNode = yymsp[0].minor.yy662; } break; case 104: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy456 = createAlterTableOption(pCxt, yymsp[-1].minor.yy456, yymsp[0].minor.yy456); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; +{ yylhsminor.yy662 = createAlterTableOption(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 */ -{ yylhsminor.yy456 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy456, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy517, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy456, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy517); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy456, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy517, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy456, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy517, &yymsp[0].minor.yy517); } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy456, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy517, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy456, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy517); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy456, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy517, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy456, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy517, &yymsp[0].minor.yy517); } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy456, &yymsp[-2].minor.yy517, yymsp[0].minor.yy456); } - yymsp[-5].minor.yy456 = yylhsminor.yy456; +{ 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); -{ yylhsminor.yy652 = addNodeToList(pCxt, yymsp[-1].minor.yy652, yymsp[0].minor.yy456); } - yymsp[-1].minor.yy652 = yylhsminor.yy652; +{ 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.yy456 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy673, yymsp[-7].minor.yy456, yymsp[-5].minor.yy456, yymsp[-4].minor.yy652, yymsp[-1].minor.yy652); } - yymsp[-8].minor.yy456 = yylhsminor.yy456; +{ 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; break; case 119: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy456 = createDropTableClause(pCxt, yymsp[-1].minor.yy673, yymsp[0].minor.yy456); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; +{ 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 392: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==392); - case 409: /* group_by_clause_opt ::= */ yytestcase(yyruleno==409); - case 420: /* order_by_clause_opt ::= */ yytestcase(yyruleno==420); -{ yymsp[1].minor.yy652 = NULL; } + 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); +{ yymsp[1].minor.yy568 = NULL; } break; case 121: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy652 = yymsp[-1].minor.yy652; } +{ yymsp[-2].minor.yy568 = yymsp[-1].minor.yy568; } break; case 122: /* full_table_name ::= table_name */ -{ yylhsminor.yy456 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy517, NULL); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createRealTableNode(pCxt, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy517, NULL); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy517, yymsp[0].minor.yy380, NULL); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy517, yymsp[-2].minor.yy380, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 129: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 130: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 131: /* type_name ::= INT */ case 132: /* type_name ::= INTEGER */ yytestcase(yyruleno==132); -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_INT); } break; case 133: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 134: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 135: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 136: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 137: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 138: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 139: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 140: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 141: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 142: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy156 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 143: /* type_name ::= JSON */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 144: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 145: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 146: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 147: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy156 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 148: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy156 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 149: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ 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 */ -{ yymsp[-5].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy156 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 152: /* tags_def_opt ::= tags_def */ - case 328: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==328); - case 383: /* select_list ::= select_sublist */ yytestcase(yyruleno==383); -{ yylhsminor.yy652 = yymsp[0].minor.yy652; } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 331: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==331); + case 386: /* select_list ::= select_sublist */ yytestcase(yyruleno==386); +{ 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 */ -{ yymsp[-3].minor.yy652 = yymsp[-1].minor.yy652; } +{ yymsp[-3].minor.yy568 = yymsp[-1].minor.yy568; } break; case 154: /* table_options ::= */ -{ yymsp[1].minor.yy456 = createTableOptions(pCxt); } +{ yymsp[1].minor.yy662 = createTableOptions(pCxt); } break; case 155: /* table_options ::= table_options COMMENT NK_STRING */ -{ ((STableOptions*)yymsp[-2].minor.yy456)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((STableOptions*)yymsp[-2].minor.yy662)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + 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.yy456)->pKeep = yymsp[0].minor.yy652; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((STableOptions*)yymsp[-2].minor.yy662)->pKeep = yymsp[0].minor.yy568; yylhsminor.yy662 = yymsp[-2].minor.yy662; } + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 158: /* table_options ::= table_options TTL NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy456)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((STableOptions*)yymsp[-2].minor.yy662)->pTtl = (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 159: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy456)->pSma = yymsp[-1].minor.yy652; yylhsminor.yy456 = yymsp[-4].minor.yy456; } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ ((STableOptions*)yymsp[-4].minor.yy662)->pSma = yymsp[-1].minor.yy568; yylhsminor.yy662 = yymsp[-4].minor.yy662; } + 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.yy456)->pFuncs = yymsp[-1].minor.yy652; yylhsminor.yy456 = yymsp[-4].minor.yy456; } - yymsp[-4].minor.yy456 = yylhsminor.yy456; +{ ((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.yy456)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((STableOptions*)yymsp[-2].minor.yy662)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy662 = yymsp[-2].minor.yy662; } + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; case 162: /* table_options ::= table_options DELAY NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy456)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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; break; case 163: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy456 = createTableOptions(pCxt); yylhsminor.yy456 = setTableAlterOption(pCxt, yylhsminor.yy456, &yymsp[0].minor.yy145); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ yylhsminor.yy662 = createTableOptions(pCxt); yylhsminor.yy662 = setTableAlterOption(pCxt, yylhsminor.yy662, &yymsp[0].minor.yy475); } + yymsp[0].minor.yy662 = yylhsminor.yy662; break; case 164: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy456 = setTableAlterOption(pCxt, yymsp[-1].minor.yy456, &yymsp[0].minor.yy145); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; +{ yylhsminor.yy662 = setTableAlterOption(pCxt, yymsp[-1].minor.yy662, &yymsp[0].minor.yy475); } + yymsp[-1].minor.yy662 = yylhsminor.yy662; break; case 165: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy145.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ 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.yy145.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy145.pList = yymsp[0].minor.yy652; } +{ yymsp[-1].minor.yy475.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy475.pList = yymsp[0].minor.yy568; } break; case 168: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy145.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy145.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy475.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy475.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 171: /* col_name ::= column_name */ -{ yylhsminor.yy456 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy517); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ yylhsminor.yy662 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy555); } + yymsp[0].minor.yy662 = yylhsminor.yy662; break; case 172: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -3554,13 +3590,13 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; case 175: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy456, yymsp[0].minor.yy456); } +{ 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 */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy456, yymsp[0].minor.yy456); } +{ 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 */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy456, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy662, NULL); } break; case 178: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -3575,7 +3611,7 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; case 182: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy456, yymsp[0].minor.yy456); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy662, yymsp[0].minor.yy662); } break; case 183: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } @@ -3594,13 +3630,13 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } break; case 189: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy555); } break; case 190: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy456); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy662); } break; case 191: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy456); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy662); } break; case 192: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } @@ -3625,148 +3661,148 @@ static YYACTIONTYPE yy_reduce( break; case 199: /* db_name_cond_opt ::= */ case 204: /* from_db_opt ::= */ yytestcase(yyruleno==204); -{ yymsp[1].minor.yy456 = createDefaultDatabaseCondValue(pCxt); } +{ yymsp[1].minor.yy662 = createDefaultDatabaseCondValue(pCxt); } break; case 200: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy517); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; +{ 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 390: /* where_clause_opt ::= */ yytestcase(yyruleno==390); - case 394: /* twindow_clause_opt ::= */ yytestcase(yyruleno==394); - case 399: /* sliding_opt ::= */ yytestcase(yyruleno==399); - case 401: /* fill_opt ::= */ yytestcase(yyruleno==401); - case 413: /* having_clause_opt ::= */ yytestcase(yyruleno==413); - case 422: /* slimit_clause_opt ::= */ yytestcase(yyruleno==422); - case 426: /* limit_clause_opt ::= */ yytestcase(yyruleno==426); -{ yymsp[1].minor.yy456 = NULL; } + 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); +{ yymsp[1].minor.yy662 = NULL; } break; case 202: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 203: /* table_name_cond ::= table_name */ -{ yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy517); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yymsp[-1].minor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy517); } +{ yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy555); } break; case 208: /* func_name ::= function_name */ -{ yylhsminor.yy456 = createFunctionNode(pCxt, &yymsp[0].minor.yy517, NULL); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy673, &yymsp[-3].minor.yy517, &yymsp[-1].minor.yy517, NULL, yymsp[0].minor.yy456); } +{ 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 */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy673, &yymsp[-5].minor.yy517, &yymsp[-3].minor.yy517, yymsp[-1].minor.yy652, NULL); } +{ 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 */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy673, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy517); } +{ 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 */ -{ yymsp[-8].minor.yy456 = createIndexOption(pCxt, yymsp[-6].minor.yy652, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), NULL, yymsp[0].minor.yy456); } +{ 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 */ -{ yymsp[-10].minor.yy456 = createIndexOption(pCxt, yymsp[-8].minor.yy652, releaseRawExprNode(pCxt, yymsp[-4].minor.yy456), releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), yymsp[0].minor.yy456); } +{ 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 */ -{ yylhsminor.yy456 = createFunctionNode(pCxt, &yymsp[-3].minor.yy517, yymsp[-1].minor.yy652); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy673, &yymsp[-3].minor.yy517, yymsp[0].minor.yy456, NULL, yymsp[-2].minor.yy456); } +{ 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 */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy673, &yymsp[-3].minor.yy517, NULL, &yymsp[0].minor.yy517, yymsp[-2].minor.yy456); } +{ 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 */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy673, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy617, &yymsp[0].minor.yy555); } break; case 221: /* topic_options ::= */ -{ yymsp[1].minor.yy456 = createTopicOptions(pCxt); } +{ yymsp[1].minor.yy662 = createTopicOptions(pCxt); } break; case 222: /* topic_options ::= topic_options WITH TABLE */ -{ ((STopicOptions*)yymsp[-2].minor.yy456)->withTable = true; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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 */ -{ ((STopicOptions*)yymsp[-2].minor.yy456)->withSchema = true; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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 */ -{ ((STopicOptions*)yymsp[-2].minor.yy456)->withTag = true; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy456); } +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy662); } break; case 227: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; case 228: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy673, yymsp[-1].minor.yy456, yymsp[0].minor.yy456); } +{ 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 380: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==380); -{ yymsp[0].minor.yy673 = true; } + case 383: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==383); +{ yymsp[0].minor.yy617 = true; } break; case 231: /* explain_options ::= */ -{ yymsp[1].minor.yy456 = createDefaultExplainOptions(pCxt); } +{ yymsp[1].minor.yy662 = createDefaultExplainOptions(pCxt); } break; case 232: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy456 = setExplainVerbose(pCxt, yymsp[-2].minor.yy456, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = setExplainRatio(pCxt, yymsp[-2].minor.yy456, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy652); } +{ 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 */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy673, yymsp[-8].minor.yy673, &yymsp[-5].minor.yy517, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy380, yymsp[0].minor.yy376); } +{ 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 */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy555); } break; case 239: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy376 = 0; } +{ yymsp[1].minor.yy610 = 0; } break; case 240: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy376 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ 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 */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy673, &yymsp[-4].minor.yy517, yymsp[-2].minor.yy456, yymsp[-3].minor.yy456, yymsp[0].minor.yy456); } +{ 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 */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy673, &yymsp[0].minor.yy517); } +{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy617, &yymsp[0].minor.yy555); } break; case 244: /* into_opt ::= INTO full_table_name */ - case 361: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==361); - case 391: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==391); - case 414: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==414); -{ yymsp[-1].minor.yy456 = yymsp[0].minor.yy456; } + 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); +{ yymsp[-1].minor.yy662 = yymsp[0].minor.yy662; } break; case 245: /* stream_options ::= */ -{ yymsp[1].minor.yy456 = createStreamOptions(pCxt); } +{ yymsp[1].minor.yy662 = createStreamOptions(pCxt); } break; case 246: /* stream_options ::= stream_options TRIGGER AT_ONCE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy456)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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 */ -{ ((SStreamOptions*)yymsp[-2].minor.yy456)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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 */ -{ ((SStreamOptions*)yymsp[-2].minor.yy456)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy456); yylhsminor.yy456 = yymsp[-2].minor.yy456; } - yymsp[-2].minor.yy456 = yylhsminor.yy456; +{ ((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 */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } @@ -3778,505 +3814,508 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 252: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy652); } +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy568); } break; case 253: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; case 254: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy652 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } +{ yymsp[-1].minor.yy568 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; case 256: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy517); } +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy555); } break; case 258: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; +{ 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 291: /* expression ::= literal */ yytestcase(yyruleno==291); - case 292: /* expression ::= pseudo_column */ yytestcase(yyruleno==292); - case 293: /* expression ::= column_reference */ yytestcase(yyruleno==293); - case 294: /* expression ::= function_expression */ yytestcase(yyruleno==294); - case 295: /* expression ::= subquery */ yytestcase(yyruleno==295); - case 353: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==353); - case 357: /* boolean_primary ::= predicate */ yytestcase(yyruleno==357); - case 359: /* common_expression ::= expression */ yytestcase(yyruleno==359); - case 360: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==360); - case 362: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==362); - case 364: /* table_reference ::= table_primary */ yytestcase(yyruleno==364); - case 365: /* table_reference ::= joined_table */ yytestcase(yyruleno==365); - case 369: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==369); - case 416: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==416); - case 419: /* query_primary ::= query_specification */ yytestcase(yyruleno==419); -{ yylhsminor.yy456 = yymsp[0].minor.yy456; } - yymsp[0].minor.yy456 = yylhsminor.yy456; + 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); +{ yylhsminor.yy662 = yymsp[0].minor.yy662; } + yymsp[0].minor.yy662 = yylhsminor.yy662; break; case 264: /* literal ::= NULL */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yymsp[-1].minor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 269: /* 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; - yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; + yymsp[-1].minor.yy662 = yylhsminor.yy662; break; case 270: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yymsp[-1].minor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; case 272: /* 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; - yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; + yymsp[-1].minor.yy662 = yylhsminor.yy662; break; case 274: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yylhsminor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy456 = yylhsminor.yy456; +{ 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 */ -{ yymsp[-1].minor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; case 277: /* signed_literal ::= duration_literal */ - case 331: /* star_func_para ::= expression */ yytestcase(yyruleno==331); - case 386: /* select_item ::= common_expression */ yytestcase(yyruleno==386); - case 431: /* search_condition ::= common_expression */ yytestcase(yyruleno==431); -{ yylhsminor.yy456 = releaseRawExprNode(pCxt, yymsp[0].minor.yy456); } - yymsp[0].minor.yy456 = yylhsminor.yy456; + 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); +{ yylhsminor.yy662 = releaseRawExprNode(pCxt, yymsp[0].minor.yy662); } + yymsp[0].minor.yy662 = yylhsminor.yy662; break; case 278: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy456 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } +{ yymsp[0].minor.yy662 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; - case 296: /* expression ::= NK_LP expression NK_RP */ - case 358: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==358); -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy456)); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + case 297: /* expression ::= NK_LP expression NK_RP */ + case 361: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==361); +{ 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 297: /* expression ::= NK_PLUS expression */ + case 298: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy456)); + 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.yy456 = yylhsminor.yy456; + yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 298: /* expression ::= NK_MINUS expression */ + case 299: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy456), NULL)); + 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.yy456 = yylhsminor.yy456; + yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 299: /* expression ::= expression NK_PLUS expression */ + case 300: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 300: /* expression ::= expression NK_MINUS expression */ + case 301: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 301: /* expression ::= expression NK_STAR expression */ + case 302: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 302: /* expression ::= expression NK_SLASH expression */ + case 303: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 303: /* expression ::= expression NK_REM expression */ + case 304: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 304: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 305: /* expression ::= column_reference NK_ARROW NK_STRING */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); + 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.yy456 = yylhsminor.yy456; - break; - case 305: /* expression_list ::= expression */ -{ yylhsminor.yy652 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy456)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; - break; - case 306: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy652 = addNodeToList(pCxt, yymsp[-2].minor.yy652, releaseRawExprNode(pCxt, yymsp[0].minor.yy456)); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; - break; - case 307: /* column_reference ::= column_name */ -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy517, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy517)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; - break; - case 308: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy517, createColumnNode(pCxt, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy517)); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; - break; - case 309: /* pseudo_column ::= ROWTS */ - case 310: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==310); - case 311: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==311); - case 312: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==312); - case 313: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==313); - case 314: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==314); - case 315: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==315); -{ yylhsminor.yy456 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy456 = yylhsminor.yy456; - break; - case 316: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 317: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==317); -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy517, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy517, yymsp[-1].minor.yy652)); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; - break; - case 318: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy456), yymsp[-1].minor.yy380)); } - yymsp[-5].minor.yy456 = yylhsminor.yy456; - break; - case 319: /* function_expression ::= noarg_func NK_LP NK_RP */ -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy0, createFunctionNodeNoArg(pCxt, &yymsp[-2].minor.yy517)); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; - break; - case 327: /* star_func_para_list ::= NK_STAR */ -{ yylhsminor.yy652 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy652 = yylhsminor.yy652; - break; - case 332: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 389: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==389); -{ yylhsminor.yy456 = createColumnNode(pCxt, &yymsp[-2].minor.yy517, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; - break; - case 333: /* predicate ::= expression compare_op expression */ - case 338: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==338); + yymsp[-2].minor.yy662 = yylhsminor.yy662; + break; + case 306: /* 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 */ +{ 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 */ +{ 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 */ +{ 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); +{ 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); +{ 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 */ +{ 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 */ +{ 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 */ +{ 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); +{ 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); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy348, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy304, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 334: /* predicate ::= expression BETWEEN expression AND expression */ + case 337: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy456), releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy662), releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-4].minor.yy456 = yylhsminor.yy456; + yymsp[-4].minor.yy662 = yylhsminor.yy662; break; - case 335: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 338: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy456), releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy662), releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-5].minor.yy456 = yylhsminor.yy456; + yymsp[-5].minor.yy662 = yylhsminor.yy662; break; - case 336: /* predicate ::= expression IS NULL */ + case 339: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), 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.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 337: /* predicate ::= expression IS NOT NULL */ + case 340: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy456), 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.yy456 = yylhsminor.yy456; + yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 339: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy348 = OP_TYPE_LOWER_THAN; } + case 342: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy304 = OP_TYPE_LOWER_THAN; } break; - case 340: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy348 = OP_TYPE_GREATER_THAN; } + case 343: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy304 = OP_TYPE_GREATER_THAN; } break; - case 341: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy348 = OP_TYPE_LOWER_EQUAL; } + case 344: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy304 = OP_TYPE_LOWER_EQUAL; } break; - case 342: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy348 = OP_TYPE_GREATER_EQUAL; } + case 345: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy304 = OP_TYPE_GREATER_EQUAL; } break; - case 343: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy348 = OP_TYPE_NOT_EQUAL; } + case 346: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy304 = OP_TYPE_NOT_EQUAL; } break; - case 344: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy348 = OP_TYPE_EQUAL; } + case 347: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy304 = OP_TYPE_EQUAL; } break; - case 345: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy348 = OP_TYPE_LIKE; } + case 348: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy304 = OP_TYPE_LIKE; } break; - case 346: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy348 = OP_TYPE_NOT_LIKE; } + case 349: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy304 = OP_TYPE_NOT_LIKE; } break; - case 347: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy348 = OP_TYPE_MATCH; } + case 350: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy304 = OP_TYPE_MATCH; } break; - case 348: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy348 = OP_TYPE_NMATCH; } + case 351: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy304 = OP_TYPE_NMATCH; } break; - case 349: /* compare_op ::= CONTAINS */ -{ yymsp[0].minor.yy348 = OP_TYPE_JSON_CONTAINS; } + case 352: /* compare_op ::= CONTAINS */ +{ yymsp[0].minor.yy304 = OP_TYPE_JSON_CONTAINS; } break; - case 350: /* in_op ::= IN */ -{ yymsp[0].minor.yy348 = OP_TYPE_IN; } + case 353: /* in_op ::= IN */ +{ yymsp[0].minor.yy304 = OP_TYPE_IN; } break; - case 351: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy348 = OP_TYPE_NOT_IN; } + case 354: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy304 = OP_TYPE_NOT_IN; } break; - case 352: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy652)); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + case 355: /* 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 354: /* boolean_value_expression ::= NOT boolean_primary */ + case 357: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy456), NULL)); + 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.yy456 = yylhsminor.yy456; + yymsp[-1].minor.yy662 = yylhsminor.yy662; break; - case 355: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 358: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 356: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 359: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy456); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy456); - yylhsminor.yy456 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy662); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy662); + yylhsminor.yy662 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy662), releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + yymsp[-2].minor.yy662 = yylhsminor.yy662; break; - case 363: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy456 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy456, yymsp[0].minor.yy456, NULL); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + case 366: /* 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 366: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy456 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy517, &yymsp[0].minor.yy517); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; + case 369: /* 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 367: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy456 = createRealTableNode(pCxt, &yymsp[-3].minor.yy517, &yymsp[-1].minor.yy517, &yymsp[0].minor.yy517); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; + case 370: /* 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 368: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy456 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy456), &yymsp[0].minor.yy517); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; + case 371: /* 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 370: /* alias_opt ::= */ -{ yymsp[1].minor.yy517 = nil_token; } + case 373: /* alias_opt ::= */ +{ yymsp[1].minor.yy555 = nil_token; } break; - case 371: /* alias_opt ::= table_alias */ -{ yylhsminor.yy517 = yymsp[0].minor.yy517; } - yymsp[0].minor.yy517 = yylhsminor.yy517; + case 374: /* alias_opt ::= table_alias */ +{ yylhsminor.yy555 = yymsp[0].minor.yy555; } + yymsp[0].minor.yy555 = yylhsminor.yy555; break; - case 372: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy517 = yymsp[0].minor.yy517; } + case 375: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy555 = yymsp[0].minor.yy555; } break; - case 373: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 374: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==374); -{ yymsp[-2].minor.yy456 = yymsp[-1].minor.yy456; } + 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); +{ yymsp[-2].minor.yy662 = yymsp[-1].minor.yy662; } break; - case 375: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy456 = createJoinTableNode(pCxt, yymsp[-4].minor.yy684, yymsp[-5].minor.yy456, yymsp[-2].minor.yy456, yymsp[0].minor.yy456); } - yymsp[-5].minor.yy456 = yylhsminor.yy456; + case 378: /* 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 376: /* join_type ::= */ -{ yymsp[1].minor.yy684 = JOIN_TYPE_INNER; } + case 379: /* join_type ::= */ +{ yymsp[1].minor.yy84 = JOIN_TYPE_INNER; } break; - case 377: /* join_type ::= INNER */ -{ yymsp[0].minor.yy684 = JOIN_TYPE_INNER; } + case 380: /* join_type ::= INNER */ +{ yymsp[0].minor.yy84 = JOIN_TYPE_INNER; } break; - case 378: /* 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 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 */ { - yymsp[-8].minor.yy456 = createSelectStmt(pCxt, yymsp[-7].minor.yy673, yymsp[-6].minor.yy652, yymsp[-5].minor.yy456); - yymsp[-8].minor.yy456 = addWhereClause(pCxt, yymsp[-8].minor.yy456, yymsp[-4].minor.yy456); - yymsp[-8].minor.yy456 = addPartitionByClause(pCxt, yymsp[-8].minor.yy456, yymsp[-3].minor.yy652); - yymsp[-8].minor.yy456 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy456, yymsp[-2].minor.yy456); - yymsp[-8].minor.yy456 = addGroupByClause(pCxt, yymsp[-8].minor.yy456, yymsp[-1].minor.yy652); - yymsp[-8].minor.yy456 = addHavingClause(pCxt, yymsp[-8].minor.yy456, yymsp[0].minor.yy456); + 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); + yymsp[-8].minor.yy662 = addPartitionByClause(pCxt, yymsp[-8].minor.yy662, yymsp[-3].minor.yy568); + yymsp[-8].minor.yy662 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy662, yymsp[-2].minor.yy662); + yymsp[-8].minor.yy662 = addGroupByClause(pCxt, yymsp[-8].minor.yy662, yymsp[-1].minor.yy568); + yymsp[-8].minor.yy662 = addHavingClause(pCxt, yymsp[-8].minor.yy662, yymsp[0].minor.yy662); } break; - case 381: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy673 = false; } + case 384: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy617 = false; } break; - case 382: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy652 = NULL; } + case 385: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy568 = NULL; } break; - case 387: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy456 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy456), &yymsp[0].minor.yy517); } - yymsp[-1].minor.yy456 = yylhsminor.yy456; + case 390: /* 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 388: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy456 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), &yymsp[0].minor.yy517); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + case 391: /* 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 393: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 410: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==410); - case 421: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==421); -{ yymsp[-2].minor.yy652 = yymsp[0].minor.yy652; } + 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); +{ yymsp[-2].minor.yy568 = yymsp[0].minor.yy568; } break; - case 395: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy456 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy456), releaseRawExprNode(pCxt, yymsp[-1].minor.yy456)); } + case 398: /* 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 396: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy456 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy456)); } + case 399: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy662 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy662)); } break; - case 397: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy456 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy456), NULL, yymsp[-1].minor.yy456, yymsp[0].minor.yy456); } + case 400: /* 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 398: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy456 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy456), releaseRawExprNode(pCxt, yymsp[-3].minor.yy456), yymsp[-1].minor.yy456, yymsp[0].minor.yy456); } + case 401: /* 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 400: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy456 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy456); } + case 403: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy662 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy662); } break; - case 402: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy456 = createFillNode(pCxt, yymsp[-1].minor.yy534, NULL); } + case 405: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy662 = createFillNode(pCxt, yymsp[-1].minor.yy284, NULL); } break; - case 403: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy456 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy652)); } + case 406: /* 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 404: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy534 = FILL_MODE_NONE; } + case 407: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy284 = FILL_MODE_NONE; } break; - case 405: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy534 = FILL_MODE_PREV; } + case 408: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy284 = FILL_MODE_PREV; } break; - case 406: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy534 = FILL_MODE_NULL; } + case 409: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy284 = FILL_MODE_NULL; } break; - case 407: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy534 = FILL_MODE_LINEAR; } + case 410: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy284 = FILL_MODE_LINEAR; } break; - case 408: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy534 = FILL_MODE_NEXT; } + case 411: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy284 = FILL_MODE_NEXT; } break; - case 411: /* group_by_list ::= expression */ -{ yylhsminor.yy652 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); } - yymsp[0].minor.yy652 = yylhsminor.yy652; + case 414: /* group_by_list ::= expression */ +{ yylhsminor.yy568 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy662))); } + yymsp[0].minor.yy568 = yylhsminor.yy568; break; - case 412: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy652 = addNodeToList(pCxt, yymsp[-2].minor.yy652, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy456))); } - yymsp[-2].minor.yy652 = yylhsminor.yy652; + case 415: /* 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 415: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 418: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy456 = addOrderByClause(pCxt, yymsp[-3].minor.yy456, yymsp[-2].minor.yy652); - yylhsminor.yy456 = addSlimitClause(pCxt, yylhsminor.yy456, yymsp[-1].minor.yy456); - yylhsminor.yy456 = addLimitClause(pCxt, yylhsminor.yy456, yymsp[0].minor.yy456); + yylhsminor.yy662 = addOrderByClause(pCxt, yymsp[-3].minor.yy662, yymsp[-2].minor.yy568); + yylhsminor.yy662 = addSlimitClause(pCxt, yylhsminor.yy662, yymsp[-1].minor.yy662); + yylhsminor.yy662 = addLimitClause(pCxt, yylhsminor.yy662, yymsp[0].minor.yy662); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; + yymsp[-3].minor.yy662 = yylhsminor.yy662; break; - case 417: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy456 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy456, yymsp[0].minor.yy456); } - yymsp[-3].minor.yy456 = yylhsminor.yy456; + case 420: /* 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 418: /* query_expression_body ::= query_expression_body UNION query_expression_body */ -{ yylhsminor.yy456 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy456, yymsp[0].minor.yy456); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + case 421: /* 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 423: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 427: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==427); -{ yymsp[-1].minor.yy456 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 426: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 430: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==430); +{ yymsp[-1].minor.yy662 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 424: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 428: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==428); -{ yymsp[-3].minor.yy456 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + 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); +{ yymsp[-3].minor.yy662 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 425: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 429: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==429); -{ yymsp[-3].minor.yy456 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + 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); +{ yymsp[-3].minor.yy662 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 430: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy456 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy456); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + case 433: /* 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 434: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy456 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy456), yymsp[-1].minor.yy250, yymsp[0].minor.yy645); } - yymsp[-2].minor.yy456 = yylhsminor.yy456; + case 437: /* 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 435: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy250 = ORDER_ASC; } + case 438: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy272 = ORDER_ASC; } break; - case 436: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy250 = ORDER_ASC; } + case 439: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy272 = ORDER_ASC; } break; - case 437: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy250 = ORDER_DESC; } + case 440: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy272 = ORDER_DESC; } break; - case 438: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy645 = NULL_ORDER_DEFAULT; } + case 441: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy181 = NULL_ORDER_DEFAULT; } break; - case 439: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy645 = NULL_ORDER_FIRST; } + case 442: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy181 = NULL_ORDER_FIRST; } break; - case 440: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy645 = NULL_ORDER_LAST; } + case 443: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy181 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 0f3e2fe414e18ef213f6b1b9257eb053a4c573a6..289888c71b3d6ff8063215e13d12e859f0d9e9fe 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -30,103 +30,128 @@ namespace { void generateInformationSchema(MockCatalogService* mcs) { { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN); builder.done(); } { ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_indexes", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_stables", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1).addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1) + .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_tables", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + ITableBuilder& builder = + mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1).addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1) + .addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } } void generateTestT1(MockCatalogService* mcs) { ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6) - .setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) - .addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20).addColumn("c3", TSDB_DATA_TYPE_BIGINT) - .addColumn("c4", TSDB_DATA_TYPE_DOUBLE).addColumn("c5", TSDB_DATA_TYPE_DOUBLE); + .setPrecision(TSDB_TIME_PRECISION_MILLI) + .setVgid(1) + .addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) + .addColumn("c1", TSDB_DATA_TYPE_INT) + .addColumn("c2", TSDB_DATA_TYPE_BINARY, 20) + .addColumn("c3", TSDB_DATA_TYPE_BIGINT) + .addColumn("c4", TSDB_DATA_TYPE_DOUBLE) + .addColumn("c5", TSDB_DATA_TYPE_DOUBLE); builder.done(); } void generateTestST1(MockCatalogService* mcs) { ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2) - .setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) - .addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20) - .addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20); + .setPrecision(TSDB_TIME_PRECISION_MILLI) + .addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP) + .addColumn("c1", TSDB_DATA_TYPE_INT) + .addColumn("c2", TSDB_DATA_TYPE_BINARY, 20) + .addTag("tag1", TSDB_DATA_TYPE_INT) + .addTag("tag2", TSDB_DATA_TYPE_BINARY, 20); builder.done(); mcs->createSubTable("test", "st1", "st1s1", 1); mcs->createSubTable("test", "st1", "st1s2", 2); } -} +} // namespace -int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) { - return 0; -} +int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; } -int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { +int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName, + STableMeta** pTableMeta) { return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta); } -int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo* vgInfo) { +int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps, + const SName* pTableName, SVgroupInfo* vgInfo) { return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo); } -int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgList) { +int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName, + SArray** pVgList) { return mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList); } -int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum) { +int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, + int32_t* tableNum) { return 0; } -int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SArray** vgroupList) { +int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* dbFName, + SArray** vgroupList) { return 0; } @@ -189,6 +214,4 @@ void generateMetaData() { mockCatalogService->showTables(); } -void destroyMetaDataEnv() { - mockCatalogService.reset(); -} +void destroyMetaDataEnv() { mockCatalogService.reset(); } diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index d36448b6869131b72f5d9c56be9bfe6e87d66532..ef989e919051c4e9f5565e7963796d8d8d46a0e5 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -13,19 +13,20 @@ * along with this program. If not, see . */ +#include "mockCatalogService.h" + #include #include #include -#include "mockCatalogService.h" -#include "tdatablock.h" +#include "tdatablock.h" #include "tname.h" #include "ttypes.h" std::unique_ptr mockCatalogService; class TableBuilder : public ITableBuilder { -public: + public: virtual TableBuilder& addColumn(const std::string& name, int8_t type, int32_t bytes) { assert(colId_ <= schema()->tableInfo.numOfTags + schema()->tableInfo.numOfColumns); SSchema* col = schema()->schema + (colId_ - 1); @@ -40,7 +41,7 @@ public: virtual TableBuilder& setVgid(int16_t vgid) { schema()->vgId = vgid; - SVgroupInfo vgroup = { vgid, 0, 0, {0}, 0}; + SVgroupInfo vgroup = {vgid, 0, 0, {0}, 0}; addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030); @@ -55,15 +56,14 @@ public: return *this; } - virtual void done() { - schema()->tableInfo.rowSize = rowsize_; - } + virtual void done() { schema()->tableInfo.rowSize = rowsize_; } -private: + private: friend class MockCatalogServiceImpl; static std::unique_ptr createTableBuilder(int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { - STableMeta* meta = (STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags)); + STableMeta* meta = + (STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags)); if (nullptr == meta) { throw std::bad_alloc(); } @@ -77,29 +77,22 @@ private: meta_->schema = schemaMeta; } - STableMeta* schema() { - return meta_->schema; - } + STableMeta* schema() { return meta_->schema; } - std::shared_ptr table() { - return meta_; - } + std::shared_ptr table() { return meta_; } col_id_t colId_; - int32_t rowsize_; + int32_t rowsize_; std::shared_ptr meta_; }; class MockCatalogServiceImpl { -public: + public: static const int32_t numOfDataTypes = sizeof(tDataTypes) / sizeof(tDataTypes[0]); - MockCatalogServiceImpl() : id_(1) { - } + MockCatalogServiceImpl() : id_(1) {} - int32_t catalogGetHandle() const { - return 0; - } + int32_t catalogGetHandle() const { return 0; } int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { std::unique_ptr table; @@ -108,7 +101,7 @@ public: tNameGetDbName(pTableName, db); const char* tname = tNameGetTableName(pTableName); - int32_t code = copyTableSchemaMeta(db, tname, &table); + int32_t code = copyTableSchemaMeta(db, tname, &table); if (TSDB_CODE_SUCCESS != code) { std::cout << "db : " << db << ", table :" << tname << std::endl; return code; @@ -129,7 +122,8 @@ public: return copyTableVgroup(db, tNameGetTableName(pTableName), vgList); } - TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { + TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, + int32_t numOfColumns, int32_t numOfTags) { builder_ = TableBuilder::createTableBuilder(tableType, numOfColumns, numOfTags); meta_[db][tbname] = builder_->table(); meta_[db][tbname]->schema->uid = id_++; @@ -146,7 +140,7 @@ public: meta_[db][tbname]->schema->uid = id_++; meta_[db][tbname]->schema->tableType = TSDB_CHILD_TABLE; - SVgroupInfo vgroup = { vgid, 0, 0, {0}, 0}; + SVgroupInfo vgroup = {vgid, 0, 0, {0}, 0}; addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030); @@ -158,26 +152,28 @@ public: } void showTables() const { - // number of forward fills - #define NOF(n) ((n) / 2) - // number of backward fills - #define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2) - // center aligned - #define CA(n, s) std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" << "|" - // string field length - #define SFL 20 - // string field header - #define SH(h) CA(SFL, std::string(h)) - // string field - #define SF(n) CA(SFL, n) - // integer field length - #define IFL 10 - // integer field header - #define IH(i) CA(IFL, std::string(i)) - // integer field - #define IF(i) CA(IFL, std::to_string(i)) - // split line - #define SL(sn, in) std::setfill('=') << std::setw((sn) * (SFL + 1) + (in) * (IFL + 1)) << "" << std::setfill(' ') +// number of forward fills +#define NOF(n) ((n) / 2) +// number of backward fills +#define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2) +// center aligned +#define CA(n, s) \ + std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" \ + << "|" +// string field length +#define SFL 20 +// string field header +#define SH(h) CA(SFL, std::string(h)) +// string field +#define SF(n) CA(SFL, n) +// integer field length +#define IFL 10 +// integer field header +#define IH(i) CA(IFL, std::string(i)) +// integer field +#define IF(i) CA(IFL, std::to_string(i)) +// split line +#define SL(sn, in) std::setfill('=') << std::setw((sn) * (SFL + 1) + (in) * (IFL + 1)) << "" << std::setfill(' ') for (const auto& db : meta_) { std::cout << "Databse:" << db.first << std::endl; @@ -185,7 +181,8 @@ public: std::cout << SL(3, 1) << std::endl; for (const auto& table : db.second) { const auto& schema = table.second->schema; - std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision)) << IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl; + std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision)) + << IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl; } std::cout << std::endl; } @@ -200,7 +197,8 @@ public: int16_t numOfFields = numOfColumns + schema->tableInfo.numOfTags; for (int16_t i = 0; i < numOfFields; ++i) { const SSchema* col = schema->schema + i; - std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type)) << IF(col->bytes) << std::endl; + std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type)) + << IF(col->bytes) << std::endl; } std::cout << std::endl; } @@ -219,9 +217,9 @@ public: return tit->second; } -private: + private: typedef std::map> TableMetaCache; - typedef std::map DbMetaCache; + typedef std::map DbMetaCache; std::string toDbname(const std::string& dbFullName) const { std::string::size_type n = dbFullName.find("."); @@ -257,9 +255,7 @@ private: } } - std::string dtToString(int8_t type) const { - return tDataTypes[type].name; - } + std::string dtToString(int8_t type) const { return tDataTypes[type].name; } std::string ftToString(int16_t colid, int16_t numOfColumns) const { return (0 == colid ? "column" : (colid < numOfColumns ? "column" : "tag")); @@ -270,7 +266,8 @@ private: return table ? table->schema : nullptr; } - int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, std::unique_ptr* dst) const { + int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, + std::unique_ptr* dst) const { STableMeta* src = getTableSchemaMeta(db, tbname); if (nullptr == src) { return TSDB_CODE_TSC_INVALID_TABLE_NAME; @@ -305,30 +302,29 @@ private: return TSDB_CODE_SUCCESS; } - uint64_t id_; + uint64_t id_; std::unique_ptr builder_; - DbMetaCache meta_; + DbMetaCache meta_; }; -MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) { -} +MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {} -MockCatalogService::~MockCatalogService() { -} +MockCatalogService::~MockCatalogService() {} -ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { +ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname, + int8_t tableType, int32_t numOfColumns, int32_t numOfTags) { return impl_->createTableBuilder(db, tbname, tableType, numOfColumns, numOfTags); } -void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid) { +void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, + int16_t vgid) { impl_->createSubTable(db, stbname, tbname, vgid); } -void MockCatalogService::showTables() const { - impl_->showTables(); -} +void MockCatalogService::showTables() const { impl_->showTables(); } -std::shared_ptr MockCatalogService::getTableMeta(const std::string& db, const std::string& tbname) const { +std::shared_ptr MockCatalogService::getTableMeta(const std::string& db, + const std::string& tbname) const { return impl_->getTableMeta(db, tbname); } diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index 887979f11e47af79a58ba7d94be4a6e46fbc17c2..edfc40dbc2114611707276d34bbc491714152b26 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -20,17 +20,15 @@ #include #include +#define ALLOW_FORBID_FUNC + #include "catalog.h" class ITableBuilder { -public: - ITableBuilder& addTag(const std::string& name, int8_t type) { - return addColumn(name, type, tDataTypes[type].bytes); - } + public: + ITableBuilder& addTag(const std::string& name, int8_t type) { return addColumn(name, type, tDataTypes[type].bytes); } - ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) { - return addColumn(name, type, bytes); - } + ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) { return addColumn(name, type, bytes); } ITableBuilder& addColumn(const std::string& name, int8_t type) { return addColumn(name, type, tDataTypes[type].bytes); @@ -39,24 +37,23 @@ public: virtual ITableBuilder& addColumn(const std::string& name, int8_t type, int32_t bytes) = 0; virtual ITableBuilder& setVgid(int16_t vgid) = 0; virtual ITableBuilder& setPrecision(uint8_t precision) = 0; - virtual void done() = 0; + virtual void done() = 0; }; struct MockTableMeta { - ~MockTableMeta() { - taosMemoryFree(schema); - } + ~MockTableMeta() { taosMemoryFree(schema); } - STableMeta* schema; + STableMeta* schema; std::vector vgs; }; class MockCatalogServiceImpl; class MockCatalogService { -public: + public: MockCatalogService(); ~MockCatalogService(); - ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags = 0); + ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, + int32_t numOfColumns, int32_t numOfTags = 0); void createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid); void showTables() const; std::shared_ptr getTableMeta(const std::string& db, const std::string& tbname) const; @@ -65,7 +62,7 @@ public: int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const; int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const; -private: + private: std::unique_ptr impl_; }; diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index 5fc4e777c18dc9194ffc1c182aacc97b10f13ec3..3cfc16600fb3b10ee5dc78460670ae079cd60759 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -18,14 +18,14 @@ #include -#include "parserTestUtil.h" #include "parInt.h" +#include "parserTestUtil.h" using namespace std; using namespace testing; class ParserTest : public Test { -protected: + protected: void setDatabase(const string& acctId, const string& db) { acctId_ = acctId; db_ = db; @@ -51,7 +51,7 @@ protected: return res; } -private: + private: static const int max_err_len = 1024; bool runImpl(int32_t parseCode, int32_t translateCode) { @@ -105,7 +105,7 @@ private: } string toString(const SNode* pRoot, bool format = false) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; int32_t code = nodesNodeToString(pRoot, format, &pStr, &len); if (code != TSDB_CODE_SUCCESS) { @@ -130,18 +130,18 @@ private: calcConstAstStr_.clear(); } - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - string sqlBuf_; + 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_; + SQuery* query_; + string parseErrStr_; + string parsedAstStr_; + string translateErrStr_; + string translatedAstStr_; + string calcConstErrStr_; + string calcConstAstStr_; }; TEST_F(ParserTest, createAccount) { @@ -207,7 +207,9 @@ TEST_F(ParserTest, selectConstant) { 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"); + 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"); @@ -353,7 +355,7 @@ TEST_F(ParserTest, selectSemanticError) { // TSDB_CODE_PAR_INVALID_FUNTION bind("SELECT cnt(*) FROM t1"); - ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_PAR_INVALID_FUNTION)); + ASSERT_TRUE(run(TSDB_CODE_SUCCESS, TSDB_CODE_FUNC_INVALID_FUNTION)); // TSDB_CODE_PAR_FUNTION_PARA_NUM // TSDB_CODE_PAR_FUNTION_PARA_TYPE @@ -449,32 +451,32 @@ TEST_F(ParserTest, createDatabase) { 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'" - ); + 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 " - ); + bind( + "create database if not exists wxy_db " + "DAYS 100m " + "KEEP 200m,300h,400d "); ASSERT_TRUE(run()); } @@ -484,14 +486,14 @@ TEST_F(ParserTest, alterDatabase) { 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 " - ); + bind( + "alter database wxy_db " + "BLOCKS 200 " + "CACHELAST 1 " + "FSYNC 200 " + "KEEP 200 " + "QUORUM 2 " + "WAL 1 "); ASSERT_TRUE(run()); } @@ -515,45 +517,55 @@ TEST_F(ParserTest, createTable) { 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)" - ); + 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" - ); + + 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)" - ); + 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" - ); + 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()); } diff --git a/source/libs/parser/test/parserInsertTest.cpp b/source/libs/parser/test/parserInsertTest.cpp index 4aec141b5537fdb9b9773fe67dbe1474d85fcabc..308152bf3ea12255ac41640b367a20c96dd50fa7 100644 --- a/source/libs/parser/test/parserInsertTest.cpp +++ b/source/libs/parser/test/parserInsertTest.cpp @@ -22,10 +22,8 @@ using namespace std; using namespace testing; namespace { - string toString(int32_t code) { - return tstrerror(code); - } -} +string toString(int32_t code) { return tstrerror(code); } +} // namespace // syntax: // INSERT INTO @@ -35,7 +33,7 @@ namespace { // VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path // [...]; class InsertTest : public Test { -protected: + protected: void setDatabase(const string& acctId, const string& db) { acctId_ = acctId; db_ = db; @@ -44,12 +42,11 @@ protected: void bind(const char* sql) { reset(); cxt_.acctId = atoi(acctId_.c_str()); - cxt_.db = (char*) db_.c_str(); + cxt_.db = (char*)db_.c_str(); strcpy(sqlBuf_, sql); cxt_.sqlLen = strlen(sql); sqlBuf_[cxt_.sqlLen] = '\0'; cxt_.pSql = sqlBuf_; - } int32_t run() { @@ -62,19 +59,21 @@ protected: void dumpReslut() { SVnodeModifOpStmt* pStmt = getVnodeModifStmt(res_); - size_t num = taosArrayGetSize(pStmt->pDataBlocks); - cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType << ", numOfVgs:" << num << endl; + size_t num = taosArrayGetSize(pStmt->pDataBlocks); + cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType + << ", numOfVgs:" << num << endl; for (size_t i = 0; i < num; ++i) { SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(pStmt->pDataBlocks, i); cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl; SSubmitReq* submit = (SSubmitReq*)vg->pData; cout << "length:" << ntohl(submit->length) << ", numOfBlocks:" << ntohl(submit->numOfBlocks) << endl; - int32_t numOfBlocks = ntohl(submit->numOfBlocks); + int32_t numOfBlocks = ntohl(submit->numOfBlocks); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); for (int32_t i = 0; i < numOfBlocks; ++i) { cout << "Block:" << i << endl; - cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding) << ", sversion:" << ntohl(blk->sversion) - << ", dataLen:" << ntohl(blk->dataLen) << ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl; + cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding) + << ", sversion:" << ntohl(blk->sversion) << ", dataLen:" << ntohl(blk->dataLen) + << ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl; blk = (SSubmitBlk*)(blk->data + ntohl(blk->dataLen)); } } @@ -93,7 +92,7 @@ protected: SSubmitReq* submit = (SSubmitReq*)vg->pData; ASSERT_GE(ntohl(submit->length), 0); ASSERT_GE(ntohl(submit->numOfBlocks), 0); - int32_t numOfBlocks = ntohl(submit->numOfBlocks); + int32_t numOfBlocks = ntohl(submit->numOfBlocks); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); for (int32_t i = 0; i < numOfBlocks; ++i) { ASSERT_EQ(ntohs(blk->numOfRows), (0 == i ? numOfRows1 : (numOfRows2 > 0 ? numOfRows2 : numOfRows1))); @@ -102,7 +101,7 @@ protected: } } -private: + private: static const int max_err_len = 1024; static const int max_sql_len = 1024 * 1024; @@ -114,17 +113,15 @@ private: code_ = TSDB_CODE_SUCCESS; } - SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) { - return (SVnodeModifOpStmt*)pQuery->pRoot; - } + SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) { return (SVnodeModifOpStmt*)pQuery->pRoot; } - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - char sqlBuf_[max_sql_len]; + string acctId_; + string db_; + char errMagBuf_[max_err_len]; + char sqlBuf_[max_sql_len]; SParseContext cxt_; - int32_t code_; - SQuery* res_; + int32_t code_; + SQuery* res_; }; // INSERT INTO tb_name VALUES (field1_value, ...) @@ -141,7 +138,9 @@ TEST_F(InsertTest, singleTableSingleRowTest) { TEST_F(InsertTest, singleTableMultiRowTest) { setDatabase("root", "test"); - bind("insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, 10, 11)"); + bind( + "insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, " + "10, 11)"); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); dumpReslut(); checkReslut(1, 3); @@ -161,20 +160,23 @@ TEST_F(InsertTest, multiTableSingleRowTest) { TEST_F(InsertTest, multiTableMultiRowTest) { setDatabase("root", "test"); - bind("insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")" - " st1s2 values (now, 10, \"131028\")(now+1s, 20, \"132028\")"); + bind( + "insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")" + " st1s2 values (now, 10, \"131028\")(now+1s, 20, \"132028\")"); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); dumpReslut(); checkReslut(2, 3, 2); } -// INSERT INTO +// INSERT INTO // tb1_name USING st1_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...) // tb2_name USING st2_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...) TEST_F(InsertTest, autoCreateTableTest) { setDatabase("root", "test"); - bind("insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")"); + bind( + "insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, " + "\"guangzhou\")"); ASSERT_EQ(run(), TSDB_CODE_SUCCESS); dumpReslut(); checkReslut(1, 3); diff --git a/source/libs/parser/test/parserTestMain.cpp b/source/libs/parser/test/parserTestMain.cpp index 95faadfc34cd9428f9ef49ae1a1addba1179aa3d..62b092251cf143f12da5a619c1b1b8fac7fee07a 100644 --- a/source/libs/parser/test/parserTestMain.cpp +++ b/source/libs/parser/test/parserTestMain.cpp @@ -13,9 +13,9 @@ * along with this program. If not, see . */ -#include #include #include +#include #include #include @@ -23,16 +23,16 @@ #ifdef WINDOWS #define TD_USE_WINSOCK #endif -#include "os.h" -#include "parserTestUtil.h" -#include "parToken.h" #include "functionMgt.h" #include "mockCatalog.h" +#include "os.h" +#include "parToken.h" +#include "parserTestUtil.h" bool g_isDump = false; class ParserEnv : public testing::Environment { -public: + public: virtual void SetUp() { initMetaDataEnv(); generateMetaData(); @@ -49,12 +49,9 @@ public: }; static void parseArg(int argc, char* argv[]) { - int opt = 0; - const char *optstring = ""; - static struct option long_options[] = { - {"dump", no_argument, NULL, 'd'}, - {0, 0, 0, 0} - }; + int opt = 0; + const char* optstring = ""; + static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}}; while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (opt) { case 'd': @@ -67,8 +64,8 @@ static void parseArg(int argc, char* argv[]) { } int main(int argc, char* argv[]) { - testing::AddGlobalTestEnvironment(new ParserEnv()); - testing::InitGoogleTest(&argc, argv); + testing::AddGlobalTestEnvironment(new ParserEnv()); + testing::InitGoogleTest(&argc, argv); parseArg(argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); } diff --git a/source/libs/planner/inc/planInt.h b/source/libs/planner/inc/planInt.h index 7f8bf144999149296519cea8713e700e42b64ecd..e6534f710db03b1f3bf36bab7ead2d281faceee8 100644 --- a/source/libs/planner/inc/planInt.h +++ b/source/libs/planner/inc/planInt.h @@ -26,12 +26,12 @@ extern "C" { #define QUERY_POLICY_HYBRID 2 #define QUERY_POLICY_QNODE 3 -#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__) -#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__) -#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__) -#define planInfo(param, ...) qInfo("PLAN: " param, __VA_ARGS__) -#define planDebug(param, ...) qDebug("PLAN: " param, __VA_ARGS__) -#define planTrace(param, ...) qTrace("PLAN: " param, __VA_ARGS__) +#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__) +#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__) +#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__) +#define planInfo(param, ...) qInfo("PLAN: " param, __VA_ARGS__) +#define planDebug(param, ...) qDebug("PLAN: " param, __VA_ARGS__) +#define planTrace(param, ...) qTrace("PLAN: " param, __VA_ARGS__) int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode); int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index ac5188170af6d148cf0956a670ffe0d92197f568..f8ff2848afd61a5c11dd325a5b51285891b1456e 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -24,11 +24,12 @@ typedef struct SLogicPlanContext { typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, SSelectStmt*, SLogicNode**); typedef int32_t (*FCreateSetOpLogicNode)(SLogicPlanContext*, SSetOperator*, SLogicNode**); -static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode); +static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, + SLogicNode** pLogicNode); static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode); typedef struct SRewriteExprCxt { - int32_t errCode; + int32_t errCode; SNodeList* pExprs; } SRewriteExprCxt; @@ -38,8 +39,8 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) { case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_FUNCTION: { SRewriteExprCxt* pCxt = (SRewriteExprCxt*)pContext; - SNode* pExpr; - int32_t index = 0; + SNode* pExpr; + int32_t index = 0; FOREACH(pExpr, pCxt->pExprs) { if (QUERY_NODE_GROUPING_SET == nodeType(pExpr)) { pExpr = nodesListGetNode(((SGroupingSetNode*)pExpr)->pParameterList, 0); @@ -87,13 +88,13 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) { static int32_t rewriteExprForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) { nodesWalkExprs(pExprs, doNameExpr, NULL); - SRewriteExprCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs }; + SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs}; nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt); return cxt.errCode; } static int32_t rewriteExprs(SNodeList* pExprs, SNodeList* pTarget) { - SRewriteExprCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs }; + SRewriteExprCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs}; nodesRewriteExprs(pTarget, doRewriteExpr, &cxt); return cxt.errCode; } @@ -115,9 +116,10 @@ static int32_t pushLogicNode(SLogicPlanContext* pCxt, SLogicNode** pOldRoot, SLo return TSDB_CODE_SUCCESS; } -static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func, SLogicNode** pRoot) { +static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func, + SLogicNode** pRoot) { SLogicNode* pNode = NULL; - int32_t code = func(pCxt, pSelect, &pNode); + int32_t code = func(pCxt, pSelect, &pNode); if (TSDB_CODE_SUCCESS == code && NULL != pNode) { code = pushLogicNode(pCxt, pRoot, pNode); } @@ -173,7 +175,7 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) { } } - bool found = false; + bool found = false; SNode* pCol = NULL; FOREACH(pCol, *pCols) { if (PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pCol)->colId) { @@ -191,7 +193,8 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) { return TSDB_CODE_SUCCESS; } -static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, SLogicNode** pLogicNode) { +static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, + SLogicNode** pLogicNode) { SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; @@ -201,7 +204,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect TSWAP(pScan->pVgroupList, pRealTable->pVgroupList, SVgroupsInfo*); pScan->scanSeq[0] = 1; pScan->scanSeq[1] = 0; - pScan->scanRange = TSWINDOW_INITIALIZER; + pScan->scanRange = TSWINDOW_INITIALIZER; pScan->tableName.type = TSDB_TABLE_NAME_T; pScan->tableName.acctId = pCxt->pPlanCxt->acctId; strcpy(pScan->tableName.dbname, pRealTable->table.dbName); @@ -212,7 +215,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect // set columns to scan SNodeList* pCols = NULL; - int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, &pCols); + int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, &pCols); if (TSDB_CODE_SUCCESS == code) { code = addPrimaryKeyCol(pScan->pMeta->uid, &pCols); } @@ -245,18 +248,18 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } -static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, SLogicNode** pLogicNode) { +static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, + SLogicNode** pLogicNode) { int32_t code = createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode); if (TSDB_CODE_SUCCESS == code) { SNode* pNode; - FOREACH(pNode, (*pLogicNode)->pTargets) { - strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias); - } + FOREACH(pNode, (*pLogicNode)->pTargets) { strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias); } } return code; } -static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable, SLogicNode** pLogicNode) { +static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable, + SLogicNode** pLogicNode) { SJoinLogicNode* pJoin = (SJoinLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; @@ -316,7 +319,8 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } -static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) { +static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, + SLogicNode** pLogicNode) { switch (nodeType(pTable)) { case QUERY_NODE_REAL_TABLE: return createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pTable, pLogicNode); @@ -330,9 +334,10 @@ static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pS return TSDB_CODE_FAILED; } -static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) { +static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, + SLogicNode** pLogicNode) { SLogicNode* pNode = NULL; - int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode); + int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode); if (TSDB_CODE_SUCCESS == code) { pNode->pConditions = nodesCloneNode(pSelect->pWhere); if (NULL != pSelect->pWhere && NULL == pNode->pConditions) { @@ -358,7 +363,7 @@ static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr) } typedef struct SCreateColumnCxt { - int32_t errCode; + int32_t errCode; SNodeList* pList; } SCreateColumnCxt; @@ -375,7 +380,7 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) { case QUERY_NODE_OPERATOR: case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_FUNCTION: { - SExprNode* pExpr = (SExprNode*)pNode; + SExprNode* pExpr = (SExprNode*)pNode; SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); if (NULL == pCol) { return DEAL_RES_ERROR; @@ -392,7 +397,7 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) { } static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pExprs, SNodeList** pList) { - SCreateColumnCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pList = (NULL == *pList ? nodesMakeList() : *pList) }; + SCreateColumnCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pList = (NULL == *pList ? nodesMakeList() : *pList)}; if (NULL == cxt.pList) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -409,12 +414,7 @@ static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pEx } static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { - SNodeList* pAggFuncs = NULL; - int32_t code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAggFuncs); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - if (NULL == pAggFuncs && NULL == pSelect->pGroupByList) { + if (!pSelect->hasAggFuncs && NULL == pSelect->pGroupByList) { return TSDB_CODE_SUCCESS; } @@ -423,18 +423,13 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, return TSDB_CODE_OUT_OF_MEMORY; } + int32_t code = TSDB_CODE_SUCCESS; + // set grouyp keys, agg funcs and having conditions if (NULL != pSelect->pGroupByList) { pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList); if (NULL == pAgg->pGroupKeys) { code = TSDB_CODE_OUT_OF_MEMORY; - } - } - - if (TSDB_CODE_SUCCESS == code && NULL != pAggFuncs) { - pAgg->pAggFuncs = nodesCloneList(pAggFuncs); - if (NULL == pAgg->pAggFuncs) { - code = TSDB_CODE_OUT_OF_MEMORY; } } @@ -442,6 +437,12 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, if (TSDB_CODE_SUCCESS == code) { code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY); } + + if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) { + code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAgg->pAggFuncs); + } + + // rewrite the expression in subsequent clauses if (TSDB_CODE_SUCCESS == code) { code = rewriteExprForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY); } @@ -470,7 +471,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, return code; } -static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, + SLogicNode** pLogicNode) { int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs); if (pCxt->pPlanCxt->streamQuery) { @@ -486,6 +488,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm code = createColumnByRewriteExps(pCxt, pWindow->pFuncs, &pWindow->node.pTargets); } + pSelect->hasAggFuncs = false; + if (TSDB_CODE_SUCCESS == code) { *pLogicNode = (SLogicNode*)pWindow; } else { @@ -495,7 +499,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm return code; } -static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect, + SLogicNode** pLogicNode) { SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW); if (NULL == pWindow) { return TSDB_CODE_OUT_OF_MEMORY; @@ -513,7 +518,8 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } -static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession, SSelectStmt* pSelect, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession, + SSelectStmt* pSelect, SLogicNode** pLogicNode) { SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW); if (NULL == pWindow) { return TSDB_CODE_OUT_OF_MEMORY; @@ -531,7 +537,8 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } -static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, SSelectStmt* pSelect, SLogicNode** pLogicNode) { +static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, + SSelectStmt* pSelect, SLogicNode** pLogicNode) { SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW); if (NULL == pWindow) { return TSDB_CODE_OUT_OF_MEMORY; @@ -542,7 +549,8 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva pWindow->intervalUnit = ((SValueNode*)pInterval->pInterval)->unit; pWindow->offset = (NULL != pInterval->pOffset ? ((SValueNode*)pInterval->pOffset)->datum.i : 0); pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval); - pWindow->slidingUnit = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit); + pWindow->slidingUnit = + (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit); pWindow->pTspk = nodesCloneNode(pInterval->pCol); if (NULL == pWindow->pTspk) { @@ -591,7 +599,7 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect } SNodeList* pCols = NULL; - int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, &pCols); + int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, &pCols); if (TSDB_CODE_SUCCESS == code && NULL != pCols) { pSort->node.pTargets = nodesCloneList(pCols); if (NULL == pSort->node.pTargets) { @@ -615,14 +623,15 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } -static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, SNodeList** pCols) { +static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, + SNodeList** pCols) { SNodeList* pList = nodesMakeList(); if (NULL == pList) { return TSDB_CODE_OUT_OF_MEMORY; } SNode* pNode; - FOREACH(pNode, pExprs) { + FOREACH(pNode, pExprs) { if (TSDB_CODE_SUCCESS != nodesListAppend(pList, createColumnByExpr(pStmtName, (SExprNode*)pNode))) { nodesDestroyList(pList); return TSDB_CODE_OUT_OF_MEMORY; @@ -687,7 +696,7 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS } SNodeList* pCols = NULL; - int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_PARTITION_BY, NULL, &pCols); + int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_PARTITION_BY, NULL, &pCols); if (TSDB_CODE_SUCCESS == code && NULL != pCols) { pPartition->node.pTargets = nodesCloneList(pCols); if (NULL == pPartition->node.pTargets) { @@ -749,7 +758,7 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { SLogicNode* pRoot = NULL; - int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot); + int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot); if (TSDB_CODE_SUCCESS == code) { code = createChildLogicNode(pCxt, pSelect, createWindowLogicNode, &pRoot); } @@ -778,9 +787,10 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele return code; } -static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, FCreateSetOpLogicNode func, SLogicNode** pRoot) { +static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, + FCreateSetOpLogicNode func, SLogicNode** pRoot) { SLogicNode* pNode = NULL; - int32_t code = func(pCxt, pSetOperator, &pNode); + int32_t code = func(pCxt, pSetOperator, &pNode); if (TSDB_CODE_SUCCESS == code && NULL != pNode) { code = pushLogicNode(pCxt, pRoot, pNode); } @@ -823,7 +833,8 @@ static int32_t createSetOpSortLogicNode(SLogicPlanContext* pCxt, SSetOperator* p return code; } -static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { +static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, + SLogicNode** pLogicNode) { SProjectLogicNode* pProject = (SProjectLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PROJECT); if (NULL == pProject) { return TSDB_CODE_OUT_OF_MEMORY; @@ -890,7 +901,7 @@ static int32_t createSetOpAggLogicNode(SLogicPlanContext* pCxt, SSetOperator* pS static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { SLogicNode* pSetOp = NULL; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; switch (pSetOperator->opType) { case SET_OP_TYPE_UNION_ALL: code = createSetOpProjectLogicNode(pCxt, pSetOperator, &pSetOp); @@ -927,9 +938,10 @@ static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetO return code; } -static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { +static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, + SLogicNode** pLogicNode) { SLogicNode* pRoot = NULL; - int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot); + int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot); if (TSDB_CODE_SUCCESS == code) { code = createSetOpChildLogicNode(pCxt, pSetOperator, createSetOpSortLogicNode, &pRoot); } @@ -944,7 +956,9 @@ 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; + return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) + ? TDMT_VND_CREATE_TABLE + : TDMT_VND_SUBMIT; } static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) { @@ -975,8 +989,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi } int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode) { - SLogicPlanContext cxt = { .pPlanCxt = pCxt }; - int32_t code = createQueryLogicNode(&cxt, pCxt->pAstRoot, pLogicNode); + SLogicPlanContext cxt = {.pPlanCxt = pCxt}; + int32_t code = createQueryLogicNode(&cxt, pCxt->pAstRoot, pLogicNode); if (TSDB_CODE_SUCCESS != code) { return code; } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 21e55fc34adb40066551008366ebfb067789b780..f1b16353b6e88b521f5d8a2a3aae1ac096947ed6 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -13,43 +13,43 @@ * along with this program. If not, see . */ -#include "planInt.h" -#include "functionMgt.h" #include "filter.h" +#include "functionMgt.h" +#include "planInt.h" -#define OPTIMIZE_FLAG_MASK(n) (1 << n) +#define OPTIMIZE_FLAG_MASK(n) (1 << n) #define OPTIMIZE_FLAG_OSD OPTIMIZE_FLAG_MASK(0) #define OPTIMIZE_FLAG_CPD OPTIMIZE_FLAG_MASK(1) #define OPTIMIZE_FLAG_OPK OPTIMIZE_FLAG_MASK(2) -#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask) +#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask) #define OPTIMIZE_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) typedef struct SOptimizeContext { SPlanContext* pPlanCxt; - bool optimized; + bool optimized; } SOptimizeContext; typedef int32_t (*FMatch)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); typedef int32_t (*FOptimize)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); typedef struct SOptimizeRule { - char* pName; + char* pName; FOptimize optimizeFunc; } SOptimizeRule; typedef struct SOsdInfo { SScanLogicNode* pScan; - SNodeList* pSdrFuncs; - SNodeList* pDsoFuncs; + SNodeList* pSdrFuncs; + SNodeList* pDsoFuncs; } SOsdInfo; typedef struct SCpdIsMultiTableCondCxt { SNodeList* pLeftCols; SNodeList* pRightCols; - bool havaLeftCol; - bool haveRightCol; + bool havaLeftCol; + bool haveRightCol; } SCpdIsMultiTableCondCxt; typedef enum ECondAction { @@ -101,8 +101,8 @@ static bool osdMayBeOptimized(SLogicNode* pNode) { if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) { return false; } - if (NULL == pNode->pParent || - (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) { + if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && + QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) { return false; } if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent)) { @@ -125,7 +125,7 @@ static SNodeList* osdGetAllFuncs(SLogicNode* pNode) { static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs, SNodeList** pDsoFuncs) { SNodeList* pAllFuncs = osdGetAllFuncs(pScan->node.pParent); - SNode* pFunc = NULL; + SNode* pFunc = NULL; FOREACH(pFunc, pAllFuncs) { int32_t code = TSDB_CODE_SUCCESS; if (fmIsSpecialDataRequiredFunc(((SFunctionNode*)pFunc)->funcId)) { @@ -138,7 +138,7 @@ static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs, nodesDestroyList(*pDsoFuncs); return code; } - } + } return TSDB_CODE_SUCCESS; } @@ -150,7 +150,7 @@ static int32_t osdMatch(SOptimizeContext* pCxt, SLogicNode* pLogicNode, SOsdInfo return osdGetRelatedFuncs(pInfo->pScan, &pInfo->pSdrFuncs, &pInfo->pDsoFuncs); } -static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l , EFuncDataRequired r) { +static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l, EFuncDataRequired r) { switch (l) { case FUNC_DATA_REQUIRED_DATA_LOAD: return l; @@ -169,7 +169,7 @@ static int32_t osdGetDataRequired(SNodeList* pFuncs) { return FUNC_DATA_REQUIRED_DATA_LOAD; } EFuncDataRequired dataRequired = FUNC_DATA_REQUIRED_FILTEROUT; - SNode* pFunc = NULL; + SNode* pFunc = NULL; FOREACH(pFunc, pFuncs) { dataRequired = osdPromoteDataRequired(dataRequired, fmFuncDataRequired((SFunctionNode*)pFunc, NULL)); } @@ -189,7 +189,7 @@ static void setScanWindowInfo(SScanLogicNode* pScan) { static int32_t osdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { SOsdInfo info = {0}; - int32_t code = osdMatch(pCxt, pLogicNode, &info); + int32_t code = osdMatch(pCxt, pLogicNode, &info); if (TSDB_CODE_SUCCESS == code && (NULL != info.pDsoFuncs || NULL != info.pSdrFuncs)) { info.pScan->dataRequired = osdGetDataRequired(info.pSdrFuncs); info.pScan->pDynamicScanFuncs = info.pDsoFuncs; @@ -234,7 +234,7 @@ static int32_t cpdMergeConds(SNode** pDst, SNodeList** pSrc) { 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->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; pLogicCond->condType = LOGIC_COND_TYPE_AND; pLogicCond->pParameterList = *pSrc; *pDst = (SNode*)pLogicCond; @@ -283,7 +283,7 @@ static int32_t cpdPartitionScanLogicCond(SScanLogicNode* pScan, SNode** pPrimary SNodeList* pPrimaryKeyConds = NULL; SNodeList* pOtherConds = NULL; - SNode* pCond = NULL; + SNode* pCond = NULL; FOREACH(pCond, pLogicCond->pParameterList) { if (cpdIsPrimaryKeyCond(pCond)) { code = nodesListMakeAppend(&pPrimaryKeyConds, nodesCloneNode(pCond)); @@ -321,7 +321,7 @@ static int32_t cpdPartitionScanLogicCond(SScanLogicNode* pScan, SNode** pPrimary static int32_t cpdPartitionScanCond(SScanLogicNode* pScan, SNode** pPrimaryKeyCond, SNode** pOtherCond) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(pScan->node.pConditions) && - LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)pScan->node.pConditions)->condType) { + LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)pScan->node.pConditions)->condType) { return cpdPartitionScanLogicCond(pScan, pPrimaryKeyCond, pOtherCond); } @@ -336,7 +336,7 @@ static int32_t cpdPartitionScanCond(SScanLogicNode* pScan, SNode** pPrimaryKeyCo } static int32_t cpdCalcTimeRange(SScanLogicNode* pScan, SNode** pPrimaryKeyCond, SNode** pOtherCond) { - bool isStrict = false; + bool isStrict = false; int32_t code = filterGetTimeRange(*pPrimaryKeyCond, &pScan->scanRange, &isStrict); if (TSDB_CODE_SUCCESS == code) { if (isStrict) { @@ -354,8 +354,8 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode* return TSDB_CODE_SUCCESS; } - SNode* pPrimaryKeyCond = NULL; - SNode* pOtherCond = NULL; + SNode* pPrimaryKeyCond = NULL; + SNode* pOtherCond = NULL; int32_t code = cpdPartitionScanCond(pScan, &pPrimaryKeyCond, &pOtherCond); if (TSDB_CODE_SUCCESS == code && NULL != pPrimaryKeyCond) { code = cpdCalcTimeRange(pScan, &pPrimaryKeyCond, &pOtherCond); @@ -399,13 +399,18 @@ static EDealRes cpdIsMultiTableCondImpl(SNode* pNode, void* pContext) { } static ECondAction cpdCondAction(EJoinType joinType, SNodeList* pLeftCols, SNodeList* pRightCols, SNode* pNode) { - SCpdIsMultiTableCondCxt cxt = { .pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false }; + SCpdIsMultiTableCondCxt cxt = { + .pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false}; nodesWalkExpr(pNode, cpdIsMultiTableCondImpl, &cxt); - return (JOIN_TYPE_INNER != joinType ? COND_ACTION_STAY : - (cxt.havaLeftCol && cxt.haveRightCol ? COND_ACTION_PUSH_JOIN : (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD))); + return (JOIN_TYPE_INNER != joinType + ? COND_ACTION_STAY + : (cxt.havaLeftCol && cxt.haveRightCol + ? COND_ACTION_PUSH_JOIN + : (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD))); } -static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { +static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, + SNode** pRightChildCond) { SLogicConditionNode* pLogicCond = (SLogicConditionNode*)pJoin->node.pConditions; if (LOGIC_COND_TYPE_AND != pLogicCond->condType) { return TSDB_CODE_SUCCESS; @@ -413,13 +418,13 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SNodeList* pOnConds = NULL; SNodeList* pLeftChildConds = NULL; SNodeList* pRightChildConds = NULL; SNodeList* pRemainConds = NULL; - SNode* pCond = NULL; + SNode* pCond = NULL; FOREACH(pCond, pLogicCond->pParameterList) { ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pCond); if (COND_ACTION_PUSH_JOIN == condAction) { @@ -473,9 +478,10 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo return code; } -static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { - SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; - SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; +static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, + SNode** pRightChildCond) { + SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; + SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pJoin->node.pConditions); if (COND_ACTION_STAY == condAction) { return TSDB_CODE_SUCCESS; @@ -490,7 +496,8 @@ static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode* return TSDB_CODE_SUCCESS; } -static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { +static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, + SNode** pRightChildCond) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(pJoin->node.pConditions)) { return cpdPartitionLogicCond(pJoin, pOnCond, pLeftChildCond, pRightChildCond); } else { @@ -509,7 +516,7 @@ static int32_t cpdPushCondToScan(SOptimizeContext* pCxt, SScanLogicNode* pScan, static int32_t cpdPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SNode** pCond) { switch (nodeType(pChild)) { case QUERY_NODE_LOGIC_PLAN_SCAN: - return cpdPushCondToScan(pCxt, (SScanLogicNode*)pChild, pCond); + return cpdPushCondToScan(pCxt, (SScanLogicNode*)pChild, pCond); default: break; } @@ -531,8 +538,8 @@ static bool cpdIsPrimaryKeyEqualCond(SJoinLogicNode* pJoin, SNode* pCond) { if (QUERY_NODE_OPERATOR != nodeType(pCond)) { return false; } - SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; - SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; + SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; + SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; SOperatorNode* pOper = (SOperatorNode*)pJoin->pOnConditions; if (cpdIsPrimaryKey(pOper->pLeft, pLeftCols)) { return cpdIsPrimaryKey(pOper->pRight, pRightCols); @@ -586,9 +593,9 @@ static int32_t cpdPushJoinCondition(SOptimizeContext* pCxt, SJoinLogicNode* pJoi return cpdCheckJoinOnCond(pCxt, pJoin); } - SNode* pOnCond = NULL; - SNode* pLeftChildCond = NULL; - SNode* pRightChildCond = NULL; + SNode* pOnCond = NULL; + SNode* pLeftChildCond = NULL; + SNode* pRightChildCond = NULL; int32_t code = cpdPartitionCond(pJoin, &pOnCond, &pLeftChildCond, &pRightChildCond); if (TSDB_CODE_SUCCESS == code && NULL != pOnCond) { code = cpdPushCondToOnCond(pCxt, pJoin, &pOnCond); @@ -694,7 +701,7 @@ static int32_t opkGetScanNodesImpl(SLogicNode* pNode, bool* pNotOptimize, SNodeL } static int32_t opkGetScanNodes(SLogicNode* pNode, SNodeList** pScanNodes) { - bool notOptimize = false; + bool notOptimize = false; int32_t code = opkGetScanNodesImpl(pNode, ¬Optimize, pScanNodes); if (TSDB_CODE_SUCCESS != code || notOptimize) { nodesClearList(*pScanNodes); @@ -746,7 +753,7 @@ static int32_t opkOptimizeImpl(SOptimizeContext* pCxt, SSortLogicNode* pSort) { return TSDB_CODE_SUCCESS; } SNodeList* pScanNodes = NULL; - int32_t code = opkGetScanNodes(nodesListGetNode(pSort->node.pChildren, 0), &pScanNodes); + int32_t code = opkGetScanNodes(nodesListGetNode(pSort->node.pChildren, 0), &pScanNodes); if (TSDB_CODE_SUCCESS == code && NULL != pScanNodes) { code = opkDoOptimized(pCxt, pSort, pScanNodes); } @@ -762,16 +769,14 @@ static int32_t opkOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { return opkOptimizeImpl(pCxt, pSort); } -static const SOptimizeRule optimizeRuleSet[] = { - { .pName = "OptimizeScanData", .optimizeFunc = osdOptimize }, - { .pName = "ConditionPushDown", .optimizeFunc = cpdOptimize }, - { .pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize } -}; +static const SOptimizeRule optimizeRuleSet[] = {{.pName = "OptimizeScanData", .optimizeFunc = osdOptimize}, + {.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize}, + {.pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize}}; static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule)); static int32_t applyOptimizeRule(SPlanContext* pCxt, SLogicNode* pLogicNode) { - SOptimizeContext cxt = { .pPlanCxt = pCxt, .optimized = false }; + SOptimizeContext cxt = {.pPlanCxt = pCxt, .optimized = false}; do { cxt.optimized = false; for (int32_t i = 0; i < optimizeRuleNum; ++i) { @@ -784,6 +789,4 @@ static int32_t applyOptimizeRule(SPlanContext* pCxt, SLogicNode* pLogicNode) { return TSDB_CODE_SUCCESS; } -int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { - return applyOptimizeRule(pCxt, pLogicNode); -} +int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { return applyOptimizeRule(pCxt, pLogicNode); } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 28635ef940dfcfae6d3f7f2b2f4174740c42b64c..4997cfd64465dbf0b5d87a0f9b32e77335eb264f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -15,26 +15,26 @@ #include "planInt.h" +#include "catalog.h" #include "functionMgt.h" #include "tglobal.h" -#include "catalog.h" typedef struct SSlotIdInfo { int16_t slotId; - bool set; + bool set; } SSlotIdInfo; typedef struct SSlotIndex { int16_t dataBlockId; - SArray* pSlotIdsInfo; // duplicate name slot + SArray* pSlotIdsInfo; // duplicate name slot } SSlotIndex; typedef struct SPhysiPlanContext { SPlanContext* pPlanCxt; - int32_t errCode; - int16_t nextDataBlockId; - SArray* pLocationHelper; - SArray* pExecNodeList; + int32_t errCode; + int16_t nextDataBlockId; + SArray* pLocationHelper; + SArray* pExecNodeList; } SPhysiPlanContext; static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) { @@ -84,27 +84,28 @@ static int32_t createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId, S static int32_t putSlotToHashImpl(int16_t dataBlockId, int16_t slotId, const char* pName, int32_t len, SHashObj* pHash) { SSlotIndex* pIndex = taosHashGet(pHash, pName, len); if (NULL != pIndex) { - SSlotIdInfo info = { .slotId = slotId, .set = false }; + SSlotIdInfo info = {.slotId = slotId, .set = false}; taosArrayPush(pIndex->pSlotIdsInfo, &info); return TSDB_CODE_SUCCESS; } - SSlotIndex index = { .dataBlockId = dataBlockId, .pSlotIdsInfo = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SSlotIdInfo)) }; + SSlotIndex index = {.dataBlockId = dataBlockId, .pSlotIdsInfo = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SSlotIdInfo))}; if (NULL == index.pSlotIdsInfo) { return TSDB_CODE_OUT_OF_MEMORY; } - SSlotIdInfo info = { .slotId = slotId, .set = false }; + SSlotIdInfo info = {.slotId = slotId, .set = false}; taosArrayPush(index.pSlotIdsInfo, &info); return taosHashPut(pHash, pName, len, &index, sizeof(SSlotIndex)); } static int32_t putSlotToHash(int16_t dataBlockId, int16_t slotId, SNode* pNode, SHashObj* pHash) { - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; int32_t len = getSlotKey(pNode, NULL, name); return putSlotToHashImpl(dataBlockId, slotId, name, len, pHash); } -static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, SHashObj** pDescHash) { +static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, + SHashObj** pDescHash) { SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == pHash) { return TSDB_CODE_OUT_OF_MEMORY; @@ -118,7 +119,8 @@ static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity return TSDB_CODE_SUCCESS; } -static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, SHashObj* pHash) { +static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, + SHashObj* pHash) { pDataBlockDesc->pSlots = nodesMakeList(); if (NULL == pDataBlockDesc->pSlots) { return TSDB_CODE_OUT_OF_MEMORY; @@ -126,7 +128,7 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD int32_t code = TSDB_CODE_SUCCESS; int16_t slotId = 0; - SNode* pNode = NULL; + SNode* pNode = NULL; FOREACH(pNode, pList) { code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, slotId, true)); if (TSDB_CODE_SUCCESS == code) { @@ -151,7 +153,7 @@ static int32_t createDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SD pDesc->dataBlockId = pCxt->nextDataBlockId++; SHashObj* pHash = NULL; - int32_t code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash); + int32_t code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash); if (TSDB_CODE_SUCCESS == code) { code = buildDataBlockSlots(pCxt, pList, pDesc, pHash); } @@ -177,19 +179,20 @@ static int16_t getUnsetSlotId(const SArray* pSlotIdsInfo) { return ((SSlotIdInfo*)taosArrayGet(pSlotIdsInfo, 0))->slotId; } -static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, const char* pStmtName, bool output) { +static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, + const char* pStmtName, bool output) { if (NULL == pList) { return TSDB_CODE_SUCCESS; } - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; SHashObj* pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId); - int16_t nextSlotId = taosHashGetSize(pHash), slotId = 0; - SNode* pNode = NULL; + int16_t nextSlotId = taosHashGetSize(pHash), slotId = 0; + SNode* pNode = NULL; FOREACH(pNode, pList) { - SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode; - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0}; - int32_t len = getSlotKey(pExpr, pStmtName, name); + SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode; + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0}; + int32_t len = getSlotKey(pExpr, pStmtName, name); SSlotIndex* pIndex = taosHashGet(pHash, name, len); if (NULL == pIndex) { code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pExpr, nextSlotId, output)); @@ -213,7 +216,7 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, REPLACE_NODE(pTarget); } } - + if (TSDB_CODE_SUCCESS != code) { break; } @@ -231,7 +234,7 @@ static int32_t addDataBlockSlot(SPhysiPlanContext* pCxt, SNode** pNode, SDataBlo } SNodeList* pList = NULL; - int32_t code = nodesListMakeAppend(&pList, *pNode); + int32_t code = nodesListMakeAppend(&pList, *pNode); if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pList, pDataBlockDesc); } @@ -242,7 +245,8 @@ static int32_t addDataBlockSlot(SPhysiPlanContext* pCxt, SNode** pNode, SDataBlo return code; } -static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) { +static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, + SDataBlockDescNode* pDataBlockDesc) { return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, pStmtName, true); } @@ -251,7 +255,7 @@ static int32_t pushdownDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, } typedef struct SSetSlotIdCxt { - int32_t errCode; + int32_t errCode; SHashObj* pLeftHash; SHashObj* pRightHash; } SSetSlotIdCxt; @@ -259,9 +263,9 @@ typedef struct SSetSlotIdCxt { static EDealRes doSetSlotId(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode) && 0 != strcmp(((SColumnNode*)pNode)->colName, "*")) { SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext; - char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; - int32_t len = getSlotKey(pNode, NULL, name); - SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, len); + char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN]; + int32_t len = getSlotKey(pNode, NULL, name); + SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, len); if (NULL == pIndex) { pIndex = taosHashGet(pCxt->pRightHash, name, len); } @@ -277,17 +281,17 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } -static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode, SNode** pOutput) { +static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode, + SNode** pOutput) { SNode* pRes = nodesCloneNode(pNode); if (NULL == pRes) { return TSDB_CODE_OUT_OF_MEMORY; } SSetSlotIdCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), - .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)) - }; + .errCode = TSDB_CODE_SUCCESS, + .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), + .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))}; nodesWalkExpr(pRes, doSetSlotId, &cxt); if (TSDB_CODE_SUCCESS != cxt.errCode) { nodesDestroyNode(pRes); @@ -298,17 +302,17 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i return TSDB_CODE_SUCCESS; } -static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, const SNodeList* pList, SNodeList** pOutput) { +static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, + const SNodeList* pList, SNodeList** pOutput) { SNodeList* pRes = nodesCloneList(pList); if (NULL == pRes) { return TSDB_CODE_OUT_OF_MEMORY; } SSetSlotIdCxt cxt = { - .errCode = TSDB_CODE_SUCCESS, - .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), - .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId)) - }; + .errCode = TSDB_CODE_SUCCESS, + .pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId), + .pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))}; nodesWalkExprs(pRes, doSetSlotId, &cxt); if (TSDB_CODE_SUCCESS != cxt.errCode) { nodesDestroyList(pRes); @@ -346,7 +350,8 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, uint8_t precision, SLo static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pLogicNode, SPhysiNode* pPhysiNode) { if (NULL != pLogicNode->pConditions) { - return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions, &pPhysiNode->pConditions); + return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions, + &pPhysiNode->pConditions); } return TSDB_CODE_SUCCESS; } @@ -364,15 +369,11 @@ static int32_t sortScanCols(SNodeList* pScanCols) { } SNode* pCol = NULL; - FOREACH(pCol, pScanCols) { - taosArrayPush(pArray, &pCol); - } + FOREACH(pCol, pScanCols) { taosArrayPush(pArray, &pCol); } taosArraySort(pArray, colIdCompare); int32_t index = 0; - FOREACH(pCol, pScanCols) { - REPLACE_NODE(taosArrayGetP(pArray, index++)); - } + FOREACH(pCol, pScanCols) { REPLACE_NODE(taosArrayGetP(pArray, index++)); } taosArrayDestroy(pArray); return TSDB_CODE_SUCCESS; @@ -386,7 +387,8 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys return sortScanCols(pScanPhysiNode->pScanCols); } -static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) { +static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, + SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) { int32_t code = createScanCols(pCxt, pScanPhysiNode, pScanLogicNode->pScanCols); if (TSDB_CODE_SUCCESS == code) { // Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t @@ -412,19 +414,23 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNo static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAddr) { pNodeAddr->nodeId = vg->vgId; - pNodeAddr->epSet = vg->epSet; + pNodeAddr->epSet = vg->epSet; } static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); + 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; } return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTagScan, pPhyNode); } -static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); +static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { + STableScanPhysiNode* pTableScan = + (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, + QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); if (NULL == pTableScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -451,8 +457,11 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode); } -static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); +static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, + SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { + SSystemTableScanPhysiNode* pScan = + (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, + (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -463,7 +472,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode); taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode); } else { - SQueryNodeAddr addr = { .nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet }; + SQueryNodeAddr addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}; taosArrayPush(pCxt->pExecNodeList, &addr); } pScan->mgmtEpSet = pCxt->pPlanCxt->mgmtEpSet; @@ -472,15 +481,19 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode); } -static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); +static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { + SStreamScanPhysiNode* pScan = + (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, + (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode); } -static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { +static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, + SPhysiNode** pPhyNode) { switch (pScanLogicNode->scanType) { case SCAN_TYPE_TAG: return createTagScanPhysiNode(pCxt, pScanLogicNode, pPhyNode); @@ -496,22 +509,26 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, return TSDB_CODE_FAILED; } -static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) { - SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); +static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, + SPhysiNode** pPhyNode) { + SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, + QUERY_NODE_PHYSICAL_PLAN_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; } SDataBlockDescNode* pLeftDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc; SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; pJoin->joinType = pJoinLogicNode->joinType; if (NULL != pJoinLogicNode->pOnConditions) { - code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); + code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, + &pJoin->pOnConditions); } if (TSDB_CODE_SUCCESS == code) { - code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets); + code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, + &pJoin->pTargets); } if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc); @@ -530,9 +547,9 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren } typedef struct SRewritePrecalcExprsCxt { - int32_t errCode; - int32_t planNodeId; - int32_t rewriteId; + int32_t errCode; + int32_t planNodeId; + int32_t rewriteId; SNodeList* pPrecalcExprs; } SRewritePrecalcExprsCxt; @@ -555,7 +572,8 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) if ('\0' != pRewrittenExpr->aliasName[0]) { strcpy(pCol->colName, pRewrittenExpr->aliasName); } else { - snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, pCxt->rewriteId); + snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, + pCxt->rewriteId); strcpy(pCol->colName, pRewrittenExpr->aliasName); } nodesDestroyNode(*pNode); @@ -581,7 +599,8 @@ static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } -static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs, SNodeList** pRewrittenList) { +static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs, + SNodeList** pRewrittenList) { if (NULL == pList) { return TSDB_CODE_SUCCESS; } @@ -613,7 +632,7 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN return TSDB_CODE_OUT_OF_MEMORY; } } - SRewritePrecalcExprsCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pPrecalcExprs = *pPrecalcExprs }; + SRewritePrecalcExprsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pPrecalcExprs = *pPrecalcExprs}; nodesRewriteExprs(*pRewrittenList, doRewritePrecalcExprs, &cxt); if (0 == LIST_LENGTH(cxt.pPrecalcExprs)) { nodesDestroyList(cxt.pPrecalcExprs); @@ -622,13 +641,14 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN return cxt.errCode; } -static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs, SNode** pRewritten) { +static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs, + SNode** pRewritten) { if (NULL == pNode) { return TSDB_CODE_SUCCESS; } SNodeList* pList = NULL; - int32_t code = nodesListMakeAppend(&pList, pNode); + int32_t code = nodesListMakeAppend(&pList, pNode); SNodeList* pRewrittenList = NULL; if (TSDB_CODE_SUCCESS == code) { code = rewritePrecalcExprs(pCxt, pList, pPrecalcExprs, &pRewrittenList); @@ -641,8 +661,10 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi return code; } -static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) { - SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG); +static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, + SPhysiNode** pPhyNode) { + SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, + QUERY_NODE_PHYSICAL_PLAN_AGG); if (NULL == pAgg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -650,7 +672,7 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SNodeList* pPrecalcExprs = NULL; SNodeList* pGroupKeys = NULL; SNodeList* pAggFuncs = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pAggLogicNode->pGroupKeys, &pPrecalcExprs, &pGroupKeys); + int32_t code = rewritePrecalcExprs(pCxt, pAggLogicNode->pGroupKeys, &pPrecalcExprs, &pGroupKeys); if (TSDB_CODE_SUCCESS == code) { code = rewritePrecalcExprs(pCxt, pAggLogicNode->pAggFuncs, &pPrecalcExprs, &pAggFuncs); } @@ -695,8 +717,10 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, return code; } -static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { - SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); +static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { + SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); if (NULL == pProject) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -706,9 +730,11 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild pProject->slimit = pProjectLogicNode->slimit; pProject->soffset = pProjectLogicNode->soffset; - int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, pProjectLogicNode->pProjections, &pProject->pProjections); + int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, + -1, pProjectLogicNode->pProjections, &pProject->pProjections); if (TSDB_CODE_SUCCESS == code) { - code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, pProject->node.pOutputDataBlockDesc); + code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, + pProject->node.pOutputDataBlockDesc); } if (TSDB_CODE_SUCCESS == code) { code = setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject); @@ -723,8 +749,10 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild return code; } -static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); +static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, + SPhysiNode** pPhyNode) { + SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode( + pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); if (NULL == pExchange) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -734,12 +762,14 @@ static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogic return TSDB_CODE_SUCCESS; } -static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); +static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, + SPhysiNode** pPhyNode) { + SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode( + pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } - + int32_t code = TSDB_CODE_SUCCESS; pScan->pScanCols = nodesCloneList(pExchangeLogicNode->node.pTargets); @@ -767,7 +797,8 @@ static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExc return code; } -static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { +static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, + SPhysiNode** pPhyNode) { if (pCxt->pPlanCxt->streamQuery) { return createStreamScanPhysiNodeByExchange(pCxt, pExchangeLogicNode, pPhyNode); } else { @@ -775,10 +806,11 @@ static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNo } } -static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { +static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { SNodeList* pPrecalcExprs = NULL; SNodeList* pFuncs = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pWindowLogicNode->pFuncs, &pPrecalcExprs, &pFuncs); + int32_t code = rewritePrecalcExprs(pCxt, pWindowLogicNode->pFuncs, &pPrecalcExprs, &pFuncs); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -812,8 +844,10 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* return code; } -static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); +static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { + SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); if (NULL == pInterval) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -833,8 +867,10 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode); } -static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); +static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { + SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); if (NULL == pSession) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -844,15 +880,17 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* return createWindowPhysiNodeFinalize(pCxt, pChildren, &pSession->window, pWindowLogicNode, pPhyNode); } -static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); +static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { + SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); if (NULL == pState) { return TSDB_CODE_OUT_OF_MEMORY; } SNodeList* pPrecalcExprs = NULL; - SNode* pStateKey = NULL; - int32_t code = rewritePrecalcExpr(pCxt, pWindowLogicNode->pStateExpr, &pPrecalcExprs, &pStateKey); + SNode* pStateKey = NULL; + int32_t code = rewritePrecalcExpr(pCxt, pWindowLogicNode->pStateExpr, &pPrecalcExprs, &pStateKey); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -878,7 +916,8 @@ static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pC return createWindowPhysiNodeFinalize(pCxt, pChildren, &pState->window, pWindowLogicNode, pPhyNode); } -static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { +static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, + SPhysiNode** pPhyNode) { switch (pWindowLogicNode->winType) { case WINDOW_TYPE_INTERVAL: return createIntervalPhysiNode(pCxt, pChildren, pWindowLogicNode, pPhyNode); @@ -892,15 +931,17 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr return TSDB_CODE_FAILED; } -static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) { - SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT); +static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, + SPhysiNode** pPhyNode) { + SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, + QUERY_NODE_PHYSICAL_PLAN_SORT); if (NULL == pSort) { return TSDB_CODE_OUT_OF_MEMORY; } SNodeList* pPrecalcExprs = NULL; SNodeList* pSortKeys = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pSortLogicNode->pSortKeys, &pPrecalcExprs, &pSortKeys); + int32_t code = rewritePrecalcExprs(pCxt, pSortLogicNode->pSortKeys, &pPrecalcExprs, &pSortKeys); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -931,15 +972,17 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren return code; } -static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) { - SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); +static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, + SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) { + SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode( + pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); if (NULL == pPart) { return TSDB_CODE_OUT_OF_MEMORY; } SNodeList* pPrecalcExprs = NULL; SNodeList* pPartitionKeys = NULL; - int32_t code = rewritePrecalcExprs(pCxt, pPartLogicNode->pPartitionKeys, &pPrecalcExprs, &pPartitionKeys); + int32_t code = rewritePrecalcExprs(pCxt, pPartLogicNode->pPartitionKeys, &pPrecalcExprs, &pPartitionKeys); SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); // push down expression to pOutputDataBlockDesc of child node @@ -970,7 +1013,8 @@ static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi return code; } -static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SNodeList* pChildren, SPhysiNode** pPhyNode) { +static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, + SNodeList* pChildren, SPhysiNode** pPhyNode) { switch (nodeType(pLogicNode)) { case QUERY_NODE_LOGIC_PLAN_SCAN: return createScanPhysiNode(pCxt, pSubplan, (SScanLogicNode*)pLogicNode, pPhyNode); @@ -995,7 +1039,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode return TSDB_CODE_FAILED; } -static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SPhysiNode** pPhyNode) { +static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, + SPhysiNode** pPhyNode) { SNodeList* pChildren = nodesMakeList(); if (NULL == pChildren) { return TSDB_CODE_OUT_OF_MEMORY; @@ -1019,9 +1064,7 @@ static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, if (TSDB_CODE_SUCCESS == code) { (*pPhyNode)->pChildren = pChildren; SNode* pChild; - FOREACH(pChild, (*pPhyNode)->pChildren) { - ((SPhysiNode*)pChild)->pParent = (*pPhyNode); - } + FOREACH(pChild, (*pPhyNode)->pChildren) { ((SPhysiNode*)pChild)->pParent = (*pPhyNode); } } else { nodesDestroyList(pChildren); } @@ -1097,7 +1140,7 @@ static int32_t createPhysiSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogic } else { nodesDestroyNode(pSubplan); } - + return code; } @@ -1137,9 +1180,10 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l return nodesListStrictAppend(pGroup->pNodeList, pSubplan); } -static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, SQueryPlan* pQueryPlan) { +static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, + SQueryPlan* pQueryPlan) { SSubplan* pSubplan = NULL; - int32_t code = createPhysiSubplan(pCxt, pLogicSubplan, &pSubplan); + int32_t code = createPhysiSubplan(pCxt, pLogicSubplan, &pSubplan); if (TSDB_CODE_SUCCESS == code) { code = pushSubplan(pCxt, pSubplan, pLogicSubplan->level, pQueryPlan->pSubplans); @@ -1196,7 +1240,7 @@ static int32_t doCreatePhysiPlan(SPhysiPlanContext* pCxt, SQueryLogicPlan* pLogi } static void destoryLocationHash(void* p) { - SHashObj* pHash = *(SHashObj**)p; + SHashObj* pHash = *(SHashObj**)p; SSlotIndex* pIndex = taosHashIterate(pHash, NULL); while (NULL != pIndex) { taosArrayDestroy(pIndex->pSlotIdsInfo); @@ -1221,13 +1265,11 @@ static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) { } int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) { - SPhysiPlanContext cxt = { - .pPlanCxt = pCxt, - .errCode = TSDB_CODE_SUCCESS, - .nextDataBlockId = 0, - .pLocationHelper = taosArrayInit(32, POINTER_BYTES), - .pExecNodeList = pExecNodeList - }; + SPhysiPlanContext cxt = {.pPlanCxt = pCxt, + .errCode = TSDB_CODE_SUCCESS, + .nextDataBlockId = 0, + .pLocationHelper = taosArrayInit(32, POINTER_BYTES), + .pExecNodeList = pExecNodeList}; if (NULL == cxt.pLocationHelper) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/planner/src/planScaleOut.c b/source/libs/planner/src/planScaleOut.c index 7bb97b59d70b1c827d7ce7831fe3d9573b8cd1d6..73c8666673ca23168d5dc2bf495cb9553bee55b8 100644 --- a/source/libs/planner/src/planScaleOut.c +++ b/source/libs/planner/src/planScaleOut.c @@ -17,7 +17,7 @@ typedef struct SScaleOutContext { SPlanContext* pPlanCxt; - int32_t subplanId; + int32_t subplanId; } SScaleOutContext; static SLogicSubplan* singleCloneSubLogicPlan(SScaleOutContext* pCxt, SLogicSubplan* pSrc, int32_t level) { @@ -40,7 +40,7 @@ static SLogicSubplan* singleCloneSubLogicPlan(SScaleOutContext* pCxt, SLogicSubp static int32_t scaleOutForModify(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pGroup) { SVnodeModifLogicNode* pNode = (SVnodeModifLogicNode*)pSubplan->pNode; - size_t numOfVgroups = taosArrayGetSize(pNode->pDataBlocks); + size_t numOfVgroups = taosArrayGetSize(pNode->pDataBlocks); for (int32_t i = 0; i < numOfVgroups; ++i) { SLogicSubplan* pNewSubplan = singleCloneSubLogicPlan(pCxt, pSubplan, level); if (NULL == pNewSubplan) { @@ -108,8 +108,8 @@ static int32_t scaleOutForScan(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, static int32_t pushHierarchicalPlan(SNodeList* pParentsGroup, SNodeList* pCurrentGroup) { int32_t code = TSDB_CODE_SUCCESS; - bool topLevel = (0 == LIST_LENGTH(pParentsGroup)); - SNode* pChild = NULL; + bool topLevel = (0 == LIST_LENGTH(pParentsGroup)); + SNode* pChild = NULL; FOREACH(pChild, pCurrentGroup) { if (topLevel) { code = nodesListAppend(pParentsGroup, pChild); @@ -192,8 +192,8 @@ int32_t scaleOutLogicPlan(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SQue return TSDB_CODE_OUT_OF_MEMORY; } - SScaleOutContext cxt = { .pPlanCxt = pCxt, .subplanId = 1 }; - int32_t code = doScaleOut(&cxt, pLogicSubplan, 0, pPlan->pTopSubplans); + SScaleOutContext cxt = {.pPlanCxt = pCxt, .subplanId = 1}; + int32_t code = doScaleOut(&cxt, pLogicSubplan, 0, pPlan->pTopSubplans); if (TSDB_CODE_SUCCESS == code) { *pLogicPlan = pPlan; } else { diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index b419414ca6ddaa3454ca4d371ea6b6f52d1f44fe..51bd36f9f956e2b432385b23a3e2cffe726e2331 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -15,39 +15,39 @@ #include "planInt.h" -#define SPLIT_FLAG_MASK(n) (1 << n) +#define SPLIT_FLAG_MASK(n) (1 << n) #define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0) #define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1) -#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask) +#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask) #define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) typedef struct SSplitContext { int32_t groupId; - bool split; + bool split; } SSplitContext; typedef int32_t (*FSplit)(SSplitContext* pCxt, SLogicSubplan* pSubplan); typedef struct SSplitRule { - char* pName; + char* pName; FSplit splitFunc; } SSplitRule; typedef struct SStsInfo { SScanLogicNode* pScan; - SLogicSubplan* pSubplan; + SLogicSubplan* pSubplan; } SStsInfo; typedef struct SCtjInfo { SScanLogicNode* pScan; - SLogicSubplan* pSubplan; + SLogicSubplan* pSubplan; } SCtjInfo; typedef struct SUaInfo { SProjectLogicNode* pProject; - SLogicSubplan* pSubplan; + SLogicSubplan* pSubplan; } SUaInfo; typedef struct SUnInfo { @@ -70,7 +70,8 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* return pSubplan; } -static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan, ESubplanType subplanType) { +static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan, + ESubplanType subplanType) { SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE); if (NULL == pExchange) { return TSDB_CODE_OUT_OF_MEMORY; @@ -117,8 +118,8 @@ static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag, } static SLogicNode* stsMatchByNode(SLogicNode* pNode) { - if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && - NULL != ((SScanLogicNode*)pNode)->pVgroupList && ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) { + if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && NULL != ((SScanLogicNode*)pNode)->pVgroupList && + ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) { return pNode; } SNode* pChild; @@ -145,7 +146,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, (FSplFindSplitNode)stsFindSplitNode, &info)) { return TSDB_CODE_SUCCESS; } - int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS)); + int32_t code = + nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS)); if (TSDB_CODE_SUCCESS == code) { code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE); } @@ -163,7 +165,8 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) { SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0); SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pNode->pChildren, 1); if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ctjIsSingleTable(((SScanLogicNode*)pLeft)->pMeta->tableType) && - QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) { + QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && + ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) { return pRight; } } @@ -191,7 +194,8 @@ static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, (FSplFindSplitNode)ctjFindSplitNode, &info)) { return TSDB_CODE_SUCCESS; } - int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ)); + int32_t code = + nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ)); if (TSDB_CODE_SUCCESS == code) { code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType); } @@ -360,17 +364,15 @@ static int32_t unSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { return code; } -static const SSplitRule splitRuleSet[] = { - { .pName = "SuperTableScan", .splitFunc = stsSplit }, - { .pName = "ChildTableJoin", .splitFunc = ctjSplit }, - { .pName = "UnionAll", .splitFunc = uaSplit }, - { .pName = "Union", .splitFunc = unSplit } -}; +static const SSplitRule splitRuleSet[] = {{.pName = "SuperTableScan", .splitFunc = stsSplit}, + {.pName = "ChildTableJoin", .splitFunc = ctjSplit}, + {.pName = "UnionAll", .splitFunc = uaSplit}, + {.pName = "Union", .splitFunc = unSplit}}; static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule)); static int32_t applySplitRule(SLogicSubplan* pSubplan) { - SSplitContext cxt = { .groupId = pSubplan->id.groupId + 1, .split = false }; + SSplitContext cxt = {.groupId = pSubplan->id.groupId + 1, .split = false}; do { cxt.split = false; for (int32_t i = 0; i < splitRuleNum; ++i) { @@ -386,14 +388,10 @@ static int32_t applySplitRule(SLogicSubplan* pSubplan) { static void doSetLogicNodeParent(SLogicNode* pNode, SLogicNode* pParent) { pNode->pParent = pParent; SNode* pChild; - FOREACH(pChild, pNode->pChildren) { - doSetLogicNodeParent((SLogicNode*)pChild, pNode); - } + FOREACH(pChild, pNode->pChildren) { doSetLogicNodeParent((SLogicNode*)pChild, pNode); } } -static void setLogicNodeParent(SLogicNode* pNode) { - doSetLogicNodeParent(pNode, NULL); -} +static void setLogicNodeParent(SLogicNode* pNode) { doSetLogicNodeParent(pNode, NULL); } int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan** pLogicSubplan) { SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); @@ -408,7 +406,8 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan } if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIF == nodeType(pLogicNode)) { pSubplan->subplanType = SUBPLAN_TYPE_MODIFY; - TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks, SArray*); + TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks, + SArray*); } else { pSubplan->subplanType = SUBPLAN_TYPE_SCAN; } diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 004f0b18fd2e1796ab932d1c062645772f5c664e..2fa6395aed7bc08fa5cffd44d60cf605a4e7968c 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -18,7 +18,7 @@ #include "planInt.h" typedef struct SCollectPlaceholderValuesCxt { - int32_t errCode; + int32_t errCode; SNodeList* pValues; } SCollectPlaceholderValuesCxt; @@ -32,7 +32,7 @@ static EDealRes collectPlaceholderValuesImpl(SNode* pNode, void* pContext) { } static int32_t collectPlaceholderValues(SPlanContext* pCxt, SQueryPlan* pPlan) { - SCollectPlaceholderValuesCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pValues = NULL }; + SCollectPlaceholderValuesCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pValues = NULL}; nodesWalkPhysiPlan((SNode*)pPlan, collectPlaceholderValuesImpl, &cxt); if (TSDB_CODE_SUCCESS == cxt.errCode) { pPlan->pPlaceholderValues = cxt.pValues; @@ -43,14 +43,14 @@ static int32_t collectPlaceholderValues(SPlanContext* pCxt, SQueryPlan* pPlan) { } int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNodeList) { - SLogicNode* pLogicNode = NULL; - SLogicSubplan* pLogicSubplan = NULL; + SLogicNode* pLogicNode = NULL; + SLogicSubplan* pLogicSubplan = NULL; SQueryLogicPlan* pLogicPlan = NULL; int32_t code = createLogicPlan(pCxt, &pLogicNode); if (TSDB_CODE_SUCCESS == code) { code = optimizeLogicPlan(pCxt, pLogicNode); - } + } if (TSDB_CODE_SUCCESS == code) { code = splitLogicPlan(pCxt, pLogicNode, &pLogicSubplan); } @@ -170,10 +170,8 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_BIND_v2* pParam) { int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_BIND_v2* pParams) { int32_t index = 0; - SNode* pNode = NULL; - FOREACH(pNode, pPlan->pPlaceholderValues) { - setValueByBindParam((SValueNode*)pNode, pParams + index); - } + SNode* pNode = NULL; + FOREACH(pNode, pPlan->pPlaceholderValues) { setValueByBindParam((SValueNode*)pNode, pParams + index); } return TSDB_CODE_SUCCESS; } @@ -188,12 +186,10 @@ int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) { return nodesNodeToString((const SNode*)pSubplan, false, pStr, pLen); } -int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) { - return nodesStringToNode(pStr, (SNode**)pSubplan); -} +int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) { return nodesStringToNode(pStr, (SNode**)pSubplan); } char* qQueryPlanToString(const SQueryPlan* pPlan) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; if (TSDB_CODE_SUCCESS != nodesNodeToString(pPlan, false, &pStr, &len)) { return NULL; @@ -209,6 +205,4 @@ SQueryPlan* qStringToQueryPlan(const char* pStr) { return pPlan; } -void qDestroyQueryPlan(SQueryPlan* pPlan) { - nodesDestroyNode(pPlan); -} +void qDestroyQueryPlan(SQueryPlan* pPlan) { nodesDestroyNode(pPlan); } diff --git a/source/libs/planner/test/planOptTest.cpp b/source/libs/planner/test/planOptTest.cpp index 4a682a5e17ff8443ab43d020fbe77fa6e18182e7..deb20c65a4a3eb9c76ec455556f52977fb9a3218 100644 --- a/source/libs/planner/test/planOptTest.cpp +++ b/source/libs/planner/test/planOptTest.cpp @@ -18,9 +18,7 @@ using namespace std; -class PlanOptimizeTest : public PlannerTestBase { - -}; +class PlanOptimizeTest : public PlannerTestBase {}; TEST_F(PlanOptimizeTest, orderByPrimaryKey) { useDb("root", "test"); diff --git a/source/libs/planner/test/planSTableTest.cpp b/source/libs/planner/test/planSTableTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49002fe8269004e736b3a4c847b2d5c9ed3393f8 --- /dev/null +++ b/source/libs/planner/test/planSTableTest.cpp @@ -0,0 +1,26 @@ +/* + * 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" + +using namespace std; + +class PlanSuperTableTest : public PlannerTestBase {}; + +TEST_F(PlanSuperTableTest, unionAll) { + useDb("root", "test"); + + run("select tbname from st1"); +} diff --git a/source/libs/planner/test/planSetOpTest.cpp b/source/libs/planner/test/planSetOpTest.cpp index 5ace503959f0987fe0d96cdcca04b8869bf2389e..ba7fde3c777e8dea2096df3c2ee0931122f19f41 100644 --- a/source/libs/planner/test/planSetOpTest.cpp +++ b/source/libs/planner/test/planSetOpTest.cpp @@ -18,9 +18,7 @@ using namespace std; -class PlanSetOpTest : public PlannerTestBase { - -}; +class PlanSetOpTest : public PlannerTestBase {}; TEST_F(PlanSetOpTest, unionAll) { useDb("root", "test"); diff --git a/source/libs/planner/test/planStmtTest.cpp b/source/libs/planner/test/planStmtTest.cpp index ca206c784356eccfec485d428c5eb104fb46b7bf..7366e7663e5c6b16deb506a4cae4d99a927240dd 100644 --- a/source/libs/planner/test/planStmtTest.cpp +++ b/source/libs/planner/test/planStmtTest.cpp @@ -19,7 +19,7 @@ using namespace std; class PlanStmtTest : public PlannerTestBase { -public: + public: void prepare(const string& sql) { run(sql); // todo calloc pBindParams_ @@ -42,9 +42,9 @@ public: // todo } -private: + private: TAOS_BIND_v2* pBindParams_; - int32_t paramNo_; + int32_t paramNo_; }; TEST_F(PlanStmtTest, stmt) { diff --git a/source/libs/planner/test/planTestMain.cpp b/source/libs/planner/test/planTestMain.cpp index 84cf75c5be8aede5873e1547c05c469c9f81a2bb..a7726973f0ebe9d6979bc8d4a39e6b38cd6fd191 100644 --- a/source/libs/planner/test/planTestMain.cpp +++ b/source/libs/planner/test/planTestMain.cpp @@ -21,27 +21,22 @@ #include "planTestUtil.h" class PlannerEnv : public testing::Environment { -public: + public: virtual void SetUp() { initMetaDataEnv(); generateMetaData(); } - virtual void TearDown() { - destroyMetaDataEnv(); - } + virtual void TearDown() { destroyMetaDataEnv(); } PlannerEnv() {} virtual ~PlannerEnv() {} }; static void parseArg(int argc, char* argv[]) { - int opt = 0; - const char *optstring = ""; - static struct option long_options[] = { - {"dump", no_argument, NULL, 'd'}, - {0, 0, 0, 0} - }; + int opt = 0; + const char* optstring = ""; + static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}}; while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (opt) { case 'd': @@ -54,8 +49,8 @@ static void parseArg(int argc, char* argv[]) { } int main(int argc, char* argv[]) { - testing::AddGlobalTestEnvironment(new PlannerEnv()); - testing::InitGoogleTest(&argc, argv); + testing::AddGlobalTestEnvironment(new PlannerEnv()); + testing::InitGoogleTest(&argc, argv); parseArg(argc, argv); - return RUN_ALL_TESTS(); + return RUN_ALL_TESTS(); } diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index f124970875ceedc582d133ecf0185975f4fab3ad..c619e9b405cdd3661fc8d87df9e0e505f42cfb8b 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#include #include "planTestUtil.h" +#include #include @@ -25,18 +25,19 @@ using namespace std; using namespace testing; -#define DO_WITH_THROW(func, ...) \ - do { \ - int32_t code__ = func(__VA_ARGS__); \ - 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())); \ - } \ - } while(0); +#define DO_WITH_THROW(func, ...) \ + do { \ + int32_t code__ = func(__VA_ARGS__); \ + 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())); \ + } \ + } while (0); bool g_isDump = false; class PlannerTestBaseImpl { -public: + public: void useDb(const string& acctId, const string& db) { caseEnv_.acctId_ = acctId; caseEnv_.db_ = db; @@ -74,24 +75,24 @@ public: } } -private: + private: struct caseEnv { string acctId_; string db_; }; struct stmtEnv { - string sql_; + string sql_; array msgBuf_; }; struct stmtRes { - string ast_; - string rawLogicPlan_; - string optimizedLogicPlan_; - string splitLogicPlan_; - string scaledLogicPlan_; - string physiPlan_; + string ast_; + string rawLogicPlan_; + string optimizedLogicPlan_; + string splitLogicPlan_; + string scaledLogicPlan_; + string physiPlan_; vector physiSubplans_; }; @@ -126,11 +127,11 @@ private: cout << subplan << endl; } } - + void doParseSql(const string& sql, SQuery** pQuery) { stmtEnv_.sql_ = sql; transform(stmtEnv_.sql_.begin(), stmtEnv_.sql_.end(), stmtEnv_.sql_.begin(), ::tolower); - + SParseContext cxt = {0}; cxt.acctId = atoi(caseEnv_.acctId_.c_str()); cxt.db = caseEnv_.db_.c_str(); @@ -138,7 +139,7 @@ private: cxt.sqlLen = stmtEnv_.sql_.length(); cxt.pMsg = stmtEnv_.msgBuf_.data(); cxt.msgLen = stmtEnv_.msgBuf_.max_size(); - + DO_WITH_THROW(qParseQuerySql, &cxt, pQuery); res_.ast_ = toString((*pQuery)->pRoot); } @@ -170,9 +171,7 @@ private: SNode* pNode; FOREACH(pNode, (*pPlan)->pSubplans) { SNode* pSubplan; - FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { - res_.physiSubplans_.push_back(toString(pSubplan)); - } + FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { res_.physiSubplans_.push_back(toString(pSubplan)); } } } @@ -197,7 +196,7 @@ private: } string toString(const SNode* pRoot) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; DO_WITH_THROW(nodesNodeToString, pRoot, false, &pStr, &len) string str(pStr); @@ -210,16 +209,10 @@ private: stmtRes res_; }; -PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) { -} +PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {} -PlannerTestBase::~PlannerTestBase() { -} +PlannerTestBase::~PlannerTestBase() {} -void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) { - impl_->useDb(acctId, db); -} +void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) { impl_->useDb(acctId, db); } -void PlannerTestBase::run(const std::string& sql) { - return impl_->run(sql); -} +void PlannerTestBase::run(const std::string& sql) { return impl_->run(sql); } diff --git a/source/libs/planner/test/planTestUtil.h b/source/libs/planner/test/planTestUtil.h index dbd14237eebb92f53319947f90e4b5af333031a5..7aabff811f06e6ad1485162102be1f350d8d0f94 100644 --- a/source/libs/planner/test/planTestUtil.h +++ b/source/libs/planner/test/planTestUtil.h @@ -21,14 +21,14 @@ class PlannerTestBaseImpl; class PlannerTestBase : public testing::Test { -public: + public: PlannerTestBase(); virtual ~PlannerTestBase(); void useDb(const std::string& acctId, const std::string& db); void run(const std::string& sql); -private: + private: std::unique_ptr impl_; }; diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 7ab61a8daaab0b6e66dfd453e3afc780a26a571a..11280768237d225aaa8a51bdc1d0b7ad558060e0 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -25,7 +25,7 @@ using namespace std; using namespace testing; class PlannerTest : public Test { -protected: + protected: void setDatabase(const string& acctId, const string& db) { acctId_ = acctId; db_ = db; @@ -45,13 +45,14 @@ protected: int32_t code = qParseQuerySql(&cxt_, &query_); if (code != TSDB_CODE_SUCCESS) { - cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl; + 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; + + SLogicNode* pLogicNode = nullptr; SPlanContext cxt = {0}; cxt.queryId = 1; cxt.acctId = 0; @@ -63,7 +64,7 @@ protected: 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; @@ -90,12 +91,13 @@ protected: return false; } - code = createPhysiPlan(&cxt, pLogicPlan, &plan_, NULL); + 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; @@ -110,7 +112,7 @@ protected: return true; } -private: + private: static const int max_err_len = 1024; void setPlanContext(SQuery* pQuery, SPlanContext* pCxt) { @@ -141,7 +143,7 @@ private: } string toString(const SNode* pRoot, bool format = true) { - char* pStr = NULL; + char* pStr = NULL; int32_t len = 0; int32_t code = nodesNodeToString(pRoot, format, &pStr, &len); if (code != TSDB_CODE_SUCCESS) { @@ -153,13 +155,13 @@ private: return str; } - string acctId_; - string db_; - char errMagBuf_[max_err_len]; - string sqlBuf_; + string acctId_; + string db_; + char errMagBuf_[max_err_len]; + string sqlBuf_; SParseContext cxt_; - SQuery* query_; - SQueryPlan* plan_; + SQuery* query_; + SQueryPlan* plan_; }; TEST_F(PlannerTest, selectBasic) { @@ -192,7 +194,9 @@ TEST_F(PlannerTest, selectJoin) { 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'"); + 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()); } @@ -210,12 +214,17 @@ TEST_F(PlannerTest, selectGroupBy) { 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"); + 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()); } @@ -362,7 +371,9 @@ TEST_F(PlannerTest, createTopic) { 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)"); + bind( + "create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 " + "interval(10s)"); ASSERT_TRUE(run()); } diff --git a/source/libs/scalar/inc/sclvector.h b/source/libs/scalar/inc/sclvector.h index adbdd13a8435773b9002d59d7ed4047dcbc5fc76..f80ffc70a21a68460df747f087f6db808b3c7218 100644 --- a/source/libs/scalar/inc/sclvector.h +++ b/source/libs/scalar/inc/sclvector.h @@ -86,8 +86,10 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) p = getVectorDoubleValue_JSON; } else if (srcType == TSDB_DATA_TYPE_BOOL) { p = getVectorDoubleValue_BOOL; + } else if (srcType == TSDB_DATA_TYPE_NULL) { + p = NULL; } else { - assert(0); + ASSERT(0); } return p; } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 820a4894b5ed756bcacfe030211b24b35e86b11e..334c58c18409e3ac161d10e21ac031224bc8caa5 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -486,10 +486,10 @@ _return: EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)*pNode; SNode* tnode = NULL; - if (fmIsUserDefinedFunc(node->funcId)) { + if (!fmIsScalarFunc(node->funcId)) { return DEAL_RES_CONTINUE; } - + FOREACH(tnode, node->pParameterList) { if (!SCL_IS_CONST_NODE(tnode)) { return DEAL_RES_CONTINUE; @@ -511,14 +511,16 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { return DEAL_RES_ERROR; } + res->translate = true; + if (colDataIsNull_s(output.columnData, 0)) { res->node.resType.type = TSDB_DATA_TYPE_NULL; } else { res->node.resType = node->node.resType; int32_t type = output.columnData->info.type; if (IS_VAR_DATA_TYPE(type)) { - res->datum.p = output.columnData->pData; - output.columnData->pData = NULL; + 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); } @@ -553,6 +555,7 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { } res->node.resType = node->node.resType; + res->translate = true; int32_t type = output.columnData->info.type; if (IS_VAR_DATA_TYPE(type)) { @@ -588,20 +591,25 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); if (NULL == res) { - sclError("make value node failed"); - sclFreeParam(&output); + sclError("make value node failed"); + sclFreeParam(&output); ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return DEAL_RES_ERROR; } - res->node.resType = node->node.resType; + res->translate = true; - int32_t type = output.columnData->info.type; - if (IS_VAR_DATA_TYPE(type)) { // todo refactor - res->datum.p = output.columnData->pData; - output.columnData->pData = NULL; + if (colDataIsNull_s(output.columnData, 0)) { + res->node.resType.type = TSDB_DATA_TYPE_NULL; } else { - memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); + res->node.resType = node->node.resType; + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { // todo refactor + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; + } else { + memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); + } } nodesDestroyNode(*pNode); @@ -612,10 +620,6 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { } EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { - if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode)) { - return DEAL_RES_CONTINUE; - } - SScalarCtx *ctx = (SScalarCtx *)pContext; if (QUERY_NODE_FUNCTION == nodeType(*pNode)) { @@ -628,17 +632,15 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { return sclRewriteOperator(pNode, ctx); - } - - sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode)); - ctx->code = TSDB_CODE_QRY_INVALID_INPUT; - return DEAL_RES_ERROR; + } + + return DEAL_RES_CONTINUE; } EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)pNode; SScalarParam output = {0}; - + ctx->code = sclExecFunction(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; @@ -655,7 +657,7 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)pNode; SScalarParam output = {0}; - + ctx->code = sclExecLogic(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 08b58cf8100a5561917d965eac10d15156f2e6bc..28514c360575a76cd5691d768b67c6da98692f89 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1265,8 +1265,11 @@ int32_t todayFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut } int32_t timezoneFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + char output[TD_TIMEZONE_LEN + VARSTR_HEADER_SIZE] = {0}; + memcpy(varDataVal(output), tsTimezoneStr, TD_TIMEZONE_LEN); + varDataSetLen(output, strlen(tsTimezoneStr)); for (int32_t i = 0; i < pInput->numOfRows; ++i) { - colDataAppend(pOutput->columnData, i, tsTimezoneStr, false); + colDataAppend(pOutput->columnData, i, output, false); } pOutput->numOfRows = pInput->numOfRows; return TSDB_CODE_SUCCESS; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index f63e539a969236d6091ea4c300ec4a7231d5d718..11a5bc9d0e8ef1a195519e0fce2e3093ac34b588 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -150,34 +150,36 @@ int64_t getVectorBigintValue_JSON(void *src, int32_t index){ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { _getBigintValue_fn_t p = NULL; - if(srcType==TSDB_DATA_TYPE_TINYINT) { - p = getVectorBigintValue_TINYINT; - }else if(srcType==TSDB_DATA_TYPE_UTINYINT) { - p = getVectorBigintValue_UTINYINT; - }else if(srcType==TSDB_DATA_TYPE_SMALLINT) { - p = getVectorBigintValue_SMALLINT; - }else if(srcType==TSDB_DATA_TYPE_USMALLINT) { - p = getVectorBigintValue_USMALLINT; - }else if(srcType==TSDB_DATA_TYPE_INT) { - p = getVectorBigintValue_INT; - }else if(srcType==TSDB_DATA_TYPE_UINT) { - p = getVectorBigintValue_UINT; - }else if(srcType==TSDB_DATA_TYPE_BIGINT) { - p = getVectorBigintValue_BIGINT; - }else if(srcType==TSDB_DATA_TYPE_UBIGINT) { - p = getVectorBigintValue_UBIGINT; - }else if(srcType==TSDB_DATA_TYPE_FLOAT) { - p = getVectorBigintValue_FLOAT; - }else if(srcType==TSDB_DATA_TYPE_DOUBLE) { - p = getVectorBigintValue_DOUBLE; - }else if(srcType==TSDB_DATA_TYPE_TIMESTAMP) { - p = getVectorBigintValue_BIGINT; - }else if(srcType==TSDB_DATA_TYPE_BOOL) { - p = getVectorBigintValue_BOOL; - }else if(srcType==TSDB_DATA_TYPE_JSON) { - p = getVectorBigintValue_JSON; - }else { - assert(0); + if (srcType==TSDB_DATA_TYPE_TINYINT) { + p = getVectorBigintValue_TINYINT; + } else if (srcType==TSDB_DATA_TYPE_UTINYINT) { + p = getVectorBigintValue_UTINYINT; + } else if (srcType==TSDB_DATA_TYPE_SMALLINT) { + p = getVectorBigintValue_SMALLINT; + } else if (srcType==TSDB_DATA_TYPE_USMALLINT) { + p = getVectorBigintValue_USMALLINT; + } else if (srcType==TSDB_DATA_TYPE_INT) { + p = getVectorBigintValue_INT; + } else if (srcType==TSDB_DATA_TYPE_UINT) { + p = getVectorBigintValue_UINT; + } else if (srcType==TSDB_DATA_TYPE_BIGINT) { + p = getVectorBigintValue_BIGINT; + } else if (srcType==TSDB_DATA_TYPE_UBIGINT) { + p = getVectorBigintValue_UBIGINT; + } else if (srcType==TSDB_DATA_TYPE_FLOAT) { + p = getVectorBigintValue_FLOAT; + } else if (srcType==TSDB_DATA_TYPE_DOUBLE) { + p = getVectorBigintValue_DOUBLE; + } else if (srcType==TSDB_DATA_TYPE_TIMESTAMP) { + p = getVectorBigintValue_BIGINT; + } else if (srcType==TSDB_DATA_TYPE_BOOL) { + p = getVectorBigintValue_BOOL; + } else if (srcType==TSDB_DATA_TYPE_JSON) { + p = getVectorBigintValue_JSON; + } else if (srcType==TSDB_DATA_TYPE_NULL){ + p = NULL; + } else { + ASSERT(0); } return p; } @@ -1594,7 +1596,7 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { case OP_TYPE_JSON_CONTAINS: return vectorJsonContains; default: - assert(0); + ASSERT(0); return NULL; } } diff --git a/source/libs/sync/CMakeLists.txt b/source/libs/sync/CMakeLists.txt index cb196acc02e49c7e3aa85a1d522515d69ebf33ef..551849c6f29f3def8b275877aba28f7048ea1793 100644 --- a/source/libs/sync/CMakeLists.txt +++ b/source/libs/sync/CMakeLists.txt @@ -11,7 +11,7 @@ target_link_libraries( target_include_directories( sync - PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" + PUBLIC "${TD_SOURCE_DIR}/include/libs/sync" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) diff --git a/source/libs/sync/inc/syncEnv.h b/source/libs/sync/inc/syncEnv.h index e9550ff989013fa99c6846659e580093d4ae9dc0..4f91990ccf29a93cdd7b9d4fd4f2e16bfc3df480 100644 --- a/source/libs/sync/inc/syncEnv.h +++ b/source/libs/sync/inc/syncEnv.h @@ -39,6 +39,8 @@ extern "C" { #define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0}) typedef struct SSyncEnv { + uint8_t isStart; + // tick timer tmr_h pEnvTickTimer; int32_t envTickTimerMS; diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c index ff2d4d4d27f691fe09240b473f3b8ed159ca6f87..4b2bc4130ab7ae9988cb927446e680d6352702ca 100644 --- a/source/libs/sync/src/syncEnv.c +++ b/source/libs/sync/src/syncEnv.c @@ -26,6 +26,14 @@ static int32_t doSyncEnvStopTimer(SSyncEnv *pSyncEnv); static void syncEnvTick(void *param, void *tmrId); // -------------------------------- +bool syncEnvIsStart() { + if (gSyncEnv == NULL) { + return false; + } + + return atomic_load_8(&(gSyncEnv->isStart)); +} + int32_t syncEnvStart() { int32_t ret = 0; taosSeedRand(taosGetTimestampSec()); @@ -88,12 +96,15 @@ static SSyncEnv *doSyncEnvStart() { // start tmr thread pSyncEnv->pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV"); + + atomic_store_8(&(pSyncEnv->isStart), 1); return pSyncEnv; } static int32_t doSyncEnvStop(SSyncEnv *pSyncEnv) { assert(pSyncEnv == gSyncEnv); if (pSyncEnv != NULL) { + atomic_store_8(&(pSyncEnv->isStart), 0); taosTmrCleanUp(pSyncEnv->pTimerManager); taosMemoryFree(pSyncEnv); } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index a3068d69a951f03014386d734adda73088b6de77..262c9d55309da56df9364d00399b2fb15e0258e8 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -457,6 +457,20 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { void syncNodeStart(SSyncNode* pSyncNode) { // start raft + if (pSyncNode->replicaNum == 1) { + syncNodeBecomeLeader(pSyncNode); + + syncNodeLog2("==state change become leader immediately==", pSyncNode); + + // Raft 3.6.2 Committing entries from previous terms + + // use this now + syncNodeAppendNoop(pSyncNode); + syncMaybeAdvanceCommitIndex(pSyncNode); // maybe only one replica + return; + } + + syncNodeBecomeFollower(pSyncNode); // for test diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index 3319a73fcf9e4c197706081c4dbee4f7e8a98ffc..8afe9ff2a724d031531bbf5fd5c867673a00c46b 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -199,197 +199,197 @@ target_sources(syncApplyMsgTest target_include_directories(syncTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEnvTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingTimerTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOTickQTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOTickPingTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOSendMsgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOClientTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIOServerTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRaftStoreTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEnqTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIndexTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncInitTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncUtilTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncVotesGrantedTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncVotesRespondTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncIndexMgrTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncLogStoreTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEntryTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRequestVoteTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRequestVoteReplyTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncAppendEntriesTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncAppendEntriesReplyTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncClientRequestTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncTimeoutTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingReplyTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRpcMsgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingTimerTest2 PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncPingSelfTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncElectTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncEncodeTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncWriteTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncReplicateTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRefTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncLogStoreCheck PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRaftCfgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncRespMgrTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncSnapshotTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) target_include_directories(syncApplyMsgTest PUBLIC - "${CMAKE_SOURCE_DIR}/include/libs/sync" + "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) diff --git a/source/libs/sync/test/test.sh b/source/libs/sync/test/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..7a693aac0b811bba987bf059b06862706d07fd7c --- /dev/null +++ b/source/libs/sync/test/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + + diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index c093bdebcef3397fe1dc71093bdbf4a5a1e8d59c..c941cace3bc1bd4207e90e5742f25857c9dfe144 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -979,7 +979,8 @@ void transCloseServer(void* arg) { transSrvInst--; if (transSrvInst == 0) { - transModuleInit = PTHREAD_ONCE_INIT; + TdThreadOnce tmpInit = PTHREAD_ONCE_INIT; + memcpy(&transModuleInit, &tmpInit, sizeof(TdThreadOnce)); uvCloseExHandleMgt(); } } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 207b7d84219750cf1d2110d30b4b6b6f9d69e842..d025ca3781a9db5262a09498cdd65a6652d019fc 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -61,7 +61,6 @@ int32_t walRollback(SWal *pWal, int64_t ver) { walBuildIdxName(pWal, walGetCurFileFirstVer(pWal), fnameStr); TdFilePtr pIdxTFile = taosOpenFile(fnameStr, TD_FILE_WRITE | TD_FILE_READ); - // TODO:change to deserialize function if (pIdxTFile == NULL) { taosThreadMutexUnlock(&pWal->mutex); return -1; @@ -73,7 +72,6 @@ int32_t walRollback(SWal *pWal, int64_t ver) { return -1; } // read idx file and get log file pos - // TODO:change to deserialize function SWalIdxEntry entry; if (taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { taosThreadMutexUnlock(&pWal->mutex); @@ -167,7 +165,7 @@ int32_t walEndSnapshot(SWal *pWal) { char fnameStr[WAL_FILE_LEN]; // remove file for (int i = 0; i < deleteCnt; i++) { - SWalFileInfo *pInfo = taosArrayGet(pWal->fileInfoSet, i); + pInfo = taosArrayGet(pWal->fileInfoSet, i); walBuildLogName(pWal, pInfo->firstVer, fnameStr); taosRemoveFile(fnameStr); walBuildIdxName(pWal, pInfo->firstVer, fnameStr); diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index 148529170c7d50a633993efb4bf4a1496bc29683..62c1747619154257c68bac98bf1e26b1b38d25c5 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -39,11 +39,11 @@ void* taosLoadDll(const char* filename) { #else void* handle = dlopen(filename, RTLD_LAZY); if (!handle) { - //printf("load dll:%s failed, error:%s", filename, dlerror()); + // printf("load dll:%s failed, error:%s", filename, dlerror()); return NULL; } - //printf("dll %s loaded", filename); + // printf("dll %s loaded", filename); return handle; #endif @@ -59,17 +59,17 @@ void* taosLoadSym(void* handle, char* name) { char* error = NULL; if ((error = dlerror()) != NULL) { - //printf("load sym:%s failed, error:%s", name, dlerror()); + // printf("load sym:%s failed, error:%s", name, dlerror()); return NULL; } - //printf("sym %s loaded", name); + // printf("sym %s loaded", name); return sym; #endif } -void taosCloseDll(void* handle) { +void taosCloseDll(void* handle) { #if defined(WINDOWS) return; #elif defined(_TD_DARWIN_64) @@ -100,7 +100,7 @@ int taosSetConsoleEcho(bool on) { struct termios term; if (tcgetattr(STDIN_FILENO, &term) == -1) { - perror("Cannot get the attribution of the terminal"); + /*perror("Cannot get the attribution of the terminal");*/ return -1; } @@ -111,7 +111,7 @@ int taosSetConsoleEcho(bool on) { err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term); if (err == -1 || err == EINTR) { - printf("Cannot set the attribution of the terminal"); + /*printf("Cannot set the attribution of the terminal");*/ return -1; } @@ -154,7 +154,7 @@ void taosSetTerminalMode() { int32_t taosGetOldTerminalMode() { #if defined(WINDOWS) - + #else /* Make sure stdin is a terminal. */ if (!isatty(STDIN_FILENO)) { @@ -181,7 +181,7 @@ void taosResetTerminalMode() { #endif } -TdCmdPtr taosOpenCmd(const char *cmd) { +TdCmdPtr taosOpenCmd(const char* cmd) { if (cmd == NULL) return NULL; #ifdef WINDOWS return (TdCmdPtr)_popen(cmd, "r"); @@ -190,8 +190,8 @@ TdCmdPtr taosOpenCmd(const char *cmd) { #endif } -int64_t taosGetLineCmd(TdCmdPtr pCmd, char ** __restrict ptrBuf) { - if (pCmd == NULL || ptrBuf == NULL ) { +int64_t taosGetLineCmd(TdCmdPtr pCmd, char** __restrict ptrBuf) { + if (pCmd == NULL || ptrBuf == NULL) { return -1; } if (*ptrBuf != NULL) { @@ -219,7 +219,7 @@ int32_t taosEOFCmd(TdCmdPtr pCmd) { return feof((FILE*)pCmd); } -int64_t taosCloseCmd(TdCmdPtr *ppCmd) { +int64_t taosCloseCmd(TdCmdPtr* ppCmd) { if (ppCmd == NULL || *ppCmd == NULL) { return 0; } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 699a7aa080fdc5e581555b7193fe257473330995..5bfef810c3d4e716beb966c8f5966442028cef32 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -18,6 +18,9 @@ #include "taoserror.h" #include "tlog.h" #include "tutil.h" +#include "tenv.h" +#include "cJSON.h" +#include "tjson.h" #define CFG_NAME_PRINT_LEN 24 #define CFG_SRC_PRINT_LEN 12 @@ -25,6 +28,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath); int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath); int32_t cfgLoadFromEnvVar(SConfig *pConfig); +int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd); int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url); int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype); @@ -45,7 +49,7 @@ SConfig *cfgInit() { return pCfg; } -int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { +int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr) { switch (cfgType) { case CFG_STYPE_CFG_FILE: return cfgLoadFromCfgFile(pCfg, sourceStr); @@ -55,6 +59,8 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { return cfgLoadFromEnvVar(pCfg); case CFG_STYPE_APOLLO_URL: return cfgLoadFromApollUrl(pCfg, sourceStr); + case CFG_STYPE_ENV_CMD: + return cfgLoadFromEnvCmd(pCfg, (const char **)sourceStr); default: return -1; } @@ -139,6 +145,12 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { return -1; } + if (taosRealPath(fullDir, NULL, PATH_MAX) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + uError("failed to get realpath of dir:%s since %s", inputDir, terrstr()); + return -1; + } + taosMemoryFreeClear(pItem->str); pItem->str = strdup(fullDir); if (pItem->str == NULL) { @@ -463,6 +475,8 @@ const char *cfgStypeStr(ECfgSrcType type) { return "arg_list"; case CFG_STYPE_TAOS_OPTIONS: return "taos_options"; + case CFG_STYPE_ENV_CMD: + return "env_cmd"; default: return "invalid"; } @@ -584,12 +598,154 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { } int32_t cfgLoadFromEnvVar(SConfig *pConfig) { - uDebug("load from env variables not implemented yet"); + char *line = NULL, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + ssize_t _bytes = 0; + TdCmdPtr pCmd = taosOpenCmd("set"); + if (pCmd == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + while (!taosEOFCmd(pCmd)) { + name = value = value2 = value3 = NULL; + olen = vlen = vlen2 = vlen3 = 0; + + _bytes = taosGetLineCmd(pCmd, &line); + if (_bytes < 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + taosEnvToCfg(line, line); + + paGetToken(line, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + + cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_VAR); + } + } + + taosCloseCmd(&pCmd); + if (line != NULL) taosMemoryFreeClear(line); + + uInfo("load from env variables cfg success"); return 0; } -int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) { - uDebug("load from env file not implemented yet"); +int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) { + char *buf, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + int32_t index = 0; + if (envCmd == NULL) return 0; + while (envCmd[index]!=NULL) { + buf = taosMemoryMalloc(strlen(envCmd[index])); + taosEnvToCfg(envCmd[index], buf); + index++; + + name = value = value2 = value3 = NULL; + olen = vlen = vlen2 = vlen3 = 0; + + paGetToken(buf, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + + cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_CMD); + } + + taosMemoryFree(buf); + } + + uInfo("load from env cmd cfg success"); + return 0; +} + +int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { + char *line = NULL, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + ssize_t _bytes = 0; + + const char *filepath = ".env"; + if (envFile != NULL && strlen(envFile)>0) { + if (!taosCheckExistFile(envFile)) { + uError("fial to load env file: %s", envFile); + return -1; + } + filepath = envFile; + }else { + if (!taosCheckExistFile(filepath)) { + uInfo("fial to load env file: %s", filepath); + return 0; + } + } + + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); + if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + while (!taosEOFFile(pFile)) { + name = value = value2 = value3 = NULL; + olen = vlen = vlen2 = vlen3 = 0; + + _bytes = taosGetLineFile(pFile, &line); + if (_bytes <= 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + taosEnvToCfg(line, line); + + paGetToken(line, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + + cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_FILE); + } + } + + taosCloseFile(&pFile); + if (line != NULL) taosMemoryFreeClear(line); + + uInfo("load from env cfg file %s success", filepath); return 0; } @@ -617,11 +773,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { olen = vlen = vlen2 = vlen3 = 0; _bytes = taosGetLineFile(pFile, &line); - if (_bytes < 0) { + if (_bytes <= 0) { break; } - line[_bytes - 1] = 0; + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; paGetToken(line, &name, &olen); if (olen == 0) continue; @@ -659,6 +815,192 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { } int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { - uDebug("load from apoll url not implemented yet"); + char *cfgLineBuf = NULL, *name, *value, *value2, *value3; + int32_t olen, vlen, vlen2, vlen3; + if (url == NULL || strlen(url) == 0) { + uInfo("fail to load apoll url"); + return 0; + } + + char *p = strchr(url, ':'); + if (p == NULL) { + uError("fail to load apoll url: %s, unknown format", url); + return -1; + } + p++; + + if (memcmp(url, "jsonFile", 8) == 0) { + char *filepath = p; + if (!taosCheckExistFile(filepath)) { + uError("fial to load json file: %s", filepath); + return -1; + } + + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); + if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); + char *buf = taosMemoryMalloc(fileSize); + taosLSeekFile(pFile, 0, SEEK_SET); + if(taosReadFile(pFile, buf, fileSize) <= 0) { + taosCloseFile(&pFile); + uError("load json file error: %s", filepath); + return -1; + } + taosCloseFile(&pFile); + SJson* pJson = tjsonParse(buf); + if (NULL == pJson) { + const char *jsonParseError = tjsonGetError(); + if (jsonParseError != NULL) { + uError("load json file parse error: %s", jsonParseError); + } + return -1; + } + taosMemoryFreeClear(buf); + + int32_t jsonArraySize = tjsonGetArraySize(pJson); + for(int32_t i = 0; i < jsonArraySize; i++) { + cJSON* item = tjsonGetArrayItem(pJson, i); + if (item == NULL) break; + char *itemName = NULL, *itemValueString = NULL; + tjsonGetObjectName(item, &itemName); + tjsonGetObjectName(item, &itemName); + tjsonGetObjectValueString(item, &itemValueString); + if (itemValueString != NULL && itemName != NULL) { + size_t itemNameLen = strlen(itemName); + size_t itemValueStringLen = strlen(itemValueString); + cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2); + memcpy(cfgLineBuf, itemName, itemNameLen); + cfgLineBuf[itemNameLen] = ' '; + memcpy(&cfgLineBuf[itemNameLen+1], itemValueString, itemValueStringLen); + cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0'; + + paGetToken(cfgLineBuf, &name, &olen); + if (olen == 0) continue; + name[olen] = 0; + + paGetToken(name + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + paGetToken(value + vlen + 1, &value2, &vlen2); + if (vlen2 != 0) { + value2[vlen2] = 0; + paGetToken(value2 + vlen2 + 1, &value3, &vlen3); + if (vlen3 != 0) value3[vlen3] = 0; + } + cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL); + if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) { + cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_APOLLO_URL); + } + } + } + tjsonDelete(pJson); + + // } else if (memcmp(url, "jsonUrl", 7) == 0) { + // } else if (memcmp(url, "etcdUrl", 7) == 0) { + } else { + uError("Unsupported url: %s", url); + return -1; + } + + uInfo("load from apoll url not implemented yet"); return 0; } + +int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl) { + int32_t index = 0; + if (envCmd == NULL) return 0; + while (envCmd[index]!=NULL) { + if (memcmp(envCmd[index], "TAOS_APOLLO_URL", 14) == 0) { + char *p = strchr(envCmd[index], '='); + if (p != NULL) { + p++; + if (*p == '\'') { + p++; + p[strlen(p)-1] = '\0'; + } + memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); + uInfo("get apollo url from env cmd success"); + return 0; + } + } + index++; + } + + char *line = NULL; + ssize_t _bytes = 0; + TdCmdPtr pCmd = taosOpenCmd("set"); + if (pCmd != NULL) { + while (!taosEOFCmd(pCmd)) { + _bytes = taosGetLineCmd(pCmd, &line); + if (_bytes < 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + if (memcmp(line, "TAOS_APOLLO_URL", 14) == 0) { + char *p = strchr(line, '='); + if (p != NULL) { + p++; + if (*p == '\'') { + p++; + p[strlen(p)-1] = '\0'; + } + memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); + uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl); + taosCloseCmd(&pCmd); + if (line != NULL) taosMemoryFreeClear(line); + return 0; + } + } + } + taosCloseCmd(&pCmd); + if (line != NULL) taosMemoryFreeClear(line); + } + + const char *filepath = ".env"; + if (envFile != NULL && strlen(envFile)>0) { + if (!taosCheckExistFile(envFile)) { + uError("fial to load env file: %s", envFile); + return -1; + } + filepath = envFile; + }else { + if (!taosCheckExistFile(filepath)) { + uInfo("fial to load env file: %s", filepath); + return 0; + } + } + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); + if (pFile != NULL) { + while (!taosEOFFile(pFile)) { + _bytes = taosGetLineFile(pFile, &line); + if (_bytes <= 0) { + break; + } + if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; + if (memcmp(line, "TAOS_APOLLO_URL", 14) == 0) { + char *p = strchr(line, '='); + if (p != NULL) { + p++; + if (*p == '\'') { + p++; + p[strlen(p)-1] = '\0'; + } + memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); + taosCloseFile(&pFile); + if (line != NULL) taosMemoryFreeClear(line); + uInfo("get apollo url from env file success"); + return 0; + } + } + } + taosCloseFile(&pFile); + if (line != NULL) taosMemoryFreeClear(line); + } + + uInfo("fail get apollo url from cmd env file"); + return -1; +} \ No newline at end of file diff --git a/source/util/src/tenv.c b/source/util/src/tenv.c new file mode 100644 index 0000000000000000000000000000000000000000..e717e82c5b27bb9911364571538cf8f6863098b8 --- /dev/null +++ b/source/util/src/tenv.c @@ -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 . + */ + +#define _DEFAULT_SOURCE +#include "tenv.h" +#include "tconfig.h" + +static char toLowChar(char c) { return (c > 'Z' || c < 'A' ? c : (c - 'A' + 'a')); } + +int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen) { + if (envNameStr == NULL || cfgNameStr == NULL) return -1; + char *p = cfgNameStr; + if (envNameStr[0] != 'T' || envNameStr[1] != 'A' || envNameStr[2] != 'O' || envNameStr[3] != 'S' || + envNameStr[4] != '_') { + // if(p != envNameStr) strncpy(p, envNameStr, cfgNameMaxLen - 1); + // p[cfgNameMaxLen - 1] = '\0'; + // return strlen(cfgNameStr); + cfgNameStr[0] = '\0'; + return -1; + } + envNameStr += 5; + if (*envNameStr != '\0') { + *p = toLowChar(*envNameStr); + p++; + envNameStr++; + } + + for (size_t i = 1; i < cfgNameMaxLen && *envNameStr != '\0'; i++) { + if (*envNameStr == '_') { + envNameStr++; + *p = *envNameStr; + if (*envNameStr == '\0') break; + } else { + *p = toLowChar(*envNameStr); + } + p++; + envNameStr++; + } + + *p = '\0'; + return strlen(cfgNameStr); +} + +int32_t taosEnvToCfg(const char *envStr, char *cfgStr) { + if (envStr == NULL && cfgStr == NULL) { + return -1; + } + if (cfgStr != envStr) strcpy(cfgStr, envStr); + char *p = strchr(cfgStr, '='); + + if (p != NULL) { + char buf[CFG_NAME_MAX_LEN]; + if (*(p+1) == '\'') { + *(p+1)= ' '; + char *pEnd = &cfgStr[strlen(cfgStr)-1]; + if (*pEnd == '\'') *pEnd = '\0'; + } + *p = '\0'; + int32_t cfgNameLen = taosEnvNameToCfgName(cfgStr, buf, CFG_NAME_MAX_LEN); + if (cfgNameLen > 0) { + memcpy(cfgStr, buf, cfgNameLen); + memset(&cfgStr[cfgNameLen], ' ', p - cfgStr - cfgNameLen + 1); + } + } + return strlen(cfgStr); +} \ No newline at end of file diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 50c924bbb972e43d97fdf3fcfb5d51824d2a2b04..399a2255ac4403ee1a966a741545b6652211d1ea 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -403,6 +403,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CHECKSUM, "Invalid msg checksum" TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_MSGLEN, "Invalid msg length") TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_MSGTYPE, "Invalid msg type") +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_LEADER, "Sync not leader") +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INTERNAL_ERROR, "Sync internal error") + // wal TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, "Unexpected generic error in wal") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_FILE_CORRUPTED, "WAL file is corrupted") diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 0b9727e0bf666b660000d4a0a57b72a6eff65fcd..558c2258f46239e94e6eebbd1acae9081284c16c 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -144,6 +144,22 @@ char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatt SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); } +int32_t tjsonGetObjectName(const SJson* pJson, char** pName) { + *pName = ((cJSON*)pJson)->string; + if (NULL == *pName) { + return TSDB_CODE_FAILED; + } + return TSDB_CODE_SUCCESS; +} + +int32_t tjsonGetObjectValueString(const SJson* pJson, char** pValueString) { + *pValueString = ((cJSON*)pJson)->valuestring; + if (NULL == *pValueString) { + return TSDB_CODE_FAILED; + } + return TSDB_CODE_SUCCESS; +} + int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) { char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName)); if (NULL == p) { @@ -309,4 +325,6 @@ bool tjsonValidateJson(const char *jIn) { } } return true; -} \ No newline at end of file +} + +const char* tjsonGetError() { return cJSON_GetErrorPtr(); } \ No newline at end of file diff --git a/source/util/test/CMakeLists.txt b/source/util/test/CMakeLists.txt index d98f9f677d33eff7517c97ecfe9f2ab9538dd4e5..3c52d52d504852528874716a2237ad671e27cef4 100644 --- a/source/util/test/CMakeLists.txt +++ b/source/util/test/CMakeLists.txt @@ -31,7 +31,7 @@ ENDIF() # TARGET_LINK_LIBRARIES(trefTest util common) #ENDIF () -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc) # freelistTest add_executable(freelistTest "") diff --git a/source/util/test/cfgTest.cpp b/source/util/test/cfgTest.cpp index 712fb2d09a240037e99fd144a5030bb670ef606a..cd13ebe8ae3a07db3cd75ec39df3f5795566d1dc 100644 --- a/source/util/test/cfgTest.cpp +++ b/source/util/test/cfgTest.cpp @@ -32,6 +32,7 @@ TEST_F(CfgTest, 01_Str) { EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var"); + EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_CMD), "env_cmd"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list"); EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid"); diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index b8abd4ff1023a7aa45ef3c0acdc143225afe2b37..ec847dedbbc91ca66ff95d3ab5aa1ae9c1bffe03 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -135,7 +135,7 @@ echo "qDebugFlag 143" >> $TAOS_CFG echo "rpcDebugFlag 143" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "uDebugFlag 143" >> $TAOS_CFG -echo "sDebugFlag 143" >> $TAOS_CFG +echo "sDebugFlag 135" >> $TAOS_CFG echo "wDebugFlag 143" >> $TAOS_CFG echo "numOfLogLines 20000000" >> $TAOS_CFG echo "statusInterval 1" >> $TAOS_CFG diff --git a/tests/script/sh/massiveTable/compileVersion.sh b/tests/script/sh/massiveTable/compileVersion.sh index dcd1f8aeea7a4feac4e215db5b09e2e7c5346854..6b45e98ea3c09d06e314d172a59b40c1cfa70870 100755 --- a/tests/script/sh/massiveTable/compileVersion.sh +++ b/tests/script/sh/massiveTable/compileVersion.sh @@ -57,7 +57,8 @@ function compileTDengineVersion() { cd ${debugDir} cmake .. - make -j24 + make -j24 + make install } ######################################################################################## ############################### main process ########################################## @@ -67,20 +68,5 @@ cd ${projectDir} gitPullBranchInfo $TDengineBrVer compileTDengineVersion -taos_dir=${projectDir}/debug/build/bin -taosd_dir=${projectDir}/debug/build/bin -exec_process_dir=${projectDir}/debug/build/bin - -rm -f /usr/bin/taos -rm -f /usr/bin/taosd -rm -f /usr/bin/create_table -rm -f /usr/bin/tmq_demo -rm -f /usr/bin/tmq_sim - -ln -s $taos_dir/taos /usr/bin/taos -ln -s $taosd_dir/taosd /usr/bin/taosd -ln -s $exec_process_dir/create_table /usr/bin/create_table -ln -s $exec_process_dir/tmq_demo /usr/bin/tmq_demo -ln -s $exec_process_dir/tmq_sim /usr/bin/tmq_sim diff --git a/tests/script/tsim/snode/basic1.sim b/tests/script/tsim/snode/basic1.sim index 2351403909e9f641e2ada2789561a095a0e915d4..660951c591bb9048b592e7be60492925b13b600d 100644 --- a/tests/script/tsim/snode/basic1.sim +++ b/tests/script/tsim/snode/basic1.sim @@ -75,46 +75,46 @@ if $data02 != LEADER then return -1 endi -print =============== create drop qnode 1 -sql create qnode on dnode 1 -sql show qnodes +print =============== create drop snode 1 +sql create snode on dnode 1 +sql show snodes if $rows != 1 then return -1 endi if $data00 != 1 then return -1 endi -sql_error create qnode on dnode 1 +sql_error create snode on dnode 1 -sql drop qnode on dnode 1 -sql show qnodes +sql drop snode on dnode 1 +sql show snodes if $rows != 0 then return -1 endi -sql_error drop qnode on dnode 1 +sql_error drop snode on dnode 1 -print =============== create drop qnode 2 -sql create qnode on dnode 2 -sql show qnodes +print =============== create drop snode 2 +sql create snode on dnode 2 +sql show snodes if $rows != 1 then return -1 endi if $data00 != 2 then return -1 endi -sql_error create qnode on dnode 2 +sql_error create snode on dnode 2 -sql drop qnode on dnode 2 -sql show qnodes +sql drop snode on dnode 2 +sql show snodes if $rows != 0 then return -1 endi -sql_error drop qnode on dnode 2 +sql_error drop snode on dnode 2 -print =============== create drop qnodes -sql create qnode on dnode 1 -sql create qnode on dnode 2 -sql show qnodes +print =============== create drop snodes +sql create snode on dnode 1 +sql create snode on dnode 2 +sql show snodes if $rows != 2 then return -1 endi @@ -126,7 +126,7 @@ system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode2 -s start sleep 2000 -sql show qnodes +sql show snodes if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/tmq/basic1.sim b/tests/script/tsim/tmq/basic1.sim index d7534338e1c0781cb911c2bcd4b3f19c730ff59e..0c96635a788ba18ab391cfad869e2a68e675954c 100644 --- a/tests/script/tsim/tmq/basic1.sim +++ b/tests/script/tsim/tmq/basic1.sim @@ -25,7 +25,7 @@ $rowsPerCtb = 10 $tstart = 1640966400000 # 2022-01-01 00:00:00.000 #---- global parameters end ----# -$pullDelay = 5 +$pullDelay = 3 $ifcheckdata = 1 $showMsg = 1 $showRow = 0 diff --git a/tests/script/tsim/tmq/basic2.sim b/tests/script/tsim/tmq/basic2.sim index ac0d2bb6df1a228ed8576103f39a4ad70ff6c850..53f10e22475cc067a25b86b7aa0c46c342d0111c 100644 --- a/tests/script/tsim/tmq/basic2.sim +++ b/tests/script/tsim/tmq/basic2.sim @@ -25,7 +25,7 @@ $rowsPerCtb = 10 $tstart = 1640966400000 # 2022-01-01 00:00:00.000 #---- global parameters end ----# -$pullDelay = 5 +$pullDelay = 3 $ifcheckdata = 1 $showMsg = 1 $showRow = 0 diff --git a/tests/script/tsim/tmq/basic3.sim b/tests/script/tsim/tmq/basic3.sim index c0ba2c97fb3528d72b67bd51b183c13f4d92e351..de771ba892ec01825fbed08464a7d3794a5226bf 100644 --- a/tests/script/tsim/tmq/basic3.sim +++ b/tests/script/tsim/tmq/basic3.sim @@ -25,7 +25,7 @@ $rowsPerCtb = 10 $tstart = 1640966400000 # 2022-01-01 00:00:00.000 #---- global parameters end ----# -$pullDelay = 5 +$pullDelay = 3 $ifcheckdata = 1 $showMsg = 1 $showRow = 0 diff --git a/tests/script/tsim/tmq/basic4.sim b/tests/script/tsim/tmq/basic4.sim index 1eed93463cc37322fe523cc1a91984b7c2c32da3..42023bda7e1f5d5defd0266ae5a4146f50851314 100644 --- a/tests/script/tsim/tmq/basic4.sim +++ b/tests/script/tsim/tmq/basic4.sim @@ -25,7 +25,7 @@ $rowsPerCtb = 10 $tstart = 1640966400000 # 2022-01-01 00:00:00.000 #---- global parameters end ----# -$pullDelay = 5 +$pullDelay = 3 $ifcheckdata = 1 $showMsg = 1 $showRow = 0 diff --git a/tests/system-test/2-query/Now.py b/tests/system-test/2-query/Now.py new file mode 100644 index 0000000000000000000000000000000000000000..7f0e17343996c709a44fbf84c7b2d0694dc67f90 --- /dev/null +++ b/tests/system-test/2-query/Now.py @@ -0,0 +1,310 @@ + + +from util.dnodes import * +from util.log import * +from util.sql import * +from util.cases import * + + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def run(self): # sourcery skip: extract-duplicate-method + # for func now() , today(), timezone() + tdSql.prepare() + today_date = datetime.datetime.strptime( + datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d") + + tdLog.printNoPrefix("==========step1:create tables==========") + tdSql.execute( + '''create table if not exists ntb + (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) + ''' + ) + tdSql.execute( + '''create table if not exists stb + (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int) + ''' + ) + tdSql.execute( + '''create table if not exists stb_1 using stb tags(100) + ''' + ) + tdLog.printNoPrefix("==========step2:insert data into ntb==========") + tdSql.execute( + 'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + tdSql.execute( + 'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + tdLog.printNoPrefix("==========step2:query test of ntb ==========") + + # test function now() + # ntable + tdSql.query("select now() from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1w from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1w from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1d from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1d from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1h from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1h from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1m from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1m from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1s from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1s from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1a from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1a from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1u from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1u from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1b from ntb") + tdSql.checkRows(3) + tdSql.query("select now() +1b from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1w from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1w from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1d from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1d from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1h from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1h from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1m from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1m from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1s from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1s from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1a from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1a from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1u from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1u from db.ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1b from ntb") + tdSql.checkRows(3) + tdSql.query("select now() -1b from db.ntb") + tdSql.checkRows(3) + tdSql.query("select * from ntb where ts=now()") + tdSql.checkRows(0) + tdSql.query("select * from ntb where ts>now()") + tdSql.checkRows(0) + tdSql.query("select now() from ntb where ts=today()") + tdSql.checkRows(1) + + # stable + tdSql.query("select now() from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1w from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1w from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() +1d from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1d from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() +1h from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1h from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() +1m from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1m from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() +1s from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1s from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() +1a from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1a from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() +1u from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1u from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() +1b from stb") + tdSql.checkRows(3) + tdSql.query("select now() +1b from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1w from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1w from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1d from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1d from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1h from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1h from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1m from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1m from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1s from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1s from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1a from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1a from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1u from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1u from db.stb") + tdSql.checkRows(3) + tdSql.query("select now() -1b from stb") + tdSql.checkRows(3) + tdSql.query("select now() -1b from db.stb") + tdSql.checkRows(3) + # 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) + + # table + tdSql.query("select now() from 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") + tdSql.checkRows(3) + tdSql.query("select now() +1d from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1d from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1h from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1h from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1m from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1m from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1s from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1s from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1a from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1a from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1u from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1u from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1b from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() +1b 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") + tdSql.checkRows(3) + tdSql.query("select now() -1d from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1d from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1h from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1h from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1m from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1m from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1s from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1s from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1a from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1a from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1u from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1u from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1b from stb_1") + tdSql.checkRows(3) + tdSql.query("select now() -1b from db.stb_1") + tdSql.checkRows(3) + tdSql.query("select * from stb_1 where ts=now()") + tdSql.checkRows(0) + tdSql.query("select * from stb_1 where ts>now()") + tdSql.checkRows(0) + + # tdSql.query("select * from stb_1 where ts=now") + # tdSql.checkRows(0) + # tdSql.query("select * from stb_1 where ts>now") + # tdSql.checkRows(0) + + tdSql.query("select now() from stb_1 where ts=today()") + tdSql.checkRows(1) + + 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/To_iso8061.py b/tests/system-test/2-query/To_iso8061.py new file mode 100644 index 0000000000000000000000000000000000000000..fca53572ca4e115749cf360dbd75274bca2d7f74 --- /dev/null +++ b/tests/system-test/2-query/To_iso8061.py @@ -0,0 +1,78 @@ +from time import sleep + +from util.log import * +from util.sql import * +from util.cases import * + + + + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def run(self): # sourcery skip: extract-duplicate-method + tdSql.prepare() + # get system timezone + today_date = datetime.datetime.strptime( + datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d") + + tdLog.printNoPrefix("==========step1:create tables==========") + tdSql.execute( + '''create table if not exists ntb + (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) + ''' + ) + tdSql.execute( + '''create table if not exists stb + (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int) + ''' + ) + tdSql.execute( + '''create table if not exists stb_1 using stb tags(100) + ''' + ) + + tdLog.printNoPrefix("==========step2:insert data==========") + tdSql.execute('insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + tdSql.execute('insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + + tdSql.query("select to_iso8601(ts) from ntb") + tdSql.checkRows(3) + tdSql.query("select c1 from ntb where ts = to_iso8601(1577808000000)") + tdSql.checkRows(1) + tdSql.checkData(0,0,10) + tdSql.query("select * from ntb where ts = to_iso8601(1577808000000)") + tdSql.checkRows(1) + tdSql.query("select to_iso8601(ts) from ntb where ts=today()") + tdSql.checkRows(1) + # tdSql.checkData(0,0,10) + for i in range(1,10): + tdSql.query("select to_iso8601(1) from ntb") + tdSql.checkData(0,0,"1970-01-01T08:00:01+0800") + i+=1 + sleep(0.2) + tdSql.checkRows(3) + tdSql.query("select to_iso8601(ts) from ntb") + tdSql.checkRows(3) + tdSql.query("select to_iso8601(ts) from db.ntb") + + tdSql.query("select to_iso8601(today()) from ntb") + tdSql.checkRows(3) + tdSql.query("select to_iso8601(now()) from ntb") + tdSql.checkRows(3) + + tdSql.error("select to_iso8601(timezone()) from ntb") + tdSql.error("select to_iso8601('abc') from ntb") + + + + + 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/Today.py b/tests/system-test/2-query/Today.py new file mode 100644 index 0000000000000000000000000000000000000000..ad4e48bda5cd707809055be6463ed080447ccbd5 --- /dev/null +++ b/tests/system-test/2-query/Today.py @@ -0,0 +1,318 @@ + + +from util.dnodes import * +from util.log import * +from util.sql import * +from util.cases import * + + +class TDTestCase: + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def run(self): # sourcery skip: extract-duplicate-method + # for func now() , today(), timezone() + tdSql.prepare() + today_date = datetime.datetime.strptime( + datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d") + + tdLog.printNoPrefix("==========step1:create tables==========") + tdSql.execute( + '''create table if not exists ntb + (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) + ''' + ) + tdSql.execute( + '''create table if not exists stb + (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int) + ''' + ) + tdSql.execute( + '''create table if not exists stb_1 using stb tags(100) + ''' + ) + tdLog.printNoPrefix("==========step2:insert data into ntb==========") + tdSql.execute( + 'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + tdSql.execute( + 'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())') + tdLog.printNoPrefix("==========step2:query test of ntb ==========") + + # test function today() + # normal table + tdSql.query("select today() from ntb") + tdSql.checkRows(3) + tdSql.checkData(0, 0, str(today_date)) + tdSql.query("select today() from db.ntb") + tdSql.checkRows(3) + tdSql.checkData(0, 0, str(today_date)) + tdSql.query("select today() +1w from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1w from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1d from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1d from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1h from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1h from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1m from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1m from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1s from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1s from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1a from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1a from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1u from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1u from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1b from ntb") + tdSql.checkRows(3) + tdSql.query("select today() +1b from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1w from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1w from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1d from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1d from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1h from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1h from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1m from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1m from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1s from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1s from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1a from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1a from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1u from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1u from db.ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1b from ntb") + tdSql.checkRows(3) + tdSql.query("select today() -1b from db.ntb") + tdSql.checkRows(3) + tdSql.query("select * from ntb where ts=today()") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 3) + tdSql.query("select * from ntb where ts<=today()") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 10) + # for bug + # tdSql.query("select * from ntb where ts=today()") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 3) + # tdSql.query("select * from ntb where ts>today()") + # tdSql.checkRows(1) + tdSql.query("select c4 from ntb where c4=today()") + tdSql.checkRows(1) + tdSql.checkData(0, 0, str(today_date)) + tdSql.query("select today() from ntb where ts=today()") + # tdSql.checkRows(2) + # tdSql.query("select * from ntb where ts>today()") + # tdSql.checkRows(1) + tdSql.query("select c4 from stb where c4=today()") + tdSql.checkRows(1) + tdSql.checkData(0, 0, str(today_date)) + tdSql.query("select today() from stb where ts=today()") + tdSql.checkRows(2) + tdSql.query("select * from ntb where ts>today()") + tdSql.checkRows(1) + tdSql.query("select c4 from stb_1 where c4=today()") + tdSql.checkRows(1) + tdSql.query("select today() from stb_1 where ts -#include #include #include #include #include #include #include -#include #include "taos.h" #include "taoserror.h" @@ -103,8 +101,8 @@ void initLogFile() { TdFilePtr pFile = taosOpenFile(file, TD_FILE_TEXT | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (NULL == pFile) { fprintf(stderr, "Failed to open %s for save result\n", "./tmqlog.txt"); - exit -1; - }; + exit(-1); + } g_fp = pFile; } diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index 5bbcceada5591454c6dcb639d6ee22112baf6073..69f15a164ef78fb750c5386683f0eb66f24d0b7e 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -28,8 +28,8 @@ char simScriptDir[PATH_MAX] = {0}; extern bool simExecSuccess; int32_t simInitCfg() { - taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, 1); - taosInitCfg(configDir, NULL, NULL, NULL, 1); + taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, NULL, 1); + taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1); SConfig *pCfg = taosGetCfg(); simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32; diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 3b22b3085211cc4fd99f00d84359305f17f0edd1..284693795ee471ad2d631758970c3033dc8e0c6c 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -3,7 +3,7 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) target_link_libraries( shell - PUBLIC taos_static + PUBLIC taos PRIVATE os common transport util ) target_include_directories( diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index 5391d28277cf3858fc8b403c91ebad247fbbe869..8ccfde4b16dd591a9535e618f0738e28c68d6332 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -61,6 +61,35 @@ void shellPrintHelp() { printf("\n\nReport bugs to %s.\n", SHELL_EMAIL); } +#ifdef LINUX +#include +#include + +const char *argp_program_version = version; +const char *argp_program_bug_address = SHELL_EMAIL; + +static struct argp_option shellOptions[] = { + {"host", 'h', "HOST", 0, SHELL_HOST}, + {"port", 'P', "PORT", 0, SHELL_PORT}, + {"user", 'u', "USER", 0, SHELL_USER}, + {0, 'p', 0, 0, SHELL_PASSWORD}, + {"auth", 'a', "AUTH", 0, SHELL_AUTH}, + {"generate-auth", 'A', 0, 0, SHELL_GEN_AUTH}, + {"config-dir", 'c', "DIR", 0, SHELL_CFG_DIR}, + {"dump-config", 'C', 0, 0, SHELL_DMP_CFG}, + {"commands", 's', "COMMANDS", 0, SHELL_CMD}, + {"raw-time", 'r', 0, 0, SHELL_RAW_TIME}, + {"file", 'f', "FILE", 0, SHELL_FILE}, + {"database", 'd', "DATABASE", 0, SHELL_DB}, + {"check", 'k', 0, 0, SHELL_CHECK}, + {"startup", 't', 0, 0, SHELL_STARTUP}, + {"display-width", 'w', "WIDTH", 0, SHELL_WIDTH}, + {"netrole", 'n', "NETROLE", 0, SHELL_NET_ROLE}, + {"pktlen", 'l', "PKTLEN", 0, SHELL_PKG_LEN}, + {"pktnum", 'N', "PKTNUM", 0, SHELL_PKT_NUM}, + {0}, +}; + static int32_t shellParseSingleOpt(int32_t key, char *arg) { SShellArgs *pArgs = &shell.args; @@ -178,35 +207,6 @@ int32_t shellParseArgsWithoutArgp(int argc, char *argv[]) { return 0; } -#ifdef LINUX -#include -#include - -const char *argp_program_version = version; -const char *argp_program_bug_address = SHELL_EMAIL; - -static struct argp_option shellOptions[] = { - {"host", 'h', "HOST", 0, SHELL_HOST}, - {"port", 'P', "PORT", 0, SHELL_PORT}, - {"user", 'u', "USER", 0, SHELL_USER}, - {0, 'p', 0, 0, SHELL_PASSWORD}, - {"auth", 'a', "AUTH", 0, SHELL_AUTH}, - {"generate-auth", 'A', 0, 0, SHELL_GEN_AUTH}, - {"config-dir", 'c', "DIR", 0, SHELL_CFG_DIR}, - {"dump-config", 'C', 0, 0, SHELL_DMP_CFG}, - {"commands", 's', "COMMANDS", 0, SHELL_CMD}, - {"raw-time", 'r', 0, 0, SHELL_RAW_TIME}, - {"file", 'f', "FILE", 0, SHELL_FILE}, - {"database", 'd', "DATABASE", 0, SHELL_DB}, - {"check", 'k', 0, 0, SHELL_CHECK}, - {"startup", 't', 0, 0, SHELL_STARTUP}, - {"display-width", 'w', "WIDTH", 0, SHELL_WIDTH}, - {"netrole", 'n', "NETROLE", 0, SHELL_NET_ROLE}, - {"pktlen", 'l', "PKTLEN", 0, SHELL_PKG_LEN}, - {"pktnum", 'N', "PKTNUM", 0, SHELL_PKT_NUM}, - {0}, -}; - static error_t shellParseOpt(int32_t key, char *arg, struct argp_state *state) { return shellParseSingleOpt(key, arg); } static struct argp shellArgp = {shellOptions, shellParseOpt, "", ""}; @@ -335,7 +335,7 @@ int32_t shellParseArgs(int32_t argc, char *argv[]) { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) shell.info.osname = "Windows"; snprintf(shell.history.file, TSDB_FILENAME_LEN, "C:/TDengine/%s", SHELL_HISTORY_FILE); - if (shellParseArgsWithoutArgp(argc, argv) != 0) return -1; + // if (shellParseArgsWithoutArgp(argc, argv) != 0) return -1; #elif defined(_TD_DARWIN_64) shell.info.osname = "Darwin"; snprintf(shell.history.file, TSDB_FILENAME_LEN, "%s/%s", getpwuid(getuid())->pw_dir, SHELL_HISTORY_FILE); diff --git a/tools/shell/src/shellCommand.c b/tools/shell/src/shellCommand.c index c34ee7a22c6da4caf03ceae4b9a24744074eb4a0..6813e9b2f77e855155d43022b768411a1d5175a6 100644 --- a/tools/shell/src/shellCommand.c +++ b/tools/shell/src/shellCommand.c @@ -54,8 +54,8 @@ static void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos); static void shellShowOnScreen(SShellCmd *cmd); #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) -static void shellPrintContinuePrompt() { printf("%s", shell.args.promptContinue); } -static void shellPrintPrompt() { printf("%s", shell.args.promptHeader); } +// static void shellPrintContinuePrompt() { printf("%s", shell.args.promptContinue); } +// static void shellPrintPrompt() { printf("%s", shell.args.promptHeader); } void shellUpdateBuffer(SShellCmd *cmd) { if (shellRegexMatch(cmd->buffer, "(\\s+$)|(^$)", REG_EXTENDED)) strcat(cmd->command, " "); @@ -112,7 +112,7 @@ int32_t shellReadCommand(char command[]) { cmd.command = NULL; return 0; } else { - shellPrintContinuePrompt(); + // shellPrintContinuePrompt(); shellUpdateBuffer(&cmd); } break; @@ -395,7 +395,7 @@ void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos) { void shellShowOnScreen(SShellCmd *cmd) { struct winsize w; if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) { - fprintf(stderr, "No stream device\n"); + // fprintf(stderr, "No stream device\n"); w.ws_col = 120; w.ws_row = 30; } diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index ac2be3c3cf89d45b032a3b26f3bafe7c218fce29..1f036ab25be42ede5ad7cdee03c4a70605804785 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -750,7 +750,7 @@ void shellReadHistory() { void shellWriteHistory() { SShellHistory *pHistory = &shell.history; - TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_WRITE | TD_FILE_STREAM); + TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_APPEND); if (pFile == NULL) return; for (int32_t i = pHistory->hstart; i != pHistory->hend;) { diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index 6672cee367b04d1a45460a87502c86480d65969b..d277920877e1ee0cc0f21cd7a265d13c0fc3d3c6 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -42,8 +42,6 @@ int main(int argc, char *argv[]) { return 0; } - taos_init(); - if (shell.args.is_dump_config) { shellDumpConfig(); taos_cleanup();